Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc → .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"no-undef": 0,
"no-undef-init": 1,
"no-unreachable": 2,
"no-unused-expressions": 2,
"no-unused-expressions": [2, {"allowShortCircuit": true}],
"no-useless-call": 2,
"no-with": 2,
"quotes": [2, "single"],
Expand Down
4 changes: 2 additions & 2 deletions dist/kuzzle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/kuzzle.js.map

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions dist/kuzzle.min.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/kuzzle.min.map

This file was deleted.

118 changes: 31 additions & 87 deletions src/kuzzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ Kuzzle.prototype.getJwtToken = function() {
* @param credentials
* @param expiresIn
* @param cb
* @returns {Kuzzle}
*/
Kuzzle.prototype.login = function (strategy) {
var
Expand All @@ -456,7 +455,7 @@ Kuzzle.prototype.login = function (strategy) {
strategy: strategy
},
credentials,
cb;
cb = null;

// Handle arguments (credentials, expiresIn, cb)
if (arguments[1]) {
Expand Down Expand Up @@ -491,20 +490,13 @@ Kuzzle.prototype.login = function (strategy) {
self.setJwtToken(response.result.jwt);
}

if (cb && typeof cb === 'function') {
cb(null, response.result);
}
cb && cb(null, response.result);
}
else {
if (cb && typeof cb === 'function') {
cb(error);
}

cb && cb(error);
self.emitEvent('loginAttempt', {success: false, error: error.message});
}
});

return self;
};

/**
Expand All @@ -523,15 +515,12 @@ Kuzzle.prototype.logout = function (cb) {
body: {}
};

this.query({controller: 'auth', action: 'logout'}, request, {queuable: false}, function(error) {
this.query({controller: 'auth', action: 'logout'}, request, {queuable: false}, typeof cb !== 'function' ? null : function(error) {
if (error === null) {
self.jwtToken = undefined;

if (typeof cb === 'function') {
cb(null, self);
}
cb(null, self);
}
else if (typeof cb === 'function') {
else {
cb(error);
}
});
Expand All @@ -545,11 +534,9 @@ Kuzzle.prototype.logout = function (cb) {
* @param {string} token The jwt token to check
* @param {function} callback The callback to be called when the response is
* available. The signature is `function(error, response)`.
* @return {Kuzzle} The Kuzzle instance to enable chaining.
*/
Kuzzle.prototype.checkToken = function (token, callback) {
var
self = this,
request = {
body: {
token: token
Expand All @@ -565,16 +552,13 @@ Kuzzle.prototype.checkToken = function (token, callback) {

callback(null, response.result);
});

return self;
};

/**
* Fetches the current user.
*
* @param {function} callback The callback to be called when the response is
* available. The signature is `function(error, response)`.
* @return {Kuzzle} The Kuzzle instance to enable chaining.
*/
Kuzzle.prototype.whoAmI = function (callback) {
var self = this;
Expand All @@ -588,13 +572,12 @@ Kuzzle.prototype.whoAmI = function (callback) {

callback(null, new KuzzleUser(self.security, response.result._id, response.result._source));
});

return self;
};

/**
* Gets the rights array of the currently logged user.
*
* @param {object} [options] - Optional parameters
Copy link

@ballinette ballinette Sep 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the options parameter should be removed from the function definition?

Kuzzle.prototype.getMyRights = function (options, cb) {
// (...)
   if (!cb && typeof options === 'function') {
     cb = options;
     options = null;
   }
// (...)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, this seems to be an old mistake. Fixing it right away.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

* @param {function} cb The callback containing the normalized array of rights.
*/
Kuzzle.prototype.getMyRights = function (options, cb) {
Expand All @@ -607,7 +590,7 @@ Kuzzle.prototype.getMyRights = function (options, cb) {

self.callbackRequired('Kuzzle.getMyRights', cb);

self.query({controller: 'auth', action:'getMyRights'}, {}, null, function (err, res) {
self.query({controller: 'auth', action:'getMyRights'}, {}, options, function (err, res) {
if (err) {
return cb(err);
}
Expand All @@ -622,6 +605,7 @@ Kuzzle.prototype.getMyRights = function (options, cb) {
* @param {object} content - a plain javascript object representing the user's modification
* @param {object} [options] - (optional) arguments
* @param {responseCallback} [cb] - (optional) Handles the query response
* @returns {Kuzzle} this object
*/
Kuzzle.prototype.updateSelf = function (content, options, cb) {
var
Expand All @@ -636,17 +620,11 @@ Kuzzle.prototype.updateSelf = function (content, options, cb) {

data.body = content;

if (cb) {
self.query(queryArgs, data, options, function (err, res) {
if (err) {
return cb(err);
}
self.query(queryArgs, data, options, cb && function (err, res) {
cb(err, err ? undefined : res.result);
});

cb(null, res.result);
});
} else {
self.query(queryArgs, data, options);
}
return this;
};

/**
Expand Down Expand Up @@ -719,9 +697,7 @@ function emitRequest (request, cb) {
self.emitEvent('jwtTokenExpired', request, cb);
}

if (cb) {
cb(response.error, response);
}
cb && cb(response.error, response);
});
}

Expand Down Expand Up @@ -830,7 +806,6 @@ Kuzzle.prototype.addListener = function(event, listener) {
*
* @param {object} [options] - Optional parameters
* @param {responseCallback} cb - Handles the query response
* @returns {object} this
*/
Kuzzle.prototype.getAllStatistics = function (options, cb) {
if (!cb && typeof options === 'function') {
Expand All @@ -847,8 +822,6 @@ Kuzzle.prototype.getAllStatistics = function (options, cb) {

cb(null, res.result.hits);
});

return this;
};

/**
Expand All @@ -858,10 +831,11 @@ Kuzzle.prototype.getAllStatistics = function (options, cb) {
* @param {number} timestamp - Epoch time. Starting time from which the frames are to be retrieved
* @param {object} [options] - Optional parameters
* @param {responseCallback} cb - Handles the query response
* @returns {object} this
*/
Kuzzle.prototype.getStatistics = function (timestamp, options, cb) {
var queryCB;
var
queryCB,
body;

if (!cb) {
if (arguments.length === 1) {
Expand All @@ -885,22 +859,13 @@ Kuzzle.prototype.getStatistics = function (timestamp, options, cb) {
return cb(err);
}

if (timestamp) {
cb(null, res.result.hits);
} else {
cb(null, [res.result]);
}
cb(null, timestamp ? res.result.hits : [res.result]);
};

this.callbackRequired('Kuzzle.getStatistics', cb);

if (!timestamp) {
this.query({controller: 'admin', action: 'getLastStats'}, {}, options, queryCB);
} else {
this.query({controller: 'admin', action: 'getStats'}, { body: { startTime: timestamp } }, options, queryCB);
}

return this;
body = timestamp ? {body: {startTime: timestamp}} : {};
this.query({controller: 'admin', action: timestamp ? 'getStats' : 'getLastStats'}, body, options, queryCB);
};

/**
Expand All @@ -922,12 +887,8 @@ Kuzzle.prototype.dataCollectionFactory = function(collection, index) {
index = this.defaultIndex;
}

if (typeof index !== 'string') {
throw new Error('Invalid "index" argument: string expected, got ' + typeof index);
}

if (typeof collection !== 'string') {
throw new Error('Invalid "collection" argument: string expected, got ' + typeof collection);
if (typeof index !== 'string' || typeof collection !== 'string') {
throw new Error('Invalid index or collection argument: string expected');
}

if (!this.collections[index]) {
Expand Down Expand Up @@ -957,7 +918,6 @@ Kuzzle.prototype.flushQueue = function () {
* @param {string} [index] - Index containing collections to be listed
* @param {object} [options] - Optional parameters
* @param {responseCallback} cb - Handles the query response
* @returns {object} this
*/
Kuzzle.prototype.listCollections = function () {
var
Expand Down Expand Up @@ -1000,18 +960,15 @@ Kuzzle.prototype.listCollections = function () {
return cb(err);
}

return cb(null, res.result.collections);
cb(null, res.result.collections);
});

return this;
};

/**
* Returns the list of existing indexes in Kuzzle
*
* @param {object} [options] - Optional arguments
* @param {responseCallback} cb - Handles the query response
* @returns {object} this
*/
Kuzzle.prototype.listIndexes = function (options, cb) {
if (!cb && typeof options === 'function') {
Expand All @@ -1022,14 +979,8 @@ Kuzzle.prototype.listIndexes = function (options, cb) {
this.callbackRequired('Kuzzle.listIndexes', cb);

this.query({controller: 'read', action: 'listIndexes'}, {}, options, function (err, res) {
if (err) {
return cb(err);
}

return cb(null, res.result.indexes);
cb(err, err ? undefined : res.result.indexes);
});

return this;
};

/**
Expand All @@ -1055,7 +1006,6 @@ Kuzzle.prototype.disconnect = function () {
*
* @param {object} [options] - Optional arguments
* @param {responseCallback} cb - Handles the query response
* @returns {object} this
*/
Kuzzle.prototype.getServerInfo = function (options, cb) {
if (!cb && typeof options === 'function') {
Expand All @@ -1072,8 +1022,6 @@ Kuzzle.prototype.getServerInfo = function (options, cb) {

cb(null, res.result.serverInfo);
});

return this;
};

/**
Expand Down Expand Up @@ -1122,7 +1070,6 @@ Kuzzle.prototype.refreshIndex = function () {
* @param {string} index - The index to get the status from. Defaults to Kuzzle.defaultIndex
* @param {object} options - Optinal arguments
* @param {responseCallback} cb - Handles the query response
* @returns {object} this
*/
Kuzzle.prototype.getAutoRefresh = function () {
var
Expand Down Expand Up @@ -1153,8 +1100,6 @@ Kuzzle.prototype.getAutoRefresh = function () {

this.callbackRequired('Kuzzle.getAutoRefresh', cb);
this.query({ index: index, controller: 'admin', action: 'getAutoRefresh'}, {}, options, cb);

return this;
};

/**
Expand Down Expand Up @@ -1210,7 +1155,6 @@ Kuzzle.prototype.setAutoRefresh = function () {
* Return the current Kuzzle's UTC Epoch time, in milliseconds
* @param {object} [options] - Optional parameters
* @param {responseCallback} cb - Handles the query response
* @returns {object} this
*/
Kuzzle.prototype.now = function (options, cb) {
if (!cb && typeof options === 'function') {
Expand All @@ -1221,14 +1165,8 @@ Kuzzle.prototype.now = function (options, cb) {
this.callbackRequired('Kuzzle.now', cb);

this.query({controller: 'read', action: 'now'}, {}, options, function (err, res) {
if (err) {
return cb(err);
}

cb(null, res.result.now);
cb(err, res && res.result.now);
});

return this;
};

/**
Expand Down Expand Up @@ -1334,6 +1272,7 @@ Kuzzle.prototype.query = function (queryArgs, query, options, cb) {
* Removes all listeners, either from a specific event or from all events
*
* @param {string} event - One of the event described in the Event Handling section of this documentation
* @returns {Kuzzle} this object
*/
Kuzzle.prototype.removeAllListeners = function (event) {
var
Expand All @@ -1351,13 +1290,16 @@ Kuzzle.prototype.removeAllListeners = function (event) {
self.eventListeners[eventName].listeners = [];
});
}

return this;
};

/**
* Removes a listener from an event.
*
* @param {string} event - One of the event described in the Event Handling section of this documentation
* @param {string} listenerId - The ID returned by addListener
* @returns {Kuzzle} this object
*/
Kuzzle.prototype.removeListener = function (event, listenerId) {
var
Expand All @@ -1373,6 +1315,8 @@ Kuzzle.prototype.removeListener = function (event, listenerId) {
self.eventListeners[event].listeners.splice(index, 1);
}
});

return this;
};

/**
Expand Down
Loading