@constela/core 0.12.1 → 0.12.2
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.d.ts +39 -2
- package/dist/index.js +49 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -395,7 +395,16 @@ interface FocusStep {
|
|
|
395
395
|
onSuccess?: ActionStep[];
|
|
396
396
|
onError?: ActionStep[];
|
|
397
397
|
}
|
|
398
|
-
|
|
398
|
+
/**
|
|
399
|
+
* If step - conditional action execution
|
|
400
|
+
*/
|
|
401
|
+
interface IfStep {
|
|
402
|
+
do: 'if';
|
|
403
|
+
condition: Expression;
|
|
404
|
+
then: ActionStep[];
|
|
405
|
+
else?: ActionStep[];
|
|
406
|
+
}
|
|
407
|
+
type ActionStep = SetStep | UpdateStep | SetPathStep | FetchStep | StorageStep | ClipboardStep | NavigateStep | ImportStep | CallStep | SubscribeStep | DisposeStep | DomStep | SendStep | CloseStep | DelayStep | IntervalStep | ClearTimerStep | FocusStep | IfStep;
|
|
399
408
|
type LocalActionStep = SetStep | UpdateStep | SetPathStep;
|
|
400
409
|
/**
|
|
401
410
|
* Event handler options for special events like intersect
|
|
@@ -1567,6 +1576,8 @@ declare const astSchema: {
|
|
|
1567
1576
|
readonly $ref: "#/$defs/ClearTimerStep";
|
|
1568
1577
|
}, {
|
|
1569
1578
|
readonly $ref: "#/$defs/FocusStep";
|
|
1579
|
+
}, {
|
|
1580
|
+
readonly $ref: "#/$defs/IfStep";
|
|
1570
1581
|
}];
|
|
1571
1582
|
};
|
|
1572
1583
|
readonly SetStep: {
|
|
@@ -1736,6 +1747,32 @@ declare const astSchema: {
|
|
|
1736
1747
|
};
|
|
1737
1748
|
};
|
|
1738
1749
|
};
|
|
1750
|
+
readonly IfStep: {
|
|
1751
|
+
readonly type: "object";
|
|
1752
|
+
readonly required: readonly ["do", "condition", "then"];
|
|
1753
|
+
readonly additionalProperties: false;
|
|
1754
|
+
readonly properties: {
|
|
1755
|
+
readonly do: {
|
|
1756
|
+
readonly type: "string";
|
|
1757
|
+
readonly const: "if";
|
|
1758
|
+
};
|
|
1759
|
+
readonly condition: {
|
|
1760
|
+
readonly $ref: "#/$defs/Expression";
|
|
1761
|
+
};
|
|
1762
|
+
readonly then: {
|
|
1763
|
+
readonly type: "array";
|
|
1764
|
+
readonly items: {
|
|
1765
|
+
readonly $ref: "#/$defs/ActionStep";
|
|
1766
|
+
};
|
|
1767
|
+
};
|
|
1768
|
+
readonly else: {
|
|
1769
|
+
readonly type: "array";
|
|
1770
|
+
readonly items: {
|
|
1771
|
+
readonly $ref: "#/$defs/ActionStep";
|
|
1772
|
+
};
|
|
1773
|
+
};
|
|
1774
|
+
};
|
|
1775
|
+
};
|
|
1739
1776
|
readonly EventHandler: {
|
|
1740
1777
|
readonly type: "object";
|
|
1741
1778
|
readonly required: readonly ["event", "action"];
|
|
@@ -2024,4 +2061,4 @@ declare const astSchema: {
|
|
|
2024
2061
|
};
|
|
2025
2062
|
};
|
|
2026
2063
|
|
|
2027
|
-
export { type ActionDefinition, type ActionStep, BINARY_OPERATORS, type BinExpr, type BinaryOperator, type BooleanField, CLIPBOARD_OPERATIONS, type CallStep, type ClearTimerStep, type ClipboardOperation, type ClipboardStep, type CloseStep, type CodeNode, type ComponentDef, type ComponentNode, type ComponentsRef, type CompoundVariant, type ConcatExpr, type CondExpr, type ConstelaAst, ConstelaError, type ConstelaProgram, type CookieInitialExpr, DATA_SOURCE_TYPES, DATA_TRANSFORMS, type DataExpr, type DataSource, type DataSourceType, type DataTransform, type DelayStep, type DisposeStep, type DomStep, type EachNode, type ElementNode, type ErrorCode, type ErrorOptions, type EventHandler, type EventHandlerOptions, type Expression, FOCUS_OPERATIONS, type FetchStep, type FocusOperation, type FocusStep, type GetExpr, HTTP_METHODS, type HttpMethod, type IfNode, type ImportExpr, type ImportStep, type IntervalStep, type LayoutProgram, type LifecycleHooks, type ListField, type LitExpr, type LocalActionDefinition, type LocalActionStep, type MarkdownNode, NAVIGATE_TARGETS, type NavigateStep, type NavigateTarget, type NotExpr, type NumberField, type ObjectField, PARAM_TYPES, type ParamDef, type ParamExpr, type ParamType, type PortalNode, type Program, type RefExpr, type RouteDefinition, type RouteExpr, STORAGE_OPERATIONS, STORAGE_TYPES, type SendStep, type SetPathStep, type SetStep, type SlotNode, type StateExpr, type StateField, type StaticPathsDefinition, type StorageOperation, type StorageStep, type StorageType, type StringField, type StyleExpr, type StylePreset, type SubscribeStep, type TextNode, UPDATE_OPERATIONS, type UpdateOperation, type UpdateStep, VALIDITY_PROPERTIES, type ValidationFailure, type ValidationResult, type ValidationSuccess, type ValidityExpr, type ValidityProperty, type VarExpr, type ViewNode, astSchema, createClipboardWriteMissingValueError, createComponentCycleError, createComponentNotFoundError, createComponentPropMissingError, createComponentPropTypeError, createCondElseRequiredError, createDataNotDefinedError, createDuplicateActionError, createDuplicateDefaultSlotError, createDuplicateSlotNameError, createImportsNotDefinedError, createInvalidClipboardOperationError, createInvalidDataSourceError, createInvalidNavigateTargetError, createInvalidSlotNameError, createInvalidStorageOperationError, createInvalidStorageTypeError, createLayoutMissingSlotError, createLayoutNotFoundError, createLocalActionInvalidStepError, createOperationInvalidForTypeError, createOperationMissingFieldError, createOperationUnknownError, createRouteNotDefinedError, createSchemaError, createSlotInLoopError, createStorageSetMissingValueError, createUndefinedActionError, createUndefinedDataError, createUndefinedDataSourceError, createUndefinedImportError, createUndefinedLocalStateError, createUndefinedParamError, createUndefinedRefError, createUndefinedRouteParamError, createUndefinedStateError, createUndefinedStyleError, createUndefinedVarError, createUndefinedVariantError, createUnsupportedVersionError, findSimilarNames, isActionStep, isBinExpr, isBooleanField, isCallStep, isClipboardStep, isCodeNode, isComponentNode, isConcatExpr, isCondExpr, isConstelaError, isCookieInitialExpr, isDataExpr, isDataSource, isDisposeStep, isEachNode, isElementNode, isEventHandler, isExpression, isFetchStep, isFocusStep, isGetExpr, isIfNode, isImportExpr, isImportStep, isLayoutProgram, isLifecycleHooks, isListField, isLitExpr, isLocalActionDefinition, isLocalActionStep, isMarkdownNode, isNamedSlotNode, isNavigateStep, isNotExpr, isNumberField, isObjectField, isParamExpr, isPortalNode, isRefExpr, isRouteDefinition, isRouteExpr, isSetPathStep, isSetStep, isSlotNode, isStateExpr, isStateField, isStaticPathsDefinition, isStorageStep, isStringField, isStyleExpr, isSubscribeStep, isTextNode, isUpdateStep, isValidityExpr, isVarExpr, isViewNode, validateAst };
|
|
2064
|
+
export { type ActionDefinition, type ActionStep, BINARY_OPERATORS, type BinExpr, type BinaryOperator, type BooleanField, CLIPBOARD_OPERATIONS, type CallStep, type ClearTimerStep, type ClipboardOperation, type ClipboardStep, type CloseStep, type CodeNode, type ComponentDef, type ComponentNode, type ComponentsRef, type CompoundVariant, type ConcatExpr, type CondExpr, type ConstelaAst, ConstelaError, type ConstelaProgram, type CookieInitialExpr, DATA_SOURCE_TYPES, DATA_TRANSFORMS, type DataExpr, type DataSource, type DataSourceType, type DataTransform, type DelayStep, type DisposeStep, type DomStep, type EachNode, type ElementNode, type ErrorCode, type ErrorOptions, type EventHandler, type EventHandlerOptions, type Expression, FOCUS_OPERATIONS, type FetchStep, type FocusOperation, type FocusStep, type GetExpr, HTTP_METHODS, type HttpMethod, type IfNode, type IfStep, type ImportExpr, type ImportStep, type IntervalStep, type LayoutProgram, type LifecycleHooks, type ListField, type LitExpr, type LocalActionDefinition, type LocalActionStep, type MarkdownNode, NAVIGATE_TARGETS, type NavigateStep, type NavigateTarget, type NotExpr, type NumberField, type ObjectField, PARAM_TYPES, type ParamDef, type ParamExpr, type ParamType, type PortalNode, type Program, type RefExpr, type RouteDefinition, type RouteExpr, STORAGE_OPERATIONS, STORAGE_TYPES, type SendStep, type SetPathStep, type SetStep, type SlotNode, type StateExpr, type StateField, type StaticPathsDefinition, type StorageOperation, type StorageStep, type StorageType, type StringField, type StyleExpr, type StylePreset, type SubscribeStep, type TextNode, UPDATE_OPERATIONS, type UpdateOperation, type UpdateStep, VALIDITY_PROPERTIES, type ValidationFailure, type ValidationResult, type ValidationSuccess, type ValidityExpr, type ValidityProperty, type VarExpr, type ViewNode, astSchema, createClipboardWriteMissingValueError, createComponentCycleError, createComponentNotFoundError, createComponentPropMissingError, createComponentPropTypeError, createCondElseRequiredError, createDataNotDefinedError, createDuplicateActionError, createDuplicateDefaultSlotError, createDuplicateSlotNameError, createImportsNotDefinedError, createInvalidClipboardOperationError, createInvalidDataSourceError, createInvalidNavigateTargetError, createInvalidSlotNameError, createInvalidStorageOperationError, createInvalidStorageTypeError, createLayoutMissingSlotError, createLayoutNotFoundError, createLocalActionInvalidStepError, createOperationInvalidForTypeError, createOperationMissingFieldError, createOperationUnknownError, createRouteNotDefinedError, createSchemaError, createSlotInLoopError, createStorageSetMissingValueError, createUndefinedActionError, createUndefinedDataError, createUndefinedDataSourceError, createUndefinedImportError, createUndefinedLocalStateError, createUndefinedParamError, createUndefinedRefError, createUndefinedRouteParamError, createUndefinedStateError, createUndefinedStyleError, createUndefinedVarError, createUndefinedVariantError, createUnsupportedVersionError, findSimilarNames, isActionStep, isBinExpr, isBooleanField, isCallStep, isClipboardStep, isCodeNode, isComponentNode, isConcatExpr, isCondExpr, isConstelaError, isCookieInitialExpr, isDataExpr, isDataSource, isDisposeStep, isEachNode, isElementNode, isEventHandler, isExpression, isFetchStep, isFocusStep, isGetExpr, isIfNode, isImportExpr, isImportStep, isLayoutProgram, isLifecycleHooks, isListField, isLitExpr, isLocalActionDefinition, isLocalActionStep, isMarkdownNode, isNamedSlotNode, isNavigateStep, isNotExpr, isNumberField, isObjectField, isParamExpr, isPortalNode, isRefExpr, isRouteDefinition, isRouteExpr, isSetPathStep, isSetStep, isSlotNode, isStateExpr, isStateField, isStaticPathsDefinition, isStorageStep, isStringField, isStyleExpr, isSubscribeStep, isTextNode, isUpdateStep, isValidityExpr, isVarExpr, isViewNode, validateAst };
|
package/dist/index.js
CHANGED
|
@@ -842,7 +842,7 @@ function isObject2(value) {
|
|
|
842
842
|
var VALID_VIEW_KINDS = ["element", "text", "if", "each", "component", "slot", "markdown", "code", "portal"];
|
|
843
843
|
var VALID_EXPR_TYPES = ["lit", "state", "var", "bin", "not", "param", "cond", "get", "style", "validity", "index"];
|
|
844
844
|
var VALID_PARAM_TYPES = ["string", "number", "boolean", "json"];
|
|
845
|
-
var VALID_ACTION_TYPES = ["set", "update", "fetch", "delay", "interval", "clearTimer", "focus"];
|
|
845
|
+
var VALID_ACTION_TYPES = ["set", "update", "fetch", "delay", "interval", "clearTimer", "focus", "if"];
|
|
846
846
|
var VALID_STATE_TYPES = ["number", "string", "list", "boolean", "object"];
|
|
847
847
|
var VALID_BIN_OPS = BINARY_OPERATORS;
|
|
848
848
|
var VALID_UPDATE_OPS = UPDATE_OPERATIONS;
|
|
@@ -1097,7 +1097,7 @@ function validateActionStep(step, path) {
|
|
|
1097
1097
|
return { path: path + "/do", message: "do is required" };
|
|
1098
1098
|
}
|
|
1099
1099
|
if (!VALID_ACTION_TYPES.includes(doType)) {
|
|
1100
|
-
return { path: path + "/do", message: "must be one of: set, update, fetch, delay, interval, clearTimer, focus" };
|
|
1100
|
+
return { path: path + "/do", message: "must be one of: set, update, fetch, delay, interval, clearTimer, focus, if" };
|
|
1101
1101
|
}
|
|
1102
1102
|
switch (doType) {
|
|
1103
1103
|
case "set":
|
|
@@ -1184,6 +1184,34 @@ function validateActionStep(step, path) {
|
|
|
1184
1184
|
return { path: path + "/operation", message: "operation is required" };
|
|
1185
1185
|
}
|
|
1186
1186
|
return validateExpression(step["target"], path + "/target");
|
|
1187
|
+
case "if":
|
|
1188
|
+
if (!("condition" in step)) {
|
|
1189
|
+
return { path: path + "/condition", message: "condition is required" };
|
|
1190
|
+
}
|
|
1191
|
+
if (!("then" in step)) {
|
|
1192
|
+
return { path: path + "/then", message: "then is required" };
|
|
1193
|
+
}
|
|
1194
|
+
{
|
|
1195
|
+
const condError = validateExpression(step["condition"], path + "/condition");
|
|
1196
|
+
if (condError) return condError;
|
|
1197
|
+
if (!Array.isArray(step["then"])) {
|
|
1198
|
+
return { path: path + "/then", message: "then must be an array" };
|
|
1199
|
+
}
|
|
1200
|
+
for (let i = 0; i < step["then"].length; i++) {
|
|
1201
|
+
const thenError = validateActionStep(step["then"][i], path + "/then/" + i);
|
|
1202
|
+
if (thenError) return thenError;
|
|
1203
|
+
}
|
|
1204
|
+
if ("else" in step) {
|
|
1205
|
+
if (!Array.isArray(step["else"])) {
|
|
1206
|
+
return { path: path + "/else", message: "else must be an array" };
|
|
1207
|
+
}
|
|
1208
|
+
for (let i = 0; i < step["else"].length; i++) {
|
|
1209
|
+
const elseError = validateActionStep(step["else"][i], path + "/else/" + i);
|
|
1210
|
+
if (elseError) return elseError;
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
break;
|
|
1187
1215
|
}
|
|
1188
1216
|
return null;
|
|
1189
1217
|
}
|
|
@@ -1838,7 +1866,8 @@ var astSchema = {
|
|
|
1838
1866
|
{ $ref: "#/$defs/DelayStep" },
|
|
1839
1867
|
{ $ref: "#/$defs/IntervalStep" },
|
|
1840
1868
|
{ $ref: "#/$defs/ClearTimerStep" },
|
|
1841
|
-
{ $ref: "#/$defs/FocusStep" }
|
|
1869
|
+
{ $ref: "#/$defs/FocusStep" },
|
|
1870
|
+
{ $ref: "#/$defs/IfStep" }
|
|
1842
1871
|
]
|
|
1843
1872
|
},
|
|
1844
1873
|
SetStep: {
|
|
@@ -1945,6 +1974,23 @@ var astSchema = {
|
|
|
1945
1974
|
}
|
|
1946
1975
|
}
|
|
1947
1976
|
},
|
|
1977
|
+
IfStep: {
|
|
1978
|
+
type: "object",
|
|
1979
|
+
required: ["do", "condition", "then"],
|
|
1980
|
+
additionalProperties: false,
|
|
1981
|
+
properties: {
|
|
1982
|
+
do: { type: "string", const: "if" },
|
|
1983
|
+
condition: { $ref: "#/$defs/Expression" },
|
|
1984
|
+
then: {
|
|
1985
|
+
type: "array",
|
|
1986
|
+
items: { $ref: "#/$defs/ActionStep" }
|
|
1987
|
+
},
|
|
1988
|
+
else: {
|
|
1989
|
+
type: "array",
|
|
1990
|
+
items: { $ref: "#/$defs/ActionStep" }
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
},
|
|
1948
1994
|
// ==================== Event Handler ====================
|
|
1949
1995
|
EventHandler: {
|
|
1950
1996
|
type: "object",
|