Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

manymerge

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

manymerge - npm Package Compare versions

Comparing version 2.5.2 to 2.5.3

dist/manymerge.cjs.development.js

8

dist/hub.d.ts

@@ -1,4 +0,4 @@

import { Doc } from "automerge";
import { Map } from "immutable";
import { Clock, Message } from "./types";
import { Doc } from 'automerge';
import { Map } from 'immutable';
import { Clock, Message } from './types';
/**

@@ -14,3 +14,3 @@ * An Automerge Network protocol getting consensus

constructor(sendMsgTo: (peerId: string, msg: Message) => void, broadcastMsg: (msg: Message) => void);
applyMessage<T>(peerId: string, msg: Message, doc: Doc<T>): Doc<T>;
applyMessage<T>(peerId: string, msg: Message, doc: Doc<T>): Doc<T> | undefined;
notify<T>(doc: Doc<T>): void;

@@ -17,0 +17,0 @@ private sendMsgTo;

@@ -1,4 +0,4 @@

export { Hub } from "./hub";
export { Peer } from "./peer";
export { squash } from "./squash";
export { Message } from "./types";
export { Hub } from './hub';
export { Peer } from './peer';
export { squash } from './squash';
export { Message } from './types';

@@ -1,8 +0,8 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var hub_1 = require("./hub");
exports.Hub = hub_1.Hub;
var peer_1 = require("./peer");
exports.Peer = peer_1.Peer;
var squash_1 = require("./squash");
exports.squash = squash_1.squash;
'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./manymerge.cjs.production.min.js')
} else {
module.exports = require('./manymerge.cjs.development.js')
}

@@ -1,4 +0,4 @@

import { Doc } from "automerge";
import { Map } from "immutable";
import { Message } from "./types";
import { Doc } from 'automerge';
import { Map } from 'immutable';
import { Message } from './types';
/**

@@ -12,5 +12,5 @@ * An Automerge Network protocol getting consensus

constructor(sendMsg: (msg: Message) => void);
applyMessage<T>(msg: Message, doc: Doc<T>): Doc<T>;
applyMessage<T>(msg: Message, doc: Doc<T>): Doc<T> | undefined;
notify<T>(doc: Doc<T>): void;
private sendMsg;
}
/// <reference types="automerge" />
import { Message } from "./types";
import { Message } from './types';
/**

@@ -4,0 +4,0 @@ * Squash messages together before applying them!

@@ -1,3 +0,3 @@

import { Change } from "automerge";
import { Map } from "immutable";
import { Change } from 'automerge';
import { Map } from 'immutable';
export declare type Clock = Map<string, number>;

@@ -4,0 +4,0 @@ export interface Message {

{
"name": "manymerge",
"version": "2.5.2",
"version": "2.5.3",
"license": "MIT",
"main": "dist/index.js",
"author": "Evan Conrad",
"license": "MIT",
"typings": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "tsc",
"test": "jest",
"prepublishOnly": "tsc"
"start": "tsdx watch",
"build": "tsdx build",
"test": "tsdx test",
"lint": "tsdx lint",
"prepare": "tsdx build"
},
"files": [
"/dist"
],
"peerDependencies": {
"automerge": "^0.12.1",
"immutable": "^4.0.0-rc.12"
"automerge": "^0.13.0",
"immutable": "^3.8.2"
},
"husky": {
"hooks": {
"pre-commit": "tsdx lint"
}
},
"prettier": {
"printWidth": 80,
"semi": true,
"singleQuote": true,
"trailingComma": "es5"
},
"author": "Evan Conrad",
"module": "dist/manymerge.esm.js",
"devDependencies": {
"@types/jest": "^24.0.24",
"@types/node": "^13.1.1",
"automerge": "^0.12.1",
"events": "^3.0.0",
"immutable": "^4.0.0-rc.12",
"jest": "^24.9.0",
"lodash": "^4.17.15",
"transit-immutable-js": "^0.7.0",
"transit-js": "^0.8.861",
"ts-jest": "^24.2.0",
"typescript": "^3.7.4"
"@types/jest": "^25.1.3",
"husky": "^4.2.3",
"tsdx": "^0.12.3",
"tslib": "^1.11.1",
"typescript": "^3.8.3"
},
"types": "dist/index.d.ts",
"dependencies": {
"@types/events": "^3.0.0",
"automerge-clocks": "1.2.0",
"automerge": "^0.13.0",
"automerge-clocks": "1.2.1",
"immutable": "^3.8.2",
"invariant": "^2.2.4"
}
}

@@ -1,93 +0,27 @@

# ManyMerge
# TSDX Bootstrap
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.
This project was bootstrapped with [TSDX](https://github.com/jaredpalmer/tsdx).
## Install
## Local Development
```
npm install --save manymerge
```
Below is a list of commands you will probably find useful.
## Usage
### `npm start` or `yarn start`
Manymerge comes with two different types of connections that work together: **Peers** and **Hubs**.
Runs the project in development/watch mode. Your project will be rebuilt upon changes. TSDX has a special logger for you convenience. Error messages are pretty printed and formatted for compatibility VS Code's Problems tab.
### Peers
<img src="https://user-images.githubusercontent.com/4060187/52168303-574d3a00-26f6-11e9-9f3b-71dbec9ebfcb.gif" width="600" />
A 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:
Your library will be rebuilt if you make edits.
```ts
import { Peer } from "manymerge";
### `npm run build` or `yarn build`
function sendMsg(msg) {
MyNetwork.emit("to-server", msg);
}
Bundles the package to the `dist` folder.
The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).
const peer = new Peer(sendMsg);
```
<img src="https://user-images.githubusercontent.com/4060187/52168322-a98e5b00-26f6-11e9-8cf6-222d716b75ef.gif" width="600" />
When a peer wants to alert it's counterpart that it changed a document, it should call the `notify` function:
### `npm test` or `yarn test`
```ts
import Automerge from "automerge";
let myDoc = Automerge.from({ title: "cool doc" });
peer.notify(myDoc);
```
When 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.
```ts
let myDoc = Automerge.from({ title: "cool doc" });
MyNetwork.on("from-server", msg => {
const newDoc = peer.applyMessage(msg, myDoc);
if (doc) {
myDoc = newDoc;
}
});
```
### Hubs
Hubs 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.
To set this up, create `broadcastMsg` and `sendMsgTo` functions:
```ts
import { Hub } from "manymerge";
function sendMsgTo(peerId, msg) {
MyNetwork.to(peerId).emit("msg", msg);
}
function broadcastMsg(msg) {
MyNetwork.on("some-channel").emit("msg", msg);
}
const hub = new Hub(sendMsgTo, broadcastMsg);
```
Then, hub works like a peer, it can notify others of documents:
```ts
// Tell folks about our doc
hub.notify(myDoc);
```
Unlike 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.
```ts
MyNetwork.on("msg", (from, msg) => {
newDoc = hub.applyMessage(from, msg, myDoc);
if (newDoc) {
myDoc = newDoc;
}
});
```
## Differences from Automerge.Connection
**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.
**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.
Runs the test watcher (Jest) in an interactive mode.
By default, runs tests related to files changed since the last commit.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc