jazzdotdev / flute

The Application Framework Built for Powerful, Secure features and add-ons
17 stars 4 forks source link

generalize rule calling, generate actions using parameters, and generate rules from events' actions' parameters #21

Open naturallymitchell opened 6 years ago

naturallymitchell commented 6 years ago

log.trace("[rule name] evaluated as TRUE")

and separate 'event' to trigger and 'parameter' with it

naturallymitchell commented 6 years ago

can we make the IF and the THEN segments separate?

naturallymitchell commented 6 years ago
priority: 2

if request.method == "GET"
  and #request.path_segments == 2
  and request.path_segments[1]:match("%a+") -- TODO: make it a known type, not just any word
  and request.path_segments[2]:match(utils.uuid_pattern)
  --and string.match( request.headers["accept"], "json" )
then
    events["request_document_json"]:trigger(request)
end
priority: 2
event: "request_document_json"
parameter: "request"

request.method == "GET"
and #request.path_segments == 2
and request.path_segments[1]:match("%a+") -- TODO: make it a known type, not just any word
and request.path_segments[2]:match(utils.uuid_pattern)
--and string.match( request.headers["accept"], "json" )

that's the THEN, what about the IF?

naturallymitchell commented 6 years ago

we need to separate the IF so that we can put a log.trace after it in the generated version which has rule_name evaluated as true or false

aleksanderwlodarczyk commented 6 years ago

Rules have their parameters, before it gets called we need to call get_action_parameters.

get_action_parameters checks input parameters of each action in each event that the rule could call and it is assigning them to the rule parameters(because the rule have to have them to pass them to the event when triggering)

aleksanderwlodarczyk commented 6 years ago

Rule interpreter should generate log.trace("[rule name] evaluated as TRUE") in THEN segment

naturallymitchell commented 6 years ago

read the actions associate with the events to trigger, and populate them in the trigger

aleksanderwlodarczyk commented 6 years ago

Call the rules with every possible parameter to get rid of arguments table in the rules loader

naturallymitchell commented 6 years ago

function to read each action's parameters for each event

when generating rules, we take events and get events_actions_parameters

when calling rules launcher, we take every events' events_actions_parameters and use that as the argument for calling rules

aleksanderwlodarczyk commented 6 years ago

Rule before:

weight: 10
parameters: ["request", "events"]
event: ["incoming_request_received"]

some condtional and other conditional

Rule after:

local log = require "log"
local weight = 10
local event = "incoming_request_received"
local function rule(rule_argument, p1, p2, p3, p4, ...)
    log.debug('[Rule] respond_to_any_request.lua with weight 10 starting to evaluate')

    if true then
        events[event]:trigger(p3, p4)
        log.trace("[respond_to_any_reqest] rule evaluated to true")
    end
    log.debug('[Rule] respond_to_any_request.lua evaluated succesfully')
end

return{
    rule = rule,
    weight = weight,
}

Action before:

event: ["incoming_request_received"]
weight: 1
input_parameters: ["p1", "p2"]

response = {
  headers = {
    ["content-type"] = "text/plain",
  },
  body = "hello" .. p1
}

return response

Action after:

local event = { "incoming_request_received" }
local weight = 1 
local log = require "log"
local input_parameters = { "p1" , "p2" }  

local function action(p1, p2)

    response = {
      headers = {
        ["content-type"] = "text/plain",
      },
      body = "hello" .. p1
    }

    return response

end

return{
    event = event,
    action = action,
    weight = weight,
    input_parameters = input_parameters
}
aleksanderwlodarczyk commented 6 years ago

We should make every possible action parameters table, in package_loader after we interpreted all of the actions and before we patch any of the rules.

The table of parameters for event/events that the specific rule can call will be created in the rule function before we trigger the event/events.

naturallymitchell commented 6 years ago

mitchell for each rules' events' actions' parameters make a table(edited) two tables: each and every rule_events_actions_parameters rules_events_actions_parameters

Aleksander Włodarczyk every_events_actions_parameters

naturallymitchell commented 6 years ago

last step of if, evaluated as TRUE else, evaluated as FALSE

naturallymitchell commented 6 years ago

https://github.com/foundpatterns/lighttouch-base/commit/4ad75561bcaa2e4cac85286a5df1199e0fbbe624 https://github.com/foundpatterns/lighttouch-base/pull/50