@umituz/web-hono 1.8.0 → 1.8.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/docstore.ts +22 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/web-hono",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
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/docstore.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Hono } from 'hono';
2
- import { and, eq, isNull } from 'drizzle-orm';
2
+ import { and, eq, isNull, sql } from 'drizzle-orm';
3
3
  import { drizzle } from 'drizzle-orm/neon-http';
4
4
  import { neon } from '@neondatabase/serverless';
5
5
  import { validator } from 'hono/validator';
@@ -124,6 +124,26 @@ export function docStore(spec: DocStoreSpec) {
124
124
  });
125
125
  }
126
126
 
127
+ /** Trusted bulk load for seed scripts: chunked multi-row upsert with the
128
+ * same revive semantics as putDoc, without per-row workflow/singleton
129
+ * guards (seeds write fresh, consistent datasets by construction). */
130
+ async function putDocs(db: CrudDb, key: string, docs: readonly Doc[], chunkSize = 200): Promise<number> {
131
+ const col = requireSpec(key);
132
+ let count = 0;
133
+ for (let i = 0; i < docs.length; i += chunkSize) {
134
+ const chunk = docs.slice(i, i + chunkSize).map((doc) => rowValues(col, doc, Date.now()));
135
+ await db
136
+ .insert(col.table)
137
+ .values(chunk as never)
138
+ .onConflictDoUpdate({
139
+ target: [col.table.id],
140
+ set: { updatedAt: sql`excluded.updated_at`, deletedAt: null, data: sql`excluded.data` } as never,
141
+ });
142
+ count += chunk.length;
143
+ }
144
+ return count;
145
+ }
146
+
127
147
  async function patchDoc(db: CrudDb, key: string, id: string, patch: Doc): Promise<Doc | undefined> {
128
148
  requireSpec(key);
129
149
  const col = byKey.get(key)!;
@@ -274,6 +294,7 @@ export function docStore(spec: DocStoreSpec) {
274
294
  router,
275
295
  collectionOf,
276
296
  putDoc,
297
+ putDocs,
277
298
  patchDoc,
278
299
  softDeleteDoc,
279
300
  listDocs,