Socket
Socket
Sign inDemoInstall

jetstream

Package Overview
Dependencies
157
Maintainers
2
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.11.5 to 0.12.0

3

lib/model_object.js

@@ -255,2 +255,5 @@ // Copyright (c) 2015 Uber Technologies, Inc.

ModelObject.getSubtypeWithTypeName = function(typeName) {
if (typeName === this.typeName) {
return this;
}
return ModelObject._subtypesByTypeName[this.typeName][typeName];

@@ -257,0 +260,0 @@ };

@@ -73,2 +73,3 @@ // Copyright (c) 2015 Uber Technologies, Inc.

unmatchedFragments = results;
doneCallback();
});

@@ -75,0 +76,0 @@ }, function(err) {

7

lib/procedures/remote_http_sync_procedure.js

@@ -128,2 +128,3 @@ // Copyright (c) 2015 Uber Technologies, Inc.

this.successStatusCodes = options.remote.successStatusCodes || CONST.DEFAULT_SUCCESS_STATUS_CODES;
this.updatesResponseKey = options.remote.updatesResponseKey || '_updates';
this._verifyUrlParamsSetOrThrow();

@@ -293,4 +294,2 @@ this._verifyParamsHeadersBodyBindingsOrThrow();

var statusCode = response ? response.statusCode : null;
var hasBody = body !== null && body !== undefined;
body = hasBody ? JSON.stringify(body) : null;

@@ -329,5 +328,5 @@ tryit(function() {

// TODO: add ability to map inline edits on the data to add fragments to additionalFragments
callback(null, new SyncProcedureResult({additionalFragments: []}));
var updates = (body && body[this.updatesResponseKey]) || null;
callback(null, new SyncProcedureResult({updates: updates}));
}.bind(this));
};

@@ -27,10 +27,10 @@ // Copyright (c) 2015 Uber Technologies, Inc.

var hasAdditionalFragments = options.hasOwnProperty('additionalFragments');
if (hasAdditionalFragments && !Array.isArray(options.additionalFragments)) {
throw new Error('Invalid additionalFragments');
} else if (!hasAdditionalFragments) {
options.additionalFragments = [];
var hasUpdates = options.hasOwnProperty('updates');
if (hasUpdates && options.updates && !Array.isArray(options.updates)) {
throw new Error('Invalid updates');
} else if (!hasUpdates || options.updates === null) {
options.updates = [];
}
this.additionalFragments = options.additionalFragments;
this.updates = options.updates;
}

@@ -56,13 +56,15 @@ // Copyright (c) 2015 Uber Technologies, Inc.

SyncProcedure.prototype.verifyAndExecute = function(scope, syncFragments, callback) {
var constraintsMatches = false;
if (scope.disableProcedureConstraints) {
constraintsMatches = true;
this.execute(scope, syncFragments, callback);
} else {
constraintsMatches = Constraint.matchesAllConstraints(scope, this.constraints, syncFragments);
Constraint.matchesAllConstraints(scope, this.constraints, syncFragments, function onResult(err, result) {
if (err) {
return callback(err);
}
if (!result) {
return callback(new Error('Changes do not match the procedure constraints'));
}
this.execute(scope, syncFragments, callback);
}.bind(this));
}
if (!constraintsMatches) {
return callback(new Error('Changes do not match the procedure constraints'));
}
this.execute(scope, syncFragments, callback);
};

@@ -72,3 +74,3 @@

// This is a no-op, derived sync procedures should override this method
callback(null, new SyncProcedureResult({additionalFragments: []}));
callback(null, new SyncProcedureResult({updates: []}));
};

@@ -238,3 +238,3 @@ // Copyright (c) 2015 Uber Technologies, Inc.

this.lock.writeLock(function(release) {
this.applySyncFragmentsWithLock(syncFragments, options, function(err, results) {
this.applySyncFragmentsWithLock(syncFragments, options, function(err, results, updates) {
release();

@@ -244,3 +244,24 @@ if (err) {

} else {
maybeCallback(callback)(null, results);
var onDone = maybeCallback(callback);
if (!updates || updates.length === 0) {
onDone(null, results);
} else {
async.eachSeries(updates, function eachUpdate(elem, callback) {
var query = elem.query || null;
var options = elem.options || {};
this.update(query, elem.update, options, function onUpdate(err) {
if (err) {
logger.error('Error applying scope success update', {
error: err,
successUpdate: elem
});
}
callback();
});
}.bind(this), function onUpdatesDone() {
onDone(null, results);
});
}
}

@@ -272,2 +293,4 @@ }.bind(this));

var onSuccessQueryUpdates = [];
async.waterfall([

@@ -305,8 +328,5 @@ function callSyncProcedure(nextCallback) {

}
if (!Array.isArray(result.additionalFragments)) {
return nextCallback(new Error('Invalid result returned from procedure'));
if (Array.isArray(result.updates)) {
onSuccessQueryUpdates = result.updates;
}
if (result.additionalFragments.length > 0) {
syncFragments = syncFragments.concat(result.additionalFragments);
}
nextCallback();

@@ -499,3 +519,4 @@ });

maybeCallback(callback)(null, results);
var onDone = maybeCallback(callback);
onDone(null, results, onSuccessQueryUpdates);

@@ -502,0 +523,0 @@ }.bind(this));

@@ -204,3 +204,2 @@ // Copyright (c) 2015 Uber Technologies, Inc.

// TODO: support additional fragments
return this.client.sendScopeSyncReplyMessage({

@@ -207,0 +206,0 @@ replyTo: message.index,

{
"name": "jetstream",
"version": "0.11.5",
"version": "0.12.0",
"description": "Jetstream Sync server framework to sync local and remote models",

@@ -5,0 +5,0 @@ "keywords": [

@@ -102,3 +102,3 @@ // Copyright (c) 2015 Uber Technologies, Inc.

assert.ok(result instanceof SyncProcedureResult);
assert.equal(result.additionalFragments.length, 0);
assert.equal(result.updates.length, 0);
nextCallback();

@@ -195,3 +195,3 @@ }

assert.ok(result instanceof SyncProcedureResult);
assert.equal(result.additionalFragments.length, 0);
assert.equal(result.updates.length, 0);
nextCallback();

@@ -265,3 +265,3 @@ }

assert.ok(result instanceof SyncProcedureResult);
assert.equal(result.additionalFragments.length, 0);
assert.equal(result.updates.length, 0);
nextCallback();

@@ -268,0 +268,0 @@ }

@@ -117,3 +117,3 @@ // Copyright (c) 2015 Uber Technologies, Inc.

assert.ok(result instanceof SyncProcedureResult);
assert.equal(result.additionalFragments.length, 0);
assert.equal(result.updates.length, 0);

@@ -120,0 +120,0 @@ nextCallback();

@@ -24,2 +24,3 @@ // Copyright (c) 2015 Uber Technologies, Inc.

var Canvas = require('../demos/shapes').Canvas;
var createTestChatRoom = require('./test/test_helpers').createTestChatRoom;
var createTestContext = require('./test/test_context');

@@ -32,2 +33,3 @@ var ModelObject = require('../lib/model_object');

var SyncFragment = require('../lib/sync_fragment');
var uuid = require('node-uuid');

@@ -217,2 +219,77 @@ var context = createTestContext('Scope');

test(thing('should apply procedure updates on success'), function t(assert) {
var chatRoom = createTestChatRoom();
var newChatRoomName = 'New name';
var syncFragments = [
new SyncFragment({
uuid: chatRoom.uuid,
type: 'change',
clsName: 'ChatRoom',
properties: {
name: newChatRoomName
}
})
];
var updatedTopicName = 'Room renamed "' + chatRoom.name + '" to "' + newChatRoomName + '"';
var accessToken = uuid.v4();
var scope = new Scope({name: 'TestScope', params: {accessToken: accessToken}});
var procedure = chatRoom.getProcedure('setName');
assert.ok(procedure);
sandbox.stub(procedure, 'httpClient', mockHttpClient);
function mockHttpClient(options, callback) {
assert.equal(options.url, 'http://chatRoomAPI/room/' + chatRoom.uuid);
assert.equal(options.method, 'POST');
assert.deepEqual(options.headers, {
'Content-Type': 'application/json',
'Authorization': scope.params.accessToken,
'X-ChatRoom-SetName': newChatRoomName
});
assert.equal(options.json, undefined);
var updates = [
{
update: {
$set: {
'attributes.topic': updatedTopicName
}
}
}
];
callback(null, {statusCode: 200}, {_updates: updates});
}
async.series([
function setRoot(nextCallback) {
scope.setRoot(chatRoom, function(err) {
assert.ifError(err);
nextCallback();
});
},
function applyChangeToRemoveSecondShape(nextCallback) {
var options = {procedure: 'ChatRoom.setName'};
scope.applySyncFragments(syncFragments, options, nextCallback);
},
function assertUpdatesApplied(nextCallback) {
assert.equal(chatRoom.attributes.topic, updatedTopicName);
nextCallback();
}
], function(err) {
assert.ifError(err);
assert.end();
});
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc