Skip to content

Commit

Permalink
Fixing to work with 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yasserf committed Jun 23, 2016
1 parent 565c339 commit 2b0451d
Show file tree
Hide file tree
Showing 24 changed files with 173 additions and 100 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: node_js
node_js:
- "stable"
script: npm run coverage
after_script: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
"test": "test"
},
"scripts": {
"test": "node_modules/.bin/istanbul cover node_modules/jasmine/bin/jasmine.js JASMINE_CONFIG_PATH=jasmine.json",
"watch": "node node_modules/watch/cli.js \"npm test\" ./src ./test-unit ./test-e2e",
"e2e": "node node_modules/jasmine/bin/jasmine JASMINE_CONFIG_PATH=jasmine.json test-e2e/specs/*Spec.js",
"e2e::watch": "node node_modules/watch/cli.js \"npm run-script e2e\" ./src ./test-e2e",
"unit": "node node_modules/jasmine/bin/jasmine JASMINE_CONFIG_PATH=jasmine.json test-unit/unit/**/*Spec.js",
"unit::watch": "node node_modules/watch/cli.js \"npm run-script unit\" ./src ./test-unit",
"reporter": "node_modules/.bin/istanbul jasmine-runner.js",
"test": "jasmine JASMINE_CONFIG_PATH=jasmine.json",
"reporter": "istanbul cover jasmine-runner.js",
"coverage": "istanbul cover node_modules/jasmine/bin/jasmine.js JASMINE_CONFIG_PATH=jasmine.json",
"watch": "watch \"npm test\" ./src ./test-unit ./test-e2e",
"e2e": "jasmine JASMINE_CONFIG_PATH=jasmine.json test-e2e/specs/*Spec.js",
"e2e::watch": "watch \"npm run e2e\" ./src ./test-e2e",
"unit": "jasmine JASMINE_CONFIG_PATH=jasmine.json test-unit/unit/**/*Spec.js",
"unit::watch": "watch \"npm run unit\" ./src ./test-unit",
"webpack": "webpack --progress test-page-webpack/index.js test-page-webpack/dist/build.js"
},
"repository": {
Expand All @@ -28,7 +29,7 @@
"net": false
},
"devDependencies": {
"deepstream.io": "1.0.0-beta.1",
"deepstream.io": "1.0.0-beta.3",
"browserify": "13.0.1",
"coveralls": "^2.11.9",
"deepstream.io-msg-redis": "latest",
Expand Down
20 changes: 10 additions & 10 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var C = require( './constants/constants' ),
* @copyright 2014 Hoxton One Ltd.
*
* @{@link http://deepstream.io}
*
*
*
* @param {String} url URL to connect to. The protocoll can be ommited, e.g. <host>:<port>. Use TCP URL for node.js
* @param {Object} options A map of options that extend the ones specified in default-options.js
Expand All @@ -30,9 +30,9 @@ var C = require( './constants/constants' ),
var Client = function( url, options ) {
this._url = url;
this._options = this._getOptions( options || {} );

this._connection = new Connection( this, this._url, this._options );

this.event = new EventHandler( this._options, this._connection, this );
this.rpc = new RpcHandler( this._options, this._connection, this );
this.record = new RecordHandler( this._options, this._connection, this );
Expand Down Expand Up @@ -68,7 +68,7 @@ Emitter( Client.prototype );
*
* login can be called multiple times until either the connection is authenticated or
* forcefully closed by the server since its maxAuthAttempts threshold has been exceeded
*
*
* @param {Object} authParams JSON.serializable authentication data
* @param {Function} callback Will be called with either (true) or (false, errorType, errorMessage)
*
Expand Down Expand Up @@ -112,7 +112,7 @@ Client.prototype.getConnectionState = function() {
Client.prototype.getUid = function() {
var timestamp = (new Date()).getTime().toString(36),
randomString = (Math.random() * 10000000000000000).toString(36).replace( '.', '' );

return timestamp + '-' + randomString;
};

Expand Down Expand Up @@ -150,7 +150,7 @@ Client.prototype._$onMessage = function( message ) {
* IMPORTANT: Errors that are specific to a request, e.g. a RPC
* timing out or a record not being permissioned are passed directly
* to the method that requested them
*
*
* @param {String} topic One of CONSTANTS.TOPIC
* @param {String} event One of CONSTANTS.EVENT
* @param {String} msg Error dependent message
Expand All @@ -177,9 +177,9 @@ Client.prototype._$onError = function( topic, event, msg ) {
this.emit( event, topic, msg );
} else {
console.log( '--- You can catch all deepstream errors by subscribing to the error event ---' );

errorMsg = event + ': ' + msg;

if( topic ) {
errorMsg += ' (' + topic + ')';
}
Expand All @@ -191,9 +191,9 @@ Client.prototype._$onError = function( topic, event, msg ) {
/**
* Passes generic messages from the error topic
* to the _$onError handler
*
*
* @param {Object} errorMessage parsed deepstream error message
*
*
* @private
* @returns {void}
*/
Expand Down
50 changes: 25 additions & 25 deletions src/default-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
************************************************/

/**
* @param {Boolean} recordPersistDefault Whether records should be
* @param {Boolean} recordPersistDefault Whether records should be
* persisted by default. Can be overwritten
* for individual records when calling getRecord( name, persist );
*/
Expand All @@ -27,13 +27,13 @@ module.exports = {
* up and declares the connection closed
*/
maxReconnectAttempts: 5,

/**
* @param {Number} rpcAckTimeout The number of milliseconds after which a rpc will create an error if
* no Ack-message has been received
*/
rpcAckTimeout: 6000,

/**
* @param {Number} rpcResponseTimeout The number of milliseconds after which a rpc will create an error if
* no response-message has been received
Expand All @@ -50,10 +50,10 @@ module.exports = {
* @param {Number} maxMessagesPerPacket If the implementation tries to send a large number of messages at the same
* time, the deepstream client will try to split them into smaller packets and send
* these every <timeBetweenSendingQueuedPackages> ms.
*
*
* This parameter specifies the number of messages after which deepstream sends the
* packet and queues the remaining messages. Set to Infinity to turn the feature off.
*
*
*/
maxMessagesPerPacket: 100,

Expand All @@ -76,7 +76,7 @@ module.exports = {

/**
* @param {Number} recordDeleteTimeout The number of milliseconds from the moment record.delete() is called
* until an error is thrown since no delete ack message had been received. Please
* until an error is thrown since no delete ack message had been received. Please
* take into account that the deletion is only complete after the record has been
* deleted from both cache and storage
*/
Expand All @@ -94,7 +94,7 @@ module.exports = {
* Set to null if you only intend to use WebRTC within your local network
*/
rtcPeerConnectionConfig: { iceServers: [
{ url: 'stun:stun.services.mozilla.com' },
{ url: 'stun:stun.services.mozilla.com' },
{ url: 'stun:stun.l.google.com:19302' }
]},

Expand All @@ -108,7 +108,7 @@ module.exports = {
agent: false,

/**
* @param {Boolean} upgrade whether the client should try to upgrade the
* @param {Boolean} upgrade whether the client should try to upgrade the
* transport from long-polling to something better
*/
upgrade: true,
Expand All @@ -119,29 +119,29 @@ module.exports = {
forceJSONP: false,

/**
* @param {Boolean} jsonp determines whether to use JSONP when
* necessary for polling. If disabled (by settings to false)
* an error will be emitted (saying "No transports available")
* if no other transports are available. If another transport
* is available for opening a connection (e.g. WebSocket)
* @param {Boolean} jsonp determines whether to use JSONP when
* necessary for polling. If disabled (by settings to false)
* an error will be emitted (saying "No transports available")
* if no other transports are available. If another transport
* is available for opening a connection (e.g. WebSocket)
* that transport will be used instead.
*/
jsonp: true,

/**
* @param {Boolean} forceBase64 forces base 64 encoding for polling transport even when XHR2 responseType
* @param {Boolean} forceBase64 forces base 64 encoding for polling transport even when XHR2 responseType
* is available and WebSocket even if the used standard supports binary.
*/
forceBase64: false,

/**
* @param {Boolean} enablesXDR enables XDomainRequest for IE8 to avoid loading bar flashing with click sound.
* @param {Boolean} enablesXDR enables XDomainRequest for IE8 to avoid loading bar flashing with click sound.
* default to false because XDomainRequest has a flaw of not sending cookie.
*/
enablesXDR: false,

/**
* @param {Boolean} timestampRequests whether to add the timestamp with each transport request. Note: this is
* @param {Boolean} timestampRequests whether to add the timestamp with each transport request. Note: this is
* ignored if the browser is IE or Android, in which case requests are always stamped
*/
timestampRequests: false,
Expand All @@ -162,27 +162,27 @@ module.exports = {
path: '/engine.io',

/**
* @param {Array} transports a list of transports to try (in order). Engine always
* attempts to connect directly with the first one,
* @param {Array} transports a list of transports to try (in order). Engine always
* attempts to connect directly with the first one,
* provided the feature detection test for it passes.
*/
transports: [ 'polling', 'websocket' ],

/**
* @param {Boolean} rememberUpgrade If true and if the previous websocket connection to
* the server succeeded, the connection attempt will bypass the normal
* upgrade process and will initially try websocket. A connection
* attempt following a transport error will use the normal upgrade
* process. It is recommended you turn this on only when using
* SSL/TLS connections, or if you know that
* @param {Boolean} rememberUpgrade If true and if the previous websocket connection to
* the server succeeded, the connection attempt will bypass the normal
* upgrade process and will initially try websocket. A connection
* attempt following a transport error will use the normal upgrade
* process. It is recommended you turn this on only when using
* SSL/TLS connections, or if you know that
* your network does not block websockets.
*/
rememberUpgrade: false,

/**
* @param {Function} mergeStrategy This provides the default strategy used to deal with merge conflicts.
* If the merge strategy is not succesfull it will set an error, else set the
* returned data as the latest revision. This can be overriden on a per record
* returned data as the latest revision. This can be overriden on a per record
* basis by setting the `setMergeStrategy`.
*/
mergeStrategy: MERGE_STRATEGIES.REMOTE_WINS
Expand Down
24 changes: 12 additions & 12 deletions src/record/record-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ RecordHandler.prototype.getRecord = function( name, recordOptions ) {
this._records[ name ].on( 'deleted', this._removeRecord.bind( this, name ) );
this._records[ name ].on( 'discard', this._removeRecord.bind( this, name ) );
}

this._records[ name ].usages++;

return this._records[ name ];
};

Expand Down Expand Up @@ -170,8 +170,8 @@ RecordHandler.prototype.has = function( name, callback ) {
RecordHandler.prototype._$handle = function( message ) {
var name;

if( message.action === C.ACTIONS.ERROR &&
( message.data[ 0 ] !== C.EVENT.VERSION_EXISTS && message.data[ 0 ] !== C.ACTIONS.SNAPSHOT && message.data[ 0 ] !== C.ACTIONS.HAS )
if( message.action === C.ACTIONS.ERROR &&
( message.data[ 0 ] !== C.EVENT.VERSION_EXISTS && message.data[ 0 ] !== C.ACTIONS.SNAPSHOT && message.data[ 0 ] !== C.ACTIONS.HAS )
) {
message.processedError = true;
this._client._$onError( C.TOPIC.RECORD, message.data[ 0 ], message.data[ 1 ] );
Expand All @@ -190,7 +190,7 @@ RecordHandler.prototype._$handle = function( message ) {
*/
if( message.data[ 0 ] === C.ACTIONS.DELETE || message.data[ 0 ] === C.ACTIONS.UNSUBSCRIBE ) {
this._destroyEventEmitter.emit( 'destroy_ack_' + name, message );

if( message.data[ 0 ] === C.ACTIONS.DELETE && this._records[ name ] ) {
this._records[ name ]._$onMessage( message );
}
Expand Down Expand Up @@ -219,23 +219,23 @@ RecordHandler.prototype._$handle = function( message ) {
if( this._records[ name ] ) {
processed = true;
this._records[ name ]._$onMessage( message );
}
}

if( message.action === C.ACTIONS.READ && this._snapshotRegistry.hasRequest( name ) ) {
processed = true;
this._snapshotRegistry.recieve( name, null, JSON.parse( message.data[ 2 ] ) );
}

if( message.action === C.ACTIONS.HAS && this._hasRegistry.hasRequest( name ) ) {
processed = true;
this._hasRegistry.recieve( name, null, messageParser.convertTyped( message.data[ 1 ] ) );
}

if( this._listener[ name ] ) {
processed = true;
this._listener[ name ]._$onMessage( message );
}
}

if( !processed ) {
this._client._$onError( C.TOPIC.RECORD, C.EVENT.UNSOLICITED_MESSAGE, name );
}
Expand All @@ -245,7 +245,7 @@ RecordHandler.prototype._$handle = function( message ) {
* Callback for 'error' events from the record.
*
* @param {String} recordName
* @param {String} error
* @param {String} error
*
* @private
* @returns {void}
Expand Down
10 changes: 5 additions & 5 deletions src/record/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ EventEmitter( Record.prototype );

/**
* Set a merge strategy to resolve any merge conflicts that may occur due
* to offline work or write conflicts. The function will be called with the
* local record, the remote version/data and a callback to call once the merge has
* to offline work or write conflicts. The function will be called with the
* local record, the remote version/data and a callback to call once the merge has
* completed or if an error occurs ( which leaves it in an inconsistent state until
* the next update merge attempt ).
*
Expand Down Expand Up @@ -312,24 +312,24 @@ Record.prototype._$onMessage = function( message ) {
* @returns {void}
*/
Record.prototype._recoverRecord = function( remoteVersion, remoteData, message ) {
message.processedError = true;
if( this._mergeStrategy ) {
this._mergeStrategy( this, remoteData, remoteVersion, this._onRecordRecovered.bind( this, remoteVersion ) );
}
else {
message.processedError = true;
this.emit( 'error', C.EVENT.VERSION_EXISTS, 'received update for ' + remoteVersion + ' but version is ' + this.version );
}
};

/**
* Callback once the record merge has completed. If successful it will set the
* record state, else emit and error and the record will remain in an
* record state, else emit and error and the record will remain in an
* inconsistent state until the next update.
*
* @param {Number} remoteVersion The remote version number
* @param {Object} remoteData The remote object data
* @param {Object} message parsed and validated deepstream message
*
*
* @private
* @returns {void}
*/
Expand Down
5 changes: 5 additions & 0 deletions test-e2e/permissions-complex.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
"write": "!oldData.value || data.value > oldData.value",
"create": true,
"read": true
},
"only-decrement": {
"write": "!oldData.value || data.value < oldData.value",
"create": true,
"read": true
},
"only-delete-egon-miller/$firstname/$lastname": {
"delete": "$firstname.toLowerCase() === 'egon' && $lastname.toLowerCase() === 'miller'"
Expand Down
1 change: 0 additions & 1 deletion test-e2e/specs/anonymous-recordSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe( 'anonymous record', function() {
deepstreamServer.on( 'started', done );
deepstreamServer.set( 'logger', logger );
deepstreamServer.set( 'showLogo', false );
deepstreamServer.set( 'permissionConfigPath', './test-e2e/permissions.json' );
deepstreamServer.start();
});

Expand Down
3 changes: 1 addition & 2 deletions test-e2e/specs/connection-lostSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ describe( 'it recovers a connection without losing record updates', function() {
/**************** SETUP ****************/
it( 'starts the server', function( done ){
deepstreamServer = new DeepstreamServer();
deepstreamServer.set( 'permissionConfigPath', './test-e2e/permissions.json' );
deepstreamServer.once( 'started', done );
deepstreamServer.set( 'logger', logger );
deepstreamServer.set( 'showLogo', false );
Expand All @@ -23,7 +22,7 @@ describe( 'it recovers a connection without losing record updates', function() {
/**************** TESTS ****************/
it( 'connects', function( done ) {
clientA = deepstreamClient( 'localhost:6021', {
mergeStrategy: function( record, remoteVersion, remoteData, callback ) {
mergeStrategy: function( record, remoteData, remoteVersion, callback ) {
callback( 'Error Merging' );
}
} );
Expand Down
Loading

0 comments on commit 2b0451d

Please sign in to comment.