@rsc-kit/mcp 0.40.0 → 0.42.0

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 (60) hide show
  1. package/dist/recipes.js +37 -20
  2. package/dist/recipes.js.map +1 -1
  3. package/guides/admin-plugins.md +206 -6
  4. package/guides/api-routes.md +159 -215
  5. package/guides/authorization.md +103 -114
  6. package/guides/backend-answered-pages.md +301 -250
  7. package/guides/bap-vs-inertia.md +67 -25
  8. package/guides/blueprints.md +307 -174
  9. package/guides/bun.md +42 -25
  10. package/guides/caching.md +46 -49
  11. package/guides/coming-from-inertia.md +5 -5
  12. package/guides/commands.md +251 -200
  13. package/guides/connection.md +50 -54
  14. package/guides/content-security-policy.md +133 -84
  15. package/guides/domains.md +190 -149
  16. package/guides/edge-caching.md +242 -268
  17. package/guides/emails.md +96 -45
  18. package/guides/errors.md +116 -137
  19. package/guides/feature-flags.md +100 -30
  20. package/guides/file-uploads.md +101 -26
  21. package/guides/fonts.md +139 -110
  22. package/guides/forms.md +520 -538
  23. package/guides/images.md +87 -28
  24. package/guides/index.json +13 -33
  25. package/guides/instrumentation.md +134 -95
  26. package/guides/isr.md +3 -3
  27. package/guides/live-data-in-production.md +695 -0
  28. package/guides/live-data.md +170 -839
  29. package/guides/mcp.md +83 -59
  30. package/guides/metadata.md +124 -179
  31. package/guides/navigation.md +118 -147
  32. package/guides/no-javascript.md +49 -57
  33. package/guides/offline.md +118 -153
  34. package/guides/openapi.md +100 -35
  35. package/guides/pages.md +160 -50
  36. package/guides/ppr.md +178 -256
  37. package/guides/pwa.md +251 -218
  38. package/guides/queries.md +171 -300
  39. package/guides/react-compiler.md +90 -50
  40. package/guides/redirects.md +141 -177
  41. package/guides/response-headers.md +76 -74
  42. package/guides/route-interception.md +112 -111
  43. package/guides/routing.md +216 -322
  44. package/guides/sections.md +63 -66
  45. package/guides/seo-files.md +127 -65
  46. package/guides/server-actions.md +285 -357
  47. package/guides/static-generation.md +131 -199
  48. package/guides/testing.md +272 -150
  49. package/guides/third-party-scripts.md +94 -47
  50. package/guides/typed-routes.md +115 -113
  51. package/guides/url-validation.md +113 -61
  52. package/guides/validation.md +53 -62
  53. package/guides/view-transitions.md +159 -132
  54. package/guides/where-it-runs.md +226 -162
  55. package/package.json +2 -2
  56. package/guides/admin.md +0 -520
  57. package/guides/deployment.md +0 -598
  58. package/guides/go.md +0 -538
  59. package/guides/laravel.md +0 -786
  60. package/guides/your-own-backend.md +0 -587
package/guides/pages.md CHANGED
@@ -3,15 +3,27 @@
3
3
  > Landing pages, an about page, a pricing page - built in the admin panel from the app's own blocks, live on the next visit.
4
4
 
5
5
  `@rsc-kit/press/pages` lets an editor build pages in the [admin panel](/guides/admin/)
6
- from blocks the app defines - a hero, a feature grid, a call to action, a
7
- [blueprint's form](/guides/blueprints/) - and serves them from one catch-all
8
- route. The blocks are the app's code and look like the rest of the site; what
9
- is on a page, and in what order, is the editor's.
6
+ from blocks the app defines: a hero, a feature grid, a call to action, a
7
+ [blueprint's form](/guides/blueprints/). One catch-all route serves them. The
8
+ blocks are the app's code and look like the rest of the site; what is on a
9
+ page, and in what order, is the editor's.
10
10
 
11
- ## Blocks
11
+ ```ts title="src/site/pages.ts"
12
+ import { definePages } from '@rsc-kit/press/pages'
13
+ import { features, hero, text } from './blocks'
14
+
15
+ export const site = definePages({
16
+ blocks: [hero, features, text],
17
+ source: pagesSource,
18
+ })
19
+ ```
12
20
 
13
- A block is a schema for what an editor fills in and a component that draws
14
- it:
21
+ An editor adds a page in the panel, picks blocks and fills them in. It is live
22
+ at its address on the next visit, with nothing rebuilt.
23
+
24
+ ## Defining a block
25
+
26
+ A block is a schema for what an editor fills in, and a component that draws it:
15
27
 
16
28
  ```tsx title="src/site/blocks.tsx"
17
29
  import * as z from 'zod'
@@ -33,13 +45,54 @@ export const hero = defineBlock({
33
45
  })
34
46
  ```
35
47
 
36
- `form` is any Standard Schema, and `fields` overrides what it cannot say, as a
37
- [resource's form](/guides/admin/#the-form-is-any-standard-schema) does. `render`
38
- is a server component and may be async: a block that lists the latest posts
39
- reads them itself. A block can place a public form - `render: () => <contact.Form />` -
40
- so the editor decides where it goes and the code decides what it does.
48
+ - `name` is what it is saved as: lowercase letters, digits and dashes.
49
+ - `label` is what an editor picks it by. It is made from the name unless said.
50
+ - `form` is any Standard Schema, and `fields` sets what it cannot say, as a
51
+ [resource's form](/guides/admin/forms/#the-form-is-any-standard-schema) does.
52
+ - `render` is a server component and may be async.
53
+
54
+ ### A block that reads data
55
+
56
+ A block that lists the latest posts reads them itself:
57
+
58
+ ```tsx
59
+ export const latestPosts = defineBlock({
60
+ name: 'latest-posts',
61
+ form: z.object({ heading: z.string(), count: z.number().int().min(1).max(12) }),
62
+ render: async ({ data }) => {
63
+ const posts = await latest(data.count)
64
+
65
+ return (
66
+ <section>
67
+ <h2>{data.heading}</h2>
68
+ <ul>{posts.map((post) => <li key={post.id}>{post.title}</li>)}</ul>
69
+ </section>
70
+ )
71
+ },
72
+ })
73
+ ```
74
+
75
+ ### A block with a form
41
76
 
42
- ## The pages
77
+ A block can place a public form, so the editor decides where it goes and the
78
+ code decides what it does:
79
+
80
+ ```tsx
81
+ import { contact } from '@/forms/contact'
82
+
83
+ export const contactForm = defineBlock({
84
+ name: 'contact-form',
85
+ form: z.object({ heading: z.string() }),
86
+ render: ({ data }) => (
87
+ <section>
88
+ <h2>{data.heading}</h2>
89
+ <contact.Form />
90
+ </section>
91
+ ),
92
+ })
93
+ ```
94
+
95
+ ## Serving the pages
43
96
 
44
97
  ```ts title="src/site/pages.ts"
45
98
  import { FileText } from 'lucide-react'
@@ -80,51 +133,78 @@ export default site.middleware
80
133
  resources: [site.resource, products, customers],
81
134
  ```
82
135
 
83
- The catch-all is the weakest route there is, so every page and route the app
84
- has wins over it; it answers only the addresses nothing else does. A page's
85
- slug is its address - `about`, `pricing/teams` - and the one named `home` is
86
- served at `/` when the app has no `app/page.tsx` of its own (`home` changes
87
- which).
136
+ - The catch-all is the weakest route there is, so every page and route the app
137
+ has wins over it. It answers only the addresses nothing else does.
138
+ - A page's slug is its address: `about`, `pricing/teams`.
139
+ - A page's title and description become its `<title>` and meta description,
140
+ through `generateMetadata`.
141
+ - A draft is a page with Published off, reachable only in the panel.
142
+ - `blocks` lists the kinds of block an editor is offered, in that order.
143
+
144
+ ### The home page
145
+
146
+ The page named `home` is served at `/` when the app has no `app/page.tsx` of
147
+ its own. `home` changes which:
148
+
149
+ ```ts
150
+ export const site = definePages({ blocks, source, home: 'welcome' })
151
+ ```
152
+
153
+ ### A real 404
88
154
 
89
155
  The middleware asks whether there is a published page at the address before
90
- anything is sent, so a draft or a typo is a real **404**. Without it the
156
+ anything is sent, so a draft or a typo is a real **404**. Without it, the
91
157
  route's shell has already gone out with a 200 by the time the page finds
92
- nothing - see [Errors](/guides/errors/#when-the-page-has-to-decide).
158
+ nothing. See [Errors](/guides/errors/#when-the-page-has-to-decide).
159
+
160
+ ### While a page is looked up
161
+
162
+ `fallback` is what shows while a page is looked up. Nothing shows by default:
163
+
164
+ ```tsx
165
+ export const site = definePages({ blocks, source, fallback: <Skeleton className="h-96" /> })
166
+ ```
93
167
 
94
168
  ## Live on the next visit
95
169
 
96
170
  A save in the panel is live on the next visit, and nothing is rebuilt. A page
97
- is looked up once and then kept, so most visits do not ask the source at all:
98
- for 60 seconds, or until any page is saved. The page is kept with
99
- [`cache()`](/guides/caching/#across-requests), in memory unless the app installs
100
- a shared store. `revalidate` sets the lifetime, and `false` asks on every
101
- request:
171
+ is looked up once and then kept, so most visits don't ask the source at all:
172
+ for 60 seconds, or until any page is saved.
173
+
174
+ `revalidate` sets how long, in seconds, and `false` asks on every request:
102
175
 
103
176
  ```ts
104
177
  export const site = definePages({ blocks, source, revalidate: 300 })
105
178
  ```
106
179
 
107
180
  A change made around the panel, straight in the database, shows when the kept
108
- copy expires, or at once after `changed('press:pages')`. The build stores the route's
109
- frame as one shell for every address, and the page streams into it. A page
110
- also has a title and a description, which become its `<title>` and meta
111
- description; a draft is a page with Published off, reachable only in the
112
- panel.
181
+ copy expires, or at once after `changed('press:pages')`:
182
+
183
+ ```ts
184
+ import { changed } from '@rsc-kit/core/changed'
185
+
186
+ await changed('press:pages')
187
+ ```
188
+
189
+ - The page is kept with [`cache()`](/guides/caching/#across-requests), in memory
190
+ unless the app installs a shared store.
191
+ - The build stores the route's frame as one shell for every address, and the
192
+ page streams into it.
113
193
 
114
194
  ## Where pages are kept
115
195
 
116
- `source` is a [data source](/guides/admin/#any-data-source) of rows shaped
117
- `{ id, title, slug, description?, published, blocks }`, where `blocks` is a
118
- list of `{ type, data }` - a JSON column in a database. Its `list()` is also
119
- how a page is found by its address: it is asked for `filters: { slug }`, and
120
- must answer with the page at that slug. `memorySource` does; a Laravel or Go
121
- backend behind `rpc()` filters on the column.
196
+ `source` is a [data source](/guides/admin/data-sources/) of rows shaped
197
+ `{ id, title, slug, description?, published, blocks }`. `blocks` is a list of
198
+ `{ type, data }`, a JSON column in a database.
199
+
200
+ Its `list()` is also how a page is found by its address:
201
+ it is asked for `filters: { slug }`, and must answer with the page at that slug.
122
202
 
123
- `memorySource` keeps the pages in the process's memory: an edit is gone
124
- when the server restarts, and two servers each have their own copy. It is
125
- for a demo, or for pages that only ever come from rows in code. Pages an
126
- editor saves belong where the app keeps its other data. On a Laravel or Go
127
- backend that is a `pages` table with a JSON `blocks` column, behind `rpc()`:
203
+ ### In a Laravel or Go backend
204
+
205
+ Pages an editor saves belong where the app keeps its other data. On a Laravel
206
+ or Go backend that is a `pages` table with a JSON `blocks` column, behind
207
+ `rpc()`:
128
208
 
129
209
  ```ts title="src/site/pages.ts"
130
210
  const pagesSource: DataSource<PageRow, PageValues> = {
@@ -147,18 +227,47 @@ public function list(array $query): array
147
227
  }
148
228
  ```
149
229
 
150
- Cast `blocks` to an array on the model, and `published` to a boolean. An app
151
- with no backend writes the same five functions over its own database -
230
+ Cast `blocks` to an array on the model, and `published` to a boolean:
231
+
232
+ ```php title="app/Models/Page.php"
233
+ protected function casts(): array
234
+ {
235
+ return ['blocks' => 'array', 'published' => 'boolean'];
236
+ }
237
+ ```
238
+
239
+ An app with no backend writes the same five functions over its own database:
152
240
  Drizzle, Prisma, `bun:sqlite`.
153
241
 
154
- Each block's data is checked by its own schema on every save, and a refusal
155
- shows under that block's field. An address belongs to one page: saving a
156
- second page at `/about` is refused under its slug.
242
+ ### In memory, for a demo
243
+
244
+ `memorySource` keeps the pages in the process's memory, and filters on `slug`
245
+ as `list()` must:
246
+
247
+ ```ts
248
+ import { memorySource } from '@rsc-kit/press'
249
+
250
+ const pagesSource = memorySource<PageRow, PageValues>(
251
+ [{ id: 1, title: 'Home', slug: 'home', published: true, blocks: [] }],
252
+ 'id',
253
+ (id, values) => ({ id, ...values }),
254
+ )
255
+ ```
256
+
257
+ An edit is gone when the server restarts, and two servers each have their own
258
+ copy. It is for a demo, or for pages that only ever come from rows in code.
259
+
260
+ ### What a save checks
261
+
262
+ - Each block's data is checked by its own schema on every save, and a refusal
263
+ shows under that block's field.
264
+ - An address belongs to one page: saving a second page at `/about` is refused
265
+ under its slug.
157
266
 
158
267
  ## Blocks in any resource
159
268
 
160
- The block editor is a field type, so any resource can have one - a product's
161
- long description, a post's body:
269
+ The block editor is a field type, so any resource can have one, such as a
270
+ product's long description or a post's body:
162
271
 
163
272
  ```ts
164
273
  form: z.object({ name: z.string(), body: z.array(z.any()) }),
@@ -173,5 +282,6 @@ import { Blocks } from '@rsc-kit/press'
173
282
  <Blocks blocks={[text, gallery, quote]} value={post.body} />
174
283
  ```
175
284
 
176
- A block whose kind the code no longer defines is left out of the page rather
177
- than failing it, and the editor says that saving will remove it.
285
+ - A block whose kind the code no longer defines is left out of the page rather
286
+ than failing it, and the editor says that saving will remove it.
287
+ - Blocks don't nest: a block with a blocks field fails when it is defined.