@nifrajs/cli 5.2.0 → 5.4.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 +125 -0
- package/dist/assure-hydration.d.ts.map +1 -1
- package/dist/assure-hydration.js +6 -2
- package/dist/assure-hydration.js.map +1 -1
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +2 -0
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +9 -3
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +61 -24
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +3 -3
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +22 -14
- package/dist/cli.js.map +1 -1
- package/dist/db-tool.d.ts.map +1 -1
- package/dist/db-tool.js +2 -1
- package/dist/db-tool.js.map +1 -1
- package/dist/env-file.d.ts.map +1 -1
- package/dist/env-file.js +41 -8
- package/dist/env-file.js.map +1 -1
- package/dist/internal/source-facts.d.ts +20 -4
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +248 -32
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/mcp-exec.d.ts +1 -0
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +11 -3
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-io.d.ts +23 -3
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +59 -12
- package/dist/mcp-io.js.map +1 -1
- package/dist/mcp-isolate.d.ts.map +1 -1
- package/dist/mcp-isolate.js +2 -1
- package/dist/mcp-isolate.js.map +1 -1
- package/dist/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +1 -0
- package/dist/migrate-layout.js.map +1 -1
- package/dist/recipes/5.3.0.d.ts +11 -0
- package/dist/recipes/5.3.0.d.ts.map +1 -0
- package/dist/recipes/5.3.0.js +35 -0
- package/dist/recipes/5.3.0.js.map +1 -0
- package/dist/recipes/5.4.0.d.ts +10 -0
- package/dist/recipes/5.4.0.d.ts.map +1 -0
- package/dist/recipes/5.4.0.js +25 -0
- package/dist/recipes/5.4.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 +2 -0
- package/dist/review.js.map +1 -1
- package/dist/rules/codes.d.ts +2 -0
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +2 -0
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/explanations.d.ts.map +1 -1
- package/dist/rules/explanations.js +12 -2
- package/dist/rules/explanations.js.map +1 -1
- package/dist/rules/pages.d.ts +25 -1
- package/dist/rules/pages.d.ts.map +1 -1
- package/dist/rules/pages.js +149 -33
- package/dist/rules/pages.js.map +1 -1
- package/dist/rules/route-statement.d.ts +10 -0
- package/dist/rules/route-statement.d.ts.map +1 -0
- package/dist/rules/route-statement.js +150 -0
- package/dist/rules/route-statement.js.map +1 -0
- package/dist/upgrade.d.ts +43 -10
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +161 -45
- package/dist/upgrade.js.map +1 -1
- package/docs/llms-full.txt +508 -190
- package/docs/types.json +217 -31
- package/package.json +11 -11
- package/src/assure-hydration.ts +7 -1
- package/src/check-diagnostics.ts +2 -0
- package/src/check-scan.ts +64 -25
- package/src/check.ts +8 -3
- package/src/cli.ts +22 -14
- package/src/db-tool.ts +2 -0
- package/src/env-file.ts +42 -7
- package/src/internal/source-facts.ts +312 -39
- package/src/mcp-exec.ts +13 -2
- package/src/mcp-http.ts +1 -1
- package/src/mcp-io.ts +72 -12
- package/src/mcp-isolate.ts +2 -0
- package/src/migrate-layout.ts +1 -0
- package/src/recipes/5.3.0.ts +36 -0
- package/src/recipes/5.4.0.ts +26 -0
- package/src/recipes/index.ts +4 -0
- package/src/review.ts +2 -0
- package/src/rules/codes.ts +2 -0
- package/src/rules/explanations.ts +12 -2
- package/src/rules/pages.ts +193 -33
- package/src/rules/route-statement.ts +170 -0
- package/src/upgrade.ts +202 -47
package/docs/llms-full.txt
CHANGED
|
@@ -235,33 +235,15 @@ to full-stack later without a rewrite.
|
|
|
235
235
|
-
|
|
236
236
|
**Throughput - the realistic case.** Router micro-benchmarks flatter Hono (a single compiled
|
|
237
237
|
regex), but a real request also pays for middleware and validation,
|
|
238
|
-
context, and serialization. In the current matrix
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
**leads the framework field too** - at
|
|
246
|
-
percentOf(
|
|
247
|
-
httpWorkloadRps("Node", "Nifra", "postUsers"),
|
|
248
|
-
httpWorkloadRps("Node", "Fastify", "postUsers"),
|
|
249
|
-
of Fastify on the validated `POST` ({formatPercent(
|
|
250
|
-
percentOf(
|
|
251
|
-
httpWorkloadRps("Node", "Nifra", "postUsers"),
|
|
252
|
-
httpWorkloadRps("Node", "node-raw", "postUsers"),
|
|
253
|
-
)} of the raw-Node ceiling) and ahead on GET, with Elysia, Hono,
|
|
254
|
-
and Express behind. In the realistic shape (security headers + CORS +
|
|
238
|
+
context, and serialization. In the current matrix Nifra runs **level with Elysia on Bun** -
|
|
239
|
+
101% of Elysia on `GET /users/:id` and
|
|
240
|
+
101% on the validated `POST` - and
|
|
241
|
+
**level with Fastify on Node** (98% of Fastify on GET,
|
|
242
|
+
101% on the validated `POST`), with Elysia, Hono,
|
|
243
|
+
and Express behind. On **Deno** it runs at 97% of Elysia on
|
|
244
|
+
GET and 114% on the validated `POST`. In the realistic shape (security headers + CORS +
|
|
255
245
|
bearer auth + cookies + validated query/body + a ~2.4 KB JSON response, measured with
|
|
256
|
-
`oha`) Nifra runs at **
|
|
257
|
-
percentOf(
|
|
258
|
-
httpRealworldRps("Bun", "Nifra", "get"),
|
|
259
|
-
httpRealworldRps("Bun", "Elysia", "get"),
|
|
260
|
-
)} of Elysia on GET and {formatPercent(
|
|
261
|
-
percentOf(
|
|
262
|
-
httpRealworldRps("Bun", "Nifra", "post"),
|
|
263
|
-
httpRealworldRps("Bun", "Elysia", "post"),
|
|
264
|
-
)} on POST**. Treat benchmark
|
|
246
|
+
`oha`) Nifra runs at **98% of Elysia on GET and 99% on POST**. Treat benchmark
|
|
265
247
|
rows as same-run evidence, not a permanent law of nature.
|
|
266
248
|
|
|
267
249
|
-
|
|
@@ -1054,9 +1036,12 @@ Prefer `c.set` over returning a raw `Response`. A `Response`
|
|
|
1054
1036
|
return makes the typed client infer `data: never`, so you silently lose drift
|
|
1055
1037
|
detection for that route (`nifra check` flags it, NF-C007). `c.set`
|
|
1056
1038
|
keeps your plain-object return fully typed. The check reads the functions a route
|
|
1057
|
-
registration
|
|
1058
|
-
|
|
1059
|
-
|
|
1039
|
+
registration (on `server()` or `createWebApp()`) or an
|
|
1040
|
+
`implement()` map passes, and a local function one returns a call to. It counts a
|
|
1041
|
+
`Response` held in a local before it is returned, a handler's
|
|
1042
|
+
`c.json()`/`c.text()`, and a call to a function imported from a
|
|
1043
|
+
relative module that returns one, reported at each route that returns it. A helper that
|
|
1044
|
+
answers an auth stage, or a handler registered from a list of route objects, is not read.
|
|
1060
1045
|
|
|
1061
1046
|
A `Response` a handler or hook returns or throws still gets the
|
|
1062
1047
|
`c.set.headers` it lacks and the queued cookies, so a guard's
|
|
@@ -1089,6 +1074,10 @@ and queued cookies still apply. On the typed client, checking `res.status === 40
|
|
|
1089
1074
|
narrows `res.data` to the declared 409 body; a status the route does not declare
|
|
1090
1075
|
falls into one arm whose `data` is `unknown`.
|
|
1091
1076
|
|
|
1077
|
+
The code may be a runtime value. Typed as a literal union (`200 | 409`), it splits
|
|
1078
|
+
into one arm per code. Typed as plain `number`, it cannot be sorted into success
|
|
1079
|
+
or error, so its body types `res.data`: a 2xx from that return can only carry it.
|
|
1080
|
+
|
|
1092
1081
|
```ts
|
|
1093
1082
|
import { client } from "@nifrajs/client"
|
|
1094
1083
|
import { server, status } from "@nifrajs/core/server"
|
|
@@ -1152,7 +1141,7 @@ A strict `t.object` here would reject real traffic. A signed cookie arrives as i
|
|
|
1152
1141
|
|
|
1153
1142
|
A `headers` schema is validated before the handler like the other slots: a missing
|
|
1154
1143
|
or malformed header is a `422` (`onValidationError` receives the kind
|
|
1155
|
-
`"headers"`), and `c.headers` becomes the schema
|
|
1144
|
+
`"headers"`), and `c.headers` becomes the schema's typed output.
|
|
1156
1145
|
Every client sends headers no route declares - `host`, `user-agent`,
|
|
1157
1146
|
`accept` - so a closed `t.object` validates only the names it declares,
|
|
1158
1147
|
each read case-insensitively, which is also how the OpenAPI document lists them: one
|
|
@@ -1303,6 +1292,16 @@ await api.users({ id: "1" }).posts({ postId: "2" }).get() // nested params
|
|
|
1303
1292
|
await api.files("report.json").get() // /files/:name.json → the segment as sent
|
|
1304
1293
|
```
|
|
1305
1294
|
|
|
1295
|
+
**Chain the routes the client calls.** Each registration returns a new type that records
|
|
1296
|
+
its route, so `typeof app` holds only the routes chained onto the expression
|
|
1297
|
+
`app` is assigned from. `app.get("/x", handler)` written as a
|
|
1298
|
+
statement of its own still serves `/x`, but the client has no call for it. Chain
|
|
1299
|
+
the registration, or declare the routes on their own `server()` and
|
|
1300
|
+
`merge()` it. `nifra check` reports such a statement on a server whose
|
|
1301
|
+
type is exported or read by `typeof` (NF-C045, advisory). The same holds for
|
|
1302
|
+
`createWebApp`: its type holds the routes chained onto it, and the routes of the
|
|
1303
|
+
`api` it mounts keep their type on that backend server.
|
|
1304
|
+
|
|
1306
1305
|
A segment that is part literal, part param - `/files/:name.json`,
|
|
1307
1306
|
`/post-:id`, `/v:major.:minor` - has no single param to name, so it is
|
|
1308
1307
|
called with the segment as the request carries it: `api.files("report.json")`,
|
|
@@ -1942,6 +1941,15 @@ const paths = prerendered.map((p) => p.path)
|
|
|
1942
1941
|
Bun.write("./dist/_routes.json", JSON.stringify(cloudflarePagesRoutes({ prerendered: paths })))
|
|
1943
1942
|
```
|
|
1944
1943
|
|
|
1944
|
+
On a server you run yourself, `nifra build --target bun` or `node`
|
|
1945
|
+
prerenders the same routes into `_prerendered/` beside `server.js`, and
|
|
1946
|
+
the server answers each from its file instead of rendering it. The file is served from the
|
|
1947
|
+
page route, so `use` middleware still runs first and a gate in front of the page
|
|
1948
|
+
still applies. A request with a query string, a navigation data request, or a draft-mode
|
|
1949
|
+
visitor renders on demand. So does a page whose build-time render set a cookie, was private or
|
|
1950
|
+
`no-store`, or varied on a request header, and every page of an app with a
|
|
1951
|
+
`nonce`. The Vite pipeline and the edge targets render every page on demand.
|
|
1952
|
+
|
|
1945
1953
|
### ISR - cache with stale-while-revalidate
|
|
1946
1954
|
|
|
1947
1955
|
When data changes but not on every request, ISR gives static-like speed with background
|
|
@@ -2016,7 +2024,7 @@ export default {
|
|
|
2016
2024
|
A store outage never fails a page. A read that throws, rejects, or outlives
|
|
2017
2025
|
`storeTimeoutMs` is a miss and the page renders; a failed write still returns the
|
|
2018
2026
|
rendered page; a failed background regeneration keeps the stale entry. Each failure goes to
|
|
2019
|
-
`onStoreError(error,
|
|
2027
|
+
`onStoreError(error, { op })`, which by default logs one line per operation
|
|
2020
2028
|
per minute without the cache key. Set `storeTimeoutMs` for a network store, so a
|
|
2021
2029
|
hung connection costs a miss rather than the request.
|
|
2022
2030
|
|
|
@@ -2109,7 +2117,7 @@ A purge is sent after the origin store is purged, coalesced for 250 ms, chunked
|
|
|
2109
2117
|
provider's per-call limit, and retried on 429 or 5xx honoring `Retry-After`. The
|
|
2110
2118
|
endpoint never reports a purge that did not happen: `202` while it is queued,
|
|
2111
2119
|
`502` with `retryable` when the CDN refused it. After a mutation in app
|
|
2112
|
-
code, `createInvalidator(
|
|
2120
|
+
code, `createInvalidator({ store, cdn, origin }).invalidate({ tags })`
|
|
2113
2121
|
does the same. Staleness compounds: a page can be up to the CDN's
|
|
2114
2122
|
`stale-while-revalidate` older than ISR's own window.
|
|
2115
2123
|
|
|
@@ -2292,7 +2300,7 @@ else document.addEventListener("nifra:hydrated", start, { once: true })
|
|
|
2292
2300
|
> Add interactivity to a zero-runtime vanilla page with islands - imperative DOM enhancers, no framework runtime, no hydration. Explicit code an AI (or a human) gets right first try: mount, coordinate over a typed bus, always return cleanup.
|
|
2293
2301
|
|
|
2294
2302
|
A `@nifrajs/web-vanilla` page ships zero framework runtime. When one corner needs
|
|
2295
|
-
to be interactive, you don
|
|
2303
|
+
to be interactive, you don't turn on hydration - you mount an **island**: a
|
|
2296
2304
|
small, plain-DOM enhancer over a server-rendered element. Explicit imperative code with no
|
|
2297
2305
|
hidden reactivity - the shape an AI agent (or a human) gets right on the first try.
|
|
2298
2306
|
|
|
@@ -2311,7 +2319,7 @@ islands for widgets on an otherwise-static page.
|
|
|
2311
2319
|
|
|
2312
2320
|
Render a `<nifra-island>` marker in your page (props are inline JSON), then
|
|
2313
2321
|
bundle one entry (in `frontend/`) that calls `mountIslands`. Load it
|
|
2314
|
-
with the `islandScripts` export of the route
|
|
2322
|
+
with the `islandScripts` export of the route's `.backend.ts` half.
|
|
2315
2323
|
|
|
2316
2324
|
```ts
|
|
2317
2325
|
// doc-check: skip - server-rendered island marker (HTML, not a checkable module).
|
|
@@ -2349,7 +2357,7 @@ function runs on soft-nav teardown; forget it and every navigation leaks the lis
|
|
|
2349
2357
|
### Coordinate islands with a typed bus
|
|
2350
2358
|
|
|
2351
2359
|
Islands are isolated by design - each enhances one element and shares no state. When two must
|
|
2352
|
-
talk (an
|
|
2360
|
+
talk (an "add to cart" button and a cart badge), use a
|
|
2353
2361
|
`createIslandBus`: one typed channel, created once and closed over by each
|
|
2354
2362
|
enhancer. No implicit global, so concurrent renders and tests never cross-talk.
|
|
2355
2363
|
|
|
@@ -2399,7 +2407,7 @@ mountIslands({ addButton, badge })
|
|
|
2399
2407
|
|
|
2400
2408
|
### Pattern: filter drives results
|
|
2401
2409
|
|
|
2402
|
-
The same shape scales to any
|
|
2410
|
+
The same shape scales to any "one island changes, another reacts" case. Each
|
|
2403
2411
|
island owns only its own DOM; they meet on the channel, never in a shared store.
|
|
2404
2412
|
|
|
2405
2413
|
```ts
|
|
@@ -2431,7 +2439,7 @@ mountIslands({ filter, results })
|
|
|
2431
2439
|
|
|
2432
2440
|
### Load strategies
|
|
2433
2441
|
|
|
2434
|
-
A marker
|
|
2442
|
+
A marker's `data-strategy` defers its enhancer: `load` (default),
|
|
2435
2443
|
`idle`, `visible` (mount when it scrolls into view), or a
|
|
2436
2444
|
`media` query. An island with no matching enhancer, or an invalid strategy, stays
|
|
2437
2445
|
inert server-rendered HTML - forward-compatible, never a runtime error.
|
|
@@ -2485,7 +2493,7 @@ The deps array is the whole contract, and its one failure mode is catchable: a
|
|
|
2485
2493
|
`computed` whose body reads a signal the array omits will never recompute when that
|
|
2486
2494
|
signal changes. `nifra check` flags exactly that as `NF-C023` - the
|
|
2487
2495
|
check reads which signals the body calls `.get()` on and compares them to the
|
|
2488
|
-
array. A framework
|
|
2496
|
+
array. A framework's auto-tracked effect gives a tool nothing to compare, which is why
|
|
2489
2497
|
the equivalent lint elsewhere is a best-effort warning, not a gate.
|
|
2490
2498
|
|
|
2491
2499
|
### Bind a signal to the DOM
|
|
@@ -2510,8 +2518,8 @@ label.set("world") // the <h1> updates synchronously
|
|
|
2510
2518
|
|
|
2511
2519
|
### Keyed lists with bindList
|
|
2512
2520
|
|
|
2513
|
-
`bindList` keeps a container
|
|
2514
|
-
reconcile like a framework
|
|
2521
|
+
`bindList` keeps a container's children in sync with an array by key - a keyed
|
|
2522
|
+
reconcile like a framework's list diff, but you spell the key out. Add, remove, and
|
|
2515
2523
|
reorder reuse the matching node (preserving focus and scroll) instead of rebuilding the list.
|
|
2516
2524
|
Key by a **stable id** on the item; keying by the array index reuses the wrong
|
|
2517
2525
|
node on reorder, and `nifra check` flags it as `NF-C022`.
|
|
@@ -2537,8 +2545,8 @@ todos.set([...todos.get(), { id: crypto.randomUUID(), text: "buy milk", done: fa
|
|
|
2537
2545
|
|
|
2538
2546
|
### Async state with resource
|
|
2539
2547
|
|
|
2540
|
-
`resource(fetcher, [deps])` is nano
|
|
2541
|
-
async cell whose value is an explicit
|
|
2548
|
+
`resource(fetcher, [deps])` is nano's answer to "suspense" - an
|
|
2549
|
+
async cell whose value is an explicit `{ status, value, error }` union.
|
|
2542
2550
|
It runs the fetcher immediately and again whenever a declared dep changes, and it handles the
|
|
2543
2551
|
two things people get wrong by hand: the fetcher receives an `AbortSignal`, and a
|
|
2544
2552
|
superseded request is aborted with its late result dropped, so the newest fetch always wins -
|
|
@@ -2567,7 +2575,7 @@ userId.set(2) // refetches; the deps array is what NF-C023 checks against the fe
|
|
|
2567
2575
|
```
|
|
2568
2576
|
|
|
2569
2577
|
The deps array is checked exactly like `computed`: a `resource` whose
|
|
2570
|
-
fetcher reads a signal the array omits won
|
|
2578
|
+
fetcher reads a signal the array omits won't refetch when it changes, and
|
|
2571
2579
|
`nifra check` flags it as `NF-C023`. Bind it to the DOM with
|
|
2572
2580
|
`bindResource`, which dispatches on `status` - one handler per state,
|
|
2573
2581
|
`ready` required, so a still-loading value can never render as a stray
|
|
@@ -2598,7 +2606,7 @@ const off = bindResource(document.querySelector("[data-user]")!, user, {
|
|
|
2598
2606
|
nano owns state and DOM edges; an [island](/docs/islands) owns mount and teardown.
|
|
2599
2607
|
Put the signals in the enhancer, collect every disposer, and return one cleanup that calls
|
|
2600
2608
|
them all. Scaffold this shape with
|
|
2601
|
-
`nifra_scaffold
|
|
2609
|
+
`nifra_scaffold { path, variant: "stateful" }` on a vanilla
|
|
2602
2610
|
project - it emits the golden pattern below.
|
|
2603
2611
|
|
|
2604
2612
|
```ts
|
|
@@ -2636,9 +2644,9 @@ mountIslands({ todos })
|
|
|
2636
2644
|
|
|
2637
2645
|
### The three checks
|
|
2638
2646
|
|
|
2639
|
-
nano
|
|
2647
|
+
nano's explicitness is the whole point: because each reactive edge is a visible call, its
|
|
2640
2648
|
three mistakes are static lints with a fix recipe - the same closed loop (`scaffold`
|
|
2641
|
-
|
|
2649
|
+
-> `check` -> `fix` -> `verify`) that makes the
|
|
2642
2650
|
backend AI-safe, now on the frontend.
|
|
2643
2651
|
|
|
2644
2652
|
-
|
|
@@ -2715,7 +2723,7 @@ NDJSON stream settles the deferred values), and it's framework-agnostic - React
|
|
|
2715
2723
|
|
|
2716
2724
|
For server push - live feeds, progress, notifications - `sse(c, run)` returns a
|
|
2717
2725
|
`text/event-stream` response a handler returns directly. Push frames with
|
|
2718
|
-
`stream.send(
|
|
2726
|
+
`stream.send({})`; the connection stays open until `run`
|
|
2719
2727
|
resolves, you call `stream.close()`, or the client disconnects (
|
|
2720
2728
|
`stream.signal`). It's a Web `ReadableStream` too, so it runs on Bun,
|
|
2721
2729
|
Node, Deno, and the edge - no `new Function`, no per-runtime API.
|
|
@@ -2759,9 +2767,9 @@ read, or pass `Infinity` to turn the limit off.
|
|
|
2759
2767
|
`stream.send()` is type-checked and the typed client grows
|
|
2760
2768
|
`.subscribe(onEvent)` with the same event type. A route whose schema declares a
|
|
2761
2769
|
`body` is a POST stream: the body validates as on any POST, and
|
|
2762
|
-
`.subscribe(onEvent,
|
|
2770
|
+
`.subscribe(onEvent, { body })` sends it. A GET stream reconnects after a
|
|
2763
2771
|
drop and resumes with `Last-Event-ID`; a POST stream does not reconnect unless you
|
|
2764
|
-
pass `reconnect: true`, since a reconnect sends the body again. The client
|
|
2772
|
+
pass `reconnect: true`, since a reconnect sends the body again. The client's
|
|
2765
2773
|
`onRequest` hook runs before each connect, so a refreshed token reaches the stream.
|
|
2766
2774
|
|
|
2767
2775
|
```ts
|
|
@@ -3009,8 +3017,8 @@ deferred boundary. Put critical page data in the route `loader`; use
|
|
|
3009
3017
|
|
|
3010
3018
|
### Markup outside the page
|
|
3011
3019
|
|
|
3012
|
-
Svelte
|
|
3013
|
-
`<head>`, after the tags from the route
|
|
3020
|
+
Svelte's `<svelte:head>` renders into the document's
|
|
3021
|
+
`<head>`, after the tags from the route's `meta`. The document
|
|
3014
3022
|
always has a `<title>` of its own and a browser uses the first one, so set the
|
|
3015
3023
|
title in `meta`.
|
|
3016
3024
|
|
|
@@ -3024,7 +3032,7 @@ the client, with a warning in development.
|
|
|
3024
3032
|
### Dev HMR support
|
|
3025
3033
|
|
|
3026
3034
|
Dev HMR works for all five adapters through `createViteDevServer` and the
|
|
3027
|
-
framework
|
|
3035
|
+
framework's Vite plugin. React, Preact, and Vue preserve edited component state. Solid
|
|
3028
3036
|
and Svelte update live without a full page reload, and the edited component may remount. Full
|
|
3029
3037
|
matrix in [Dev & HMR](/docs/dev).
|
|
3030
3038
|
|
|
@@ -3066,9 +3074,9 @@ app
|
|
|
3066
3074
|
app.use((a) => a.decorate("db", db).derive((c) => ({ now: Date.now() })))
|
|
3067
3075
|
```
|
|
3068
3076
|
|
|
3069
|
-
### What a parent
|
|
3077
|
+
### What a parent's use() covers
|
|
3070
3078
|
|
|
3071
|
-
A `group()` scope inherits the parent
|
|
3079
|
+
A `group()` scope inherits the parent's chain as it stands at the call. A
|
|
3072
3080
|
`merge()`d server was compiled on its own, so its routes keep _their_ chain. Only
|
|
3073
3081
|
what the parent installed **before** the `group()` or `merge()` counts.
|
|
3074
3082
|
|
|
@@ -3104,14 +3112,14 @@ yes, when the route declares capabilities and has no ledger of its own
|
|
|
3104
3112
|
|
|
3105
3113
|
yes
|
|
3106
3114
|
|
|
3107
|
-
the merged server
|
|
3115
|
+
the merged server's own - a route declaring `idempotency` without one is
|
|
3108
3116
|
refused at registration
|
|
3109
3117
|
|
|
3110
3118
|
Two checks catch the silent cases. In development and tests, `unusedScopedHooks`
|
|
3111
3119
|
reports a hook followed only by `merge()` calls, and a `responseContract()`
|
|
3112
3120
|
or `effectLedger()` installed after routes it would have covered.
|
|
3113
3121
|
`nifra check` reports a `merge()` whose server authenticates none of its
|
|
3114
|
-
routes while this server
|
|
3122
|
+
routes while this server's `authenticate()` or auth plugin covers its own
|
|
3115
3123
|
(NF-C043); a module that is public on purpose takes
|
|
3116
3124
|
`// nifra-expect NF-C043: <reason>` on the merge line.
|
|
3117
3125
|
|
|
@@ -3201,11 +3209,11 @@ A **WebSocket** route, listed as `WS /path`, runs the request hooks, then the
|
|
|
3201
3209
|
authentication stages, `derive`s, `beforeHandle`s and
|
|
3202
3210
|
`onError` declared before it. Its handshake runs no `around`,
|
|
3203
3211
|
`afterHandle` or response hooks, but a refused handshake carries the
|
|
3204
|
-
app
|
|
3212
|
+
app's `responseHeaders()`.
|
|
3205
3213
|
|
|
3206
3214
|
`nifra routes --hooks --json` writes the report; `--since <file>`
|
|
3207
3215
|
prints what runs differently from a saved one. `nifra upgrade --write` saves the
|
|
3208
|
-
report before it edits anything and prints the scope diff, and `nifra check --json`
|
|
3216
|
+
report before it edits anything and prints the scope diff once the target is installed, and `nifra check --json`
|
|
3209
3217
|
includes it as `hooks` when `nifra.assurance.ts` names a
|
|
3210
3218
|
`source`. Origins are recorded only outside production builds.
|
|
3211
3219
|
|
|
@@ -3581,10 +3589,10 @@ Express, and Elysia, see [security posture, compared](/docs/security-comparison)
|
|
|
3581
3589
|
|
|
3582
3590
|
### Responses that cannot leak more than they declare
|
|
3583
3591
|
|
|
3584
|
-
A `response` schema is a **lower** bound: it says
|
|
3585
|
-
fields
|
|
3586
|
-
it also ships every other column, and nothing points at it - TypeScript
|
|
3587
|
-
excess-property check does not reach a handler
|
|
3592
|
+
A `response` schema is a **lower** bound: it says "at least these
|
|
3593
|
+
fields", never "only these". A handler returning a database row that satisfies
|
|
3594
|
+
it also ships every other column, and nothing points at it - TypeScript's
|
|
3595
|
+
excess-property check does not reach a handler's return position, and the client's
|
|
3588
3596
|
type reports the contract rather than the bytes. So the leak is invisible from both ends, and it
|
|
3589
3597
|
can appear with no code change at all: add a column, and the next deploy ships it to browsers.
|
|
3590
3598
|
|
|
@@ -3613,7 +3621,7 @@ export const app = server().use(responseContract("enforce", { extra: "strip" }))
|
|
|
3613
3621
|
// enforce, { extra: "strip" } -> 200 {"id":"u1","name":"Ada"}
|
|
3614
3622
|
```
|
|
3615
3623
|
|
|
3616
|
-
Not installing the plugin is
|
|
3624
|
+
Not installing the plugin is "off", which is exactly today's behaviour and
|
|
3617
3625
|
keeps the lane out of your bundle rather than shipping a disabled branch to everyone.
|
|
3618
3626
|
`"warn"` checks every response, logs the undeclared fields by name, and
|
|
3619
3627
|
serves the payload **unchanged** - so turning it on in staging can never be the
|
|
@@ -3625,10 +3633,10 @@ returns it early, or `onError` answers with it; only a hand-built
|
|
|
3625
3633
|
should cover: like
|
|
3626
3634
|
`idempotency()`, the decision is made per route at registration.
|
|
3627
3635
|
|
|
3628
|
-
By default, enforcement follows your schema
|
|
3636
|
+
By default, enforcement follows your schema's own semantics, because Standard Schema
|
|
3629
3637
|
exposes `validate` and no way to enumerate declared keys. A _stripping_ schema
|
|
3630
3638
|
(Zod, Valibot) yields a cleaned value, so the extra fields are dropped. A _strict_ one
|
|
3631
|
-
(`@nifrajs/schema
|
|
3639
|
+
(`@nifrajs/schema`'s `t.object`) reports them as issues, so the
|
|
3632
3640
|
response becomes a 500 and the detail goes to the logger, never to the caller.
|
|
3633
3641
|
`{ extra: "strip" }` changes that for `t` schemas: they carry their
|
|
3634
3642
|
JSON Schema, which does list the declared keys, so the payload is projected onto them - nested
|
|
@@ -3648,8 +3656,8 @@ For a metric or an alert, pass `onReport`. It receives every response the
|
|
|
3648
3656
|
contract has something to say about: `violation` (enforce mode, a 500 went out
|
|
3649
3657
|
instead), `warn` (warn mode, sent anyway, with the undeclared keys in
|
|
3650
3658
|
`fields` when they are the reason) and `stripped` (enforce mode, sent
|
|
3651
|
-
without `fields`). Each report carries the route
|
|
3652
|
-
the log line
|
|
3659
|
+
without `fields`). Each report carries the route's method and pattern and
|
|
3660
|
+
the log line's message, never a value. A hook that throws or rejects is logged once and
|
|
3653
3661
|
changes no response.
|
|
3654
3662
|
|
|
3655
3663
|
```ts
|
|
@@ -3670,14 +3678,14 @@ export const app = server().use(
|
|
|
3670
3678
|
)
|
|
3671
3679
|
```
|
|
3672
3680
|
|
|
3673
|
-
A `merge()`d server
|
|
3681
|
+
A `merge()`d server's routes are covered by a contract the parent installed
|
|
3674
3682
|
before the merge, as long as the route declares a response and its own server installed none.
|
|
3675
|
-
See [what a parent
|
|
3683
|
+
See [what a parent's use() covers](/docs/plugins#parent-use).
|
|
3676
3684
|
|
|
3677
3685
|
The check itself is essentially free: with a compiled validator it measures in the
|
|
3678
3686
|
~100ns-per-response range, and a realistic middleware-carrying route benchmarks within noise
|
|
3679
3687
|
of the same route with no contract at all, on Bun and Node alike. What a contracted route
|
|
3680
|
-
does give up is the bare-route fused lane - the check needs the handler
|
|
3688
|
+
does give up is the bare-route fused lane - the check needs the handler's value before
|
|
3681
3689
|
it becomes bytes - and a route with any middleware, derive, or lifecycle hook has already
|
|
3682
3690
|
left that lane. If a route looks like production, the contract costs nothing: declare it.
|
|
3683
3691
|
|
|
@@ -3817,14 +3825,14 @@ app.post(
|
|
|
3817
3825
|
```
|
|
3818
3826
|
|
|
3819
3827
|
`t.file` checks the size before it reads a byte, and `accept` is matched
|
|
3820
|
-
against the file
|
|
3828
|
+
against the file's **leading bytes**, never the type the client claimed: a script renamed
|
|
3821
3829
|
`photo.png` fails validation. With `accept` set, the file the handler
|
|
3822
3830
|
receives carries the detected type. A type that has no signature to check (`text/csv`,
|
|
3823
3831
|
`image/svg+xml`) is refused when the schema is built, not silently let through. Text
|
|
3824
3832
|
fields are coerced from their string form, a repeated field becomes a list, and a field the form
|
|
3825
3833
|
does not declare fails validation unless `additionalProperties` is set.
|
|
3826
3834
|
|
|
3827
|
-
The body is bounded before any of it is validated. The route
|
|
3835
|
+
The body is bounded before any of it is validated. The route's `bodyLimit` caps
|
|
3828
3836
|
the whole request; `maxFields` (100), `maxFiles` (10),
|
|
3829
3837
|
`maxFieldBytes` (64 KiB) and `maxFileBytes` cap what it may carry. A request
|
|
3830
3838
|
over one is answered `413` with the limit it crossed (`payload_too_large`,
|
|
@@ -3877,14 +3885,14 @@ format behind it, and `application/zip` is also what a `.docx` or
|
|
|
3877
3885
|
|
|
3878
3886
|
-
|
|
3879
3887
|
**
|
|
3880
|
-
`file.name` is the client
|
|
3888
|
+
`file.name` is the client's.
|
|
3881
3889
|
**
|
|
3882
3890
|
Path separators and control characters are removed, and that is all. Generate the storage key;
|
|
3883
3891
|
never build a path from the name.
|
|
3884
3892
|
|
|
3885
3893
|
-
|
|
3886
3894
|
**
|
|
3887
|
-
Without `accept`, `file.type` is the client
|
|
3895
|
+
Without `accept`, `file.type` is the client's too.
|
|
3888
3896
|
**
|
|
3889
3897
|
Some runtimes derive it from the file extension. Only a type that `accept` matched is
|
|
3890
3898
|
one the bytes proved.
|
|
@@ -3896,9 +3904,9 @@ one the bytes proved.
|
|
|
3896
3904
|
-
|
|
3897
3905
|
**A form post is a simple cross-origin request.** A browser sends
|
|
3898
3906
|
`multipart/form-data`, urlencoded and `text/plain` with cookies and no
|
|
3899
|
-
preflight. A body-schema route refuses one whose `Origin` is another site
|
|
3907
|
+
preflight. A body-schema route refuses one whose `Origin` is another site's
|
|
3900
3908
|
with `403` before reading it; list a site that must post forms to the app in the
|
|
3901
|
-
server
|
|
3909
|
+
server's `formOrigins`. A request without an `Origin` passes, so
|
|
3902
3910
|
a cookie-authenticated upload route still needs `csrf()` like any other state
|
|
3903
3911
|
change.
|
|
3904
3912
|
|
|
@@ -3949,14 +3957,14 @@ app.post(
|
|
|
3949
3957
|
```
|
|
3950
3958
|
|
|
3951
3959
|
The route opts in, not the app: a parser registered once for every route would widen what each
|
|
3952
|
-
of them accepts. Before `parse` runs, the request
|
|
3960
|
+
of them accepts. Before `parse` runs, the request's media type has matched one
|
|
3953
3961
|
of `types` in full (case folded, parameters set aside) and the body has been read
|
|
3954
|
-
under the route
|
|
3962
|
+
under the route's `bodyLimit`, counted on the bytes delivered. After it, and
|
|
3955
3963
|
before the schema:
|
|
3956
3964
|
|
|
3957
3965
|
-
|
|
3958
3966
|
**A parser that throws is a `400`.** The answer is `invalid_body`; the
|
|
3959
|
-
parser
|
|
3967
|
+
parser's own message is not sent.
|
|
3960
3968
|
|
|
3961
3969
|
-
|
|
3962
3970
|
**The value must be a tree.** An object or array reached twice is what an alias or a cycle
|
|
@@ -3972,15 +3980,15 @@ and an object whose prototype the decoder replaced with data are rejected or str
|
|
|
3972
3980
|
JSON. An instance of a class, such as a `Date` or a `Uint8Array`, is
|
|
3973
3981
|
passed through without being looked into.
|
|
3974
3982
|
|
|
3975
|
-
What stays yours is the decoder
|
|
3983
|
+
What stays yours is the decoder's own limits: nesting depth, alias expansion, and the size
|
|
3976
3984
|
of a number or a string are spent inside `parse`, before anything above can look.
|
|
3977
3985
|
Configure it for untrusted input.
|
|
3978
3986
|
|
|
3979
3987
|
`types` takes full media types only, and refuses four: JSON, urlencoded and multipart
|
|
3980
3988
|
already have readers, and `text/plain` is a body a browser sends from any site with
|
|
3981
|
-
the user
|
|
3989
|
+
the user's cookies and no preflight. Every type it does accept is one a browser must
|
|
3982
3990
|
preflight, so your CORS policy sees the request first. The generated OpenAPI document lists
|
|
3983
|
-
each type under the operation
|
|
3991
|
+
each type under the operation's request body. The typed client keeps sending JSON, which
|
|
3984
3992
|
the route still reads; send another format with `fetch`.
|
|
3985
3993
|
|
|
3986
3994
|
### File uploads - `@nifrajs/uploads`
|
|
@@ -4207,20 +4215,20 @@ const app = server().use(securityHeaders({
|
|
|
4207
4215
|
Every value is fixed at construction, so the headers are declared statically rather than
|
|
4208
4216
|
written by a response hook - an app whose response middleware is only this keeps the fused
|
|
4209
4217
|
native response lanes. A route that sets one of these names itself keeps its own value. A
|
|
4210
|
-
group can apply its own configuration over the app
|
|
4211
|
-
inside `app.group("/admin", ...)` - and each header it sets replaces the app
|
|
4212
|
-
value on the group
|
|
4218
|
+
group can apply its own configuration over the app's - `admin.use(securityHeaders({ contentSecurityPolicy: "default-src 'none'" }))`
|
|
4219
|
+
inside `app.group("/admin", ...)` - and each header it sets replaces the app's
|
|
4220
|
+
value on the group's routes only.
|
|
4213
4221
|
|
|
4214
|
-
A fixed `Content-Security-Policy` here cannot allow nifra
|
|
4222
|
+
A fixed `Content-Security-Policy` here cannot allow nifra's inline scripts by
|
|
4215
4223
|
nonce. For a strict `script-src` on web pages, give `createWebApp` a
|
|
4216
|
-
`csp` from `createCspPolicy`: it allows the framework
|
|
4224
|
+
`csp` from `createCspPolicy`: it allows the framework's constant
|
|
4217
4225
|
scripts by hash and adds a nonce only to a page that needs one, so every other page sends the
|
|
4218
4226
|
same header and stays cacheable under `withISR` or a CDN. See
|
|
4219
4227
|
[A strict CSP that still caches](/docs/contract#strict-csp).
|
|
4220
4228
|
|
|
4221
4229
|
### Route assurance - prove every route is guarded
|
|
4222
4230
|
|
|
4223
|
-
Installing security middleware is not the same as proving it covers every route. Nifra
|
|
4231
|
+
Installing security middleware is not the same as proving it covers every route. Nifra's
|
|
4224
4232
|
official auth, CSRF, body-limit, rate-limit, idempotency, IP-restriction, and security-header
|
|
4225
4233
|
modules publish reflection-safe evidence at the hook where they enforce it. A policy then
|
|
4226
4234
|
classifies every route and fails closed when evidence is missing or forbidden.
|
|
@@ -4262,7 +4270,7 @@ runs only through reflection or `nifra assure`, so requests pay no assurance cos
|
|
|
4262
4270
|
|
|
4263
4271
|
WebSocket routes are reflected under the pseudo-method `"WS"`, so a policy classifies
|
|
4264
4272
|
every socket too. A handshake runs the auth guards registered before the socket and the
|
|
4265
|
-
app
|
|
4273
|
+
app's request hooks, so a socket carries authentication and rate-limit evidence from them.
|
|
4266
4274
|
It never claims evidence whose enforcement its message handlers bypass, such as a durable
|
|
4267
4275
|
command journal. A socket declares its effects with
|
|
4268
4276
|
`app.ws(path, { capabilities })`, and capability assurance checks them against
|
|
@@ -4271,7 +4279,7 @@ the module that registers it.
|
|
|
4271
4279
|
### Effect assurance - declared capability versus provenance
|
|
4272
4280
|
|
|
4273
4281
|
Authentication does not reveal what a route can do. Capability assurance compares an exact
|
|
4274
|
-
route declaration against every approved effect import reachable through that route
|
|
4282
|
+
route declaration against every approved effect import reachable through that route's local
|
|
4275
4283
|
module graph. Static, dynamic, `require`, and re-export edges are scanned; raw provider
|
|
4276
4284
|
imports fail `nifra check`. Runtime beacons add denial at owned adapters, but are never
|
|
4277
4285
|
treated as a substitute for static provenance.
|
|
@@ -4570,8 +4578,8 @@ this way. So when `nifra.assurance.ts` loads the app, Nifra also records, in
|
|
|
4570
4578
|
development, the module whose call registered each route, and the walk starts there too: a
|
|
4571
4579
|
computed path, or a route on a server a helper builds, is still covered.
|
|
4572
4580
|
`nifra check` still names such an expression in an NF-C036 finding, since the
|
|
4573
|
-
route lints read the source alone. When the registering module is not where the route
|
|
4574
|
-
code lives, such as a shared helper that registers other modules
|
|
4581
|
+
route lints read the source alone. When the registering module is not where the route's
|
|
4582
|
+
code lives, such as a shared helper that registers other modules' handlers, list the
|
|
4575
4583
|
right module in `provenance.routeModules`.
|
|
4576
4584
|
|
|
4577
4585
|
### Runtime beacons
|
|
@@ -5686,6 +5694,13 @@ the same module declares. A table built any other way, or written in a `.svelte`
|
|
|
5686
5694
|
(TypeScript 7 ships none) the build warns and keeps tables whole. It adds about 1 ms per
|
|
5687
5695
|
module to a production build.
|
|
5688
5696
|
|
|
5697
|
+
- A server entry that calls `createWebApp` with a `clientEntry` and
|
|
5698
|
+
no `copyChunks` passes `nifra dev`, which never splits, and fails on the
|
|
5699
|
+
first production page that renders copy. `nifra check` reports that call as
|
|
5700
|
+
`NF-C044`; the generated server manifest exports `copyChunks` for it
|
|
5701
|
+
to import, and `// nifra-expect NF-C044: <reason>` on the call accepts a
|
|
5702
|
+
server that never serves those pages.
|
|
5703
|
+
|
|
5689
5704
|
### Rich text
|
|
5690
5705
|
|
|
5691
5706
|
`rich(t, key, tags, vars)` renders a message's tags with your components, never
|
|
@@ -6117,7 +6132,8 @@ every other runtime.
|
|
|
6117
6132
|
|
|
6118
6133
|
```ts
|
|
6119
6134
|
// doc-check: skip - Workers entry: a Durable Object hub holds the connections.
|
|
6120
|
-
import {
|
|
6135
|
+
import { toFetchHandler } from "@nifrajs/core/server"
|
|
6136
|
+
import { createWebSocketHub } from "@nifrajs/workers"
|
|
6121
6137
|
|
|
6122
6138
|
export const NifraWebSocketHub = createWebSocketHub(app) // bind as NIFRA_WS_HUB in wrangler.toml
|
|
6123
6139
|
export default toFetchHandler(app, { webSocketHub: (env) => env.NIFRA_WS_HUB })
|
|
@@ -6386,8 +6402,8 @@ host-specific deploy step for you to fill in (Fly, a registry push, SSH, …).
|
|
|
6386
6402
|
|
|
6387
6403
|
### Bun (its home)
|
|
6388
6404
|
|
|
6389
|
-
`app.listen(3000)` - the native Bun server.
|
|
6390
|
-
|
|
6405
|
+
`app.listen(3000)` - the native Bun server. Bun is the runtime where Nifra measures
|
|
6406
|
+
fastest (see [benchmarks](/benchmarks)).
|
|
6391
6407
|
|
|
6392
6408
|
**Every core:** Bun is single-threaded per process - for multi-core boxes,
|
|
6393
6409
|
spawn one process per core, each binding the same port with
|
|
@@ -6413,10 +6429,20 @@ On Cloudflare/Vercel the platform serves assets, so you don't need it there.
|
|
|
6413
6429
|
Every file under the mount is cached as immutable by default. If the directory also holds
|
|
6414
6430
|
files that keep their name across deploys, pass the build manifest's `assets` as
|
|
6415
6431
|
`hashedFiles`: only those URL paths stay immutable, and every other file is sent
|
|
6416
|
-
with its validators so the browser revalidates it
|
|
6417
|
-
|
|
6418
|
-
|
|
6419
|
-
|
|
6432
|
+
with its validators so the browser revalidates it, plus `cacheControl` when you
|
|
6433
|
+
set one. Its `ETag` comes from its bytes, so a deploy that keeps timestamps (a
|
|
6434
|
+
container image, `rsync -a`, the Nix store) still revalidates a changed file. The server that `nifra build --target bun` or `node`
|
|
6435
|
+
generates does this already. It caches only the client build's own content-hashed outputs as
|
|
6436
|
+
immutable. A file copied from `public/`, even under `public/assets/`,
|
|
6437
|
+
gets a one-day policy.
|
|
6438
|
+
|
|
6439
|
+
`static` also takes an array of mounts; a path goes to the first mount that
|
|
6440
|
+
takes it, by its prefix and, when set, its `files`. Give a mount
|
|
6441
|
+
`files` to serve only those URL paths from a directory that holds other things
|
|
6442
|
+
too; any other path passes to the next mount, so a later mount over the same paths can still
|
|
6443
|
+
serve it. The generated Node server mounts `/assets` and, at
|
|
6444
|
+
the root, only the `public/` files the build copied, so `server.js`
|
|
6445
|
+
beside them is never served. Dotfiles are refused, except `/.well-known`.
|
|
6420
6446
|
|
|
6421
6447
|
### HTTPS without a proxy
|
|
6422
6448
|
|
|
@@ -6489,12 +6515,13 @@ function under `.vercel/output`.
|
|
|
6489
6515
|
|
|
6490
6516
|
## Nifra - CLI
|
|
6491
6517
|
|
|
6492
|
-
>
|
|
6518
|
+
> Every Nifra CLI command: dev, build and start, the check and contract gates, code generation, the agent and dev-server tools, and upgrades.
|
|
6493
6519
|
|
|
6494
|
-
`
|
|
6495
|
-
|
|
6496
|
-
`@nifrajs/web` entrypoint
|
|
6497
|
-
`
|
|
6520
|
+
`nifra` runs, builds, checks and upgrades an app from its project root. It reads
|
|
6521
|
+
`routes/`, `backend/framework.ts`, `backend/app.ts` and
|
|
6522
|
+
`nifra.config.ts` and wires the right `@nifrajs/web` entrypoint, so there
|
|
6523
|
+
is no `dev.ts`, `build.ts` or `server.ts` to write.
|
|
6524
|
+
`create-nifra` scaffolds the layout.
|
|
6498
6525
|
|
|
6499
6526
|
```ts
|
|
6500
6527
|
nifra dev # true-HMR dev server (Bun native HMR + Nifra SSR) - http://localhost:4321
|
|
@@ -6508,13 +6535,13 @@ nifra build --target cloudflare # also: node | deno | vercel | static; add --re
|
|
|
6508
6535
|
# --vite | --bun (dev/build) force the pipeline
|
|
6509
6536
|
```
|
|
6510
6537
|
|
|
6511
|
-
### The
|
|
6538
|
+
### The layout the CLI reads
|
|
6512
6539
|
|
|
6513
|
-
|
|
6514
|
-
|
|
6515
|
-
|
|
6516
|
-
|
|
6517
|
-
|
|
6540
|
+
`nifra dev` runs the Bun-native [HMR dev server](/docs/dev);
|
|
6541
|
+
`nifra build` runs the production build (content-hashed client assets plus a
|
|
6542
|
+
target-specific server); `nifra start` runs the default Bun output. The generated
|
|
6543
|
+
server serves assets and SSR with matched-route chunks preloaded and route CSS linked in each
|
|
6544
|
+
`<head>`.
|
|
6518
6545
|
|
|
6519
6546
|
**One rule picks the bundler, and it is the same rule in both phases** - so a
|
|
6520
6547
|
project can never be bundled by one toolchain in dev and the other in production. Bun runs
|
|
@@ -6528,41 +6555,50 @@ answers the same question without starting a server - see
|
|
|
6528
6555
|
|
|
6529
6556
|
```ts
|
|
6530
6557
|
my-app/
|
|
6531
|
-
routes/ #
|
|
6532
|
-
|
|
6533
|
-
|
|
6534
|
-
|
|
6535
|
-
|
|
6536
|
-
|
|
6537
|
-
|
|
6538
|
-
|
|
6539
|
-
|
|
6540
|
-
|
|
6541
|
-
|
|
6542
|
-
|
|
6543
|
-
|
|
6544
|
-
|
|
6545
|
-
|
|
6558
|
+
routes/ # the URL tree: index.tsx, _layout.tsx, [id].tsx, each with an optional x.backend.ts half
|
|
6559
|
+
backend/
|
|
6560
|
+
framework.ts # the render adapter and server options - deploy-safe
|
|
6561
|
+
app.ts # export const backend = server()... (optional - the typed API)
|
|
6562
|
+
frontend/ # components and browser code
|
|
6563
|
+
shared/ # schemas, types and helpers both sides import
|
|
6564
|
+
nifra.config.ts # CLI-only: client module, deploy target, dev/build plugins
|
|
6565
|
+
```
|
|
6566
|
+
|
|
6567
|
+
These paths are **fixed**: the CLI resolves them from the project root.
|
|
6568
|
+
`backend/app.ts` is optional; without it `nifra dev` and
|
|
6569
|
+
`nifra build` run the pages alone. A root `backend.ts` or
|
|
6570
|
+
`framework.ts`, the layout before 4.0, is refused with the command that moves it,
|
|
6571
|
+
and `nifra check` reports it as NF-C038: run
|
|
6572
|
+
`nifra migrate layout`. Only the entry file is pinned; the feature modules it
|
|
6573
|
+
`.merge()`s can live anywhere under `backend/`. Keep
|
|
6574
|
+
`backend/app.ts` a composition root - merging modules, registering no routes of
|
|
6575
|
+
its own - so each route's capability reach stays its own module's. What goes in each
|
|
6576
|
+
zone, and what the builds refuse to cross, is on
|
|
6577
|
+
[Project structure](/docs/structure).
|
|
6546
6578
|
|
|
6547
|
-
### framework.ts
|
|
6579
|
+
### backend/framework.ts and nifra.config.ts
|
|
6548
6580
|
|
|
6549
|
-
Keep the render `adapter`
|
|
6550
|
-
`
|
|
6551
|
-
`
|
|
6552
|
-
|
|
6581
|
+
Keep the render `adapter` and the server options (`apiPrefix`,
|
|
6582
|
+
`mounts`, `csp`, `i18n`) in deploy-safe
|
|
6583
|
+
`backend/framework.ts`: the generated server entry imports it. Put
|
|
6584
|
+
`clientModule`, the deploy `target`, Vite plugins, compiler plugins,
|
|
6585
|
+
conditions, and defines in CLI-only `nifra.config.ts`, which re-exports the
|
|
6586
|
+
adapter. This keeps build tooling and native dependencies out of generated server bundles.
|
|
6553
6587
|
|
|
6554
6588
|
```ts
|
|
6555
|
-
// framework.ts - deploy-safe; generated server
|
|
6589
|
+
// backend/framework.ts - deploy-safe; the generated server entry imports this file.
|
|
6556
6590
|
import { reactAdapter } from "@nifrajs/web-react"
|
|
6557
6591
|
|
|
6558
6592
|
export const adapter = reactAdapter
|
|
6593
|
+
export const apiPrefix = "" // "" keeps backend/app.ts loader-only; "/api" also serves it over HTTP
|
|
6559
6594
|
|
|
6560
6595
|
// nifra.config.ts - CLI-only build/dev tooling; never imported by a deployed server.
|
|
6561
6596
|
// doc-check: skip - needs the third-party @vitejs/plugin-react; install it to run this.
|
|
6562
6597
|
import react from "@vitejs/plugin-react"
|
|
6563
|
-
export { adapter } from "./framework"
|
|
6598
|
+
export { adapter } from "./backend/framework"
|
|
6564
6599
|
export const clientModule = "@nifrajs/web-react/client"
|
|
6565
|
-
export const
|
|
6600
|
+
export const target = "bun" // what nifra build emits; nifra target <t> switches it
|
|
6601
|
+
export const vitePlugins = [react()] // only if you want Vite's dev pipeline
|
|
6566
6602
|
// Vue/Svelte/Solid also export:
|
|
6567
6603
|
// clientPlugins = [vueBunPlugin("dom")] // compile routes for the client build
|
|
6568
6604
|
// serverPlugins = [vueBunPlugin("ssr")] // compile routes into the target's server bundle
|
|
@@ -6570,6 +6606,224 @@ export const vitePlugins = [react()] // dev HMR (Fast Refresh)
|
|
|
6570
6606
|
// define = { __VUE_OPTIONS_API__: "true", ... } // Vue feature flags
|
|
6571
6607
|
```
|
|
6572
6608
|
|
|
6609
|
+
### Command reference
|
|
6610
|
+
|
|
6611
|
+
Every command `nifra --help` lists, by what it is for. Most take
|
|
6612
|
+
`--json` for agents and CI. `--env-file <path>` works on every
|
|
6613
|
+
command and may repeat (a later file wins; a variable already set in the environment is never
|
|
6614
|
+
overwritten), which matters because commands that reflect your app import it. A dry run is
|
|
6615
|
+
the default wherever a command edits files.
|
|
6616
|
+
|
|
6617
|
+
#### Run and build
|
|
6618
|
+
|
|
6619
|
+
Develop, build a deploy directory, and run it.
|
|
6620
|
+
|
|
6621
|
+
Command
|
|
6622
|
+
What it does
|
|
6623
|
+
|
|
6624
|
+
`nifra dev [--port <n>] [--vite | --bun] [--poll]`
|
|
6625
|
+
|
|
6626
|
+
The dev server with true HMR, on port 4321. Bun runs it unless `vitePlugins` are the app's only transforms. `--no-indicator` hides the in-page issues badge.
|
|
6627
|
+
|
|
6628
|
+
`nifra build [--target <t>] [--out <dir>] [--report]`
|
|
6629
|
+
|
|
6630
|
+
A complete deploy directory for `bun`, `node`, `deno`, `cloudflare`, `vercel` or `static`. The server entry is generated from `backend/framework.ts`, `backend/app.ts` and `routes/`. `--report` prints each chunk's size.
|
|
6631
|
+
|
|
6632
|
+
`nifra start [--port <n>] [--out <dir>]`
|
|
6633
|
+
|
|
6634
|
+
Run the Bun build at `<out>/server.js`.
|
|
6635
|
+
|
|
6636
|
+
`nifra target [<target>]`
|
|
6637
|
+
|
|
6638
|
+
Show the deploy target kept in `nifra.config.ts`, or switch it. `nifra build` emits that target when no `--target` is given.
|
|
6639
|
+
|
|
6640
|
+
#### Check and gate
|
|
6641
|
+
|
|
6642
|
+
The gates to run before calling a change done, locally and in CI.
|
|
6643
|
+
|
|
6644
|
+
Command
|
|
6645
|
+
What it does
|
|
6646
|
+
|
|
6647
|
+
`nifra check [--lints-only] [--json] [--sarif]`
|
|
6648
|
+
|
|
6649
|
+
Typecheck plus contract lints: a hand-rolled `fetch()` to your own API, an untyped client, backend code reached from browser code. `--lints-only` skips tsc; `--sarif` emits SARIF 2.1.0.
|
|
6650
|
+
|
|
6651
|
+
`nifra review [--diff <ref>] [--strict] [--fix] [--write]`
|
|
6652
|
+
|
|
6653
|
+
A deterministic, evidence-backed review of the project or a diff. `--fix` plans the recipes it can apply; `--fix --write` applies them.
|
|
6654
|
+
|
|
6655
|
+
`nifra fix [--code <NF-code>]`
|
|
6656
|
+
|
|
6657
|
+
Apply the registered recipe for a diagnostic, then print the diagnostics that remain.
|
|
6658
|
+
|
|
6659
|
+
`nifra doctor [--strict] [--auto-fix] [--target <t>]`
|
|
6660
|
+
|
|
6661
|
+
Find undeclared imports and duplicate copies of `@nifrajs/core`, React and other identity-sensitive packages, and print production readiness. `--auto-fix` writes the safe dependency fixes.
|
|
6662
|
+
|
|
6663
|
+
`nifra port [--target <t>] [--ci] [--strict]`
|
|
6664
|
+
|
|
6665
|
+
A feature-by-deploy-target matrix (in-memory stores, in-process cron and WebSockets, runtime globals, `node:` built-ins) with file:line evidence. `--ci` fails on a feature the target lacks.
|
|
6666
|
+
|
|
6667
|
+
`nifra routes [--json] [--modes] [--hooks] [--graph]`
|
|
6668
|
+
|
|
6669
|
+
Every page and API route with its methods. `--modes` shows each page's render mode and fails against `--target`; `--hooks` lists the hooks each route runs; `--graph` draws the routes as Mermaid.
|
|
6670
|
+
|
|
6671
|
+
`nifra smoke [--fixture <file>] [--in-process]`
|
|
6672
|
+
|
|
6673
|
+
The declared production smoke checks: SSR, the mounted API, 404s, headers, auth, contracts and hydration.
|
|
6674
|
+
|
|
6675
|
+
`nifra cdn-check <url>`
|
|
6676
|
+
|
|
6677
|
+
Check a deployed page behind a CDN: served from cache, no internal headers reaching visitors, and soft navigations getting page data rather than the cached document.
|
|
6678
|
+
|
|
6679
|
+
`nifra i18n check [entry] [--strict]`
|
|
6680
|
+
|
|
6681
|
+
Check i18n catalogs: coverage, missing and unused keys, ICU syntax, placeholder parity and plural cases. It imports the entry module.
|
|
6682
|
+
|
|
6683
|
+
`nifra verify [--release]`
|
|
6684
|
+
|
|
6685
|
+
Run the verification gate plan against the project's `package.json` scripts; a gate with no script is reported, not run. `--release` adds the build, test, coverage and cross-runtime gates.
|
|
6686
|
+
|
|
6687
|
+
#### Contracts and assurance
|
|
6688
|
+
|
|
6689
|
+
Lock the API contract, prove the security posture, and fail CI when either regresses. See Verification for the ladder these build.
|
|
6690
|
+
|
|
6691
|
+
Command
|
|
6692
|
+
What it does
|
|
6693
|
+
|
|
6694
|
+
`nifra snapshot [--out <file>]`
|
|
6695
|
+
|
|
6696
|
+
Write the backend's API contract (routes and schemas) as JSON, `api-snapshot.json` by default: the baseline for `nifra diff`.
|
|
6697
|
+
|
|
6698
|
+
`nifra diff [<baseline>]`
|
|
6699
|
+
|
|
6700
|
+
The breaking-change gate. A new required request field or a removed response field breaks; a new response field does not. Exits non-zero on a break.
|
|
6701
|
+
|
|
6702
|
+
`nifra contracts snapshot | check`
|
|
6703
|
+
|
|
6704
|
+
Write the deterministic route contract lock, `contracts.lock.json`, or check the current routes against it.
|
|
6705
|
+
|
|
6706
|
+
`nifra assure [--config <file>]`
|
|
6707
|
+
|
|
6708
|
+
Classify every route against `nifra.assurance.ts` and list the evidence each one is missing.
|
|
6709
|
+
|
|
6710
|
+
`nifra assure --bundle [--strict] [--hydration] [--interact]`
|
|
6711
|
+
|
|
6712
|
+
One JSON verdict over every applicable gate, each recorded as pass, fail or skip. Exits non-zero unless the verdict is green.
|
|
6713
|
+
|
|
6714
|
+
`nifra levels [--min <n>]`
|
|
6715
|
+
|
|
6716
|
+
The verification ladder: L0 typed contract, L1 route assurance, L2 capability lockfile, L3 route manifest, L4 invariant-tested. `--min` fails below a level.
|
|
6717
|
+
|
|
6718
|
+
`nifra prove [--file <path>] [--min <n>]`
|
|
6719
|
+
|
|
6720
|
+
Plan the cheapest proofs for the changed files and report a machine-checkable stop condition. Needs a fresh build.
|
|
6721
|
+
|
|
6722
|
+
`nifra capabilities snapshot | check | explain`
|
|
6723
|
+
|
|
6724
|
+
Write the capability lockfile once provenance and idempotency assurance pass; fail CI on an effect import that bypasses it, drift, a GET that writes, or an idempotency gap; explain one route's tokens with `explain <METHOD> <path>`.
|
|
6725
|
+
|
|
6726
|
+
`nifra manifest emit | diff`
|
|
6727
|
+
|
|
6728
|
+
Emit the hash-verified route trust manifest, signed with `--sign <key-ref>` through the configured KMS signer, or compare two manifests and fail on a regression.
|
|
6729
|
+
|
|
6730
|
+
`nifra replay <file>`
|
|
6731
|
+
|
|
6732
|
+
Validate a token-only verification metadata file and run it against its gate.
|
|
6733
|
+
|
|
6734
|
+
#### Generate
|
|
6735
|
+
|
|
6736
|
+
Write the files the types and clients come from.
|
|
6737
|
+
|
|
6738
|
+
Command
|
|
6739
|
+
What it does
|
|
6740
|
+
|
|
6741
|
+
`nifra types [--check]`
|
|
6742
|
+
|
|
6743
|
+
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.
|
|
6744
|
+
|
|
6745
|
+
`nifra schemas [--write] [--check]`
|
|
6746
|
+
|
|
6747
|
+
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.
|
|
6748
|
+
|
|
6749
|
+
`nifra sync-routes`
|
|
6750
|
+
|
|
6751
|
+
Regenerate `nifra-routes.d.ts` so `navigate({ to, search })` is typed by each route's search schema.
|
|
6752
|
+
|
|
6753
|
+
`nifra sync-manifest`
|
|
6754
|
+
|
|
6755
|
+
Regenerate a committed `server-manifest.ts` from `routes/` without a full build.
|
|
6756
|
+
|
|
6757
|
+
`nifra openapi [--format json | yaml] [--path <prefix>]`
|
|
6758
|
+
|
|
6759
|
+
The backend's OpenAPI document, including response types inferred at build time.
|
|
6760
|
+
|
|
6761
|
+
`nifra sdk --lang python | go [--out <file>]`
|
|
6762
|
+
|
|
6763
|
+
A deterministic Python or Go SDK generated from `backend/app.ts`.
|
|
6764
|
+
|
|
6765
|
+
#### Agents and the dev server
|
|
6766
|
+
|
|
6767
|
+
What a coding agent reads and runs. nifra mcp serves the same information as tools; see Coding agents.
|
|
6768
|
+
|
|
6769
|
+
Command
|
|
6770
|
+
What it does
|
|
6771
|
+
|
|
6772
|
+
`nifra mcp [dir]`
|
|
6773
|
+
|
|
6774
|
+
Start the project's MCP server over stdio: the route index, scaffolding, `nifra_check`, SSR rendering, the dev server's errors and logs, and the declared dev database.
|
|
6775
|
+
|
|
6776
|
+
`nifra docs-mcp [--port <n>]`
|
|
6777
|
+
|
|
6778
|
+
Serve the public docs MCP (`nifra_docs`, `nifra_example`) over HTTP, on port 8787 by default.
|
|
6779
|
+
|
|
6780
|
+
`nifra context`
|
|
6781
|
+
|
|
6782
|
+
Print the project's route index and conventions for an agent's prompt.
|
|
6783
|
+
|
|
6784
|
+
`nifra learn [<step>]`
|
|
6785
|
+
|
|
6786
|
+
Print the guided build-an-app path, or one step's goal, actions and check.
|
|
6787
|
+
|
|
6788
|
+
`nifra init-agents [--force] [--sync-mcp]`
|
|
6789
|
+
|
|
6790
|
+
Add the agent files a new app ships (`.mcp.json`, the `AGENTS.md` sections, each agent's pointer) to an existing app. `--sync-mcp` re-pins the MCP launch to the installed nifra.
|
|
6791
|
+
|
|
6792
|
+
`nifra errors [--since <n>] [--category <c>]`
|
|
6793
|
+
|
|
6794
|
+
What the running dev server caught (SSR, loader, API, build, browser and hydration errors), each a structured diagnostic. Exits 1 while errors are open.
|
|
6795
|
+
|
|
6796
|
+
`nifra logs [--level <l>] [--grep <s>]`
|
|
6797
|
+
|
|
6798
|
+
The dev server's console, server and browser, each line tagged with its request.
|
|
6799
|
+
|
|
6800
|
+
`nifra explain [<message> | <NF-code>]`
|
|
6801
|
+
|
|
6802
|
+
A structured diagnostic for an error, or what a check rule reports and how to fix it.
|
|
6803
|
+
|
|
6804
|
+
`nifra db schema | query | role | audit`
|
|
6805
|
+
|
|
6806
|
+
Read the development database declared as `devDatabase` in `nifra.config.ts`: its tables, one read-only `SELECT` (rows capped, secrets masked), the SQL for a read-only Postgres role, and a log of what ran.
|
|
6807
|
+
|
|
6808
|
+
#### Migrate and upgrade
|
|
6809
|
+
|
|
6810
|
+
Move an app between layouts and releases. Each one is a dry run until --write.
|
|
6811
|
+
|
|
6812
|
+
Command
|
|
6813
|
+
What it does
|
|
6814
|
+
|
|
6815
|
+
`nifra migrate layout [--write] [--zones]`
|
|
6816
|
+
|
|
6817
|
+
Move an app onto the 4.0 layout: split each route into `x.tsx` and `x.backend.ts`, fold `_middleware.ts` into `_layout.backend.ts`, move `backend.ts` and `framework.ts` under `backend/`, and zone the other modules.
|
|
6818
|
+
|
|
6819
|
+
`nifra migrate --from tailwind --to stylex`
|
|
6820
|
+
|
|
6821
|
+
Move static Tailwind classes to StyleX; see below.
|
|
6822
|
+
|
|
6823
|
+
`nifra upgrade <version> [--write] [--list]`
|
|
6824
|
+
|
|
6825
|
+
Run every release recipe between the installed version and the target; see below.
|
|
6826
|
+
|
|
6573
6827
|
### Tailwind to StyleX
|
|
6574
6828
|
|
|
6575
6829
|
Nifra includes a conservative codemod for moving static Tailwind classes to StyleX. It is a dry
|
|
@@ -6588,7 +6842,7 @@ expressions, arbitrary values, parent-dependent variants, and unknown utilities
|
|
|
6588
6842
|
and are reported with file/line evidence. A non-zero exit status means manual migration issues
|
|
6589
6843
|
remain.
|
|
6590
6844
|
|
|
6591
|
-
StyleX compilation is native to Nifra
|
|
6845
|
+
StyleX compilation is native to Nifra's Bun pipeline. Install the runtime and compiler peers,
|
|
6592
6846
|
then register both the browser and SSR transforms:
|
|
6593
6847
|
|
|
6594
6848
|
```sh
|
|
@@ -6607,7 +6861,7 @@ export const serverPlugins = [stylexBunPlugin("ssr")]
|
|
|
6607
6861
|
```
|
|
6608
6862
|
|
|
6609
6863
|
If the project intentionally uses Vite, add the Vite adapter alongside its existing Vite
|
|
6610
|
-
transforms. Nifra will use Vite when `vitePlugins` are the app
|
|
6864
|
+
transforms. Nifra will use Vite when `vitePlugins` are the app's only transforms:
|
|
6611
6865
|
|
|
6612
6866
|
```ts
|
|
6613
6867
|
// doc-check: skip - requires the third-party Vite React plugin
|
|
@@ -6628,19 +6882,25 @@ oldest first. A recipe moves a removed package to its replacement, rewrites impo
|
|
|
6628
6882
|
moved, lists comments a release stopped honoring, and pins each group dependency to the
|
|
6629
6883
|
target, keeping its `^` or `~` unless you pass `--exact`.
|
|
6630
6884
|
The pins in `overrides`, `resolutions` and
|
|
6631
|
-
`pnpm.overrides` move with them, since an override decides what installs.
|
|
6885
|
+
`pnpm.overrides` move with them, since an override decides what installs. A
|
|
6886
|
+
`peerDependencies` range is what a library accepts, not a pin: it is raised only
|
|
6887
|
+
when it excludes the target (keeping its operator, even with `--exact`), and a
|
|
6888
|
+
library's `">=3.1.0"` floor never sets the version the upgrade
|
|
6889
|
+
starts from unless nothing else, installed or declared, names one.
|
|
6632
6890
|
|
|
6633
6891
|
```bash
|
|
6634
6892
|
nifra upgrade --list # the release targets this CLI knows
|
|
6635
6893
|
nifra upgrade 5.0.0 # dry-run: every planned edit, nothing written
|
|
6636
|
-
nifra upgrade 5.0.0 --write # apply
|
|
6894
|
+
nifra upgrade 5.0.0 --write # apply; it verifies with nifra check once the target is installed
|
|
6895
|
+
bun install # install the new pins
|
|
6896
|
+
nifra check # verify against them
|
|
6637
6897
|
nifra doctor # afterwards: no "mixed nifra versions" advisory left
|
|
6638
6898
|
```
|
|
6639
6899
|
|
|
6640
6900
|
It is a dry-run until `--write`, and the same run twice makes no further edits. An
|
|
6641
6901
|
unknown version or a target below what is installed is refused (`--allow-downgrade`
|
|
6642
6902
|
when the rollback is intended); a target newer than the running CLI prints the command for
|
|
6643
|
-
that release
|
|
6903
|
+
that release's CLI. It edits files under the workspace root only: a symlinked package
|
|
6644
6904
|
directory or `package.json` is never followed, and a group package installed by a
|
|
6645
6905
|
link from outside the root is listed under "Left alone" for you to upgrade in its
|
|
6646
6906
|
own repository. The MCP launch pin in `.mcp.json`, `.cursor/mcp.json`,
|
|
@@ -6649,10 +6909,15 @@ the project declares `@nifrajs/cli` so the launch runs that install from then on
|
|
|
6649
6909
|
the edit `nifra init-agents --sync-mcp` makes. Another version pinned outside
|
|
6650
6910
|
`package.json` is listed with its line: the rest of an agent file, an MCP config
|
|
6651
6911
|
elsewhere, a Dockerfile or compose file, a CI workflow, and a lockfile other than the
|
|
6652
|
-
workspace
|
|
6653
|
-
installing.
|
|
6654
|
-
|
|
6655
|
-
|
|
6912
|
+
workspace's own (an image build's frozen lockfile, say), which you regenerate after
|
|
6913
|
+
installing. `nifra check` reads the installed packages, so `--write`
|
|
6914
|
+
runs it (`--no-verify` skips that) only once they match the target: until the new
|
|
6915
|
+
pins are installed it would judge the release you are leaving, and the command prints the
|
|
6916
|
+
install to run first instead. With `--write` it also saves the hook report from
|
|
6917
|
+
before the edits and, once the target is installed, prints how hook scope changed across the
|
|
6918
|
+
upgrade (`--no-hooks` skips that); before then,
|
|
6919
|
+
`nifra routes --hooks --since` compares after the install.
|
|
6920
|
+
`nifra doctor` and
|
|
6656
6921
|
`nifra check` (NF-D002) point here when a workspace carries more than one version;
|
|
6657
6922
|
see [mixed nifra versions](/docs/troubleshooting#mixed-versions). A
|
|
6658
6923
|
`file:` package whose dependencies this upgrade moves keeps its old ones in
|
|
@@ -7921,7 +8186,7 @@ start - they are the edges you can hit later, collected in one place.
|
|
|
7921
8186
|
|
|
7922
8187
|
#### Keep the adapter out of your config file
|
|
7923
8188
|
|
|
7924
|
-
Split `framework.ts` (the adapter, imported by your server and edge entries) from
|
|
8189
|
+
Split `backend/framework.ts` (the adapter, imported by your server and edge entries) from
|
|
7925
8190
|
`nifra.config.ts` (the CLI's config, where the Vite plugins and SFC compilers live).
|
|
7926
8191
|
If your server entry reaches the adapter _through_ the config, everything the config
|
|
7927
8192
|
imports is bundled into your production server - the Vite plugin, the framework compiler, and
|
|
@@ -7930,7 +8195,7 @@ native binding, which reads like a broken install rather than a config-shape pro
|
|
|
7930
8195
|
|
|
7931
8196
|
```ts
|
|
7932
8197
|
// doc-check: skip - fragment: two files from one app, shown together.
|
|
7933
|
-
// framework.ts - imported by your SERVER and edge entries. Adapter only, nothing else.
|
|
8198
|
+
// backend/framework.ts - imported by your SERVER and edge entries. Adapter only, nothing else.
|
|
7934
8199
|
import { svelteAdapter } from "@nifrajs/web-svelte"
|
|
7935
8200
|
export const adapter = svelteAdapter
|
|
7936
8201
|
|
|
@@ -7938,7 +8203,7 @@ export const adapter = svelteAdapter
|
|
|
7938
8203
|
// belong here. Re-export the adapter; never define it here, or the dev toolchain it pulls in
|
|
7939
8204
|
// (Vite, the SFC compiler, their native bindings) is bundled into your production server.
|
|
7940
8205
|
import { svelte } from "@sveltejs/vite-plugin-svelte"
|
|
7941
|
-
export { adapter } from "./framework"
|
|
8206
|
+
export { adapter } from "./backend/framework"
|
|
7942
8207
|
export const clientModule = "@nifrajs/web-svelte/client"
|
|
7943
8208
|
export const vitePlugins = [svelte()]
|
|
7944
8209
|
```
|
|
@@ -8244,7 +8509,7 @@ routes added after it stay typed. See
|
|
|
8244
8509
|
####
|
|
8245
8510
|
Call site rejects `{ query: {…} }`
|
|
8246
8511
|
|
|
8247
|
-
If `api.thing.get(
|
|
8512
|
+
If `api.thing.get({ query: { … } })` errors, the route declares no
|
|
8248
8513
|
`query` schema - its query types as `never`, so the client can't accept query
|
|
8249
8514
|
params. The error reads out the fix; add a schema to the route:
|
|
8250
8515
|
`.get("/thing", { query: z.object({ page: z.string() }) }, h)`. Then
|
|
@@ -8512,7 +8777,10 @@ server entry and the dev server read one value without a re-export. A hand-writt
|
|
|
8512
8777
|
`createWebApp` call passes `apiPrefix` itself; import it from
|
|
8513
8778
|
`backend/framework.ts` so production serves the backend where
|
|
8514
8779
|
`nifra dev` does. `nifra check` reports `NF-C035` at a call
|
|
8515
|
-
that mounts a backend with no `apiPrefix`, or with a different one.
|
|
8780
|
+
that mounts a backend with no `apiPrefix`, or with a different one. When another
|
|
8781
|
+
server already serves the backend there, behind middleware of its own, an
|
|
8782
|
+
`apiPrefix` on the call would add a second path to it that skips that middleware: mark the call
|
|
8783
|
+
`// nifra-expect NF-C035: <reason>` instead.
|
|
8516
8784
|
|
|
8517
8785
|
Because the backend answers first and its 404 is final, a page file under the prefix (
|
|
8518
8786
|
`routes/api/report.tsx`) could never render. Nifra refuses it instead of serving a
|
|
@@ -8609,14 +8877,14 @@ each other. Each domain therefore owns its full absolute paths (`/api/listings`,
|
|
|
8609
8877
|
`routes()`, OpenAPI, capability events and the effect ledger. The builder
|
|
8610
8878
|
inherits this server's middleware chain as it stands at the call; what it adds stays in the
|
|
8611
8879
|
group, and its `onRequest`/`onResponse` hooks run only for requests at
|
|
8612
|
-
or under the prefix. A static header the group declares replaces the parent
|
|
8613
|
-
of that name on the group
|
|
8614
|
-
own configuration applies over the app
|
|
8615
|
-
applied stays the parent
|
|
8880
|
+
or under the prefix. A static header the group declares replaces the parent's value
|
|
8881
|
+
of that name on the group's routes, so `securityHeaders()` with the group's
|
|
8882
|
+
own configuration applies over the app's there. Any other plugin the parent already
|
|
8883
|
+
applied stays the parent's: the group's `use()` of that same instance
|
|
8616
8884
|
does nothing, and its `use()` of another instance under the same name (another
|
|
8617
8885
|
`cors()` policy) throws a `RouteConfigError` when the group is
|
|
8618
8886
|
declared, rather than being dropped. A plugin the group applies still shares the
|
|
8619
|
-
parent
|
|
8887
|
+
parent's copy of a plugin it `use()`s itself. The prefix is plain text (no
|
|
8620
8888
|
params or wildcards), and a collision throws before any group route is added.
|
|
8621
8889
|
|
|
8622
8890
|
-
|
|
@@ -9108,7 +9376,8 @@ header keeps the page out of the store.
|
|
|
9108
9376
|
-
|
|
9109
9377
|
**Prerender.** A prerendered page is a static file: it is served without the
|
|
9110
9378
|
loader's headers or cookies. Set those on the host that serves the file, or keep the route
|
|
9111
|
-
on-demand.
|
|
9379
|
+
on-demand. A `bun` or `node` build serves the file itself, after
|
|
9380
|
+
`use` middleware, with the page's `content-language` and CSP.
|
|
9112
9381
|
|
|
9113
9382
|
### Two ways to handle a request
|
|
9114
9383
|
|
|
@@ -10386,7 +10655,7 @@ then up to 127 of `A-Z a-z 0-9 . _ : / -`), more than 32 tags, or something othe
|
|
|
10386
10655
|
an array. Those tags were dropped, so a purge by them reaches nothing. The warning names the
|
|
10387
10656
|
route, never the tag.
|
|
10388
10657
|
|
|
10389
|
-
**Fix:** build tags from route params (`product
|
|
10658
|
+
**Fix:** build tags from route params (`product:${params.id}`),
|
|
10390
10659
|
keep to the allowed characters, and return at most 32.
|
|
10391
10660
|
|
|
10392
10661
|
#### NIFRA_CDN_RATE_LIMITED
|
|
@@ -11220,7 +11489,7 @@ keeps the 4.x behavior for each.
|
|
|
11220
11489
|
Past 5.0, 5.1 adds one change a frontend on another origin sees. A route with a
|
|
11221
11490
|
`body` schema answers a urlencoded, multipart or `text/plain` body whose
|
|
11222
11491
|
`Origin` names another site with `403 forbidden_origin`, before reading
|
|
11223
|
-
it. List that frontend
|
|
11492
|
+
it. List that frontend's origin, or an identity provider's for a
|
|
11224
11493
|
`form_post` callback, in the `formOrigins` server option (an array of
|
|
11225
11494
|
exact origins or a function; `@nifrajs/edge` takes it too). JSON bodies are
|
|
11226
11495
|
unchanged. [Security](/docs/security) covers what the check leaves to
|
|
@@ -11435,6 +11704,8 @@ app.
|
|
|
11435
11704
|
|
|
11436
11705
|
-
|
|
11437
11706
|
**Much faster SSR** - the current dynamic-page snapshot reports Nifra at
|
|
11707
|
+
20× the throughput of Next.js, 7× Nuxt, and
|
|
11708
|
+
3.2× SvelteKit / 3.3× SolidStart, with a fraction
|
|
11438
11709
|
of the client JavaScript. See [benchmarks](/benchmarks).
|
|
11439
11710
|
|
|
11440
11711
|
-
|
|
@@ -11464,7 +11735,7 @@ mount small and temporary, and use typed routes for every migrated endpoint.
|
|
|
11464
11735
|
The platform object is forwarded as the second argument when the runtime supplies one.
|
|
11465
11736
|
|
|
11466
11737
|
A mounted fetch handler carries HTTP only. A WebSocket upgrade under the mount reaches it as
|
|
11467
|
-
an ordinary request and never becomes a socket, so keep the legacy app
|
|
11738
|
+
an ordinary request and never becomes a socket, so keep the legacy app's sockets on its own
|
|
11468
11739
|
server until they move to `app.ws()` routes (see
|
|
11469
11740
|
[WebSockets in a composed app](/docs/websockets#composed)).
|
|
11470
11741
|
|
|
@@ -11586,7 +11857,7 @@ and a `process <job>` consumer span per attempt. The process span is a child
|
|
|
11586
11857
|
of the send span, plus a link to it, so one trace runs from the request to the worker even when
|
|
11587
11858
|
the worker is another process. Retries are separate spans, and the attempt that dead-letters a
|
|
11588
11859
|
job says so. A job store persists the trace context as an optional field;
|
|
11589
|
-
`jobStoreCertificationProfile(
|
|
11860
|
+
`jobStoreCertificationProfile({ traceparent: true })` checks it.
|
|
11590
11861
|
|
|
11591
11862
|
### Event consumers
|
|
11592
11863
|
|
|
@@ -11681,7 +11952,7 @@ reads, no events, no extra frames.
|
|
|
11681
11952
|
|
|
11682
11953
|
> A dimension-by-dimension security comparison of Nifra against the current releases of Hono, Fastify, Express, and Elysia - which hardening each framework ships by default, which is opt-in, and which is left to third-party packages.
|
|
11683
11954
|
|
|
11684
|
-
Which hardening each framework actually ships. A dimension-by-dimension read of Nifra
|
|
11955
|
+
Which hardening each framework actually ships. A dimension-by-dimension read of Nifra's
|
|
11685
11956
|
security defaults against the **current releases** of Hono, Fastify, Express, and Elysia -
|
|
11686
11957
|
what is on by default, what is opt-in, and what is left to a third-party package. For how each
|
|
11687
11958
|
Nifra primitive works, see [Security & hardening](/docs/security).
|
|
@@ -11701,10 +11972,10 @@ verification, env-independent error responses, client-IP trust model.
|
|
|
11701
11972
|
**Par with the best-in-class:** body limits (Fastify class), JSON prototype-poisoning
|
|
11702
11973
|
rejection (par Fastify, default-on), schema validation (par Fastify/Elysia), CSRF (par
|
|
11703
11974
|
Fastify), security headers (par Hono, first-party), cookie prefixes (par Hono), sessions,
|
|
11704
|
-
JWT hardening, static serving, supply chain (par Hono
|
|
11975
|
+
JWT hardening, static serving, supply chain (par Hono's zero-dependency core).
|
|
11705
11976
|
|
|
11706
11977
|
**One caveat no capability table removes.** Hono, Fastify, and Express have orders of
|
|
11707
|
-
magnitude more production exposure and more external researchers looking at them. Nifra
|
|
11978
|
+
magnitude more production exposure and more external researchers looking at them. Nifra's
|
|
11708
11979
|
protections are implementation-verified and unit-tested, but have not had that volume of
|
|
11709
11980
|
adversarial attention or a third-party audit. Ongoing scrutiny is the part only time buys.
|
|
11710
11981
|
|
|
@@ -11979,10 +12250,10 @@ body is drained through a true streaming byte counter that cancels at the cap. T
|
|
|
11979
12250
|
charged on the bytes actually **delivered**, never on the number a caller wrote in the
|
|
11980
12251
|
header - so an adapter that rebuilds a request from an event envelope cannot smuggle a large
|
|
11981
12252
|
payload behind a small declared length. Fastify enforces its 1 MiB default on real bytes and
|
|
11982
|
-
is the gold standard among the four; Nifra matches it. Hono
|
|
12253
|
+
is the gold standard among the four; Nifra matches it. Hono's `bodyLimit` is
|
|
11983
12254
|
an opt-in middleware that keys on `Content-Length`; Express relies on
|
|
11984
|
-
body-parser
|
|
11985
|
-
(Bun
|
|
12255
|
+
body-parser's 100 KB default only if you mount it; Elysia inherits the runtime cap
|
|
12256
|
+
(Bun's 128 MB).
|
|
11986
12257
|
|
|
11987
12258
|
#### Prototype pollution
|
|
11988
12259
|
|
|
@@ -11992,7 +12263,7 @@ JSON body lane **rejects** the poisoning shape by default - an own `__proto__`
|
|
|
11992
12263
|
key, or a `constructor` carrying a `prototype` - answering the same flat
|
|
11993
12264
|
400 as malformed JSON, with `"strip"` and `"ignore"`
|
|
11994
12265
|
as alternatives. That matches Fastify, whose `onProtoPoisoning` and
|
|
11995
|
-
`onConstructorPoisoning` both default to
|
|
12266
|
+
`onConstructorPoisoning` both default to `'error'`. Hono and
|
|
11996
12267
|
Express do not reject proto keys in the JSON body; Elysia strips undeclared keys only on a
|
|
11997
12268
|
validated route via its schema normalization.
|
|
11998
12269
|
|
|
@@ -12002,38 +12273,38 @@ Nifra does per-route Standard Schema validation for body/query/params, and - the
|
|
|
12002
12273
|
differentiating half - **response** schemas as an enforced upper bound:
|
|
12003
12274
|
`"warn"` logs undeclared fields, `"enforce"` strips
|
|
12004
12275
|
them. That kills the `passwordHash`-in-the-response class at the framework layer.
|
|
12005
|
-
Fastify offers the same protection through a declared response schema (opt-in); Elysia
|
|
12276
|
+
Fastify offers the same protection through a declared response schema (opt-in); Elysia's
|
|
12006
12277
|
exactMirror normalization strips undeclared response fields and is its strongest default.
|
|
12007
|
-
Hono
|
|
12278
|
+
Hono's validator is opt-in with no response-side story, and Express ships nothing.
|
|
12008
12279
|
|
|
12009
12280
|
#### CORS, CSRF, and error handling
|
|
12010
12281
|
|
|
12011
|
-
Nifra
|
|
12282
|
+
Nifra's `cors()` throws at construction when `credentials: true`
|
|
12012
12283
|
meets `origin: "*"`, never reflects an origin by default with credentials,
|
|
12013
12284
|
and lands headers on error responses too - it is **the only one of the five where the
|
|
12014
12285
|
dangerous configuration is a construction-time error**. The other four leave
|
|
12015
12286
|
reflect-with-credentials configurable. CSRF is two independent layers (Origin/Referer check
|
|
12016
|
-
plus a signed double-submit token, timing-safe); Hono
|
|
12017
|
-
Sec-Fetch-Site heuristic, Fastify
|
|
12287
|
+
plus a signed double-submit token, timing-safe); Hono's CSRF is an Origin /
|
|
12288
|
+
Sec-Fetch-Site heuristic, Fastify's official token package is comparable, Express's
|
|
12018
12289
|
csurf is deprecated, and Elysia ships none in-tree. Uncaught errors become a flat 500
|
|
12019
|
-
unconditionally - not env-gated - so no configuration leaks a stack to the wire; Express
|
|
12290
|
+
unconditionally - not env-gated - so no configuration leaks a stack to the wire; Express's
|
|
12020
12291
|
dev handler printing stacks when `NODE_ENV` is unset is the perennial
|
|
12021
12292
|
counter-example.
|
|
12022
12293
|
|
|
12023
12294
|
#### Headers, cookies, sessions, JWT
|
|
12024
12295
|
|
|
12025
12296
|
Both Nifra and Hono ship a first-party security-headers middleware you add with
|
|
12026
|
-
`use()`. Nifra
|
|
12297
|
+
`use()`. Nifra's turns on nosniff, `X-Frame-Options: DENY`, and
|
|
12027
12298
|
`Referrer-Policy: no-referrer`, and keeps the headers that can break a working app
|
|
12028
|
-
(COOP/COEP/CORP, Permissions-Policy, CSP, HSTS) opt-in by design; Hono
|
|
12299
|
+
(COOP/COEP/CORP, Permissions-Policy, CSP, HSTS) opt-in by design; Hono's covers a broader
|
|
12029
12300
|
list on by default once added, HSTS included. Cookie serialization enforces RFC 6265 name
|
|
12030
12301
|
tokens, caps at 4096 bytes, and enforces `__Host-`/`__Secure-` prefix
|
|
12031
|
-
preconditions at serialization time, throwing on a violation - the same behavior Hono
|
|
12302
|
+
preconditions at serialization time, throwing on a violation - the same behavior Hono's
|
|
12032
12303
|
cookie helper has, and stricter than a silent browser drop. Sessions are always HMAC-signed,
|
|
12033
12304
|
HttpOnly, SameSite=Lax, fail-closed, with `regenerate()` for fixation - no
|
|
12034
12305
|
competitor ships sessions in-tree. JWT verification demands an algorithm allowlist, rejects
|
|
12035
12306
|
`alg: none`, blocks algorithm confusion at the key level, and requires
|
|
12036
|
-
`exp` by default; Hono
|
|
12307
|
+
`exp` by default; Hono's JWT middleware takes a single required algorithm with
|
|
12037
12308
|
no enforced allowlist and treats `exp` as optional, so Nifra is stricter there.
|
|
12038
12309
|
|
|
12039
12310
|
#### Static serving, redirects, uploads, proxying
|
|
@@ -12051,12 +12322,12 @@ bytes and strip EXIF/GPS by re-encode, where the others do size limits at best.
|
|
|
12051
12322
|
#### Rate limiting, IP trust, load shedding
|
|
12052
12323
|
|
|
12053
12324
|
The rate limiter keys on the caller IP the server resolved, never on a client-sent header, so
|
|
12054
|
-
the
|
|
12325
|
+
the "trust proxy = spoofable keys" footgun has no default path; with no resolvable
|
|
12055
12326
|
IP it fails closed instead of sharing one bucket.
|
|
12056
12327
|
`X-Forwarded-For` is ignored at the default and counted from the right only when you
|
|
12057
12328
|
declare trusted proxies. `c.clientIp` is the socket peer unless you pass an explicit
|
|
12058
12329
|
trust config, and short chains fail closed. Admission sheds on live capacity evidence
|
|
12059
|
-
(in-flight count plus event-loop lag). Fastify
|
|
12330
|
+
(in-flight count plus event-loop lag). Fastify's under-pressure is the only peer for load
|
|
12060
12331
|
shedding; nothing else in the field defaults to an unspoofable key or fails closed on IP trust.
|
|
12061
12332
|
|
|
12062
12333
|
### Beyond parity - what none of the four ship
|
|
@@ -12084,10 +12355,10 @@ third-party add-on for the others; Nifra ships them first-party with assurance i
|
|
|
12084
12355
|
|
|
12085
12356
|
### Where each alternative is still the right call
|
|
12086
12357
|
|
|
12087
|
-
This is a security read, not a blanket
|
|
12088
|
-
minimalism and its zero-dependency core are genuinely excellent; Fastify
|
|
12358
|
+
This is a security read, not a blanket "pick Nifra". Hono's run-anywhere
|
|
12359
|
+
minimalism and its zero-dependency core are genuinely excellent; Fastify's maturity,
|
|
12089
12360
|
ecosystem, and years of adversarial attention are real advantages a young framework cannot
|
|
12090
|
-
claim; Express
|
|
12361
|
+
claim; Express's ubiquity means every hire already knows it. Nifra's argument is
|
|
12091
12362
|
narrower and honest: it makes the dangerous configurations _unrepresentable_, ships the
|
|
12092
12363
|
hardening primitives first-party, and lets `nifra assure` prove in CI that every
|
|
12093
12364
|
route is guarded. For the full capability and throughput comparison, see
|
|
@@ -12399,7 +12670,7 @@ test("the API contract withstands hostile inputs", async () => {
|
|
|
12399
12670
|
For every selected route, the laboratory synthesizes a valid **contract witness**. It then
|
|
12400
12671
|
changes types, removes required fields, crosses numeric and length bounds, inserts unknown
|
|
12401
12672
|
properties, and descends into nested objects and arrays. A mutation is sent only after the
|
|
12402
|
-
route
|
|
12673
|
+
route's own Standard Schema validator proves it invalid. Query values are proved after URL
|
|
12403
12674
|
serialization, exactly as the server receives them.
|
|
12404
12675
|
|
|
12405
12676
|
Invalid inputs must produce 422 by default. A valid witness is also executed for every
|
|
@@ -12409,7 +12680,7 @@ has a different validation response.
|
|
|
12409
12680
|
|
|
12410
12681
|
### Assert the server keeps its own contract
|
|
12411
12682
|
|
|
12412
|
-
A route
|
|
12683
|
+
A route's `response` schema types the handler and the client, but nothing
|
|
12413
12684
|
re-checks the bytes that actually leave the app. `validateResponses` closes that gap
|
|
12414
12685
|
in tests: every JSON response is validated against the schema declared for its status, and a
|
|
12415
12686
|
mismatch throws `ResponseContractViolation` straight through the
|
|
@@ -12428,7 +12699,7 @@ const res = await api.me.get() // ResponseContractViolation if the payload dri
|
|
|
12428
12699
|
```
|
|
12429
12700
|
|
|
12430
12701
|
Whether it catches _undeclared extra_ fields depends on your validator, not on nifra: a
|
|
12431
|
-
strict schema (`@nifrajs/schema
|
|
12702
|
+
strict schema (`@nifrajs/schema`'s `t.object`) reports them and the
|
|
12432
12703
|
test fails, while a stripping one (Zod, Valibot) accepts them silently. To catch extras
|
|
12433
12704
|
regardless, or to stop them reaching the wire in production, use
|
|
12434
12705
|
[
|
|
@@ -12438,7 +12709,7 @@ regardless, or to stop them reaching the wire in production, use
|
|
|
12438
12709
|
|
|
12439
12710
|
### Opaque schemas stay validator-neutral
|
|
12440
12711
|
|
|
12441
|
-
Nifra
|
|
12712
|
+
Nifra's `t` schemas carry inspectable JSON Schema, so witness generation is
|
|
12442
12713
|
automatic. Other Standard Schema libraries do not have to expose structure. Supply a known-good
|
|
12443
12714
|
witness; their own validator still proves every hostile mutation.
|
|
12444
12715
|
|
|
@@ -12716,7 +12987,7 @@ The tooling reads the backend `backend/app.ts` exports. An app that
|
|
|
12716
12987
|
factory, is invisible to the contract lock and the route lints until that file serves it.
|
|
12717
12988
|
`nifra check` names each implemented operation the backend does not serve
|
|
12718
12989
|
(NF-C039), and counts them when there is no `backend/app.ts` at all. It reads a
|
|
12719
|
-
contract imported from a workspace package through that package
|
|
12990
|
+
contract imported from a workspace package through that package's
|
|
12720
12991
|
`exports`; a package installed from a registry is never read, and the check says
|
|
12721
12992
|
so rather than passing it. Export the same app built with stand-in dependencies:
|
|
12722
12993
|
|
|
@@ -15981,10 +16252,22 @@ the check there only makes it need repeated swaps. Mutable or attacker-writable
|
|
|
15981
16252
|
therefore outside the adapter's guarantee on those platforms. Store user-controlled files outside the static root and serve them through
|
|
15982
16253
|
an application or object-storage path with its own validation policy.
|
|
15983
16254
|
|
|
15984
|
-
Every file carries a strong `ETag`
|
|
15985
|
-
|
|
15986
|
-
|
|
15987
|
-
the
|
|
16255
|
+
Every file carries `Accept-Ranges: bytes` and a strong `ETag` from its content: 128 bits of its
|
|
16256
|
+
SHA-256, the same for the same bytes on every instance and on `servePublicDir`. A replacement that
|
|
16257
|
+
keeps a file's size and timestamps - `cp -p`, `rsync -a`, tar, a container image layer,
|
|
16258
|
+
SOURCE_DATE_EPOCH, the Nix store - still changes its tag. The tag is remembered per file version
|
|
16259
|
+
(device, inode, size, mtime and ctime), so a known file costs no extra read; the first request for a
|
|
16260
|
+
file reads it once (a file up to 256 KiB is then served from those bytes), and one changed in the last
|
|
16261
|
+
2 s is read again until its ctime settles. A file over 256 MiB is tagged by that identity instead of
|
|
16262
|
+
its bytes: still strong, but different on each instance.
|
|
16263
|
+
|
|
16264
|
+
`Last-Modified` is sent only while the file's mtime is the time of its own last change (it matches its
|
|
16265
|
+
ctime), since a copy that keeps or normalizes mtimes gives a changed file the old date. Explicit
|
|
16266
|
+
validator headers still apply. `If-None-Match` takes precedence over `If-Modified-Since`; a matching
|
|
16267
|
+
condition gets a bodyless 304. `Range` on GET is parsed by a copy of `@nifrajs/core/range`, the parser
|
|
16268
|
+
`servePublicDir` uses, and gated by `If-Range`: it must name the file's strong tag, or its exact date
|
|
16269
|
+
when the file has no strong tag. One range (overlapping or adjacent ones merge into one) gets 206, a
|
|
16270
|
+
range-set that selects nothing gets 416, and several disjoint ranges get the whole file.
|
|
15988
16271
|
|
|
15989
16272
|
## Graceful shutdown on signals
|
|
15990
16273
|
|
|
@@ -16391,6 +16674,41 @@ const openapi = toOpenAPI(app) // OpenAPI 3.1
|
|
|
16391
16674
|
`operationId`s); also works on a live app. Routes using a BYO Standard Schema are
|
|
16392
16675
|
emitted without a detailed schema (Standard Schema exposes no JSON Schema).
|
|
16393
16676
|
|
|
16677
|
+
### Static validators for edge runtimes
|
|
16678
|
+
|
|
16679
|
+
`@nifrajs/schema/compile` generates a TypeScript module at build time. Import that generated module
|
|
16680
|
+
in the server: its validator runs without `new Function`, retains the source schema's inferred types,
|
|
16681
|
+
and keeps the schema builder and dynamic compiler out of the runtime bundle. Invalid data still
|
|
16682
|
+
produces the same structured issues, capped at 100.
|
|
16683
|
+
|
|
16684
|
+
Define the source schema in `src/schemas/users.ts`:
|
|
16685
|
+
|
|
16686
|
+
```ts
|
|
16687
|
+
import { t } from "@nifrajs/schema"
|
|
16688
|
+
export const body = t.object({ name: t.string({ minLength: 1 }), age: t.integer() })
|
|
16689
|
+
```
|
|
16690
|
+
|
|
16691
|
+
Generate `src/generated/users.ts` before building the app:
|
|
16692
|
+
|
|
16693
|
+
```ts
|
|
16694
|
+
import { compileSchema } from "@nifrajs/schema/compile"
|
|
16695
|
+
import { body } from "../src/schemas/users.ts"
|
|
16696
|
+
|
|
16697
|
+
await Bun.write(
|
|
16698
|
+
"src/generated/users.ts",
|
|
16699
|
+
compileSchema(body, { source: "../schemas/users.ts", exportName: "body" }),
|
|
16700
|
+
)
|
|
16701
|
+
```
|
|
16702
|
+
|
|
16703
|
+
The server imports `body` from `./generated/users.ts` and uses it as its route schema. The generated
|
|
16704
|
+
source-schema import is type-only and disappears from the deployed bundle. Regenerate when the source
|
|
16705
|
+
schema changes. Custom string formats must be registered in the serving process, as with ordinary schemas.
|
|
16706
|
+
|
|
16707
|
+
Compilation refuses coercing schemas (`t.query`, `t.form` and the other request-slot schemas), a
|
|
16708
|
+
schema whose `validate` does more than check its `jsonSchema`, custom registry kinds such as dates/deferred values,
|
|
16709
|
+
runtime-only metadata, and known TypeBox compiler escape hazards. Use the ordinary `t` adapter for
|
|
16710
|
+
these shapes. This opt-in build step leaves the existing validation API and runtime behavior intact.
|
|
16711
|
+
|
|
16394
16712
|
### Forms and files - `@nifrajs/schema/form`
|
|
16395
16713
|
|
|
16396
16714
|
The `t` exported from `@nifrajs/schema/form` is the same builder plus `t.file` and `t.form`. A
|
|
@@ -17540,7 +17858,7 @@ done-gate, or `nifra mcp` to give the agent live project tools.
|
|
|
17540
17858
|
|
|
17541
17859
|
## @nifrajs/otel
|
|
17542
17860
|
|
|
17543
|
-
`ActiveObservation`, `AttributeValue`, `EffectTracingOptions`, `EffectTracingPlugin`, `EndObservation`, `NifraSpan`, `ObservationAdapter`, `ObservationClock`, `ObservationContext`, `ObservationLifecycle`, `ObservationLifecycleOptions`, `ObservationLink`, `ObservationParent`, `ObservationScope`, `OtlpExporter`, `OtlpExporterOptions`, `ParsedTraceparent`, `SpanKind`, `SpanStatus`, `StartObservation`, `TraceContext`, `TracingOptions`, `causalitySpanLink`, `combineObservationAdapters`, `consoleSpanExporter`, `createObservationLifecycle`, `effectTracing`, `formatTraceparent`, `generateSpanId`, `generateTraceId`, `otlpExporter`, `parseTraceparent`, `traceHeaders`, `tracing`
|
|
17861
|
+
`ActiveObservation`, `AttributeValue`, `EffectTracingOptions`, `EffectTracingPlugin`, `EndObservation`, `NifraSpan`, `ObservationAdapter`, `ObservationClock`, `ObservationContext`, `ObservationLifecycle`, `ObservationLifecycleOptions`, `ObservationLink`, `ObservationParent`, `ObservationScope`, `OtlpExporter`, `OtlpExporterOptions`, `ParsedTraceparent`, `RecordingObservationLifecycle`, `SpanKind`, `SpanStatus`, `StartObservation`, `TraceContext`, `TracingOptions`, `causalitySpanLink`, `combineObservationAdapters`, `consoleSpanExporter`, `createObservationLifecycle`, `effectTracing`, `formatTraceparent`, `generateSpanId`, `generateTraceId`, `otlpExporter`, `parseTraceparent`, `traceHeaders`, `tracing`
|
|
17544
17862
|
|
|
17545
17863
|
## @nifrajs/pi
|
|
17546
17864
|
|
|
@@ -17580,7 +17898,7 @@ done-gate, or `nifra mcp` to give the agent live project tools.
|
|
|
17580
17898
|
|
|
17581
17899
|
## @nifrajs/web
|
|
17582
17900
|
|
|
17583
|
-
`ACTION_GLOBAL`, `Action`, `BOUNDARY_GLOBAL`, `BackendOnly`, `Blocker`, `BlockerController`, `BlockerFunction`, `BlockerLocation`, `BlockerState`, `Boundary`, `BoundaryDescriptor`, `BoundaryError`, `BoundaryMode`, `BoundaryRegistration`, `BoundaryRequestCtx`, `BoundaryState`, `BoundaryStates`, `BoundaryStatus`, `BrowserNavigate`, `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`, `Deferred`, `DehydratedState`, `DocumentParts`, `DraftCookieControls`, `DynamicBoundary`, `DynamicBoundaryBatch`, `EnableDraftOptions`, `FetchRouteData`, `Fetcher`, `FetcherState`, `FontDisplay`, `FontFace`, `FontPreloadInput`, `FontSource`, `GenerateClientEntryOptions`, `GenerateRouteSearchTypesOptions`, `GenerateServerManifestOptions`, `GetStaticPaths`, `HANDOVER_ID`, `HtmlSanitizer`, `IDLE_BLOCKER`, `ISRApp`, `ISROptions`, `ISRPlatform`, `ISRQuery`, `ISRStoreOp`, `ISR_REVALIDATE_HEADER`, `ISR_REVALIDATE_TAGS_HEADER`, `ISR_STATUS_HEADER`, `InertScriptType`, `InfiniteData`, `InfiniteQueryHandle`, `InfiniteQueryOptions`, `InterceptBoundary`, `KVCacheStore`, `KVCacheStoreOptions`, `KVNamespaceLike`, `LAYOUT_DATA_GLOBAL`, `LOCALES_GLOBAL`, `LayoutEntry`, `LinkDescriptor`, `Loader`, `LoaderContext`, `LoaderResponseControls`, `LoadingEntry`, `Manifest`, `MatchChain`, `MemoryCacheStore`, `MemoryCacheStoreOptions`, `MemoryStaticBoundaryCache`, `Meta`, `MetaArgs`, `MetaDescriptor`, `MetaInput`, `MiddlewareOutcome`, `MountRouterOptions`, `MutationCallbacks`, `MutationHandle`, `MutationState`, `MutationStatus`, `NAV_FROM_HEADER`, `NavigateFunction`, `NavigateOptions`, `NavigateSearchOf`, `NavigateTargetInput`, `NonceContext`, `NonceGenerator`, `NonceHeader`, `NonceHeaderContext`, `NonceResolver`, `NotFoundEntry`, `NotFoundScope`, `OpenGraphInput`, `PRE_HYDRATION_GUARD`, `PageLocale`, `PageLocales`, `PendingBoundary`, `PrefetchMode`, `PreviewEndpointOptions`, `PublicDirCache`, `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`, `RevalidateResult`, `RevalidateTags`, `RevalidateTagsInput`, `RouteEntry`, `RouteMatch`, `RouteMiddleware`, `RouteModule`, `RoutePattern`, `RouteSearch`, `RouterState`, `SERVER_FN_MODULE`, `STATUS_HEADER`, `SanitizedHtml`, `ScriptDescriptor`, `SearchOf`, `ServePublicDirOptions`, `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`, `createClientRouter`, `createCspPolicy`, `createMatcher`, `createMutation`, `createNonceResolver`, `createQueryClient`, `createWebApp`, `defer`, `disableDraft`, `enableDraft`, `enumerateStaticRoutes`, `filePathToPattern`, `filePathToPatterns`, `fontFace`, `fontPreload`, `generateClientEntry`, `generateRouteSearchTypes`, `generateServerManifest`, `getBrowserNavigate`, `gone`, `hashQueryKey`, `isCacheablePage`, `isDraftEnabled`, `jsonLd`, `localeOfProps`, `mergeHeads`, `nifraScriptHashes`, `normalizeCssLoading`, `notFound`, `openGraph`, `pageLocaleIn`, `previewEndpoint`, `redirect`, `registerBlocker`, `renderPage`, `renderPageResult`, `resolveChainMeta`, `resolveDynamicBoundaries`, `resolveMeta`, `resolveNavigate`, `resolvePublicPath`, `resolveStaticBoundaries`, `revalidate`, `revalidateEndpoint`, `sanitizeHtml`, `sanitizedHtml`, `searchOf`, `searchOfChain`, `serializeData`, `serializeSearch`, `servePublicDir`, `setBlockerController`, `setBrowserNavigate`, `setSsrModuleLoader`, `ssrModuleLoader`, `startDynamicBoundaries`, `statusPage`, `trustHtml`, `unsafeInlineScript`, `webProjectEvidence`, `withISR`
|
|
17901
|
+
`ACTION_GLOBAL`, `Action`, `BOUNDARY_GLOBAL`, `BackendOnly`, `Blocker`, `BlockerController`, `BlockerFunction`, `BlockerLocation`, `BlockerState`, `Boundary`, `BoundaryDescriptor`, `BoundaryError`, `BoundaryMode`, `BoundaryRegistration`, `BoundaryRequestCtx`, `BoundaryState`, `BoundaryStates`, `BoundaryStatus`, `BrowserNavigate`, `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`, `Deferred`, `DehydratedState`, `DocumentParts`, `DraftCookieControls`, `DynamicBoundary`, `DynamicBoundaryBatch`, `EnableDraftOptions`, `FetchRouteData`, `Fetcher`, `FetcherState`, `FontDisplay`, `FontFace`, `FontPreloadInput`, `FontSource`, `GenerateClientEntryOptions`, `GenerateRouteSearchTypesOptions`, `GenerateServerManifestOptions`, `GetStaticPaths`, `HANDOVER_ID`, `HtmlSanitizer`, `IDLE_BLOCKER`, `ISRApp`, `ISROptions`, `ISRPlatform`, `ISRQuery`, `ISRStoreOp`, `ISR_REVALIDATE_HEADER`, `ISR_REVALIDATE_TAGS_HEADER`, `ISR_STATUS_HEADER`, `InertScriptType`, `InfiniteData`, `InfiniteQueryHandle`, `InfiniteQueryOptions`, `InterceptBoundary`, `KVCacheStore`, `KVCacheStoreOptions`, `KVNamespaceLike`, `LAYOUT_DATA_GLOBAL`, `LOCALES_GLOBAL`, `LayoutEntry`, `LinkDescriptor`, `Loader`, `LoaderContext`, `LoaderResponseControls`, `LoadingEntry`, `Manifest`, `MatchChain`, `MemoryCacheStore`, `MemoryCacheStoreOptions`, `MemoryStaticBoundaryCache`, `Meta`, `MetaArgs`, `MetaDescriptor`, `MetaInput`, `MiddlewareOutcome`, `MountRouterOptions`, `MutationCallbacks`, `MutationHandle`, `MutationState`, `MutationStatus`, `NAV_FROM_HEADER`, `NavigateFunction`, `NavigateOptions`, `NavigateSearchOf`, `NavigateTargetInput`, `NonceContext`, `NonceGenerator`, `NonceHeader`, `NonceHeaderContext`, `NonceResolver`, `NotFoundEntry`, `NotFoundScope`, `OpenGraphInput`, `PRE_HYDRATION_GUARD`, `PageLocale`, `PageLocales`, `PendingBoundary`, `PrefetchMode`, `PrerenderedPageReaderOptions`, `PrerenderedPages`, `PreviewEndpointOptions`, `PublicDirCache`, `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`, `RevalidateResult`, `RevalidateTags`, `RevalidateTagsInput`, `RouteEntry`, `RouteMatch`, `RouteMiddleware`, `RouteModule`, `RoutePattern`, `RouteSearch`, `RouterState`, `SERVER_FN_MODULE`, `STATUS_HEADER`, `SanitizedHtml`, `ScriptDescriptor`, `SearchOf`, `ServePublicDirOptions`, `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`, `createClientRouter`, `createCspPolicy`, `createMatcher`, `createMutation`, `createNonceResolver`, `createQueryClient`, `createWebApp`, `defer`, `disableDraft`, `enableDraft`, `enumerateStaticRoutes`, `filePathToPattern`, `filePathToPatterns`, `fontFace`, `fontPreload`, `generateClientEntry`, `generateRouteSearchTypes`, `generateServerManifest`, `getBrowserNavigate`, `gone`, `hashQueryKey`, `isCacheablePage`, `isDraftEnabled`, `jsonLd`, `localeOfProps`, `mergeHeads`, `nifraScriptHashes`, `normalizeCssLoading`, `notFound`, `openGraph`, `pageLocaleIn`, `prerenderedPageReader`, `previewEndpoint`, `redirect`, `registerBlocker`, `renderPage`, `renderPageResult`, `resolveChainMeta`, `resolveDynamicBoundaries`, `resolveMeta`, `resolveNavigate`, `resolvePublicPath`, `resolveStaticBoundaries`, `revalidate`, `revalidateEndpoint`, `sanitizeHtml`, `sanitizedHtml`, `searchOf`, `searchOfChain`, `serializeData`, `serializeSearch`, `servePublicDir`, `setBlockerController`, `setBrowserNavigate`, `setSsrModuleLoader`, `ssrModuleLoader`, `startDynamicBoundaries`, `statusPage`, `trustHtml`, `unsafeInlineScript`, `webProjectEvidence`, `withISR`
|
|
17584
17902
|
|
|
17585
17903
|
## @nifrajs/web-preact
|
|
17586
17904
|
|