import type { Context } from 'hono' import type * as App from '../../App.js' import type * as Db from '../../db/Db.js' import * as FundingProvider from '../../internal/funding/Provider.js' const sourceScopes = new WeakMap() let nextSourceScope = 0 /** Returns an inventory cache key scoped by request URL, providers, and database source. */ export function key(c: Context) { const url = new URL(c.req.url) const providers = c .get('providers') .filter(FundingProvider.is) .map((provider) => provider.id) .sort() url.searchParams.set('__tempo_database', String(sourceScope(c.get('dbCached')))) url.searchParams.set('__tempo_providers', providers.join(',')) return url.toString() } function sourceScope(source: Db.Source) { const current = sourceScopes.get(source) if (current !== undefined) return current // A production isolate has one source, while multi-app runtimes receive distinct scopes. const scope = nextSourceScope++ sourceScopes.set(source, scope) return scope }