@server/next 0.28.9 → 0.28.11
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/index.d.ts +5 -3
- package/index.js +2 -2
- package/package.json +10 -4
- package/src/jsx/jsx-runtime.d.ts +14 -0
- package/src/jsx/jsx-runtime.js +28 -11
- package/src/jsx/jsx-runtime.test.jsx +92 -0
package/index.d.ts
CHANGED
|
@@ -66,9 +66,11 @@ type SerializableValue = BasicValue | {
|
|
|
66
66
|
} | Array<SerializableValue>;
|
|
67
67
|
type KVStore = {
|
|
68
68
|
name?: string;
|
|
69
|
-
prefix: (
|
|
70
|
-
get: <T = SerializableValue>(key: string) => Promise<T>;
|
|
71
|
-
set: <T = SerializableValue>(key: string, value: T,
|
|
69
|
+
prefix: (prefix?: string) => KVStore;
|
|
70
|
+
get: <T = SerializableValue>(key: string) => Promise<T | null>;
|
|
71
|
+
set: <T = SerializableValue>(key: string, value: T, options?: {
|
|
72
|
+
expires?: string | number | null;
|
|
73
|
+
}) => Promise<void | string>;
|
|
72
74
|
has: (key: string) => Promise<boolean>;
|
|
73
75
|
del: (key: string) => Promise<void | string>;
|
|
74
76
|
keys: () => Promise<string[]>;
|
package/index.js
CHANGED
|
@@ -101,7 +101,7 @@ var createSession = async (user, ctx) => {
|
|
|
101
101
|
await session2.set(
|
|
102
102
|
id,
|
|
103
103
|
{ id, strategy, provider, user: user.email },
|
|
104
|
-
"1w"
|
|
104
|
+
{ expires: "1w" }
|
|
105
105
|
);
|
|
106
106
|
if (!strategy) throw new Error(`Invalid strategy "${strategy}"`);
|
|
107
107
|
if (strategy.includes("token")) {
|
|
@@ -343,7 +343,7 @@ var callback = async (ctx) => {
|
|
|
343
343
|
created: profile.created_at
|
|
344
344
|
});
|
|
345
345
|
await store.set(auth2.user, user);
|
|
346
|
-
await session2.set(auth2.id, auth2, "1w");
|
|
346
|
+
await session2.set(auth2.id, auth2, { expires: "1w" });
|
|
347
347
|
if (auth2.strategy.includes("token")) {
|
|
348
348
|
return status(201).json({ ...user, token: auth2.id });
|
|
349
349
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@server/next",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.11",
|
|
4
4
|
"description": "A fully-fledged web server with routing, file uploads, sessions, static files, schema validation, websockets, testing, etc.",
|
|
5
5
|
"homepage": "https://server-js.com/",
|
|
6
6
|
"repository": "https://github.com/franciscop/server-next.git",
|
|
@@ -40,8 +40,14 @@
|
|
|
40
40
|
"exports": {
|
|
41
41
|
".": "./index.js",
|
|
42
42
|
"./index.d.ts": "./index.d.ts",
|
|
43
|
-
"./jsx-runtime":
|
|
44
|
-
|
|
43
|
+
"./jsx-runtime": {
|
|
44
|
+
"types": "./src/jsx/jsx-runtime.d.ts",
|
|
45
|
+
"default": "./src/jsx/jsx-runtime.js"
|
|
46
|
+
},
|
|
47
|
+
"./jsx-dev-runtime": {
|
|
48
|
+
"types": "./src/jsx/jsx-runtime.d.ts",
|
|
49
|
+
"default": "./src/jsx/jsx-dev-runtime.js"
|
|
50
|
+
}
|
|
45
51
|
},
|
|
46
52
|
"devDependencies": {
|
|
47
53
|
"@types/bun": "^1.3.0",
|
|
@@ -50,7 +56,7 @@
|
|
|
50
56
|
"bun": "^1.3.13",
|
|
51
57
|
"check-dts": "^0.8.2",
|
|
52
58
|
"jest": "^29.7.0",
|
|
53
|
-
"polystore": "^0.
|
|
59
|
+
"polystore": "^0.21.1",
|
|
54
60
|
"tsup": "^8.5.1",
|
|
55
61
|
"typescript": "^5.9.3"
|
|
56
62
|
},
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function jsx(type: any, props: any, key?: any): any;
|
|
2
|
+
export declare function jsxs(type: any, props: any, key?: any): any;
|
|
3
|
+
export declare function jsxDEV(type: any, props: any, key?: any): any;
|
|
4
|
+
export declare const Fragment: unique symbol;
|
|
5
|
+
|
|
6
|
+
export declare namespace JSX {
|
|
7
|
+
interface Element {
|
|
8
|
+
type: any;
|
|
9
|
+
props: any;
|
|
10
|
+
}
|
|
11
|
+
interface IntrinsicElements {
|
|
12
|
+
[elem: string]: any;
|
|
13
|
+
}
|
|
14
|
+
}
|
package/src/jsx/jsx-runtime.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const ENTITIES = {
|
|
2
2
|
"&": "&",
|
|
3
3
|
"<": "<",
|
|
4
4
|
">": ">",
|
|
@@ -6,23 +6,34 @@ const entities = {
|
|
|
6
6
|
"'": "'",
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
const encode = (str = "") => {
|
|
10
|
-
if (typeof str === "number") str = String(str);
|
|
11
|
-
if (typeof str !== "string") return "";
|
|
12
|
-
return str.replace(/[&<>"']/g, (tag) => entities[tag]);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
9
|
const SELFCLOSE = new Set(
|
|
16
10
|
"area,base,br,col,embed,hr,img,input,link,meta,source,track,wbr".split(","),
|
|
17
11
|
);
|
|
18
12
|
|
|
13
|
+
const SVG_TAGS = new Set([
|
|
14
|
+
"svg",
|
|
15
|
+
"circle",
|
|
16
|
+
"rect",
|
|
17
|
+
"path",
|
|
18
|
+
"line",
|
|
19
|
+
"g",
|
|
20
|
+
"text",
|
|
21
|
+
"defs",
|
|
22
|
+
]);
|
|
23
|
+
|
|
19
24
|
const REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
|
|
20
25
|
|
|
21
|
-
const
|
|
26
|
+
const ALT_NAMES = {
|
|
22
27
|
classname: "class",
|
|
23
28
|
htmlfor: "for",
|
|
24
29
|
};
|
|
25
30
|
|
|
31
|
+
const encode = (str = "") => {
|
|
32
|
+
if (typeof str === "number") str = String(str);
|
|
33
|
+
if (typeof str !== "string") return "";
|
|
34
|
+
return str.replace(/[&<>"']/g, (tag) => ENTITIES[tag]);
|
|
35
|
+
};
|
|
36
|
+
|
|
26
37
|
// valid primitives only — null, undefined, false, true are all skipped
|
|
27
38
|
const isValidChild = (child) =>
|
|
28
39
|
child != null && child !== false && child !== true;
|
|
@@ -53,7 +64,6 @@ const renderChild = (child) => {
|
|
|
53
64
|
|
|
54
65
|
if (typeof child === "function") {
|
|
55
66
|
const result = child();
|
|
56
|
-
// Strings returned by functions are pre-rendered HTML — don't re-encode them
|
|
57
67
|
if (result == null || result === false || result === true) return "";
|
|
58
68
|
if (typeof result === "string") return result;
|
|
59
69
|
if (typeof result === "number") return String(result);
|
|
@@ -63,7 +73,6 @@ const renderChild = (child) => {
|
|
|
63
73
|
if (typeof child === "string") return encode(child);
|
|
64
74
|
if (typeof child === "number") return String(child);
|
|
65
75
|
|
|
66
|
-
// Raw marker bypasses encoding (used by script, style, dangerouslySetInnerHTML)
|
|
67
76
|
if (typeof child === "object" && RAW in child) return child[RAW];
|
|
68
77
|
|
|
69
78
|
if (isReactElement(child)) {
|
|
@@ -133,7 +142,15 @@ const jsx = (tag, { children, ...props } = {}) => {
|
|
|
133
142
|
.filter(([k, v]) => !/on[A-Z]/.test(k) && typeof v !== "function")
|
|
134
143
|
.filter(([, v]) => v !== false)
|
|
135
144
|
.map(([k, v]) => {
|
|
136
|
-
const
|
|
145
|
+
const preserveSvg = k === "viewBox" || k === "preserveAspectRatio";
|
|
146
|
+
|
|
147
|
+
const key =
|
|
148
|
+
ALT_NAMES[k.toLowerCase()] ||
|
|
149
|
+
(SVG_TAGS.has(tag)
|
|
150
|
+
? preserveSvg
|
|
151
|
+
? k
|
|
152
|
+
: k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)
|
|
153
|
+
: encode(k));
|
|
137
154
|
|
|
138
155
|
if (v === true) return key;
|
|
139
156
|
|
|
@@ -537,3 +537,95 @@ describe("styles", () => {
|
|
|
537
537
|
).toRender('<div style="color:red"></div>');
|
|
538
538
|
});
|
|
539
539
|
});
|
|
540
|
+
|
|
541
|
+
describe("svg attributes", () => {
|
|
542
|
+
it("converts strokeWidth to stroke-width", () => {
|
|
543
|
+
expect(
|
|
544
|
+
<svg>
|
|
545
|
+
<circle strokeWidth="2" />
|
|
546
|
+
</svg>,
|
|
547
|
+
).toRender('<svg><circle stroke-width="2"></circle></svg>');
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
it("converts fillOpacity to fill-opacity", () => {
|
|
551
|
+
expect(
|
|
552
|
+
<svg>
|
|
553
|
+
<rect fillOpacity="0.5" />
|
|
554
|
+
</svg>,
|
|
555
|
+
).toRender('<svg><rect fill-opacity="0.5"></rect></svg>');
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
it("converts strokeLinecap to stroke-linecap", () => {
|
|
559
|
+
expect(
|
|
560
|
+
<svg>
|
|
561
|
+
<line strokeLinecap="round" />
|
|
562
|
+
</svg>,
|
|
563
|
+
).toRender('<svg><line stroke-linecap="round"></line></svg>');
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
it("does NOT break viewBox casing", () => {
|
|
567
|
+
expect(
|
|
568
|
+
<svg viewBox="0 0 100 100">
|
|
569
|
+
<rect />
|
|
570
|
+
</svg>,
|
|
571
|
+
).toRender('<svg viewBox="0 0 100 100"><rect></rect></svg>');
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
it("handles mixed SVG attributes correctly", () => {
|
|
575
|
+
expect(
|
|
576
|
+
<svg viewBox="0 0 10 10">
|
|
577
|
+
<circle strokeWidth="1" fillOpacity="0.2" />
|
|
578
|
+
</svg>,
|
|
579
|
+
).toRender(
|
|
580
|
+
'<svg viewBox="0 0 10 10"><circle stroke-width="1" fill-opacity="0.2"></circle></svg>',
|
|
581
|
+
);
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
it("keeps viewBox unchanged", () => {
|
|
585
|
+
expect(
|
|
586
|
+
<svg viewBox="0 0 100 100">
|
|
587
|
+
<rect />
|
|
588
|
+
</svg>,
|
|
589
|
+
).toRender('<svg viewBox="0 0 100 100"><rect></rect></svg>');
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
it("does NOT convert viewBox to view-box", () => {
|
|
593
|
+
expect(<svg viewBox="0 0 10 10"></svg>).toRender(
|
|
594
|
+
'<svg viewBox="0 0 10 10"></svg>',
|
|
595
|
+
);
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
it("converts strokeWidth to stroke-width", () => {
|
|
599
|
+
expect(
|
|
600
|
+
<svg>
|
|
601
|
+
<circle strokeWidth="2" />
|
|
602
|
+
</svg>,
|
|
603
|
+
).toRender('<svg><circle stroke-width="2"></circle></svg>');
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
it("converts fillOpacity to fill-opacity", () => {
|
|
607
|
+
expect(
|
|
608
|
+
<svg>
|
|
609
|
+
<rect fillOpacity="0.5" />
|
|
610
|
+
</svg>,
|
|
611
|
+
).toRender('<svg><rect fill-opacity="0.5"></rect></svg>');
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
it("converts strokeLinecap to stroke-linecap", () => {
|
|
615
|
+
expect(
|
|
616
|
+
<svg>
|
|
617
|
+
<line strokeLinecap="round" />
|
|
618
|
+
</svg>,
|
|
619
|
+
).toRender('<svg><line stroke-linecap="round"></line></svg>');
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
it("handles mixed SVG attributes correctly", () => {
|
|
623
|
+
expect(
|
|
624
|
+
<svg viewBox="0 0 10 10">
|
|
625
|
+
<circle strokeWidth="1" fillOpacity="0.2" />
|
|
626
|
+
</svg>,
|
|
627
|
+
).toRender(
|
|
628
|
+
'<svg viewBox="0 0 10 10"><circle stroke-width="1" fill-opacity="0.2"></circle></svg>',
|
|
629
|
+
);
|
|
630
|
+
});
|
|
631
|
+
});
|