@rshono/core 1.0.0-rc.0 → 1.0.0-rc.10

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 (143) hide show
  1. package/README.md +202 -159
  2. package/dist/builder/page-files.d.ts.map +1 -1
  3. package/dist/builder/page-files.js +7 -3
  4. package/dist/builder/page-files.js.map +1 -1
  5. package/dist/builder/public-env.d.ts +6 -0
  6. package/dist/builder/public-env.d.ts.map +1 -1
  7. package/dist/builder/public-env.js +6 -0
  8. package/dist/builder/public-env.js.map +1 -1
  9. package/dist/builder/rspack-config.d.ts +3 -3
  10. package/dist/builder/rspack-config.d.ts.map +1 -1
  11. package/dist/builder/rspack-config.js +62 -16
  12. package/dist/builder/rspack-config.js.map +1 -1
  13. package/dist/cli/build.d.ts +2 -2
  14. package/dist/cli/build.js.map +1 -1
  15. package/dist/cli/dev.d.ts +2 -2
  16. package/dist/cli/dev.d.ts.map +1 -1
  17. package/dist/cli/dev.js +63 -35
  18. package/dist/cli/dev.js.map +1 -1
  19. package/dist/cli/index.js +10 -10
  20. package/dist/cli/index.js.map +1 -1
  21. package/dist/config.d.ts +58 -70
  22. package/dist/config.d.ts.map +1 -1
  23. package/dist/config.js +17 -1
  24. package/dist/config.js.map +1 -1
  25. package/dist/deploy/cloudflare/build.js +1 -1
  26. package/dist/deploy/cloudflare/build.js.map +1 -1
  27. package/dist/deploy/cloudflare/runtime.d.ts.map +1 -1
  28. package/dist/deploy/cloudflare/runtime.js +7 -37
  29. package/dist/deploy/cloudflare/runtime.js.map +1 -1
  30. package/dist/deploy/contract.d.ts +22 -16
  31. package/dist/deploy/contract.d.ts.map +1 -1
  32. package/dist/deploy/contract.js.map +1 -1
  33. package/dist/deploy/filesystem.d.ts +1 -1
  34. package/dist/deploy/filesystem.d.ts.map +1 -1
  35. package/dist/deploy/filesystem.js +7 -10
  36. package/dist/deploy/filesystem.js.map +1 -1
  37. package/dist/deploy/node/runtime.d.ts +4 -0
  38. package/dist/deploy/node/runtime.d.ts.map +1 -1
  39. package/dist/deploy/node/runtime.js +24 -3
  40. package/dist/deploy/node/runtime.js.map +1 -1
  41. package/dist/deploy/presets.d.ts +3 -3
  42. package/dist/deploy/presets.d.ts.map +1 -1
  43. package/dist/deploy/presets.js +13 -30
  44. package/dist/deploy/presets.js.map +1 -1
  45. package/dist/deploy/vercel/runtime.d.ts.map +1 -1
  46. package/dist/deploy/vercel/runtime.js +0 -3
  47. package/dist/deploy/vercel/runtime.js.map +1 -1
  48. package/dist/index.d.ts +6 -9
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +8 -3
  51. package/dist/index.js.map +1 -1
  52. package/dist/router.d.ts +85 -48
  53. package/dist/router.d.ts.map +1 -1
  54. package/dist/router.js +4 -6
  55. package/dist/router.js.map +1 -1
  56. package/dist/runtime/boundaries.d.ts +39 -25
  57. package/dist/runtime/boundaries.d.ts.map +1 -1
  58. package/dist/runtime/boundaries.js +22 -17
  59. package/dist/runtime/boundaries.js.map +1 -1
  60. package/dist/runtime/client.d.ts +9 -8
  61. package/dist/runtime/client.d.ts.map +1 -1
  62. package/dist/runtime/client.js +9 -8
  63. package/dist/runtime/client.js.map +1 -1
  64. package/dist/runtime/context.d.ts +216 -70
  65. package/dist/runtime/context.d.ts.map +1 -1
  66. package/dist/runtime/context.js +299 -93
  67. package/dist/runtime/context.js.map +1 -1
  68. package/dist/runtime/control.d.ts.map +1 -1
  69. package/dist/runtime/control.js +7 -0
  70. package/dist/runtime/control.js.map +1 -1
  71. package/dist/runtime/dev-protocol.d.ts.map +1 -1
  72. package/dist/runtime/dev-protocol.js.map +1 -1
  73. package/dist/runtime/entry.client.d.ts +4 -0
  74. package/dist/runtime/entry.client.d.ts.map +1 -1
  75. package/dist/runtime/entry.client.js +190 -154
  76. package/dist/runtime/entry.client.js.map +1 -1
  77. package/dist/runtime/entry.rsc.d.ts.map +1 -1
  78. package/dist/runtime/entry.rsc.js +145 -159
  79. package/dist/runtime/entry.rsc.js.map +1 -1
  80. package/dist/runtime/entry.ssr.d.ts +9 -1
  81. package/dist/runtime/entry.ssr.d.ts.map +1 -1
  82. package/dist/runtime/entry.ssr.js +36 -18
  83. package/dist/runtime/entry.ssr.js.map +1 -1
  84. package/dist/runtime/flight-inject.d.ts +31 -0
  85. package/dist/runtime/flight-inject.d.ts.map +1 -0
  86. package/dist/runtime/flight-inject.js +221 -0
  87. package/dist/runtime/flight-inject.js.map +1 -0
  88. package/dist/runtime/navigation.d.ts +20 -38
  89. package/dist/runtime/navigation.d.ts.map +1 -1
  90. package/dist/runtime/navigation.js +10 -53
  91. package/dist/runtime/navigation.js.map +1 -1
  92. package/dist/runtime/request.d.ts +6 -0
  93. package/dist/runtime/request.d.ts.map +1 -1
  94. package/dist/runtime/request.js +8 -0
  95. package/dist/runtime/request.js.map +1 -1
  96. package/dist/runtime/server.d.ts +7 -12
  97. package/dist/runtime/server.d.ts.map +1 -1
  98. package/dist/runtime/server.js +15 -12
  99. package/dist/runtime/server.js.map +1 -1
  100. package/dist/server/headers.d.ts +9 -9
  101. package/dist/server/headers.js +9 -9
  102. package/dist/server/headers.js.map +1 -1
  103. package/dist/server/load-config.d.ts +2 -2
  104. package/dist/server/load-config.d.ts.map +1 -1
  105. package/dist/server/load-config.js +22 -11
  106. package/dist/server/load-config.js.map +1 -1
  107. package/dist/server/prerendered.d.ts +43 -15
  108. package/dist/server/prerendered.d.ts.map +1 -1
  109. package/dist/server/prerendered.js +47 -0
  110. package/dist/server/prerendered.js.map +1 -1
  111. package/dist/server/server-config.d.ts +13 -39
  112. package/dist/server/server-config.d.ts.map +1 -1
  113. package/dist/server/server-config.js +5 -74
  114. package/dist/server/server-config.js.map +1 -1
  115. package/dist/server/ssg.d.ts +2 -2
  116. package/dist/server/ssg.d.ts.map +1 -1
  117. package/dist/server/ssg.js +21 -34
  118. package/dist/server/ssg.js.map +1 -1
  119. package/package.json +13 -16
  120. package/dist/deploy/bun/runtime.d.ts +0 -11
  121. package/dist/deploy/bun/runtime.d.ts.map +0 -1
  122. package/dist/deploy/bun/runtime.js +0 -22
  123. package/dist/deploy/bun/runtime.js.map +0 -1
  124. package/dist/deploy/deno/runtime.d.ts +0 -11
  125. package/dist/deploy/deno/runtime.d.ts.map +0 -1
  126. package/dist/deploy/deno/runtime.js +0 -16
  127. package/dist/deploy/deno/runtime.js.map +0 -1
  128. package/dist/deploy/listen.d.ts +0 -20
  129. package/dist/deploy/listen.d.ts.map +0 -1
  130. package/dist/deploy/listen.js +0 -24
  131. package/dist/deploy/listen.js.map +0 -1
  132. package/dist/deploy/netlify/build.d.ts +0 -8
  133. package/dist/deploy/netlify/build.d.ts.map +0 -1
  134. package/dist/deploy/netlify/build.js +0 -52
  135. package/dist/deploy/netlify/build.js.map +0 -1
  136. package/dist/deploy/netlify/runtime.d.ts +0 -13
  137. package/dist/deploy/netlify/runtime.d.ts.map +0 -1
  138. package/dist/deploy/netlify/runtime.js +0 -24
  139. package/dist/deploy/netlify/runtime.js.map +0 -1
  140. package/dist/server/compress.d.ts +0 -15
  141. package/dist/server/compress.d.ts.map +0 -1
  142. package/dist/server/compress.js +0 -76
  143. package/dist/server/compress.js.map +0 -1
package/dist/router.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Env, Handler } from 'hono';
2
2
  import type { ParamKeys, ParamKeyToRecord } from 'hono/types';
3
3
  import type { ReactNode } from 'react';
4
- import type { Ctx } from './runtime/context.js';
4
+ import type { RequestContext } from './runtime/context.js';
5
5
  type Simplify<T> = {
6
6
  [K in keyof T]: T[K];
7
7
  } & {};
@@ -19,6 +19,8 @@ type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) exten
19
19
  * ```ts
20
20
  * type P = PathParams<'/users/:id/posts/:postId'>; // { id: string; postId: string }
21
21
  * ```
22
+ *
23
+ * @see {@link https://hono.dev/docs/api/routing#path-parameter | Hono — path parameters}
22
24
  */
23
25
  export type PathParams<P extends string> = ParamKeys<P> extends never ? Record<string, never> : Simplify<UnionToIntersection<ParamKeyToRecord<ParamKeys<P>>>>;
24
26
  /**
@@ -34,8 +36,8 @@ export type PathParams<P extends string> = ParamKeys<P> extends never ? Record<s
34
36
  * the server/client line is a copy-paste.
35
37
  *
36
38
  * @typeParam Path - The literal path this page is mounted at, e.g. `'/profile/:id'`.
37
- * @typeParam E - The app's Hono {@link Env}, to type {@link Ctx.var} and
38
- * {@link Ctx.env} on {@link PageProps.ctx}.
39
+ * @typeParam E - The app's Hono {@link Env}, to type {@link RequestContext.var} and
40
+ * {@link RequestContext.env} on {@link PageProps.ctx}.
39
41
  *
40
42
  * @example
41
43
  * ```tsx
@@ -47,6 +49,8 @@ export type PathParams<P extends string> = ParamKeys<P> extends never ? Record<s
47
49
  * return <Layout>{user.name} — {tab}</Layout>;
48
50
  * }
49
51
  * ```
52
+ *
53
+ * @see {@link https://www.rshono.com/docs/pages#page-props | Docs — page props}
50
54
  */
51
55
  export interface PageProps<Path extends string = string, E extends Env = Env> {
52
56
  /**
@@ -55,42 +59,35 @@ export interface PageProps<Path extends string = string, E extends Env = Env> {
55
59
  * the rest off it.
56
60
  *
57
61
  * A fresh instance per request that nothing else holds, so mutating it is local
58
- * to the page — but note it is *not* serializable, so a `'use client'` component
59
- * has to be handed `url.href` rather than `url`.
62
+ * to the page. It is not serializable, so a `'use client'` component has to be
63
+ * handed `url.href` rather than `url`.
60
64
  *
61
- * On a prerendered page it is the build-time URL: a `render: 'static'` route is
62
- * rendered once, against `siteUrl` and with no query string, and that one file
63
- * then answers every request whatever its own query. So `url.searchParams` is
64
- * always empty there — read the query from `useNavigation().url` in a
65
- * `'use client'` component instead, or mark the route `render: 'dynamic'`.
65
+ * On a `render: 'static'` route this is the build-time URL — rendered once
66
+ * against `siteUrl` with no query string, and that one file answers every
67
+ * request whatever its own query. So `url.searchParams` is always empty there:
68
+ * read the query from `useNavigation().url` in a `'use client'` component
69
+ * instead, or mark the route `render: 'dynamic'`.
66
70
  */
67
71
  url: URL;
68
72
  /** Matched route params for this request, e.g. `{ id: '42' }` for `/profile/:id`. */
69
73
  params: string extends Path ? Record<string, string> : PathParams<Path>;
70
74
  /**
71
- * The request context — the very object `getContext()` returns, handed to the
75
+ * The request context — the very object `getRequestContext()` returns, handed to the
72
76
  * page so cookies, headers, env and middleware variables are reachable without
73
77
  * an import.
74
78
  *
75
- * Server-only, and never serialized: React renders a server component and puts
76
- * its *output* on the wire, not its props. It is also deliberately a
77
- * non-enumerable property, which has three consequences worth knowing:
78
- *
79
- * - It **cannot be handed to a `'use client'` component** — it wraps the live
80
- * request and response, which do not exist in the browser. Passing it
81
- * explicitly (`<Counter ctx={ctx} />`) fails the render with React's *"Only
82
- * plain objects … can be passed to Client Components"*. Read what you need on
83
- * the server and pass plain values down.
84
- * - Spreading the page's props instead (`<Counter {...props} />`) drops `ctx`
85
- * silently rather than failing, since the spread copies enumerables only.
86
- * (That spread still fails, mind — on `url`, which is enumerable and just as
87
- * unserializable. Pass the values you need.)
88
- * - `Object.keys(props)`, `JSON.stringify(props)` and friends don't see it.
79
+ * Server-only and never serialized: React puts a server component's *output* on
80
+ * the wire, not its props. It is also deliberately **non-enumerable**, so
81
+ * `Object.keys(props)`, `JSON.stringify(props)` and a `{...props}` spread all
82
+ * skip it. Handing it to a `'use client'` component directly
83
+ * (`<Counter ctx={ctx} />`) fails the render — it wraps the live request and
84
+ * response, which do not exist in the browser. Read what you need here and pass
85
+ * plain values down.
89
86
  *
90
87
  * Reading it on a `render: 'static'` route throws: a prerendered page has no
91
- * per-request context at build time. Mark the route `render: 'dynamic'` (or use
92
- * the `url` / `params` props, which are available either way — with the
93
- * build-time caveats noted on `url`).
88
+ * per-request context at build time. Mark the route `render: 'dynamic'`, or use
89
+ * the `url` / `params` props — available either way, with the build-time caveat
90
+ * noted on `url`.
94
91
  *
95
92
  * @example
96
93
  * ```tsx
@@ -101,7 +98,7 @@ export interface PageProps<Path extends string = string, E extends Env = Env> {
101
98
  * }
102
99
  * ```
103
100
  */
104
- ctx: Ctx<E>;
101
+ ctx: RequestContext<E>;
105
102
  }
106
103
  /**
107
104
  * A page: a React **server component** that renders the entire document
@@ -112,6 +109,9 @@ export interface PageProps<Path extends string = string, E extends Env = Env> {
112
109
  * belong in `'use client'` components the page imports — only those ship JS.
113
110
  *
114
111
  * @typeParam P - The component's props; for a page these are {@link PageProps}.
112
+ *
113
+ * @see {@link https://react.dev/reference/rsc/server-components | React — Server Components}
114
+ * @see {@link https://www.rshono.com/docs/pages | Docs — pages}
115
115
  */
116
116
  export type PageComponent<P = any> = (props: P) => ReactNode | Promise<ReactNode>;
117
117
  /**
@@ -122,13 +122,21 @@ export type PageComponent<P = any> = (props: P) => ReactNode | Promise<ReactNode
122
122
  * @example
123
123
  * ```ts
124
124
  * // src/health.ts
125
- * import type { Handler } from '@rshono/core';
125
+ * import type { Handler } from 'hono';
126
126
  *
127
127
  * export const handler: Handler = (c) => c.json({ ok: true });
128
128
  * ```
129
+ *
130
+ * @see {@link https://www.rshono.com/docs/routing#endpoint-routes | Docs — endpoint routes}
129
131
  */
130
132
  export interface EndpointServerModule {
131
- /** A Hono {@link Handler} handling every request matched by the route. */
133
+ /**
134
+ * A Hono {@link Handler} handling every request matched by the route. It is passed Hono's
135
+ * `Context`, so the request, response builders (`c.json`, `c.text`, `c.body`) and middleware
136
+ * variables are all reached through it.
137
+ *
138
+ * @see {@link https://hono.dev/docs/api/context | Hono — Context}
139
+ */
132
140
  handler: Handler;
133
141
  }
134
142
  /**
@@ -143,7 +151,12 @@ export interface EndpointServerModule {
143
151
  export interface PageRoute {
144
152
  /** Discriminates a page from an endpoint; optional because `'page'` is the default. */
145
153
  type?: 'page';
146
- /** Hono-style path pattern, e.g. `/`, `/profile/:id`, `/files/*`. */
154
+ /**
155
+ * Hono-style path pattern, e.g. `/`, `/profile/:id`, `/files/*`. Routes are matched in
156
+ * declaration order.
157
+ *
158
+ * @see {@link https://hono.dev/docs/api/routing | Hono — routing}
159
+ */
147
160
  path: string;
148
161
  /**
149
162
  * Dynamic import of the page module, whose default export is the
@@ -156,6 +169,8 @@ export interface PageRoute {
156
169
  * component up any other way — a variable, a barrel re-export, a computed
157
170
  * specifier — add `'use server-entry'` as the first line of the page module
158
171
  * yourself; the framework throws a descriptive error when neither happened.
172
+ *
173
+ * @see {@link https://www.rshono.com/docs/pages#the-use-server-entry-directive | Docs — the `'use server-entry'` directive}
159
174
  */
160
175
  component: () => Promise<{
161
176
  default: PageComponent;
@@ -180,6 +195,8 @@ export interface PageRoute {
180
195
  * staticPaths: async () => (await db.docs.all()).map((d) => ({ slug: d.slug })),
181
196
  * }
182
197
  * ```
198
+ *
199
+ * @see {@link https://www.rshono.com/docs/routing#static-rendering | Docs — static rendering}
183
200
  */
184
201
  staticPaths?: () => Array<Record<string, string>> | Promise<Array<Record<string, string>>>;
185
202
  }
@@ -192,11 +209,17 @@ export interface PageRoute {
192
209
  * ```ts
193
210
  * { type: 'endpoint', path: '/api/health', server: () => import('./health') }
194
211
  * ```
212
+ *
213
+ * @see {@link https://www.rshono.com/docs/routing#endpoint-routes | Docs — endpoint routes}
195
214
  */
196
215
  export interface EndpointRoute {
197
216
  /** Marks this route as an endpoint rather than a page. Required. */
198
217
  type: 'endpoint';
199
- /** Hono-style path pattern, e.g. `/api/health`, `/api/users/:id`. */
218
+ /**
219
+ * Hono-style path pattern, e.g. `/api/health`, `/api/users/:id`.
220
+ *
221
+ * @see {@link https://hono.dev/docs/api/routing | Hono — routing}
222
+ */
200
223
  path: string;
201
224
  /** HTTP method to match. Defaults to `'all'` — every method. */
202
225
  method?: HTTPMethod;
@@ -211,12 +234,10 @@ export type Route = PageRoute | EndpointRoute;
211
234
  * Type guard narrowing a {@link Route} to a {@link PageRoute}. Because `type` is
212
235
  * optional on page routes, anything not explicitly `'endpoint'` is a page.
213
236
  *
214
- * @example
215
- * ```ts
216
- * for (const route of routes) {
217
- * if (isPageRoute(route)) console.log(route.render ?? 'dynamic');
218
- * }
219
- * ```
237
+ * Framework internal — not re-exported from `index.ts`. The request renderer and
238
+ * the SSG pass use it to split the route table.
239
+ *
240
+ * @internal
220
241
  */
221
242
  export declare function isPageRoute(route: Route): route is PageRoute;
222
243
  /**
@@ -235,7 +256,7 @@ export interface FallbackPage {
235
256
  * message is a generic `'Internal Server Error'` and there is no `stack`. In dev
236
257
  * you get the real message plus the stack.
237
258
  */
238
- export interface ErrorInfo {
259
+ export interface ErrorPageInfo {
239
260
  /** The thrown error's message in dev; `'Internal Server Error'` in production. */
240
261
  message: string;
241
262
  /** The stack trace. Present in dev only. */
@@ -243,7 +264,7 @@ export interface ErrorInfo {
243
264
  }
244
265
  /**
245
266
  * Props for the `error` page declared in {@link RouteConfig.error} — the usual
246
- * {@link PageProps} plus the redaction-aware {@link ErrorInfo}.
267
+ * {@link PageProps} plus the redaction-aware {@link ErrorPageInfo}.
247
268
  *
248
269
  * @typeParam E - The app's Hono {@link Env}, forwarded to {@link PageProps.ctx}.
249
270
  *
@@ -257,7 +278,8 @@ export interface ErrorInfo {
257
278
  * ```
258
279
  */
259
280
  export type ErrorPageProps<E extends Env = Env> = PageProps<string, E> & {
260
- error: ErrorInfo;
281
+ /** The error that failed the request, redacted in production — see {@link ErrorPageInfo}. */
282
+ error: ErrorPageInfo;
261
283
  };
262
284
  /**
263
285
  * The object form accepted by {@link defineRoutes}: the route table plus the two
@@ -265,6 +287,8 @@ export type ErrorPageProps<E extends Env = Env> = PageProps<string, E> & {
265
287
  *
266
288
  * @typeParam TRoutes - Inferred tuple of route literals, which is what makes the
267
289
  * per-route `path` → props check possible.
290
+ *
291
+ * @see {@link https://www.rshono.com/docs/routing#notfound-and-error | Docs — notFound and error pages}
268
292
  */
269
293
  export interface RouteConfig<TRoutes extends readonly Route[] = readonly Route[]> {
270
294
  /** Every page and endpoint in the app, matched in order. */
@@ -298,8 +322,10 @@ type ValidateRoutes<TRoutes extends readonly Route[]> = {
298
322
  * PageProps<'/…'>`. Fix it by matching the page's `PageProps<Path>` type
299
323
  * argument to the path it's mounted at.
300
324
  *
301
- * @param config - A {@link RouteConfig}, or a bare {@link Route} array as
302
- * shorthand when there are no `notFound` / `error` pages.
325
+ * A bare {@link Route} array is accepted as shorthand — see the second overload.
326
+ *
327
+ * @param config - A {@link RouteConfig}: the `routes` array plus the optional
328
+ * `notFound` and `error` pages.
303
329
  * @returns The config, unchanged and fully typed.
304
330
  *
305
331
  * @example
@@ -324,14 +350,25 @@ type ValidateRoutes<TRoutes extends readonly Route[]> = {
324
350
  * });
325
351
  * ```
326
352
  *
327
- * @example Array shorthand
328
- * ```ts
329
- * export const routes = defineRoutes([{ path: '/', component: () => import('./components/home') }]);
330
- * ```
353
+ * @see {@link https://www.rshono.com/docs/routing | Docs — routing}
331
354
  */
332
355
  export declare function defineRoutes<const TRoutes extends readonly Route[]>(config: RouteConfig<TRoutes> & {
333
356
  routes: ValidateRoutes<TRoutes>;
334
357
  }): RouteConfig<TRoutes>;
358
+ /**
359
+ * Array shorthand for {@link defineRoutes} — equivalent to `defineRoutes({ routes })`, for an app
360
+ * with no `notFound` or `error` page.
361
+ *
362
+ * @param routes - The {@link Route} array; each page is checked against its own `path`.
363
+ * @returns A {@link RouteConfig} wrapping them.
364
+ *
365
+ * @example
366
+ * ```ts
367
+ * export const routes = defineRoutes([{ path: '/', component: () => import('./components/home') }]);
368
+ * ```
369
+ *
370
+ * @see {@link https://www.rshono.com/docs/routing | Docs — routing}
371
+ */
335
372
  export declare function defineRoutes<const TRoutes extends readonly Route[]>(routes: TRoutes & ValidateRoutes<TRoutes>): RouteConfig<TRoutes>;
336
373
  export {};
337
374
  //# sourceMappingURL=router.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,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;IACtF,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,8FAA8F;IAC9F,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAMD,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS;IAChC,IAAI,EAAE,MAAM,CAAC,SAAS,MAAM,CAAC;IAC7B,SAAS,EAAE,MAAM,OAAO,CAAC;QAAE,OAAO,EAAE,aAAa,CAAC,MAAM,EAAE,CAAC,CAAA;KAAE,CAAC,CAAC;CAChE,GACG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,GAC9B,CAAC,GACD,CAAC,GAAG;IAAE,SAAS,EAAE,mDAAmD,CAAC,IAAI,CAAA;CAAE,GAC7E,CAAC,CAAC;AAEN,KAAK,cAAc,CAAC,OAAO,SAAS,SAAS,KAAK,EAAE,IAAI;KAAG,CAAC,IAAI,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AAE5G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,YAAY,CAAC,KAAK,CAAC,OAAO,SAAS,SAAS,KAAK,EAAE,EACjE,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG;IAAE,MAAM,EAAE,cAAc,CAAC,OAAO,CAAC,CAAA;CAAE,GACjE,WAAW,CAAC,OAAO,CAAC,CAAC;AACxB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,KAAK,CAAC,OAAO,SAAS,SAAS,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC"}
package/dist/router.js CHANGED
@@ -2,12 +2,10 @@
2
2
  * Type guard narrowing a {@link Route} to a {@link PageRoute}. Because `type` is
3
3
  * optional on page routes, anything not explicitly `'endpoint'` is a page.
4
4
  *
5
- * @example
6
- * ```ts
7
- * for (const route of routes) {
8
- * if (isPageRoute(route)) console.log(route.render ?? 'dynamic');
9
- * }
10
- * ```
5
+ * Framework internal — not re-exported from `index.ts`. The request renderer and
6
+ * the SSG pass use it to split the route table.
7
+ *
8
+ * @internal
11
9
  */
12
10
  export function isPageRoute(route) {
13
11
  return route.type !== 'endpoint';
@@ -1 +1 @@
1
- {"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AA0NA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CAAC,KAAY;IACtC,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC;AACnC,CAAC;AAwHD,MAAM,UAAU,YAAY,CAAC,KAAqC;IAChE,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,CAAE,KAAqB,CAAC;AAC3E,CAAC","sourcesContent":["import type { Env, Handler } from 'hono';\nimport type { ParamKeys, ParamKeyToRecord } from 'hono/types';\nimport type { ReactNode } from 'react';\n// Type-only, so this stays a build-time module: the import is erased and none of `context.ts`'s\n// runtime machinery (AsyncLocalStorage, hono/cookie) is pulled in by importing `@rshono/core`.\nimport type { Ctx } from './runtime/context.js';\n\ntype Simplify<T> = { [K in keyof T]: T[K] } & {};\ntype UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;\n\n/**\n * The `params` record implied by a route path pattern — one required `string` key\n * per `:param` segment, `Record<string, never>` for a path with no params.\n *\n * Paths use Hono's syntax, so `:id`, `:id{[0-9]+}` and `*` all work. You rarely\n * name this type directly; {@link PageProps} applies it for you.\n *\n * @typeParam P - The literal route path, e.g. `'/users/:id/posts/:postId'`.\n *\n * @example\n * ```ts\n * type P = PathParams<'/users/:id/posts/:postId'>; // { id: string; postId: string }\n * ```\n */\nexport type PathParams<P extends string> =\n ParamKeys<P> extends never ? Record<string, never> : Simplify<UnionToIntersection<ParamKeyToRecord<ParamKeys<P>>>>;\n\n/**\n * Props every page component receives. Pass the route's path as the type\n * argument to get `params` typed key-by-key; without it `params` falls back to\n * an open `Record<string, string>`.\n *\n * `defineRoutes` checks each page's props against `PageProps<path>` at compile\n * time, so a mismatched path literal is a type error at the route definition.\n *\n * The location props (`url` and `params`) mirror what a `'use client'` component\n * gets from `useNavigation()` — same names, same types — so moving a read across\n * the server/client line is a copy-paste.\n *\n * @typeParam Path - The literal path this page is mounted at, e.g. `'/profile/:id'`.\n * @typeParam E - The app's Hono {@link Env}, to type {@link Ctx.var} and\n * {@link Ctx.env} on {@link PageProps.ctx}.\n *\n * @example\n * ```tsx\n * import type { PageProps } from '@rshono/core';\n *\n * export default async function Profile({ params, url }: PageProps<'/profile/:id'>) {\n * const user = await db.getUser(params.id); // params.id is string\n * const tab = url.searchParams.get('tab') ?? 'overview';\n * return <Layout>{user.name} — {tab}</Layout>;\n * }\n * ```\n */\nexport interface PageProps<Path extends string = string, E extends Env = Env> {\n /**\n * The absolute browser-facing request {@link URL}, proxy-header aware\n * (`X-Forwarded-Host` / `-Proto`). Read `url.pathname`, `url.searchParams` and\n * the rest off it.\n *\n * A fresh instance per request that nothing else holds, so mutating it is local\n * to the page — but note it is *not* serializable, so a `'use client'` component\n * has to be handed `url.href` rather than `url`.\n *\n * On a prerendered page it is the build-time URL: a `render: 'static'` route is\n * rendered once, against `siteUrl` and with no query string, and that one file\n * then answers every request whatever its own query. So `url.searchParams` is\n * always empty there — read the query from `useNavigation().url` in a\n * `'use client'` component instead, or mark the route `render: 'dynamic'`.\n */\n url: URL;\n /** Matched route params for this request, e.g. `{ id: '42' }` for `/profile/:id`. */\n params: string extends Path ? Record<string, string> : PathParams<Path>;\n /**\n * The request context — the very object `getContext()` returns, handed to the\n * page so cookies, headers, env and middleware variables are reachable without\n * an import.\n *\n * Server-only, and never serialized: React renders a server component and puts\n * its *output* on the wire, not its props. It is also deliberately a\n * non-enumerable property, which has three consequences worth knowing:\n *\n * - It **cannot be handed to a `'use client'` component** — it wraps the live\n * request and response, which do not exist in the browser. Passing it\n * explicitly (`<Counter ctx={ctx} />`) fails the render with React's *\"Only\n * plain objects … can be passed to Client Components\"*. Read what you need on\n * the server and pass plain values down.\n * - Spreading the page's props instead (`<Counter {...props} />`) drops `ctx`\n * silently rather than failing, since the spread copies enumerables only.\n * (That spread still fails, mind — on `url`, which is enumerable and just as\n * unserializable. Pass the values you need.)\n * - `Object.keys(props)`, `JSON.stringify(props)` and friends don't see it.\n *\n * Reading it on a `render: 'static'` route throws: a prerendered page has no\n * per-request context at build time. Mark the route `render: 'dynamic'` (or use\n * the `url` / `params` props, which are available either way — with the\n * build-time caveats noted on `url`).\n *\n * @example\n * ```tsx\n * export default function Dashboard({ ctx }: PageProps) {\n * const session = ctx.cookies.get('session');\n * if (!session) redirect('/login');\n * return <Layout>Signed in as {session}</Layout>;\n * }\n * ```\n */\n ctx: Ctx<E>;\n}\n\n/**\n * A page: a React **server component** that renders the entire document\n * (`<html>…</html>`), usually via a shared layout. It may be `async` and await\n * data directly.\n *\n * Each page module must default-export exactly one of these. Interactive parts\n * belong in `'use client'` components the page imports — only those ship JS.\n *\n * @typeParam P - The component's props; for a page these are {@link PageProps}.\n */\nexport type PageComponent<P = any> = (props: P) => ReactNode | Promise<ReactNode>;\n\n/**\n * The shape an `{ type: 'endpoint' }` route's server module must have: a single\n * named `handler` export. The module only ever loads on the server, so it is\n * safe to import a database client or read secrets from it.\n *\n * @example\n * ```ts\n * // src/health.ts\n * import type { Handler } from '@rshono/core';\n *\n * export const handler: Handler = (c) => c.json({ ok: true });\n * ```\n */\nexport interface EndpointServerModule {\n /** A Hono {@link Handler} handling every request matched by the route. */\n handler: Handler;\n}\n\n/**\n * A page route — a path rendered by a server component. This is the default\n * route kind, so `type` can be omitted.\n *\n * @example\n * ```ts\n * { path: '/profile/:id', component: () => import('./components/profile') }\n * ```\n */\nexport interface PageRoute {\n /** Discriminates a page from an endpoint; optional because `'page'` is the default. */\n type?: 'page';\n /** Hono-style path pattern, e.g. `/`, `/profile/:id`, `/files/*`. */\n path: string;\n /**\n * Dynamic import of the page module, whose default export is the\n * {@link PageComponent}.\n *\n * Write it inline as shown — the framework detects that exact\n * `() => import('…')` form and injects Rspack's `'use server-entry'`\n * directive into the module for you (that directive is what attaches the\n * page's client JS/CSS, giving per-page code splitting). If you wire the\n * component up any other way — a variable, a barrel re-export, a computed\n * specifier — add `'use server-entry'` as the first line of the page module\n * yourself; the framework throws a descriptive error when neither happened.\n */\n component: () => Promise<{ default: PageComponent }>;\n /** `'static'` prerenders the route at build time; `'dynamic'` (the default) renders per request. */\n render?: 'static' | 'dynamic';\n /**\n * For a `render: 'static'` route with params: the param sets to prerender, one\n * HTML file each. Runs at build time only, on the server, so it may hit a\n * database or read the filesystem.\n *\n * A parameterised static route without `staticPaths` falls back to rendering\n * per request (with a build warning). Wildcard (`*`), optional and regex\n * params can't be prerendered.\n *\n * @example\n * ```ts\n * {\n * path: '/docs/:slug',\n * render: 'static',\n * component: () => import('./components/documentation'),\n * staticPaths: async () => (await db.docs.all()).map((d) => ({ slug: d.slug })),\n * }\n * ```\n */\n staticPaths?: () => Array<Record<string, string>> | Promise<Array<Record<string, string>>>;\n}\n\n/**\n * An endpoint route — a path served by a raw Hono handler instead of a React\n * component. Use it for JSON APIs, webhooks, redirects, feeds, or anything that\n * isn't an HTML page.\n *\n * @example\n * ```ts\n * { type: 'endpoint', path: '/api/health', server: () => import('./health') }\n * ```\n */\nexport interface EndpointRoute {\n /** Marks this route as an endpoint rather than a page. Required. */\n type: 'endpoint';\n /** Hono-style path pattern, e.g. `/api/health`, `/api/users/:id`. */\n path: string;\n /** HTTP method to match. Defaults to `'all'` — every method. */\n method?: HTTPMethod;\n /** Dynamic import of the {@link EndpointServerModule} exporting `handler`. */\n server: () => Promise<EndpointServerModule>;\n}\n\n/** HTTP methods an {@link EndpointRoute} can match. `'all'` matches every method. */\nexport type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'head' | 'options' | 'all';\n\n/** Any entry in the `routes` array: a {@link PageRoute} or an {@link EndpointRoute}. */\nexport type Route = PageRoute | EndpointRoute;\n\n/**\n * Type guard narrowing a {@link Route} to a {@link PageRoute}. Because `type` is\n * optional on page routes, anything not explicitly `'endpoint'` is a page.\n *\n * @example\n * ```ts\n * for (const route of routes) {\n * if (isPageRoute(route)) console.log(route.render ?? 'dynamic');\n * }\n * ```\n */\nexport function isPageRoute(route: Route): route is PageRoute {\n return route.type !== 'endpoint';\n}\n\n/**\n * A page the framework falls back to rather than routes to — `notFound` and\n * `error` in {@link RouteConfig}. Same contract as a {@link PageRoute}\n * `component`, without a path of its own.\n */\nexport interface FallbackPage {\n /** Dynamic import of the page module; its default export is the {@link PageComponent}. */\n component: () => Promise<{ default: PageComponent }>;\n}\n\n/**\n * The error detail handed to the `error` page. Redacted in production: the\n * message is a generic `'Internal Server Error'` and there is no `stack`. In dev\n * you get the real message plus the stack.\n */\nexport interface ErrorInfo {\n /** The thrown error's message in dev; `'Internal Server Error'` in production. */\n message: string;\n /** The stack trace. Present in dev only. */\n stack?: string;\n}\n\n/**\n * Props for the `error` page declared in {@link RouteConfig.error} — the usual\n * {@link PageProps} plus the redaction-aware {@link ErrorInfo}.\n *\n * @typeParam E - The app's Hono {@link Env}, forwarded to {@link PageProps.ctx}.\n *\n * @example\n * ```tsx\n * import type { ErrorPageProps } from '@rshono/core';\n *\n * export default function ServerError({ error }: ErrorPageProps) {\n * return <html><body><h1>Something went wrong</h1><p>{error.message}</p></body></html>;\n * }\n * ```\n */\nexport type ErrorPageProps<E extends Env = Env> = PageProps<string, E> & { error: ErrorInfo };\n\n/**\n * The object form accepted by {@link defineRoutes}: the route table plus the two\n * optional framework-owned pages.\n *\n * @typeParam TRoutes - Inferred tuple of route literals, which is what makes the\n * per-route `path` → props check possible.\n */\nexport interface RouteConfig<TRoutes extends readonly Route[] = readonly Route[]> {\n /** Every page and endpoint in the app, matched in order. */\n routes: TRoutes;\n /** Page rendered with a 404 status for unmatched paths and for `notFound()` calls. */\n notFound?: FallbackPage;\n /** Page rendered with a 500 status when a request throws. Receives {@link ErrorPageProps}. */\n error?: FallbackPage;\n}\n\n// `PageProps<P, any>`, not `PageProps<P>`: this check is about the *path* matching the page's\n// `params`, and pinning the Env to the default would additionally demand that a page declaring its\n// own (`PageProps<'/x', MyEnv>`, to type `ctx.var`) accept a `Ctx<Env>` — which it doesn't, so every\n// such page would fail its own route check. `any` makes `ctx` compatible either way.\ntype ValidateRoute<R> = R extends {\n path: infer P extends string;\n component: () => Promise<{ default: PageComponent<infer CP> }>;\n}\n ? [PageProps<P, any>] extends [CP]\n ? R\n : R & { component: `component props are not satisfied by PageProps<'${P}'>` }\n : R;\n\ntype ValidateRoutes<TRoutes extends readonly Route[]> = { [K in keyof TRoutes]: ValidateRoute<TRoutes[K]> };\n\n/**\n * Declares the app's route table. Default-export the result as `routes` from\n * `src/routes.ts` — the one file rshono requires.\n *\n * `routes.ts` only ever runs on the server, so importing server-only modules\n * from it (e.g. inside `staticPaths`) is safe.\n *\n * Beyond typing the config, this cross-checks every page against its own path:\n * if a component's props aren't satisfied by `PageProps<'<its path>'>`, the\n * `component` field errors with `component props are not satisfied by\n * PageProps<'/…'>`. Fix it by matching the page's `PageProps<Path>` type\n * argument to the path it's mounted at.\n *\n * @param config - A {@link RouteConfig}, or a bare {@link Route} array as\n * shorthand when there are no `notFound` / `error` pages.\n * @returns The config, unchanged and fully typed.\n *\n * @example\n * ```ts\n * // src/routes.ts\n * import { defineRoutes } from '@rshono/core';\n *\n * export const routes = defineRoutes({\n * routes: [\n * { path: '/', component: () => import('./components/home') },\n * { path: '/profile/:id', component: () => import('./components/profile') },\n * {\n * path: '/docs/:slug',\n * render: 'static',\n * component: () => import('./components/documentation'),\n * staticPaths: async () => [{ slug: 'getting-started' }, { slug: 'deployment' }],\n * },\n * { type: 'endpoint', path: '/api/health', server: () => import('./health') },\n * ],\n * notFound: { component: () => import('./components/404') },\n * error: { component: () => import('./components/500') },\n * });\n * ```\n *\n * @example Array shorthand\n * ```ts\n * export const routes = defineRoutes([{ path: '/', component: () => import('./components/home') }]);\n * ```\n */\nexport function defineRoutes<const TRoutes extends readonly Route[]>(\n config: RouteConfig<TRoutes> & { routes: ValidateRoutes<TRoutes> },\n): RouteConfig<TRoutes>;\nexport function defineRoutes<const TRoutes extends readonly Route[]>(routes: TRoutes & ValidateRoutes<TRoutes>): RouteConfig<TRoutes>;\nexport function defineRoutes(input: readonly Route[] | RouteConfig): RouteConfig {\n return Array.isArray(input) ? { routes: input } : (input as RouteConfig);\n}\n"]}
1
+ {"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAiPA;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,KAAY;IACtC,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC;AACnC,CAAC;AA0ID,MAAM,UAAU,YAAY,CAAC,KAAqC;IAChE,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,CAAE,KAAqB,CAAC;AAC3E,CAAC","sourcesContent":["import type { Env, Handler } from 'hono';\nimport type { ParamKeys, ParamKeyToRecord } from 'hono/types';\nimport type { ReactNode } from 'react';\n// Type-only, so this stays a build-time module: the import is erased and none of `context.ts`'s\n// runtime machinery (AsyncLocalStorage, hono/cookie) is pulled in by importing `@rshono/core`.\nimport type { RequestContext } from './runtime/context.js';\n\ntype Simplify<T> = { [K in keyof T]: T[K] } & {};\ntype UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;\n\n/**\n * The `params` record implied by a route path pattern — one required `string` key\n * per `:param` segment, `Record<string, never>` for a path with no params.\n *\n * Paths use Hono's syntax, so `:id`, `:id{[0-9]+}` and `*` all work. You rarely\n * name this type directly; {@link PageProps} applies it for you.\n *\n * @typeParam P - The literal route path, e.g. `'/users/:id/posts/:postId'`.\n *\n * @example\n * ```ts\n * type P = PathParams<'/users/:id/posts/:postId'>; // { id: string; postId: string }\n * ```\n *\n * @see {@link https://hono.dev/docs/api/routing#path-parameter | Hono — path parameters}\n */\nexport type PathParams<P extends string> =\n ParamKeys<P> extends never ? Record<string, never> : Simplify<UnionToIntersection<ParamKeyToRecord<ParamKeys<P>>>>;\n\n/**\n * Props every page component receives. Pass the route's path as the type\n * argument to get `params` typed key-by-key; without it `params` falls back to\n * an open `Record<string, string>`.\n *\n * `defineRoutes` checks each page's props against `PageProps<path>` at compile\n * time, so a mismatched path literal is a type error at the route definition.\n *\n * The location props (`url` and `params`) mirror what a `'use client'` component\n * gets from `useNavigation()` — same names, same types — so moving a read across\n * the server/client line is a copy-paste.\n *\n * @typeParam Path - The literal path this page is mounted at, e.g. `'/profile/:id'`.\n * @typeParam E - The app's Hono {@link Env}, to type {@link RequestContext.var} and\n * {@link RequestContext.env} on {@link PageProps.ctx}.\n *\n * @example\n * ```tsx\n * import type { PageProps } from '@rshono/core';\n *\n * export default async function Profile({ params, url }: PageProps<'/profile/:id'>) {\n * const user = await db.getUser(params.id); // params.id is string\n * const tab = url.searchParams.get('tab') ?? 'overview';\n * return <Layout>{user.name} — {tab}</Layout>;\n * }\n * ```\n *\n * @see {@link https://www.rshono.com/docs/pages#page-props | Docs — page props}\n */\nexport interface PageProps<Path extends string = string, E extends Env = Env> {\n /**\n * The absolute browser-facing request {@link URL}, proxy-header aware\n * (`X-Forwarded-Host` / `-Proto`). Read `url.pathname`, `url.searchParams` and\n * the rest off it.\n *\n * A fresh instance per request that nothing else holds, so mutating it is local\n * to the page. It is not serializable, so a `'use client'` component has to be\n * handed `url.href` rather than `url`.\n *\n * On a `render: 'static'` route this is the build-time URL — rendered once\n * against `siteUrl` with no query string, and that one file answers every\n * request whatever its own query. So `url.searchParams` is always empty there:\n * read the query from `useNavigation().url` in a `'use client'` component\n * instead, or mark the route `render: 'dynamic'`.\n */\n url: URL;\n /** Matched route params for this request, e.g. `{ id: '42' }` for `/profile/:id`. */\n params: string extends Path ? Record<string, string> : PathParams<Path>;\n /**\n * The request context — the very object `getRequestContext()` returns, handed to the\n * page so cookies, headers, env and middleware variables are reachable without\n * an import.\n *\n * Server-only and never serialized: React puts a server component's *output* on\n * the wire, not its props. It is also deliberately **non-enumerable**, so\n * `Object.keys(props)`, `JSON.stringify(props)` and a `{...props}` spread all\n * skip it. Handing it to a `'use client'` component directly\n * (`<Counter ctx={ctx} />`) fails the render — it wraps the live request and\n * response, which do not exist in the browser. Read what you need here and pass\n * plain values down.\n *\n * Reading it on a `render: 'static'` route throws: a prerendered page has no\n * per-request context at build time. Mark the route `render: 'dynamic'`, or use\n * the `url` / `params` props — available either way, with the build-time caveat\n * noted on `url`.\n *\n * @example\n * ```tsx\n * export default function Dashboard({ ctx }: PageProps) {\n * const session = ctx.cookies.get('session');\n * if (!session) redirect('/login');\n * return <Layout>Signed in as {session}</Layout>;\n * }\n * ```\n */\n ctx: RequestContext<E>;\n}\n\n/**\n * A page: a React **server component** that renders the entire document\n * (`<html>…</html>`), usually via a shared layout. It may be `async` and await\n * data directly.\n *\n * Each page module must default-export exactly one of these. Interactive parts\n * belong in `'use client'` components the page imports — only those ship JS.\n *\n * @typeParam P - The component's props; for a page these are {@link PageProps}.\n *\n * @see {@link https://react.dev/reference/rsc/server-components | React — Server Components}\n * @see {@link https://www.rshono.com/docs/pages | Docs — pages}\n */\nexport type PageComponent<P = any> = (props: P) => ReactNode | Promise<ReactNode>;\n\n/**\n * The shape an `{ type: 'endpoint' }` route's server module must have: a single\n * named `handler` export. The module only ever loads on the server, so it is\n * safe to import a database client or read secrets from it.\n *\n * @example\n * ```ts\n * // src/health.ts\n * import type { Handler } from 'hono';\n *\n * export const handler: Handler = (c) => c.json({ ok: true });\n * ```\n *\n * @see {@link https://www.rshono.com/docs/routing#endpoint-routes | Docs — endpoint routes}\n */\nexport interface EndpointServerModule {\n /**\n * A Hono {@link Handler} handling every request matched by the route. It is passed Hono's\n * `Context`, so the request, response builders (`c.json`, `c.text`, `c.body`) and middleware\n * variables are all reached through it.\n *\n * @see {@link https://hono.dev/docs/api/context | Hono — Context}\n */\n handler: Handler;\n}\n\n/**\n * A page route — a path rendered by a server component. This is the default\n * route kind, so `type` can be omitted.\n *\n * @example\n * ```ts\n * { path: '/profile/:id', component: () => import('./components/profile') }\n * ```\n */\nexport interface PageRoute {\n /** Discriminates a page from an endpoint; optional because `'page'` is the default. */\n type?: 'page';\n /**\n * Hono-style path pattern, e.g. `/`, `/profile/:id`, `/files/*`. Routes are matched in\n * declaration order.\n *\n * @see {@link https://hono.dev/docs/api/routing | Hono — routing}\n */\n path: string;\n /**\n * Dynamic import of the page module, whose default export is the\n * {@link PageComponent}.\n *\n * Write it inline as shown — the framework detects that exact\n * `() => import('…')` form and injects Rspack's `'use server-entry'`\n * directive into the module for you (that directive is what attaches the\n * page's client JS/CSS, giving per-page code splitting). If you wire the\n * component up any other way — a variable, a barrel re-export, a computed\n * specifier — add `'use server-entry'` as the first line of the page module\n * yourself; the framework throws a descriptive error when neither happened.\n *\n * @see {@link https://www.rshono.com/docs/pages#the-use-server-entry-directive | Docs — the `'use server-entry'` directive}\n */\n component: () => Promise<{ default: PageComponent }>;\n /** `'static'` prerenders the route at build time; `'dynamic'` (the default) renders per request. */\n render?: 'static' | 'dynamic';\n /**\n * For a `render: 'static'` route with params: the param sets to prerender, one\n * HTML file each. Runs at build time only, on the server, so it may hit a\n * database or read the filesystem.\n *\n * A parameterised static route without `staticPaths` falls back to rendering\n * per request (with a build warning). Wildcard (`*`), optional and regex\n * params can't be prerendered.\n *\n * @example\n * ```ts\n * {\n * path: '/docs/:slug',\n * render: 'static',\n * component: () => import('./components/documentation'),\n * staticPaths: async () => (await db.docs.all()).map((d) => ({ slug: d.slug })),\n * }\n * ```\n *\n * @see {@link https://www.rshono.com/docs/routing#static-rendering | Docs — static rendering}\n */\n staticPaths?: () => Array<Record<string, string>> | Promise<Array<Record<string, string>>>;\n}\n\n/**\n * An endpoint route — a path served by a raw Hono handler instead of a React\n * component. Use it for JSON APIs, webhooks, redirects, feeds, or anything that\n * isn't an HTML page.\n *\n * @example\n * ```ts\n * { type: 'endpoint', path: '/api/health', server: () => import('./health') }\n * ```\n *\n * @see {@link https://www.rshono.com/docs/routing#endpoint-routes | Docs — endpoint routes}\n */\nexport interface EndpointRoute {\n /** Marks this route as an endpoint rather than a page. Required. */\n type: 'endpoint';\n /**\n * Hono-style path pattern, e.g. `/api/health`, `/api/users/:id`.\n *\n * @see {@link https://hono.dev/docs/api/routing | Hono — routing}\n */\n path: string;\n /** HTTP method to match. Defaults to `'all'` — every method. */\n method?: HTTPMethod;\n /** Dynamic import of the {@link EndpointServerModule} exporting `handler`. */\n server: () => Promise<EndpointServerModule>;\n}\n\n/** HTTP methods an {@link EndpointRoute} can match. `'all'` matches every method. */\nexport type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'head' | 'options' | 'all';\n\n/** Any entry in the `routes` array: a {@link PageRoute} or an {@link EndpointRoute}. */\nexport type Route = PageRoute | EndpointRoute;\n\n/**\n * Type guard narrowing a {@link Route} to a {@link PageRoute}. Because `type` is\n * optional on page routes, anything not explicitly `'endpoint'` is a page.\n *\n * Framework internal — not re-exported from `index.ts`. The request renderer and\n * the SSG pass use it to split the route table.\n *\n * @internal\n */\nexport function isPageRoute(route: Route): route is PageRoute {\n return route.type !== 'endpoint';\n}\n\n/**\n * A page the framework falls back to rather than routes to — `notFound` and\n * `error` in {@link RouteConfig}. Same contract as a {@link PageRoute}\n * `component`, without a path of its own.\n */\nexport interface FallbackPage {\n /** Dynamic import of the page module; its default export is the {@link PageComponent}. */\n component: () => Promise<{ default: PageComponent }>;\n}\n\n/**\n * The error detail handed to the `error` page. Redacted in production: the\n * message is a generic `'Internal Server Error'` and there is no `stack`. In dev\n * you get the real message plus the stack.\n */\nexport interface ErrorPageInfo {\n /** The thrown error's message in dev; `'Internal Server Error'` in production. */\n message: string;\n /** The stack trace. Present in dev only. */\n stack?: string;\n}\n\n/**\n * Props for the `error` page declared in {@link RouteConfig.error} — the usual\n * {@link PageProps} plus the redaction-aware {@link ErrorPageInfo}.\n *\n * @typeParam E - The app's Hono {@link Env}, forwarded to {@link PageProps.ctx}.\n *\n * @example\n * ```tsx\n * import type { ErrorPageProps } from '@rshono/core';\n *\n * export default function ServerError({ error }: ErrorPageProps) {\n * return <html><body><h1>Something went wrong</h1><p>{error.message}</p></body></html>;\n * }\n * ```\n */\nexport type ErrorPageProps<E extends Env = Env> = PageProps<string, E> & {\n /** The error that failed the request, redacted in production — see {@link ErrorPageInfo}. */\n error: ErrorPageInfo;\n};\n\n/**\n * The object form accepted by {@link defineRoutes}: the route table plus the two\n * optional framework-owned pages.\n *\n * @typeParam TRoutes - Inferred tuple of route literals, which is what makes the\n * per-route `path` → props check possible.\n *\n * @see {@link https://www.rshono.com/docs/routing#notfound-and-error | Docs — notFound and error pages}\n */\nexport interface RouteConfig<TRoutes extends readonly Route[] = readonly Route[]> {\n /** Every page and endpoint in the app, matched in order. */\n routes: TRoutes;\n /** Page rendered with a 404 status for unmatched paths and for `notFound()` calls. */\n notFound?: FallbackPage;\n /** Page rendered with a 500 status when a request throws. Receives {@link ErrorPageProps}. */\n error?: FallbackPage;\n}\n\n// `PageProps<P, any>`, not `PageProps<P>`: this checks the *path* against the page's `params`, and\n// pinning the Env to the default would additionally demand that a page declaring its own\n// (`PageProps<'/x', MyEnv>`, to type `ctx.var`) accept a `RequestContext<Env>` — which it doesn't, so\n// every such page would fail its own route check. `any` makes `ctx` compatible either way.\ntype ValidateRoute<R> = R extends {\n path: infer P extends string;\n component: () => Promise<{ default: PageComponent<infer CP> }>;\n}\n ? [PageProps<P, any>] extends [CP]\n ? R\n : R & { component: `component props are not satisfied by PageProps<'${P}'>` }\n : R;\n\ntype ValidateRoutes<TRoutes extends readonly Route[]> = { [K in keyof TRoutes]: ValidateRoute<TRoutes[K]> };\n\n/**\n * Declares the app's route table. Default-export the result as `routes` from\n * `src/routes.ts` — the one file rshono requires.\n *\n * `routes.ts` only ever runs on the server, so importing server-only modules\n * from it (e.g. inside `staticPaths`) is safe.\n *\n * Beyond typing the config, this cross-checks every page against its own path:\n * if a component's props aren't satisfied by `PageProps<'<its path>'>`, the\n * `component` field errors with `component props are not satisfied by\n * PageProps<'/…'>`. Fix it by matching the page's `PageProps<Path>` type\n * argument to the path it's mounted at.\n *\n * A bare {@link Route} array is accepted as shorthand — see the second overload.\n *\n * @param config - A {@link RouteConfig}: the `routes` array plus the optional\n * `notFound` and `error` pages.\n * @returns The config, unchanged and fully typed.\n *\n * @example\n * ```ts\n * // src/routes.ts\n * import { defineRoutes } from '@rshono/core';\n *\n * export const routes = defineRoutes({\n * routes: [\n * { path: '/', component: () => import('./components/home') },\n * { path: '/profile/:id', component: () => import('./components/profile') },\n * {\n * path: '/docs/:slug',\n * render: 'static',\n * component: () => import('./components/documentation'),\n * staticPaths: async () => [{ slug: 'getting-started' }, { slug: 'deployment' }],\n * },\n * { type: 'endpoint', path: '/api/health', server: () => import('./health') },\n * ],\n * notFound: { component: () => import('./components/404') },\n * error: { component: () => import('./components/500') },\n * });\n * ```\n *\n * @see {@link https://www.rshono.com/docs/routing | Docs — routing}\n */\nexport function defineRoutes<const TRoutes extends readonly Route[]>(\n config: RouteConfig<TRoutes> & { routes: ValidateRoutes<TRoutes> },\n): RouteConfig<TRoutes>;\n/**\n * Array shorthand for {@link defineRoutes} — equivalent to `defineRoutes({ routes })`, for an app\n * with no `notFound` or `error` page.\n *\n * @param routes - The {@link Route} array; each page is checked against its own `path`.\n * @returns A {@link RouteConfig} wrapping them.\n *\n * @example\n * ```ts\n * export const routes = defineRoutes([{ path: '/', component: () => import('./components/home') }]);\n * ```\n *\n * @see {@link https://www.rshono.com/docs/routing | Docs — routing}\n */\nexport function defineRoutes<const TRoutes extends readonly Route[]>(routes: TRoutes & ValidateRoutes<TRoutes>): RouteConfig<TRoutes>;\nexport function defineRoutes(input: readonly Route[] | RouteConfig): RouteConfig {\n return Array.isArray(input) ? { routes: input } : (input as RouteConfig);\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { Component, type ReactNode } from 'react';
2
2
  /**
3
- * What an {@link ErrorBoundary} / {@link Boundary} renders once a child throws.
3
+ * What a {@link CatchBoundary} / {@link AsyncBoundary} renders once a child throws.
4
4
  * Either a static node, or a render function that also gets a `reset` callback
5
5
  * to clear the error and re-render the children (e.g. a "Try again" button).
6
6
  *
@@ -9,7 +9,8 @@ import { Component, type ReactNode } from 'react';
9
9
  * server component, pass a `ReactNode`.
10
10
  */
11
11
  export type ErrorFallback = ReactNode | ((error: Error, reset: () => void) => ReactNode);
12
- export interface ErrorBoundaryProps {
12
+ /** Props for {@link CatchBoundary}. */
13
+ export interface CatchBoundaryProps {
13
14
  /**
14
15
  * Rendered in place of the children after one of them throws. Omit it to
15
16
  * report the error via `onError` and re-throw to the next boundary out (or
@@ -24,9 +25,10 @@ export interface ErrorBoundaryProps {
24
25
  * recover when the user navigates away: `resetKeys={[useNavigation().url.pathname]}`.
25
26
  */
26
27
  resetKeys?: readonly unknown[];
28
+ /** The subtree this boundary protects. */
27
29
  children: ReactNode;
28
30
  }
29
- interface ErrorBoundaryState {
31
+ interface CatchBoundaryState {
30
32
  error: Error | null;
31
33
  }
32
34
  /**
@@ -36,40 +38,50 @@ interface ErrorBoundaryState {
36
38
  * tearing down the whole page.
37
39
  *
38
40
  * It's a `'use client'` component (React error boundaries must be), so drop it
39
- * anywhere in the tree from a server or client component. Use {@link Boundary}
41
+ * anywhere in the tree from a server or client component. Use {@link AsyncBoundary}
40
42
  * when you also want a Suspense loading fallback in the same wrapper.
41
43
  *
42
44
  * @example
43
45
  * ```tsx
44
- * import { ErrorBoundary } from '@rshono/core/client';
46
+ * import { CatchBoundary } from '@rshono/core/client';
45
47
  *
46
- * <ErrorBoundary fallback={(error, reset) => (
48
+ * <CatchBoundary fallback={(error, reset) => (
47
49
  * <div role="alert">
48
50
  * <p>{error.message}</p>
49
51
  * <button onClick={reset}>Try again</button>
50
52
  * </div>
51
53
  * )}>
52
54
  * <RiskyWidget />
53
- * </ErrorBoundary>
55
+ * </CatchBoundary>
54
56
  * ```
57
+ *
58
+ * @see {@link https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary | React — error boundaries}
59
+ * @see {@link https://www.rshono.com/docs/api#rshonocoreclient | Docs — `@rshono/core/client`}
55
60
  */
56
- export declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
57
- state: ErrorBoundaryState;
58
- static getDerivedStateFromError(error: Error): ErrorBoundaryState;
61
+ export declare class CatchBoundary extends Component<CatchBoundaryProps, CatchBoundaryState> {
62
+ state: CatchBoundaryState;
63
+ static getDerivedStateFromError(error: Error): CatchBoundaryState;
59
64
  componentDidCatch(error: Error): void;
60
- componentDidUpdate(prev: ErrorBoundaryProps): void;
65
+ componentDidUpdate(prev: CatchBoundaryProps): void;
61
66
  reset: () => void;
62
67
  render(): ReactNode;
63
68
  }
64
- export interface BoundaryProps {
65
- /** Suspense fallback, shown while the children (or their data) are still loading. */
66
- loading?: ReactNode;
69
+ /** Props for {@link AsyncBoundary}. */
70
+ export interface AsyncBoundaryProps {
71
+ /**
72
+ * Suspense fallback, shown while the children (or their data) are still
73
+ * loading. Required — a loading state is the reason to reach for this over
74
+ * {@link CatchBoundary}, so showing nothing is an explicit `loading={null}`
75
+ * rather than something you get by leaving the prop off.
76
+ */
77
+ loading: ReactNode;
67
78
  /** Error fallback, shown if a child throws. See {@link ErrorFallback}. */
68
79
  error?: ErrorFallback;
69
80
  /** Called with the caught error. */
70
81
  onError?: (error: Error) => void;
71
- /** Clears the error fallback when any value changes — see {@link ErrorBoundaryProps.resetKeys}. */
82
+ /** Clears the error fallback when any value changes — see {@link CatchBoundaryProps.resetKeys}. */
72
83
  resetKeys?: readonly unknown[];
84
+ /** The subtree this boundary suspends on and protects. */
73
85
  children: ReactNode;
74
86
  }
75
87
  /**
@@ -77,26 +89,28 @@ export interface BoundaryProps {
77
89
  * section of a page. It always renders the same shape:
78
90
  *
79
91
  * ```tsx
80
- * <ErrorBoundary fallback={error}>
92
+ * <CatchBoundary fallback={error}>
81
93
  * <Suspense fallback={loading}>{children}</Suspense>
82
- * </ErrorBoundary>
94
+ * </CatchBoundary>
83
95
  * ```
84
96
  *
85
97
  * so `error` catches anything the children throw (including while suspended) and
86
- * `loading` shows until they resolve. Both fallbacks are optional: omit
87
- * `loading` and nothing shows while loading; omit `error` and thrown errors
88
- * propagate to the next boundary out (or the global error page) rather than
89
- * being caught here.
98
+ * `loading` shows until they resolve. `error` is optional: omit it and thrown
99
+ * errors propagate to the next boundary out (or the global error page) rather
100
+ * than being caught here.
90
101
  *
91
102
  * @example
92
103
  * ```tsx
93
- * import { Boundary } from '@rshono/core/client';
104
+ * import { AsyncBoundary } from '@rshono/core/client';
94
105
  *
95
- * <Boundary loading={<Spinner />} error={(e, reset) => <Retry onClick={reset} />}>
106
+ * <AsyncBoundary loading={<Spinner />} error={(e, reset) => <Retry onClick={reset} />}>
96
107
  * <SlowServerComponent />
97
- * </Boundary>
108
+ * </AsyncBoundary>
98
109
  * ```
110
+ *
111
+ * @see {@link https://react.dev/reference/react/Suspense | React — `<Suspense>`}
112
+ * @see {@link https://www.rshono.com/docs/api#rshonocoreclient | Docs — `@rshono/core/client`}
99
113
  */
100
- export declare function Boundary({ loading, error, onError, resetKeys, children }: BoundaryProps): ReactNode;
114
+ export declare function AsyncBoundary({ loading, error, onError, resetKeys, children }: AsyncBoundaryProps): ReactNode;
101
115
  export {};
102
116
  //# sourceMappingURL=boundaries.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"boundaries.d.ts","sourceRoot":"","sources":["../../src/runtime/boundaries.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAY,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAa5D;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,CAAC,CAAC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oCAAoC;IACpC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,mGAAmG;IACnG,SAAS,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;IAC/B,0DAA0D;IAC1D,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,aAAa,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,kBAAkB,GAAG,SAAS,CAM7G"}
@@ -5,7 +5,7 @@ import { isControlDigest } from './control.js';
5
5
  /**
6
6
  * `redirect()` and `notFound()` reach the browser as a thrown error carrying a control digest.
7
7
  * They are navigation, not failure, so no boundary may absorb one — otherwise a `redirect()` from
8
- * a component inside a `<Boundary>` would render "something went wrong" instead of navigating.
8
+ * a component inside a `<CatchBoundary>` would render "something went wrong" instead of navigating.
9
9
  * They're re-thrown to the root, where the runtime turns the digest into a real navigation.
10
10
  */
11
11
  function isControlError(error) {
@@ -21,24 +21,27 @@ function keysChanged(a, b) {
21
21
  * tearing down the whole page.
22
22
  *
23
23
  * It's a `'use client'` component (React error boundaries must be), so drop it
24
- * anywhere in the tree from a server or client component. Use {@link Boundary}
24
+ * anywhere in the tree from a server or client component. Use {@link AsyncBoundary}
25
25
  * when you also want a Suspense loading fallback in the same wrapper.
26
26
  *
27
27
  * @example
28
28
  * ```tsx
29
- * import { ErrorBoundary } from '@rshono/core/client';
29
+ * import { CatchBoundary } from '@rshono/core/client';
30
30
  *
31
- * <ErrorBoundary fallback={(error, reset) => (
31
+ * <CatchBoundary fallback={(error, reset) => (
32
32
  * <div role="alert">
33
33
  * <p>{error.message}</p>
34
34
  * <button onClick={reset}>Try again</button>
35
35
  * </div>
36
36
  * )}>
37
37
  * <RiskyWidget />
38
- * </ErrorBoundary>
38
+ * </CatchBoundary>
39
39
  * ```
40
+ *
41
+ * @see {@link https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary | React — error boundaries}
42
+ * @see {@link https://www.rshono.com/docs/api#rshonocoreclient | Docs — `@rshono/core/client`}
40
43
  */
41
- export class ErrorBoundary extends Component {
44
+ export class CatchBoundary extends Component {
42
45
  state = { error: null };
43
46
  static getDerivedStateFromError(error) {
44
47
  return { error };
@@ -75,27 +78,29 @@ export class ErrorBoundary extends Component {
75
78
  * section of a page. It always renders the same shape:
76
79
  *
77
80
  * ```tsx
78
- * <ErrorBoundary fallback={error}>
81
+ * <CatchBoundary fallback={error}>
79
82
  * <Suspense fallback={loading}>{children}</Suspense>
80
- * </ErrorBoundary>
83
+ * </CatchBoundary>
81
84
  * ```
82
85
  *
83
86
  * so `error` catches anything the children throw (including while suspended) and
84
- * `loading` shows until they resolve. Both fallbacks are optional: omit
85
- * `loading` and nothing shows while loading; omit `error` and thrown errors
86
- * propagate to the next boundary out (or the global error page) rather than
87
- * being caught here.
87
+ * `loading` shows until they resolve. `error` is optional: omit it and thrown
88
+ * errors propagate to the next boundary out (or the global error page) rather
89
+ * than being caught here.
88
90
  *
89
91
  * @example
90
92
  * ```tsx
91
- * import { Boundary } from '@rshono/core/client';
93
+ * import { AsyncBoundary } from '@rshono/core/client';
92
94
  *
93
- * <Boundary loading={<Spinner />} error={(e, reset) => <Retry onClick={reset} />}>
95
+ * <AsyncBoundary loading={<Spinner />} error={(e, reset) => <Retry onClick={reset} />}>
94
96
  * <SlowServerComponent />
95
- * </Boundary>
97
+ * </AsyncBoundary>
96
98
  * ```
99
+ *
100
+ * @see {@link https://react.dev/reference/react/Suspense | React — `<Suspense>`}
101
+ * @see {@link https://www.rshono.com/docs/api#rshonocoreclient | Docs — `@rshono/core/client`}
97
102
  */
98
- export function Boundary({ loading = null, error, onError, resetKeys, children }) {
99
- return (_jsx(ErrorBoundary, { fallback: error, onError: onError, resetKeys: resetKeys, children: _jsx(Suspense, { fallback: loading, children: children }) }));
103
+ export function AsyncBoundary({ loading, error, onError, resetKeys, children }) {
104
+ return (_jsx(CatchBoundary, { fallback: error, onError: onError, resetKeys: resetKeys, children: _jsx(Suspense, { fallback: loading, children: children }) }));
100
105
  }
101
106
  //# sourceMappingURL=boundaries.js.map