Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

diffusion

Package Overview
Dependencies
Maintainers
1
Versions
191
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

diffusion - npm Package Compare versions

Comparing version 5.9.2 to 5.9.3

5

package.json
{
"name": "diffusion",
"version": "5.9.2",
"version": "5.9.3",
"description": "Diffusion Javascript UCI client",

@@ -19,3 +19,3 @@ "keywords" : ["diffusion", "reappt", "websockets", "data"],

"inherits" : "2.0.1",
"hashmap" : "2.0.3",
"hashmap" : "2.0.6",
"long" : "2.2.5",

@@ -37,2 +37,3 @@ "loglevel" : "1.4.0",

"gulp-insert" : "0.5.0",
"gulp-strip-comments" : "2.4.3",
"gulp-remove-empty-lines" : "0.0.8",

@@ -39,0 +40,0 @@ "sinon" : "1.17.5",

116

README.md

@@ -7,3 +7,4 @@ ## Diffusion JavaScript API

Clients use a WebSocket or plain HTTP connection to send and receive, as well as perform
other functions such as adding, removing or updating topics.
other functions such as adding, removing or updating topics. For a full list of capabilities
in the JavaScript API, see the [Contents](index.html#toc3) section below.

@@ -86,3 +87,3 @@

accessed without requiring decoding. These values are then delivered as [value](TypedSubscription.html#event:value) events. So, for instance,
to subscribe to a stream of [JSON](DataTypes.JSON.html) updates:
to subscribe to a stream of [JSON](diffusion.datatypes.JSON.html) updates:

@@ -108,2 +109,113 @@ ```javascript

### Contents
The JavaScript client provides namespaces, classes, and methods that support the following capabilities:
#### Basics
* Connect the JavaScript client to Diffusion or Reappt by using the [diffusion.connect](diffusion.html#connect) method.
* To change the security principal that the client is connected with, use the [changePrincipal](Session.security.html#changePrincipal) method.
* The client can log out information by using the [diffusion.log](diffusion.html#log) method.
#### Receive data from topics
* Subscribe to JSON or binary topics.
Use the [session.subscribe](Session.html#subscribe) method to subscribe to a topic and get a [Subscription](Subscription.html) object that you can use to receive
updates and subscription events.
The updates to a JSON or binary topic can be interacted with by the classes in the [diffusion.datatypes](diffusion.datatypes.html) namespace. Call
[asType](Subscription.html#asType) method on your [Subscription](Subscription.html) object to get a [TypedSubscription](TypedSubscription.html) that receives
the values as a particular datatype.
* Fetch data from topics.
Use the [fetch](Session.html#fetch) method to make a fetch request and get a [FetchStream](FetchStream.html) object that you can use to receive fetched values.
* Subscribe to other topic types.
Use the [session.subscribe](Session.html#subscribe) method to subscribe to a topic and get a [Subscription](Subscription.html) object that you can use to
receive updates and subscription events.
The updates to record topics can be interacted with by the classes in the [diffusion.metadata](diffusion.metadata.html) namespace.
#### Create and manage topics
* Add a topic.
Use the [add](Session.topics.html#add) method to add a topic. Depending on the parameters you pass to the method, you can create a topic from an initial
value, by explicitly defining the topic type, or by providing metadata.
* Handle missing topics.
Use the [addMissingTopicHandler](Session.topics.html#addMissingTopicHandler) method to register a [MissingTopicHandler](MissingTopicHandler.html).
This handler receives a [MissingTopicNotification](MissingTopicNotification.html) when a client session subscribes to a topic that does not currently exist.
The notified client can then choose to create that topic if appropriate.
* Remove topics.
Use the [remove](Session.topics.html#remove) method to remove topics. You can also mark topics to be deleted when the client session closes with the
[removeWithSession](Session.topics.html#removeWithSession) method.
#### Update topics
* Update a topic non-exclusively by using the [update](Session.topics.html#update) method.
* Update a topic exclusively.
Use the [registerUpdateSource](Session.topics.html#registerUpdateSource) method to register a [TopicUpdateHandler](TopicUpdateHandler.html) to perform
updates on a topic.
* Update JSON or binary topics by using the classes in the [diffusion.datatypes](diffusion.datatypes.html) namespace to create update values.
* Update other topic types by using the classes in the [diffusion.metadata](diffusion.metadata.html) namespace to create update values.
#### Manage other clients
* Subscribe other client sessions to topics.
Use the [subscribe](Session.clients.html#subscribe) and [unsubscribe](Session.clients.html#subscribe) methods in [Session.clients](Session.clients.html)
namespace to manage another client session's subscriptions.
* Receive notifications about other sessions and their properties.
Use the [setSessionPropertiesListener](Session.clients.html#setSessionPropertiesListener) method to register
a [SessionPropertiesListener](Session.clients.SessionPropertiesListener.html) to receive notifications for session events or when a session changes properties.
* Query the session properties of a specific session.
Use the [getSessionProperties](Session.clients.html#getSessionProperties) method. Specify which sets of properties to receive using
[PropertyKeys](diffusion.clients.html#.PropertyKeys).
#### Send messages
* Send a message.
Use the [send](Session.messages.html#send) method to either send a [message](Session.messages.html#toc11) to a specific client session or
send a [message](Session.messages.html#toc14) to a path.
* Receive messages sent to this client session.
Use the [listen](Session.messages.html#listen) method to receive [messages](Session.messages.html#toc11) sent to this client session through
a [MessageStream](Session.messages.MessageStream.html).
* Receive messages sent to a path.
Use the [addHandler](Session.messages.html#addHandler) method to register a [MessageHandler](Session.messages.MessageHandler.html) that receives
[messages](Session.messages.html#toc14) sent to a path.
#### Authenticating clients
The server uses information stored in the system authentication store to authenticate connecting clients.
* Get the system authentication store information with the
[getSystemAuthenticationConfiguration](Session.security.html#getSystemAuthenticationConfiguration) method.
* Update the system authentication store.
Use the [authenticationScriptBuilder](Session.security.html#authenticationScriptBuilder) method to get a
[SystemAuthenticationScriptBuilder](SystemAuthenticationScriptBuilder.html). The builder can be used to create a script. Pass the script
to the [updateAuthenticationStore](Session.security.html#updateAuthenticationStore) method to update the system authentication store.
#### Updating security roles
* Get the security store information [getSecurityConfiguration](Session.security.html#getSecurityConfiguration) method.
* Update the security store.
Use the [securityScriptBuilder](Session.security.html#securityScriptBuilder) method to get a [SecurityScriptBuilder](SecurityScriptBuilder.html). The
builder can be used to create a script. Pass the script to the [updateAuthenticationStore](Session.security.html#updateAuthenticationStore) method to update
the system authentication store.

@@ -36,5 +36,5 @@ var SessionImpl = require('session/session-impl');

*/
version: '5.9.2',
version: '5.9.3',
build: '2_dev#internal',
build: '3_dev#internal',

@@ -41,0 +41,0 @@ /**

@@ -652,56 +652,2 @@ var _interface = require('util/interface').interface;

/**
* The reason that a topic could not be added.
*
* @readonly
* @enum
*/
module.exports.TopicAddFailReason = {
/** The topic already exists with the same details. */
EXISTS: {
id: 1,
reason: "The topic already exists with the same details"
},
/** The topic already exists, with different details. */
EXISTS_MISMATCH: {
id: 2,
reason: "The topic already exists, with different details"
},
/** The topic path is invalid. */
INVALID_PATH: {
id: 3,
reason: "The topic path is invalid"
},
/** The topic details are invalid. */
INVALID_DETAILS: {
id: 4,
reason: "The topic details are invalid"
},
/** A user supplied class could not be found or instantiated. */
USER_CODE_ERROR: {
id: 5,
reason: "A user supplied class could not be found or instantiated"
},
/** A referenced topic could not be found. */
TOPIC_NOT_FOUND: {
id: 6,
reason: "A referenced topic could not be found"
},
/** Invalid permissions to add a topic at the specified path. */
PERMISSIONS_FAILURE: {
id: 7,
reason: "Invalid permissions to add a topic at the specified path"
},
/** The topic could not be initialised, supplied value may be of the wrong format. */
INITIALISE_ERROR: {
id: 8,
reason: "The topic could not be initialised, supplied value may be of the wrong format"
},
/** An unexpected error occured while creating the topic. */
UNEXPECTED_ERROR: {
id: 9,
reason: "An unexpected error occured while creating the topic"
}
};
/**
* The reason that a topic could not be updated.

@@ -708,0 +654,0 @@ *

@@ -12,3 +12,3 @@ var _implements = require('util/interface')._implements;

var AddResult = require('services/add-topic/add-topic-failure-reason');
var TopicAddFailReason = require('../../topics/topics').TopicAddFailReason;

@@ -122,3 +122,3 @@ var WillResult = require('services/wills/will-registration-result');

// This emits 'complete' because add topic is idempotent
if (result.reason === AddResult.EXISTS) {
if (result.reason === TopicAddFailReason.EXISTS) {
logger.debug("Topic add complete (already exists)", path);

@@ -125,0 +125,0 @@

var Services = require('services/services');
var DataTypes = require('data/datatypes');
var UpdateFailReason = require('../../../topics/topics').UpdateFailReason;
module.exports = function UniversalUpdater(internal) {

@@ -13,2 +15,8 @@ var SET_SERVICE = internal.getServiceLocator().obtain(Services.UPDATE_TOPIC_SET);

var datatype = DataTypes.get(content);
if (!datatype) {
callback(UpdateFailReason.INCOMPATIBLE_UPDATE);
return;
}
var value = datatype.from(content);

@@ -15,0 +23,0 @@

@@ -10,2 +10,3 @@ var parseSelector = require('topics/topic-selector-parser');

var UpdateFailReason = require('../../topics/topics').UpdateFailReason;
var CloseReason = require('v4-stack/close-reason');

@@ -73,2 +74,8 @@

var datatype = DataTypes.get(content);
if (!datatype) {
emitter.error(UpdateFailReason.INCOMPATIBLE_UPDATE);
return;
}
var value = datatype.from(content);

@@ -75,0 +82,0 @@ var prev = valueCache.get(path);

@@ -8,3 +8,3 @@ var Codec = require('io/codec');

var BEES = require('serialisers/byte-encoded-enum-serialiser');
var AddTopicFailureReason = require('services/add-topic/add-topic-failure-reason');
var TopicAddFailReason = require('../../../topics/topics').TopicAddFailReason;
var TopicDetailsSerialiser = require('topics/details/topic-details-serialiser');

@@ -25,3 +25,3 @@

if (status === Status.FAILURE) {
reason = BEES.read(input, AddTopicFailureReason);
reason = BEES.read(input, TopicAddFailReason);
}

@@ -28,0 +28,0 @@

@@ -236,8 +236,10 @@ var RecoveryBuffer = require('message-queue/recovery-buffer');

* @param {CloseReason} reason - The close reason
* @param {Boolean} force - Whether to directly force the close
*/
this.close = function(reason) {
closeReason = reason;
if (fsm.change('disconnecting')) {
if (fsm.state === 'disconnected') {
// transport is already closed and the event isn't emitted again so the callback is called directly
onClose();
} else if (fsm.change('disconnecting')) {
// We allow the server a grace period to close the transport connection

@@ -244,0 +246,0 @@ dispatch(Message.create(Message.types.CLOSE_REQUEST));

@@ -175,3 +175,4 @@ var DEFAULT_HOST = 'localhost';

* @property {String} [principal] - The principal name this session should connect with. Used for authentication.
* @property {String} [credentials] - A password string to authenticate with.
* @property {String|Buffer} [credentials] - A password string to authenticate with, or a buffer containing custom
* credentials in binary format.
* @property {Boolean|Number|Function|Object} [reconnect=true] - Reconnection options.

@@ -178,0 +179,0 @@ * @property {String|Array} [transports=["WEBSOCKET"]] - The transports to be used for connection establishment.

@@ -237,2 +237,130 @@ /**

AUTHORIZATION : reason(3, "Not authorized to subscribe to this topic")
};
function UpdateFailReason(id, reason) {
this.id = id;
this.reason = reason;
}
/**
* The reason that a topic could not be updated.
*
* @example
* session.topics.update("foo", "bar").then(function() { ... }, function(err) {
* switch (err) {
* case diffusion.topics.UpdateFailReason.MISSING_TOPIC:
* ...
* case diffusion.topics.UpdateFailReason.EXCLUSIVE_UPDATER_CONFLICT:
* ...
* }
* });
*
* @readonly
* @enum
* @memberof diffusion.topics
* @alias UpdateFailReason
*/
module.exports.UpdateFailReason = {
/**
* The update was of a type that is not compatible with the topic it was submitted for, or
* the topic does not support updating.
*/
INCOMPATIBLE_UPDATE: new UpdateFailReason(1, "Update type is incompatible with topic type"),
/**
* The update failed, possibly because the content sent with the update was invalid/incompatible with topic type or
* data format.
*/
UPDATE_FAILED: new UpdateFailReason(2, "Update failed - possible content incompatibility"),
/**
* The updater used is not active.
*/
INVALID_UPDATER: new UpdateFailReason(3, "Updater is invalid for updating"),
/**
* The topic being updated does not exist.
*/
MISSING_TOPIC: new UpdateFailReason(4, "Topic does not exist"),
/**
* Invalid key or index used for addressing topic content.
*/
INVALID_ADDRESS: new UpdateFailReason(5, "Key or index value is invalid for topic data"),
/**
* Violation of content duplication restrictions.
*/
DUPLICATES: new UpdateFailReason(6, "Duplicates violation"),
/**
* Attempt to perform a non-exclusive update to a topic branch that already has an update source registered to it.
*/
EXCLUSIVE_UPDATER_CONFLICT:
new UpdateFailReason(7, "An exclusive update source is already registered for the topic branch"),
/**
* An attempt has been made to apply a delta to a topic that has not yet has a value specified for it.
*/
DELTA_WITHOUT_VALUE:
new UpdateFailReason(8, "An attempt has been made to apply a delta to a topic that does not yet have a value")
};
/**
* The reason that a topic could not be added.
*
* @example
* session.topics.add("foo").then(function() { ... }, function(err) {
* switch (err) {
* case diffusion.topics.TopicAddFailReason.EXISTS:
* ...
* case diffusion.topics.TopicAddFailReason.INVALID_PATH:
* ...
* }
* });
*
* @readonly
* @enum
* @memberOf diffusion.topics
* @alias TopicAddFailReason
*/
module.exports.TopicAddFailReason = {
/** The topic already exists with the same details. */
EXISTS: {
id: 1,
reason: "The topic already exists with the same details"
},
/** The topic already exists, with different details. */
EXISTS_MISMATCH: {
id: 2,
reason: "The topic already exists, with different details"
},
/** The topic path is invalid. */
INVALID_PATH: {
id: 3,
reason: "The topic path is invalid"
},
/** The topic details are invalid. */
INVALID_DETAILS: {
id: 4,
reason: "The topic details are invalid"
},
/** A user supplied class could not be found or instantiated. */
USER_CODE_ERROR: {
id: 5,
reason: "A user supplied class could not be found or instantiated"
},
/** A referenced topic could not be found. */
TOPIC_NOT_FOUND: {
id: 6,
reason: "A referenced topic could not be found"
},
/** Invalid permissions to add a topic at the specified path. */
PERMISSIONS_FAILURE: {
id: 7,
reason: "Invalid permissions to add a topic at the specified path"
},
/** The topic could not be initialised, supplied value may be of the wrong format. */
INITIALISE_ERROR: {
id: 8,
reason: "The topic could not be initialised, supplied value may be of the wrong format"
},
/** An unexpected error occured while creating the topic. */
UNEXPECTED_ERROR: {
id: 9,
reason: "An unexpected error occured while creating the topic"
}
};
import {Session} from './session.d';
import {ErrorReason} from './error.d';
import {Options} from './options.d';
import {SessionOptions} from './options.d';
import {Result} from './events/result.d';

@@ -12,5 +12,7 @@ import {DataTypes} from './data/datatypes.d'

type LogVerbosityLevel = "silent" | "error" | "warn" | "info" | "debug";
export var version: string;
export function connect(options: Options): Result<Session, ErrorReason>;
export function log(level: string): void;
export function connect(options: SessionOptions): Result<Session, ErrorReason>;
export function log(level: LogVerbosityLevel): void;
export var datatypes: DataTypes;

@@ -17,0 +19,0 @@ export var selectors: TopicSelectors;

import {Session} from './session.d';
import {ErrorReason} from './error.d';
import {Options} from './options.d';
import {SessionOptions} from './options.d';
import {Result} from './events/result.d';

@@ -12,6 +12,8 @@ import {DataTypes} from './data/datatypes.d'

type LogVerbosityLevel = "silent" | "error" | "warn" | "info" | "debug";
interface DiffusionStatic {
version: string;
connect(options: Options): Result<Session, ErrorReason>;
log(level: string): void;
connect(options: SessionOptions): Result<Session, ErrorReason>;
log(level: LogVerbosityLevel): void;
datatypes: DataTypes;

@@ -18,0 +20,0 @@ selectors: TopicSelectors;

@@ -1,2 +0,4 @@

export interface Options {
export type TransportType = "ws" | "WS" | "WEBSOCKET" | "xhr" | "XHR" | "HTTP_POLLING";
export interface SessionOptions {
host?: string;

@@ -9,3 +11,3 @@ port?: number;

reconnect?: boolean | number | Function | ReconnectOptions;
transports?: string | string[];
transports?: TransportType | TransportType[];
}

@@ -12,0 +14,0 @@

@@ -5,3 +5,3 @@ import {Topics} from './features/topics.d';

import {Messages} from './features/messages.d';
import {Options} from './options.d';
import {SessionOptions} from './options.d';
import {Stream} from './events/stream.d';

@@ -19,3 +19,3 @@ import {Security} from './features/security.d';

clients: ClientControl;
options: Options;
options: SessionOptions;
sessionID: string;

@@ -22,0 +22,0 @@ toString: () => string;

@@ -5,7 +5,20 @@ import * as diffusion from './diffusion.d';

// It uses every Diffusion API call and should compile
// If the API is changed and the TypeScript definition is not updated the compilation should fail
const TOPIC_PATH = 'f/o/o/b/a/r';
diffusion.log('silent');
diffusion.log('error');
diffusion.log('warn');
diffusion.log('info');
diffusion.log('debug');
// Test transports
diffusion.connect({
transports: "WS"
});
diffusion.connect({
transports: ["WS", "XHR"]
});
diffusion.connect({
host: 'localhost',

@@ -15,3 +28,3 @@ port: 8080,

credentials: 'password'
}).then((session) => {
}).then(function(session) {

@@ -91,4 +104,4 @@ // Session methods

session.clients.getSessionProperties('XXX-YYY', ['$x', '$y', '$z'])
.then((session, properties) => {}, () => {})
.then((session, properties) => {});
.then((properties) => {}, () => {})
.then((properties) => {});
session.clients.setSessionPropertiesListener(['$q', '$w', '$e'], {

@@ -150,2 +163,20 @@ onActive: (deregister) => {},

});
}, (error) => { console.log('Failed to connect because of error: ' + error.message); });
// Chain some promises a bit
session.topics.add('foo/json1', value).then(function(result) {
if (result.added) {
return session.topics.remove(result.topic);
}
}, function(reason) {
return reason;
}).then(function() {
return session.security.getSecurityConfiguration();
}, function() {
return session.topics.update('foo/bar', 'baz');
}).then(function() {
console.log("Chained");
}, function() {
console.log("Chained");
});
}, function(error) { console.log('Failed to connect because of error: ' + error.message); });
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc