@sigil-dev/grimoire 0.9.28 → 0.9.30
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/bin/sigil.ts +4 -0
- package/index.ts +16 -10
- package/package.json +14 -6
- package/server.ts +2 -2
- package/src/adapters/bun.ts +17 -17
- package/src/adapters/static.ts +41 -41
- package/src/adapters/types.ts +36 -36
- package/src/base.ts +4 -1
- package/src/client/csrf.ts +47 -47
- package/src/client/deferred.ts +1 -4
- package/src/client/enhance.ts +160 -160
- package/src/client/router.ts +927 -926
- package/src/config-file.ts +84 -0
- package/src/dev/compile-module.ts +199 -193
- package/src/dev/hmr-client.ts +229 -229
- package/src/dev/hmr-server.ts +274 -266
- package/src/dev/loader.ts +144 -144
- package/src/dev/runtime-bundle.ts +5 -3
- package/src/duration.ts +46 -0
- package/src/env/modules.ts +62 -62
- package/src/env/required.ts +42 -42
- package/src/env/typegen.ts +61 -61
- package/src/headers.ts +105 -105
- package/src/logger/transports.ts +117 -117
- package/src/plugin-order.ts +88 -0
- package/src/rendering/head.ts +49 -49
- package/src/rendering/hydrate.ts +162 -162
- package/src/rendering/images.ts +43 -43
- package/src/rendering/preload.ts +22 -8
- package/src/rendering/ssrPlugin.ts +107 -107
- package/src/rendering/timing.ts +40 -40
- package/src/routing/route-ids.ts +65 -0
- package/src/routing/route.ts +65 -0
- package/src/routing/router.ts +84 -32
- package/src/routing/scanner.ts +18 -5
- package/src/routing/transform-routes.ts +102 -102
- package/src/server/after-response.ts +206 -206
- package/src/server/asset-cache.ts +57 -57
- package/src/server/build.ts +304 -295
- package/src/server/cached.ts +114 -114
- package/src/server/client-address.ts +82 -82
- package/src/server/client-dir.ts +63 -63
- package/src/server/client-entry.ts +44 -44
- package/src/server/context.ts +18 -10
- package/src/server/cookie-utils.ts +80 -80
- package/src/server/coordinator.ts +476 -476
- package/src/server/hooks.ts +122 -122
- package/src/server/index.ts +8 -0
- package/src/server/plugins.ts +172 -172
- package/src/server/prerender.ts +473 -473
- package/src/server/reserved.ts +17 -17
- package/src/server/resolver.ts +149 -123
- package/src/server/rewrite.ts +28 -28
- package/src/server/warm.ts +9 -3
- package/src/server/with-headers.ts +27 -27
- package/src/server/worker.ts +2 -6
- package/src/server-only.ts +78 -0
- package/src/testing/dom.ts +73 -73
- package/src/testing/index.ts +169 -169
- package/src/testing/server.ts +1 -0
- package/src/typegen/index.ts +97 -2
- package/src/types.ts +140 -19
- package/test/after-response.test.ts +132 -132
- package/test/asset-cache-policy.test.ts +6 -2
- package/test/base.test.ts +20 -6
- package/test/cached.test.ts +126 -126
- package/test/client-address.test.ts +78 -78
- package/test/client-csrf.test.ts +61 -61
- package/test/client-dir.test.ts +101 -101
- package/test/client-router.test.ts +37 -5
- package/test/config-file.test.ts +84 -0
- package/test/coordinator.test.ts +9 -2
- package/test/deferred.test.ts +4 -2
- package/test/dev-loader.test.ts +30 -30
- package/test/env.test.ts +171 -171
- package/test/force-production.test.ts +7 -2
- package/test/images.test.ts +20 -8
- package/test/locals-header.test.ts +61 -61
- package/test/middleware.test.ts +243 -243
- package/test/parser-plugins.test.ts +98 -92
- package/test/plugin-handle.test.ts +62 -62
- package/test/plugin-order.test.ts +98 -0
- package/test/plugin-routes.test.ts +47 -42
- package/test/plugin-services-context.test.ts +7 -2
- package/test/preload.test.ts +4 -1
- package/test/prerender.test.ts +3 -1
- package/test/rendering.test.ts +3 -2
- package/test/required-env.test.ts +32 -32
- package/test/resolver-windows.test.ts +22 -23
- package/test/rewrite-html.test.ts +90 -90
- package/test/route-group-layouts.test.ts +38 -36
- package/test/route.test.ts +103 -0
- package/test/routing.test.ts +225 -197
- package/test/scanning.test.ts +53 -33
- package/test/server-context.test.ts +22 -0
- package/test/server-only.test.ts +110 -0
- package/test/server.test.ts +640 -640
- package/test/services.test.ts +3 -3
- package/test/streaming.test.ts +11 -6
- package/test/testing-helpers.test.ts +166 -166
- package/test/typegen.test.ts +209 -112
- package/test/warm.test.ts +96 -96
- package/test/worker-context.test.ts +59 -59
- package/test/workspace-files.test.ts +26 -10
- package/test/workspace-versions.test.ts +146 -131
|
@@ -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
|
+
}
|