@sigil-dev/grimoire 0.9.21 → 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 -105
  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 -749
  28. package/src/rendering/preload.ts +101 -101
  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 -206
  35. package/src/server/asset-cache.ts +57 -57
  36. package/src/server/build.ts +262 -262
  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 -44
  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 -1018
  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 -27
  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 -132
  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 -101
  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
package/README.md CHANGED
@@ -1,83 +1,83 @@
1
- # @sigil-dev/grimoire
2
-
3
- The full-stack framework for [Sigil](https://sigil.cane1712.dev): file-based routes, server `load` functions, form actions that work without JavaScript, streaming SSR, WebSockets and a plugin system. If you know SvelteKit, most of it will feel familiar.
4
-
5
- ```sh
6
- bun i -g @sigil-dev/cli
7
- sigil create my-app && cd my-app && sigil dev
8
- ```
9
-
10
- ## Routes
11
-
12
- Files in `src/routes` are pages and endpoints:
13
-
14
- | File | What it is |
15
- | --- | --- |
16
- | `+page.tsx` | A page (`about.tsx` and `about/index.tsx` work too) |
17
- | `+page.server.ts` | Its `load` and form actions, server only |
18
- | `+layout.tsx`, `+layout.server.ts` | A layout and its data |
19
- | `+server.ts` | An endpoint: `GET`, `POST`, … return a `Response` |
20
- | `+error.tsx` | The error page for everything below it |
21
- | `hooks.server.ts` | Per-request middleware, at the project root |
22
-
23
- `[slug]` is a parameter, `[[...rest]]` an optional catch-all.
24
-
25
- ```ts
26
- // src/routes/posts/[slug]/+page.server.ts
27
- import { error, fail, redirect } from "@sigil-dev/grimoire";
28
-
29
- export async function load({ params }) {
30
- const post = await db.posts.findFirst({ where: { slug: params.slug } });
31
- if (!post) throw error(404, "Post not found");
32
- return { post }; // the page's `data` prop
33
- }
34
-
35
- export async function comment({ request, locals }) {
36
- const form = await request.formData(); // a <form method="POST" action="?/comment">
37
- if (!form.get("body")) return fail(400, { error: "Say something" }); // the page's `form` prop
38
- await saveComment(form, locals.user);
39
- throw redirect(303, "/posts");
40
- }
41
- ```
42
-
43
- ```tsx
44
- // src/routes/posts/[slug]/+page.tsx
45
- export default function Post({ data, form }) {
46
- return (
47
- <article>
48
- <h1>{data.post.title}</h1>
49
- <form method="POST" action="?/comment">
50
- <textarea name="body" />
51
- {form?.error && <p>{form.error}</p>}
52
- <button>Comment</button>
53
- </form>
54
- </article>
55
- );
56
- }
57
- ```
58
-
59
- Every form post carries a CSRF token; Grimoire adds it to rendered forms for you.
60
-
61
- ## Batteries
62
-
63
- These are separate packages, so an app only carries what it uses:
64
-
65
- - [`@sigil-dev/tome`](https://www.npmjs.com/package/@sigil-dev/tome): schema, typed queries, validation and migrations
66
- - [`@sigil-dev/auth`](https://www.npmjs.com/package/@sigil-dev/auth): sign-up, sign-in, sessions and OAuth
67
- - [`@sigil-dev/plugin-sql`](https://www.npmjs.com/package/@sigil-dev/plugin-sql): the database connection
68
- - [`@sigil-dev/plugin-jobs`](https://www.npmjs.com/package/@sigil-dev/plugin-jobs): background jobs and schedules
69
- - `plugin-health`, `plugin-sentry`, `plugin-namepool`: health checks, error tracking, worker names
70
-
71
- ## Configuration
72
-
73
- ```ts
74
- // sigil.config.ts
75
- import { defineConfig } from "@sigil-dev/grimoire";
76
-
77
- export default defineConfig({
78
- port: 3000,
79
- plugins: [],
80
- });
81
- ```
82
-
83
- **Docs:** [sigil.cane1712.dev/docs](https://sigil.cane1712.dev/docs). Start with the [tutorial](https://sigil.cane1712.dev/docs/tutorial), or go to [routing](https://sigil.cane1712.dev/docs/reference/routing), [loading](https://sigil.cane1712.dev/docs/reference/loading), [actions](https://sigil.cane1712.dev/docs/reference/actions), [hooks](https://sigil.cane1712.dev/docs/reference/hooks) and [deploying](https://sigil.cane1712.dev/docs/guides/deploying).
1
+ # @sigil-dev/grimoire
2
+
3
+ The full-stack framework for [Sigil](https://sigil.cane1712.dev): file-based routes, server `load` functions, form actions that work without JavaScript, streaming SSR, WebSockets and a plugin system. If you know SvelteKit, most of it will feel familiar.
4
+
5
+ ```sh
6
+ bun i -g @sigil-dev/cli
7
+ sigil create my-app && cd my-app && sigil dev
8
+ ```
9
+
10
+ ## Routes
11
+
12
+ Files in `src/routes` are pages and endpoints:
13
+
14
+ | File | What it is |
15
+ | --- | --- |
16
+ | `+page.tsx` | A page (`about.tsx` and `about/index.tsx` work too) |
17
+ | `+page.server.ts` | Its `load` and form actions, server only |
18
+ | `+layout.tsx`, `+layout.server.ts` | A layout and its data |
19
+ | `+server.ts` | An endpoint: `GET`, `POST`, … return a `Response` |
20
+ | `+error.tsx` | The error page for everything below it |
21
+ | `hooks.server.ts` | Per-request middleware, at the project root |
22
+
23
+ `[slug]` is a parameter, `[[...rest]]` an optional catch-all.
24
+
25
+ ```ts
26
+ // src/routes/posts/[slug]/+page.server.ts
27
+ import { error, fail, redirect } from "@sigil-dev/grimoire";
28
+
29
+ export async function load({ params }) {
30
+ const post = await db.posts.findFirst({ where: { slug: params.slug } });
31
+ if (!post) throw error(404, "Post not found");
32
+ return { post }; // the page's `data` prop
33
+ }
34
+
35
+ export async function comment({ request, locals }) {
36
+ const form = await request.formData(); // a <form method="POST" action="?/comment">
37
+ if (!form.get("body")) return fail(400, { error: "Say something" }); // the page's `form` prop
38
+ await saveComment(form, locals.user);
39
+ throw redirect(303, "/posts");
40
+ }
41
+ ```
42
+
43
+ ```tsx
44
+ // src/routes/posts/[slug]/+page.tsx
45
+ export default function Post({ data, form }) {
46
+ return (
47
+ <article>
48
+ <h1>{data.post.title}</h1>
49
+ <form method="POST" action="?/comment">
50
+ <textarea name="body" />
51
+ {form?.error && <p>{form.error}</p>}
52
+ <button>Comment</button>
53
+ </form>
54
+ </article>
55
+ );
56
+ }
57
+ ```
58
+
59
+ Every form post carries a CSRF token; Grimoire adds it to rendered forms for you.
60
+
61
+ ## Batteries
62
+
63
+ These are separate packages, so an app only carries what it uses:
64
+
65
+ - [`@sigil-dev/tome`](https://www.npmjs.com/package/@sigil-dev/tome): schema, typed queries, validation and migrations
66
+ - [`@sigil-dev/auth`](https://www.npmjs.com/package/@sigil-dev/auth): sign-up, sign-in, sessions and OAuth
67
+ - [`@sigil-dev/plugin-sql`](https://www.npmjs.com/package/@sigil-dev/plugin-sql): the database connection
68
+ - [`@sigil-dev/plugin-jobs`](https://www.npmjs.com/package/@sigil-dev/plugin-jobs): background jobs and schedules
69
+ - `plugin-health`, `plugin-sentry`, `plugin-namepool`: health checks, error tracking, worker names
70
+
71
+ ## Configuration
72
+
73
+ ```ts
74
+ // sigil.config.ts
75
+ import { defineConfig } from "@sigil-dev/grimoire";
76
+
77
+ export default defineConfig({
78
+ port: 3000,
79
+ plugins: [],
80
+ });
81
+ ```
82
+
83
+ **Docs:** [sigil.cane1712.dev/docs](https://sigil.cane1712.dev/docs). Start with the [tutorial](https://sigil.cane1712.dev/docs/tutorial), or go to [routing](https://sigil.cane1712.dev/docs/reference/routing), [loading](https://sigil.cane1712.dev/docs/reference/loading), [actions](https://sigil.cane1712.dev/docs/reference/actions), [hooks](https://sigil.cane1712.dev/docs/reference/hooks) and [deploying](https://sigil.cane1712.dev/docs/guides/deploying).
package/index.ts CHANGED
@@ -1,48 +1,50 @@
1
- // server loads call depends() to register invalidation keys
2
- export { depends } from "./src/client/deps";
3
- export type { Deferred } from "./src/client/deferred";
4
- export { deferred, onDeferred } from "./src/client/deferred";
5
- export { Head } from "./src/rendering/head";
6
- // registerSSRPlugin is server-only — import from "@sigil-dev/grimoire/bun"
7
- export type { RouteFile, RouteTree } from "./src/routing/scanner";
8
- export type { ErrorResult } from "./src/sentinels/error.ts";
9
- export { error, isErrorResult } from "./src/sentinels/error.ts";
10
- export type { FailResult } from "./src/sentinels/fail.ts";
11
- export { fail, isFailResult } from "./src/sentinels/fail.ts";
12
- export type { RedirectResult } from "./src/sentinels/redirect.ts";
13
- export { isRedirectResult, redirect } from "./src/sentinels/redirect.ts";
14
- export type {
15
- CookieOptions,
16
- Cookies,
17
- Handle,
18
- RequestEvent,
19
- ResolveFunction,
20
- } from "./src/server/hooks";
21
- export {
22
- type CachedFn,
23
- type CachedOptions,
24
- cached,
25
- cachedBy,
26
- } from "./src/server/cached";
27
- export { clientAddress } from "./src/server/client-address";
28
- export { createHooks, sequence } from "./src/server/hooks";
29
- export type {
30
- BuiltinWorkerMode,
31
- CliCommand,
32
- CoordinatorContext,
33
- GrimoireConfig,
34
- GrimoirePlugin,
35
- LayoutServerLoad,
36
- LoadContext,
37
- PageServerLoad,
38
- RenderContext,
39
- RequestHandler,
40
- RouteInfo,
41
- TypedLoadContext,
42
- WorkerDescriptor,
43
- WorkerEnv,
44
- WorkerMode,
45
- WsRouteHandler,
46
- WorkerContext,
47
- } from "./src/types";
48
- export { defineConfig, workerContext } from "./src/types";
1
+ // the path the app is served under, and the helper that puts it on a URL
2
+ export { base, withBase } from "./src/base";
3
+ // server loads call depends() to register invalidation keys
4
+ export { depends } from "./src/client/deps";
5
+ export type { Deferred } from "./src/client/deferred";
6
+ export { deferred, onDeferred } from "./src/client/deferred";
7
+ export { Head } from "./src/rendering/head";
8
+ // registerSSRPlugin is server-only — import from "@sigil-dev/grimoire/bun"
9
+ export type { RouteFile, RouteTree } from "./src/routing/scanner";
10
+ export type { ErrorResult } from "./src/sentinels/error.ts";
11
+ export { error, isErrorResult } from "./src/sentinels/error.ts";
12
+ export type { FailResult } from "./src/sentinels/fail.ts";
13
+ export { fail, isFailResult } from "./src/sentinels/fail.ts";
14
+ export type { RedirectResult } from "./src/sentinels/redirect.ts";
15
+ export { isRedirectResult, redirect } from "./src/sentinels/redirect.ts";
16
+ export type {
17
+ CookieOptions,
18
+ Cookies,
19
+ Handle,
20
+ RequestEvent,
21
+ ResolveFunction,
22
+ } from "./src/server/hooks";
23
+ export {
24
+ type CachedFn,
25
+ type CachedOptions,
26
+ cached,
27
+ cachedBy,
28
+ } from "./src/server/cached";
29
+ export { clientAddress } from "./src/server/client-address";
30
+ export { createHooks, sequence } from "./src/server/hooks";
31
+ export type {
32
+ BuiltinWorkerMode,
33
+ CliCommand,
34
+ CoordinatorContext,
35
+ GrimoireConfig,
36
+ GrimoirePlugin,
37
+ LayoutServerLoad,
38
+ LoadContext,
39
+ PageServerLoad,
40
+ RenderContext,
41
+ RequestHandler,
42
+ RouteInfo,
43
+ TypedLoadContext,
44
+ WorkerDescriptor,
45
+ WorkerEnv,
46
+ WorkerMode,
47
+ WsRouteHandler,
48
+ WorkerContext,
49
+ } from "./src/types";
50
+ export { defineConfig, workerContext } from "./src/types";
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "module": "index.ts",
12
12
  "type": "module",
13
13
  "private": false,
14
- "version": "0.9.21",
14
+ "version": "0.9.22",
15
15
  "exports": {
16
16
  ".": "./index.ts",
17
17
  "./server": "./server.ts",
@@ -24,18 +24,29 @@
24
24
  "./bun": "./src/rendering/ssrPlugin.ts",
25
25
  "./env/public": "./src/env/public.ts",
26
26
  "./env/private": "./src/env/private.ts",
27
- "./logger": "./src/logger/index.ts"
27
+ "./logger": "./src/logger/index.ts",
28
+ "./adapters/static": "./src/adapters/static.ts",
29
+ "./adapters/bun": "./src/adapters/bun.ts",
30
+ "./testing": "./src/testing/index.ts",
31
+ "./testing/dom": "./src/testing/dom.ts",
32
+ "./testing/server": "./src/testing/server.ts"
28
33
  },
29
34
  "scripts": {
30
35
  "test": "bun test"
31
36
  },
32
37
  "dependencies": {
33
- "@sigil-dev/compiler": "0.9.21",
34
- "@sigil-dev/runtime": "0.9.21",
38
+ "@sigil-dev/compiler": "0.9.22",
39
+ "@sigil-dev/runtime": "0.9.22",
35
40
  "vite": "^8.0.16"
36
41
  },
37
42
  "peerDependencies": {
38
- "typescript": "^5"
43
+ "typescript": "^5",
44
+ "happy-dom": "*"
45
+ },
46
+ "peerDependenciesMeta": {
47
+ "happy-dom": {
48
+ "optional": true
49
+ }
39
50
  },
40
51
  "devDependencies": {
41
52
  "@babel/core": "8.0.0-rc.6",
@@ -0,0 +1,12 @@
1
+ // Grimoire client shim for HMR dev mode
2
+ export function Head({ children }) {
3
+ if (children instanceof Node) {
4
+ document.head.appendChild(children);
5
+ }
6
+ return document.createComment("head");
7
+ }
8
+
9
+ export const navigate = (...args) => window.__grimoire_navigate__?.(...args);
10
+ export const beforeNavigate = (cb) => window.__grimoire_beforeNavigate__?.(cb);
11
+ export const onNavigate = (cb) => window.__grimoire_onNavigate__?.(cb);
12
+ export const afterNavigate = (cb) => window.__grimoire_afterNavigate__?.(cb);