Skip to content

elasticfeed plugin for JS compiler/interpreter #10

@kris-lab

Description

@kris-lab

Following #4

Elasticfeed DSL Overview (Domain-Specific-Language)

Golang written with embedded javascript as syntax

syntax
  • javascript inspired
parser input
  • pure javascript syntax
  • JSON scenario template
{
  "name": "foo",
  "engine": {
    "version": "v1"
  },
  "defaults": {
    "app": "id"
    "feed": "id",
    "storage": "id",
    "user": "id",
    "stream": "id",
  },
  "callback": {
    "success": "url"
    "error": "url"
  },
  "trigger": {
    "public_feed": {
       "id": "ANY | ID"
       "on_add": true,
       "on_delete": true,
       "on_update": true,
    },
    "user": {
       "id": "ANY | ID"
       "on_relation": true,
       "on_skip": true,
    },
    "schedule": {
      "daily": true,
      "monthly": true,
   }
  },
  "steps" : {
    "search":  {
      "search1": {
        "search": function (api) {
          return {
            "key1": {'name':'foo', 'age':22, 'location': 'london'},
            "key2": {'name':'foo', 'age':45, 'location': 'paris'},
          }
        },
        "select": function (api, key, value) {
          emit(key, {'age': value['age']})
        },
        "reduce": function (api, key, value){
          emit(key, sum(value))
        },
        "sort": function (api){
          'age': -1
        }
      },
      "search2": {
        "search": function () {
          x = in('search1').range(0, 9)
          out(x)
        },
        "select": function (),
        "reduce": function (),
        "sort": function ()
      },
      "searchN": {
        "search": function (),
        "select": function (),
        "reduce": function (),
        "sort": function ()
      }
    },
    "save": {
      "action": "method_bar",
      "lifetime": "5m"
    },
    "notify": "method_bar"
  },
  "controllers": {
    "method_foo": function(key, value, api, [storage, user, stream]) {},
    "method_bar": function(key, value, api, [storage, user, stream]) {},
    "method_foobar": function(key, value, api, [storage, user, stream]) {},
  }
}
keywords
  • emit, pull, next, skip
types
  • entry, graph, storage, map, stream
functions
  • type_of_entry; type_of_relation; instance_of
  • entry_age(), entry_relations(), entry_tags(), entry_history(), entry_stats()
  • user_friend(), user_wife(), user_kids(), user_holidays(), user_jobs()
  • photo_location(), photo_date(), photo_season(), photo_rgb(), photo_colors()
Plugins
GLOBAL Objects
  • Api() or a();
  • App() or ap()
  • Feed() or f()
  • Graph() or g();
  • Stream() or s();
  • Storage() or st(),
iterators
  • each(), map()
casting
  • to_array(), to_hash()

Examples

  • How to use language
  • How to extend with own JS code
  • How to prototype JS objects

Testing

  • cli tool for compiling

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions