@rshono/core 1.0.0-rc.11 → 1.0.0-rc.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/bin/rshono.mjs +3 -4
- package/dist/builder/env-shadow-loader.cjs +5 -5
- package/dist/builder/page-files.js +5 -5
- package/dist/builder/page-files.js.map +1 -1
- package/dist/builder/public-env.d.ts +5 -4
- package/dist/builder/public-env.d.ts.map +1 -1
- package/dist/builder/public-env.js +5 -4
- package/dist/builder/public-env.js.map +1 -1
- package/dist/builder/rspack-config.d.ts +10 -0
- package/dist/builder/rspack-config.d.ts.map +1 -1
- package/dist/builder/rspack-config.js +38 -40
- package/dist/builder/rspack-config.js.map +1 -1
- package/dist/cli/build.js +4 -4
- package/dist/cli/build.js.map +1 -1
- package/dist/cli/dev.d.ts.map +1 -1
- package/dist/cli/dev.js +50 -37
- package/dist/cli/dev.js.map +1 -1
- package/dist/cli/index.js +4 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/start.d.ts.map +1 -1
- package/dist/cli/start.js +2 -3
- package/dist/cli/start.js.map +1 -1
- package/dist/config.d.ts +28 -31
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -2
- package/dist/config.js.map +1 -1
- package/dist/deploy/aws-lambda/runtime.d.ts +4 -6
- package/dist/deploy/aws-lambda/runtime.d.ts.map +1 -1
- package/dist/deploy/aws-lambda/runtime.js +5 -8
- package/dist/deploy/aws-lambda/runtime.js.map +1 -1
- package/dist/deploy/build-marker.d.ts +3 -5
- package/dist/deploy/build-marker.d.ts.map +1 -1
- package/dist/deploy/build-marker.js +3 -5
- package/dist/deploy/build-marker.js.map +1 -1
- package/dist/deploy/cloudflare/build.d.ts.map +1 -1
- package/dist/deploy/cloudflare/build.js +6 -10
- package/dist/deploy/cloudflare/build.js.map +1 -1
- package/dist/deploy/cloudflare/runtime.d.ts +2 -5
- package/dist/deploy/cloudflare/runtime.d.ts.map +1 -1
- package/dist/deploy/cloudflare/runtime.js +19 -32
- package/dist/deploy/cloudflare/runtime.js.map +1 -1
- package/dist/deploy/contract.d.ts +25 -42
- package/dist/deploy/contract.d.ts.map +1 -1
- package/dist/deploy/contract.js.map +1 -1
- package/dist/deploy/filesystem.d.ts +3 -5
- package/dist/deploy/filesystem.d.ts.map +1 -1
- package/dist/deploy/filesystem.js +12 -15
- package/dist/deploy/filesystem.js.map +1 -1
- package/dist/deploy/node/runtime.d.ts +4 -5
- package/dist/deploy/node/runtime.d.ts.map +1 -1
- package/dist/deploy/node/runtime.js +9 -15
- package/dist/deploy/node/runtime.js.map +1 -1
- package/dist/deploy/presets.d.ts +19 -29
- package/dist/deploy/presets.d.ts.map +1 -1
- package/dist/deploy/presets.js +18 -25
- package/dist/deploy/presets.js.map +1 -1
- package/dist/deploy/vercel/build.d.ts.map +1 -1
- package/dist/deploy/vercel/build.js +9 -12
- package/dist/deploy/vercel/build.js.map +1 -1
- package/dist/deploy/vercel/runtime.d.ts +4 -7
- package/dist/deploy/vercel/runtime.d.ts.map +1 -1
- package/dist/deploy/vercel/runtime.js +4 -7
- package/dist/deploy/vercel/runtime.js.map +1 -1
- package/dist/index.d.ts +13 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -12
- package/dist/index.js.map +1 -1
- package/dist/router.d.ts +65 -93
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +2 -5
- package/dist/router.js.map +1 -1
- package/dist/runtime/boundaries.d.ts +24 -30
- package/dist/runtime/boundaries.d.ts.map +1 -1
- package/dist/runtime/boundaries.js +15 -22
- package/dist/runtime/boundaries.js.map +1 -1
- package/dist/runtime/client.d.ts +16 -7
- package/dist/runtime/client.d.ts.map +1 -1
- package/dist/runtime/client.js +16 -7
- package/dist/runtime/client.js.map +1 -1
- package/dist/runtime/context.d.ts +89 -118
- package/dist/runtime/context.d.ts.map +1 -1
- package/dist/runtime/context.js +107 -167
- package/dist/runtime/context.js.map +1 -1
- package/dist/runtime/control.js +3 -3
- package/dist/runtime/control.js.map +1 -1
- package/dist/runtime/dev-protocol.d.ts +4 -8
- package/dist/runtime/dev-protocol.d.ts.map +1 -1
- package/dist/runtime/dev-protocol.js.map +1 -1
- package/dist/runtime/entry.client.d.ts.map +1 -1
- package/dist/runtime/entry.client.js +92 -120
- package/dist/runtime/entry.client.js.map +1 -1
- package/dist/runtime/entry.rsc.d.ts +5 -6
- package/dist/runtime/entry.rsc.d.ts.map +1 -1
- package/dist/runtime/entry.rsc.js +67 -122
- package/dist/runtime/entry.rsc.js.map +1 -1
- package/dist/runtime/entry.ssr.d.ts +7 -12
- package/dist/runtime/entry.ssr.d.ts.map +1 -1
- package/dist/runtime/entry.ssr.js +13 -24
- package/dist/runtime/entry.ssr.js.map +1 -1
- package/dist/runtime/flight-inject.d.ts +10 -17
- package/dist/runtime/flight-inject.d.ts.map +1 -1
- package/dist/runtime/flight-inject.js +35 -53
- package/dist/runtime/flight-inject.js.map +1 -1
- package/dist/runtime/hot-update.d.ts +45 -0
- package/dist/runtime/hot-update.d.ts.map +1 -0
- package/dist/runtime/hot-update.js +44 -0
- package/dist/runtime/hot-update.js.map +1 -0
- package/dist/runtime/navigation.d.ts +14 -19
- package/dist/runtime/navigation.d.ts.map +1 -1
- package/dist/runtime/navigation.js +9 -13
- package/dist/runtime/navigation.js.map +1 -1
- package/dist/runtime/request.d.ts +4 -6
- package/dist/runtime/request.d.ts.map +1 -1
- package/dist/runtime/request.js +2 -3
- package/dist/runtime/request.js.map +1 -1
- package/dist/runtime/server.d.ts +18 -10
- package/dist/runtime/server.d.ts.map +1 -1
- package/dist/runtime/server.js +21 -19
- package/dist/runtime/server.js.map +1 -1
- package/dist/server/headers.d.ts +8 -15
- package/dist/server/headers.d.ts.map +1 -1
- package/dist/server/headers.js +8 -15
- package/dist/server/headers.js.map +1 -1
- package/dist/server/load-config.d.ts +2 -2
- package/dist/server/load-config.d.ts.map +1 -1
- package/dist/server/load-config.js +6 -9
- package/dist/server/load-config.js.map +1 -1
- package/dist/server/prerendered.d.ts +30 -43
- package/dist/server/prerendered.d.ts.map +1 -1
- package/dist/server/prerendered.js +20 -29
- package/dist/server/prerendered.js.map +1 -1
- package/dist/server/server-config.d.ts +18 -25
- package/dist/server/server-config.d.ts.map +1 -1
- package/dist/server/server-config.js +7 -11
- package/dist/server/server-config.js.map +1 -1
- package/dist/server/shutdown.d.ts +2 -3
- package/dist/server/shutdown.d.ts.map +1 -1
- package/dist/server/shutdown.js +2 -3
- package/dist/server/shutdown.js.map +1 -1
- package/dist/server/ssg.d.ts +3 -6
- package/dist/server/ssg.d.ts.map +1 -1
- package/dist/server/ssg.js +11 -20
- package/dist/server/ssg.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../src/runtime/navigation.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAsC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE3E;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,gBAAgB;IAC/B,0DAA0D;IAC1D,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,sFAAsF;IACtF,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,sFAAsF;IACtF,OAAO,IAAI,IAAI,CAAC;IAChB,kGAAkG;IAClG,OAAO,EAAE,OAAO,CAAC;CAClB;AAKD,oGAAoG;AACpG,MAAM,WAAW,eAAe;IAC9B
|
|
1
|
+
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../src/runtime/navigation.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAsC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE3E;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,gBAAgB;IAC/B,0DAA0D;IAC1D,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,sFAAsF;IACtF,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,sFAAsF;IACtF,OAAO,IAAI,IAAI,CAAC;IAChB,kGAAkG;IAClG,OAAO,EAAE,OAAO,CAAC;CAClB;AAKD,oGAAoG;AACpG,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,GAAG,EAAE,GAAG,CAAC;IACT,yFAAyF;IACzF,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,4DAA4D;IAC5D,MAAM,EAAE,gBAAgB,CAAC;CAC1B;AAMD;;;;GAIG;AACH,eAAO,MAAM,aAAa,2CAAiD,CAAC;AAI5E;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAA;CAAE,+BAK/H;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,aAAa,IAAI,eAAe,CAQ/C"}
|
|
@@ -4,17 +4,15 @@ import { createContext, useContext, useMemo } from 'react';
|
|
|
4
4
|
const noop = () => { };
|
|
5
5
|
const defaultRouter = { push: noop, replace: noop, refresh: noop, pending: false };
|
|
6
6
|
/**
|
|
7
|
-
* Carries the live {@link NavigationRouter}
|
|
8
|
-
* to {@link RouterProvider}. Framework internal — read the router through
|
|
9
|
-
* {@link useNavigation} instead.
|
|
7
|
+
* Carries the live {@link NavigationRouter} from the hydration runtime down to {@link RouterProvider}.
|
|
10
8
|
*
|
|
11
9
|
* @internal
|
|
12
10
|
*/
|
|
13
11
|
export const RouterContext = createContext(defaultRouter);
|
|
14
12
|
const NavigationContext = createContext(null);
|
|
15
13
|
/**
|
|
16
|
-
* Publishes the per-render location and params
|
|
17
|
-
*
|
|
14
|
+
* Publishes the per-render location and params for {@link useNavigation} to read. The RSC entry wraps
|
|
15
|
+
* every page in one.
|
|
18
16
|
*
|
|
19
17
|
* @internal
|
|
20
18
|
*/
|
|
@@ -24,16 +22,14 @@ export function RouterProvider({ href, params, children }) {
|
|
|
24
22
|
return _jsx(NavigationContext.Provider, { value: value, children: children });
|
|
25
23
|
}
|
|
26
24
|
/**
|
|
27
|
-
* Reactive access to the current URL and programmatic navigation, in one hook.
|
|
25
|
+
* Reactive access to the current URL and programmatic navigation, in one hook. Call it from a
|
|
26
|
+
* `'use client'` component.
|
|
28
27
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* every navigation. The `router` sub-object holds the imperative actions plus a
|
|
33
|
-
* `pending` flag that is `true` while a client navigation is in flight.
|
|
28
|
+
* `url` and `params` are computed on the server and travel in the flight payload, so they are correct
|
|
29
|
+
* during SSR — no hydration flicker — and update on every navigation. `router` holds the imperative
|
|
30
|
+
* actions plus a `pending` flag, `true` while a soft navigation is in flight.
|
|
34
31
|
*
|
|
35
|
-
* Hooks can't run in a server component; read the same
|
|
36
|
-
* `getRequestContext()` (`@rshono/core/server`) instead.
|
|
32
|
+
* Hooks can't run in a server component; read the same data there from `getRequestContext()`.
|
|
37
33
|
*
|
|
38
34
|
* @example
|
|
39
35
|
* ```tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation.js","sourceRoot":"","sources":["../../src/runtime/navigation.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAkB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"navigation.js","sourceRoot":"","sources":["../../src/runtime/navigation.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAkB,MAAM,OAAO,CAAC;AA4C3E,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAEtB,MAAM,aAAa,GAAqB,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAErG;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAmB,aAAa,CAAC,CAAC;AAE5E,MAAM,iBAAiB,GAAG,aAAa,CAAyB,IAAI,CAAC,CAAC;AAEtE;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAyE;IAC9H,MAAM,MAAM,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IACzC,MAAM,KAAK,GAAG,OAAO,CAAkB,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAE/G,OAAO,KAAC,iBAAiB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAA8B,CAAC;AAC3F,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,KAAK,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC;IAC5C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,mKAAmK,CACpK,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["'use client';\n\nimport { createContext, useContext, useMemo, type ReactNode } from 'react';\n\n/**\n * Imperative navigation actions, reached as `useNavigation().router`.\n *\n * `push` / `replace` / `refresh` are **soft** navigations: the new page's flight payload is fetched and\n * applied in place, so client component state outside the changed subtree survives. Off-site hrefs fall\n * back to a full load.\n *\n * @example\n * ```tsx\n * const { router } = useNavigation();\n * router.push('/dashboard'); // navigate, new history entry\n * router.replace('/login'); // navigate, no new entry\n * router.refresh(); // re-run this route's server components\n * ```\n */\nexport interface NavigationRouter {\n /** Navigates to `href` and pushes a new history entry. */\n push(href: string): void;\n /** Navigates to `href`, replacing the current history entry instead of adding one. */\n replace(href: string): void;\n /** Re-fetches the current route from the server, re-running its server components. */\n refresh(): void;\n /** `true` while a soft navigation is in flight — use it to disable controls or show a spinner. */\n pending: boolean;\n}\n\n// No `back()` / `forward()`: `history.back()` needs no framework, and the runtime's `popstate` listener\n// picks the traversal up either way.\n\n/** The current location plus the {@link NavigationRouter}, as returned by {@link useNavigation}. */\nexport interface NavigationState {\n /**\n * The full current {@link URL}. A fresh instance per navigation, so mutating it affects nothing else\n * — it is not written back to the address bar.\n */\n url: URL;\n /** Matched route params for the current page, e.g. `{ id: '42' }` for `/profile/:id`. */\n params: Record<string, string>;\n /** Imperative navigation actions and the `pending` flag. */\n router: NavigationRouter;\n}\n\nconst noop = () => {};\n\nconst defaultRouter: NavigationRouter = { push: noop, replace: noop, refresh: noop, pending: false };\n\n/**\n * Carries the live {@link NavigationRouter} from the hydration runtime down to {@link RouterProvider}.\n *\n * @internal\n */\nexport const RouterContext = createContext<NavigationRouter>(defaultRouter);\n\nconst NavigationContext = createContext<NavigationState | null>(null);\n\n/**\n * Publishes the per-render location and params for {@link useNavigation} to read. The RSC entry wraps\n * every page in one.\n *\n * @internal\n */\nexport function RouterProvider({ href, params, children }: { href: string; params: Record<string, string>; children: ReactNode }) {\n const router = useContext(RouterContext);\n const value = useMemo<NavigationState>(() => ({ url: new URL(href), params, router }), [href, params, router]);\n\n return <NavigationContext.Provider value={value}>{children}</NavigationContext.Provider>;\n}\n\n/**\n * Reactive access to the current URL and programmatic navigation, in one hook. Call it from a\n * `'use client'` component.\n *\n * `url` and `params` are computed on the server and travel in the flight payload, so they are correct\n * during SSR — no hydration flicker — and update on every navigation. `router` holds the imperative\n * actions plus a `pending` flag, `true` while a soft navigation is in flight.\n *\n * Hooks can't run in a server component; read the same data there from `getRequestContext()`.\n *\n * @example\n * ```tsx\n * 'use client';\n * import { useNavigation } from '@rshono/core/client';\n *\n * export function NextPage() {\n * const { url, router } = useNavigation();\n * const page = Number(url.searchParams.get('page') ?? '1');\n * return (\n * <button disabled={router.pending} onClick={() => router.push(`${url.pathname}?page=${page + 1}`)}>\n * Next {router.pending ? '…' : ''}\n * </button>\n * );\n * }\n * ```\n *\n * @returns The current {@link NavigationState}: `url` and `params`, plus `router`\n * ({@link NavigationRouter}) with `push` / `replace` / `refresh` / `pending`.\n * @throws If called outside a page's React tree, where there is no navigation\n * context to read.\n *\n * @see {@link https://www.rshono.com/docs/api#rshonocoreclient | Docs — `@rshono/core/client`}\n * @see {@link https://www.rshono.com/docs/pages#client-components | Docs — client components}\n */\nexport function useNavigation(): NavigationState {\n const value = useContext(NavigationContext);\n if (!value) {\n throw new Error(\n \"[rshono] useNavigation() must be called inside a 'use client' component rendered by a page. In a server component, read the URL from getRequestContext() instead.\",\n );\n }\n return value;\n}\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The four
|
|
3
|
-
*
|
|
4
|
-
* unrepresentable and every consumer dispatches exhaustively on `kind`.
|
|
2
|
+
* The four shapes an incoming render request can take, as a discriminated union so that illegal
|
|
3
|
+
* combinations — an action id on a GET — are unrepresentable.
|
|
5
4
|
*
|
|
6
5
|
* - `document` — a normal navigation; respond with a full SSR HTML document.
|
|
7
6
|
* - `rsc` — a soft-navigation flight fetch (`Accept: text/x-component`).
|
|
@@ -29,9 +28,8 @@ export declare function acceptsRsc(request: Request): boolean;
|
|
|
29
28
|
/** True when the response should be a flight payload rather than an HTML document. */
|
|
30
29
|
export declare function wantsRsc(renderRequest: RenderRequest): boolean;
|
|
31
30
|
/**
|
|
32
|
-
* {@link wantsRsc} straight off the request, for the error and control-signal paths
|
|
33
|
-
* parsed {@link RenderRequest} to hand
|
|
34
|
-
* than from the render.
|
|
31
|
+
* {@link wantsRsc} straight off the request, for the error and control-signal paths — reached from Hono's
|
|
32
|
+
* `onError` / `notFound`, so they have no parsed {@link RenderRequest} to hand.
|
|
35
33
|
*/
|
|
36
34
|
export declare function requestWantsRsc(request: Request): boolean;
|
|
37
35
|
/** True when the request carries a server action to run before rendering. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/runtime/request.ts"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/runtime/request.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAExI,uHAAuH;AACvH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAAG,OAAO,CASpG;AAID,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,aAAa,CAQlE;AAED,gHAAgH;AAChH,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAEpD;AAED,sFAAsF;AACtF,wBAAgB,QAAQ,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAE9D;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAEzD;AAED,6EAA6E;AAC7E,wBAAgB,eAAe,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,OAAO,CAAC,aAAa,EAAE;IAAE,IAAI,EAAE,aAAa,GAAG,YAAY,CAAA;CAAE,CAAC,CAE7I"}
|
package/dist/runtime/request.js
CHANGED
|
@@ -33,9 +33,8 @@ export function wantsRsc(renderRequest) {
|
|
|
33
33
|
return renderRequest.kind === 'rsc' || renderRequest.kind === 'rsc-action';
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
* {@link wantsRsc} straight off the request, for the error and control-signal paths
|
|
37
|
-
* parsed {@link RenderRequest} to hand
|
|
38
|
-
* than from the render.
|
|
36
|
+
* {@link wantsRsc} straight off the request, for the error and control-signal paths — reached from Hono's
|
|
37
|
+
* `onError` / `notFound`, so they have no parsed {@link RenderRequest} to hand.
|
|
39
38
|
*/
|
|
40
39
|
export function requestWantsRsc(request) {
|
|
41
40
|
return wantsRsc(parseRenderRequest(request));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/runtime/request.ts"],"names":[],"mappings":"AAAA,MAAM,gBAAgB,GAAG,cAAc,CAAC;AACxC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/runtime/request.ts"],"names":[],"mappings":"AAAA,MAAM,gBAAgB,GAAG,cAAc,CAAC;AACxC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAa5C,uHAAuH;AACvH,MAAM,UAAU,gBAAgB,CAAC,SAAiB,EAAE,MAAuC;IACzF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAChD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAC1D,IAAI,MAAM;QAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IACrD,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE;QACtB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,K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,OAAO,aAAa,CAAC,IAAI,KAAK,aAAa,IAAI,aAAa,CAAC,IAAI,KAAK,YAAY,CAAC;AACrF,CAAC","sourcesContent":["const HEADER_ACTION_ID = 'x-rsc-action';\nconst RSC_CONTENT_TYPE = 'text/x-component';\n\n/**\n * The four shapes an incoming render request can take, as a discriminated union so that illegal\n * combinations — an action id on a GET — are unrepresentable.\n *\n * - `document` — a normal navigation; respond with a full SSR HTML document.\n * - `rsc` — a soft-navigation flight fetch (`Accept: text/x-component`).\n * - `form-action` — a progressive-enhancement `<form>` POST (no JavaScript).\n * - `rsc-action` — a client-initiated server-action call carrying an action id.\n */\nexport type RenderRequest = { kind: 'document' } | { kind: 'rsc' } | { kind: 'form-action' } | { kind: 'rsc-action'; actionId: string };\n\n/** Builds the `Request` the client sends to ask a page for its flight payload, optionally carrying a server action. */\nexport function createRscRequest(urlString: string, action?: { id: string; body: BodyInit }): Request {\n const url = new URL(urlString, location.origin);\n const headers = new Headers({ Accept: RSC_CONTENT_TYPE });\n if (action) headers.set(HEADER_ACTION_ID, action.id);\n return new Request(url, {\n method: action ? 'POST' : 'GET',\n headers,\n body: action?.body,\n });\n}\n\nconst FORM_CONTENT_TYPES = /^(?:multipart\\/form-data|application\\/x-www-form-urlencoded)/i;\n\nexport function parseRenderRequest(request: Request): RenderRequest {\n if (request.method === 'POST') {\n const actionId = request.headers.get(HEADER_ACTION_ID);\n if (actionId) return { kind: 'rsc-action', actionId };\n if (FORM_CONTENT_TYPES.test(request.headers.get('content-type') ?? '')) return { kind: 'form-action' };\n return { kind: 'document' };\n }\n return { kind: acceptsRsc(request) ? 'rsc' : 'document' };\n}\n\n/** Whether the client asked for a flight payload. For GET paths that only need the boolean, without parsing. */\nexport function acceptsRsc(request: Request): boolean {\n return request.headers.get('accept')?.includes(RSC_CONTENT_TYPE) ?? false;\n}\n\n/** True when the response should be a flight payload rather than an HTML document. */\nexport function wantsRsc(renderRequest: RenderRequest): boolean {\n return renderRequest.kind === 'rsc' || renderRequest.kind === 'rsc-action';\n}\n\n/**\n * {@link wantsRsc} straight off the request, for the error and control-signal paths — reached from Hono's\n * `onError` / `notFound`, so they have no parsed {@link RenderRequest} to hand.\n */\nexport function requestWantsRsc(request: Request): boolean {\n return wantsRsc(parseRenderRequest(request));\n}\n\n/** True when the request carries a server action to run before rendering. */\nexport function isActionRequest(renderRequest: RenderRequest): renderRequest is Extract<RenderRequest, { kind: 'form-action' | 'rsc-action' }> {\n return renderRequest.kind === 'form-action' || renderRequest.kind === 'rsc-action';\n}\n"]}
|
package/dist/runtime/server.d.ts
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@rshono/core/server` — the request-scoped surface, for use
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* is handed Hono's `c` rather than a request context.
|
|
2
|
+
* `@rshono/core/server` — the request-scoped surface, for server components and `'use server'` action
|
|
3
|
+
* modules: `getRequestContext()` for the URL, cookies, params, env and middleware variables, the
|
|
4
|
+
* `redirect()` and `notFound()` control-flow helpers, and `onServerError()` for reporting the errors
|
|
5
|
+
* the framework catches. Plus `publicUrl(c)` for middleware, which is handed Hono's `c` rather than a
|
|
6
|
+
* request context.
|
|
8
7
|
*
|
|
9
|
-
* Server-only
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* Server-only: a `'use client'` module runs in the browser, with no bound context. Read what you need
|
|
9
|
+
* on the server and pass it down as props, or use `useNavigation()` from `@rshono/core/client`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* 'use server';
|
|
14
|
+
* import { getRequestContext, redirect } from '@rshono/core/server';
|
|
15
|
+
*
|
|
16
|
+
* export async function logout() {
|
|
17
|
+
* getRequestContext().cookies.delete('session', { path: '/' });
|
|
18
|
+
* redirect('/');
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
13
21
|
*
|
|
14
22
|
* @see {@link https://www.rshono.com/docs/api#rshonocoreserver | Docs — `@rshono/core/server`}
|
|
15
23
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/runtime/server.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/runtime/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAIH,OAAO,EACL,iBAAiB,EACjB,QAAQ,EACR,aAAa,EACb,SAAS,EACT,QAAQ,EACR,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,GACvB,MAAM,cAAc,CAAC"}
|
package/dist/runtime/server.js
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@rshono/core/server` — the request-scoped surface, for use
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* is handed Hono's `c` rather than a request context.
|
|
2
|
+
* `@rshono/core/server` — the request-scoped surface, for server components and `'use server'` action
|
|
3
|
+
* modules: `getRequestContext()` for the URL, cookies, params, env and middleware variables, the
|
|
4
|
+
* `redirect()` and `notFound()` control-flow helpers, and `onServerError()` for reporting the errors
|
|
5
|
+
* the framework catches. Plus `publicUrl(c)` for middleware, which is handed Hono's `c` rather than a
|
|
6
|
+
* request context.
|
|
8
7
|
*
|
|
9
|
-
* Server-only
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* Server-only: a `'use client'` module runs in the browser, with no bound context. Read what you need
|
|
9
|
+
* on the server and pass it down as props, or use `useNavigation()` from `@rshono/core/client`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* 'use server';
|
|
14
|
+
* import { getRequestContext, redirect } from '@rshono/core/server';
|
|
15
|
+
*
|
|
16
|
+
* export async function logout() {
|
|
17
|
+
* getRequestContext().cookies.delete('session', { path: '/' });
|
|
18
|
+
* redirect('/');
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
13
21
|
*
|
|
14
22
|
* @see {@link https://www.rshono.com/docs/api#rshonocoreserver | Docs — `@rshono/core/server`}
|
|
15
23
|
*
|
|
16
24
|
* @packageDocumentation
|
|
17
25
|
*/
|
|
18
|
-
// A barrel rather than pointing the
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
// autocomplete and under semver. They stay reachable by relative import.
|
|
22
|
-
export { getRequestContext, notFound, onServerError,
|
|
23
|
-
// For middleware, which is handed Hono's `c` and so has no request context to read a URL from.
|
|
24
|
-
// Hono's own middleware all resolve the origin from `c.req.url`, which is the internal address
|
|
25
|
-
// behind a proxy — this is what `trustProxy` means to them.
|
|
26
|
-
publicUrl, redirect, } from './context.js';
|
|
26
|
+
// A barrel rather than pointing the subpath at `./context.js`, which also exports the framework's own
|
|
27
|
+
// plumbing — that would put `runWithContext` and friends in a consumer's autocomplete and under semver.
|
|
28
|
+
export { getRequestContext, notFound, onServerError, publicUrl, redirect, } from './context.js';
|
|
27
29
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/runtime/server.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/runtime/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,sGAAsG;AACtG,wGAAwG;AACxG,OAAO,EACL,iBAAiB,EACjB,QAAQ,EACR,aAAa,EACb,SAAS,EACT,QAAQ,GAOT,MAAM,cAAc,CAAC","sourcesContent":["/**\n * `@rshono/core/server` — the request-scoped surface, for server components and `'use server'` action\n * modules: `getRequestContext()` for the URL, cookies, params, env and middleware variables, the\n * `redirect()` and `notFound()` control-flow helpers, and `onServerError()` for reporting the errors\n * the framework catches. Plus `publicUrl(c)` for middleware, which is handed Hono's `c` rather than a\n * request context.\n *\n * Server-only: a `'use client'` module runs in the browser, with no bound context. Read what you need\n * on the server and pass it down as props, or use `useNavigation()` from `@rshono/core/client`.\n *\n * @example\n * ```ts\n * 'use server';\n * import { getRequestContext, redirect } from '@rshono/core/server';\n *\n * export async function logout() {\n * getRequestContext().cookies.delete('session', { path: '/' });\n * redirect('/');\n * }\n * ```\n *\n * @see {@link https://www.rshono.com/docs/api#rshonocoreserver | Docs — `@rshono/core/server`}\n *\n * @packageDocumentation\n */\n\n// A barrel rather than pointing the subpath at `./context.js`, which also exports the framework's own\n// plumbing — that would put `runWithContext` and friends in a consumer's autocomplete and under semver.\nexport {\n getRequestContext,\n notFound,\n onServerError,\n publicUrl,\n redirect,\n type EnvVars,\n type RedirectStatus,\n type RequestContext,\n type ServerErrorContext,\n type ServerErrorHandler,\n type ServerErrorSource,\n} from './context.js';\n"]}
|
package/dist/server/headers.d.ts
CHANGED
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* thing that only shows up behind a CDN.
|
|
2
|
+
* Header utilities shared by the response-header defaults and the prerendered-page cache. Their own module
|
|
3
|
+
* because getting `Vary` and `ETag` comparison subtly wrong only shows up behind a CDN.
|
|
5
4
|
*/
|
|
6
5
|
/**
|
|
7
|
-
* Adds `value` to the `Vary` header without discarding what is already there
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* one URL) is not necessarily the only one: a route, a middleware or a proxy may have added its own.
|
|
11
|
-
* A plain `set` would drop the others, and a cache would then serve one variant in place of another.
|
|
12
|
-
* `*` is left alone: it already means "never reuse this".
|
|
6
|
+
* Adds `value` to the `Vary` header without discarding what is already there — a route, a middleware or a proxy
|
|
7
|
+
* may have added its own entry, and a plain `set` would drop it, leaving a cache free to serve one variant in
|
|
8
|
+
* place of another. `*` is left alone: it already means "never reuse this".
|
|
13
9
|
*/
|
|
14
10
|
export declare function appendVary(headers: Headers, value: string): void;
|
|
15
11
|
/**
|
|
16
|
-
* True when an `If-None-Match`
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* The header carries a *list*, and each entry may be weak (`W/"…"`). The weak prefix is ignored on
|
|
20
|
-
* both sides: a proxy or CDN that gzips on the way out changes the bytes without changing the
|
|
21
|
-
* representation, and is entitled to weaken the validator when it does.
|
|
12
|
+
* True when an `If-None-Match` matches `etag` — the client already holds this body and can be answered with a
|
|
13
|
+
* 304. The header carries a list, and the weak prefix is ignored on both sides: a CDN that gzips on the way out
|
|
14
|
+
* changes the bytes without changing the representation, and may weaken the validator when it does.
|
|
22
15
|
*/
|
|
23
16
|
export declare function etagMatches(ifNoneMatch: string | undefined, etag: string): boolean;
|
|
24
17
|
//# sourceMappingURL=headers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../src/server/headers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../src/server/headers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAShE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAQlF"}
|
package/dist/server/headers.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* thing that only shows up behind a CDN.
|
|
2
|
+
* Header utilities shared by the response-header defaults and the prerendered-page cache. Their own module
|
|
3
|
+
* because getting `Vary` and `ETag` comparison subtly wrong only shows up behind a CDN.
|
|
5
4
|
*/
|
|
6
5
|
/**
|
|
7
|
-
* Adds `value` to the `Vary` header without discarding what is already there
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* one URL) is not necessarily the only one: a route, a middleware or a proxy may have added its own.
|
|
11
|
-
* A plain `set` would drop the others, and a cache would then serve one variant in place of another.
|
|
12
|
-
* `*` is left alone: it already means "never reuse this".
|
|
6
|
+
* Adds `value` to the `Vary` header without discarding what is already there — a route, a middleware or a proxy
|
|
7
|
+
* may have added its own entry, and a plain `set` would drop it, leaving a cache free to serve one variant in
|
|
8
|
+
* place of another. `*` is left alone: it already means "never reuse this".
|
|
13
9
|
*/
|
|
14
10
|
export function appendVary(headers, value) {
|
|
15
11
|
const existing = headers.get('vary');
|
|
@@ -24,12 +20,9 @@ export function appendVary(headers, value) {
|
|
|
24
20
|
headers.set('vary', `${existing}, ${value}`);
|
|
25
21
|
}
|
|
26
22
|
/**
|
|
27
|
-
* True when an `If-None-Match`
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* The header carries a *list*, and each entry may be weak (`W/"…"`). The weak prefix is ignored on
|
|
31
|
-
* both sides: a proxy or CDN that gzips on the way out changes the bytes without changing the
|
|
32
|
-
* representation, and is entitled to weaken the validator when it does.
|
|
23
|
+
* True when an `If-None-Match` matches `etag` — the client already holds this body and can be answered with a
|
|
24
|
+
* 304. The header carries a list, and the weak prefix is ignored on both sides: a CDN that gzips on the way out
|
|
25
|
+
* changes the bytes without changing the representation, and may weaken the validator when it does.
|
|
33
26
|
*/
|
|
34
27
|
export function etagMatches(ifNoneMatch, etag) {
|
|
35
28
|
if (!ifNoneMatch)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/server/headers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/server/headers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,OAAgB,EAAE,KAAa;IACxD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACrC,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC3B,OAAO;IACT,CAAC;IACD,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG;QAAE,OAAO;IACpC,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;IACxG,IAAI,CAAC,OAAO;QAAE,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,QAAQ,KAAK,KAAK,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,WAA+B,EAAE,IAAY;IACvE,IAAI,CAAC,WAAW;QAAE,OAAO,KAAK,CAAC;IAC/B,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACtE,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;QAC3C,MAAM,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QACnC,OAAO,SAAS,KAAK,GAAG,IAAI,SAAS,KAAK,MAAM,CAAC;IACnD,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * Header utilities shared by the response-header defaults and the prerendered-page cache. Their own module\n * because getting `Vary` and `ETag` comparison subtly wrong only shows up behind a CDN.\n */\n\n/**\n * Adds `value` to the `Vary` header without discarding what is already there — a route, a middleware or a proxy\n * may have added its own entry, and a plain `set` would drop it, leaving a cache free to serve one variant in\n * place of another. `*` is left alone: it already means \"never reuse this\".\n */\nexport function appendVary(headers: Headers, value: string): void {\n const existing = headers.get('vary');\n if (existing === null) {\n headers.set('vary', value);\n return;\n }\n if (existing.trim() === '*') return;\n const already = existing.split(',').some((entry) => entry.trim().toLowerCase() === value.toLowerCase());\n if (!already) headers.set('vary', `${existing}, ${value}`);\n}\n\n/**\n * True when an `If-None-Match` matches `etag` — the client already holds this body and can be answered with a\n * 304. The header carries a list, and the weak prefix is ignored on both sides: a CDN that gzips on the way out\n * changes the bytes without changing the representation, and may weaken the validator when it does.\n */\nexport function etagMatches(ifNoneMatch: string | undefined, etag: string): boolean {\n if (!ifNoneMatch) return false;\n const normalize = (value: string) => value.trim().replace(/^W\\//, '');\n const wanted = normalize(etag);\n return ifNoneMatch.split(',').some((entry) => {\n const candidate = normalize(entry);\n return candidate === '*' || candidate === wanted;\n });\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RshonoConfig } from '../config.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Loads the project config, or `{}` if there is none: scans `rshono.config.{ts,js,mjs}` at `rootDir`, unless an
|
|
4
|
+
* explicit `configPath` is given (resolved relative to `cwd`).
|
|
5
5
|
*/
|
|
6
6
|
export declare function loadConfig(rootDir: string, configPath?: string): Promise<RshonoConfig>;
|
|
7
7
|
//# sourceMappingURL=load-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-config.d.ts","sourceRoot":"","sources":["../../src/server/load-config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"load-config.d.ts","sourceRoot":"","sources":["../../src/server/load-config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAgBjD;;;GAGG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CA6B5F"}
|
|
@@ -3,22 +3,19 @@ import { isAbsolute, join, resolve } from 'node:path';
|
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
4
|
const CONFIG_FILES = ['rshono.config.ts', 'rshono.config.js', 'rshono.config.mjs'];
|
|
5
5
|
/**
|
|
6
|
-
* Imports the config module.
|
|
7
|
-
*
|
|
8
|
-
* A `.ts` config needs no loader of its own: Node strips types natively from 22.18 on, which is what
|
|
9
|
-
* the package's `engines` floor is for. That replaced a `tsx` dependency whose only job was these two
|
|
10
|
-
* lines — and `tsx` bundles esbuild, so it was the largest thing in the install.
|
|
6
|
+
* Imports the config module. A `.ts` config needs no loader: Node strips types natively from 22.18 on, which is
|
|
7
|
+
* what the package's `engines` floor is for.
|
|
11
8
|
*
|
|
12
9
|
* The one thing native stripping will not do is resolve a `.js` specifier to a `.ts` file, so a config
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* importing a sibling has to name it with its real extension — {@link loadConfig} turns that resolution failure
|
|
11
|
+
* into the advice rather than letting a raw `ERR_MODULE_NOT_FOUND` out.
|
|
15
12
|
*/
|
|
16
13
|
function importConfig(file) {
|
|
17
14
|
return import(pathToFileURL(file).href);
|
|
18
15
|
}
|
|
19
16
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
17
|
+
* Loads the project config, or `{}` if there is none: scans `rshono.config.{ts,js,mjs}` at `rootDir`, unless an
|
|
18
|
+
* explicit `configPath` is given (resolved relative to `cwd`).
|
|
22
19
|
*/
|
|
23
20
|
export async function loadConfig(rootDir, configPath) {
|
|
24
21
|
const file = configPath
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-config.js","sourceRoot":"","sources":["../../src/server/load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C;QACtB,MAAM,IAAI,KAAK,CAAC,mCAAmC,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,GAA+B,CAAC;IACpC,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,0FAA0F;QAC1F,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAK,KAAkC,EAAE,IAAI,KAAK,sBAAsB,EAAE,CAAC;YACpG,MAAM,IAAI,KAAK,CACb,YAAY,IAAI,6CAA8C,KAAe,CAAC,OAAO,IAAI;gBACvF,kGAAkG;gBAClG,sFAAsF,EACxF,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;QACJ,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,YAAY,IAAI,yEAAyE,CAAC,CAAC;IAC7G,CAAC;IACD,OAAO,GAAG,CAAC,OAAO,CAAC;AACrB,CAAC","sourcesContent":["import { existsSync } from 'node:fs';\nimport { isAbsolute, join, resolve } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { RshonoConfig } from '../config.js';\n\nconst CONFIG_FILES = ['rshono.config.ts', 'rshono.config.js', 'rshono.config.mjs'];\n\n/**\n * Imports the config module. A `.ts` config needs no loader: Node strips types natively from 22.18 on, which is\n * what the package's `engines` floor is for.\n *\n * The one thing native stripping will not do is resolve a `.js` specifier to a `.ts` file, so a config\n * importing a sibling has to name it with its real extension — {@link loadConfig} turns that resolution failure\n * into the advice rather than letting a raw `ERR_MODULE_NOT_FOUND` out.\n */\nfunction importConfig(file: string): Promise<{ default?: RshonoConfig }> {\n return import(pathToFileURL(file).href) as Promise<{ default?: RshonoConfig }>;\n}\n\n/**\n * Loads the project config, or `{}` if there is none: scans `rshono.config.{ts,js,mjs}` at `rootDir`, unless an\n * explicit `configPath` is given (resolved relative to `cwd`).\n */\nexport async function loadConfig(rootDir: string, configPath?: string): Promise<RshonoConfig> {\n const file = configPath\n ? isAbsolute(configPath)\n ? configPath\n : resolve(process.cwd(), configPath)\n : CONFIG_FILES.map((f) => join(rootDir, f)).find(existsSync);\n if (!file) return {};\n if (!existsSync(file)) {\n throw new Error(`[rshono] config file not found: ${file}`);\n }\n let mod: { default?: RshonoConfig };\n try {\n mod = await importConfig(file);\n } catch (error) {\n // The one failure mode native type stripping has that a TypeScript-aware loader does not.\n if (/\\.[cm]?ts$/.test(file) && (error as { code?: string } | null)?.code === 'ERR_MODULE_NOT_FOUND') {\n throw new Error(\n `[rshono] ${file} imports a module Node could not resolve: ${(error as Error).message}\\n` +\n ' A .ts config is loaded by Node itself, which does not rewrite a .js specifier to the .ts file ' +\n 'beside it. Import it by its real extension, or move the config to rshono.config.mjs.',\n { cause: error },\n );\n }\n throw error;\n }\n if (!mod.default) {\n throw new Error(`[rshono] ${file} must \\`export default\\` a config object (use \\`defineConfig({ … })\\`).`);\n }\n return mod.default;\n}\n"]}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Everything about a prerendered page that doesn't need a filesystem: where the build puts it, and
|
|
3
|
-
*
|
|
2
|
+
* Everything about a prerendered page that doesn't need a filesystem: where the build puts it, and what it
|
|
3
|
+
* looks like once read back.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Apart from `ssg.ts`, which does the reading and writing through `node:fs`, because a deploy target without a
|
|
6
|
+
* filesystem reads the same layout out of an asset store — and importing it from there would drag `node:fs`
|
|
7
|
+
* into a bundle that has neither.
|
|
8
8
|
*/
|
|
9
9
|
/**
|
|
10
|
-
* The two representations of a page, prerendered side by side: a hard load wants the HTML document, a
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* The two representations of a page, prerendered side by side: a hard load wants the HTML document, a soft
|
|
11
|
+
* navigation asks the same URL for a flight payload. Without both, every in-app click would re-render a page
|
|
12
|
+
* that was already built.
|
|
13
13
|
*/
|
|
14
14
|
export type PrerenderVariant = 'html' | 'flight';
|
|
15
15
|
export declare const VARIANTS: {
|
|
@@ -25,70 +25,57 @@ export declare const VARIANTS: {
|
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
/**
|
|
28
|
-
* Where a route's prerendered output lives, relative to the output root — or `null` for a path that
|
|
29
|
-
*
|
|
28
|
+
* Where a route's prerendered output lives, relative to the output root — or `null` for a path that cannot be
|
|
29
|
+
* prerendered at all, one with a param or a wildcard left in it.
|
|
30
30
|
*
|
|
31
|
-
* Always `/`-separated
|
|
32
|
-
*
|
|
33
|
-
* where a backslash would simply be the wrong character.
|
|
31
|
+
* Always `/`-separated: the same string addresses a file on a filesystem, which accepts forward slashes on
|
|
32
|
+
* Windows too, and a key in an asset store, where a backslash would be the wrong character.
|
|
34
33
|
*/
|
|
35
34
|
export declare function ssgFilePath(routePath: string, variant?: PrerenderVariant): string | null;
|
|
36
35
|
/**
|
|
37
|
-
* {@link ssgFilePath} for a path that came off a request, so traversal is a miss rather than a lookup.
|
|
38
|
-
*
|
|
39
|
-
* The first line of defence for every deploy target: a store addressed by key has no `resolve()` to
|
|
40
|
-
* fall back on, so `..` has to be refused here or not at all.
|
|
36
|
+
* {@link ssgFilePath} for a path that came off a request, so traversal is a miss rather than a lookup. A store
|
|
37
|
+
* addressed by key has no `resolve()` to fall back on, so `..` is refused here or not at all.
|
|
41
38
|
*/
|
|
42
39
|
export declare function prerenderedRelPath(requestPath: string, variant: PrerenderVariant): string | null;
|
|
43
40
|
/**
|
|
44
|
-
* A bounded, insertion-ordered cache of prerendered pages
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* build in memory. Only *hits* are ever stored: caching misses would let anyone mint entries by
|
|
48
|
-
* requesting paths that don't exist. The files are written at build time and never change while the
|
|
49
|
-
* server is up, so an entry never needs invalidating.
|
|
41
|
+
* A bounded, insertion-ordered cache of prerendered pages, so a site with thousands of them keeps a working set
|
|
42
|
+
* rather than the whole build in memory. Only *hits* are stored — caching misses would let anyone mint entries
|
|
43
|
+
* by requesting paths that don't exist — and the files never change while the server is up.
|
|
50
44
|
*/
|
|
51
45
|
export declare function createPageCache(max?: number): {
|
|
52
46
|
get(key: string): PrerenderedPage | undefined;
|
|
53
47
|
set(key: string, page: PrerenderedPage): void;
|
|
54
48
|
};
|
|
55
49
|
/**
|
|
56
|
-
* A weak `ETag` for a page body — see {@link PrerenderedPage.etag} for why weak.
|
|
57
|
-
*
|
|
58
|
-
* Web Crypto rather than `node:crypto`, so the one implementation serves both a Node server and
|
|
59
|
-
* `workerd`.
|
|
50
|
+
* A weak `ETag` for a page body — see {@link PrerenderedPage.etag} for why weak. Web Crypto rather than
|
|
51
|
+
* `node:crypto`, so one implementation serves both a Node server and `workerd`.
|
|
60
52
|
*/
|
|
61
53
|
export declare function weakEtag(body: Uint8Array<ArrayBuffer>): Promise<string>;
|
|
62
54
|
/**
|
|
63
|
-
* Assembles a {@link PrerenderedPage} from a body just read out of the build.
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* exact bytes, so it is preferred over hashing them again, and only weakened.
|
|
55
|
+
* Assembles a {@link PrerenderedPage} from a body just read out of the build. `storeEtag` is the validator the
|
|
56
|
+
* store supplied, where it has one: it already describes these exact bytes, so it is weakened rather than
|
|
57
|
+
* replaced by a fresh hash.
|
|
67
58
|
*/
|
|
68
59
|
export declare function toPrerenderedPage(body: Uint8Array<ArrayBuffer>, storeEtag?: string | null): Promise<PrerenderedPage>;
|
|
69
60
|
/** A prerendered page, ready to serve: its body and a validator derived from those exact bytes. */
|
|
70
61
|
export interface PrerenderedPage {
|
|
71
62
|
/**
|
|
72
|
-
* The document or the flight payload, depending on which {@link PrerenderVariant} was read.
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* hits it — held as a string, each of those would pay a fresh UTF-8 encode of the whole page on the
|
|
76
|
-
* way out. Read once, encoded never.
|
|
63
|
+
* The document or the flight payload, depending on which {@link PrerenderVariant} was read. Bytes rather
|
|
64
|
+
* than a string, because this cache entry is served verbatim to every request that hits it — as a string,
|
|
65
|
+
* each would pay a fresh UTF-8 encode of the whole page.
|
|
77
66
|
*/
|
|
78
67
|
body: Uint8Array<ArrayBuffer>;
|
|
79
68
|
/**
|
|
80
|
-
* `Content-Length` for {@link body}, in bytes
|
|
81
|
-
*
|
|
82
|
-
* decisions with it — whether gzipping this response is worth the framing, most obviously.
|
|
69
|
+
* `Content-Length` for {@link body}, in bytes. Served explicitly because Hono sets no length for an
|
|
70
|
+
* in-memory body, and a proxy in front is entitled to make decisions with it.
|
|
83
71
|
*/
|
|
84
72
|
contentLength: string;
|
|
85
73
|
/**
|
|
86
74
|
* `ETag` for the page, so a revalidating client can be answered with a 304 instead of the body.
|
|
87
75
|
*
|
|
88
|
-
* Deliberately **weak
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* "the same representation", which is what stays true across content codings.
|
|
76
|
+
* Deliberately **weak**: the bytes on the wire depend on whether something in front re-encoded them, so a
|
|
77
|
+
* strong validator would differ per coding and a cache would treat the 200 and the 304 that revalidates it
|
|
78
|
+
* as different pages. A weak tag says "the same representation", which stays true across codings.
|
|
92
79
|
*/
|
|
93
80
|
etag: string;
|
|
94
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prerendered.d.ts","sourceRoot":"","sources":["../../src/server/prerendered.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEjD,eAAO,MAAM,QAAQ;;iBACX,IAAI,EAAE,YAAY;iBAAE,MAAM,EAAE,WAAW;iBAAE,WAAW,EAAE,WAAW;;;iBAC/D,IAAI,EAAE,WAAW;iBAAE,MAAM,EAAE,kBAAkB;iBAAE,WAAW,EAAE,kBAAkB;;CACU,CAAC;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