viborm 1.3.3 → 1.4.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.
- package/dist/{adapter-internals-AGgQRu5t.mjs → adapter-internals-Cy2QEBnH.mjs} +1 -1
- package/dist/{adapter-internals-AGgQRu5t.mjs.map → adapter-internals-Cy2QEBnH.mjs.map} +1 -1
- package/dist/{adapter-namespace-CWLEmon2.mjs → adapter-namespace-BLejG8FA.mjs} +1 -1
- package/dist/{adapter-namespace-CWLEmon2.mjs.map → adapter-namespace-BLejG8FA.mjs.map} +1 -1
- package/dist/adapter-result-parser-D6lluSMi.mjs +2 -0
- package/dist/adapter-result-parser-D6lluSMi.mjs.map +1 -0
- package/dist/adapters.d.mts +1 -1
- package/dist/adapters.mjs +1 -1
- package/dist/{array-literal-BKdLfNzM.mjs → array-literal-BsbbSLw3.mjs} +1 -1
- package/dist/{array-literal-BKdLfNzM.mjs.map → array-literal-BsbbSLw3.mjs.map} +1 -1
- package/dist/{batch-refs-DGJPz8-G.mjs → batch-refs-BYCu1JnQ.mjs} +1 -1
- package/dist/{batch-refs-DGJPz8-G.mjs.map → batch-refs-BYCu1JnQ.mjs.map} +1 -1
- package/dist/bind-parameter-capacity-D6p9HrbB.mjs +2 -0
- package/dist/bind-parameter-capacity-D6p9HrbB.mjs.map +1 -0
- package/dist/builder-BS8EW4BQ.mjs +2 -0
- package/dist/builder-BS8EW4BQ.mjs.map +1 -0
- package/dist/bun-sql.d.mts +3 -1
- package/dist/bun-sql.mjs +1 -1
- package/dist/bun-sql.mjs.map +1 -1
- package/dist/bun-sqlite.d.mts +1 -1
- package/dist/bun-sqlite.mjs +1 -1
- package/dist/cache/cloudflare-kv.d.mts +1 -1
- package/dist/cache/cloudflare-kv.mjs +1 -1
- package/dist/cache/memory.d.mts +1 -1
- package/dist/cache/memory.mjs +1 -1
- package/dist/cache.d.mts +1 -1
- package/dist/cache.mjs +1 -1
- package/dist/{canonical-json-BReb5nFO.mjs → canonical-json-acY4dQNQ.mjs} +2 -2
- package/dist/canonical-json-acY4dQNQ.mjs.map +1 -0
- package/dist/chain-D5J9hIw-.mjs +2 -0
- package/dist/chain-D5J9hIw-.mjs.map +1 -0
- package/dist/cli.mjs +1 -1
- package/dist/client-Bhl2mWam.mjs +2 -0
- package/dist/client-Bhl2mWam.mjs.map +1 -0
- package/dist/{client-DR0vYetv.d.mts → client-BzgBm_86.d.mts} +3 -1
- package/dist/{client-DjtWangN.mjs → client-aU3YhZ6G.mjs} +16 -16
- package/dist/client-aU3YhZ6G.mjs.map +1 -0
- package/dist/client.d.mts +1 -1
- package/dist/client.mjs +1 -1
- package/dist/{clock-YTLtjLFS.mjs → clock-CJotKAxc.mjs} +1 -1
- package/dist/{clock-YTLtjLFS.mjs.map → clock-CJotKAxc.mjs.map} +1 -1
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs +1 -1
- package/dist/d1.d.mts +1 -1
- package/dist/d1.mjs +1 -1
- package/dist/d1.mjs.map +1 -1
- package/dist/{datetime-physical-codec-qKxFtI3B.mjs → datetime-physical-codec-lX7IJBlz.mjs} +1 -1
- package/dist/{datetime-physical-codec-qKxFtI3B.mjs.map → datetime-physical-codec-lX7IJBlz.mjs.map} +1 -1
- package/dist/driver-CQQbCQh9.mjs +2 -0
- package/dist/{driver-Bzc0GCQ4.mjs.map → driver-CQQbCQh9.mjs.map} +1 -1
- package/dist/{driver-BvP7eW0A.mjs → driver-u2qJicrE.mjs} +2 -2
- package/dist/{driver-BvP7eW0A.mjs.map → driver-u2qJicrE.mjs.map} +1 -1
- package/dist/driver.d.mts +1 -1
- package/dist/driver.mjs +1 -1
- package/dist/error-mapping-6op318w6.mjs.map +1 -1
- package/dist/every-CzF00eDV.mjs +2 -0
- package/dist/{every-WUr3mlvg.mjs.map → every-CzF00eDV.mjs.map} +1 -1
- package/dist/{fs-estate-azK36i9V.mjs → fs-estate-N_F2YqYa.mjs} +2 -2
- package/dist/{fs-estate-azK36i9V.mjs.map → fs-estate-N_F2YqYa.mjs.map} +1 -1
- package/dist/{identifier-conversion-Bs7A2GGU.mjs → identifier-conversion-Dc0Rf4Gi.mjs} +2 -2
- package/dist/{identifier-conversion-Bs7A2GGU.mjs.map → identifier-conversion-Dc0Rf4Gi.mjs.map} +1 -1
- package/dist/identity-CmRos0Yf.mjs +2 -0
- package/dist/identity-CmRos0Yf.mjs.map +1 -0
- package/dist/{index-B_jh2oaQ.d.mts → index-B4IWFJfv.d.mts} +1282 -1053
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/instrumentation.d.mts +1 -1
- package/dist/instrumentation.mjs +1 -1
- package/dist/{invariant-D57gi_yW.mjs → invariant-D_fIjY_z.mjs} +1 -1
- package/dist/{invariant-D57gi_yW.mjs.map → invariant-D_fIjY_z.mjs.map} +1 -1
- package/dist/{json-number-DvmiNx0n.mjs → json-number-CGXpPu4D.mjs} +1 -1
- package/dist/{json-number-DvmiNx0n.mjs.map → json-number-CGXpPu4D.mjs.map} +1 -1
- package/dist/{libsql-C8dn4id0.mjs → libsql-CrDXsfpL.mjs} +2 -2
- package/dist/{libsql-C8dn4id0.mjs.map → libsql-CrDXsfpL.mjs.map} +1 -1
- package/dist/libsql.d.mts +1 -1
- package/dist/libsql.mjs +1 -1
- package/dist/libsql.mjs.map +1 -1
- package/dist/{memory-B7CcHS6I.mjs → memory-TXO4KgBy.mjs} +2 -2
- package/dist/{memory-B7CcHS6I.mjs.map → memory-TXO4KgBy.mjs.map} +1 -1
- package/dist/migrations/mysql.d.mts +4 -4
- package/dist/migrations/mysql.mjs +1 -1
- package/dist/migrations/postgres.d.mts +4 -4
- package/dist/migrations/postgres.mjs +1 -1
- package/dist/migrations/sqlite.d.mts +4 -4
- package/dist/migrations/sqlite.mjs +1 -1
- package/dist/migrations/storage/durable-object.mjs +1 -1
- package/dist/migrations/storage/fs.mjs +1 -1
- package/dist/migrations/storage/r2.mjs +1 -1
- package/dist/migrations/tenant.d.mts +2 -2
- package/dist/migrations/tenant.mjs +1 -1
- package/dist/migrations.d.mts +4 -4
- package/dist/migrations.mjs +1 -1
- package/dist/{mysql-mUmhH9Cf.mjs → mysql-C2vOPcuA.mjs} +2 -2
- package/dist/{mysql-mUmhH9Cf.mjs.map → mysql-C2vOPcuA.mjs.map} +1 -1
- package/dist/mysql-adapter-C5CMIYRS.mjs +2 -0
- package/dist/{mysql-adapter-ABpgFB2N.mjs.map → mysql-adapter-C5CMIYRS.mjs.map} +1 -1
- package/dist/mysql2.d.mts +1 -1
- package/dist/mysql2.mjs +1 -1
- package/dist/mysql2.mjs.map +1 -1
- package/dist/neon-http.d.mts +3 -1
- package/dist/neon-http.mjs +1 -1
- package/dist/neon-http.mjs.map +1 -1
- package/dist/normalized-result-BF7gr4_b.mjs +2 -0
- package/dist/normalized-result-BF7gr4_b.mjs.map +1 -0
- package/dist/{object-store-CZADAv4c.mjs → object-store-WjVilDvN.mjs} +2 -2
- package/dist/{object-store-CZADAv4c.mjs.map → object-store-WjVilDvN.mjs.map} +1 -1
- package/dist/{object-store-Ds9NKRU6.d.mts → object-store-uRqi0URP.d.mts} +3 -3
- package/dist/permissions.d.mts +1 -1
- package/dist/pg.d.mts +26 -1
- package/dist/pg.mjs +1 -1
- package/dist/pg.mjs.map +1 -1
- package/dist/pglite.d.mts +3 -1
- package/dist/pglite.mjs +1 -1
- package/dist/pglite.mjs.map +1 -1
- package/dist/{pinned-session-C79aDzOg.mjs → pinned-session-FYOFV_gB.mjs} +2 -2
- package/dist/{pinned-session-C79aDzOg.mjs.map → pinned-session-FYOFV_gB.mjs.map} +1 -1
- package/dist/planetscale.d.mts +1 -1
- package/dist/planetscale.mjs +1 -1
- package/dist/planetscale.mjs.map +1 -1
- package/dist/{planner-DHZG9Vy7.d.mts → planner-SzkGh-3T.d.mts} +1 -1
- package/dist/{postgres-BACQ_wqF.mjs → postgres-BSmy1PYR.mjs} +2 -2
- package/dist/{postgres-BACQ_wqF.mjs.map → postgres-BSmy1PYR.mjs.map} +1 -1
- package/dist/postgres-adapter-B1RyJlWL.mjs +2 -0
- package/dist/{postgres-adapter-DaMvNOkx.mjs.map → postgres-adapter-B1RyJlWL.mjs.map} +1 -1
- package/dist/postgres-adapter-BAqRfWl1.mjs +2 -0
- package/dist/postgres-adapter-BAqRfWl1.mjs.map +1 -0
- package/dist/postgres-result-BCUQf8b_.mjs +2 -0
- package/dist/{postgres-result-D403cLyA.mjs.map → postgres-result-BCUQf8b_.mjs.map} +1 -1
- package/dist/postgres.d.mts +3 -1
- package/dist/postgres.mjs +1 -1
- package/dist/postgres.mjs.map +1 -1
- package/dist/{provider-limits-DSv2tYFr.mjs → provider-limits-V09frtmK.mjs} +1 -1
- package/dist/{provider-limits-DSv2tYFr.mjs.map → provider-limits-V09frtmK.mjs.map} +1 -1
- package/dist/relation-bound-BrZLsSke.mjs +2 -0
- package/dist/relation-bound-BrZLsSke.mjs.map +1 -0
- package/dist/{result-parsing-8wEK3GY1.mjs → result-parsing-CQf_eCl8.mjs} +1 -1
- package/dist/{result-parsing-8wEK3GY1.mjs.map → result-parsing-CQf_eCl8.mjs.map} +1 -1
- package/dist/result-shape-Fi1-Fvri.mjs +2 -0
- package/dist/result-shape-Fi1-Fvri.mjs.map +1 -0
- package/dist/{rows-v1VuwOTa.mjs → rows-BiaiswSV.mjs} +2 -2
- package/dist/{rows-v1VuwOTa.mjs.map → rows-BiaiswSV.mjs.map} +1 -1
- package/dist/schema/json.d.mts +1 -1
- package/dist/{schema-introspection-TdJrSaKd.mjs → schema-introspection-C1-XrQP4.mjs} +2 -2
- package/dist/{schema-introspection-TdJrSaKd.mjs.map → schema-introspection-C1-XrQP4.mjs.map} +1 -1
- package/dist/{schema-D3-ScVH6.mjs → schema-tGtziyCJ.mjs} +1 -1
- package/dist/{schema-D3-ScVH6.mjs.map → schema-tGtziyCJ.mjs.map} +1 -1
- package/dist/schema.d.mts +1 -1
- package/dist/schema.mjs +1 -1
- package/dist/select-assembly-BjT_fDbu.mjs +2 -0
- package/dist/select-assembly-BjT_fDbu.mjs.map +1 -0
- package/dist/{settle-etgtP1WM.mjs → settle-C4w1GfTU.mjs} +2 -2
- package/dist/{settle-etgtP1WM.mjs.map → settle-C4w1GfTU.mjs.map} +1 -1
- package/dist/{sha256-CEYo7k7R.mjs → sha256-_Nu4s32f.mjs} +1 -1
- package/dist/{sha256-CEYo7k7R.mjs.map → sha256-_Nu4s32f.mjs.map} +1 -1
- package/dist/soft-delete.d.mts +3 -3
- package/dist/{sql-statement-tokens-BW7Q-rF-.mjs → sql-statement-tokens-4J5l5Lyt.mjs} +1 -1
- package/dist/{sql-statement-tokens-BW7Q-rF-.mjs.map → sql-statement-tokens-4J5l5Lyt.mjs.map} +1 -1
- package/dist/sqlite-adapter-CoDeF2h2.mjs +2 -0
- package/dist/sqlite-adapter-CoDeF2h2.mjs.map +1 -0
- package/dist/{sqlite-utils-BvSlEs5W.mjs → sqlite-utils-C0TyzOys.mjs} +2 -2
- package/dist/{sqlite-utils-BvSlEs5W.mjs.map → sqlite-utils-C0TyzOys.mjs.map} +1 -1
- package/dist/sqlite3.d.mts +1 -1
- package/dist/sqlite3.mjs +1 -1
- package/dist/sqlite3.mjs.map +1 -1
- package/dist/{standard-sql-CYdZ_KXH.mjs → standard-sql-DmKF8msN.mjs} +2 -2
- package/dist/{standard-sql-CYdZ_KXH.mjs.map → standard-sql-DmKF8msN.mjs.map} +1 -1
- package/dist/transaction-operation-CU1zlxiG.mjs.map +1 -1
- package/dist/{utils-Qr8ug94X.mjs → utils-DkAxKcDD.mjs} +1 -1
- package/dist/{utils-Qr8ug94X.mjs.map → utils-DkAxKcDD.mjs.map} +1 -1
- package/dist/{validation-CPnrLcjW.mjs → validation-C7Z6wTJa.mjs} +1 -1
- package/dist/{validation-CPnrLcjW.mjs.map → validation-C7Z6wTJa.mjs.map} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/dist/version-n393hhwM.mjs +2 -0
- package/dist/{version-0RVYpih5.mjs.map → version-n393hhwM.mjs.map} +1 -1
- package/package.json +14 -14
- package/dist/bind-parameter-capacity-DiwRmZ1h.mjs +0 -2
- package/dist/bind-parameter-capacity-DiwRmZ1h.mjs.map +0 -1
- package/dist/builder-D6Ug-zjM.mjs +0 -2
- package/dist/builder-D6Ug-zjM.mjs.map +0 -1
- package/dist/canonical-json-BReb5nFO.mjs.map +0 -1
- package/dist/chain-B5IbqLGi.mjs +0 -2
- package/dist/chain-B5IbqLGi.mjs.map +0 -1
- package/dist/client-BmcHzDBa.mjs +0 -2
- package/dist/client-BmcHzDBa.mjs.map +0 -1
- package/dist/client-DjtWangN.mjs.map +0 -1
- package/dist/driver-Bzc0GCQ4.mjs +0 -2
- package/dist/every-WUr3mlvg.mjs +0 -2
- package/dist/identity-Bj2EN6Ss.mjs +0 -2
- package/dist/identity-Bj2EN6Ss.mjs.map +0 -1
- package/dist/mysql-adapter-ABpgFB2N.mjs +0 -2
- package/dist/postgres-adapter-Ci07rgh_.mjs +0 -2
- package/dist/postgres-adapter-Ci07rgh_.mjs.map +0 -1
- package/dist/postgres-adapter-DaMvNOkx.mjs +0 -2
- package/dist/postgres-result-D403cLyA.mjs +0 -2
- package/dist/result-shape-BKydBCsR.mjs +0 -2
- package/dist/result-shape-BKydBCsR.mjs.map +0 -1
- package/dist/select-assembly-uZfvbYjz.mjs +0 -2
- package/dist/select-assembly-uZfvbYjz.mjs.map +0 -1
- package/dist/sqlite-adapter-DPc9T6Lh.mjs +0 -2
- package/dist/sqlite-adapter-DPc9T6Lh.mjs.map +0 -1
- package/dist/version-0RVYpih5.mjs +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{n as e}from"./chunk-BuuaeEvq.mjs";import{n as t,r as n}from"./cache-CIPRF-pz.mjs";import{n as r}from"./v-514RME2X.mjs";import{n as i,r as a,t as o}from"./key-B89Z4vxn.mjs";import{d as s,f as c,t as l}from"./observation-Co72iCd1.mjs";import{o as u}from"./execution-context-rJXTRVrJ.mjs";import{t as d}from"./clock-
|
|
2
|
-
//# sourceMappingURL=driver-
|
|
1
|
+
import{n as e}from"./chunk-BuuaeEvq.mjs";import{n as t,r as n}from"./cache-CIPRF-pz.mjs";import{n as r}from"./v-514RME2X.mjs";import{n as i,r as a,t as o}from"./key-B89Z4vxn.mjs";import{d as s,f as c,t as l}from"./observation-Co72iCd1.mjs";import{o as u}from"./execution-context-rJXTRVrJ.mjs";import{t as d}from"./clock-CJotKAxc.mjs";const f=`:reval`,p=3e4;function scheduleBackground(e,t){let n=e.catch(()=>void 0);if(t)try{t(n)}catch{}}const m={ms:1,millisecond:1,milliseconds:1,s:1e3,sec:1e3,second:1e3,seconds:1e3,m:60*1e3,min:60*1e3,minute:60*1e3,minutes:60*1e3,h:3600*1e3,hr:3600*1e3,hour:3600*1e3,hours:3600*1e3,d:1440*60*1e3,day:1440*60*1e3,days:1440*60*1e3,w:10080*60*1e3,week:10080*60*1e3,weeks:10080*60*1e3,month:720*60*60*1e3,months:720*60*60*1e3},h=Object.keys(m).join(`, `),g=/^(\d+(?:\.\d+)?)\s*([a-z]+)$/;function parseTTL(e){if(typeof e==`number`){if(!Number.isFinite(e)||e<=0||e>2**53-1)throw new n(`TTL must be positive, got: ${e}`);return e}let t=e.trim().toLowerCase().match(g);if(!t)throw new n(`Invalid TTL format: "${e}". Expected format: "<number> <unit>" (e.g., "1 hour", "20 seconds")`);let r=t[1],i=t[2],a=Number.parseFloat(r),o=m[i];if(o===void 0)throw new n(`Unknown time unit: "${i}". Valid units: ${h}`);let s=Math.floor(a*o);if(!Number.isSafeInteger(s)||s<=0)throw new n(`TTL must be positive, got: ${s}ms from "${e}"`);return s}const _=r.object({invalidate:r.string({array:!0,optional:!0}),autoInvalidate:r.boolean({optional:!0,default:!0})},{optional:!0,default:{autoInvalidate:!0}});function hasCacheInvalidationWork(e){return e===void 0||e.autoInvalidate===!0||e?.invalidate!==void 0&&e.invalidate.length>0}const v=300*1e3,y=r.object({ttl:r.coerce(r.optional(r.union([r.string(),r.number()]),v),e=>parseTTL(e)),swr:r.coerce(r.optional(r.union([r.boolean(),r.string(),r.number()])),e=>e===void 0||typeof e==`boolean`?e:parseTTL(e)),key:r.string({optional:!0}),bypass:r.boolean({optional:!0})},{optional:!0,default:{ttl:v,swr:!1,bypass:!1}});let executeCachedWithResultCodecFriend,invalidateOfficialCacheFriend;const b=new WeakMap,x=new WeakMap,completeWithoutFacts=()=>void 0;function createCacheOutcome(e,t,n){return{event:e,status:t,at:Date.now(),error:n}}function recordCacheOutcome(e,t,n,r){if(e===void 0||l(u(e))?.wants(`cache-outcomes`)!==!0)return;let i=x.get(e);i===void 0&&(i={outcomes:[],completed:!1},x.set(e,i)),i.outcomes.push(createCacheOutcome(t,n,r))}function placeCacheSetFailure(e,t){let n=createCacheOutcome(`miss`,`cache-set-failed`,t),r=x.get(e);if(r!==void 0&&!r.completed){r.outcomes.push(n);return}return Object.freeze({kind:`cache`,outcomes:[n]})}function readCacheExecutionOutcomes(e){let t=x.get(e);if(t!==void 0)return()=>(t.completed=!0,Object.freeze([...t.outcomes]))}function createOfficialCacheScope(e){let t=Object.freeze({});return b.set(t,e),t}function readOfficialCacheNamespace(e){let n=b.get(e);if(n===void 0)throw new t(`Official cache scope is not authentic for this cache execution.`);return n}function refuseExternalScope(e){if(e!==void 0)throw new t(`Cache driver methods do not accept an external cache scope.`)}var CacheDriver=class{#e=0;driverName;clock;static{executeCachedWithResultCodecFriend=(e,t,n,r,i,a,o,s)=>{let c=readOfficialCacheNamespace(s);return e.#t(t,n,r,i,a,o,c)},invalidateOfficialCacheFriend=(e,t,n,r,i)=>e.#d(t,n,r,readOfficialCacheNamespace(i))}constructor(e,t=d){this.driverName=e,this.clock=t}async#t(e,t,n,r,i,o,s){let c=a(e,t,n),l=`${c.key}${i.key===void 0?``:`:${i.key}`}`,u=JSON.stringify([c.identity,i.key]),d=this.#e,executeCore=async()=>{if(i.bypass){let e=await r();return this.#r(l,e,i,o,s,u,d),recordCacheOutcome(i.executionContext,`bypass`),e}let n=await this.#n(l,i.executionContext,s,o,u);if(n){let a=this.clock.now()-n.createdAt;if(!(a>=n.ttl))return recordCacheOutcome(i.executionContext,`hit`),n.value;let c=i.swr;if(c!==!1&&a<c&&(n.expiresAt===void 0||this.clock.now()<n.expiresAt))return scheduleBackground(this.#a(e,t,l,r,i,c,o,s,u,d),i.waitUntil),recordCacheOutcome(i.executionContext,`hit`,`stale`),n.value}let a=await r();return this.#r(l,a,i,o,s,u,d),recordCacheOutcome(i.executionContext,`miss`),a};return executeCore()}async#n(e,t,n,r,i){let a=await this.#s(e,t,n);return a===null||a.identity!==i||!Number.isFinite(a.createdAt)||!Number.isFinite(a.ttl)||a.ttl<=0||a.expiresAt===void 0||!Number.isFinite(a.expiresAt)||a.expiresAt<a.createdAt?null:{createdAt:a.createdAt,ttl:a.ttl,expiresAt:a.expiresAt,value:r.materialize(a.value)}}#r(e,t,n,r,i,a,o){if(o!==this.#e)return;let s;try{s=r.snapshot(t)}catch(e){recordCacheOutcome(n.executionContext,`miss`,`cache-set-failed`,e);return}this.#i(e,s,n,i,a,o)}#i(e,t,n,r,i,a){scheduleBackground(this.#c(e,t,{ttl:n.ttlMs,swrTtl:n.swr===!1?void 0:n.swr},n.executionContext,r,n.executionContext,i,a).catch(()=>void 0),n.waitUntil)}async#a(e,t,n,r,i,a,o,c,l,d){let f;try{f=await this.#l(n,c)}catch{return}if(!f)return;let p=u(i.executionContext)?.observe,m=p===void 0||p.length===0?void 0:{failed:!1,error:void 0},h,doRevalidate=async()=>{let e;try{let t=await r(),s=o.snapshot(t);await this.#c(n,s,{ttl:i.ttlMs,swrTtl:a},i.executionContext,c,void 0,l,d),e=createCacheOutcome(`revalidate`,`success`)}catch(t){m!==void 0&&(m.failed=!0,m.error=t),e=createCacheOutcome(`revalidate`,`error`,t)}finally{if(m===void 0)await this.#u(n,c).catch(()=>void 0);else try{await this.#u(n,c)}catch(e){if(m.failed){let t=m.error;m.error=AggregateError([t,e],`Cache revalidation work and cleanup both failed.`,{cause:t})}else m.failed=!0,m.error=e}}return e};await(m===void 0?doRevalidate():s({kind:`cache`,operation:`revalidate`},p,async()=>{if(h=Object.freeze({kind:`cache`,outcomes:[await doRevalidate()]}),m.failed)throw m.error},void 0,()=>Object.freeze({kind:`cache`,context:i.executionContext,read:Object.freeze({model:e,operation:t,identity:i.driverIdentity}),complete:()=>h})))}#o(e,t,n,r=completeWithoutFacts,i){let a=u(t)?.observe;if(a===void 0||a.length===0)return n();let o=e===`clear`||e===`delete`;return s({kind:`cache`,operation:o?`invalidate`:e},o?c(a):a,n,void 0,()=>Object.freeze(o?{kind:`cache-backend`,boundary:e,driverName:this.driverName,complete:completeWithoutFacts}:{kind:`cache`,context:t,driverName:this.driverName,...i===void 0?{}:{ttl:i},complete:r}))}async _get(e,t,n){return refuseExternalScope(n),this.#s(e,t)}async#s(e,t,n){let r=this.#m(e,n),i;return this.#o(`get`,t,async()=>{let e=await this.get(r);return i=e?this.clock.now()-e.createdAt>e.ttl?`stale`:`hit`:`miss`,e},()=>i===void 0?void 0:Object.freeze({kind:`cache`,result:i}))}async _set(e,t,n,r,i){return refuseExternalScope(i),this.#c(e,t,n,r)}async#c(e,t,n,r,i,a,o,s){if(s!==void 0&&s!==this.#e)return;let c=this.#m(e,i),l={value:t,createdAt:this.clock.now(),ttl:n.ttl,...o===void 0?{}:{identity:o,expiresAt:this.clock.now()+(n.swrTtl??n.ttl)}},u=n.swrTtl??n.ttl;return this.#o(`set`,r,async()=>{await this.set(c,u,l),s!==void 0&&s!==this.#e&&await this.delete([c])},a===void 0?void 0:e=>e.status===`failure`?placeCacheSetFailure(a,e.failure):void 0,n.ttl)}async _delete(e,t,n){refuseExternalScope(n);let r=this.#m(e);return this.#f(r,t)}async _clear(e,t,n){refuseExternalScope(n);let r=this.#m(e??``);return this.#p(r,t)}async _markRevalidating(e,t){return refuseExternalScope(t),this.#l(e)}async#l(e,t){let n=`${this.#m(e,t)}${f}`,r=await this.get(n);if(r&&this.clock.now()-r.createdAt<r.ttl)return!1;let i={value:!0,createdAt:this.clock.now(),ttl:p};return await this.set(n,p,i),!0}async _clearRevalidating(e,t){return refuseExternalScope(t),this.#u(e)}async#u(e,t){let n=`${this.#m(e,t)}${f}`;await this.delete([n])}async _invalidate(e,t,n,r){return refuseExternalScope(r),this.#d(e,t,n)}async#d(e,t,n,r){if(!hasCacheInvalidationWork(t))return;this.#e+=1;let i=[];if((t===void 0||t.autoInvalidate===!0)&&i.push({kind:`clear`,prefixedKey:this.#m(r===void 0?`${e}:`:``,r)}),t?.invalidate)for(let e of t.invalidate){let t=e.endsWith(`*`),n=t?e.slice(0,-1):e;i.push({kind:t?`clear`:`delete`,prefixedKey:this.#m(n,r)})}return this.#o(`invalidate`,n,async()=>{let e=[];for(let t of i)e.push(t.kind===`clear`?this.#p(t.prefixedKey,n):this.#f(t.prefixedKey,n));await Promise.all(e)})}#f(e,t){this.#e+=1;let n=[e,`${e}${f}`];return this.#o(`delete`,t,()=>this.delete(n))}#p(e,t){return this.#e+=1,this.#o(`clear`,t,()=>this.clear(e))}#m(e,n){if(n!==void 0){if(e.startsWith(`${o}:`))throw new t(`Official cache keys and prefixes must be relative and cannot begin with 'viborm:'.`);return`${n}:${e}`}let r=e.startsWith(`${o}:`)?e:e?`${o}:${e}`:o;if(r===i||r.startsWith(`${i}:`))throw new t(`The official cache namespace requires an authenticated cache extension.`);return r}};function executeCachedWithResultCodec(e,t,n,r,i,a,o,s){return executeCachedWithResultCodecFriend(e,t,n,r,i,a,o,s)}function invalidateOfficialCache(e,t,n,r,i){return invalidateOfficialCacheFriend(e,t,n,r,i)}export{readCacheExecutionOutcomes as a,invalidateOfficialCache as i,createOfficialCacheScope as n,_ as o,executeCachedWithResultCodec as r,y as s,CacheDriver as t};
|
|
2
|
+
//# sourceMappingURL=driver-u2qJicrE.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"driver-BvP7eW0A.mjs","names":["v","#executeCached","#invalidateScoped","#fillRevision","result","#setResultInBackground","#getCachedResult","#revalidateInBackground","#getScoped","#setInBackground","#setScoped","#markRevalidatingScoped","#clearRevalidatingScoped","#prefixKey","#observe","#deletePrefixed","#clearPrefixed"],"sources":["../src/cache/cache-background.ts","../src/cache/ttl.ts","../src/cache/schema.ts","../src/cache/driver.ts"],"sourcesContent":["import type { WaitUntilFn } from \"./driver\";\n\nexport const REVALIDATING_SUFFIX = \":reval\";\nexport const REVALIDATING_TTL_MS = 30_000;\n\nexport function scheduleBackground(\n promise: Promise<unknown>,\n waitUntil: WaitUntilFn | undefined\n): void {\n const observed = promise.catch(() => undefined);\n if (!waitUntil) return;\n try {\n waitUntil(observed);\n } catch {\n // Background scheduling cannot alter the authoritative query outcome.\n }\n}\n","/**\n * TTL Parser\n *\n * Converts human-readable TTL strings to milliseconds.\n */\n\nimport { CacheInvalidTTLError } from \"@errors\";\n\n/**\n * Time unit multipliers in milliseconds\n */\nconst TIME_UNITS: Record<string, number> = {\n ms: 1,\n millisecond: 1,\n milliseconds: 1,\n s: 1000,\n sec: 1000,\n second: 1000,\n seconds: 1000,\n m: 60 * 1000,\n min: 60 * 1000,\n minute: 60 * 1000,\n minutes: 60 * 1000,\n h: 60 * 60 * 1000,\n hr: 60 * 60 * 1000,\n hour: 60 * 60 * 1000,\n hours: 60 * 60 * 1000,\n d: 24 * 60 * 60 * 1000,\n day: 24 * 60 * 60 * 1000,\n days: 24 * 60 * 60 * 1000,\n w: 7 * 24 * 60 * 60 * 1000,\n week: 7 * 24 * 60 * 60 * 1000,\n weeks: 7 * 24 * 60 * 60 * 1000,\n month: 30 * 24 * 60 * 60 * 1000,\n months: 30 * 24 * 60 * 60 * 1000,\n};\n\nconst VALID_UNITS = Object.keys(TIME_UNITS).join(\", \");\n\n/**\n * Parse a TTL string into milliseconds\n *\n * @example\n * parseTTL(\"1 hour\") // 3600000\n * parseTTL(\"20 seconds\") // 20000\n * parseTTL(\"5m\") // 300000\n * parseTTL(\"2.5 hours\") // 9000000\n * parseTTL(3000) // 3000 (passthrough)\n *\n * @throws CacheInvalidTTLError if format is invalid\n */\nconst TTL_PATTERN = /^(\\d+(?:\\.\\d+)?)\\s*([a-z]+)$/;\n\nexport function parseTTL(ttl: string | number): number {\n if (typeof ttl === \"number\") {\n if (!Number.isFinite(ttl) || ttl <= 0 || ttl > Number.MAX_SAFE_INTEGER) {\n throw new CacheInvalidTTLError(`TTL must be positive, got: ${ttl}`);\n }\n return ttl;\n }\n\n const normalized = ttl.trim().toLowerCase();\n\n // Match patterns like \"1 hour\", \"20seconds\", \"2.5 h\"\n const match = normalized.match(TTL_PATTERN);\n\n if (!match) {\n throw new CacheInvalidTTLError(\n `Invalid TTL format: \"${ttl}\". Expected format: \"<number> <unit>\" (e.g., \"1 hour\", \"20 seconds\")`\n );\n }\n\n const valueStr = match[1] as string;\n const unit = match[2] as string;\n const value = Number.parseFloat(valueStr);\n const multiplier = TIME_UNITS[unit];\n\n if (multiplier === undefined) {\n throw new CacheInvalidTTLError(\n `Unknown time unit: \"${unit}\". Valid units: ${VALID_UNITS}`\n );\n }\n\n const result = Math.floor(value * multiplier);\n\n if (!Number.isSafeInteger(result) || result <= 0) {\n throw new CacheInvalidTTLError(\n `TTL must be positive, got: ${result}ms from \"${ttl}\"`\n );\n }\n\n return result;\n}\n","import v, { type V } from \"@validation/primitives/v\";\nimport { parseTTL } from \"./ttl\";\n\n// =============================================================================\n// CACHE INVALIDATION SCHEMA (for mutations)\n// =============================================================================\n\nexport type CacheInvalidationSchemaEntries = {\n invalidate: V.String<{ array: true; optional: true }>;\n autoInvalidate: V.Boolean<{ optional: true }>;\n};\n\nexport type CacheInvalidationSchema = V.Object<\n CacheInvalidationSchemaEntries,\n { optional: true }\n>;\n\nexport const cacheInvalidationSchema = v.object(\n {\n /**\n * Specific keys to clear from cache\n * Can end with a * to invalidate all keys starting with the given prefix\n */\n invalidate: v.string({ array: true, optional: true }),\n /**\n * Automatically invalidate all entries in the bound cache scope after a durable mutation\n * @default true\n */\n autoInvalidate: v.boolean({ optional: true, default: true }),\n },\n { optional: true, default: { autoInvalidate: true } }\n);\n\n/**\n * Input type for cache invalidation options (inferred from schema)\n */\nexport type CacheInvalidationOptions =\n CacheInvalidationSchema[\" vibInferred\"][\"0\"];\n\n/** Whether normalized mutation options request any invalidation work. */\nexport function hasCacheInvalidationWork(\n options: CacheInvalidationOptions | undefined\n): boolean {\n return (\n options === undefined ||\n options.autoInvalidate === true ||\n (options?.invalidate !== undefined && options.invalidate.length > 0)\n );\n}\n\n// =============================================================================\n// WITH CACHE OPTIONS SCHEMA (for $withCache method)\n// =============================================================================\n\n/**\n * Default TTL: 5 minutes (in milliseconds)\n */\nexport const DEFAULT_CACHE_TTL = 5 * 60 * 1000;\n\nexport type WithCacheSchemaEntries = {\n ttl: V.Optional<V.Union<[V.String, V.Number]>>;\n swr: V.Optional<V.Union<[V.Boolean, V.String, V.Number]>>;\n key: V.String<{ optional: true }>;\n bypass: V.Boolean<{ optional: true }>;\n};\n\nexport type WithCacheSchema = V.Object<\n WithCacheSchemaEntries,\n { optional: true }\n>;\n\nexport const withCacheSchema = v.object(\n {\n /**\n * Time to live for cache entries\n * Can be a number (milliseconds) or a string like \"1 hour\", \"20 seconds\"\n * @default 300000 (5 minutes)\n */\n ttl: v.coerce(\n v.optional(v.union([v.string(), v.number()]), DEFAULT_CACHE_TTL),\n (value: string | number) => {\n return parseTTL(value);\n }\n ),\n /**\n * Enable stale-while-revalidate pattern\n * When true, returns stale data immediately and revalidates in background\n *\n * The value represents the \"stale window\" - how long data can be served stale.\n * Storage TTL is automatically calculated as `ttl + staleWindow`.\n *\n * Can be a boolean or a duration value (number in ms or string like \"1 hour\")\n * - true: stale window = ttl (storage TTL = 2x ttl)\n * - false/undefined: SWR disabled\n * - number/string: custom stale window duration (storage TTL = ttl + swr)\n * @default false\n */\n swr: v.coerce(\n v.optional(v.union([v.boolean(), v.string(), v.number()])),\n (value: boolean | string | number | undefined) => {\n if (value === undefined || typeof value === \"boolean\") {\n return value;\n }\n return parseTTL(value);\n }\n ),\n /**\n * The official cache extension retains the canonical model/operation/args\n * key and appends this value as a suffix contribution.\n */\n key: v.string({ optional: true }),\n /**\n * Bypass cache read and force fresh data\n * Still writes result to cache for subsequent requests\n * @default false\n */\n bypass: v.boolean({ optional: true }),\n },\n {\n optional: true,\n default: {\n ttl: DEFAULT_CACHE_TTL,\n swr: false,\n bypass: false,\n },\n }\n);\n\n/**\n * Input type for $withCache options (inferred from schema)\n */\nexport type WithCacheOptions = WithCacheSchema[\" vibInferred\"][\"0\"];\n","/**\n * Cache Driver\n *\n * Abstract base class for cache implementations.\n * Follows the same pattern as the database Driver class.\n * Handles both storage operations and cache orchestration (hit/miss/stale/SWR).\n */\n\nimport type { DriverIdentity } from \"@drivers/driver-identity\";\nimport { getExecutionExtensionChain } from \"@drivers/execution-context\";\nimport type { QueryExecutionContext } from \"@drivers/exports\";\nimport { CacheInvalidKeyError } from \"@errors\";\nimport {\n getOfficialInstrumentationChainCapability,\n runProtectedObservers,\n selectTrustedObservers,\n} from \"@extensions/observation\";\nimport type {\n CacheCompletionFacts,\n CacheOutcome,\n CacheUnitFacts,\n} from \"@extensions/official-facts\";\nimport { type Clock, systemClock } from \"../clock\";\nimport {\n REVALIDATING_SUFFIX,\n REVALIDATING_TTL_MS,\n scheduleBackground,\n} from \"./cache-background\";\nimport {\n CACHE_PREFIX,\n cacheLookupOf,\n OFFICIAL_CACHE_NAMESPACE_ROOT,\n} from \"./key\";\nimport {\n type CacheInvalidationOptions,\n hasCacheInvalidationWork,\n} from \"./schema\";\n\n/** Extend a request lifetime until background cache work settles. */\nexport type WaitUntilFn = (promise: Promise<unknown>) => void;\n\n/** Cache entry with freshness metadata for stale-while-revalidate. */\nexport interface CacheEntry<T = unknown> {\n value: T;\n createdAt: number;\n ttl: number;\n /** Exact operation identity on official detached entries. */\n identity?: string;\n /** Logical expiry, independent of a backend minimum physical TTL. */\n expiresAt?: number;\n}\n\n/** Storage options for a cache write. */\nexport interface CacheSetOptions {\n /** Time to live in milliseconds. */\n ttl: number;\n /** Storage TTL including the stale window, when SWR is enabled. */\n swrTtl?: number;\n}\n\n/** Parsed options for one cached ORM execution. */\nexport interface CacheExecutionOptions {\n ttlMs: number;\n swr: number | false;\n bypass: boolean;\n key?: string;\n waitUntil?: WaitUntilFn;\n /**\n * The database driver's identity, read once at `$withCache`; absent when\n * that read throws, and the revalidation root is presented without it.\n */\n driverIdentity?: DriverIdentity | undefined;\n executionContext?: QueryExecutionContext;\n}\n\nexport interface DetachedCacheResultCodec<T> {\n snapshot(value: T): unknown;\n materialize(snapshot: unknown): T;\n}\n\ninterface ObservedRevalidationFailure {\n failed: boolean;\n error: unknown;\n}\n\ntype ExecuteCachedWithResultCodec = <T>(\n cache: CacheDriver,\n modelName: string,\n operation: string,\n args: unknown,\n executor: () => Promise<T>,\n options: CacheExecutionOptions,\n codec: DetachedCacheResultCodec<T>,\n scope: object\n) => Promise<T>;\n\nlet executeCachedWithResultCodecFriend: ExecuteCachedWithResultCodec;\n\ntype InvalidateOfficialCache = (\n cache: CacheDriver,\n modelName: string,\n options: CacheInvalidationOptions | undefined,\n context: QueryExecutionContext | undefined,\n scope: object\n) => Promise<void>;\n\nlet invalidateOfficialCacheFriend: InvalidateOfficialCache;\n\nconst officialCacheNamespaces = new WeakMap<object, string>();\n\ninterface CacheOutcomeList {\n readonly outcomes: CacheOutcome[];\n /** Set once the operation completion has read the list. */\n completed: boolean;\n}\n\n/** One outcome list per logical cache execution, keyed by its context. */\nconst executionOutcomes = new WeakMap<\n QueryExecutionContext,\n CacheOutcomeList\n>();\n\nconst completeWithoutFacts = (): undefined => undefined;\n\nfunction createCacheOutcome(\n event: CacheOutcome[\"event\"],\n status?: string,\n error?: unknown\n): CacheOutcome {\n return { event, status, at: Date.now(), error };\n}\n\n/** Record one decision of this execution when its capability wants outcomes. */\nfunction recordCacheOutcome(\n context: QueryExecutionContext | undefined,\n event: CacheOutcome[\"event\"],\n status?: string,\n error?: unknown\n): void {\n if (\n context === undefined ||\n getOfficialInstrumentationChainCapability(\n getExecutionExtensionChain(context)\n )?.wants(\"cache-outcomes\") !== true\n ) {\n return;\n }\n let list = executionOutcomes.get(context);\n if (list === undefined) {\n list = { outcomes: [], completed: false };\n executionOutcomes.set(context, list);\n }\n list.outcomes.push(createCacheOutcome(event, status, error));\n}\n\n/**\n * A background set failure joins its execution's list while that list is still\n * open, so it presents after the logical miss; otherwise it completes the set\n * unit itself.\n */\nfunction placeCacheSetFailure(\n context: QueryExecutionContext,\n failure: unknown\n): CacheCompletionFacts | undefined {\n const outcome = createCacheOutcome(\"miss\", \"cache-set-failed\", failure);\n const list = executionOutcomes.get(context);\n if (list !== undefined && !list.completed) {\n list.outcomes.push(outcome);\n return undefined;\n }\n return Object.freeze({ kind: \"cache\", outcomes: [outcome] });\n}\n\n/** Close and read one execution's outcome list at its operation completion. */\nexport function readCacheExecutionOutcomes(\n context: QueryExecutionContext\n): (() => readonly CacheOutcome[]) | undefined {\n const list = executionOutcomes.get(context);\n if (list === undefined) return undefined;\n return () => {\n list.completed = true;\n return Object.freeze([...list.outcomes]);\n };\n}\n\n/** Create one opaque scope recognized only by this module's private namespace map. */\nexport function createOfficialCacheScope(namespace: string): object {\n const scope = Object.freeze({});\n officialCacheNamespaces.set(scope, namespace);\n return scope;\n}\n\nfunction readOfficialCacheNamespace(scope: object): string {\n const namespace = officialCacheNamespaces.get(scope);\n if (namespace === undefined) {\n throw new CacheInvalidKeyError(\n \"Official cache scope is not authentic for this cache execution.\"\n );\n }\n return namespace;\n}\n\nfunction refuseExternalScope(scope: unknown): void {\n if (scope === undefined) return;\n throw new CacheInvalidKeyError(\n \"Cache driver methods do not accept an external cache scope.\"\n );\n}\n\ninterface PreparedInvalidationTarget {\n readonly kind: \"clear\" | \"delete\";\n readonly prefixedKey: string;\n}\n\n/**\n * Abstract base class for cache drivers.\n *\n * Follows the same pattern as the database Driver class:\n * - Protected abstract methods for concrete implementations (non-underscored)\n * - Public underscored methods handle key prefixing, instrumentation, and delegation\n * - Instrumentation support\n * - Cache orchestration (hit/miss/stale/SWR logic)\n */\nexport abstract class CacheDriver {\n #fillRevision = 0;\n readonly driverName: string;\n /**\n * Every freshness decision this class makes reads from here. Internal seam,\n * not public API: it exists so tests can advance time rather than sleep\n * through a TTL. Defaults to the host clock.\n */\n protected readonly clock: Clock;\n\n static {\n executeCachedWithResultCodecFriend = (\n cache,\n modelName,\n operation,\n args,\n executor,\n options,\n codec,\n scope\n ) => {\n const namespace = readOfficialCacheNamespace(scope);\n return cache.#executeCached(\n modelName,\n operation,\n args,\n executor,\n options,\n codec,\n namespace\n );\n };\n invalidateOfficialCacheFriend = (\n cache,\n modelName,\n options,\n context,\n scope\n ) =>\n cache.#invalidateScoped(\n modelName,\n options,\n context,\n readOfficialCacheNamespace(scope)\n );\n }\n\n constructor(driverName: string, clock: Clock = systemClock) {\n this.driverName = driverName;\n this.clock = clock;\n }\n\n // ============================================================\n // ABSTRACT METHODS - Concrete drivers implement these\n // ============================================================\n\n /**\n * Get a value from cache\n */\n protected abstract get<T>(key: string): Promise<CacheEntry<T> | null>;\n\n /**\n * Set a value in cache\n * @param key - The cache key\n * @param storageTtl - TTL for the backing store (already SWR-compliant)\n * @param entry - Cache entry with user's original TTL for staleness checks\n */\n protected abstract set<T>(\n key: string,\n storageTtl: number,\n entry: CacheEntry<T>\n ): Promise<void>;\n\n /**\n * Delete keys from cache\n * @param keys - Array of keys to delete\n */\n protected abstract delete(keys: string[]): Promise<void>;\n\n /**\n * Clear cache by prefix\n * @param prefix - Always provided (at minimum CACHE_PREFIX to avoid clearing unrelated data)\n */\n protected abstract clear(prefix: string): Promise<void>;\n\n // ============================================================\n // CACHE ORCHESTRATION - Hit/Miss/Stale/SWR logic\n // ============================================================\n\n async #executeCached<T>(\n modelName: string,\n operation: string,\n args: unknown,\n executor: () => Promise<T>,\n options: CacheExecutionOptions,\n codec: DetachedCacheResultCodec<T>,\n namespace: string\n ): Promise<T> {\n const lookup = cacheLookupOf(modelName, operation, args);\n const cacheKey = `${lookup.key}${options.key === undefined ? \"\" : `:${options.key}`}`;\n const identity = JSON.stringify([lookup.identity, options.key]);\n const revision = this.#fillRevision;\n\n // Core execution logic\n const executeCore = async (): Promise<T> => {\n // Bypass cache read if requested\n if (options.bypass) {\n const result = await executor();\n this.#setResultInBackground(\n cacheKey,\n result,\n options,\n codec,\n namespace,\n identity,\n revision\n );\n recordCacheOutcome(options.executionContext, \"bypass\");\n return result;\n }\n\n // Try to get from cache\n const cached = await this.#getCachedResult<T>(\n cacheKey,\n options.executionContext,\n namespace,\n codec,\n identity\n );\n\n if (cached) {\n const age = this.clock.now() - cached.createdAt;\n const isStale = age >= cached.ttl;\n\n if (!isStale) {\n // Fresh cache hit\n recordCacheOutcome(options.executionContext, \"hit\");\n return cached.value;\n }\n\n const swrTtl = options.swr;\n if (\n swrTtl !== false &&\n age < swrTtl &&\n (cached.expiresAt === undefined ||\n this.clock.now() < cached.expiresAt)\n ) {\n // Stale but SWR enabled - return stale and revalidate in background\n scheduleBackground(\n this.#revalidateInBackground(\n modelName,\n operation,\n cacheKey,\n executor,\n options,\n swrTtl,\n codec,\n namespace,\n identity,\n revision\n ),\n options.waitUntil\n );\n recordCacheOutcome(options.executionContext, \"hit\", \"stale\");\n return cached.value;\n }\n\n // Stale and no SWR - fall through to fetch fresh\n }\n\n // Cache miss or stale without SWR - execute query\n const result = await executor();\n this.#setResultInBackground(\n cacheKey,\n result,\n options,\n codec,\n namespace,\n identity,\n revision\n );\n recordCacheOutcome(options.executionContext, \"miss\");\n return result;\n };\n\n return executeCore();\n }\n\n async #getCachedResult<T>(\n key: string,\n context: QueryExecutionContext | undefined,\n namespace: string,\n codec: DetachedCacheResultCodec<T>,\n identity: string\n ): Promise<CacheEntry<T> | null> {\n const cached = await this.#getScoped<unknown>(key, context, namespace);\n return cached === null ||\n cached.identity !== identity ||\n !Number.isFinite(cached.createdAt) ||\n !Number.isFinite(cached.ttl) ||\n cached.ttl <= 0 ||\n cached.expiresAt === undefined ||\n !Number.isFinite(cached.expiresAt) ||\n cached.expiresAt < cached.createdAt\n ? null\n : {\n createdAt: cached.createdAt,\n ttl: cached.ttl,\n expiresAt: cached.expiresAt,\n value: codec.materialize(cached.value),\n };\n }\n\n #setResultInBackground<T>(\n key: string,\n value: T,\n options: CacheExecutionOptions,\n codec: DetachedCacheResultCodec<T>,\n namespace: string,\n identity: string,\n revision: number\n ): void {\n if (revision !== this.#fillRevision) return;\n let stored: unknown;\n try {\n stored = codec.snapshot(value);\n } catch (error) {\n recordCacheOutcome(\n options.executionContext,\n \"miss\",\n \"cache-set-failed\",\n error\n );\n return;\n }\n this.#setInBackground(key, stored, options, namespace, identity, revision);\n }\n\n /**\n * Set cache value in background (non-blocking)\n */\n #setInBackground<T>(\n key: string,\n value: T,\n options: CacheExecutionOptions,\n namespace: string,\n identity: string,\n revision: number\n ): void {\n // The observed set unit presents a failure; without the catch it would\n // become an unhandled rejection.\n const cachePromise = this.#setScoped(\n key,\n value,\n {\n ttl: options.ttlMs,\n swrTtl: options.swr !== false ? options.swr : undefined,\n },\n options.executionContext,\n namespace,\n options.executionContext,\n identity,\n revision\n ).catch(() => undefined);\n\n scheduleBackground(cachePromise, options.waitUntil);\n }\n\n /**\n * Revalidate cache entry in background (for SWR)\n * Uses the backing cache marker for best-effort duplicate suppression.\n */\n async #revalidateInBackground<T>(\n modelName: string,\n operation: string,\n cacheKey: string,\n executor: () => Promise<T>,\n options: CacheExecutionOptions,\n swrTtl: number,\n codec: DetachedCacheResultCodec<T>,\n namespace: string,\n identity: string,\n revision: number\n ): Promise<void> {\n // Check whether another request has already published this marker.\n let shouldRevalidate: boolean;\n try {\n shouldRevalidate = await this.#markRevalidatingScoped(\n cacheKey,\n namespace\n );\n } catch {\n // If marking fails, skip revalidation to avoid request failure\n return;\n }\n if (!shouldRevalidate) {\n // Another request is handling revalidation, skip\n return;\n }\n\n const observers = getExecutionExtensionChain(\n options.executionContext\n )?.observe;\n const observedFailure: ObservedRevalidationFailure | undefined =\n observers === undefined || observers.length === 0\n ? undefined\n : { failed: false, error: undefined };\n // The observed child stores its terminal outcome before it settles, and the\n // rail reads completion facts only after that.\n let completion: CacheCompletionFacts | undefined;\n\n const doRevalidate = async (): Promise<CacheOutcome> => {\n let terminal: CacheOutcome;\n try {\n const result = await executor();\n const stored = codec.snapshot(result);\n await this.#setScoped(\n cacheKey,\n stored,\n {\n ttl: options.ttlMs,\n swrTtl,\n },\n options.executionContext,\n namespace,\n undefined,\n identity,\n revision\n );\n terminal = createCacheOutcome(\"revalidate\", \"success\");\n } catch (error) {\n // Log error but don't throw - this is background operation\n if (observedFailure !== undefined) {\n observedFailure.failed = true;\n observedFailure.error = error;\n }\n terminal = createCacheOutcome(\"revalidate\", \"error\", error);\n } finally {\n if (observedFailure === undefined) {\n await this.#clearRevalidatingScoped(cacheKey, namespace).catch(\n () => undefined\n );\n } else {\n try {\n await this.#clearRevalidatingScoped(cacheKey, namespace);\n } catch (cleanupFailure) {\n if (observedFailure.failed) {\n const workerFailure = observedFailure.error;\n observedFailure.error = new AggregateError(\n [workerFailure, cleanupFailure],\n \"Cache revalidation work and cleanup both failed.\",\n { cause: workerFailure }\n );\n } else {\n observedFailure.failed = true;\n observedFailure.error = cleanupFailure;\n }\n }\n }\n }\n return terminal;\n };\n\n const revalidationPromise =\n observedFailure === undefined\n ? doRevalidate()\n : runProtectedObservers(\n { kind: \"cache\", operation: \"revalidate\" },\n observers,\n async () => {\n completion = Object.freeze({\n kind: \"cache\",\n outcomes: [await doRevalidate()],\n });\n if (observedFailure.failed) throw observedFailure.error;\n },\n undefined,\n (): CacheUnitFacts =>\n Object.freeze({\n kind: \"cache\",\n context: options.executionContext,\n read: Object.freeze({\n model: modelName,\n operation,\n identity: options.driverIdentity,\n }),\n complete: () => completion,\n })\n );\n\n await revalidationPromise;\n }\n\n // ============================================================\n // PUBLIC API - Storage operations\n // ============================================================\n\n /**\n * Run one cache step inside its exact chain's observers. A backend delete or\n * clear has no public unit and reaches only the trusted observer.\n */\n #observe<T>(\n step: \"clear\" | \"delete\" | \"get\" | \"invalidate\" | \"set\",\n context: QueryExecutionContext | undefined,\n execute: () => Promise<T>,\n complete: CacheUnitFacts[\"complete\"] = completeWithoutFacts,\n ttl?: number\n ): Promise<T> {\n const observers = getExecutionExtensionChain(context)?.observe;\n // An unobserved step builds no unit and no facts closure, as the\n // revalidation above does. Measured on a no-op backend: without this, a get\n // allocates about 330 B more and takes about 16 ns longer.\n if (observers === undefined || observers.length === 0) return execute();\n const backend = step === \"clear\" || step === \"delete\";\n return runProtectedObservers(\n { kind: \"cache\", operation: backend ? \"invalidate\" : step },\n backend ? selectTrustedObservers(observers) : observers,\n execute,\n undefined,\n () =>\n Object.freeze(\n backend\n ? {\n kind: \"cache-backend\",\n boundary: step,\n driverName: this.driverName,\n complete: completeWithoutFacts,\n }\n : {\n kind: \"cache\",\n context,\n driverName: this.driverName,\n ...(ttl === undefined ? {} : { ttl }),\n complete,\n }\n )\n );\n }\n\n /**\n * Get a value from cache\n * @param key - Cache key (will be prefixed automatically)\n */\n _get<T>(\n key: string,\n context?: QueryExecutionContext\n ): Promise<CacheEntry<T> | null>;\n async _get<T>(\n key: string,\n context?: QueryExecutionContext,\n externalScope?: unknown\n ): Promise<CacheEntry<T> | null> {\n refuseExternalScope(externalScope);\n return this.#getScoped<T>(key, context);\n }\n\n async #getScoped<T>(\n key: string,\n context?: QueryExecutionContext,\n namespace?: string\n ): Promise<CacheEntry<T> | null> {\n const prefixedKey = this.#prefixKey(key, namespace);\n let cacheResult: \"hit\" | \"miss\" | \"stale\" | undefined;\n\n return this.#observe(\n \"get\",\n context,\n async () => {\n const entry = await this.get<T>(prefixedKey);\n if (entry) {\n const isStale = this.clock.now() - entry.createdAt > entry.ttl;\n cacheResult = isStale ? \"stale\" : \"hit\";\n } else {\n cacheResult = \"miss\";\n }\n return entry;\n },\n () =>\n cacheResult === undefined\n ? undefined\n : Object.freeze({ kind: \"cache\", result: cacheResult })\n );\n }\n\n /**\n * Set a value in cache\n * @param key - Cache key (will be prefixed automatically)\n * @param value - Value to cache\n * @param options - Cache options including TTL\n */\n _set<T>(\n key: string,\n value: T,\n options: CacheSetOptions,\n context?: QueryExecutionContext\n ): Promise<void>;\n async _set<T>(\n key: string,\n value: T,\n options: CacheSetOptions,\n context?: QueryExecutionContext,\n externalScope?: unknown\n ): Promise<void> {\n refuseExternalScope(externalScope);\n return this.#setScoped(key, value, options, context);\n }\n\n async #setScoped<T>(\n key: string,\n value: T,\n options: CacheSetOptions,\n context?: QueryExecutionContext,\n namespace?: string,\n /** The logical execution a background set belongs to, which a failure joins. */\n backgroundOf?: QueryExecutionContext,\n identity?: string,\n revision?: number\n ): Promise<void> {\n if (revision !== undefined && revision !== this.#fillRevision) return;\n const prefixedKey = this.#prefixKey(key, namespace);\n const entry: CacheEntry<T> = {\n value,\n createdAt: this.clock.now(),\n ttl: options.ttl,\n ...(identity === undefined\n ? {}\n : {\n identity,\n expiresAt: this.clock.now() + (options.swrTtl ?? options.ttl),\n }),\n };\n\n // Use SWR TTL if provided, otherwise just use regular TTL\n const storageTtl = options.swrTtl ?? options.ttl;\n\n return this.#observe(\n \"set\",\n context,\n async () => {\n await this.set(prefixedKey, storageTtl, entry);\n // A durable invalidation may finish while a backend set is pending.\n // Suppress this obsolete fill locally; generic KV remains eventual.\n if (revision !== undefined && revision !== this.#fillRevision)\n await this.delete([prefixedKey]);\n },\n backgroundOf === undefined\n ? undefined\n : (outcome) =>\n outcome.status === \"failure\"\n ? placeCacheSetFailure(backgroundOf, outcome.failure)\n : undefined,\n options.ttl\n );\n }\n\n /**\n * Delete a specific key (and its revalidating key)\n * @param key - Cache key (will be prefixed automatically)\n */\n _delete(key: string, context?: QueryExecutionContext): Promise<void>;\n async _delete(\n key: string,\n context?: QueryExecutionContext,\n externalScope?: unknown\n ): Promise<void> {\n refuseExternalScope(externalScope);\n const prefixedKey = this.#prefixKey(key);\n return this.#deletePrefixed(prefixedKey, context);\n }\n\n /**\n * Clear cache by prefix or all within the public unscoped namespace.\n * @param prefix - Optional prefix to clear (will be prefixed automatically)\n */\n _clear(prefix?: string, context?: QueryExecutionContext): Promise<void>;\n async _clear(\n prefix?: string,\n context?: QueryExecutionContext,\n externalScope?: unknown\n ): Promise<void> {\n refuseExternalScope(externalScope);\n const prefixedPrefix = this.#prefixKey(prefix ?? \"\");\n return this.#clearPrefixed(prefixedPrefix, context);\n }\n\n /**\n * Mark entry as revalidating (for SWR coordination)\n * Returns true if this caller should perform revalidation\n * @param key - Cache key (will be prefixed automatically)\n */\n _markRevalidating(key: string): Promise<boolean>;\n async _markRevalidating(\n key: string,\n externalScope?: unknown\n ): Promise<boolean> {\n refuseExternalScope(externalScope);\n return this.#markRevalidatingScoped(key);\n }\n\n async #markRevalidatingScoped(\n key: string,\n namespace?: string\n ): Promise<boolean> {\n const revalidatingKey = `${this.#prefixKey(key, namespace)}${REVALIDATING_SUFFIX}`;\n\n // Check if already revalidating\n const existing = await this.get(revalidatingKey);\n if (existing && this.clock.now() - existing.createdAt < existing.ttl)\n return false;\n\n // Set revalidating flag with short TTL\n const entry: CacheEntry<boolean> = {\n value: true,\n createdAt: this.clock.now(),\n ttl: REVALIDATING_TTL_MS,\n };\n await this.set(revalidatingKey, REVALIDATING_TTL_MS, entry);\n\n return true;\n }\n\n /**\n * Clear revalidating flag\n * @param key - Cache key (will be prefixed automatically)\n */\n _clearRevalidating(key: string): Promise<void>;\n async _clearRevalidating(\n key: string,\n externalScope?: unknown\n ): Promise<void> {\n refuseExternalScope(externalScope);\n return this.#clearRevalidatingScoped(key);\n }\n\n async #clearRevalidatingScoped(\n key: string,\n namespace?: string\n ): Promise<void> {\n const revalidatingKey = `${this.#prefixKey(key, namespace)}${REVALIDATING_SUFFIX}`;\n await this.delete([revalidatingKey]);\n }\n\n /**\n * Invalidate cache entries after a mutation\n * @param modelName - The model name for auto-invalidation\n * @param options - Cache invalidation options\n */\n _invalidate(\n modelName: string,\n options?: CacheInvalidationOptions,\n context?: QueryExecutionContext\n ): Promise<void>;\n async _invalidate(\n modelName: string,\n options?: CacheInvalidationOptions,\n context?: QueryExecutionContext,\n externalScope?: unknown\n ): Promise<void> {\n refuseExternalScope(externalScope);\n return this.#invalidateScoped(modelName, options, context);\n }\n\n async #invalidateScoped(\n modelName: string,\n options?: CacheInvalidationOptions,\n context?: QueryExecutionContext,\n namespace?: string\n ): Promise<void> {\n if (!hasCacheInvalidationWork(options)) return;\n this.#fillRevision += 1;\n const targets: PreparedInvalidationTarget[] = [];\n if (options === undefined || options.autoInvalidate === true) {\n targets.push({\n kind: \"clear\",\n prefixedKey: this.#prefixKey(\n namespace === undefined ? `${modelName}:` : \"\",\n namespace\n ),\n });\n }\n if (options?.invalidate) {\n for (const entry of options.invalidate) {\n const isPrefix = entry.endsWith(\"*\");\n const key = isPrefix ? entry.slice(0, -1) : entry;\n targets.push({\n kind: isPrefix ? \"clear\" : \"delete\",\n prefixedKey: this.#prefixKey(key, namespace),\n });\n }\n }\n return this.#observe(\"invalidate\", context, async () => {\n const promises: Promise<void>[] = [];\n for (const target of targets) {\n promises.push(\n target.kind === \"clear\"\n ? this.#clearPrefixed(target.prefixedKey, context)\n : this.#deletePrefixed(target.prefixedKey, context)\n );\n }\n await Promise.all(promises);\n });\n }\n\n /**\n * Optional: connect to cache backend\n */\n connect?(): Promise<void>;\n\n /**\n * Optional: disconnect from cache backend\n */\n disconnect?(): Promise<void>;\n\n // ============================================================\n // INTERNAL HELPERS\n // ============================================================\n\n #deletePrefixed(\n prefixedKey: string,\n context?: QueryExecutionContext\n ): Promise<void> {\n this.#fillRevision += 1;\n const keys = [prefixedKey, `${prefixedKey}${REVALIDATING_SUFFIX}`];\n return this.#observe(\"delete\", context, () => this.delete(keys));\n }\n\n #clearPrefixed(\n prefixedKey: string,\n context?: QueryExecutionContext\n ): Promise<void> {\n this.#fillRevision += 1;\n return this.#observe(\"clear\", context, () => this.clear(prefixedKey));\n }\n\n /**\n * Prefix a public storage key, or rebase an official relative key into its\n * authenticated extension namespace.\n *\n * An EMPTY relative key is the whole scope — `$invalidate(\"*\")` — and it\n * rebases to `<scope>:`, WITH the separator, because the storage backends\n * clear by `startsWith`. A bare `<scope>` would also match every sibling scope\n * whose namespace string merely extends this one, and one axis of the scope\n * grammar can do that: the cache `version` is the last component and its `s:`\n * body is variable-length, so `version: \"a\"` is a strict prefix of\n * `version: \"ab\"` at the same dialect and namespace. That axis is exactly what\n * §7.1 leaves users to partition SQLite and unbound MySQL databases with, so a\n * clear-all crossing it would empty a physically different database's entries.\n *\n * Adding the separator loses nothing: every key this scope can hold is written\n * through `#executeCached`, whose relative key is always\n * `<model>:<operation>:<hash>`, so no stored key is ever equal to the bare\n * scope. The unscoped arm below deliberately keeps its bare `viborm` root — a\n * public caller CAN store at exactly that key, there is only one such root,\n * and no sibling exists for a clear to cross into.\n */\n #prefixKey(key: string, namespace?: string): string {\n if (namespace !== undefined) {\n if (key.startsWith(`${CACHE_PREFIX}:`)) {\n throw new CacheInvalidKeyError(\n \"Official cache keys and prefixes must be relative and cannot begin with 'viborm:'.\"\n );\n }\n return `${namespace}:${key}`;\n }\n\n const prefixedKey = key.startsWith(`${CACHE_PREFIX}:`)\n ? key\n : key\n ? `${CACHE_PREFIX}:${key}`\n : CACHE_PREFIX;\n if (\n prefixedKey === OFFICIAL_CACHE_NAMESPACE_ROOT ||\n prefixedKey.startsWith(`${OFFICIAL_CACHE_NAMESPACE_ROOT}:`)\n ) {\n throw new CacheInvalidKeyError(\n \"The official cache namespace requires an authenticated cache extension.\"\n );\n }\n return prefixedKey;\n }\n}\n\n/** Internal cache-result seam; absent from the package cache barrel. */\nexport function executeCachedWithResultCodec<T>(\n cache: CacheDriver,\n modelName: string,\n operation: string,\n args: unknown,\n executor: () => Promise<T>,\n options: CacheExecutionOptions,\n codec: DetachedCacheResultCodec<T>,\n scope: object\n): Promise<T> {\n return executeCachedWithResultCodecFriend(\n cache,\n modelName,\n operation,\n args,\n executor,\n options,\n codec,\n scope\n );\n}\n\n/** Internal official invalidation seam; absent from the package cache barrel. */\nexport function invalidateOfficialCache(\n cache: CacheDriver,\n modelName: string,\n options: CacheInvalidationOptions | undefined,\n context: QueryExecutionContext | undefined,\n scope: object\n): Promise<void> {\n return invalidateOfficialCacheFriend(\n cache,\n modelName,\n options,\n context,\n scope\n );\n}\n"],"mappings":"8UAEA,MAAa,EAAsB,SACtB,EAAsB,IAEnC,SAAgB,mBACd,EACA,EACM,CACN,IAAM,EAAW,EAAQ,UAAY,IAAA,GAAU,CAC1C,KACL,GAAI,CACF,EAAU,EAAS,MACb,GCFV,MAAM,EAAqC,CACzC,GAAI,EACJ,YAAa,EACb,aAAc,EACd,EAAG,IACH,IAAK,IACL,OAAQ,IACR,QAAS,IACT,EAAG,GAAK,IACR,IAAK,GAAK,IACV,OAAQ,GAAK,IACb,QAAS,GAAK,IACd,EAAG,KAAU,IACb,GAAI,KAAU,IACd,KAAM,KAAU,IAChB,MAAO,KAAU,IACjB,EAAG,KAAU,GAAK,IAClB,IAAK,KAAU,GAAK,IACpB,KAAM,KAAU,GAAK,IACrB,EAAG,MAAc,GAAK,IACtB,KAAM,MAAc,GAAK,IACzB,MAAO,MAAc,GAAK,IAC1B,MAAO,IAAU,GAAK,GAAK,IAC3B,OAAQ,IAAU,GAAK,GAAK,IAC7B,CAEK,EAAc,OAAO,KAAK,EAAW,CAAC,KAAK,KAAK,CAchD,EAAc,+BAEpB,SAAgB,SAAS,EAA8B,CACrD,GAAI,OAAO,GAAQ,SAAU,CAC3B,GAAI,CAAC,OAAO,SAAS,EAAI,EAAI,GAAO,GAAK,UACvC,MAAM,IAAI,EAAqB,8BAA8B,IAAM,CAErE,OAAO,EAMT,IAAM,EAHa,EAAI,MAAM,CAAC,aAAa,CAGlB,MAAM,EAAY,CAE3C,GAAI,CAAC,EACH,MAAM,IAAI,EACR,wBAAwB,EAAI,sEAC7B,CAGH,IAAM,EAAW,EAAM,GACjB,EAAO,EAAM,GACb,EAAQ,OAAO,WAAW,EAAS,CACnC,EAAa,EA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B,GAAI,EAAI,WAAW,GAAG,EAAa,GAAG,CACpC,MAAM,IAAI,EACR,qFACD,CAEH,MAAO,GAAG,EAAU,GAAG,IAGzB,IAAM,EAAc,EAAI,WAAW,GAAG,EAAa,GAAG,CAClD,EACA,EACE,GAAG,EAAa,GAAG,IACnB,EACN,GACE,IAAgB,GAChB,EAAY,WAAW,GAAG,EAA8B,GAAG,CAE3D,MAAM,IAAI,EACR,0EACD,CAEH,OAAO,IAKX,SAAgB,6BACd,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACY,CACZ,OAAO,mCACL,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACD,CAIH,SAAgB,wBACd,EACA,EACA,EACA,EACA,EACe,CACf,OAAO,8BACL,EACA,EACA,EACA,EACA,EACD"}
|
|
1
|
+
{"version":3,"file":"driver-u2qJicrE.mjs","names":["v","#executeCached","#invalidateScoped","#fillRevision","result","#setResultInBackground","#getCachedResult","#revalidateInBackground","#getScoped","#setInBackground","#setScoped","#markRevalidatingScoped","#clearRevalidatingScoped","#prefixKey","#observe","#deletePrefixed","#clearPrefixed"],"sources":["../src/cache/cache-background.ts","../src/cache/ttl.ts","../src/cache/schema.ts","../src/cache/driver.ts"],"sourcesContent":["import type { WaitUntilFn } from \"./driver\";\n\nexport const REVALIDATING_SUFFIX = \":reval\";\nexport const REVALIDATING_TTL_MS = 30_000;\n\nexport function scheduleBackground(\n promise: Promise<unknown>,\n waitUntil: WaitUntilFn | undefined\n): void {\n const observed = promise.catch(() => undefined);\n if (!waitUntil) return;\n try {\n waitUntil(observed);\n } catch {\n // Background scheduling cannot alter the authoritative query outcome.\n }\n}\n","/**\n * TTL Parser\n *\n * Converts human-readable TTL strings to milliseconds.\n */\n\nimport { CacheInvalidTTLError } from \"@errors\";\n\n/**\n * Time unit multipliers in milliseconds\n */\nconst TIME_UNITS: Record<string, number> = {\n ms: 1,\n millisecond: 1,\n milliseconds: 1,\n s: 1000,\n sec: 1000,\n second: 1000,\n seconds: 1000,\n m: 60 * 1000,\n min: 60 * 1000,\n minute: 60 * 1000,\n minutes: 60 * 1000,\n h: 60 * 60 * 1000,\n hr: 60 * 60 * 1000,\n hour: 60 * 60 * 1000,\n hours: 60 * 60 * 1000,\n d: 24 * 60 * 60 * 1000,\n day: 24 * 60 * 60 * 1000,\n days: 24 * 60 * 60 * 1000,\n w: 7 * 24 * 60 * 60 * 1000,\n week: 7 * 24 * 60 * 60 * 1000,\n weeks: 7 * 24 * 60 * 60 * 1000,\n month: 30 * 24 * 60 * 60 * 1000,\n months: 30 * 24 * 60 * 60 * 1000,\n};\n\nconst VALID_UNITS = Object.keys(TIME_UNITS).join(\", \");\n\n/**\n * Parse a TTL string into milliseconds\n *\n * @example\n * parseTTL(\"1 hour\") // 3600000\n * parseTTL(\"20 seconds\") // 20000\n * parseTTL(\"5m\") // 300000\n * parseTTL(\"2.5 hours\") // 9000000\n * parseTTL(3000) // 3000 (passthrough)\n *\n * @throws CacheInvalidTTLError if format is invalid\n */\nconst TTL_PATTERN = /^(\\d+(?:\\.\\d+)?)\\s*([a-z]+)$/;\n\nexport function parseTTL(ttl: string | number): number {\n if (typeof ttl === \"number\") {\n if (!Number.isFinite(ttl) || ttl <= 0 || ttl > Number.MAX_SAFE_INTEGER) {\n throw new CacheInvalidTTLError(`TTL must be positive, got: ${ttl}`);\n }\n return ttl;\n }\n\n const normalized = ttl.trim().toLowerCase();\n\n // Match patterns like \"1 hour\", \"20seconds\", \"2.5 h\"\n const match = normalized.match(TTL_PATTERN);\n\n if (!match) {\n throw new CacheInvalidTTLError(\n `Invalid TTL format: \"${ttl}\". Expected format: \"<number> <unit>\" (e.g., \"1 hour\", \"20 seconds\")`\n );\n }\n\n const valueStr = match[1] as string;\n const unit = match[2] as string;\n const value = Number.parseFloat(valueStr);\n const multiplier = TIME_UNITS[unit];\n\n if (multiplier === undefined) {\n throw new CacheInvalidTTLError(\n `Unknown time unit: \"${unit}\". Valid units: ${VALID_UNITS}`\n );\n }\n\n const result = Math.floor(value * multiplier);\n\n if (!Number.isSafeInteger(result) || result <= 0) {\n throw new CacheInvalidTTLError(\n `TTL must be positive, got: ${result}ms from \"${ttl}\"`\n );\n }\n\n return result;\n}\n","import v, { type V } from \"@validation/primitives/v\";\nimport { parseTTL } from \"./ttl\";\n\n// =============================================================================\n// CACHE INVALIDATION SCHEMA (for mutations)\n// =============================================================================\n\nexport type CacheInvalidationSchemaEntries = {\n invalidate: V.String<{ array: true; optional: true }>;\n autoInvalidate: V.Boolean<{ optional: true }>;\n};\n\nexport type CacheInvalidationSchema = V.Object<\n CacheInvalidationSchemaEntries,\n { optional: true }\n>;\n\nexport const cacheInvalidationSchema = v.object(\n {\n /**\n * Specific keys to clear from cache\n * Can end with a * to invalidate all keys starting with the given prefix\n */\n invalidate: v.string({ array: true, optional: true }),\n /**\n * Automatically invalidate all entries in the bound cache scope after a durable mutation\n * @default true\n */\n autoInvalidate: v.boolean({ optional: true, default: true }),\n },\n { optional: true, default: { autoInvalidate: true } }\n);\n\n/**\n * Input type for cache invalidation options (inferred from schema)\n */\nexport type CacheInvalidationOptions =\n CacheInvalidationSchema[\" vibInferred\"][\"0\"];\n\n/** Whether normalized mutation options request any invalidation work. */\nexport function hasCacheInvalidationWork(\n options: CacheInvalidationOptions | undefined\n): boolean {\n return (\n options === undefined ||\n options.autoInvalidate === true ||\n (options?.invalidate !== undefined && options.invalidate.length > 0)\n );\n}\n\n// =============================================================================\n// WITH CACHE OPTIONS SCHEMA (for $withCache method)\n// =============================================================================\n\n/**\n * Default TTL: 5 minutes (in milliseconds)\n */\nexport const DEFAULT_CACHE_TTL = 5 * 60 * 1000;\n\nexport type WithCacheSchemaEntries = {\n ttl: V.Optional<V.Union<[V.String, V.Number]>>;\n swr: V.Optional<V.Union<[V.Boolean, V.String, V.Number]>>;\n key: V.String<{ optional: true }>;\n bypass: V.Boolean<{ optional: true }>;\n};\n\nexport type WithCacheSchema = V.Object<\n WithCacheSchemaEntries,\n { optional: true }\n>;\n\nexport const withCacheSchema = v.object(\n {\n /**\n * Time to live for cache entries\n * Can be a number (milliseconds) or a string like \"1 hour\", \"20 seconds\"\n * @default 300000 (5 minutes)\n */\n ttl: v.coerce(\n v.optional(v.union([v.string(), v.number()]), DEFAULT_CACHE_TTL),\n (value: string | number) => {\n return parseTTL(value);\n }\n ),\n /**\n * Enable stale-while-revalidate pattern\n * When true, returns stale data immediately and revalidates in background\n *\n * The value represents the \"stale window\" - how long data can be served stale.\n * Storage TTL is automatically calculated as `ttl + staleWindow`.\n *\n * Can be a boolean or a duration value (number in ms or string like \"1 hour\")\n * - true: stale window = ttl (storage TTL = 2x ttl)\n * - false/undefined: SWR disabled\n * - number/string: custom stale window duration (storage TTL = ttl + swr)\n * @default false\n */\n swr: v.coerce(\n v.optional(v.union([v.boolean(), v.string(), v.number()])),\n (value: boolean | string | number | undefined) => {\n if (value === undefined || typeof value === \"boolean\") {\n return value;\n }\n return parseTTL(value);\n }\n ),\n /**\n * The official cache extension retains the canonical model/operation/args\n * key and appends this value as a suffix contribution.\n */\n key: v.string({ optional: true }),\n /**\n * Bypass cache read and force fresh data\n * Still writes result to cache for subsequent requests\n * @default false\n */\n bypass: v.boolean({ optional: true }),\n },\n {\n optional: true,\n default: {\n ttl: DEFAULT_CACHE_TTL,\n swr: false,\n bypass: false,\n },\n }\n);\n\n/**\n * Input type for $withCache options (inferred from schema)\n */\nexport type WithCacheOptions = WithCacheSchema[\" vibInferred\"][\"0\"];\n","/**\n * Cache Driver\n *\n * Abstract base class for cache implementations.\n * Follows the same pattern as the database Driver class.\n * Handles both storage operations and cache orchestration (hit/miss/stale/SWR).\n */\n\nimport type { DriverIdentity } from \"@drivers/driver-identity\";\nimport { getExecutionExtensionChain } from \"@drivers/execution-context\";\nimport type { QueryExecutionContext } from \"@drivers/exports\";\nimport { CacheInvalidKeyError } from \"@errors\";\nimport {\n getOfficialInstrumentationChainCapability,\n runProtectedObservers,\n selectTrustedObservers,\n} from \"@extensions/observation\";\nimport type {\n CacheCompletionFacts,\n CacheOutcome,\n CacheUnitFacts,\n} from \"@extensions/official-facts\";\nimport { type Clock, systemClock } from \"../clock\";\nimport {\n REVALIDATING_SUFFIX,\n REVALIDATING_TTL_MS,\n scheduleBackground,\n} from \"./cache-background\";\nimport {\n CACHE_PREFIX,\n cacheLookupOf,\n OFFICIAL_CACHE_NAMESPACE_ROOT,\n} from \"./key\";\nimport {\n type CacheInvalidationOptions,\n hasCacheInvalidationWork,\n} from \"./schema\";\n\n/** Extend a request lifetime until background cache work settles. */\nexport type WaitUntilFn = (promise: Promise<unknown>) => void;\n\n/** Cache entry with freshness metadata for stale-while-revalidate. */\nexport interface CacheEntry<T = unknown> {\n value: T;\n createdAt: number;\n ttl: number;\n /** Exact operation identity on official detached entries. */\n identity?: string;\n /** Logical expiry, independent of a backend minimum physical TTL. */\n expiresAt?: number;\n}\n\n/** Storage options for a cache write. */\nexport interface CacheSetOptions {\n /** Time to live in milliseconds. */\n ttl: number;\n /** Storage TTL including the stale window, when SWR is enabled. */\n swrTtl?: number;\n}\n\n/** Parsed options for one cached ORM execution. */\nexport interface CacheExecutionOptions {\n ttlMs: number;\n swr: number | false;\n bypass: boolean;\n key?: string;\n waitUntil?: WaitUntilFn;\n /**\n * The database driver's identity, read once at `$withCache`; absent when\n * that read throws, and the revalidation root is presented without it.\n */\n driverIdentity?: DriverIdentity | undefined;\n executionContext?: QueryExecutionContext;\n}\n\nexport interface DetachedCacheResultCodec<T> {\n snapshot(value: T): unknown;\n materialize(snapshot: unknown): T;\n}\n\ninterface ObservedRevalidationFailure {\n failed: boolean;\n error: unknown;\n}\n\ntype ExecuteCachedWithResultCodec = <T>(\n cache: CacheDriver,\n modelName: string,\n operation: string,\n args: unknown,\n executor: () => Promise<T>,\n options: CacheExecutionOptions,\n codec: DetachedCacheResultCodec<T>,\n scope: object\n) => Promise<T>;\n\nlet executeCachedWithResultCodecFriend: ExecuteCachedWithResultCodec;\n\ntype InvalidateOfficialCache = (\n cache: CacheDriver,\n modelName: string,\n options: CacheInvalidationOptions | undefined,\n context: QueryExecutionContext | undefined,\n scope: object\n) => Promise<void>;\n\nlet invalidateOfficialCacheFriend: InvalidateOfficialCache;\n\nconst officialCacheNamespaces = new WeakMap<object, string>();\n\ninterface CacheOutcomeList {\n readonly outcomes: CacheOutcome[];\n /** Set once the operation completion has read the list. */\n completed: boolean;\n}\n\n/** One outcome list per logical cache execution, keyed by its context. */\nconst executionOutcomes = new WeakMap<\n QueryExecutionContext,\n CacheOutcomeList\n>();\n\nconst completeWithoutFacts = (): undefined => undefined;\n\nfunction createCacheOutcome(\n event: CacheOutcome[\"event\"],\n status?: string,\n error?: unknown\n): CacheOutcome {\n return { event, status, at: Date.now(), error };\n}\n\n/** Record one decision of this execution when its capability wants outcomes. */\nfunction recordCacheOutcome(\n context: QueryExecutionContext | undefined,\n event: CacheOutcome[\"event\"],\n status?: string,\n error?: unknown\n): void {\n if (\n context === undefined ||\n getOfficialInstrumentationChainCapability(\n getExecutionExtensionChain(context)\n )?.wants(\"cache-outcomes\") !== true\n ) {\n return;\n }\n let list = executionOutcomes.get(context);\n if (list === undefined) {\n list = { outcomes: [], completed: false };\n executionOutcomes.set(context, list);\n }\n list.outcomes.push(createCacheOutcome(event, status, error));\n}\n\n/**\n * A background set failure joins its execution's list while that list is still\n * open, so it presents after the logical miss; otherwise it completes the set\n * unit itself.\n */\nfunction placeCacheSetFailure(\n context: QueryExecutionContext,\n failure: unknown\n): CacheCompletionFacts | undefined {\n const outcome = createCacheOutcome(\"miss\", \"cache-set-failed\", failure);\n const list = executionOutcomes.get(context);\n if (list !== undefined && !list.completed) {\n list.outcomes.push(outcome);\n return undefined;\n }\n return Object.freeze({ kind: \"cache\", outcomes: [outcome] });\n}\n\n/** Close and read one execution's outcome list at its operation completion. */\nexport function readCacheExecutionOutcomes(\n context: QueryExecutionContext\n): (() => readonly CacheOutcome[]) | undefined {\n const list = executionOutcomes.get(context);\n if (list === undefined) return undefined;\n return () => {\n list.completed = true;\n return Object.freeze([...list.outcomes]);\n };\n}\n\n/** Create one opaque scope recognized only by this module's private namespace map. */\nexport function createOfficialCacheScope(namespace: string): object {\n const scope = Object.freeze({});\n officialCacheNamespaces.set(scope, namespace);\n return scope;\n}\n\nfunction readOfficialCacheNamespace(scope: object): string {\n const namespace = officialCacheNamespaces.get(scope);\n if (namespace === undefined) {\n throw new CacheInvalidKeyError(\n \"Official cache scope is not authentic for this cache execution.\"\n );\n }\n return namespace;\n}\n\nfunction refuseExternalScope(scope: unknown): void {\n if (scope === undefined) return;\n throw new CacheInvalidKeyError(\n \"Cache driver methods do not accept an external cache scope.\"\n );\n}\n\ninterface PreparedInvalidationTarget {\n readonly kind: \"clear\" | \"delete\";\n readonly prefixedKey: string;\n}\n\n/**\n * Abstract base class for cache drivers.\n *\n * Follows the same pattern as the database Driver class:\n * - Protected abstract methods for concrete implementations (non-underscored)\n * - Public underscored methods handle key prefixing, instrumentation, and delegation\n * - Instrumentation support\n * - Cache orchestration (hit/miss/stale/SWR logic)\n */\nexport abstract class CacheDriver {\n #fillRevision = 0;\n readonly driverName: string;\n /**\n * Every freshness decision this class makes reads from here. Internal seam,\n * not public API: it exists so tests can advance time rather than sleep\n * through a TTL. Defaults to the host clock.\n */\n protected readonly clock: Clock;\n\n static {\n executeCachedWithResultCodecFriend = (\n cache,\n modelName,\n operation,\n args,\n executor,\n options,\n codec,\n scope\n ) => {\n const namespace = readOfficialCacheNamespace(scope);\n return cache.#executeCached(\n modelName,\n operation,\n args,\n executor,\n options,\n codec,\n namespace\n );\n };\n invalidateOfficialCacheFriend = (\n cache,\n modelName,\n options,\n context,\n scope\n ) =>\n cache.#invalidateScoped(\n modelName,\n options,\n context,\n readOfficialCacheNamespace(scope)\n );\n }\n\n constructor(driverName: string, clock: Clock = systemClock) {\n this.driverName = driverName;\n this.clock = clock;\n }\n\n // ============================================================\n // ABSTRACT METHODS - Concrete drivers implement these\n // ============================================================\n\n /**\n * Get a value from cache\n */\n protected abstract get<T>(key: string): Promise<CacheEntry<T> | null>;\n\n /**\n * Set a value in cache\n * @param key - The cache key\n * @param storageTtl - TTL for the backing store (already SWR-compliant)\n * @param entry - Cache entry with user's original TTL for staleness checks\n */\n protected abstract set<T>(\n key: string,\n storageTtl: number,\n entry: CacheEntry<T>\n ): Promise<void>;\n\n /**\n * Delete keys from cache\n * @param keys - Array of keys to delete\n */\n protected abstract delete(keys: string[]): Promise<void>;\n\n /**\n * Clear cache by prefix\n * @param prefix - Always provided (at minimum CACHE_PREFIX to avoid clearing unrelated data)\n */\n protected abstract clear(prefix: string): Promise<void>;\n\n // ============================================================\n // CACHE ORCHESTRATION - Hit/Miss/Stale/SWR logic\n // ============================================================\n\n async #executeCached<T>(\n modelName: string,\n operation: string,\n args: unknown,\n executor: () => Promise<T>,\n options: CacheExecutionOptions,\n codec: DetachedCacheResultCodec<T>,\n namespace: string\n ): Promise<T> {\n const lookup = cacheLookupOf(modelName, operation, args);\n const cacheKey = `${lookup.key}${options.key === undefined ? \"\" : `:${options.key}`}`;\n const identity = JSON.stringify([lookup.identity, options.key]);\n const revision = this.#fillRevision;\n\n // Core execution logic\n const executeCore = async (): Promise<T> => {\n // Bypass cache read if requested\n if (options.bypass) {\n const result = await executor();\n this.#setResultInBackground(\n cacheKey,\n result,\n options,\n codec,\n namespace,\n identity,\n revision\n );\n recordCacheOutcome(options.executionContext, \"bypass\");\n return result;\n }\n\n // Try to get from cache\n const cached = await this.#getCachedResult<T>(\n cacheKey,\n options.executionContext,\n namespace,\n codec,\n identity\n );\n\n if (cached) {\n const age = this.clock.now() - cached.createdAt;\n const isStale = age >= cached.ttl;\n\n if (!isStale) {\n // Fresh cache hit\n recordCacheOutcome(options.executionContext, \"hit\");\n return cached.value;\n }\n\n const swrTtl = options.swr;\n if (\n swrTtl !== false &&\n age < swrTtl &&\n (cached.expiresAt === undefined ||\n this.clock.now() < cached.expiresAt)\n ) {\n // Stale but SWR enabled - return stale and revalidate in background\n scheduleBackground(\n this.#revalidateInBackground(\n modelName,\n operation,\n cacheKey,\n executor,\n options,\n swrTtl,\n codec,\n namespace,\n identity,\n revision\n ),\n options.waitUntil\n );\n recordCacheOutcome(options.executionContext, \"hit\", \"stale\");\n return cached.value;\n }\n\n // Stale and no SWR - fall through to fetch fresh\n }\n\n // Cache miss or stale without SWR - execute query\n const result = await executor();\n this.#setResultInBackground(\n cacheKey,\n result,\n options,\n codec,\n namespace,\n identity,\n revision\n );\n recordCacheOutcome(options.executionContext, \"miss\");\n return result;\n };\n\n return executeCore();\n }\n\n async #getCachedResult<T>(\n key: string,\n context: QueryExecutionContext | undefined,\n namespace: string,\n codec: DetachedCacheResultCodec<T>,\n identity: string\n ): Promise<CacheEntry<T> | null> {\n const cached = await this.#getScoped<unknown>(key, context, namespace);\n return cached === null ||\n cached.identity !== identity ||\n !Number.isFinite(cached.createdAt) ||\n !Number.isFinite(cached.ttl) ||\n cached.ttl <= 0 ||\n cached.expiresAt === undefined ||\n !Number.isFinite(cached.expiresAt) ||\n cached.expiresAt < cached.createdAt\n ? null\n : {\n createdAt: cached.createdAt,\n ttl: cached.ttl,\n expiresAt: cached.expiresAt,\n value: codec.materialize(cached.value),\n };\n }\n\n #setResultInBackground<T>(\n key: string,\n value: T,\n options: CacheExecutionOptions,\n codec: DetachedCacheResultCodec<T>,\n namespace: string,\n identity: string,\n revision: number\n ): void {\n if (revision !== this.#fillRevision) return;\n let stored: unknown;\n try {\n stored = codec.snapshot(value);\n } catch (error) {\n recordCacheOutcome(\n options.executionContext,\n \"miss\",\n \"cache-set-failed\",\n error\n );\n return;\n }\n this.#setInBackground(key, stored, options, namespace, identity, revision);\n }\n\n /**\n * Set cache value in background (non-blocking)\n */\n #setInBackground<T>(\n key: string,\n value: T,\n options: CacheExecutionOptions,\n namespace: string,\n identity: string,\n revision: number\n ): void {\n // The observed set unit presents a failure; without the catch it would\n // become an unhandled rejection.\n const cachePromise = this.#setScoped(\n key,\n value,\n {\n ttl: options.ttlMs,\n swrTtl: options.swr !== false ? options.swr : undefined,\n },\n options.executionContext,\n namespace,\n options.executionContext,\n identity,\n revision\n ).catch(() => undefined);\n\n scheduleBackground(cachePromise, options.waitUntil);\n }\n\n /**\n * Revalidate cache entry in background (for SWR)\n * Uses the backing cache marker for best-effort duplicate suppression.\n */\n async #revalidateInBackground<T>(\n modelName: string,\n operation: string,\n cacheKey: string,\n executor: () => Promise<T>,\n options: CacheExecutionOptions,\n swrTtl: number,\n codec: DetachedCacheResultCodec<T>,\n namespace: string,\n identity: string,\n revision: number\n ): Promise<void> {\n // Check whether another request has already published this marker.\n let shouldRevalidate: boolean;\n try {\n shouldRevalidate = await this.#markRevalidatingScoped(\n cacheKey,\n namespace\n );\n } catch {\n // If marking fails, skip revalidation to avoid request failure\n return;\n }\n if (!shouldRevalidate) {\n // Another request is handling revalidation, skip\n return;\n }\n\n const observers = getExecutionExtensionChain(\n options.executionContext\n )?.observe;\n const observedFailure: ObservedRevalidationFailure | undefined =\n observers === undefined || observers.length === 0\n ? undefined\n : { failed: false, error: undefined };\n // The observed child stores its terminal outcome before it settles, and the\n // rail reads completion facts only after that.\n let completion: CacheCompletionFacts | undefined;\n\n const doRevalidate = async (): Promise<CacheOutcome> => {\n let terminal: CacheOutcome;\n try {\n const result = await executor();\n const stored = codec.snapshot(result);\n await this.#setScoped(\n cacheKey,\n stored,\n {\n ttl: options.ttlMs,\n swrTtl,\n },\n options.executionContext,\n namespace,\n undefined,\n identity,\n revision\n );\n terminal = createCacheOutcome(\"revalidate\", \"success\");\n } catch (error) {\n // Log error but don't throw - this is background operation\n if (observedFailure !== undefined) {\n observedFailure.failed = true;\n observedFailure.error = error;\n }\n terminal = createCacheOutcome(\"revalidate\", \"error\", error);\n } finally {\n if (observedFailure === undefined) {\n await this.#clearRevalidatingScoped(cacheKey, namespace).catch(\n () => undefined\n );\n } else {\n try {\n await this.#clearRevalidatingScoped(cacheKey, namespace);\n } catch (cleanupFailure) {\n if (observedFailure.failed) {\n const workerFailure = observedFailure.error;\n observedFailure.error = new AggregateError(\n [workerFailure, cleanupFailure],\n \"Cache revalidation work and cleanup both failed.\",\n { cause: workerFailure }\n );\n } else {\n observedFailure.failed = true;\n observedFailure.error = cleanupFailure;\n }\n }\n }\n }\n return terminal;\n };\n\n const revalidationPromise =\n observedFailure === undefined\n ? doRevalidate()\n : runProtectedObservers(\n { kind: \"cache\", operation: \"revalidate\" },\n observers,\n async () => {\n completion = Object.freeze({\n kind: \"cache\",\n outcomes: [await doRevalidate()],\n });\n if (observedFailure.failed) throw observedFailure.error;\n },\n undefined,\n (): CacheUnitFacts =>\n Object.freeze({\n kind: \"cache\",\n context: options.executionContext,\n read: Object.freeze({\n model: modelName,\n operation,\n identity: options.driverIdentity,\n }),\n complete: () => completion,\n })\n );\n\n await revalidationPromise;\n }\n\n // ============================================================\n // PUBLIC API - Storage operations\n // ============================================================\n\n /**\n * Run one cache step inside its exact chain's observers. A backend delete or\n * clear has no public unit and reaches only the trusted observer.\n */\n #observe<T>(\n step: \"clear\" | \"delete\" | \"get\" | \"invalidate\" | \"set\",\n context: QueryExecutionContext | undefined,\n execute: () => Promise<T>,\n complete: CacheUnitFacts[\"complete\"] = completeWithoutFacts,\n ttl?: number\n ): Promise<T> {\n const observers = getExecutionExtensionChain(context)?.observe;\n // An unobserved step builds no unit and no facts closure, as the\n // revalidation above does. Measured on a no-op backend: without this, a get\n // allocates about 330 B more and takes about 16 ns longer.\n if (observers === undefined || observers.length === 0) return execute();\n const backend = step === \"clear\" || step === \"delete\";\n return runProtectedObservers(\n { kind: \"cache\", operation: backend ? \"invalidate\" : step },\n backend ? selectTrustedObservers(observers) : observers,\n execute,\n undefined,\n () =>\n Object.freeze(\n backend\n ? {\n kind: \"cache-backend\",\n boundary: step,\n driverName: this.driverName,\n complete: completeWithoutFacts,\n }\n : {\n kind: \"cache\",\n context,\n driverName: this.driverName,\n ...(ttl === undefined ? {} : { ttl }),\n complete,\n }\n )\n );\n }\n\n /**\n * Get a value from cache\n * @param key - Cache key (will be prefixed automatically)\n */\n _get<T>(\n key: string,\n context?: QueryExecutionContext\n ): Promise<CacheEntry<T> | null>;\n async _get<T>(\n key: string,\n context?: QueryExecutionContext,\n externalScope?: unknown\n ): Promise<CacheEntry<T> | null> {\n refuseExternalScope(externalScope);\n return this.#getScoped<T>(key, context);\n }\n\n async #getScoped<T>(\n key: string,\n context?: QueryExecutionContext,\n namespace?: string\n ): Promise<CacheEntry<T> | null> {\n const prefixedKey = this.#prefixKey(key, namespace);\n let cacheResult: \"hit\" | \"miss\" | \"stale\" | undefined;\n\n return this.#observe(\n \"get\",\n context,\n async () => {\n const entry = await this.get<T>(prefixedKey);\n if (entry) {\n const isStale = this.clock.now() - entry.createdAt > entry.ttl;\n cacheResult = isStale ? \"stale\" : \"hit\";\n } else {\n cacheResult = \"miss\";\n }\n return entry;\n },\n () =>\n cacheResult === undefined\n ? undefined\n : Object.freeze({ kind: \"cache\", result: cacheResult })\n );\n }\n\n /**\n * Set a value in cache\n * @param key - Cache key (will be prefixed automatically)\n * @param value - Value to cache\n * @param options - Cache options including TTL\n */\n _set<T>(\n key: string,\n value: T,\n options: CacheSetOptions,\n context?: QueryExecutionContext\n ): Promise<void>;\n async _set<T>(\n key: string,\n value: T,\n options: CacheSetOptions,\n context?: QueryExecutionContext,\n externalScope?: unknown\n ): Promise<void> {\n refuseExternalScope(externalScope);\n return this.#setScoped(key, value, options, context);\n }\n\n async #setScoped<T>(\n key: string,\n value: T,\n options: CacheSetOptions,\n context?: QueryExecutionContext,\n namespace?: string,\n /** The logical execution a background set belongs to, which a failure joins. */\n backgroundOf?: QueryExecutionContext,\n identity?: string,\n revision?: number\n ): Promise<void> {\n if (revision !== undefined && revision !== this.#fillRevision) return;\n const prefixedKey = this.#prefixKey(key, namespace);\n const entry: CacheEntry<T> = {\n value,\n createdAt: this.clock.now(),\n ttl: options.ttl,\n ...(identity === undefined\n ? {}\n : {\n identity,\n expiresAt: this.clock.now() + (options.swrTtl ?? options.ttl),\n }),\n };\n\n // Use SWR TTL if provided, otherwise just use regular TTL\n const storageTtl = options.swrTtl ?? options.ttl;\n\n return this.#observe(\n \"set\",\n context,\n async () => {\n await this.set(prefixedKey, storageTtl, entry);\n // A durable invalidation may finish while a backend set is pending.\n // Suppress this obsolete fill locally; generic KV remains eventual.\n if (revision !== undefined && revision !== this.#fillRevision)\n await this.delete([prefixedKey]);\n },\n backgroundOf === undefined\n ? undefined\n : (outcome) =>\n outcome.status === \"failure\"\n ? placeCacheSetFailure(backgroundOf, outcome.failure)\n : undefined,\n options.ttl\n );\n }\n\n /**\n * Delete a specific key (and its revalidating key)\n * @param key - Cache key (will be prefixed automatically)\n */\n _delete(key: string, context?: QueryExecutionContext): Promise<void>;\n async _delete(\n key: string,\n context?: QueryExecutionContext,\n externalScope?: unknown\n ): Promise<void> {\n refuseExternalScope(externalScope);\n const prefixedKey = this.#prefixKey(key);\n return this.#deletePrefixed(prefixedKey, context);\n }\n\n /**\n * Clear cache by prefix or all within the public unscoped namespace.\n * @param prefix - Optional prefix to clear (will be prefixed automatically)\n */\n _clear(prefix?: string, context?: QueryExecutionContext): Promise<void>;\n async _clear(\n prefix?: string,\n context?: QueryExecutionContext,\n externalScope?: unknown\n ): Promise<void> {\n refuseExternalScope(externalScope);\n const prefixedPrefix = this.#prefixKey(prefix ?? \"\");\n return this.#clearPrefixed(prefixedPrefix, context);\n }\n\n /**\n * Mark entry as revalidating (for SWR coordination)\n * Returns true if this caller should perform revalidation\n * @param key - Cache key (will be prefixed automatically)\n */\n _markRevalidating(key: string): Promise<boolean>;\n async _markRevalidating(\n key: string,\n externalScope?: unknown\n ): Promise<boolean> {\n refuseExternalScope(externalScope);\n return this.#markRevalidatingScoped(key);\n }\n\n async #markRevalidatingScoped(\n key: string,\n namespace?: string\n ): Promise<boolean> {\n const revalidatingKey = `${this.#prefixKey(key, namespace)}${REVALIDATING_SUFFIX}`;\n\n // Check if already revalidating\n const existing = await this.get(revalidatingKey);\n if (existing && this.clock.now() - existing.createdAt < existing.ttl)\n return false;\n\n // Set revalidating flag with short TTL\n const entry: CacheEntry<boolean> = {\n value: true,\n createdAt: this.clock.now(),\n ttl: REVALIDATING_TTL_MS,\n };\n await this.set(revalidatingKey, REVALIDATING_TTL_MS, entry);\n\n return true;\n }\n\n /**\n * Clear revalidating flag\n * @param key - Cache key (will be prefixed automatically)\n */\n _clearRevalidating(key: string): Promise<void>;\n async _clearRevalidating(\n key: string,\n externalScope?: unknown\n ): Promise<void> {\n refuseExternalScope(externalScope);\n return this.#clearRevalidatingScoped(key);\n }\n\n async #clearRevalidatingScoped(\n key: string,\n namespace?: string\n ): Promise<void> {\n const revalidatingKey = `${this.#prefixKey(key, namespace)}${REVALIDATING_SUFFIX}`;\n await this.delete([revalidatingKey]);\n }\n\n /**\n * Invalidate cache entries after a mutation\n * @param modelName - The model name for auto-invalidation\n * @param options - Cache invalidation options\n */\n _invalidate(\n modelName: string,\n options?: CacheInvalidationOptions,\n context?: QueryExecutionContext\n ): Promise<void>;\n async _invalidate(\n modelName: string,\n options?: CacheInvalidationOptions,\n context?: QueryExecutionContext,\n externalScope?: unknown\n ): Promise<void> {\n refuseExternalScope(externalScope);\n return this.#invalidateScoped(modelName, options, context);\n }\n\n async #invalidateScoped(\n modelName: string,\n options?: CacheInvalidationOptions,\n context?: QueryExecutionContext,\n namespace?: string\n ): Promise<void> {\n if (!hasCacheInvalidationWork(options)) return;\n this.#fillRevision += 1;\n const targets: PreparedInvalidationTarget[] = [];\n if (options === undefined || options.autoInvalidate === true) {\n targets.push({\n kind: \"clear\",\n prefixedKey: this.#prefixKey(\n namespace === undefined ? `${modelName}:` : \"\",\n namespace\n ),\n });\n }\n if (options?.invalidate) {\n for (const entry of options.invalidate) {\n const isPrefix = entry.endsWith(\"*\");\n const key = isPrefix ? entry.slice(0, -1) : entry;\n targets.push({\n kind: isPrefix ? \"clear\" : \"delete\",\n prefixedKey: this.#prefixKey(key, namespace),\n });\n }\n }\n return this.#observe(\"invalidate\", context, async () => {\n const promises: Promise<void>[] = [];\n for (const target of targets) {\n promises.push(\n target.kind === \"clear\"\n ? this.#clearPrefixed(target.prefixedKey, context)\n : this.#deletePrefixed(target.prefixedKey, context)\n );\n }\n await Promise.all(promises);\n });\n }\n\n /**\n * Optional: connect to cache backend\n */\n connect?(): Promise<void>;\n\n /**\n * Optional: disconnect from cache backend\n */\n disconnect?(): Promise<void>;\n\n // ============================================================\n // INTERNAL HELPERS\n // ============================================================\n\n #deletePrefixed(\n prefixedKey: string,\n context?: QueryExecutionContext\n ): Promise<void> {\n this.#fillRevision += 1;\n const keys = [prefixedKey, `${prefixedKey}${REVALIDATING_SUFFIX}`];\n return this.#observe(\"delete\", context, () => this.delete(keys));\n }\n\n #clearPrefixed(\n prefixedKey: string,\n context?: QueryExecutionContext\n ): Promise<void> {\n this.#fillRevision += 1;\n return this.#observe(\"clear\", context, () => this.clear(prefixedKey));\n }\n\n /**\n * Prefix a public storage key, or rebase an official relative key into its\n * authenticated extension namespace.\n *\n * An EMPTY relative key is the whole scope — `$invalidate(\"*\")` — and it\n * rebases to `<scope>:`, WITH the separator, because the storage backends\n * clear by `startsWith`. A bare `<scope>` would also match every sibling scope\n * whose namespace string merely extends this one, and one axis of the scope\n * grammar can do that: the cache `version` is the last component and its `s:`\n * body is variable-length, so `version: \"a\"` is a strict prefix of\n * `version: \"ab\"` at the same dialect and namespace. That axis is exactly what\n * §7.1 leaves users to partition SQLite and unbound MySQL databases with, so a\n * clear-all crossing it would empty a physically different database's entries.\n *\n * Adding the separator loses nothing: every key this scope can hold is written\n * through `#executeCached`, whose relative key is always\n * `<model>:<operation>:<hash>`, so no stored key is ever equal to the bare\n * scope. The unscoped arm below deliberately keeps its bare `viborm` root — a\n * public caller CAN store at exactly that key, there is only one such root,\n * and no sibling exists for a clear to cross into.\n */\n #prefixKey(key: string, namespace?: string): string {\n if (namespace !== undefined) {\n if (key.startsWith(`${CACHE_PREFIX}:`)) {\n throw new CacheInvalidKeyError(\n \"Official cache keys and prefixes must be relative and cannot begin with 'viborm:'.\"\n );\n }\n return `${namespace}:${key}`;\n }\n\n const prefixedKey = key.startsWith(`${CACHE_PREFIX}:`)\n ? key\n : key\n ? `${CACHE_PREFIX}:${key}`\n : CACHE_PREFIX;\n if (\n prefixedKey === OFFICIAL_CACHE_NAMESPACE_ROOT ||\n prefixedKey.startsWith(`${OFFICIAL_CACHE_NAMESPACE_ROOT}:`)\n ) {\n throw new CacheInvalidKeyError(\n \"The official cache namespace requires an authenticated cache extension.\"\n );\n }\n return prefixedKey;\n }\n}\n\n/** Internal cache-result seam; absent from the package cache barrel. */\nexport function executeCachedWithResultCodec<T>(\n cache: CacheDriver,\n modelName: string,\n operation: string,\n args: unknown,\n executor: () => Promise<T>,\n options: CacheExecutionOptions,\n codec: DetachedCacheResultCodec<T>,\n scope: object\n): Promise<T> {\n return executeCachedWithResultCodecFriend(\n cache,\n modelName,\n operation,\n args,\n executor,\n options,\n codec,\n scope\n );\n}\n\n/** Internal official invalidation seam; absent from the package cache barrel. */\nexport function invalidateOfficialCache(\n cache: CacheDriver,\n modelName: string,\n options: CacheInvalidationOptions | undefined,\n context: QueryExecutionContext | undefined,\n scope: object\n): Promise<void> {\n return invalidateOfficialCacheFriend(\n cache,\n modelName,\n options,\n context,\n scope\n );\n}\n"],"mappings":"8UAEA,MAAa,EAAsB,SACtB,EAAsB,IAEnC,SAAgB,mBACd,EACA,EACM,CACN,IAAM,EAAW,EAAQ,UAAY,IAAA,GAAU,CAC1C,KACL,GAAI,CACF,EAAU,EAAS,MACb,GCFV,MAAM,EAAqC,CACzC,GAAI,EACJ,YAAa,EACb,aAAc,EACd,EAAG,IACH,IAAK,IACL,OAAQ,IACR,QAAS,IACT,EAAG,GAAK,IACR,IAAK,GAAK,IACV,OAAQ,GAAK,IACb,QAAS,GAAK,IACd,EAAG,KAAU,IACb,GAAI,KAAU,IACd,KAAM,KAAU,IAChB,MAAO,KAAU,IACjB,EAAG,KAAU,GAAK,IAClB,IAAK,KAAU,GAAK,IACpB,KAAM,KAAU,GAAK,IACrB,EAAG,MAA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CAC7C,CAAC,CAGN,OAAO,MAAA,EAAc,aAAc,EAAS,SAAY,CACtD,IAAM,EAA4B,EAAE,CACpC,IAAK,IAAM,KAAU,EACnB,EAAS,KACP,EAAO,OAAS,QACZ,MAAA,EAAoB,EAAO,YAAa,EAAQ,CAChD,MAAA,EAAqB,EAAO,YAAa,EAAQ,CACtD,CAEH,MAAM,QAAQ,IAAI,EAAS,EAC3B,CAiBJ,GACE,EACA,EACe,CACf,MAAA,GAAsB,EACtB,IAAM,EAAO,CAAC,EAAa,GAAG,IAAc,IAAsB,CAClE,OAAO,MAAA,EAAc,SAAU,MAAe,KAAK,OAAO,EAAK,CAAC,CAGlE,GACE,EACA,EACe,CAEf,MADA,OAAA,GAAsB,EACf,MAAA,EAAc,QAAS,MAAe,KAAK,MAAM,EAAY,CAAC,CAwBvE,GAAW,EAAa,EAA4B,CAClD,GAAI,IAAc,IAAA,GAAW,CAC3B,GAAI,EAAI,WAAW,GAAG,EAAa,GAAG,CACpC,MAAM,IAAI,EACR,qFACD,CAEH,MAAO,GAAG,EAAU,GAAG,IAGzB,IAAM,EAAc,EAAI,WAAW,GAAG,EAAa,GAAG,CAClD,EACA,EACE,GAAG,EAAa,GAAG,IACnB,EACN,GACE,IAAgB,GAChB,EAAY,WAAW,GAAG,EAA8B,GAAG,CAE3D,MAAM,IAAI,EACR,0EACD,CAEH,OAAO,IAKX,SAAgB,6BACd,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACY,CACZ,OAAO,mCACL,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACD,CAIH,SAAgB,wBACd,EACA,EACA,EACA,EACA,EACe,CACf,OAAO,8BACL,EACA,EACA,EACA,EACA,EACD"}
|
package/dist/driver.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { An as BatchQuery, Ci as UniqueConstraintError, En as sqliteResultParser, Li as isRetryableError, Mn as Dialect, Nn as QueryExecutionContext, Pn as QueryResult, Si as NotNullConstraintError, ai as FeatureNotSupportedError, bi as CheckConstraintError, f as SQLITE_MIGRATION_CAPABILITY, fi as QueryError, h as DriverResultParser, ii as ConnectionError, l as AnyDriver, ni as TransactionError, p as SqliteMigrationCapability, u as Driver, xi as ForeignKeyError } from "./index-
|
|
1
|
+
import { An as BatchQuery, Ci as UniqueConstraintError, En as sqliteResultParser, Li as isRetryableError, Mn as Dialect, Nn as QueryExecutionContext, Pn as QueryResult, Si as NotNullConstraintError, ai as FeatureNotSupportedError, bi as CheckConstraintError, f as SQLITE_MIGRATION_CAPABILITY, fi as QueryError, h as DriverResultParser, ii as ConnectionError, l as AnyDriver, ni as TransactionError, p as SqliteMigrationCapability, u as Driver, xi as ForeignKeyError } from "./index-B4IWFJfv.mjs";
|
|
2
2
|
export { type AnyDriver, type BatchQuery, CheckConstraintError, ConnectionError, type Dialect, Driver, type DriverResultParser, FeatureNotSupportedError, ForeignKeyError, NotNullConstraintError, QueryError, type QueryExecutionContext, type QueryResult, SQLITE_MIGRATION_CAPABILITY, type SqliteMigrationCapability, TransactionError, UniqueConstraintError, isRetryableError, sqliteResultParser };
|
package/dist/driver.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./base-D3m1S7Uc.mjs";import{b as t,v as n,x as r,y as i}from"./error-mapping-6op318w6.mjs";import{a,i as o,p as s}from"./validation-gwZYm3Yn.mjs";import{n as c}from"./transaction-4dfqals6.mjs";import{n as l,t as u}from"./driver-
|
|
1
|
+
import{r as e}from"./base-D3m1S7Uc.mjs";import{b as t,v as n,x as r,y as i}from"./error-mapping-6op318w6.mjs";import{a,i as o,p as s}from"./validation-gwZYm3Yn.mjs";import{n as c}from"./transaction-4dfqals6.mjs";import{n as l,t as u}from"./driver-CQQbCQh9.mjs";import{l as d}from"./sqlite-utils-C0TyzOys.mjs";export{n as CheckConstraintError,o as ConnectionError,u as Driver,a as FeatureNotSupportedError,i as ForeignKeyError,t as NotNullConstraintError,s as QueryError,l as SQLITE_MIGRATION_CAPABILITY,c as TransactionError,r as UniqueConstraintError,e as isRetryableError,d as sqliteResultParser};
|