@fairfox/polly 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -78,7 +78,9 @@ async function createPeerRepoServer(options) {
78
78
  client.terminate();
79
79
  } catch {}
80
80
  }
81
- repo.shutdown();
81
+ try {
82
+ await repo.shutdown();
83
+ } catch {}
82
84
  try {
83
85
  wss.close();
84
86
  } catch {}
@@ -394,4 +396,4 @@ export {
394
396
  peerRepo
395
397
  };
396
398
 
397
- //# debugId=0BDEE51AC0A70CC764756E2164756E21
399
+ //# debugId=93C98D54564BCF4764756E2164756E21
@@ -3,13 +3,13 @@
3
3
  "sources": ["../src/elysia/peer-repo-plugin.ts", "../src/shared/lib/peer-repo-server.ts", "../src/elysia/plugin.ts", "../src/core/clock.ts", "../src/utils/function-serialization.ts", "../src/elysia/signaling-server-plugin.ts"],
4
4
  "sourcesContent": [
5
5
  "// @ts-nocheck - Optional peer dependencies (elysia, @automerge/automerge-repo*)\n/**\n * peerRepo — Elysia plugin that runs a Polly peer-relay server alongside an\n * Elysia application and exposes the server's Repo on the Elysia context.\n *\n * The Phase 1 plan originally framed the relay server as an Elysia plugin\n * that registers a WebSocket route on Elysia's native socket layer. That\n * design does not work directly: Automerge's WebSocketServerAdapter requires\n * an `isomorphic-ws` WebSocketServer instance, and Elysia's WebSocket layer\n * is built on Bun's native WebSocket API, which is a different shape. The\n * realistic Phase 1 cut is therefore a *lifecycle* plugin: it runs\n * createPeerRepoServer on its own port during Elysia startup, decorates the\n * Elysia context so route handlers can reach the resulting Repo, and tears\n * the server down during Elysia shutdown. Authenticated WebSocket upgrades\n * via Elysia's hook system are a Phase 1.1 follow-up that requires either\n * a custom Bun-native NetworkAdapter or an upgrade-time auth bridge.\n *\n * @example\n * ```ts\n * import { Elysia } from \"elysia\";\n * import { peerRepo } from \"@fairfox/polly/elysia\";\n *\n * const app = new Elysia()\n * .use(peerRepo({ port: 3030, storagePath: \"./data/polly-peer\" }))\n * .get(\"/stats\", ({ pollyPeerRepo }) => {\n * return { peers: pollyPeerRepo.peers.length };\n * })\n * .listen(8080);\n * ```\n */\n\nimport { Elysia } from \"elysia\";\nimport {\n type CreatePeerRepoServerOptions,\n createPeerRepoServer,\n type PeerRepoServer,\n} from \"../shared/lib/peer-repo-server\";\n\nexport interface PeerRepoPluginOptions extends CreatePeerRepoServerOptions {\n /** Optional path for a health endpoint that returns peer count and storage\n * id. Set to false to skip the health route entirely. Defaults to\n * \"/polly/peer/health\". */\n healthPath?: string | false;\n}\n\n/**\n * Elysia plugin that boots a Polly peer-relay server alongside the host app\n * and decorates the context with `pollyPeerRepo` (the Repo) and\n * `pollyPeerServer` (the full {@link PeerRepoServer} for advanced use).\n *\n * The plugin starts the relay server during Elysia's onStart lifecycle and\n * shuts it down during onStop, so route handlers and cron jobs can use the\n * decorated Repo throughout the request lifetime without managing the\n * underlying transport themselves.\n */\nexport function peerRepo(options: PeerRepoPluginOptions) {\n // The plugin holds a single PeerRepoServer for the lifetime of the Elysia\n // app. It is created during onStart so the listening socket is bound and\n // ready before any request handler can reach it.\n let server: PeerRepoServer | undefined;\n\n const healthPath =\n options.healthPath === false ? null : (options.healthPath ?? \"/polly/peer/health\");\n\n let app = new Elysia({ name: \"polly-peer-repo\" })\n .decorate(\"pollyPeerRepo\", null as unknown as PeerRepoServer[\"repo\"] | null)\n .decorate(\"pollyPeerServer\", null as unknown as PeerRepoServer | null)\n .onStart(async () => {\n server = await createPeerRepoServer(options);\n // Decorate after construction so handlers see the live Repo. Elysia's\n // decorate is mutable in-place when called on the running instance.\n app.decorate(\"pollyPeerRepo\", server.repo);\n app.decorate(\"pollyPeerServer\", server);\n })\n .onStop(async () => {\n if (server) {\n await server.close();\n server = undefined;\n }\n });\n\n if (healthPath) {\n app = app.get(healthPath, () => {\n if (!server) {\n return { status: \"starting\", peers: 0 };\n }\n return {\n status: \"running\",\n peers: server.repo.peers.length,\n port: options.port,\n };\n });\n }\n\n return app;\n}\n",
6
- "/**\n * peer-repo-server — Phase 1 server-side factory for the Polly peer-relay\n * transport. Constructs an Automerge-Repo `Repo` wired to a WebSocket server\n * and a NodeFS storage backend, ready to relay sync messages between\n * connected $peerState clients.\n *\n * The \"always-on peer\" role for $peerState lives here. The server holds a\n * full Automerge replica of every document, participates in the sync protocol\n * as an ordinary peer, and persists state to disk so the next process restart\n * picks up where the previous one left off. Server-side cron, HTTP handlers,\n * and other compute can open document handles on the returned Repo and mutate\n * them; mutations propagate to connected clients through the same sync\n * protocol that handles client-to-client traffic.\n *\n * The plan originally called this an \"Elysia plugin,\" but Automerge's\n * `WebSocketServerAdapter` requires an `isomorphic-ws` `WebSocketServer`\n * instance — not Elysia's native WebSocket — so the cleanest first cut is a\n * standalone factory that runs its own `ws` server. Elysia integration for\n * authenticated upgrades is a Phase 1.1 follow-up that wraps this factory.\n *\n * @example\n * ```ts\n * import { createPeerRepoServer } from \"@fairfox/polly\";\n *\n * const server = await createPeerRepoServer({\n * port: 3030,\n * storagePath: \"./data/polly-peer\",\n * });\n *\n * // Open a document handle on the server's Repo for cron or compute work.\n * const handle = server.repo.create({ counter: 0 });\n *\n * // On shutdown:\n * await server.close();\n * ```\n */\n\nimport { Repo } from \"@automerge/automerge-repo\";\nimport { WebSocketServerAdapter } from \"@automerge/automerge-repo-network-websocket\";\nimport { NodeFSStorageAdapter } from \"@automerge/automerge-repo-storage-nodefs\";\nimport * as ws from \"ws\";\n\n// `@types/ws` uses CJS `export = WebSocket` with WebSocketServer hanging off\n// the namespace. Under the project's bundler module resolution, the namespace\n// import gives us access to both the constructor and the type.\ntype WebSocketServer = ws.WebSocketServer;\n\nexport interface CreatePeerRepoServerOptions {\n /** Port to listen on. The factory creates its own `WebSocketServer` and\n * binds to this port. */\n port: number;\n /** Filesystem directory for the NodeFS storage adapter. The directory is\n * created on demand. Defaults to `./automerge-repo-data` (Automerge's own\n * default). */\n storagePath?: string;\n /** Hostname interface to bind to. Defaults to all interfaces. */\n host?: string;\n /** Override the `WebSocketServer` instance entirely. When provided, `port`\n * and `host` are ignored and the caller is responsible for the lifecycle.\n * Useful for tests that want to bind to a random port. */\n webSocketServer?: WebSocketServer;\n}\n\nexport interface PeerRepoServer {\n /** A configured Repo participating as the always-on peer. Server-side\n * cron and HTTP handlers can open document handles on this directly. */\n repo: Repo;\n /** The underlying WebSocket server. Exposed for advanced use such as\n * health checks or graceful shutdown coordination. */\n webSocketServer: WebSocketServer;\n /** The Automerge network adapter wrapping the WebSocket server. */\n adapter: WebSocketServerAdapter;\n /** The NodeFS storage adapter writing to {@link CreatePeerRepoServerOptions.storagePath}. */\n storage: NodeFSStorageAdapter;\n /** Tear down the server: disconnect peers, flush storage, close the\n * underlying WebSocket server. Returns a promise that resolves once the\n * tear-down is complete. */\n close: () => Promise<void>;\n}\n\n/**\n * Construct a Polly peer-relay server. Returns a Repo that participates as\n * the always-on peer, the underlying WebSocket server and storage adapter\n * for advanced use, and a close function for orderly shutdown.\n *\n * Applications typically call this once at startup, hold the returned\n * `repo` reference for cron and compute work, and wire the close function\n * into their process shutdown signal handlers.\n */\nexport async function createPeerRepoServer(\n options: CreatePeerRepoServerOptions\n): Promise<PeerRepoServer> {\n // Construct the WebSocket server first and wait until it is actually\n // listening before wiring up the Repo. Using the constructor callback\n // avoids the race where the 'listening' event fires before our listener\n // is attached (the callback form is reliable across Node and Bun).\n const wss = await (options.webSocketServer\n ? Promise.resolve(options.webSocketServer)\n : new Promise<WebSocketServer>((resolve, reject) => {\n const created: WebSocketServer = new ws.WebSocketServer(\n {\n port: options.port,\n ...(options.host !== undefined && { host: options.host }),\n },\n () => resolve(created)\n );\n created.once(\"error\", reject);\n }));\n\n // The cast bridges a @types/ws identity quirk: Automerge's adapter type\n // expects WebSocketServer with options.WebSocket typed via isomorphic-ws's\n // CJS-style namespace, and our direct `ws` import resolves through a\n // different path with the same runtime shape but a structurally distinct\n // TypeScript type. The runtime is identical, the cast names that fact.\n const adapter = new WebSocketServerAdapter(\n wss as unknown as ConstructorParameters<typeof WebSocketServerAdapter>[0]\n );\n const storage = new NodeFSStorageAdapter(options.storagePath);\n\n const repo = new Repo({\n network: [adapter],\n storage,\n });\n\n // Force the storage subsystem to finish initialising before returning. The\n // Repo constructor is synchronous, but its NetworkSubsystem holds back the\n // peer-metadata JOIN until storageSubsystem.id() resolves. If a client\n // connects before that resolution lands, the handshake stalls indefinitely.\n // Awaiting storageId() drains the relevant microtask chain and guarantees\n // the server is ready to accept peers when this factory returns.\n await repo.storageId();\n\n return {\n repo,\n webSocketServer: wss,\n adapter,\n storage,\n close: async () => {\n // Forcibly terminate any still-open client sockets before closing the\n // server, otherwise wss.close() can hang waiting for orderly drain when\n // a peer disappeared without a clean disconnect. We then fire the\n // server close without awaiting its callback — the underlying socket\n // is released immediately by terminate(), and waiting for the close\n // callback can hang under Bun even after every client is gone.\n for (const client of wss.clients) {\n try {\n client.terminate();\n } catch {\n // best effort\n }\n }\n void repo.shutdown();\n try {\n wss.close();\n } catch {\n // best effort\n }\n },\n };\n}\n",
6
+ "/**\n * peer-repo-server — Phase 1 server-side factory for the Polly peer-relay\n * transport. Constructs an Automerge-Repo `Repo` wired to a WebSocket server\n * and a NodeFS storage backend, ready to relay sync messages between\n * connected $peerState clients.\n *\n * The \"always-on peer\" role for $peerState lives here. The server holds a\n * full Automerge replica of every document, participates in the sync protocol\n * as an ordinary peer, and persists state to disk so the next process restart\n * picks up where the previous one left off. Server-side cron, HTTP handlers,\n * and other compute can open document handles on the returned Repo and mutate\n * them; mutations propagate to connected clients through the same sync\n * protocol that handles client-to-client traffic.\n *\n * The plan originally called this an \"Elysia plugin,\" but Automerge's\n * `WebSocketServerAdapter` requires an `isomorphic-ws` `WebSocketServer`\n * instance — not Elysia's native WebSocket — so the cleanest first cut is a\n * standalone factory that runs its own `ws` server. Elysia integration for\n * authenticated upgrades is a Phase 1.1 follow-up that wraps this factory.\n *\n * @example\n * ```ts\n * import { createPeerRepoServer } from \"@fairfox/polly\";\n *\n * const server = await createPeerRepoServer({\n * port: 3030,\n * storagePath: \"./data/polly-peer\",\n * });\n *\n * // Open a document handle on the server's Repo for cron or compute work.\n * const handle = server.repo.create({ counter: 0 });\n *\n * // On shutdown:\n * await server.close();\n * ```\n */\n\nimport { Repo } from \"@automerge/automerge-repo\";\nimport { WebSocketServerAdapter } from \"@automerge/automerge-repo-network-websocket\";\nimport { NodeFSStorageAdapter } from \"@automerge/automerge-repo-storage-nodefs\";\nimport * as ws from \"ws\";\n\n// `@types/ws` uses CJS `export = WebSocket` with WebSocketServer hanging off\n// the namespace. Under the project's bundler module resolution, the namespace\n// import gives us access to both the constructor and the type.\ntype WebSocketServer = ws.WebSocketServer;\n\nexport interface CreatePeerRepoServerOptions {\n /** Port to listen on. The factory creates its own `WebSocketServer` and\n * binds to this port. */\n port: number;\n /** Filesystem directory for the NodeFS storage adapter. The directory is\n * created on demand. Defaults to `./automerge-repo-data` (Automerge's own\n * default). */\n storagePath?: string;\n /** Hostname interface to bind to. Defaults to all interfaces. */\n host?: string;\n /** Override the `WebSocketServer` instance entirely. When provided, `port`\n * and `host` are ignored and the caller is responsible for the lifecycle.\n * Useful for tests that want to bind to a random port. */\n webSocketServer?: WebSocketServer;\n}\n\nexport interface PeerRepoServer {\n /** A configured Repo participating as the always-on peer. Server-side\n * cron and HTTP handlers can open document handles on this directly. */\n repo: Repo;\n /** The underlying WebSocket server. Exposed for advanced use such as\n * health checks or graceful shutdown coordination. */\n webSocketServer: WebSocketServer;\n /** The Automerge network adapter wrapping the WebSocket server. */\n adapter: WebSocketServerAdapter;\n /** The NodeFS storage adapter writing to {@link CreatePeerRepoServerOptions.storagePath}. */\n storage: NodeFSStorageAdapter;\n /** Tear down the server: disconnect peers, flush storage, close the\n * underlying WebSocket server. Returns a promise that resolves once the\n * tear-down is complete. */\n close: () => Promise<void>;\n}\n\n/**\n * Construct a Polly peer-relay server. Returns a Repo that participates as\n * the always-on peer, the underlying WebSocket server and storage adapter\n * for advanced use, and a close function for orderly shutdown.\n *\n * Applications typically call this once at startup, hold the returned\n * `repo` reference for cron and compute work, and wire the close function\n * into their process shutdown signal handlers.\n */\nexport async function createPeerRepoServer(\n options: CreatePeerRepoServerOptions\n): Promise<PeerRepoServer> {\n // Construct the WebSocket server first and wait until it is actually\n // listening before wiring up the Repo. Using the constructor callback\n // avoids the race where the 'listening' event fires before our listener\n // is attached (the callback form is reliable across Node and Bun).\n const wss = await (options.webSocketServer\n ? Promise.resolve(options.webSocketServer)\n : new Promise<WebSocketServer>((resolve, reject) => {\n const created: WebSocketServer = new ws.WebSocketServer(\n {\n port: options.port,\n ...(options.host !== undefined && { host: options.host }),\n },\n () => resolve(created)\n );\n created.once(\"error\", reject);\n }));\n\n // The cast bridges a @types/ws identity quirk: Automerge's adapter type\n // expects WebSocketServer with options.WebSocket typed via isomorphic-ws's\n // CJS-style namespace, and our direct `ws` import resolves through a\n // different path with the same runtime shape but a structurally distinct\n // TypeScript type. The runtime is identical, the cast names that fact.\n const adapter = new WebSocketServerAdapter(\n wss as unknown as ConstructorParameters<typeof WebSocketServerAdapter>[0]\n );\n const storage = new NodeFSStorageAdapter(options.storagePath);\n\n const repo = new Repo({\n network: [adapter],\n storage,\n });\n\n // Force the storage subsystem to finish initialising before returning. The\n // Repo constructor is synchronous, but its NetworkSubsystem holds back the\n // peer-metadata JOIN until storageSubsystem.id() resolves. If a client\n // connects before that resolution lands, the handshake stalls indefinitely.\n // Awaiting storageId() drains the relevant microtask chain and guarantees\n // the server is ready to accept peers when this factory returns.\n await repo.storageId();\n\n return {\n repo,\n webSocketServer: wss,\n adapter,\n storage,\n close: async () => {\n // Forcibly terminate any still-open client sockets before closing the\n // server, otherwise wss.close() can hang waiting for orderly drain when\n // a peer disappeared without a clean disconnect. We then fire the\n // server close without awaiting its callback — the underlying socket\n // is released immediately by terminate(), and waiting for the close\n // callback can hang under Bun even after every client is gone.\n for (const client of wss.clients) {\n try {\n client.terminate();\n } catch {\n // best effort\n }\n }\n try {\n await repo.shutdown();\n } catch {\n // best effort — automerge-repo's xstate DocHandle machine can\n // throw \"Cycle detected\" during teardown when sync messages are\n // still in flight.\n }\n try {\n wss.close();\n } catch {\n // best effort\n }\n },\n };\n}\n",
7
7
  "// @ts-nocheck - Optional peer dependencies (elysia, @elysiajs/eden)\nimport type { Signal } from \"@preact/signals-core\";\nimport { Elysia } from \"elysia\";\nimport { createLamportClock } from \"../core/clock\";\nimport { serializeFunction } from \"../utils/function-serialization\";\nimport type { PollyConfig, PollyResponseMetadata } from \"./types\";\n\n/**\n * Broadcast message sent to connected clients\n */\ninterface BroadcastMessage {\n type: \"effect\";\n path: string;\n method: string;\n result: unknown;\n clock: { tick: number; contextId: string };\n}\n\n/**\n * Minimal WebSocket interface for broadcasting\n */\ninterface MinimalWebSocket {\n readyState: number;\n send(data: string): void;\n}\n\n/**\n * Route pattern matcher\n * Supports:\n * - Exact match: 'POST /todos'\n * - Param match: 'GET /todos/:id'\n * - Wildcard: '/todos/*'\n */\nfunction matchRoute(pattern: string, method: string, path: string): boolean {\n // Split pattern into method + path or just path\n const hasMethod = pattern.includes(\" \");\n const patternMethod = hasMethod ? pattern.split(\" \")[0] : null;\n const patternPath = hasMethod ? pattern.split(\" \")[1] : pattern;\n\n // Check method\n if (patternMethod && patternMethod !== method) {\n return false;\n }\n\n // Check path\n const patternSegments = patternPath.split(\"/\").filter(Boolean);\n const pathSegments = path.split(\"/\").filter(Boolean);\n\n if (patternSegments.length !== pathSegments.length && !patternPath.includes(\"*\")) {\n return false;\n }\n\n for (let i = 0; i < patternSegments.length; i++) {\n const patternSeg = patternSegments[i];\n const pathSeg = pathSegments[i];\n\n if (patternSeg === \"*\") return true;\n if (patternSeg.startsWith(\":\")) continue; // Param match\n if (patternSeg !== pathSeg) return false;\n }\n\n return true;\n}\n\n/**\n * Find matching config for a route\n */\nfunction findMatchingConfig<T>(\n configs: Record<string, T> | undefined,\n method: string,\n path: string\n): T | undefined {\n if (!configs) return undefined;\n\n for (const [pattern, config] of Object.entries(configs)) {\n if (matchRoute(pattern, method, path)) {\n return config;\n }\n }\n\n return undefined;\n}\n\n/**\n * WebSocket broadcast manager\n */\nclass BroadcastManager {\n private connections = new Map<string, MinimalWebSocket>();\n\n register(clientId: string, ws: MinimalWebSocket) {\n this.connections.set(clientId, ws);\n }\n\n unregister(clientId: string) {\n this.connections.delete(clientId);\n }\n\n broadcast(message: BroadcastMessage, filter?: (clientId: string) => boolean) {\n const payload = JSON.stringify(message);\n\n for (const [clientId, ws] of this.connections.entries()) {\n if (filter && !filter(clientId)) continue;\n if (ws.readyState === 1) {\n // WebSocket.OPEN = 1\n ws.send(payload);\n }\n }\n }\n}\n\n/**\n * Main Polly Elysia plugin\n */\nexport function polly(config: PollyConfig = {}) {\n const isDev = process.env.NODE_ENV !== \"production\";\n const clock = createLamportClock(\"server\");\n const broadcaster = new BroadcastManager();\n const clientStateByConnection = new Map<string, Record<string, Signal<unknown>>>();\n\n const app = new Elysia({ name: \"polly\" })\n // Add state to context\n .decorate(\"pollyState\", {\n client: config.state?.client || {},\n server: config.state?.server || {},\n })\n .decorate(\"pollyClock\", clock)\n .decorate(\"pollyBroadcast\", broadcaster)\n\n // WebSocket endpoint for real-time updates\n .ws(config.websocketPath || \"/polly/ws\", {\n // @ts-expect-error - Elysia WebSocket types from optional peer dependency\n open(ws) {\n const clientId = ws.data.headers?.[\"x-client-id\"] || crypto.randomUUID();\n broadcaster.register(clientId, ws.raw);\n\n // Send initial state sync\n ws.send(\n JSON.stringify({\n type: \"state-sync\",\n state: config.state?.client || {},\n clock: clock.now(),\n })\n );\n },\n // @ts-expect-error - Elysia WebSocket types from optional peer dependency\n close(ws) {\n const clientId = ws.data.headers?.[\"x-client-id\"];\n if (clientId) {\n broadcaster.unregister(clientId);\n clientStateByConnection.delete(clientId);\n }\n },\n // @ts-expect-error - Elysia WebSocket types from optional peer dependency\n message(ws, message) {\n // Handle client state updates\n const data = JSON.parse(message as unknown as string);\n\n if (data.type === \"state-update\") {\n const clientId = ws.data.headers?.[\"x-client-id\"];\n if (clientId) {\n clientStateByConnection.set(clientId, data.state);\n }\n }\n },\n })\n\n // Authorization hook (runs before handler)\n // @ts-expect-error - Elysia context types from optional peer dependency\n .onBeforeHandle(async ({ request, pollyState, body, params }) => {\n const method = request.method;\n const path = new URL(request.url).pathname;\n\n const authHandler = findMatchingConfig(config.authorization, method, path);\n\n if (authHandler) {\n const allowed = await authHandler({\n state: pollyState,\n body,\n params,\n headers: Object.fromEntries(request.headers.entries()),\n });\n\n if (!allowed) {\n return new Response(\"Unauthorized\", { status: 403 });\n }\n }\n })\n\n // Response hook (runs after handler)\n // @ts-expect-error - Elysia context types from optional peer dependency\n .onAfterHandle(\n async ({ request, response, _pollyState, pollyClock, pollyBroadcast, _body, _params }) => {\n const method = request.method;\n const path = new URL(request.url).pathname;\n\n // Find matching effect config\n const effectConfig = findMatchingConfig(config.effects, method, path);\n\n // Tick clock\n pollyClock.tick();\n\n // If broadcast enabled, send to all connected clients\n // This works in both dev and prod for real-time updates\n if (effectConfig?.broadcast) {\n const broadcastMessage = {\n type: \"effect\",\n path,\n method,\n result: response,\n clock: pollyClock.now(),\n };\n\n if (effectConfig.broadcastFilter) {\n pollyBroadcast.broadcast(broadcastMessage, (clientId) => {\n const clientState = clientStateByConnection.get(clientId) || {};\n return effectConfig.broadcastFilter?.(clientState) ?? false;\n });\n } else {\n pollyBroadcast.broadcast(broadcastMessage);\n }\n }\n\n // In production, skip expensive metadata operations\n if (!isDev) {\n return response;\n }\n\n // DEV ONLY: Add Polly metadata to response for debugging/hot-reload\n const offlineConfig = findMatchingConfig(config.offline, method, path);\n const metadata: PollyResponseMetadata = {\n clientEffect: effectConfig\n ? {\n handler: serializeFunction(effectConfig.client),\n broadcast: effectConfig.broadcast || false,\n }\n : undefined,\n offline: offlineConfig,\n clock: pollyClock.now(),\n };\n\n // Attach metadata as header\n return new Response(JSON.stringify(response), {\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-Polly-Metadata\": JSON.stringify(metadata),\n },\n });\n }\n );\n\n return app;\n}\n",
8
8
  "/**\n * Lamport Clock Implementation\n *\n * Provides logical timestamps for distributed systems to establish\n * causal ordering of events across different contexts (client/server).\n *\n * Key properties:\n * - Each event increments the local clock\n * - When receiving a message, clock = max(local, received) + 1\n * - If A happens before B, then timestamp(A) < timestamp(B)\n *\n * References:\n * - Lamport, L. (1978). \"Time, Clocks, and the Ordering of Events in a Distributed System\"\n * - https://lamport.azurewebsites.net/pubs/time-clocks.pdf\n */\n\n/**\n * Lamport clock state\n */\nexport interface LamportClock {\n tick: number;\n contextId: string;\n}\n\n/**\n * Lamport clock with operations\n */\nexport interface LamportClockOps {\n /**\n * Get current clock value\n */\n now(): LamportClock;\n\n /**\n * Increment the clock (before sending a message or performing an action)\n */\n tick(): number;\n\n /**\n * Update clock when receiving a message\n * Sets clock to max(local, received) + 1\n */\n update(receivedClock: LamportClock): void;\n}\n\n/**\n * Create a Lamport clock for a specific context\n *\n * @param contextId - Unique identifier for this context (e.g., \"client\", \"server\", \"worker-1\")\n * @returns Clock operations\n *\n * @example\n * ```typescript\n * const serverClock = createLamportClock(\"server\");\n *\n * // Before sending a message\n * serverClock.tick();\n * const timestamp = serverClock.now();\n * send({ data: \"...\", clock: timestamp });\n *\n * // When receiving a message\n * onReceive((message) => {\n * serverClock.update(message.clock);\n * // Process message with updated clock\n * });\n * ```\n */\nexport function createLamportClock(contextId: string): LamportClockOps {\n let tick = 0;\n\n return {\n now(): LamportClock {\n return { tick, contextId };\n },\n\n tick(): number {\n tick += 1;\n return tick;\n },\n\n update(receivedClock: LamportClock): void {\n tick = Math.max(tick, receivedClock.tick) + 1;\n },\n };\n}\n",
9
9
  "import serialize from \"serialize-javascript\";\n\n/**\n * Check if we're in development mode\n */\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * Serialize a function to send to client\n *\n * DEV ONLY: Used for hot reloading and debugging\n * PROD: No-op - client effects are baked into bundle at build time\n */\n// biome-ignore lint/complexity/noBannedTypes: Generic function serialization requires Function type\nexport function serializeFunction(fn: Function): string {\n if (!isDev) {\n // In production, return empty string - this won't be used\n return \"\";\n }\n\n return serialize(fn, { space: 0 });\n}\n\n/**\n * Deserialize a function received from server\n *\n * DEV ONLY: Eval serialized function source\n * PROD: Should never be called - effects come from bundle\n */\n// biome-ignore lint/complexity/noBannedTypes: Generic function deserialization requires Function type\nexport function deserializeFunction(serialized: string): Function {\n if (!isDev) {\n throw new Error(\n \"[Polly] deserializeFunction should not be called in production. \" +\n \"Client effects should be imported from your bundle.\"\n );\n }\n\n if (!serialized) {\n throw new Error(\"[Polly] Cannot deserialize empty function\");\n }\n\n // biome-ignore lint/security/noGlobalEval: Required for dev-mode function deserialization\n return eval(`(${serialized})`);\n}\n",
10
10
  "// @ts-nocheck - Optional peer dependencies (elysia, @elysiajs/eden)\n/**\n * signalingServer — Phase 2 Elysia plugin that exposes a stateless\n * WebSocket route for SDP/ICE relay between $meshState peers.\n *\n * The mesh transport is a star-of-data-channels: peers establish direct\n * WebRTC connections to each other and exchange document operations\n * peer-to-peer once those channels are open. WebRTC connection setup\n * needs an out-of-band channel for SDP offer/answer and ICE candidate\n * exchange, and that channel is what this plugin provides. The plugin\n * does not own any document state, does not hold any encryption keys,\n * and never inspects the contents of the messages it relays. It is a\n * pure pub-sub by peer id.\n *\n * Once two peers have completed the SDP exchange and opened a direct\n * data channel, the signalling server is no longer on the critical\n * path — the peers talk directly. The signalling server's role is\n * therefore intermittent: peers connect to it only during the brief\n * windows when they are establishing or re-establishing connections.\n *\n * Wire protocol:\n *\n * Client → server (join):\n * { type: \"join\", peerId: \"peer-alice\" }\n *\n * Client → server (signal to another peer):\n * { type: \"signal\", peerId: \"peer-alice\", targetPeerId: \"peer-bob\",\n * payload: { ... } }\n *\n * Server → client (delivered signal):\n * { type: \"signal\", peerId: \"peer-alice\", targetPeerId: \"peer-bob\",\n * payload: { ... } }\n *\n * Server → client (notification of unknown target):\n * { type: \"error\", reason: \"unknown-target\", targetPeerId: \"...\" }\n *\n * The `payload` is opaque to the signalling server — typically it\n * carries an SDP offer, SDP answer, or ICE candidate. Applications can\n * also use the relay for any other peer-to-peer message that needs an\n * intermediary, such as the initial handshake of a pairing flow.\n *\n * @example\n * ```ts\n * import { Elysia } from \"elysia\";\n * import { signalingServer } from \"@fairfox/polly/elysia\";\n *\n * const app = new Elysia()\n * .use(signalingServer({ path: \"/polly/signaling\" }))\n * .listen(8080);\n * ```\n */\n\nimport { Elysia } from \"elysia\";\n\n/** A signalling message. The `type` discriminates between join (peer\n * registration), signal (relayed message), and error (server response). */\nexport type SignalingMessage =\n | {\n type: \"join\";\n /** The peer registering itself with the signalling server. */\n peerId: string;\n }\n | {\n type: \"signal\";\n /** The peer sending the signal. */\n peerId: string;\n /** The peer the signal is being relayed to. */\n targetPeerId: string;\n /** Opaque payload, typically SDP or ICE. */\n payload: unknown;\n }\n | {\n type: \"error\";\n reason: \"unknown-target\" | \"not-joined\" | \"malformed\";\n targetPeerId?: string;\n };\n\nexport interface SignalingServerOptions {\n /** WebSocket route path. Defaults to \"/polly/signaling\". */\n path?: string;\n}\n\n/**\n * Construct the signalling-server Elysia plugin. The plugin keeps a\n * per-instance map of peer id → WebSocket connection so that incoming\n * \"signal\" messages can be routed to the right target socket. The map\n * is local to the plugin instance, not shared across processes; for\n * multi-instance deployments behind a load balancer, applications need\n * sticky connection routing or a shared backplane (Redis pub-sub or\n * similar). That is a follow-up.\n */\nexport function signalingServer(options: SignalingServerOptions = {}) {\n const path = options.path ?? \"/polly/signaling\";\n // Per-peer-id map of joined sockets. The inverse mapping is stored\n // directly on ws.data (a mutable property bag that Elysia preserves\n // across message callbacks for a given connection); the webrtc-p2p-chat\n // example in examples/ confirms this pattern is stable under Bun.\n const peerSockets = new Map<string, { send: (msg: unknown) => void }>();\n\n // Intentionally unnamed — Elysia deduplicates plugins by name, and each\n // signalingServer() call needs its own closure-captured peer map.\n const parseMessage = (raw: unknown): SignalingMessage | undefined => {\n try {\n return typeof raw === \"string\" ? JSON.parse(raw) : (raw as unknown as SignalingMessage);\n } catch {\n return undefined;\n }\n };\n\n const handleJoin = (ws: unknown, peerId: string): void => {\n peerSockets.set(peerId, ws as unknown as { send: (m: unknown) => void });\n const wsWithData = ws as unknown as { data: Record<string, unknown> };\n wsWithData.data.peerId = peerId;\n };\n\n const sendUnknownTarget = (ws: unknown, targetPeerId: string): void => {\n (ws as unknown as { send: (m: unknown) => void }).send({\n type: \"error\",\n reason: \"unknown-target\",\n targetPeerId,\n } as unknown as SignalingMessage);\n };\n\n /** Look up a target socket and confirm it is still open. */\n const findOpenTarget = (targetPeerId: string): { send: (msg: unknown) => void } | undefined => {\n const target = peerSockets.get(targetPeerId);\n if (!target) return undefined;\n const readyState = (target as unknown as { readyState?: number }).readyState;\n const OPEN = 1;\n if (readyState !== undefined && readyState !== OPEN) {\n peerSockets.delete(targetPeerId);\n return undefined;\n }\n return target;\n };\n\n const handleSignal = (ws: unknown, msg: Extract<SignalingMessage, { type: \"signal\" }>): void => {\n const wsWithData = ws as unknown as {\n data: Record<string, unknown>;\n send: (m: unknown) => void;\n };\n const senderId = wsWithData.data.peerId as unknown as string | undefined;\n if (!senderId) {\n wsWithData.send({ type: \"error\", reason: \"not-joined\" } as unknown as SignalingMessage);\n return;\n }\n const target = findOpenTarget(msg.targetPeerId);\n if (!target) {\n sendUnknownTarget(ws, msg.targetPeerId);\n return;\n }\n const relayed: SignalingMessage = {\n type: \"signal\",\n peerId: senderId,\n targetPeerId: msg.targetPeerId,\n payload: msg.payload,\n };\n try {\n target.send(relayed);\n } catch {\n peerSockets.delete(msg.targetPeerId);\n sendUnknownTarget(ws, msg.targetPeerId);\n }\n };\n\n return new Elysia().ws(path, {\n message(ws, raw) {\n const msg = parseMessage(raw);\n if (!msg) {\n ws.send({ type: \"error\", reason: \"malformed\" } as unknown as SignalingMessage);\n return;\n }\n if (msg.type === \"join\") {\n handleJoin(ws, msg.peerId);\n return;\n }\n if (msg.type === \"signal\") {\n handleSignal(ws, msg);\n return;\n }\n ws.send({ type: \"error\", reason: \"malformed\" } as unknown as SignalingMessage);\n },\n\n close(ws) {\n const peerId = (ws.data as unknown as Record<string, unknown>).peerId as unknown as\n | string\n | undefined;\n if (peerId) {\n // Only delete the entry if it still points at *this* socket, so a\n // stale close after a reconnect does not evict the new socket.\n if (peerSockets.get(peerId) === (ws as unknown as { send: (m: unknown) => void })) {\n peerSockets.delete(peerId);\n }\n }\n },\n });\n}\n"
11
11
  ],
12
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA;;;ACMA;AACA;AACA;AACA;AAiDA,eAAsB,oBAAoB,CACxC,SACyB;AAAA,EAKzB,MAAM,MAAM,OAAO,QAAQ,kBACvB,QAAQ,QAAQ,QAAQ,eAAe,IACvC,IAAI,QAAyB,CAAC,SAAS,WAAW;AAAA,IAChD,MAAM,UAA2B,IAAO,mBACtC;AAAA,MACE,MAAM,QAAQ;AAAA,SACV,QAAQ,SAAS,aAAa,EAAE,MAAM,QAAQ,KAAK;AAAA,IACzD,GACA,MAAM,QAAQ,OAAO,CACvB;AAAA,IACA,QAAQ,KAAK,SAAS,MAAM;AAAA,GAC7B;AAAA,EAOL,MAAM,UAAU,IAAI,uBAClB,GACF;AAAA,EACA,MAAM,UAAU,IAAI,qBAAqB,QAAQ,WAAW;AAAA,EAE5D,MAAM,OAAO,IAAI,KAAK;AAAA,IACpB,SAAS,CAAC,OAAO;AAAA,IACjB;AAAA,EACF,CAAC;AAAA,EAQD,MAAM,KAAK,UAAU;AAAA,EAErB,OAAO;AAAA,IACL;AAAA,IACA,iBAAiB;AAAA,IACjB;AAAA,IACA;AAAA,IACA,OAAO,YAAY;AAAA,MAOjB,WAAW,UAAU,IAAI,SAAS;AAAA,QAChC,IAAI;AAAA,UACF,OAAO,UAAU;AAAA,UACjB,MAAM;AAAA,MAGV;AAAA,MACK,KAAK,SAAS;AAAA,MACnB,IAAI;AAAA,QACF,IAAI,MAAM;AAAA,QACV,MAAM;AAAA;AAAA,E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KAAI;AAAA,MACR,MAAM,SAAU,IAAG,KAA4C;AAAA,MAG/D,IAAI,QAAQ;AAAA,QAGV,IAAI,YAAY,IAAI,MAAM,MAAO,KAAkD;AAAA,UACjF,YAAY,OAAO,MAAM;AAAA,QAC3B;AAAA,MACF;AAAA;AAAA,EAEJ,CAAC;AAAA;",
13
+ "debugId": "93C98D54564BCF4764756E2164756E21",
14
14
  "names": []
15
15
  }
package/dist/src/peer.js CHANGED
@@ -801,7 +801,9 @@ async function createPeerRepoServer(options) {
801
801
  client.terminate();
802
802
  } catch {}
803
803
  }
804
- repo.shutdown();
804
+ try {
805
+ await repo.shutdown();
806
+ } catch {}
805
807
  try {
806
808
  wss.close();
807
809
  } catch {}
@@ -925,4 +927,4 @@ export {
925
927
  $crdtCounter
926
928
  };
927
929
 
928
- //# debugId=81EED7520484C6A364756E2164756E21
930
+ //# debugId=5E1D406403AE952E64756E2164756E21
@@ -11,10 +11,10 @@
11
11
  "/**\n * mesh-network-adapter — Phase 2 wrapping NetworkAdapter that adds Polly's\n * mesh-transport semantics on top of any underlying Automerge NetworkAdapter.\n *\n * The mesh transport's job is to make every message between peers signed\n * and encrypted before it reaches the wire. Rather than reimplementing the\n * Automerge sync protocol, this adapter takes a base adapter (in production\n * a real WebRTC or WebSocket adapter; in tests an in-memory loopback) and\n * applies the crypto envelope to every message that flows through.\n *\n * Outgoing path (Repo → wire):\n * 1. The Repo's NetworkSubsystem calls send(message) on this adapter.\n * 2. We serialise the message to bytes, encrypt them under the local\n * keyring's document key, sign the resulting blob with the local\n * identity's secret key, and pack the pair into a MeshFrame.\n * 3. We hand the MeshFrame off to the base adapter, which puts it on\n * whatever wire it owns.\n *\n * Incoming path (wire → Repo):\n * 1. The base adapter emits a 'message' event with bytes from the wire.\n * 2. We unpack the MeshFrame, look up the sender's public key in the\n * keyring, verify the signature, look up the document key, decrypt\n * the payload, and deserialise it back to the original message.\n * 3. We re-emit the 'message' event upward to the Repo's NetworkSubsystem\n * with the decrypted message.\n *\n * The keyring is an injected dependency. In production it's backed by\n * persistent storage and populated through the pairing flow. For tests it\n * is just a Map of publicly-known fixtures that both sides share.\n *\n * Caveat for the Phase 2 first cut: Automerge sync messages don't have a\n * stable \"what document does this belong to\" field at the wire level (the\n * documentId is part of the message contents). The mesh adapter therefore\n * uses a single per-Repo encryption key for now rather than per-document\n * keys, and stores the key once in the keyring under the well-known id\n * \"polly-mesh-default\". The plan describes per-document keys as the right\n * end state; that requires either parsing the message to extract the\n * documentId before encrypting (peeking inside the binary protocol) or\n * threading the document context through the network subsystem (which\n * needs upstream support). A follow-up will address this.\n */\n\nimport {\n type Message,\n NetworkAdapter,\n type PeerId,\n type PeerMetadata,\n} from \"@automerge/automerge-repo\";\nimport {\n decodeEncryptedEnvelope,\n encodeEncryptedEnvelope,\n openEnvelope as openEncryptedEnvelope,\n sealEnvelope as sealEncryptedEnvelope,\n} from \"./encryption\";\nimport {\n decodeSignedEnvelope,\n encodeSignedEnvelope,\n openEnvelope as openSignedEnvelope,\n type SigningKeyPair,\n signEnvelope,\n} from \"./signing\";\n\n/** The well-known document id used for the Phase 2 first-cut single-key\n * encryption mode. See the file-level comment for the per-document key\n * follow-up. */\nexport const DEFAULT_MESH_KEY_ID = \"polly-mesh-default\";\n\n/**\n * A mesh keyring holds the local peer's signing identity, the public keys\n * of every peer the local node will accept messages from, the symmetric\n * encryption keys for documents the local node has access to, and the set\n * of peers whose keys have been revoked.\n */\nexport interface MeshKeyring {\n /** The local peer's signing keypair. The secret never leaves this\n * keyring; the public key is gossiped through the access set. */\n identity: SigningKeyPair;\n /** Map from peer id (string) to that peer's signing public key. The\n * mesh adapter rejects messages from peers not present in this map. */\n knownPeers: Map<string, Uint8Array>;\n /** Map from document key id (typically the documentId, or the well-known\n * default for the single-key first cut) to the symmetric encryption key. */\n documentKeys: Map<string, Uint8Array>;\n /** Set of peer ids whose keys have been revoked. The mesh adapter drops\n * incoming messages from any peer in this set, even if the peer is still\n * present in {@link knownPeers}. Revocation is applied via the revocation\n * module; the set is kept separate from knownPeers so that an application\n * can audit who was once authorised without losing the revocation record. */\n revokedPeers: Set<string>;\n /** Optional set of peer ids authorised to issue revocations. When present\n * and non-empty, `decodeRevocation` accepts a signed record only if the\n * issuer is in this set. When undefined or empty, any signed revocation\n * from a known peer is accepted (the Phase 2 first-cut default). This\n * field layers a \"who can revoke whom\" check on top of the signature\n * layer without breaking existing callers. */\n revocationAuthority?: Set<string>;\n}\n\n/**\n * Constructor options for {@link MeshNetworkAdapter}.\n */\nexport interface MeshNetworkAdapterOptions {\n /** The underlying NetworkAdapter that puts crypto-wrapped bytes on the\n * wire. In production this is a WebRTC or WebSocket adapter; in tests\n * it's an in-memory loopback. */\n base: NetworkAdapter;\n /** The local node's keyring. The adapter signs every outgoing message\n * with `identity.secretKey` and verifies every incoming message against\n * the public keys in `knownPeers`. */\n keyring: MeshKeyring;\n /** When false, the adapter signs but does not encrypt. Outgoing messages\n * carry a signature envelope but the payload is plaintext; incoming\n * messages are verified against the sender's public key without a\n * decryption step. This mode is used by $peerState's `sign: true`\n * option, where the server must still be able to parse Automerge sync\n * messages. Defaults to true (encrypt + sign, the full $meshState\n * posture). */\n encryptionEnabled?: boolean;\n}\n\n/**\n * NetworkAdapter that wraps another adapter with Polly's mesh-transport\n * crypto envelope. Every outgoing message is encrypted then signed; every\n * incoming message is verified then decrypted before being forwarded to\n * the Repo's network subsystem.\n *\n * The adapter delegates lifecycle (connect, disconnect, isReady, peer\n * discovery) to the base adapter unchanged. Only the message body is\n * intercepted.\n */\nexport class MeshNetworkAdapter extends NetworkAdapter {\n readonly base: NetworkAdapter;\n readonly keyring: MeshKeyring;\n readonly encryptionEnabled: boolean;\n\n constructor(options: MeshNetworkAdapterOptions) {\n super();\n this.base = options.base;\n this.keyring = options.keyring;\n this.encryptionEnabled = options.encryptionEnabled ?? true;\n\n // Forward lifecycle and peer events from the base adapter.\n this.base.on(\"close\", () => this.emit(\"close\"));\n this.base.on(\"peer-candidate\", (payload) => this.emit(\"peer-candidate\", payload));\n this.base.on(\"peer-disconnected\", (payload) => this.emit(\"peer-disconnected\", payload));\n\n // Intercept incoming messages: the base adapter will surface them as\n // 'message' events with crypto-wrapped payloads. We unwrap and re-emit.\n this.base.on(\"message\", (rawMessage) => {\n const unwrapped = this.tryUnwrap(rawMessage);\n if (unwrapped) {\n this.emit(\"message\", unwrapped);\n }\n // Silently drop messages that fail verification or decryption. A\n // production adapter would surface this through a diagnostic channel\n // so the application could prompt the user; the Phase 2 first cut\n // logs through the standard \"drop unknown\" semantics of the network\n // subsystem.\n });\n }\n\n isReady(): boolean {\n return this.base.isReady();\n }\n\n whenReady(): Promise<void> {\n return this.base.whenReady();\n }\n\n connect(peerId: PeerId, peerMetadata?: PeerMetadata): void {\n this.peerId = peerId;\n if (peerMetadata !== undefined) {\n this.peerMetadata = peerMetadata;\n }\n this.base.connect(peerId, peerMetadata);\n }\n\n disconnect(): void {\n this.base.disconnect();\n }\n\n send(message: Message): void {\n const wrapped = this.wrap(message);\n this.base.send(wrapped);\n }\n\n /**\n * Wrap an outgoing Automerge message in an encrypt-then-sign envelope.\n * The wrapped payload is returned as a Message with the original sender\n * and target ids and the crypto blob in the `data` field.\n */\n private wrap(message: Message): Message {\n const serialised = serialiseMessage(message);\n\n let payloadToSign: Uint8Array;\n if (this.encryptionEnabled) {\n const docKey = this.keyring.documentKeys.get(DEFAULT_MESH_KEY_ID);\n if (!docKey) {\n throw new Error(\n `MeshNetworkAdapter: missing document encryption key under id \"${DEFAULT_MESH_KEY_ID}\". Provision the key in the keyring before sending.`\n );\n }\n const encrypted = sealEncryptedEnvelope(serialised, DEFAULT_MESH_KEY_ID, docKey);\n payloadToSign = encodeEncryptedEnvelope(encrypted);\n } else {\n payloadToSign = serialised;\n }\n\n const signed = signEnvelope(payloadToSign, message.senderId, this.keyring.identity.secretKey);\n const signedBytes = encodeSignedEnvelope(signed);\n\n return {\n type: message.type,\n senderId: message.senderId,\n targetId: message.targetId,\n data: signedBytes,\n } as unknown as Message;\n }\n\n /**\n * Try to unwrap an incoming crypto-wrapped message. Returns the original\n * Message on success, undefined on verification or decryption failure.\n */\n private tryUnwrap(message: Message): Message | undefined {\n if (!message.data) return undefined;\n\n let signed: ReturnType<typeof decodeSignedEnvelope>;\n try {\n signed = decodeSignedEnvelope(message.data);\n } catch {\n return undefined;\n }\n\n // Drop messages from peers whose keys have been revoked, even if the\n // public key is still present in knownPeers. The revocation set is the\n // authoritative \"this peer is no longer trusted\" marker.\n if (this.keyring.revokedPeers.has(signed.senderId)) {\n return undefined;\n }\n\n const senderKey = this.keyring.knownPeers.get(signed.senderId);\n if (!senderKey) {\n return undefined;\n }\n\n let verifiedPayload: Uint8Array;\n try {\n verifiedPayload = openSignedEnvelope(signed, senderKey);\n } catch {\n return undefined;\n }\n\n if (!this.encryptionEnabled) {\n // Sign-only mode: the verified payload IS the serialised message.\n return deserialiseMessage(verifiedPayload);\n }\n\n // Full encrypt+sign mode: unwrap the encryption envelope.\n let encrypted: ReturnType<typeof decodeEncryptedEnvelope>;\n try {\n encrypted = decodeEncryptedEnvelope(verifiedPayload);\n } catch {\n return undefined;\n }\n\n const docKey = this.keyring.documentKeys.get(encrypted.documentId);\n if (!docKey) {\n return undefined;\n }\n\n let plaintext: Uint8Array;\n try {\n plaintext = openEncryptedEnvelope(encrypted, docKey);\n } catch {\n return undefined;\n }\n\n return deserialiseMessage(plaintext);\n }\n}\n\n// ─── message serialisation ─────────────────────────────────────────────────\n\n/**\n * Serialise an Automerge sync message to a binary blob suitable for\n * encryption. The format is a length-prefixed JSON header (carrying the\n * non-binary fields) followed by the raw `data` bytes (which Automerge's\n * sync messages carry as Uint8Array). This avoids round-tripping the\n * binary payload through JSON, which would balloon its size.\n */\nfunction serialiseMessage(message: Message): Uint8Array {\n const headerObj: Record<string, unknown> = {\n type: message.type,\n senderId: message.senderId,\n targetId: message.targetId,\n };\n if (\"documentId\" in message && message.documentId !== undefined) {\n headerObj[\"documentId\"] = message.documentId;\n }\n if (\"count\" in message && message.count !== undefined) {\n headerObj[\"count\"] = message.count;\n }\n if (\"sessionId\" in message && message.sessionId !== undefined) {\n headerObj[\"sessionId\"] = message.sessionId;\n }\n const headerBytes = new TextEncoder().encode(JSON.stringify(headerObj));\n const dataBytes: Uint8Array =\n \"data\" in message && message.data instanceof Uint8Array ? message.data : new Uint8Array(0);\n\n const out = new Uint8Array(4 + headerBytes.length + dataBytes.length);\n const view = new DataView(out.buffer);\n view.setUint32(0, headerBytes.length, false);\n out.set(headerBytes, 4);\n out.set(dataBytes, 4 + headerBytes.length);\n return out;\n}\n\n/**\n * Inverse of {@link serialiseMessage}.\n */\nfunction deserialiseMessage(bytes: Uint8Array): Message {\n if (bytes.length < 4) {\n throw new Error(\"MeshNetworkAdapter: message too short to deserialise.\");\n }\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n const headerLen = view.getUint32(0, false);\n if (bytes.length < 4 + headerLen) {\n throw new Error(\"MeshNetworkAdapter: message header truncated.\");\n }\n const header = JSON.parse(new TextDecoder().decode(bytes.subarray(4, 4 + headerLen)));\n const data = bytes.slice(4 + headerLen);\n return { ...header, data } as unknown as Message;\n}\n",
12
12
  "/**\n * encryption — symmetric authenticated encryption for Polly's $meshState\n * primitive (Phase 2). Wraps tweetnacl's secretbox (XSalsa20-Poly1305) with\n * a small Polly-flavoured API so the rest of the codebase never imports\n * tweetnacl directly.\n *\n * Every $meshState document has a per-document symmetric key that is\n * provisioned to authorised peers at pairing time and never held by any\n * server. Outgoing operations are encrypted under this key before they\n * touch the network adapter; incoming operations are decrypted on receipt.\n * The signing layer in {@link signing.ts} provides authenticity (proof of\n * who sent the message); this layer provides confidentiality (the bytes\n * are unreadable to anything that does not hold the document key).\n *\n * tweetnacl's secretbox uses a 32-byte symmetric key and a 24-byte nonce.\n * The output of `nacl.secretbox` is the ciphertext concatenated with a\n * 16-byte Poly1305 authentication tag. We package the nonce + ciphertext\n * into a single binary blob using a small length-prefixed envelope so the\n * receiver can recover the nonce without out-of-band coordination.\n *\n * - {@link generateDocumentKey} returns a fresh 32-byte symmetric key.\n *\n * - {@link encrypt} produces a sealed blob from a payload and a key.\n *\n * - {@link decrypt} recovers the payload from a sealed blob and a key.\n * Returns undefined if the blob is malformed or the authentication\n * tag does not match (i.e. wrong key or tampered ciphertext) — the\n * undefined signal lets call sites distinguish \"wrong key\" from\n * \"structurally invalid\" without throwing.\n *\n * - {@link sealEnvelope} and {@link openEnvelope} are convenience helpers\n * that wrap encrypt/decrypt in a structured EncryptedEnvelope shape so\n * the mesh transport layer can handle the binary plumbing uniformly.\n */\n\nimport nacl from \"tweetnacl\";\n\n/** Length in bytes of a secretbox symmetric key. */\nexport const KEY_BYTES = 32;\n/** Length in bytes of a secretbox nonce. */\nexport const NONCE_BYTES = 24;\n/** Length in bytes of the Poly1305 authentication tag. */\nexport const TAG_BYTES = 16;\n\n/**\n * A sealed blob suitable for storage or network transmission. The wire\n * layout is the concatenation of the nonce and the ciphertext+tag from\n * tweetnacl. Callers should not depend on the exact bytes — round-trip\n * through {@link encrypt} / {@link decrypt} or the envelope helpers.\n */\nexport type SealedBytes = Uint8Array;\n\n/** Errors thrown by the encryption subsystem. */\nexport class EncryptionError extends Error {\n readonly code: \"invalid-key-length\" | \"decrypt-failed\" | \"envelope-malformed\";\n constructor(message: string, code: EncryptionError[\"code\"]) {\n super(message);\n this.name = \"EncryptionError\";\n this.code = code;\n }\n}\n\n/**\n * Generate a fresh 32-byte symmetric document key. Calls into tweetnacl's\n * CSPRNG.\n */\nexport function generateDocumentKey(): Uint8Array {\n return nacl.randomBytes(KEY_BYTES);\n}\n\n/**\n * Encrypt a payload under a symmetric key. The returned blob includes a\n * fresh nonce so the receiver does not need any out-of-band coordination\n * to decrypt.\n */\nexport function encrypt(payload: Uint8Array, key: Uint8Array): SealedBytes {\n if (key.length !== KEY_BYTES) {\n throw new EncryptionError(\n `secretbox key must be ${KEY_BYTES} bytes, got ${key.length}.`,\n \"invalid-key-length\"\n );\n }\n const nonce = nacl.randomBytes(NONCE_BYTES);\n const ciphertext = nacl.secretbox(payload, nonce, key);\n const out = new Uint8Array(NONCE_BYTES + ciphertext.length);\n out.set(nonce, 0);\n out.set(ciphertext, NONCE_BYTES);\n return out;\n}\n\n/**\n * Decrypt a sealed blob under a symmetric key. Returns the original\n * payload on success. Returns undefined if the blob is too short to\n * contain a nonce and tag, or if the authentication tag does not match\n * (which indicates either a wrong key or a tampered ciphertext).\n *\n * The undefined return is deliberate: call sites typically want to fall\n * back to a different key or surface a \"could not decrypt\" message rather\n * than catching an exception. Use {@link decryptOrThrow} when an exception\n * is preferred.\n */\nexport function decrypt(sealed: SealedBytes, key: Uint8Array): Uint8Array | undefined {\n if (key.length !== KEY_BYTES) {\n throw new EncryptionError(\n `secretbox key must be ${KEY_BYTES} bytes, got ${key.length}.`,\n \"invalid-key-length\"\n );\n }\n if (sealed.length < NONCE_BYTES + TAG_BYTES) {\n return undefined;\n }\n const nonce = sealed.subarray(0, NONCE_BYTES);\n const ciphertext = sealed.subarray(NONCE_BYTES);\n const opened = nacl.secretbox.open(ciphertext, nonce, key);\n return opened ?? undefined;\n}\n\n/**\n * Decrypt a sealed blob, throwing {@link EncryptionError} on failure\n * instead of returning undefined.\n */\nexport function decryptOrThrow(sealed: SealedBytes, key: Uint8Array): Uint8Array {\n const opened = decrypt(sealed, key);\n if (!opened) {\n throw new EncryptionError(\n `Failed to decrypt sealed blob: wrong key, malformed input, or tampered ciphertext.`,\n \"decrypt-failed\"\n );\n }\n return opened;\n}\n\n/**\n * A high-level structured envelope combining encryption with a small\n * amount of metadata the receiver needs to find the right key. The mesh\n * network adapter uses this shape on the wire.\n */\nexport interface EncryptedEnvelope {\n /** Stable identifier for the document this payload belongs to. The\n * receiver looks this up in its local key store to find the right key. */\n documentId: string;\n /** Sealed blob containing the encrypted payload plus its nonce. */\n sealed: SealedBytes;\n}\n\n/**\n * Encrypt a payload and pack it into an {@link EncryptedEnvelope} along\n * with the document id.\n */\nexport function sealEnvelope(\n payload: Uint8Array,\n documentId: string,\n key: Uint8Array\n): EncryptedEnvelope {\n return {\n documentId,\n sealed: encrypt(payload, key),\n };\n}\n\n/**\n * Decrypt an {@link EncryptedEnvelope} using the given key. Throws on\n * failure for symmetry with {@link sealEnvelope}.\n */\nexport function openEnvelope(envelope: EncryptedEnvelope, key: Uint8Array): Uint8Array {\n return decryptOrThrow(envelope.sealed, key);\n}\n\n/**\n * Serialise an {@link EncryptedEnvelope} to a single binary blob.\n *\n * Wire format:\n *\n * [4 bytes BE: documentId byte length]\n * [N bytes: documentId UTF-8]\n * [remaining: sealed blob (nonce + ciphertext + tag)]\n */\nexport function encodeEncryptedEnvelope(envelope: EncryptedEnvelope): Uint8Array {\n const idBytes = new TextEncoder().encode(envelope.documentId);\n const out = new Uint8Array(4 + idBytes.length + envelope.sealed.length);\n const view = new DataView(out.buffer);\n view.setUint32(0, idBytes.length, false);\n out.set(idBytes, 4);\n out.set(envelope.sealed, 4 + idBytes.length);\n return out;\n}\n\n/**\n * Deserialise a binary envelope produced by {@link encodeEncryptedEnvelope}.\n * Throws on malformed input.\n */\nexport function decodeEncryptedEnvelope(bytes: Uint8Array): EncryptedEnvelope {\n if (bytes.length < 4) {\n throw new EncryptionError(\n `Encrypted envelope too short: ${bytes.length} bytes.`,\n \"envelope-malformed\"\n );\n }\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n const idLen = view.getUint32(0, false);\n if (bytes.length < 4 + idLen) {\n throw new EncryptionError(\n `Encrypted envelope truncated: declared id length ${idLen}, total ${bytes.length}.`,\n \"envelope-malformed\"\n );\n }\n const documentId = new TextDecoder().decode(bytes.subarray(4, 4 + idLen));\n const sealed = bytes.slice(4 + idLen);\n return { documentId, sealed };\n}\n",
13
13
  "/**\n * signing — Ed25519 signing and verification for Polly's $meshState\n * primitive (Phase 2). Wraps tweetnacl with a small Polly-flavoured API\n * so the rest of the codebase never imports tweetnacl directly.\n *\n * Every operation that flows through a $meshState transport is signed by\n * the originating peer's private key before transmission and verified by\n * every receiving peer against a known public-key set before being applied.\n * This is the Byzantine-tolerance mechanism: a peer whose private key is\n * compromised can be revoked through a further signed operation, after\n * which honest peers reject anything signed by the revoked key.\n *\n * tweetnacl uses the Ed25519 curve. Public keys and signatures are 32 and\n * 64 bytes respectively, which keeps the per-op overhead small enough that\n * signing every Automerge sync message is feasible even on mobile.\n *\n * The shape of the wrapper:\n *\n * - {@link generateSigningKeyPair} produces a new Ed25519 keypair. The\n * private key never leaves the device that generated it; the public\n * key is gossiped through the access set.\n *\n * - {@link sign} produces a 64-byte detached signature over a payload.\n *\n * - {@link verify} checks a payload against a signature and a public\n * key. Returns boolean rather than throwing so call sites can handle\n * verification failure as a normal control-flow case.\n *\n * - {@link signEnvelope} and {@link openEnvelope} package payload + sender\n * id + signature into a single binary envelope, which is what the mesh\n * network adapter actually puts on the wire.\n */\n\nimport nacl from \"tweetnacl\";\n\n/** Length in bytes of an Ed25519 public key. */\nexport const PUBLIC_KEY_BYTES = 32;\n/** Length in bytes of an Ed25519 secret (private) key. */\nexport const SECRET_KEY_BYTES = 64;\n/** Length in bytes of an Ed25519 detached signature. */\nexport const SIGNATURE_BYTES = 64;\n\n/**\n * An Ed25519 keypair. The {@link publicKey} is safe to share with peers;\n * the {@link secretKey} must never leave the device.\n */\nexport interface SigningKeyPair {\n publicKey: Uint8Array;\n secretKey: Uint8Array;\n}\n\n/**\n * A signed envelope. The wire format is the concatenation of the sender id\n * length, the sender id bytes, the signature, and the payload. Callers\n * shouldn't rely on the exact layout — use {@link signEnvelope} and\n * {@link openEnvelope} to round-trip.\n */\nexport interface SignedEnvelope {\n /** Stable sender peer identifier (UTF-8 string). The receiving side uses\n * this to look up the sender's public key in the document's access set. */\n senderId: string;\n /** The original payload bytes, untouched. */\n payload: Uint8Array;\n /** 64-byte Ed25519 signature over the payload. */\n signature: Uint8Array;\n}\n\n/** Errors thrown by the signing subsystem. */\nexport class SigningError extends Error {\n readonly code:\n | \"invalid-secret-key\"\n | \"invalid-public-key\"\n | \"invalid-signature-length\"\n | \"envelope-malformed\";\n\n constructor(message: string, code: SigningError[\"code\"]) {\n super(message);\n this.name = \"SigningError\";\n this.code = code;\n }\n}\n\n/**\n * Generate a fresh Ed25519 keypair. Calls into tweetnacl's CSPRNG.\n */\nexport function generateSigningKeyPair(): SigningKeyPair {\n const pair = nacl.sign.keyPair();\n return {\n publicKey: pair.publicKey,\n secretKey: pair.secretKey,\n };\n}\n\n/**\n * Reconstruct a keypair from an existing 64-byte secret key. Useful for\n * loading keys from persistent storage. Throws if the key is the wrong size.\n */\nexport function signingKeyPairFromSecret(secretKey: Uint8Array): SigningKeyPair {\n if (secretKey.length !== SECRET_KEY_BYTES) {\n throw new SigningError(\n `Ed25519 secret key must be ${SECRET_KEY_BYTES} bytes, got ${secretKey.length}.`,\n \"invalid-secret-key\"\n );\n }\n const pair = nacl.sign.keyPair.fromSecretKey(secretKey);\n return {\n publicKey: pair.publicKey,\n secretKey: pair.secretKey,\n };\n}\n\n/**\n * Produce a 64-byte detached signature over the given payload using the\n * supplied secret key.\n */\nexport function sign(payload: Uint8Array, secretKey: Uint8Array): Uint8Array {\n if (secretKey.length !== SECRET_KEY_BYTES) {\n throw new SigningError(\n `Ed25519 secret key must be ${SECRET_KEY_BYTES} bytes, got ${secretKey.length}.`,\n \"invalid-secret-key\"\n );\n }\n return nacl.sign.detached(payload, secretKey);\n}\n\n/**\n * Verify a detached signature against a payload and a public key. Returns\n * true if the signature is valid, false otherwise. Wrong-length keys or\n * signatures throw {@link SigningError} so callers can distinguish a bad\n * signature from a misshapen input.\n */\nexport function verify(payload: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): boolean {\n if (publicKey.length !== PUBLIC_KEY_BYTES) {\n throw new SigningError(\n `Ed25519 public key must be ${PUBLIC_KEY_BYTES} bytes, got ${publicKey.length}.`,\n \"invalid-public-key\"\n );\n }\n if (signature.length !== SIGNATURE_BYTES) {\n throw new SigningError(\n `Ed25519 signature must be ${SIGNATURE_BYTES} bytes, got ${signature.length}.`,\n \"invalid-signature-length\"\n );\n }\n return nacl.sign.detached.verify(payload, signature, publicKey);\n}\n\n/**\n * Sign a payload and pack it into a {@link SignedEnvelope} along with the\n * sender id. The mesh network adapter calls this on every outgoing message\n * before handing it to the transport.\n */\nexport function signEnvelope(\n payload: Uint8Array,\n senderId: string,\n secretKey: Uint8Array\n): SignedEnvelope {\n const signature = sign(payload, secretKey);\n return { senderId, payload, signature };\n}\n\n/**\n * Verify a {@link SignedEnvelope} against the sender's known public key.\n * Returns the inner payload on success, throws on failure. The mesh\n * network adapter calls this on every incoming message before forwarding\n * the payload to the underlying Automerge sync subsystem.\n */\nexport function openEnvelope(envelope: SignedEnvelope, publicKey: Uint8Array): Uint8Array {\n const ok = verify(envelope.payload, envelope.signature, publicKey);\n if (!ok) {\n throw new SigningError(\n `Signature verification failed for envelope from ${envelope.senderId}.`,\n \"envelope-malformed\"\n );\n }\n return envelope.payload;\n}\n\n/**\n * Serialise a {@link SignedEnvelope} to a single binary blob suitable for\n * transmission over a network adapter. Wire format:\n *\n * [4 bytes BE: senderId byte length]\n * [N bytes: senderId UTF-8]\n * [64 bytes: signature]\n * [remaining: payload]\n *\n * Callers should not depend on the exact bytes — they should round-trip\n * through {@link encodeSignedEnvelope} / {@link decodeSignedEnvelope}.\n */\nexport function encodeSignedEnvelope(envelope: SignedEnvelope): Uint8Array {\n const senderBytes = new TextEncoder().encode(envelope.senderId);\n const total = 4 + senderBytes.length + SIGNATURE_BYTES + envelope.payload.length;\n const out = new Uint8Array(total);\n const view = new DataView(out.buffer);\n view.setUint32(0, senderBytes.length, false);\n out.set(senderBytes, 4);\n out.set(envelope.signature, 4 + senderBytes.length);\n out.set(envelope.payload, 4 + senderBytes.length + SIGNATURE_BYTES);\n return out;\n}\n\n/**\n * Deserialise a binary envelope produced by {@link encodeSignedEnvelope}.\n * Throws on malformed input.\n */\nexport function decodeSignedEnvelope(bytes: Uint8Array): SignedEnvelope {\n if (bytes.length < 4 + SIGNATURE_BYTES) {\n throw new SigningError(\n `Envelope too short: ${bytes.length} bytes, need at least ${4 + SIGNATURE_BYTES}.`,\n \"envelope-malformed\"\n );\n }\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n const senderLen = view.getUint32(0, false);\n if (bytes.length < 4 + senderLen + SIGNATURE_BYTES) {\n throw new SigningError(\n `Envelope truncated: declared sender length ${senderLen}, total ${bytes.length}.`,\n \"envelope-malformed\"\n );\n }\n const senderId = new TextDecoder().decode(bytes.subarray(4, 4 + senderLen));\n const signature = bytes.slice(4 + senderLen, 4 + senderLen + SIGNATURE_BYTES);\n const payload = bytes.slice(4 + senderLen + SIGNATURE_BYTES);\n return { senderId, payload, signature };\n}\n",
14
- "/**\n * peer-repo-server — Phase 1 server-side factory for the Polly peer-relay\n * transport. Constructs an Automerge-Repo `Repo` wired to a WebSocket server\n * and a NodeFS storage backend, ready to relay sync messages between\n * connected $peerState clients.\n *\n * The \"always-on peer\" role for $peerState lives here. The server holds a\n * full Automerge replica of every document, participates in the sync protocol\n * as an ordinary peer, and persists state to disk so the next process restart\n * picks up where the previous one left off. Server-side cron, HTTP handlers,\n * and other compute can open document handles on the returned Repo and mutate\n * them; mutations propagate to connected clients through the same sync\n * protocol that handles client-to-client traffic.\n *\n * The plan originally called this an \"Elysia plugin,\" but Automerge's\n * `WebSocketServerAdapter` requires an `isomorphic-ws` `WebSocketServer`\n * instance — not Elysia's native WebSocket — so the cleanest first cut is a\n * standalone factory that runs its own `ws` server. Elysia integration for\n * authenticated upgrades is a Phase 1.1 follow-up that wraps this factory.\n *\n * @example\n * ```ts\n * import { createPeerRepoServer } from \"@fairfox/polly\";\n *\n * const server = await createPeerRepoServer({\n * port: 3030,\n * storagePath: \"./data/polly-peer\",\n * });\n *\n * // Open a document handle on the server's Repo for cron or compute work.\n * const handle = server.repo.create({ counter: 0 });\n *\n * // On shutdown:\n * await server.close();\n * ```\n */\n\nimport { Repo } from \"@automerge/automerge-repo\";\nimport { WebSocketServerAdapter } from \"@automerge/automerge-repo-network-websocket\";\nimport { NodeFSStorageAdapter } from \"@automerge/automerge-repo-storage-nodefs\";\nimport * as ws from \"ws\";\n\n// `@types/ws` uses CJS `export = WebSocket` with WebSocketServer hanging off\n// the namespace. Under the project's bundler module resolution, the namespace\n// import gives us access to both the constructor and the type.\ntype WebSocketServer = ws.WebSocketServer;\n\nexport interface CreatePeerRepoServerOptions {\n /** Port to listen on. The factory creates its own `WebSocketServer` and\n * binds to this port. */\n port: number;\n /** Filesystem directory for the NodeFS storage adapter. The directory is\n * created on demand. Defaults to `./automerge-repo-data` (Automerge's own\n * default). */\n storagePath?: string;\n /** Hostname interface to bind to. Defaults to all interfaces. */\n host?: string;\n /** Override the `WebSocketServer` instance entirely. When provided, `port`\n * and `host` are ignored and the caller is responsible for the lifecycle.\n * Useful for tests that want to bind to a random port. */\n webSocketServer?: WebSocketServer;\n}\n\nexport interface PeerRepoServer {\n /** A configured Repo participating as the always-on peer. Server-side\n * cron and HTTP handlers can open document handles on this directly. */\n repo: Repo;\n /** The underlying WebSocket server. Exposed for advanced use such as\n * health checks or graceful shutdown coordination. */\n webSocketServer: WebSocketServer;\n /** The Automerge network adapter wrapping the WebSocket server. */\n adapter: WebSocketServerAdapter;\n /** The NodeFS storage adapter writing to {@link CreatePeerRepoServerOptions.storagePath}. */\n storage: NodeFSStorageAdapter;\n /** Tear down the server: disconnect peers, flush storage, close the\n * underlying WebSocket server. Returns a promise that resolves once the\n * tear-down is complete. */\n close: () => Promise<void>;\n}\n\n/**\n * Construct a Polly peer-relay server. Returns a Repo that participates as\n * the always-on peer, the underlying WebSocket server and storage adapter\n * for advanced use, and a close function for orderly shutdown.\n *\n * Applications typically call this once at startup, hold the returned\n * `repo` reference for cron and compute work, and wire the close function\n * into their process shutdown signal handlers.\n */\nexport async function createPeerRepoServer(\n options: CreatePeerRepoServerOptions\n): Promise<PeerRepoServer> {\n // Construct the WebSocket server first and wait until it is actually\n // listening before wiring up the Repo. Using the constructor callback\n // avoids the race where the 'listening' event fires before our listener\n // is attached (the callback form is reliable across Node and Bun).\n const wss = await (options.webSocketServer\n ? Promise.resolve(options.webSocketServer)\n : new Promise<WebSocketServer>((resolve, reject) => {\n const created: WebSocketServer = new ws.WebSocketServer(\n {\n port: options.port,\n ...(options.host !== undefined && { host: options.host }),\n },\n () => resolve(created)\n );\n created.once(\"error\", reject);\n }));\n\n // The cast bridges a @types/ws identity quirk: Automerge's adapter type\n // expects WebSocketServer with options.WebSocket typed via isomorphic-ws's\n // CJS-style namespace, and our direct `ws` import resolves through a\n // different path with the same runtime shape but a structurally distinct\n // TypeScript type. The runtime is identical, the cast names that fact.\n const adapter = new WebSocketServerAdapter(\n wss as unknown as ConstructorParameters<typeof WebSocketServerAdapter>[0]\n );\n const storage = new NodeFSStorageAdapter(options.storagePath);\n\n const repo = new Repo({\n network: [adapter],\n storage,\n });\n\n // Force the storage subsystem to finish initialising before returning. The\n // Repo constructor is synchronous, but its NetworkSubsystem holds back the\n // peer-metadata JOIN until storageSubsystem.id() resolves. If a client\n // connects before that resolution lands, the handshake stalls indefinitely.\n // Awaiting storageId() drains the relevant microtask chain and guarantees\n // the server is ready to accept peers when this factory returns.\n await repo.storageId();\n\n return {\n repo,\n webSocketServer: wss,\n adapter,\n storage,\n close: async () => {\n // Forcibly terminate any still-open client sockets before closing the\n // server, otherwise wss.close() can hang waiting for orderly drain when\n // a peer disappeared without a clean disconnect. We then fire the\n // server close without awaiting its callback — the underlying socket\n // is released immediately by terminate(), and waiting for the close\n // callback can hang under Bun even after every client is gone.\n for (const client of wss.clients) {\n try {\n client.terminate();\n } catch {\n // best effort\n }\n }\n void repo.shutdown();\n try {\n wss.close();\n } catch {\n // best effort\n }\n },\n };\n}\n",
14
+ "/**\n * peer-repo-server — Phase 1 server-side factory for the Polly peer-relay\n * transport. Constructs an Automerge-Repo `Repo` wired to a WebSocket server\n * and a NodeFS storage backend, ready to relay sync messages between\n * connected $peerState clients.\n *\n * The \"always-on peer\" role for $peerState lives here. The server holds a\n * full Automerge replica of every document, participates in the sync protocol\n * as an ordinary peer, and persists state to disk so the next process restart\n * picks up where the previous one left off. Server-side cron, HTTP handlers,\n * and other compute can open document handles on the returned Repo and mutate\n * them; mutations propagate to connected clients through the same sync\n * protocol that handles client-to-client traffic.\n *\n * The plan originally called this an \"Elysia plugin,\" but Automerge's\n * `WebSocketServerAdapter` requires an `isomorphic-ws` `WebSocketServer`\n * instance — not Elysia's native WebSocket — so the cleanest first cut is a\n * standalone factory that runs its own `ws` server. Elysia integration for\n * authenticated upgrades is a Phase 1.1 follow-up that wraps this factory.\n *\n * @example\n * ```ts\n * import { createPeerRepoServer } from \"@fairfox/polly\";\n *\n * const server = await createPeerRepoServer({\n * port: 3030,\n * storagePath: \"./data/polly-peer\",\n * });\n *\n * // Open a document handle on the server's Repo for cron or compute work.\n * const handle = server.repo.create({ counter: 0 });\n *\n * // On shutdown:\n * await server.close();\n * ```\n */\n\nimport { Repo } from \"@automerge/automerge-repo\";\nimport { WebSocketServerAdapter } from \"@automerge/automerge-repo-network-websocket\";\nimport { NodeFSStorageAdapter } from \"@automerge/automerge-repo-storage-nodefs\";\nimport * as ws from \"ws\";\n\n// `@types/ws` uses CJS `export = WebSocket` with WebSocketServer hanging off\n// the namespace. Under the project's bundler module resolution, the namespace\n// import gives us access to both the constructor and the type.\ntype WebSocketServer = ws.WebSocketServer;\n\nexport interface CreatePeerRepoServerOptions {\n /** Port to listen on. The factory creates its own `WebSocketServer` and\n * binds to this port. */\n port: number;\n /** Filesystem directory for the NodeFS storage adapter. The directory is\n * created on demand. Defaults to `./automerge-repo-data` (Automerge's own\n * default). */\n storagePath?: string;\n /** Hostname interface to bind to. Defaults to all interfaces. */\n host?: string;\n /** Override the `WebSocketServer` instance entirely. When provided, `port`\n * and `host` are ignored and the caller is responsible for the lifecycle.\n * Useful for tests that want to bind to a random port. */\n webSocketServer?: WebSocketServer;\n}\n\nexport interface PeerRepoServer {\n /** A configured Repo participating as the always-on peer. Server-side\n * cron and HTTP handlers can open document handles on this directly. */\n repo: Repo;\n /** The underlying WebSocket server. Exposed for advanced use such as\n * health checks or graceful shutdown coordination. */\n webSocketServer: WebSocketServer;\n /** The Automerge network adapter wrapping the WebSocket server. */\n adapter: WebSocketServerAdapter;\n /** The NodeFS storage adapter writing to {@link CreatePeerRepoServerOptions.storagePath}. */\n storage: NodeFSStorageAdapter;\n /** Tear down the server: disconnect peers, flush storage, close the\n * underlying WebSocket server. Returns a promise that resolves once the\n * tear-down is complete. */\n close: () => Promise<void>;\n}\n\n/**\n * Construct a Polly peer-relay server. Returns a Repo that participates as\n * the always-on peer, the underlying WebSocket server and storage adapter\n * for advanced use, and a close function for orderly shutdown.\n *\n * Applications typically call this once at startup, hold the returned\n * `repo` reference for cron and compute work, and wire the close function\n * into their process shutdown signal handlers.\n */\nexport async function createPeerRepoServer(\n options: CreatePeerRepoServerOptions\n): Promise<PeerRepoServer> {\n // Construct the WebSocket server first and wait until it is actually\n // listening before wiring up the Repo. Using the constructor callback\n // avoids the race where the 'listening' event fires before our listener\n // is attached (the callback form is reliable across Node and Bun).\n const wss = await (options.webSocketServer\n ? Promise.resolve(options.webSocketServer)\n : new Promise<WebSocketServer>((resolve, reject) => {\n const created: WebSocketServer = new ws.WebSocketServer(\n {\n port: options.port,\n ...(options.host !== undefined && { host: options.host }),\n },\n () => resolve(created)\n );\n created.once(\"error\", reject);\n }));\n\n // The cast bridges a @types/ws identity quirk: Automerge's adapter type\n // expects WebSocketServer with options.WebSocket typed via isomorphic-ws's\n // CJS-style namespace, and our direct `ws` import resolves through a\n // different path with the same runtime shape but a structurally distinct\n // TypeScript type. The runtime is identical, the cast names that fact.\n const adapter = new WebSocketServerAdapter(\n wss as unknown as ConstructorParameters<typeof WebSocketServerAdapter>[0]\n );\n const storage = new NodeFSStorageAdapter(options.storagePath);\n\n const repo = new Repo({\n network: [adapter],\n storage,\n });\n\n // Force the storage subsystem to finish initialising before returning. The\n // Repo constructor is synchronous, but its NetworkSubsystem holds back the\n // peer-metadata JOIN until storageSubsystem.id() resolves. If a client\n // connects before that resolution lands, the handshake stalls indefinitely.\n // Awaiting storageId() drains the relevant microtask chain and guarantees\n // the server is ready to accept peers when this factory returns.\n await repo.storageId();\n\n return {\n repo,\n webSocketServer: wss,\n adapter,\n storage,\n close: async () => {\n // Forcibly terminate any still-open client sockets before closing the\n // server, otherwise wss.close() can hang waiting for orderly drain when\n // a peer disappeared without a clean disconnect. We then fire the\n // server close without awaiting its callback — the underlying socket\n // is released immediately by terminate(), and waiting for the close\n // callback can hang under Bun even after every client is gone.\n for (const client of wss.clients) {\n try {\n client.terminate();\n } catch {\n // best effort\n }\n }\n try {\n await repo.shutdown();\n } catch {\n // best effort — automerge-repo's xstate DocHandle machine can\n // throw \"Cycle detected\" during teardown when sync messages are\n // still in flight.\n }\n try {\n wss.close();\n } catch {\n // best effort\n }\n },\n };\n}\n",
15
15
  "/**\n * peer-state — Phase 1 wrappers exposing $peerState, $peerText, $peerCounter,\n * and $peerList. These are the application-facing constructors for the middle\n * resilience tier in RFC-041: every device is a full Automerge replica, the\n * server included, and server-side code can read and mutate document contents\n * because the server participates in the data plane as an ordinary peer.\n *\n * Each primitive wraps the corresponding Phase 0 base ($crdtState, $crdtText,\n * $crdtCounter, $crdtList) with three additions:\n *\n * 1. The `primitive` label is hard-coded to \"peerState\" so the\n * primitive-registry collision detection knows which family the key\n * belongs to.\n *\n * 2. A handle factory that resolves the application's logical key to an\n * Automerge DocumentId via a per-Repo key map. The first time a key is\n * registered, the factory creates a new document on the configured Repo\n * and records the mapping. On subsequent constructions of the same key,\n * the factory looks up the existing DocumentId and finds the handle.\n *\n * 3. The `sign` option field validates that the configured Repo was\n * created with signing enabled (via createPeerStateClient with\n * `sign: true`). Signing adds Byzantine defence at the transport\n * level without preventing the server from reading document\n * contents. Encryption is not offered on $peerState because it\n * would prevent the server from participating as an Automerge\n * peer; applications that want encrypted state should use $meshState.\n *\n * The Repo itself is supplied by the application via {@link configurePeerState}\n * or per-call via the `repo` option. There is no transport in this Phase 1\n * cut — applications use a local-only Repo and document operations stay\n * inside the calling process. Phase 1's WebSocket relay adapter will plug in\n * via the same configuration path; Phase 2's mesh adapter does the same for\n * $meshState.\n */\n\nimport type { DocHandle, DocumentId, Repo } from \"@automerge/automerge-repo\";\nimport type { Access } from \"./access\";\nimport {\n $crdtCounter,\n $crdtList,\n $crdtText,\n type CounterDoc,\n type ListDoc,\n type SpecialisedPrimitive,\n type TextDoc,\n} from \"./crdt-specialised\";\nimport { $crdtState, type CrdtPrimitive } from \"./crdt-state\";\nimport type { Migrations, VersionedDoc } from \"./schema-version\";\n\n/** Common option shape across all four $peer* primitives. */\nexport interface PeerStateOptions<T> {\n /** Override the default Repo for this primitive. Useful for tests and for\n * applications that maintain multiple Repos (rare). */\n repo?: Repo;\n /** Request per-op Ed25519 signing for this primitive. Signing is a\n * transport-level concern: pass `sign: true` to `createPeerStateClient`\n * to enable it for all primitives on that Repo. Passing `sign: true`\n * here validates that the configured Repo was created with signing\n * enabled and throws if it was not. */\n sign?: boolean;\n /** Schema version target for the application. Migrations run on load. */\n schemaVersion?: number;\n /** Migration table keyed by target version. Required if schemaVersion is set. */\n migrations?: Migrations;\n /** Declarative read/write access. Compiled into a server share policy\n * once the relay transport is wired in. */\n access?: Access;\n /** Initial value used when this primitive's key has not been registered\n * before. Phase 0 callers passed this positionally; Phase 1 application\n * code does the same. */\n initialValue?: T;\n}\n\n/** Internal: per-Repo key → DocumentId map. Cleared by configurePeerState. */\nconst keyMapsByRepo = new WeakMap<Repo, Map<string, DocumentId>>();\n/** Internal: set of Repos configured with signing enabled. */\nconst signingEnabledRepos = new WeakSet<Repo>();\nlet defaultRepo: Repo | undefined;\n\n/**\n * Set the default Repo that the $peer* primitives use when no `repo` option\n * is supplied. Calling this with a new Repo clears the per-Repo key map so\n * that tests start each scenario with a fresh document space.\n *\n * Production code typically calls this once at application startup with a\n * Repo configured for the relay transport. Tests call it before each scenario\n * with an in-memory Repo.\n */\nexport function configurePeerState(repo: Repo, options?: { signEnabled?: boolean }): void {\n defaultRepo = repo;\n keyMapsByRepo.set(repo, new Map());\n if (options?.signEnabled) {\n signingEnabledRepos.add(repo);\n }\n}\n\n/**\n * Reset the peer-state subsystem to its initial unconfigured state. Intended\n * for tests; production code should not call this.\n */\nexport function resetPeerState(): void {\n defaultRepo = undefined;\n}\n\nfunction resolveRepo(option: Repo | undefined): Repo {\n const repo = option ?? defaultRepo;\n if (!repo) {\n throw new Error(\n \"Polly $peerState: no Repo configured. Call configurePeerState(repo) at startup or pass { repo } in the primitive options.\"\n );\n }\n return repo;\n}\n\nfunction getKeyMap(repo: Repo): Map<string, DocumentId> {\n let map = keyMapsByRepo.get(repo);\n if (!map) {\n map = new Map();\n keyMapsByRepo.set(repo, map);\n }\n return map;\n}\n\nfunction validateSignOption(options: PeerStateOptions<unknown>, repo: Repo): void {\n if (!options.sign) return;\n if (!signingEnabledRepos.has(repo)) {\n throw new Error(\n \"Polly $peerState: { sign: true } was passed to the primitive but the configured Repo does not have signing enabled. \" +\n \"Pass { sign: true, keyring: ... } to createPeerStateClient to enable signing at the transport level, \" +\n \"then call configurePeerState(client.repo, { signEnabled: true }).\"\n );\n }\n}\n\n/**\n * Build a getHandle factory that resolves a logical key to a DocHandle on\n * the supplied Repo. The first call creates a new document seeded with the\n * given initial value and records the (key → DocumentId) mapping; subsequent\n * calls look up the existing DocumentId and find the handle.\n */\nfunction buildHandleFactory<D>(\n repo: Repo,\n key: string,\n initialDoc: D\n): () => Promise<DocHandle<D>> {\n return async () => {\n const map = getKeyMap(repo);\n const existingId = map.get(key);\n if (existingId !== undefined) {\n return repo.find<D>(existingId);\n }\n const handle = repo.create<D>(initialDoc);\n map.set(key, handle.documentId);\n return handle;\n };\n}\n\n// ─── $peerState ─────────────────────────────────────────────────────────────\n\n/**\n * Create a peer-replicated state primitive backed by Automerge. Every device\n * holds a full replica; the server, when one is configured via the relay\n * transport, holds one too and participates in the sync protocol as an\n * ordinary peer. Server-side code can read and mutate document contents.\n *\n * @example\n * ```ts\n * const settings = $peerState<Settings>(\"settings\", { theme: \"dark\" });\n * await settings.loaded;\n * settings.value = { theme: \"light\" };\n * ```\n */\nexport function $peerState<T extends VersionedDoc>(\n key: string,\n initialValue: T,\n options: PeerStateOptions<T> = {}\n): CrdtPrimitive<T> {\n const repo = resolveRepo(options.repo);\n validateSignOption(options, repo);\n return $crdtState<T>({\n key,\n primitive: \"peerState\",\n initialValue,\n getHandle: buildHandleFactory<T>(repo, key, initialValue),\n schemaVersion: options.schemaVersion,\n migrations: options.migrations,\n access: options.access,\n });\n}\n\n// ─── $peerText ──────────────────────────────────────────────────────────────\n\nexport interface PeerTextOptions extends Omit<PeerStateOptions<unknown>, \"initialValue\"> {}\n\n/**\n * Create a peer-replicated text primitive. Concurrent character-level edits\n * from peers merge cleanly via Automerge's updateText splicing.\n */\nexport function $peerText(\n key: string,\n initialValue: string,\n options: PeerTextOptions = {}\n): SpecialisedPrimitive<string> {\n const repo = resolveRepo(options.repo);\n validateSignOption(options, repo);\n return $crdtText(key, initialValue, {\n primitive: \"peerState\",\n getHandle: buildHandleFactory<TextDoc>(repo, key, { text: initialValue }),\n schemaVersion: options.schemaVersion,\n migrations: options.migrations,\n access: options.access,\n });\n}\n\n// ─── $peerCounter ───────────────────────────────────────────────────────────\n\nexport interface PeerCounterOptions extends Omit<PeerStateOptions<unknown>, \"initialValue\"> {}\n\n/**\n * Create a peer-replicated counter primitive. Concurrent increments from\n * peers commute, so two clients each adding 1 to a counter at 5 produce a\n * counter at 7 after merging.\n */\nexport function $peerCounter(\n key: string,\n initialValue: number,\n options: PeerCounterOptions = {}\n): SpecialisedPrimitive<number> {\n const repo = resolveRepo(options.repo);\n validateSignOption(options, repo);\n return $crdtCounter(key, initialValue, {\n primitive: \"peerState\",\n getHandle: buildHandleFactory<CounterDoc>(repo, key, {}),\n schemaVersion: options.schemaVersion,\n migrations: options.migrations,\n access: options.access,\n });\n}\n\n// ─── $peerList ──────────────────────────────────────────────────────────────\n\nexport interface PeerListOptions extends Omit<PeerStateOptions<unknown>, \"initialValue\"> {}\n\n/**\n * Create a peer-replicated list primitive. The Phase 0 base uses naive\n * whole-array replacement; Phase 1.1 will refine the write path with\n * structural diff-to-splice for concurrent insert/remove preservation.\n */\nexport function $peerList<T>(\n key: string,\n initialValue: T[],\n options: PeerListOptions = {}\n): SpecialisedPrimitive<T[]> {\n const repo = resolveRepo(options.repo);\n validateSignOption(options, repo);\n return $crdtList<T>(key, initialValue, {\n primitive: \"peerState\",\n getHandle: buildHandleFactory<ListDoc<T>>(repo, key, { items: initialValue }),\n schemaVersion: options.schemaVersion,\n migrations: options.migrations,\n access: options.access,\n });\n}\n"
16
16
  ],
17
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA;AACA;;;ACqBO,MAAM,uBAAuB,MAAM;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EAET,WAAW,CACT,SACA,MACA,KACA,WACA;AAAA,IACA,MAAM,OAAO;AAAA,IACb,KAAK,OAAO;AAAA,IACZ,KAAK,OAAO;AAAA,IACZ,KAAK,MAAM;AAAA,IACX,KAAK,YAAY;AAAA;AAErB;AAAA;AAOO,MAAM,kBAAkB;AAAA,EACZ,QAAQ,IAAI;AAAA,EAErB,QAAQ,CAAC,KAAa,WAAkC;AAAA,IAC9D,OAAO,GAAG,aAAa;AAAA;AAAA,EAIzB,IAAI,CAAC,KAAa,WAAgC;AAAA,IAChD,KAAK,MAAM,IAAI,KAAK,SAAS,KAAK,SAAS,CAAC;AAAA;AAAA,EAI9C,QAAQ,CAAC,KAAa,WAAmC;AAAA,IACvD,OAAO,KAAK,MAAM,IAAI,KAAK,SAAS,KAAK,SAAS,CAAC;AAAA;AAAA,EAIrD,KAAK,GAAS;AAAA,IACZ,KAAK,MAAM,MAAM;AAAA;AAAA,MAIf,IAAI,GAAW;AAAA,IACjB,OAAO,KAAK,MAAM;AAAA;AAEtB;A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;AAAA,EAClB,CAAC;AAAA;AAYI,SAAS,SAAY,CAC1B,KACA,cACA,UAA2B,CAAC,GACD;AAAA,EAC3B,MAAM,OAAO,YAAY,QAAQ,IAAI;AAAA,EACrC,mBAAmB,SAAS,IAAI;AAAA,EAChC,OAAO,UAAa,KAAK,cAAc;AAAA,IACrC,WAAW;AAAA,IACX,WAAW,mBAA+B,MAAM,KAAK,EAAE,OAAO,aAAa,CAAC;AAAA,IAC5E,eAAe,QAAQ;AAAA,IACvB,YAAY,QAAQ;AAAA,IACpB,QAAQ,QAAQ;AAAA,EAClB,CAAC;AAAA;",
18
+ "debugId": "5E1D406403AE952E64756E2164756E21",
19
19
  "names": []
20
20
  }
@@ -42,28 +42,55 @@ function isLineClean(line) {
42
42
  }
43
43
  if (line.match(/\bas\s*[=:,]/))
44
44
  return true;
45
- if (line.match(/\)\s+as\s+\w+/))
45
+ if (everyAsInsideString(line))
46
+ return true;
47
+ if (isJsxText(trimmed))
48
+ return true;
49
+ if (isPlainText(trimmed))
46
50
  return true;
47
- const idx = line.indexOf(" as ");
48
- if (idx >= 0) {
49
- const before = line.substring(0, idx);
50
- const singleQuotes = (before.match(/'/g) ?? []).length;
51
- const doubleQuotes = (before.match(/"/g) ?? []).length;
52
- const backticks = (before.match(/`/g) ?? []).length;
53
- if (singleQuotes % 2 === 1 || doubleQuotes % 2 === 1 || backticks % 2 === 1) {
54
- return true;
55
- }
56
- }
57
51
  const commentIdx = line.indexOf("//");
58
52
  if (commentIdx >= 0 && line.indexOf(" as ", commentIdx) >= 0) {
59
53
  const beforeComment = line.substring(0, commentIdx);
60
54
  if (!beforeComment.includes(" as "))
61
55
  return true;
62
56
  }
57
+ if (line.match(/"\)\s+as\s+\w+"/))
58
+ return true;
63
59
  if (line.includes(" satisfies "))
64
60
  return true;
65
61
  return false;
66
62
  }
63
+ function everyAsInsideString(line) {
64
+ let searchFrom = 0;
65
+ while (true) {
66
+ const idx = line.indexOf(" as ", searchFrom);
67
+ if (idx < 0)
68
+ return true;
69
+ const before = line.substring(0, idx);
70
+ const singleQuotes = (before.match(/'/g) ?? []).length;
71
+ const doubleQuotes = (before.match(/"/g) ?? []).length;
72
+ const backticks = (before.match(/`/g) ?? []).length;
73
+ if (singleQuotes % 2 === 0 && doubleQuotes % 2 === 0 && backticks % 2 === 0) {
74
+ return false;
75
+ }
76
+ searchFrom = idx + 4;
77
+ }
78
+ }
79
+ function isJsxText(trimmed) {
80
+ if (trimmed.match(/^[^{};=()]*\bas\b[^{};=()]*$/)) {
81
+ if (!trimmed.match(/\bas\s+[A-Z]\w*/) && !trimmed.match(/\bas\s+(string|number|boolean|any|unknown|never)\b/)) {
82
+ return true;
83
+ }
84
+ }
85
+ return false;
86
+ }
87
+ function isPlainText(trimmed) {
88
+ const idx = trimmed.indexOf(" as ");
89
+ if (idx < 0)
90
+ return false;
91
+ const before = trimmed.substring(0, idx);
92
+ return !before.match(/[={}:;(]/) && !before.match(/\b(const|let|var|type|interface|function|return|await)\b/);
93
+ }
67
94
  function suggestFix(line) {
68
95
  if (line.includes("JSON.parse")) {
69
96
  return "Use a validation function or type guard to parse and validate the result.";
@@ -94,52 +121,65 @@ function suggestFix(line) {
94
121
  }
95
122
  return;
96
123
  }
124
+ function isFileExcluded(relative, excludeDirs, excludePackages, excludeFiles) {
125
+ const segments = relative.split("/");
126
+ if (segments.some((s) => excludeDirs.has(s)))
127
+ return true;
128
+ if (excludePackages.size > 0 && segments.some((s) => excludePackages.has(s)))
129
+ return true;
130
+ const basename = segments[segments.length - 1] ?? "";
131
+ return excludeFiles.has(basename) || excludeFiles.has(relative);
132
+ }
133
+ function findViolations(relative, content) {
134
+ const results = [];
135
+ const lines = content.split(`
136
+ `);
137
+ for (let i = 0;i < lines.length; i++) {
138
+ const line = lines[i] ?? "";
139
+ if (!isLineClean(line)) {
140
+ results.push({
141
+ file: relative,
142
+ line: i + 1,
143
+ content: line.trim(),
144
+ advice: suggestFix(line.trim())
145
+ });
146
+ }
147
+ }
148
+ return results;
149
+ }
150
+ function printViolations(violations) {
151
+ if (violations.length === 0) {
152
+ console.log("[no-as-casting] ✅ No violations found.");
153
+ return;
154
+ }
155
+ console.log(`[no-as-casting] ❌ ${violations.length} violation(s) found:
156
+ `);
157
+ for (const v of violations) {
158
+ console.log(` ${v.file}:${v.line}`);
159
+ console.log(` ${v.content}`);
160
+ if (v.advice)
161
+ console.log(` \uD83D\uDCA1 ${v.advice}`);
162
+ console.log();
163
+ }
164
+ console.log("[no-as-casting] Use type guards, validation, or fix the types at the source.");
165
+ console.log('[no-as-casting] Only "as const" and "as unknown as" are allowed.');
166
+ }
97
167
  async function checkNoAsCasting(options) {
98
168
  const rootDir = options.rootDir;
99
169
  const excludeDirs = new Set(options.exclude ?? ["node_modules", "dist", ".git", ".bun"]);
170
+ const excludePackages = new Set(options.excludePackages ?? []);
171
+ const excludeFiles = new Set(options.excludeFiles ?? []);
100
172
  const pattern = options.filePatterns ?? "**/*.{ts,tsx}";
101
173
  const glob = new Glob(pattern);
102
174
  const violations = [];
103
175
  for await (const file of glob.scan({ cwd: rootDir, absolute: true })) {
104
176
  const relative = file.replace(`${rootDir}/`, "");
105
- const segments = relative.split("/");
106
- if (segments.some((s) => excludeDirs.has(s)))
177
+ if (isFileExcluded(relative, excludeDirs, excludePackages, excludeFiles))
107
178
  continue;
108
179
  const content = readFileSync(file, "utf-8");
109
- const lines = content.split(`
110
- `);
111
- for (let i = 0;i < lines.length; i++) {
112
- const line = lines[i] ?? "";
113
- if (!isLineClean(line)) {
114
- violations.push({
115
- file: relative,
116
- line: i + 1,
117
- content: line.trim(),
118
- advice: suggestFix(line.trim())
119
- });
120
- }
121
- }
180
+ violations.push(...findViolations(relative, content));
122
181
  }
123
- return {
124
- violations,
125
- print() {
126
- if (violations.length === 0) {
127
- console.log("[no-as-casting] ✅ No violations found.");
128
- return;
129
- }
130
- console.log(`[no-as-casting] ❌ ${violations.length} violation(s) found:
131
- `);
132
- for (const v of violations) {
133
- console.log(` ${v.file}:${v.line}`);
134
- console.log(` ${v.content}`);
135
- if (v.advice)
136
- console.log(` \uD83D\uDCA1 ${v.advice}`);
137
- console.log();
138
- }
139
- console.log("[no-as-casting] Use type guards, validation, or fix the types at the source.");
140
- console.log('[no-as-casting] Only "as const" and "as unknown as" are allowed.');
141
- }
142
- };
182
+ return { violations, print: () => printViolations(violations) };
143
183
  }
144
184
 
145
185
  // tools/quality/src/cli.ts
@@ -150,13 +190,17 @@ function getFlag(name) {
150
190
  }
151
191
  var rootDir = getFlag("root") ?? process.cwd();
152
192
  var exclude = getFlag("exclude")?.split(",") ?? ["node_modules", "dist", ".git", ".bun"];
193
+ var excludePackages = getFlag("exclude-packages")?.split(",");
194
+ var excludeFiles = getFlag("exclude-files")?.split(",");
153
195
  var filePatterns = getFlag("pattern");
154
196
  var result = await checkNoAsCasting({
155
197
  rootDir,
156
198
  exclude,
199
+ ...excludePackages ? { excludePackages } : {},
200
+ ...excludeFiles ? { excludeFiles } : {},
157
201
  ...filePatterns ? { filePatterns } : {}
158
202
  });
159
203
  result.print();
160
204
  process.exit(result.violations.length > 0 ? 1 : 0);
161
205
 
162
- //# debugId=C4D3FE8A6910608764756E2164756E21
206
+ //# debugId=E6501402C1BD2E6764756E2164756E21
@@ -2,10 +2,10 @@
2
2
  "version": 3,
3
3
  "sources": ["../tools/quality/src/no-as-casting.ts", "../tools/quality/src/cli.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * No-as-casting conformance check.\n *\n * Bans all TypeScript type assertions (`as Type`) except the allowed\n * patterns: `as const` (literal narrowing), `as unknown as` (explicit\n * escape hatch), import/export renames, and `as` inside strings or\n * comments. Violations include pattern-specific fix advice.\n *\n * This module exports the check logic as a library so consuming\n * applications can import it from `@fairfox/polly/quality` and run it\n * programmatically. Polly's own `scripts/check-no-as-casting.ts` is a\n * thin CLI wrapper around these exports.\n */\n\nimport { readFileSync } from \"node:fs\";\nimport { Glob } from \"bun\";\n\nexport interface Violation {\n file: string;\n line: number;\n content: string;\n advice?: string;\n}\n\nexport interface CheckResult {\n violations: Violation[];\n print: () => void;\n}\n\nexport interface CheckOptions {\n rootDir: string;\n exclude?: string[];\n filePatterns?: string;\n}\n\n/**\n * Check whether a line contains a forbidden `as` type assertion.\n * Returns true if the line is clean (no violation), false if it violates.\n */\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Source-text scanning with many skip rules is inherently branchy.\nexport function isLineClean(line: string): boolean {\n if (!line.includes(\" as \")) return true;\n\n const trimmed = line.trim();\n\n if (trimmed.startsWith(\"//\") || trimmed.startsWith(\"*\") || trimmed.startsWith(\"/*\")) {\n return true;\n }\n\n if (line.match(/\\bas const\\b/)) {\n const withoutAsConst = line.replace(/\\bas const\\b/g, \"\");\n if (!withoutAsConst.includes(\" as \")) return true;\n }\n\n if (line.includes(\" as unknown as \") || line.trimEnd().endsWith(\"as unknown as\")) {\n const withoutEscapeHatch = line.replace(/\\bas unknown as\\b/g, \"\");\n if (!withoutEscapeHatch.includes(\" as \")) return true;\n }\n\n if (\n line.match(/\\b(import|export)\\s+.*\\s+as\\s+\\w+/) ||\n line.match(/\\b(import|export)\\s+\\*\\s+as\\s+\\w+/) ||\n line.match(/\\b(import|export)\\s+type\\s+.*\\s+as\\s+\\w+/) ||\n line.match(/^\\s*\\w+\\s+as\\s+\\w+,?\\s*$/) ||\n line.match(/^\\s*type\\s+\\w+\\s+as\\s+\\w+,?\\s*$/)\n ) {\n return true;\n }\n\n if (line.match(/\\bas\\s*[=:,]/)) return true;\n if (line.match(/\\)\\s+as\\s+\\w+/)) return true;\n\n const idx = line.indexOf(\" as \");\n if (idx >= 0) {\n const before = line.substring(0, idx);\n const singleQuotes = (before.match(/'/g) ?? []).length;\n const doubleQuotes = (before.match(/\"/g) ?? []).length;\n const backticks = (before.match(/`/g) ?? []).length;\n if (singleQuotes % 2 === 1 || doubleQuotes % 2 === 1 || backticks % 2 === 1) {\n return true;\n }\n }\n\n const commentIdx = line.indexOf(\"//\");\n if (commentIdx >= 0 && line.indexOf(\" as \", commentIdx) >= 0) {\n const beforeComment = line.substring(0, commentIdx);\n if (!beforeComment.includes(\" as \")) return true;\n }\n\n if (line.includes(\" satisfies \")) return true;\n\n return false;\n}\n\n/**\n * Suggest a concrete fix for a specific violation pattern.\n */\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Pattern-matching advice is a linear chain of if-returns.\nexport function suggestFix(line: string): string | undefined {\n if (line.includes(\"JSON.parse\")) {\n return \"Use a validation function or type guard to parse and validate the result.\";\n }\n if (\n line.includes(\"as HTMLInputElement\") ||\n line.includes(\"as HTMLTextAreaElement\") ||\n line.includes(\"as HTMLButtonElement\")\n ) {\n return \"Use instanceof: if (el instanceof HTMLInputElement) { el.value ... }\";\n }\n if (line.includes(\"as HTMLElement\") || line.includes(\"as Element\")) {\n return \"Use instanceof: if (el instanceof HTMLElement) { ... }\";\n }\n if (line.includes(\".doc()\") && line.includes(\"as \")) {\n return \"Type the DocHandle generic: repo.find<MyType>(id) returns DocHandle<MyType>.\";\n }\n if (\n line.includes(\"Record<string, unknown>\") &&\n (line.includes(\"window\") || line.includes(\"globalThis\"))\n ) {\n return \"Extract a type guard: function getGlobalProp(name: string): unknown { ... }\";\n }\n if (line.includes(\"Record<string, unknown>\")) {\n return \"Use a type guard function that narrows the unknown value to the target shape.\";\n }\n if (line.includes(\"as PeerId\") || line.includes(\"as DocumentId\")) {\n return \"Use the library's branded-type constructor if available, or centralise the cast in a factory.\";\n }\n if (line.includes(\"as string\") || line.includes(\"as number\") || line.includes(\"as boolean\")) {\n return \"Narrow with typeof: if (typeof x === 'string') { ... }\";\n }\n if (line.includes(\"as any\")) {\n return \"Replace 'any' with 'unknown' and add a type guard or validation at the boundary.\";\n }\n return undefined;\n}\n\n/**\n * Run the no-as-casting check against a directory. Returns a result\n * object with the violations and a print function for CLI output.\n */\nexport async function checkNoAsCasting(options: CheckOptions): Promise<CheckResult> {\n const rootDir = options.rootDir;\n const excludeDirs = new Set(options.exclude ?? [\"node_modules\", \"dist\", \".git\", \".bun\"]);\n const pattern = options.filePatterns ?? \"**/*.{ts,tsx}\";\n const glob = new Glob(pattern);\n const violations: Violation[] = [];\n\n for await (const file of glob.scan({ cwd: rootDir, absolute: true })) {\n const relative = file.replace(`${rootDir}/`, \"\");\n const segments = relative.split(\"/\");\n if (segments.some((s) => excludeDirs.has(s))) continue;\n\n const content = readFileSync(file, \"utf-8\");\n const lines = content.split(\"\\n\");\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i] ?? \"\";\n if (!isLineClean(line)) {\n violations.push({\n file: relative,\n line: i + 1,\n content: line.trim(),\n advice: suggestFix(line.trim()),\n });\n }\n }\n }\n\n return {\n violations,\n print() {\n if (violations.length === 0) {\n console.log(\"[no-as-casting] ✅ No violations found.\");\n return;\n }\n console.log(`[no-as-casting] ❌ ${violations.length} violation(s) found:\\n`);\n for (const v of violations) {\n console.log(` ${v.file}:${v.line}`);\n console.log(` ${v.content}`);\n if (v.advice) console.log(` 💡 ${v.advice}`);\n console.log();\n }\n console.log(\"[no-as-casting] Use type guards, validation, or fix the types at the source.\");\n console.log('[no-as-casting] Only \"as const\" and \"as unknown as\" are allowed.');\n },\n };\n}\n",
6
- "#!/usr/bin/env bun\n\n/**\n * CLI entry point for Polly quality checks.\n *\n * polly quality [--root <dir>] [--exclude <dirs>] [--pattern <glob>]\n *\n * Runs all conformance checks (currently: no-as-casting) against the\n * target directory and exits non-zero when violations are found.\n */\n\nimport { checkNoAsCasting } from \"./no-as-casting\";\n\nconst args = process.argv.slice(2);\n\nfunction getFlag(name: string): string | undefined {\n const idx = args.indexOf(`--${name}`);\n return idx >= 0 ? args[idx + 1] : undefined;\n}\n\nconst rootDir = getFlag(\"root\") ?? process.cwd();\nconst exclude = getFlag(\"exclude\")?.split(\",\") ?? [\"node_modules\", \"dist\", \".git\", \".bun\"];\nconst filePatterns = getFlag(\"pattern\");\n\nconst result = await checkNoAsCasting({\n rootDir,\n exclude,\n ...(filePatterns ? { filePatterns } : {}),\n});\n\nresult.print();\nprocess.exit(result.violations.length > 0 ? 1 : 0);\n"
5
+ "/**\n * No-as-casting conformance check.\n *\n * Bans all TypeScript type assertions (`as Type`) except the allowed\n * patterns: `as const` (literal narrowing), `as unknown as` (explicit\n * escape hatch), import/export renames, and `as` inside strings or\n * comments. Violations include pattern-specific fix advice.\n *\n * This module exports the check logic as a library so consuming\n * applications can import it from `@fairfox/polly/quality` and run it\n * programmatically. Polly's own `scripts/check-no-as-casting.ts` is a\n * thin CLI wrapper around these exports.\n */\n\nimport { readFileSync } from \"node:fs\";\nimport { Glob } from \"bun\";\n\nexport interface Violation {\n file: string;\n line: number;\n content: string;\n advice?: string;\n}\n\nexport interface CheckResult {\n violations: Violation[];\n print: () => void;\n}\n\nexport interface CheckOptions {\n rootDir: string;\n exclude?: string[];\n excludePackages?: string[];\n excludeFiles?: string[];\n filePatterns?: string;\n}\n\n/**\n * Check whether a line contains a forbidden `as` type assertion.\n * Returns true if the line is clean (no violation), false if it violates.\n */\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Source-text scanning with many skip rules is inherently branchy.\nexport function isLineClean(line: string): boolean {\n if (!line.includes(\" as \")) return true;\n\n const trimmed = line.trim();\n\n // Full-line comments\n if (trimmed.startsWith(\"//\") || trimmed.startsWith(\"*\") || trimmed.startsWith(\"/*\")) {\n return true;\n }\n\n // as const (literal narrowing)\n if (line.match(/\\bas const\\b/)) {\n const withoutAsConst = line.replace(/\\bas const\\b/g, \"\");\n if (!withoutAsConst.includes(\" as \")) return true;\n }\n\n // as unknown as (explicit escape hatch)\n if (line.includes(\" as unknown as \") || line.trimEnd().endsWith(\"as unknown as\")) {\n const withoutEscapeHatch = line.replace(/\\bas unknown as\\b/g, \"\");\n if (!withoutEscapeHatch.includes(\" as \")) return true;\n }\n\n // Import/export renames\n if (\n line.match(/\\b(import|export)\\s+.*\\s+as\\s+\\w+/) ||\n line.match(/\\b(import|export)\\s+\\*\\s+as\\s+\\w+/) ||\n line.match(/\\b(import|export)\\s+type\\s+.*\\s+as\\s+\\w+/) ||\n line.match(/^\\s*\\w+\\s+as\\s+\\w+,?\\s*$/) ||\n line.match(/^\\s*type\\s+\\w+\\s+as\\s+\\w+,?\\s*$/)\n ) {\n return true;\n }\n\n // Property declarations: as= or as: or as,\n if (line.match(/\\bas\\s*[=:,]/)) return true;\n\n // String literal detection: count quotes before each ` as ` occurrence.\n // If any quote type has an odd count, the ` as ` is inside a string.\n if (everyAsInsideString(line)) return true;\n\n // JSX text: ` as ` between > and < with no code syntax around it\n if (isJsxText(trimmed)) return true;\n\n // Plain text heuristic: indented line with no code syntax characters\n // before ` as ` — catches multiline JSX text and template literal bodies.\n if (isPlainText(trimmed)) return true;\n\n // Inline comment: ` as ` appears only after //\n const commentIdx = line.indexOf(\"//\");\n if (commentIdx >= 0 && line.indexOf(\" as \", commentIdx) >= 0) {\n const beforeComment = line.substring(0, commentIdx);\n if (!beforeComment.includes(\" as \")) return true;\n }\n\n // SQL alias: `) as column_name`\n if (line.match(/\"\\)\\s+as\\s+\\w+\"/)) return true;\n\n if (line.includes(\" satisfies \")) return true;\n\n return false;\n}\n\n/**\n * Returns true when every ` as ` occurrence in the line falls inside a\n * string literal (single-quoted, double-quoted, or backtick).\n */\nfunction everyAsInsideString(line: string): boolean {\n let searchFrom = 0;\n while (true) {\n const idx = line.indexOf(\" as \", searchFrom);\n if (idx < 0) return true; // no more ` as ` to check\n const before = line.substring(0, idx);\n const singleQuotes = (before.match(/'/g) ?? []).length;\n const doubleQuotes = (before.match(/\"/g) ?? []).length;\n const backticks = (before.match(/`/g) ?? []).length;\n if (singleQuotes % 2 === 0 && doubleQuotes % 2 === 0 && backticks % 2 === 0) {\n return false; // this ` as ` is outside any string\n }\n searchFrom = idx + 4;\n }\n}\n\n/**\n * Detects JSX text content — ` as ` appearing between > and < with no\n * code-like syntax around it (no braces, semicolons, equals signs).\n */\nfunction isJsxText(trimmed: string): boolean {\n // Classic JSX text: starts after > or is plain text ending before <\n if (trimmed.match(/^[^{};=()]*\\bas\\b[^{};=()]*$/)) {\n // No code syntax at all — could be JSX text or template literal body.\n // Reject if it looks like a type assertion (word ` as ` TypeName pattern\n // where TypeName starts with uppercase, or is a known TS type).\n if (\n !trimmed.match(/\\bas\\s+[A-Z]\\w*/) &&\n !trimmed.match(/\\bas\\s+(string|number|boolean|any|unknown|never)\\b/)\n ) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Heuristic for plain text in template literals or JSX: the line has no\n * code-like characters before ` as ` — no `=`, `{`, `}`, `:`, `;`, `(`.\n */\nfunction isPlainText(trimmed: string): boolean {\n const idx = trimmed.indexOf(\" as \");\n if (idx < 0) return false;\n const before = trimmed.substring(0, idx);\n // If nothing before ` as ` looks like code, it's probably prose.\n return (\n !before.match(/[={}:;(]/) &&\n !before.match(/\\b(const|let|var|type|interface|function|return|await)\\b/)\n );\n}\n\n/**\n * Suggest a concrete fix for a specific violation pattern.\n */\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Pattern-matching advice is a linear chain of if-returns.\nexport function suggestFix(line: string): string | undefined {\n if (line.includes(\"JSON.parse\")) {\n return \"Use a validation function or type guard to parse and validate the result.\";\n }\n if (\n line.includes(\"as HTMLInputElement\") ||\n line.includes(\"as HTMLTextAreaElement\") ||\n line.includes(\"as HTMLButtonElement\")\n ) {\n return \"Use instanceof: if (el instanceof HTMLInputElement) { el.value ... }\";\n }\n if (line.includes(\"as HTMLElement\") || line.includes(\"as Element\")) {\n return \"Use instanceof: if (el instanceof HTMLElement) { ... }\";\n }\n if (line.includes(\".doc()\") && line.includes(\"as \")) {\n return \"Type the DocHandle generic: repo.find<MyType>(id) returns DocHandle<MyType>.\";\n }\n if (\n line.includes(\"Record<string, unknown>\") &&\n (line.includes(\"window\") || line.includes(\"globalThis\"))\n ) {\n return \"Extract a type guard: function getGlobalProp(name: string): unknown { ... }\";\n }\n if (line.includes(\"Record<string, unknown>\")) {\n return \"Use a type guard function that narrows the unknown value to the target shape.\";\n }\n if (line.includes(\"as PeerId\") || line.includes(\"as DocumentId\")) {\n return \"Use the library's branded-type constructor if available, or centralise the cast in a factory.\";\n }\n if (line.includes(\"as string\") || line.includes(\"as number\") || line.includes(\"as boolean\")) {\n return \"Narrow with typeof: if (typeof x === 'string') { ... }\";\n }\n if (line.includes(\"as any\")) {\n return \"Replace 'any' with 'unknown' and add a type guard or validation at the boundary.\";\n }\n return undefined;\n}\n\nfunction isFileExcluded(\n relative: string,\n excludeDirs: Set<string>,\n excludePackages: Set<string>,\n excludeFiles: Set<string>\n): boolean {\n const segments = relative.split(\"/\");\n if (segments.some((s) => excludeDirs.has(s))) return true;\n if (excludePackages.size > 0 && segments.some((s) => excludePackages.has(s))) return true;\n const basename = segments[segments.length - 1] ?? \"\";\n return excludeFiles.has(basename) || excludeFiles.has(relative);\n}\n\nfunction findViolations(relative: string, content: string): Violation[] {\n const results: Violation[] = [];\n const lines = content.split(\"\\n\");\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i] ?? \"\";\n if (!isLineClean(line)) {\n results.push({\n file: relative,\n line: i + 1,\n content: line.trim(),\n advice: suggestFix(line.trim()),\n });\n }\n }\n return results;\n}\n\nfunction printViolations(violations: Violation[]): void {\n if (violations.length === 0) {\n console.log(\"[no-as-casting] ✅ No violations found.\");\n return;\n }\n console.log(`[no-as-casting] ❌ ${violations.length} violation(s) found:\\n`);\n for (const v of violations) {\n console.log(` ${v.file}:${v.line}`);\n console.log(` ${v.content}`);\n if (v.advice) console.log(` 💡 ${v.advice}`);\n console.log();\n }\n console.log(\"[no-as-casting] Use type guards, validation, or fix the types at the source.\");\n console.log('[no-as-casting] Only \"as const\" and \"as unknown as\" are allowed.');\n}\n\n/**\n * Run the no-as-casting check against a directory. Returns a result\n * object with the violations and a print function for CLI output.\n */\nexport async function checkNoAsCasting(options: CheckOptions): Promise<CheckResult> {\n const rootDir = options.rootDir;\n const excludeDirs = new Set(options.exclude ?? [\"node_modules\", \"dist\", \".git\", \".bun\"]);\n const excludePackages = new Set(options.excludePackages ?? []);\n const excludeFiles = new Set(options.excludeFiles ?? []);\n const pattern = options.filePatterns ?? \"**/*.{ts,tsx}\";\n const glob = new Glob(pattern);\n const violations: Violation[] = [];\n\n for await (const file of glob.scan({ cwd: rootDir, absolute: true })) {\n const relative = file.replace(`${rootDir}/`, \"\");\n if (isFileExcluded(relative, excludeDirs, excludePackages, excludeFiles)) continue;\n const content = readFileSync(file, \"utf-8\");\n violations.push(...findViolations(relative, content));\n }\n\n return { violations, print: () => printViolations(violations) };\n}\n",
6
+ "#!/usr/bin/env bun\n\n/**\n * CLI entry point for Polly quality checks.\n *\n * polly quality [--root <dir>] [--exclude <dirs>] [--pattern <glob>]\n * [--exclude-packages <names>] [--exclude-files <names>]\n *\n * Runs all conformance checks (currently: no-as-casting) against the\n * target directory and exits non-zero when violations are found.\n */\n\nimport { checkNoAsCasting } from \"./no-as-casting\";\n\nconst args = process.argv.slice(2);\n\nfunction getFlag(name: string): string | undefined {\n const idx = args.indexOf(`--${name}`);\n return idx >= 0 ? args[idx + 1] : undefined;\n}\n\nconst rootDir = getFlag(\"root\") ?? process.cwd();\nconst exclude = getFlag(\"exclude\")?.split(\",\") ?? [\"node_modules\", \"dist\", \".git\", \".bun\"];\nconst excludePackages = getFlag(\"exclude-packages\")?.split(\",\");\nconst excludeFiles = getFlag(\"exclude-files\")?.split(\",\");\nconst filePatterns = getFlag(\"pattern\");\n\nconst result = await checkNoAsCasting({\n rootDir,\n exclude,\n ...(excludePackages ? { excludePackages } : {}),\n ...(excludeFiles ? { excludeFiles } : {}),\n ...(filePatterns ? { filePatterns } : {}),\n});\n\nresult.print();\nprocess.exit(result.violations.length > 0 ? 1 : 0);\n"
7
7
  ],
8
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAcA;AACA;AAyBO,SAAS,WAAW,CAAC,MAAuB;AAAA,EACjD,IAAI,CAAC,KAAK,SAAS,MAAM;AAAA,IAAG,OAAO;AAAA,EAEnC,MAAM,UAAU,KAAK,KAAK;AAAA,EAE1B,IAAI,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IAC1C,WAAW,KAAK,GAAG,eAAe,UAAU,OAAO,CAAC;AAAA,EACtD;AAAA,EAEA,OAAO,EAAE,YAAY,OAAO,MAAM,gBAAgB,UAAU,EAAE;AAAA;;;AC7PhE,IAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AAEjC,SAAS,OAAO,CAAC,MAAkC;AAAA,EACjD,MAAM,MAAM,KAAK,QAAQ,KAAK,MAAM;AAAA,EACpC,OAAO,OAAO,IAAI,KAAK,MAAM,KAAK;AAAA;AAGpC,IAAM,UAAU,QAAQ,MAAM,KAAK,QAAQ,IAAI;AAC/C,IAAM,UAAU,QAAQ,SAAS,GAAG,MAAM,GAAG,KAAK,CAAC,gBAAgB,QAAQ,QAAQ,MAAM;AACzF,IAAM,kBAAkB,QAAQ,kBAAkB,GAAG,MAAM,GAAG;AAC9D,IAAM,eAAe,QAAQ,eAAe,GAAG,MAAM,GAAG;AACxD,IAAM,eAAe,QAAQ,SAAS;AAEtC,IAAM,SAAS,MAAM,iBAAiB;AAAA,EACpC;AAAA,EACA;AAAA,KACI,kBAAkB,EAAE,gBAAgB,IAAI,CAAC;AAAA,KACzC,eAAe,EAAE,aAAa,IAAI,CAAC;AAAA,KACnC,eAAe,EAAE,aAAa,IAAI,CAAC;AACzC,CAAC;AAED,OAAO,MAAM;AACb,QAAQ,KAAK,OAAO,WAAW,SAAS,IAAI,IAAI,CAAC;",
9
+ "debugId": "E6501402C1BD2E6764756E2164756E21",
10
10
  "names": []
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fairfox/polly",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Multi-execution-context framework with reactive state and cross-context messaging for Chrome extensions, PWAs, and worker-based applications",