@constela/core 0.3.2 → 0.4.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 +60 -2
- package/dist/index.js +85 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -231,7 +231,22 @@ interface ComponentNode {
|
|
|
231
231
|
interface SlotNode {
|
|
232
232
|
kind: 'slot';
|
|
233
233
|
}
|
|
234
|
-
|
|
234
|
+
/**
|
|
235
|
+
* Markdown node - renders markdown content
|
|
236
|
+
*/
|
|
237
|
+
interface MarkdownNode {
|
|
238
|
+
kind: 'markdown';
|
|
239
|
+
content: Expression;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Code node - renders syntax-highlighted code
|
|
243
|
+
*/
|
|
244
|
+
interface CodeNode {
|
|
245
|
+
kind: 'code';
|
|
246
|
+
language: Expression;
|
|
247
|
+
content: Expression;
|
|
248
|
+
}
|
|
249
|
+
type ViewNode = ElementNode | TextNode | IfNode | EachNode | ComponentNode | SlotNode | MarkdownNode | CodeNode;
|
|
235
250
|
interface ComponentDef {
|
|
236
251
|
params?: Record<string, ParamDef>;
|
|
237
252
|
view: ViewNode;
|
|
@@ -338,6 +353,14 @@ declare function isComponentNode(value: unknown): value is ComponentNode;
|
|
|
338
353
|
* Checks if value is a slot node
|
|
339
354
|
*/
|
|
340
355
|
declare function isSlotNode(value: unknown): value is SlotNode;
|
|
356
|
+
/**
|
|
357
|
+
* Checks if value is a markdown node
|
|
358
|
+
*/
|
|
359
|
+
declare function isMarkdownNode(value: unknown): value is MarkdownNode;
|
|
360
|
+
/**
|
|
361
|
+
* Checks if value is a code node
|
|
362
|
+
*/
|
|
363
|
+
declare function isCodeNode(value: unknown): value is CodeNode;
|
|
341
364
|
/**
|
|
342
365
|
* Checks if value is any valid view node
|
|
343
366
|
*/
|
|
@@ -921,6 +944,10 @@ declare const astSchema: {
|
|
|
921
944
|
readonly $ref: "#/$defs/ComponentNode";
|
|
922
945
|
}, {
|
|
923
946
|
readonly $ref: "#/$defs/SlotNode";
|
|
947
|
+
}, {
|
|
948
|
+
readonly $ref: "#/$defs/MarkdownNode";
|
|
949
|
+
}, {
|
|
950
|
+
readonly $ref: "#/$defs/CodeNode";
|
|
924
951
|
}];
|
|
925
952
|
};
|
|
926
953
|
readonly ElementNode: {
|
|
@@ -1050,6 +1077,37 @@ declare const astSchema: {
|
|
|
1050
1077
|
};
|
|
1051
1078
|
};
|
|
1052
1079
|
};
|
|
1080
|
+
readonly MarkdownNode: {
|
|
1081
|
+
readonly type: "object";
|
|
1082
|
+
readonly required: readonly ["kind", "content"];
|
|
1083
|
+
readonly additionalProperties: false;
|
|
1084
|
+
readonly properties: {
|
|
1085
|
+
readonly kind: {
|
|
1086
|
+
readonly type: "string";
|
|
1087
|
+
readonly const: "markdown";
|
|
1088
|
+
};
|
|
1089
|
+
readonly content: {
|
|
1090
|
+
readonly $ref: "#/$defs/Expression";
|
|
1091
|
+
};
|
|
1092
|
+
};
|
|
1093
|
+
};
|
|
1094
|
+
readonly CodeNode: {
|
|
1095
|
+
readonly type: "object";
|
|
1096
|
+
readonly required: readonly ["kind", "language", "content"];
|
|
1097
|
+
readonly additionalProperties: false;
|
|
1098
|
+
readonly properties: {
|
|
1099
|
+
readonly kind: {
|
|
1100
|
+
readonly type: "string";
|
|
1101
|
+
readonly const: "code";
|
|
1102
|
+
};
|
|
1103
|
+
readonly language: {
|
|
1104
|
+
readonly $ref: "#/$defs/Expression";
|
|
1105
|
+
};
|
|
1106
|
+
readonly content: {
|
|
1107
|
+
readonly $ref: "#/$defs/Expression";
|
|
1108
|
+
};
|
|
1109
|
+
};
|
|
1110
|
+
};
|
|
1053
1111
|
readonly ParamDef: {
|
|
1054
1112
|
readonly type: "object";
|
|
1055
1113
|
readonly required: readonly ["type"];
|
|
@@ -1083,4 +1141,4 @@ declare const astSchema: {
|
|
|
1083
1141
|
};
|
|
1084
1142
|
};
|
|
1085
1143
|
|
|
1086
|
-
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 };
|
|
1144
|
+
export { type ActionDefinition, type ActionStep, BINARY_OPERATORS, type BinExpr, type BinaryOperator, type BooleanField, type CodeNode, 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 MarkdownNode, 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, isCodeNode, isComponentNode, isCondExpr, isConstelaError, isEachNode, isElementNode, isEventHandler, isExpression, isFetchStep, isGetExpr, isIfNode, isListField, isLitExpr, isMarkdownNode, isNotExpr, isNumberField, isObjectField, isParamExpr, isSetStep, isSlotNode, isStateExpr, isStateField, isStringField, isTextNode, isUpdateStep, isVarExpr, isViewNode, validateAst };
|
package/dist/index.js
CHANGED
|
@@ -128,8 +128,20 @@ function isSlotNode(value) {
|
|
|
128
128
|
if (!isObject(value)) return false;
|
|
129
129
|
return value["kind"] === "slot";
|
|
130
130
|
}
|
|
131
|
+
function isMarkdownNode(value) {
|
|
132
|
+
if (!isObject(value)) return false;
|
|
133
|
+
if (value["kind"] !== "markdown") return false;
|
|
134
|
+
return "content" in value && isObject(value["content"]);
|
|
135
|
+
}
|
|
136
|
+
function isCodeNode(value) {
|
|
137
|
+
if (!isObject(value)) return false;
|
|
138
|
+
if (value["kind"] !== "code") return false;
|
|
139
|
+
if (!("language" in value) || !isObject(value["language"])) return false;
|
|
140
|
+
if (!("content" in value) || !isObject(value["content"])) return false;
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
131
143
|
function isViewNode(value) {
|
|
132
|
-
return isElementNode(value) || isTextNode(value) || isIfNode(value) || isEachNode(value) || isComponentNode(value) || isSlotNode(value);
|
|
144
|
+
return isElementNode(value) || isTextNode(value) || isIfNode(value) || isEachNode(value) || isComponentNode(value) || isSlotNode(value) || isMarkdownNode(value) || isCodeNode(value);
|
|
133
145
|
}
|
|
134
146
|
function isSetStep(value) {
|
|
135
147
|
if (!isObject(value)) return false;
|
|
@@ -327,8 +339,8 @@ function createCondElseRequiredError(path) {
|
|
|
327
339
|
function isObject2(value) {
|
|
328
340
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
329
341
|
}
|
|
330
|
-
var VALID_VIEW_KINDS = ["element", "text", "if", "each", "component", "slot"];
|
|
331
|
-
var VALID_EXPR_TYPES = ["lit", "state", "var", "bin", "not", "param"];
|
|
342
|
+
var VALID_VIEW_KINDS = ["element", "text", "if", "each", "component", "slot", "markdown", "code"];
|
|
343
|
+
var VALID_EXPR_TYPES = ["lit", "state", "var", "bin", "not", "param", "cond", "get"];
|
|
332
344
|
var VALID_PARAM_TYPES = ["string", "number", "boolean", "json"];
|
|
333
345
|
var VALID_ACTION_TYPES = ["set", "update", "fetch"];
|
|
334
346
|
var VALID_STATE_TYPES = ["number", "string", "list", "boolean", "object"];
|
|
@@ -344,7 +356,7 @@ function validateViewNode(node, path) {
|
|
|
344
356
|
return { path: path + "/kind", message: "kind is required" };
|
|
345
357
|
}
|
|
346
358
|
if (!VALID_VIEW_KINDS.includes(kind)) {
|
|
347
|
-
return { path: path + "/kind", message: "must be one of: element, text, if, each, component, slot" };
|
|
359
|
+
return { path: path + "/kind", message: "must be one of: element, text, if, each, component, slot, markdown, code" };
|
|
348
360
|
}
|
|
349
361
|
switch (kind) {
|
|
350
362
|
case "element":
|
|
@@ -426,6 +438,23 @@ function validateViewNode(node, path) {
|
|
|
426
438
|
break;
|
|
427
439
|
case "slot":
|
|
428
440
|
break;
|
|
441
|
+
case "markdown":
|
|
442
|
+
if (!("content" in node)) {
|
|
443
|
+
return { path: path + "/content", message: "content is required" };
|
|
444
|
+
}
|
|
445
|
+
return validateExpression(node["content"], path + "/content");
|
|
446
|
+
case "code":
|
|
447
|
+
if (!("language" in node)) {
|
|
448
|
+
return { path: path + "/language", message: "language is required" };
|
|
449
|
+
}
|
|
450
|
+
if (!("content" in node)) {
|
|
451
|
+
return { path: path + "/content", message: "content is required" };
|
|
452
|
+
}
|
|
453
|
+
{
|
|
454
|
+
const langError = validateExpression(node["language"], path + "/language");
|
|
455
|
+
if (langError) return langError;
|
|
456
|
+
return validateExpression(node["content"], path + "/content");
|
|
457
|
+
}
|
|
429
458
|
}
|
|
430
459
|
return null;
|
|
431
460
|
}
|
|
@@ -438,7 +467,7 @@ function validateExpression(expr, path) {
|
|
|
438
467
|
return { path: path + "/expr", message: "expr is required" };
|
|
439
468
|
}
|
|
440
469
|
if (!VALID_EXPR_TYPES.includes(exprType)) {
|
|
441
|
-
return { path: path + "/expr", message: "must be one of: lit, state, var, bin, not, param" };
|
|
470
|
+
return { path: path + "/expr", message: "must be one of: lit, state, var, bin, not, param, cond, get" };
|
|
442
471
|
}
|
|
443
472
|
switch (exprType) {
|
|
444
473
|
case "lit":
|
|
@@ -485,6 +514,33 @@ function validateExpression(expr, path) {
|
|
|
485
514
|
return { path: path + "/path", message: "path must be a string" };
|
|
486
515
|
}
|
|
487
516
|
break;
|
|
517
|
+
case "cond":
|
|
518
|
+
if (!("if" in expr)) {
|
|
519
|
+
return { path: path + "/if", message: "if is required" };
|
|
520
|
+
}
|
|
521
|
+
if (!("then" in expr)) {
|
|
522
|
+
return { path: path + "/then", message: "then is required" };
|
|
523
|
+
}
|
|
524
|
+
if (!("else" in expr)) {
|
|
525
|
+
return { path: path + "/else", message: "else is required" };
|
|
526
|
+
}
|
|
527
|
+
{
|
|
528
|
+
const ifError = validateExpression(expr["if"], path + "/if");
|
|
529
|
+
if (ifError) return ifError;
|
|
530
|
+
const thenError = validateExpression(expr["then"], path + "/then");
|
|
531
|
+
if (thenError) return thenError;
|
|
532
|
+
const elseError = validateExpression(expr["else"], path + "/else");
|
|
533
|
+
if (elseError) return elseError;
|
|
534
|
+
}
|
|
535
|
+
break;
|
|
536
|
+
case "get":
|
|
537
|
+
if (!("base" in expr)) {
|
|
538
|
+
return { path: path + "/base", message: "base is required" };
|
|
539
|
+
}
|
|
540
|
+
if (typeof expr["path"] !== "string") {
|
|
541
|
+
return { path: path + "/path", message: "path is required" };
|
|
542
|
+
}
|
|
543
|
+
return validateExpression(expr["base"], path + "/base");
|
|
488
544
|
}
|
|
489
545
|
return null;
|
|
490
546
|
}
|
|
@@ -1110,7 +1166,9 @@ var astSchema = {
|
|
|
1110
1166
|
{ $ref: "#/$defs/IfNode" },
|
|
1111
1167
|
{ $ref: "#/$defs/EachNode" },
|
|
1112
1168
|
{ $ref: "#/$defs/ComponentNode" },
|
|
1113
|
-
{ $ref: "#/$defs/SlotNode" }
|
|
1169
|
+
{ $ref: "#/$defs/SlotNode" },
|
|
1170
|
+
{ $ref: "#/$defs/MarkdownNode" },
|
|
1171
|
+
{ $ref: "#/$defs/CodeNode" }
|
|
1114
1172
|
]
|
|
1115
1173
|
},
|
|
1116
1174
|
ElementNode: {
|
|
@@ -1193,6 +1251,25 @@ var astSchema = {
|
|
|
1193
1251
|
kind: { type: "string", const: "slot" }
|
|
1194
1252
|
}
|
|
1195
1253
|
},
|
|
1254
|
+
MarkdownNode: {
|
|
1255
|
+
type: "object",
|
|
1256
|
+
required: ["kind", "content"],
|
|
1257
|
+
additionalProperties: false,
|
|
1258
|
+
properties: {
|
|
1259
|
+
kind: { type: "string", const: "markdown" },
|
|
1260
|
+
content: { $ref: "#/$defs/Expression" }
|
|
1261
|
+
}
|
|
1262
|
+
},
|
|
1263
|
+
CodeNode: {
|
|
1264
|
+
type: "object",
|
|
1265
|
+
required: ["kind", "language", "content"],
|
|
1266
|
+
additionalProperties: false,
|
|
1267
|
+
properties: {
|
|
1268
|
+
kind: { type: "string", const: "code" },
|
|
1269
|
+
language: { $ref: "#/$defs/Expression" },
|
|
1270
|
+
content: { $ref: "#/$defs/Expression" }
|
|
1271
|
+
}
|
|
1272
|
+
},
|
|
1196
1273
|
// ==================== Component Definition ====================
|
|
1197
1274
|
ParamDef: {
|
|
1198
1275
|
type: "object",
|
|
@@ -1245,6 +1322,7 @@ export {
|
|
|
1245
1322
|
isActionStep,
|
|
1246
1323
|
isBinExpr,
|
|
1247
1324
|
isBooleanField,
|
|
1325
|
+
isCodeNode,
|
|
1248
1326
|
isComponentNode,
|
|
1249
1327
|
isCondExpr,
|
|
1250
1328
|
isConstelaError,
|
|
@@ -1257,6 +1335,7 @@ export {
|
|
|
1257
1335
|
isIfNode,
|
|
1258
1336
|
isListField,
|
|
1259
1337
|
isLitExpr,
|
|
1338
|
+
isMarkdownNode,
|
|
1260
1339
|
isNotExpr,
|
|
1261
1340
|
isNumberField,
|
|
1262
1341
|
isObjectField,
|