@umituz/web-hono 1.20.0 → 1.20.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.
- package/package.json +1 -1
- package/src/crud.ts +6 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-hono",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.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), 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
|
@@ -27,6 +27,7 @@ export interface CreateSpec {
|
|
|
27
27
|
schema: z.ZodType;
|
|
28
28
|
prefix: string;
|
|
29
29
|
defaults?: (c: RequestContext) => Record<string, unknown>;
|
|
30
|
+
pre?: (c: RequestContext, body: Record<string, unknown>) => Promise<Response | void>;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
export interface OrgScopeSpec {
|
|
@@ -163,7 +164,7 @@ export function crudRoutes(spec: CrudSpec): Hono<{ Bindings: ApiEnv }> {
|
|
|
163
164
|
});
|
|
164
165
|
|
|
165
166
|
if (spec.create) {
|
|
166
|
-
const { schema, prefix, defaults } = spec.create;
|
|
167
|
+
const { schema, prefix, defaults, pre } = spec.create;
|
|
167
168
|
router.post(path, async (c) => {
|
|
168
169
|
const raw = await c.req.json().catch(() => undefined);
|
|
169
170
|
if (raw === undefined || typeof raw !== 'object' || raw === null) {
|
|
@@ -174,6 +175,10 @@ export function crudRoutes(spec: CrudSpec): Hono<{ Bindings: ApiEnv }> {
|
|
|
174
175
|
return c.json({ error: 'Invalid request body', details: parsed.error.flatten().fieldErrors }, 400);
|
|
175
176
|
}
|
|
176
177
|
const body = normalizeRow(table, parsed.data as Record<string, unknown>);
|
|
178
|
+
if (pre) {
|
|
179
|
+
const gate = await pre(c, body);
|
|
180
|
+
if (gate) return gate;
|
|
181
|
+
}
|
|
177
182
|
const db = getDb(c);
|
|
178
183
|
const stamped: Record<string, unknown> = {};
|
|
179
184
|
if (spec.orgScope) {
|