@fairfox/polly 0.29.2 → 0.29.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/mesh.js +15 -2
- package/dist/src/mesh.js.map +3 -3
- package/dist/src/peer.js +15 -2
- package/dist/src/peer.js.map +3 -3
- package/dist/tools/quality/src/cli.js +231 -3
- package/dist/tools/quality/src/cli.js.map +6 -4
- package/dist/tools/quality/src/index.d.ts +2 -0
- package/dist/tools/quality/src/index.js +221 -1
- package/dist/tools/quality/src/index.js.map +6 -4
- package/dist/tools/quality/src/no-require.d.ts +44 -0
- package/dist/tools/quality/src/secrets.d.ts +100 -0
- package/package.json +1 -1
package/dist/src/peer.js.map
CHANGED
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
"/**\n * migrate-primitive — one-way cross-primitive data migration helper.\n *\n * Moving data from one Polly primitive to another ($sharedState to $peerState,\n * $peerState to $meshState, etc.) is a deliberate, one-time, application-authored\n * operation. The three primitive families serialise differently — LWW value plus\n * Lamport clock, plaintext Automerge ops, signed and encrypted Automerge ops —\n * and Polly never silently coerces between them. An application that wants to\n * move data explicitly reads the current value from the source, applies a\n * user-supplied transform, writes the result into the destination, and marks\n * the source as migrated so subsequent reads from it fail loudly rather than\n * returning stale data.\n *\n * This module provides the helper ({@link migratePrimitive}) and the migration\n * registry ({@link migrationRegistry}) that records which (key, primitive kind)\n * pairs have been migrated. Primitive read paths consult the registry at load\n * time and refuse to hydrate sources that have been marked. Migration is one-way\n * by design: there is no rollback, and running a migration twice throws.\n *\n * The registry is in-memory only. Persistence of the migrated flag across page\n * loads is each primitive's own responsibility at its storage boundary; Phase 1\n * and Phase 2 primitives will restore the registry state on startup from their\n * local stores.\n *\n * @example\n * ```ts\n * await migratePrimitive(\n * $sharedState<OldNotes>(\"notes\"),\n * $meshState<NewNotes>(\"notes\", { entries: [] }),\n * (old) => ({ entries: old.entries ?? [] }),\n * );\n * ```\n */\n\nimport type { PrimitiveKind } from \"./primitive-registry\";\n\n/**\n * Minimal interface that every migratable state primitive must satisfy. Real\n * primitive instances will implement this plus everything else their type\n * expects; tests construct plain objects.\n */\nexport interface MigratableState<T> {\n /** Stable logical key the primitive was registered under. */\n readonly key: string;\n /** The primitive kind owning this state. Used to identify entries in the\n * migration registry alongside the key. */\n readonly primitive: PrimitiveKind;\n /** Current value. Must be readable and writable. */\n value: T;\n /** Hydration promise. The migration helper awaits this on both source and\n * destination before reading the source value. */\n readonly loaded: Promise<void>;\n}\n\n/**\n * Error thrown by the migration subsystem. The {@link code} field distinguishes\n * the failure modes so callers can branch on them.\n */\nexport class MigrationError extends Error {\n readonly code: \"already-migrated\" | \"same-primitive-instance\";\n readonly key: string;\n readonly primitive: PrimitiveKind;\n\n constructor(\n message: string,\n code: MigrationError[\"code\"],\n key: string,\n primitive: PrimitiveKind\n ) {\n super(message);\n this.name = \"MigrationError\";\n this.code = code;\n this.key = key;\n this.primitive = primitive;\n }\n}\n\n/**\n * In-memory registry of migrated (key, primitive kind) pairs. Exported as a\n * class so tests can construct fresh instances; application code uses the\n * module-level {@link migrationRegistry} singleton.\n */\nexport class MigrationRegistry {\n private readonly marks = new Set<string>();\n\n private entryKey(key: string, primitive: PrimitiveKind): string {\n return `${primitive}:${key}`;\n }\n\n /** Mark a source primitive as migrated. Idempotent. */\n mark(key: string, primitive: PrimitiveKind): void {\n this.marks.add(this.entryKey(key, primitive));\n }\n\n /** Check whether a source primitive has been marked as migrated. */\n isMarked(key: string, primitive: PrimitiveKind): boolean {\n return this.marks.has(this.entryKey(key, primitive));\n }\n\n /** Drop every mark. Intended for tests; application code should not call this. */\n clear(): void {\n this.marks.clear();\n }\n\n /** Number of recorded marks. Intended for tests. */\n get size(): number {\n return this.marks.size;\n }\n}\n\n/**\n * The process-wide migration registry. Primitives and application migrations\n * both consult it: tests can reset it with {@link MigrationRegistry.clear}.\n */\nexport const migrationRegistry = new MigrationRegistry();\n\n/**\n * Migrate data from one Polly primitive to another. Reads the source's current\n * value, applies the caller's transform, writes the result to the destination,\n * and marks the source as migrated so subsequent reads fail loudly.\n *\n * The helper is one-way and one-time. Running it twice on the same source\n * throws a {@link MigrationError} with code `already-migrated`. Running it\n * with the same object as both source and destination throws with code\n * `same-primitive-instance`.\n *\n * Applications invoke this explicitly on upgrade, once per device, typically\n * inside a startup hook before the primitives that depend on the migrated data\n * are read. It is not a replacement for the schema-version migration protocol\n * inside a single primitive — that handles shape evolution within one primitive\n * family, whereas this helper handles moves between primitive families.\n */\nexport async function migratePrimitive<Source, Destination>(\n source: MigratableState<Source>,\n destination: MigratableState<Destination>,\n transform: (value: Source) => Destination\n): Promise<void> {\n if ((source as unknown as unknown) === (destination as unknown as unknown)) {\n throw new MigrationError(\n `Cannot migrate a primitive to itself: \"${source.key}\" under ${source.primitive}.`,\n \"same-primitive-instance\",\n source.key,\n source.primitive\n );\n }\n if (migrationRegistry.isMarked(source.key, source.primitive)) {\n throw new MigrationError(\n `Cannot migrate: source \"${source.key}\" under $${source.primitive} has already been migrated. Migrations are one-way and one-time.`,\n \"already-migrated\",\n source.key,\n source.primitive\n );\n }\n await source.loaded;\n await destination.loaded;\n const transformed = transform(source.value);\n destination.value = transformed;\n migrationRegistry.mark(source.key, source.primitive);\n}\n",
|
|
9
9
|
"/**\n * PrimitiveRegistry — runtime namespace collision detection across Polly's\n * synced state primitives.\n *\n * The three primitive families ($sharedState, $peerState, $meshState) each store\n * data under a developer-chosen logical key. If two different primitives both\n * claim the same key, the developer almost certainly has a bug: the on-disk\n * formats are incompatible, no sync happens between them, and whichever primitive\n * resolves first silently \"wins\" from the developer's perspective. By the time\n * the mistake is noticed, data has diverged.\n *\n * The registry catches the mistake at the first mismatched registration and\n * throws a structured error naming the key, both primitives, and (when available)\n * the call site of each registration. This is run-to-failure by design: a\n * collision is always a bug, and the failure should be loud.\n *\n * Same primitive re-registering the same key is allowed and is a no-op — it\n * supports hot module reloading and component re-mounts without spurious errors.\n * Changing the primitive kind of an existing key is still an error; developers\n * doing that during local HMR should hard-reload to reset the registry.\n *\n * @example\n * ```ts\n * primitiveRegistry.register(\"notes\", \"sharedState\", \"src/app.ts:10\");\n * primitiveRegistry.register(\"notes\", \"peerState\", \"src/other.ts:22\");\n * // throws PrimitiveCollisionError — names both primitives and both call sites\n * ```\n */\n\n/**\n * Canonical identifiers for Polly's synced state primitives. The registry\n * uses these as opaque labels; nothing else in Polly needs to match them.\n */\nexport type PrimitiveKind =\n | \"sharedState\"\n | \"syncedState\"\n | \"persistedState\"\n | \"state\"\n | \"peerState\"\n | \"meshState\";\n\n/**\n * Thrown when a logical key is registered under more than one primitive.\n * The message names the key, both primitives, and (when available) the\n * call site of each registration, so the developer can navigate to both\n * sites from the error output.\n */\nexport class PrimitiveCollisionError extends Error {\n readonly key: string;\n readonly firstPrimitive: PrimitiveKind;\n readonly firstCallSite: string | undefined;\n readonly secondPrimitive: PrimitiveKind;\n readonly secondCallSite: string | undefined;\n\n constructor(\n key: string,\n firstPrimitive: PrimitiveKind,\n firstCallSite: string | undefined,\n secondPrimitive: PrimitiveKind,\n secondCallSite: string | undefined\n ) {\n const firstLocation = firstCallSite ? ` (at ${firstCallSite})` : \"\";\n const secondLocation = secondCallSite ? ` (at ${secondCallSite})` : \"\";\n super(\n `Polly primitive key collision: \"${key}\" is already registered as ` +\n `$${firstPrimitive}${firstLocation} and cannot also be registered ` +\n `as $${secondPrimitive}${secondLocation}. Pick a different key or ` +\n `use the same primitive in both places.`\n );\n this.name = \"PrimitiveCollisionError\";\n this.key = key;\n this.firstPrimitive = firstPrimitive;\n this.firstCallSite = firstCallSite;\n this.secondPrimitive = secondPrimitive;\n this.secondCallSite = secondCallSite;\n }\n}\n\ntype RegistryEntry = {\n primitive: PrimitiveKind;\n callSite: string | undefined;\n};\n\n/**\n * A small Map-backed registry of \"logical key → primitive kind\". Exported as\n * a class so tests can construct fresh instances without sharing state; the\n * module-level {@link primitiveRegistry} singleton is what application code\n * actually uses.\n */\nexport class PrimitiveRegistry {\n private readonly entries = new Map<string, RegistryEntry>();\n\n /**\n * Register a key under a primitive kind. Re-registering the same key under\n * the same primitive is a no-op, which is what hot module reloading and\n * component re-mounts produce.\n *\n * @throws {PrimitiveCollisionError} if the key is already registered under\n * a different primitive kind.\n */\n register(key: string, primitive: PrimitiveKind, callSite?: string): void {\n const existing = this.entries.get(key);\n if (existing && existing.primitive !== primitive) {\n throw new PrimitiveCollisionError(\n key,\n existing.primitive,\n existing.callSite,\n primitive,\n callSite\n );\n }\n if (!existing) {\n this.entries.set(key, { primitive, callSite });\n }\n }\n\n /**\n * True if the key has been registered (under any primitive kind).\n */\n has(key: string): boolean {\n return this.entries.has(key);\n }\n\n /**\n * Look up the primitive kind a key is registered under, if any.\n * Returns undefined for unregistered keys.\n */\n kindOf(key: string): PrimitiveKind | undefined {\n return this.entries.get(key)?.primitive;\n }\n\n /**\n * Drop every registration. Intended for test setup and teardown; application\n * code should not call this.\n */\n clear(): void {\n this.entries.clear();\n }\n\n /**\n * Number of registered keys. Intended for tests.\n */\n get size(): number {\n return this.entries.size;\n }\n}\n\n/**\n * The process-wide primitive registry. Application code registers here\n * implicitly via primitive constructors; tests can reset it with `clear()`.\n */\nexport const primitiveRegistry = new PrimitiveRegistry();\n",
|
|
10
10
|
"/**\n * schema-version — plumbing for the shared schema-version migration protocol\n * used by $peerState and $meshState documents.\n *\n * Every peer-first document carries a reserved schema-version field. When a\n * client loads a document whose stored version is lower than the application's\n * declared target version, Polly walks the registered migrations in sequence,\n * mutating the document from one version to the next, and stamps the new\n * version on the way through. When the stored version is higher, Polly refuses\n * to load and surfaces a structured error: the application is older than the\n * document and should be upgraded.\n *\n * For concurrent writes across mixed client versions, every op also carries\n * the schema version under which it was produced. Ops whose version is lower\n * than the document's current version are rejected at sync time; the peer\n * producing them needs to upgrade its local replica through the migration\n * runner before retrying. Ops whose version is higher mean the current peer\n * is behind the application that produced them; rejecting them prevents\n * corruption while still surfacing the mismatch to the user.\n *\n * This module provides only the plumbing — the reserved field name, the\n * reader and writer for the version field, the migration runner, and the\n * op-version compatibility check. Phase 1 and Phase 2 primitives will consume\n * these helpers; nothing in this file depends on Automerge or any transport.\n */\n\n/**\n * The reserved field name used to store the schema version on every peer-first\n * document. Applications must not use this field for their own data; the\n * primitive constructors reserve it at the document boundary.\n */\nexport const SCHEMA_VERSION_FIELD = \"__schemaVersion\" as const;\n\n/**\n * The minimal shape every peer-first document satisfies. Applications layer\n * their own fields on top of this; the reserved {@link SCHEMA_VERSION_FIELD}\n * is the only required key.\n */\nexport type VersionedDoc = {\n [SCHEMA_VERSION_FIELD]?: number;\n [otherField: string]: unknown;\n};\n\n/**\n * A single migration step. Mutates the document in place, transforming it\n * from version (target - 1) to version target. The implementation must be\n * total (accept any valid v(target-1) document) and deterministic (running\n * it twice produces the same result). Applications that want return-a-new-doc\n * semantics should copy inside the migration body rather than returning.\n */\nexport type Migration = (doc: Record<string, unknown>) => void;\n\n/**\n * A map from target schema version to the migration that produces it. The\n * keys must be contiguous from 1 upward through the application's target\n * version, with no gaps. Gaps throw at migration time.\n *\n * @example\n * ```ts\n * const migrations: Migrations = {\n * 1: (doc) => { doc[\"title\"] = \"\"; }, // v0 → v1\n * 2: (doc) => { doc[\"tags\"] = []; }, // v1 → v2\n * 3: (doc) => { doc[\"archived\"] = false; delete doc[\"deleted\"]; }, // v2 → v3\n * };\n * ```\n */\nexport type Migrations = Record<number, Migration>;\n\n/**\n * Error thrown by the schema-version subsystem. The `code` field distinguishes\n * the failure modes so that callers (primitive constructors, application error\n * handlers) can decide whether to surface the error to the user, prompt an\n * upgrade, or drop the offending op.\n */\nexport class SchemaVersionError extends Error {\n readonly code:\n | \"doc-ahead-of-app\"\n | \"missing-migration\"\n | \"op-older-than-doc\"\n | \"op-newer-than-doc\";\n readonly docVersion?: number;\n readonly targetVersion?: number;\n readonly opVersion?: number;\n readonly missingVersion?: number;\n\n constructor(\n message: string,\n code: SchemaVersionError[\"code\"],\n details: {\n docVersion?: number;\n targetVersion?: number;\n opVersion?: number;\n missingVersion?: number;\n } = {}\n ) {\n super(message);\n this.name = \"SchemaVersionError\";\n this.code = code;\n if (details.docVersion !== undefined) this.docVersion = details.docVersion;\n if (details.targetVersion !== undefined) this.targetVersion = details.targetVersion;\n if (details.opVersion !== undefined) this.opVersion = details.opVersion;\n if (details.missingVersion !== undefined) this.missingVersion = details.missingVersion;\n }\n}\n\n/**\n * Read the schema version stored on a document. Returns 0 for documents that\n * have never been stamped (undefined field), which is the canonical \"pre-v1\"\n * sentinel — the first migration in a registry is always keyed at 1 and\n * handles the undefined-to-1 transition.\n */\nexport function getDocVersion(doc: unknown): number {\n if (typeof doc !== \"object\" || doc === null) return 0;\n const record = doc as unknown as Record<string, unknown>;\n const value = record[SCHEMA_VERSION_FIELD];\n return typeof value === \"number\" && Number.isInteger(value) && value >= 0 ? value : 0;\n}\n\n/**\n * Stamp a schema version onto a document in place. Primitive constructors call\n * this after each migration step and once on document creation.\n */\nexport function setDocVersion(doc: Record<string, unknown>, version: number): void {\n doc[SCHEMA_VERSION_FIELD] = version;\n}\n\n/**\n * Run any pending migrations on a document. Mutates the document in place.\n *\n * @throws {SchemaVersionError} with code `doc-ahead-of-app` if the document is\n * already at a version higher than the application's target.\n * @throws {SchemaVersionError} with code `missing-migration` if an intermediate\n * migration is missing from the registry.\n */\nexport function runMigrations(\n doc: Record<string, unknown>,\n targetVersion: number,\n migrations: Migrations\n): void {\n const current = getDocVersion(doc);\n if (current > targetVersion) {\n throw new SchemaVersionError(\n `Document is at schema version ${current} but the application targets ${targetVersion}. Upgrade the application to continue.`,\n \"doc-ahead-of-app\",\n { docVersion: current, targetVersion }\n );\n }\n for (let v = current + 1; v <= targetVersion; v++) {\n const migration = migrations[v];\n if (!migration) {\n throw new SchemaVersionError(\n `Missing migration for schema version ${v}. Migrations must be contiguous from ${current + 1} through ${targetVersion}.`,\n \"missing-migration\",\n { docVersion: current, targetVersion, missingVersion: v }\n );\n }\n migration(doc);\n setDocVersion(doc, v);\n }\n}\n\n/**\n * Result of an op-version compatibility check. Discriminated by the {@link compatible}\n * field so callers can switch cleanly.\n */\nexport type OpVersionCheck =\n | { compatible: true }\n | {\n compatible: false;\n reason: \"op-older-than-doc\" | \"op-newer-than-doc\";\n opVersion: number;\n docVersion: number;\n };\n\n/**\n * Check whether an incoming op's declared schema version is compatible with\n * the document's current version. Ops that match are applied; ops that are\n * older are rejected (the producing peer is behind and should migrate); ops\n * that are newer are also rejected (the current peer is behind and should\n * upgrade).\n */\nexport function checkOpVersion(opVersion: number, docVersion: number): OpVersionCheck {\n if (opVersion < docVersion) {\n return { compatible: false, reason: \"op-older-than-doc\", opVersion, docVersion };\n }\n if (opVersion > docVersion) {\n return { compatible: false, reason: \"op-newer-than-doc\", opVersion, docVersion };\n }\n return { compatible: true };\n}\n\n/**\n * Convenience wrapper around {@link checkOpVersion} that throws a structured\n * {@link SchemaVersionError} on incompatibility. Useful inside sync handlers\n * that want to surface the mismatch through their normal error pipeline.\n */\nexport function assertOpVersion(opVersion: number, docVersion: number): void {\n const result = checkOpVersion(opVersion, docVersion);\n if (result.compatible) return;\n const message =\n result.reason === \"op-older-than-doc\"\n ? `Incoming op was produced at schema version ${opVersion} but the document is at version ${docVersion}. The producing peer is behind.`\n : `Incoming op was produced at schema version ${opVersion} but the document is at version ${docVersion}. The current peer is behind and should upgrade.`;\n throw new SchemaVersionError(message, result.reason, { opVersion, docVersion });\n}\n",
|
|
11
|
-
"/**\n * crdt-state — base machinery for Polly's peer-first state primitives.\n *\n * This module is transport-agnostic: it takes a caller-supplied async factory\n * that produces a ready {@link DocHandle}, binds it bidirectionally to a\n * Preact signal, runs any pending schema migrations on load, and integrates\n * with the primitive-registry and migration-registry guards. Phase 1's\n * $peerState and Phase 2's $meshState both construct these base primitives\n * with their own handle factories — one over Automerge-Repo's WebSocket\n * client adapter, the other over WebRTC — and the base never knows which.\n *\n * The signal-to-handle binding uses an `updating` guard flag to prevent write\n * loops: when a local signal assignment runs the effect that pushes the value\n * into `handle.change`, the flag is raised so that the 'change' event the\n * handle fires back is ignored. The same flag protects in the other direction\n * when a remote change seeds the signal.\n *\n * For the Phase 0 cut, writes are applied with a naive top-level structural\n * replacement inside the `Automerge.change` block. This is correct for\n * JSON-shaped documents with scalar and flat-object fields and is good enough\n * to exercise the rest of the pipeline. The specialised variants for text,\n * counters, and lists (which require type-specific operation capture to\n * preserve concurrent-edit semantics) land in Phase 1's crdt-specialised.ts.\n */\n\nimport type { DocHandle } from \"@automerge/automerge-repo/slim\";\nimport { effect, signal } from \"@preact/signals\";\nimport type { Access } from \"./access\";\nimport { type MigratableState, MigrationError, migrationRegistry } from \"./migrate-primitive\";\nimport { type PrimitiveKind, primitiveRegistry } from \"./primitive-registry\";\nimport {\n type Migrations,\n runMigrations,\n SCHEMA_VERSION_FIELD,\n setDocVersion,\n type VersionedDoc,\n} from \"./schema-version\";\n\n/**\n * The interface a Polly peer-first primitive exposes at the call site. It\n * satisfies {@link MigratableState} so that the cross-primitive migration\n * helper can consume it directly.\n */\nexport interface CrdtPrimitive<T extends VersionedDoc> extends MigratableState<T> {\n /** Stable logical key the primitive was registered under. */\n readonly key: string;\n /** Primitive kind — one of the {@link PrimitiveKind} labels. */\n readonly primitive: PrimitiveKind;\n /** Current value. Writes push into the backing Automerge document. */\n value: T;\n /** Resolves when the handle is ready and migrations have run. */\n readonly loaded: Promise<void>;\n /** The underlying {@link DocHandle}, populated after {@link loaded} resolves.\n * Intended for advanced escape hatches; most callers should stay at the\n * signal surface. */\n readonly handle: DocHandle<T> | undefined;\n}\n\n/**\n * Options for constructing a base CRDT-backed primitive. Phase 1 and Phase 2\n * primitive constructors pass a transport-specific {@link getHandle} factory\n * and their own {@link primitive} label; everything else is shared.\n */\nexport interface CrdtStateOptions<T extends VersionedDoc> {\n /** Stable logical key identifying this piece of state. */\n key: string;\n /** Primitive kind label for registry and error-message purposes. */\n primitive: PrimitiveKind;\n /** Initial value if no stored document exists yet. Applied by the caller's\n * handle factory; the base module does not create documents itself. */\n initialValue: T;\n /** Async factory that resolves to a ready {@link DocHandle}. The factory is\n * responsible for repo lookup, document creation, and any transport-specific\n * setup. The base module calls this once, during hydration. */\n getHandle: () => Promise<DocHandle<T>>;\n /** Target schema version for the application. If set, migrations run on\n * load to bring the document up to this version before the signal hydrates. */\n schemaVersion?: number;\n /** Migration table. Ignored if {@link schemaVersion} is not set. */\n migrations?: Migrations;\n /** Declarative access predicates. Not consumed by the base module; the\n * transport-specific constructors compile it to their enforcement layer. */\n access?: Access;\n /** Optional free-text call-site label for primitive-registry error messages. */\n callSite?: string;\n}\n\n/**\n * Construct a base CRDT-backed Polly primitive. Integrates with\n * primitive-registry (for collision detection), migration-registry (for\n * cross-family migration guards), and schema-version (for on-load migrations).\n *\n * @throws {MigrationError} if the source key has been marked as migrated.\n * @throws {PrimitiveCollisionError} if the key is already registered under a\n * different primitive kind.\n */\nexport function $crdtState<T extends VersionedDoc>(options: CrdtStateOptions<T>): CrdtPrimitive<T> {\n if (migrationRegistry.isMarked(options.key, options.primitive)) {\n throw new MigrationError(\n `Cannot construct $${options.primitive}(\"${options.key}\"): this key has been marked as migrated. Migrations are one-way; use the destination primitive instead.`,\n \"already-migrated\",\n options.key,\n options.primitive\n );\n }\n primitiveRegistry.register(options.key, options.primitive, options.callSite);\n\n const inner = signal<T>(options.initialValue);\n let updating = false;\n let currentHandle: DocHandle<T> | undefined;\n\n const loaded = (async () => {\n const handle = await options.getHandle();\n await handle.whenReady();\n currentHandle = handle;\n\n // Run any pending schema migrations inside a change block so they land\n // as a single Automerge operation set.\n if (options.schemaVersion !== undefined) {\n const targetVersion = options.schemaVersion;\n const migrations = options.migrations ?? {};\n handle.change((doc) => {\n runMigrations(doc as unknown as Record<string, unknown>, targetVersion, migrations);\n // runMigrations stamps the version on every intermediate step; make\n // sure the final value is recorded even when no migrations ran.\n setDocVersion(doc as unknown as Record<string, unknown>, targetVersion);\n });\n }\n\n // Seed the signal with the hydrated doc state. Raise the guard first so\n // the 'change' listener we install below does not echo this write back.\n updating = true;\n try {\n inner.value = cloneDoc(handle.doc());\n } finally {\n updating = false;\n }\n\n // Remote-changes-to-signal binding.\n handle.on(\"change\", (payload) => {\n if (updating) return;\n updating = true;\n try {\n inner.value = cloneDoc(payload.doc);\n } finally {\n updating = false;\n }\n });\n\n // Signal-to-remote binding. The effect runs once on registration with\n // the already-hydrated value; the guard makes that first run a no-op at\n // the handle level because updating is false but the doc already equals\n // the signal, so Automerge records no new operations.\n effect(() => {\n const value = inner.value;\n if (updating) return;\n if (!currentHandle) return;\n updating = true;\n try {\n currentHandle.change((doc) => {\n applyTopLevel(doc as unknown as Record<string, unknown>, value);\n });\n } finally {\n updating = false;\n }\n });\n })();\n\n return {\n key: options.key,\n primitive: options.primitive,\n get value() {\n return inner.value;\n },\n set value(next: T) {\n inner.value = next;\n },\n loaded,\n get handle() {\n return currentHandle;\n },\n };\n}\n\n/**\n * Shallow clone of an Automerge doc into a plain JS object. Automerge docs\n * are Proxies; the signal holds a detached plain-object snapshot so that\n * application code does not accidentally mutate the CRDT through the signal.\n */\nfunction cloneDoc<T>(doc: T): T {\n return JSON.parse(JSON.stringify(doc)) as T;\n}\n\n/**\n * Copy every top-level field from the incoming value onto the Automerge doc.\n * This is the naive Phase 0 write path: correct for flat JSON-shaped documents\n * and good enough for the base module's tests. Specialised primitives in\n * Phase 1 will replace this with type-aware operation capture for text,\n * counters, and lists.\n *\n * The reserved schema-version field is not copied — it is managed by the\n * migration subsystem and must not be overwritten by application writes.\n */\nfunction applyTopLevel<T extends VersionedDoc>(doc: Record<string, unknown>, value: T): void {\n for (const key of Object.keys(value)) {\n if (key === SCHEMA_VERSION_FIELD) continue;\n doc[key] = (value as unknown as Record<string, unknown>)[key];\n }\n}\n",
|
|
11
|
+
"/**\n * crdt-state — base machinery for Polly's peer-first state primitives.\n *\n * This module is transport-agnostic: it takes a caller-supplied async factory\n * that produces a ready {@link DocHandle}, binds it bidirectionally to a\n * Preact signal, runs any pending schema migrations on load, and integrates\n * with the primitive-registry and migration-registry guards. Phase 1's\n * $peerState and Phase 2's $meshState both construct these base primitives\n * with their own handle factories — one over Automerge-Repo's WebSocket\n * client adapter, the other over WebRTC — and the base never knows which.\n *\n * The signal-to-handle binding uses an `updating` guard flag to prevent write\n * loops: when a local signal assignment runs the effect that pushes the value\n * into `handle.change`, the flag is raised so that the 'change' event the\n * handle fires back is ignored. The same flag protects in the other direction\n * when a remote change seeds the signal.\n *\n * For the Phase 0 cut, writes are applied with a naive top-level structural\n * replacement inside the `Automerge.change` block. This is correct for\n * JSON-shaped documents with scalar and flat-object fields and is good enough\n * to exercise the rest of the pipeline. The specialised variants for text,\n * counters, and lists (which require type-specific operation capture to\n * preserve concurrent-edit semantics) land in Phase 1's crdt-specialised.ts.\n */\n\nimport type { DocHandle } from \"@automerge/automerge-repo/slim\";\nimport { effect, signal } from \"@preact/signals\";\nimport type { Access } from \"./access\";\nimport { type MigratableState, MigrationError, migrationRegistry } from \"./migrate-primitive\";\nimport { type PrimitiveKind, primitiveRegistry } from \"./primitive-registry\";\nimport {\n type Migrations,\n runMigrations,\n SCHEMA_VERSION_FIELD,\n setDocVersion,\n type VersionedDoc,\n} from \"./schema-version\";\n\n/**\n * The interface a Polly peer-first primitive exposes at the call site. It\n * satisfies {@link MigratableState} so that the cross-primitive migration\n * helper can consume it directly.\n */\nexport interface CrdtPrimitive<T extends VersionedDoc> extends MigratableState<T> {\n /** Stable logical key the primitive was registered under. */\n readonly key: string;\n /** Primitive kind — one of the {@link PrimitiveKind} labels. */\n readonly primitive: PrimitiveKind;\n /** Current value. Writes push into the backing Automerge document. */\n value: T;\n /** Resolves when the handle is ready and migrations have run. */\n readonly loaded: Promise<void>;\n /** The underlying {@link DocHandle}, populated after {@link loaded} resolves.\n * Intended for advanced escape hatches; most callers should stay at the\n * signal surface. */\n readonly handle: DocHandle<T> | undefined;\n}\n\n/**\n * Options for constructing a base CRDT-backed primitive. Phase 1 and Phase 2\n * primitive constructors pass a transport-specific {@link getHandle} factory\n * and their own {@link primitive} label; everything else is shared.\n */\nexport interface CrdtStateOptions<T extends VersionedDoc> {\n /** Stable logical key identifying this piece of state. */\n key: string;\n /** Primitive kind label for registry and error-message purposes. */\n primitive: PrimitiveKind;\n /** Initial value if no stored document exists yet. Applied by the caller's\n * handle factory; the base module does not create documents itself. */\n initialValue: T;\n /** Async factory that resolves to a ready {@link DocHandle}. The factory is\n * responsible for repo lookup, document creation, and any transport-specific\n * setup. The base module calls this once, during hydration. */\n getHandle: () => Promise<DocHandle<T>>;\n /** Target schema version for the application. If set, migrations run on\n * load to bring the document up to this version before the signal hydrates. */\n schemaVersion?: number;\n /** Migration table. Ignored if {@link schemaVersion} is not set. */\n migrations?: Migrations;\n /** Declarative access predicates. Not consumed by the base module; the\n * transport-specific constructors compile it to their enforcement layer. */\n access?: Access;\n /** Optional free-text call-site label for primitive-registry error messages. */\n callSite?: string;\n}\n\n/**\n * Construct a base CRDT-backed Polly primitive. Integrates with\n * primitive-registry (for collision detection), migration-registry (for\n * cross-family migration guards), and schema-version (for on-load migrations).\n *\n * @throws {MigrationError} if the source key has been marked as migrated.\n * @throws {PrimitiveCollisionError} if the key is already registered under a\n * different primitive kind.\n */\nexport function $crdtState<T extends VersionedDoc>(options: CrdtStateOptions<T>): CrdtPrimitive<T> {\n if (migrationRegistry.isMarked(options.key, options.primitive)) {\n throw new MigrationError(\n `Cannot construct $${options.primitive}(\"${options.key}\"): this key has been marked as migrated. Migrations are one-way; use the destination primitive instead.`,\n \"already-migrated\",\n options.key,\n options.primitive\n );\n }\n primitiveRegistry.register(options.key, options.primitive, options.callSite);\n\n const inner = signal<T>(options.initialValue);\n let updating = false;\n let currentHandle: DocHandle<T> | undefined;\n\n const loaded = (async () => {\n const handle = await options.getHandle();\n await handle.whenReady();\n currentHandle = handle;\n\n // Run any pending schema migrations inside a change block so they land\n // as a single Automerge operation set.\n if (options.schemaVersion !== undefined) {\n const targetVersion = options.schemaVersion;\n const migrations = options.migrations ?? {};\n handle.change((doc) => {\n runMigrations(doc as unknown as Record<string, unknown>, targetVersion, migrations);\n // runMigrations stamps the version on every intermediate step; make\n // sure the final value is recorded even when no migrations ran.\n setDocVersion(doc as unknown as Record<string, unknown>, targetVersion);\n });\n }\n\n // Seed the signal with the hydrated doc state. Raise the guard first so\n // the 'change' listener we install below does not echo this write back.\n updating = true;\n try {\n inner.value = cloneDoc(handle.doc());\n } finally {\n updating = false;\n }\n\n // Remote-changes-to-signal binding.\n handle.on(\"change\", (payload) => {\n if (updating) return;\n updating = true;\n try {\n inner.value = cloneDoc(payload.doc);\n } finally {\n updating = false;\n }\n });\n\n // Signal-to-remote binding. The effect runs once on registration with\n // the already-hydrated value; the guard makes that first run a no-op at\n // the handle level because updating is false but the doc already equals\n // the signal, so Automerge records no new operations.\n effect(() => {\n const value = inner.value;\n if (updating) return;\n if (!currentHandle) return;\n updating = true;\n try {\n currentHandle.change((doc) => {\n applyTopLevel(doc as unknown as Record<string, unknown>, value);\n });\n } finally {\n updating = false;\n }\n });\n })();\n\n return {\n key: options.key,\n primitive: options.primitive,\n get value() {\n return inner.value;\n },\n set value(next: T) {\n inner.value = next;\n },\n loaded,\n get handle() {\n return currentHandle;\n },\n };\n}\n\n/**\n * Shallow clone of an Automerge doc into a plain JS object. Automerge docs\n * are Proxies; the signal holds a detached plain-object snapshot so that\n * application code does not accidentally mutate the CRDT through the signal.\n */\nfunction cloneDoc<T>(doc: T): T {\n return JSON.parse(JSON.stringify(doc)) as T;\n}\n\n/**\n * Copy every top-level field from the incoming value onto the Automerge doc\n * — but only for fields whose serialised form actually differs from what's\n * already there. The equality skip is load-bearing, not an optimisation:\n *\n * - Automerge records a new operation for every assignment (`doc[k] = v`),\n * even when v is structurally identical to the current value.\n * - Every op triggers a state-machine transition, which via\n * `#checkForChanges` fires a `change` event, which the signal binding\n * above handles by setting `inner.value = cloneDoc(...)`.\n * - Under certain event-loop timings — most consistently on bun — preact\n * signals' synchronous effect propagation re-runs this write path with\n * the just-cloned value, which compares ref-different to the previous\n * signal value, so the effect doesn't short-circuit, so applyTopLevel\n * runs again, so more ops are recorded, and the whole chain loops until\n * preact's own cycle counter trips with \"Cycle detected\".\n *\n * Skipping value-equal assignments makes the write a true no-op at the\n * Automerge level, which makes `docChanged` in `#checkForChanges` false,\n * which skips the change emission, which breaks the loop at its origin.\n * Browsers mask this under typical interactive timing; a tight CLI boot\n * reproduces it every time.\n *\n * The reserved schema-version field is not copied — it is managed by the\n * migration subsystem and must not be overwritten by application writes.\n */\nfunction applyTopLevel<T extends VersionedDoc>(doc: Record<string, unknown>, value: T): void {\n const source = value as unknown as Record<string, unknown>;\n for (const key of Object.keys(value)) {\n if (key === SCHEMA_VERSION_FIELD) continue;\n const incoming = source[key];\n if (fieldEquals(doc[key], incoming)) continue;\n doc[key] = incoming;\n }\n}\n\n/** Structural equality check for the top-level-field comparison. JSON.stringify\n * round-trip because Automerge docs are Proxies and `===` would miss a match\n * when the proxy wraps an equal value. Arrays, objects, and primitives all\n * round-trip cleanly for the CRDT-state use case. Cycles in the input aren't\n * supported (neither is Automerge — it refuses cyclic structures). */\nfunction fieldEquals(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n try {\n return JSON.stringify(a) === JSON.stringify(b);\n } catch {\n return false;\n }\n}\n",
|
|
12
12
|
"/**\n * peer-relay-adapter — Phase 1 client helper for connecting a Polly $peerState\n * application to an Automerge-Repo relay server over WebSocket.\n *\n * The Phase 0 base $crdtState and the Phase 1 $peerState wrapper both consume\n * a caller-supplied `Repo` via `configurePeerState`. This module provides the\n * one-call factory that builds a Repo wired to the relay transport: a\n * `WebSocketClientAdapter` from `@automerge/automerge-repo-network-websocket`\n * pointed at the server URL, an `IndexedDBStorageAdapter` for client-side\n * persistence, and a Polly-shaped connection-state signal that the application\n * can render as a diagnostic UI or feed into reconnection logic.\n *\n * The mirror server-side factory is in {@link peer-repo-server}.\n *\n * @example\n * ```ts\n * import { configurePeerState } from \"@fairfox/polly\";\n * import { createPeerStateClient } from \"@fairfox/polly\";\n *\n * const { repo, connectionState } = await createPeerStateClient({\n * url: \"wss://yourapp.example.com/polly/peer\",\n * });\n * configurePeerState(repo);\n *\n * // connectionState is a Signal<\"connecting\" | \"connected\" | \"disconnected\">\n * ```\n */\n\nimport { type NetworkAdapterInterface, Repo } from \"@automerge/automerge-repo/slim\";\nimport { WebSocketClientAdapter } from \"@automerge/automerge-repo-network-websocket\";\nimport { type Signal, signal } from \"@preact/signals\";\nimport { type MeshKeyring, MeshNetworkAdapter } from \"./mesh-network-adapter\";\n\nexport type PeerRelayConnectionState = \"connecting\" | \"connected\" | \"disconnected\";\n\nexport interface CreatePeerStateClientOptions {\n /** WebSocket URL of the Polly peer-relay server. Use `ws://` for local\n * development and `wss://` for any deployment that terminates TLS. */\n url: string;\n /** Reconnect interval in milliseconds. Defaults to Automerge-Repo's own\n * default (5 seconds at the time of writing). */\n retryInterval?: number;\n /** Optional storage adapter. Applications running in a browser typically\n * pass an `IndexedDBStorageAdapter`; tests pass nothing for a local-only\n * Repo. The default is no storage, which keeps the client purely in-memory. */\n storage?: ConstructorParameters<typeof Repo>[0] extends infer C\n ? C extends { storage?: infer S }\n ? S\n : never\n : never;\n /** Enable Ed25519 signing on every sync message. Adds Byzantine defence:\n * a compromised client cannot push unsigned writes through the relay.\n * Requires a keyring with the local peer's signing identity and the\n * public keys of peers whose ops should be accepted. The server can\n * still read and mutate document contents because the payload is\n * signed, not encrypted. */\n sign?: boolean;\n /** Keyring for the signing layer. Required when `sign` is true. */\n keyring?: MeshKeyring;\n}\n\nexport interface PeerStateClient {\n /** A configured Repo backed by the WebSocket relay. Pass to\n * {@link configurePeerState}. */\n repo: Repo;\n /** Reactive connection state. Updates as the underlying WebSocket opens,\n * closes, and reconnects. */\n connectionState: Signal<PeerRelayConnectionState>;\n /** The underlying network adapter, exposed for advanced use. */\n adapter: WebSocketClientAdapter;\n /** True if the client was constructed with `sign: true`. Used by\n * $peerState primitives to validate per-primitive sign options. */\n signEnabled: boolean;\n /** Disconnect from the relay and tear down the Repo. Awaiting the\n * returned promise drains the Repo's subsystems cleanly. */\n close: () => Promise<void>;\n}\n\n/**\n * Construct a Polly-flavoured client for the peer-relay transport.\n *\n * The returned object includes the Repo, a connection-state signal, the\n * underlying network adapter, and a close function. Production code typically\n * passes the Repo to {@link configurePeerState} and renders the connection\n * state somewhere visible.\n */\nexport function createPeerStateClient(options: CreatePeerStateClientOptions): PeerStateClient {\n if (options.sign && !options.keyring) {\n throw new Error(\n \"Polly createPeerStateClient: { sign: true } requires a keyring. Pass { keyring: { identity, knownPeers, documentKeys: new Map(), revokedPeers: new Set() } } to enable signing.\"\n );\n }\n\n const adapter = new WebSocketClientAdapter(options.url, options.retryInterval);\n const connectionState = signal<PeerRelayConnectionState>(\"connecting\");\n\n // The WebSocketClientAdapter is itself an EventEmitter (via Automerge's\n // NetworkAdapter base class) and emits 'peer-candidate' / 'peer-disconnected'\n // events. We track the simpler open/close lifecycle by listening to those.\n adapter.on(\"peer-candidate\", () => {\n connectionState.value = \"connected\";\n });\n adapter.on(\"peer-disconnected\", () => {\n connectionState.value = \"disconnected\";\n });\n adapter.on(\"close\", () => {\n connectionState.value = \"disconnected\";\n });\n\n // When signing is enabled, wrap the WebSocket adapter with a sign-only\n // MeshNetworkAdapter. This signs every outgoing message but does NOT\n // encrypt, so the relay server can still parse Automerge sync messages\n // and participate as a full peer (cron, HTTP handlers, etc.).\n const networkAdapter: NetworkAdapterInterface =\n options.sign && options.keyring\n ? new MeshNetworkAdapter({\n base: adapter,\n keyring: options.keyring,\n encryptionEnabled: false,\n })\n : adapter;\n\n const repo = new Repo({\n network: [networkAdapter],\n ...(options.storage !== undefined && { storage: options.storage }),\n });\n\n return {\n repo,\n connectionState,\n adapter,\n signEnabled: options.sign === true,\n close: async () => {\n await repo.shutdown();\n },\n };\n}\n",
|
|
13
13
|
"/**\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/slim\";\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",
|
|
14
14
|
"/**\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",
|
|
15
15
|
"/**\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\n// Heavy peer-relay dependencies (@automerge/automerge-repo, ws) are dynamic\n// imports loaded only when createPeerRepoServer is actually called. Static\n// imports at this file's top level were hoisted into @fairfox/polly/elysia's\n// module-init chain, breaking Elysia apps that don't use peer state and\n// don't install the automerge peer deps. Types come from the static package\n// references — TypeScript only reads them for shape, so no runtime cost is\n// incurred.\nimport type { Repo as RepoType } from \"@automerge/automerge-repo/slim\";\nimport type { WebSocketServerAdapter as WebSocketServerAdapterType } from \"@automerge/automerge-repo-network-websocket\";\nimport type { NodeFSStorageAdapter as NodeFSStorageAdapterType } from \"@automerge/automerge-repo-storage-nodefs\";\nimport type * as wsType 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 = wsType.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: RepoType;\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: WebSocketServerAdapterType;\n /** The NodeFS storage adapter writing to {@link CreatePeerRepoServerOptions.storagePath}. */\n storage: NodeFSStorageAdapterType;\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 // Dynamic imports keep automerge-repo and ws out of the static module\n // graph. Apps that never call this function — which is most of them —\n // never pay the dependency cost and don't need the peer packages\n // installed at all.\n const [{ Repo }, { WebSocketServerAdapter }, { NodeFSStorageAdapter }, ws] = await Promise.all([\n import(\"@automerge/automerge-repo/slim\"),\n import(\"@automerge/automerge-repo-network-websocket\"),\n import(\"@automerge/automerge-repo-storage-nodefs\"),\n import(\"ws\"),\n ]);\n\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",
|
|
16
16
|
"/**\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/slim\";\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"
|
|
17
17
|
],
|
|
18
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA;AA+BO,SAAS,mBAAmB,GAAe;AAAA,EAChD,OAAO,KAAK,YAAY,SAAS;AAAA;AAQ5B,SAAS,OAAO,CAAC,SAAqB,KAA8B;AAAA,EACzE,IAAI,IAAI,WAAW,WAAW;AAAA,IAC5B,MAAM,IAAI,gBACR,yBAAyB,wBAAwB,IAAI,WACrD,oBACF;AAAA,EACF;AAAA,EACA,MAAM,QAAQ,KAAK,YAAY,WAAW;AAAA,EAC1C,MAAM,aAAa,KAAK,UAAU,SAAS,OAAO,GAAG;AAAA,EACrD,MAAM,MAAM,IAAI,WAAW,cAAc,WAAW,MAAM;AAAA,EAC1D,IAAI,IAAI,OAAO,CAAC;AAAA,EAChB,IAAI,IAAI,YAAY,WAAW;AAAA,EAC/B,OAAO;AAAA;AAcF,SAAS,OAAO,CAAC,QAAqB,KAAyC;AAAA,EACpF,IAAI,IAAI,WAAW,WAAW;AAAA,IAC5B,MAA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AAO,aAAa,CAAC;AAAA,IAC5E,eAAe,QAAQ;AAAA,IACvB,YAAY,QAAQ;AAAA,IACpB,QAAQ,QAAQ;AAAA,EAClB,CAAC;AAAA;",
|
|
19
|
+
"debugId": "3A93C353C75A704E64756E2164756E21",
|
|
20
20
|
"names": []
|
|
21
21
|
}
|
|
@@ -838,6 +838,222 @@ async function checkNoAsCasting(options) {
|
|
|
838
838
|
}
|
|
839
839
|
return { violations, print: () => printViolations(violations) };
|
|
840
840
|
}
|
|
841
|
+
// tools/quality/src/no-require.ts
|
|
842
|
+
import { readFileSync as readFileSync2 } from "node:fs";
|
|
843
|
+
import { Glob as Glob2 } from "bun";
|
|
844
|
+
function isLineRequireClean(line) {
|
|
845
|
+
if (!line.includes("require")) {
|
|
846
|
+
return true;
|
|
847
|
+
}
|
|
848
|
+
const trimmed = line.trim();
|
|
849
|
+
if (trimmed.startsWith("//") || trimmed.startsWith("*") || trimmed.startsWith("/*")) {
|
|
850
|
+
return true;
|
|
851
|
+
}
|
|
852
|
+
const match = line.match(/\brequire\s*\(/);
|
|
853
|
+
if (!match || match.index === undefined) {
|
|
854
|
+
return true;
|
|
855
|
+
}
|
|
856
|
+
if (line.slice(0, match.index + 8).endsWith("require.resolve(")) {
|
|
857
|
+
return true;
|
|
858
|
+
}
|
|
859
|
+
const before = line.slice(0, match.index);
|
|
860
|
+
const singles = (before.match(/(?<!\\)'/g) ?? []).length;
|
|
861
|
+
const doubles = (before.match(/(?<!\\)"/g) ?? []).length;
|
|
862
|
+
const backticks = (before.match(/(?<!\\)`/g) ?? []).length;
|
|
863
|
+
if (singles % 2 === 1 || doubles % 2 === 1 || backticks % 2 === 1) {
|
|
864
|
+
return true;
|
|
865
|
+
}
|
|
866
|
+
const commentIdx = line.indexOf("//");
|
|
867
|
+
if (commentIdx >= 0 && match.index > commentIdx) {
|
|
868
|
+
return true;
|
|
869
|
+
}
|
|
870
|
+
return false;
|
|
871
|
+
}
|
|
872
|
+
function findRequireViolations(relative3, content) {
|
|
873
|
+
const results = [];
|
|
874
|
+
const lines = content.split(`
|
|
875
|
+
`);
|
|
876
|
+
let insideTemplate = false;
|
|
877
|
+
for (let i = 0;i < lines.length; i++) {
|
|
878
|
+
const line = lines[i] ?? "";
|
|
879
|
+
const backticks = (line.match(/`/g) ?? []).length;
|
|
880
|
+
const startedInTemplate = insideTemplate;
|
|
881
|
+
if (backticks % 2 === 1) {
|
|
882
|
+
insideTemplate = !insideTemplate;
|
|
883
|
+
}
|
|
884
|
+
if (startedInTemplate && backticks === 0 && !line.includes("${")) {
|
|
885
|
+
continue;
|
|
886
|
+
}
|
|
887
|
+
if (!isLineRequireClean(line)) {
|
|
888
|
+
results.push({ file: relative3, line: i + 1, content: line.trim() });
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
return results;
|
|
892
|
+
}
|
|
893
|
+
function printRequireViolations(violations) {
|
|
894
|
+
if (violations.length === 0) {
|
|
895
|
+
logger.log("[no-require] ✅ No violations found.");
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
logger.log(`[no-require] ❌ ${violations.length} violation(s) found:
|
|
899
|
+
`);
|
|
900
|
+
for (const v of violations) {
|
|
901
|
+
logger.log(` ${v.file}:${v.line}`);
|
|
902
|
+
logger.log(` ${v.content}`);
|
|
903
|
+
logger.log("");
|
|
904
|
+
}
|
|
905
|
+
logger.log("[no-require] Replace with static ES imports or `await import(...)` for lazy ESM.");
|
|
906
|
+
}
|
|
907
|
+
async function checkNoRequire(options) {
|
|
908
|
+
const rootDir = options.rootDir;
|
|
909
|
+
const excludeDirs = new Set(options.exclude ?? ["node_modules", "dist", ".git", ".bun"]);
|
|
910
|
+
const pattern = options.filePatterns ?? "**/*.{ts,tsx}";
|
|
911
|
+
const glob = new Glob2(pattern);
|
|
912
|
+
const violations = [];
|
|
913
|
+
for await (const file of glob.scan({ cwd: rootDir, absolute: true })) {
|
|
914
|
+
const relative3 = file.replace(`${rootDir}/`, "");
|
|
915
|
+
const segments = relative3.split("/");
|
|
916
|
+
if (segments.some((s) => excludeDirs.has(s))) {
|
|
917
|
+
continue;
|
|
918
|
+
}
|
|
919
|
+
const content = readFileSync2(file, "utf-8");
|
|
920
|
+
violations.push(...findRequireViolations(relative3, content));
|
|
921
|
+
}
|
|
922
|
+
return {
|
|
923
|
+
violations,
|
|
924
|
+
print: () => printRequireViolations(violations)
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
// tools/quality/src/secrets.ts
|
|
928
|
+
import { readFile } from "node:fs/promises";
|
|
929
|
+
import { join as join3 } from "node:path";
|
|
930
|
+
var defaultWrite = (msg) => logger.error(msg);
|
|
931
|
+
async function checkSecrets(options) {
|
|
932
|
+
const which = Bun.spawn(["which", "gitleaks"], {
|
|
933
|
+
stdout: "ignore",
|
|
934
|
+
stderr: "ignore"
|
|
935
|
+
});
|
|
936
|
+
await which.exited;
|
|
937
|
+
if (which.exitCode !== 0) {
|
|
938
|
+
return {
|
|
939
|
+
binaryFound: false,
|
|
940
|
+
exitCode: null,
|
|
941
|
+
output: "",
|
|
942
|
+
print: (write = defaultWrite) => {
|
|
943
|
+
write("gitleaks is not on PATH. Install with `brew install gitleaks` (macOS) or from https://github.com/gitleaks/gitleaks/releases.");
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
const args = ["gitleaks", "detect", "--source", options.root ?? "."];
|
|
948
|
+
if (options.noGit !== false) {
|
|
949
|
+
args.push("--no-git");
|
|
950
|
+
}
|
|
951
|
+
if (options.configPath) {
|
|
952
|
+
args.push("-c", options.configPath);
|
|
953
|
+
}
|
|
954
|
+
const proc = Bun.spawn(args, {
|
|
955
|
+
cwd: options.root,
|
|
956
|
+
stdout: "pipe",
|
|
957
|
+
stderr: "pipe"
|
|
958
|
+
});
|
|
959
|
+
const [stdout, stderr] = await Promise.all([
|
|
960
|
+
new Response(proc.stdout).text(),
|
|
961
|
+
new Response(proc.stderr).text()
|
|
962
|
+
]);
|
|
963
|
+
await proc.exited;
|
|
964
|
+
const output = `${stdout}${stderr}`;
|
|
965
|
+
return {
|
|
966
|
+
binaryFound: true,
|
|
967
|
+
exitCode: proc.exitCode,
|
|
968
|
+
output,
|
|
969
|
+
print: (write = defaultWrite) => {
|
|
970
|
+
if (output) {
|
|
971
|
+
write(output);
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
function parseRequiredPaths(toml, starts, ends) {
|
|
977
|
+
const required = [];
|
|
978
|
+
let inSection = false;
|
|
979
|
+
for (const line of toml.split(`
|
|
980
|
+
`)) {
|
|
981
|
+
if (starts.some((m) => line.includes(m))) {
|
|
982
|
+
inSection = true;
|
|
983
|
+
continue;
|
|
984
|
+
}
|
|
985
|
+
if (ends.some((m) => line.includes(m))) {
|
|
986
|
+
inSection = false;
|
|
987
|
+
continue;
|
|
988
|
+
}
|
|
989
|
+
if (!inSection) {
|
|
990
|
+
continue;
|
|
991
|
+
}
|
|
992
|
+
const match = line.match(/'''(.+?)'''/);
|
|
993
|
+
if (!match?.[1]) {
|
|
994
|
+
continue;
|
|
995
|
+
}
|
|
996
|
+
required.push(match[1].replace(/\\\./g, ".").replace(/\$$/, ""));
|
|
997
|
+
}
|
|
998
|
+
return required;
|
|
999
|
+
}
|
|
1000
|
+
function gitignoreLineCovers(giLine, filename) {
|
|
1001
|
+
if (!giLine || giLine.startsWith("#")) {
|
|
1002
|
+
return false;
|
|
1003
|
+
}
|
|
1004
|
+
if (giLine === filename) {
|
|
1005
|
+
return true;
|
|
1006
|
+
}
|
|
1007
|
+
const dirMatch = giLine.match(/^\*?\*?\/?(.+)\/$/);
|
|
1008
|
+
if (dirMatch?.[1] && filename.startsWith(dirMatch[1])) {
|
|
1009
|
+
return true;
|
|
1010
|
+
}
|
|
1011
|
+
if (giLine.endsWith("/") && filename.startsWith(giLine)) {
|
|
1012
|
+
return true;
|
|
1013
|
+
}
|
|
1014
|
+
return false;
|
|
1015
|
+
}
|
|
1016
|
+
var emptyGitignoreResult = {
|
|
1017
|
+
missing: [],
|
|
1018
|
+
required: [],
|
|
1019
|
+
print: () => {}
|
|
1020
|
+
};
|
|
1021
|
+
async function checkGitignoreCoversAllowlist(options) {
|
|
1022
|
+
const tomlPath = join3(options.root, options.tomlPath ?? ".gitleaks.toml");
|
|
1023
|
+
const gitignorePath = join3(options.root, options.gitignorePath ?? ".gitignore");
|
|
1024
|
+
const starts = options.sectionStartMarkers ?? ["Gitignored files", "Local dev TLS certs"];
|
|
1025
|
+
const ends = options.sectionEndMarkers ?? ["Test fixtures"];
|
|
1026
|
+
let toml;
|
|
1027
|
+
try {
|
|
1028
|
+
toml = await readFile(tomlPath, "utf8");
|
|
1029
|
+
} catch {
|
|
1030
|
+
return emptyGitignoreResult;
|
|
1031
|
+
}
|
|
1032
|
+
let gitignore;
|
|
1033
|
+
try {
|
|
1034
|
+
gitignore = await readFile(gitignorePath, "utf8");
|
|
1035
|
+
} catch {
|
|
1036
|
+
gitignore = "";
|
|
1037
|
+
}
|
|
1038
|
+
const required = parseRequiredPaths(toml, starts, ends);
|
|
1039
|
+
const gitignoreLines = gitignore.split(`
|
|
1040
|
+
`).map((l) => l.trim());
|
|
1041
|
+
const missing = required.filter((filename) => !gitignoreLines.some((gi) => gitignoreLineCovers(gi, filename)));
|
|
1042
|
+
return {
|
|
1043
|
+
missing,
|
|
1044
|
+
required,
|
|
1045
|
+
print: (write = defaultWrite) => {
|
|
1046
|
+
if (missing.length === 0) {
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
write("Paths allowed by .gitleaks.toml are NOT covered by .gitignore:");
|
|
1050
|
+
for (const f of missing) {
|
|
1051
|
+
write(` ${f}`);
|
|
1052
|
+
}
|
|
1053
|
+
write("These files may contain secrets. Add them to .gitignore so the allowlist entry doesn't become a hiding place.");
|
|
1054
|
+
}
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
841
1057
|
// tools/quality/src/cli.ts
|
|
842
1058
|
var args = process.argv.slice(2);
|
|
843
1059
|
function getFlag(name) {
|
|
@@ -876,6 +1092,15 @@ async function runNoAsCasting() {
|
|
|
876
1092
|
result.print();
|
|
877
1093
|
return result.violations.length > 0 ? 1 : 0;
|
|
878
1094
|
}
|
|
1095
|
+
async function runNoRequire() {
|
|
1096
|
+
const result = await checkNoRequire({
|
|
1097
|
+
rootDir,
|
|
1098
|
+
exclude,
|
|
1099
|
+
...filePatterns ? { filePatterns } : {}
|
|
1100
|
+
});
|
|
1101
|
+
result.print();
|
|
1102
|
+
return result.violations.length > 0 ? 1 : 0;
|
|
1103
|
+
}
|
|
879
1104
|
async function runCssQuality() {
|
|
880
1105
|
const r = await checkCssQuality({ rootDir, skipDirs: exclude });
|
|
881
1106
|
r.print();
|
|
@@ -906,7 +1131,7 @@ async function runCssAll() {
|
|
|
906
1131
|
return results.some((code) => code !== 0) ? 1 : 0;
|
|
907
1132
|
}
|
|
908
1133
|
async function runAll() {
|
|
909
|
-
const results = [await runNoAsCasting(), await runCssAll()];
|
|
1134
|
+
const results = [await runNoAsCasting(), await runNoRequire(), await runCssAll()];
|
|
910
1135
|
return results.some((code) => code !== 0) ? 1 : 0;
|
|
911
1136
|
}
|
|
912
1137
|
var exitCode = 0;
|
|
@@ -914,6 +1139,9 @@ switch (subcommand) {
|
|
|
914
1139
|
case "no-as-casting":
|
|
915
1140
|
exitCode = await runNoAsCasting();
|
|
916
1141
|
break;
|
|
1142
|
+
case "no-require":
|
|
1143
|
+
exitCode = await runNoRequire();
|
|
1144
|
+
break;
|
|
917
1145
|
case "css":
|
|
918
1146
|
exitCode = await runCssAll();
|
|
919
1147
|
break;
|
|
@@ -934,9 +1162,9 @@ switch (subcommand) {
|
|
|
934
1162
|
break;
|
|
935
1163
|
default:
|
|
936
1164
|
logger.error(`Unknown quality subcommand: ${subcommand}`);
|
|
937
|
-
logger.error("Expected one of: no-as-casting, css, css-quality, css-layout, css-vars, css-unused");
|
|
1165
|
+
logger.error("Expected one of: no-as-casting, no-require, css, css-quality, css-layout, css-vars, css-unused");
|
|
938
1166
|
exitCode = 2;
|
|
939
1167
|
}
|
|
940
1168
|
process.exit(exitCode);
|
|
941
1169
|
|
|
942
|
-
//# debugId=
|
|
1170
|
+
//# debugId=886844E82815890D64756E2164756E21
|