@nifrajs/cli 5.9.0 → 5.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +85 -0
- package/dist/check-diagnostics.d.ts +1 -0
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +4 -0
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +1 -0
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +8 -1
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +7 -2
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +21 -20
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts +1 -5
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +2 -21
- package/dist/command-catalog.js.map +1 -1
- package/dist/doctor.js +2 -2
- package/dist/doctor.js.map +1 -1
- package/dist/internal/source-facts.d.ts +30 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +127 -0
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/load.d.ts +4 -2
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +6 -1
- package/dist/load.js.map +1 -1
- package/dist/mcp-delegate.d.ts +17 -3
- package/dist/mcp-delegate.d.ts.map +1 -1
- package/dist/mcp-delegate.js +24 -9
- package/dist/mcp-delegate.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-http.js.map +1 -1
- package/dist/mcp-relay.d.ts +37 -0
- package/dist/mcp-relay.d.ts.map +1 -0
- package/dist/mcp-relay.js +129 -0
- package/dist/mcp-relay.js.map +1 -0
- package/dist/mcp-tool-meta.d.ts.map +1 -1
- package/dist/mcp-tool-meta.js +0 -1
- package/dist/mcp-tool-meta.js.map +1 -1
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +55 -1
- package/dist/mcp.js.map +1 -1
- package/dist/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +45 -33
- package/dist/migrate-layout.js.map +1 -1
- package/dist/recipes/5.10.0.d.ts +13 -0
- package/dist/recipes/5.10.0.d.ts.map +1 -0
- package/dist/recipes/5.10.0.js +45 -0
- package/dist/recipes/5.10.0.js.map +1 -0
- package/dist/recipes/5.11.0.d.ts +10 -0
- package/dist/recipes/5.11.0.d.ts.map +1 -0
- package/dist/recipes/5.11.0.js +50 -0
- package/dist/recipes/5.11.0.js.map +1 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +4 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +3 -0
- package/dist/review.js.map +1 -1
- package/dist/rules/codes.d.ts +3 -0
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +3 -0
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/explanations.d.ts.map +1 -1
- package/dist/rules/explanations.js +15 -0
- package/dist/rules/explanations.js.map +1 -1
- package/dist/rules/internal-links.d.ts +5 -0
- package/dist/rules/internal-links.d.ts.map +1 -0
- package/dist/rules/internal-links.js +418 -0
- package/dist/rules/internal-links.js.map +1 -0
- package/dist/rules/legacy.d.ts.map +1 -1
- package/dist/rules/legacy.js +20 -0
- package/dist/rules/legacy.js.map +1 -1
- package/dist/rules/server-fn-namespace.d.ts +8 -0
- package/dist/rules/server-fn-namespace.d.ts.map +1 -0
- package/dist/rules/server-fn-namespace.js +43 -0
- package/dist/rules/server-fn-namespace.js.map +1 -0
- package/dist/rules/source-scan.d.ts +29 -0
- package/dist/rules/source-scan.d.ts.map +1 -0
- package/dist/rules/source-scan.js +38 -0
- package/dist/rules/source-scan.js.map +1 -0
- package/dist/rules/text-slot-boolean.d.ts.map +1 -1
- package/dist/rules/text-slot-boolean.js +21 -43
- package/dist/rules/text-slot-boolean.js.map +1 -1
- package/dist/source-rewrites.d.ts +0 -5
- package/dist/source-rewrites.d.ts.map +1 -1
- package/dist/source-rewrites.js +350 -10
- package/dist/source-rewrites.js.map +1 -1
- package/dist/typecheck-coverage.d.ts +9 -0
- package/dist/typecheck-coverage.d.ts.map +1 -1
- package/dist/typecheck-coverage.js +16 -0
- package/dist/typecheck-coverage.js.map +1 -1
- package/dist/upgrade.d.ts +19 -1
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +55 -2
- package/dist/upgrade.js.map +1 -1
- package/docs/examples.json +21 -9
- package/docs/llms-full.txt +800 -262
- package/docs/types.json +868 -128
- package/package.json +11 -11
- package/src/check-diagnostics.ts +5 -0
- package/src/check-scan.ts +9 -1
- package/src/check.ts +15 -3
- package/src/cli.ts +25 -20
- package/src/command-catalog.ts +2 -26
- package/src/doctor.ts +2 -2
- package/src/internal/source-facts.ts +155 -0
- package/src/load.ts +15 -3
- package/src/mcp-delegate.ts +37 -11
- package/src/mcp-http.ts +1 -1
- package/src/mcp-relay.ts +155 -0
- package/src/mcp-tool-meta.ts +0 -1
- package/src/mcp.ts +51 -1
- package/src/migrate-layout.ts +61 -29
- package/src/recipes/5.10.0.ts +46 -0
- package/src/recipes/5.11.0.ts +51 -0
- package/src/recipes/index.ts +4 -0
- package/src/review.ts +3 -0
- package/src/rules/codes.ts +3 -0
- package/src/rules/explanations.ts +15 -0
- package/src/rules/internal-links.ts +490 -0
- package/src/rules/legacy.ts +21 -0
- package/src/rules/server-fn-namespace.ts +47 -0
- package/src/rules/source-scan.ts +66 -0
- package/src/rules/text-slot-boolean.ts +26 -42
- package/src/source-rewrites.ts +383 -12
- package/src/typecheck-coverage.ts +23 -0
- package/src/upgrade.ts +71 -3
- package/dist/sync-routes.d.ts +0 -29
- package/dist/sync-routes.d.ts.map +0 -1
- package/dist/sync-routes.js +0 -56
- package/dist/sync-routes.js.map +0 -1
- package/src/sync-routes.ts +0 -70
package/docs/llms-full.txt
CHANGED
|
@@ -47,7 +47,7 @@ cd my-app
|
|
|
47
47
|
bun install
|
|
48
48
|
bun run dev`
|
|
49
49
|
|
|
50
|
-
See the
|
|
50
|
+
See the CLI guide for other templates, UI frameworks, and deploy
|
|
51
51
|
targets.
|
|
52
52
|
|
|
53
53
|
### One app, two agent loops
|
|
@@ -55,8 +55,8 @@ targets.
|
|
|
55
55
|
A coding agent can inspect the live project, change it, run real requests, and prove the result.
|
|
56
56
|
A user-facing agent can discover explicit page tools, stream progress into the UI, predict a
|
|
57
57
|
state change, and reconcile it with the server. Both use the same typed capabilities and
|
|
58
|
-
verification boundary. Start with the
|
|
59
|
-
|
|
58
|
+
verification boundary. Start with the agent layer or the
|
|
59
|
+
WebMCP & predictive UI guide when you are ready to add them.
|
|
60
60
|
|
|
61
61
|
### A backend-only alternative
|
|
62
62
|
|
|
@@ -104,12 +104,12 @@ In the `site` template, a route is two files: the page, and a
|
|
|
104
104
|
`.backend.ts` half whose loader calls your backend in-process during SSR and
|
|
105
105
|
whose `actions` handle mutations. Only what the loader's output schema declares
|
|
106
106
|
reaches the browser. Add streaming, `defer()`, optimistic UI, and a keyed query
|
|
107
|
-
cache as you grow, then
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
cache as you grow, then live refresh,
|
|
108
|
+
keep-alive pages,
|
|
109
|
+
server components and
|
|
110
|
+
partial prerendering where a page needs them. The
|
|
111
111
|
data model is framework-agnostic, so the renderer stays replaceable. See
|
|
112
|
-
|
|
112
|
+
Project structure for where code lives.
|
|
113
113
|
|
|
114
114
|
```ts
|
|
115
115
|
// routes/index.backend.ts - the loader runs on the server (in-process during SSR, no network),
|
|
@@ -150,9 +150,9 @@ export default function Page({ data }: Route.ComponentProps) {
|
|
|
150
150
|
-
|
|
151
151
|
**Vercel Edge, AWS Lambda, or a static host** - `nifra build --target vercel`,
|
|
152
152
|
`@nifrajs/aws-lambda`, or `nifra build --target static` for a
|
|
153
|
-
prerendered site. See
|
|
153
|
+
prerendered site. See Deployment.
|
|
154
154
|
|
|
155
|
-
See the
|
|
155
|
+
See the benchmarks for how it performs.
|
|
156
156
|
|
|
157
157
|
## Nifra vs. other frameworks - the honest comparison
|
|
158
158
|
|
|
@@ -202,23 +202,23 @@ Across the board, Nifra ships the modern full-stack feature set on all five UI f
|
|
|
202
202
|
|
|
203
203
|
-
|
|
204
204
|
File routing (dynamic / catch-all / groups / optional) + nested layouts, typed search
|
|
205
|
-
params, and a route
|
|
205
|
+
params, and a route opened in a modal.
|
|
206
206
|
|
|
207
207
|
-
|
|
208
208
|
SSR · SSG · ISR, streaming SSR with out-of-order Suspense,
|
|
209
|
-
|
|
209
|
+
partial prerendering, view
|
|
210
210
|
transitions, and a ~0 KB-client vanilla adapter with
|
|
211
|
-
|
|
211
|
+
islands and slot swaps.
|
|
212
212
|
|
|
213
213
|
-
|
|
214
|
-
Loaders + actions +
|
|
214
|
+
Loaders + actions + server functions (typed
|
|
215
215
|
`serverFn` RPC, server code never shipped to the browser) + progressive-enhancement
|
|
216
216
|
forms; `defer()` / `<Await>` streaming data; query cache, optimistic
|
|
217
217
|
UI, concurrent fetchers, revalidation.
|
|
218
218
|
|
|
219
219
|
-
|
|
220
|
-
|
|
221
|
-
changed keys) and
|
|
220
|
+
Live refresh (a publish reloads only the loaders that read the
|
|
221
|
+
changed keys) and keep-alive pages (back and forward bring
|
|
222
222
|
the same page back, state and scroll included).
|
|
223
223
|
|
|
224
224
|
- Head/meta, hover/focus prefetch, scroll restoration.
|
|
@@ -234,11 +234,11 @@ of one.
|
|
|
234
234
|
### Server code and server-only views
|
|
235
235
|
|
|
236
236
|
Nifra provides typed loaders and actions, streaming SSR, islands and typed
|
|
237
|
-
|
|
237
|
+
server functions. Server functions keep their
|
|
238
238
|
implementation, secrets and database handles off the browser and use the same validated
|
|
239
239
|
mutation API across the supported UI libraries.
|
|
240
240
|
|
|
241
|
-
The optional
|
|
241
|
+
The optional server-components pipeline adds
|
|
242
242
|
server-only views and state-preserving refresh. React uses native RSC/Flight; Vue, Svelte,
|
|
243
243
|
Solid and Preact use their native islands in validated server-rendered ranges. All five
|
|
244
244
|
adapters pass the same certification, and a partially prerendered page can show a server
|
|
@@ -247,14 +247,14 @@ component in a hole. Server functions remain the mutation API; native React
|
|
|
247
247
|
|
|
248
248
|
### Caching and fresh data
|
|
249
249
|
|
|
250
|
-
|
|
250
|
+
SSG and ISR cover pages that change rarely. Three more tools
|
|
251
251
|
cover the pages that do not:
|
|
252
252
|
|
|
253
253
|
-
|
|
254
254
|
**
|
|
255
|
-
|
|
255
|
+
Partial prerendering
|
|
256
256
|
**
|
|
257
|
-
(
|
|
257
|
+
(all five adapters). The part of a page that is the same for every visitor is
|
|
258
258
|
built once, cached and sent at once; each per-visitor hole streams into it as its own loader
|
|
259
259
|
settles. The build refuses a shell whose code reaches a module that reads the visitor, and
|
|
260
260
|
`checkShellCanaries` looks for visitor data in a served shell. A shared hole, such
|
|
@@ -263,7 +263,7 @@ as partial prerendering under Cache Components.
|
|
|
263
263
|
|
|
264
264
|
-
|
|
265
265
|
**
|
|
266
|
-
|
|
266
|
+
Live refresh
|
|
267
267
|
**
|
|
268
268
|
. A loader names the keys its data read with `live(...keys)`; a
|
|
269
269
|
`publish`, or an action's `revalidate(paths, data, { keys })`,
|
|
@@ -280,7 +280,7 @@ the write. A page store shared between processes is signed.
|
|
|
280
280
|
|
|
281
281
|
-
|
|
282
282
|
**
|
|
283
|
-
|
|
283
|
+
Keep-alive
|
|
284
284
|
**
|
|
285
285
|
(all five adapters). `export const keepAlive = true` keeps a page mounted after
|
|
286
286
|
the visitor leaves it; back and forward bring it back with its state, scroll and focus.
|
|
@@ -294,14 +294,14 @@ to full-stack later without a rewrite.
|
|
|
294
294
|
**Throughput - the realistic case.** Router micro-benchmarks flatter Hono (a single compiled
|
|
295
295
|
regex), but a real request also pays for middleware and validation,
|
|
296
296
|
context, and serialization. In the current matrix Nifra runs **level with Elysia on Bun** -
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
**level with Fastify on Node** (
|
|
300
|
-
|
|
301
|
-
and Express behind. On **Deno** it runs at
|
|
302
|
-
GET and
|
|
303
|
-
bearer auth + cookies + validated query/body + a ~2.4 KB JSON response, measured
|
|
304
|
-
`oha`) Nifra runs at **
|
|
297
|
+
99% of Elysia on `GET /users/:id` and
|
|
298
|
+
101% on the validated `POST` - and
|
|
299
|
+
**level with Fastify on Node** (106% of Fastify on GET,
|
|
300
|
+
105% on the validated `POST`), with Elysia, Hono,
|
|
301
|
+
and Express behind. On **Deno** it runs at 105% of Elysia on
|
|
302
|
+
GET and 128% on the validated `POST`. In the realistic shape (security headers + CORS +
|
|
303
|
+
bearer auth + cookies + validated query/body + a ~2.4 KB JSON response, measured on
|
|
304
|
+
**Bun** with `oha`) Nifra runs at **111% of Elysia on GET and 114% on POST**. Treat benchmark
|
|
305
305
|
rows as same-run evidence, not a permanent law of nature.
|
|
306
306
|
|
|
307
307
|
-
|
|
@@ -427,7 +427,7 @@ chain (so `n` optionals → `2ⁿ` patterns).
|
|
|
427
427
|
-
|
|
428
428
|
`x.backend.ts` beside a page or layout is its server half: `loader`,
|
|
429
429
|
`action`, their output schemas, and the other server-only exports. It never
|
|
430
|
-
reaches the browser - see
|
|
430
|
+
reaches the browser - see Project structure.
|
|
431
431
|
|
|
432
432
|
-
|
|
433
433
|
`_404.tsx` renders unmatched paths, and whatever a loader answers with
|
|
@@ -472,8 +472,13 @@ the root one shows instead. A navigation that settles sooner (a prefetched link,
|
|
|
472
472
|
loader) goes straight to the new page, as does one with no eligible
|
|
473
473
|
`_loading`; a change of search on the same path and a form submit keep the
|
|
474
474
|
page and report `pending`. The component receives `pending` and no
|
|
475
|
-
`data`.
|
|
476
|
-
|
|
475
|
+
`data`. React's `NavLink` widens this to a per-link signal: its
|
|
476
|
+
`className`, `style` and `children` take functions over
|
|
477
|
+
`{ isActive, isPending }`, where `isPending` is
|
|
478
|
+
`true` while a navigation into that link's own target is in flight; the
|
|
479
|
+
other adapters expose the route-level `pending` described here only. It is a
|
|
480
|
+
browser-only convention on every adapter - the first load of a URL is a server render,
|
|
481
|
+
where `defer()` streams the slow part.
|
|
477
482
|
|
|
478
483
|
-
|
|
479
484
|
`_error.tsx` is the segment's **error boundary**. On the server - if a route's
|
|
@@ -519,7 +524,7 @@ routes/
|
|
|
519
524
|
Each page default-exports a component; an optional `meta` export drives
|
|
520
525
|
`<head>` (applied on SSR and on client navigation). Its data comes from a
|
|
521
526
|
`loader` in its `.backend.ts` half - see
|
|
522
|
-
|
|
527
|
+
Loaders & actions.
|
|
523
528
|
|
|
524
529
|
A layout's `meta` receives its own loader's data as `data`, the value its
|
|
525
530
|
component renders, or `null` when the layout has no loader. The page's data is
|
|
@@ -560,12 +565,12 @@ before a nested `_404` there. Middleware higher in the tree runs first.
|
|
|
560
565
|
|
|
561
566
|
```ts
|
|
562
567
|
// routes/account/_layout.backend.ts - runs before every page under /account
|
|
563
|
-
import { type RouteMiddleware, redirect } from "@nifrajs/web"
|
|
568
|
+
import { type RouteMiddleware, rawHref, redirect } from "@nifrajs/web"
|
|
564
569
|
|
|
565
570
|
export const middleware: RouteMiddleware = ({ request, set }) => {
|
|
566
571
|
set.headers["cache-control"] = "private, no-store"
|
|
567
572
|
const signedIn = request.headers.get("cookie")?.includes("session=") ?? false
|
|
568
|
-
return signedIn ? undefined : redirect("/login")
|
|
573
|
+
return signedIn ? undefined : redirect(rawHref("/login"))
|
|
569
574
|
}
|
|
570
575
|
```
|
|
571
576
|
|
|
@@ -692,15 +697,93 @@ React/Preact, a `Ref` on Vue, an accessor on Solid/Svelte. For imperative reads
|
|
|
692
697
|
writes of the raw query, `useSearchParams()` mirrors react-router's
|
|
693
698
|
`[params, setParams]` tuple.
|
|
694
699
|
|
|
695
|
-
To WRITE search, `
|
|
696
|
-
`navigate({ to: "/reports", search: { page: 2 } })
|
|
697
|
-
|
|
698
|
-
`
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
`
|
|
703
|
-
|
|
700
|
+
To WRITE search, build the link with `href` and hand it to `useNavigate`:
|
|
701
|
+
`navigate(href({ to: "/reports", search: { page: 2 } }))`. `href` and
|
|
702
|
+
`rawHref` are exported by every adapter's router entry (
|
|
703
|
+
`@nifrajs/web-<framework>/router`). `nifra dev`,
|
|
704
|
+
`nifra build`, `nifra check` and `nifra types` write
|
|
705
|
+
`.nifra/types/routes.d.ts`, which maps every route pattern to its params and its
|
|
706
|
+
schema output, and each route's generated `./+types` module loads it. So
|
|
707
|
+
`to` is one of those patterns, `params` holds that route's params, and
|
|
708
|
+
`search` is typed against its schema: a misspelt route, a missing param and a wrong
|
|
709
|
+
search shape are compile errors, and a changed `searchSchema` shows up as a
|
|
710
|
+
`tsc` error at the stale call. A route without a `searchSchema` takes any
|
|
711
|
+
`search`.
|
|
712
|
+
|
|
713
|
+
Each param is encoded as one path segment, so a value such as `a/b` or
|
|
714
|
+
`//evil.com` stays inside the segment and never changes where the link goes. A
|
|
715
|
+
param that is missing, empty, `.`, `..` or an unpaired surrogate throws a
|
|
716
|
+
`TypeError` naming it. `navigate` takes only an `href` result,
|
|
717
|
+
or a history delta such as `navigate(-1)`; a string or a template literal is a
|
|
718
|
+
compile error. So do React's `Link`, `NavLink` and `Navigate`
|
|
719
|
+
(`<Link to={href({ to: "/pricing" })}>`) and the server's
|
|
720
|
+
`redirect()`; when `to` is not a same-origin path,
|
|
721
|
+
`Link` and `NavLink` render the anchor without an `href`,
|
|
722
|
+
and `Navigate` and `setSearchParams` do not navigate; each logs a
|
|
723
|
+
`console.error` that names the call and never the value. `redirect`
|
|
724
|
+
takes an off-origin location with `{ external: true }`, which still refuses
|
|
725
|
+
one holding a line break. For a same-origin path built elsewhere - a CMS link,
|
|
726
|
+
`/llms.txt` - `rawHref("/llms.txt")` checks it (one leading
|
|
727
|
+
`/`, no backslash or control character) and returns the same type. A link to
|
|
728
|
+
another site is a plain `<a href>`. A path that comes from outside is
|
|
729
|
+
checked where it is read: `rawHref` throws a `TypeError` for one that is
|
|
730
|
+
not same-origin, so catch it at that call when a field cannot be trusted. A value that gets
|
|
731
|
+
past it as a forged `Href` costs only its own link.
|
|
732
|
+
|
|
733
|
+
### Moving existing links to href()
|
|
734
|
+
|
|
735
|
+
A link written as a string is not checked: `navigate("/pricng")` and
|
|
736
|
+
`<a href="/pricng">` compile and then 404. Moving one is mechanical.
|
|
737
|
+
|
|
738
|
+
```tsx
|
|
739
|
+
// doc-check: skip - routes of your own app; one line per call, before and after.
|
|
740
|
+
import { href, rawHref } from "@nifrajs/web-react/router"
|
|
741
|
+
|
|
742
|
+
navigate(`/users/${id}?tab=posts`)
|
|
743
|
+
navigate(href({ to: "/users/:id", params: { id }, search: { tab: "posts" } }))
|
|
744
|
+
|
|
745
|
+
<a href="/pricing">Pricing</a>
|
|
746
|
+
<a href={href({ to: "/pricing" })}>Pricing</a>
|
|
747
|
+
|
|
748
|
+
<Link to="/docs#install">Install</Link>
|
|
749
|
+
<Link to={href({ to: "/docs", hash: "install" })}>Install</Link>
|
|
750
|
+
|
|
751
|
+
throw redirect("/login")
|
|
752
|
+
throw redirect(href({ to: "/login" }))
|
|
753
|
+
|
|
754
|
+
navigate(cmsLink) // a same-origin path built elsewhere
|
|
755
|
+
navigate(rawHref(cmsLink))
|
|
756
|
+
```
|
|
757
|
+
|
|
758
|
+
A leftover `navigate("/x")`, `<Link to="/x">` or
|
|
759
|
+
`redirect("/x")` is a compile error at the call, so `tsc` lists what is
|
|
760
|
+
left. A plain `<a href="/x">` is not an error, so search for
|
|
761
|
+
`href="/` and `href={`/` too; a link that opens another site stays
|
|
762
|
+
an `<a href>`. This site, the examples and the starters are held to it by a
|
|
763
|
+
test that fails on a literal internal anchor.
|
|
764
|
+
|
|
765
|
+
`nifra check` finds the plain anchors in your app too, and reads the route table to
|
|
766
|
+
tell two cases apart. `NF-C057` (a warning) is a path that no page, no backend route
|
|
767
|
+
and no file in `public/` serves: the link is a 404, and the message names the
|
|
768
|
+
nearest page when it is a typo away. `NF-C058` (info) is a path that is a page
|
|
769
|
+
today; the message gives the `href()` call that replaces it. A template literal such
|
|
770
|
+
as ``/users/${id}`` is judged by its shape and never reported as dead, since the
|
|
771
|
+
route it builds may live outside the file routes. Links in `.tsx`, `.vue`
|
|
772
|
+
and `.svelte` files are read. Raise, lower or silence either code with
|
|
773
|
+
`rules` in `nifra.config`, or keep one link as written with
|
|
774
|
+
`rawHref()` or `// nifra-expect NF-C058: <reason>` above the
|
|
775
|
+
attribute (`<!-- nifra-expect NF-C058: <reason> -->` above the anchor in a
|
|
776
|
+
`.vue` or `.svelte` template). A backend mounted under
|
|
777
|
+
`apiPrefix` counts as serving its paths, read from `backend/framework.ts`
|
|
778
|
+
or `nifra.config.ts`; when either holds a value `check` cannot read, no
|
|
779
|
+
link is reported dead. `.jsx` files and an `href` built by a function are
|
|
780
|
+
not read.
|
|
781
|
+
|
|
782
|
+
The table is a generated file, `.nifra/types/routes.d.ts`. A program in which no route
|
|
783
|
+
imports a `./+types/...` module does not load it, and `to` then accepts no
|
|
784
|
+
route at all, and `nifra check` warns. List `.nifra/types/routes.d.ts` under
|
|
785
|
+
the tsconfig `files`: the `**` globs skip a dot directory, and a
|
|
786
|
+
`files` entry is not filtered by `exclude`.
|
|
704
787
|
|
|
705
788
|
### Prefetching
|
|
706
789
|
|
|
@@ -730,7 +813,7 @@ around it (the nearest one wins), says when:
|
|
|
730
813
|
</nav>
|
|
731
814
|
|
|
732
815
|
// React's <Link> takes it as a prop.
|
|
733
|
-
<Link to="/pricing" prefetch="render">Pricing</Link>
|
|
816
|
+
<Link to={href({ to: "/pricing" })} prefetch="render">Pricing</Link>
|
|
734
817
|
```
|
|
735
818
|
|
|
736
819
|
Warmed data is used by a click within 30 seconds; after that the click loads the route
|
|
@@ -840,9 +923,10 @@ type it with that route's `LoaderData`. `routes/photos/[id].tsx`
|
|
|
840
923
|
stays an ordinary page.
|
|
841
924
|
|
|
842
925
|
-
|
|
843
|
-
Back closes the modal and forward reopens it.
|
|
844
|
-
|
|
845
|
-
|
|
926
|
+
Back closes the modal and forward reopens it. Closing shows the page underneath as it was,
|
|
927
|
+
with its loader data and boundaries, without fetching it again; a page loaded for a
|
|
928
|
+
previous visitor loads again. A link inside the modal to another matching URL replaces its
|
|
929
|
+
content, and back steps through each one. Navigating anywhere else closes it.
|
|
846
930
|
|
|
847
931
|
-
|
|
848
932
|
A reload, a shared link, or a navigation from a page outside the declaring layout or page
|
|
@@ -897,6 +981,82 @@ The component renders the boundary itself: it reads `boundaries.<name>`
|
|
|
897
981
|
from its props and calls the boundary's `render` with the data. Every
|
|
898
982
|
adapter passes `boundaries` to the layouts and the page.
|
|
899
983
|
|
|
984
|
+
### Independently navigable route slots
|
|
985
|
+
|
|
986
|
+
An intercepted route is useful for one modal over its owning page. A dashboard with several
|
|
987
|
+
panels that open, change route, and close independently uses route slots. The page declares
|
|
988
|
+
named slots and an allowlist of route patterns for each. A slot renders that target's full
|
|
989
|
+
layout and page chain in its own component tree; each slot has separate loading and error UI.
|
|
990
|
+
|
|
991
|
+
```tsx
|
|
992
|
+
// routes/dashboard.tsx - name the only route identities this panel may display
|
|
993
|
+
import { href } from "@nifrajs/web"
|
|
994
|
+
import { RouteSlot, useRouteSlot } from "@nifrajs/web-react/router"
|
|
995
|
+
|
|
996
|
+
export const routeSlots = {
|
|
997
|
+
inspector: ["/users/:id"],
|
|
998
|
+
activity: ["/activity"],
|
|
999
|
+
} as const
|
|
1000
|
+
|
|
1001
|
+
export default function Dashboard() {
|
|
1002
|
+
const inspector = useRouteSlot("inspector")
|
|
1003
|
+
return (
|
|
1004
|
+
<>
|
|
1005
|
+
<button type="button" onClick={() => inspector.open(href({ to: "/users/:id", params: { id: "7" } }))}>
|
|
1006
|
+
Inspect user 7
|
|
1007
|
+
</button>
|
|
1008
|
+
<RouteSlot name="inspector" fallback={<p>Select a user.</p>} />
|
|
1009
|
+
<RouteSlot name="activity" fallback={<p>Activity is closed.</p>} />
|
|
1010
|
+
</>
|
|
1011
|
+
)
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
// A shareable link can open more than one panel at once.
|
|
1015
|
+
const dashboard = href({
|
|
1016
|
+
to: "/dashboard",
|
|
1017
|
+
slots: {
|
|
1018
|
+
inspector: href({ to: "/users/:id", params: { id: "7" } }),
|
|
1019
|
+
activity: href({ to: "/activity" }),
|
|
1020
|
+
},
|
|
1021
|
+
})
|
|
1022
|
+
```
|
|
1023
|
+
|
|
1024
|
+
-
|
|
1025
|
+
Generated route types constrain the slot name and target route passed to `href`.
|
|
1026
|
+
At runtime, the client checks slot-only navigation against the page's registration and
|
|
1027
|
+
route identity, and the server applies the same checks to direct requests. Malformed,
|
|
1028
|
+
duplicate, unknown, or oversized slot state is rejected before rendering; the server
|
|
1029
|
+
returns `400` for an invalid direct URL. The reserved flat query keys use the
|
|
1030
|
+
form `slot.<name>=<target>`, allow at most four targets, 1,024
|
|
1031
|
+
encoded characters per target, and 4,096 encoded characters total. They are removed before
|
|
1032
|
+
application search parsing, while unrelated query text stays intact.
|
|
1033
|
+
|
|
1034
|
+
-
|
|
1035
|
+
The server sends only the page shell. After hydration, each target loads through the normal
|
|
1036
|
+
same-origin route-data request, so its middleware, gates, and loader run with the current
|
|
1037
|
+
request's authorization. Target data is never embedded in the cached shell. Slot URLs
|
|
1038
|
+
are inputs, never authorization grants; keep sensitive values out because URLs can appear
|
|
1039
|
+
in `Referer` headers, logs, and analytics. Identity changes clear old data before
|
|
1040
|
+
reauthorization. Returning focus revalidates at most once per 30 seconds while keeping
|
|
1041
|
+
ready content visible, and navigation cancels stale work.
|
|
1042
|
+
|
|
1043
|
+
-
|
|
1044
|
+
Opening, changing, and closing a slot create history entries; Browser Back and Forward
|
|
1045
|
+
restore the previous slot URLs. Updating one slot retains sibling slots and the page's
|
|
1046
|
+
own loader data; changing slot state alone does not rerun that page loader. Up to four slot
|
|
1047
|
+
targets may be open at once, with bounded concurrent loading.
|
|
1048
|
+
|
|
1049
|
+
-
|
|
1050
|
+
Slot content is client-rendered in this first slice: server HTML contains the fallback,
|
|
1051
|
+
then hydration performs an authorized route-data fetch. This works well for overlays and
|
|
1052
|
+
modals; always-visible panels incur that post-hydration request.
|
|
1053
|
+
|
|
1054
|
+
-
|
|
1055
|
+
React, Preact, Solid, and Vue export `RouteSlot` and `useRouteSlot`
|
|
1056
|
+
from their `/router` entry. Svelte exports `useRouteSlot` from
|
|
1057
|
+
`@nifrajs/web-svelte/router` and the `RouteSlot` component from
|
|
1058
|
+
`@nifrajs/web-svelte/route-slot`.
|
|
1059
|
+
|
|
900
1060
|
### Guarding navigation
|
|
901
1061
|
|
|
902
1062
|
A page with unsaved work shouldn't lose it to a stray click or the back button.
|
|
@@ -957,7 +1117,7 @@ arktype, …); outputs are inferred end-to-end.
|
|
|
957
1117
|
|
|
958
1118
|
Everything on this page is just `@nifrajs/core` - no frontend, no build step. Use Nifra
|
|
959
1119
|
as a standalone backend the way you'd use Hono or Elysia, deploy it to any runtime, and reach
|
|
960
|
-
for
|
|
1120
|
+
for the frontend adapters only if and when you go full-stack.
|
|
961
1121
|
|
|
962
1122
|
### An inline server
|
|
963
1123
|
|
|
@@ -1592,9 +1752,9 @@ client sends nothing rather than reach a route the call does not name.
|
|
|
1592
1752
|
`.ws()` throws.
|
|
1593
1753
|
|
|
1594
1754
|
The same client runs in the browser and on the server. During SSR, a route's
|
|
1595
|
-
|
|
1596
|
-
`ctx.api`. Next:
|
|
1597
|
-
|
|
1755
|
+
loader calls it **in-process** (no network hop) via
|
|
1756
|
+
`ctx.api`. Next: file routing,
|
|
1757
|
+
loaders & actions, and plugins.
|
|
1598
1758
|
|
|
1599
1759
|
## Nifra - Loaders & actions
|
|
1600
1760
|
|
|
@@ -1615,9 +1775,9 @@ leaves the server. Declare a timestamp as `t.date()` and the page gets a
|
|
|
1615
1775
|
field that is any JSON value, passed through whole - a tool-call payload or a settings blob
|
|
1616
1776
|
the page does not pick apart. A loader without a schema is flagged by
|
|
1617
1777
|
`nifra check`. See
|
|
1618
|
-
|
|
1778
|
+
Project structure for the route pair. A loader that names the
|
|
1619
1779
|
data it read with `live(...keys)` reloads on its own when that data changes - see
|
|
1620
|
-
|
|
1780
|
+
Live refresh.
|
|
1621
1781
|
|
|
1622
1782
|
```ts
|
|
1623
1783
|
// routes/users/[id].backend.ts - a loader runs on the server: in-process during SSR (no network
|
|
@@ -1689,7 +1849,7 @@ loader **revalidates** (no full reload); with JS disabled the native form POST r
|
|
|
1689
1849
|
`actionData`, bounded by `actionOutput`.
|
|
1690
1850
|
|
|
1691
1851
|
A reload of the page on screen (an action's revalidation, `invalidate()`, a
|
|
1692
|
-
|
|
1852
|
+
live refresh, a fetcher loading its path again) keeps every part of `data` and the
|
|
1693
1853
|
layouts' data that it did not change as the same object, with one bound: an array none of
|
|
1694
1854
|
whose first 32 elements is unchanged is replaced whole, so a reload that changed every row
|
|
1695
1855
|
stops comparing early. A row kept this way keeps its DOM and component state: a Solid
|
|
@@ -1752,7 +1912,7 @@ in middleware. In development, nifra warns the first time a layout loader withou
|
|
|
1752
1912
|
`gate` refuses a request with a redirect, a `Response`, or a 401 or 403,
|
|
1753
1913
|
and `nifra check` reports one whose loader refuses in its own body (NF-C042). A
|
|
1754
1914
|
`_layout.backend.ts` that exports `middleware` guards a directory, with
|
|
1755
|
-
or without a layout component - see
|
|
1915
|
+
or without a layout component - see Route middleware.
|
|
1756
1916
|
|
|
1757
1917
|
A layout's `shouldRevalidate` overrides that default. It runs on the server and
|
|
1758
1918
|
receives `defaultShouldRevalidate` with the URL and params being left and the ones
|
|
@@ -1815,8 +1975,8 @@ export async function loader() {
|
|
|
1815
1975
|
```
|
|
1816
1976
|
|
|
1817
1977
|
For optimistic UI, concurrent fetchers, and a keyed query cache, the same primitives compose
|
|
1818
|
-
on all five adapters: see
|
|
1819
|
-
|
|
1978
|
+
on all five adapters: see fetchers and
|
|
1979
|
+
the query cache.
|
|
1820
1980
|
|
|
1821
1981
|
## Nifra - Server functions
|
|
1822
1982
|
|
|
@@ -1896,9 +2056,10 @@ The namespace becomes a URL segment, so it is constrained to lowercase dot/dash
|
|
|
1896
2056
|
branded export mounts at `/_nifra/fn/<namespace>/<exportName>`; anything
|
|
1897
2057
|
in the module that is not a server function is ignored rather than mounted.
|
|
1898
2058
|
|
|
1899
|
-
One thing worth knowing: the namespace you pass here and the `*.fn.ts` filename
|
|
1900
|
-
|
|
1901
|
-
|
|
2059
|
+
One thing worth knowing: the namespace you pass here and the `*.fn.ts` filename must
|
|
2060
|
+
agree, or the call 404s. The compiler does not compare them, but `nifra check`
|
|
2061
|
+
reports a mismatch as NF-C056 when the module is imported with
|
|
2062
|
+
`import * as todos from "./todos.fn"` and mounted in the same file. The build fails on a
|
|
1902
2063
|
filename that is not a valid namespace (`todoItems.fn.ts`; use
|
|
1903
2064
|
`todo-items.fn.ts`). Two files with one basename (`admin/todos.fn.ts`
|
|
1904
2065
|
and `user/todos.fn.ts`) share the namespace: both mount, and an export name they
|
|
@@ -1996,8 +2157,8 @@ nifra assure
|
|
|
1996
2157
|
✖ POST /_nifra/fn/todos/addTodo (authenticated-write) is missing nifra.authenticated
|
|
1997
2158
|
```
|
|
1998
2159
|
|
|
1999
|
-
See
|
|
2000
|
-
against, and
|
|
2160
|
+
See effect provenance for what the declaration is checked
|
|
2161
|
+
against, and the verification ladder for where this sits.
|
|
2001
2162
|
|
|
2002
2163
|
### Cost
|
|
2003
2164
|
|
|
@@ -2068,7 +2229,7 @@ const anyPending = useFetchers().some((f) => f.snapshot().pending)
|
|
|
2068
2229
|
```
|
|
2069
2230
|
|
|
2070
2231
|
A fetcher holds nothing for the next visitor: `identityChanged()` returns every
|
|
2071
|
-
fetcher to idle, and a load still in flight loads once more for the new visitor. In an app with a
|
|
2232
|
+
fetcher to idle, and a load still in flight loads once more for the new visitor. In an app with a keepAlive route, so
|
|
2072
2233
|
does the identity epoch cookie a sign-in or sign-out response rotates, on the next
|
|
2073
2234
|
`useFetcher` read.
|
|
2074
2235
|
|
|
@@ -2132,7 +2293,7 @@ export default function Product({ data }: Route.ComponentProps) {
|
|
|
2132
2293
|
This is request-time progressive SSR: the whole page, shell included, renders for each
|
|
2133
2294
|
request, and deferred values remain request-scoped. To serve the part that is the same for
|
|
2134
2295
|
every visitor from a cache and stream only the per-visitor parts, use
|
|
2135
|
-
|
|
2296
|
+
partial prerendering.
|
|
2136
2297
|
|
|
2137
2298
|
### SSG - prerender at build
|
|
2138
2299
|
|
|
@@ -2342,7 +2503,7 @@ and is reported once to `onInvalidationError`.
|
|
|
2342
2503
|
A per-request CSP nonce makes a page uncacheable. For a strict policy under ISR, give
|
|
2343
2504
|
`createWebApp` a `csp` from `createCspPolicy` instead of a
|
|
2344
2505
|
`nonce`: constant scripts are allowed by hash, so only a page that needs a nonce
|
|
2345
|
-
carries one - see
|
|
2506
|
+
carries one - see A strict CSP that still caches.
|
|
2346
2507
|
|
|
2347
2508
|
A page that must not be cached as a whole, because it is personalized or carries a nonce, can
|
|
2348
2509
|
still cache the data its loader reads. Wrap the expensive call in `cache.wrap` from
|
|
@@ -2445,14 +2606,14 @@ cache. Pass the same `draftSecret` to `createWebApp` and
|
|
|
2445
2606
|
`withISR`; a forged or tampered cookie fails the constant-time signature check.
|
|
2446
2607
|
|
|
2447
2608
|
```ts
|
|
2448
|
-
// doc-check: skip - fragment spanning three files: your `app`, `env`,
|
|
2609
|
+
// doc-check: skip - fragment spanning three files: your `app`, `env`, and route `slug`.
|
|
2449
2610
|
// 1. Mount the preview entry point your CMS links to. It checks the token in CONSTANT TIME,
|
|
2450
2611
|
// sets the signed HttpOnly cookie, and refuses an off-site ?to= (an open redirect otherwise).
|
|
2451
|
-
import { previewEndpoint, disableDraft } from "@nifrajs/web"
|
|
2612
|
+
import { previewEndpoint, disableDraft, redirect, rawHref } from "@nifrajs/web"
|
|
2452
2613
|
|
|
2453
2614
|
const preview = previewEndpoint({ secret: env.PREVIEW_TOKEN, draftSecret: env.DRAFT_SECRET })
|
|
2454
2615
|
app.get("/api/preview", (c) => preview(c.req)) // ?token=…&to=/posts/hello
|
|
2455
|
-
app.get("/api/preview/exit", (c) => (disableDraft(c), redirect("/")))
|
|
2616
|
+
app.get("/api/preview/exit", (c) => (disableDraft(c), redirect(rawHref("/"))))
|
|
2456
2617
|
// Gating it yourself instead? Use enableDraft(c, env.DRAFT_SECRET) AFTER your own check - and
|
|
2457
2618
|
// compare the token in constant time, since === leaks it one character at a time.
|
|
2458
2619
|
|
|
@@ -2534,9 +2695,8 @@ a metric instead of its final value - aggregate those with `delta` or
|
|
|
2534
2695
|
Content that's the same for everyone and changes rarely → **SSG**. Content that changes
|
|
2535
2696
|
occasionally and can tolerate seconds-to-minutes of staleness → **ISR**. Per-request or
|
|
2536
2697
|
per-user content → plain **SSR** (the default). A page that is mostly shared with a few
|
|
2537
|
-
per-visitor parts →
|
|
2538
|
-
|
|
2539
|
-
is open, without a reload, adds [live refresh](/docs/live) to any of them.
|
|
2698
|
+
per-visitor parts → partial prerendering. You can mix them in one app, route by route. A page that must update while it
|
|
2699
|
+
is open, without a reload, adds live refresh to any of them.
|
|
2540
2700
|
|
|
2541
2701
|
## Nifra - Hydration & pre-hydration forms
|
|
2542
2702
|
|
|
@@ -3040,10 +3200,10 @@ export default function Page({ data }: Route.ComponentProps) {
|
|
|
3040
3200
|
The same `defer()` works in actions and across client-side soft navigations (an
|
|
3041
3201
|
NDJSON stream settles the deferred values), and it's framework-agnostic - React
|
|
3042
3202
|
`<Suspense>` and Solid's streaming both drive it from one core. See
|
|
3043
|
-
|
|
3203
|
+
Frameworks for which adapters stream the boundary in the
|
|
3044
3204
|
server HTML.
|
|
3045
3205
|
|
|
3046
|
-
|
|
3206
|
+
Partial prerendering streams the same
|
|
3047
3207
|
way from a cached shell: the part of the page every visitor shares goes out at once from the
|
|
3048
3208
|
cache, and each per-visitor hole streams in as its loader settles.
|
|
3049
3209
|
|
|
@@ -3135,7 +3295,7 @@ feed.close()
|
|
|
3135
3295
|
|
|
3136
3296
|
## Nifra - Query cache
|
|
3137
3297
|
|
|
3138
|
-
> Nifra's keyed query cache:
|
|
3298
|
+
> Nifra's cross-framework keyed query cache: reactive queries, mutations, infinite lists, and SSR hydration.
|
|
3139
3299
|
|
|
3140
3300
|
For client-side data that isn't a route loader - lists, widgets, anything refetchable -
|
|
3141
3301
|
Nifra ships a keyed query cache (TanStack-Query-style), agnostic across all five adapters.
|
|
@@ -3146,8 +3306,9 @@ Nifra ships a keyed query cache (TanStack-Query-style), agnostic across all five
|
|
|
3146
3306
|
`createQuery(key, fn)` (Solid), each from the adapter's `/query`
|
|
3147
3307
|
entry, subscribe a component to a cached, keyed query. Concurrent reads of the same key
|
|
3148
3308
|
**dedup** into one in-flight fetch; results are cached with a `staleTime` (the
|
|
3149
|
-
third argument's option), a background refetch, and bounded GC.
|
|
3150
|
-
|
|
3309
|
+
third argument's option), a background refetch, and bounded GC. The query cache also has
|
|
3310
|
+
mutation and infinite-query bindings across the adapters, using each framework's reactive
|
|
3311
|
+
model.
|
|
3151
3312
|
|
|
3152
3313
|
```ts
|
|
3153
3314
|
import { useQuery, useQueryClient } from "@nifrajs/web-react/query"
|
|
@@ -3169,13 +3330,90 @@ function CreateUser() {
|
|
|
3169
3330
|
}
|
|
3170
3331
|
```
|
|
3171
3332
|
|
|
3333
|
+
### Mutations and infinite queries
|
|
3334
|
+
|
|
3335
|
+
React and Preact expose `useMutation` and `useInfiniteQuery`. Vue
|
|
3336
|
+
exposes composables whose reactive state is read from refs. Svelte returns readable stores,
|
|
3337
|
+
and Solid exposes `createMutation` and `createInfiniteQuery` accessors.
|
|
3338
|
+
Each mutation has `mutate`, `mutateAsync`, `reset`, and
|
|
3339
|
+
`cancel`; each paged query exposes next/previous-page controls and page-availability
|
|
3340
|
+
state. Mutations remain client state bindings: the server action or endpoint still enforces
|
|
3341
|
+
authorization. Mutation functions receive a shared context with a `signal` as
|
|
3342
|
+
their second argument. `onMutate` receives that context second;
|
|
3343
|
+
`onSuccess` and `onError` receive it third; and `onSettled`
|
|
3344
|
+
receives it fourth. Pass `context.signal` to `fetch` and check it before
|
|
3345
|
+
side effects after an `await`. `cancel` aborts that signal, rejects the local promise, and
|
|
3346
|
+
discards local results; the request or server action only stops if it honors the signal, and accepted server work may
|
|
3347
|
+
finish.
|
|
3348
|
+
|
|
3349
|
+
```ts
|
|
3350
|
+
// React / Preact: hooks with a promise-returning mutation.
|
|
3351
|
+
// The mutation function receives a context with a shared AbortSignal as its second argument.
|
|
3352
|
+
const saveProfile = async (profile, { signal }) => {
|
|
3353
|
+
const response = await fetch("/api/profile", {
|
|
3354
|
+
method: "PUT",
|
|
3355
|
+
headers: { "content-type": "application/json" },
|
|
3356
|
+
body: JSON.stringify(profile),
|
|
3357
|
+
signal,
|
|
3358
|
+
})
|
|
3359
|
+
if (!response.ok) throw new Error("Profile save failed")
|
|
3360
|
+
return response
|
|
3361
|
+
}
|
|
3362
|
+
const save = useMutation(saveProfile)
|
|
3363
|
+
await save.mutateAsync(profile)
|
|
3364
|
+
|
|
3365
|
+
// Vue: state is a ref; read it with .value.
|
|
3366
|
+
const save = useMutation(saveProfile)
|
|
3367
|
+
await save.mutateAsync(profile)
|
|
3368
|
+
save.state.value.status
|
|
3369
|
+
|
|
3370
|
+
// Svelte: mutation and infinite-query bindings are readable stores.
|
|
3371
|
+
const save = useMutation(saveProfile)
|
|
3372
|
+
await save.mutateAsync(profile)
|
|
3373
|
+
// In markup, read $save.status.
|
|
3374
|
+
|
|
3375
|
+
// Solid: state is exposed through accessors.
|
|
3376
|
+
const save = createMutation(saveProfile)
|
|
3377
|
+
await save.mutateAsync(profile)
|
|
3378
|
+
save.state().status
|
|
3379
|
+
```
|
|
3380
|
+
|
|
3381
|
+
### SSR cache hydration
|
|
3382
|
+
|
|
3383
|
+
Query-cache hydration is separate from hydrating server-rendered markup. Create a fresh query
|
|
3384
|
+
client for each server request, prefetch the data, and pass its dehydrated state through Nifra
|
|
3385
|
+
route data. React and Preact use `QueryClientProvider` with
|
|
3386
|
+
`HydrationBoundary`; Solid accepts the state on `QueryClientProvider`;
|
|
3387
|
+
Vue and Svelte call `provideQueryClient(client, state)` in the app root before child
|
|
3388
|
+
queries initialize. The browser may keep one client for the app. Query state is cleared on
|
|
3389
|
+
identity changes, and in-flight mutation results are discarded at that boundary.
|
|
3390
|
+
|
|
3391
|
+
Every value included by `dehydrate` is serialized to the browser and is visible to
|
|
3392
|
+
that visitor, so `dehydrate` sends nothing by default. Pass
|
|
3393
|
+
`shouldDehydrateQuery` to name the regular and infinite queries that are safe to
|
|
3394
|
+
send; pass `() => true` only when every successful query in that client is
|
|
3395
|
+
meant for the browser. Never include tokens or server-only fields.
|
|
3396
|
+
|
|
3397
|
+
```ts
|
|
3398
|
+
// Create one QueryClient for this server request.
|
|
3399
|
+
const queryClient = createQueryClient({ now: () => Date.now() })
|
|
3400
|
+
await queryClient.prefetchQuery(["profile", user.id], loadProfile)
|
|
3401
|
+
const queryState = queryClient.dehydrate({
|
|
3402
|
+
// Nothing is sent unless this returns true: name what is safe for the visitor to read.
|
|
3403
|
+
shouldDehydrateQuery: ({ key }) => Array.isArray(key) && key[0] === "profile",
|
|
3404
|
+
})
|
|
3405
|
+
|
|
3406
|
+
// Return queryState through the route's normal loader-data serializer.
|
|
3407
|
+
// On the client, seed the app's client before query components mount.
|
|
3408
|
+
```
|
|
3409
|
+
|
|
3172
3410
|
### Invalidation
|
|
3173
3411
|
|
|
3174
3412
|
After a mutation, `useQueryClient().invalidateQueries(key)` marks matching entries
|
|
3175
3413
|
stale (by exact key or array **prefix**) and refetches the mounted ones - no manual cache
|
|
3176
3414
|
surgery.
|
|
3177
3415
|
|
|
3178
|
-
In an app with
|
|
3416
|
+
In an app with live refresh, a query can name the live keys its data
|
|
3179
3417
|
depends on: `useQuery(key, fn, { live: [`post:${id}`] })` refetches whenever
|
|
3180
3418
|
the server publishes one of them.
|
|
3181
3419
|
|
|
@@ -3185,7 +3423,7 @@ A cached query never answers for the next visitor. `identityChanged()` from
|
|
|
3185
3423
|
`@nifrajs/web/client` clears every query client in the page: mounted queries go
|
|
3186
3424
|
back to pending and refetch, the rest drop their data. A fetch still loading loads once more
|
|
3187
3425
|
for the new visitor before it settles. In an app with a
|
|
3188
|
-
|
|
3426
|
+
keepAlive route, the identity epoch cookie a sign-in
|
|
3189
3427
|
or sign-out response rotates does the same on the client's next read.
|
|
3190
3428
|
|
|
3191
3429
|
It's the same agnostic core under every adapter: the cache, dedup, and invalidation logic
|
|
@@ -3252,7 +3490,7 @@ Everything that lives in `@nifrajs/web` rather than the view layer works unchang
|
|
|
3252
3490
|
loaders, actions, ISR, SSG, head management, streaming. What you give up is hydration - these
|
|
3253
3491
|
are server-rendered documents, so set `export const hydrate = false` in the route's
|
|
3254
3492
|
`.backend.ts` half and reach for
|
|
3255
|
-
|
|
3493
|
+
islands where a page needs interactivity.
|
|
3256
3494
|
|
|
3257
3495
|
Worth it for the surfaces where HTML is the product: landing pages, listings, docs, comparison
|
|
3258
3496
|
tables. This documentation site renders that way.
|
|
@@ -3295,7 +3533,7 @@ export async function loader({ api }: Route.LoaderArgs) {
|
|
|
3295
3533
|
|
|
3296
3534
|
Component `<style scoped>` (Vue) and `<style>` (Svelte -
|
|
3297
3535
|
scoped by default) are compiled and scoped into the app stylesheet - no runtime, no FOUC - plus
|
|
3298
|
-
CSS Modules and global imports. See
|
|
3536
|
+
CSS Modules and global imports. See Dev & HMR → Styling.
|
|
3299
3537
|
`examples/routing-vue-sfc` is a full SSR + hydration + client-nav demo.
|
|
3300
3538
|
|
|
3301
3539
|
### Same features, every framework
|
|
@@ -3315,13 +3553,13 @@ progressive-enhancement forms (work with JS off).
|
|
|
3315
3553
|
- Optimistic UI, targeted revalidation, hover-prefetch, and scroll restoration.
|
|
3316
3554
|
|
|
3317
3555
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3556
|
+
Live refresh, keep-alive pages,
|
|
3557
|
+
server components, and
|
|
3558
|
+
partial prerendering.
|
|
3321
3559
|
|
|
3322
3560
|
-
|
|
3323
3561
|
True HMR in dev for all five (`@nifrajs/web/vite`) - see
|
|
3324
|
-
|
|
3562
|
+
Dev & HMR.
|
|
3325
3563
|
|
|
3326
3564
|
### One line changes
|
|
3327
3565
|
|
|
@@ -3385,7 +3623,7 @@ the client, with a warning in development.
|
|
|
3385
3623
|
Dev HMR works for all five adapters through `createViteDevServer` and the
|
|
3386
3624
|
framework's Vite plugin. React, Preact, and Vue preserve edited component state. Solid
|
|
3387
3625
|
and Svelte update live without a full page reload, and the edited component may remount. Full
|
|
3388
|
-
matrix in
|
|
3626
|
+
matrix in Dev & HMR.
|
|
3389
3627
|
|
|
3390
3628
|
### React Compiler
|
|
3391
3629
|
|
|
@@ -3811,7 +4049,7 @@ plugin, the principal is read from the **returned instance** - `auth.principal(r
|
|
|
3811
4049
|
(nullable) or `auth.requirePrincipal(req)` (throws `401`) - mirroring
|
|
3812
4050
|
`@nifrajs/auth` and `@nifrajs/better-auth`. It's verified once per request and
|
|
3813
4051
|
cached. For full session-based auth (OAuth, magic links, 2FA), see
|
|
3814
|
-
|
|
4052
|
+
Auth & sessions.
|
|
3815
4053
|
|
|
3816
4054
|
```ts
|
|
3817
4055
|
// doc-check: skip - fragment: `app`, `lookupUser`, and the `db` lookup are your application's.
|
|
@@ -3914,7 +4152,7 @@ app
|
|
|
3914
4152
|
`idempotency()` makes a retried unsafe request (same `Idempotency-Key` header)
|
|
3915
4153
|
replay the first response instead of re-running the side effect - no double-charge on a dropped
|
|
3916
4154
|
connection. It short-circuits before the handler; a concurrent retry gets a `409`. See
|
|
3917
|
-
|
|
4155
|
+
Security & hardening for the store contract, the production
|
|
3918
4156
|
guidance (shared store + DB constraint), and the `Set-Cookie` rule.
|
|
3919
4157
|
|
|
3920
4158
|
```ts
|
|
@@ -4165,7 +4403,7 @@ touches one key, so it runs on whichever node owns it.
|
|
|
4165
4403
|
The security set - `csrf` (signed double-submit + Origin/Referer), `jwt`,
|
|
4166
4404
|
`ipRestriction` (IPv4/IPv6 + CIDR, fails closed), and `bodyLimit`
|
|
4167
4405
|
(Content-Length cap before routing) - is documented with hardening guidance on
|
|
4168
|
-
|
|
4406
|
+
Security & hardening. All comparisons are constant-time and all
|
|
4169
4407
|
defaults fail closed.
|
|
4170
4408
|
|
|
4171
4409
|
### Error reporting
|
|
@@ -4192,7 +4430,7 @@ The pieces every production endpoint needs - a body-size cap for raw routes, rea
|
|
|
4192
4430
|
validation, constant-time webhook verification, and idempotent retries - ship as first-party
|
|
4193
4431
|
primitives. All are **edge-safe** (WebCrypto, no `node:crypto`) and run unchanged
|
|
4194
4432
|
on Bun, Node, Deno, and Workers. For how these defaults stack up against Hono, Fastify,
|
|
4195
|
-
Express, and Elysia, see
|
|
4433
|
+
Express, and Elysia, see security posture, compared.
|
|
4196
4434
|
|
|
4197
4435
|
### Responses that cannot leak more than they declare
|
|
4198
4436
|
|
|
@@ -4287,7 +4525,7 @@ export const app = server().use(
|
|
|
4287
4525
|
|
|
4288
4526
|
A `merge()`d server's routes are covered by a contract the parent installed
|
|
4289
4527
|
before the merge, as long as the route declares a response and its own server installed none.
|
|
4290
|
-
See
|
|
4528
|
+
See what a parent's use() covers.
|
|
4291
4529
|
|
|
4292
4530
|
The check itself is essentially free: with a compiled validator it measures in the
|
|
4293
4531
|
~100ns-per-response range, and a realistic middleware-carrying route benchmarks within noise
|
|
@@ -4298,26 +4536,26 @@ left that lane. If a route looks like production, the contract costs nothing: de
|
|
|
4298
4536
|
|
|
4299
4537
|
### Bounded request bodies
|
|
4300
4538
|
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
`c.
|
|
4539
|
+
Every HTTP route has a body limit, defaulting to `maxBodyBytes` (1,000,000 bytes).
|
|
4540
|
+
Nifra enforces it when the body is read, including direct `c.req`/`c.request` reads
|
|
4541
|
+
such as `json()`, `arrayBuffer()`, `text()`, and the raw stream. A route
|
|
4542
|
+
can explicitly opt out with `bodyLimit: "unlimited"`. Framework helpers, including
|
|
4543
|
+
`verifyWebhook` and `c.boundedBody(maxBytes?)`, read through their own bounded-reader
|
|
4544
|
+
paths. `verifyWebhook` defaults to 1 MiB, and an explicit `c.boundedBody(maxBytes)`
|
|
4545
|
+
value can exceed the route's `bodyLimit`. Set helper limits explicitly when the route-wide
|
|
4546
|
+
cap must apply to those reads. `c.boundedJson<T>(maxBytes?)` reads under that cap and parses JSON.
|
|
4306
4547
|
|
|
4307
4548
|
```ts
|
|
4308
4549
|
import { server } from "@nifrajs/core/server"
|
|
4309
4550
|
|
|
4310
4551
|
const app = server()
|
|
4311
4552
|
|
|
4312
|
-
//
|
|
4313
|
-
//
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
//
|
|
4318
|
-
// Responses (caught by the lifecycle like `throw redirect()`), so a handler can't
|
|
4319
|
-
// accidentally ignore the cap. The over-cap length is rejected BEFORE buffering;
|
|
4320
|
-
// a chunked / length-less body is aborted mid-stream once it crosses the cap.
|
|
4553
|
+
// Every route is bounded, including raw-body / file / BYO-validation routes that
|
|
4554
|
+
// read c.req directly. Raise the route cap when this endpoint needs more than the default:
|
|
4555
|
+
app.post("/import", { bodyLimit: 5 * 1024 * 1024 }, async (c) => {
|
|
4556
|
+
const bytes = await c.req.arrayBuffer() // the direct read is capped at 5 MiB
|
|
4557
|
+
// An over-cap Content-Length is rejected BEFORE buffering; chunked bodies are
|
|
4558
|
+
// aborted mid-stream. Both answer a flat 413 through the request lifecycle.
|
|
4321
4559
|
return { received: bytes.byteLength } // a returned object is serialized as JSON 200
|
|
4322
4560
|
})
|
|
4323
4561
|
|
|
@@ -4328,10 +4566,10 @@ app.post("/rpc", async (c) => {
|
|
|
4328
4566
|
})
|
|
4329
4567
|
```
|
|
4330
4568
|
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
smaller
|
|
4569
|
+
An over-cap read is rejected with a flat `413`; a malformed
|
|
4570
|
+
`Content-Length` gets a `400`. `c.boundedJson` also returns
|
|
4571
|
+
`400` for malformed or rejected JSON. Set a larger finite route
|
|
4572
|
+
`bodyLimit` for an upload, or a smaller `maxBytes` to tighten an individual read.
|
|
4335
4573
|
|
|
4336
4574
|
The cap is enforced on the bytes actually **delivered**, never on the number the caller wrote in
|
|
4337
4575
|
`Content-Length`. That distinction is the whole defense: an adapter that rebuilds a
|
|
@@ -4354,12 +4592,16 @@ through the streaming guard.
|
|
|
4354
4592
|
|
|
4355
4593
|
### Prototype-poisoning defense
|
|
4356
4594
|
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4595
|
+
The schema body reader and `c.boundedJson` screen parsed JSON for the prototype-pollution
|
|
4596
|
+
shape: an own `__proto__` key, or a `constructor` whose value carries a
|
|
4597
|
+
`prototype`. `JSON.parse`
|
|
4360
4598
|
creates these as ordinary data properties, and the damage lands later, when innocent code does
|
|
4361
4599
|
`{ ...body }`, `Object.assign(target, body)`, or a deep merge and
|
|
4362
|
-
walks that key onto a real prototype.
|
|
4600
|
+
walks that key onto a real prototype. This screen is on by default for those guarded readers.
|
|
4601
|
+
|
|
4602
|
+
Direct `c.req.json()` reads are still subject to the body-size cap, but do not apply the
|
|
4603
|
+
`protoPoisoning` policy. Treat their parsed object keys as untrusted before merging; use
|
|
4604
|
+
`c.boundedJson` when you want Nifra to apply that policy.
|
|
4363
4605
|
|
|
4364
4606
|
```ts
|
|
4365
4607
|
import { server } from "@nifrajs/core/server"
|
|
@@ -4609,38 +4851,43 @@ size cap and sniffs the **real** type from magic bytes - never the client-set
|
|
|
4609
4851
|
// doc-check: skip - fragment: `app`, `save`, `id`, and `env` are your application's.
|
|
4610
4852
|
import { validateUpload, signDownloadUrl } from "@nifrajs/uploads"
|
|
4611
4853
|
|
|
4612
|
-
app.post(
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4854
|
+
app.post(
|
|
4855
|
+
"/avatar",
|
|
4856
|
+
{ bodyLimit: 2_100_000 }, // request cap includes multipart framing around a 2 MB file
|
|
4857
|
+
async (c) => {
|
|
4858
|
+
const form = await c.req.formData()
|
|
4859
|
+
const file = form.get("file")
|
|
4860
|
+
if (!(file instanceof Blob)) { c.set.status = 400; return { ok: false, error: "no_file" } }
|
|
4861
|
+
|
|
4862
|
+
// Size cap + REAL type by magic bytes - a .exe renamed .png (or a spoofed
|
|
4863
|
+
// Content-Type) is caught, because the bytes win. An oversized Blob is rejected
|
|
4864
|
+
// by its .size BEFORE it's buffered into memory.
|
|
4865
|
+
const result = await validateUpload(file, {
|
|
4866
|
+
maxBytes: 2_000_000,
|
|
4867
|
+
accept: ["image/png", "image/jpeg"], // exact, or "image/*"
|
|
4868
|
+
})
|
|
4869
|
+
if (!result.ok) { c.set.status = 400; return { ok: false, error: result.reason } }
|
|
4870
|
+
// reason: "too_large" | "empty" | "unrecognized" | "type_not_allowed"
|
|
4626
4871
|
|
|
4627
|
-
|
|
4872
|
+
await save(result.bytes, `${id}.${result.ext}`) // result.mime / .ext are trustworthy
|
|
4628
4873
|
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
}
|
|
4874
|
+
// Hand back a short-TTL, tamper-evident URL (HMAC over path + expiry):
|
|
4875
|
+
const url = await signDownloadUrl(`/files/${id}`, env.FILE_SECRET, { expiresInSeconds: 300 })
|
|
4876
|
+
return { ok: true, url } // a returned object is serialized as JSON 200
|
|
4877
|
+
},
|
|
4878
|
+
)
|
|
4633
4879
|
```
|
|
4634
4880
|
|
|
4635
|
-
|
|
4636
|
-
the
|
|
4881
|
+
Direct request reads already follow the route's body limit. Use `c.boundedBody` to
|
|
4882
|
+
set an explicit cap for the bytes you pass to `validateUpload`. The detection alone is
|
|
4883
|
+
`detectFileType(bytes)` from
|
|
4637
4884
|
`@nifrajs/core/file-type` (returns `{ mime, ext }` or `null`),
|
|
4638
4885
|
covering common image / A-V / archive types.
|
|
4639
4886
|
|
|
4640
4887
|
`signDownloadUrl` / `verifyDownloadUrl` mint short-TTL, tamper-evident
|
|
4641
4888
|
download links (HMAC-SHA256 over the path + expiry, constant-time verify). And
|
|
4642
4889
|
`stripImageMetadata` drops EXIF/GPS by re-encoding the image - through any
|
|
4643
|
-
|
|
4890
|
+
@nifrajs/image backend, with no dependency on it:
|
|
4644
4891
|
|
|
4645
4892
|
```ts
|
|
4646
4893
|
// doc-check: skip - fragment: continues the upload handler above (`result.bytes`).
|
|
@@ -4786,7 +5033,8 @@ const app = server()
|
|
|
4786
5033
|
// X-Forwarded-For is never believed.
|
|
4787
5034
|
.use(ipRestriction({ allow: ["10.0.0.0/8", "::1"] }))
|
|
4788
5035
|
// Reject oversized bodies at the EDGE by Content-Length, before routing - fails closed (411) on a
|
|
4789
|
-
// length-less body.
|
|
5036
|
+
// length-less body. This is the cheap pre-filter; the route's cap on direct and
|
|
5037
|
+
// framework reads is the read-time guard.
|
|
4790
5038
|
.use(bodyLimit({ maxBytes: 1_000_000 }))
|
|
4791
5039
|
```
|
|
4792
5040
|
|
|
@@ -4807,8 +5055,8 @@ trustworthy client IP can be derived, and never trusts `X-Forwarded-For` unless
|
|
|
4807
5055
|
|
|
4808
5056
|
-
|
|
4809
5057
|
`bodyLimit` - a cheap `Content-Length` pre-filter that rejects oversized
|
|
4810
|
-
bodies before routing (fails closed with `411` on a length-less body). The
|
|
4811
|
-
|
|
5058
|
+
bodies before routing (fails closed with `411` on a length-less body). The route's
|
|
5059
|
+
read-time body limit applies to direct reads, schema validation, and bounded readers.
|
|
4812
5060
|
|
|
4813
5061
|
### Security response headers - `securityHeaders`
|
|
4814
5062
|
|
|
@@ -4849,7 +5097,7 @@ nonce. For a strict `script-src` on web pages, give `createWebApp` a
|
|
|
4849
5097
|
`csp` from `createCspPolicy`: it allows the framework's constant
|
|
4850
5098
|
scripts by hash and adds a nonce only to a page that needs one, so every other page sends the
|
|
4851
5099
|
same header and stays cacheable under `withISR` or a CDN. See
|
|
4852
|
-
|
|
5100
|
+
A strict CSP that still caches.
|
|
4853
5101
|
|
|
4854
5102
|
### Route assurance - prove every route is guarded
|
|
4855
5103
|
|
|
@@ -5013,9 +5261,9 @@ rejected), SSR serialization that escapes every inline-script value,
|
|
|
5013
5261
|
`__Host-`/`__Secure-` cookie-prefix enforcement (a cookie whose
|
|
5014
5262
|
attributes violate its prefix contract fails at serialization rather than being silently
|
|
5015
5263
|
dropped by the browser), signed-cookie sessions + CSRF + route guards
|
|
5016
|
-
(
|
|
5017
|
-
limiter (
|
|
5018
|
-
(
|
|
5264
|
+
(@nifrajs/auth), bearer/apiKey auth + a shared-store rate
|
|
5265
|
+
limiter (@nifrajs/middleware), and a hardened image-resize endpoint
|
|
5266
|
+
(@nifrajs/image/server).
|
|
5019
5267
|
|
|
5020
5268
|
### Redacting logs
|
|
5021
5269
|
|
|
@@ -5038,6 +5286,91 @@ const app = server({
|
|
|
5038
5286
|
// Add your own: { valuePatterns: [...commonSecretPatterns, /\bord_[a-z0-9]+/g] }
|
|
5039
5287
|
```
|
|
5040
5288
|
|
|
5289
|
+
### Credentials that reach the browser - NF-C032
|
|
5290
|
+
|
|
5291
|
+
The zone rules keep `backend/` halves and server-only imports out of the browser
|
|
5292
|
+
bundle; the credential scan is the net under them - for a credential typed straight into
|
|
5293
|
+
browser code, one a dependency carries, and a server-only environment value that reached the
|
|
5294
|
+
output some other way (a `define`, a prerendered page, a copied
|
|
5295
|
+
`public/` file). `nifra check` (NF-C032, an error) scans each app's
|
|
5296
|
+
browser-zone modules and every file in `public/`; the build runs the same net on
|
|
5297
|
+
what it publishes - every emitted file with its inline source maps decoded, every
|
|
5298
|
+
`public/` copy, every prerendered page - and matches the values of the build
|
|
5299
|
+
environment's non-public variables there, raw and URL-, base64-, JSON- and
|
|
5300
|
+
HTML-encoded. A `PUBLIC_`-prefixed variable is public by declaration.
|
|
5301
|
+
|
|
5302
|
+
Five rules:
|
|
5303
|
+
|
|
5304
|
+
-
|
|
5305
|
+
**Known token formats** - AWS access keys, Stripe secret keys and webhook secrets,
|
|
5306
|
+
GitHub, Slack (tokens and webhook URLs), OpenAI, Anthropic, SendGrid, Twilio, Mailgun, npm,
|
|
5307
|
+
and a Supabase service-role JWT.
|
|
5308
|
+
|
|
5309
|
+
-
|
|
5310
|
+
**PEM private keys** - a block with a body present, not a parser's bare
|
|
5311
|
+
`-----BEGIN PRIVATE KEY-----` constant.
|
|
5312
|
+
|
|
5313
|
+
-
|
|
5314
|
+
**URLs with a password** - `postgres://user:password@host`, unless the
|
|
5315
|
+
password is a placeholder.
|
|
5316
|
+
|
|
5317
|
+
-
|
|
5318
|
+
**Assigned secrets** - a random literal given to a secret-like name, in first-party
|
|
5319
|
+
source only: `apiKey: "..."`, a quoted header name including its hyphens (
|
|
5320
|
+
`"x-api-key": "..."`), a header set by call (
|
|
5321
|
+
`headers.set("x-api-key", ...)`), a pair in
|
|
5322
|
+
`new Headers([...])`, and `Authorization` read into its
|
|
5323
|
+
`Bearer` token or `Basic` credentials.
|
|
5324
|
+
|
|
5325
|
+
-
|
|
5326
|
+
**Private env values** - the value of a build variable whose name says secret (
|
|
5327
|
+
`TOKEN`, `API_KEY`, `DATABASE_URL`, …) or that looks
|
|
5328
|
+
random, in any encoding above. A defined set of recognized ambient shell, OS and CI names
|
|
5329
|
+
is skipped unless the name itself looks secret-like. Other names are scanned when they
|
|
5330
|
+
look secret-like, contain a credential URL, or hold a random-looking value.
|
|
5331
|
+
|
|
5332
|
+
Deliberate skips: keys public by design (Stripe `pk_`, Google `AIza`,
|
|
5333
|
+
reCAPTCHA `6L`, `G-` and `UA-` ids), placeholders (
|
|
5334
|
+
`changeme`, `<your-key-here>`, a whole-value stand-in such as
|
|
5335
|
+
`your_signing_secret` or an interpolated shell value), low-entropy and word-shaped
|
|
5336
|
+
values, and labels inside a message catalog (`password: "Lykilorð"`). A
|
|
5337
|
+
finding never prints the value: the rule, the location, and a preview of the first few
|
|
5338
|
+
characters plus the length. When a match sits in a content-hashed output file, the build
|
|
5339
|
+
names the module it came from.
|
|
5340
|
+
|
|
5341
|
+
A reviewed false positive can be exempted in `nifra.config.ts`. A `file`
|
|
5342
|
+
exemption suppresses that rule throughout the named file, so the same credential in another
|
|
5343
|
+
file still fails. For `private-env-value`, an `env` exemption suppresses
|
|
5344
|
+
every finding from that variable anywhere in scanned output; use it only when publishing that
|
|
5345
|
+
value everywhere it appears is intended. Every exemption needs its rule and reason, or the
|
|
5346
|
+
build refuses:
|
|
5347
|
+
|
|
5348
|
+
```ts
|
|
5349
|
+
// nifra.config.ts
|
|
5350
|
+
// doc-check: skip - exemptions name your own findings; there is nothing to run
|
|
5351
|
+
export const secretExemptions = [
|
|
5352
|
+
{
|
|
5353
|
+
rule: "key-format",
|
|
5354
|
+
file: "routes/docs.tsx",
|
|
5355
|
+
reason: "the sample literally spells an AWS access key id",
|
|
5356
|
+
},
|
|
5357
|
+
// A file exemption covers this rule throughout the named file. An env exemption covers every
|
|
5358
|
+
// finding from that variable anywhere in scanned output; use it only when that is intended.
|
|
5359
|
+
{
|
|
5360
|
+
rule: "private-env-value",
|
|
5361
|
+
env: "SIGNING_SALT",
|
|
5362
|
+
reason: "this value is intentionally published wherever it appears; it shapes a public nonce",
|
|
5363
|
+
},
|
|
5364
|
+
]
|
|
5365
|
+
```
|
|
5366
|
+
|
|
5367
|
+
The net is a heuristic, not a guarantee. A credential spelled inside a longer string - a
|
|
5368
|
+
URL's query (`https://api.example.com/v1?key=...`) or a cookie header's
|
|
5369
|
+
value - is seen by the known-format rules alone, and a random value given to a name the scan
|
|
5370
|
+
does not judge secret-like is not the `assigned-secret` rule's target. Keep
|
|
5371
|
+
credentials in a route's backend half or under `backend/`, and rotate any
|
|
5372
|
+
that were ever committed.
|
|
5373
|
+
|
|
5041
5374
|
## Nifra - Effect provenance
|
|
5042
5375
|
|
|
5043
5376
|
> A route declares the effects it performs, and `nifra check` fails it for being able to reach further than it declared. How reach is computed, why that shapes your modules, and how the declaration turns into an enforced policy.
|
|
@@ -5359,8 +5692,8 @@ $ nifra levels
|
|
|
5359
5692
|
✓ L2 capability lockfile
|
|
5360
5693
|
```
|
|
5361
5694
|
|
|
5362
|
-
That is L2 on
|
|
5363
|
-
|
|
5695
|
+
That is L2 on the verification ladder. See also
|
|
5696
|
+
server functions, which are public POST endpoints and are
|
|
5364
5697
|
covered by exactly the same policy.
|
|
5365
5698
|
|
|
5366
5699
|
### Turning it down
|
|
@@ -5498,7 +5831,7 @@ as a session.
|
|
|
5498
5831
|
`identity` names the data keys that say who the visitor is: the user id, and any
|
|
5499
5832
|
key that changes what a page may show, such as an organization or a role. The cookie's tag,
|
|
5500
5833
|
in either mode, then changes only when one of them does, so
|
|
5501
|
-
|
|
5834
|
+
keep-alive keeps the pages it holds across a commit
|
|
5502
5835
|
that writes a cart or a preference. Unset, every key counts. A key left out that decides what
|
|
5503
5836
|
a page shows lets the next visitor of a browser see the pages kept for the previous one.
|
|
5504
5837
|
|
|
@@ -5534,12 +5867,12 @@ app.post("/api/login", async (c) => {
|
|
|
5534
5867
|
session.set("userId", String(username))
|
|
5535
5868
|
sessions.regenerate(session) // rotate the id on login (fixation defense)
|
|
5536
5869
|
await sessions.commit(c, session)
|
|
5537
|
-
return redirect("/")
|
|
5870
|
+
return redirect(rawHref("/")) // the Set-Cookie rides the redirect
|
|
5538
5871
|
})
|
|
5539
5872
|
|
|
5540
5873
|
app.post("/api/logout", async (c) => {
|
|
5541
5874
|
await sessions.destroy(c, await sessions.get(c))
|
|
5542
|
-
return redirect("/login")
|
|
5875
|
+
return redirect(rawHref("/login"))
|
|
5543
5876
|
})
|
|
5544
5877
|
```
|
|
5545
5878
|
|
|
@@ -5553,7 +5886,7 @@ path), and `requireSession` passes it, so guard a signed-in page with
|
|
|
5553
5886
|
`requireUser`. It is plain data, not
|
|
5554
5887
|
a `Response`: same bytes on the wire, on the lane an ordinary return takes. To guard
|
|
5555
5888
|
every page under a directory, run the same check in the `middleware` export of that
|
|
5556
|
-
directory's `_layout.backend.ts` - see
|
|
5889
|
+
directory's `_layout.backend.ts` - see Route middleware.
|
|
5557
5890
|
|
|
5558
5891
|
```ts
|
|
5559
5892
|
// routes/account.backend.ts - a protected route's loader reads the session and redirects when absent.
|
|
@@ -5684,7 +6017,7 @@ A page or a `frontend/` component that imported `backend/auth.ts` fails
|
|
|
5684
6017
|
the build with the import chain that reached it, so a secret cannot ride into the browser
|
|
5685
6018
|
bundle. A page that needs the user reads it from its loader data, which
|
|
5686
6019
|
`loaderOutput` narrows to the fields it declares - see
|
|
5687
|
-
|
|
6020
|
+
Project structure.
|
|
5688
6021
|
|
|
5689
6022
|
### CSRF
|
|
5690
6023
|
|
|
@@ -5759,9 +6092,9 @@ loader at a CDN and the runtime stays tiny. Or self-host: the optional
|
|
|
5759
6092
|
|
|
5760
6093
|
### The <Image> component
|
|
5761
6094
|
|
|
5762
|
-
`width` and `height` are **required** and validated
|
|
5763
|
-
`> 0
|
|
5764
|
-
(the CLS contract). It's `loading="lazy"` + `decoding="async"` by default;
|
|
6095
|
+
For string URLs, `width` and `height` are **required** and validated
|
|
6096
|
+
`> 0`. Imported metadata can supply them automatically. Dimensions reserve layout
|
|
6097
|
+
space so the page never shifts (the CLS contract). It's `loading="lazy"` + `decoding="async"` by default;
|
|
5765
6098
|
mark the LCP image with `priority` to get `eager` +
|
|
5766
6099
|
`fetchpriority="high"`. Extra DOM props (`className`, `style`,
|
|
5767
6100
|
`id`, `data-*`) pass straight through to the `<img>`.
|
|
@@ -5794,6 +6127,81 @@ The responsive `srcSet` is built from `widths` (default
|
|
|
5794
6127
|
the same URL (e.g. the identity loader), `srcSet` is omitted. The browser then picks
|
|
5795
6128
|
the right candidate for the device's pixel ratio and the `sizes` you declare.
|
|
5796
6129
|
|
|
6130
|
+
### Local image imports
|
|
6131
|
+
|
|
6132
|
+
Opt into `?image` imports to read PNG, JPEG, GIF and WebP dimensions at build time,
|
|
6133
|
+
including JPEG, PNG and WebP display orientation. The import is a browser-safe `StaticImageData`
|
|
6134
|
+
object; no filesystem code or codec ships to the browser. Ordinary string URLs are unchanged.
|
|
6135
|
+
|
|
6136
|
+
```ts
|
|
6137
|
+
// env.d.ts — enable the typed metadata import:
|
|
6138
|
+
/// <reference types="@nifrajs/image/imports" />
|
|
6139
|
+
|
|
6140
|
+
// routes/index.tsx (React; also supported by Preact, Solid, Vue and Svelte)
|
|
6141
|
+
import { Image } from "@nifrajs/web-react/image"
|
|
6142
|
+
import hero from "../shared/images/hero.jpg?image"
|
|
6143
|
+
|
|
6144
|
+
export default function Page() {
|
|
6145
|
+
return <Image src={hero} alt="Mountain lake" priority />
|
|
6146
|
+
// Optional width={600} infers height from the source aspect ratio.
|
|
6147
|
+
}
|
|
6148
|
+
```
|
|
6149
|
+
|
|
6150
|
+
```ts
|
|
6151
|
+
// backend/framework.ts — add these beside your existing framework plugins:
|
|
6152
|
+
import { imageBunPlugin } from "@nifrajs/image/plugins"
|
|
6153
|
+
|
|
6154
|
+
const images = { root: process.cwd() }
|
|
6155
|
+
export const clientPlugins = [imageBunPlugin(images)]
|
|
6156
|
+
export const serverPlugins = [imageBunPlugin(images)]
|
|
6157
|
+
|
|
6158
|
+
// For the Vite pipeline instead (including component mode):
|
|
6159
|
+
// import { imageVitePlugin } from "@nifrajs/image/plugins"
|
|
6160
|
+
// export const vitePlugins = [imageVitePlugin(images)]
|
|
6161
|
+
```
|
|
6162
|
+
|
|
6163
|
+
Keep the same image options in client and server builds. Preserve your framework's existing
|
|
6164
|
+
plugins when adding these. Metadata-only imports need no native dependency. Nifra emits the
|
|
6165
|
+
original bytes under `/assets/_images/` with content-hashed names, registers them in
|
|
6166
|
+
the build manifest, and serves them in development. Static builds deploy these files too;
|
|
6167
|
+
no image endpoint is needed. For standalone bundler use, emit the plugin's
|
|
6168
|
+
`nifraStaticAssets()` files yourself. A custom `publicPath` (a root-relative prefix
|
|
6169
|
+
or an absolute http(s) URL) must match your client build's asset prefix; a mismatch fails the build.
|
|
6170
|
+
|
|
6171
|
+
### Build-time responsive variants
|
|
6172
|
+
|
|
6173
|
+
Supply `widths` and an explicit `ImageBackend` to generate real responsive
|
|
6174
|
+
files at build time. This reuses the sharp, Bun.Image or WASM backend seam; sharp is an optional
|
|
6175
|
+
application dependency, not a Nifra runtime dependency. Both the processor and sharp path work
|
|
6176
|
+
on Node without Bun. Outputs support WebP (default), JPEG and PNG; widths never upscale the source.
|
|
6177
|
+
|
|
6178
|
+
```ts
|
|
6179
|
+
// doc-check: skip - install sharp and merge with your framework's existing plugins.
|
|
6180
|
+
import sharp from "sharp"
|
|
6181
|
+
import { Buffer } from "node:buffer"
|
|
6182
|
+
import { sharpImageBackend } from "@nifrajs/image/backends"
|
|
6183
|
+
import { imageBunPlugin } from "@nifrajs/image/plugins"
|
|
6184
|
+
|
|
6185
|
+
const images = {
|
|
6186
|
+
root: process.cwd(),
|
|
6187
|
+
widths: [320, 640, 1200],
|
|
6188
|
+
format: "webp" as const,
|
|
6189
|
+
quality: 80,
|
|
6190
|
+
backend: sharpImageBackend((bytes) => sharp(Buffer.from(bytes))),
|
|
6191
|
+
}
|
|
6192
|
+
export const clientPlugins = [imageBunPlugin(images)]
|
|
6193
|
+
export const serverPlugins = [imageBunPlugin(images)]
|
|
6194
|
+
// Vite: use imageVitePlugin(images) in vitePlugins instead.
|
|
6195
|
+
```
|
|
6196
|
+
|
|
6197
|
+
The component chooses only emitted variants; per-render `widths` filters available
|
|
6198
|
+
candidates rather than creating files. Build-time `quality` is baked in. An explicit
|
|
6199
|
+
CDN loader overrides the static variant selection. Defaults cap sources at 16 MiB and 40 million
|
|
6200
|
+
pixels; `maxSourceBytes` and `maxSourcePixels` are configurable. At most 32
|
|
6201
|
+
widths, each up to 8192 pixels, are accepted. Sources must remain inside `root`,
|
|
6202
|
+
including symlink targets. GIF, animated PNG and animated WebP imports are metadata-only; AVIF and SVG metadata
|
|
6203
|
+
imports are not supported.
|
|
6204
|
+
|
|
5797
6205
|
### Loaders
|
|
5798
6206
|
|
|
5799
6207
|
A loader is a pure `({ src, width, quality? }) => string` URL builder. Ship with
|
|
@@ -5946,7 +6354,7 @@ const url = signImageUrl("/_image", { src: "/private/a.jpg", width: 800 }, {
|
|
|
5946
6354
|
Signatures over `(src, w, q)` are **stable** (no expiry), so an SSR-rendered
|
|
5947
6355
|
`<Image>` srcset hydrates and caches identically. The secret makes a loader
|
|
5948
6356
|
config **server-only** - inject it from `env` in backend code, never a page or
|
|
5949
|
-
`frontend/` module (same discipline as a
|
|
6357
|
+
`frontend/` module (same discipline as a session secret). For time-limited links to
|
|
5950
6358
|
private images, `signImageUrl(…, { expiresIn })` adds an `&exp=` the
|
|
5951
6359
|
handler enforces.
|
|
5952
6360
|
|
|
@@ -6046,7 +6454,7 @@ permanent redirect - on full page loads, client navigations and form posts alike
|
|
|
6046
6454
|
// routes/[lang]/_layout.backend.ts - 404 unknown and draft locales, redirect /en/... to /...
|
|
6047
6455
|
import { defineLocales } from "@nifrajs/i18n"
|
|
6048
6456
|
import { defineI18nRouting } from "@nifrajs/i18n/routing"
|
|
6049
|
-
import { notFound, type RouteMiddleware, redirect } from "@nifrajs/web"
|
|
6457
|
+
import { notFound, type RouteMiddleware, rawHref, redirect } from "@nifrajs/web"
|
|
6050
6458
|
|
|
6051
6459
|
const urls = defineI18nRouting(
|
|
6052
6460
|
defineLocales({ default: "en", locales: { en: {}, hi: {}, gu: { draft: true } } }),
|
|
@@ -6056,7 +6464,7 @@ export const middleware: RouteMiddleware = (ctx) => {
|
|
|
6056
6464
|
const { pathname, search } = new URL(ctx.request.url)
|
|
6057
6465
|
const match = urls.matchSegment(ctx.params.lang, pathname + search)
|
|
6058
6466
|
if (match.kind === "not-found") notFound()
|
|
6059
|
-
if (match.kind === "redirect") return redirect(match.location, { status: 308 })
|
|
6467
|
+
if (match.kind === "redirect") return redirect(rawHref(match.location), { status: 308 })
|
|
6060
6468
|
return undefined
|
|
6061
6469
|
}
|
|
6062
6470
|
```
|
|
@@ -6094,7 +6502,7 @@ export function meta({ params, origin }: MetaArgs): Meta {
|
|
|
6094
6502
|
```
|
|
6095
6503
|
|
|
6096
6504
|
A page that exists in some languages only is declared once, with `pageLocales`
|
|
6097
|
-
(given the path without its locale prefix; it must be pure). Then
|
|
6505
|
+
(given the canonical path without its locale prefix; it must be pure). Then
|
|
6098
6506
|
`matchSegment` answers not-found for the other locales, `alternates`
|
|
6099
6507
|
lists only the page's own (none for a page in one locale), `localesOf(path)` names
|
|
6100
6508
|
them for a prerender's static paths, and `localizePathname(path, locale, { fallback: "default" })`
|
|
@@ -6102,6 +6510,84 @@ links a menu entry to the default locale's page where the page is missing. A
|
|
|
6102
6510
|
`pageLocales` that throws, or names a locale the registry does not declare, throws
|
|
6103
6511
|
rather than serving every locale.
|
|
6104
6512
|
|
|
6513
|
+
#### Explicit static translated pathnames
|
|
6514
|
+
|
|
6515
|
+
Optionally declare `pathnames`: canonical unprefixed static paths mapped to
|
|
6516
|
+
unprefixed locale spellings. Missing entries keep the canonical spelling; they do not make a
|
|
6517
|
+
page unavailable (`pageLocales` still owns that). Language switches, reverse
|
|
6518
|
+
lookup, canonical links, `hreflang` and `matchSegment` redirects all
|
|
6519
|
+
use the same table. With no table, existing prefix-only behavior is unchanged.
|
|
6520
|
+
|
|
6521
|
+
```ts
|
|
6522
|
+
// shared/i18n.ts - explicit STATIC pathname translations, not content or dynamic slug translation.
|
|
6523
|
+
import { defineLocales } from "@nifrajs/i18n"
|
|
6524
|
+
import { defineI18nRouting } from "@nifrajs/i18n/routing"
|
|
6525
|
+
|
|
6526
|
+
const locales = defineLocales({ default: "en", locales: { en: {}, fr: {}, de: {} } })
|
|
6527
|
+
export const urls = defineI18nRouting(locales, {
|
|
6528
|
+
pathnames: {
|
|
6529
|
+
"/about": { fr: "/a-propos", de: "/ueber-uns" },
|
|
6530
|
+
"/contact": { fr: "/contactez-nous" }, // Missing German name; availability is separate below.
|
|
6531
|
+
},
|
|
6532
|
+
// Always the canonical key, even when the incoming URL is /fr/contactez-nous.
|
|
6533
|
+
pageLocales: (path) => path === "/contact" ? ["en", "fr"] : undefined,
|
|
6534
|
+
})
|
|
6535
|
+
|
|
6536
|
+
urls.localizePathname("/about", "fr") // "/fr/a-propos"
|
|
6537
|
+
urls.localizePathname("/fr/a-propos", "de") // "/de/ueber-uns"
|
|
6538
|
+
urls.unlocalizePathname("/de/ueber-uns") // { locale: "de", pathname: "/about" }
|
|
6539
|
+
urls.alternates("/fr/a-propos").canonical // "/fr/a-propos"
|
|
6540
|
+
urls.staticPathnames() // ["/about", "/fr/a-propos", "/de/ueber-uns", "/contact", "/fr/contactez-nous"]
|
|
6541
|
+
```
|
|
6542
|
+
|
|
6543
|
+
`staticPathnames()` enumerates mapped public URLs only, in mapping declaration
|
|
6544
|
+
order then served-locale registry order, filtered by `pageLocales`. Feed explicit
|
|
6545
|
+
static entries to your prerender setup after wiring incoming routing; the prerender driver
|
|
6546
|
+
does not automatically enumerate catch-all routes. Unmapped pages are not discovered.
|
|
6547
|
+
Draft locales are never included. Unicode spellings such as `/紹介` are
|
|
6548
|
+
emitted URL-encoded and resolve from `new URL(request.url).pathname`. Reverse
|
|
6549
|
+
lookup returns a URL-encoded canonical pathname; `pageLocales` sees the declared
|
|
6550
|
+
canonical key. Query strings and trailing slashes survive translation, hashes too;
|
|
6551
|
+
SEO links and redirects omit the hash as before.
|
|
6552
|
+
|
|
6553
|
+
**Mappings do not create files or filesystem aliases.** A file named
|
|
6554
|
+
` about.tsx` alone will not serve `/fr/a-propos`. Supply matching
|
|
6555
|
+
routes yourself, or use a catch-all dispatcher that resolves
|
|
6556
|
+
` unlocalizePathname` to an explicit page registry, for example:
|
|
6557
|
+
|
|
6558
|
+
```ts
|
|
6559
|
+
// doc-check: skip - imports the app's own routing module and generated route types.
|
|
6560
|
+
// routes/[...path].backend.ts, paired with routes/[...path].tsx rendering props.data.page.
|
|
6561
|
+
// A root catch-all receives /about, /fr/a-propos and /de/ueber-uns; it needs at least one segment.
|
|
6562
|
+
import { notFound, redirect } from "@nifrajs/web"
|
|
6563
|
+
import { t } from "@nifrajs/schema"
|
|
6564
|
+
import { urls } from "../shared/i18n"
|
|
6565
|
+
import type { Route } from "./+types/[...path]"
|
|
6566
|
+
|
|
6567
|
+
const pages = new Map([["/about", "about"], ["/contact", "contact"]])
|
|
6568
|
+
export const loaderOutput = t.object({ page: t.string(), locale: t.string() })
|
|
6569
|
+
export function loader({ request }: Route.LoaderArgs) {
|
|
6570
|
+
const { pathname, search } = new URL(request.url)
|
|
6571
|
+
const match = urls.matchSegment(urls.getPathLocale(pathname), pathname + search)
|
|
6572
|
+
if (match.kind === "not-found") notFound()
|
|
6573
|
+
if (match.kind === "redirect") return redirect(match.location, { status: 308 })
|
|
6574
|
+
const canonical = urls.unlocalizePathname(pathname).pathname.replace(/\/$/, "") || "/"
|
|
6575
|
+
const page = pages.get(canonical)
|
|
6576
|
+
if (!page) notFound() // Includes unknown and draft-prefixed paths: never dispatch arbitrary input.
|
|
6577
|
+
return { page, locale: urls.localeOf(pathname) }
|
|
6578
|
+
}
|
|
6579
|
+
```
|
|
6580
|
+
|
|
6581
|
+
Keep a separate `routes/index.tsx` for the root; a catch-all needs at least one
|
|
6582
|
+
segment. Literal routes take precedence, so ensure they also use the same canonical checks
|
|
6583
|
+
when they overlap this dispatcher. Registering `i18n` below supplies locale
|
|
6584
|
+
metadata and prefix guards, not pathname rewrites. Dynamic slug maps, automatic filesystem
|
|
6585
|
+
aliases, automatic content translation and domain-based routing are outside this API.
|
|
6586
|
+
Invalid static paths (patterns, URL delimiters, dot segments or encoded separators), unknown
|
|
6587
|
+
locale keys, per-locale collisions including fallback paths, and translations shadowing
|
|
6588
|
+
another canonical key throw when the router is defined. Paths must not already carry a
|
|
6589
|
+
served locale prefix.
|
|
6590
|
+
|
|
6105
6591
|
### Register the routing once
|
|
6106
6592
|
|
|
6107
6593
|
Export the router as `i18n` from `backend/framework.ts` (re-export it from
|
|
@@ -6537,7 +7023,7 @@ export default { fetch: (req: Request, env: Env, ctx: ExecutionContext) =>
|
|
|
6537
7023
|
Export through `toFetchHandler` rather than handing the app out directly. Besides
|
|
6538
7024
|
`env` and `ctx.waitUntil`, it tells nifra the request came from the
|
|
6539
7025
|
platform's own HTTP parser, which lets the
|
|
6540
|
-
|
|
7026
|
+
bounded-body cap trust the declared
|
|
6541
7027
|
`Content-Length` as a real transport frame instead of re-counting every JSON body.
|
|
6542
7028
|
A bare `export default app` has no such signal and pays the extra pass unless you
|
|
6543
7029
|
set `server({ trustBodyFraming: true })`.
|
|
@@ -6661,7 +7147,7 @@ HTTP request, and `upgrade` reads what the guards derived. The origin check runs
|
|
|
6661
7147
|
first. A socket registered before a guard stays public, like an HTTP route there. A browser
|
|
6662
7148
|
cannot set a header on the handshake, so `authenticate()` can read a short-lived,
|
|
6663
7149
|
single-use ticket from `input.query` - see
|
|
6664
|
-
|
|
7150
|
+
Authentication runs first.
|
|
6665
7151
|
|
|
6666
7152
|
```ts
|
|
6667
7153
|
// doc-check: skip - illustrative: an existing auth guard and session lookup.
|
|
@@ -7012,7 +7498,7 @@ server()
|
|
|
7012
7498
|
|
|
7013
7499
|
## Nifra - Deployment
|
|
7014
7500
|
|
|
7015
|
-
> One Nifra app, one command per target - Bun, Node (Docker), Deno Deploy, Cloudflare Pages, Vercel Edge.
|
|
7501
|
+
> One Nifra app, one command per target - Bun, Node (Docker), Deno Deploy, Cloudflare Pages, Vercel Edge or Node.
|
|
7016
7502
|
|
|
7017
7503
|
`app.fetch(request)` is a pure Web-standard handler, so the same app runs
|
|
7018
7504
|
anywhere. Pick a runtime; the code doesn't change.
|
|
@@ -7082,7 +7568,7 @@ Cloudflare Pages
|
|
|
7082
7568
|
|
|
7083
7569
|
`wrangler.toml`
|
|
7084
7570
|
|
|
7085
|
-
Vercel Edge
|
|
7571
|
+
Vercel (Edge by default; Node opt-in)
|
|
7086
7572
|
|
|
7087
7573
|
`.vercel/output/`
|
|
7088
7574
|
|
|
@@ -7092,11 +7578,45 @@ none (Build Output API v3)
|
|
|
7092
7578
|
|
|
7093
7579
|
`nifra build --target static` also builds a site with no server: the prerendered
|
|
7094
7580
|
pages, the client bundle and `public/`, for any static host. See
|
|
7095
|
-
|
|
7581
|
+
SSG & ISR.
|
|
7096
7582
|
|
|
7097
7583
|
The Bun, Node and Deno entries serve the client bundle from disk next to themselves; on
|
|
7098
7584
|
Cloudflare and Vercel the platform serves it.
|
|
7099
7585
|
|
|
7586
|
+
#### Vercel: Edge or Node.js
|
|
7587
|
+
|
|
7588
|
+
Ordinary SSR keeps the existing Edge output for `nifra build --target vercel`.
|
|
7589
|
+
For Node built-ins and Node-compatible server libraries, keep the target and opt into Node
|
|
7590
|
+
in `nifra.config.ts` (there is no separate runtime CLI flag):
|
|
7591
|
+
|
|
7592
|
+
```ts
|
|
7593
|
+
// nifra.config.ts (alongside your adapter/clientModule exports)
|
|
7594
|
+
export const target = "vercel"
|
|
7595
|
+
export const vercelRuntime = "node" // "edge" or omitted preserves the Edge function
|
|
7596
|
+
|
|
7597
|
+
// Build and deploy from the project root:
|
|
7598
|
+
// bunx nifra build # or: bunx nifra build --target vercel
|
|
7599
|
+
// vercel deploy --prebuilt
|
|
7600
|
+
```
|
|
7601
|
+
|
|
7602
|
+
Both Bun and Vite production pipelines emit Build Output API v3 at
|
|
7603
|
+
`.vercel/output`: `static/` holds the client chunks and public files;
|
|
7604
|
+
`functions/index.func/` holds the SSR function. Node mode declares
|
|
7605
|
+
`nodejs22.x` and exports an HTTP handler without listening at import. It serves
|
|
7606
|
+
pages and the backend mounted with `apiPrefix`. Programmatic builds use
|
|
7607
|
+
`buildTarget("vercel", { ...options, vercelRuntime: "node" })`, or the same
|
|
7608
|
+
option on `buildTargetVite`. A different target or an unsupported runtime is
|
|
7609
|
+
refused before clearing the previous build; remove the selector when switching targets.
|
|
7610
|
+
|
|
7611
|
+
This is serverless Node, not the self-hosted `node` target: no Bun APIs, listening
|
|
7612
|
+
sockets, persistent in-process jobs or WebSocket server. Execution duration, streaming and
|
|
7613
|
+
filesystem availability remain subject to Vercel limits; native dependencies must be
|
|
7614
|
+
deploy-compatible. `selfHost` does not start a server here. Builds still require
|
|
7615
|
+
Bun. Static files are served first by Vercel, so host policy in the function cannot protect
|
|
7616
|
+
CDN files. The component pipeline retains its existing Vercel Node output and does not take
|
|
7617
|
+
this ordinary-SSR selector. The generated handler is tested locally under Node; this is not
|
|
7618
|
+
a claim of a live Vercel deployment test.
|
|
7619
|
+
|
|
7100
7620
|
The Bun, Node and Deno entries pass the socket peer as `c.clientIp`. Cloudflare
|
|
7101
7621
|
and Vercel expose no socket, so an edge build has no caller address unless
|
|
7102
7622
|
`nifra.config.ts` declares `export const clientIp = "platform"`: then
|
|
@@ -7195,7 +7715,7 @@ host-specific deploy step for you to fill in (Fly, a registry push, SSH, …).
|
|
|
7195
7715
|
### Bun (its home)
|
|
7196
7716
|
|
|
7197
7717
|
`app.listen(3000)` - the native Bun server. Bun is the runtime where Nifra measures
|
|
7198
|
-
fastest (see
|
|
7718
|
+
fastest (see benchmarks).
|
|
7199
7719
|
|
|
7200
7720
|
**Every core:** Bun is single-threaded per process - for multi-core boxes,
|
|
7201
7721
|
spawn one process per core, each binding the same port with
|
|
@@ -7204,8 +7724,8 @@ across them (Linux balances ~evenly). A supervisor that spawns + restarts worker
|
|
|
7204
7724
|
lines - see `examples/cluster.ts`. Anything shared across workers (rate limits,
|
|
7205
7725
|
sessions, pub/sub) needs a shared store, as in any multi-instance deploy. So do an ISR page
|
|
7206
7726
|
store (signed with one `storeSecret` in every process - see
|
|
7207
|
-
|
|
7208
|
-
|
|
7727
|
+
SSG & ISR) and
|
|
7728
|
+
live refresh (one Redis Streams bus for every process).
|
|
7209
7729
|
|
|
7210
7730
|
### Node & Deno
|
|
7211
7731
|
|
|
@@ -7319,8 +7839,9 @@ export default toFetchHandler(app)
|
|
|
7319
7839
|
```
|
|
7320
7840
|
|
|
7321
7841
|
Deploy: `wrangler pages deploy dist` (Pages) or `wrangler deploy`
|
|
7322
|
-
(Workers). The `vercel` target
|
|
7323
|
-
|
|
7842
|
+
(Workers). The `vercel` target defaults to an Edge Build Output API function
|
|
7843
|
+
under `.vercel/output`; [opt into Node.js](#vercel-node) for
|
|
7844
|
+
Node-compatible server dependencies.
|
|
7324
7845
|
|
|
7325
7846
|
## Nifra - CLI
|
|
7326
7847
|
|
|
@@ -7346,7 +7867,7 @@ nifra build --target cloudflare # also: node | deno | vercel | static; add --re
|
|
|
7346
7867
|
|
|
7347
7868
|
### The layout the CLI reads
|
|
7348
7869
|
|
|
7349
|
-
`nifra dev` runs the Bun-native
|
|
7870
|
+
`nifra dev` runs the Bun-native HMR dev server;
|
|
7350
7871
|
`nifra build` runs the production build (content-hashed client assets plus a
|
|
7351
7872
|
target-specific server); `nifra start` runs the default Bun output. The generated
|
|
7352
7873
|
server serves assets and SSR with matched-route chunks preloaded and route CSS linked in each
|
|
@@ -7360,7 +7881,7 @@ pipeline cannot run those, so that app gets Vite for dev and build alike, and sa
|
|
|
7360
7881
|
Vite-only app rather than dropping its transforms silently. Every `dev` and
|
|
7361
7882
|
`build` run prints which bundler it picked and why, and `nifra check`
|
|
7362
7883
|
answers the same question without starting a server - see
|
|
7363
|
-
|
|
7884
|
+
which pipeline runs, when for the full table.
|
|
7364
7885
|
|
|
7365
7886
|
```ts
|
|
7366
7887
|
my-app/
|
|
@@ -7383,7 +7904,7 @@ and `nifra check` reports it as NF-C038: run
|
|
|
7383
7904
|
`backend/app.ts` a composition root - merging modules, registering no routes of
|
|
7384
7905
|
its own - so each route's capability reach stays its own module's. What goes in each
|
|
7385
7906
|
zone, and what the builds refuse to cross, is on
|
|
7386
|
-
|
|
7907
|
+
Project structure.
|
|
7387
7908
|
|
|
7388
7909
|
### backend/framework.ts and nifra.config.ts
|
|
7389
7910
|
|
|
@@ -7415,6 +7936,17 @@ export const vitePlugins = [react()] // only if you want Vite's dev pip
|
|
|
7415
7936
|
// define = { __VUE_OPTIONS_API__: "true", ... } // Vue feature flags
|
|
7416
7937
|
```
|
|
7417
7938
|
|
|
7939
|
+
Ordinary `vercel` builds default to Edge. To opt into Node.js 22, export both
|
|
7940
|
+
`target = "vercel"` and `vercelRuntime = "node"` from
|
|
7941
|
+
`nifra.config.ts`, then run `nifra build` (or
|
|
7942
|
+
`nifra build --target vercel`) and `vercel deploy --prebuilt` from
|
|
7943
|
+
the project root. Both Bun and Vite builds write `.vercel/output` unless
|
|
7944
|
+
`--out` overrides it. Omit the selector or use `"edge"` to retain
|
|
7945
|
+
Edge; other values and use with a different target are refused before output is cleared.
|
|
7946
|
+
There is no separate runtime flag. Node functions support Node built-ins but not Bun APIs
|
|
7947
|
+
or a persistent server; the CLI/build still requires Bun. See
|
|
7948
|
+
runtime output and limitations.
|
|
7949
|
+
|
|
7418
7950
|
### Command reference
|
|
7419
7951
|
|
|
7420
7952
|
Every command `nifra --help` lists, by what it is for. Most take
|
|
@@ -7552,23 +8084,19 @@ What it does
|
|
|
7552
8084
|
|
|
7553
8085
|
`nifra types [--check]`
|
|
7554
8086
|
|
|
7555
|
-
Each route's `./+types` module under `.nifra/types`: params, schema-typed data, and `api` typed by `backend/app.ts`. `dev`, `build` and `check` refresh them too.
|
|
8087
|
+
Each route's `./+types` module under `.nifra/types`: params, schema-typed data, and `api` typed by `backend/app.ts`. It also writes `routes.d.ts`, the route table `href()` reads. `dev`, `build` and `check` refresh them too.
|
|
7556
8088
|
|
|
7557
8089
|
`nifra schemas [--write] [--check]`
|
|
7558
8090
|
|
|
7559
8091
|
Draft `loaderOutput` and `actionOutput` from each loader's and action's return type. `--write` adds the missing ones; it also lists returned fields a hand-written schema drops.
|
|
7560
8092
|
|
|
7561
|
-
`nifra sync-routes`
|
|
7562
|
-
|
|
7563
|
-
Regenerate `nifra-routes.d.ts` so `navigate({ to, search })` is typed by each route's search schema.
|
|
7564
|
-
|
|
7565
8093
|
`nifra sync-manifest`
|
|
7566
8094
|
|
|
7567
8095
|
Regenerate a committed `server-manifest.ts` from `routes/` without a full build.
|
|
7568
8096
|
|
|
7569
8097
|
`nifra scaffold hole <route> <name> [--shared] [--interactive] [--timeout <ms>] [--server]`
|
|
7570
8098
|
|
|
7571
|
-
|
|
8099
|
+
Add a hole to a partially prerendered route: its definition, `boundaries` entry and `Hole` in a JSX page, and a loader with its output schema in the backend half. A Vue or Svelte page gets the code to paste.
|
|
7572
8100
|
|
|
7573
8101
|
`nifra openapi [--format json | yaml] [--path <prefix>]`
|
|
7574
8102
|
|
|
@@ -7708,12 +8236,16 @@ starts from unless nothing else, installed or declared, names one.
|
|
|
7708
8236
|
nifra upgrade --list # the release targets this CLI knows
|
|
7709
8237
|
nifra upgrade 5.6.0 # dry-run: every planned edit, nothing written
|
|
7710
8238
|
nifra upgrade 5.6.0 --write # apply; it verifies with nifra check once the target is installed
|
|
8239
|
+
nifra upgrade 5.6.0 --from 5.4.0 --write # pins already bumped by hand: apply the recipes they skipped
|
|
7711
8240
|
bun install # install the new pins
|
|
7712
8241
|
nifra check # verify against them
|
|
7713
8242
|
nifra doctor # afterwards: no "mixed nifra versions" advisory left
|
|
7714
8243
|
```
|
|
7715
8244
|
|
|
7716
|
-
It is a dry-run until `--write`, and the same run twice makes no further edits.
|
|
8245
|
+
It is a dry-run until `--write`, and the same run twice makes no further edits. Once
|
|
8246
|
+
the pins name the target, no recipe is left to apply: pass `--from <version>`
|
|
8247
|
+
with the version they were at to apply the ones they skipped. An option it does not know is
|
|
8248
|
+
refused rather than ignored. An
|
|
7717
8249
|
unknown version or a target below what is installed is refused (`--allow-downgrade`
|
|
7718
8250
|
when the rollback is intended); a target newer than the running CLI prints the command for
|
|
7719
8251
|
that release's CLI. It edits files under the workspace root only: a symlinked package
|
|
@@ -7739,11 +8271,11 @@ install. Run from a CLI whose
|
|
|
7739
8271
|
copy cannot reflect the project's app, and says so in one line.
|
|
7740
8272
|
`nifra doctor` and
|
|
7741
8273
|
`nifra check` (NF-D002) point here when a workspace carries more than one version;
|
|
7742
|
-
see
|
|
8274
|
+
see mixed nifra versions. A
|
|
7743
8275
|
`file:` package whose dependencies this upgrade moves keeps its old ones in
|
|
7744
8276
|
`bun.lock`, where Bun never refreshes them; the plan lists each, and
|
|
7745
8277
|
`--write` drops those entries so the next `bun install` records them
|
|
7746
|
-
again (see
|
|
8278
|
+
again (see stale file: links).
|
|
7747
8279
|
|
|
7748
8280
|
A `link:` or `file:` dependency outside the root that installs its own
|
|
7749
8281
|
`@nifrajs/*` at another version stops the upgrade before anything is written: its
|
|
@@ -7773,7 +8305,7 @@ fixes for data loss ship as patches of it, so move to the latest with
|
|
|
7773
8305
|
|
|
7774
8306
|
`nifra build` defaults to a self-hosted Bun server. Use `--target node`,
|
|
7775
8307
|
`deno`, `cloudflare`, `vercel`, or `static` for another
|
|
7776
|
-
complete deploy shape (see
|
|
8308
|
+
complete deploy shape (see Deployment). Run non-Bun outputs with
|
|
7777
8309
|
the command printed by the build.
|
|
7778
8310
|
|
|
7779
8311
|
## Nifra - Coding agents
|
|
@@ -7783,7 +8315,7 @@ the command printed by the build.
|
|
|
7783
8315
|
Nifra ships an MCP server. It is not a documentation lookup bolted onto a framework: an agent
|
|
7784
8316
|
can read the project, learn the real API, run actual requests against the backend it just
|
|
7785
8317
|
edited, and finish with a report of what the change proved. The same typed capabilities can
|
|
7786
|
-
power the agent inside your product through
|
|
8318
|
+
power the agent inside your product through WebMCP and predictive UI
|
|
7787
8319
|
or stream into a product surface through AG-UI.
|
|
7788
8320
|
|
|
7789
8321
|
### One MCP, two ways to connect
|
|
@@ -8312,7 +8844,7 @@ Passing tests say the code does what its tests say. `nifra_levels` answers the
|
|
|
8312
8844
|
different question of what the project _holds_, as a cumulative ladder from a typed
|
|
8313
8845
|
contract (L0) to contract-derived invariant tests (L4). A scaffolded app starts at L1, and each
|
|
8314
8846
|
rung it has not reached reports the specific thing missing - so the ladder doubles as the list
|
|
8315
|
-
of what to do next. See
|
|
8847
|
+
of what to do next. See the verification ladder.
|
|
8316
8848
|
|
|
8317
8849
|
```bash
|
|
8318
8850
|
# The two an agent should gate on. Both exit non-zero on failure, so they work in CI unchanged.
|
|
@@ -8817,7 +9349,7 @@ export function Counter(props: { message: string }) {
|
|
|
8817
9349
|
|
|
8818
9350
|
`@nifrajs/devtools` is a plugin that streams what each request actually did - loader
|
|
8819
9351
|
traces, ISR status, route metadata - over a secured SSE endpoint, with an overlay to read it
|
|
8820
|
-
in the browser. In an app with
|
|
9352
|
+
in the browser. In an app with keep-alive routes, the overlay
|
|
8821
9353
|
also lists the pages kept hidden.
|
|
8822
9354
|
|
|
8823
9355
|
```ts
|
|
@@ -8840,12 +9372,12 @@ reads it through `nifra_errors`, `nifra_logs` and
|
|
|
8840
9372
|
`nifra_inspect`, and you can read it with `nifra errors` and
|
|
8841
9373
|
`nifra logs`. Pages get a small inline script that reports browser errors and
|
|
8842
9374
|
hydration mismatches back to the dev server; the dev server writes `.nifra/dev-server.json`
|
|
8843
|
-
so the tools can find it. See
|
|
9375
|
+
so the tools can find it. See coding agents.
|
|
8844
9376
|
|
|
8845
9377
|
When a page reports an error, a badge appears in its corner. It lists that page's errors with
|
|
8846
9378
|
their code, message, codeframe and fix, and a **Copy prompt** button per fix hands
|
|
8847
9379
|
a coding agent the error, one fix and the steps to check it worked (the
|
|
8848
|
-
|
|
9380
|
+
error codes page has the same prompts). The badge lives in a closed
|
|
8849
9381
|
shadow root, so the page's styles cannot reach it, and it loads under the page's CSP: by nonce,
|
|
8850
9382
|
by its exact URL, or through `'strict-dynamic'`. A page that never errors never
|
|
8851
9383
|
fetches it. Turn it off for one run with `nifra dev --no-indicator`, for every run
|
|
@@ -9374,7 +9906,7 @@ never reported.
|
|
|
9374
9906
|
This applies to every framework with module-global render state, not just React (Preact,
|
|
9375
9907
|
Vue, Solid, Svelte). Nifra dedupes the active adapter's runtime in build and dev; a
|
|
9376
9908
|
`file:`-linked package shipping its own copy is the thing to fix. See
|
|
9377
|
-
|
|
9909
|
+
Dev & HMR and the `file:`-linked-package note in
|
|
9378
9910
|
`AGENTS.md`.
|
|
9379
9911
|
|
|
9380
9912
|
###
|
|
@@ -9390,7 +9922,7 @@ That route's `data` infers `never` (Nifra can't see the shape). Return a
|
|
|
9390
9922
|
plain object and shape the response with `c.set` - reach for `c.json` /
|
|
9391
9923
|
`c.text` only for an error short-circuit (`throw` from a
|
|
9392
9924
|
`derive` / `beforeHandle`), not a route's happy path. See
|
|
9393
|
-
|
|
9925
|
+
API & typed client.
|
|
9394
9926
|
|
|
9395
9927
|
-
|
|
9396
9928
|
**A plugin widened the app's type.** A plugin that registers routes/hooks but whose return
|
|
@@ -9399,7 +9931,7 @@ makes `.use()` return `Server<any, any>` and the client loses your
|
|
|
9399
9931
|
registry. Build it with `defineRouterPlugin(name, …)` (the clearer-named
|
|
9400
9932
|
`defineIdentityPlugin`) so `.use()` returns your server unchanged and
|
|
9401
9933
|
routes added after it stay typed. See
|
|
9402
|
-
|
|
9934
|
+
Plugins → keep types with defineRouterPlugin.
|
|
9403
9935
|
|
|
9404
9936
|
`nifra check` flags the raw-`Response` case; the plugin case surfaces as a
|
|
9405
9937
|
`never` client at the call site.
|
|
@@ -9465,7 +9997,7 @@ export const app = server()
|
|
|
9465
9997
|
upfront**, and `implement(contract, handlers)` binds handlers to it. Nothing
|
|
9466
9998
|
grows a registry per call, so there is **no ceiling at all** - this is the path for
|
|
9467
9999
|
an API that will keep adding routes for years. Handlers stay checked against the contract exactly
|
|
9468
|
-
as inline routes are. See
|
|
10000
|
+
as inline routes are. See Contract-first.
|
|
9469
10001
|
|
|
9470
10002
|
```ts
|
|
9471
10003
|
import { defineContract, implement } from "@nifrajs/core/contract"
|
|
@@ -9542,7 +10074,7 @@ those, whatever the workspace installs, so two live-linked repositories that eac
|
|
|
9542
10074
|
version still run two), and the running CLI. When they disagree it names each version and
|
|
9543
10075
|
where it came from. It only reads files, and it never fails the run.
|
|
9544
10076
|
|
|
9545
|
-
The fix is
|
|
10077
|
+
The fix is `nifra upgrade <highest>`, not a
|
|
9546
10078
|
hand edit of the pins: it runs
|
|
9547
10079
|
every release's migration steps between your oldest pin and the target, then re-pins. Run it
|
|
9548
10080
|
without `--write` first to see each planned edit. It edits files under the
|
|
@@ -9572,7 +10104,7 @@ the manifests it is about to write and leaves `bun.lock` as it is.
|
|
|
9572
10104
|
|
|
9573
10105
|
Run `nifra check --json` as the done-gate - it surfaces the import-chain leaks,
|
|
9574
10106
|
typed-client drift, and raw-`Response`-from-a-route issues before you ship. The
|
|
9575
|
-
full machine-readable contract is at
|
|
10107
|
+
full machine-readable contract is at /llms-full.txt, and each
|
|
9576
10108
|
package ships a tight `LLM.md` contract card.
|
|
9577
10109
|
|
|
9578
10110
|
## Nifra - Backends & API (dev and prod)
|
|
@@ -10214,7 +10746,7 @@ A route is two files. The page (`x.tsx`) holds the view and its head:
|
|
|
10214
10746
|
`revalidate`. A `loader` runs on **GET** and feeds
|
|
10215
10747
|
`props.data`; an `action` runs on **POST** and feeds
|
|
10216
10748
|
`props.actionData`. A server-only export in the page file is a build error - see
|
|
10217
|
-
|
|
10749
|
+
Project structure.
|
|
10218
10750
|
|
|
10219
10751
|
```ts
|
|
10220
10752
|
// routes/users/[id].tsx - the page: it ships to the browser whole. Only `default` is required.
|
|
@@ -10271,7 +10803,7 @@ with `ctx.set.cookie()` / `ctx.set.deleteCookie()`.
|
|
|
10271
10803
|
```ts
|
|
10272
10804
|
// routes/account.backend.ts - response headers and cookies, from a loader or an action.
|
|
10273
10805
|
import { t } from "@nifrajs/schema"
|
|
10274
|
-
import { type LoaderContext, redirect } from "@nifrajs/web"
|
|
10806
|
+
import { type LoaderContext, rawHref, redirect } from "@nifrajs/web"
|
|
10275
10807
|
|
|
10276
10808
|
declare function signIn(email: string, password: string): Promise<{ token: string } | null>
|
|
10277
10809
|
|
|
@@ -10291,7 +10823,7 @@ export async function action(ctx: LoaderContext) {
|
|
|
10291
10823
|
if (session === null) return { error: "Wrong email or password" }
|
|
10292
10824
|
// HttpOnly; Secure; SameSite=Lax; Path=/ unless the options say otherwise.
|
|
10293
10825
|
ctx.set.cookie("session", session.token, { maxAge: 60 * 60 * 24 * 7 })
|
|
10294
|
-
throw redirect("/dashboard") // the cookie rides the redirect
|
|
10826
|
+
throw redirect(rawHref("/dashboard")) // the cookie rides the redirect
|
|
10295
10827
|
}
|
|
10296
10828
|
```
|
|
10297
10829
|
|
|
@@ -10675,7 +11207,7 @@ file that reaches it.
|
|
|
10675
11207
|
|
|
10676
11208
|
### Optional server components
|
|
10677
11209
|
|
|
10678
|
-
The optional
|
|
11210
|
+
The optional server-components pipeline supports
|
|
10679
11211
|
React, Preact, Vue, Svelte and Solid. Declare closed input/public-props schemas and authorization
|
|
10680
11212
|
in `*.component.server.ts(x)`, register owner instances and export a named
|
|
10681
11213
|
`componentPipeline` configuration. React uses native RSC/Flight; the other four
|
|
@@ -10848,8 +11380,8 @@ stable. The consumer still gets full end-to-end types both ways -
|
|
|
10848
11380
|
`.merge()` threads the router's routes into the host app's registry, and
|
|
10849
11381
|
`client(contract, url)` types every call from the same exported object.
|
|
10850
11382
|
|
|
10851
|
-
See
|
|
10852
|
-
two dev loops and the `--port` flag, and
|
|
11383
|
+
See SSG & ISR for prerendering, Dev & HMR for the
|
|
11384
|
+
two dev loops and the `--port` flag, and Loaders & actions for the
|
|
10853
11385
|
data layer in depth.
|
|
10854
11386
|
|
|
10855
11387
|
## Nifra - Control APIs (one schema, every client)
|
|
@@ -11310,7 +11842,7 @@ read the app import it, so everything the app does at module scope runs. A comma
|
|
|
11310
11842
|
reads what the app declares sets `NIFRA_REFLECT` to its own name first:
|
|
11311
11843
|
`check`, `routes`, `context`, `openapi`,
|
|
11312
11844
|
`contracts`, `capabilities`, `manifest`, `doctor`
|
|
11313
|
-
, `diff`, `sync-
|
|
11845
|
+
, `diff`, `sync-manifest`, and
|
|
11314
11846
|
`assure` without `--bundle`, `--strict`,
|
|
11315
11847
|
`--hydration`, `--interact` or `--out`. Commands that send the
|
|
11316
11848
|
app requests, such as `smoke`, `prove`, `levels` and the
|
|
@@ -11373,7 +11905,7 @@ nifra loads this app's copy for every importer:
|
|
|
11373
11905
|
|
|
11374
11906
|
Packages duplicated the same way are reported as one finding with one combined
|
|
11375
11907
|
`singleCopy` list. The preload this needs, and the version-skew case it cannot
|
|
11376
|
-
cover, are in
|
|
11908
|
+
cover, are in Troubleshooting.
|
|
11377
11909
|
|
|
11378
11910
|
## Nifra - Databases
|
|
11379
11911
|
|
|
@@ -11562,7 +12094,7 @@ CREATE POLICY tenant_isolation ON notes
|
|
|
11562
12094
|
|
|
11563
12095
|
The policy is the source of truth; `scoped()` just supplies the identity. Pair it with a
|
|
11564
12096
|
UUIDv7 `user_id` and an index on it. Connect `c.session.userId` from
|
|
11565
|
-
|
|
12097
|
+
@nifrajs/better-auth.
|
|
11566
12098
|
|
|
11567
12099
|
### Postgres (Raw Driver)
|
|
11568
12100
|
|
|
@@ -11635,13 +12167,13 @@ Cloudflare D1, Turso/libSQL
|
|
|
11635
12167
|
Neon serverless, Postgres over Hyperdrive, Prisma Accelerate
|
|
11636
12168
|
|
|
11637
12169
|
On Cloudflare, bindings like D1 are **typed** through `c.env` - see
|
|
11638
|
-
|
|
12170
|
+
Edge & bindings. For Workers MySQL/Postgres, Hyperdrive pools the
|
|
11639
12171
|
connection so a native driver works over the binding.
|
|
11640
12172
|
|
|
11641
12173
|
**Security:** always parameterize (`?` / driver placeholders or an ORM) - never
|
|
11642
12174
|
string-build SQL from request input. Nifra validates the request body/params at the boundary
|
|
11643
12175
|
(with `t` or any Standard Schema), so malformed input is rejected before your query
|
|
11644
|
-
runs. See
|
|
12176
|
+
runs. See Security.
|
|
11645
12177
|
|
|
11646
12178
|
Complete runnable references - a typed CRUD API you can diff your own against:
|
|
11647
12179
|
`examples/db-postgres` (Drizzle + Postgres, embedded PGlite - zero setup) and
|
|
@@ -11768,7 +12300,7 @@ patched the server HTML. In development the page reports it to the dev server as
|
|
|
11768
12300
|
`Date.now()`, `Math.random()`, locale formatting, reads of
|
|
11769
12301
|
`window` or `localStorage`, invalid HTML nesting. With happy-dom
|
|
11770
12302
|
installed in the project, `nifra_hydrate` reproduces it with a stable diagnostic.
|
|
11771
|
-
See
|
|
12303
|
+
See hydration.
|
|
11772
12304
|
|
|
11773
12305
|
#### NIFRA_SCHEMA_PARSE
|
|
11774
12306
|
|
|
@@ -11831,7 +12363,7 @@ them. Development reports each cookie name once.
|
|
|
11831
12363
|
carries the session, or in `keepAlive.ignoreCookies` if it does not. When the
|
|
11832
12364
|
session is a token in client storage, call `identityChanged()` from
|
|
11833
12365
|
`@nifrajs/web/client` at sign-in and sign-out. See
|
|
11834
|
-
|
|
12366
|
+
keep-alive and sign-in.
|
|
11835
12367
|
|
|
11836
12368
|
#### NIFRA_KEEPALIVE_DIRECT_CHILD_CSS
|
|
11837
12369
|
|
|
@@ -12122,7 +12654,7 @@ reads.
|
|
|
12122
12654
|
-
|
|
12123
12655
|
**CSP and browser:** React `Activity` hydration, inline styles under a
|
|
12124
12656
|
strict Content-Security-Policy, and WebKit's handling of streamed module scripts. Server-runtime differences are in
|
|
12125
|
-
|
|
12657
|
+
runtime differences.
|
|
12126
12658
|
|
|
12127
12659
|
### Version-sensitive advice
|
|
12128
12660
|
|
|
@@ -12208,7 +12740,7 @@ This is the part teams hand-roll incorrectly. `verifyWebhook` reads the raw body
|
|
|
12208
12740
|
bounded (DoS guard), verifies the signature in constant time, checks the timestamp
|
|
12209
12741
|
tolerance, and only then hands you the payload. Presets exist for Stripe and GitHub, and a
|
|
12210
12742
|
generic header/encoding form covers any other provider - including key rotation via an
|
|
12211
|
-
array of secrets. Details in
|
|
12743
|
+
array of secrets. Details in security.
|
|
12212
12744
|
|
|
12213
12745
|
#### 3. Processing exactly once
|
|
12214
12746
|
|
|
@@ -12228,7 +12760,7 @@ duplicate while the first is in flight.
|
|
|
12228
12760
|
|
|
12229
12761
|
### When to write a plugin
|
|
12230
12762
|
|
|
12231
|
-
Reach for
|
|
12763
|
+
Reach for a plugin only when a library should participate in
|
|
12232
12764
|
the framework itself: contribute typed context to every handler (`c.stripe`, a
|
|
12233
12765
|
session, a tenant), mount routes of its own, or hook the request lifecycle. That is
|
|
12234
12766
|
`definePlugin` - a few lines, typed end-to-end. For everything else, an import
|
|
@@ -12299,7 +12831,7 @@ Going back and then following a link drops the pages ahead of it, as the browser
|
|
|
12299
12831
|
those history entries.
|
|
12300
12832
|
|
|
12301
12833
|
-
|
|
12302
|
-
A page left with a
|
|
12834
|
+
A page left with a route open in a modal over
|
|
12303
12835
|
it is kept with the modal. Back to that entry shows the page and opens the modal over it
|
|
12304
12836
|
again.
|
|
12305
12837
|
|
|
@@ -12322,7 +12854,7 @@ them; reset in `onPageShow` what must start fresh.
|
|
|
12322
12854
|
|
|
12323
12855
|
-
|
|
12324
12856
|
Each kept page holds its DOM and its components' memory, at most three per tab. In
|
|
12325
|
-
development, the
|
|
12857
|
+
development, the devtools overlay lists them with their
|
|
12326
12858
|
path, how long each has been hidden and how many elements it renders.
|
|
12327
12859
|
|
|
12328
12860
|
### Fresh data
|
|
@@ -12333,14 +12865,14 @@ nothing below an unchanged value renders again, and form input in a list survive
|
|
|
12333
12865
|
`revalidate: false` to skip the reload; an action submitted while the page was
|
|
12334
12866
|
hidden still reloads it.
|
|
12335
12867
|
|
|
12336
|
-
A
|
|
12868
|
+
A partially prerendered page that is kept stops its
|
|
12337
12869
|
holes while it is hidden: a hole still loading is cancelled on the server, and a reload on its
|
|
12338
12870
|
way is dropped. When the page comes back each hole reloads in place, its old content marked
|
|
12339
12871
|
`aria-busy="true"` until the new arrives, with `revalidate: false` too.
|
|
12340
12872
|
An interactive hole keeps its state through it, in React as well, where
|
|
12341
12873
|
`<Activity>` cleans the page's effects up while it is hidden.
|
|
12342
12874
|
|
|
12343
|
-
With
|
|
12875
|
+
With live refresh, a hidden page is not watched. When it comes back,
|
|
12344
12876
|
what changed while it was hidden reloads, whatever `revalidate` says, and a grant
|
|
12345
12877
|
that expired in the meantime is loaded again.
|
|
12346
12878
|
|
|
@@ -12455,7 +12987,7 @@ export const clock = defineIsland((el) => {
|
|
|
12455
12987
|
})
|
|
12456
12988
|
```
|
|
12457
12989
|
|
|
12458
|
-
The
|
|
12990
|
+
The server components of a kept page stay mounted too.
|
|
12459
12991
|
With `bindComponentRouter` installed, navigation leaves them alone while the page
|
|
12460
12992
|
is hidden, and the reload of a page that comes back updates them.
|
|
12461
12993
|
|
|
@@ -12480,7 +13012,7 @@ main section { padding: 2rem; }
|
|
|
12480
13012
|
|
|
12481
13013
|
In development, the first time a kept page is shown the client reads the page's
|
|
12482
13014
|
same-origin stylesheets and reports each such selector once, as
|
|
12483
|
-
|
|
13015
|
+
NIFRA_KEEPALIVE_DIRECT_CHILD_CSS.
|
|
12484
13016
|
|
|
12485
13017
|
### Keep-alive and sign-in
|
|
12486
13018
|
|
|
@@ -12501,9 +13033,9 @@ A response that renews the same visitor's session keeps the epoch: a session coo
|
|
|
12501
13033
|
with a new lifetime, or an `@nifrajs/auth` session committed again with the same
|
|
12502
13034
|
data. Any change to an `@nifrajs/auth` session's data rotates it, in either mode,
|
|
12503
13035
|
so a sign-in or sign-out shows even when the session id stays the same. With
|
|
12504
|
-
|
|
13036
|
+
|
|
12505
13037
|
`identity`
|
|
12506
|
-
|
|
13038
|
+
|
|
12507
13039
|
set on `createSessions`, only a change to the keys it names rotates it, and a write
|
|
12508
13040
|
to a cart or a preference keeps it. An Auth.js session
|
|
12509
13041
|
read writes a new token every time; mounted through `@nifrajs/authjs`, it keeps
|
|
@@ -12527,7 +13059,7 @@ export const keepAlive = {
|
|
|
12527
13059
|
|
|
12528
13060
|
In development, an `HttpOnly` cookie that changes and is in neither list is
|
|
12529
13061
|
reported once, as
|
|
12530
|
-
|
|
13062
|
+
NIFRA_KEEPALIVE_IDENTITY_COOKIE. A flow
|
|
12531
13063
|
that changes who is signed in without changing a cookie rotates the epoch itself:
|
|
12532
13064
|
|
|
12533
13065
|
```ts
|
|
@@ -12627,7 +13159,7 @@ seed.
|
|
|
12627
13159
|
is your own name for a piece of data, such as `post:42`: a letter, then up to
|
|
12628
13160
|
127 of `A-Z a-z 0-9 . _ : / -`. A frame holds at most 64. A live load returns
|
|
12629
13161
|
an encrypted grant for its keys beside the data. A hole of a
|
|
12630
|
-
|
|
13162
|
+
partially prerendered page declares its own the
|
|
12631
13163
|
same way, and a change reloads that hole alone.
|
|
12632
13164
|
|
|
12633
13165
|
```ts
|
|
@@ -13316,7 +13848,7 @@ Past 5.0, 5.1 adds one change a frontend on another origin sees. A route with a
|
|
|
13316
13848
|
it. List that frontend's origin, or an identity provider's for a
|
|
13317
13849
|
`form_post` callback, in the `formOrigins` server option (an array of
|
|
13318
13850
|
exact origins or a function; `@nifrajs/edge` takes it too). JSON bodies are
|
|
13319
|
-
unchanged.
|
|
13851
|
+
unchanged. Security covers what the check leaves to
|
|
13320
13852
|
`csrf()`.
|
|
13321
13853
|
|
|
13322
13854
|
### 6. Run the release gates
|
|
@@ -13348,7 +13880,7 @@ rest needs a hand:
|
|
|
13348
13880
|
longer mounted. An islets `island("id", setup)` becomes
|
|
13349
13881
|
`bindIsland(setup)` passed to `mountIslands({ id })`, and a
|
|
13350
13882
|
nano signal is read by calling it (`count()`). See
|
|
13351
|
-
|
|
13883
|
+
Islands.
|
|
13352
13884
|
|
|
13353
13885
|
-
|
|
13354
13886
|
`withISR` over any store but `MemoryCacheStore` takes a
|
|
@@ -13464,8 +13996,8 @@ becomes a return.
|
|
|
13464
13996
|
1:1: `.get/.post` + a `t` schema, and an Eden-style typed client. You
|
|
13465
13997
|
gain Node / Deno / edge portability and an optional SSR frontend on five UI libraries.
|
|
13466
13998
|
|
|
13467
|
-
Then connect a database (
|
|
13468
|
-
full-stack, see
|
|
13999
|
+
Then connect a database (Database) and, if you're going
|
|
14000
|
+
full-stack, see Migrating a meta-framework.
|
|
13469
14001
|
|
|
13470
14002
|
## Nifra - Migrating from Next.js, Nuxt, SvelteKit & SolidStart
|
|
13471
14003
|
|
|
@@ -13522,26 +14054,26 @@ Nifra's client router - `Link` + hover/focus prefetch, scroll restoration
|
|
|
13522
14054
|
|
|
13523
14055
|
an action's `revalidate(paths, data, { tags })`, or
|
|
13524
14056
|
`revalidateEndpoint` for a webhook - see
|
|
13525
|
-
|
|
14057
|
+
SSG & ISR
|
|
13526
14058
|
|
|
13527
14059
|
Server Components · `"use client"`
|
|
13528
14060
|
|
|
13529
|
-
opt-in
|
|
14061
|
+
opt-in server components on all five adapters
|
|
13530
14062
|
|
|
13531
14063
|
Partial prerendering (Cache Components)
|
|
13532
14064
|
|
|
13533
14065
|
a `shellLoader` and holes - see
|
|
13534
|
-
|
|
14066
|
+
Partial prerendering
|
|
13535
14067
|
|
|
13536
14068
|
Intercepting routes (`(.)photo`)
|
|
13537
14069
|
|
|
13538
14070
|
a boundary with `{ intercept: "/photos/:id" }` - see
|
|
13539
|
-
|
|
14071
|
+
Opening a route in a modal
|
|
13540
14072
|
|
|
13541
14073
|
`keepalive` in `definePageMeta`
|
|
13542
14074
|
|
|
13543
14075
|
`export const keepAlive = true` - see
|
|
13544
|
-
|
|
14076
|
+
Keep-alive
|
|
13545
14077
|
|
|
13546
14078
|
### Data loading (Next.js → Nifra + React)
|
|
13547
14079
|
|
|
@@ -13594,16 +14126,16 @@ app.
|
|
|
13594
14126
|
|
|
13595
14127
|
-
|
|
13596
14128
|
**Much faster SSR** - the current dynamic-page snapshot reports Nifra at
|
|
13597
|
-
15× the throughput of Next.js,
|
|
13598
|
-
|
|
13599
|
-
of the client JavaScript. See
|
|
14129
|
+
15× the throughput of Next.js, 6.9× Nuxt, and
|
|
14130
|
+
4.1× SvelteKit / 2.6× SolidStart, with a fraction
|
|
14131
|
+
of the client JavaScript. See benchmarks.
|
|
13600
14132
|
|
|
13601
14133
|
-
|
|
13602
14134
|
**End-to-end types with no codegen**, the same app on Bun / Node / Deno / the edge, and a
|
|
13603
|
-
backend you can also ship on its own. Start with
|
|
14135
|
+
backend you can also ship on its own. Start with Getting started.
|
|
13604
14136
|
|
|
13605
14137
|
Moving a backend (Express, Hono, Fastify, Elysia) instead? See
|
|
13606
|
-
|
|
14138
|
+
Migrating a backend.
|
|
13607
14139
|
|
|
13608
14140
|
## Nifra - Migrate route by route
|
|
13609
14141
|
|
|
@@ -13631,7 +14163,7 @@ app. Mount before the plugin when the legacy app keeps its own auth.
|
|
|
13631
14163
|
A mounted fetch handler carries HTTP only. A WebSocket upgrade under the mount reaches it as
|
|
13632
14164
|
an ordinary request and never becomes a socket, so keep the legacy app's sockets on its own
|
|
13633
14165
|
server until they move to `app.ws()` routes (see
|
|
13634
|
-
|
|
14166
|
+
WebSockets in a composed app).
|
|
13635
14167
|
|
|
13636
14168
|
```ts
|
|
13637
14169
|
import { Hono } from "hono"
|
|
@@ -13842,7 +14374,7 @@ No span carries a request body, a job payload, an event payload, a raw cache key
|
|
|
13842
14374
|
Without a tracer configured, the cache and the queue run the code they ran before: no clock
|
|
13843
14375
|
reads, no events, no extra frames.
|
|
13844
14376
|
|
|
13845
|
-
## Nifra - Partial prerendering
|
|
14377
|
+
## Nifra - Partial prerendering
|
|
13846
14378
|
|
|
13847
14379
|
> Serve a page's shared frame from a cached shell at once, then stream each per-visitor part as its own loader settles. Shared holes, server components in holes, a store shared by processes, Deno and Workers, eligibility rules, the no-JavaScript limit, proxies and connection limits.
|
|
13848
14380
|
|
|
@@ -13850,9 +14382,6 @@ Most of a product page is the same for everyone: the title, the description, the
|
|
|
13850
14382
|
partially prerendered route serves that part from a cached shell at once, then streams each
|
|
13851
14383
|
per-visitor part, a hole, into it as its own loader settles.
|
|
13852
14384
|
|
|
13853
|
-
[!WARNING] Experimental. It is enabled through `experimental.ppr`, and its API may
|
|
13854
|
-
change in any release.
|
|
13855
|
-
|
|
13856
14385
|
### Set it up
|
|
13857
14386
|
|
|
13858
14387
|
`compileShells` bundles each route's shell and refuses one whose emitted code
|
|
@@ -13890,9 +14419,7 @@ export const app = createWebApp({
|
|
|
13890
14419
|
csp: createCspPolicy({
|
|
13891
14420
|
header: ({ sources }) => `script-src 'self' ${sources}; object-src 'none'; base-uri 'none'`,
|
|
13892
14421
|
}),
|
|
13893
|
-
|
|
13894
|
-
ppr: partialPrerendering({ shellChecks, origin: "https://shop.example" }),
|
|
13895
|
-
},
|
|
14422
|
+
ppr: partialPrerendering({ shellChecks, origin: "https://shop.example" }),
|
|
13896
14423
|
})
|
|
13897
14424
|
```
|
|
13898
14425
|
|
|
@@ -14093,7 +14620,14 @@ largest timeout plus one second, at most 30 seconds.
|
|
|
14093
14620
|
|
|
14094
14621
|
-
|
|
14095
14622
|
A layout above it may have a loader only as a `gate`: the gate runs to redirect
|
|
14096
|
-
or refuse, and its data reaches no response.
|
|
14623
|
+
or refuse, and its data reaches no response.
|
|
14624
|
+
|
|
14625
|
+
-
|
|
14626
|
+
A route may declare an intercepting boundary (a
|
|
14627
|
+
modal route) beside its holes. It is not a hole and
|
|
14628
|
+
is not counted against the limit above. The shell carries it unresolved; a client
|
|
14629
|
+
navigation to its URL opens the target over the page, which stays mounted with its holes
|
|
14630
|
+
filled.
|
|
14097
14631
|
|
|
14098
14632
|
-
|
|
14099
14633
|
`shellVariations` lists closed sets of query values that each select their own
|
|
@@ -14593,7 +15127,7 @@ its `compatibility_date`.
|
|
|
14593
15127
|
|
|
14594
15128
|
The browser side has the same property: the behavior belongs to React or the
|
|
14595
15129
|
browser, and Nifra only sits on top of it. Those entries live in the
|
|
14596
|
-
|
|
15130
|
+
frontend gotchas catalog (`nifra frontend`),
|
|
14597
15131
|
next to the per-framework reactivity cases:
|
|
14598
15132
|
|
|
14599
15133
|
-
|
|
@@ -14621,7 +15155,7 @@ each runtime, record the versions, and keep the cause to what the runtime does.
|
|
|
14621
15155
|
Which hardening each framework actually ships. A dimension-by-dimension read of Nifra's
|
|
14622
15156
|
security defaults against the **current releases** of Hono, Fastify, Express, and Elysia -
|
|
14623
15157
|
what is on by default, what is opt-in, and what is left to a third-party package. For how each
|
|
14624
|
-
Nifra primitive works, see
|
|
15158
|
+
Nifra primitive works, see Security & hardening.
|
|
14625
15159
|
|
|
14626
15160
|
### The honest verdict
|
|
14627
15161
|
|
|
@@ -15028,8 +15562,8 @@ claim; Express's ubiquity means every hire already knows it. Nifra's argument is
|
|
|
15028
15562
|
narrower and honest: it makes the dangerous configurations _unrepresentable_, ships the
|
|
15029
15563
|
hardening primitives first-party, and lets `nifra assure` prove in CI that every
|
|
15030
15564
|
route is guarded. For the full capability and throughput comparison, see
|
|
15031
|
-
|
|
15032
|
-
|
|
15565
|
+
vs other frameworks and the
|
|
15566
|
+
per-framework pages.
|
|
15033
15567
|
|
|
15034
15568
|
## Nifra - Security testing
|
|
15035
15569
|
|
|
@@ -15138,9 +15672,8 @@ Reaches the browser
|
|
|
15138
15672
|
`routes/x.tsx` (`.svelte`, `.vue`, `.mdx`)
|
|
15139
15673
|
|
|
15140
15674
|
a page: the component, `meta`,
|
|
15141
|
-
|
|
15675
|
+
|
|
15142
15676
|
`keepAlive`
|
|
15143
|
-
](/docs/keep-alive)
|
|
15144
15677
|
|
|
15145
15678
|
yes
|
|
15146
15679
|
|
|
@@ -15149,7 +15682,7 @@ yes
|
|
|
15149
15682
|
that page's `loader`, `action`, `loaderOutput`,
|
|
15150
15683
|
`actionOutput`, `hydrate`, `revalidate`,
|
|
15151
15684
|
`shellLoader` and `boundaryLoaders` (a
|
|
15152
|
-
|
|
15685
|
+
partially prerendered page),
|
|
15153
15686
|
`middleware` (in `_layout.backend.ts`)
|
|
15154
15687
|
|
|
15155
15688
|
never
|
|
@@ -15262,7 +15795,7 @@ Those commands, the contract lock and the route lints see only what
|
|
|
15262
15795
|
same app from `backend/app.ts` built with stand-in dependencies, so every operation
|
|
15263
15796
|
is visible without a database or secrets; `nifra check` names an implemented
|
|
15264
15797
|
operation it does not serve (NF-C039). See
|
|
15265
|
-
|
|
15798
|
+
the stand-in entry.
|
|
15266
15799
|
|
|
15267
15800
|
### A route is two files
|
|
15268
15801
|
|
|
@@ -15311,7 +15844,9 @@ and `Route.ComponentProps` types `data` as exactly what
|
|
|
15311
15844
|
`loaderOutput` lets through. `nifra dev`, `nifra build`,
|
|
15312
15845
|
`nifra check` and `nifra types` write these files under
|
|
15313
15846
|
`.nifra/types`; the app's `tsconfig.json` resolves them with
|
|
15314
|
-
`"rootDirs": [".", "./.nifra/types"]`.
|
|
15847
|
+
`"rootDirs": [".", "./.nifra/types"]`. The same directory holds
|
|
15848
|
+
`routes.d.ts`, one entry per URL pattern with its params and search output, and
|
|
15849
|
+
every generated `./+types` module loads it.
|
|
15315
15850
|
|
|
15316
15851
|
### What may import what
|
|
15317
15852
|
|
|
@@ -15455,9 +15990,9 @@ Whether it catches _undeclared extra_ fields depends on your validator, not on n
|
|
|
15455
15990
|
strict schema (`@nifrajs/schema`'s `t.object`) reports them and the
|
|
15456
15991
|
test fails, while a stripping one (Zod, Valibot) accepts them silently. To catch extras
|
|
15457
15992
|
regardless, or to stop them reaching the wire in production, use
|
|
15458
|
-
|
|
15993
|
+
|
|
15459
15994
|
`responseContract`
|
|
15460
|
-
|
|
15995
|
+
|
|
15461
15996
|
.
|
|
15462
15997
|
|
|
15463
15998
|
### Opaque schemas stay validator-neutral
|
|
@@ -15732,7 +16267,7 @@ more than one service, declare it with `defineContract` and connect handlers wit
|
|
|
15732
16267
|
`implement`. That keeps the contract type available without importing a server
|
|
15733
16268
|
implementation into the client.
|
|
15734
16269
|
|
|
15735
|
-
See
|
|
16270
|
+
See Framework contract for the decoupled form and its scaling
|
|
15736
16271
|
guidance.
|
|
15737
16272
|
|
|
15738
16273
|
The tooling reads the backend `backend/app.ts` exports. An app that
|
|
@@ -15800,7 +16335,7 @@ would refuse: backend code in a page, or a server package in browser code.
|
|
|
15800
16335
|
-
|
|
15801
16336
|
Validation only covers what you put in a schema. A raw-body, file-upload, or
|
|
15802
16337
|
bring-your-own-validation route reads the body directly - cap and validate those yourself
|
|
15803
|
-
(see
|
|
16338
|
+
(see Security's `c.boundedBody`).
|
|
15804
16339
|
|
|
15805
16340
|
-
|
|
15806
16341
|
The typed client infers from the server _type_, so it needs an
|
|
@@ -18947,9 +19482,12 @@ const app = server()
|
|
|
18947
19482
|
- **`rateLimit(options)`** - `429` + `Retry-After` + `RateLimit-*` headers, with a
|
|
18948
19483
|
pluggable `RateLimitStore`. The default bucket key is the caller IP the server resolved (the
|
|
18949
19484
|
socket peer, or the app's `clientIp` trust declaration behind a proxy); a custom `key`, trusted
|
|
18950
|
-
single-IP `header`, or `trustedProxies` overrides it.
|
|
18951
|
-
|
|
18952
|
-
|
|
19485
|
+
single-IP `header`, or `trustedProxies` overrides it. A configured header must contain exactly one
|
|
19486
|
+
valid IP; comma-separated or malformed values fall through to configured `trustedProxies` or
|
|
19487
|
+
`allowGlobalKey` fallbacks. Without a usable key or explicit global fallback, requests fail closed
|
|
19488
|
+
(`500`) instead of silently sharing one bucket. The bundled `MemoryStore` **refuses to run in
|
|
19489
|
+
production** (a per-instance limiter is unsafe across instances) - provide a shared store (Redis,
|
|
19490
|
+
etc.) there.
|
|
18953
19491
|
- **`cache({ store, ttlMs })` / `responseCache(...)`** - full response cache with a pluggable
|
|
18954
19492
|
store, `Vary`-aware keys, `Age`, byte caps, and `Cache-Control` / `Set-Cookie` safety defaults.
|
|
18955
19493
|
`MemoryResponseCache` is dev/single-instance only unless explicitly allowed in production.
|
|
@@ -20108,7 +20646,7 @@ done-gate, or `nifra mcp` to give the agent live project tools.
|
|
|
20108
20646
|
|
|
20109
20647
|
## @nifrajs/ts-plugin
|
|
20110
20648
|
|
|
20111
|
-
A TypeScript language-service plugin for [nifra](https://github.com/nifrajs/nifra). It adds go-to-definition on route-path string literals: put your cursor on `"/orders"` in `
|
|
20649
|
+
A TypeScript language-service plugin for [nifra](https://github.com/nifrajs/nifra). It adds go-to-definition on route-path string literals: put your cursor on `"/orders"` in `href({ to: "/orders" })`, `rawHref("/orders")`, or `<a href="/orders">`, and jump straight to the `routes/` file that serves it. A route-table pattern such as `"/users/:id"` resolves to its file too.
|
|
20112
20650
|
|
|
20113
20651
|
The routing rules are nifra's own - it discovers routes with `@nifrajs/web` and matches them with `@nifrajs/core`'s pattern matcher - so a path resolves to exactly the file it would serve at runtime, dynamic segments included (`/users/42` → `routes/users/[id].tsx`).
|
|
20114
20652
|
|
|
@@ -20194,8 +20732,8 @@ One package, the same on React, Preact, Vue, Solid and Svelte (pick the renderer
|
|
|
20194
20732
|
- Streaming SSR with `defer()`, SSG, and ISR with tag purges - [rendering](https://nifra.dev/docs/rendering).
|
|
20195
20733
|
- [Live refresh](https://nifra.dev/docs/live) (`@nifrajs/web/live`, `/live-client`, `/live-redis`):
|
|
20196
20734
|
loaders declare keys, a publish reloads only what read them.
|
|
20197
|
-
- [Partial prerendering](https://nifra.dev/docs/partial-prerendering) (`@nifrajs/web/ppr
|
|
20198
|
-
|
|
20735
|
+
- [Partial prerendering](https://nifra.dev/docs/partial-prerendering) (`@nifrajs/web/ppr`): a cached
|
|
20736
|
+
shell, with per-visitor holes streamed in.
|
|
20199
20737
|
- [Keep-alive](https://nifra.dev/docs/keep-alive) pages, a query cache, optimistic fetchers, and
|
|
20200
20738
|
[islands](https://nifra.dev/docs/islands) (`@nifrajs/web/islands`) for pages with no framework runtime.
|
|
20201
20739
|
- Optional [server components](https://nifra.dev/docs/server-components) on all five adapters:
|
|
@@ -20774,7 +21312,7 @@ done-gate, or `nifra mcp` to give the agent live project tools.
|
|
|
20774
21312
|
|
|
20775
21313
|
## @nifrajs/image
|
|
20776
21314
|
|
|
20777
|
-
`CloudflareLoaderOptions`, `HtmlImageAttrs`, `ImageFormat`, `ImageInfo`, `ImageLoader`, `ImageProps`, `OgImageOptions`, `OgImageRasterized`, `OgImageRasterizer`, `PngRenderer`, `ResolvedImage`, `ResvgConstructor`, `ResvgRenderer`, `SelfHostedLoaderOptions`, `SignImageUrlOptions`, `cloudflareLoader`, `createPngRasterizer`, `createResvgRasterizer`, `identityLoader`, `imageDimensions`, `ogImageResponse`, `readImageDimensions`, `renderOgImage`, `resolveImage`, `selfHostedLoader`, `signImageUrl`, `toHtmlAttrs`
|
|
21315
|
+
`CloudflareLoaderOptions`, `HtmlImageAttrs`, `ImageFormat`, `ImageInfo`, `ImageInputProps`, `ImageLoader`, `ImagePresentationProps`, `ImageProps`, `OgImageOptions`, `OgImageRasterized`, `OgImageRasterizer`, `PngRenderer`, `ResolvedImage`, `ResvgConstructor`, `ResvgRenderer`, `SelfHostedLoaderOptions`, `SignImageUrlOptions`, `StaticImageData`, `StaticImageProps`, `StaticImageVariant`, `cloudflareLoader`, `createPngRasterizer`, `createResvgRasterizer`, `identityLoader`, `imageDimensions`, `ogImageResponse`, `readImageDimensions`, `renderOgImage`, `resolveImage`, `selfHostedLoader`, `signImageUrl`, `toHtmlAttrs`
|
|
20778
21316
|
|
|
20779
21317
|
## @nifrajs/island-trigger
|
|
20780
21318
|
|
|
@@ -20846,7 +21384,7 @@ done-gate, or `nifra mcp` to give the agent live project tools.
|
|
|
20846
21384
|
|
|
20847
21385
|
## @nifrajs/web
|
|
20848
21386
|
|
|
20849
|
-
`ACTION_GLOBAL`, `Action`, `BOUNDARY_GLOBAL`, `BackendOnly`, `Blocker`, `BlockerController`, `BlockerFunction`, `BlockerLocation`, `BlockerState`, `Boundary`, `BoundaryDescriptor`, `BoundaryError`, `BoundaryLoaderEntry`, `BoundaryLoadersOf`, `BoundaryMode`, `BoundaryRegistration`, `BoundaryRequestCtx`, `BoundaryState`, `BoundaryStates`, `BoundaryStatus`, `BrowserNavigate`, `BuildAssetSet`, `CacheStore`, `CachedResponse`, `CdnPurgeOutcome`, `CdnPurgeTarget`, `ClientAction`, `ClientActionArgs`, `ClientActionResult`, `ClientLoader`, `ClientLoaderArgs`, `ClientRequestBody`, `ClientRouteHooks`, `ClientRouter`, `ClientRouterOptions`, `CreateCspPolicyOptions`, `CreateNonceResolverOptions`, `CreateWebAppOptions`, `CspHeaderContext`, `CspPolicy`, `CssLoadingMode`, `DATA_GLOBAL`, `DATA_HEADER`, `DEFAULT_CSS_LOADING`, `DEFAULT_DEV_PORT`, `DRAFT_COOKIE`, `DataText`, `Deferred`, `DehydratedState`, `DocumentParts`, `DraftCookieControls`, `DynamicBoundary`, `DynamicBoundaryBatch`, `EnableDraftOptions`, `FetchRouteData`, `Fetcher`, `FetcherState`, `FontDisplay`, `FontFace`, `FontPreloadInput`, `FontSource`, `GenerateClientEntryOptions`, `
|
|
21387
|
+
`ACTION_GLOBAL`, `Action`, `BOUNDARY_GLOBAL`, `BackendOnly`, `Blocker`, `BlockerController`, `BlockerFunction`, `BlockerLocation`, `BlockerState`, `Boundary`, `BoundaryDescriptor`, `BoundaryError`, `BoundaryLoaderEntry`, `BoundaryLoadersOf`, `BoundaryMode`, `BoundaryRegistration`, `BoundaryRequestCtx`, `BoundaryState`, `BoundaryStates`, `BoundaryStatus`, `BrowserNavigate`, `BuildAssetSet`, `CacheStore`, `CachedResponse`, `CdnPurgeOutcome`, `CdnPurgeTarget`, `ClientAction`, `ClientActionArgs`, `ClientActionResult`, `ClientLoader`, `ClientLoaderArgs`, `ClientRequestBody`, `ClientRouteHooks`, `ClientRouter`, `ClientRouterOptions`, `CreateCspPolicyOptions`, `CreateNonceResolverOptions`, `CreateWebAppOptions`, `CspHeaderContext`, `CspPolicy`, `CssLoadingMode`, `DATA_GLOBAL`, `DATA_HEADER`, `DEFAULT_CSS_LOADING`, `DEFAULT_DEV_PORT`, `DRAFT_COOKIE`, `DataText`, `Deferred`, `DehydrateOptions`, `DehydratedQueryInfo`, `DehydratedState`, `DocumentParts`, `DraftCookieControls`, `DynamicBoundary`, `DynamicBoundaryBatch`, `EnableDraftOptions`, `FetchRouteData`, `Fetcher`, `FetcherState`, `FontDisplay`, `FontFace`, `FontPreloadInput`, `FontSource`, `GenerateClientEntryOptions`, `GenerateServerManifestOptions`, `GetStaticPaths`, `HANDOVER_ID`, `HostPolicy`, `HostPolicyOptions`, `HostPolicyRule`, `Href`, `HrefOptions`, `HtmlSanitizer`, `IDLE_BLOCKER`, `ISRApp`, `ISROptions`, `ISRPlatform`, `ISRQuery`, `ISRStoreOp`, `ISR_REVALIDATE_HEADER`, `ISR_REVALIDATE_TAGS_HEADER`, `ISR_STATUS_HEADER`, `IdentityEpochContext`, `InertScriptType`, `InfiniteData`, `InfiniteQueryHandle`, `InfiniteQueryOptions`, `InterceptBoundary`, `Intercepted`, `KVCacheStore`, `KVCacheStoreOptions`, `KVNamespaceLike`, `KeepAliveOptions`, `KeepAliveServerOptions`, `KeptPage`, `LAYOUT_DATA_GLOBAL`, `LOCALES_GLOBAL`, `LayoutEntry`, `LinkDescriptor`, `LiveClientEntry`, `Loader`, `LoaderContext`, `LoaderResponseControls`, `LoadingEntry`, `Manifest`, `MatchChain`, `MemoryCacheStore`, `MemoryCacheStoreOptions`, `MemoryStaticBoundaryCache`, `Meta`, `MetaArgs`, `MetaDescriptor`, `MetaInput`, `MiddlewareOutcome`, `MountRouterOptions`, `MutationCallbacks`, `MutationCancelledError`, `MutationContext`, `MutationHandle`, `MutationState`, `MutationStatus`, `NAV_FROM_HEADER`, `NavigateFunction`, `NavigateOptions`, `NonceContext`, `NonceGenerator`, `NonceHeader`, `NonceHeaderContext`, `NonceResolver`, `NotFoundEntry`, `NotFoundScope`, `OpenGraphInput`, `PREFETCH_HEADER`, `PRE_HYDRATION_GUARD`, `PageLocale`, `PageLocales`, `PendingBoundary`, `PrefetchMode`, `PrerenderedPageReaderOptions`, `PrerenderedPages`, `PreviewEndpointOptions`, `QueryClient`, `QueryClientOptions`, `QueryHandle`, `QueryOptions`, `QueryState`, `QueryStatus`, `REDIRECT_HEADER`, `RETAIN_HEADER`, `REVALIDATE_HEADER`, `ROOT_ATTRIBUTE`, `ROUTE_GLOBAL`, `RedirectOptions`, `RenderAdapter`, `RenderAdapterConformanceError`, `RenderAdapterConformanceFixture`, `RenderAssemblyCache`, `RenderPageInput`, `RenderPageOptions`, `RenderProps`, `RenderStreamOptions`, `RenderedPage`, `RevalidateEndpointOptions`, `RevalidateOptions`, `RevalidateResult`, `RevalidateTags`, `RevalidateTagsInput`, `RouteEntry`, `RouteMatch`, `RouteMiddleware`, `RouteModule`, `RoutePattern`, `RouteSlotName`, `RouteSlotPatternsOf`, `RouteSlotRegistry`, `RouteSlotTarget`, `RouteTable`, `RouterState`, `SERVER_FN_MODULE`, `STATUS_HEADER`, `SanitizedHtml`, `ScriptDescriptor`, `SearchOf`, `SharedBoundary`, `SharedHoleCtx`, `ShellCtx`, `ShouldRevalidate`, `ShouldRevalidateArgs`, `SsrModuleLoader`, `StaticBoundary`, `StaticBoundaryCache`, `StaticBoundaryImportEdge`, `StaticBoundaryRoot`, `StaticCtx`, `StaticPath`, `StaticPaths`, `StaticRoutes`, `StatusPageOptions`, `Submission`, `SubmitOptions`, `TrustedHtml`, `UIMatch`, `UnsafeScriptDescriptor`, `WebAppI18n`, `assertCssLoadingCompatible`, `assertRenderAdapterConformance`, `assertStaticBoundaryImports`, `boundaryDescriptors`, `boundaryModeKey`, `buildManifest`, `canonical`, `closeBoundary`, `createClientRouter`, `createCspPolicy`, `createHostPolicy`, `createMatcher`, `createMutation`, `createNonceResolver`, `createQueryClient`, `createWebApp`, `defer`, `disableDraft`, `enableDraft`, `enumerateStaticRoutes`, `filePathToPattern`, `filePathToPatterns`, `fontFace`, `fontPreload`, `generateClientEntry`, `generateServerManifest`, `getBrowserNavigate`, `gone`, `hashQueryKey`, `href`, `isCacheablePage`, `isDraftEnabled`, `isHostPolicy`, `jsonLd`, `localeOfProps`, `mergeHeads`, `nifraScriptHashes`, `normalizeCssLoading`, `notFound`, `openGraph`, `pageLocaleIn`, `prerenderedPageReader`, `previewEndpoint`, `rawHref`, `redirect`, `registerBlocker`, `renderPage`, `renderPageResult`, `resolveChainMeta`, `resolveDynamicBoundaries`, `resolveMeta`, `resolvePublicPath`, `resolveStaticBoundaries`, `revalidate`, `revalidateEndpoint`, `rotateIdentityEpoch`, `sanitizeHtml`, `sanitizedHtml`, `searchOf`, `searchOfChain`, `serializeData`, `serializeSearch`, `setBlockerController`, `setBrowserNavigate`, `setSsrModuleLoader`, `ssrModuleLoader`, `startDynamicBoundaries`, `statusPage`, `trustHtml`, `unsafeInlineScript`, `webProjectEvidence`, `withISR`
|
|
20850
21388
|
|
|
20851
21389
|
## @nifrajs/web-preact
|
|
20852
21390
|
|