@umituz/web-hono 1.9.0 → 1.10.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/README.md +1 -1
- package/package.json +1 -1
- package/src/api.ts +30 -0
- package/src/store.ts +0 -0
package/README.md
CHANGED
|
@@ -153,7 +153,7 @@ const { status, error, retry } = useHydration();
|
|
|
153
153
|
const orders = useCollection('orders'); // typed, re-renders on its channel
|
|
154
154
|
```
|
|
155
155
|
|
|
156
|
-
The machine: first read hydrates every collection in
|
|
156
|
+
The machine: first read hydrates every collection through `GET /api/bootstrap` in small sequential batches (default 12 paths per request — the server replays its own list routes in-process and answers one bundle; collections emit progressively as their batch lands, so the database wakes once instead of once per collection; APIs predating the route answer 404 and hydration falls back to the 1.x parallel fan-out; `bootstrap: false` pins the legacy mode); repositories read synchronously via `getDb()` or `store.read(fn)`; writes go through `store.apiWrite(path, init, keys)` / `store.http.write` which refresh only the touched collections on success and leave the cache untouched on failure; per-collection pub/sub (plus the `__refetch_all__` wildcard) drives the hooks; `view(keys, selector)` gives change-detected derived reads.
|
|
157
157
|
|
|
158
158
|
**7. Lifecycle scripts** (`scripts/`) — keep only your `TABLE_SPECS` registry and thin wrappers:
|
|
159
159
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-hono",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "API backend platform for Cloudflare Workers + Neon Postgres: createApi skeleton + error envelope layer, full-CRUD resource factory (opt-in create/remove, list params), schema→client type bridge (ClientRow), apiFetch/apiWrite client, reactive fetch-backed store (+React hooks), and db lifecycle scripts (reset / snapshot / seed)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
package/src/api.ts
CHANGED
|
@@ -34,6 +34,11 @@ export interface ApiConfig<E extends ApiEnv = ApiEnv> {
|
|
|
34
34
|
middleware?: ReadonlyArray<MiddlewareHandler<{ Bindings: E }>>;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
/** Cap on replayed paths per bootstrap call — keeps one Worker request
|
|
38
|
+
* inside the free-tier subrequest budget even when a replayed route runs
|
|
39
|
+
* a couple of queries of its own. */
|
|
40
|
+
const BOOTSTRAP_MAX_PATHS = 40;
|
|
41
|
+
|
|
37
42
|
export function createApi<E extends ApiEnv = ApiEnv>(config: ApiConfig<E>): Hono<{ Bindings: E }> {
|
|
38
43
|
const api = new Hono<{ Bindings: E }>();
|
|
39
44
|
|
|
@@ -46,6 +51,31 @@ export function createApi<E extends ApiEnv = ApiEnv>(config: ApiConfig<E>): Hono
|
|
|
46
51
|
// Widening ApiEnv→E is safe at runtime (c.env: E ⊇ ApiEnv); hono's Context
|
|
47
52
|
// invariance just refuses the direct cast.
|
|
48
53
|
app.onError(apiOnError as unknown as ErrorHandler<{ Bindings: E }>);
|
|
54
|
+
|
|
55
|
+
// GET /api/bootstrap?paths=/api/a,/api/b — replays the app's own list
|
|
56
|
+
// routes in-process (no network) and bundles their JSON bodies under one
|
|
57
|
+
// response, so a hydrating client pays one round trip per chunk instead
|
|
58
|
+
// of one per collection. Only /api paths are replayed; anything else the
|
|
59
|
+
// router would have answered stays answerable only the normal way.
|
|
60
|
+
app.get('/api/bootstrap', async (c) => {
|
|
61
|
+
const raw = c.req.query('paths') ?? '';
|
|
62
|
+
const paths = [...new Set(raw.split(',').map((p) => p.trim()).filter((p) => p.startsWith('/api/') && p !== '/api/bootstrap'))]
|
|
63
|
+
.slice(0, BOOTSTRAP_MAX_PATHS);
|
|
64
|
+
const results: Record<string, { status: number; body?: unknown }> = {};
|
|
65
|
+
await Promise.all(
|
|
66
|
+
paths.map(async (p) => {
|
|
67
|
+
const res = await app.request(p, { headers: c.req.raw.headers }, c.env);
|
|
68
|
+
if (res.status !== 200) {
|
|
69
|
+
results[p] = { status: res.status };
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const body = await res.json().catch(() => undefined);
|
|
73
|
+
results[p] = body === undefined ? { status: res.status } : { status: res.status, body };
|
|
74
|
+
}),
|
|
75
|
+
);
|
|
76
|
+
return c.json({ results });
|
|
77
|
+
});
|
|
78
|
+
|
|
49
79
|
app.all('/api/*', apiNotFound);
|
|
50
80
|
app.get('*', spaFallback);
|
|
51
81
|
return app;
|
package/src/store.ts
CHANGED
|
Binary file
|