Skip to content

Commit

Permalink
Merge pull request #32 from fastly/tyler/vars
Browse files Browse the repository at this point in the history
Implement vars, choose/when, and expressions
  • Loading branch information
kailan authored Jan 15, 2025
2 parents ee34e76 + 38f60ee commit f7ac889
Show file tree
Hide file tree
Showing 21 changed files with 2,303 additions and 50 deletions.
4 changes: 2 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build]
target = "wasm32-wasi"
target = "wasm32-wasip1"

[target.wasm32-wasi]
[target.wasm32-wasip1]
rustflags = ["-C", "debuginfo=2"]
runner = "viceroy run -- "
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
- name: Add wasm32-wasi Rust target
run: rustup target add wasm32-wasi
- name: Add wasm32-wasip1 Rust target
run: rustup target add wasm32-wasip1
- name: Install rustfmt
run: rustup component add rustfmt
shell: bash
Expand Down
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ members = [
"examples/esi_example_minimal",
"examples/esi_example_advanced_error_handling",
"examples/esi_try_example",
"examples/esi_vars_example",
"examples/esi_example_variants",
]

[workspace.package]
version = "0.5.0"
authors = ["Kailan Blanks <kblanks@fastly.com>"]
authors = [
"Kailan Blanks <kblanks@fastly.com>",
"Vadim Getmanshchuk <vadim@fastly.com>",
"Tyler McMullen <tyler@fastly.com>",
]
license = "MIT"
edition = "2018"
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ The implementation is a subset of the [ESI Language Specification 1.0](https://w

- `<esi:include>` (+ `alt`, `onerror="continue"`)
- `<esi:try>` | `<esi:attempt>` | `<esi:except>`
- `<esi:vars>` | `<esi:assign>`
- `<esi:choose>` | `<esi:when>` | `<esi:otherwise>`
- `<esi:comment>`
- `<esi:remove>`

Other tags will be ignored and served to the client as-is.

This implementation also includes an expression interpreter and library of functions that can be used. Current functions include:

- `$lower(string)`
- `$html_encode(string)`
- `$replace(haystack, needle, replacement [, count])`

## Example Usage

```rust,no_run
Expand Down
6 changes: 4 additions & 2 deletions esi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ repository = "https://github.com/fastly/esi"
readme = "./README.md"

[dependencies]
quick-xml = "0.36.0"
thiserror = "^1.0"
quick-xml = "0.37.1"
thiserror = "2.0.6"
fastly = "^0.11"
log = "^0.4"
regex = "1.11.1"
html-escape = "0.2.13"

[dev-dependencies]
env_logger = "^0.11"
12 changes: 12 additions & 0 deletions esi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ pub enum ExecutionError {
/// Writer error
#[error("writer error: {0}")]
WriterError(#[from] std::io::Error),

/// Expression error
#[error("expression failed to evaluate: `{0}`")]
ExpressionError(String),

/// An error occurred while creating a regular expression in an eval context
#[error("failed to create a regular expression")]
RegexError(#[from] regex::Error),

/// An error occurred while executing a function in an eval context
#[error("failed to execute a function: `{0}`")]
FunctionError(String),
}

pub type Result<T> = std::result::Result<T, ExecutionError>;
Loading

0 comments on commit f7ac889

Please sign in to comment.