@constela/server 0.1.2 → 1.0.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.
Files changed (2) hide show
  1. package/dist/index.js +47 -0
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -136,12 +136,59 @@ function evaluate(expr, ctx) {
136
136
  }
137
137
  return value;
138
138
  }
139
+ case "route": {
140
+ const source = expr.source ?? "param";
141
+ const routeCtx = ctx.route;
142
+ if (!routeCtx) return "";
143
+ switch (source) {
144
+ case "param":
145
+ return routeCtx.params[expr.name] ?? "";
146
+ case "query":
147
+ return routeCtx.query[expr.name] ?? "";
148
+ case "path":
149
+ return routeCtx.path;
150
+ }
151
+ }
152
+ case "import": {
153
+ const importData = ctx.imports?.[expr.name];
154
+ if (importData === void 0) return void 0;
155
+ if (expr.path) {
156
+ return getNestedValue(importData, expr.path);
157
+ }
158
+ return importData;
159
+ }
139
160
  default: {
140
161
  const _exhaustiveCheck = expr;
141
162
  throw new Error(`Unknown expression type: ${JSON.stringify(_exhaustiveCheck)}`);
142
163
  }
143
164
  }
144
165
  }
166
+ function getNestedValue(obj, path) {
167
+ const forbiddenKeys = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
168
+ const parts = path.split(".");
169
+ let value = obj;
170
+ for (const part of parts) {
171
+ if (forbiddenKeys.has(part)) {
172
+ return void 0;
173
+ }
174
+ if (value == null) {
175
+ return void 0;
176
+ }
177
+ if (Array.isArray(value)) {
178
+ const index = Number(part);
179
+ if (Number.isInteger(index) && index >= 0) {
180
+ value = value[index];
181
+ } else {
182
+ value = value[part];
183
+ }
184
+ } else if (typeof value === "object") {
185
+ value = value[part];
186
+ } else {
187
+ return void 0;
188
+ }
189
+ }
190
+ return value;
191
+ }
145
192
  function evaluateBinary(op, left, right, ctx) {
146
193
  if (op === "&&") {
147
194
  const leftVal2 = evaluate(left, ctx);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/server",
3
- "version": "0.1.2",
3
+ "version": "1.0.0",
4
4
  "description": "Server-side rendering for Constela UI framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -15,7 +15,7 @@
15
15
  "dist"
16
16
  ],
17
17
  "peerDependencies": {
18
- "@constela/compiler": "^0.4.0"
18
+ "@constela/compiler": "^0.5.0"
19
19
  },
20
20
  "dependencies": {
21
21
  "isomorphic-dompurify": "^2.35.0",
@@ -27,7 +27,7 @@
27
27
  "tsup": "^8.0.0",
28
28
  "typescript": "^5.3.0",
29
29
  "vitest": "^2.0.0",
30
- "@constela/compiler": "0.4.0"
30
+ "@constela/compiler": "0.5.0"
31
31
  },
32
32
  "engines": {
33
33
  "node": ">=20.0.0"