{"_id":"@ai-path/lattica-collab","_rev":"2-456f11c7bcb4209d4beb7b418173f80d","name":"@ai-path/lattica-collab","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@ai-path/lattica-collab","version":"0.1.0","license":"MIT","_id":"@ai-path/lattica-collab@0.1.0","maintainers":[{"name":"fsakurai","email":"f-sakurai@ai-path.jp"}],"dist":{"shasum":"01f3eecc5cc991754b806902885acab5a6f5b87c","tarball":"https://registry.npmjs.org/@ai-path/lattica-collab/-/lattica-collab-0.1.0.tgz","fileCount":9,"integrity":"sha512-IxNOc8NCJufabpuxW2ySdF1KgekUvt0pUwjdHyo/B0DQDvXim6M+sfvM/bmIWNlOD2Uygfk8+NEWiTgIDAyD2Q==","signatures":[{"sig":"MEQCIBKM2rK/73T9yZr16mAewuhUFTgHgTfrrLPgeytr7QW3AiAAkW+95ZFllSrhQ1prhXj/esnAZ+L1Oto1OO8EvNYB1g==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":80716},"main":"./dist/index.cjs","type":"module","_from":"file:ai-path-lattica-collab-0.1.0.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"scripts":{"build":"tsup","typecheck":"tsc --noEmit"},"_npmUser":{"name":"fsakurai","email":"f-sakurai@ai-path.jp"},"_resolved":"/private/var/folders/tf/0c43660d4k1dg4ssxq0n63ww0000gn/T/51fb95e362985063352b1fba80edc9af/ai-path-lattica-collab-0.1.0.tgz","_integrity":"sha512-IxNOc8NCJufabpuxW2ySdF1KgekUvt0pUwjdHyo/B0DQDvXim6M+sfvM/bmIWNlOD2Uygfk8+NEWiTgIDAyD2Q==","_npmVersion":"10.9.3","description":"Realtime collaboration primitives for Lattica: a table-specific LWW CRDT, fractional indexing for stable row/column order, presence, and a transport abstraction.","directories":{},"sideEffects":false,"_nodeVersion":"22.18.0","dependencies":{"@ai-path/lattica-core":"0.1.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/lattica-collab_0.1.0_1783177105358_0.8681088450289798","host":"s3://npm-registry-packages-npm-production"},"deprecated":"Renamed to @ai-path/tb-collab (product: Taible). Install @ai-path/tb-collab instead."}},"time":{"created":"2026-07-04T14:58:25.117Z","modified":"2026-07-04T16:08:48.622Z","0.1.0":"2026-07-04T14:58:25.494Z"},"license":"MIT","description":"Realtime collaboration primitives for Lattica: a table-specific LWW CRDT, fractional indexing for stable row/column order, presence, and a transport abstraction.","maintainers":[{"name":"fsakurai","email":"f-sakurai@ai-path.jp"}],"readme":"# @ai-path/lattica-collab\n\nRealtime collaboration primitives for Lattica. It provides a last-writer-wins\nCRDT for cell values (`TableDocument`), a presence registry for remote cursors\nand selections, a transport abstraction with an in-memory implementation for\ntests and local demos, and `CollabSession` which wires them together into the\nsingle object a UI layer talks to. Fractional order keys (`keyBetween`) support\nstable ordering of inserted rows/columns.\n\n## Install\n\n```sh\npnpm add @ai-path/lattica-collab\n```\n\n## API overview\n\n### CollabSession + InMemoryNetwork\n\nA `CollabSession` applies and broadcasts local edits and merges remote ones. The\n`InMemoryNetwork` connects multiple sessions in-process — ideal for tests.\n\n```ts\nimport { CollabSession, InMemoryNetwork } from '@ai-path/lattica-collab';\n\nconst network = new InMemoryNetwork();\nconst alice = new CollabSession('alice', network.connect(), { name: 'Alice', color: '#e11' });\nconst bob = new CollabSession('bob', network.connect(), { name: 'Bob' });\n\nalice.setCell('A1', 'hello');\nbob.doc.get('A1'); // 'hello' — replicated through the network\n\nalice.updatePresence({ cursor: 'B2' });\nalice.leave();\n```\n\n### TableDocument (CRDT)\n\n`TableDocument` is a self-contained LWW cell store. `setLocal` produces a\n`CellOp` to broadcast; `applyRemote` merges an incoming op; `merge` folds in\nanother document's ops.\n\n```ts\nimport { TableDocument } from '@ai-path/lattica-collab';\n\nconst doc = new TableDocument('site-1');\nconst op = doc.setLocal('A1', 42);\ndoc.get('A1');     // 42\ndoc.snapshot();    // { A1: 42 }\n\nconst other = new TableDocument('site-2');\nother.applyRemote(op);\n```\n\n### Presence\n\n```ts\nimport { PresenceRegistry, type PresenceState } from '@ai-path/lattica-collab';\n\nconst presence = new PresenceRegistry();\npresence.set({ site: 'bob', name: 'Bob', cursor: 'C3' } as PresenceState);\npresence.remove('bob');\n```\n\n### Order keys\n\n`keyBetween` / `keysBetween` generate fractional-index strings for ordering\ninserted items; `isOrderKey` validates them.\n\n```ts\nimport { keyBetween } from '@ai-path/lattica-collab';\n\nconst k = keyBetween(null, null);  // first key\nconst k2 = keyBetween(k, null);    // sorts after k\n```\n\nTo bridge a real backend, implement the `CollabTransport` interface\n(`send` + `subscribe`) and pass it to `CollabSession` in place of the in-memory\ntransport.\n","readmeFilename":"README.md"}