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

gulf

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulf - npm Package Compare versions

Comparing version 0.4.11 to 1.0.0

8

lib/Document.js

@@ -65,5 +65,7 @@ /**

* Creates a new Link and attaches it as a slave
* @param authorizeFn (optional) function(msg, credentials, cb) that authorizes the message
*/
Document.prototype.slaveLink = function() {
Document.prototype.slaveLink = function(authorizeFn) {
var link = new Link
link.authorizeFn = authorizeFn
this.attachSlaveLink(link)

@@ -76,5 +78,7 @@ return link

* (You will want to listen to the link's 'close' event)
* @param credentials (optional) A string or object containing the client'S credentials
*/
Document.prototype.masterLink = function() {
Document.prototype.masterLink = function(credentials) {
var link = new Link
link.credentials = credentials
this.attachMasterLink(link)

@@ -81,0 +85,0 @@ return link

@@ -34,3 +34,3 @@ /**

if(json.cs) {
edit.changeset = json.cs
edit.changeset = JSON.parse(json.cs)
}

@@ -59,2 +59,13 @@ edit.parent = json.parent

/**
* Returns an edit overtaking every necessary attrib from the snapshot
*/
Edit.fromSnapshot = function(s, ottype) {
var edit = new Edit(ottype)
edit.changeset = s.changes? JSON.parse(s.changes) : s.changes
edit.id = s.id
edit.parent = s.parent
return edit
}
/**
* Applies this edit on a snapshot

@@ -95,3 +106,3 @@ */

if(this.changeset) {
o.cs = this.changeset
o.cs = JSON.stringify(this.changeset)
}

@@ -98,0 +109,0 @@ return JSON.stringify(o)

@@ -52,9 +52,9 @@ /**

this.history.latest(function(er, latestSnaphot) {
this.history.latest(function(er, latestSnapshot) {
if(er) throw er
edit.parent = latestSnaphot.id
edit.parent = latestSnapshot.edit.id
// Merge into the queue for increased collab speed
if(this.master.queue.length == 1) {
if(false && this.master.queue.length == 1) {
var parent = this.master.queue[0].parent

@@ -75,3 +75,3 @@ , callback =this.master.queue[0].callback

//this.distributeEdit(edit) // Unnecessary round trip
this.history.storeSnapshot({id: edit.id, contents: this.content, edit: edit})
this.history.storeSnapshot({contents: this.content, edit: edit})
}.bind(this))

@@ -78,0 +78,0 @@ }.bind(this))

@@ -43,7 +43,5 @@ /**

if(er) return cb && cb(er)
snapshot = {
edit: Edit.unpack(snapshot.edit, this.document.ottype)
, contents: snapshot.contents
, id: snapshot.id
}
snapshot = { edit: Edit.fromSnapshot(snapshot, this.document.ottype)
, contents: snapshot.contents
}
cb(null, snapshot)

@@ -57,7 +55,5 @@ }.bind(this))

if(!snapshot) return cb(new Error('No snapshot found'))
snapshot = {
edit: Edit.unpack(snapshot.edit, this.document.ottype)
, contents: snapshot.contents
, id: snapshot.id
}
snapshot = { edit: Edit.fromSnapshot(snapshot, this.document.ottype)
, contents: snapshot.contents
}
cb(null, snapshot)

@@ -69,3 +65,3 @@ }.bind(this))

// Only Master Document may set ids
if(!snapshot.id) {
if(!snapshot.edit.id) {
snapshot.id = ++this.idCounter

@@ -77,5 +73,4 @@ snapshot.edit.id = snapshot.id

if(er) cb && cb(er)
if(latest && latest.id != snapshot.edit.parent) cb && cb(new Error('This edit\'s parent is not the latest edit in history: '+JSON.stringify(snapshot)))
snapshot.edit = snapshot.edit.pack()
this.document.adapter.storeSnapshot(snapshot, function(er) {
if(latest && latest.edit.id != snapshot.edit.parent) cb && cb(new Error('This edit\'s parent is not the latest edit in history: '+JSON.stringify(snapshot)))
this.document.adapter.storeSnapshot({id: snapshot.edit.id, changes: JSON.stringify(snapshot.edit.changeset), parent: snapshot.edit.parent, contents: snapshot.contents}, function(er) {
cb && cb(er)

@@ -96,5 +91,4 @@ })

snapshots = snapshots.map(function(snapshot) {
return { edit: Edit.unpack(snapshot.edit, this.document.ottype)
return { edit: Edit.fromSnapshot(snapshot, this.document.ottype)
, contents: snapshot.contents
, id: snapshot.id
}

@@ -101,0 +95,0 @@ }.bind(this))

@@ -30,2 +30,8 @@ /**

function Link () {
this.credentials
this.authorizeFn
this.sentEdit
this.queue
this.callbacks
Duplex.call(this, {allowHalfOpen: false, objectMode: true})

@@ -58,3 +64,3 @@

Link.prototype.send = function(event/*, args..*/) {
var data = JSON.stringify(Array.prototype.slice.call(arguments))
var data = JSON.stringify(Array.prototype.slice.call(arguments).concat([this.credentials]))
console.log('->', data)

@@ -98,29 +104,40 @@ //console.trace()

// Intercept acks for shifting the queue and calling callbacks
if(args[0] == 'ack') {
var id = args[1]
this.authorize(args, args[args.length-1], function(er, authorized) {
if(this.sentEdit && this.sentEdit.callback) {
// Callback
this.sentEdit.id = id
// The nextTick shim for browsers doesn't seem to enforce the call order
// (_read is called below and they must be in that order), so we call directly
//nextTick(this.sentEdit.callback.bind(null, null, this.sentEdit))
try {
this.sentEdit.callback(null, this.sentEdit)
}catch(e) {
this.emit('error', e)
if(er) this.emit('error', er)
if(!authorized) return
// Intercept acks for shifting the queue and calling callbacks
if(args[0] == 'ack') {
var id = args[1]
if(this.sentEdit && this.sentEdit.callback) {
// Callback
this.sentEdit.id = id
// The nextTick shim for browsers doesn't seem to enforce the call order
// (_read is called below and they must be in that order), so we call directly
//nextTick(this.sentEdit.callback.bind(null, null, this.sentEdit))
try {
this.sentEdit.callback(null, this.sentEdit)
}catch(e) {
this.emit('error', e)
}
delete this.sentEdit.callback
}
delete this.sentEdit.callback
this.sentEdit = null
setImmediate(function() {
this._read(0)
}.bind(this))
}
this.sentEdit = null
setImmediate(function() {
this._read(0)
}.bind(this))
}
args[0] = 'link:'+args[0]
this.emit.apply(this, args)
cb()
}.bind(this))
}
args[0] = 'link:'+args[0]
this.emit.apply(this, args)
cb()
Link.prototype.authorize = function(msg, credentials, cb) {
if(!this.authorizeFn) return cb(null, true)
this.authorizeFn(msg, credentials, cb)
}
{
"name": "gulf",
"version": "0.4.11",
"version": "1.0.0",
"description": "transport-agnostic operational transformation control layer",

@@ -5,0 +5,0 @@ "repository": {

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