@constela/core 0.2.0 → 0.3.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/dist/index.d.ts +179 -6
- package/dist/index.js +127 -8
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
declare const BINARY_OPERATORS: readonly ["+", "-", "*", "/", "==", "!=", "<", "<=", ">", ">=", "&&", "||"];
|
|
8
8
|
type BinaryOperator = (typeof BINARY_OPERATORS)[number];
|
|
9
|
-
declare const UPDATE_OPERATIONS: readonly ["increment", "decrement", "push", "pop", "remove"];
|
|
9
|
+
declare const UPDATE_OPERATIONS: readonly ["increment", "decrement", "push", "pop", "remove", "toggle", "merge", "replaceAt", "insertAt", "splice"];
|
|
10
10
|
type UpdateOperation = (typeof UPDATE_OPERATIONS)[number];
|
|
11
11
|
declare const HTTP_METHODS: readonly ["GET", "POST", "PUT", "DELETE"];
|
|
12
12
|
type HttpMethod = (typeof HTTP_METHODS)[number];
|
|
@@ -62,7 +62,24 @@ interface ParamExpr {
|
|
|
62
62
|
name: string;
|
|
63
63
|
path?: string;
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Cond expression - conditional if/then/else
|
|
67
|
+
*/
|
|
68
|
+
interface CondExpr {
|
|
69
|
+
expr: 'cond';
|
|
70
|
+
if: Expression;
|
|
71
|
+
then: Expression;
|
|
72
|
+
else: Expression;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get expression - property access
|
|
76
|
+
*/
|
|
77
|
+
interface GetExpr {
|
|
78
|
+
expr: 'get';
|
|
79
|
+
base: Expression;
|
|
80
|
+
path: string;
|
|
81
|
+
}
|
|
82
|
+
type Expression = LitExpr | StateExpr | VarExpr | BinExpr | NotExpr | ParamExpr | CondExpr | GetExpr;
|
|
66
83
|
/**
|
|
67
84
|
* Number state field
|
|
68
85
|
*/
|
|
@@ -84,7 +101,21 @@ interface ListField {
|
|
|
84
101
|
type: 'list';
|
|
85
102
|
initial: unknown[];
|
|
86
103
|
}
|
|
87
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Boolean state field
|
|
106
|
+
*/
|
|
107
|
+
interface BooleanField {
|
|
108
|
+
type: 'boolean';
|
|
109
|
+
initial: boolean;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Object state field
|
|
113
|
+
*/
|
|
114
|
+
interface ObjectField {
|
|
115
|
+
type: 'object';
|
|
116
|
+
initial: Record<string, unknown>;
|
|
117
|
+
}
|
|
118
|
+
type StateField = NumberField | StringField | ListField | BooleanField | ObjectField;
|
|
88
119
|
/**
|
|
89
120
|
* Set step - sets a state field to a new value
|
|
90
121
|
*/
|
|
@@ -95,12 +126,31 @@ interface SetStep {
|
|
|
95
126
|
}
|
|
96
127
|
/**
|
|
97
128
|
* Update step - performs an operation on a state field
|
|
129
|
+
*
|
|
130
|
+
* Operations and their required fields:
|
|
131
|
+
* - increment/decrement: Numeric operations. Optional `value` for amount (default: 1)
|
|
132
|
+
* - push: Add item to array. Requires `value`
|
|
133
|
+
* - pop: Remove last item from array. No additional fields
|
|
134
|
+
* - remove: Remove item from array by value or index. Requires `value`
|
|
135
|
+
* - toggle: Flip boolean value. No additional fields
|
|
136
|
+
* - merge: Shallow merge object. Requires `value` (object)
|
|
137
|
+
* - replaceAt: Replace array item at index. Requires `index` and `value`
|
|
138
|
+
* - insertAt: Insert item at array index. Requires `index` and `value`
|
|
139
|
+
* - splice: Delete and/or insert items. Requires `index` and `deleteCount`, optional `value` (array)
|
|
140
|
+
*
|
|
141
|
+
* @property target - The state field name to update
|
|
142
|
+
* @property operation - The update operation to perform
|
|
143
|
+
* @property value - Value for push/merge/replaceAt/insertAt/splice operations
|
|
144
|
+
* @property index - Array index for replaceAt/insertAt/splice operations
|
|
145
|
+
* @property deleteCount - Number of items to delete for splice operation
|
|
98
146
|
*/
|
|
99
147
|
interface UpdateStep {
|
|
100
148
|
do: 'update';
|
|
101
149
|
target: string;
|
|
102
150
|
operation: UpdateOperation;
|
|
103
151
|
value?: Expression;
|
|
152
|
+
index?: Expression;
|
|
153
|
+
deleteCount?: Expression;
|
|
104
154
|
}
|
|
105
155
|
/**
|
|
106
156
|
* Fetch step - makes an HTTP request
|
|
@@ -240,6 +290,26 @@ declare function isNotExpr(value: unknown): value is NotExpr;
|
|
|
240
290
|
* Checks if value is a param expression
|
|
241
291
|
*/
|
|
242
292
|
declare function isParamExpr(value: unknown): value is ParamExpr;
|
|
293
|
+
/**
|
|
294
|
+
* Checks if value is a cond expression
|
|
295
|
+
*
|
|
296
|
+
* Note: This performs shallow validation only - it checks that `if`, `then`, and `else`
|
|
297
|
+
* are objects but does not recursively validate they are valid Expressions.
|
|
298
|
+
* This is intentional for performance: deep validation would require traversing
|
|
299
|
+
* potentially deeply nested expression trees on every type guard call.
|
|
300
|
+
* Use the AST validator for full recursive validation instead.
|
|
301
|
+
*/
|
|
302
|
+
declare function isCondExpr(value: unknown): value is CondExpr;
|
|
303
|
+
/**
|
|
304
|
+
* Checks if value is a get expression
|
|
305
|
+
*
|
|
306
|
+
* Note: This performs shallow validation only - it checks that `base` is
|
|
307
|
+
* an object but does not recursively validate it is a valid Expression.
|
|
308
|
+
* This is intentional for performance: deep validation would require traversing
|
|
309
|
+
* potentially deeply nested expression trees on every type guard call.
|
|
310
|
+
* Use the AST validator for full recursive validation instead.
|
|
311
|
+
*/
|
|
312
|
+
declare function isGetExpr(value: unknown): value is GetExpr;
|
|
243
313
|
/**
|
|
244
314
|
* Checks if value is any valid expression
|
|
245
315
|
*/
|
|
@@ -300,6 +370,14 @@ declare function isStringField(value: unknown): value is StringField;
|
|
|
300
370
|
* Checks if value is a list field
|
|
301
371
|
*/
|
|
302
372
|
declare function isListField(value: unknown): value is ListField;
|
|
373
|
+
/**
|
|
374
|
+
* Checks if value is a boolean field
|
|
375
|
+
*/
|
|
376
|
+
declare function isBooleanField(value: unknown): value is BooleanField;
|
|
377
|
+
/**
|
|
378
|
+
* Checks if value is an object field
|
|
379
|
+
*/
|
|
380
|
+
declare function isObjectField(value: unknown): value is ObjectField;
|
|
303
381
|
/**
|
|
304
382
|
* Checks if value is any valid state field
|
|
305
383
|
*/
|
|
@@ -315,7 +393,7 @@ declare function isEventHandler(value: unknown): value is EventHandler;
|
|
|
315
393
|
* This module defines error types, the ConstelaError class,
|
|
316
394
|
* and factory functions for creating specific errors.
|
|
317
395
|
*/
|
|
318
|
-
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';
|
|
396
|
+
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';
|
|
319
397
|
/**
|
|
320
398
|
* Custom error class for Constela validation errors
|
|
321
399
|
*/
|
|
@@ -380,6 +458,22 @@ declare function createComponentPropTypeError(componentName: string, propName: s
|
|
|
380
458
|
* Creates an undefined param reference error
|
|
381
459
|
*/
|
|
382
460
|
declare function createUndefinedParamError(paramName: string, path?: string): ConstelaError;
|
|
461
|
+
/**
|
|
462
|
+
* Creates an operation invalid for type error
|
|
463
|
+
*/
|
|
464
|
+
declare function createOperationInvalidForTypeError(operation: string, stateType: string, path?: string): ConstelaError;
|
|
465
|
+
/**
|
|
466
|
+
* Creates an operation missing field error
|
|
467
|
+
*/
|
|
468
|
+
declare function createOperationMissingFieldError(operation: string, field: string, path?: string): ConstelaError;
|
|
469
|
+
/**
|
|
470
|
+
* Creates an operation unknown error
|
|
471
|
+
*/
|
|
472
|
+
declare function createOperationUnknownError(operation: string, path?: string): ConstelaError;
|
|
473
|
+
/**
|
|
474
|
+
* Creates a cond else required error
|
|
475
|
+
*/
|
|
476
|
+
declare function createCondElseRequiredError(path?: string): ConstelaError;
|
|
383
477
|
|
|
384
478
|
/**
|
|
385
479
|
* AST Validator for Constela
|
|
@@ -459,6 +553,10 @@ declare const astSchema: {
|
|
|
459
553
|
readonly $ref: "#/$defs/NotExpr";
|
|
460
554
|
}, {
|
|
461
555
|
readonly $ref: "#/$defs/ParamExpr";
|
|
556
|
+
}, {
|
|
557
|
+
readonly $ref: "#/$defs/CondExpr";
|
|
558
|
+
}, {
|
|
559
|
+
readonly $ref: "#/$defs/GetExpr";
|
|
462
560
|
}];
|
|
463
561
|
};
|
|
464
562
|
readonly LitExpr: {
|
|
@@ -568,6 +666,43 @@ declare const astSchema: {
|
|
|
568
666
|
};
|
|
569
667
|
};
|
|
570
668
|
};
|
|
669
|
+
readonly CondExpr: {
|
|
670
|
+
readonly type: "object";
|
|
671
|
+
readonly required: readonly ["expr", "if", "then", "else"];
|
|
672
|
+
readonly additionalProperties: false;
|
|
673
|
+
readonly properties: {
|
|
674
|
+
readonly expr: {
|
|
675
|
+
readonly type: "string";
|
|
676
|
+
readonly const: "cond";
|
|
677
|
+
};
|
|
678
|
+
readonly if: {
|
|
679
|
+
readonly $ref: "#/$defs/Expression";
|
|
680
|
+
};
|
|
681
|
+
readonly then: {
|
|
682
|
+
readonly $ref: "#/$defs/Expression";
|
|
683
|
+
};
|
|
684
|
+
readonly else: {
|
|
685
|
+
readonly $ref: "#/$defs/Expression";
|
|
686
|
+
};
|
|
687
|
+
};
|
|
688
|
+
};
|
|
689
|
+
readonly GetExpr: {
|
|
690
|
+
readonly type: "object";
|
|
691
|
+
readonly required: readonly ["expr", "base", "path"];
|
|
692
|
+
readonly additionalProperties: false;
|
|
693
|
+
readonly properties: {
|
|
694
|
+
readonly expr: {
|
|
695
|
+
readonly type: "string";
|
|
696
|
+
readonly const: "get";
|
|
697
|
+
};
|
|
698
|
+
readonly base: {
|
|
699
|
+
readonly $ref: "#/$defs/Expression";
|
|
700
|
+
};
|
|
701
|
+
readonly path: {
|
|
702
|
+
readonly type: "string";
|
|
703
|
+
};
|
|
704
|
+
};
|
|
705
|
+
};
|
|
571
706
|
readonly StateField: {
|
|
572
707
|
readonly oneOf: readonly [{
|
|
573
708
|
readonly $ref: "#/$defs/NumberField";
|
|
@@ -575,6 +710,10 @@ declare const astSchema: {
|
|
|
575
710
|
readonly $ref: "#/$defs/StringField";
|
|
576
711
|
}, {
|
|
577
712
|
readonly $ref: "#/$defs/ListField";
|
|
713
|
+
}, {
|
|
714
|
+
readonly $ref: "#/$defs/BooleanField";
|
|
715
|
+
}, {
|
|
716
|
+
readonly $ref: "#/$defs/ObjectField";
|
|
578
717
|
}];
|
|
579
718
|
};
|
|
580
719
|
readonly NumberField: {
|
|
@@ -619,6 +758,34 @@ declare const astSchema: {
|
|
|
619
758
|
};
|
|
620
759
|
};
|
|
621
760
|
};
|
|
761
|
+
readonly BooleanField: {
|
|
762
|
+
readonly type: "object";
|
|
763
|
+
readonly required: readonly ["type", "initial"];
|
|
764
|
+
readonly additionalProperties: false;
|
|
765
|
+
readonly properties: {
|
|
766
|
+
readonly type: {
|
|
767
|
+
readonly type: "string";
|
|
768
|
+
readonly const: "boolean";
|
|
769
|
+
};
|
|
770
|
+
readonly initial: {
|
|
771
|
+
readonly type: "boolean";
|
|
772
|
+
};
|
|
773
|
+
};
|
|
774
|
+
};
|
|
775
|
+
readonly ObjectField: {
|
|
776
|
+
readonly type: "object";
|
|
777
|
+
readonly required: readonly ["type", "initial"];
|
|
778
|
+
readonly additionalProperties: false;
|
|
779
|
+
readonly properties: {
|
|
780
|
+
readonly type: {
|
|
781
|
+
readonly type: "string";
|
|
782
|
+
readonly const: "object";
|
|
783
|
+
};
|
|
784
|
+
readonly initial: {
|
|
785
|
+
readonly type: "object";
|
|
786
|
+
};
|
|
787
|
+
};
|
|
788
|
+
};
|
|
622
789
|
readonly ActionStep: {
|
|
623
790
|
readonly oneOf: readonly [{
|
|
624
791
|
readonly $ref: "#/$defs/SetStep";
|
|
@@ -659,11 +826,17 @@ declare const astSchema: {
|
|
|
659
826
|
};
|
|
660
827
|
readonly operation: {
|
|
661
828
|
readonly type: "string";
|
|
662
|
-
readonly enum: readonly ["increment", "decrement", "push", "pop", "remove"];
|
|
829
|
+
readonly enum: readonly ["increment", "decrement", "push", "pop", "remove", "toggle", "merge", "replaceAt", "insertAt", "splice"];
|
|
663
830
|
};
|
|
664
831
|
readonly value: {
|
|
665
832
|
readonly $ref: "#/$defs/Expression";
|
|
666
833
|
};
|
|
834
|
+
readonly index: {
|
|
835
|
+
readonly $ref: "#/$defs/Expression";
|
|
836
|
+
};
|
|
837
|
+
readonly deleteCount: {
|
|
838
|
+
readonly $ref: "#/$defs/Expression";
|
|
839
|
+
};
|
|
667
840
|
};
|
|
668
841
|
};
|
|
669
842
|
readonly FetchStep: {
|
|
@@ -909,4 +1082,4 @@ declare const astSchema: {
|
|
|
909
1082
|
};
|
|
910
1083
|
};
|
|
911
1084
|
|
|
912
|
-
export { type ActionDefinition, type ActionStep, BINARY_OPERATORS, type BinExpr, type BinaryOperator, type ComponentDef, type ComponentNode, type ConstelaAst, ConstelaError, type EachNode, type ElementNode, type ErrorCode, type EventHandler, type Expression, type FetchStep, HTTP_METHODS, type HttpMethod, type IfNode, type ListField, type LitExpr, type NotExpr, type NumberField, PARAM_TYPES, type ParamDef, type ParamExpr, type ParamType, type Program, type SetStep, type SlotNode, type StateExpr, type StateField, type StringField, type TextNode, UPDATE_OPERATIONS, type UpdateOperation, type UpdateStep, type ValidationFailure, type ValidationResult, type ValidationSuccess, type VarExpr, type ViewNode, astSchema, createComponentCycleError, createComponentNotFoundError, createComponentPropMissingError, createComponentPropTypeError, createDuplicateActionError, createSchemaError, createUndefinedActionError, createUndefinedParamError, createUndefinedStateError, createUndefinedVarError, createUnsupportedVersionError, isActionStep, isBinExpr, isComponentNode, isConstelaError, isEachNode, isElementNode, isEventHandler, isExpression, isFetchStep, isIfNode, isListField, isLitExpr, isNotExpr, isNumberField, isParamExpr, isSetStep, isSlotNode, isStateExpr, isStateField, isStringField, isTextNode, isUpdateStep, isVarExpr, isViewNode, validateAst };
|
|
1085
|
+
export { type ActionDefinition, type ActionStep, BINARY_OPERATORS, type BinExpr, type BinaryOperator, type BooleanField, type ComponentDef, type ComponentNode, type CondExpr, type ConstelaAst, ConstelaError, type EachNode, type ElementNode, type ErrorCode, type EventHandler, type Expression, type FetchStep, type GetExpr, HTTP_METHODS, type HttpMethod, type IfNode, type ListField, type LitExpr, type NotExpr, type NumberField, type ObjectField, PARAM_TYPES, type ParamDef, type ParamExpr, type ParamType, type Program, type SetStep, type SlotNode, type StateExpr, type StateField, type StringField, type TextNode, UPDATE_OPERATIONS, type UpdateOperation, type UpdateStep, type ValidationFailure, type ValidationResult, type ValidationSuccess, type VarExpr, type ViewNode, astSchema, createComponentCycleError, createComponentNotFoundError, createComponentPropMissingError, createComponentPropTypeError, createCondElseRequiredError, createDuplicateActionError, createOperationInvalidForTypeError, createOperationMissingFieldError, createOperationUnknownError, createSchemaError, createUndefinedActionError, createUndefinedParamError, createUndefinedStateError, createUndefinedVarError, createUnsupportedVersionError, isActionStep, isBinExpr, isBooleanField, isComponentNode, isCondExpr, isConstelaError, isEachNode, isElementNode, isEventHandler, isExpression, isFetchStep, isGetExpr, isIfNode, isListField, isLitExpr, isNotExpr, isNumberField, isObjectField, isParamExpr, isSetStep, isSlotNode, isStateExpr, isStateField, isStringField, isTextNode, isUpdateStep, isVarExpr, isViewNode, validateAst };
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,12 @@ var UPDATE_OPERATIONS = [
|
|
|
18
18
|
"decrement",
|
|
19
19
|
"push",
|
|
20
20
|
"pop",
|
|
21
|
-
"remove"
|
|
21
|
+
"remove",
|
|
22
|
+
"toggle",
|
|
23
|
+
"merge",
|
|
24
|
+
"replaceAt",
|
|
25
|
+
"insertAt",
|
|
26
|
+
"splice"
|
|
22
27
|
];
|
|
23
28
|
var HTTP_METHODS = ["GET", "POST", "PUT", "DELETE"];
|
|
24
29
|
var PARAM_TYPES = ["string", "number", "boolean", "json"];
|
|
@@ -66,8 +71,21 @@ function isParamExpr(value) {
|
|
|
66
71
|
}
|
|
67
72
|
return true;
|
|
68
73
|
}
|
|
74
|
+
function isCondExpr(value) {
|
|
75
|
+
if (!isObject(value)) return false;
|
|
76
|
+
if (value["expr"] !== "cond") return false;
|
|
77
|
+
if (!isObject(value["if"]) || !isObject(value["then"]) || !isObject(value["else"])) return false;
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
function isGetExpr(value) {
|
|
81
|
+
if (!isObject(value)) return false;
|
|
82
|
+
if (value["expr"] !== "get") return false;
|
|
83
|
+
if (!isObject(value["base"])) return false;
|
|
84
|
+
if (typeof value["path"] !== "string") return false;
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
69
87
|
function isExpression(value) {
|
|
70
|
-
return isLitExpr(value) || isStateExpr(value) || isVarExpr(value) || isBinExpr(value) || isNotExpr(value) || isParamExpr(value);
|
|
88
|
+
return isLitExpr(value) || isStateExpr(value) || isVarExpr(value) || isBinExpr(value) || isNotExpr(value) || isParamExpr(value) || isCondExpr(value) || isGetExpr(value);
|
|
71
89
|
}
|
|
72
90
|
function isElementNode(value) {
|
|
73
91
|
if (!isObject(value)) return false;
|
|
@@ -158,8 +176,18 @@ function isListField(value) {
|
|
|
158
176
|
if (value["type"] !== "list") return false;
|
|
159
177
|
return Array.isArray(value["initial"]);
|
|
160
178
|
}
|
|
179
|
+
function isBooleanField(value) {
|
|
180
|
+
if (!isObject(value)) return false;
|
|
181
|
+
if (value["type"] !== "boolean") return false;
|
|
182
|
+
return typeof value["initial"] === "boolean";
|
|
183
|
+
}
|
|
184
|
+
function isObjectField(value) {
|
|
185
|
+
if (!isObject(value)) return false;
|
|
186
|
+
if (value["type"] !== "object") return false;
|
|
187
|
+
return typeof value["initial"] === "object" && value["initial"] !== null;
|
|
188
|
+
}
|
|
161
189
|
function isStateField(value) {
|
|
162
|
-
return isNumberField(value) || isStringField(value) || isListField(value);
|
|
190
|
+
return isNumberField(value) || isStringField(value) || isListField(value) || isBooleanField(value) || isObjectField(value);
|
|
163
191
|
}
|
|
164
192
|
function isEventHandler(value) {
|
|
165
193
|
if (!isObject(value)) return false;
|
|
@@ -266,6 +294,34 @@ function createUndefinedParamError(paramName, path) {
|
|
|
266
294
|
path
|
|
267
295
|
);
|
|
268
296
|
}
|
|
297
|
+
function createOperationInvalidForTypeError(operation, stateType, path) {
|
|
298
|
+
return new ConstelaError(
|
|
299
|
+
"OPERATION_INVALID_FOR_TYPE",
|
|
300
|
+
`Operation '${operation}' is not valid for state type '${stateType}'`,
|
|
301
|
+
path
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
function createOperationMissingFieldError(operation, field, path) {
|
|
305
|
+
return new ConstelaError(
|
|
306
|
+
"OPERATION_MISSING_FIELD",
|
|
307
|
+
`Operation '${operation}' requires field '${field}'`,
|
|
308
|
+
path
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
function createOperationUnknownError(operation, path) {
|
|
312
|
+
return new ConstelaError(
|
|
313
|
+
"OPERATION_UNKNOWN",
|
|
314
|
+
`Unknown operation: '${operation}'`,
|
|
315
|
+
path
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
function createCondElseRequiredError(path) {
|
|
319
|
+
return new ConstelaError(
|
|
320
|
+
"EXPR_COND_ELSE_REQUIRED",
|
|
321
|
+
`Cond expression requires 'else' field`,
|
|
322
|
+
path
|
|
323
|
+
);
|
|
324
|
+
}
|
|
269
325
|
|
|
270
326
|
// src/schema/validator.ts
|
|
271
327
|
import Ajv from "ajv";
|
|
@@ -313,7 +369,9 @@ var astSchema = {
|
|
|
313
369
|
{ $ref: "#/$defs/VarExpr" },
|
|
314
370
|
{ $ref: "#/$defs/BinExpr" },
|
|
315
371
|
{ $ref: "#/$defs/NotExpr" },
|
|
316
|
-
{ $ref: "#/$defs/ParamExpr" }
|
|
372
|
+
{ $ref: "#/$defs/ParamExpr" },
|
|
373
|
+
{ $ref: "#/$defs/CondExpr" },
|
|
374
|
+
{ $ref: "#/$defs/GetExpr" }
|
|
317
375
|
]
|
|
318
376
|
},
|
|
319
377
|
LitExpr: {
|
|
@@ -385,12 +443,35 @@ var astSchema = {
|
|
|
385
443
|
path: { type: "string" }
|
|
386
444
|
}
|
|
387
445
|
},
|
|
446
|
+
CondExpr: {
|
|
447
|
+
type: "object",
|
|
448
|
+
required: ["expr", "if", "then", "else"],
|
|
449
|
+
additionalProperties: false,
|
|
450
|
+
properties: {
|
|
451
|
+
expr: { type: "string", const: "cond" },
|
|
452
|
+
if: { $ref: "#/$defs/Expression" },
|
|
453
|
+
then: { $ref: "#/$defs/Expression" },
|
|
454
|
+
else: { $ref: "#/$defs/Expression" }
|
|
455
|
+
}
|
|
456
|
+
},
|
|
457
|
+
GetExpr: {
|
|
458
|
+
type: "object",
|
|
459
|
+
required: ["expr", "base", "path"],
|
|
460
|
+
additionalProperties: false,
|
|
461
|
+
properties: {
|
|
462
|
+
expr: { type: "string", const: "get" },
|
|
463
|
+
base: { $ref: "#/$defs/Expression" },
|
|
464
|
+
path: { type: "string" }
|
|
465
|
+
}
|
|
466
|
+
},
|
|
388
467
|
// ==================== State Fields ====================
|
|
389
468
|
StateField: {
|
|
390
469
|
oneOf: [
|
|
391
470
|
{ $ref: "#/$defs/NumberField" },
|
|
392
471
|
{ $ref: "#/$defs/StringField" },
|
|
393
|
-
{ $ref: "#/$defs/ListField" }
|
|
472
|
+
{ $ref: "#/$defs/ListField" },
|
|
473
|
+
{ $ref: "#/$defs/BooleanField" },
|
|
474
|
+
{ $ref: "#/$defs/ObjectField" }
|
|
394
475
|
]
|
|
395
476
|
},
|
|
396
477
|
NumberField: {
|
|
@@ -420,6 +501,24 @@ var astSchema = {
|
|
|
420
501
|
initial: { type: "array" }
|
|
421
502
|
}
|
|
422
503
|
},
|
|
504
|
+
BooleanField: {
|
|
505
|
+
type: "object",
|
|
506
|
+
required: ["type", "initial"],
|
|
507
|
+
additionalProperties: false,
|
|
508
|
+
properties: {
|
|
509
|
+
type: { type: "string", const: "boolean" },
|
|
510
|
+
initial: { type: "boolean" }
|
|
511
|
+
}
|
|
512
|
+
},
|
|
513
|
+
ObjectField: {
|
|
514
|
+
type: "object",
|
|
515
|
+
required: ["type", "initial"],
|
|
516
|
+
additionalProperties: false,
|
|
517
|
+
properties: {
|
|
518
|
+
type: { type: "string", const: "object" },
|
|
519
|
+
initial: { type: "object" }
|
|
520
|
+
}
|
|
521
|
+
},
|
|
423
522
|
// ==================== Action Steps ====================
|
|
424
523
|
ActionStep: {
|
|
425
524
|
oneOf: [
|
|
@@ -447,9 +546,11 @@ var astSchema = {
|
|
|
447
546
|
target: { type: "string" },
|
|
448
547
|
operation: {
|
|
449
548
|
type: "string",
|
|
450
|
-
enum: ["increment", "decrement", "push", "pop", "remove"]
|
|
549
|
+
enum: ["increment", "decrement", "push", "pop", "remove", "toggle", "merge", "replaceAt", "insertAt", "splice"]
|
|
451
550
|
},
|
|
452
|
-
value: { $ref: "#/$defs/Expression" }
|
|
551
|
+
value: { $ref: "#/$defs/Expression" },
|
|
552
|
+
index: { $ref: "#/$defs/Expression" },
|
|
553
|
+
deleteCount: { $ref: "#/$defs/Expression" }
|
|
453
554
|
}
|
|
454
555
|
},
|
|
455
556
|
FetchStep: {
|
|
@@ -632,7 +733,7 @@ var VALID_VIEW_KINDS = ["element", "text", "if", "each", "component", "slot"];
|
|
|
632
733
|
var VALID_EXPR_TYPES = ["lit", "state", "var", "bin", "not", "param"];
|
|
633
734
|
var VALID_PARAM_TYPES = ["string", "number", "boolean", "json"];
|
|
634
735
|
var VALID_ACTION_TYPES = ["set", "update", "fetch"];
|
|
635
|
-
var VALID_STATE_TYPES = ["number", "string", "list"];
|
|
736
|
+
var VALID_STATE_TYPES = ["number", "string", "list", "boolean", "object"];
|
|
636
737
|
var VALID_BIN_OPS = BINARY_OPERATORS;
|
|
637
738
|
var VALID_UPDATE_OPS = UPDATE_OPERATIONS;
|
|
638
739
|
var VALID_HTTP_METHODS = HTTP_METHODS;
|
|
@@ -874,6 +975,16 @@ function validateStateField(field, path) {
|
|
|
874
975
|
return { path: path + "/initial", message: "must be an array" };
|
|
875
976
|
}
|
|
876
977
|
break;
|
|
978
|
+
case "boolean":
|
|
979
|
+
if (typeof field["initial"] !== "boolean") {
|
|
980
|
+
return { path: path + "/initial", message: "must be a boolean" };
|
|
981
|
+
}
|
|
982
|
+
break;
|
|
983
|
+
case "object":
|
|
984
|
+
if (!isObject2(field["initial"])) {
|
|
985
|
+
return { path: path + "/initial", message: "must be an object" };
|
|
986
|
+
}
|
|
987
|
+
break;
|
|
877
988
|
}
|
|
878
989
|
return null;
|
|
879
990
|
}
|
|
@@ -1145,7 +1256,11 @@ export {
|
|
|
1145
1256
|
createComponentNotFoundError,
|
|
1146
1257
|
createComponentPropMissingError,
|
|
1147
1258
|
createComponentPropTypeError,
|
|
1259
|
+
createCondElseRequiredError,
|
|
1148
1260
|
createDuplicateActionError,
|
|
1261
|
+
createOperationInvalidForTypeError,
|
|
1262
|
+
createOperationMissingFieldError,
|
|
1263
|
+
createOperationUnknownError,
|
|
1149
1264
|
createSchemaError,
|
|
1150
1265
|
createUndefinedActionError,
|
|
1151
1266
|
createUndefinedParamError,
|
|
@@ -1154,18 +1269,22 @@ export {
|
|
|
1154
1269
|
createUnsupportedVersionError,
|
|
1155
1270
|
isActionStep,
|
|
1156
1271
|
isBinExpr,
|
|
1272
|
+
isBooleanField,
|
|
1157
1273
|
isComponentNode,
|
|
1274
|
+
isCondExpr,
|
|
1158
1275
|
isConstelaError,
|
|
1159
1276
|
isEachNode,
|
|
1160
1277
|
isElementNode,
|
|
1161
1278
|
isEventHandler,
|
|
1162
1279
|
isExpression,
|
|
1163
1280
|
isFetchStep,
|
|
1281
|
+
isGetExpr,
|
|
1164
1282
|
isIfNode,
|
|
1165
1283
|
isListField,
|
|
1166
1284
|
isLitExpr,
|
|
1167
1285
|
isNotExpr,
|
|
1168
1286
|
isNumberField,
|
|
1287
|
+
isObjectField,
|
|
1169
1288
|
isParamExpr,
|
|
1170
1289
|
isSetStep,
|
|
1171
1290
|
isSlotNode,
|