Skip to content

Commit

Permalink
3.35.0
Browse files Browse the repository at this point in the history
* FEAT(remaining-validity): adds remaining valitity method (#778)
* FEAT(unit-testing-relevance): adds unit testing relevance methods (#777)
* FEAT(adds-assign-user-ids): adds assignUserIDs method and tests (#783)
  • Loading branch information
nunomaduro committed Sep 26, 2019
1 parent 1688b1e commit cff5f96
Show file tree
Hide file tree
Showing 12 changed files with 336 additions and 26 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# CHANGELOG

## 3.35.0
>2019-09-26
* FEAT(remaining-validity): adds remaining valitity method (#778)
* `client.getSecuredApiKeyRemainingValidity('securedAPIKey')`: Gets remaining validity seconds of an secured API Key
* FEAT(unit-testing-relevance): adds unit testing relevance methods (#777)
* `index.findObject(hit => hit.firstname == 'Jimmie')`: Find an object by the given condition
* `index.getObjectPosition(results, 'a-unique-identifier')`: Retrieve the given object position in the given results set
* FEAT(adds-assign-user-ids): adds assignUserIDs method and tests (#783)
* `client.assignUserIDs({ cluster: 'c1-test', userIDs: ['some-user-1', 'some-user-2'] })`: Assign a array of userIDs to a cluster

## 3.34.0
>2019-08-29
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "algoliasearch",
"version": "3.34.0",
"version": "3.35.0",
"homepage": "https://github.com/algolia/algoliasearch-client-js",
"authors": [
"Algolia Team <[email protected]>"
Expand Down
101 changes: 99 additions & 2 deletions dist/algoliasearch.angular.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! algoliasearch 3.34.0 | © 2014, 2015 Algolia SAS | github.com/algolia/algoliasearch-client-js */
/*! algoliasearch 3.35.0 | © 2014, 2015 Algolia SAS | github.com/algolia/algoliasearch-client-js */
(function(f){var g;if(typeof window!=='undefined'){g=window}else if(typeof self!=='undefined'){g=self}g.ALGOLIA_MIGRATION_LAYER=f()})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

module.exports = function load (src, opts, cb) {
Expand Down Expand Up @@ -3355,6 +3355,31 @@ AlgoliaSearch.prototype.assignUserID = function(data, callback) {
});
};

/**
* Assign a array of userIDs to a cluster.
*
* @param {Array} data.userIDs The array of userIDs to assign to a new cluster
* @param {string} data.cluster The cluster to assign the user to
* @return {Promise|undefined} Returns a promise if no callback given
* @example
* client.assignUserIDs({ cluster: 'c1-test', userIDs: ['some-user-1', 'some-user-2'] });
*/
AlgoliaSearch.prototype.assignUserIDs = function(data, callback) {
if (!data.userIDs || !data.cluster) {
throw new errors.AlgoliaSearchError('You have to provide both an array of userIDs and cluster', data);
}
return this._jsonRequest({
method: 'POST',
url: '/1/clusters/mapping/batch',
hostType: 'write',
body: {
cluster: data.cluster,
users: data.userIDs
},
callback: callback
});
};

/**
* Get the top userIDs
*
Expand Down Expand Up @@ -3541,6 +3566,7 @@ AlgoliaSearch.prototype.disableRateLimitForward = notImplemented;
AlgoliaSearch.prototype.useSecuredAPIKey = notImplemented;
AlgoliaSearch.prototype.disableSecuredAPIKey = notImplemented;
AlgoliaSearch.prototype.generateSecuredApiKey = notImplemented;
AlgoliaSearch.prototype.getSecuredApiKeyRemainingValidity = notImplemented;

function notImplemented() {
var message = 'Not implemented in this environment.\n' +
Expand Down Expand Up @@ -5447,6 +5473,69 @@ Index.prototype.exists = function(callback) {
});
};

Index.prototype.findObject = function(findCallback, requestOptions, callback) {
requestOptions = requestOptions === undefined ? {} : requestOptions;
var paginate = requestOptions.paginate !== undefined ? requestOptions.paginate : true;
var query = requestOptions.query !== undefined ? requestOptions.query : '';

var that = this;
var page = 0;

var paginateLoop = function() {
requestOptions.page = page;

return that.search(query, requestOptions).then(function(result) {
var hits = result.hits;

for (var position = 0; position < hits.length; position++) {
var hit = hits[position];
if (findCallback(hit)) {
return {
object: hit,
position: position,
page: page
};
}
}

page += 1;

// paginate if option was set and has next page
if (!paginate || page >= result.nbPages) {
throw new errors.ObjectNotFound('Object not found');
}

return paginateLoop();
});
};

var promise = paginateLoop(page);

if (callback === undefined) {
return promise;
}

promise
.then(function(res) {
callback(null, res);
})
.catch(function(err) {
callback(err);
});
};

Index.prototype.getObjectPosition = function(result, objectID) {
var hits = result.hits;

for (var position = 0; position < hits.length; position++) {
if (hits[position].objectID === objectID) {
return position;
}
}

return -1;
};

/*
* Set settings for this index
*
Expand Down Expand Up @@ -7085,10 +7174,18 @@ module.exports = {
'JSONPScriptFail',
'<script> was loaded but did not call our provided callback'
),
ValidUntilNotFound: createCustomError(
'ValidUntilNotFound',
'The SecuredAPIKey does not have a validUntil parameter.'
),
JSONPScriptError: createCustomError(
'JSONPScriptError',
'<script> unable to load due to an `error` event on it'
),
ObjectNotFound: createCustomError(
'ObjectNotFound',
'Object not found'
),
Unknown: createCustomError(
'Unknown',
'Unknown error occured'
Expand Down Expand Up @@ -7296,6 +7393,6 @@ function cleanup() {
},{"1":1}],38:[function(require,module,exports){
'use strict';

module.exports = '3.34.0';
module.exports = '3.35.0';

},{}]},{},[21]);
8 changes: 4 additions & 4 deletions dist/algoliasearch.angular.min.js

Large diffs are not rendered by default.

101 changes: 99 additions & 2 deletions dist/algoliasearch.jquery.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! algoliasearch 3.34.0 | © 2014, 2015 Algolia SAS | github.com/algolia/algoliasearch-client-js */
/*! algoliasearch 3.35.0 | © 2014, 2015 Algolia SAS | github.com/algolia/algoliasearch-client-js */
(function(f){var g;if(typeof window!=='undefined'){g=window}else if(typeof self!=='undefined'){g=self}g.ALGOLIA_MIGRATION_LAYER=f()})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

module.exports = function load (src, opts, cb) {
Expand Down Expand Up @@ -3355,6 +3355,31 @@ AlgoliaSearch.prototype.assignUserID = function(data, callback) {
});
};

/**
* Assign a array of userIDs to a cluster.
*
* @param {Array} data.userIDs The array of userIDs to assign to a new cluster
* @param {string} data.cluster The cluster to assign the user to
* @return {Promise|undefined} Returns a promise if no callback given
* @example
* client.assignUserIDs({ cluster: 'c1-test', userIDs: ['some-user-1', 'some-user-2'] });
*/
AlgoliaSearch.prototype.assignUserIDs = function(data, callback) {
if (!data.userIDs || !data.cluster) {
throw new errors.AlgoliaSearchError('You have to provide both an array of userIDs and cluster', data);
}
return this._jsonRequest({
method: 'POST',
url: '/1/clusters/mapping/batch',
hostType: 'write',
body: {
cluster: data.cluster,
users: data.userIDs
},
callback: callback
});
};

/**
* Get the top userIDs
*
Expand Down Expand Up @@ -3541,6 +3566,7 @@ AlgoliaSearch.prototype.disableRateLimitForward = notImplemented;
AlgoliaSearch.prototype.useSecuredAPIKey = notImplemented;
AlgoliaSearch.prototype.disableSecuredAPIKey = notImplemented;
AlgoliaSearch.prototype.generateSecuredApiKey = notImplemented;
AlgoliaSearch.prototype.getSecuredApiKeyRemainingValidity = notImplemented;

function notImplemented() {
var message = 'Not implemented in this environment.\n' +
Expand Down Expand Up @@ -5447,6 +5473,69 @@ Index.prototype.exists = function(callback) {
});
};

Index.prototype.findObject = function(findCallback, requestOptions, callback) {
requestOptions = requestOptions === undefined ? {} : requestOptions;
var paginate = requestOptions.paginate !== undefined ? requestOptions.paginate : true;
var query = requestOptions.query !== undefined ? requestOptions.query : '';

var that = this;
var page = 0;

var paginateLoop = function() {
requestOptions.page = page;

return that.search(query, requestOptions).then(function(result) {
var hits = result.hits;

for (var position = 0; position < hits.length; position++) {
var hit = hits[position];
if (findCallback(hit)) {
return {
object: hit,
position: position,
page: page
};
}
}

page += 1;

// paginate if option was set and has next page
if (!paginate || page >= result.nbPages) {
throw new errors.ObjectNotFound('Object not found');
}

return paginateLoop();
});
};

var promise = paginateLoop(page);

if (callback === undefined) {
return promise;
}

promise
.then(function(res) {
callback(null, res);
})
.catch(function(err) {
callback(err);
});
};

Index.prototype.getObjectPosition = function(result, objectID) {
var hits = result.hits;

for (var position = 0; position < hits.length; position++) {
if (hits[position].objectID === objectID) {
return position;
}
}

return -1;
};

/*
* Set settings for this index
*
Expand Down Expand Up @@ -7031,10 +7120,18 @@ module.exports = {
'JSONPScriptFail',
'<script> was loaded but did not call our provided callback'
),
ValidUntilNotFound: createCustomError(
'ValidUntilNotFound',
'The SecuredAPIKey does not have a validUntil parameter.'
),
JSONPScriptError: createCustomError(
'JSONPScriptError',
'<script> unable to load due to an `error` event on it'
),
ObjectNotFound: createCustomError(
'ObjectNotFound',
'Object not found'
),
Unknown: createCustomError(
'Unknown',
'Unknown error occured'
Expand Down Expand Up @@ -7242,6 +7339,6 @@ function cleanup() {
},{"1":1}],38:[function(require,module,exports){
'use strict';

module.exports = '3.34.0';
module.exports = '3.35.0';

},{}]},{},[21]);
8 changes: 4 additions & 4 deletions dist/algoliasearch.jquery.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit cff5f96

Please sign in to comment.