@dee-wan/cache 1.1.0 → 2.0.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 (40) hide show
  1. package/README.md +31 -1
  2. package/dist/chunk-2V6MG4YX.js +652 -0
  3. package/dist/chunk-2V6MG4YX.js.map +1 -0
  4. package/dist/{chunk-MOJBHU3S.js → chunk-6VWIKYUQ.js} +72 -173
  5. package/dist/chunk-6VWIKYUQ.js.map +1 -0
  6. package/dist/{chunk-HGAUU4EU.js → chunk-7OWX6SH5.js} +52 -15
  7. package/dist/chunk-7OWX6SH5.js.map +1 -0
  8. package/dist/{chunk-A4WV6RY4.js → chunk-GGSQ6C6X.js} +8 -3
  9. package/dist/chunk-GGSQ6C6X.js.map +1 -0
  10. package/dist/{chunk-ZREX7LLC.js → chunk-M4UOCIDQ.js} +18 -6
  11. package/dist/chunk-M4UOCIDQ.js.map +1 -0
  12. package/dist/chunk-NFBMWKY5.js +54 -0
  13. package/dist/chunk-NFBMWKY5.js.map +1 -0
  14. package/dist/{chunk-OOPPXK7Q.js → chunk-WKZ7TKGM.js} +3 -54
  15. package/dist/chunk-WKZ7TKGM.js.map +1 -0
  16. package/dist/chunk-ZBYAKDNZ.js +45 -0
  17. package/dist/chunk-ZBYAKDNZ.js.map +1 -0
  18. package/dist/client.d.ts +14 -1
  19. package/dist/client.js +37 -1
  20. package/dist/client.js.map +1 -1
  21. package/dist/cloudflare/index.d.ts +1 -1
  22. package/dist/cloudflare/index.js +4 -4
  23. package/dist/d1/index.d.ts +18 -2
  24. package/dist/d1/index.js +33 -11
  25. package/dist/d1/index.js.map +1 -1
  26. package/dist/d1/response-lease.js +11 -9
  27. package/dist/d1/response-lease.js.map +1 -1
  28. package/dist/index.d.ts +2 -2
  29. package/dist/index.js +1 -1
  30. package/dist/response-lease.js +8 -3
  31. package/dist/{types-D-Gd11to.d.ts → types-CtErcz2a.d.ts} +13 -1
  32. package/docs/cache-contract.md +2 -0
  33. package/package.json +1 -1
  34. package/dist/chunk-A4WV6RY4.js.map +0 -1
  35. package/dist/chunk-D2EESWMC.js +0 -19
  36. package/dist/chunk-D2EESWMC.js.map +0 -1
  37. package/dist/chunk-HGAUU4EU.js.map +0 -1
  38. package/dist/chunk-MOJBHU3S.js.map +0 -1
  39. package/dist/chunk-OOPPXK7Q.js.map +0 -1
  40. package/dist/chunk-ZREX7LLC.js.map +0 -1
package/README.md CHANGED
@@ -194,7 +194,7 @@ Models that reference the target through a foreign key are invalidated too. Unkn
194
194
 
195
195
  ## Runtime requirements
196
196
 
197
- - Cloudflare Workers with a SQLite-backed Durable Object and D1. No `nodejs_compat` needed.
197
+ - Cloudflare Workers with a SQLite-backed Durable Object and D1. The core and Cloudflare entries do not require `nodejs_compat`; Workers importing `@dee-wan/cache/d1` require it.
198
198
  - Prisma 6.19.3 or newer 6.x with `@prisma/adapter-d1` (tested with 6.19.3).
199
199
  - Generator: Node 20 or newer (CI runs it on 20, 22 and 24). Wrangler 4 and Miniflare need Node 22.
200
200
 
@@ -348,3 +348,33 @@ Defaults are 48 targets per batch, 4 concurrent requests across all warmup batch
348
348
  `createIntentWarmup(cooldownMs?, now?)` warms reads on navigation intent, without storing response values. Call `setScope(siteAndActor)` before use and `warm(key, async isCurrent => ...)` on mouse hover or keyboard focus. One task runs; only the latest waiting intent remains. Check `isCurrent()` between sequential reads. Successful tasks cool for 60 seconds by default. Scope changes and `invalidate()` clear waiting tasks and cooldowns; old completions cannot warm a new scope. Use silent, bounded, read-only requests with the same URL, credentials and headers as normal reads. Do not adopt results into active editor stores or start a startup fanout.
349
349
 
350
350
  `cacheReadValue` from `@dee-wan/cache/scoped-read` provides a Cache API value cache without D1 or a Durable Object. Pass a nonempty `namespace`, a bounded structured `key`, and a `validate` type guard with the source loader. Include every authorization and result-varying scope in the key; do not put credentials in cached values. `ttlMs` defaults to 5000 and cannot exceed 5000. `maxBytes` defaults to 1,500,000 and can be lowered. Optional `cache` and `now` allow a Cache API implementation and clock to be supplied. Cache failures, invalid values, and expired entries fall back to the loader; loader errors propagate. Expiry starts before the loader runs.
351
+
352
+ ### D1 bookmark client transport
353
+
354
+ `createD1BookmarkFetch(fetch)` wraps a fetch implementation and remembers valid
355
+ `X-Dee-Wan-D1-Bookmarks` response headers. Later requests include the greatest
356
+ bookmark seen for each physical database. Create one wrapper per independent
357
+ client context. Bookmark maps are bounded to 64 database UUIDs and 8192
358
+ characters; invalid maps are ignored. Pass `{ storage }` as the second argument to persist per-origin maps in a `getItem`/`setItem` store such as sessionStorage. Storage errors fall back to memory.
359
+
360
+ ### D1 sessions
361
+
362
+ Cloudflare Workers importing `@dee-wan/cache/d1` require the `nodejs_compat`
363
+ compatibility flag, including when D1 sessions are not enabled.
364
+
365
+ Wrap HTTP handlers with `wrapD1ReadSessionHandler(handler, options)` outside
366
+ `wrapD1Handler`. Set `bindingNames`, `bindingPrefixes`, `databaseIdsEnv`, and
367
+ optionally `primaryBindings`, `freshnessHeader`, and `ignoreRequestCacheControl`. The named environment variable contains a JSON
368
+ map from each configured binding name to its physical D1 UUID. Bindings that
369
+ share a UUID share a request session. If the variable is absent, bindings keep
370
+ their original behavior. Invalid maps fail configuration; invalid bookmark
371
+ headers return HTTP 400.
372
+
373
+ For a reusable Prisma D1 adapter, pass `prismaD1SessionDatabase(database)` to
374
+ `PrismaD1` and run every Prisma operation through
375
+ `runD1SessionOperation(database, operation)`, including scheduled operations.
376
+ Admission waits at most 30 seconds for an earlier operation on the same physical database. Apply `sessionD1Env(env, options)` before cache wrapping scheduled bindings so
377
+ those operations use the same facades. Ordinary D1 calls use the regular
378
+ binding. Allow and expose
379
+ `X-Dee-Wan-D1-Bookmarks` in CORS configuration where browser clients need it.
380
+ D1 cache source fills start on the primary; cache hits reuse source bookmarks. Generic Prisma caches must set `sessionCache: d1SessionCacheHooks(database)`. Queries started after streaming response headers are sent cannot advance those headers. WebSocket upgrades bypass sessions.