@constela/server 0.1.2 → 2.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.
- package/dist/index.js +49 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -136,12 +136,61 @@ 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
|
+
}
|
|
160
|
+
case "ref":
|
|
161
|
+
return null;
|
|
139
162
|
default: {
|
|
140
163
|
const _exhaustiveCheck = expr;
|
|
141
164
|
throw new Error(`Unknown expression type: ${JSON.stringify(_exhaustiveCheck)}`);
|
|
142
165
|
}
|
|
143
166
|
}
|
|
144
167
|
}
|
|
168
|
+
function getNestedValue(obj, path) {
|
|
169
|
+
const forbiddenKeys = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
170
|
+
const parts = path.split(".");
|
|
171
|
+
let value = obj;
|
|
172
|
+
for (const part of parts) {
|
|
173
|
+
if (forbiddenKeys.has(part)) {
|
|
174
|
+
return void 0;
|
|
175
|
+
}
|
|
176
|
+
if (value == null) {
|
|
177
|
+
return void 0;
|
|
178
|
+
}
|
|
179
|
+
if (Array.isArray(value)) {
|
|
180
|
+
const index = Number(part);
|
|
181
|
+
if (Number.isInteger(index) && index >= 0) {
|
|
182
|
+
value = value[index];
|
|
183
|
+
} else {
|
|
184
|
+
value = value[part];
|
|
185
|
+
}
|
|
186
|
+
} else if (typeof value === "object") {
|
|
187
|
+
value = value[part];
|
|
188
|
+
} else {
|
|
189
|
+
return void 0;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return value;
|
|
193
|
+
}
|
|
145
194
|
function evaluateBinary(op, left, right, ctx) {
|
|
146
195
|
if (op === "&&") {
|
|
147
196
|
const leftVal2 = evaluate(left, ctx);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constela/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "2.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.
|
|
18
|
+
"@constela/compiler": "^0.6.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.
|
|
30
|
+
"@constela/compiler": "0.6.0"
|
|
31
31
|
},
|
|
32
32
|
"engines": {
|
|
33
33
|
"node": ">=20.0.0"
|