@constela/core 0.9.0 → 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 +55 -4
- package/dist/index.d.ts +46 -3
- package/dist/index.js +46 -2
- package/package.json +1 -1
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
|
-
|
|
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:
|
|
@@ -79,6 +99,9 @@ All fields except `version`, `state`, `actions`, and `view` are optional.
|
|
|
79
99
|
// Loop node
|
|
80
100
|
{ "kind": "each", "items": { "expr": "state", "name": "todos" }, "as": "item", "body": { ... } }
|
|
81
101
|
|
|
102
|
+
// Loop node with key (efficient diffing)
|
|
103
|
+
{ "kind": "each", "items": { ... }, "as": "item", "key": { "expr": "var", "name": "item", "path": "id" }, "body": { ... } }
|
|
104
|
+
|
|
82
105
|
// Component node
|
|
83
106
|
{ "kind": "component", "name": "Button", "props": { "label": { ... } } }
|
|
84
107
|
|
|
@@ -95,7 +118,7 @@ All fields except `version`, `state`, `actions`, and `view` are optional.
|
|
|
95
118
|
|
|
96
119
|
## Action Step Types
|
|
97
120
|
|
|
98
|
-
|
|
121
|
+
14 step types for declarative actions:
|
|
99
122
|
|
|
100
123
|
```json
|
|
101
124
|
// Set state value
|
|
@@ -105,6 +128,10 @@ All fields except `version`, `state`, `actions`, and `view` are optional.
|
|
|
105
128
|
{ "do": "update", "target": "count", "operation": "increment" }
|
|
106
129
|
{ "do": "update", "target": "todos", "operation": "push", "value": { ... } }
|
|
107
130
|
|
|
131
|
+
// Set nested path (fine-grained update)
|
|
132
|
+
{ "do": "setPath", "target": "posts", "path": [5, "liked"], "value": { "expr": "lit", "value": true } }
|
|
133
|
+
{ "do": "setPath", "target": "posts", "path": { "expr": "var", "name": "payload", "path": "index" }, "field": "liked", "value": { ... } }
|
|
134
|
+
|
|
108
135
|
// HTTP request
|
|
109
136
|
{ "do": "fetch", "url": { ... }, "method": "GET", "onSuccess": [ ... ], "onError": [ ... ] }
|
|
110
137
|
|
|
@@ -131,6 +158,30 @@ All fields except `version`, `state`, `actions`, and `view` are optional.
|
|
|
131
158
|
|
|
132
159
|
// DOM manipulation
|
|
133
160
|
{ "do": "dom", "operation": "addClass", "ref": "myElement", "value": { ... } }
|
|
161
|
+
|
|
162
|
+
// WebSocket send
|
|
163
|
+
{ "do": "send", "connection": "chat", "data": { "expr": "state", "name": "inputText" } }
|
|
164
|
+
|
|
165
|
+
// WebSocket close
|
|
166
|
+
{ "do": "close", "connection": "chat" }
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Connections
|
|
170
|
+
|
|
171
|
+
WebSocket connections for real-time data:
|
|
172
|
+
|
|
173
|
+
```json
|
|
174
|
+
{
|
|
175
|
+
"connections": {
|
|
176
|
+
"chat": {
|
|
177
|
+
"type": "websocket",
|
|
178
|
+
"url": "wss://api.example.com/ws",
|
|
179
|
+
"onMessage": { "action": "handleMessage" },
|
|
180
|
+
"onOpen": { "action": "connectionOpened" },
|
|
181
|
+
"onClose": { "action": "connectionClosed" }
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
134
185
|
```
|
|
135
186
|
|
|
136
187
|
**Update Operations:**
|
|
@@ -274,11 +325,11 @@ if (result.ok) {
|
|
|
274
325
|
|
|
275
326
|
### Type Guards
|
|
276
327
|
|
|
277
|
-
|
|
328
|
+
48 type guard functions for runtime type checking:
|
|
278
329
|
|
|
279
330
|
```typescript
|
|
280
331
|
import {
|
|
281
|
-
isLitExpr, isStateExpr, isVarExpr, isBinExpr,
|
|
332
|
+
isLitExpr, isStateExpr, isVarExpr, isBinExpr, isConcatExpr,
|
|
282
333
|
isElementNode, isTextNode, isIfNode, isEachNode,
|
|
283
334
|
isSetStep, isUpdateStep, isFetchStep,
|
|
284
335
|
isNumberField, isStringField, isListField,
|
package/dist/index.d.ts
CHANGED
|
@@ -135,7 +135,14 @@ interface StyleExpr {
|
|
|
135
135
|
name: string;
|
|
136
136
|
variants?: Record<string, Expression>;
|
|
137
137
|
}
|
|
138
|
-
|
|
138
|
+
/**
|
|
139
|
+
* Concat expression - concatenates multiple expressions into a string
|
|
140
|
+
*/
|
|
141
|
+
interface ConcatExpr {
|
|
142
|
+
expr: 'concat';
|
|
143
|
+
items: Expression[];
|
|
144
|
+
}
|
|
145
|
+
type Expression = LitExpr | StateExpr | VarExpr | BinExpr | NotExpr | ParamExpr | CondExpr | GetExpr | RouteExpr | ImportExpr | DataExpr | RefExpr | IndexExpr | StyleExpr | ConcatExpr;
|
|
139
146
|
/**
|
|
140
147
|
* Number state field
|
|
141
148
|
*/
|
|
@@ -334,6 +341,7 @@ interface CloseStep {
|
|
|
334
341
|
connection: string;
|
|
335
342
|
}
|
|
336
343
|
type ActionStep = SetStep | UpdateStep | SetPathStep | FetchStep | StorageStep | ClipboardStep | NavigateStep | ImportStep | CallStep | SubscribeStep | DisposeStep | DomStep | SendStep | CloseStep;
|
|
344
|
+
type LocalActionStep = SetStep | UpdateStep | SetPathStep;
|
|
337
345
|
/**
|
|
338
346
|
* Event handler - binds an event to an action
|
|
339
347
|
*/
|
|
@@ -349,6 +357,14 @@ interface ActionDefinition {
|
|
|
349
357
|
name: string;
|
|
350
358
|
steps: ActionStep[];
|
|
351
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
|
+
}
|
|
352
368
|
/**
|
|
353
369
|
* Element node - represents an HTML element
|
|
354
370
|
*/
|
|
@@ -421,6 +437,8 @@ interface CodeNode {
|
|
|
421
437
|
type ViewNode = ElementNode | TextNode | IfNode | EachNode | ComponentNode | SlotNode | MarkdownNode | CodeNode;
|
|
422
438
|
interface ComponentDef {
|
|
423
439
|
params?: Record<string, ParamDef>;
|
|
440
|
+
localState?: Record<string, StateField>;
|
|
441
|
+
localActions?: LocalActionDefinition[];
|
|
424
442
|
view: ViewNode;
|
|
425
443
|
}
|
|
426
444
|
/**
|
|
@@ -611,6 +629,10 @@ declare function isRefExpr(value: unknown): value is RefExpr;
|
|
|
611
629
|
* Checks if value is a style expression
|
|
612
630
|
*/
|
|
613
631
|
declare function isStyleExpr(value: unknown): value is StyleExpr;
|
|
632
|
+
/**
|
|
633
|
+
* Checks if value is a concat expression
|
|
634
|
+
*/
|
|
635
|
+
declare function isConcatExpr(value: unknown): value is ConcatExpr;
|
|
614
636
|
/**
|
|
615
637
|
* Checks if value is a data source
|
|
616
638
|
*/
|
|
@@ -671,6 +693,10 @@ declare function isSetStep(value: unknown): value is SetStep;
|
|
|
671
693
|
* Checks if value is an update step
|
|
672
694
|
*/
|
|
673
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;
|
|
674
700
|
/**
|
|
675
701
|
* Checks if value is a fetch step
|
|
676
702
|
*/
|
|
@@ -707,6 +733,15 @@ declare function isDisposeStep(value: unknown): value is DisposeStep;
|
|
|
707
733
|
* Checks if value is any valid action step
|
|
708
734
|
*/
|
|
709
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;
|
|
710
745
|
/**
|
|
711
746
|
* Checks if value is a number field
|
|
712
747
|
*/
|
|
@@ -759,7 +794,7 @@ declare function isLifecycleHooks(value: unknown): value is LifecycleHooks;
|
|
|
759
794
|
* This module defines error types, the ConstelaError class,
|
|
760
795
|
* and factory functions for creating specific errors.
|
|
761
796
|
*/
|
|
762
|
-
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';
|
|
763
798
|
/**
|
|
764
799
|
* Options for creating enhanced ConstelaError instances
|
|
765
800
|
*/
|
|
@@ -958,6 +993,14 @@ declare function createUndefinedStyleError(styleName: string, path?: string, opt
|
|
|
958
993
|
* Creates an undefined variant key error
|
|
959
994
|
*/
|
|
960
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;
|
|
961
1004
|
/**
|
|
962
1005
|
* Finds similar names from a set of candidates using Levenshtein distance
|
|
963
1006
|
* and prefix matching.
|
|
@@ -1709,4 +1752,4 @@ declare const astSchema: {
|
|
|
1709
1752
|
};
|
|
1710
1753
|
};
|
|
1711
1754
|
|
|
1712
|
-
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 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, 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
|
@@ -139,6 +139,9 @@ function isStyleExpr(value) {
|
|
|
139
139
|
}
|
|
140
140
|
return true;
|
|
141
141
|
}
|
|
142
|
+
function isConcatExpr(value) {
|
|
143
|
+
return typeof value === "object" && value !== null && value.expr === "concat" && Array.isArray(value.items);
|
|
144
|
+
}
|
|
142
145
|
function isDataSource(value) {
|
|
143
146
|
if (!isObject(value)) return false;
|
|
144
147
|
const type = value["type"];
|
|
@@ -175,7 +178,7 @@ function isRouteDefinition(value) {
|
|
|
175
178
|
return true;
|
|
176
179
|
}
|
|
177
180
|
function isExpression(value) {
|
|
178
|
-
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);
|
|
181
|
+
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);
|
|
179
182
|
}
|
|
180
183
|
function isElementNode(value) {
|
|
181
184
|
if (!isObject(value)) return false;
|
|
@@ -249,6 +252,14 @@ function isUpdateStep(value) {
|
|
|
249
252
|
}
|
|
250
253
|
return true;
|
|
251
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
|
+
}
|
|
252
263
|
function isFetchStep(value) {
|
|
253
264
|
if (!isObject(value)) return false;
|
|
254
265
|
if (value["do"] !== "fetch") return false;
|
|
@@ -319,7 +330,19 @@ function isDisposeStep(value) {
|
|
|
319
330
|
return true;
|
|
320
331
|
}
|
|
321
332
|
function isActionStep(value) {
|
|
322
|
-
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;
|
|
323
346
|
}
|
|
324
347
|
function isNumberField(value) {
|
|
325
348
|
if (!isObject(value)) return false;
|
|
@@ -694,6 +717,21 @@ function createUndefinedVariantError(variantKey, styleName, path, options) {
|
|
|
694
717
|
options
|
|
695
718
|
);
|
|
696
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
|
+
}
|
|
697
735
|
function levenshteinDistance(a, b) {
|
|
698
736
|
const aLen = a.length;
|
|
699
737
|
const bLen = b.length;
|
|
@@ -1877,6 +1915,7 @@ export {
|
|
|
1877
1915
|
createInvalidStorageTypeError,
|
|
1878
1916
|
createLayoutMissingSlotError,
|
|
1879
1917
|
createLayoutNotFoundError,
|
|
1918
|
+
createLocalActionInvalidStepError,
|
|
1880
1919
|
createOperationInvalidForTypeError,
|
|
1881
1920
|
createOperationMissingFieldError,
|
|
1882
1921
|
createOperationUnknownError,
|
|
@@ -1888,6 +1927,7 @@ export {
|
|
|
1888
1927
|
createUndefinedDataError,
|
|
1889
1928
|
createUndefinedDataSourceError,
|
|
1890
1929
|
createUndefinedImportError,
|
|
1930
|
+
createUndefinedLocalStateError,
|
|
1891
1931
|
createUndefinedParamError,
|
|
1892
1932
|
createUndefinedRefError,
|
|
1893
1933
|
createUndefinedRouteParamError,
|
|
@@ -1904,6 +1944,7 @@ export {
|
|
|
1904
1944
|
isClipboardStep,
|
|
1905
1945
|
isCodeNode,
|
|
1906
1946
|
isComponentNode,
|
|
1947
|
+
isConcatExpr,
|
|
1907
1948
|
isCondExpr,
|
|
1908
1949
|
isConstelaError,
|
|
1909
1950
|
isDataExpr,
|
|
@@ -1922,6 +1963,8 @@ export {
|
|
|
1922
1963
|
isLifecycleHooks,
|
|
1923
1964
|
isListField,
|
|
1924
1965
|
isLitExpr,
|
|
1966
|
+
isLocalActionDefinition,
|
|
1967
|
+
isLocalActionStep,
|
|
1925
1968
|
isMarkdownNode,
|
|
1926
1969
|
isNamedSlotNode,
|
|
1927
1970
|
isNavigateStep,
|
|
@@ -1932,6 +1975,7 @@ export {
|
|
|
1932
1975
|
isRefExpr,
|
|
1933
1976
|
isRouteDefinition,
|
|
1934
1977
|
isRouteExpr,
|
|
1978
|
+
isSetPathStep,
|
|
1935
1979
|
isSetStep,
|
|
1936
1980
|
isSlotNode,
|
|
1937
1981
|
isStateExpr,
|