@constela/core 0.3.3 → 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 +56 -4
- 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,7 +339,7 @@ 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"];
|
|
342
|
+
var VALID_VIEW_KINDS = ["element", "text", "if", "each", "component", "slot", "markdown", "code"];
|
|
331
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"];
|
|
@@ -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
|
}
|
|
@@ -1137,7 +1166,9 @@ var astSchema = {
|
|
|
1137
1166
|
{ $ref: "#/$defs/IfNode" },
|
|
1138
1167
|
{ $ref: "#/$defs/EachNode" },
|
|
1139
1168
|
{ $ref: "#/$defs/ComponentNode" },
|
|
1140
|
-
{ $ref: "#/$defs/SlotNode" }
|
|
1169
|
+
{ $ref: "#/$defs/SlotNode" },
|
|
1170
|
+
{ $ref: "#/$defs/MarkdownNode" },
|
|
1171
|
+
{ $ref: "#/$defs/CodeNode" }
|
|
1141
1172
|
]
|
|
1142
1173
|
},
|
|
1143
1174
|
ElementNode: {
|
|
@@ -1220,6 +1251,25 @@ var astSchema = {
|
|
|
1220
1251
|
kind: { type: "string", const: "slot" }
|
|
1221
1252
|
}
|
|
1222
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
|
+
},
|
|
1223
1273
|
// ==================== Component Definition ====================
|
|
1224
1274
|
ParamDef: {
|
|
1225
1275
|
type: "object",
|
|
@@ -1272,6 +1322,7 @@ export {
|
|
|
1272
1322
|
isActionStep,
|
|
1273
1323
|
isBinExpr,
|
|
1274
1324
|
isBooleanField,
|
|
1325
|
+
isCodeNode,
|
|
1275
1326
|
isComponentNode,
|
|
1276
1327
|
isCondExpr,
|
|
1277
1328
|
isConstelaError,
|
|
@@ -1284,6 +1335,7 @@ export {
|
|
|
1284
1335
|
isIfNode,
|
|
1285
1336
|
isListField,
|
|
1286
1337
|
isLitExpr,
|
|
1338
|
+
isMarkdownNode,
|
|
1287
1339
|
isNotExpr,
|
|
1288
1340
|
isNumberField,
|
|
1289
1341
|
isObjectField,
|