// fixtures/generate-peer-updates.mjs — a peer's // typing, for the native realtime audit's UI probe: Yjs updates // from client 999, each inserting one "Z" after the previous one, in a // paragraph in the middle of the seed document. Written as 0.bin, 1.bin… import * as Y from 'yjs' import { readFileSync, writeFileSync, mkdirSync } from 'node:fs' const [seed, countArg = '30', outdir = '/tmp/docs-peer'] = process.argv.slice(2) const doc = new Y.Doc() doc.clientID = 999 Y.applyUpdate(doc, readFileSync(seed)) const root = doc.getXmlFragment('prosemirror') const blocks = root.toArray() let text = null for (let i = Math.floor(blocks.length / 2); i < blocks.length && !text; i++) { const first = blocks[i].toArray ? blocks[i].toArray()[0] : null if (blocks[i].nodeName === 'paragraph' && first instanceof Y.XmlText && first.length > 40) text = first } if (!text) throw new Error('no paragraph to type into') mkdirSync(outdir, { recursive: true }) const at = 20 for (let k = 0; k < Number(countArg); k++) { const before = Y.encodeStateVector(doc) text.insert(at + k, 'Z') writeFileSync(`${outdir}/${k}.bin`, Y.encodeStateAsUpdate(doc, before)) } console.log(JSON.stringify({ count: Number(countArg), outdir }))