Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
feat: non dynamic values
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphg6 committed Dec 19, 2023
1 parent 79879b4 commit 1c5a6d6
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

rule RequiredParams salience 10000000 {
when
true
then

ctx.SetRequiredConfigured();
Changed("ctx");
Retract("RequiredParams");
}

rule HasRequiredParamsError salience 9999999 {
when
ctx.Has("requiredParamErrors")
then
Complete();
}

rule feat_test salience 1000 {
when
true
then
ctx.Put("test", processor.ToMap("{\"percent\":\"%percent\"}"));
result.Put("test", ctx.GetMap("test"));
Changed("result");
Retract("feat_test");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
10 changes: 10 additions & 0 deletions __tests__/transpiler/cases/0053 - slice_add_itens copy/rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"test": {
"condition": "true",
"value": {
"percent": "%percent"
},
"dynamic": false,
"type": "object"
}
}
10 changes: 9 additions & 1 deletion lib/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function buildRules(rulesPlain, features, parameters, saliences) {
const condition = `${typeof expression.condition == "undefined"
? "true"
: expression.condition}`;
const dynamic = typeof expression.dynamic === 'undefined' || String(expression.dynamic).toLowerCase() === "true";
let result = true;
const feature = features.find((f) => f.name == feat) || {
type: "boolean",
Expand All @@ -160,6 +161,7 @@ function buildRules(rulesPlain, features, parameters, saliences) {
name: feat,
outputType,
condition,
dynamic,
precedence: `${saliences[feat] || base_salience}`,
expression,
result,
Expand Down Expand Up @@ -312,7 +314,13 @@ function calcPrecedences(rulesPlain) {
let rule = rulesPlain[feat];
if (typeof rule === "object") {
const condition = rule.condition;
rule = JSON.stringify(rule.value);
const dynamic = typeof rule.dynamic === 'undefined' || String(rule.dynamic).toLowerCase() === "true";

if (dynamic) {
rule = JSON.stringify(rule.value);
} else {
rule = "";
}

if (typeof condition != "undefined") {
rule += ` ${condition}`;
Expand Down
13 changes: 9 additions & 4 deletions lib/transpiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,15 @@ const transpile = (expression, options) => {
expression = JSON.stringify(expression);
}

expression = expression.replace(
/([$#%@])(\w+)((\.?\w+)*)(::(\w+))?/g,
transpileReplacer(options)
);
const dynamic = typeof options.dynamic === 'undefined' || String(options.dynamic).toLowerCase() === "true";

if (dynamic) {
expression = expression.replace(
/([$#%@])(\w+)((\.?\w+)*)(::(\w+))?/g,
transpileReplacer(options)
);
}

expression = transpileValue(options.outputType, expression);

return expression;
Expand Down Expand Up @@ -232,6 +236,7 @@ const transpiler = async (dir) => {
outputType: fr.outputType,
parameters: data.parameters,
features: data.features,
dynamic: fr.dynamic
}),
}));

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "featws-cli",
"version": "0.0.3-rc1",
"version": "0.0.4-rc1",
"description": "A FeatWS CLI to GRL",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 1c5a6d6

Please sign in to comment.