@nifrajs/cli 5.11.0 → 5.12.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.
@@ -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
- 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 +
297
+ 100% of Elysia on `GET /users/:id` and
298
+ 103% on the validated `POST` - and
299
+ **level with Fastify on Node** (108% of Fastify on GET,
300
+ 107% on the validated `POST`), with Elysia, Hono,
301
+ and Express behind. On **Deno** it runs at 107% of Elysia on
302
+ GET and 133% on the validated `POST`. In the realistic shape (security headers + CORS +
303
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
304
+ **Bun** with `oha`) Nifra runs at **109% of Elysia on GET and 113% on POST**. Treat benchmark
305
305
  rows as same-run evidence, not a permanent law of nature.
306
306
 
307
307
  -
@@ -1404,6 +1404,24 @@ export const app = server()
1404
1404
  })
1405
1405
  ```
1406
1406
 
1407
+ ### Static bodyless responses
1408
+
1409
+ For a route whose response is always empty, use `staticResponse()` instead of
1410
+ creating a `Response` in a handler on every request. Pass fixed status and headers
1411
+ to the helper; caller-supplied `Content-Length` and `Transfer-Encoding`
1412
+ are rejected. On Bun, a plain literal-path GET or HEAD route can use Bun's static response
1413
+ table when no request policy, validation, response middleware, or app-wide
1414
+ `.responseHeaders(...)` defaults need to run. Null-body status codes use the
1415
+ regular handler path to preserve framing on Bun 1.3. Otherwise Nifra keeps the regular route
1416
+ pipeline. `app.fetch` and other runtimes also produce a fresh response per call.
1417
+
1418
+ ```ts
1419
+ import { server, staticResponse } from "@nifrajs/core/server"
1420
+
1421
+ export const app = server().get("/health", staticResponse())
1422
+ app.listen(3000)
1423
+ ```
1424
+
1407
1425
  Prefer `c.set` over returning a raw `Response`. A `Response`
1408
1426
  return makes the typed client infer `data: never`, so you silently lose drift
1409
1427
  detection for that route (`nifra check` flags it, NF-C007). `c.set`
@@ -7372,7 +7390,7 @@ app.ws("/room/:id", {
7372
7390
 
7373
7391
  Bun, Deno, and Node are long-lived processes, so this works directly on a single instance.
7374
7392
  Across a load balancer, `app.publish` only reaches sockets on the same instance -
7375
- bridge an external fan-out (Redis pub/sub, NATS, a queue) to broadcast across all of them. On
7393
+ configure a `TopicAdapter` on `server()` to bridge a shared fan-out. On
7376
7394
  **Cloudflare Workers**, a stateless isolate can’t broadcast across connections,
7377
7395
  so Nifra ships a Durable Object hub: `createWebSocketHub(app)` holds the
7378
7396
  connections, and `toFetchHandler(app, { webSocketHub })` routes upgrades to it
@@ -7380,6 +7398,22 @@ connections, and `toFetchHandler(app, { webSocketHub })` routes upgrades to it
7380
7398
  upgrade request for a path with no WebSocket route still gets that path's HTTP answer, as on
7381
7399
  every other runtime.
7382
7400
 
7401
+ ```ts
7402
+ import { server } from "@nifrajs/core/server"
7403
+ import { websocket } from "@nifrajs/core/ws"
7404
+ import { sharedTopics } from "./shared-topics"
7405
+
7406
+ const app = server({ topicAdapter: sharedTopics })
7407
+ .use(websocket())
7408
+ .ws("/chat", { open: (ws) => ws.subscribe("room") })
7409
+
7410
+ await app.publish("room", "hello from any instance")
7411
+ ```
7412
+
7413
+ A `TopicAdapter` implements socket subscription cleanup and topic broadcasts. Its
7414
+ `publish` may return a promise; await `app.publish` when it does. The
7415
+ default in-process registry remains synchronous.
7416
+
7383
7417
  ```ts
7384
7418
  // doc-check: skip - Workers entry: a Durable Object hub holds the connections.
7385
7419
  import { toFetchHandler } from "@nifrajs/core/server"
@@ -8233,13 +8267,13 @@ library's `">=3.1.0"` floor never sets the version the upgrade
8233
8267
  starts from unless nothing else, installed or declared, names one.
8234
8268
 
8235
8269
  ```bash
8236
- nifra upgrade --list # the release targets this CLI knows
8237
- nifra upgrade 5.6.0 # dry-run: every planned edit, nothing written
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
8240
- bun install # install the new pins
8241
- nifra check # verify against them
8242
- nifra doctor # afterwards: no "mixed nifra versions" advisory left
8270
+ nifra upgrade --list # the release targets this CLI knows
8271
+ nifra upgrade 5.12.0 # dry-run: every planned edit, nothing written
8272
+ nifra upgrade 5.12.0 --write # apply; it verifies with nifra check once the target is installed
8273
+ # if pins were already bumped by hand, add --from <installed-version>
8274
+ bun install # install the new pins
8275
+ nifra check # verify against them
8276
+ nifra doctor # afterwards: no "mixed nifra versions" advisory left
8243
8277
  ```
8244
8278
 
8245
8279
  It is a dry-run until `--write`, and the same run twice makes no further edits. Once
@@ -13665,13 +13699,13 @@ each deploy adapter it uses.
13665
13699
 
13666
13700
  ## Nifra 5 upgrade guide - from 3.x, 4.x or an earlier 5.x
13667
13701
 
13668
- > Upgrade a Nifra 3.x or 4.x application to 5.0: the chained upgrade command, the frontend/backend layout move and its follow-ups, drafted output schemas, the backend's HTTP mount, the 5.0 defaults that changed, and the release gates. Then move a 5.x app to 5.6.
13702
+ > Upgrade a Nifra 3.x or 4.x application to 5.0, then move a 5.x app to the current Nifra release.
13669
13703
 
13670
13704
  Nifra 4.0 split every app into a frontend and a backend half, and 5.0 enforces the split and
13671
13705
  changes a handful of defaults. The upgrade command pins the packages and moves imports; the
13672
13706
  layout migration moves files; this guide covers what each leaves to you and how to tell a
13673
13707
  finished migration from one that needs a decision. An app already on 5.x skips to
13674
- [Moving to 5.6](#5-6).
13708
+ [The 5.6 migration details](#5-6).
13675
13709
 
13676
13710
  ### 1. Run the executable upgrade
13677
13711
 
@@ -13866,11 +13900,15 @@ If the project has `nifra.assurance.ts`, run `nifra assure --json`.
13866
13900
  Exercise the pages that load or post data, and every browser call to the backend, under
13867
13901
  `nifra dev` and against the production build.
13868
13902
 
13869
- ### Moving to 5.6
13903
+ ### The 5.6 migration details
13870
13904
 
13871
- An app already on 5.x moves with `nifra upgrade 5.6.0`, which prints every note
13872
- below with the rest of the release's. It moves the imports and dependencies itself; the
13873
- rest needs a hand:
13905
+ An app already on 5.x moves to the current release with
13906
+ the command below, which runs every recipe since its installed version. The 5.6 recipe moves
13907
+ its imports and dependencies; the follow-up changes below need a hand.
13908
+
13909
+ ```sh
13910
+ nifra upgrade 5.12.0
13911
+ ```
13874
13912
 
13875
13913
  -
13876
13914
  `@nifrajs/islets` and `@nifrajs/web/nano` merge into
@@ -13907,235 +13945,403 @@ tag name or inside `<script>`.
13907
13945
  A Svelte page receives `data` as the router published it, not a deep reactive
13908
13946
  proxy: copy what you edit into the page's own state.
13909
13947
 
13910
- ## Nifra - Migrating from Express, Hono, Fastify & Elysia
13948
+ ## Nifra - Migrating Express, Fastify, Hono & Elysia backends
13949
+
13950
+ > Move an Express, Fastify, Hono, or Elysia API to Nifra with direct route examples for routing, validation, responses, and deployment.
13911
13951
 
13912
- > Move a backend to Nifra: routing, middleware, validation, and body parsing map directly from Express, Hono, Fastify, and Elysia - and you gain a typed client, multi-runtime deploy, and optional SSR.
13952
+ Migrate an API from Express, Fastify, Hono, or Elysia. The route handlers become chainable
13953
+ Nifra routes; request validation becomes part of the route contract; and the same app can
13954
+ serve a typed client on Bun, Node, Deno, or an edge runtime.
13913
13955
 
13914
- Nifra's `server()` is a chainable, Web-standard router - the move from Express, Hono,
13915
- Fastify, or Elysia is mostly mechanical renames. What you gain: an end-to-end-typed client with
13916
- zero codegen, schema validation built into the route, the same app on Bun / Node / Deno / the
13917
- edge, and an SSR frontend whenever you want one.
13956
+ Keep your database, service layer, and domain logic. Move one endpoint at a time, translate
13957
+ its request and response shape, then point the existing frontend at the new endpoint. Nifra
13958
+ can stay backend-only or mount under a full-stack app. Use `t.looseObject` when
13959
+ you need to keep accepting undeclared body fields; `t.object` rejects them.
13918
13960
 
13919
- ### How the concepts map
13961
+ ### Map the backend primitives
13920
13962
 
13921
- Express / Hono / Fastify
13963
+ Express / Fastify / Hono / Elysia
13922
13964
  Nifra
13923
13965
 
13924
13966
  `app.get(path, handler)`
13967
+ `server().get(path, handler)`; path params are inferred from the path
13925
13968
 
13926
- `server().get(path, handler)` - chainable, fully type-inferred
13969
+ `req` / `reply` / framework context
13970
+ `c`, with `c.params`, `c.query`, `c.body`, and the Web Request
13927
13971
 
13928
- `req` / `res` · Hono `Context`
13972
+ `res.json(x)`, `reply.send(x)`, `c.json(x)`
13973
+ Return `x` for JSON, or return a Web `Response`
13929
13974
 
13930
- `c` - `c.req`, `c.params`, `c.query`; **return** a value (JSON) or a
13931
- `Response`
13975
+ JSON Schema, TypeBox, or validator middleware
13976
+ Declare `body`, `query`, or `params` with `t`; validated values are typed in the handler
13932
13977
 
13933
- `app.use(mw)` · Hono middleware
13978
+ Set a status or response header
13979
+ `c.set.status` and `c.set.headers`, or return a `Response`
13934
13980
 
13935
- `.use()` + the `@nifrajs/middleware` pack (CORS, auth, rate limit, …)
13981
+ Middleware and plugins
13982
+ `.use()` and the optional `@nifrajs/middleware` packages
13936
13983
 
13937
- `express.json()` / body parsing
13938
- built in - declare a schema and the parsed body is typed
13984
+ Generated client types or a separate SDK
13985
+ `client<typeof app>()` from `@nifrajs/client`, no codegen
13939
13986
 
13940
- Fastify JSON schema · `zod` middleware · Elysia `t`
13987
+ OpenAPI and interactive API docs
13988
+ Generate a document from the route schemas with `nifra openapi`
13941
13989
 
13942
- `{ body, query, params }` validated by `t` (TypeBox) or any
13943
- [Standard Schema](https://standardschema.dev)
13990
+ ### Express to Nifra
13944
13991
 
13945
- `res.json(x)` / `reply.send(x)` / `c.json(x)`
13992
+ Replace `req.params` with `c.params`, body-parser middleware with a
13993
+ route schema, and `res.status().json()` with `c.set.status` plus a
13994
+ returned value. Keep Express middleware only where it is still needed during a staged
13995
+ migration.
13946
13996
 
13947
- `return x`
13948
-
13949
- `app.listen(3000)`
13997
+ ```ts
13998
+ // Express
13999
+ import express from "express"
14000
+ const expressApp = express()
14001
+ expressApp.get("/users/:id", (req, res) => res.json({ id: req.params.id, name: "Ada" }))
14002
+ expressApp.post("/users", express.json(), (req, res) =>
14003
+ res.status(201).json({ id: crypto.randomUUID(), name: req.body.name }),
14004
+ )
13950
14005
 
13951
- `app.listen()` (Bun) · `@nifrajs/node` · `@nifrajs/deno` ·
13952
- `toFetchHandler` (edge)
14006
+ // Nifra
14007
+ import { server } from "@nifrajs/core/server"
14008
+ import { t } from "@nifrajs/schema"
13953
14009
 
13954
- OpenAPI plugins / swagger
13955
- generated from the same `t` schemas - no second source of truth
14010
+ export const app = server()
14011
+ .get("/users/:id", (c) => ({ id: c.params.id, name: "Ada" }))
14012
+ .post("/users", { body: t.looseObject({ name: t.string() }) }, (c) => {
14013
+ c.set.status = 201
14014
+ return { id: crypto.randomUUID(), name: c.body.name }
14015
+ })
14016
+ ```
13956
14017
 
13957
- ### Express → Nifra
14018
+ ### Fastify to Nifra
13958
14019
 
13959
- The handler returns its result instead of calling `res.json`, and validation moves
13960
- onto the route. The client then infers all of this for free.
14020
+ Move Fastify JSON Schema onto the route as Nifra's `body`,
14021
+ `query`, or `params` schema. Replace `reply.code().send()`
14022
+ with the response status and return value; move Fastify plugins to a Nifra plugin or
14023
+ `.use()` middleware where the behavior fits.
13961
14024
 
13962
14025
  ```ts
13963
- // Express
13964
- app.get("/users/:id", (req, res) => res.json({ id: req.params.id }))
13965
- app.post("/users", express.json(), (req, res) => res.status(201).json(create(req.body)))
14026
+ // Fastify
14027
+ import Fastify from "fastify"
14028
+ type UserParams = { id: string }
14029
+ type UserBody = { name: string }
14030
+ const fastify = Fastify()
14031
+ fastify.get<{ Params: UserParams }>("/users/:id", async (request, reply) =>
14032
+ reply.send({ id: request.params.id, name: "Ada" }),
14033
+ )
14034
+ fastify.post<{ Body: UserBody }>(
14035
+ "/users",
14036
+ {
14037
+ schema: {
14038
+ body: {
14039
+ type: "object",
14040
+ required: ["name"],
14041
+ properties: { name: { type: "string" } },
14042
+ },
14043
+ },
14044
+ },
14045
+ async (request, reply) =>
14046
+ reply.code(201).send({ id: crypto.randomUUID(), name: request.body.name }),
14047
+ )
13966
14048
 
13967
- // Nifra - return the value (or a Response); c is Web-standard; the body is parsed + validated
13968
- server()
13969
- .get("/users/:id", (c) => ({ id: c.params.id }))
13970
- .post("/users", { body: t.object({ name: t.string() }) }, (c) => create(c.body))
14049
+ // Nifra
14050
+ import { server } from "@nifrajs/core/server"
14051
+ import { t } from "@nifrajs/schema"
14052
+
14053
+ export const app = server()
14054
+ .get("/users/:id", (c) => ({ id: c.params.id, name: "Ada" }))
14055
+ .post("/users", { body: t.looseObject({ name: t.string() }) }, (c) => {
14056
+ c.set.status = 201
14057
+ return { id: crypto.randomUUID(), name: c.body.name }
14058
+ })
13971
14059
  ```
13972
14060
 
13973
- ### Hono → Nifra
14061
+ ### Hono to Nifra
13974
14062
 
13975
- The closest of the routers - `c.req.param("id")` becomes a typed
13976
- `c.params.id`, and you return the value rather than `c.json(...)`. Nifra
13977
- adds the typed client, schema validation, multi-runtime deploy, and (if you want it) SSR.
14063
+ The handler shape is close: `c.req.param("id")` becomes the typed
14064
+ `c.params.id`, and `c.json()` becomes a return. Move body parsing and
14065
+ validation into the route declaration so invalid input is rejected before the handler runs.
13978
14066
 
13979
14067
  ```ts
13980
14068
  // Hono
13981
- app.get("/users/:id", (c) => c.json({ id: c.req.param("id") }))
14069
+ import { Hono } from "hono"
14070
+ const legacy = new Hono()
14071
+ legacy
14072
+ .get("/users/:id", (c) => c.json({ id: c.req.param("id"), name: "Ada" }))
14073
+ .post("/users", async (c) => {
14074
+ const body = await c.req.json<{ name: string }>()
14075
+ return c.json({ id: crypto.randomUUID(), name: body.name }, 201)
14076
+ })
14077
+
14078
+ // Nifra
14079
+ import { server } from "@nifrajs/core/server"
14080
+ import { t } from "@nifrajs/schema"
13982
14081
 
13983
- // Nifra - nearly identical; params are a typed object, you return the value
13984
- server().get("/users/:id", (c) => ({ id: c.params.id }))
14082
+ export const app = server()
14083
+ .get("/users/:id", (c) => ({ id: c.params.id, name: "Ada" }))
14084
+ .post("/users", { body: t.looseObject({ name: t.string() }) }, (c) => {
14085
+ c.set.status = 201
14086
+ return { id: crypto.randomUUID(), name: c.body.name }
14087
+ })
13985
14088
  ```
13986
14089
 
13987
- ### Fastify & Elysia
14090
+ ### Elysia to Nifra
13988
14091
 
13989
- -
13990
- **Fastify** - its per-route JSON-schema validation maps directly to Nifra's
13991
- `{ body, query, params }`; plugins become Nifra plugins; `reply.send`
13992
- becomes a return.
14092
+ Both use a chainable route API and TypeBox-shaped schemas. In Nifra, import `t`
14093
+ from `@nifrajs/schema` and declare the schema beside the handler; the handler
14094
+ receives a typed context and returns its response. This keeps the route contract available
14095
+ to Nifra's inferred client and other adapters.
13993
14096
 
13994
- -
13995
- **Elysia** - the closest peer (Bun, typed, TypeBox `t`). The shapes are nearly
13996
- 1:1: `.get/.post` + a `t` schema, and an Eden-style typed client. You
13997
- gain Node / Deno / edge portability and an optional SSR frontend on five UI libraries.
14097
+ ```ts
14098
+ // Elysia
14099
+ import { Elysia, t as elysiaT } from "elysia"
14100
+ const legacy = new Elysia()
14101
+ .get("/users/:id", ({ params }) => ({ id: params.id, name: "Ada" }))
14102
+ .post(
14103
+ "/users",
14104
+ ({ body }) => ({ id: crypto.randomUUID(), name: body.name }),
14105
+ { body: elysiaT.Object({ name: elysiaT.String() }) },
14106
+ )
13998
14107
 
13999
- Then connect a database (Database) and, if you're going
14000
- full-stack, see Migrating a meta-framework.
14108
+ // Nifra
14109
+ import { server } from "@nifrajs/core/server"
14110
+ import { t } from "@nifrajs/schema"
14001
14111
 
14002
- ## Nifra - Migrating from Next.js, Nuxt, SvelteKit & SolidStart
14112
+ export const app = server()
14113
+ .get("/users/:id", (c) => ({ id: c.params.id, name: "Ada" }))
14114
+ .post("/users", { body: t.looseObject({ name: t.string() }) }, (c) => {
14115
+ return { id: crypto.randomUUID(), name: c.body.name }
14116
+ })
14117
+ ```
14003
14118
 
14004
- > Move from a meta-framework to Nifra: file routes, data loading, API routes, layouts, and SSG/ISR map across React (Next), Vue (Nuxt), Svelte (SvelteKit), and Solid (SolidStart).
14119
+ ### Connect the API to a frontend or another runtime
14005
14120
 
14006
- Nifra is framework-agnostic, so you keep your UI library and replace the meta-framework around
14007
- it: Next.js → Nifra + React, Nuxt → Nifra + Vue, SvelteKit → Nifra + Svelte, SolidStart → Nifra +
14008
- Solid. The concepts map one-to-one, and you can migrate incrementally - stand up Nifra's API
14009
- first, point your existing app at it, then move routes over.
14121
+ The backend app itself is fetch-compatible. A frontend can call it in-process during SSR
14122
+ with `inProcessClient(app)`, while `apiPrefix: "/api"` also mounts the
14123
+ routes at `/api/*` over HTTP. The prefix is passed through by default: set
14124
+ `apiStrip: true` to mount backend routes declared as `/users/*`, or
14125
+ declare their full `/api/users/*` paths. The same app can be served through Bun,
14126
+ `@nifrajs/node`, `@nifrajs/deno`, or an edge fetch handler.
14010
14127
 
14011
- ### How the concepts map
14128
+ For the UI migration, see
14129
+ Migrate a frontend. For route schemas,
14130
+ middleware, and deployment details, continue to
14131
+ API & typed client,
14132
+ Plugins & middleware, and
14133
+ Deployment.
14012
14134
 
14013
- Meta-framework concept
14014
- Nifra
14135
+ ## Nifra - Migrating React, Preact, Solid, Vue & Svelte apps
14015
14136
 
14016
- File routes (`pages/`, `app/`, `routes/`)
14137
+ > Migrate a Next.js, Remix, Preact, SolidStart, Nuxt, or SvelteKit frontend to Nifra while keeping React, Preact, Solid, Vue, or Svelte.
14017
14138
 
14018
- `routes/` - `.tsx` / `.vue` / `.svelte` / `.mdx`, same dynamic
14019
- `[param]` / `[...catch-all]` conventions
14139
+ Keep your UI framework and replace the meta-framework around it. Nifra has adapters for
14140
+ React, Preact, Solid, Vue, and Svelte; the routes, loaders, actions, and rendering features
14141
+ work the same across all five.
14020
14142
 
14021
- `getServerSideProps` · `load` · `createAsync` · `asyncData`
14143
+ This guide covers React apps from Next.js or Remix / React Router, Preact SSR apps, SolidStart,
14144
+ Nuxt, and SvelteKit. Move one route at a time: copy the view, move its server data work into
14145
+ the matching `.backend.ts` file, and let the loader schema define what reaches the
14146
+ browser.
14022
14147
 
14023
- `export async function loader()` in the route's `.backend.ts`
14024
- half - runs on the server, typed into the page through `loaderOutput`
14148
+ Scaffold the adapter you want with
14149
+ `bun create nifra my-app --framework react` (replace `react` with
14150
+ `preact`, `solid`, `vue`, or `svelte`). See
14151
+ Frameworks for adapter setup and file formats.
14025
14152
 
14026
- API routes (`pages/api`, `+server.ts`, route handlers)
14153
+ ### Map the route and data model
14027
14154
 
14028
- a `server()` backend + the typed client - no `fetch()` wrappers
14155
+ Starting point
14156
+ Nifra adapter and page
14157
+ Move server data to
14029
14158
 
14030
- Layouts (`layout.tsx`, `+layout`, `app.vue`)
14159
+ Next.js, Remix, React Router
14160
+ React, `routes/example.tsx`
14161
+ route `.backend.ts`
14031
14162
 
14032
- `_layout.tsx` - nested layout chains
14163
+ Preact SSR / Fresh
14164
+ Preact, `routes/example.tsx`
14165
+ route `.backend.ts`
14033
14166
 
14034
- Form actions / route handlers for mutations
14167
+ SolidStart
14168
+ Solid, `routes/example.tsx`
14169
+ route `.backend.ts`
14035
14170
 
14036
- `export async function action()` - typed, progressive-enhancement forms
14171
+ Nuxt
14172
+ Vue, `routes/example.vue`
14173
+ route `.backend.ts`
14037
14174
 
14038
- `getStaticProps` / `prerender` / `export const prerender`
14175
+ SvelteKit
14176
+ Svelte, `routes/example.svelte`
14177
+ route `.backend.ts`
14039
14178
 
14040
- `export const prerender = true` (SSG) + ISR via `withISR`
14179
+ A route is a view file plus its server half: for example
14180
+ `routes/users/[id].tsx` and `routes/users/[id].backend.ts`. Dynamic
14181
+ segments keep the `[param]` convention. Layouts move to
14182
+ `_layout.tsx` (or the matching adapter format); API handlers move to a
14183
+ `server()` backend and can be called in-process by loaders.
14041
14184
 
14042
- `<Link>` · `<NuxtLink>` · `<a data-sveltekit-preload>`
14043
- Nifra's client router - `Link` + hover/focus prefetch, scroll restoration
14185
+ ### Move data loading and mutations once
14044
14186
 
14045
- `next/image` · `nuxt/image`
14187
+ Replace `getServerSideProps`, route `loader` functions,
14188
+ `useAsyncData`, and `+page.server.ts` with the same Nifra loader. It
14189
+ runs on the server, calls your API in-process during SSR, and returns only fields allowed by
14190
+ `loaderOutput`. Put mutations in `action`; native forms still work
14191
+ without JavaScript and client submissions revalidate the page data.
14046
14192
 
14047
- `<Image>` from `@nifrajs/web-<fw>/image`
14193
+ ```ts
14194
+ // routes/users/[id].backend.ts - server-only data work, shared by every UI adapter
14195
+ import { t } from "@nifrajs/schema"
14196
+ import { notFound } from "@nifrajs/web"
14197
+ import type { Route } from "./+types/[id]"
14048
14198
 
14049
- `metadata` / `<Head>` / `definePageMeta`
14199
+ export const loaderOutput = t.object({ id: t.string(), name: t.string() })
14200
+ export const loader: Route.Loader = async ({ params, api }) => {
14201
+ const result = await api.users({ id: params.id }).get()
14202
+ if (!result.ok) {
14203
+ if (result.status === 404) throw notFound()
14204
+ throw new Error("User API request failed (" + result.status + ")")
14205
+ }
14206
+ return result.data
14207
+ }
14208
+ ```
14050
14209
 
14051
- `export const meta` (or a `meta()` function of the loader data)
14210
+ ### React - Next.js, Remix, and React Router
14052
14211
 
14053
- `revalidatePath` · `revalidateTag`
14212
+ Keep the React component. Move server fetching from a Next page, Server Component, or
14213
+ framework route loader into the paired backend file above. A route component receives typed
14214
+ `data` as a prop. Nifra does not require React Server Components; if you need them,
14215
+ they are an opt-in feature on the shared route model; see
14216
+ Server components.
14054
14217
 
14055
- an action's `revalidate(paths, data, { tags })`, or
14056
- `revalidateEndpoint` for a webhook - see
14057
- SSG & ISR
14218
+ ```tsx
14219
+ // routes/users/[id].tsx - React page, data is inferred from loaderOutput
14220
+ import type { Route } from "./+types/[id]"
14058
14221
 
14059
- Server Components · `"use client"`
14222
+ export default function User({ data }: Route.ComponentProps) {
14223
+ return <h1>{data.name}</h1>
14224
+ }
14225
+ ```
14060
14226
 
14061
- opt-in server components on all five adapters
14227
+ ### Preact - Preact SSR and Fresh
14062
14228
 
14063
- Partial prerendering (Cache Components)
14229
+ Keep Preact JSX and component state. Replace Fresh or custom SSR route data with the shared
14230
+ backend loader, then author the page as a `.tsx` route using the Preact adapter.
14231
+ Fresh-specific middleware and route conventions move to Nifra's backend and file routes.
14064
14232
 
14065
- a `shellLoader` and holes - see
14066
- Partial prerendering
14233
+ ```tsx
14234
+ /** @jsxImportSource preact */
14235
+ // routes/users/[id].tsx - Preact uses the same route and loader shape
14236
+ import type { Route } from "./+types/[id]"
14067
14237
 
14068
- Intercepting routes (`(.)photo`)
14238
+ export default function User({ data }: Route.ComponentProps) {
14239
+ return <h1>{data.name}</h1>
14240
+ }
14241
+ ```
14069
14242
 
14070
- a boundary with `{ intercept: "/photos/:id" }` - see
14071
- Opening a route in a modal
14243
+ ### Solid - SolidStart
14072
14244
 
14073
- `keepalive` in `definePageMeta`
14245
+ Keep Solid components and signals. Move SolidStart route data into the shared loader; the
14246
+ page stays a `.tsx` file, with the loader result passed through props.
14074
14247
 
14075
- `export const keepAlive = true` - see
14076
- Keep-alive
14248
+ ```tsx
14249
+ // routes/users/[id].tsx - keep Solid components and JSX
14250
+ import type { Route } from "./+types/[id]"
14077
14251
 
14078
- ### Data loading (Next.js → Nifra + React)
14252
+ export default function User(props: Route.ComponentProps) {
14253
+ return <h1>{props.data.name}</h1>
14254
+ }
14255
+ ```
14079
14256
 
14080
- The biggest change: data fetching becomes a typed `loader` that calls your backend
14081
- in-process during SSR - no `fetch` to your own API, no untyped JSON.
14257
+ ### Vue - Nuxt
14082
14258
 
14083
- ```tsx
14084
- // Next.js - app/users/[id]/page.tsx
14085
- export default async function Page({ params }) {
14086
- const res = await fetch(`https://api/users/${params.id}`)
14087
- const user = await res.json()
14088
- return <h1>{user.name}</h1>
14089
- }
14259
+ Move `useAsyncData` and server-only calls from Nuxt pages into the backend loader.
14260
+ Keep the template and author the Nifra route as a Vue Single-File Component. Its frontmatter
14261
+ exports live in the plain `<script>`; component props and markup live in
14262
+ `<script setup>` and `<template>`.
14090
14263
 
14091
- // Nifra - routes/users/[id].backend.ts: the loader, which never reaches the browser
14092
- export const loaderOutput = t.object({ name: t.string() }) // the only fields the page receives
14093
- export async function loader({ params, api }: Route.LoaderArgs) {
14094
- const res = await api.users({ id: params.id }).get() // typed, in-process during SSR
14095
- if (!res.ok) throw notFound()
14096
- return res.data
14097
- }
14264
+ ```vue
14265
+ <!-- routes/users/[id].vue - the view stays a Vue Single-File Component -->
14266
+ <script setup lang="ts">
14267
+ const props = defineProps<{ data: { id: string; name: string } }>()
14268
+ </script>
14098
14269
 
14099
- // Nifra - routes/users/[id].tsx: the page
14100
- export default function User({ data }: Route.ComponentProps) {
14101
- return <h1>{data.name}</h1>
14102
- }
14270
+ <template>
14271
+ <h1>{{ props.data.name }}</h1>
14272
+ </template>
14103
14273
  ```
14104
14274
 
14105
- ### Svelte / Solid / Vue
14275
+ ### Svelte - SvelteKit
14106
14276
 
14107
- Identical shape - only the page file's extension and component syntax change. The route's
14108
- `.backend.ts` half (`loader`, `action`,
14109
- `loaderOutput`) is the same file on every framework (that's Nifra's render seam).
14110
- SvelteKit's `+page.server.ts` maps onto it one to one:
14277
+ Move `+page.server.ts` data loading to the paired backend file. Keep the
14278
+ `+page.svelte` markup and component logic in a Nifra `.svelte` route;
14279
+ Svelte 5 receives route data through `$props()`.
14111
14280
 
14112
- ```ts
14113
- // SvelteKit - +page.server.ts + +page.svelte
14114
- export async function load({ params }) { return { post: await getPost(params.slug) } }
14281
+ ```svelte
14282
+ <!-- routes/users/[id].svelte - Svelte 5 props -->
14283
+ <script lang="ts">
14284
+ let { data }: { data: { id: string; name: string } } = $props()
14285
+ </script>
14115
14286
 
14116
- // Nifra - routes/blog/[slug].backend.ts + routes/blog/[slug].svelte
14117
- export const loaderOutput = t.object({ post: t.object({ title: t.string(), html: t.string() }) })
14118
- export async function loader({ params }: Route.LoaderArgs) { return { post: await getPost(params.slug) } }
14287
+ <h1>{data.name}</h1>
14119
14288
  ```
14120
14289
 
14121
- ### What Nifra adds
14290
+ ### Map the rest of your frontend
14122
14291
 
14123
- -
14124
- **One model, any UI library** - switch React→Solid later by changing one import, not your
14125
- app.
14292
+ Existing feature
14293
+ Nifra equivalent
14126
14294
 
14127
- -
14128
- **Much faster SSR** - the current dynamic-page snapshot reports Nifra at
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.
14295
+ Nested layouts
14296
+ `_layout.tsx` or the adapter's layout format; parent data is shared with child routes
14132
14297
 
14133
- -
14134
- **End-to-end types with no codegen**, the same app on Bun / Node / Deno / the edge, and a
14135
- backend you can also ship on its own. Start with Getting started.
14298
+ API route handlers
14299
+ A `server()` backend; loaders can use its typed client directly during SSR
14300
+
14301
+ Form actions and mutations
14302
+ Route `action` plus native form POST; client submissions revalidate loader data
14303
+
14304
+ Static generation and ISR
14305
+ `prerender = true` for SSG; `withISR` for revalidation
14306
+
14307
+ Metadata and document head
14308
+ Named `meta` export, or a function of the loader data
14309
+
14310
+ Link prefetch and scroll restore
14311
+ Nifra's client router and `Link`, with hover/focus prefetch and scroll restoration
14312
+
14313
+ Image components
14314
+ `Image` from `@nifrajs/web-<framework>/image`
14315
+
14316
+ Tag or path revalidation
14317
+ An action's `revalidate(paths, data, { tags })` or `revalidateEndpoint` for a webhook
14318
+
14319
+ Partial prerendering
14320
+ `shellLoader` and boundary loaders; see Partial prerendering
14321
+
14322
+ Intercepted modal routes
14323
+ A route boundary with an `intercept` target; see Modal routes
14324
+
14325
+ Keep-alive pages
14326
+ `keepAlive = true`; see Keep-alive
14327
+
14328
+ ### What stays the same across adapters
14329
+
14330
+ - Nested routes, layouts, metadata, forms, streaming, SSG, and ISR use the shared route model.
14331
+
14332
+ - Route loaders and actions stay server-only; output schemas bound the data sent to the browser.
14333
+
14334
+ - Switching among React, Preact, Solid, Vue, and Svelte changes the adapter and view syntax, not your backend contract.
14335
+
14336
+ Moving an API server too? See
14337
+ Migrate a backend. For the full
14338
+ rendering and route model, see Loaders & actions
14339
+ and Routing.
14136
14340
 
14137
- Moving a backend (Express, Hono, Fastify, Elysia) instead? See
14138
- Migrating a backend.
14341
+ The current dynamic SSR snapshot reports Nifra at 18× the throughput
14342
+ of Next.js, 7.9× Nuxt, 5.3× SvelteKit, and
14343
+ 2.7× SolidStart on the measured pages. See the
14344
+ benchmark methodology and full results.
14139
14345
 
14140
14346
  ## Nifra - Migrate route by route
14141
14347
 
@@ -21276,7 +21482,7 @@ done-gate, or `nifra mcp` to give the agent live project tools.
21276
21482
 
21277
21483
  ## @nifrajs/core
21278
21484
 
21279
- `AdmissionController`, `AdmissionDecision`, `AnyServer`, `AuthHeaders`, `AuthMaybePromise`, `AuthenticationFailure`, `AuthenticationFailureReason`, `AuthenticationInput`, `AuthenticationResult`, `AuthenticationStage`, `AuthenticationSuccess`, `Context`, `ContextPlugin`, `CookieOptions`, `CookieSecret`, `DeclaredMountRoute`, `DefinePluginResult`, `DurableObjectNamespaceLike`, `ExecutionContext`, `FRAMEWORK_NAME`, `FetchApp`, `FrameworkError`, `FrameworkName`, `Handler`, `IdentityPlugin`, `InferInput`, `InferOutput`, `JoinRoutePath`, `LambdaEvent`, `LambdaHandler`, `LambdaResponse`, `LambdaV1Event`, `LambdaV2Event`, `ListenTlsOptions`, `LogFields`, `Logger`, `METHODS`, `McpPromptDescriptor`, `McpResourceDescriptor`, `Method`, `Middleware`, `MountFetchOptions`, `MountOptions`, `MountableApp`, `NetlifyEvent`, `NetlifyHandler`, `NifraFeatureVersion`, `NifraPlugin`, `NifraWebSocket`, `NodeRequestContext`, `NodeRequestHook`, `NodeResponseBodyHook`, `NodeResponseContext`, `NodeResponseHook`, `NodeServeOutcome`, `OnRequestResult`, `OpaqueMountDeclaration`, `Params`, `PlainRender`, `Platform`, `PlatformResponse`, `PluginTypeCollapsed`, `PrefixRegistry`, `Prettify`, `PromptArgument`, `PromptMessage`, `ROUTE_PATTERN_OVERLAP_MAX_STATES`, `RedactOptions`, `Registry`, `RequestLocal`, `RequestPath`, `ResponseBodyHook`, `ResponseBodyReplacement`, `ResponseControls`, `ResponseFinalization`, `ResponseHeadersHook`, `ResponseHeadersView`, `ResponseMapFor`, `ResponseResult`, `RouteConfigError`, `RouteConfigErrorCode`, `RouteDescriptor`, `RouteInfo`, `RouteInfoFor`, `RouteMethod`, `RoutePatternOverlapLimitError`, `RouteSchema`, `Router`, `RouterMatch`, `RunningServer`, `SSEContext`, `SSEInit`, `SSEMessage`, `SSEStream`, `ScheduledController`, `ScheduledHandler`, `Server`, `ServerOptions`, `StandardIssue`, `StandardResult`, `StandardSchemaV1`, `StandardTypes`, `StandardWebSocket`, `StatusResponse`, `ToolAnnotations`, `TypedSSEStream`, `UrlParts`, `VERSION`, `ValidationOutcome`, `VercelHandler`, `Version`, `WebSocketContext`, `WebSocketData`, `WebSocketHandler`, `WebSocketUpgradeOutcome`, `authenticated`, `beforeHandler`, `carryRequestLocals`, `commonSecretPatterns`, `cookieNamePrefix`, `defineContextPlugin`, `defineIdentityPlugin`, `definePlugin`, `defineRouterPlugin`, `hasDuplicateCookie`, `isAuthenticatedRequest`, `isSameOriginForm`, `isSameOriginPath`, `isSameOriginRequest`, `jsonLogger`, `markAuthenticatedRequest`, `parseCookies`, `pathnameOf`, `redactLogFields`, `rejected`, `replacedRequestOf`, `requestLocal`, `routePatternOverlap`, `routeTemplateOf`, `serializeCookie`, `server`, `signValue`, `silentLogger`, `status`, `toFetchHandler`, `toLambdaHandler`, `toNetlifyHandler`, `toVercelHandler`, `unsignValue`, `urlPartsOf`, `varyOn`, `writableResponse`
21485
+ `AdmissionController`, `AdmissionDecision`, `AnyServer`, `AuthHeaders`, `AuthMaybePromise`, `AuthenticationFailure`, `AuthenticationFailureReason`, `AuthenticationInput`, `AuthenticationResult`, `AuthenticationStage`, `AuthenticationSuccess`, `Context`, `ContextPlugin`, `CookieOptions`, `CookieSecret`, `DeclaredMountRoute`, `DefinePluginResult`, `DurableObjectNamespaceLike`, `ExecutionContext`, `FRAMEWORK_NAME`, `FetchApp`, `FrameworkError`, `FrameworkName`, `Handler`, `IdentityPlugin`, `InferInput`, `InferOutput`, `JoinRoutePath`, `LambdaEvent`, `LambdaHandler`, `LambdaResponse`, `LambdaV1Event`, `LambdaV2Event`, `ListenTlsOptions`, `LogFields`, `Logger`, `METHODS`, `McpPromptDescriptor`, `McpResourceDescriptor`, `Method`, `Middleware`, `MountFetchOptions`, `MountOptions`, `MountableApp`, `NetlifyEvent`, `NetlifyHandler`, `NifraFeatureVersion`, `NifraPlugin`, `NifraWebSocket`, `NodeRequestContext`, `NodeRequestHook`, `NodeResponseBodyHook`, `NodeResponseContext`, `NodeResponseHook`, `NodeServeOutcome`, `OnRequestResult`, `OpaqueMountDeclaration`, `Params`, `PlainRender`, `Platform`, `PlatformResponse`, `PluginTypeCollapsed`, `PrefixRegistry`, `Prettify`, `PromptArgument`, `PromptMessage`, `ROUTE_PATTERN_OVERLAP_MAX_STATES`, `RedactOptions`, `Registry`, `RequestLocal`, `RequestPath`, `ResponseBodyHook`, `ResponseBodyReplacement`, `ResponseControls`, `ResponseFinalization`, `ResponseHeadersHook`, `ResponseHeadersView`, `ResponseMapFor`, `ResponseResult`, `RouteConfigError`, `RouteConfigErrorCode`, `RouteDescriptor`, `RouteInfo`, `RouteInfoFor`, `RouteMethod`, `RoutePatternOverlapLimitError`, `RouteSchema`, `Router`, `RouterMatch`, `RunningServer`, `SSEContext`, `SSEInit`, `SSEMessage`, `SSEStream`, `ScheduledController`, `ScheduledHandler`, `Server`, `ServerOptions`, `StandardIssue`, `StandardResult`, `StandardSchemaV1`, `StandardTypes`, `StandardWebSocket`, `StatusResponse`, `ToolAnnotations`, `TopicAdapter`, `TypedSSEStream`, `UrlParts`, `VERSION`, `ValidationOutcome`, `VercelHandler`, `Version`, `WebSocketContext`, `WebSocketData`, `WebSocketHandler`, `WebSocketUpgradeOutcome`, `authenticated`, `beforeHandler`, `carryRequestLocals`, `commonSecretPatterns`, `cookieNamePrefix`, `defineContextPlugin`, `defineIdentityPlugin`, `definePlugin`, `defineRouterPlugin`, `hasDuplicateCookie`, `isAuthenticatedRequest`, `isSameOriginForm`, `isSameOriginPath`, `isSameOriginRequest`, `jsonLogger`, `markAuthenticatedRequest`, `parseCookies`, `pathnameOf`, `redactLogFields`, `rejected`, `replacedRequestOf`, `requestLocal`, `routePatternOverlap`, `routeTemplateOf`, `serializeCookie`, `server`, `signValue`, `silentLogger`, `staticResponse`, `status`, `toFetchHandler`, `toLambdaHandler`, `toNetlifyHandler`, `toVercelHandler`, `unsignValue`, `urlPartsOf`, `varyOn`, `writableResponse`
21280
21486
 
21281
21487
  ## @nifrajs/cron
21282
21488