@constela/runtime 0.17.0 → 0.18.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
@@ -163,6 +163,41 @@ Close connection:
163
163
  { "do": "close", "connection": "chat" }
164
164
  ```
165
165
 
166
+ ### Call/Lambda Expressions
167
+
168
+ Call methods on arrays, strings, Math, and Date:
169
+
170
+ ```json
171
+ // Filter completed todos
172
+ {
173
+ "expr": "call",
174
+ "target": { "expr": "state", "name": "todos" },
175
+ "method": "filter",
176
+ "args": [{
177
+ "expr": "lambda",
178
+ "param": "todo",
179
+ "body": { "expr": "get", "base": { "expr": "var", "name": "todo" }, "path": "completed" }
180
+ }]
181
+ }
182
+
183
+ // Get array length
184
+ { "expr": "call", "target": { "expr": "state", "name": "items" }, "method": "length" }
185
+
186
+ // Math.max
187
+ {
188
+ "expr": "call",
189
+ "target": { "expr": "var", "name": "Math" },
190
+ "method": "max",
191
+ "args": [{ "expr": "lit", "value": 10 }, { "expr": "state", "name": "count" }]
192
+ }
193
+ ```
194
+
195
+ **Supported methods:**
196
+ - Array: length, at, includes, slice, indexOf, join, filter, map, find, findIndex, some, every
197
+ - String: length, charAt, substring, slice, split, trim, toUpperCase, toLowerCase, replace, includes, startsWith, endsWith, indexOf
198
+ - Math: min, max, round, floor, ceil, abs, sqrt, pow, random, sin, cos, tan
199
+ - Date: now, parse, toISOString, getTime, getFullYear, getMonth, getDate, getHours, getMinutes, getSeconds, getMilliseconds
200
+
166
201
  ### Markdown Rendering
167
202
 
168
203
  ```json
package/dist/index.js CHANGED
@@ -583,9 +583,9 @@ function callMathMethod(method, args) {
583
583
  const numbers = args.filter((a) => typeof a === "number");
584
584
  switch (method) {
585
585
  case "min":
586
- return Math.min(...numbers);
586
+ return numbers.length > 0 ? Math.min(...numbers) : void 0;
587
587
  case "max":
588
- return Math.max(...numbers);
588
+ return numbers.length > 0 ? Math.max(...numbers) : void 0;
589
589
  case "round": {
590
590
  const num = numbers[0];
591
591
  return num !== void 0 ? Math.round(num) : void 0;
@@ -846,6 +846,10 @@ function evaluate(expr, ctx) {
846
846
  }
847
847
  case "lambda":
848
848
  return void 0;
849
+ case "array": {
850
+ const arrayExpr = expr;
851
+ return arrayExpr.elements.map((elem) => evaluate(elem, ctx));
852
+ }
849
853
  default: {
850
854
  const _exhaustiveCheck = expr;
851
855
  throw new Error(`Unknown expression type: ${JSON.stringify(_exhaustiveCheck)}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/runtime",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "Runtime DOM renderer for Constela UI framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,8 +18,8 @@
18
18
  "dompurify": "^3.3.1",
19
19
  "marked": "^17.0.1",
20
20
  "shiki": "^3.20.0",
21
- "@constela/compiler": "0.13.0",
22
- "@constela/core": "0.14.0"
21
+ "@constela/compiler": "0.14.0",
22
+ "@constela/core": "0.15.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/dompurify": "^3.2.0",
@@ -29,7 +29,7 @@
29
29
  "tsup": "^8.0.0",
30
30
  "typescript": "^5.3.0",
31
31
  "vitest": "^2.0.0",
32
- "@constela/server": "10.0.1"
32
+ "@constela/server": "11.0.1"
33
33
  },
34
34
  "engines": {
35
35
  "node": ">=20.0.0"