create-nifra 0.1.0-alpha.5 → 0.1.0-alpha.6
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/dist/agents.d.ts.map +1 -1
- package/dist/agents.js +18 -7
- package/dist/agents.js.map +1 -1
- package/package.json +1 -1
- package/template/package.json +2 -1
- package/template-isr/package.json +1 -0
- package/template-site/package.json +1 -0
- package/template-site-preact/package.json +1 -0
- package/template-site-solid/package.json +1 -0
- package/template-site-svelte/package.json +1 -0
- package/template-site-vue/package.json +1 -0
package/dist/agents.d.ts.map
CHANGED
|
@@ -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;
|
|
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;AA2PlE,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,24 @@ export type App = typeof app
|
|
|
38
38
|
|
|
39
39
|
Rules an agent must follow:
|
|
40
40
|
|
|
41
|
-
- **Validate every input at the boundary.**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
\`await c.req.json()\` and poke at properties — that's the bug class the
|
|
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
|
-
- **
|
|
49
|
-
\`
|
|
50
|
-
|
|
52
|
+
- **Data-or-error routes: return a discriminated UNION, set the code via \`c.set.status\`** — e.g.
|
|
53
|
+
\`response: t.union([Item, t.object({ ok: t.literal(false), error: t.string() })])\`, then
|
|
54
|
+
\`c.set.status = 404; return { ok: false, error: "not_found" }\`. This keeps the typed client's \`res.data\`
|
|
55
|
+
precise — do NOT return a raw \`Response\` just to set an error status.
|
|
56
|
+
- **Raw \`Response\` is for redirects / streams / files** (\`Response.redirect(url, 302)\`, a file body, an
|
|
57
|
+
SSE stream). The typed client infers \`res.data: never\` on such a route and \`nifra check\` emits a
|
|
58
|
+
non-blocking \`response-route\` warning — both are EXPECTED there, not defects.
|
|
51
59
|
- **\`app.fetch(request)\` is the whole app** — \`(Request) => Response | Promise<Response>\`. Tests drive it
|
|
52
60
|
directly (\`await app.fetch(new Request("http://x/users/1"))\`); no server needs to be running.
|
|
53
61
|
- **Don't reach for a heavy ORM/HTTP layer.** Routing, validation, cookies, and the typed client are
|
|
@@ -79,6 +87,9 @@ function webRules(framework) {
|
|
|
79
87
|
\`_404.tsx\` / \`_error.tsx\` are the fallbacks.
|
|
80
88
|
- A route file may export: \`default\` (the page component), \`loader\` (server-only data), \`action\`
|
|
81
89
|
(server-only mutation), and \`meta\` (head tags). The \`loader\` returns data typed straight into the page.
|
|
90
|
+
- **The \`server()\` backend is IN-PROCESS, not a public HTTP surface.** Loaders/actions call it through
|
|
91
|
+
\`ctx.api\` (the typed client — no network) during SSR; there is no \`GET /your-route\` endpoint on the page
|
|
92
|
+
server to curl. Build features through loaders/actions + the typed client, not direct HTTP calls.
|
|
82
93
|
- Swap UI frameworks by changing one import (\`@nifrajs/web-${framework}\` → another adapter); your route,
|
|
83
94
|
loader, and action code do not change.
|
|
84
95
|
- **Loaders \`throw redirect(url)\`, actions \`return redirect(url)\`.** Loader redirects abort the
|
package/dist/agents.js.map
CHANGED
|
@@ -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,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,GAAG,EAAE,KAAK;IACV,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;CACjB,CAAA;AAED,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