@kirejs/h3 0.2.3 → 0.2.5
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/AGENT.md +27 -0
- package/README.md +13 -0
- package/dist/cjs/index.js +275 -217
- package/dist/esm/index.js +276 -218
- package/dist/types/types.d.ts +23 -0
- package/llms.txt +48 -0
- package/package.json +7 -3
package/llms.txt
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @kirejs/h3 — h3 (unjs) integration
|
|
2
|
+
|
|
3
|
+
> Wire Kire (and optionally Kirewire) into h3 through a returned `{ view, middleware, engine }` handle.
|
|
4
|
+
|
|
5
|
+
`kireH3(options)` builds a Kire engine (or reuses `options.engine`), loads `plugins` and `globals`, and returns a `KireH3` handle. Unlike the other integrations it does not decorate the request: you call `kire.view(dotted.name, data)` yourself inside handlers (it returns an HTML `Response` that h3 sends as-is), and you optionally mount `kire.middleware` to serve the Kirewire endpoints.
|
|
6
|
+
|
|
7
|
+
## API
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { H3, serve } from "h3";
|
|
11
|
+
import { kireH3 } from "@kirejs/h3";
|
|
12
|
+
|
|
13
|
+
const kire = kireH3({ views: "resources/views" });
|
|
14
|
+
const app = new H3();
|
|
15
|
+
|
|
16
|
+
app.use(kire.middleware); // only does work when `wire` is set; otherwise passes through
|
|
17
|
+
|
|
18
|
+
app.get("/", () => kire.view("home", { title: "Hi" }));
|
|
19
|
+
app.get("/about", () => kire.view("pages.about", { who: "Kire" }));
|
|
20
|
+
serve(app, { port: 3000 });
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
There is a single call style: `kireH3(options): KireH3`. The handle has:
|
|
24
|
+
- `engine`: the `Kire` instance.
|
|
25
|
+
- `view(name, data?)`: `Promise<Response>` with `content-type: text/html; charset=utf-8`.
|
|
26
|
+
- `middleware(event, next)`: h3 middleware; serves wire endpoints when `wire` is set, else calls `next()`.
|
|
27
|
+
|
|
28
|
+
Options (`KireH3Options`):
|
|
29
|
+
`{ views: string; extension?: string = "kire"; production?: boolean; engine?: Kire; plugins?: (KirePlugin | [KirePlugin, opts])[]; globals?: Record<string, unknown>; wire?: WireIntegration }`
|
|
30
|
+
|
|
31
|
+
## Kirewire setup
|
|
32
|
+
|
|
33
|
+
`wire: { instance, path?, scriptUrl?, clientScript?, store? }` requires `@kirejs/wire` (optional peer; throws at creation if missing). It loads `kirewirePlugin(instance, { scriptUrl, path })`; `kire.middleware` then answers `POST <path>` (default `/_wire`; reads `event.req.text()`, calls `handleUpdate`, replies `Response.json(body, { status })`) and `GET <scriptUrl>` (default `/kirewire.js`) serving the client runtime resolved from `@kirejs/wire` or `clientScript`.
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
const kire = kireH3({ views: "resources/views", wire: { instance: wire } });
|
|
37
|
+
app.use(kire.middleware);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Notes
|
|
41
|
+
|
|
42
|
+
- Written for the h3 v2 API (`new H3()`, `event.req`, `event.url.pathname`); the middleware relies on those properties.
|
|
43
|
+
- You MUST register `app.use(kire.middleware)` for wire to work; `wire` alone does not mount routes.
|
|
44
|
+
- Because `view` is not on the event, import/share the `kire` handle between modules (or export it) to render from route files.
|
|
45
|
+
- Use dotted view paths (`pages.about` -> `pages/about.kire`).
|
|
46
|
+
- Wire reads the raw text body, so no body-parser is needed.
|
|
47
|
+
- `store` exists on the shared `WireIntegration` type but is not used by the h3 wiring.
|
|
48
|
+
- `production: true` disables source maps and enables caching.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kirejs/h3",
|
|
3
3
|
"description": "h3 (unjs) integration for Kire — view rendering, a view() helper and one-line Kirewire setup.",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.5",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
7
7
|
"types": "./dist/types/index.d.ts",
|
|
@@ -29,15 +29,19 @@
|
|
|
29
29
|
"author": "drysius",
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"kire": "0.2.
|
|
32
|
+
"kire": "0.2.5"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"@kirejs/wire": "workspace:*",
|
|
36
|
-
"h3": "^2"
|
|
36
|
+
"h3": "^2",
|
|
37
|
+
"ws": "^8"
|
|
37
38
|
},
|
|
38
39
|
"peerDependenciesMeta": {
|
|
39
40
|
"@kirejs/wire": {
|
|
40
41
|
"optional": true
|
|
42
|
+
},
|
|
43
|
+
"ws": {
|
|
44
|
+
"optional": true
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
47
|
}
|