Comparing version 0.6.0 to 0.6.1
@@ -249,2 +249,51 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
AbstractQueryOperation.prototype._bindLateBoundAddSyncFragments = function(op, scope, lateBoundSyncFragments, callback) { | ||
var addSyncFragments = _.filter(lateBoundSyncFragments, function(syncFragment) { | ||
return syncFragment.type === 'add'; | ||
}); | ||
// Here we work out if this is specifying an already existing object that | ||
// wants to be set as a reference and updated as part of this operation | ||
async.eachSeries(addSyncFragments, function(lateBoundSyncFragment, doneCallback) { | ||
scope.getModelObjectByUUID(lateBoundSyncFragment.objectUUID, function(err, modelObject) { | ||
if (err) { | ||
return doneCallback(err); | ||
} | ||
if (!modelObject) { | ||
return doneCallback(); | ||
} | ||
if (modelObject.typeName !== lateBoundSyncFragment.clsName) { | ||
return doneCallback(new Error( | ||
'Illegal ' + op + ' modification for ModelObject \'' + | ||
lateBoundSyncFragment.objectUUID + '\' has conflicting type \'' + | ||
modelObject.typeName + '\' with type being set \'' + | ||
lateBoundSyncFragment.clsName + '\'')); | ||
} | ||
lateBoundSyncFragment.type = 'change'; | ||
doneCallback(); | ||
}); | ||
}, callback); | ||
}; | ||
AbstractQueryOperation.prototype._applySyncFragmentsAndCreateQueryResult = function(scope, syncFragments, options, modelObject, callback) { | ||
syncFragments = syncFragments.filter(function(syncFragment) { | ||
if (syncFragment.type === 'change') { | ||
return Object.keys(syncFragment.properties).length > 0; | ||
} else { | ||
return true; | ||
} | ||
}); | ||
scope.applySyncFragments(syncFragments, options, function(err, results) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
var result = this._createQueryResult(modelObject, syncFragments, results); | ||
callback(null, result); | ||
}.bind(this)); | ||
}; | ||
AbstractQueryOperation.prototype._createQueryResult = function(matchedModelObject, syncFragments, results) { | ||
@@ -251,0 +300,0 @@ var matched = [new QueryResultEntry({ |
@@ -41,4 +41,3 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
this.executed = false; | ||
this.lateBoundChangeSyncFragments = []; | ||
this.lateBoundAddSyncFragments = []; | ||
this.lateBoundSyncFragments = []; | ||
} | ||
@@ -134,4 +133,3 @@ | ||
this.prepared = true; | ||
this.lateBoundChangeSyncFragments = changeFragments; | ||
this.lateBoundAddSyncFragments = addSyncFragments; | ||
this.lateBoundSyncFragments = changeFragments.concat(addSyncFragments); | ||
callback(); | ||
@@ -160,3 +158,6 @@ }.bind(this)); | ||
function bindLateBoundChangeSyncFragments(nextCallback) { | ||
var changeSyncFragments = this.lateBoundChangeSyncFragments; | ||
var changeSyncFragments = _.filter(this.lateBoundSyncFragments, function(syncFragment) { | ||
return syncFragment.type === 'change'; | ||
}); | ||
async.eachSeries(changeSyncFragments, function(lateBoundSyncFragment, doneCallback) { | ||
@@ -204,18 +205,12 @@ var keyPath = lateBoundSyncFragment.keyPath; | ||
function applySyncFragments(nextCallback) { | ||
var syncFragments = this.lateBoundChangeSyncFragments.filter(function(syncFragment) { | ||
return Object.keys(syncFragment.properties).length > 0; | ||
}); | ||
syncFragments = syncFragments.concat(this.lateBoundAddSyncFragments); | ||
function bindLateBoundAddSyncFragments(nextCallback) { | ||
this._bindLateBoundAddSyncFragments(this.operator, scope, this.lateBoundSyncFragments, nextCallback); | ||
}.bind(this), | ||
function applySyncFragmentsAndCreateQueryResult(nextCallback) { | ||
var fragments = this.lateBoundSyncFragments; | ||
var options = this.options; | ||
scope.applySyncFragments(syncFragments, options, function(err, results) { | ||
nextCallback(err, syncFragments, results); | ||
}); | ||
this._applySyncFragmentsAndCreateQueryResult(scope, fragments, options, modelObject, nextCallback); | ||
}.bind(this), | ||
function createQueryResult(syncFragments, results, nextCallback) { | ||
var result = this._createQueryResult(modelObject, syncFragments, results); | ||
nextCallback(null, result); | ||
}.bind(this) | ||
], function(err, result) { | ||
@@ -222,0 +217,0 @@ this.executed = true; |
@@ -164,15 +164,13 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
function applySyncFragments(nextCallback) { | ||
var syncFragments = this.lateBoundSyncFragments; | ||
function bindLateBoundAddSyncFragments(nextCallback) { | ||
this._bindLateBoundAddSyncFragments('$set', scope, this.lateBoundSyncFragments, nextCallback); | ||
}.bind(this), | ||
function applySyncFragmentsAndCreateQueryResult(nextCallback) { | ||
var fragments = this.lateBoundSyncFragments; | ||
var options = this.options; | ||
scope.applySyncFragments(syncFragments, options, function(err, results) { | ||
nextCallback(err, syncFragments, results); | ||
}); | ||
this._applySyncFragmentsAndCreateQueryResult(scope, fragments, options, modelObject, nextCallback); | ||
}.bind(this), | ||
function createQueryResult(syncFragments, results, nextCallback) { | ||
var result = this._createQueryResult(modelObject, syncFragments, results); | ||
nextCallback(null, result); | ||
}.bind(this) | ||
], function(err, result) { | ||
@@ -179,0 +177,0 @@ this.executed = true; |
@@ -51,3 +51,3 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
if (typeof options.disableProcedureConstraints !== 'boolean') { | ||
if (typeof options.disableProcedureConstraints === 'boolean') { | ||
this.disableProcedureConstraints = options.disableProcedureConstraints; | ||
@@ -54,0 +54,0 @@ } else { |
{ | ||
"name": "jetstream", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "Jetstream Sync server framework to sync local and remote models", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -110,3 +110,3 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
function executeProcedure(nextCallback) { | ||
procedure.execute(scope, syncFragments, nextCallback); | ||
procedure.verifyAndExecute(scope, syncFragments, nextCallback); | ||
}, | ||
@@ -113,0 +113,0 @@ |
@@ -153,12 +153,10 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
test(thing('should not be able to push a "new" ModelObject with an existing UUID'), function t(assert) { | ||
test(thing('should be able to push an existing ModelObject and set properties'), function t(assert) { | ||
var room = createTestChatRoom(); | ||
var testAuthor = createTestUser(); | ||
testAuthor.username = 'PushQueryTestUser'; | ||
room.users = [testAuthor]; | ||
var testExistingMessage = createTestMessage(); | ||
room.messages = [testExistingMessage]; | ||
var testExistingMessageAuthor = testExistingMessage.author; | ||
async.waterfall([ | ||
@@ -177,4 +175,2 @@ function setRoot(nextCallback) { | ||
$uuid: testExistingMessage.uuid, | ||
author: testAuthor.uuid, | ||
postedAt: new Date(), | ||
text: 'Overwrite message' | ||
@@ -187,7 +183,26 @@ } | ||
function verifyQueryResult(result, nextCallback) { | ||
assert.equal(result.writeErrors.length, 1); | ||
assert.equal(room.messages.length, 2); | ||
assert.ok(new RegExp(testExistingMessage.uuid).test(result.writeErrors[0].message)); | ||
assert.ok(/already exists/.test(result.writeErrors[0].message)); | ||
assert.equal(room.messages.objectAtIndex(0).uuid, testExistingMessage.uuid); | ||
assert.equal(room.messages.objectAtIndex(0).author, testExistingMessageAuthor); | ||
assert.equal(room.messages.objectAtIndex(0).text, 'Overwrite message'); | ||
assert.equal(room.messages.objectAtIndex(1).uuid, testExistingMessage.uuid); | ||
assert.equal(room.messages.objectAtIndex(1).author, testExistingMessageAuthor); | ||
assert.equal(room.messages.objectAtIndex(1).text, 'Overwrite message'); | ||
assert.equal(result.matched.length, 1); | ||
assert.equal(result.matched[0].uuid, room.uuid); | ||
assert.equal(result.matched[0].clsName, room.typeName); | ||
assert.equal(result.created.length, 0); | ||
assert.equal(result.modified.length, 2); | ||
assert.equal(result.modified[0].uuid, room.uuid); | ||
assert.equal(result.modified[0].clsName, room.typeName); | ||
assert.equal(result.modified[1].uuid, testExistingMessage.uuid); | ||
assert.equal(result.modified[1].clsName, testExistingMessage.typeName); | ||
nextCallback(); | ||
@@ -194,0 +209,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
484336
10800