|
| 1 | +# Patterns in Quamina |
| 2 | + |
| 3 | +**Patterns** are added to Quamina instances using the |
| 4 | +`AddPattern` API. This document specifies the syntax and |
| 5 | +semantics of Patterns. |
| 6 | + |
| 7 | +## Fields |
| 8 | + |
| 9 | +Patterns exist to match **Fields** in incoming **Events**. At |
| 10 | +launch, Quamina supports only JSON syntax for Events. An |
| 11 | +Event **MUST** be equivalent to a JSON Object in the |
| 12 | +sense that it consists of an unordered set of members, |
| 13 | +each identified by a name which is string composed of |
| 14 | +Unicode characters. |
| 15 | + |
| 16 | +As in JSON, the allowed member values may be strings, |
| 17 | +numbers, the literals `true`, `false`, and `null`, arrays, |
| 18 | +and objects. We refer to values which are neither arrays |
| 19 | +nor objects as **Leaf** values. |
| 20 | + |
| 21 | +A **Field** is the combination of a Leaf value and a |
| 22 | +**Path**, a list of strings which are the Field names |
| 23 | +that must be traversed to reach it from the Event root. |
| 24 | + |
| 25 | +For example, in the Event |
| 26 | +```json |
| 27 | +{"alpha": {"beta": 1}} |
| 28 | +``` |
| 29 | +There is only one Field whose Leaf value is `1` |
| 30 | +and whose Path is `"alpha","beta"`. |
| 31 | + |
| 32 | +Paths omit arrays. So in the Event |
| 33 | +```json |
| 34 | +{"alpha": [ {"beta": [1, 2]}, {"beta": [3, 4]} ] } |
| 35 | +``` |
| 36 | +The Path for the Leaf value `1` is still `"alpha","beta"` |
| 37 | + |
| 38 | +### Pattern Syntax and Semantics |
| 39 | +A Pattern **MUST** be a JSON object all of whose Leaf |
| 40 | +values **MUST** be in arrays. |
| 41 | + |
| 42 | +To match a Field in an Event, the Pattern **MUST** contain |
| 43 | +an exactly-matching Path whose value **MUST** be an array |
| 44 | +which contains either the Field’s Leaf value or an |
| 45 | +**Extended Pattern** |
| 46 | + |
| 47 | +Thus, the following Pattern would match both JSON events above: |
| 48 | +```json |
| 49 | +{"alpha": {"beta": [1]}} |
| 50 | +``` |
| 51 | + |
| 52 | +## Extended Patterns |
| 53 | +An **Extended Pattern** **MUST** be a JSON object containing |
| 54 | +a single field whose name is called the **Pattern Type**. |
| 55 | + |
| 56 | +### Exists Pattern |
| 57 | + |
| 58 | +The Pattern Type of an Exists Pattern is `exists` and its |
| 59 | +value **MUST** be `true` or `false`. Here |
| 60 | +are two Exists Patterns that would match the Events above: |
| 61 | +```json |
| 62 | +{"alpha": {"beta": [ {"exists": true} ]}} |
| 63 | +``` |
| 64 | +```json |
| 65 | +{"alpha": {"gamma": [ {"exists": false} ]}} |
| 66 | +``` |
| 67 | + |
| 68 | +If a Field in a Pattern contains an Exists Pattern, it |
| 69 | +**MUST NOT** contain any other values. |
| 70 | + |
| 71 | +### Shellstyle Pattern |
| 72 | + |
| 73 | +The Pattern Type of a Shellstyle Pattern is `shellstyle` |
| 74 | +and its value **MUST** be a string which **MAY** contain |
| 75 | +a single `*` (“star”) character. The star character |
| 76 | +functions exactly as the same character does in |
| 77 | +command-line processors which descend from Unix’s |
| 78 | +shell; i.e., matches the regular expression `.*` |
| 79 | + |
| 80 | +Consider the following Event: |
| 81 | +```json |
| 82 | +{"img": "https://example.com/9943.jpg"} |
| 83 | +``` |
| 84 | +The following Shellstyle Patterns would match it: |
| 85 | +```json |
| 86 | +{"img": [ {"shellstyle": "*.jpg"} ]} |
| 87 | +``` |
| 88 | +```json |
| 89 | +{"img": [ {"shellstyle": "https://example.com/*"} ]} |
| 90 | +``` |
| 91 | +```json |
| 92 | +{"img": [ {"shellstyle": "https://example.com/*.jpg"} ]} |
| 93 | +``` |
| 94 | + |
| 95 | +## EventBridge Patterns |
| 96 | + |
| 97 | +Quamina’s Patterns are inspired by those offered by |
| 98 | +the AWS EventBridge service, as documented in |
| 99 | +[Amazon EventBridge event patterns](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns.html). |
| 100 | + |
| 101 | +As of release 0.1.1, Quamina supports Exists patterns |
| 102 | +but does not yet support AWS’s `numeric`, `prefix`, or |
| 103 | +`anything-but` patterns. Note that a Shellstyle |
| 104 | +Pattern with a trailing `*` is equivalent to an AWS `prefix` |
| 105 | +pattern. |
| 106 | + |
| 107 | + |
| 108 | + |
0 commit comments