@umituz/web-hono 1.18.0 → 1.19.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/http.ts +13 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/web-hono",
3
- "version": "1.18.0",
3
+ "version": "1.19.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), 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/http.ts CHANGED
@@ -33,6 +33,17 @@ export function requestScopeOf(c: Context, config: RequestScopeConfig): string |
33
33
  return null;
34
34
  }
35
35
 
36
+ /**
37
+ * The 304 half of the If-None-Match dance on its own: returns the empty
38
+ * Not-Modified response when the request's If-None-Match weak-compares
39
+ * against `etag`, or null when the caller must build and send the full
40
+ * payload — so routes can skip the expensive work before committing to it.
41
+ */
42
+ export function notModifiedResponse(c: Context, etag: string): Response | null {
43
+ if (!matchesEtag(c.req.header('If-None-Match'), etag)) return null;
44
+ return c.body(null, 304, { ETag: etag, 'Cache-Control': CACHE_CONTROLS.etagRevalidate });
45
+ }
46
+
36
47
  /**
37
48
  * The If-None-Match dance in one call: weak-compares the request's
38
49
  * If-None-Match against `etag` and answers 304 (ETag + no-cache headers,
@@ -40,9 +51,8 @@ export function requestScopeOf(c: Context, config: RequestScopeConfig): string |
40
51
  * stay the caller's — only the transport is shared.
41
52
  */
42
53
  export function respondWithEtag(c: Context, etag: string, payload: unknown) {
43
- if (matchesEtag(c.req.header('If-None-Match'), etag)) {
44
- return c.body(null, 304, { ETag: etag, 'Cache-Control': CACHE_CONTROLS.etagRevalidate });
45
- }
54
+ const notModified = notModifiedResponse(c, etag);
55
+ if (notModified) return notModified;
46
56
  c.header('ETag', etag);
47
57
  c.header('Cache-Control', CACHE_CONTROLS.etagRevalidate);
48
58
  return c.json(payload);