create-nifra 0.1.0-alpha.5 → 0.1.0-alpha.7

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.
@@ -1 +1 @@
1
- {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,EAAc,KAAK,QAAQ,EAAiB,MAAM,SAAS,CAAA;AAgPlE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAA;IAC/B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAA;IACtB,mFAAmF;IACnF,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAA;CAC3B;AAED,+DAA+D;AAC/D,wBAAgB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAuBtD"}
1
+ {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,EAAc,KAAK,QAAQ,EAAiB,MAAM,SAAS,CAAA;AAsQlE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAA;IAC/B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAA;IACtB,mFAAmF;IACnF,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAA;CAC3B;AAED,+DAA+D;AAC/D,wBAAgB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAuBtD"}
package/dist/agents.js CHANGED
@@ -38,16 +38,28 @@ export type App = typeof app
38
38
 
39
39
  Rules an agent must follow:
40
40
 
41
- - **Validate every input at the boundary.** Pass a schema (\`{ body, query, params, headers }\`) on any
42
- route that reads untrusted input — use \`t\` from \`@nifrajs/schema\` or any Standard Schema (zod, valibot).
43
- Then read \`c.body\` / \`c.query\` / \`c.params\`, which are typed and already validated. **Never** hand-parse
44
- \`await c.req.json()\` and poke at properties — that's the bug class the schema exists to remove.
41
+ - **Validate every input at the boundary.** The route schema slots are \`{ body, query }\` (plus
42
+ \`response\`, below) — use \`t\` from \`@nifrajs/schema\` (installed) or any Standard Schema (zod, valibot).
43
+ Read the typed, already-validated \`c.body\` / \`c.query\` (invalid input was rejected with a 400 before the
44
+ handler ran). **Never** hand-parse \`await c.req.json()\` and poke at properties — that's the bug class the
45
+ schema exists to remove.
46
+ - **Path params are NOT a schema slot.** \`:id\` etc. are inferred from the path literal as \`string\` and
47
+ read via \`c.params.id\`; there is no \`params\` (or \`headers\`) key in the route schema. Validate a param's
48
+ shape inside the handler (a length/format check), not via \`{ params: ... }\` — that's a type error.
45
49
  - **Lock the output shape with \`response\` (no drift).** Add \`{ response: t.object({...}) }\` to a route:
46
50
  the handler's return is type-checked against it, and the typed client sees exactly that shape. One
47
51
  contract, both sides — the frontend physically can't drift from the backend's output.
48
- - **Return values, not boilerplate.** Returning a plain object/array/string sends JSON. Return a
49
- \`Response\` for full control, or \`new Response(..., { status })\` for errors. Prefer explicit error
50
- shapes (\`{ ok: false, error: "slot_unavailable" }\`) with the right status over generic 500s.
52
+ - **Data-or-error routes: set the status with \`c.set.status\`, then read the error off \`res.error\` (NOT \`res.data\`).**
53
+ The typed client maps \`res.ok\` to the HTTP status. A route that does \`c.set.status = 404; return { ok: false,
54
+ error: "not_found" }\` arrives at the client as \`res.ok === false\`, \`res.data === null\`, and the body on
55
+ \`res.error\` (\`res.error.error === "not_found"\`). So branch on \`res.ok\` FIRST, then read \`res.data\` on success
56
+ or \`res.error\` on failure — never assert a 4xx onto \`res.data\`. Declaring the error arm in \`response\`
57
+ (\`t.union([Item, t.object({ ok: t.literal(false), error: t.string() })])\`) documents the shape and keeps the
58
+ success \`res.data\` precise, but a 4xx still surfaces via \`res.error\`. Do NOT return a raw \`Response\` just to
59
+ set an error status.
60
+ - **Raw \`Response\` is for redirects / streams / files** (\`Response.redirect(url, 302)\`, a file body, an
61
+ SSE stream). The typed client infers \`res.data: never\` on such a route and \`nifra check\` emits a
62
+ non-blocking \`response-route\` warning — both are EXPECTED there, not defects.
51
63
  - **\`app.fetch(request)\` is the whole app** — \`(Request) => Response | Promise<Response>\`. Tests drive it
52
64
  directly (\`await app.fetch(new Request("http://x/users/1"))\`); no server needs to be running.
53
65
  - **Don't reach for a heavy ORM/HTTP layer.** Routing, validation, cookies, and the typed client are
@@ -79,6 +91,9 @@ function webRules(framework) {
79
91
  \`_404.tsx\` / \`_error.tsx\` are the fallbacks.
80
92
  - A route file may export: \`default\` (the page component), \`loader\` (server-only data), \`action\`
81
93
  (server-only mutation), and \`meta\` (head tags). The \`loader\` returns data typed straight into the page.
94
+ - **The \`server()\` backend is IN-PROCESS, not a public HTTP surface.** Loaders/actions call it through
95
+ \`ctx.api\` (the typed client — no network) during SSR; there is no \`GET /your-route\` endpoint on the page
96
+ server to curl. Build features through loaders/actions + the typed client, not direct HTTP calls.
82
97
  - Swap UI frameworks by changing one import (\`@nifrajs/web-${framework}\` → another adapter); your route,
83
98
  loader, and action code do not change.
84
99
  - **Loaders \`throw redirect(url)\`, actions \`return redirect(url)\`.** Loader redirects abort the
@@ -218,14 +233,21 @@ const COMMANDS = {
218
233
  - \`nifra check\` — typecheck + typed-client lint (run before you call work done)`,
219
234
  site: `- \`bun install\` — install dependencies
220
235
  - \`nifra dev\` — true-HMR dev server
221
- - \`nifra build\` — content-hashed client bundle + manifest
222
- - \`nifra start\` — serve the built app (SSR)
223
- - \`nifra check\` — typecheck + typed-client lint (run before you call work done)`,
236
+ - \`nifra build\` — content-hashed client bundle + manifest (local build)
237
+ - \`nifra start\` — serve the built app (SSR) — pairs with \`nifra build\`
238
+ - \`nifra check\` — typecheck + typed-client lint (run before you call work done)
239
+
240
+ For a local production run use \`nifra build && nifra start\` (or \`bun run build:bun && bun run start\`). NOTE:
241
+ the bare \`bun run build\` script targets **Cloudflare Pages for DEPLOY** (emits \`dist/\`, a different layout)
242
+ — it does NOT pair with \`nifra start\`/\`bun run start\` (which serve \`dist-bun/\`). Don't mix the two.`,
224
243
  isr: `- \`bun install\` — install dependencies
225
244
  - \`nifra dev\` — true-HMR dev server
226
- - \`nifra build\` — build for your deploy target
227
- - \`nifra start\` — serve the built app (SSR + ISR cache)
228
- - \`nifra check\` — typecheck + typed-client lint (run before you call work done)`,
245
+ - \`nifra build\` — content-hashed client bundle + manifest (local build)
246
+ - \`nifra start\` — serve the built app (SSR + ISR cache) — pairs with \`nifra build\`
247
+ - \`nifra check\` — typecheck + typed-client lint (run before you call work done)
248
+
249
+ For a local production run use \`nifra build && nifra start\`. NOTE: the bare \`bun run build\` script targets
250
+ **Cloudflare Pages for DEPLOY** (\`dist/\`) and does NOT pair with \`nifra start\` — don't mix the two.`,
229
251
  };
230
252
  /** The agent's stop condition — what makes the anti-drift guarantees actually fire. */
231
253
  const DONE = `## Definition of done — run \`nifra check\`
@@ -1 +1 @@
1
- {"version":3,"file":"agents.js","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAGnD,OAAO,EAAE,UAAU,EAAgC,MAAM,SAAS,CAAA;AAElE,MAAM,eAAe,GAAwC;IAC3D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AAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAA;AACnD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-nifra",
3
- "version": "0.1.0-alpha.5",
3
+ "version": "0.1.0-alpha.7",
4
4
  "description": "Scaffold a new nifra app — `bun create nifra <dir>`.",
5
5
  "keywords": [
6
6
  "bun",
@@ -11,7 +11,8 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@nifrajs/client": "^0.1.0-alpha.4",
14
- "@nifrajs/core": "^0.1.0-alpha.4"
14
+ "@nifrajs/core": "^0.1.0-alpha.4",
15
+ "@nifrajs/schema": "^0.1.0-alpha.4"
15
16
  },
16
17
  "devDependencies": {
17
18
  "@types/bun": "latest",
@@ -11,6 +11,7 @@
11
11
  "dependencies": {
12
12
  "@nifrajs/client": "^0.1.0-alpha.4",
13
13
  "@nifrajs/core": "^0.1.0-alpha.4",
14
+ "@nifrajs/schema": "^0.1.0-alpha.4",
14
15
  "@nifrajs/web": "^0.1.0-alpha.4",
15
16
  "@nifrajs/web-react": "^0.1.0-alpha.4",
16
17
  "react": "^19.0.0",
@@ -19,6 +19,7 @@
19
19
  "dependencies": {
20
20
  "@nifrajs/client": "^0.1.0-alpha.4",
21
21
  "@nifrajs/core": "^0.1.0-alpha.4",
22
+ "@nifrajs/schema": "^0.1.0-alpha.4",
22
23
  "@nifrajs/deno": "^0.1.0-alpha.4",
23
24
  "@nifrajs/node": "^0.1.0-alpha.4",
24
25
  "@nifrajs/web": "^0.1.0-alpha.4",
@@ -19,6 +19,7 @@
19
19
  "dependencies": {
20
20
  "@nifrajs/client": "^0.1.0-alpha.4",
21
21
  "@nifrajs/core": "^0.1.0-alpha.4",
22
+ "@nifrajs/schema": "^0.1.0-alpha.4",
22
23
  "@nifrajs/deno": "^0.1.0-alpha.4",
23
24
  "@nifrajs/node": "^0.1.0-alpha.4",
24
25
  "@nifrajs/web": "^0.1.0-alpha.4",
@@ -19,6 +19,7 @@
19
19
  "dependencies": {
20
20
  "@nifrajs/client": "^0.1.0-alpha.4",
21
21
  "@nifrajs/core": "^0.1.0-alpha.4",
22
+ "@nifrajs/schema": "^0.1.0-alpha.4",
22
23
  "@nifrajs/deno": "^0.1.0-alpha.4",
23
24
  "@nifrajs/node": "^0.1.0-alpha.4",
24
25
  "@nifrajs/web": "^0.1.0-alpha.4",
@@ -19,6 +19,7 @@
19
19
  "dependencies": {
20
20
  "@nifrajs/client": "^0.1.0-alpha.4",
21
21
  "@nifrajs/core": "^0.1.0-alpha.4",
22
+ "@nifrajs/schema": "^0.1.0-alpha.4",
22
23
  "@nifrajs/deno": "^0.1.0-alpha.4",
23
24
  "@nifrajs/node": "^0.1.0-alpha.4",
24
25
  "@nifrajs/web": "^0.1.0-alpha.4",
@@ -19,6 +19,7 @@
19
19
  "dependencies": {
20
20
  "@nifrajs/client": "^0.1.0-alpha.4",
21
21
  "@nifrajs/core": "^0.1.0-alpha.4",
22
+ "@nifrajs/schema": "^0.1.0-alpha.4",
22
23
  "@nifrajs/deno": "^0.1.0-alpha.4",
23
24
  "@nifrajs/node": "^0.1.0-alpha.4",
24
25
  "@nifrajs/web": "^0.1.0-alpha.4",