Skip to content

Commit

Permalink
2.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Harley committed Jun 2, 2017
1 parent e1e84a8 commit 58db6ff
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 38 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [2.2.1] - 2017-06-02

### Fixes
- Update `dist/` files correctly

## [2.2.0] - 2017-05-29

### Features
Expand Down
117 changes: 100 additions & 17 deletions dist/deepstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,7 @@ exports.ACTIONS.LISTEN_REJECT = 'LR';
exports.ACTIONS.PROVIDER_UPDATE = 'PU';
exports.ACTIONS.QUERY = 'Q';
exports.ACTIONS.CREATEORREAD = 'CR';
exports.ACTIONS.CREATEANDUPDATE = 'CU';
exports.ACTIONS.EVENT = 'EVT';
exports.ACTIONS.ERROR = 'E';
exports.ACTIONS.REQUEST = 'REQ';
Expand Down Expand Up @@ -4273,13 +4274,16 @@ module.exports = List;
},{"../constants/constants":11,"./record":23,"component-emitter2":1}],22:[function(_dereq_,module,exports){
'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

var Record = _dereq_('./record');
var AnonymousRecord = _dereq_('./anonymous-record');
var List = _dereq_('./list');
var Listener = _dereq_('../utils/listener');
var SingleNotifier = _dereq_('../utils/single-notifier');
var C = _dereq_('../constants/constants');
var messageParser = _dereq_('../message/message-parser');
var messageBuilder = _dereq_('../message/message-builder');
var EventEmitter = _dereq_('component-emitter2');

/**
Expand All @@ -4297,6 +4301,7 @@ var RecordHandler = function RecordHandler(options, connection, client) {
this._records = {};
this._lists = {};
this._listener = {};
this._writeCallbacks = {};
this._destroyEventEmitter = new EventEmitter();

this._hasRegistry = new SingleNotifier(client, connection, C.TOPIC.RECORD, C.ACTIONS.HAS, this._options.recordReadTimeout);
Expand Down Expand Up @@ -4461,6 +4466,80 @@ RecordHandler.prototype.has = function (name, callback) {
}
};

/**
* Allows setting the data for a record without being subscribed to it. If
* the client is subscribed to the record locally, the update will be proxied
* through the record object like a normal call to Record.set. Otherwise a force
* write will be performed that overwrites any remote data.
*
* @param {String} recordName the name of the record to write to
* @param {String|Object} pathOrData either the path to write data to or the data to
* set the record to
* @param {Object|Primitive|Function} dataOrCallback either the data to write to the
* record or a callback function
* indicating write success
* @param {Function} callback if provided this will be called with the result of the
* write
*/
RecordHandler.prototype.setData = function (recordName, pathOrData, dataOrCallback, callback) {
var path = void 0;
var data = void 0;
var cb = void 0;
var valid = false;

if (arguments.length === 4) {
// setData(recordName, path, data, cb)
path = pathOrData;
data = dataOrCallback;
cb = callback;
valid = true;
} else if (arguments.length === 3) {
if (typeof pathOrData === 'string' && typeof dataOrCallback !== 'function') {
// setData(recordName, path, data)
path = pathOrData;
data = dataOrCallback;
valid = true;
} else if ((typeof pathOrData === 'undefined' ? 'undefined' : _typeof(pathOrData)) === 'object' && typeof dataOrCallback === 'function') {
// setData(recordName, data, callback)
path = null;
data = pathOrData;
cb = dataOrCallback;
valid = true;
}
} else if (arguments.length === 2 && (typeof pathOrData === 'undefined' ? 'undefined' : _typeof(pathOrData)) === 'object') {
// setData(recordName, data)
data = pathOrData;
valid = true;
}

if (!valid) {
throw new Error('incorrect arguments used: records must exist as objects at the root level');
}

var record = this._records[recordName];
if (record) {
if (path && cb) {
record.set(path, data, cb);
} else if (path) {
record.set(path, data);
} else if (cb) {
record.set(data, cb);
} else {
record.set(data);
}
} else {
var recordData = path ? [recordName, -1, path, messageBuilder.typed(data)] : [recordName, -1, data];
var config = {};
if (cb) {
config.writeSuccess = true;
this._writeCallbacks[recordName] = {};
this._writeCallbacks[recordName][-1] = cb;
}
recordData.push(config);
this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.CREATEANDUPDATE, recordData);
}
};

/**
* Will be called by the client for incoming messages on the RECORD topic
*
Expand Down Expand Up @@ -4515,22 +4594,22 @@ RecordHandler.prototype._$handle = function (message) {

var processed = false;

if (this._records[name]) {
var record = this._records[name];
if (record) {
processed = true;
this._records[name]._$onMessage(message);
record._$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)) {
} else if (message.action === C.ACTIONS.HAS && this._hasRegistry.hasRequest(name)) {
processed = true;
this._hasRegistry.recieve(name, null, messageParser.convertTyped(message.data[1]));
}

if (message.action === C.ACTIONS.ACK && message.data[0] === C.ACTIONS.UNLISTEN && this._listener[name] && this._listener[name].destroyPending) {
} else if (message.action === C.ACTIONS.WRITE_ACKNOWLEDGEMENT && !record) {
processed = true;
Record._handleWriteAcknowledgements(message, this._writeCallbacks[name], this._client);
} else if (message.action === C.ACTIONS.ACK && message.data[0] === C.ACTIONS.UNLISTEN && this._listener[name] && this._listener[name].destroyPending) {
processed = true;
this._listener[name].destroy();
delete this._listener[name];
Expand Down Expand Up @@ -4600,7 +4679,7 @@ RecordHandler.prototype._removeRecord = function (recordName) {

module.exports = RecordHandler;

},{"../constants/constants":11,"../message/message-parser":17,"../utils/listener":28,"../utils/single-notifier":30,"./anonymous-record":19,"./list":21,"./record":23,"component-emitter2":1}],23:[function(_dereq_,module,exports){
},{"../constants/constants":11,"../message/message-builder":16,"../message/message-parser":17,"../utils/listener":28,"../utils/single-notifier":30,"./anonymous-record":19,"./list":21,"./record":23,"component-emitter2":1}],23:[function(_dereq_,module,exports){
'use strict';
/* eslint-disable prefer-spread, prefer-rest-params */

Expand Down Expand Up @@ -4973,14 +5052,7 @@ Record.prototype._$onMessage = function (message) {
} else if (message.action === C.ACTIONS.UPDATE || message.action === C.ACTIONS.PATCH) {
this._applyUpdate(message, this._client);
} else if (message.action === C.ACTIONS.WRITE_ACKNOWLEDGEMENT) {
var versions = JSON.parse(message.data[1]);
for (var i = 0; i < versions.length; i++) {
var callback = this._writeCallbacks[versions[i]];
if (callback !== undefined) {
callback(messageParser.convertTyped(message.data[2], this._client));
delete this._writeCallbacks[versions[i]];
}
}
Record._handleWriteAcknowledgements(message, this._writeCallbacks, this._client);
} else if (message.data[0] === C.EVENT.VERSION_EXISTS) {
// Otherwise it should be an error, and dealt with accordingly
this._recoverRecord(message.data[2], JSON.parse(message.data[3]), message);
Expand All @@ -4993,6 +5065,17 @@ Record.prototype._$onMessage = function (message) {
}
};

Record._handleWriteAcknowledgements = function (message, callbacks, client) {
var versions = JSON.parse(message.data[1]);
for (var i = 0; i < versions.length; i++) {
var callback = callbacks[versions[i]];
if (callback !== undefined) {
callback(messageParser.convertTyped(message.data[2], client));
delete callbacks[versions[i]];
}
}
};

/**
* Called when a merge conflict is detected by a VERSION_EXISTS error or if an update recieved
* is directly after the clients. If no merge strategy is configure it will emit a VERSION_EXISTS
Expand Down
8 changes: 4 additions & 4 deletions dist/deepstream.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/lib/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ exports.ACTIONS.LISTEN_REJECT = 'LR';
exports.ACTIONS.PROVIDER_UPDATE = 'PU';
exports.ACTIONS.QUERY = 'Q';
exports.ACTIONS.CREATEORREAD = 'CR';
exports.ACTIONS.CREATEANDUPDATE = 'CU';
exports.ACTIONS.EVENT = 'EVT';
exports.ACTIONS.ERROR = 'E';
exports.ACTIONS.REQUEST = 'REQ';
Expand Down
94 changes: 86 additions & 8 deletions dist/lib/record/record-handler.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

var Record = require('./record');
var AnonymousRecord = require('./anonymous-record');
var List = require('./list');
var Listener = require('../utils/listener');
var SingleNotifier = require('../utils/single-notifier');
var C = require('../constants/constants');
var messageParser = require('../message/message-parser');
var messageBuilder = require('../message/message-builder');
var EventEmitter = require('component-emitter2');

/**
Expand All @@ -24,6 +27,7 @@ var RecordHandler = function RecordHandler(options, connection, client) {
this._records = {};
this._lists = {};
this._listener = {};
this._writeCallbacks = {};
this._destroyEventEmitter = new EventEmitter();

this._hasRegistry = new SingleNotifier(client, connection, C.TOPIC.RECORD, C.ACTIONS.HAS, this._options.recordReadTimeout);
Expand Down Expand Up @@ -188,6 +192,80 @@ RecordHandler.prototype.has = function (name, callback) {
}
};

/**
* Allows setting the data for a record without being subscribed to it. If
* the client is subscribed to the record locally, the update will be proxied
* through the record object like a normal call to Record.set. Otherwise a force
* write will be performed that overwrites any remote data.
*
* @param {String} recordName the name of the record to write to
* @param {String|Object} pathOrData either the path to write data to or the data to
* set the record to
* @param {Object|Primitive|Function} dataOrCallback either the data to write to the
* record or a callback function
* indicating write success
* @param {Function} callback if provided this will be called with the result of the
* write
*/
RecordHandler.prototype.setData = function (recordName, pathOrData, dataOrCallback, callback) {
var path = void 0;
var data = void 0;
var cb = void 0;
var valid = false;

if (arguments.length === 4) {
// setData(recordName, path, data, cb)
path = pathOrData;
data = dataOrCallback;
cb = callback;
valid = true;
} else if (arguments.length === 3) {
if (typeof pathOrData === 'string' && typeof dataOrCallback !== 'function') {
// setData(recordName, path, data)
path = pathOrData;
data = dataOrCallback;
valid = true;
} else if ((typeof pathOrData === 'undefined' ? 'undefined' : _typeof(pathOrData)) === 'object' && typeof dataOrCallback === 'function') {
// setData(recordName, data, callback)
path = null;
data = pathOrData;
cb = dataOrCallback;
valid = true;
}
} else if (arguments.length === 2 && (typeof pathOrData === 'undefined' ? 'undefined' : _typeof(pathOrData)) === 'object') {
// setData(recordName, data)
data = pathOrData;
valid = true;
}

if (!valid) {
throw new Error('incorrect arguments used: records must exist as objects at the root level');
}

var record = this._records[recordName];
if (record) {
if (path && cb) {
record.set(path, data, cb);
} else if (path) {
record.set(path, data);
} else if (cb) {
record.set(data, cb);
} else {
record.set(data);
}
} else {
var recordData = path ? [recordName, -1, path, messageBuilder.typed(data)] : [recordName, -1, data];
var config = {};
if (cb) {
config.writeSuccess = true;
this._writeCallbacks[recordName] = {};
this._writeCallbacks[recordName][-1] = cb;
}
recordData.push(config);
this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.CREATEANDUPDATE, recordData);
}
};

/**
* Will be called by the client for incoming messages on the RECORD topic
*
Expand Down Expand Up @@ -242,22 +320,22 @@ RecordHandler.prototype._$handle = function (message) {

var processed = false;

if (this._records[name]) {
var record = this._records[name];
if (record) {
processed = true;
this._records[name]._$onMessage(message);
record._$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)) {
} else if (message.action === C.ACTIONS.HAS && this._hasRegistry.hasRequest(name)) {
processed = true;
this._hasRegistry.recieve(name, null, messageParser.convertTyped(message.data[1]));
}

if (message.action === C.ACTIONS.ACK && message.data[0] === C.ACTIONS.UNLISTEN && this._listener[name] && this._listener[name].destroyPending) {
} else if (message.action === C.ACTIONS.WRITE_ACKNOWLEDGEMENT && !record) {
processed = true;
Record._handleWriteAcknowledgements(message, this._writeCallbacks[name], this._client);
} else if (message.action === C.ACTIONS.ACK && message.data[0] === C.ACTIONS.UNLISTEN && this._listener[name] && this._listener[name].destroyPending) {
processed = true;
this._listener[name].destroy();
delete this._listener[name];
Expand Down
20 changes: 12 additions & 8 deletions dist/lib/record/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,7 @@ Record.prototype._$onMessage = function (message) {
} else if (message.action === C.ACTIONS.UPDATE || message.action === C.ACTIONS.PATCH) {
this._applyUpdate(message, this._client);
} else if (message.action === C.ACTIONS.WRITE_ACKNOWLEDGEMENT) {
var versions = JSON.parse(message.data[1]);
for (var i = 0; i < versions.length; i++) {
var callback = this._writeCallbacks[versions[i]];
if (callback !== undefined) {
callback(messageParser.convertTyped(message.data[2], this._client));
delete this._writeCallbacks[versions[i]];
}
}
Record._handleWriteAcknowledgements(message, this._writeCallbacks, this._client);
} else if (message.data[0] === C.EVENT.VERSION_EXISTS) {
// Otherwise it should be an error, and dealt with accordingly
this._recoverRecord(message.data[2], JSON.parse(message.data[3]), message);
Expand All @@ -390,6 +383,17 @@ Record.prototype._$onMessage = function (message) {
}
};

Record._handleWriteAcknowledgements = function (message, callbacks, client) {
var versions = JSON.parse(message.data[1]);
for (var i = 0; i < versions.length; i++) {
var callback = callbacks[versions[i]];
if (callback !== undefined) {
callback(messageParser.convertTyped(message.data[2], client));
delete callbacks[versions[i]];
}
}
};

/**
* Called when a merge conflict is detected by a VERSION_EXISTS error or if an update recieved
* is directly after the clients. If no merge strategy is configure it will emit a VERSION_EXISTS
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deepstream.io-client-js",
"version": "2.2.0",
"version": "2.2.1",
"description": "the javascript client for deepstream.io",
"main": "dist/lib/client.js",
"types": "src/client.d.ts",
Expand Down

0 comments on commit 58db6ff

Please sign in to comment.