@sigil-dev/grimoire 0.9.3 → 0.9.5

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 (78) hide show
  1. package/index.ts +37 -35
  2. package/package.json +9 -12
  3. package/preload.js +3 -3
  4. package/server.ts +19 -19
  5. package/src/client/deps.ts +36 -19
  6. package/src/client/enhance.ts +102 -98
  7. package/src/client/head.ts +30 -30
  8. package/src/client/index.ts +2 -2
  9. package/src/client/router.ts +174 -68
  10. package/src/client/scope.ts +22 -22
  11. package/src/dev/compile-module.ts +215 -163
  12. package/src/dev/effect-registry.ts +23 -23
  13. package/src/dev/graph.ts +109 -114
  14. package/src/dev/hmr-client.ts +202 -185
  15. package/src/dev/hmr-server.ts +261 -187
  16. package/src/dev/loader.ts +120 -47
  17. package/src/dev/paths.ts +14 -14
  18. package/src/dev/resolve.ts +70 -0
  19. package/src/dev/runtime-bundle.ts +52 -52
  20. package/src/dev/scan.ts +78 -0
  21. package/src/dev/watcher.ts +69 -47
  22. package/src/env/dynamic-private.ts +19 -19
  23. package/src/env/dynamic-public.ts +22 -22
  24. package/src/env/index.ts +25 -25
  25. package/src/env/plugin.ts +19 -19
  26. package/src/env/private.ts +5 -5
  27. package/src/env/public.ts +7 -7
  28. package/src/env/typegen.ts +61 -61
  29. package/src/headers.ts +114 -114
  30. package/src/integrations/vite.ts +73 -73
  31. package/src/logger/index.ts +4 -4
  32. package/src/logger/instance.ts +6 -6
  33. package/src/logger/logger.ts +113 -113
  34. package/src/logger/request-middleware.ts +24 -24
  35. package/src/logger/transports.ts +117 -117
  36. package/src/logger/types.ts +39 -39
  37. package/src/rendering/head.ts +52 -47
  38. package/src/rendering/hydrate.ts +159 -138
  39. package/src/rendering/index.ts +140 -18
  40. package/src/rendering/ssrPlugin.ts +78 -69
  41. package/src/routing/manifest-gen.ts +13 -1
  42. package/src/routing/router.ts +135 -109
  43. package/src/routing/scanner.ts +196 -141
  44. package/src/routing/transform-routes.ts +102 -102
  45. package/src/sentinels/error.ts +52 -52
  46. package/src/sentinels/fail.ts +41 -41
  47. package/src/sentinels/redirect.ts +35 -35
  48. package/src/server/build.ts +250 -243
  49. package/src/server/context.ts +10 -10
  50. package/src/server/cookie-utils.ts +66 -66
  51. package/src/server/coordinator.ts +364 -364
  52. package/src/server/hooks.ts +114 -114
  53. package/src/server/index.ts +711 -655
  54. package/src/server/interactive.ts +56 -56
  55. package/src/server/plugins.ts +121 -121
  56. package/src/server/worker.ts +58 -58
  57. package/src/typegen/index.ts +389 -356
  58. package/src/types.ts +286 -282
  59. package/test/client-router.test.ts +295 -44
  60. package/test/context.test.ts +52 -52
  61. package/test/env.test.ts +90 -90
  62. package/test/exports.test.ts +37 -37
  63. package/test/fail.test.ts +46 -46
  64. package/test/headers.test.ts +100 -100
  65. package/test/hmr.test.ts +426 -0
  66. package/test/hydration.test.ts +119 -119
  67. package/test/middleware.test.ts +223 -223
  68. package/test/preload.ts +5 -5
  69. package/test/redirect-error.test.ts +112 -112
  70. package/test/rendering.test.ts +719 -615
  71. package/test/routing.test.ts +197 -81
  72. package/test/scanning.test.ts +314 -200
  73. package/test/scope.test.ts +195 -195
  74. package/test/server.test.ts +360 -249
  75. package/test/streaming.test.ts +242 -125
  76. package/test/transform-routes.test.ts +87 -84
  77. package/test/typegen.test.ts +697 -682
  78. package/tsconfig.json +10 -10
@@ -1,37 +1,37 @@
1
- /**
2
- * Verifies that every symbol mentioned in the README is actually exported
3
- * from the correct import path. If any of these break, the README is lying.
4
- */
5
- import { describe, expect, test } from "bun:test";
6
-
7
- describe("README public API exports", () => {
8
- test("main package exports: error, fail, redirect, sequence, defineConfig, Head, createServer, TypedLoadContext", async () => {
9
- const mod = await import("@sigil-dev/grimoire");
10
- expect(typeof mod.error).toBe("function");
11
- expect(typeof mod.fail).toBe("function");
12
- expect(typeof mod.redirect).toBe("function");
13
- expect(typeof mod.sequence).toBe("function");
14
- expect(typeof mod.defineConfig).toBe("function");
15
- expect(typeof mod.Head).toBe("function");
16
- // isXxx helpers used internally
17
- expect(typeof mod.isErrorResult).toBe("function");
18
- expect(typeof mod.isFailResult).toBe("function");
19
- expect(typeof mod.isRedirectResult).toBe("function");
20
- });
21
-
22
- test("@sigil-dev/grimoire/client exports enhance", async () => {
23
- const mod = await import("@sigil-dev/grimoire/client");
24
- expect(typeof mod.enhance).toBe("function");
25
- });
26
-
27
- test("@sigil-dev/grimoire/hooks exports sequence and createHooks", async () => {
28
- const mod = await import("@sigil-dev/grimoire/hooks");
29
- expect(typeof mod.sequence).toBe("function");
30
- expect(typeof mod.createHooks).toBe("function");
31
- });
32
-
33
- test("@sigil-dev/grimoire/headers exports securityHeaders", async () => {
34
- const mod = await import("@sigil-dev/grimoire/headers");
35
- expect(typeof mod.securityHeaders).toBe("function");
36
- });
37
- });
1
+ /**
2
+ * Verifies that every symbol mentioned in the README is actually exported
3
+ * from the correct import path. If any of these break, the README is lying.
4
+ */
5
+ import { describe, expect, test } from "bun:test";
6
+
7
+ describe("README public API exports", () => {
8
+ test("main package exports: error, fail, redirect, sequence, defineConfig, Head, createServer, TypedLoadContext", async () => {
9
+ const mod = await import("@sigil-dev/grimoire");
10
+ expect(typeof mod.error).toBe("function");
11
+ expect(typeof mod.fail).toBe("function");
12
+ expect(typeof mod.redirect).toBe("function");
13
+ expect(typeof mod.sequence).toBe("function");
14
+ expect(typeof mod.defineConfig).toBe("function");
15
+ expect(typeof mod.Head).toBe("function");
16
+ // isXxx helpers used internally
17
+ expect(typeof mod.isErrorResult).toBe("function");
18
+ expect(typeof mod.isFailResult).toBe("function");
19
+ expect(typeof mod.isRedirectResult).toBe("function");
20
+ });
21
+
22
+ test("@sigil-dev/grimoire/client exports enhance", async () => {
23
+ const mod = await import("@sigil-dev/grimoire/client");
24
+ expect(typeof mod.enhance).toBe("function");
25
+ });
26
+
27
+ test("@sigil-dev/grimoire/hooks exports sequence and createHooks", async () => {
28
+ const mod = await import("@sigil-dev/grimoire/hooks");
29
+ expect(typeof mod.sequence).toBe("function");
30
+ expect(typeof mod.createHooks).toBe("function");
31
+ });
32
+
33
+ test("@sigil-dev/grimoire/headers exports securityHeaders", async () => {
34
+ const mod = await import("@sigil-dev/grimoire/headers");
35
+ expect(typeof mod.securityHeaders).toBe("function");
36
+ });
37
+ });
package/test/fail.test.ts CHANGED
@@ -1,46 +1,46 @@
1
- import { describe, expect, test } from "bun:test";
2
- import { fail, isFailResult } from "../src/sentinels/fail.ts";
3
-
4
- describe("fail()", () => {
5
- test("returns a FailResult with status and data", () => {
6
- const result = fail(400, { name: "required" });
7
- expect(result).toEqual({
8
- __fail: true,
9
- status: 400,
10
- data: { name: "required" },
11
- });
12
- });
13
-
14
- test("isFailResult returns true for fail()", () => {
15
- const result = fail(422, { errors: { email: "invalid" } });
16
- expect(isFailResult(result)).toBe(true);
17
- });
18
-
19
- test("isFailResult returns false for plain objects", () => {
20
- expect(isFailResult({ redirect: "/foo" })).toBe(false);
21
- expect(isFailResult(null)).toBe(false);
22
- expect(isFailResult(undefined)).toBe(false);
23
- expect(isFailResult("string")).toBe(false);
24
- });
25
-
26
- test("preserves complex data structures", () => {
27
- const data = {
28
- formData: { email: "test@example.com", name: "" },
29
- errors: {
30
- name: "Name is required",
31
- email: null,
32
- },
33
- timestamp: Date.now(),
34
- };
35
- const result = fail(400, data);
36
- expect(result.data).toEqual(data);
37
- expect(result.status).toBe(400);
38
- });
39
-
40
- test("works with different status codes", () => {
41
- expect(fail(400, {}).status).toBe(400);
42
- expect(fail(403, {}).status).toBe(403);
43
- expect(fail(422, {}).status).toBe(422);
44
- expect(fail(500, {}).status).toBe(500);
45
- });
46
- });
1
+ import { describe, expect, test } from "bun:test";
2
+ import { fail, isFailResult } from "../src/sentinels/fail.ts";
3
+
4
+ describe("fail()", () => {
5
+ test("returns a FailResult with status and data", () => {
6
+ const result = fail(400, { name: "required" });
7
+ expect(result).toEqual({
8
+ __fail: true,
9
+ status: 400,
10
+ data: { name: "required" },
11
+ });
12
+ });
13
+
14
+ test("isFailResult returns true for fail()", () => {
15
+ const result = fail(422, { errors: { email: "invalid" } });
16
+ expect(isFailResult(result)).toBe(true);
17
+ });
18
+
19
+ test("isFailResult returns false for plain objects", () => {
20
+ expect(isFailResult({ redirect: "/foo" })).toBe(false);
21
+ expect(isFailResult(null)).toBe(false);
22
+ expect(isFailResult(undefined)).toBe(false);
23
+ expect(isFailResult("string")).toBe(false);
24
+ });
25
+
26
+ test("preserves complex data structures", () => {
27
+ const data = {
28
+ formData: { email: "test@example.com", name: "" },
29
+ errors: {
30
+ name: "Name is required",
31
+ email: null,
32
+ },
33
+ timestamp: Date.now(),
34
+ };
35
+ const result = fail(400, data);
36
+ expect(result.data).toEqual(data);
37
+ expect(result.status).toBe(400);
38
+ });
39
+
40
+ test("works with different status codes", () => {
41
+ expect(fail(400, {}).status).toBe(400);
42
+ expect(fail(403, {}).status).toBe(403);
43
+ expect(fail(422, {}).status).toBe(422);
44
+ expect(fail(500, {}).status).toBe(500);
45
+ });
46
+ });
@@ -1,100 +1,100 @@
1
- import { describe, expect, test } from "bun:test";
2
- import { securityHeaders } from "../src/headers";
3
-
4
- function fakeRequest(path = "/") {
5
- return new Request(`http://localhost${path}`);
6
- }
7
-
8
- async function runPlugin(
9
- config: Parameters<typeof securityHeaders>[0],
10
- req?: Request,
11
- ): Promise<Headers> {
12
- const plugin = securityHeaders(config);
13
- const res = new Response("<html></html>", {
14
- headers: { "Content-Type": "text/html" },
15
- });
16
- const result = await plugin.onRequest!(req ?? fakeRequest(), async () => res);
17
- return result.headers;
18
- }
19
-
20
- describe("securityHeaders()", () => {
21
- test("applies default headers", async () => {
22
- const headers = await runPlugin({});
23
- expect(headers.get("X-Content-Type-Options")).toBe("nosniff");
24
- expect(headers.get("X-Frame-Options")).toBe("DENY");
25
- expect(headers.get("Referrer-Policy")).toBe(
26
- "strict-origin-when-cross-origin",
27
- );
28
- expect(headers.get("Permissions-Policy")).toBe(
29
- "camera=(), microphone=(), geolocation=()",
30
- );
31
- expect(headers.get("X-XSS-Protection")).toBe("0");
32
- });
33
-
34
- test("applies CSP by default", async () => {
35
- const headers = await runPlugin({});
36
- expect(headers.get("Content-Security-Policy")).toContain(
37
- "default-src 'self'",
38
- );
39
- });
40
-
41
- test("allows overriding individual headers", async () => {
42
- const headers = await runPlugin({
43
- frameOptions: "SAMEORIGIN",
44
- contentTypeOptions: false,
45
- });
46
- expect(headers.get("X-Frame-Options")).toBe("SAMEORIGIN");
47
- expect(headers.has("X-Content-Type-Options")).toBe(false);
48
- });
49
-
50
- test("disables headers when set to false", async () => {
51
- const headers = await runPlugin({
52
- contentSecurityPolicy: false,
53
- strictTransportSecurity: false,
54
- permissionsPolicy: false,
55
- });
56
- expect(headers.has("Content-Security-Policy")).toBe(false);
57
- expect(headers.has("Strict-Transport-Security")).toBe(false);
58
- expect(headers.has("Permissions-Policy")).toBe(false);
59
- });
60
-
61
- test("applies route overrides", async () => {
62
- const headers = await runPlugin(
63
- {
64
- frameOptions: "DENY",
65
- routes: {
66
- "/admin": { frameOptions: "SAMEORIGIN" },
67
- },
68
- },
69
- fakeRequest("/admin/settings"),
70
- );
71
- expect(headers.get("X-Frame-Options")).toBe("SAMEORIGIN");
72
- });
73
-
74
- test("route override only applies to matching prefix", async () => {
75
- const headers = await runPlugin(
76
- {
77
- frameOptions: "DENY",
78
- routes: {
79
- "/admin": { frameOptions: "SAMEORIGIN" },
80
- },
81
- },
82
- fakeRequest("/dashboard"),
83
- );
84
- expect(headers.get("X-Frame-Options")).toBe("DENY");
85
- });
86
-
87
- test("preserves existing response headers", async () => {
88
- const plugin = securityHeaders({});
89
- const res = new Response("<html></html>", {
90
- headers: {
91
- "Content-Type": "text/html",
92
- "Set-Cookie": "session=abc",
93
- },
94
- });
95
- const result = await plugin.onRequest!(fakeRequest(), async () => res);
96
- expect(result.headers.get("Content-Type")).toBe("text/html");
97
- expect(result.headers.get("Set-Cookie")).toBe("session=abc");
98
- expect(result.headers.get("X-Frame-Options")).toBe("DENY");
99
- });
100
- });
1
+ import { describe, expect, test } from "bun:test";
2
+ import { securityHeaders } from "../src/headers";
3
+
4
+ function fakeRequest(path = "/") {
5
+ return new Request(`http://localhost${path}`);
6
+ }
7
+
8
+ async function runPlugin(
9
+ config: Parameters<typeof securityHeaders>[0],
10
+ req?: Request,
11
+ ): Promise<Headers> {
12
+ const plugin = securityHeaders(config);
13
+ const res = new Response("<html></html>", {
14
+ headers: { "Content-Type": "text/html" },
15
+ });
16
+ const result = await plugin.onRequest!(req ?? fakeRequest(), async () => res);
17
+ return result.headers;
18
+ }
19
+
20
+ describe("securityHeaders()", () => {
21
+ test("applies default headers", async () => {
22
+ const headers = await runPlugin({});
23
+ expect(headers.get("X-Content-Type-Options")).toBe("nosniff");
24
+ expect(headers.get("X-Frame-Options")).toBe("DENY");
25
+ expect(headers.get("Referrer-Policy")).toBe(
26
+ "strict-origin-when-cross-origin",
27
+ );
28
+ expect(headers.get("Permissions-Policy")).toBe(
29
+ "camera=(), microphone=(), geolocation=()",
30
+ );
31
+ expect(headers.get("X-XSS-Protection")).toBe("0");
32
+ });
33
+
34
+ test("applies CSP by default", async () => {
35
+ const headers = await runPlugin({});
36
+ expect(headers.get("Content-Security-Policy")).toContain(
37
+ "default-src 'self'",
38
+ );
39
+ });
40
+
41
+ test("allows overriding individual headers", async () => {
42
+ const headers = await runPlugin({
43
+ frameOptions: "SAMEORIGIN",
44
+ contentTypeOptions: false,
45
+ });
46
+ expect(headers.get("X-Frame-Options")).toBe("SAMEORIGIN");
47
+ expect(headers.has("X-Content-Type-Options")).toBe(false);
48
+ });
49
+
50
+ test("disables headers when set to false", async () => {
51
+ const headers = await runPlugin({
52
+ contentSecurityPolicy: false,
53
+ strictTransportSecurity: false,
54
+ permissionsPolicy: false,
55
+ });
56
+ expect(headers.has("Content-Security-Policy")).toBe(false);
57
+ expect(headers.has("Strict-Transport-Security")).toBe(false);
58
+ expect(headers.has("Permissions-Policy")).toBe(false);
59
+ });
60
+
61
+ test("applies route overrides", async () => {
62
+ const headers = await runPlugin(
63
+ {
64
+ frameOptions: "DENY",
65
+ routes: {
66
+ "/admin": { frameOptions: "SAMEORIGIN" },
67
+ },
68
+ },
69
+ fakeRequest("/admin/settings"),
70
+ );
71
+ expect(headers.get("X-Frame-Options")).toBe("SAMEORIGIN");
72
+ });
73
+
74
+ test("route override only applies to matching prefix", async () => {
75
+ const headers = await runPlugin(
76
+ {
77
+ frameOptions: "DENY",
78
+ routes: {
79
+ "/admin": { frameOptions: "SAMEORIGIN" },
80
+ },
81
+ },
82
+ fakeRequest("/dashboard"),
83
+ );
84
+ expect(headers.get("X-Frame-Options")).toBe("DENY");
85
+ });
86
+
87
+ test("preserves existing response headers", async () => {
88
+ const plugin = securityHeaders({});
89
+ const res = new Response("<html></html>", {
90
+ headers: {
91
+ "Content-Type": "text/html",
92
+ "Set-Cookie": "session=abc",
93
+ },
94
+ });
95
+ const result = await plugin.onRequest!(fakeRequest(), async () => res);
96
+ expect(result.headers.get("Content-Type")).toBe("text/html");
97
+ expect(result.headers.get("Set-Cookie")).toBe("session=abc");
98
+ expect(result.headers.get("X-Frame-Options")).toBe("DENY");
99
+ });
100
+ });