@constela/core 0.9.1 → 0.10.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
@@ -42,7 +42,7 @@ All fields except `version`, `state`, `actions`, and `view` are optional.
42
42
 
43
43
  ## Expression Types
44
44
 
45
- 13 expression types for constrained computation:
45
+ 14 expression types for constrained computation:
46
46
 
47
47
  | Type | JSON Example | Description |
48
48
  |------|-------------|-------------|
@@ -59,9 +59,29 @@ All fields except `version`, `state`, `actions`, and `view` are optional.
59
59
  | `data` | `{ "expr": "data", "name": "posts" }` | Build-time data |
60
60
  | `ref` | `{ "expr": "ref", "name": "inputEl" }` | DOM element ref |
61
61
  | `style` | `{ "expr": "style", "name": "button", "variants": {...} }` | Style reference |
62
+ | `concat` | `{ "expr": "concat", "items": [...] }` | String concatenation |
62
63
 
63
64
  **Binary Operators:** `+`, `-`, `*`, `/`, `==`, `!=`, `<`, `<=`, `>`, `>=`, `&&`, `||`
64
65
 
66
+ **Concat Expression:**
67
+
68
+ Concatenate multiple expressions into a single string:
69
+
70
+ ```json
71
+ {
72
+ "expr": "concat",
73
+ "items": [
74
+ { "expr": "lit", "value": "Hello, " },
75
+ { "expr": "var", "name": "username" },
76
+ { "expr": "lit", "value": "!" }
77
+ ]
78
+ }
79
+ ```
80
+
81
+ - Evaluates each item and joins them as strings
82
+ - `null`/`undefined` values become empty strings
83
+ - Numbers and booleans are converted to strings
84
+
65
85
  ## View Node Types
66
86
 
67
87
  8 node types for building UI:
@@ -305,11 +325,11 @@ if (result.ok) {
305
325
 
306
326
  ### Type Guards
307
327
 
308
- 47 type guard functions for runtime type checking:
328
+ 48 type guard functions for runtime type checking:
309
329
 
310
330
  ```typescript
311
331
  import {
312
- isLitExpr, isStateExpr, isVarExpr, isBinExpr,
332
+ isLitExpr, isStateExpr, isVarExpr, isBinExpr, isConcatExpr,
313
333
  isElementNode, isTextNode, isIfNode, isEachNode,
314
334
  isSetStep, isUpdateStep, isFetchStep,
315
335
  isNumberField, isStringField, isListField,
package/dist/index.d.ts CHANGED
@@ -341,6 +341,7 @@ interface CloseStep {
341
341
  connection: string;
342
342
  }
343
343
  type ActionStep = SetStep | UpdateStep | SetPathStep | FetchStep | StorageStep | ClipboardStep | NavigateStep | ImportStep | CallStep | SubscribeStep | DisposeStep | DomStep | SendStep | CloseStep;
344
+ type LocalActionStep = SetStep | UpdateStep | SetPathStep;
344
345
  /**
345
346
  * Event handler - binds an event to an action
346
347
  */
@@ -356,6 +357,14 @@ interface ActionDefinition {
356
357
  name: string;
357
358
  steps: ActionStep[];
358
359
  }
360
+ /**
361
+ * Local action definition - a named sequence of local steps
362
+ * Only set, update, and setPath steps are allowed
363
+ */
364
+ interface LocalActionDefinition {
365
+ name: string;
366
+ steps: LocalActionStep[];
367
+ }
359
368
  /**
360
369
  * Element node - represents an HTML element
361
370
  */
@@ -428,6 +437,8 @@ interface CodeNode {
428
437
  type ViewNode = ElementNode | TextNode | IfNode | EachNode | ComponentNode | SlotNode | MarkdownNode | CodeNode;
429
438
  interface ComponentDef {
430
439
  params?: Record<string, ParamDef>;
440
+ localState?: Record<string, StateField>;
441
+ localActions?: LocalActionDefinition[];
431
442
  view: ViewNode;
432
443
  }
433
444
  /**
@@ -682,6 +693,10 @@ declare function isSetStep(value: unknown): value is SetStep;
682
693
  * Checks if value is an update step
683
694
  */
684
695
  declare function isUpdateStep(value: unknown): value is UpdateStep;
696
+ /**
697
+ * Checks if value is a setPath step
698
+ */
699
+ declare function isSetPathStep(value: unknown): value is SetPathStep;
685
700
  /**
686
701
  * Checks if value is a fetch step
687
702
  */
@@ -718,6 +733,15 @@ declare function isDisposeStep(value: unknown): value is DisposeStep;
718
733
  * Checks if value is any valid action step
719
734
  */
720
735
  declare function isActionStep(value: unknown): value is ActionStep;
736
+ /**
737
+ * Checks if value is a valid local action step
738
+ * Local actions only allow set, update, and setPath steps
739
+ */
740
+ declare function isLocalActionStep(value: unknown): value is LocalActionStep;
741
+ /**
742
+ * Checks if value is a local action definition
743
+ */
744
+ declare function isLocalActionDefinition(value: unknown): value is LocalActionDefinition;
721
745
  /**
722
746
  * Checks if value is a number field
723
747
  */
@@ -770,7 +794,7 @@ declare function isLifecycleHooks(value: unknown): value is LifecycleHooks;
770
794
  * This module defines error types, the ConstelaError class,
771
795
  * and factory functions for creating specific errors.
772
796
  */
773
- type ErrorCode = 'SCHEMA_INVALID' | 'UNDEFINED_STATE' | 'UNDEFINED_ACTION' | 'VAR_UNDEFINED' | 'DUPLICATE_ACTION' | 'UNSUPPORTED_VERSION' | 'COMPONENT_NOT_FOUND' | 'COMPONENT_PROP_MISSING' | 'COMPONENT_CYCLE' | 'COMPONENT_PROP_TYPE' | 'PARAM_UNDEFINED' | 'OPERATION_INVALID_FOR_TYPE' | 'OPERATION_MISSING_FIELD' | 'OPERATION_UNKNOWN' | 'EXPR_INVALID_BASE' | 'EXPR_INVALID_CONDITION' | 'EXPR_COND_ELSE_REQUIRED' | 'UNDEFINED_ROUTE_PARAM' | 'ROUTE_NOT_DEFINED' | 'UNDEFINED_IMPORT' | 'IMPORTS_NOT_DEFINED' | 'LAYOUT_MISSING_SLOT' | 'LAYOUT_NOT_FOUND' | 'INVALID_SLOT_NAME' | 'DUPLICATE_SLOT_NAME' | 'DUPLICATE_DEFAULT_SLOT' | 'SLOT_IN_LOOP' | 'INVALID_DATA_SOURCE' | 'UNDEFINED_DATA_SOURCE' | 'DATA_NOT_DEFINED' | 'UNDEFINED_DATA' | 'UNDEFINED_REF' | 'INVALID_STORAGE_OPERATION' | 'INVALID_STORAGE_TYPE' | 'STORAGE_SET_MISSING_VALUE' | 'INVALID_CLIPBOARD_OPERATION' | 'CLIPBOARD_WRITE_MISSING_VALUE' | 'INVALID_NAVIGATE_TARGET' | 'UNDEFINED_STYLE' | 'UNDEFINED_VARIANT';
797
+ type ErrorCode = 'SCHEMA_INVALID' | 'UNDEFINED_STATE' | 'UNDEFINED_ACTION' | 'VAR_UNDEFINED' | 'DUPLICATE_ACTION' | 'UNSUPPORTED_VERSION' | 'COMPONENT_NOT_FOUND' | 'COMPONENT_PROP_MISSING' | 'COMPONENT_CYCLE' | 'COMPONENT_PROP_TYPE' | 'PARAM_UNDEFINED' | 'OPERATION_INVALID_FOR_TYPE' | 'OPERATION_MISSING_FIELD' | 'OPERATION_UNKNOWN' | 'EXPR_INVALID_BASE' | 'EXPR_INVALID_CONDITION' | 'EXPR_COND_ELSE_REQUIRED' | 'UNDEFINED_ROUTE_PARAM' | 'ROUTE_NOT_DEFINED' | 'UNDEFINED_IMPORT' | 'IMPORTS_NOT_DEFINED' | 'LAYOUT_MISSING_SLOT' | 'LAYOUT_NOT_FOUND' | 'INVALID_SLOT_NAME' | 'DUPLICATE_SLOT_NAME' | 'DUPLICATE_DEFAULT_SLOT' | 'SLOT_IN_LOOP' | 'INVALID_DATA_SOURCE' | 'UNDEFINED_DATA_SOURCE' | 'DATA_NOT_DEFINED' | 'UNDEFINED_DATA' | 'UNDEFINED_REF' | 'INVALID_STORAGE_OPERATION' | 'INVALID_STORAGE_TYPE' | 'STORAGE_SET_MISSING_VALUE' | 'INVALID_CLIPBOARD_OPERATION' | 'CLIPBOARD_WRITE_MISSING_VALUE' | 'INVALID_NAVIGATE_TARGET' | 'UNDEFINED_STYLE' | 'UNDEFINED_VARIANT' | 'UNDEFINED_LOCAL_STATE' | 'LOCAL_ACTION_INVALID_STEP';
774
798
  /**
775
799
  * Options for creating enhanced ConstelaError instances
776
800
  */
@@ -969,6 +993,14 @@ declare function createUndefinedStyleError(styleName: string, path?: string, opt
969
993
  * Creates an undefined variant key error
970
994
  */
971
995
  declare function createUndefinedVariantError(variantKey: string, styleName: string, path?: string, options?: ErrorOptions): ConstelaError;
996
+ /**
997
+ * Creates an undefined local state reference error
998
+ */
999
+ declare function createUndefinedLocalStateError(stateName: string, path?: string, options?: ErrorOptions): ConstelaError;
1000
+ /**
1001
+ * Creates a local action invalid step error
1002
+ */
1003
+ declare function createLocalActionInvalidStepError(stepType: string, path?: string): ConstelaError;
972
1004
  /**
973
1005
  * Finds similar names from a set of candidates using Levenshtein distance
974
1006
  * and prefix matching.
@@ -1720,4 +1752,4 @@ declare const astSchema: {
1720
1752
  };
1721
1753
  };
1722
1754
 
1723
- export { type ActionDefinition, type ActionStep, BINARY_OPERATORS, type BinExpr, type BinaryOperator, type BooleanField, CLIPBOARD_OPERATIONS, type CallStep, 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, DATA_SOURCE_TYPES, DATA_TRANSFORMS, type DataExpr, type DataSource, type DataSourceType, type DataTransform, type DisposeStep, type DomStep, type EachNode, type ElementNode, type ErrorCode, type ErrorOptions, type EventHandler, type Expression, type FetchStep, type GetExpr, HTTP_METHODS, type HttpMethod, type IfNode, type ImportExpr, type ImportStep, type LayoutProgram, type LifecycleHooks, type ListField, type LitExpr, type MarkdownNode, NAVIGATE_TARGETS, type NavigateStep, type NavigateTarget, type NotExpr, type NumberField, type ObjectField, PARAM_TYPES, type ParamDef, type ParamExpr, type ParamType, 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, type ValidationFailure, type ValidationResult, type ValidationSuccess, type VarExpr, type ViewNode, astSchema, createClipboardWriteMissingValueError, createComponentCycleError, createComponentNotFoundError, createComponentPropMissingError, createComponentPropTypeError, createCondElseRequiredError, createDataNotDefinedError, createDuplicateActionError, createDuplicateDefaultSlotError, createDuplicateSlotNameError, createImportsNotDefinedError, createInvalidClipboardOperationError, createInvalidDataSourceError, createInvalidNavigateTargetError, createInvalidSlotNameError, createInvalidStorageOperationError, createInvalidStorageTypeError, createLayoutMissingSlotError, createLayoutNotFoundError, createOperationInvalidForTypeError, createOperationMissingFieldError, createOperationUnknownError, createRouteNotDefinedError, createSchemaError, createSlotInLoopError, createStorageSetMissingValueError, createUndefinedActionError, createUndefinedDataError, createUndefinedDataSourceError, createUndefinedImportError, createUndefinedParamError, createUndefinedRefError, createUndefinedRouteParamError, createUndefinedStateError, createUndefinedStyleError, createUndefinedVarError, createUndefinedVariantError, createUnsupportedVersionError, findSimilarNames, isActionStep, isBinExpr, isBooleanField, isCallStep, isClipboardStep, isCodeNode, isComponentNode, isConcatExpr, isCondExpr, isConstelaError, isDataExpr, isDataSource, isDisposeStep, isEachNode, isElementNode, isEventHandler, isExpression, isFetchStep, isGetExpr, isIfNode, isImportExpr, isImportStep, isLayoutProgram, isLifecycleHooks, isListField, isLitExpr, isMarkdownNode, isNamedSlotNode, isNavigateStep, isNotExpr, isNumberField, isObjectField, isParamExpr, isRefExpr, isRouteDefinition, isRouteExpr, isSetStep, isSlotNode, isStateExpr, isStateField, isStaticPathsDefinition, isStorageStep, isStringField, isStyleExpr, isSubscribeStep, isTextNode, isUpdateStep, isVarExpr, isViewNode, validateAst };
1755
+ export { type ActionDefinition, type ActionStep, BINARY_OPERATORS, type BinExpr, type BinaryOperator, type BooleanField, CLIPBOARD_OPERATIONS, type CallStep, 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, DATA_SOURCE_TYPES, DATA_TRANSFORMS, type DataExpr, type DataSource, type DataSourceType, type DataTransform, type DisposeStep, type DomStep, type EachNode, type ElementNode, type ErrorCode, type ErrorOptions, type EventHandler, type Expression, type FetchStep, type GetExpr, HTTP_METHODS, type HttpMethod, type IfNode, type ImportExpr, type ImportStep, 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 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, type ValidationFailure, type ValidationResult, type ValidationSuccess, 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, isDataExpr, isDataSource, isDisposeStep, isEachNode, isElementNode, isEventHandler, isExpression, isFetchStep, isGetExpr, isIfNode, isImportExpr, isImportStep, isLayoutProgram, isLifecycleHooks, isListField, isLitExpr, isLocalActionDefinition, isLocalActionStep, isMarkdownNode, isNamedSlotNode, isNavigateStep, isNotExpr, isNumberField, isObjectField, isParamExpr, isRefExpr, isRouteDefinition, isRouteExpr, isSetPathStep, isSetStep, isSlotNode, isStateExpr, isStateField, isStaticPathsDefinition, isStorageStep, isStringField, isStyleExpr, isSubscribeStep, isTextNode, isUpdateStep, isVarExpr, isViewNode, validateAst };
package/dist/index.js CHANGED
@@ -252,6 +252,14 @@ function isUpdateStep(value) {
252
252
  }
253
253
  return true;
254
254
  }
255
+ function isSetPathStep(value) {
256
+ if (!isObject(value)) return false;
257
+ if (value["do"] !== "setPath") return false;
258
+ if (typeof value["target"] !== "string") return false;
259
+ if (!isObject(value["path"])) return false;
260
+ if (!isObject(value["value"])) return false;
261
+ return true;
262
+ }
255
263
  function isFetchStep(value) {
256
264
  if (!isObject(value)) return false;
257
265
  if (value["do"] !== "fetch") return false;
@@ -322,7 +330,19 @@ function isDisposeStep(value) {
322
330
  return true;
323
331
  }
324
332
  function isActionStep(value) {
325
- return isSetStep(value) || isUpdateStep(value) || isFetchStep(value) || isStorageStep(value) || isClipboardStep(value) || isNavigateStep(value) || isImportStep(value) || isCallStep(value) || isSubscribeStep(value) || isDisposeStep(value);
333
+ return isSetStep(value) || isUpdateStep(value) || isSetPathStep(value) || isFetchStep(value) || isStorageStep(value) || isClipboardStep(value) || isNavigateStep(value) || isImportStep(value) || isCallStep(value) || isSubscribeStep(value) || isDisposeStep(value);
334
+ }
335
+ function isLocalActionStep(value) {
336
+ return isSetStep(value) || isUpdateStep(value) || isSetPathStep(value);
337
+ }
338
+ function isLocalActionDefinition(value) {
339
+ if (!isObject(value)) return false;
340
+ if (typeof value["name"] !== "string") return false;
341
+ if (!Array.isArray(value["steps"])) return false;
342
+ for (const step of value["steps"]) {
343
+ if (!isLocalActionStep(step)) return false;
344
+ }
345
+ return true;
326
346
  }
327
347
  function isNumberField(value) {
328
348
  if (!isObject(value)) return false;
@@ -697,6 +717,21 @@ function createUndefinedVariantError(variantKey, styleName, path, options) {
697
717
  options
698
718
  );
699
719
  }
720
+ function createUndefinedLocalStateError(stateName, path, options) {
721
+ return new ConstelaError(
722
+ "UNDEFINED_LOCAL_STATE",
723
+ `Undefined local state reference: '${stateName}' is not defined in localState`,
724
+ path,
725
+ options
726
+ );
727
+ }
728
+ function createLocalActionInvalidStepError(stepType, path) {
729
+ return new ConstelaError(
730
+ "LOCAL_ACTION_INVALID_STEP",
731
+ `Invalid step type '${stepType}' in local action. Only 'set', 'update', and 'setPath' are allowed`,
732
+ path
733
+ );
734
+ }
700
735
  function levenshteinDistance(a, b) {
701
736
  const aLen = a.length;
702
737
  const bLen = b.length;
@@ -1880,6 +1915,7 @@ export {
1880
1915
  createInvalidStorageTypeError,
1881
1916
  createLayoutMissingSlotError,
1882
1917
  createLayoutNotFoundError,
1918
+ createLocalActionInvalidStepError,
1883
1919
  createOperationInvalidForTypeError,
1884
1920
  createOperationMissingFieldError,
1885
1921
  createOperationUnknownError,
@@ -1891,6 +1927,7 @@ export {
1891
1927
  createUndefinedDataError,
1892
1928
  createUndefinedDataSourceError,
1893
1929
  createUndefinedImportError,
1930
+ createUndefinedLocalStateError,
1894
1931
  createUndefinedParamError,
1895
1932
  createUndefinedRefError,
1896
1933
  createUndefinedRouteParamError,
@@ -1926,6 +1963,8 @@ export {
1926
1963
  isLifecycleHooks,
1927
1964
  isListField,
1928
1965
  isLitExpr,
1966
+ isLocalActionDefinition,
1967
+ isLocalActionStep,
1929
1968
  isMarkdownNode,
1930
1969
  isNamedSlotNode,
1931
1970
  isNavigateStep,
@@ -1936,6 +1975,7 @@ export {
1936
1975
  isRefExpr,
1937
1976
  isRouteDefinition,
1938
1977
  isRouteExpr,
1978
+ isSetPathStep,
1939
1979
  isSetStep,
1940
1980
  isSlotNode,
1941
1981
  isStateExpr,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/core",
3
- "version": "0.9.1",
3
+ "version": "0.10.0",
4
4
  "description": "Core types, schema, and validator for Constela UI framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",