amb-client-js
Advanced tools
Comparing version 18.0.0 to 19.0.0
@@ -10,5 +10,10 @@ "use strict"; | ||
var _amb2 = require("./amb.Helper"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Channel = function Channel(cometd, channelName, initialized) { | ||
var subscribeOptionsCallback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function () { | ||
return {}; | ||
}; | ||
var subscription = null; | ||
@@ -126,4 +131,10 @@ var subscriptionCallbackResponse = null; | ||
function subscribeToCometD() { | ||
subscription = cometd.subscribe(channelName, this._handleResponse.bind(this), this.subscriptionCallback); | ||
LOGGER.debug('Successfully subscribed to channel: ' + channelName); | ||
var subscribeOptions = subscribeOptionsCallback(); | ||
if ((0, _amb2.isNil)(subscribeOptions) || (0, _amb2.isEmptyObject)(subscribeOptions)) subscription = cometd.subscribe(channelName, this._handleResponse.bind(this), this.subscriptionCallback);else { | ||
var subscribeOptionsWrapper = { | ||
"subscribeOptions": subscribeOptions | ||
}; | ||
subscription = cometd.subscribe(channelName, this._handleResponse.bind(this), subscribeOptionsWrapper, this.subscriptionCallback); | ||
} | ||
LOGGER.debug('Successfully subscribed to channel: ' + channelName + ', Subscribe options: ' + subscribeOptions); | ||
}, | ||
@@ -161,2 +172,5 @@ | ||
}, | ||
getSubscribeOptionsCallback: function getSubscribeOptionsCallback() { | ||
return subscribeOptionsCallback; | ||
}, | ||
getName: function getName() { | ||
@@ -163,0 +177,0 @@ return channelName; |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.isObject = exports.isNil = exports.isNull = exports.isUndefined = void 0; | ||
exports.isEmptyObject = exports.isObject = exports.isNil = exports.isNull = exports.isUndefined = void 0; | ||
@@ -33,2 +33,8 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
exports.isObject = isObject; | ||
exports.isObject = isObject; | ||
var isEmptyObject = function isEmptyObject(obj) { | ||
return isObject(obj) && Object.keys(obj).length === 0; | ||
}; | ||
exports.isEmptyObject = isEmptyObject; |
@@ -131,5 +131,6 @@ "use strict"; | ||
subscriptionCallback = _ref.subscriptionCallback, | ||
serializedGraphQLSubscription = _ref.serializedGraphQLSubscription; | ||
serializedGraphQLSubscription = _ref.serializedGraphQLSubscription, | ||
subscribeOptionsCallback = _ref.subscribeOptionsCallback; | ||
var channel = serverConnection.getChannel(channelName); | ||
var channel = serverConnection.getChannel(channelName, subscribeOptionsCallback); | ||
@@ -136,0 +137,0 @@ if (graphQLSubscriptionExtension.isGraphQLChannel(channelName)) { |
@@ -152,5 +152,5 @@ "use strict"; | ||
/*String*/ | ||
channelName) { | ||
channelName, subscriptionOptionsCallback) { | ||
if (channelName in channels) return channels[channelName]; | ||
var channel = new _amb5.default(cometd, channelName, initialized); | ||
var channel = new _amb5.default(cometd, channelName, initialized, subscriptionOptionsCallback); | ||
channels[channelName] = channel; | ||
@@ -472,4 +472,4 @@ return channel; | ||
/*String*/ | ||
channelName) { | ||
return _getChannel(channelName); | ||
channelName, subscriptionOptionsCallback) { | ||
return _getChannel(channelName, subscriptionOptionsCallback); | ||
}; | ||
@@ -476,0 +476,0 @@ |
{ | ||
"name": "amb-client-js", | ||
"version": "18.0.0", | ||
"version": "19.0.0", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "Asynchronous Message Bus JavaScript Client", |
import Channel from '../amb.Channel'; | ||
import { isNull } from '../amb.Helper'; | ||
@@ -19,2 +20,34 @@ describe('Channel', () => { | ||
function testSubscribe(subscribeOptionsCallback, sendToCometD, testResubscribe) { | ||
const mockChannelListener = { | ||
getCallback: jest.fn().mockImplementation(() => { | ||
return "Llama"; | ||
}), | ||
getSubscriptionCallback: jest.fn(), | ||
resubscribe: jest.fn() | ||
}; | ||
let testChannel; | ||
if (isNull(subscribeOptionsCallback)) | ||
testChannel = new Channel(mockCometD, 'testChannelName', true); | ||
else | ||
testChannel = new Channel(mockCometD, 'testChannelName', true, subscribeOptionsCallback); | ||
testChannel.subscribe(mockChannelListener); | ||
expect(mockCometD.subscribe).toHaveBeenCalledTimes(1); | ||
if (testResubscribe) { | ||
testChannel.resubscribe(); | ||
expect(mockChannelListener.resubscribe).toHaveBeenCalledTimes(1); | ||
} | ||
if (sendToCometD) { | ||
const subOptionsWrapper = { "subscribeOptions": subscribeOptionsCallback() }; | ||
expect(mockCometD.subscribe).toHaveBeenCalledWith('testChannelName', jasmine.any(Function), | ||
subOptionsWrapper, jasmine.any(Function)); | ||
} else | ||
expect(mockCometD.subscribe).toHaveBeenCalledWith('testChannelName', jasmine.any(Function), | ||
jasmine.any(Function)); | ||
} | ||
it('returns the channel name', () => { | ||
@@ -26,2 +59,21 @@ const testChannel = new Channel(mockCometD, 'testChannelName', false); | ||
describe('subscribe', () => { | ||
it('calls cometd subscribe with subscribe options when subscribe options is not an empty object', () => { | ||
let subscribeOptionsCallback = function() { return {"blah": "blah"}; }; | ||
testSubscribe(subscribeOptionsCallback, true, false); | ||
}); | ||
it('calls cometd subscribe without subscribe options when subscribe options is an empty object', () => { | ||
let subscribeOptionsCallback = (() => { return {}; }); | ||
testSubscribe(subscribeOptionsCallback, false, false); | ||
}); | ||
it('calls cometd subscribe without subscribe options when subscribe options is missing', () => { | ||
testSubscribe(null, false, false); | ||
}); | ||
it('calls cometd subscribe without subscribe options when subscribe options callback is an empty function', () => { | ||
const subscribeOptionsCallback = (() => {}); | ||
testSubscribe(subscribeOptionsCallback, false, false); | ||
}); | ||
it('does not call cometd subscribe to channel if disconnected but does create listener', () => { | ||
@@ -216,2 +268,6 @@ | ||
it('resubscribes listener with subscribe options', () => { | ||
let subscribeOptionsCallback = function() { return {"blah": "blah"}; }; | ||
testSubscribe(subscribeOptionsCallback, true, true); | ||
}); | ||
}); | ||
@@ -218,0 +274,0 @@ |
@@ -68,4 +68,6 @@ import MessageClient from '../amb.MessageClient'; | ||
const resubscribeToCometD = jest.fn(); | ||
Channel.mockImplementation((cometd, channelName, active) => { | ||
const getSubscribeOptionsCallback = jest.fn(); | ||
Channel.mockImplementation((cometd, channelName, active, subscribeOptionsCallback) => { | ||
return { | ||
getSubscribeOptionsCallback: getSubscribeOptionsCallback.mockImplementation(() => { return subscribeOptionsCallback; }), | ||
subscribeOnInitCompletion: subscribeOnInitCompletion, | ||
@@ -89,4 +91,4 @@ getName: getName.mockImplementation(() => { | ||
connect: connect, | ||
getChannel: getChannel.mockImplementation((channelName) => { | ||
return new Channel(null, channelName, true); | ||
getChannel: getChannel.mockImplementation((channelName, subscribeOptionsCallback) => { | ||
return new Channel(null, channelName, true, subscribeOptionsCallback); | ||
}), | ||
@@ -184,3 +186,3 @@ reload: reload, | ||
it('connect does not try to connect if already connectedt', () => { | ||
it('connect does not try to connect if already connected', () => { | ||
testMessageClient.connect(); | ||
@@ -243,2 +245,17 @@ testMessageClient.connect(); | ||
describe('channels', () => { | ||
it('getChannel gets channel listener from server channel with subscribe options callback', () => { | ||
getName.mockImplementation(() => { | ||
return 'channel name'; | ||
}); | ||
const subConfig = { | ||
subscribeOptionsCallback: function() { return {"blah":"blah"}; }, | ||
subscriptionCallback : () => {} | ||
}; | ||
const channelListener = testMessageClient.getChannel('channel name', subConfig); | ||
expect(getChannel).toHaveBeenCalledWith('channel name', subConfig.subscribeOptionsCallback); | ||
expect(channelListener.getName()).toBe('channel name'); | ||
expect(channelListener.getSubscriptionCallback()).toBe(subConfig.subscriptionCallback); | ||
expect(addGraphQLChannel).toHaveBeenCalledTimes(0); | ||
}); | ||
it('getChannel gets channel listener from server channel', () => { | ||
@@ -252,2 +269,3 @@ getName.mockImplementation(() => { | ||
const channelListener = testMessageClient.getChannel('channel name', subConfig); | ||
expect(getChannel).toHaveBeenCalledWith('channel name', undefined); | ||
expect(channelListener.getName()).toBe('channel name'); | ||
@@ -266,2 +284,3 @@ expect(channelListener.getSubscriptionCallback()).toBe(subConfig.subscriptionCallback); | ||
const channelListener = testMessageClient.getChannel('channel name'); | ||
expect(getChannel).toHaveBeenCalledWith('channel name', undefined); | ||
expect(channelListener.getName()).toBe('channel name'); | ||
@@ -268,0 +287,0 @@ expect(Object.keys(testMessageClient.getChannels()).length).toBe(1); |
import Logger from './amb.Logger'; | ||
import {isEmptyObject, isNil} from "./amb.Helper"; | ||
const Channel = function Channel(cometd, channelName, initialized) { | ||
const Channel = function Channel(cometd, channelName, initialized, subscribeOptionsCallback = (() => { return {}; })) { | ||
@@ -107,4 +108,11 @@ let subscription = null; | ||
subscribeToCometD: /*void*/ function() { | ||
subscription = cometd.subscribe(channelName, this._handleResponse.bind(this), this.subscriptionCallback); | ||
LOGGER.debug('Successfully subscribed to channel: ' + channelName); | ||
let subscribeOptions = subscribeOptionsCallback(); | ||
if (isNil(subscribeOptions) || isEmptyObject(subscribeOptions)) | ||
subscription = cometd.subscribe(channelName, this._handleResponse.bind(this), this.subscriptionCallback); | ||
else { | ||
const subscribeOptionsWrapper = {"subscribeOptions": subscribeOptions}; | ||
subscription = cometd.subscribe(channelName, this._handleResponse.bind(this), subscribeOptionsWrapper, | ||
this.subscriptionCallback); | ||
} | ||
LOGGER.debug('Successfully subscribed to channel: ' + channelName + ', Subscribe options: ' + subscribeOptions); | ||
}, | ||
@@ -143,2 +151,6 @@ | ||
getSubscribeOptionsCallback: function() { | ||
return subscribeOptionsCallback; | ||
}, | ||
getName: function() { | ||
@@ -145,0 +157,0 @@ return channelName; |
export const isUndefined = value => value === undefined; | ||
export const isNull = value => value === null; | ||
export const isNil = value => isNull(value) || isUndefined(value); | ||
export const isObject = x => x != null && typeof x === 'object'; | ||
export const isObject = x => x != null && typeof x === 'object'; | ||
export const isEmptyObject = obj => isObject(obj) && Object.keys(obj).length === 0; |
@@ -108,6 +108,7 @@ import cometdLib from 'cometd'; | ||
subscriptionCallback, | ||
serializedGraphQLSubscription | ||
serializedGraphQLSubscription, | ||
subscribeOptionsCallback | ||
} = subscriptionConfig || {}; | ||
const channel = serverConnection.getChannel(channelName); | ||
const channel = serverConnection.getChannel(channelName, subscribeOptionsCallback); | ||
@@ -114,0 +115,0 @@ if (graphQLSubscriptionExtension.isGraphQLChannel(channelName)) { |
@@ -121,7 +121,7 @@ import EventManager from './amb.EventManager'; | ||
function _getChannel(/*String*/ channelName) { | ||
function _getChannel(/*String*/ channelName, subscriptionOptionsCallback) { | ||
if (channelName in channels) | ||
return channels[channelName]; | ||
const channel = new Channel(cometd, channelName, initialized); | ||
const channel = new Channel(cometd, channelName, initialized, subscriptionOptionsCallback); | ||
channels[channelName] = channel; | ||
@@ -417,4 +417,4 @@ return channel; | ||
ambServerConnection.getChannel = function(/*String*/ channelName) { | ||
return _getChannel(channelName); | ||
ambServerConnection.getChannel = function(/*String*/ channelName, subscriptionOptionsCallback) { | ||
return _getChannel(channelName, subscriptionOptionsCallback); | ||
}; | ||
@@ -421,0 +421,0 @@ |
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
164167
4498