{"_id":"@cucumber/manymerge","_rev":"7-937c03a1896d8ddd8067e5c38e3184e6","name":"@cucumber/manymerge","dist-tags":{"latest":"2.5.5"},"versions":{"2.5.5":{"name":"@cucumber/manymerge","version":"2.5.5","author":{"name":"Evan Conrad"},"license":"MIT","_id":"@cucumber/manymerge@2.5.5","maintainers":[{"name":"cukebot","email":"cukebot@cucumber.io"},{"name":"aslakhellesoy","email":"aslak.hellesoy@gmail.com"}],"dist":{"shasum":"9fcdfa9cc2512a5f2f79586f6736545635d393ac","tarball":"https://registry.npmjs.org/@cucumber/manymerge/-/manymerge-2.5.5.tgz","fileCount":18,"integrity":"sha512-laxGWntTIDXItD6uFsKzCUaGIsD/er4UN0tQusu9nPF1J56EEXfwPYAbRNEHixGxG+M9PyLCXRr6DggGT/PcGQ==","signatures":[{"sig":"MEQCIGAV0SGHo7FdnjJ/POePbJ3akDxwnlpSq8MG47PqB8xcAiByrnQpV9kumev5o7o/7gZTGxXE44ES7VItYMP3fK8xaA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":58191,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJetSCCCRA9TVsSAnZWagAAOgoP/0Pc8pSJ3qT97LyM1Gj5\nuM+fyJGwLNX0ezbMNyTQO/ndE8WhGHd95wtko3/N5RgLfT2eyhGuVHdGK1Uu\nH3L693O0PvjIVnMuhy8smb8pLV2Cqwd2fRxufOIyH3zGwY9bDWT4WX1xmBg2\nfqbAKYayTyPqJBWGyqG3qmcahRM/C0aFWFq7W+yZtX4vWJ+SQ4Isg9STfRCI\nrwHnAjsMXZp+n/axrLPkXbYBtTjKLR6wo1Sic1pHxufvYZES+CE+Slz8wolh\nUtfYvHLGgZKpKinGOEkVwrEQQOmHcqGpnq+r6UVhViboEzuicx63jMw5VWdo\nr6OofS0p63TroKZwSpGQYmdpepCUc+FL9/cCAIo/4z4reIqQ0x92e23fAKkr\nw/gKqlvKcl25BUzZSwdUJYsU81D+xR9t51i2YJZ14dSDRxroK1k8S9RqzpFb\nyHCvrGD6MkHWQwCQnyXi+5s0E3MG28rw994sTu15q9XtyolVd29BXr6/zl4D\n9RsIcxecq6NXT/BOcQ5K/Bemxp/qqjrRhwRaonkdibezToGQTmJlZKQk7UN/\nTkYfVmgFRBer/EyHM/IYC2Ln+cLW3hqClDv6lcOAIa4iTfyEPkEbwFX/okwL\ngeqDCy1sUVjDdxGCwDEdJlt0FhX9B4YanyYWbOpjPtroCx3AC4+p/nld+ASy\njsD4\r\n=ERBr\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.js","husky":{"hooks":{"pre-commit":"tsdx lint"}},"module":"dist/manymerge.esm.js","gitHead":"6bc6c203df02985b2f8da7803c9f348674d74093","scripts":{"lint":"tsdx lint","test":"tsdx test","build":"tsdx build","start":"tsdx watch","prepare":"tsdx build"},"typings":"dist/index.d.ts","_npmUser":{"name":"cukebot","email":"cukebot@cucumber.io"},"prettier":{"semi":true,"printWidth":80,"singleQuote":true,"trailingComma":"es5"},"_npmVersion":"6.14.5","description":"ManyMerge is a protocol for synchronizing Automerge documents. It's a replacement for `Automerge.Connection` that supports many-to-many and one-to-many relationships.","directories":{},"_nodeVersion":"14.0.0","dependencies":{"immutable":"^3.8.2","invariant":"^2.2.4","@types/events":"^3.0.0","automerge-clocks":"1.2.1"},"_hasShrinkwrap":false,"devDependencies":{"tsdx":"^0.12.3","husky":"^4.2.3","tslib":"^1.11.1","automerge":"^0.13.0","typescript":"^3.8.3","@types/jest":"^25.1.3"},"peerDependencies":{"automerge":"^0.13.0","immutable":"^3.8.2"},"_npmOperationalInternal":{"tmp":"tmp/manymerge_2.5.5_1588928642000_0.05292131911779796","host":"s3://npm-registry-packages"},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."}},"time":{"created":"2020-05-08T09:04:01.780Z","modified":"2025-09-17T22:02:57.177Z","2.5.5":"2020-05-08T09:04:02.129Z"},"author":{"name":"Evan Conrad"},"license":"MIT","description":"ManyMerge is a protocol for synchronizing Automerge documents. It's a replacement for `Automerge.Connection` that supports many-to-many and one-to-many relationships.","maintainers":[{"name":"cukebot","email":"cukebot@cucumber.io"}],"readme":"# ManyMerge\n\nManyMerge is a protocol for synchronizing Automerge documents. It's a replacement for `Automerge.Connection` that supports many-to-many and one-to-many relationships.\n\n## Install\n\n```\nnpm install --save manymerge\n```\n\n## Usage\n\nManymerge comes with two different types of connections that work together: **Peers** and **Hubs**.\n\n### Peers\n\nA Peer is **a 1-1 relationship** that can talk to a Hub or another Peer. Your peer will need to create a `sendMsg` function that takes a ManyMerge `Message` and sends it to the network. Typically that looks like this:\n\n```ts\nimport { Peer } from 'manymerge';\n\nfunction sendMsg(msg) {\n  MyNetwork.emit('to-server', msg);\n}\n\nconst peer = new Peer(sendMsg);\n```\n\nWhen a peer wants to alert it's counterpart that it changed a document, it should call the `notify` function:\n\n```ts\nimport Automerge from 'automerge';\n\nlet myDoc = Automerge.from({ title: 'cool doc' });\npeer.notify(myDoc);\n```\n\nWhen a peer gets a message from the network, it should run `applyMessage`, which will return a new document with any changes applied. If the document is not updated, it will return nothing. In this case, you should not update the doc.\n\n```ts\nlet myDoc = Automerge.from({ title: 'cool doc' });\n\nMyNetwork.on('from-server', msg => {\n  const doc = peer.applyMessage(msg, myDoc);\n  if (doc) {\n    myDoc = newDoc;\n  }\n});\n```\n\n### Hubs\n\nHubs are a **many-to-many (or 1-to-many) relationship** that can talk to many Peers or other Hubs. Unlike Peers, Hubs need the ability to \"broadcast\" a message to everyone on the network (or at least as many people as possible). To save time, Hubs will also cache Peer's they've seen recently and directly communicate directly with them.\n\nTo set this up, create `broadcastMsg` and `sendMsgTo` functions:\n\n```ts\nimport { Hub } from 'manymerge';\n\nfunction sendMsgTo(peerId, msg) {\n  MyNetwork.to(peerId).emit('msg', msg);\n}\n\nfunction broadcastMsg(msg) {\n  MyNetwork.on('some-channel').emit('msg', msg);\n}\n\nconst hub = new Hub(sendMsgTo, broadcastMsg);\n```\n\nThen, hub works like a peer, it can notify others of documents:\n\n```ts\n// Tell folks about our doc\nhub.notify(myDoc);\n```\n\nUnlike the peer, when it gets a message, it'll need to know the unique id of the connection sending it. It will use this later in the `sendMsgTo` function.\n\n```ts\nMyNetwork.on('msg', (from, msg) => {\n  newDoc = hub.applyMessage(from, msg, myDoc);\n  if (newDoc) {\n    myDoc = newDoc;\n  }\n});\n```\n\n## Differences from Automerge.Connection\n\n**ManyMerge does not use DocSet.** Unlike Automerge.Connection, ManyMerge does not know how you store your documents. If it did, all the hubs would have to store many, many documents of many different peers in memory, which doesn't scale well.\n\n**ManyMerge does not multiplex many document updates over the same network.** If you want, you can implement this yourself by just batching messages in your `sendMsg` function.\n","readmeFilename":"README.md"}