Skip to content

Commit

Permalink
Example evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
expede committed Jul 2, 2024
1 parent 743323b commit 374b732
Showing 1 changed file with 144 additions and 17 deletions.
161 changes: 144 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ For example, consider the following `args` from an `Invocation`:
"cc": ["[email protected]"],
"title": "Meeting Confirmation",
"body": "I'll see you on Tuesday"
},
// ...
}
}
```

Expand Down Expand Up @@ -279,6 +278,7 @@ NOTE: You cannot add _any_ indentation to this table if you want
<td>

``` json
// FIXME double check with implementation
null
```

Expand All @@ -289,32 +289,159 @@ null

### Validation

## Examples
Validation

``` js
// Delegation
{
"cmd": "/msg/send",
"pol": [
["==", ".from", "[email protected]"
["==", ".title", "Coffee"]
],
// ...
}
Being tree structured, evaluation MAY proceed in any order. Here is one step-by-step example:

// Valid invocation
{
<details>
<summary>Example Context</summary>

``` js
{ // Invocation
"cmd": "/msg/send",
"args": {
"from": "[email protected]", // Matches above
"from": "[email protected]",
"to": ["[email protected]", "[email protected]"],
"title": "Coffee",
"body": "Still on for coffee" // Matches above
"body": "Still on for coffee"
},
// ...
}

{ // Delegation
"cmd": "/msg",
"pol": [
["==", ".from", "[email protected]"],
["some", ".to", ["match", ".", "*@example.com"]]
],
// ...
}
```

</details>

<details>
<summary>Code Example</summary>

``` js
// Extract policy
[
["==", ".from", "[email protected]"],
["some", ".to", ["match", ".", "*@example.com"]]
]

// Resolve selectors
[
["==", "[email protected]", "[email protected]"],
["some", ["[email protected]", "[email protected]"], ["match", ".", "*@example.com"]]
]

// Expand quantifier
[
["==", "[email protected]", "[email protected]"],
["or", [
["match", "[email protected]", "*@example.com"]
["match", "[email protected]", "*@example.com"]]]
]

// Evaluate first clause
[
true,
["or", [
["match", "[email protected]", "*@example.com"]
["match", "[email protected]", "*@example.com"]]]
]

// Evaluate second clause's children
[
true,
["or", [true, false]]
]

// Evaluate second clause
[true, true]

// Implicit top-level `and`
true
```

</details>

<details>

<summary>Graphical Example</summary>

``` mermaid
flowchart BT
policy
eq["=="] --> policy
from[".from"] --> eq
alice["[email protected]"] --> eq
some --> policy
to[".to"] --> some
match --> some
this["."] --> match
pattern["*@example.com"] --> match
```

``` mermaid
flowchart BT
policy
eq["=="] --> policy
from["[email protected]"] --> eq
alice["[email protected]"] --> eq
some --> policy
to["[]"] --> some
bob["[email protected]"] --> to
carol["[email protected]"] --> to
match --> some
this["."] --> match
pattern["*@example.com"] --> match
```

``` mermaid
flowchart BT
policy
eq["=="] --> policy
from["[email protected]"] --> eq
alice["[email protected]"] --> eq
or --> policy
match_bob --> or
bob["[email protected]"] --> match_bob
bob_pattern["*@example.com"] --> match_bob
match_carol --> or
carol["[email protected]"] --> match_carol
carol_pattern["*@example.com"] --> match_carol
```

``` mermaid
flowchart BT
policy
alice["true"] --> policy
or --> policy
match_bob["true"] --> or
match_carol["false"] --> or
```

``` mermaid
flowchart BT
policy
alice["true"] --> policy
or["true"] --> policy
```

``` mermaid
flowchart BT
true
```

</details>

Any arguments MUST be taken verbatim and MUST NOT be further adjusted. For more flexible validation of Arguments, use [Conditions].

Note that this also applies to arrays and objects. For example, the `to` array in this example is considered to be exact, so the Invocation fails validation in this case:
Expand Down

0 comments on commit 374b732

Please sign in to comment.