@umituz/web-hono 1.19.1 → 1.19.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/web-hono",
3
- "version": "1.19.1",
3
+ "version": "1.19.3",
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), doc-sync diff/snapshot/push machine (snapshotDocs/diffOps/pushOps), better-auth server integration (tables/getter/mount/session helpers), weak-compare If-None-Match matcher (matchesEtag), cookie channels + request scope/ETag/R2-stream server helpers, TTL resource cache, and db lifecycle scripts (reset / snapshot / seed)",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/crud.ts CHANGED
@@ -13,7 +13,10 @@ type RequestContext = Context<{ Bindings: ApiEnv }>;
13
13
  function defaultDb(c: RequestContext) {
14
14
  return drizzle(neon(c.env.DATABASE_URL));
15
15
  }
16
- export type CrudDb = Pick<NeonHttpDatabase<Record<string, never>>, 'select' | 'insert' | 'update'>;
16
+ export type CrudDb = Pick<NeonHttpDatabase<Record<string, never>>, 'select' | 'insert' | 'update'> & {
17
+ /** Present on neon-http (production Workers); absent on some local drivers (pglite). */
18
+ batch?: NeonHttpDatabase<Record<string, never>>['batch'];
19
+ };
17
20
  export type CrudDbFactory = (c: RequestContext) => CrudDb;
18
21
 
19
22
  export type CrudTable = PgTable & { id: PgColumn; deletedAt: PgColumn };
package/src/docstore.ts CHANGED
@@ -258,6 +258,40 @@ export function docStore<E extends ApiEnv = ApiEnv>(spec: DocStoreSpec<E>) {
258
258
  return rows.map((r) => r.data as Doc);
259
259
  }
260
260
 
261
+ /**
262
+ * List many collections in ONE Neon HTTP round trip when the driver
263
+ * supports db.batch (neon-http on Workers). Workers plans cap subrequests
264
+ * per invocation (50 on the free tier), so hydrating dozens of collections
265
+ * with parallel listDocs calls trips the cap — this sidesteps it. Drivers
266
+ * without batch (local pglite) fall back to sequential selects.
267
+ */
268
+ async function listDocsBatch(db: CrudDb, keys: readonly string[], scope?: string): Promise<Record<string, Doc[]>> {
269
+ const cols = keys.map((key) => requireSpec(key));
270
+ const queries = cols.map((col) => {
271
+ const conds = [isNull(col.table.deletedAt)];
272
+ if (col.scope && scope !== undefined) conds.push(eq(col.scope.column, scope));
273
+ return db
274
+ .select({ data: col.table.data })
275
+ .from(col.table)
276
+ .where(and(...conds))
277
+ .orderBy(col.table.id);
278
+ });
279
+ const out: Record<string, Doc[]> = {};
280
+ if (typeof db.batch === 'function') {
281
+ const results = await db.batch(queries as never);
282
+ cols.forEach((col, i) => {
283
+ out[col.key] = (results[i] as { data: unknown }[]).map((r) => r.data as Doc);
284
+ });
285
+ return out;
286
+ }
287
+ for (const [i, col] of cols.entries()) {
288
+ const query = queries[i];
289
+ if (!query) continue;
290
+ out[col.key] = (await query).map((r) => r.data as Doc);
291
+ }
292
+ return out;
293
+ }
294
+
261
295
  async function getDoc(db: CrudDb, key: string, id: string, scope?: string): Promise<Doc | undefined> {
262
296
  const col = requireSpec(key);
263
297
  const [row] = await db
@@ -515,6 +549,7 @@ export function docStore<E extends ApiEnv = ApiEnv>(spec: DocStoreSpec<E>) {
515
549
  patchDoc,
516
550
  softDeleteDoc,
517
551
  listDocs,
552
+ listDocsBatch,
518
553
  getDoc,
519
554
  };
520
555
  }