diffusion
Advanced tools
Comparing version 5.9.0 to 5.9.1
{ | ||
"name": "diffusion", | ||
"version": "5.9.0", | ||
"version": "5.9.1", | ||
"description": "Diffusion Javascript UCI client", | ||
@@ -5,0 +5,0 @@ "keywords" : ["diffusion", "reappt", "websockets", "data"], |
@@ -61,4 +61,7 @@ var _interface = require('util/interface').interface; | ||
* @example | ||
* var delta = jsonValue.diff({ foo : "bar" }); | ||
* var binaryDelta = jsonValue.diff({ foo : "bar" }); | ||
* | ||
* @example | ||
* var jsonDelta = jsonValue.diff({ foo : "bar" }, "json"); | ||
* | ||
* @param {diffusion.datatypes.JSON|Object} original - The value to diff against this | ||
@@ -73,2 +76,22 @@ * @param {String} [type="binary"] - The type of delta to generate | ||
/** | ||
* Compare this JSON value with an earlier version to create a structural {@link JSONDelta json delta}. | ||
* <P> | ||
* | ||
* Convenient equivalent to: | ||
* <code>this.diff(original, "json"); | ||
* <P> | ||
* Standard JSON objects may also be provided as the value to diff instead of a {@link diffusion.datatypes.JSON} | ||
* instance. | ||
* | ||
* @example | ||
* var delta = jsonValue.jsonDiff({ foo : "bar" }); | ||
* | ||
* @param {diffusion.datatypes.JSON|Object} original - The value to diff against this | ||
* @return {diffusion.datatypes.JSONDelta} A delta representing the difference between this and the provided value | ||
* | ||
* @function diffusion.datatypes.JSON#jsonDiff | ||
*/ | ||
'jsonDiff', | ||
/** | ||
* Apply a delta to this JSON value to create a new value. | ||
@@ -75,0 +98,0 @@ * <P> |
@@ -36,5 +36,5 @@ var SessionImpl = require('session/session-impl'); | ||
*/ | ||
version: '5.9.0', | ||
version: '5.9.1', | ||
build: '0_dev#internal', | ||
build: '1_dev#internal', | ||
@@ -41,0 +41,0 @@ /** |
@@ -30,4 +30,5 @@ var _interface = require('util/interface').interface; | ||
* | ||
* @fires Stream#error | ||
* @fires Stream#close | ||
* @fires FetchStream#open | ||
* @fires FetchStream#close | ||
* @fires FetchStream#value | ||
@@ -52,8 +53,2 @@ * | ||
*/ | ||
/** | ||
* Emitted when the fetch request has been completed. No further events will be emitted after this. | ||
* | ||
* @event FetchStream#close | ||
*/ | ||
]); |
@@ -17,2 +17,3 @@ var _interface = require('util/interface').interface; | ||
* @fires Stream#error | ||
* @fires Stream#close | ||
* | ||
@@ -56,4 +57,17 @@ * @class Stream | ||
* | ||
* @example | ||
* // Bind a single listener to the 'foo' event and then deregister it | ||
* var listener = function() {}; | ||
* stream.on('foo', listener); | ||
* stream.off('foo', listener); | ||
* | ||
* @example | ||
* // Bind a listener to the 'foo' event and deregister all listeners | ||
* var listener = function() {}; | ||
* stream.on('foo', listener); | ||
* stream.off('foo'); | ||
* | ||
* @param {String} event - The event to remove listeners from | ||
* @param {Function} listener - The listener to remove | ||
* @param {Function} [listener] - The listener to remove. | ||
* All listeners for the event are removed if this is not specified | ||
* | ||
@@ -66,3 +80,4 @@ * @returns {Stream} This stream. | ||
/** | ||
* Emitted when the fetch request has been completed. No further events will be emitted after this. | ||
* Emitted when an error occurs in the {@link Stream} or in any of its listeners. | ||
* No further events will be emitted after this. | ||
* | ||
@@ -72,2 +87,9 @@ * @event Stream#error | ||
*/ | ||
/** | ||
* Emitted when the {@link Stream} has been closed through completion or the underlying session has been closed. | ||
* No further events will be emitted after this. | ||
* | ||
* @event Stream#close | ||
*/ | ||
]); |
@@ -22,3 +22,3 @@ var _interface = require('util/interface').interface; | ||
* The message content may be of any type that can be used for topic {@link Session.topics#update updates}. It is | ||
* up to any receiving session to deserialise it as appropriate. | ||
* up to any receiving session to de-serialise it as appropriate. | ||
* <P> | ||
@@ -38,7 +38,8 @@ * An optional argument may be provided to target a specific session or a collection of sessions that satisfy a | ||
* If a Session ID was used as the recipient, then the result will resolve with an object containing both | ||
* <code>path</code> and <code>recipient</code> fields. | ||
* <code>path</code> and <code>recipient</code> fields. The result will only resolve when the message has | ||
* been successfully received by the intended recipient. | ||
* <P> | ||
* If a Session Filter was used to send the message, then the result will contain <code>path</code>, | ||
* <code>recipient</code>, <code>sent</code> and <code>errors</code> fields. The <code>sent</code> field specifies | ||
* the number of sessions that the filter resolved and succesfully sent the message to. The <code>errors</code> | ||
* the number of sessions that the filter resolved and successfully sent the message to. The <code>errors</code> | ||
* field contains an array of errors for any session that could not receive the message. | ||
@@ -61,3 +62,4 @@ * | ||
* @param {Session.messages.SendOptions} [options] - The optional message send options | ||
* @param {String} [sessionID | filter] - The target recipient's Session ID as a string or a filter string. | ||
* @param {(String|Object)} [target] - The target recipient's Session ID (as a string or | ||
* Session ID object) or a session property filter string. | ||
* @returns {Result} The result of the send operation | ||
@@ -147,2 +149,4 @@ * @function Session.messages#send | ||
* | ||
* @fires Stream#error | ||
* @fires Stream#close | ||
* @fires Session.messages.MessageStream#message | ||
@@ -149,0 +153,0 @@ * |
@@ -36,3 +36,3 @@ module.exports.types = { | ||
module.exports.isStructStart = function(token) { | ||
switch (token) { | ||
switch (token) { | ||
case module.exports.tokens.ARRAY_START : | ||
@@ -39,0 +39,0 @@ case module.exports.tokens.MAP_START : |
@@ -11,2 +11,5 @@ var Context = require('./context'); | ||
// Used for buffer value of virtual tokens | ||
var EMPTY_BUFFER = new Buffer([]); | ||
function Tokeniser(data, offset, length) { | ||
@@ -36,3 +39,3 @@ length = length === undefined ? data.length : length; | ||
return pos < len; | ||
return pos < offset + len; | ||
}; | ||
@@ -59,3 +62,3 @@ | ||
var ctx = context.type(); | ||
var p = pos; | ||
var previousPos = pos; | ||
@@ -78,4 +81,7 @@ if (ctx !== 'root' && !context.hasRemaining()) { | ||
return { | ||
pos : p, | ||
type : type | ||
pos : pos, | ||
type : type, | ||
getBuffer : function() { | ||
return EMPTY_BUFFER; | ||
} | ||
}; | ||
@@ -142,6 +148,10 @@ } else { | ||
token = { | ||
pos : p, | ||
pos : previousPos, | ||
type : type, | ||
value : value, | ||
header : header | ||
header : header, | ||
length : pos, | ||
getBuffer : function() { | ||
return data.slice(this.pos, this.length); | ||
} | ||
}; | ||
@@ -197,6 +207,3 @@ | ||
function readBuffer(len) { | ||
var buf = new Buffer(len); | ||
data.copy(buf, 0, pos, pos += len); | ||
return buf; | ||
return data.slice(pos, pos += len); | ||
} | ||
@@ -203,0 +210,0 @@ |
var implements = require('util/interface').implements; | ||
var Tokeniser = require('cbor/tokeniser'); | ||
var BinaryDelta = require('../../../data/binary/binary-delta'); | ||
@@ -9,2 +11,31 @@ | ||
this.visit = function(visitor) { | ||
if (this.hasChanges()) { | ||
var tokeniser = new Tokeniser(buffer, offset, length); | ||
while (tokeniser.hasRemaining()) { | ||
var token = tokeniser.nextToken(); | ||
var isEnd = false; | ||
if (Buffer.isBuffer(token.value)) { | ||
isEnd = !visitor.insert(token.value); | ||
} else { | ||
var start = token.value; | ||
var end = tokeniser.nextToken().value; | ||
isEnd = !visitor.match(start, end); | ||
} | ||
if (isEnd) { | ||
visitor.end(); | ||
return; | ||
} | ||
} | ||
visitor.end(); | ||
} else { | ||
visitor.noChange(); | ||
} | ||
}; | ||
this.hasChanges = function() { | ||
@@ -11,0 +42,0 @@ return length !== 1; |
@@ -23,2 +23,23 @@ var implements = require('util/interface').implements; | ||
}; | ||
this.equalBytes = function(buffer, offset, length) { | ||
if (this.$length !== length) { | ||
return false; | ||
} | ||
var $buffer = this.$buffer; | ||
var $offset = this.$offset; | ||
if ($buffer === buffer && $offset === offset) { | ||
return true; | ||
} | ||
for (var i = 0; i < length; ++i) { | ||
if ($buffer[$offset + i] !== buffer[offset + i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
}); |
@@ -5,2 +5,3 @@ var implements = require('util/interface').implements; | ||
var JSONDeltaImpl = require('data/json/json-delta-impl'); | ||
var JSONType = require('../../../data/json/json'); | ||
@@ -27,7 +28,15 @@ | ||
this.diff = function(original, type) { | ||
type = type || "binary"; | ||
var binaryDiff = datatype.deltaType("binary").diff(original, self); | ||
return datatype.deltaType(type).diff(original, self); | ||
if (type === "json") { | ||
return new JSONDeltaImpl(datatype, original, self, binaryDiff); | ||
} else { | ||
return binaryDiff; | ||
} | ||
}; | ||
this.jsonDiff = function(original) { | ||
return self.diff(original, "json"); | ||
}; | ||
this.apply = function(delta) { | ||
@@ -34,0 +43,0 @@ return datatype.deltaType(delta).apply(self, delta); |
@@ -30,6 +30,8 @@ var requireNonNull = require('util/require-non-null'); | ||
for (; i < pointer.segments.length; ++i) { | ||
var c = node.findChild(pointer.segments[i]); | ||
for (; i < pointer.segments.length;) { | ||
var s = pointer.segments[i++]; | ||
var c = node.findChild(s); | ||
if (c === null) { | ||
node = node.addChild(s); | ||
break; | ||
@@ -41,9 +43,7 @@ } | ||
for (; i < pointer.segments.length; ++i) { | ||
for (; i < pointer.segments.length; i++) { | ||
node = node.addChild(pointer.segments[i]); | ||
} | ||
var prev = node.setValue(value); | ||
return prev; | ||
return node.setValue(value); | ||
}; | ||
@@ -50,0 +50,0 @@ |
@@ -212,5 +212,3 @@ var JSONPointer = require('data/json/json-pointer'); | ||
} | ||
} while (consumeFirstValue || | ||
next < offset || | ||
!consts.isStructStart(t) && self.nextTokenIsStructEnd(next)); | ||
} while (consumeFirstValue || next < offset || self.nextTokenIsStructEnd(t, next)); | ||
@@ -226,8 +224,12 @@ for (var i = 0; i < parentStack.length; ++i) { | ||
this.nextTokenIsStructEnd = function(next) { | ||
this.nextTokenIsStructEnd = function(t, next) { | ||
var context = tokeniser.getContext(); | ||
if (consts.isStructStart(t.type)) { | ||
return context.expected() === 0; | ||
} | ||
return context.acceptsBreakMarker() && | ||
next < json.$length && | ||
json.$buffer[json.$offset + next] === consts.additional.BREAK || | ||
(json.$buffer[json.$offset + next] & 0x1F) === consts.additional.BREAK || | ||
!context.hasRemaining(); | ||
@@ -234,0 +236,0 @@ }; |
var topicSelectorParser = require('topics/topic-selector-parser'); | ||
var implements = require('util/interface').implements; | ||
var CommandError = require('services/command-error'); | ||
var Services = require('services/services'); | ||
@@ -59,9 +61,20 @@ | ||
onRequest : function(internal, message, callback) { | ||
callback.respond(); | ||
var received = false; | ||
streams.forEach(function(stream) { | ||
if (stream.l.selector.selects(message.path)) { | ||
stream.e.emit('message', message); | ||
} | ||
}); | ||
streams.forEach(function(stream) { | ||
if (stream.l.selector.selects(message.path)) { | ||
stream.e.emit('message', message); | ||
received = true; | ||
} | ||
}); | ||
if (received) { | ||
callback.respond(); | ||
} else { | ||
logger.info("No messaging streams registered for message on path: " + message.path); | ||
callback.fail(new CommandError(CommandError.ErrorType.COMMUNICATION_FAILURE, | ||
"Session " + internal.getSessionId() + | ||
"has no registered streams for message sent to: " + message.path)); | ||
} | ||
} | ||
@@ -197,3 +210,3 @@ }); | ||
// or a SendFilter. | ||
if (options && typeof options === 'string') { | ||
if (options && (typeof options === 'string' || options instanceof SessionId)) { | ||
recipient = options; | ||
@@ -219,3 +232,3 @@ options = createSendOptions(); | ||
if (recipient) { | ||
var session = parseSessionId(recipient); | ||
var session = typeof recipient === 'string' ? parseSessionId(recipient) : recipient; | ||
@@ -222,0 +235,0 @@ if (session) { |
@@ -99,9 +99,9 @@ var split = require('util/string').split; | ||
qualifier = DQ.MATCH_AND_DESCENDANTS; | ||
base = remainder.substring(0, remainder.length - 2); | ||
base = utils.canonicalise(remainder.substring(0, remainder.length - 2)); | ||
} else { | ||
qualifier = DQ.DESCENDANTS_OF_MATCH; | ||
base = remainder.substring(0, remainder.length - 1); | ||
base = utils.canonicalise(remainder.substring(0, remainder.length - 1)); | ||
} | ||
} else { | ||
base = remainder; | ||
base = utils.canonicalise(remainder); | ||
qualifier = DQ.MATCH; | ||
@@ -108,0 +108,0 @@ } |
@@ -37,3 +37,4 @@ import {Session} from './session.d'; | ||
ALL_USER_PROPERTIES: any; | ||
ALL_PROPERTIES: any; | ||
}; | ||
}; |
@@ -38,2 +38,3 @@ import {Session} from './session.d'; | ||
ALL_USER_PROPERTIES: any; | ||
ALL_PROPERTIES: any; | ||
}; | ||
@@ -40,0 +41,0 @@ }; |
@@ -6,3 +6,3 @@ import {Result} from '../events/result.d'; | ||
export interface Messages { | ||
send: (path: string, message: any, sessionID?: string) => Result<SendResult, any>; | ||
send: (path: string, message: any, sessionID?: string | Object) => Result<SendResult, any>; | ||
listen: (path: string, listener?: (message: SessionMessage) => void) => MessageStream; | ||
@@ -9,0 +9,0 @@ addHandler: (path: string, handler: MessageHandler) => Result<void, any>; |
@@ -5,4 +5,4 @@ import {Subscription} from './../events/subscription.d'; | ||
import {Result} from './../events/result.d'; | ||
import {Json} from '../data/json.d.ts'; | ||
import {Binary} from '../data/binary.d.ts'; | ||
import {Json} from '../data/json.d'; | ||
import {Binary} from '../data/binary.d'; | ||
@@ -9,0 +9,0 @@ export interface Topics { |
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
627507
313
17127