@constela/core 0.14.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
@@ -172,7 +172,14 @@ interface LambdaExpr {
172
172
  index?: string;
173
173
  body: Expression;
174
174
  }
175
- type Expression = LitExpr | StateExpr | VarExpr | BinExpr | NotExpr | ParamExpr | CondExpr | GetExpr | RouteExpr | ImportExpr | DataExpr | RefExpr | IndexExpr | StyleExpr | ConcatExpr | ValidityExpr | CallExpr | LambdaExpr;
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,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", "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
848
  var VALID_ACTION_TYPES = ["set", "update", "fetch", "delay", "interval", "clearTimer", "focus", "if"];
846
849
  var VALID_STATE_TYPES = ["number", "string", "list", "boolean", "object"];
@@ -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
  }
@@ -2273,6 +2288,7 @@ export {
2273
2288
  createUnsupportedVersionError,
2274
2289
  findSimilarNames,
2275
2290
  isActionStep,
2291
+ isArrayExpr,
2276
2292
  isBinExpr,
2277
2293
  isBooleanField,
2278
2294
  isCallStep,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/core",
3
- "version": "0.14.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",