@constela/server 14.0.1 → 14.0.3

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.
Files changed (2) hide show
  1. package/dist/index.js +28 -2
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -537,6 +537,14 @@ function evaluate(expr, ctx) {
537
537
  const arrayExpr = expr;
538
538
  return arrayExpr.elements.map((elem) => evaluate(elem, ctx));
539
539
  }
540
+ case "obj": {
541
+ const objExpr = expr;
542
+ const result = {};
543
+ for (const [key, value] of Object.entries(objExpr.props)) {
544
+ result[key] = evaluate(value, ctx);
545
+ }
546
+ return result;
547
+ }
540
548
  default: {
541
549
  const _exhaustiveCheck = expr;
542
550
  throw new Error(`Unknown expression type: ${JSON.stringify(_exhaustiveCheck)}`);
@@ -794,7 +802,12 @@ async function renderPortal(node, ctx) {
794
802
  async function renderLocalState(node, ctx) {
795
803
  const localStateValues = {};
796
804
  for (const [name, field] of Object.entries(node.state)) {
797
- localStateValues[name] = field.initial;
805
+ const initial = field.initial;
806
+ if (initial && typeof initial === "object" && "expr" in initial) {
807
+ localStateValues[name] = evaluate(initial, ctx);
808
+ } else {
809
+ localStateValues[name] = initial;
810
+ }
798
811
  }
799
812
  const childCtx = {
800
813
  ...ctx,
@@ -1293,6 +1306,14 @@ function evaluate2(expr, ctx) {
1293
1306
  const arrayExpr = expr;
1294
1307
  return arrayExpr.elements.map((elem) => evaluate2(elem, ctx));
1295
1308
  }
1309
+ case "obj": {
1310
+ const objExpr = expr;
1311
+ const result = {};
1312
+ for (const [key, value] of Object.entries(objExpr.props)) {
1313
+ result[key] = evaluate2(value, ctx);
1314
+ }
1315
+ return result;
1316
+ }
1296
1317
  default: {
1297
1318
  return void 0;
1298
1319
  }
@@ -1604,7 +1625,12 @@ async function renderPortalToStream(node, ctx) {
1604
1625
  async function renderLocalStateToStream(node, ctx) {
1605
1626
  const localStateValues = {};
1606
1627
  for (const [name, field] of Object.entries(node.state)) {
1607
- localStateValues[name] = field.initial;
1628
+ const initial = field.initial;
1629
+ if (initial && typeof initial === "object" && "expr" in initial) {
1630
+ localStateValues[name] = evaluate2(initial, ctx);
1631
+ } else {
1632
+ localStateValues[name] = initial;
1633
+ }
1608
1634
  }
1609
1635
  const childCtx = {
1610
1636
  ...ctx,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/server",
3
- "version": "14.0.1",
3
+ "version": "14.0.3",
4
4
  "description": "Server-side rendering for Constela UI framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -15,8 +15,8 @@
15
15
  "dist"
16
16
  ],
17
17
  "peerDependencies": {
18
- "@constela/compiler": "^0.15.7",
19
- "@constela/core": "^0.18.1"
18
+ "@constela/compiler": "^0.15.8",
19
+ "@constela/core": "^0.18.2"
20
20
  },
21
21
  "dependencies": {
22
22
  "isomorphic-dompurify": "^2.35.0",
@@ -29,8 +29,8 @@
29
29
  "tsup": "^8.0.0",
30
30
  "typescript": "^5.3.0",
31
31
  "vitest": "^2.0.0",
32
- "@constela/core": "0.18.1",
33
- "@constela/compiler": "0.15.7"
32
+ "@constela/compiler": "0.15.8",
33
+ "@constela/core": "0.18.2"
34
34
  },
35
35
  "engines": {
36
36
  "node": ">=20.0.0"