@rsc-kit/core 0.27.1 → 0.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/broadcast.d.ts +22 -0
- package/dist/broadcast.js +109 -0
- package/dist/broadcast.js.map +1 -0
- package/dist/changed.d.ts +114 -31
- package/dist/changed.js +271 -37
- package/dist/changed.js.map +1 -1
- package/dist/js/refreshOn.d.ts +9 -1
- package/dist/js/refreshOn.js +12 -1
- package/dist/js/refreshOn.js.map +1 -1
- package/dist/testHost.d.ts +15 -4
- package/dist/testHost.js +2 -11
- package/dist/testHost.js.map +1 -1
- package/package.json +2 -2
package/dist/changed.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"changed.js","sourceRoot":"","sources":["../src/changed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAe,CAAC;AAgChD,0FAA0F;AAC1F,MAAM,UAAU,cAAc;IAC5B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC3C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAc,CAAC;IAEtC,MAAM,SAAS,GAAG,CAAC,KAA6B,EAA0B,EAAE;QAC1E,MAAM,GAAG,GAA2B,EAAE,CAAC;QAEvC,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACjD,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAExC,IAAI,OAAO,KAAK,IAAI;gBAAE,GAAG,CAAC,IAAI,CAAC,GAAG,OAAO,C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AI,CAAC,CAAC;YACjD,CAAC;YAED,oEAAoE;YACpE,yEAAyE;YACzE,iEAAiE;YACjE,KAAK,aAAa,EAAE;iBACjB,OAAO,CAAC,KAAK,EAAE,eAAe,CAAC;iBAC/B,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;gBACd,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;oBACjD,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC3B,CAAC,CAAC;iBACD,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;YAEnB,IAAI,CAAC,OAAO;gBAAE,KAAK,IAAI,EAAE,CAAC;;gBACrB,IAAI,EAAE,EAAE,CAAC;QAChB,CAAC;QACD,MAAM;YACJ,IAAI,MAAM;gBAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACrC,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE;QACxB,OAAO,EAAE;YACP,cAAc,EAAE,kCAAkC;YAClD,oEAAoE;YACpE,6DAA6D;YAC7D,eAAe,EAAE,wBAAwB;YACzC,mBAAmB,EAAE,IAAI;SAC1B;KACF,CAAC,CAAC;AACL,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,YAAY;IAC1B,OAAO,CAAC,KAAK,EAAE,CAAC;IAChB,KAAK,CAAC,KAAK,EAAE,CAAC;IACd,MAAM,GAAG,KAAK,CAAC;IACf,OAAO,OAAO,CAAC,YAAY,CAAC,CAAC;AAC/B,CAAC;AAED,oDAAoD;AACpD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,WAAW,CAAC","sourcesContent":["/**\n * Names: a name for data a page depends on, so whatever changes it can say so\n * from anywhere - a webhook, a job, another visitor's action - and every open\n * tab showing it refreshes.\n *\n * // a section says what it depends on\n * export default section('repos', Repos, { refreshOn: ({ params }) => [`team:${params.team}:repos`] })\n *\n * // and whatever changes it says so\n * changed(`team:${team}:repos`) // here, from a route.ts or an action\n * rsckit.Changed(ctx, \"team:1:repos\") // or the backend, from its webhook\n * Rsc::changed(\"team:$team:repos\"); // Laravel\n *\n * A name has a version: a number that moves whenever something says the name\n * changed. Nothing else - not what changed, not the data. A page learns the\n * versions at render; one stream per open tab watches them; when one moves,\n * the sections carrying that name ask for themselves again, the way refresh()\n * does. Data is never pushed, which is what keeps this working on a host that\n * cannot hold state: a version is a read.\n *\n * Where versions live is the source's business. Without a backend they are in\n * this process, which is one instance. With one, the backend keeps them - in\n * its cache or a table, shared by every instance it runs - and answers\n * `__rsc.changed`: given the versions a watcher holds, the ones that differ now.\n * A backend that can wait holds the call until one does; one that cannot\n * answers at once, and the watcher asks again on its interval. The protocol\n * is the same either way, and so is the page.\n */\n\nimport { frame, keepaliveMs } from \"./events.js\";\nimport { HEADER } from \"./headers.js\";\n\n/** The reserved name a backend answers name versions on. */\nexport const CHANGED_FUNCTION = \"__rsc.changed\";\n\n/** What `__rsc.changed` is asked. */\nexport interface ChangedQuery {\n /** The versions the asker holds. A name never changed is 0; -1 asks for every current version. */\n since: Record<string, number>;\n /** How long the backend may hold the call waiting for one to differ, in ms. It may answer at once. */\n wait?: number;\n}\n\n/** What `__rsc.changed` answers: the versions among `since` that differ now. */\nexport interface ChangedAnswer {\n versions: Record<string, number>;\n}\n\n/**\n * Where name versions are read from, and - when they live here - bumped.\n *\n * `changed` answers the versions among `since` that differ now, and may wait\n * up to `wait` ms for one to. Nothing else is required of it, which is why a\n * backend's cache, a table, this process's memory, or a pub/sub that answers\n * the moment a name moves all fit behind it.\n */\nexport interface VersionSource {\n changed(\n since: Record<string, number>,\n wait: number,\n ): Promise<Record<string, number>>;\n /** Say these names changed. Only a source that holds its own versions can. */\n bump(names: string[]): void | Promise<void>;\n}\n\n/** Versions kept in this process: the source without a backend, and the one tests use. */\nexport function memoryVersions(): VersionSource {\n const versions = new Map<string, number>();\n const waiters = new Set<() => void>();\n\n const differing = (since: Record<string, number>): Record<string, number> => {\n const out: Record<string, number> = {};\n\n for (const [name, held] of Object.entries(since)) {\n const current = versions.get(name) ?? 0;\n\n if (current !== held) out[name] = current;\n }\n\n return out;\n };\n\n return {\n async changed(since, wait) {\n const now = differing(since);\n\n if (Object.keys(now).length > 0 || wait <= 0) return now;\n\n await new Promise<void>((resolve) => {\n const done = () => {\n clearTimeout(timer);\n waiters.delete(done);\n resolve();\n };\n const timer = setTimeout(done, wait);\n\n // A test or a build must not be held open by a watcher's wait.\n (timer as { unref?: () => void }).unref?.();\n waiters.add(done);\n });\n\n return differing(since);\n },\n bump(names) {\n for (const name of names)\n versions.set(name, (versions.get(name) ?? 0) + 1);\n for (const wake of [...waiters]) wake();\n },\n };\n}\n\ntype HostFn = (name: string, ...args: unknown[]) => Promise<unknown>;\n\n/**\n * Versions kept by the backend, read through `__rsc.changed`.\n *\n * A backend that has not got the function - an adapter from before names, or\n * a host of plain rpc functions - is answered from this process instead,\n * found out on the first ask and remembered, so a page with names still works\n * on it: one instance, versions bumped by `changed()` here.\n */\nexport function backendVersions(call: HostFn): VersionSource {\n let local: VersionSource | null = null;\n\n // A backend's \"no such function\", or the test host's \"no handler for\".\n const unknown = (error: unknown): boolean =>\n /no host function named|has no handler for/i.test(\n error instanceof Error ? error.message : String(error),\n );\n\n return {\n async changed(since, wait) {\n if (local) return local.changed(since, wait);\n\n try {\n const answer = (await call(CHANGED_FUNCTION, {\n since,\n wait,\n } satisfies ChangedQuery)) as Partial<ChangedAnswer> | null;\n\n return answer?.versions ?? {};\n } catch (error) {\n if (!unknown(error)) throw error;\n\n local = memoryVersions();\n\n return local.changed(since, wait);\n }\n },\n bump(names) {\n if (local) return local.bump(names);\n\n throw new Error(\n \"changed() bumps versions this process keeps, and a backend keeps these: say the name changed there - \" +\n \"rsckit.Changed(ctx, ...) in Go, Rsc::changed(...) in Laravel.\",\n );\n },\n };\n}\n\n/** Runs one statement with positional parameters and resolves to its rows. */\nexport type SqlQuery = (\n text: string,\n params: unknown[],\n) => Promise<readonly Record<string, unknown>[]>;\n\nexport interface SqlVersionsOptions {\n /**\n * Your driver, as a function of SQL text and parameters:\n *\n * query: (text, params) => sql.unsafe(text, params) // postgres.js, Bun.sql\n * query: async (text, params) => (await pool.query(text, params)).rows // node-postgres\n */\n query: SqlQuery;\n /** The table: `CREATE TABLE rsc_versions (name TEXT PRIMARY KEY, version BIGINT NOT NULL)`. */\n table?: string;\n /** How the n-th parameter is written (1-based). Default `?`; Postgres is `(n) => '$' + n`. */\n placeholder?: (n: number) => string;\n /**\n * Called once with a function that wakes every waiting ask, for a database\n * that can say the moment a version moved - Postgres's LISTEN:\n *\n * listen: (wake) => sql.listen('rsc_versions', wake)\n *\n * Without it, a waiting ask reads the table every `poll` ms.\n */\n listen?: (wake: () => void) => unknown;\n /**\n * Run after every bump, to tell the other instances - Postgres's NOTIFY:\n *\n * notify: () => sql.notify('rsc_versions', '')\n */\n notify?: () => unknown;\n /** How often a waiting ask reads the table. Default 1000ms. */\n poll?: number;\n}\n\n/**\n * Versions in a table every instance shares: the web servers, and the worker\n * that finishes a job and says so. The same table and columns Go's\n * `SQLVersions` uses, so a Go service and a JavaScript worker can share one.\n *\n * installVersionSource(sqlVersions({\n * query: (text, params) => sql.unsafe(text, params),\n * placeholder: (n) => '$' + n,\n * listen: (wake) => sql.listen('rsc_versions', wake),\n * notify: () => sql.notify('rsc_versions', ''),\n * }))\n *\n * Written with an UPDATE and, the first time, an INSERT - two statements any\n * SQL dialect has - rather than an upsert each spells differently. Takes the\n * app's own driver, so the engine has no database dependency of its own.\n */\nexport function sqlVersions(options: SqlVersionsOptions): VersionSource {\n const { query } = options;\n const table = options.table ?? \"rsc_versions\";\n const mark = options.placeholder ?? (() => \"?\");\n\n return createVersions(\n {\n async read(names) {\n const rows = await query(\n `SELECT name, version FROM ${table} WHERE name IN (${names.map((_, i) => mark(i + 1)).join(\", \")})`,\n names,\n );\n\n // A BIGINT comes back as a string from most drivers.\n return Object.fromEntries(\n rows.map((row) => [String(row.name), Number(row.version)]),\n );\n },\n async bump(names) {\n const update = `UPDATE ${table} SET version = version + 1 WHERE name = ${mark(1)}`;\n const insert = `INSERT INTO ${table} (name, version) VALUES (${mark(1)}, 1)`;\n\n for (const name of names) {\n // The row count is not something every driver reports the same way,\n // so ask: a name with no row yet gets one.\n const [exists] = await query(\n `SELECT 1 AS found FROM ${table} WHERE name = ${mark(1)}`,\n [name],\n );\n\n if (exists) {\n await query(update, [name]);\n continue;\n }\n\n try {\n await query(insert, [name]);\n } catch {\n // Another instance inserted it first: bump that one.\n await query(update, [name]);\n }\n }\n },\n listen: options.listen,\n notify: options.notify,\n },\n { poll: options.poll },\n );\n}\n\n/**\n * Where versions are kept, as the app writes it for its own database: the\n * three things rsc-kit cannot know about your storage, and nothing else.\n * `createVersions` does the rest - comparing, waiting, waking.\n *\n * // Drizzle\n * read: async (names) => Object.fromEntries(\n * (await db.select().from(rscVersions).where(inArray(rscVersions.name, names)))\n * .map((r) => [r.name, Number(r.version)])),\n * bump: async (names) => { for (const name of names) await db.insert(rscVersions)\n * .values({ name, version: 1 })\n * .onConflictDoUpdate({ target: rscVersions.name, set: { version: sql`${rscVersions.version} + 1` } }) },\n *\n * // Redis\n * read: async (names) => Object.fromEntries((await redis.mget(names.map(k)))\n * .map((v, i) => [names[i], Number(v ?? 0)])),\n * bump: async (names) => { await Promise.all(names.map((n) => redis.incr(k(n)))) },\n */\nexport interface VersionStore {\n /** The current version of each name asked for. A name it has never seen may be left out: it is 0. */\n read(names: string[]): Promise<Record<string, number>>;\n /** Move each name's version - by one, or to anything new: watchers compare, they do not count. */\n bump(names: string[]): Promise<void>;\n /**\n * Called once with a function that wakes every waiting ask, when the store\n * can say the moment a version moved - Postgres LISTEN, Redis SUBSCRIBE.\n * Without it a waiting ask reads again every `poll` ms.\n */\n listen?(wake: () => void): unknown;\n /** Run after a bump, to tell the other instances listening: Postgres NOTIFY, Redis PUBLISH. */\n notify?(): unknown;\n}\n\n/**\n * A version source over any store: SQL through any driver or ORM - Drizzle,\n * Prisma, Kysely, Knex - or Redis, or anything with a read and an increment.\n *\n * installVersionSource(createVersions({ read, bump, listen, notify }))\n *\n * rsc-kit owns the rest: an ask waits up to the time it was given for a\n * version to differ, reading every `poll` ms (1000 by default) or the moment\n * `listen` wakes it, and a bump in this process wakes this process's asks at\n * once whatever the store.\n */\nexport function createVersions(\n store: VersionStore,\n options: { poll?: number } = {},\n): VersionSource {\n const poll = options.poll ?? 1_000;\n const waiters = new Set<() => void>();\n const wakeAll = () => {\n for (const wake of [...waiters]) wake();\n };\n\n // Listening opens a connection, and an open connection keeps a process\n // alive: started here, a store installed in register() - which a build\n // runs too - held the build open for ever. So it starts with the first\n // ask that waits, which only a server with a tab watching ever makes.\n let listening = false;\n const listen = () => {\n if (listening || !store.listen) return;\n listening = true;\n void Promise.resolve(store.listen(wakeAll)).catch(() => {\n listening = false;\n });\n };\n\n const read = async (names: string[]): Promise<Record<string, number>> => {\n if (names.length === 0) return {};\n\n const found = await store.read(names);\n\n return Object.fromEntries(\n names.map((name) => [name, Number(found[name] ?? 0)]),\n );\n };\n\n return {\n async changed(since, wait) {\n if (wait > 0) listen();\n\n const names = Object.keys(since);\n const deadline = Date.now() + Math.max(0, wait);\n\n for (;;) {\n const versions = await read(names);\n const differ: Record<string, number> = {};\n\n for (const name of names)\n if (versions[name] !== since[name])\n differ[name] = versions[name] ?? 0;\n\n const remaining = deadline - Date.now();\n\n if (Object.keys(differ).length > 0 || remaining <= 0) return differ;\n\n await new Promise<void>((resolve) => {\n const done = () => {\n clearTimeout(timer);\n waiters.delete(done);\n resolve();\n };\n const timer = setTimeout(done, Math.min(poll, remaining));\n\n (timer as { unref?: () => void }).unref?.();\n waiters.add(done);\n });\n }\n },\n async bump(names) {\n const unique = [...new Set(names)];\n\n if (unique.length === 0) return;\n\n await store.bump(unique);\n wakeAll();\n if (store.notify) await store.notify();\n },\n };\n}\n\n/** The parts of a Postgres client `postgresVersions` uses: postgres.js and `Bun.sql` both have them. */\nexport interface PostgresClient {\n unsafe(\n text: string,\n params?: unknown[],\n ): PromiseLike<readonly Record<string, unknown>[]>;\n /** postgres.js has it; with it, a waiting ask hears another instance at once. */\n listen?(channel: string, onNotify: () => void): unknown;\n notify?(channel: string, payload: string): unknown;\n}\n\n/**\n * Versions in Postgres, from the client the app already has:\n *\n * installVersionSource(postgresVersions(sql))\n *\n * `sqlVersions` with Postgres's placeholders, and - when the client can\n * LISTEN, as postgres.js can - a change on one instance wakes the waiting asks\n * on every other at once, rather than on their next read of the table.\n * Without it (`Bun.sql`), the table is read once a second while an ask waits.\n *\n * CREATE TABLE rsc_versions (name TEXT PRIMARY KEY, version BIGINT NOT NULL)\n */\nexport function postgresVersions(\n sql: PostgresClient,\n options: { table?: string; channel?: string; poll?: number } = {},\n): VersionSource {\n const channel = options.channel ?? \"rsc_versions\";\n const listen = sql.listen?.bind(sql);\n const notify = sql.notify?.bind(sql);\n\n return sqlVersions({\n query: async (text, params) => await sql.unsafe(text, params),\n placeholder: (n) => \"$\" + n,\n table: options.table,\n poll: options.poll,\n listen: listen ? (wake) => listen(channel, wake) : undefined,\n notify: listen && notify ? () => notify(channel, \"\") : undefined,\n });\n}\n\nconst SOURCE = Symbol.for(\"rsc-kit.version-source\");\nconst BACKEND_SOURCE = Symbol.for(\"rsc-kit.backend-version-source\");\nconst LOCAL_SOURCE = Symbol.for(\"rsc-kit.local-version-source\");\nconst globals = globalThis as Record<symbol, unknown>;\n\n/**\n * Install where versions are read from - a table, Redis, any store - for this\n * process; `null` takes it out again.\n *\n * The app's choice wins over the backend's: with a Go or Laravel backend that\n * writes its versions to a store this process can read too, reading it here\n * means watching costs the backend nothing.\n */\nexport function installVersionSource(source: VersionSource | null): void {\n globals[SOURCE] = source;\n}\n\n/** The engine's, when a backend is installed: its versions, read through it. Not for apps. */\nexport function installBackendVersionSource(\n source: VersionSource | null,\n): void {\n globals[BACKEND_SOURCE] = source;\n}\n\n/** The source in use: the app's, else the backend's, else this process's own. */\nexport function versionSource(): VersionSource {\n const chosen =\n (globals[SOURCE] as VersionSource | null | undefined) ??\n (globals[BACKEND_SOURCE] as VersionSource | null | undefined);\n\n if (chosen) return chosen;\n\n let local = globals[LOCAL_SOURCE] as VersionSource | undefined;\n\n if (!local) {\n local = globals[LOCAL_SOURCE] = memoryVersions();\n\n // The fallback works in development and in tests, which are one process,\n // and fails silently in production with two: a change on one instance\n // never reaches the tabs on another. Said once, at the first use. An app\n // that really is one instance installs memoryVersions() itself, which is\n // a choice rather than a fallback, and is not warned.\n if (production()) {\n console.warn(\n \"[rsc-kit] refreshOn versions are kept in this process only: a change made on another \" +\n \"instance, or in a worker, will not reach the tabs this one serves. Install a store every \" +\n \"process shares with installVersionSource() in instrumentation.ts - sqlVersions for MySQL \" +\n \"or SQLite, postgresVersions for Postgres, createVersions for anything else: \" +\n \"https://docs.rsc-kit.dev/guides/sections#where-the-versions-live. For a deploy that is one \" +\n \"instance, installVersionSource(memoryVersions()) says so.\",\n );\n }\n }\n\n return local;\n}\n\n/**\n * Say these names changed, so every open tab showing them refreshes.\n *\n * export async function POST(request: Request) { // a webhook, in a route.ts\n * const { team } = await request.json()\n * changed(`team:${team}:repos`)\n * return new Response(null, { status: 204 })\n * }\n *\n * For an app that keeps its versions here. With a backend the versions are\n * its, and so is the call: `rsckit.Changed`, `Rsc::changed`.\n */\nexport async function changed(...names: string[]): Promise<void> {\n await versionSource().bump(names);\n}\n\n// ── Tokens ───────────────────────────────────────────────────────────────────\n//\n// A tab may watch exactly the names its page was rendered with. Rather than\n// remembering what each tab was given - state, which a Worker cannot keep\n// between requests - every name goes to the client signed, and comes back\n// with its signature. Verified, not looked up, so a watch request is\n// stateless, and a browser cannot make up a name to watch.\n\n/** Thrown when a production server has no key to sign names with. */\nexport class MissingSigningSecret extends Error {\n constructor() {\n super(\n \"refreshOn needs a signing secret in production, the same on every instance: set RSC_SIGNING_SECRET \" +\n \"to a long random string. Without one, each instance would sign with its own random key, and a tab \" +\n \"served by one would be refused by the next.\",\n );\n this.name = \"MissingSigningSecret\";\n }\n}\n\n// On the global rather than in this module: an app imports this file through\n// its own copy of the package, and a key configured there must be the key the\n// engine's copy signs and verifies with.\nconst KEY = Symbol.for(\"rsc-kit.signing-key\");\n\ninterface Keying {\n secret: string | null;\n keyed: Promise<CryptoKey> | null;\n signatures: Map<string, Promise<string>>;\n}\n\nfunction keying(): Keying {\n return ((globals[KEY] as Keying | undefined) ??= {\n secret: null,\n keyed: null,\n signatures: new Map(),\n });\n}\n\nconst env = (name: string): string | undefined =>\n (globalThis as { process?: { env?: Record<string, string | undefined> } })\n .process?.env?.[name] || undefined;\n\nconst production = (): boolean => env(\"NODE_ENV\") === \"production\";\n\n/**\n * The secret names are signed with, when it does not come from the\n * environment. Normally it does: `RSC_SIGNING_SECRET`, the same on every\n * instance, or a tab served by one is refused by another.\n *\n * Its own secret, not the backend's host-call secret: that one authorises\n * calls between the renderer and a backend, and an app with no backend has\n * no reason to have it. Two jobs, two keys - one leaking does not hand out\n * the other.\n */\nexport function configureChanged(options: { secret?: string | null }): void {\n const state = keying();\n\n state.secret = options.secret ?? null;\n state.keyed = null;\n state.signatures.clear();\n}\n\n/** The secret in use: configured, or from the environment; null when there is none. */\nfunction secretInUse(): string | null {\n const state = keying();\n\n return state.secret ?? env(\"RSC_SIGNING_SECRET\") ?? null;\n}\n\n/**\n * Refuse, in production, to sign with a key nobody else has.\n *\n * A random key is right for one process - a dev server - and silently wrong\n * for two: every tab served by one instance is refused by the next, and never\n * refreshes. The server calls this on its first request when the app uses\n * refreshOn, so the misconfiguration is an error at once rather than a page\n * that quietly stops updating.\n */\nexport function assertSigningSecret(): void {\n if (!secretInUse() && production()) throw new MissingSigningSecret();\n}\n\nlet warnedRandom = false;\n\nasync function key(): Promise<CryptoKey> {\n const state = keying();\n\n return (state.keyed ??= (async () => {\n const secret = secretInUse();\n let raw: Uint8Array<ArrayBuffer>;\n\n if (secret) raw = new TextEncoder().encode(secret);\n else if (production()) throw new MissingSigningSecret();\n else {\n if (!warnedRandom) {\n warnedRandom = true;\n console.warn(\n \"[rsc-kit] refreshOn is signing with a random key, which is fine for one dev server. \" +\n \"Set RSC_SIGNING_SECRET before running more than one instance.\",\n );\n }\n\n raw = crypto.getRandomValues(new Uint8Array(32));\n }\n\n return await crypto.subtle.importKey(\n \"raw\",\n raw,\n { name: \"HMAC\", hash: \"SHA-256\" },\n false,\n [\"sign\"],\n );\n })());\n}\n\n/** A name's signature: the first 16 bytes of an HMAC, base64url, which is what rides in a url. */\nexport function sign(name: string): Promise<string> {\n const { signatures } = keying();\n let pending = signatures.get(name);\n\n if (!pending) {\n pending = (async () => {\n const mac = await crypto.subtle.sign(\n \"HMAC\",\n await key(),\n new TextEncoder().encode(name),\n );\n\n return base64url(new Uint8Array(mac).slice(0, 16));\n })();\n\n // Bounded: a name with a visitor's id in it is a new entry per visitor.\n if (signatures.size > 10_000) signatures.clear();\n signatures.set(name, pending);\n }\n\n return pending;\n}\n\nasync function verify(name: string, signature: string): Promise<boolean> {\n const expected = await sign(name);\n\n if (expected.length !== signature.length) return false;\n\n let differ = 0;\n\n for (let i = 0; i < expected.length; i++)\n differ |= expected.charCodeAt(i) ^ signature.charCodeAt(i);\n\n return differ === 0;\n}\n\nfunction base64url(bytes: Uint8Array): string {\n let text = \"\";\n\n for (const byte of bytes) text += String.fromCharCode(byte);\n\n return btoa(text).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\n\n/** What a page hands the client for one name: its version at render, and its signature. */\nexport type SignedName = [version: number, signature: string];\n\n// ── Watching ─────────────────────────────────────────────────────────────────\n//\n// One stream per open tab, and one ask of the source per process: every\n// stream's names are asked about together, on an interval, and a version that\n// moved is written to every stream holding its name. A thousand tabs on a\n// long-lived server cost the backend one call per interval, not a thousand.\n// On a host that answers each request in its own isolate the sharing is\n// whatever the isolate serves at once, and a lone stream asks for itself -\n// the same code, degrading to one small call per tab per interval.\n\n/** How often the source is asked, when it answered at once. */\nexport const CHANGES_INTERVAL_MS = 2_000;\n\n/** How long the source may hold one ask. Bounds how long a new tab waits to join the shared ask. */\nexport const CHANGES_WAIT_MS = 5_000;\n\ninterface Stream {\n names: Set<string>;\n send(name: string, version: number): void;\n}\n\nconst streams = new Set<Stream>();\n\n/** The latest version seen for each name any stream holds. */\nconst known = new Map<string, number>();\n\nlet running = false;\nlet wake: (() => void) | null = null;\nlet warned = false;\n\nfunction observe(name: string, version: number): void {\n if (known.get(name) === version) return;\n\n known.set(name, version);\n\n for (const stream of streams)\n if (stream.names.has(name)) stream.send(name, version);\n}\n\n/** Mapped to this process's set of streams: what to ask about, relative to what is known. */\nfunction sinceAll(): Record<string, number> {\n const since: Record<string, number> = {};\n\n for (const stream of streams)\n for (const name of stream.names) since[name] = known.get(name) ?? 0;\n\n return since;\n}\n\nasync function loop(): Promise<void> {\n running = true;\n\n try {\n while (streams.size > 0) {\n const started = Date.now();\n\n try {\n const moved = await versionSource().changed(\n sinceAll(),\n CHANGES_WAIT_MS,\n );\n\n for (const [name, version] of Object.entries(moved))\n observe(name, version);\n } catch (error) {\n // A backend blip is not the end of watching. Said once, not per interval.\n if (!warned) {\n warned = true;\n console.warn(\n \"[rsc-kit] asking the backend for name versions failed: \" +\n (error instanceof Error ? error.message : String(error)),\n );\n }\n }\n\n // A source that waited used the interval; one that answered at once is\n // asked again after it. A stream opening meanwhile wakes this early.\n const remaining = CHANGES_INTERVAL_MS - (Date.now() - started);\n\n if (remaining > 0 && streams.size > 0) {\n await new Promise<void>((resolve) => {\n const timer = setTimeout(resolve, remaining);\n\n (timer as { unref?: () => void }).unref?.();\n wake = () => {\n clearTimeout(timer);\n resolve();\n };\n });\n wake = null;\n }\n }\n } finally {\n running = false;\n // A stream that opened as the loop was ending starts it again.\n if (streams.size > 0) void loop();\n }\n}\n\nfunction parseWatch(\n url: URL,\n): { name: string; version: number; signature: string }[] | null {\n const raw = url.searchParams.get(\"w\");\n\n if (!raw) return null;\n\n let entries: unknown;\n\n try {\n entries = JSON.parse(raw);\n } catch {\n return null;\n }\n\n if (!Array.isArray(entries) || entries.length === 0 || entries.length > 200)\n return null;\n\n const parsed: { name: string; version: number; signature: string }[] = [];\n\n for (const entry of entries) {\n if (!Array.isArray(entry) || entry.length !== 3) return null;\n\n const [name, version, signature] = entry as unknown[];\n\n if (\n typeof name !== \"string\" ||\n typeof version !== \"number\" ||\n typeof signature !== \"string\"\n )\n return null;\n\n parsed.push({ name, version, signature });\n }\n\n return parsed;\n}\n\n/**\n * The stream a tab watches its names on: `GET /_rsc/changes?w=[[name, version, signature], …]`.\n *\n * One `data:` line per version that moved, `{ name, version }`, from the moment\n * the stream opens - a name that moved between the render and now is reported\n * at once, so nothing that happened in the gap is missed. Keepalives as an\n * events() route sends them; ends when the browser goes away.\n */\nexport async function changes(request: Request): Promise<Response> {\n const entries = parseWatch(new URL(request.url));\n\n if (!entries) return new Response(\"Bad watch request.\", { status: 400 });\n\n for (const { name, signature } of entries) {\n if (!(await verify(name, signature))) {\n return new Response(\"Not a name this page was rendered with.\", {\n status: 403,\n });\n }\n }\n\n const since: Record<string, number> = {};\n\n for (const { name, version } of entries) since[name] = version;\n\n const encoder = new TextEncoder();\n let stream: Stream | null = null;\n\n const body = new ReadableStream<Uint8Array>({\n start(sink) {\n const write = (text: string) => {\n try {\n sink.enqueue(encoder.encode(text));\n } catch {\n // Closed under us; the cancel below ends the rest.\n }\n };\n\n write(\"retry: 2000\\n\\n\");\n\n const keepalive = setInterval(\n () => write(\": keepalive\\n\\n\"),\n keepaliveMs(),\n );\n\n (keepalive as { unref?: () => void }).unref?.();\n\n const me: Stream = {\n names: new Set(Object.keys(since)),\n send: (name, version) => write(frame({ name, version })),\n };\n\n stream = me;\n streams.add(me);\n\n const end = () => {\n clearInterval(keepalive);\n streams.delete(me);\n\n try {\n sink.close();\n } catch {\n // Already closed.\n }\n };\n\n request.signal.addEventListener(\"abort\", end, { once: true });\n\n // What is known already answers at once; what is not is seeded with\n // what this tab holds, so the shared ask compares against it.\n for (const [name, version] of Object.entries(since)) {\n const seen = known.get(name);\n\n if (seen === undefined) known.set(name, version);\n else if (seen !== version) me.send(name, seen);\n }\n\n // This tab's own first ask, holding as long as the source will: the\n // shared ask may be mid-wait on an older set of names, and a name moving\n // in the seconds before this one joins it must not go unnoticed.\n void versionSource()\n .changed(since, CHANGES_WAIT_MS)\n .then((moved) => {\n for (const [name, version] of Object.entries(moved))\n observe(name, version);\n })\n .catch(() => {});\n\n if (!running) void loop();\n else wake?.();\n },\n cancel() {\n if (stream) streams.delete(stream);\n },\n });\n\n return new Response(body, {\n headers: {\n \"Content-Type\": \"text/event-stream; charset=utf-8\",\n // no-transform: a proxy or CDN in front must not compress or buffer\n // it either - Cloudflare compresses text unless told not to.\n \"Cache-Control\": \"no-store, no-transform\",\n \"X-Accel-Buffering\": \"no\",\n },\n });\n}\n\n/** For tests: forget every stream and version this process has seen. */\nexport function resetChanges(): void {\n streams.clear();\n known.clear();\n warned = false;\n delete globals[LOCAL_SOURCE];\n}\n\n/** The url a tab opens to watch, for the client. */\nexport const CHANGES_PATH = HEADER.changesPath;\n"]}
|
|
1
|
+
{"version":3,"file":"changed.js","sourceRoot":"","sources":["../src/changed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,iBAAiB,EAAyB,MAAM,gBAAgB,CAAC;AAE1E,4DAA4D;AAC5D,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAe,CAAC;AAgChD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAC,OAAO,GAAG,CAAC;IACrC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,EAAE,IAAI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F,CAAC,CAAC;AACL,CAAC;AAED,wEAAwE;AACxE,6EAA6E;AAC7E,MAAM,UAAU,eAAe;IAC7B,OAAO,KAAK,CAAC,IAAI,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;IACvB,OAAO,CAAC,KAAK,EAAE,CAAC;IAChB,KAAK,CAAC,KAAK,EAAE,CAAC;IACd,MAAM,GAAG,KAAK,CAAC;IACf,OAAO,OAAO,CAAC,YAAY,CAAC,CAAC;AAC/B,CAAC;AAED,oDAAoD;AACpD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,WAAW,CAAC","sourcesContent":["/**\n * Names: a name for data a page depends on, so whatever changes it can say so\n * from anywhere - a webhook, a job, another visitor's action - and every open\n * tab showing it refreshes.\n *\n * // a section says what it depends on\n * export default section('repos', Repos, { refreshOn: ({ params }) => [`team:${params.team}:repos`] })\n *\n * // and whatever changes it says so\n * changed(`team:${team}:repos`) // here, from a route.ts or an action\n * rsckit.Changed(ctx, \"team:1:repos\") // or the backend, from its webhook\n * Rsc::changed(\"team:$team:repos\"); // Laravel\n *\n * A name has a version: a number that moves whenever something says the name\n * changed. Nothing else - not what changed, not the data. A page learns the\n * versions at render; one stream per open tab watches them; when one moves,\n * the sections carrying that name ask for themselves again, the way refresh()\n * does. Data is never pushed, which is what keeps this working on a host that\n * cannot hold state: a version is a read.\n *\n * Where versions live is the source's business. Without a backend they are in\n * this process, which is one instance. With one, the backend keeps them - in\n * its cache or a table, shared by every instance it runs - and answers\n * `__rsc.changed`: given the versions a watcher holds, the ones that differ now.\n * A backend that can wait holds the call until one does; one that cannot\n * answers at once, and the watcher asks again on its interval. The protocol\n * is the same either way, and so is the page.\n */\n\nimport { frame, keepaliveMs } from \"./events.js\";\nimport { HEADER } from \"./headers.js\";\nimport { listenToBroadcast } from \"./broadcast.js\";\n\nexport { listenToBroadcast, type BroadcastOptions } from \"./broadcast.js\";\n\n/** The reserved name a backend answers name versions on. */\nexport const CHANGED_FUNCTION = \"__rsc.changed\";\n\n/** What `__rsc.changed` is asked. */\nexport interface ChangedQuery {\n /** The versions the asker holds. A name never changed is 0; -1 asks for every current version. */\n since: Record<string, number>;\n /** How long the backend may hold the call waiting for one to differ, in ms. It may answer at once. */\n wait?: number;\n}\n\n/** What `__rsc.changed` answers: the versions among `since` that differ now. */\nexport interface ChangedAnswer {\n versions: Record<string, number>;\n}\n\n/**\n * Where name versions are read from, and - when they live here - bumped.\n *\n * `changed` answers the versions among `since` that differ now, and may wait\n * up to `wait` ms for one to. Nothing else is required of it, which is why a\n * backend's cache, a table, this process's memory, or a pub/sub that answers\n * the moment a name moves all fit behind it.\n */\nexport interface VersionSource {\n changed(\n since: Record<string, number>,\n wait: number,\n ): Promise<Record<string, number>>;\n /** Say these names changed. Only a source that holds its own versions can. */\n bump(names: string[]): void | Promise<void>;\n}\n\n/**\n * The version a name moves to: the larger of one past where it was and the\n * current time in milliseconds.\n *\n * A counter would do for \"it moved\", but a counter repeats once its row is\n * gone - deleted to keep the store small, a name starts again from 0 and\n * climbs back to a value some tab is still holding, and that tab misses the\n * change. A time never comes round again, so a name may be forgotten at any\n * moment: a tab holding the old value sees a different one, and at worst\n * refreshes once for nothing. It is also when the name last moved, which is\n * all cleanup needs. Every store bumps with it; one that writes `+ 1` still\n * works, it is just not safe to prune.\n */\nexport function nextVersion(current = 0): number {\n return Math.max(current + 1, Date.now());\n}\n\n/** The safety-net read of a store that listens: longer than any ask waits, so once per ask. */\nexport const LISTENING_POLL_MS = 30_000;\n\n/** How long a name nobody changes is kept, by the stores that forget on their own. */\nexport const VERSIONS_KEPT_MS = 30 * 24 * 60 * 60 * 1000;\n\n/**\n * Versions kept in this process: the source without a backend, and the one\n * tests use. A name not changed in `forgetAfter` ms (30 days) is forgotten,\n * swept at most once an hour, so a process up for months does not hold every\n * name it ever saw.\n */\nexport function memoryVersions(\n options: { forgetAfter?: number } = {},\n): VersionSource {\n const forgetAfter = options.forgetAfter ?? VERSIONS_KEPT_MS;\n const versions = new Map<string, number>();\n const waiters = new Set<() => void>();\n let swept = Date.now();\n\n const sweep = () => {\n const now = Date.now();\n\n if (now - swept < Math.min(forgetAfter, 60 * 60 * 1000)) return;\n swept = now;\n\n for (const [name, version] of versions)\n if (version < now - forgetAfter) versions.delete(name);\n };\n\n const differing = (since: Record<string, number>): Record<string, number> => {\n const out: Record<string, number> = {};\n\n for (const [name, held] of Object.entries(since)) {\n const current = versions.get(name) ?? 0;\n\n if (current !== held) out[name] = current;\n }\n\n return out;\n };\n\n return {\n async changed(since, wait) {\n const now = differing(since);\n\n if (Object.keys(now).length > 0 || wait <= 0) return now;\n\n await new Promise<void>((resolve) => {\n const done = () => {\n clearTimeout(timer);\n waiters.delete(done);\n resolve();\n };\n const timer = setTimeout(done, wait);\n\n // A test or a build must not be held open by a watcher's wait.\n (timer as { unref?: () => void }).unref?.();\n waiters.add(done);\n });\n\n return differing(since);\n },\n bump(names) {\n sweep();\n for (const name of names)\n versions.set(name, nextVersion(versions.get(name)));\n for (const wake of [...waiters]) wake();\n },\n };\n}\n\ntype HostFn = (name: string, ...args: unknown[]) => Promise<unknown>;\n\n/**\n * Versions kept by the backend, read through `__rsc.changed`.\n *\n * A backend that has not got the function - an adapter from before names, or\n * a host of plain rpc functions - is answered from this process instead,\n * found out on the first ask and remembered, so a page with names still works\n * on it: one instance, versions bumped by `changed()` here.\n */\nexport function backendVersions(call: HostFn): VersionSource {\n let local: VersionSource | null = null;\n\n // A backend's \"no such function\", or the test host's \"no handler for\".\n const unknown = (error: unknown): boolean =>\n /no host function named|has no handler for/i.test(\n error instanceof Error ? error.message : String(error),\n );\n\n return {\n async changed(since, wait) {\n if (local) return local.changed(since, wait);\n\n try {\n const answer = (await call(CHANGED_FUNCTION, {\n since,\n wait,\n } satisfies ChangedQuery)) as Partial<ChangedAnswer> | null;\n\n return answer?.versions ?? {};\n } catch (error) {\n if (!unknown(error)) throw error;\n\n local = memoryVersions();\n\n return local.changed(since, wait);\n }\n },\n bump(names) {\n if (local) return local.bump(names);\n\n throw new Error(\n \"changed() bumps versions this process keeps, and a backend keeps these: say the name changed there - \" +\n \"rsckit.Changed(ctx, ...) in Go, Rsc::changed(...) in Laravel.\",\n );\n },\n };\n}\n\n/** Runs one statement with positional parameters and resolves to its rows. */\nexport type SqlQuery = (\n text: string,\n params: unknown[],\n) => Promise<readonly Record<string, unknown>[]>;\n\nexport interface SqlVersionsOptions {\n /**\n * Which database, so a change is one statement - an upsert of every name\n * it moves - rather than a read and a write per name. Left out, the store\n * uses only SQL every database has, at the cost of those extra queries.\n */\n dialect?: \"postgres\" | \"mysql\" | \"sqlite\";\n /**\n * Postgres only: NOTIFY this channel in the same statement as the upsert,\n * so a listening server wakes - and only once the write commits.\n */\n channel?: string;\n /**\n * Your driver, as a function of SQL text and parameters:\n *\n * query: (text, params) => sql.unsafe(text, params) // postgres.js, Bun.sql\n * query: async (text, params) => (await pool.query(text, params)).rows // node-postgres\n */\n query: SqlQuery;\n /** The table: `CREATE TABLE rsc_versions (name TEXT PRIMARY KEY, version BIGINT NOT NULL)`. */\n table?: string;\n /** How the n-th parameter is written (1-based). Default `?`; Postgres is `(n) => '$' + n`. */\n placeholder?: (n: number) => string;\n /**\n * Called once with a function that wakes every waiting ask, for a database\n * that can say the moment a version moved - Postgres's LISTEN:\n *\n * listen: (wake) => sql.listen('rsc_versions', wake)\n *\n * Without it, a waiting ask reads the table every `poll` ms.\n */\n listen?: (wake: () => void, health: ListenerHealth) => unknown;\n /**\n * Run after every bump, to tell the other instances - Postgres's NOTIFY:\n *\n * notify: () => sql.notify('rsc_versions', '')\n */\n notify?: () => unknown;\n /**\n * How often a waiting ask reads the table: every second by default, or,\n * with `listen`, only as a safety net - about once per ask.\n */\n poll?: number;\n}\n\n/**\n * Versions in a table every instance shares: the web servers, and the worker\n * that finishes a job and says so. The same table and columns Go's\n * `SQLVersions` uses, so a Go service and a JavaScript worker can share one.\n *\n * installVersionSource(sqlVersions({\n * query: (text, params) => sql.unsafe(text, params),\n * placeholder: (n) => '$' + n,\n * listen: (wake) => sql.listen('rsc_versions', wake),\n * notify: () => sql.notify('rsc_versions', ''),\n * }))\n *\n * Written with an UPDATE and, the first time, an INSERT - two statements any\n * SQL dialect has - rather than an upsert each spells differently. Takes the\n * app's own driver, so the engine has no database dependency of its own.\n */\n/**\n * One statement that moves every name to nextVersion: an upsert, in the\n * dialect's own words, and on Postgres the NOTIFY with it. A name is either\n * inserted at `now` or moved to the larger of one more and `now`.\n */\nfunction upsert(\n dialect: \"postgres\" | \"mysql\" | \"sqlite\",\n table: string,\n mark: (n: number) => string,\n names: string[],\n now: number,\n channel?: string,\n): [string, unknown[]] {\n if (dialect === \"postgres\") {\n // $1 is now, the names follow; the channel, if any, comes last.\n const rows = names.map((_, i) => `(${mark(i + 2)}, ${mark(1)})`).join(\", \");\n const insert =\n `INSERT INTO ${table} (name, version) VALUES ${rows} ` +\n `ON CONFLICT (name) DO UPDATE SET version = GREATEST(${table}.version + 1, EXCLUDED.version)`;\n\n if (!channel) return [insert, [now, ...names]];\n\n // A NOTIFY is delivered when the transaction commits, so a listener is\n // never woken before the change it is told about can be read.\n return [\n `WITH moved AS (${insert} RETURNING 1) SELECT pg_notify(${mark(names.length + 2)}, '') FROM (SELECT count(*) FROM moved) AS done`,\n [now, ...names, channel],\n ];\n }\n\n const rows = names.map(() => `(${mark(1)}, ${mark(1)})`).join(\", \");\n const params = names.flatMap((name) => [name, now]);\n\n return dialect === \"mysql\"\n ? [\n `INSERT INTO ${table} (name, version) VALUES ${rows} ON DUPLICATE KEY UPDATE version = GREATEST(version + 1, VALUES(version))`,\n params,\n ]\n : [\n `INSERT INTO ${table} (name, version) VALUES ${rows} ON CONFLICT (name) DO UPDATE SET version = MAX(version + 1, excluded.version)`,\n params,\n ];\n}\n\n/** A store whose old names can be cleared out: the SQL ones. */\nexport interface PrunableVersions extends VersionSource {\n /**\n * Delete every name not changed in `olderThan` ms (30 days by default).\n * Always safe: a version is a time and never comes round again, so a tab\n * still holding a pruned name sees it differ and refreshes once. Run it\n * from a scheduled job - a daily one is plenty.\n */\n prune(olderThan?: number): Promise<void>;\n}\n\nexport function sqlVersions(options: SqlVersionsOptions): PrunableVersions {\n const { query } = options;\n const table = options.table ?? \"rsc_versions\";\n const mark = options.placeholder ?? (() => \"?\");\n\n const source = createVersions(\n {\n async read(names) {\n const rows = await query(\n `SELECT name, version FROM ${table} WHERE name IN (${names.map((_, i) => mark(i + 1)).join(\", \")})`,\n names,\n );\n\n // A BIGINT comes back as a string from most drivers.\n return Object.fromEntries(\n rows.map((row) => [String(row.name), Number(row.version)]),\n );\n },\n async bump(names) {\n if (options.dialect) {\n await query(\n ...upsert(\n options.dialect,\n table,\n mark,\n names,\n Date.now(),\n options.channel,\n ),\n );\n\n return;\n }\n\n // nextVersion, in SQL every dialect has: CASE rather than GREATEST,\n // which SQLite spells MAX. The time is this process's, passed in, so\n // the database's clock never has to agree with it.\n const update =\n `UPDATE ${table} SET version = CASE WHEN version + 1 > ${mark(1)} THEN version + 1 ELSE ${mark(2)} END ` +\n `WHERE name = ${mark(3)}`;\n const insert = `INSERT INTO ${table} (name, version) VALUES (${mark(1)}, ${mark(2)})`;\n\n for (const name of names) {\n const now = Date.now();\n\n // The row count is not something every driver reports the same way,\n // so ask: a name with no row yet gets one.\n const [exists] = await query(\n `SELECT 1 AS found FROM ${table} WHERE name = ${mark(1)}`,\n [name],\n );\n\n if (exists) {\n await query(update, [now, now, name]);\n continue;\n }\n\n try {\n await query(insert, [name, now]);\n } catch {\n // Another instance inserted it first: bump that one.\n await query(update, [now, now, name]);\n }\n }\n },\n listen: options.listen,\n notify: options.notify,\n },\n { poll: options.poll },\n );\n\n return {\n ...source,\n async prune(olderThan = VERSIONS_KEPT_MS) {\n await query(`DELETE FROM ${table} WHERE version < ${mark(1)}`, [\n Date.now() - olderThan,\n ]);\n },\n };\n}\n\n/**\n * Where versions are kept, as the app writes it for its own database: the\n * three things rsc-kit cannot know about your storage, and nothing else.\n * `createVersions` does the rest - comparing, waiting, waking.\n *\n * // Drizzle\n * read: async (names) => Object.fromEntries(\n * (await db.select().from(rscVersions).where(inArray(rscVersions.name, names)))\n * .map((r) => [r.name, Number(r.version)])),\n * bump: async (names) => { for (const name of names) await db.insert(rscVersions)\n * .values({ name, version: 1 })\n * .onConflictDoUpdate({ target: rscVersions.name, set: { version: sql`${rscVersions.version} + 1` } }) },\n *\n * // Redis\n * read: async (names) => Object.fromEntries((await redis.mget(names.map(k)))\n * .map((v, i) => [names[i], Number(v ?? 0)])),\n * bump: async (names) => { await Promise.all(names.map((n) => redis.incr(k(n)))) },\n */\nexport interface VersionStore {\n /** The current version of each name asked for. A name it has never seen may be left out: it is 0. */\n read(names: string[]): Promise<Record<string, number>>;\n /**\n * Move each name's version to `nextVersion(current)` - one past where it\n * was, or the current time in ms if that is larger. Watchers only compare,\n * so any new value works; this one never repeats, which is what makes it\n * safe to delete a name later. A plain `+ 1` works too, until a row is\n * deleted.\n */\n bump(names: string[]): Promise<void>;\n /**\n * Called once with a function that wakes every waiting ask, when the store\n * can say the moment a version moved - Postgres LISTEN, Redis SUBSCRIBE.\n * Without it a waiting ask reads again every `poll` ms.\n *\n * Given `health` too: a store that finds it hears nothing - a Postgres\n * listener behind a pooler in transaction mode - calls `health.deaf(why)`,\n * and rsc-kit says so and goes back to reading every second.\n */\n listen?(wake: () => void, health: ListenerHealth): unknown;\n /** Run after a bump, to tell the other instances listening: Postgres NOTIFY, Redis PUBLISH. */\n notify?(): unknown;\n}\n\n/**\n * A version source over any store: SQL through any driver or ORM - Drizzle,\n * Prisma, Kysely, Knex - or Redis, or anything with a read and an increment.\n *\n * installVersionSource(createVersions({ read, bump, listen, notify }))\n *\n * rsc-kit owns the rest: an ask waits up to the time it was given for a\n * version to differ, reading every `poll` ms (1000 by default) or the moment\n * `listen` wakes it, and a bump in this process wakes this process's asks at\n * once whatever the store.\n */\nexport function createVersions(\n store: VersionStore,\n options: { poll?: number } = {},\n): VersionSource {\n // A store that listens is woken the moment a version moves, so reading the\n // table on a timer is only a safety net - for a listening connection that\n // dropped without a word. Once an ask is enough: about every five seconds\n // per server, where one that cannot listen reads every second.\n let listening = Boolean(store.listen);\n const poll = () => options.poll ?? (listening ? LISTENING_POLL_MS : 1_000);\n const waiters = new Set<() => void>();\n const wakeAll = () => {\n for (const wake of [...waiters]) wake();\n };\n\n // A store that can listen wakes the renderer the way anything else does -\n // through wakeOn, which starts it with the first watching tab and never in\n // a build. A wake also ends an ask this store is holding.\n if (store.listen) {\n const listen = store.listen.bind(store);\n\n wakeOn((wake, health) =>\n listen(wake, {\n deaf: (reason) => {\n listening = false;\n health.deaf(reason);\n },\n }),\n );\n }\n wakers().sleepers.add(wakeAll);\n\n const read = async (names: string[]): Promise<Record<string, number>> => {\n if (names.length === 0) return {};\n\n const found = await store.read(names);\n\n return Object.fromEntries(\n names.map((name) => [name, Number(found[name] ?? 0)]),\n );\n };\n\n return {\n async changed(since, wait) {\n // Only a server with a tab watching asks with a wait - never a build -\n // so this is a safe moment to start listening, as is the first tab.\n if (wait > 0) startWakers();\n\n const names = Object.keys(since);\n const deadline = Date.now() + Math.max(0, wait);\n\n for (;;) {\n const versions = await read(names);\n const differ: Record<string, number> = {};\n\n for (const name of names)\n if (versions[name] !== since[name])\n differ[name] = versions[name] ?? 0;\n\n const remaining = deadline - Date.now();\n\n if (Object.keys(differ).length > 0 || remaining <= 0) return differ;\n\n await new Promise<void>((resolve) => {\n const done = () => {\n clearTimeout(timer);\n waiters.delete(done);\n resolve();\n };\n const timer = setTimeout(done, Math.min(poll(), remaining));\n\n (timer as { unref?: () => void }).unref?.();\n waiters.add(done);\n });\n }\n },\n async bump(names) {\n const unique = [...new Set(names)];\n\n if (unique.length === 0) return;\n\n await store.bump(unique);\n wakeAll();\n if (store.notify) await store.notify();\n },\n };\n}\n\n/** The parts of a Postgres client `postgresVersions` uses: postgres.js and `Bun.sql` both have them. */\nexport interface PostgresClient {\n unsafe(\n text: string,\n params?: unknown[],\n ): PromiseLike<readonly Record<string, unknown>[]>;\n /** postgres.js and Bun.sql have it; with it, a waiting ask hears another instance at once. */\n listen?(channel: string, onNotify: (payload?: string) => void): unknown;\n notify?(channel: string, payload: string): unknown;\n}\n\n/**\n * Versions in Postgres, from the client the app already has:\n *\n * installVersionSource(postgresVersions(sql))\n *\n * `sqlVersions` with Postgres's placeholders, and - when the client can\n * LISTEN, as postgres.js and `Bun.sql` (Bun 1.4+) can - a change on one\n * instance wakes the waiting asks on every other at once, rather than on\n * their next read of the table. Without it, the table is read once a second\n * while an ask waits.\n *\n * CREATE TABLE rsc_versions (name TEXT PRIMARY KEY, version BIGINT NOT NULL)\n */\nexport function postgresVersions(\n sql: PostgresClient,\n options: {\n table?: string;\n channel?: string;\n poll?: number;\n /**\n * A client to listen on, when `sql` goes through a connection pooler in\n * transaction mode - PgBouncer, or DigitalOcean's, Supabase's or Neon's\n * pooled connection - which hands the server connection back after each\n * statement, so a LISTEN on it hears nothing. A direct or session-mode\n * connection; reads and writes stay on `sql`. One connection per process.\n */\n listenWith?: PostgresClient;\n /**\n * `false`: do not listen - read every second instead, on purpose. For a\n * database whose direct connections are too few to spend one per process\n * on, behind a pooler that cannot listen. No listener, so no probe and no\n * warning about one. A change made in this process still reaches its own\n * tabs at once; one made elsewhere within about a second.\n */\n listen?: boolean;\n } = {},\n): PrunableVersions {\n const channel = options.channel ?? \"rsc_versions\";\n const listener = options.listenWith ?? sql;\n const listenOn =\n options.listen === false ? undefined : listener.listen?.bind(listener);\n\n // One statement per change: the upsert of every name, and the NOTIFY that\n // wakes every listening server - this one included - when it commits.\n return sqlVersions({\n query: async (text, params) => await sql.unsafe(text, params),\n placeholder: (n) => \"$\" + n,\n dialect: \"postgres\",\n channel,\n table: options.table,\n poll: options.poll,\n listen: listenOn\n ? async (wake, health) => {\n // A probe, sent the way a change is - through `sql` - and listened\n // for on the listening connection. Behind a transaction-mode pooler\n // the LISTEN lands on a connection the pooler takes back, sending\n // still works, and nothing says the listener is deaf: changes from\n // other instances would wait for the safety-net read. The probe\n // not arriving is how that is found out - once, as listening starts.\n const probe = \"rsc-kit:probe:\" + crypto.randomUUID();\n let heard = false;\n\n await listenOn(channel, (payload) => {\n if (payload === probe) heard = true;\n else wake();\n });\n await sql.unsafe(\"SELECT pg_notify($1, $2)\", [channel, probe]);\n\n const timer = setTimeout(() => {\n if (heard) return;\n\n health.deaf(\n \"listening on Postgres receives no notifications - is the connection going through a pooler \" +\n \"in transaction mode (PgBouncer; DigitalOcean, Supabase or Neon pooled connections)? \" +\n \"Pass a direct or session-mode connection: postgresVersions(sql, { listenWith }). \" +\n \"Reading every second meanwhile.\",\n );\n }, LISTEN_PROBE_MS);\n\n (timer as { unref?: () => void }).unref?.();\n }\n : undefined,\n });\n}\n\n/** How long a listener's probe may take to come back before it counts as deaf. */\nexport const LISTEN_PROBE_MS = 5_000;\n\nconst SOURCE = Symbol.for(\"rsc-kit.version-source\");\nconst BACKEND_SOURCE = Symbol.for(\"rsc-kit.backend-version-source\");\nconst LOCAL_SOURCE = Symbol.for(\"rsc-kit.local-version-source\");\nconst globals = globalThis as Record<symbol, unknown>;\n\n/**\n * Install where versions are read from - a table, Redis, any store - for this\n * process; `null` takes it out again.\n *\n * The app's choice wins over the backend's: with a Go or Laravel backend that\n * writes its versions to a store this process can read too, reading it here\n * means watching costs the backend nothing.\n */\nexport function installVersionSource(\n source: VersionSource | (() => VersionSource) | null,\n): void {\n globals[SOURCE] = source;\n}\n\n/** The engine's, when a backend is installed: its versions, read through it. Not for apps. */\nexport function installBackendVersionSource(\n source: VersionSource | null,\n): void {\n globals[BACKEND_SOURCE] = source;\n}\n\n/** The source in use: the app's, else the backend's, else this process's own. */\nexport function versionSource(): VersionSource {\n // A factory, made into the store on first use: a store made in register()\n // would make its database client in the build too, which runs register()\n // without the database's settings.\n if (typeof globals[SOURCE] === \"function\")\n globals[SOURCE] = (globals[SOURCE] as () => VersionSource)();\n\n const chosen =\n (globals[SOURCE] as VersionSource | null | undefined) ??\n (globals[BACKEND_SOURCE] as VersionSource | null | undefined);\n\n if (chosen) return chosen;\n\n let local = globals[LOCAL_SOURCE] as VersionSource | undefined;\n\n if (!local) {\n local = globals[LOCAL_SOURCE] = memoryVersions();\n\n // The fallback works in development and in tests, which are one process,\n // and fails silently in production with two: a change on one instance\n // never reaches the tabs on another. Said once, at the first use. An app\n // that really is one instance installs memoryVersions() itself, which is\n // a choice rather than a fallback, and is not warned.\n if (production()) {\n console.warn(\n \"[rsc-kit] refreshOn versions are kept in this process only: a change made on another \" +\n \"instance, or in a worker, will not reach the tabs this one serves. Install a store every \" +\n \"process shares with installVersionSource() in instrumentation.ts - sqlVersions for MySQL \" +\n \"or SQLite, postgresVersions for Postgres, createVersions for anything else: \" +\n \"https://docs.rsc-kit.dev/guides/live-data#where-the-versions-live. For a deploy that is one \" +\n \"instance, installVersionSource(memoryVersions()) says so.\",\n );\n }\n }\n\n return local;\n}\n\n/**\n * Say these names changed, so every open tab showing them refreshes.\n *\n * export async function POST(request: Request) { // a webhook, in a route.ts\n * const { team } = await request.json()\n * changed(`team:${team}:repos`)\n * return new Response(null, { status: 204 })\n * }\n *\n * For an app that keeps its versions here. With a backend the versions are\n * its, and so is the call: `rsckit.Changed`, `Rsc::changed`.\n */\nexport async function changed(...names: string[]): Promise<void> {\n await versionSource().bump(names);\n}\n\n// ── Tokens ───────────────────────────────────────────────────────────────────\n//\n// A tab may watch exactly the names its page was rendered with. Rather than\n// remembering what each tab was given - state, which a Worker cannot keep\n// between requests - every name goes to the client signed, and comes back\n// with its signature. Verified, not looked up, so a watch request is\n// stateless, and a browser cannot make up a name to watch.\n\n/** Thrown when a production server has no key to sign names with. */\nexport class MissingSigningSecret extends Error {\n constructor() {\n super(\n \"refreshOn needs a signing secret in production, the same on every instance: set RSC_SIGNING_SECRET \" +\n \"to a long random string. Without one, each instance would sign with its own random key, and a tab \" +\n \"served by one would be refused by the next.\",\n );\n this.name = \"MissingSigningSecret\";\n }\n}\n\n// On the global rather than in this module: an app imports this file through\n// its own copy of the package, and a key configured there must be the key the\n// engine's copy signs and verifies with.\nconst KEY = Symbol.for(\"rsc-kit.signing-key\");\n\ninterface Keying {\n secret: string | null;\n keyed: Promise<CryptoKey> | null;\n signatures: Map<string, Promise<string>>;\n}\n\nfunction keying(): Keying {\n return ((globals[KEY] as Keying | undefined) ??= {\n secret: null,\n keyed: null,\n signatures: new Map(),\n });\n}\n\nconst env = (name: string): string | undefined =>\n (globalThis as { process?: { env?: Record<string, string | undefined> } })\n .process?.env?.[name] || undefined;\n\nconst production = (): boolean => env(\"NODE_ENV\") === \"production\";\n\n/**\n * The secret names are signed with, when it does not come from the\n * environment. Normally it does: `RSC_SIGNING_SECRET`, the same on every\n * instance, or a tab served by one is refused by another.\n *\n * Its own secret, not the backend's host-call secret: that one authorises\n * calls between the renderer and a backend, and an app with no backend has\n * no reason to have it. Two jobs, two keys - one leaking does not hand out\n * the other.\n */\nexport function configureChanged(options: { secret?: string | null }): void {\n const state = keying();\n\n state.secret = options.secret ?? null;\n state.keyed = null;\n state.signatures.clear();\n}\n\n/** The secret in use: configured, or from the environment; null when there is none. */\nfunction secretInUse(): string | null {\n const state = keying();\n\n return state.secret ?? env(\"RSC_SIGNING_SECRET\") ?? null;\n}\n\n/**\n * Refuse, in production, to sign with a key nobody else has.\n *\n * A random key is right for one process - a dev server - and silently wrong\n * for two: every tab served by one instance is refused by the next, and never\n * refreshes. The server calls this on its first request when the app uses\n * refreshOn, so the misconfiguration is an error at once rather than a page\n * that quietly stops updating.\n */\nexport function assertSigningSecret(): void {\n if (!secretInUse() && production()) throw new MissingSigningSecret();\n}\n\nlet warnedRandom = false;\n\nasync function key(): Promise<CryptoKey> {\n const state = keying();\n\n return (state.keyed ??= (async () => {\n const secret = secretInUse();\n let raw: Uint8Array<ArrayBuffer>;\n\n if (secret) raw = new TextEncoder().encode(secret);\n else if (production()) throw new MissingSigningSecret();\n else {\n if (!warnedRandom) {\n warnedRandom = true;\n console.warn(\n \"[rsc-kit] refreshOn is signing with a random key, which is fine for one dev server. \" +\n \"Set RSC_SIGNING_SECRET before running more than one instance.\",\n );\n }\n\n raw = crypto.getRandomValues(new Uint8Array(32));\n }\n\n return await crypto.subtle.importKey(\n \"raw\",\n raw,\n { name: \"HMAC\", hash: \"SHA-256\" },\n false,\n [\"sign\"],\n );\n })());\n}\n\n/** A name's signature: the first 16 bytes of an HMAC, base64url, which is what rides in a url. */\nexport function sign(name: string): Promise<string> {\n const { signatures } = keying();\n let pending = signatures.get(name);\n\n if (!pending) {\n pending = (async () => {\n const mac = await crypto.subtle.sign(\n \"HMAC\",\n await key(),\n new TextEncoder().encode(name),\n );\n\n return base64url(new Uint8Array(mac).slice(0, 16));\n })();\n\n // Bounded: a name with a visitor's id in it is a new entry per visitor.\n if (signatures.size > 10_000) signatures.clear();\n signatures.set(name, pending);\n }\n\n return pending;\n}\n\nasync function verify(name: string, signature: string): Promise<boolean> {\n const expected = await sign(name);\n\n if (expected.length !== signature.length) return false;\n\n let differ = 0;\n\n for (let i = 0; i < expected.length; i++)\n differ |= expected.charCodeAt(i) ^ signature.charCodeAt(i);\n\n return differ === 0;\n}\n\nfunction base64url(bytes: Uint8Array): string {\n let text = \"\";\n\n for (const byte of bytes) text += String.fromCharCode(byte);\n\n return btoa(text).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\n\n/** What a page hands the client for one name: its version at render, and its signature. */\nexport type SignedName = [version: number, signature: string];\n\n// ── Watching ─────────────────────────────────────────────────────────────────\n//\n// One stream per open tab, and one ask of the source per process: every\n// stream's names are asked about together, on an interval, and a version that\n// moved is written to every stream holding its name. A thousand tabs on a\n// long-lived server cost the backend one call per interval, not a thousand.\n// On a host that answers each request in its own isolate the sharing is\n// whatever the isolate serves at once, and a lone stream asks for itself -\n// the same code, degrading to one small call per tab per interval.\n\n/** How often the source is asked, when it answered at once. */\nexport const CHANGES_INTERVAL_MS = 2_000;\n\n/** How long the source may hold one ask. Bounds how long a new tab waits to join the shared ask. */\nexport const CHANGES_WAIT_MS = 5_000;\n\ninterface Stream {\n names: Set<string>;\n send(name: string, version: number): void;\n}\n\nconst streams = new Set<Stream>();\n\n/** The latest version seen for each name any stream holds. */\nconst known = new Map<string, number>();\n\nlet running = false;\nlet wake: (() => void) | null = null;\nlet warned = false;\n\nfunction observe(name: string, version: number): void {\n if (known.get(name) === version) return;\n\n known.set(name, version);\n\n for (const stream of streams)\n if (stream.names.has(name)) stream.send(name, version);\n}\n\n/**\n * A stream gone: and with it every name no other stream holds, which this\n * process has no reason to remember. Kept, the latest version of every name\n * any tab ever watched piled up for as long as the server ran.\n */\nfunction close(stream: Stream): void {\n if (!streams.delete(stream)) return;\n\n for (const name of stream.names) {\n let held = false;\n\n for (const other of streams) {\n if (other.names.has(name)) {\n held = true;\n break;\n }\n }\n\n if (!held) known.delete(name);\n }\n}\n\n/** Mapped to this process's set of streams: what to ask about, relative to what is known. */\nfunction sinceAll(): Record<string, number> {\n const since: Record<string, number> = {};\n\n for (const stream of streams)\n for (const name of stream.names) since[name] = known.get(name) ?? 0;\n\n return since;\n}\n\n// ── Waking ───────────────────────────────────────────────────────────────────\n//\n// A backend that cannot hold a question open - PHP - is asked again on an\n// interval. Something that can say \"a version moved\" the moment it does -\n// a broadcast, a Redis channel - makes that interval a safety net: the\n// renderer asks the moment it is woken, and otherwise rarely.\n\nconst WAKERS = Symbol.for(\"rsc-kit.wakers\");\n\ninterface Wakers {\n listens: ((wake: () => void, health: ListenerHealth) => unknown)[];\n started: boolean;\n /** A wake that came while an ask was in flight: ask again straight after. */\n pending: boolean;\n /** Asks a store is holding open, ended by a wake. */\n sleepers: Set<() => void>;\n}\n\nfunction wakers(): Wakers {\n return ((globals[WAKERS] as Wakers | undefined) ??= {\n listens: [],\n started: false,\n pending: false,\n sleepers: new Set(),\n });\n}\n\n/**\n * Wake the renderer when a version may have moved, so it asks then rather\n * than on its next interval.\n *\n * wakeOn(listenToBroadcast({ url, key })) // a broadcast server\n * wakeOn((wake) => subscriber.subscribe('rsc', wake)) // a Redis channel\n *\n * `listen` is given a function to call - it carries no names and no data;\n * the renderer asks wherever the versions live, as always. It is started\n * when the first tab starts watching, never in a build. With one installed,\n * a backend that answers at once is asked again every 30 seconds as a safety\n * net instead of every two.\n */\n/** What a listener is told besides how to wake: how to say it hears nothing. */\nexport interface ListenerHealth {\n /** This listener will never wake anything: say why, once, and stop counting on it. */\n deaf(reason: string): void;\n}\n\nexport function wakeOn(\n listen: (wake: () => void, health: ListenerHealth) => unknown,\n): void {\n const state = wakers();\n\n state.listens.push(listen);\n if (state.started) start(listen);\n}\n\n/**\n * Start one listener; one that fails - a database not up yet - is tried\n * again, backing off to thirty seconds. Until it is up the timer stands in.\n */\nfunction start(\n listen: (wake: () => void, health: ListenerHealth) => unknown,\n failures = 0,\n): void {\n const health: ListenerHealth = {\n deaf: (reason) => {\n const state = wakers();\n const at = state.listens.indexOf(listen);\n\n // No longer counted: the renderer goes back to asking on the shorter\n // interval, as it does with nothing to wake it.\n if (at === -1) return;\n state.listens.splice(at, 1);\n console.warn(\"[rsc-kit] \" + reason);\n },\n };\n\n void Promise.resolve()\n .then(() => listen(signal, health))\n .catch((error: unknown) => {\n if (failures === 0) {\n console.warn(\n \"[rsc-kit] a wakeOn listener failed to start, trying again: \" +\n (error instanceof Error ? error.message : String(error)),\n );\n }\n\n const retry = setTimeout(\n () => start(listen, failures + 1),\n Math.min(30_000, 1000 * 2 ** failures),\n );\n\n (retry as { unref?: () => void }).unref?.();\n });\n}\n\n/** Something said a version may have moved: ask now, and end any ask a store is holding. */\nfunction signal(): void {\n const state = wakers();\n\n state.pending = true;\n wake?.();\n for (const sleeper of [...state.sleepers]) sleeper();\n}\n\nfunction startWakers(): void {\n const state = wakers();\n\n if (state.started) return;\n state.started = true;\n\n // Set in the environment, not guessed: a broadcast server to listen to.\n const url = env(\"RSC_BROADCAST_URL\");\n const key = env(\"RSC_BROADCAST_KEY\");\n\n if (url && key) state.listens.push(listenToBroadcast({ url, key }));\n\n for (const listen of state.listens) start(listen);\n}\n\nasync function loop(): Promise<void> {\n running = true;\n startWakers();\n\n try {\n while (streams.size > 0) {\n const started = Date.now();\n const state = wakers();\n\n state.pending = false;\n\n try {\n const moved = await versionSource().changed(\n sinceAll(),\n CHANGES_WAIT_MS,\n );\n\n for (const [name, version] of Object.entries(moved))\n observe(name, version);\n } catch (error) {\n // A backend blip is not the end of watching. Said once, not per interval.\n if (!warned) {\n warned = true;\n console.warn(\n \"[rsc-kit] asking the backend for name versions failed: \" +\n (error instanceof Error ? error.message : String(error)),\n );\n }\n }\n\n // A source that waited used the interval; one that answered at once is\n // asked again after it - or, with something to wake it, only as a\n // safety net. A stream opening, or a wake, ends the wait early; a wake\n // that came during the ask is answered at once.\n const interval =\n state.listens.length > 0 ? LISTENING_POLL_MS : CHANGES_INTERVAL_MS;\n const remaining = state.pending ? 0 : interval - (Date.now() - started);\n\n if (remaining > 0 && streams.size > 0) {\n await new Promise<void>((resolve) => {\n const timer = setTimeout(resolve, remaining);\n\n (timer as { unref?: () => void }).unref?.();\n wake = () => {\n clearTimeout(timer);\n resolve();\n };\n });\n wake = null;\n }\n }\n } finally {\n running = false;\n // A stream that opened as the loop was ending starts it again.\n if (streams.size > 0) void loop();\n }\n}\n\nfunction parseWatch(\n url: URL,\n): { name: string; version: number; signature: string }[] | null {\n const raw = url.searchParams.get(\"w\");\n\n if (!raw) return null;\n\n let entries: unknown;\n\n try {\n entries = JSON.parse(raw);\n } catch {\n return null;\n }\n\n if (!Array.isArray(entries) || entries.length === 0 || entries.length > 200)\n return null;\n\n const parsed: { name: string; version: number; signature: string }[] = [];\n\n for (const entry of entries) {\n if (!Array.isArray(entry) || entry.length !== 3) return null;\n\n const [name, version, signature] = entry as unknown[];\n\n if (\n typeof name !== \"string\" ||\n typeof version !== \"number\" ||\n typeof signature !== \"string\"\n )\n return null;\n\n parsed.push({ name, version, signature });\n }\n\n return parsed;\n}\n\n/**\n * The stream a tab watches its names on: `GET /_rsc/changes?w=[[name, version, signature], …]`.\n *\n * One `data:` line per version that moved, `{ name, version }`, from the moment\n * the stream opens - a name that moved between the render and now is reported\n * at once, so nothing that happened in the gap is missed. Keepalives as an\n * events() route sends them; ends when the browser goes away.\n */\nexport async function changes(request: Request): Promise<Response> {\n const entries = parseWatch(new URL(request.url));\n\n if (!entries) return new Response(\"Bad watch request.\", { status: 400 });\n\n for (const { name, signature } of entries) {\n if (!(await verify(name, signature))) {\n return new Response(\"Not a name this page was rendered with.\", {\n status: 403,\n });\n }\n }\n\n const since: Record<string, number> = {};\n\n for (const { name, version } of entries) since[name] = version;\n\n const encoder = new TextEncoder();\n let stream: Stream | null = null;\n\n const body = new ReadableStream<Uint8Array>({\n start(sink) {\n const write = (text: string) => {\n try {\n sink.enqueue(encoder.encode(text));\n } catch {\n // Closed under us; the cancel below ends the rest.\n }\n };\n\n write(\"retry: 2000\\n\\n\");\n\n const keepalive = setInterval(\n () => write(\": keepalive\\n\\n\"),\n keepaliveMs(),\n );\n\n (keepalive as { unref?: () => void }).unref?.();\n\n const me: Stream = {\n names: new Set(Object.keys(since)),\n send: (name, version) => write(frame({ name, version })),\n };\n\n stream = me;\n streams.add(me);\n\n const end = () => {\n clearInterval(keepalive);\n close(me);\n\n try {\n sink.close();\n } catch {\n // Already closed.\n }\n };\n\n request.signal.addEventListener(\"abort\", end, { once: true });\n\n // What is known already answers at once; what is not is seeded with\n // what this tab holds, so the shared ask compares against it.\n for (const [name, version] of Object.entries(since)) {\n const seen = known.get(name);\n\n if (seen === undefined) known.set(name, version);\n else if (seen !== version) me.send(name, seen);\n }\n\n // This tab's own first ask, holding as long as the source will: the\n // shared ask may be mid-wait on an older set of names, and a name moving\n // in the seconds before this one joins it must not go unnoticed.\n void versionSource()\n .changed(since, CHANGES_WAIT_MS)\n .then((moved) => {\n for (const [name, version] of Object.entries(moved))\n observe(name, version);\n })\n .catch(() => {});\n\n if (!running) void loop();\n else wake?.();\n },\n cancel() {\n if (stream) close(stream);\n },\n });\n\n return new Response(body, {\n headers: {\n \"Content-Type\": \"text/event-stream; charset=utf-8\",\n // no-transform: a proxy or CDN in front must not compress or buffer\n // it either - Cloudflare compresses text unless told not to.\n \"Cache-Control\": \"no-store, no-transform\",\n \"X-Accel-Buffering\": \"no\",\n },\n });\n}\n\n/** For tests: forget every stream and version this process has seen. */\n/** For tests: how many names this process remembers for its open streams. */\nexport function rememberedNames(): number {\n return known.size;\n}\n\nexport function resetChanges(): void {\n delete globals[WAKERS];\n streams.clear();\n known.clear();\n warned = false;\n delete globals[LOCAL_SOURCE];\n}\n\n/** The url a tab opens to watch, for the client. */\nexport const CHANGES_PATH = HEADER.changesPath;\n"]}
|
package/dist/js/refreshOn.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* What a refreshOn function is given: the page's params and search params,
|
|
4
|
+
* already awaited, beside whatever props the section was rendered with.
|
|
5
|
+
*/
|
|
6
|
+
export type RefreshOnInput<P> = Omit<P, "params" | "searchParams"> & {
|
|
7
|
+
params: Record<string, string>;
|
|
8
|
+
searchParams: URLSearchParams | Record<string, unknown>;
|
|
9
|
+
};
|
|
2
10
|
/** What a section or page refreshes on: names, or a function of its props that makes them. */
|
|
3
|
-
export type RefreshOnList<P> = string[] | ((
|
|
11
|
+
export type RefreshOnList<P> = string[] | ((input: RefreshOnInput<P>) => string[] | Promise<string[]>);
|
|
4
12
|
/**
|
|
5
13
|
* The names a region refreshes on, read for this render and signed for the tab.
|
|
6
14
|
*
|
package/dist/js/refreshOn.js
CHANGED
|
@@ -34,7 +34,18 @@ async function Resolve({ target, refreshOn, props, }) {
|
|
|
34
34
|
await connection();
|
|
35
35
|
// The page's params and searchParams, under whatever the page passed: a
|
|
36
36
|
// section rendered by its page is given nothing, and alone is given these.
|
|
37
|
-
const
|
|
37
|
+
const given = { ...currentPageProps(), ...props };
|
|
38
|
+
// Awaited here, so `({ params }) => [\`team:${params.team}\`]` - the way
|
|
39
|
+
// anyone writes it - means the team. A page's params and search params
|
|
40
|
+
// are promises, and read without awaiting they made `team:undefined`:
|
|
41
|
+
// one name for every team, so each refreshed on all the others' changes.
|
|
42
|
+
// Awaiting costs nothing here; the names are made per request anyway.
|
|
43
|
+
const input = {
|
|
44
|
+
...given,
|
|
45
|
+
params: ((await given.params) ?? {}),
|
|
46
|
+
searchParams: ((await given.searchParams) ??
|
|
47
|
+
new URLSearchParams()),
|
|
48
|
+
};
|
|
38
49
|
const named = typeof refreshOn === "function" ? await refreshOn(input) : refreshOn;
|
|
39
50
|
const unique = [...new Set(named)].filter((name) => typeof name === "string" && name !== "");
|
|
40
51
|
if (unique.length === 0)
|
package/dist/js/refreshOn.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refreshOn.js","sourceRoot":"","sources":["../../src/js/refreshOn.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"refreshOn.js","sourceRoot":"","sources":["../../src/js/refreshOn.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAepC;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,SAAS,CAAI,EAC3B,MAAM,EACN,SAAS,EACT,KAAK,GAKN;IACC,O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M,aAAa,EAAE,CAAC,OAAO,CAC5C,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EACpD,CAAC,CACF,CAAC;QACF,MAAM,MAAM,GAA+B,EAAE,CAAC;QAE9C,KAAK,MAAM,IAAI,IAAI,MAAM;YACvB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAEzD,OAAO,aAAa,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACxB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACnB,OAAO,CAAC,IAAI,CACV,kBAAkB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,mDAAmD;gBACzF,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAC3D,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { Suspense, createElement } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { connection, currentPageProps } from \"../request\";\nimport { sign, versionSource } from \"../changed\";\nimport type { SignedName } from \"../changed\";\nimport { Changes } from \"./Changes\";\n\n/**\n * What a refreshOn function is given: the page's params and search params,\n * already awaited, beside whatever props the section was rendered with.\n */\nexport type RefreshOnInput<P> = Omit<P, \"params\" | \"searchParams\"> & {\n params: Record<string, string>;\n searchParams: URLSearchParams | Record<string, unknown>;\n};\n\n/** What a section or page refreshes on: names, or a function of its props that makes them. */\nexport type RefreshOnList<P> =\n string[] | ((input: RefreshOnInput<P>) => string[] | Promise<string[]>);\n\n/**\n * The names a region refreshes on, read for this render and signed for the tab.\n *\n * A server component, rendered beside the region: it works out the names\n * from the props, asks the source what version each is at, and hands them to\n * the client as `Changes`. Under its own Suspense boundary, so the ask never\n * holds up the region's paint - the data is what the visitor is waiting on,\n * not the version numbers behind it.\n *\n * Renders nothing when the source cannot answer - a backend that is down\n * for this one call. The region still renders; it just does not refresh on\n * its names until the next time it is rendered.\n */\nexport function RefreshOn<P>({\n target,\n refreshOn,\n props,\n}: {\n target: string;\n refreshOn: RefreshOnList<P>;\n props: P;\n}): ReactNode {\n return createElement(\n Suspense,\n { fallback: null },\n createElement(Resolve as never, { target, refreshOn, props }),\n );\n}\n\nconst warned = new Set<string>();\n\n/**\n * Never throws. An error here would become an error row inside the region's\n * payload, and the browser decodes that as the region failing - a blank\n * document for a version lookup that did not go through. Said once per\n * region instead, and the region renders without refreshing on anything.\n */\nasync function Resolve<P>({\n target,\n refreshOn,\n props,\n}: {\n target: string;\n refreshOn: RefreshOnList<P>;\n props: P;\n}): Promise<ReactNode> {\n try {\n // Per request, never at build. A version read at build is stale by the\n // time anyone loads the page, and a name signed at build is signed with\n // whatever key the build machine had. At build this suspends and the\n // names become a hole in the stored shell, filled per request.\n await connection();\n\n // The page's params and searchParams, under whatever the page passed: a\n // section rendered by its page is given nothing, and alone is given these.\n const given = { ...currentPageProps(), ...(props as object) } as Record<\n string,\n unknown\n >;\n\n // Awaited here, so `({ params }) => [\\`team:${params.team}\\`]` - the way\n // anyone writes it - means the team. A page's params and search params\n // are promises, and read without awaiting they made `team:undefined`:\n // one name for every team, so each refreshed on all the others' changes.\n // Awaiting costs nothing here; the names are made per request anyway.\n const input = {\n ...given,\n params: ((await given.params) ?? {}) as Record<string, string>,\n searchParams: ((await given.searchParams) ??\n new URLSearchParams()) as URLSearchParams,\n } as RefreshOnInput<P>;\n const named =\n typeof refreshOn === \"function\" ? await refreshOn(input) : refreshOn;\n const unique = [...new Set(named)].filter(\n (name) => typeof name === \"string\" && name !== \"\",\n );\n\n if (unique.length === 0) return null;\n\n // -1 is a version nothing is at, so every name comes back with its current version.\n const versions = await versionSource().changed(\n Object.fromEntries(unique.map((name) => [name, -1])),\n 0,\n );\n const signed: Record<string, SignedName> = {};\n\n for (const name of unique)\n signed[name] = [versions[name] ?? 0, await sign(name)];\n\n return createElement(Changes, { target, names: signed });\n } catch (error) {\n if (!warned.has(target)) {\n warned.add(target);\n console.warn(\n `[rsc-kit] what ${JSON.stringify(target)} refreshes on could not be read, so it will not: ` +\n (error instanceof Error ? error.message : String(error)),\n );\n }\n\n return null;\n }\n}\n"]}
|
package/dist/testHost.d.ts
CHANGED
|
@@ -14,11 +14,22 @@ export declare const HOST_MIDDLEWARE = "__rsc.middleware";
|
|
|
14
14
|
* `host` answers `__rsc.changed` the way an adapter does - holding the call up
|
|
15
15
|
* to `wait` for a name to move - and `changed` moves one.
|
|
16
16
|
*/
|
|
17
|
+
/**
|
|
18
|
+
* The test host's answer to `__rsc.changed`: given what any test host is
|
|
19
|
+
* given, answering a `ChangedAnswer`.
|
|
20
|
+
*
|
|
21
|
+
* Both halves matter. It takes `HostCallInput`, so an untyped host of
|
|
22
|
+
* `HostHandler`s accepts it; it returns a `ChangedAnswer`, so a host typed
|
|
23
|
+
* from the app's rsc-host.json - whose `__rsc.changed` must answer one -
|
|
24
|
+
* accepts it too. Typed as `HostHandler`, it returned `unknown`, and
|
|
25
|
+
* spreading it into a typed host did not compile.
|
|
26
|
+
*/
|
|
27
|
+
export interface ChangedHost {
|
|
28
|
+
[CHANGED_FUNCTION]: (call: HostCallInput) => Promise<ChangedAnswer>;
|
|
29
|
+
}
|
|
17
30
|
export declare function testChanges(): {
|
|
18
|
-
host:
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
changed: (...tags: string[]) => void;
|
|
31
|
+
host: ChangedHost;
|
|
32
|
+
changed: (...names: string[]) => void;
|
|
22
33
|
};
|
|
23
34
|
/** What a test handler is given: the call's arguments, and the headers the renderer forwarded. */
|
|
24
35
|
export interface HostCallInput {
|
package/dist/testHost.js
CHANGED
|
@@ -9,16 +9,6 @@ import { CHANGED_FUNCTION, memoryVersions } from './changed.js';
|
|
|
9
9
|
const REPLY = Symbol.for('rsc-kit.test-host-reply');
|
|
10
10
|
/** The name the engine asks a host's route guards under. */
|
|
11
11
|
export const HOST_MIDDLEWARE = '__rsc.middleware';
|
|
12
|
-
/**
|
|
13
|
-
* Tag versions for a test host, kept in the test.
|
|
14
|
-
*
|
|
15
|
-
* const names = testChanges()
|
|
16
|
-
* const app = await createTestApp({ host: { ...names.host, 'Repos.list': () => repos } })
|
|
17
|
-
* names.changed('team:1:repos') // what the backend's webhook would say
|
|
18
|
-
*
|
|
19
|
-
* `host` answers `__rsc.changed` the way an adapter does - holding the call up
|
|
20
|
-
* to `wait` for a name to move - and `changed` moves one.
|
|
21
|
-
*/
|
|
22
12
|
export function testChanges() {
|
|
23
13
|
const source = memoryVersions();
|
|
24
14
|
return {
|
|
@@ -28,7 +18,7 @@ export function testChanges() {
|
|
|
28
18
|
return { versions: await source.changed(query?.since ?? {}, Math.min(query?.wait ?? 0, 5_000)) };
|
|
29
19
|
},
|
|
30
20
|
},
|
|
31
|
-
changed: (...
|
|
21
|
+
changed: (...names) => void source.bump(names),
|
|
32
22
|
};
|
|
33
23
|
}
|
|
34
24
|
const reply = (fields) => ({ ...fields, [REPLY]: true });
|
|
@@ -61,6 +51,7 @@ function isReply(value) {
|
|
|
61
51
|
return typeof value === 'object' && value !== null && value[REPLY] === true;
|
|
62
52
|
}
|
|
63
53
|
async function answer(host, name, args, headers) {
|
|
54
|
+
// By a name only known at runtime: a typed host has no index signature.
|
|
64
55
|
const handler = host[name];
|
|
65
56
|
// Fails the call rather than answering null: a function the test forgot
|
|
66
57
|
// is a test that would otherwise pass against nothing.
|
package/dist/testHost.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-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AAI,OAAO,IAAI,IAAI,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC;gBACV,OAAO,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;aACnG,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,CAAA;IAC1E,CAAC,CAAiB,CAAA;AACpB,CAAC","sourcesContent":["// A backend for tests: answers rpc() calls and host middleware the way a Go\n// or Laravel host answers them over HTTP, without one running.\n//\n// The app under test talks to it through the real client, httpHostCalls,\n// handed a fetch that answers in-process. So a test exercises what ships -\n// batching, a redirect raised as the engine's own, an unauthenticated reply\n// becoming a 401 - and only the backend is stood in for.\n\nimport type { HostCallReply } from './hostCalls.js'\nimport { CHANGED_FUNCTION, memoryVersions } from './changed.js'\nimport type { ChangedAnswer, ChangedQuery } from './changed.js'\n\nconst REPLY = Symbol.for('rsc-kit.test-host-reply')\n\n/** The name the engine asks a host's route guards under. */\nexport const HOST_MIDDLEWARE = '__rsc.middleware'\n\n/**\n * Tag versions for a test host, kept in the test.\n *\n * const names = testChanges()\n * const app = await createTestApp({ host: { ...names.host, 'Repos.list': () => repos } })\n * names.changed('team:1:repos') // what the backend's webhook would say\n *\n * `host` answers `__rsc.changed` the way an adapter does - holding the call up\n * to `wait` for a name to move - and `changed` moves one.\n */\nexport function testChanges(): { host: { [CHANGED_FUNCTION]: HostHandler }; changed: (...tags: string[]) => void } {\n const source = memoryVersions()\n\n return {\n host: {\n [CHANGED_FUNCTION]: async ({ args }) => {\n const query = args[0] as Partial<ChangedQuery> | undefined\n\n return { versions: await source.changed(query?.since ?? {}, Math.min(query?.wait ?? 0, 5_000)) } satisfies ChangedAnswer\n },\n },\n changed: (...tags) => void source.bump(tags),\n }\n}\n\n/** What a test handler is given: the call's arguments, and the headers the renderer forwarded. */\nexport interface HostCallInput {\n args: unknown[]\n /** The visitor's request headers the renderer passed on - the cookie, the Accept-Language. */\n headers: Headers\n}\n\n/** Answers one function. Return a value for its result, or one of `hostReply`'s answers. */\nexport type HostHandler = (call: HostCallInput) => unknown\n\ntype Reply = Omit<HostCallReply, 'result'> & { [REPLY]: true }\n\n/** One of the protocol's own answers, from `hostReply`. */\nexport type HostReply = Reply\n\ndeclare global {\n /**\n * The backend's functions, as the build read them from rsc-host.json:\n * each one's arguments and result. Written into .rsc-kit/rsc-env.d.ts;\n * empty without a manifest.\n */\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n interface RscHostFunctions {}\n}\n\ntype Answer<T> = T | HostReply | Promise<T | HostReply>\n\ntype Guards = {\n [HOST_MIDDLEWARE]?: (call: { args: [names: string[]]; headers: Headers }) => Answer<true>\n [CHANGED_FUNCTION]?: (call: { args: [query: ChangedQuery]; headers: Headers }) => Answer<ChangedAnswer>\n}\n\n/**\n * The backend's functions, by the name rpc() calls them with.\n *\n * Typed from the app's rsc-host.json when it has one: a handler may only\n * answer for a function the backend has, is given its arguments, and returns\n * its result or one of `hostReply`'s answers - never a shape the backend\n * would not send, which is how a fake drifts from the real thing while its\n * tests stay green. Without a manifest, any name and any value.\n *\n * Route guards declared for the host are asked as `__rsc.middleware`\n * (`HOST_MIDDLEWARE`), with the guard names as the first argument; answer\n * `true` to let the page render.\n */\nexport type TestHost = [keyof RscHostFunctions] extends [never]\n ? Record<string, HostHandler>\n : {\n [K in keyof RscHostFunctions]?: RscHostFunctions[K] extends { args: infer A extends unknown[]; result: infer R }\n ? (call: { args: A; headers: Headers }) => Answer<R>\n : never\n } & Guards\n\nconst reply = (fields: Omit<Reply, typeof REPLY>): Reply => ({ ...fields, [REPLY]: true })\n\n/**\n * The protocol's own answers, for a handler to return.\n *\n * host: {\n * 'Apps.list': ({ headers }) =>\n * headers.get('cookie')?.includes('session=') ? [{ id: 1 }] : hostReply.unauthenticated(),\n * 'Apps.create': ({ args }) => hostReply.invalid({ name: ['Taken.'] }),\n * }\n */\nexport const hostReply = {\n /** No session: the page answers 401, an action its auth error. */\n unauthenticated: (message?: string): Reply => reply({ unauthenticated: true, error: message }),\n /** A session that still may not: 403. */\n unauthorized: (message?: string): Reply => reply({ unauthorized: true, error: message }),\n /** Send the visitor somewhere else, as the host's redirect does. */\n redirect: (to: string, status = 307): Reply => reply({ redirect: to, redirectStatus: status }),\n /** Refuse with a status - a 404 for a record this caller cannot see, a 429. */\n refuse: (status: number, message = 'Refused.'): Reply => reply({ error: message, refusalStatus: status }),\n /** The input was refused, by field: an action returns these as validationErrors. */\n invalid: (errors: Record<string, string[]>): Reply => reply({ validationErrors: errors }),\n /** An unexpected failure, as an adapter answers a crash: an error, not a refusal. */\n fail: (message = 'Something went wrong.'): Reply => reply({ error: message }),\n /** A result, and the regions of the page the call says it changed. */\n revalidating: (result: unknown, ...targets: string[]): Reply =>\n reply({ result, revalidate: targets } as Omit<Reply, typeof REPLY>),\n} as const\n\nfunction isReply(value: unknown): value is Reply {\n return typeof value === 'object' && value !== null && (value as Record<symbol, unknown>)[REPLY] === true\n}\n\nasync function answer(host: TestHost, name: string, args: unknown[], headers: Headers): Promise<HostCallReply> {\n const handler = host[name]\n\n // Fails the call rather than answering null: a function the test forgot\n // is a test that would otherwise pass against nothing.\n if (!handler) {\n return {\n error:\n name === HOST_MIDDLEWARE\n ? `the page asked its host guards (${JSON.stringify(args[0])}) and the test host has no \"${HOST_MIDDLEWARE}\" handler`\n : `the test host has no handler for ${JSON.stringify(name)}`,\n }\n }\n\n const value = await handler({ args, headers })\n\n if (isReply(value)) {\n const { [REPLY]: _, ...fields } = value\n\n return fields\n }\n\n return { result: value === undefined ? null : value }\n}\n\n/**\n * A fetch that answers the host-call endpoint from `host`: one call as\n * itself, a batch as `{ replies }`, in order.\n */\nexport function testHostFetch(host: TestHost): typeof fetch {\n return (async (_input: RequestInfo | URL, init?: RequestInit) => {\n const headers = new Headers(init?.headers)\n const body = JSON.parse(String(init?.body ?? '{}')) as\n | { function: string; args?: unknown[] }\n | { calls: { function: string; args?: unknown[] }[] }\n\n // The renderer's own headers are not the visitor's.\n headers.delete('x-rsc-host-secret')\n headers.delete('content-type')\n\n const json = (value: unknown) =>\n new Response(JSON.stringify(value), { headers: { 'content-type': 'application/json' } })\n\n if ('calls' in body) {\n return json({\n replies: await Promise.all(body.calls.map((c) => answer(host, c.function, c.args ?? [], headers))),\n })\n }\n\n return json(await answer(host, body.function, body.args ?? [], headers))\n }) as typeof fetch\n}\n"]}
|
|
1
|
+
{"version":3,"file":"testHost.js","sourceRoot":"","sources":["../src/testHost.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,+DAA+D;AAC/D,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,4EAA4E;AAC5E,yDAAyD;AAGzD,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAG/D,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAA;AAEnD,4DAA4D;AAC5D,MAAM,CAAC,MAAM,eAAe,GAAG,kBAAkB,CAAA;AA0BjD,MAAM,UAAU,WAAW;IACzB,MAAM,MAAM,GAAG,cAAc,EAAE,CAAA;IAE/B,OAAO;QACL,IAAI,EAAE;YACJ,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;gBACrC,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAsC,CAAA;gBAE1D,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,IAAI,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,IA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D,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,IAAI,IAAI,CAAC,CAEK,CAAA;QAEvD,oDAAoD;QACpD,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAA;QACnC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA;QAE9B,MAAM,IAAI,GAAG,CAAC,KAAc,EAAE,EAAE,CAC9B,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,EAAE,CAAC,CAAA;QAE1F,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC;gBACV,OAAO,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;aACnG,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,CAAA;IAC1E,CAAC,CAAiB,CAAA;AACpB,CAAC","sourcesContent":["// A backend for tests: answers rpc() calls and host middleware the way a Go\n// or Laravel host answers them over HTTP, without one running.\n//\n// The app under test talks to it through the real client, httpHostCalls,\n// handed a fetch that answers in-process. So a test exercises what ships -\n// batching, a redirect raised as the engine's own, an unauthenticated reply\n// becoming a 401 - and only the backend is stood in for.\n\nimport type { HostCallReply } from './hostCalls.js'\nimport { CHANGED_FUNCTION, memoryVersions } from './changed.js'\nimport type { ChangedAnswer, ChangedQuery } from './changed.js'\n\nconst REPLY = Symbol.for('rsc-kit.test-host-reply')\n\n/** The name the engine asks a host's route guards under. */\nexport const HOST_MIDDLEWARE = '__rsc.middleware'\n\n/**\n * Tag versions for a test host, kept in the test.\n *\n * const names = testChanges()\n * const app = await createTestApp({ host: { ...names.host, 'Repos.list': () => repos } })\n * names.changed('team:1:repos') // what the backend's webhook would say\n *\n * `host` answers `__rsc.changed` the way an adapter does - holding the call up\n * to `wait` for a name to move - and `changed` moves one.\n */\n/**\n * The test host's answer to `__rsc.changed`: given what any test host is\n * given, answering a `ChangedAnswer`.\n *\n * Both halves matter. It takes `HostCallInput`, so an untyped host of\n * `HostHandler`s accepts it; it returns a `ChangedAnswer`, so a host typed\n * from the app's rsc-host.json - whose `__rsc.changed` must answer one -\n * accepts it too. Typed as `HostHandler`, it returned `unknown`, and\n * spreading it into a typed host did not compile.\n */\nexport interface ChangedHost {\n [CHANGED_FUNCTION]: (call: HostCallInput) => Promise<ChangedAnswer>\n}\n\nexport function testChanges(): { host: ChangedHost; changed: (...names: string[]) => void } {\n const source = memoryVersions()\n\n return {\n host: {\n [CHANGED_FUNCTION]: async ({ args }) => {\n const query = args[0] as Partial<ChangedQuery> | undefined\n\n return { versions: await source.changed(query?.since ?? {}, Math.min(query?.wait ?? 0, 5_000)) }\n },\n },\n changed: (...names) => void source.bump(names),\n }\n}\n\n/** What a test handler is given: the call's arguments, and the headers the renderer forwarded. */\nexport interface HostCallInput {\n args: unknown[]\n /** The visitor's request headers the renderer passed on - the cookie, the Accept-Language. */\n headers: Headers\n}\n\n/** Answers one function. Return a value for its result, or one of `hostReply`'s answers. */\nexport type HostHandler = (call: HostCallInput) => unknown\n\ntype Reply = Omit<HostCallReply, 'result'> & { [REPLY]: true }\n\n/** One of the protocol's own answers, from `hostReply`. */\nexport type HostReply = Reply\n\ndeclare global {\n /**\n * The backend's functions, as the build read them from rsc-host.json:\n * each one's arguments and result. Written into .rsc-kit/rsc-env.d.ts;\n * empty without a manifest.\n */\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n interface RscHostFunctions {}\n}\n\ntype Answer<T> = T | HostReply | Promise<T | HostReply>\n\ntype Guards = {\n [HOST_MIDDLEWARE]?: (call: { args: [names: string[]]; headers: Headers }) => Answer<true>\n [CHANGED_FUNCTION]?: (call: { args: [query: ChangedQuery]; headers: Headers }) => Answer<ChangedAnswer>\n}\n\n/**\n * The backend's functions, by the name rpc() calls them with.\n *\n * Typed from the app's rsc-host.json when it has one: a handler may only\n * answer for a function the backend has, is given its arguments, and returns\n * its result or one of `hostReply`'s answers - never a shape the backend\n * would not send, which is how a fake drifts from the real thing while its\n * tests stay green. Without a manifest, any name and any value.\n *\n * Route guards declared for the host are asked as `__rsc.middleware`\n * (`HOST_MIDDLEWARE`), with the guard names as the first argument; answer\n * `true` to let the page render.\n */\nexport type TestHost = [keyof RscHostFunctions] extends [never]\n ? Record<string, HostHandler>\n : {\n [K in keyof RscHostFunctions]?: RscHostFunctions[K] extends { args: infer A extends unknown[]; result: infer R }\n ? (call: { args: A; headers: Headers }) => Answer<R>\n : never\n } & Guards\n\nconst reply = (fields: Omit<Reply, typeof REPLY>): Reply => ({ ...fields, [REPLY]: true })\n\n/**\n * The protocol's own answers, for a handler to return.\n *\n * host: {\n * 'Apps.list': ({ headers }) =>\n * headers.get('cookie')?.includes('session=') ? [{ id: 1 }] : hostReply.unauthenticated(),\n * 'Apps.create': ({ args }) => hostReply.invalid({ name: ['Taken.'] }),\n * }\n */\nexport const hostReply = {\n /** No session: the page answers 401, an action its auth error. */\n unauthenticated: (message?: string): Reply => reply({ unauthenticated: true, error: message }),\n /** A session that still may not: 403. */\n unauthorized: (message?: string): Reply => reply({ unauthorized: true, error: message }),\n /** Send the visitor somewhere else, as the host's redirect does. */\n redirect: (to: string, status = 307): Reply => reply({ redirect: to, redirectStatus: status }),\n /** Refuse with a status - a 404 for a record this caller cannot see, a 429. */\n refuse: (status: number, message = 'Refused.'): Reply => reply({ error: message, refusalStatus: status }),\n /** The input was refused, by field: an action returns these as validationErrors. */\n invalid: (errors: Record<string, string[]>): Reply => reply({ validationErrors: errors }),\n /** An unexpected failure, as an adapter answers a crash: an error, not a refusal. */\n fail: (message = 'Something went wrong.'): Reply => reply({ error: message }),\n /** A result, and the regions of the page the call says it changed. */\n revalidating: (result: unknown, ...targets: string[]): Reply =>\n reply({ result, revalidate: targets } as Omit<Reply, typeof REPLY>),\n} as const\n\nfunction isReply(value: unknown): value is Reply {\n return typeof value === 'object' && value !== null && (value as Record<symbol, unknown>)[REPLY] === true\n}\n\nasync function answer(host: TestHost, name: string, args: unknown[], headers: Headers): Promise<HostCallReply> {\n // By a name only known at runtime: a typed host has no index signature.\n const handler = (host as Record<string, HostHandler | undefined>)[name]\n\n // Fails the call rather than answering null: a function the test forgot\n // is a test that would otherwise pass against nothing.\n if (!handler) {\n return {\n error:\n name === HOST_MIDDLEWARE\n ? `the page asked its host guards (${JSON.stringify(args[0])}) and the test host has no \"${HOST_MIDDLEWARE}\" handler`\n : `the test host has no handler for ${JSON.stringify(name)}`,\n }\n }\n\n const value = await handler({ args, headers })\n\n if (isReply(value)) {\n const { [REPLY]: _, ...fields } = value\n\n return fields\n }\n\n return { result: value === undefined ? null : value }\n}\n\n/**\n * A fetch that answers the host-call endpoint from `host`: one call as\n * itself, a batch as `{ replies }`, in order.\n */\nexport function testHostFetch(host: TestHost): typeof fetch {\n return (async (_input: RequestInfo | URL, init?: RequestInit) => {\n const headers = new Headers(init?.headers)\n const body = JSON.parse(String(init?.body ?? '{}')) as\n | { function: string; args?: unknown[] }\n | { calls: { function: string; args?: unknown[] }[] }\n\n // The renderer's own headers are not the visitor's.\n headers.delete('x-rsc-host-secret')\n headers.delete('content-type')\n\n const json = (value: unknown) =>\n new Response(JSON.stringify(value), { headers: { 'content-type': 'application/json' } })\n\n if ('calls' in body) {\n return json({\n replies: await Promise.all(body.calls.map((c) => answer(host, c.function, c.args ?? [], headers))),\n })\n }\n\n return json(await answer(host, body.function, body.args ?? [], headers))\n }) as typeof fetch\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsc-kit/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.1",
|
|
4
4
|
"description": "React Server Components as a Vite plugin. Routing, streaming, server actions, typed urls and build-time prerendering — deploy to Bun, Node, Workers, Vercel or Deno.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -276,7 +276,7 @@
|
|
|
276
276
|
},
|
|
277
277
|
"scripts": {
|
|
278
278
|
"test": "bun test --isolate tests/js",
|
|
279
|
-
"typecheck": "tsc --noEmit && tsc --noEmit -p tests/js/routeTypes.tsconfig.json",
|
|
279
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tests/js/routeTypes.tsconfig.json && tsc --noEmit -p tests/js/testHostTypes.tsconfig.json",
|
|
280
280
|
"build": "rm -rf dist && tsc -p tsconfig.build.json && chmod +x dist/typegen.js dist/conformance.js",
|
|
281
281
|
"prepack": "bun run build"
|
|
282
282
|
},
|