Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event Filters #169

Open
brianneisler opened this issue Jul 24, 2017 · 0 comments
Open

Event Filters #169

brianneisler opened this issue Jul 24, 2017 · 0 comments

Comments

@brianneisler
Copy link
Contributor

brianneisler commented Jul 24, 2017

This is a Feature Request

Description

Provide a easy way of filtering events. Filters should be configurable and capable of filtering on multiple values.

Use-cases

  • Prevent a function from being invoked on every event of a particular type.
  • Filter events based on data values.
  • Segment events between functions based on data in the event.

Concepts

  • Filters are specified using the filters property.
  • The filters property is expected to be an array.
  • Each filter is a logical statement that is meant to be resolved to a boolean.
  • Statements are simple code meant to be compiled to executable functions (some better way?)
  • Multiple filters are AND'd together.

Variables

  • Each statement has a few predefined variables that are available.

event

  • The event variable represents the current event that is being compared.
  • All of the event's internal properties are available for comparison
  • The data field in the event should be lazily deserialized (if possible)

Literals

false

  • represents the boolean primitive false

true

  • represents the boolean primitive true

Functions

  • Each statement has a few predefined functions that are available.

isString

  • determines if the value is a string
isString(event.data.foo)

isNumber

  • determines if the value is a number
isNumber(event.data.foo)

isBoolean

  • determines if the value is a boolean
isBoolean(event.data.foo)

Operators

  • There are several operators that are available for comparison
Operator Description Example
== equality event.data.foo == 'bar'
!= inequality event.data.bar != 'baz'
> greater than event.received > 0
>= greater than or equal
< less than
<= less than or equal
&& and event.data.a && event.data.b
|| or event.data.a || event.data.b
! not !event.data.val

Examples

  1. Filter events based on some data property

Event

{
  "event": "someEventType",
  "id": "66dfc31d-6844-42fd-b1a7-a489a49f65f3",
  "received": 1500897327098,
  "data": "{\"foo\": \"bar\"}",
  "encoding": "json"
}

Subscription that matches event sdk usage

fdk.subscribe("someFunction", {
  event: "someEventType",
  filters: [
    "event.data.foo == 'bar'"
  ]
})

Subscription - framework usage

functions:
  sendEmail:
    handler: index.sendEmail
    events:
      - myapp.user.created:
           filters: 
             - "event.data.validEmail != true"
This was referenced Jul 24, 2017
@mthenw mthenw changed the title Feature Request: Event Filters Event Filters Aug 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants