@constela/core 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +29 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -328,7 +328,7 @@ function isObject2(value) {
|
|
|
328
328
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
329
329
|
}
|
|
330
330
|
var VALID_VIEW_KINDS = ["element", "text", "if", "each", "component", "slot"];
|
|
331
|
-
var VALID_EXPR_TYPES = ["lit", "state", "var", "bin", "not", "param"];
|
|
331
|
+
var VALID_EXPR_TYPES = ["lit", "state", "var", "bin", "not", "param", "cond", "get"];
|
|
332
332
|
var VALID_PARAM_TYPES = ["string", "number", "boolean", "json"];
|
|
333
333
|
var VALID_ACTION_TYPES = ["set", "update", "fetch"];
|
|
334
334
|
var VALID_STATE_TYPES = ["number", "string", "list", "boolean", "object"];
|
|
@@ -438,7 +438,7 @@ function validateExpression(expr, path) {
|
|
|
438
438
|
return { path: path + "/expr", message: "expr is required" };
|
|
439
439
|
}
|
|
440
440
|
if (!VALID_EXPR_TYPES.includes(exprType)) {
|
|
441
|
-
return { path: path + "/expr", message: "must be one of: lit, state, var, bin, not, param" };
|
|
441
|
+
return { path: path + "/expr", message: "must be one of: lit, state, var, bin, not, param, cond, get" };
|
|
442
442
|
}
|
|
443
443
|
switch (exprType) {
|
|
444
444
|
case "lit":
|
|
@@ -485,6 +485,33 @@ function validateExpression(expr, path) {
|
|
|
485
485
|
return { path: path + "/path", message: "path must be a string" };
|
|
486
486
|
}
|
|
487
487
|
break;
|
|
488
|
+
case "cond":
|
|
489
|
+
if (!("if" in expr)) {
|
|
490
|
+
return { path: path + "/if", message: "if is required" };
|
|
491
|
+
}
|
|
492
|
+
if (!("then" in expr)) {
|
|
493
|
+
return { path: path + "/then", message: "then is required" };
|
|
494
|
+
}
|
|
495
|
+
if (!("else" in expr)) {
|
|
496
|
+
return { path: path + "/else", message: "else is required" };
|
|
497
|
+
}
|
|
498
|
+
{
|
|
499
|
+
const ifError = validateExpression(expr["if"], path + "/if");
|
|
500
|
+
if (ifError) return ifError;
|
|
501
|
+
const thenError = validateExpression(expr["then"], path + "/then");
|
|
502
|
+
if (thenError) return thenError;
|
|
503
|
+
const elseError = validateExpression(expr["else"], path + "/else");
|
|
504
|
+
if (elseError) return elseError;
|
|
505
|
+
}
|
|
506
|
+
break;
|
|
507
|
+
case "get":
|
|
508
|
+
if (!("base" in expr)) {
|
|
509
|
+
return { path: path + "/base", message: "base is required" };
|
|
510
|
+
}
|
|
511
|
+
if (typeof expr["path"] !== "string") {
|
|
512
|
+
return { path: path + "/path", message: "path is required" };
|
|
513
|
+
}
|
|
514
|
+
return validateExpression(expr["base"], path + "/base");
|
|
488
515
|
}
|
|
489
516
|
return null;
|
|
490
517
|
}
|