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

kuzzle-sdk

Package Overview
Dependencies
Maintainers
1
Versions
178
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kuzzle-sdk - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

package.json
{
"name": "kuzzle-sdk",
"version": "1.0.0",
"version": "1.0.1",
"description": "Official Javascript SDK for Kuzzle",

@@ -5,0 +5,0 @@ "author": "The Kuzzle Team <support@kuzzle.io>",

@@ -85,3 +85,3 @@ var

value: {
pending: 0
pending: {}
},

@@ -247,2 +247,11 @@ writable: true

Object.keys(self.subscriptions).forEach(function (roomId) {
Object.keys(self.subscriptions[roomId]).forEach(function (subscriptionId) {
var subscription = self.subscriptions[roomId][subscriptionId];
subscription.renew(subscription.callback);
});
});
dequeue.call(self);
if (cb) {

@@ -253,3 +262,3 @@ cb(null, self);

self.socket.once('connect_error', function (error) {
self.socket.on('connect_error', function (error) {
self.state = 'error';

@@ -670,11 +679,11 @@

emitRequest.call(this, object, cb);
} else if (self.queuing) {
} else if (self.queuing|| self.state === 'initializing') {
cleanQueue.call(this, object, cb);
if (self.queueFilter) {
if (self.queueFilter(query)) {
self.offlineQueue.push({ts: Date.now(), query: query, cb: cb});
if (self.queueFilter(object)) {
self.offlineQueue.push({ts: Date.now(), query: object, cb: cb});
}
} else {
self.offlineQueue.push({ts: Date.now(), query: query, cb: cb});
self.offlineQueue.push({ts: Date.now(), query: object, cb: cb});
}

@@ -681,0 +690,0 @@ }

@@ -164,3 +164,3 @@ var uuid = require('node-uuid');

this.subscribing = true;
this.kuzzle.subscriptions.pending++;
self.kuzzle.subscriptions.pending[self.id] = self;

@@ -174,3 +174,4 @@ if (filters) {

subscribeQuery = this.kuzzle.addHeaders({body: filters}, this.headers);
subscribeQuery = this.kuzzle.addHeaders({body: self.filters}, this.headers);
self.kuzzle.query(this.collection, 'subscribe', 'on', subscribeQuery, {metadata: this.metadata}, function (error, response) {

@@ -182,3 +183,3 @@ if (error) {

*/
if (error.details.roomId) {
if (error.details && error.details.roomId) {
self.roomId = error.details.roomId;

@@ -202,3 +203,4 @@ } else {

self.subscribing = false;
self.kuzzle.subscriptions.pending--;
delete self.kuzzle.subscriptions.pending[self.id];
self.dequeue();

@@ -236,7 +238,7 @@ });

if (self.kuzzle.subscriptions.pending === 0) {
if (Object.keys(self.kuzzle.subscriptions.pending).length === 0) {
self.kuzzle.query(this.collection, 'subscribe', 'off', {body: {roomId: room}});
} else {
interval = setInterval(function () {
if (self.kuzzle.subscriptions.pending === 0) {
if (Object.keys(self.kuzzle.subscriptions.pending).length === 0) {
if (!self.kuzzle.subscriptions[room]) {

@@ -243,0 +245,0 @@ self.kuzzle.query(self.collection, 'subscribe', 'off', {body: {roomId: room}});

@@ -6,3 +6,5 @@ var

Kuzzle = rewire('../../src/kuzzle'),
KuzzleDataCollection = rewire('../../src/kuzzleDataCollection');
KuzzleDataCollection = rewire('../../src/kuzzleDataCollection'),
KuzzleDocument = require('../../src/kuzzleDocument'),
KuzzleDataMapping = require('../../src/kuzzleDataMapping');

@@ -12,14 +14,12 @@ describe('KuzzleDataCollection methods', function () {

expectedQuery,
passedOptions,
error,
result,
collection,
queryStub = function (c, controller, action, query, options, cb) {
queryStub = function (collection, controller, action, query, options, cb) {
emitted = true;
should(c).be.exactly(collection);
should(collection).be.exactly(expectedQuery.collection);
should(controller).be.exactly(expectedQuery.controller);
should(action).be.exactly(expectedQuery.action);
if (passedOptions) {
should(options).match(passedOptions);
if (expectedQuery.options) {
should(options).match(expectedQuery.options);
}

@@ -33,3 +33,9 @@

cb(error, result);
if (cb) {
if (error) {
return cb(error);
}
cb(error, result);
}
},

@@ -43,10 +49,709 @@ emitted,

kuzzle.query = queryStub;
emitted = false;
result = { hits: { total: 123, hits: [ {_id: 'foobar', _source: { foo: 'bar'}} ]}};
error = null;
expectedQuery = {
collection: 'foo',
action: 'search',
controller: 'read'
controller: 'read',
body: {}
};
});
//it('')
it('should send the right search query to kuzzle', function (done) {
var
collection = kuzzle.dataCollectionFactory(expectedQuery.collection),
options = {queuable: false},
filters = { and: [ {term: {foo: 'bar'}}, { ids: ['baz', 'qux'] } ] };
this.timeout(50);
expectedQuery.options = options;
expectedQuery.body = filters;
should(collection.advancedSearch(filters, options, function (err, res) {
should(err).be.null();
should(res).be.an.Object();
should(res.total).be.a.Number().and.be.exactly(result.hits.total);
should(res.documents).be.an.Array();
should(res.documents.length).be.exactly(result.hits.hits.length);
res.documents.forEach(function (item) {
should(item).be.instanceof(KuzzleDocument);
});
done();
})).be.exactly(collection);
should(emitted).be.true();
});
it('should raise an error if no callback is provided', function () {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
should(function () { collection.advancedSearch(); }).throw(Error);
should(emitted).be.false();
should(function () { collection.advancedSearch({}); }).throw(Error);
should(emitted).be.false();
should(function () { collection.advancedSearch({}, {}); }).throw(Error);
should(emitted).be.false();
});
it('should handle the callback argument correctly', function () {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
collection.advancedSearch({}, function () {});
should(emitted).be.true();
emitted = false;
collection.advancedSearch({}, {}, function () {});
should(emitted).be.true();
});
it('should call the callback with an error if one occurs', function (done) {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
error = 'foobar';
this.timeout(50);
collection.advancedSearch({}, function (err, res) {
should(err).be.exactly('foobar');
should(res).be.undefined();
done();
});
});
});
describe('#count', function () {
beforeEach(function () {
kuzzle = new Kuzzle('foo');
kuzzle.query = queryStub;
emitted = false;
result = { count: 42 };
error = null;
expectedQuery = {
collection: 'foo',
action: 'count',
controller: 'read',
body: {}
};
});
it('should send the right count query to Kuzzle', function (done) {
var
collection = kuzzle.dataCollectionFactory(expectedQuery.collection),
options = { queuable: false },
filters = { and: [ {term: {foo: 'bar'}}, { ids: ['baz', 'qux'] } ] };
expectedQuery.options = options;
expectedQuery.body = filters;
should(collection.count(filters, options, function (err, res) {
should(err).be.null();
should(res).be.a.Number().and.be.exactly(result.count);
done();
})).be.exactly(collection);
should(emitted).be.true();
});
it('should raise an error if no callback is provided', function () {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
should(function () { collection.count(); }).throw(Error);
should(emitted).be.false();
should(function () { collection.count({}); }).throw(Error);
should(emitted).be.false();
should(function () { collection.count({}, {}); }).throw(Error);
should(emitted).be.false();
});
it('should handle the callback argument correctly', function () {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
collection.count({}, function () {});
should(emitted).be.true();
emitted = false;
collection.count({}, {}, function () {});
should(emitted).be.true();
});
it('should call the callback with an error if one occurs', function (done) {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
error = 'foobar';
this.timeout(50);
collection.count({}, function (err, res) {
should(err).be.exactly('foobar');
should(res).be.undefined();
done();
});
});
});
describe('#create', function () {
beforeEach(function () {
kuzzle = new Kuzzle('foo');
kuzzle.query = queryStub;
emitted = false;
result = { acknowledged: true };
error = null;
expectedQuery = {
collection: 'foo',
action: 'createCollection',
controller: 'write',
body: {}
};
});
it('should send the right createCollection query to Kuzzle', function (done) {
var
collection = kuzzle.dataCollectionFactory(expectedQuery.collection),
options = { queuable: false };
expectedQuery.options = options;
should(collection.create(options, function (err, res) {
should(err).be.null();
should(res).be.an.Object().and.be.exactly(result);
done();
})).be.exactly(collection);
should(emitted).be.true();
});
it('should handle the callback argument correctly', function () {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
collection.create(function () {});
should(emitted).be.true();
emitted = false;
collection.create({}, function () {});
should(emitted).be.true();
});
it('should call the callback with an error if one occurs', function (done) {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
error = 'foobar';
this.timeout(50);
collection.create(function (err, res) {
should(err).be.exactly('foobar');
should(res).be.undefined();
done();
});
});
});
describe('#createDocument', function () {
beforeEach(function () {
kuzzle = new Kuzzle('foo');
kuzzle.query = queryStub;
emitted = false;
result = { _id: 'foobar', _source: { foo: 'bar' } };
error = null;
expectedQuery = {
collection: 'foo',
action: 'create',
controller: 'write',
body: {}
};
});
it('should send the right createDocument query to Kuzzle', function (done) {
var
collection = kuzzle.dataCollectionFactory(expectedQuery.collection),
options = { queuable: false };
expectedQuery.options = options;
should(collection.createDocument(result._source, options, function (err, res) {
should(err).be.null();
should(res).be.instanceof(KuzzleDocument);
done();
})).be.exactly(collection);
should(emitted).be.true();
});
it('should handle the callback argument correctly', function () {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
collection.createDocument({}, function () {});
should(emitted).be.true();
emitted = false;
collection.createDocument({}, {}, function () {});
should(emitted).be.true();
});
it('should call the callback with an error if one occurs', function (done) {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
error = 'foobar';
this.timeout(50);
collection.createDocument({}, function (err, res) {
should(err).be.exactly('foobar');
should(res).be.undefined();
done();
});
});
it('should be able to handle a KuzzleDocument argument', function (done) {
var
collection = kuzzle.dataCollectionFactory(expectedQuery.collection),
document = new KuzzleDocument(collection, result._source);
should(collection.createDocument(document, function (err, res) {
should(err).be.null();
should(res).be.instanceof(KuzzleDocument);
done();
})).be.exactly(collection);
should(emitted).be.true();
});
it('should be able to handle the updateIfExist option', function () {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
expectedQuery.action = 'createOrUpdate';
collection.createDocument(result._source, {updateIfExist: true});
should(emitted).be.true();
});
});
describe('#delete', function () {
beforeEach(function () {
kuzzle = new Kuzzle('foo');
kuzzle.query = queryStub;
emitted = false;
result = { acknowledged: true };
error = null;
expectedQuery = {
collection: 'foo',
action: 'deleteCollection',
controller: 'admin',
body: {}
};
});
it('should send the right deleteCollection query to Kuzzle', function (done) {
var
collection = kuzzle.dataCollectionFactory(expectedQuery.collection),
options = { queuable: false };
expectedQuery.options = options;
should(collection.delete(options, function (err, res) {
should(err).be.null();
should(res).be.an.Object().and.be.exactly(result);
done();
})).be.exactly(collection);
should(emitted).be.true();
});
it('should handle the callback argument correctly', function () {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
collection.delete(function () {});
should(emitted).be.true();
emitted = false;
collection.delete({}, function () {});
should(emitted).be.true();
});
it('should call the callback with an error if one occurs', function (done) {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
error = 'foobar';
this.timeout(50);
collection.delete(function (err, res) {
should(err).be.exactly('foobar');
should(res).be.undefined();
done();
});
});
});
describe('#deleteDocument', function () {
beforeEach(function () {
kuzzle = new Kuzzle('foo');
kuzzle.query = queryStub;
emitted = false;
result = { _id: 'foobar' };
error = null;
expectedQuery = {
collection: 'foo',
action: 'delete',
controller: 'write',
body: {}
};
});
it('should send the right delete query to Kuzzle', function (done) {
var
collection = kuzzle.dataCollectionFactory(expectedQuery.collection),
options = { queuable: false };
expectedQuery.options = options;
should(collection.deleteDocument(result._id, options, function (err, res) {
should(err).be.null();
should(res).be.an.Array().and.match([result._id]);
done();
})).be.exactly(collection);
should(emitted).be.true();
});
it('should handle arguments correctly', function () {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
collection.deleteDocument(result._id);
should(emitted).be.true();
collection.deleteDocument(result._id, function () {});
should(emitted).be.true();
emitted = false;
collection.deleteDocument(result._id, {}, function () {});
should(emitted).be.true();
});
it('should call the callback with an error if one occurs', function (done) {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
error = 'foobar';
this.timeout(50);
collection.deleteDocument(result._id, function (err, res) {
should(err).be.exactly('foobar');
should(res).be.undefined();
done();
});
});
it('should execute a deleteByQuery if a set of filters is provided', function (done) {
var
collection = kuzzle.dataCollectionFactory(expectedQuery.collection),
filters = { and: [ {term: {foo: 'bar'}}, { ids: ['baz', 'qux'] } ] };
this.timeout(50);
expectedQuery.body = filters;
expectedQuery.action = 'deleteByQuery';
result = { ids: ['foo', 'bar'] };
collection.deleteDocument(filters, function (err, res) {
should(err).be.null();
should(res).be.an.Array().and.match(result.ids);
done();
});
should(emitted).be.true();
});
});
describe('#fetchDocument', function () {
beforeEach(function () {
kuzzle = new Kuzzle('foo');
kuzzle.query = queryStub;
emitted = false;
result = { _id: 'foobar', _source: {foo: 'bar'} };
error = null;
expectedQuery = {
collection: 'foo',
action: 'get',
controller: 'read',
body: {}
};
});
it('should send the right fetchDocument query to Kuzzle', function (done) {
var
collection = kuzzle.dataCollectionFactory(expectedQuery.collection),
options = { queuable: false };
expectedQuery.options = options;
should(collection.fetchDocument(result._id, options, function (err, res) {
should(err).be.null();
should(res).be.instanceof(KuzzleDocument);
done();
})).be.exactly(collection);
should(emitted).be.true();
});
it('should raise an error if no callback is provided', function () {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
should(function () { collection.fetchDocument(); }).throw(Error);
should(emitted).be.false();
should(function () { collection.fetchDocument({}); }).throw(Error);
should(emitted).be.false();
should(function () { collection.fetchDocument({}, {}); }).throw(Error);
should(emitted).be.false();
});
it('should handle the callback argument correctly', function () {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
collection.fetchDocument({}, function () {});
should(emitted).be.true();
emitted = false;
collection.fetchDocument({}, {}, function () {});
should(emitted).be.true();
});
it('should call the callback with an error if one occurs', function (done) {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
error = 'foobar';
this.timeout(50);
collection.fetchDocument({}, function (err, res) {
should(err).be.exactly('foobar');
should(res).be.undefined();
done();
});
});
});
describe('#fetchAllDocuments', function () {
beforeEach(function () {
kuzzle = new Kuzzle('foo');
emitted = false;
});
it('should forward the query to the advancedSearch method', function () {
var
collection = kuzzle.dataCollectionFactory(expectedQuery.collection),
options = { queuable: false };
collection.advancedSearch = function () { emitted = true; };
expectedQuery.options = options;
should(collection.fetchAllDocuments(options, function () {})).be.exactly(collection);
should(emitted).be.true();
});
it('should raise an error if no callback is provided', function () {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
should(function () { collection.fetchAllDocuments(); }).throw(Error);
should(emitted).be.false();
should(function () { collection.fetchAllDocuments({}); }).throw(Error);
should(emitted).be.false();
});
it('should handle the callback argument correctly', function () {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
collection.advancedSearch = function () { emitted = true; };
collection.fetchAllDocuments(function () {});
should(emitted).be.true();
emitted = false;
collection.fetchAllDocuments({}, function () {});
should(emitted).be.true();
});
});
describe('#getMapping', function () {
beforeEach(function () {
kuzzle = new Kuzzle('foo');
kuzzle.query = queryStub;
emitted = false;
result = { mainindex: { mappings: { foo: { properties: {}}}} };
error = null;
expectedQuery = {
collection: 'foo',
action: 'getMapping',
controller: 'admin',
body: {}
};
});
it('should send instantiate a new KuzzleDataMapping object', function (done) {
var
collection = kuzzle.dataCollectionFactory(expectedQuery.collection),
options = { queuable: false };
expectedQuery.options = options;
should(collection.getMapping(options, function (err, res) {
should(err).be.null();
should(res).be.instanceof(KuzzleDataMapping);
done();
})).be.exactly(collection);
should(emitted).be.true();
});
it('should raise an error if no callback is provided', function () {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
should(function () { collection.getMapping(); }).throw(Error);
should(emitted).be.false();
should(function () { collection.getMapping({}); }).throw(Error);
should(emitted).be.false();
});
it('should handle the callback argument correctly', function () {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
collection.getMapping(function () {});
should(emitted).be.true();
emitted = false;
collection.getMapping({}, function () {});
should(emitted).be.true();
});
it('should call the callback with an error if one occurs', function (done) {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
error = 'foobar';
this.timeout(50);
collection.getMapping({}, function (err, res) {
should(err).be.exactly('foobar');
should(res).be.undefined();
done();
});
});
});
describe('#publish', function () {
beforeEach(function () {
kuzzle = new Kuzzle('foo');
kuzzle.query = queryStub;
emitted = false;
result = { _id: 'foobar', _source: {foo: 'bar'} };
error = null;
expectedQuery = {
collection: 'foo',
action: 'create',
controller: 'write',
body: {}
};
});
it('should send the right publish query to Kuzzle', function () {
var
collection = kuzzle.dataCollectionFactory(expectedQuery.collection),
options = { queuable: false };
expectedQuery.options = options;
collection.publish(result._source, options);
should(emitted).be.true();
});
it('should handle a KuzzleDocument object as an argument', function () {
var
collection = kuzzle.dataCollectionFactory(expectedQuery.collection),
options = { queuable: false };
expectedQuery.options = options;
collection.publish(new KuzzleDocument(collection, result._source), options);
should(emitted).be.true();
});
});
describe('#putMapping', function () {
beforeEach(function () {
kuzzle = new Kuzzle('foo');
kuzzle.query = queryStub;
emitted = false;
result = { _source: { properties: {}}};
error = null;
expectedQuery = {
collection: 'foo',
action: 'putMapping',
controller: 'admin',
body: {}
};
});
it('should send instantiate a new KuzzleDataMapping object', function (done) {
var
collection = kuzzle.dataCollectionFactory(expectedQuery.collection),
options = { queuable: false };
expectedQuery.options = options;
should(collection.putMapping(result, options, function (err, res) {
should(err).be.null();
should(res).be.instanceof(KuzzleDataMapping);
done();
})).be.exactly(collection);
should(emitted).be.true();
});
it('should handle the callback argument correctly', function () {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
collection.putMapping(result, function () {});
should(emitted).be.true();
emitted = false;
collection.putMapping(result, {}, function () {});
should(emitted).be.true();
});
it('should call the callback with an error if one occurs', function (done) {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
error = 'foobar';
this.timeout(50);
collection.putMapping({}, function (err, res) {
should(err).be.exactly('foobar');
should(res).be.undefined();
done();
});
});
});
describe('#replaceDocument', function () {
beforeEach(function () {
kuzzle = new Kuzzle('foo');
kuzzle.query = queryStub;
emitted = false;
result = { _id: 'foobar', _source: { foo: 'bar' } };
error = null;
expectedQuery = {
collection: 'foo',
action: 'createOrUpdate',
controller: 'write',
body: {}
};
});
it('should send the right replaceDocument query to Kuzzle', function (done) {
var
collection = kuzzle.dataCollectionFactory(expectedQuery.collection),
options = { queuable: false };
expectedQuery.options = options;
should(collection.replaceDocument(result._id, result._source, options, function (err, res) {
should(err).be.null();
should(res).be.instanceof(KuzzleDocument);
done();
})).be.exactly(collection);
should(emitted).be.true();
});
it('should handle arguments correctly', function () {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
collection.replaceDocument('foo');
should(emitted).be.true();
emitted = false;
collection.replaceDocument('foo', {});
should(emitted).be.true();
emitted = false;
collection.replaceDocument('foo', {}, function () {});
should(emitted).be.true();
emitted = false;
collection.replaceDocument('foo', {}, {}, function () {});
should(emitted).be.true();
});
it('should call the callback with an error if one occurs', function (done) {
var collection = kuzzle.dataCollectionFactory(expectedQuery.collection);
error = 'foobar';
this.timeout(50);
collection.replaceDocument(result._id, result._source, function (err, res) {
should(err).be.exactly('foobar');
should(res).be.undefined();
done();
});
});
});
});
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