@sigil-dev/grimoire 0.9.20 → 0.9.22

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 (94) hide show
  1. package/README.md +83 -83
  2. package/index.ts +50 -48
  3. package/package.json +16 -5
  4. package/public/__grimoire__/grimoire-client.js +12 -0
  5. package/public/__grimoire__/runtime.js +1241 -0
  6. package/server.ts +22 -20
  7. package/src/adapters/bun.ts +17 -0
  8. package/src/adapters/static.ts +41 -0
  9. package/src/adapters/types.ts +36 -0
  10. package/src/base.ts +91 -0
  11. package/src/client/csrf.ts +47 -47
  12. package/src/client/deferred.ts +179 -179
  13. package/src/client/enhance.ts +160 -160
  14. package/src/client/router.ts +870 -833
  15. package/src/dev/compile-module.ts +211 -211
  16. package/src/dev/loader.ts +141 -141
  17. package/src/dev/resolve.ts +70 -70
  18. package/src/dev/runtime-bundle.ts +51 -51
  19. package/src/env/modules.ts +62 -62
  20. package/src/env/required.ts +42 -0
  21. package/src/env/typegen.ts +61 -61
  22. package/src/headers.ts +105 -114
  23. package/src/logger/transports.ts +117 -117
  24. package/src/rendering/head.ts +49 -49
  25. package/src/rendering/hydrate.ts +161 -161
  26. package/src/rendering/images.ts +43 -43
  27. package/src/rendering/index.ts +755 -745
  28. package/src/rendering/preload.ts +101 -95
  29. package/src/rendering/ssrPlugin.ts +108 -108
  30. package/src/rendering/timing.ts +40 -40
  31. package/src/routing/router.ts +186 -186
  32. package/src/routing/scanner.ts +225 -196
  33. package/src/routing/transform-routes.ts +102 -102
  34. package/src/server/after-response.ts +206 -194
  35. package/src/server/asset-cache.ts +57 -55
  36. package/src/server/build.ts +262 -249
  37. package/src/server/cached.ts +114 -114
  38. package/src/server/client-address.ts +82 -82
  39. package/src/server/client-dir.ts +57 -57
  40. package/src/server/client-entry.ts +44 -0
  41. package/src/server/cookie-utils.ts +80 -80
  42. package/src/server/coordinator.ts +476 -471
  43. package/src/server/hooks.ts +122 -122
  44. package/src/server/index.ts +1138 -1022
  45. package/src/server/plugins.ts +172 -172
  46. package/src/server/prerender.ts +444 -0
  47. package/src/server/reserved.ts +17 -0
  48. package/src/server/resolver.ts +98 -98
  49. package/src/server/rewrite.ts +28 -0
  50. package/src/server/warm.ts +91 -91
  51. package/src/server/with-headers.ts +27 -0
  52. package/src/server/worker.ts +74 -72
  53. package/src/testing/dom.ts +73 -0
  54. package/src/testing/index.ts +169 -0
  55. package/src/testing/server.ts +162 -0
  56. package/src/typegen/index.ts +450 -450
  57. package/src/types.ts +501 -432
  58. package/test/after-response.test.ts +132 -113
  59. package/test/asset-cache-policy.test.ts +96 -96
  60. package/test/base.test.ts +134 -0
  61. package/test/cached.test.ts +126 -126
  62. package/test/client-address.test.ts +78 -78
  63. package/test/client-csrf.test.ts +61 -61
  64. package/test/client-dir.test.ts +101 -69
  65. package/test/client-router.test.ts +789 -734
  66. package/test/coordinator.test.ts +96 -94
  67. package/test/deferred.test.ts +256 -256
  68. package/test/dev-loader.test.ts +30 -30
  69. package/test/env.test.ts +168 -168
  70. package/test/force-production.test.ts +44 -0
  71. package/test/images.test.ts +49 -49
  72. package/test/locals-header.test.ts +61 -0
  73. package/test/middleware.test.ts +243 -243
  74. package/test/parser-plugins.test.ts +92 -92
  75. package/test/plugin-handle.test.ts +62 -62
  76. package/test/plugin-services-context.test.ts +97 -97
  77. package/test/preload.test.ts +48 -48
  78. package/test/prerender.test.ts +353 -0
  79. package/test/rendering.test.ts +798 -798
  80. package/test/required-env.test.ts +32 -0
  81. package/test/rewrite-html.test.ts +90 -0
  82. package/test/scanning.test.ts +349 -314
  83. package/test/server.test.ts +640 -619
  84. package/test/services.test.ts +90 -90
  85. package/test/streaming.test.ts +378 -378
  86. package/test/testing-helpers.test.ts +166 -0
  87. package/test/typegen.test.ts +805 -799
  88. package/test/warm.test.ts +96 -96
  89. package/test/worker-context.test.ts +59 -59
  90. package/test/workspace-files.test.ts +149 -146
  91. package/test/workspace-versions.test.ts +131 -131
  92. package/.grimoire/_routes.ts +0 -4
  93. package/public/__grimoire__/client.js +0 -55
  94. package/public/__grimoire__/hydrate.js +0 -63
@@ -1,80 +1,80 @@
1
- import type { CookieOptions } from "./hooks";
2
-
3
- /**
4
- * Parse cookies from a Cookie header string.
5
- */
6
- export function parseCookies(cookieHeader: string): Map<string, string> {
7
- const map = new Map<string, string>();
8
- if (!cookieHeader) return map;
9
- for (const pair of cookieHeader.split(";")) {
10
- const [name, ...rest] = pair.split("=");
11
- if (!name) continue;
12
- // set() encodes values, so get() must decode them to round-trip
13
- const raw = rest.join("=").trim();
14
- let value = raw;
15
- try {
16
- value = decodeURIComponent(raw);
17
- } catch {}
18
- map.set(name.trim(), value);
19
- }
20
- return map;
21
- }
22
-
23
- /**
24
- * Build a Set-Cookie header from name, value, and options.
25
- */
26
- export function serializeCookie(
27
- name: string,
28
- value: string,
29
- options?: {
30
- path?: string;
31
- domain?: string;
32
- maxAge?: number;
33
- expires?: Date;
34
- httpOnly?: boolean;
35
- secure?: boolean;
36
- sameSite?: "strict" | "lax" | "none";
37
- },
38
- ): string {
39
- let cookie = `${name}=${encodeURIComponent(value)}`;
40
- if (options?.path) cookie += `; Path=${options.path}`;
41
- if (options?.domain) cookie += `; Domain=${options.domain}`;
42
- if (options?.maxAge != null) cookie += `; Max-Age=${options.maxAge}`;
43
- if (options?.expires) cookie += `; Expires=${options.expires.toUTCString()}`;
44
- if (options?.httpOnly) cookie += "; HttpOnly";
45
- if (options?.secure) cookie += "; Secure";
46
- if (options?.sameSite) cookie += `; SameSite=${options.sameSite}`;
47
- return cookie;
48
- }
49
-
50
- /**
51
- * Create a Cookies helper from a Cookie header string.
52
- */
53
- export function createCookies(
54
- cookieHeader: string,
55
- ): import("./hooks").Cookies & { toHeaders(): string[] } {
56
- const store = parseCookies(cookieHeader);
57
- const pending: string[] = [];
58
-
59
- return {
60
- get(name: string) {
61
- return store.get(name);
62
- },
63
- // Path defaults to "/": without one the browser scopes the cookie to
64
- // the request's directory, so a session set by /account/login would
65
- // never reach /, and a delete from another page would miss it
66
- set(name: string, value: string, options?: CookieOptions) {
67
- store.set(name, value);
68
- pending.push(serializeCookie(name, value, { path: "/", ...options }));
69
- },
70
- delete(name: string, options?: Pick<CookieOptions, "path" | "domain">) {
71
- store.delete(name);
72
- pending.push(
73
- serializeCookie(name, "", { path: "/", ...options, maxAge: 0 }),
74
- );
75
- },
76
- toHeaders() {
77
- return pending;
78
- },
79
- };
80
- }
1
+ import type { CookieOptions } from "./hooks";
2
+
3
+ /**
4
+ * Parse cookies from a Cookie header string.
5
+ */
6
+ export function parseCookies(cookieHeader: string): Map<string, string> {
7
+ const map = new Map<string, string>();
8
+ if (!cookieHeader) return map;
9
+ for (const pair of cookieHeader.split(";")) {
10
+ const [name, ...rest] = pair.split("=");
11
+ if (!name) continue;
12
+ // set() encodes values, so get() must decode them to round-trip
13
+ const raw = rest.join("=").trim();
14
+ let value = raw;
15
+ try {
16
+ value = decodeURIComponent(raw);
17
+ } catch {}
18
+ map.set(name.trim(), value);
19
+ }
20
+ return map;
21
+ }
22
+
23
+ /**
24
+ * Build a Set-Cookie header from name, value, and options.
25
+ */
26
+ export function serializeCookie(
27
+ name: string,
28
+ value: string,
29
+ options?: {
30
+ path?: string;
31
+ domain?: string;
32
+ maxAge?: number;
33
+ expires?: Date;
34
+ httpOnly?: boolean;
35
+ secure?: boolean;
36
+ sameSite?: "strict" | "lax" | "none";
37
+ },
38
+ ): string {
39
+ let cookie = `${name}=${encodeURIComponent(value)}`;
40
+ if (options?.path) cookie += `; Path=${options.path}`;
41
+ if (options?.domain) cookie += `; Domain=${options.domain}`;
42
+ if (options?.maxAge != null) cookie += `; Max-Age=${options.maxAge}`;
43
+ if (options?.expires) cookie += `; Expires=${options.expires.toUTCString()}`;
44
+ if (options?.httpOnly) cookie += "; HttpOnly";
45
+ if (options?.secure) cookie += "; Secure";
46
+ if (options?.sameSite) cookie += `; SameSite=${options.sameSite}`;
47
+ return cookie;
48
+ }
49
+
50
+ /**
51
+ * Create a Cookies helper from a Cookie header string.
52
+ */
53
+ export function createCookies(
54
+ cookieHeader: string,
55
+ ): import("./hooks").Cookies & { toHeaders(): string[] } {
56
+ const store = parseCookies(cookieHeader);
57
+ const pending: string[] = [];
58
+
59
+ return {
60
+ get(name: string) {
61
+ return store.get(name);
62
+ },
63
+ // Path defaults to "/": without one the browser scopes the cookie to
64
+ // the request's directory, so a session set by /account/login would
65
+ // never reach /, and a delete from another page would miss it
66
+ set(name: string, value: string, options?: CookieOptions) {
67
+ store.set(name, value);
68
+ pending.push(serializeCookie(name, value, { path: "/", ...options }));
69
+ },
70
+ delete(name: string, options?: Pick<CookieOptions, "path" | "domain">) {
71
+ store.delete(name);
72
+ pending.push(
73
+ serializeCookie(name, "", { path: "/", ...options, maxAge: 0 }),
74
+ );
75
+ },
76
+ toHeaders() {
77
+ return pending;
78
+ },
79
+ };
80
+ }