import type { Upstream } from '../upstream.ts'; import type { CacheContext } from './cache.ts'; /** Everything a gateway route reads from: the network through `Upstream`, the cache, and the two * microcosm services it passes through to. */ export interface Gateway extends CacheContext { fetch: Upstream; /** This worker's origin. Cache keys live under it. */ origin: string; slingshot: string; constellation: string; } /** A cache key: a URL under this worker's origin, with the params in a fixed order so equivalent * requests share one entry. */ export function cacheKey(g: Gateway, path: string, params: Record): string { const url = new URL(path, g.origin); for (const [name, value] of Object.entries(params).sort(([a], [b]) => a.localeCompare(b))) { if (value !== undefined) url.searchParams.set(name, value); } return url.toString(); }