mono-jsx 0.10.0-beta.2 → 0.10.0-beta.4
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 +34 -12
- package/jsx-runtime.mjs +15 -6
- package/package.json +2 -2
- package/types/mono.d.ts +4 -0
- package/types/render.d.ts +2 -1
package/README.md
CHANGED
|
@@ -1343,17 +1343,39 @@ export default {
|
|
|
1343
1343
|
### Session Storage API
|
|
1344
1344
|
|
|
1345
1345
|
```ts
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1346
|
+
export interface Session {
|
|
1347
|
+
/**
|
|
1348
|
+
* The session ID.
|
|
1349
|
+
*/
|
|
1350
|
+
readonly sessionId: string;
|
|
1351
|
+
/**
|
|
1352
|
+
* If true, update the session cookie to the client.
|
|
1353
|
+
*/
|
|
1354
|
+
readonly isDirty: boolean;
|
|
1355
|
+
/**
|
|
1356
|
+
* If true, the session is expired.
|
|
1357
|
+
*/
|
|
1358
|
+
readonly isExpired: boolean;
|
|
1359
|
+
/**
|
|
1360
|
+
* Gets a value from the session.
|
|
1361
|
+
*/
|
|
1362
|
+
get<T = unknown>(key: string): T | undefined;
|
|
1363
|
+
/**
|
|
1364
|
+
* Gets all the entries from the session.
|
|
1365
|
+
*/
|
|
1366
|
+
all(): Record<string, unknown>;
|
|
1367
|
+
/**
|
|
1368
|
+
* Sets a value in the session.
|
|
1369
|
+
*/
|
|
1370
|
+
set(key: string, value: string | number | boolean | any[] | Record<string, unknown>): void;
|
|
1371
|
+
/**
|
|
1372
|
+
* Deletes a value from the session.
|
|
1373
|
+
*/
|
|
1374
|
+
delete(key: string): void;
|
|
1375
|
+
/**
|
|
1376
|
+
* Destroys the session.
|
|
1377
|
+
*/
|
|
1378
|
+
destroy(): void;
|
|
1357
1379
|
}
|
|
1358
1380
|
```
|
|
1359
1381
|
|
|
@@ -1402,7 +1424,7 @@ You can access the request info in RPC functions by using the `this` scope:
|
|
|
1402
1424
|
- `this.context`: The [context](#using-context) object.
|
|
1403
1425
|
- `this.session`: The [session](#session-storage-api) storage.
|
|
1404
1426
|
|
|
1405
|
-
```
|
|
1427
|
+
```tsx
|
|
1406
1428
|
type Admin = {
|
|
1407
1429
|
isAdmin: (id: number) => boolean;
|
|
1408
1430
|
}
|
package/jsx-runtime.mjs
CHANGED
|
@@ -179,7 +179,7 @@ var $setup = /* @__PURE__ */ Symbol.for("mono.setup");
|
|
|
179
179
|
var $rpc = /* @__PURE__ */ Symbol.for("mono.rpc");
|
|
180
180
|
|
|
181
181
|
// version.ts
|
|
182
|
-
var VERSION = "0.10.0-beta.
|
|
182
|
+
var VERSION = "0.10.0-beta.4";
|
|
183
183
|
|
|
184
184
|
// render.ts
|
|
185
185
|
var FunctionIdGenerator = class extends Map {
|
|
@@ -534,7 +534,7 @@ async function render(node, options, write, writeJS, componentMode, routeForm) {
|
|
|
534
534
|
if (Object.keys(sessionStore).length > 0) {
|
|
535
535
|
const data = JSON.stringify([
|
|
536
536
|
sessionStore,
|
|
537
|
-
Math.floor((expires ? expires.getTime() : Date.now() + (maxAge ??
|
|
537
|
+
Math.floor((expires ? expires.getTime() : Date.now() + (maxAge ?? 1800) * 1e3) / 1e3)
|
|
538
538
|
]);
|
|
539
539
|
const signature = await subtle.sign(
|
|
540
540
|
"HMAC",
|
|
@@ -830,9 +830,9 @@ async function renderNode(rc, node, stripSlotProp) {
|
|
|
830
830
|
const now = Date.now();
|
|
831
831
|
const value = cache.get(key);
|
|
832
832
|
if (value && (!value.expiresAt || value.expiresAt > now)) {
|
|
833
|
-
write("<!-- cache-hit -->");
|
|
833
|
+
write("<!-- " + tag + "(" + (tag === "cache" ? "hit" : "cache-hit") + ") -->");
|
|
834
834
|
write(value.html);
|
|
835
|
-
write("<!-- /
|
|
835
|
+
write("<!-- /" + tag + " -->");
|
|
836
836
|
} else {
|
|
837
837
|
let buf = "";
|
|
838
838
|
await renderChildren(
|
|
@@ -849,6 +849,7 @@ async function renderNode(rc, node, stripSlotProp) {
|
|
|
849
849
|
rc.write(buf);
|
|
850
850
|
}
|
|
851
851
|
} else {
|
|
852
|
+
console.warn("[mono-jsx] <" + tag + "> The `key` prop is required for caching.");
|
|
852
853
|
await renderChildren(rc, children, true);
|
|
853
854
|
}
|
|
854
855
|
}
|
|
@@ -1373,6 +1374,7 @@ async function createSession(request, options) {
|
|
|
1373
1374
|
let sessionId;
|
|
1374
1375
|
let sessionStore = /* @__PURE__ */ new Map();
|
|
1375
1376
|
let isDirty = false;
|
|
1377
|
+
let isExpired = false;
|
|
1376
1378
|
let session = {
|
|
1377
1379
|
get sessionId() {
|
|
1378
1380
|
return sessionId ?? "";
|
|
@@ -1380,6 +1382,9 @@ async function createSession(request, options) {
|
|
|
1380
1382
|
get isDirty() {
|
|
1381
1383
|
return isDirty;
|
|
1382
1384
|
},
|
|
1385
|
+
get isExpired() {
|
|
1386
|
+
return isExpired;
|
|
1387
|
+
},
|
|
1383
1388
|
get: (key) => sessionStore.get(key),
|
|
1384
1389
|
all: () => Object.fromEntries(sessionStore.entries()),
|
|
1385
1390
|
set: (key, value) => {
|
|
@@ -1414,8 +1419,12 @@ async function createSession(request, options) {
|
|
|
1414
1419
|
);
|
|
1415
1420
|
if (verified) {
|
|
1416
1421
|
const [map, exp] = JSON.parse(data);
|
|
1417
|
-
if (typeof exp === "number"
|
|
1418
|
-
|
|
1422
|
+
if (typeof exp === "number") {
|
|
1423
|
+
if (exp * 1e3 > Date.now()) {
|
|
1424
|
+
sessionStore = new Map(Object.entries(map));
|
|
1425
|
+
} else {
|
|
1426
|
+
isExpired = true;
|
|
1427
|
+
}
|
|
1419
1428
|
sessionId = sid;
|
|
1420
1429
|
}
|
|
1421
1430
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mono-jsx",
|
|
3
|
-
"version": "0.10.0-beta.
|
|
4
|
-
"description": "`<html>` as a `Response
|
|
3
|
+
"version": "0.10.0-beta.4",
|
|
4
|
+
"description": "`<html>` as a `Response` (Yet another JSX runtime for server-side rendering).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.mjs",
|
|
7
7
|
"types": "./types/index.d.ts",
|
package/types/mono.d.ts
CHANGED
|
@@ -166,6 +166,10 @@ export interface Session {
|
|
|
166
166
|
* If true, update the session cookie to the client.
|
|
167
167
|
*/
|
|
168
168
|
readonly isDirty: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* If true, the session is expired.
|
|
171
|
+
*/
|
|
172
|
+
readonly isExpired: boolean;
|
|
169
173
|
/**
|
|
170
174
|
* Gets a value from the session.
|
|
171
175
|
*/
|
package/types/render.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference path="./htmx.d.ts" />
|
|
2
2
|
|
|
3
|
+
import { inflate } from "node:zlib";
|
|
3
4
|
import type { ComponentType } from "./jsx.d.ts";
|
|
4
5
|
|
|
5
6
|
export type MaybeModule<T> = T | Promise<{ default: T; FormHandler?: Function }>;
|
|
@@ -61,7 +62,7 @@ export type SessionOptions = {
|
|
|
61
62
|
* The cookie options to be used by the session.
|
|
62
63
|
*/
|
|
63
64
|
cookie?: CookieOptions;
|
|
64
|
-
// TODO: add session
|
|
65
|
+
// TODO: add session storage options
|
|
65
66
|
};
|
|
66
67
|
|
|
67
68
|
/**
|