@constela/core 0.14.0 → 0.15.1
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/README.md +23 -1
- package/dist/index.d.ts +13 -2
- package/dist/index.js +39 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ String state can use a cookie expression to read initial value from cookies (SSR
|
|
|
60
60
|
|
|
61
61
|
## Expression Types
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
18 expression types for constrained computation:
|
|
64
64
|
|
|
65
65
|
| Type | JSON Example | Description |
|
|
66
66
|
|------|-------------|-------------|
|
|
@@ -79,6 +79,9 @@ String state can use a cookie expression to read initial value from cookies (SSR
|
|
|
79
79
|
| `style` | `{ "expr": "style", "name": "button", "variants": {...} }` | Style reference |
|
|
80
80
|
| `concat` | `{ "expr": "concat", "items": [...] }` | String concatenation |
|
|
81
81
|
| `cookie` | `{ "expr": "cookie", "key": "theme", "default": "dark" }` | Cookie value (SSR-safe) |
|
|
82
|
+
| `call` | `{ "expr": "call", "target": ..., "method": "filter", "args": [...] }` | Method call |
|
|
83
|
+
| `lambda` | `{ "expr": "lambda", "param": "item", "body": ... }` | Anonymous function |
|
|
84
|
+
| `array` | `{ "expr": "array", "elements": [...] }` | Array construction |
|
|
82
85
|
|
|
83
86
|
**Binary Operators:** `+`, `-`, `*`, `/`, `==`, `!=`, `<`, `<=`, `>`, `>=`, `&&`, `||`
|
|
84
87
|
|
|
@@ -101,6 +104,25 @@ Concatenate multiple expressions into a single string:
|
|
|
101
104
|
- `null`/`undefined` values become empty strings
|
|
102
105
|
- Numbers and booleans are converted to strings
|
|
103
106
|
|
|
107
|
+
**Array Expression:**
|
|
108
|
+
|
|
109
|
+
Construct arrays dynamically from expressions:
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
{
|
|
113
|
+
"expr": "array",
|
|
114
|
+
"elements": [
|
|
115
|
+
{ "expr": "var", "name": "basicSetup" },
|
|
116
|
+
{ "expr": "call", "target": { "expr": "var", "name": "json" }, "method": "apply", "args": [] },
|
|
117
|
+
{ "expr": "state", "name": "config" }
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
- Each element can be any expression type
|
|
123
|
+
- Elements are evaluated and collected into an array
|
|
124
|
+
- Useful for dynamic configurations (e.g., CodeMirror extensions: `[basicSetup, json()]`)
|
|
125
|
+
|
|
104
126
|
## View Node Types
|
|
105
127
|
|
|
106
128
|
8 node types for building UI:
|
package/dist/index.d.ts
CHANGED
|
@@ -172,7 +172,14 @@ interface LambdaExpr {
|
|
|
172
172
|
index?: string;
|
|
173
173
|
body: Expression;
|
|
174
174
|
}
|
|
175
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Array expression - constructs an array from expressions
|
|
177
|
+
*/
|
|
178
|
+
interface ArrayExpr {
|
|
179
|
+
expr: 'array';
|
|
180
|
+
elements: Expression[];
|
|
181
|
+
}
|
|
182
|
+
type Expression = LitExpr | StateExpr | VarExpr | BinExpr | NotExpr | ParamExpr | CondExpr | GetExpr | RouteExpr | ImportExpr | DataExpr | RefExpr | IndexExpr | StyleExpr | ConcatExpr | ValidityExpr | CallExpr | LambdaExpr | ArrayExpr;
|
|
176
183
|
/**
|
|
177
184
|
* Cookie expression for state initial value
|
|
178
185
|
*/
|
|
@@ -747,6 +754,10 @@ declare function isStyleExpr(value: unknown): value is StyleExpr;
|
|
|
747
754
|
* Checks if value is a concat expression
|
|
748
755
|
*/
|
|
749
756
|
declare function isConcatExpr(value: unknown): value is ConcatExpr;
|
|
757
|
+
/**
|
|
758
|
+
* Checks if value is an array expression
|
|
759
|
+
*/
|
|
760
|
+
declare function isArrayExpr(value: unknown): value is ArrayExpr;
|
|
750
761
|
/**
|
|
751
762
|
* Checks if value is a validity expression
|
|
752
763
|
*/
|
|
@@ -2092,4 +2103,4 @@ declare const astSchema: {
|
|
|
2092
2103
|
};
|
|
2093
2104
|
};
|
|
2094
2105
|
|
|
2095
|
-
export { type ActionDefinition, type ActionStep, BINARY_OPERATORS, type BinExpr, type BinaryOperator, type BooleanField, CLIPBOARD_OPERATIONS, type CallExpr, 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 IndexExpr, type IntervalStep, type LambdaExpr, 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 };
|
|
2106
|
+
export { type ActionDefinition, type ActionStep, type ArrayExpr, BINARY_OPERATORS, type BinExpr, type BinaryOperator, type BooleanField, CLIPBOARD_OPERATIONS, type CallExpr, 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 IndexExpr, type IntervalStep, type LambdaExpr, 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, isArrayExpr, 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
|
@@ -155,6 +155,9 @@ function isStyleExpr(value) {
|
|
|
155
155
|
function isConcatExpr(value) {
|
|
156
156
|
return typeof value === "object" && value !== null && value.expr === "concat" && Array.isArray(value.items);
|
|
157
157
|
}
|
|
158
|
+
function isArrayExpr(value) {
|
|
159
|
+
return typeof value === "object" && value !== null && value.expr === "array" && Array.isArray(value.elements);
|
|
160
|
+
}
|
|
158
161
|
function isValidityExpr(value) {
|
|
159
162
|
if (!isObject(value)) return false;
|
|
160
163
|
if (value["expr"] !== "validity") return false;
|
|
@@ -202,7 +205,7 @@ function isRouteDefinition(value) {
|
|
|
202
205
|
return true;
|
|
203
206
|
}
|
|
204
207
|
function isExpression(value) {
|
|
205
|
-
return isLitExpr(value) || isStateExpr(value) || isVarExpr(value) || isBinExpr(value) || isNotExpr(value) || isParamExpr(value) || isCondExpr(value) || isGetExpr(value) || isRouteExpr(value) || isImportExpr(value) || isDataExpr(value) || isRefExpr(value) || isIndexExpr(value) || isStyleExpr(value) || isConcatExpr(value) || isValidityExpr(value);
|
|
208
|
+
return isLitExpr(value) || isStateExpr(value) || isVarExpr(value) || isBinExpr(value) || isNotExpr(value) || isParamExpr(value) || isCondExpr(value) || isGetExpr(value) || isRouteExpr(value) || isImportExpr(value) || isDataExpr(value) || isRefExpr(value) || isIndexExpr(value) || isStyleExpr(value) || isConcatExpr(value) || isValidityExpr(value) || isArrayExpr(value);
|
|
206
209
|
}
|
|
207
210
|
function isElementNode(value) {
|
|
208
211
|
if (!isObject(value)) return false;
|
|
@@ -840,9 +843,9 @@ function isObject2(value) {
|
|
|
840
843
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
841
844
|
}
|
|
842
845
|
var VALID_VIEW_KINDS = ["element", "text", "if", "each", "component", "slot", "markdown", "code", "portal"];
|
|
843
|
-
var VALID_EXPR_TYPES = ["lit", "state", "var", "bin", "not", "param", "cond", "get", "style", "validity", "index", "call", "lambda"];
|
|
846
|
+
var VALID_EXPR_TYPES = ["lit", "state", "var", "bin", "not", "param", "cond", "get", "style", "validity", "index", "call", "lambda", "array"];
|
|
844
847
|
var VALID_PARAM_TYPES = ["string", "number", "boolean", "json"];
|
|
845
|
-
var VALID_ACTION_TYPES = ["set", "update", "fetch", "delay", "interval", "clearTimer", "focus", "if"];
|
|
848
|
+
var VALID_ACTION_TYPES = ["set", "update", "setPath", "fetch", "delay", "interval", "clearTimer", "focus", "if"];
|
|
846
849
|
var VALID_STATE_TYPES = ["number", "string", "list", "boolean", "object"];
|
|
847
850
|
var VALID_BIN_OPS = BINARY_OPERATORS;
|
|
848
851
|
var VALID_UPDATE_OPS = UPDATE_OPERATIONS;
|
|
@@ -978,7 +981,7 @@ function validateExpression(expr, path) {
|
|
|
978
981
|
return { path: path + "/expr", message: "expr is required" };
|
|
979
982
|
}
|
|
980
983
|
if (!VALID_EXPR_TYPES.includes(exprType)) {
|
|
981
|
-
return { path: path + "/expr", message:
|
|
984
|
+
return { path: path + "/expr", message: `must be one of: ${VALID_EXPR_TYPES.join(", ")}` };
|
|
982
985
|
}
|
|
983
986
|
switch (exprType) {
|
|
984
987
|
case "lit":
|
|
@@ -1121,6 +1124,18 @@ function validateExpression(expr, path) {
|
|
|
1121
1124
|
if (bodyError) return bodyError;
|
|
1122
1125
|
}
|
|
1123
1126
|
break;
|
|
1127
|
+
case "array":
|
|
1128
|
+
if (!("elements" in expr)) {
|
|
1129
|
+
return { path: path + "/elements", message: "elements is required" };
|
|
1130
|
+
}
|
|
1131
|
+
if (!Array.isArray(expr["elements"])) {
|
|
1132
|
+
return { path: path + "/elements", message: "elements must be an array" };
|
|
1133
|
+
}
|
|
1134
|
+
for (let i = 0; i < expr["elements"].length; i++) {
|
|
1135
|
+
const elemError = validateExpression(expr["elements"][i], path + "/elements/" + i);
|
|
1136
|
+
if (elemError) return elemError;
|
|
1137
|
+
}
|
|
1138
|
+
break;
|
|
1124
1139
|
}
|
|
1125
1140
|
return null;
|
|
1126
1141
|
}
|
|
@@ -1133,7 +1148,7 @@ function validateActionStep(step, path) {
|
|
|
1133
1148
|
return { path: path + "/do", message: "do is required" };
|
|
1134
1149
|
}
|
|
1135
1150
|
if (!VALID_ACTION_TYPES.includes(doType)) {
|
|
1136
|
-
return { path: path + "/do", message:
|
|
1151
|
+
return { path: path + "/do", message: `must be one of: ${VALID_ACTION_TYPES.join(", ")}` };
|
|
1137
1152
|
}
|
|
1138
1153
|
switch (doType) {
|
|
1139
1154
|
case "set":
|
|
@@ -1158,6 +1173,24 @@ function validateActionStep(step, path) {
|
|
|
1158
1173
|
return validateExpression(step["value"], path + "/value");
|
|
1159
1174
|
}
|
|
1160
1175
|
break;
|
|
1176
|
+
case "setPath":
|
|
1177
|
+
if (typeof step["target"] !== "string") {
|
|
1178
|
+
return { path: path + "/target", message: "target is required" };
|
|
1179
|
+
}
|
|
1180
|
+
if (!("path" in step)) {
|
|
1181
|
+
return { path: path + "/path", message: "path is required" };
|
|
1182
|
+
}
|
|
1183
|
+
{
|
|
1184
|
+
const pathError = validateExpression(step["path"], path + "/path");
|
|
1185
|
+
if (pathError) return pathError;
|
|
1186
|
+
}
|
|
1187
|
+
if (!("field" in step) || typeof step["field"] !== "string") {
|
|
1188
|
+
return { path: path + "/field", message: "field is required" };
|
|
1189
|
+
}
|
|
1190
|
+
if (!("value" in step)) {
|
|
1191
|
+
return { path: path + "/value", message: "value is required" };
|
|
1192
|
+
}
|
|
1193
|
+
return validateExpression(step["value"], path + "/value");
|
|
1161
1194
|
case "fetch":
|
|
1162
1195
|
if (!("url" in step)) {
|
|
1163
1196
|
return { path: path + "/url", message: "url is required" };
|
|
@@ -2273,6 +2306,7 @@ export {
|
|
|
2273
2306
|
createUnsupportedVersionError,
|
|
2274
2307
|
findSimilarNames,
|
|
2275
2308
|
isActionStep,
|
|
2309
|
+
isArrayExpr,
|
|
2276
2310
|
isBinExpr,
|
|
2277
2311
|
isBooleanField,
|
|
2278
2312
|
isCallStep,
|