Skip to content

Commit

Permalink
Merge pull request #235 from kuzzleio/5.0.4-proposal
Browse files Browse the repository at this point in the history
Release: 5.0.4
  • Loading branch information
scottinet authored Jun 20, 2017
2 parents 00dcaca + 93c3d68 commit ae73740
Show file tree
Hide file tree
Showing 16 changed files with 3,813 additions and 101 deletions.
3,158 changes: 3,158 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kuzzle-sdk",
"version": "5.0.3",
"version": "5.0.4",
"description": "Official Javascript SDK for Kuzzle",
"author": "The Kuzzle Team <[email protected]>",
"repository": {
Expand All @@ -27,28 +27,28 @@
"main": "index.js",
"license": "Apache-2.0",
"dependencies": {
"bluebird": "3.4.7",
"eslint-loader": "^1.6.1",
"uuid": "3.0.1",
"bluebird": "3.5.0",
"eslint-loader": "^1.8.0",
"uuid": "3.1.0",
"ws": "3.0.0"
},
"peerDependencies": {
"bufferutil": "^2.0.1",
"utf-8-validate": "^3.0.1"
},
"devDependencies": {
"codecov": "^1.0.1",
"eslint": "^3.15.0",
"eslint-friendly-formatter": "^2.0.7",
"codecov": "^2.2.0",
"eslint": "^4.0.0",
"eslint-friendly-formatter": "^3.0.0",
"istanbul": "0.4.5",
"istanbul-middleware": "0.2.2",
"mocha": "3.2.0",
"ora": "^1.1.0",
"proxyquire": "^1.7.11",
"mocha": "3.4.2",
"ora": "^1.3.0",
"proxyquire": "^1.8.0",
"rewire": "^2.5.2",
"should": "11.2.0",
"should": "11.2.1",
"should-sinon": "0.0.5",
"sinon": "^1.17.7",
"sinon": "^2.3.5",
"webpack": "^1.13.1"
},
"engines": {
Expand Down
192 changes: 178 additions & 14 deletions src/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,32 @@ Collection.prototype.deleteDocument = function (arg, options, cb) {
return this;
};

/**
* Deletes the current specifications of this collection
*
* @param {object} [options] - Optional parameters
* @param {responseCallback} [cb] - Handles the query response
* @return {object} this
*/
Collection.prototype.deleteSpecifications = function (options, cb) {
var
data = { index: this.index, collection: this.collection },
self = this;

if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

data = self.kuzzle.addHeaders(data, this.headers);

self.kuzzle.query(this.buildQueryArgs('collection', 'deleteSpecifications'), data, options, function (err, res) {
cb(err, err ? undefined : res.result);
});

return self;
};

/**
* Returns a boolean indicating whether or not a document with provided ID exists.
*
Expand Down Expand Up @@ -335,8 +361,7 @@ Collection.prototype.getMapping = function (options, cb) {
* @returns {object} this
*/
Collection.prototype.mCreateDocument = function (documents, options, cb) {
var
data = {
var data = {
body: {},
},
self = this;
Expand Down Expand Up @@ -374,8 +399,7 @@ Collection.prototype.mCreateDocument = function (documents, options, cb) {
* @returns {object} this
*/
Collection.prototype.mCreateOrReplaceDocument = function (documents, options, cb) {
var
data = {
var data = {
body: {},
},
self = this;
Expand Down Expand Up @@ -413,8 +437,7 @@ Collection.prototype.mCreateOrReplaceDocument = function (documents, options, cb
* @returns {object} this
*/
Collection.prototype.mDeleteDocument = function (documentIds, options, cb) {
var
data = {
var data = {
body: {
ids: documentIds
}
Expand Down Expand Up @@ -449,8 +472,7 @@ Collection.prototype.mDeleteDocument = function (documentIds, options, cb) {
* @param {responseCallback} cb - Returns an instantiated CollectionMapping object
*/
Collection.prototype.mGetDocument = function (documentIds, options, cb) {
var
data = {
var data = {
body: {
ids: documentIds
}
Expand Down Expand Up @@ -484,8 +506,7 @@ Collection.prototype.mGetDocument = function (documentIds, options, cb) {
* @returns {object} this
*/
Collection.prototype.mReplaceDocument = function (documents, options, cb) {
var
data = {
var data = {
body: {}
},
self = this;
Expand Down Expand Up @@ -523,8 +544,7 @@ Collection.prototype.mReplaceDocument = function (documents, options, cb) {
* @returns {object} this
*/
Collection.prototype.mUpdateDocument = function (documents, options, cb) {
var
data = {
var data = {
body: {}
},
self = this;
Expand Down Expand Up @@ -553,6 +573,30 @@ Collection.prototype.mUpdateDocument = function (documents, options, cb) {
return self;
};

/**
* Retrieves the current specifications of this collection
*
* @param {object} [options] - Optional parameters
* @param {responseCallback} cb - Handles the query response
*/
Collection.prototype.getSpecifications = function (options, cb) {
var
data = { index: this.index, collection: this.collection },
self = this;

if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

self.kuzzle.callbackRequired('Collection.getSpecifications', cb);
data = self.kuzzle.addHeaders(data, this.headers);

self.kuzzle.query(this.buildQueryArgs('collection', 'getSpecifications'), data, options, function (err, res) {
cb(err, err ? undefined : res.result);
});
};

/**
* Publish a realtime message
*
Expand Down Expand Up @@ -752,6 +796,68 @@ Collection.prototype.scroll = function (scrollId, options, filters, cb) {
return this;
};

/**
* Retrieves next result of a search with scroll query.
*
* @param {string} scrollId
* @param {object} [options] - Optional parameters
* @param {responseCallback} cb - Handles the query response
*/
Collection.prototype.scrollSpecifications = function (scrollId, options, cb) {
var
data = { scrollId: scrollId };

if (!scrollId) {
throw new Error('Collection.scrollSpecifications: scrollId is required');
}

if (!cb && typeof options === 'function') {
cb = options;
options = {};
}

this.kuzzle.callbackRequired('Collection.scrollSpecifications', cb);

if (options && options.scroll) {
data.scroll = options.scroll;
}

this.kuzzle.query(
{ controller: 'collection', action: 'scrollSpecifications'},
this.kuzzle.addHeaders(data, this.headers),
options,
function (err, res) {
cb (err, err ? undefined : res.result);
}
);
};

/**
* Searches specifications across indexes/collections according to the provided filters
*
* @param {object} [filters] - Optional filters in ElasticSearch Query DSL format
* @param {object} [options] - Optional parameters
* @param {responseCallback} cb - Handles the query response
*/
Collection.prototype.searchSpecifications = function (filters, options, cb) {
var
data = { body: { query: filters } },
self = this;

if (!cb && typeof options === 'function') {
cb = options;
options = {};
}

self.kuzzle.callbackRequired('Collection.searchSpecifications', cb);

data = self.kuzzle.addHeaders(data, this.headers);

self.kuzzle.query({ controller: 'collection', action: 'searchSpecifications' }, data, options, function (err, res) {
cb(err, err ? undefined : res.result);
});
};

/**
* Subscribes to this data collection with a set of filters.
* To subscribe to the entire data collection, simply provide an empty filter.
Expand Down Expand Up @@ -818,8 +924,7 @@ Collection.prototype.truncate = function (options, cb) {
* @return {object} this
*/
Collection.prototype.updateDocument = function (documentId, content, options, cb) {
var
data = {
var data = {
_id: documentId,
body: content
},
Expand Down Expand Up @@ -847,6 +952,65 @@ Collection.prototype.updateDocument = function (documentId, content, options, cb
return self;
};

/**
* Updates the current specifications of this collection
*
* @param {object} specifications - Specifications content
* @param {object} [options] - Optional parameters
* @param {responseCallback} [cb] - Handles the query response
* @return {object} this
*/
Collection.prototype.updateSpecifications = function (specifications, options, cb) {
var
collection = {},
data = { body: {} },
self = this;

collection[this.collection] = specifications;
data.body[this.index] = collection;

if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

data = self.kuzzle.addHeaders(data, this.headers);

self.kuzzle.query(this.buildQueryArgs('collection', 'updateSpecifications'), data, options, cb && function (err, res) {
cb(err, err ? undefined : res.result);
});

return self;
};

/**
* Validates the provided specifications
*
* @param {object} specifications - Specifications content
* @param {object} [options] - Optional parameters
* @param {responseCallback} cb - Handles the query response
*/
Collection.prototype.validateSpecifications = function (specifications, options, cb) {
var
collection = {},
data = { body: {} },
self = this;

collection[this.collection] = specifications;
data.body[this.index] = collection;

if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

self.kuzzle.callbackRequired('Collection.validateSpecifications', cb);
data = self.kuzzle.addHeaders(data, this.headers);

self.kuzzle.query(this.buildQueryArgs('collection', 'validateSpecifications'), data, options, function (err, res) {
cb(err, err ? undefined : res.result.valid);
});
};

/**
* Instantiate a new Document object. Workaround to the module.exports limitation, preventing multiple
Expand Down
8 changes: 4 additions & 4 deletions src/Kuzzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function Kuzzle (host, options, cb) {
'networkError',
'disconnected',
'reconnected',
'jwtTokenExpired',
'tokenExpired',
'loginAttempt',
'offlineQueuePush',
'offlineQueuePop',
Expand Down Expand Up @@ -273,7 +273,7 @@ function Kuzzle (host, options, cb) {
error: {timeout: this.eventTimeout},
disconnected: {timeout: this.eventTimeout},
reconnected: {timeout: this.eventTimeout},
jwtTokenExpired: {timeout: this.eventTimeout},
tokenExpired: {timeout: this.eventTimeout},
loginAttempt: {timeout: this.eventTimeout}
},
writeable: false
Expand Down Expand Up @@ -414,7 +414,7 @@ Kuzzle.prototype.connect = function () {
// shouldn't obtain an error but let's invalidate the token anyway
if (err || !res.valid) {
self.jwtToken = undefined;
self.emitEvent('jwtTokenExpired');
self.emitEvent('tokenExpired');
}

reconnect();
Expand Down Expand Up @@ -869,7 +869,7 @@ function emitRequest (request, cb) {

if (request.action !== 'logout' && response.error && response.error.message === 'Token expired') {
self.jwtToken = undefined;
self.emitEvent('jwtTokenExpired', request, cb);
self.emitEvent('tokenExpired', request, cb);
}

if (response.error) {
Expand Down
3 changes: 1 addition & 2 deletions src/MemoryStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,7 @@ function mapGeoRadiusResults(results) {

return results.map(function (point) {
// The point id is always the first item
var
p = {
var p = {
name: point[0]
},
i;
Expand Down
14 changes: 4 additions & 10 deletions src/Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,22 +311,16 @@ Room.prototype.setHeaders = function (content, replace) {
* @returns {*}
*/
function notificationCallback (data) {
if (data.error) {
return this.callback(data.error);
}

if (data.action === 'jwtTokenExpired') {
if (data.type === 'TokenExpired') {
this.kuzzle.jwtToken = undefined;
return this.kuzzle.emitEvent('jwtTokenExpired');
return this.kuzzle.emitEvent('tokenExpired');
}

if (data.controller === 'document' || (data.controller === 'realtime' && data.action === 'publish')) {
data.type = 'document';
if (data.type === 'document') {
data.document = new Document(this.collection, data.result._id, data.result._source, data.result._meta);
delete data.result;
}
else if (data.controller === 'realtime') {
data.type = 'user';
else if (data.type === 'user') {
data.user = {count: data.result.count};
delete data.result;
}
Expand Down
2 changes: 0 additions & 2 deletions src/security/Security.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,6 @@ Security.prototype.scrollProfiles = function (scrollId, options, cb) {
scrollId: scrollId
});
});

return this;
};

/**
Expand Down
Loading

0 comments on commit ae73740

Please sign in to comment.