oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

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