@constela/core 0.13.0 → 0.15.0

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 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
- 15 expression types for constrained computation:
63
+ 17 expression types for constrained computation:
64
64
 
65
65
  | Type | JSON Example | Description |
66
66
  |------|-------------|-------------|
@@ -79,6 +79,8 @@ 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 |
82
84
 
83
85
  **Binary Operators:** `+`, `-`, `*`, `/`, `==`, `!=`, `<`, `<=`, `>`, `>=`, `&&`, `||`
84
86
 
package/dist/index.d.ts CHANGED
@@ -154,7 +154,32 @@ interface ValidityExpr {
154
154
  ref: string;
155
155
  property?: ValidityProperty;
156
156
  }
157
- type Expression = LitExpr | StateExpr | VarExpr | BinExpr | NotExpr | ParamExpr | CondExpr | GetExpr | RouteExpr | ImportExpr | DataExpr | RefExpr | IndexExpr | StyleExpr | ConcatExpr | ValidityExpr;
157
+ /**
158
+ * Call expression - calls a method on a target
159
+ */
160
+ interface CallExpr {
161
+ expr: 'call';
162
+ target: Expression;
163
+ method: string;
164
+ args?: Expression[];
165
+ }
166
+ /**
167
+ * Lambda expression - anonymous function for array methods
168
+ */
169
+ interface LambdaExpr {
170
+ expr: 'lambda';
171
+ param: string;
172
+ index?: string;
173
+ body: Expression;
174
+ }
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;
158
183
  /**
159
184
  * Cookie expression for state initial value
160
185
  */
@@ -729,6 +754,10 @@ declare function isStyleExpr(value: unknown): value is StyleExpr;
729
754
  * Checks if value is a concat expression
730
755
  */
731
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;
732
761
  /**
733
762
  * Checks if value is a validity expression
734
763
  */
@@ -2074,4 +2103,4 @@ declare const astSchema: {
2074
2103
  };
2075
2104
  };
2076
2105
 
2077
- 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 };
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,7 +843,7 @@ 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"];
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
848
  var VALID_ACTION_TYPES = ["set", "update", "fetch", "delay", "interval", "clearTimer", "focus", "if"];
846
849
  var VALID_STATE_TYPES = ["number", "string", "list", "boolean", "object"];
@@ -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: "must be one of: lit, state, var, bin, not, param, cond, get, style, validity, index" };
984
+ return { path: path + "/expr", message: "must be one of: lit, state, var, bin, not, param, cond, get, style, validity, index, call, lambda" };
982
985
  }
983
986
  switch (exprType) {
984
987
  case "lit":
@@ -1085,6 +1088,54 @@ function validateExpression(expr, path) {
1085
1088
  if (keyError) return keyError;
1086
1089
  }
1087
1090
  break;
1091
+ case "call":
1092
+ if (!("target" in expr)) {
1093
+ return { path: path + "/target", message: "target is required" };
1094
+ }
1095
+ if (typeof expr["method"] !== "string") {
1096
+ return { path: path + "/method", message: "method is required" };
1097
+ }
1098
+ {
1099
+ const targetError = validateExpression(expr["target"], path + "/target");
1100
+ if (targetError) return targetError;
1101
+ if ("args" in expr && expr["args"] !== void 0) {
1102
+ if (!Array.isArray(expr["args"])) {
1103
+ return { path: path + "/args", message: "args must be an array" };
1104
+ }
1105
+ for (let i = 0; i < expr["args"].length; i++) {
1106
+ const argError = validateExpression(expr["args"][i], path + "/args/" + i);
1107
+ if (argError) return argError;
1108
+ }
1109
+ }
1110
+ }
1111
+ break;
1112
+ case "lambda":
1113
+ if (typeof expr["param"] !== "string") {
1114
+ return { path: path + "/param", message: "param is required" };
1115
+ }
1116
+ if ("index" in expr && typeof expr["index"] !== "string") {
1117
+ return { path: path + "/index", message: "index must be a string" };
1118
+ }
1119
+ if (!("body" in expr)) {
1120
+ return { path: path + "/body", message: "body is required" };
1121
+ }
1122
+ {
1123
+ const bodyError = validateExpression(expr["body"], path + "/body");
1124
+ if (bodyError) return bodyError;
1125
+ }
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;
1088
1139
  }
1089
1140
  return null;
1090
1141
  }
@@ -2237,6 +2288,7 @@ export {
2237
2288
  createUnsupportedVersionError,
2238
2289
  findSimilarNames,
2239
2290
  isActionStep,
2291
+ isArrayExpr,
2240
2292
  isBinExpr,
2241
2293
  isBooleanField,
2242
2294
  isCallStep,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/core",
3
- "version": "0.13.0",
3
+ "version": "0.15.0",
4
4
  "description": "Core types, schema, and validator for Constela UI framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",