|
@@ -1,12 +1,41 @@
|
|
EliasDB Event Condition Action Language
|
|
EliasDB Event Condition Action Language
|
|
=======================================
|
|
=======================================
|
|
|
|
|
|
-EliasDB supports a scripting language called [Event Condition Action Language (ECAL)](https://devt.de/krotik/ecal/) to enable rule based scripting functionality.
|
|
+EliasDB supports a scripting language called [Event Condition Action Language (ECAL)](https://devt.de/krotik/ecal/) to enable rule based scripting functionality. ECAL provides [database trigger](https://en.wikipedia.org/wiki/Database_trigger) functionality for EliasDB.
|
|
|
|
+
|
|
|
|
+ECAL was added for the following use-cases:
|
|
|
|
+- Providing a way to manipulate data in response to events
|
|
|
|
+- Enforce certain aspects of a database schema
|
|
|
|
+- Providing back-end logic for web applications using EliasDB
|
|
|
|
+
|
|
|
|
+ECAL related config values:
|
|
|
|
+--
|
|
|
|
+| Configuration Option | Description |
|
|
|
|
+| --- | --- |
|
|
|
|
+| EnableECALScripts | Enable ECAL scripting. |
|
|
|
|
+| ECALScriptFolder | Scripting folder for ECAL scripts. |
|
|
|
|
+| ECALEntryScript | Entry script in the script folder. |
|
|
|
|
+| ECALLogFile | File in which the logs should be written (use an empty string for stdout). |
|
|
|
|
+| ECALLogLevel | Log level for the printed logs. |
|
|
|
|
+| EnableECALDebugServer | Start an ECAL debug server. |
|
|
|
|
+| ECALDebugServerHost | Host for the debug server. |
|
|
|
|
+| ECALDebugServerPort | Port for the debug server. |
|
|
|
|
+
|
|
|
|
+ECAL Debugging
|
|
|
|
+--
|
|
|
|
+If the debug server is enabled in the config file then it is possible to debug ECAL scripts with [VSCode](https://devt.de/krotik/ecal/src/master/ecal-support/README.md). The debugger supports break points and thread state inspection. It is also possible to restart and reload the scripts.
|
|
|
|
+
|
|
|
|
+Using the `-ecal-console` parameter it is possible to open an interactive console into the server process. If used together with the debug server additional debug commands are available also there. Enter `?` to see the build-in documentation.
|
|
|
|
|
|
EliasDB specific events which can be handled:
|
|
EliasDB specific events which can be handled:
|
|
--
|
|
--
|
|
The ECAL interpreter in EliasDB receives the following events:
|
|
The ECAL interpreter in EliasDB receives the following events:
|
|
|
|
|
|
|
|
+Web Request | ECAL event kind | Event state contents | Description
|
|
|
|
+-|-|-|-
|
|
|
|
+/db/api/|`db.web.api`| bodyJSON, bodyString, header, method, path, pathList, query | Any web request to /db/api/*. These endpoints are public and never require authentication.
|
|
|
|
+/db/ecal/|`db.web.ecal`| bodyJSON, bodyString, header, method, path, pathList, query | Any web request to /db/ecal/*. These endpoints are considered internal and require authentication if access control is enabled.
|
|
|
|
+
|
|
EliasDB Graph Event | ECAL event kind | Event state contents | Description
|
|
EliasDB Graph Event | ECAL event kind | Event state contents | Description
|
|
-|-|-|-
|
|
-|-|-|-
|
|
graph.EventNodeCreated | `db.node.created` | part, trans, node | A node was created.
|
|
graph.EventNodeCreated | `db.node.created` | part, trans, node | A node was created.
|
|
@@ -16,15 +45,12 @@ graph.EventEdgeCreated | `db.edge.created` | part, trans, edge | An edge was cre
|
|
graph.EventEdgeUpdated | `db.edge.updated` | part, trans, edge, old_edge | An edge was updated.
|
|
graph.EventEdgeUpdated | `db.edge.updated` | part, trans, edge, old_edge | An edge was updated.
|
|
graph.EventEdgeDeleted | `db.edge.deleted` | part, trans, edge | An edge was deleted.
|
|
graph.EventEdgeDeleted | `db.edge.deleted` | part, trans, edge | An edge was deleted.
|
|
graph.EventNodeStore | `db.node.store` | part, trans, node | A node is about to be stored (always overwriting existing values).
|
|
graph.EventNodeStore | `db.node.store` | part, trans, node | A node is about to be stored (always overwriting existing values).
|
|
-graph.EventNodeUpdate | `db.node.update` | part, trans, node | A node is about to be updated. Only thrown when graph.UpdateNode is called directly.
|
|
+graph.EventNodeUpdate | `db.node.update` | part, trans, node | A node is about to be updated.
|
|
graph.EventNodeDelete | `db.node.delete` | part, trans, key, kind | A node is about to be deleted.
|
|
graph.EventNodeDelete | `db.node.delete` | part, trans, key, kind | A node is about to be deleted.
|
|
graph.EventEdgeStore | `db.edge.store` | part, trans, edge | An edge is about to be stored.
|
|
graph.EventEdgeStore | `db.edge.store` | part, trans, edge | An edge is about to be stored.
|
|
graph.EventEdgeDelete | `db.edge.delete` | part, trans, key, kind | An edge is about to be deleted.
|
|
graph.EventEdgeDelete | `db.edge.delete` | part, trans, key, kind | An edge is about to be deleted.
|
|
|
|
|
|
-TODO: Explaination
|
|
+Note: EliasDB will wait for the event cascade to be finished before performing the actual operation (e.g. inserting a node). If the event handling requires a time consuming operation then a new parallel event cascade can be started using `addEvent` with a scope:
|
|
-Add special function to signal that an event has been handled
|
|
|
|
-
|
|
|
|
-Note: EliasDB will wait for the event cascade to be finished before performing the actual operation (e.g. inserting a node). If the event handling requires a time consuming operation then a new event cascade should be started using `addEvent` with a scope:
|
|
|
|
```
|
|
```
|
|
addEvent("request", "foo.bar.xxx", {
|
|
addEvent("request", "foo.bar.xxx", {
|
|
"payload" : 123
|
|
"payload" : 123
|
|
@@ -55,6 +81,24 @@ db.storeNode("main", {
|
|
})
|
|
})
|
|
```
|
|
```
|
|
|
|
|
|
|
|
+#### `db.updateNode(partition, nodeMap, [transaction])`
|
|
|
|
+Updates a node in EliasDB (only update the given values of the node).
|
|
|
|
+
|
|
|
|
+Parameter | Description
|
|
|
|
+-|-
|
|
|
|
+partition | Partition of the node
|
|
|
|
+nodeMap | Node object as a map with at least a key and a kind attribute
|
|
|
|
+transaction | Optional a transaction to group a set of changes
|
|
|
|
+
|
|
|
|
+Example:
|
|
|
|
+```
|
|
|
|
+db.updateNode("main", {
|
|
|
|
+ "key" : "foo",
|
|
|
|
+ "kind" : "bar",
|
|
|
|
+ "data" : 123,
|
|
|
|
+})
|
|
|
|
+```
|
|
|
|
+
|
|
#### `db.removeNode(partition, nodeKey, nodeKind, [transaction])`
|
|
#### `db.removeNode(partition, nodeKey, nodeKind, [transaction])`
|
|
Removes a node in EliasDB.
|
|
Removes a node in EliasDB.
|
|
|
|
|
|
@@ -227,3 +271,23 @@ sink mysink
|
|
db.raiseGraphEventHandled()
|
|
db.raiseGraphEventHandled()
|
|
}
|
|
}
|
|
```
|
|
```
|
|
|
|
+
|
|
|
|
+#### `db.raiseWebEventHandled()`
|
|
|
|
+"When handling a web event, notify the web API of EliasDB that the web request was handled.
|
|
|
|
+
|
|
|
|
+Example:
|
|
|
|
+```
|
|
|
|
+sink mysink
|
|
|
|
+ kindmatch [ "web.*.*" ],
|
|
|
|
+{
|
|
|
|
+ db.raiseWebEventHandled({
|
|
|
|
+ "status" : 200,
|
|
|
|
+ "headers" : {
|
|
|
|
+ "Date": "today"
|
|
|
|
+ },
|
|
|
|
+ "body" : {
|
|
|
|
+ "mydata" : [1,2,3]
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+```
|