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

@meilisearch/instant-meilisearch

Package Overview
Dependencies
Maintainers
5
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@meilisearch/instant-meilisearch - npm Package Compare versions

Comparing version 0.13.6 to 0.14.0

454

dist/instant-meilisearch.cjs.js

@@ -83,12 +83,2 @@ 'use strict';

function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {

@@ -120,3 +110,3 @@ var e = new Error(message);

* Resolves apiKey if it is a function
* @param {string | apiKeyCallback} apiKey
* @param {string | ApiKeyCallback} apiKey
* @returns {string} api key value

@@ -229,4 +219,9 @@ */

var filterEscapeRegExp = /([\\"])/g;
function getValueWithEscapedBackslashesAndQuotes(value) {
return value.replace(filterEscapeRegExp, '\\$1');
}
/**
* Transform InstantSearch filter to Meilisearch compatible filter format.
* Transform InstantSearch [facet filter](https://www.algolia.com/doc/api-reference/api-parameters/facetFilters/)
* to Meilisearch compatible filter format.
* Change sign from `:` to `=`

@@ -236,36 +231,56 @@ * "facet:facetValue" becomes "facet=facetValue"

* Wrap both the facet and its facet value between quotes.
* This avoid formating issues on facets containing multiple words.
* This avoids formatting issues on facets containing multiple words.
* Escape backslash \\ and quote " characters.
*
* 'My facet:My facet value' becomes '"My facet":"My facet value"'
*
* @param {string} filter?
* @returns {Filter}
* @param {string} filter
* @returns {string}
*/
function transformFilter(filter) {
return filter.replace(/(.*):(.*)/i, '"$1"="$2"');
function transformFacetFilter(filter) {
var escapedFilter = getValueWithEscapedBackslashesAndQuotes(filter);
var colonIndex = escapedFilter.indexOf(':');
var attribute = escapedFilter.slice(0, colonIndex);
var value = escapedFilter.slice(colonIndex + 1);
return "\"".concat(attribute, "\"=\"").concat(value, "\"");
}
// Matches first occurrence of an operator
var numericSplitRegExp = /(?<!(?:[<!>]?=|<|>|:).*)([<!>]?=|<|>|:)/;
/**
* Itterate over all filters.
* Transform InstantSearch [numeric filter](https://www.algolia.com/doc/api-reference/api-parameters/numericFilters/)
* to Meilisearch compatible filter format.
*
* 'price:5.99 TO 100' becomes '"price" 5.99 TO 100'
*
* 'price = 5.99' becomes '"price"=5.99'
*
* Wrap the attribute between quotes.
* Escape backslash (\\) and quote (") characters.
*
* @param {string} filter
* @returns {string}
*/
function transformNumericFilter(filter) {
// TODO: Warn users to not enable facet values escape for negative numbers.
// https://github.com/algolia/instantsearch/blob/da701529ed325bb7a1d782e80cb994711e20d94a/packages/instantsearch.js/src/lib/utils/escapeFacetValue.ts#L13-L21
var _a = filter.split(numericSplitRegExp), attribute = _a[0], operator = _a[1], value = _a[2];
var escapedAttribute = getValueWithEscapedBackslashesAndQuotes(attribute);
return "\"".concat(escapedAttribute.trim(), "\"").concat(operator === ':' ? ' ' : operator).concat(value.trim());
}
/**
* Iterate over all filters.
* Return the filters in a Meilisearch compatible format.
*
* @param {SearchContext['facetFilters']} filters?
* @param {(filter: string) => string} transformCallback
* @param {SearchContext['facetFilters']} filters
* @returns {Filter}
*/
function transformFilters(filters) {
if (typeof filters === 'string') {
return transformFilter(filters);
}
else if (Array.isArray(filters))
return filters
.map(function (filter) {
if (Array.isArray(filter))
return filter
.map(function (nestedFilter) { return transformFilter(nestedFilter); })
.filter(function (elem) { return elem; });
else {
return transformFilter(filter);
}
})
.filter(function (elem) { return elem; });
return [];
function transformFilters(transformCallback, filters) {
return typeof filters === 'string'
? transformCallback(filters)
: filters.map(function (filter) {
return typeof filter === 'string'
? transformCallback(filter)
: filter.map(function (nestedFilter) { return transformCallback(nestedFilter); });
});
}

@@ -276,36 +291,31 @@ /**

*
* @param {Filter} filter
* @returns {Array}
* @param {Filter} [filter]
* @returns {Array|undefined}
*/
function filterToArray(filter) {
// Filter is a string
if (filter === '')
return [];
else if (typeof filter === 'string')
return [filter];
// Filter is either an array of strings, or an array of array of strings
return filter;
return typeof filter === 'string' ? [filter] : filter;
}
/**
* Merge facetFilters, numericFilters and filters together.
* Merge filters, transformedNumericFilters and transformedFacetFilters
* together.
*
* @param {Filter} facetFilters
* @param {Filter} numericFilters
* @param {string} filters
* @param {Filter} transformedNumericFilters
* @param {Filter} transformedFacetFilters
* @returns {Filter}
*/
function mergeFilters(facetFilters, numericFilters, filters) {
var adaptedFilters = filters.trim();
var adaptedFacetFilters = filterToArray(facetFilters);
var adaptedNumericFilters = filterToArray(numericFilters);
var adaptedFilter = __spreadArray(__spreadArray(__spreadArray([], adaptedFacetFilters, true), adaptedNumericFilters, true), [
adaptedFilters,
], false);
var cleanedFilters = adaptedFilter.filter(function (filter) {
if (Array.isArray(filter)) {
return filter.length;
}
return filter;
});
return cleanedFilters;
function mergeFilters(filters, transformedNumericFilters, transformedFacetFilters) {
var adaptedNumericFilters = filterToArray(transformedNumericFilters);
var adaptedFacetFilters = filterToArray(transformedFacetFilters);
var adaptedFilters = [];
if (filters !== undefined) {
adaptedFilters.push(filters);
}
if (adaptedNumericFilters !== undefined) {
adaptedFilters.push.apply(adaptedFilters, adaptedNumericFilters);
}
if (adaptedFacetFilters !== undefined) {
adaptedFilters.push.apply(adaptedFilters, adaptedFacetFilters);
}
return adaptedFilters;
}

@@ -322,5 +332,9 @@ /**

function adaptFilters(filters, numericFilters, facetFilters) {
var transformedFilter = transformFilters(facetFilters || []);
var transformedNumericFilter = transformFilters(numericFilters || []);
return mergeFilters(transformedFilter, transformedNumericFilter, filters || '');
var transformedNumericFilters = numericFilters !== undefined
? transformFilters(transformNumericFilter, numericFilters)
: numericFilters;
var transformedFacetFilters = facetFilters !== undefined
? transformFilters(transformFacetFilter, facetFilters)
: facetFilters;
return mergeFilters(filters, transformedNumericFilters, transformedFacetFilters);
}

@@ -333,6 +347,3 @@

// There must be no filters
if (!placeholderSearch && !query && (!filter || filter.length === 0)) {
return false;
}
return true;
return !(!placeholderSearch && !query && (!filter || filter.length === 0));
}

@@ -374,4 +385,4 @@ function setScrollPagination(pagination, paginationRequired) {

function MeiliParamsCreator(searchContext) {
var meiliSearchParams = {};
var facets = searchContext.facets, attributesToSnippet = searchContext.attributesToSnippet, snippetEllipsisText = searchContext.snippetEllipsisText, attributesToRetrieve = searchContext.attributesToRetrieve, attributesToHighlight = searchContext.attributesToHighlight, highlightPreTag = searchContext.highlightPreTag, highlightPostTag = searchContext.highlightPostTag, placeholderSearch = searchContext.placeholderSearch, query = searchContext.query, sort = searchContext.sort, pagination = searchContext.pagination, matchingStrategy = searchContext.matchingStrategy, filters = searchContext.filters, numericFilters = searchContext.numericFilters, facetFilters = searchContext.facetFilters, indexUid = searchContext.indexUid;
var query = searchContext.query, indexUid = searchContext.indexUid, facets = searchContext.facets, attributesToSnippet = searchContext.attributesToSnippet, snippetEllipsisText = searchContext.snippetEllipsisText, filters = searchContext.filters, numericFilters = searchContext.numericFilters, facetFilters = searchContext.facetFilters, attributesToRetrieve = searchContext.attributesToRetrieve, attributesToHighlight = searchContext.attributesToHighlight, highlightPreTag = searchContext.highlightPreTag, highlightPostTag = searchContext.highlightPostTag, placeholderSearch = searchContext.placeholderSearch, pagination = searchContext.pagination, sort = searchContext.sort, restrictSearchableAttributes = searchContext.restrictSearchableAttributes, overrideParams = searchContext.meiliSearchParams;
var meiliSearchParams = { indexUid: indexUid };
var meilisearchFilters = adaptFilters(filters, numericFilters, facetFilters);

@@ -385,27 +396,28 @@ return {

},
addIndexUid: function () {
meiliSearchParams.indexUid = indexUid;
},
addFacets: function () {
if (Array.isArray(facets)) {
meiliSearchParams.facets = facets;
var value = facets;
if (value !== undefined) {
// despite Instantsearch.js typing it as `string[]`,
// it still can send `string`
meiliSearchParams.facets = typeof value === 'string' ? [value] : value;
}
else if (typeof facets === 'string') {
meiliSearchParams.facets = [facets];
}
},
addAttributesToCrop: function () {
if (attributesToSnippet) {
meiliSearchParams.attributesToCrop = attributesToSnippet;
var _a;
var value = (_a = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.attributesToCrop) !== null && _a !== void 0 ? _a : attributesToSnippet;
if (value !== undefined) {
meiliSearchParams.attributesToCrop = value;
}
},
addCropMarker: function () {
// Attributes To Crop marker
if (snippetEllipsisText != null) {
meiliSearchParams.cropMarker = snippetEllipsisText;
addCropLength: function () {
var value = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.cropLength;
if (value !== undefined) {
meiliSearchParams.cropLength = value;
}
},
addAttributesToRetrieve: function () {
if (attributesToRetrieve) {
meiliSearchParams.attributesToRetrieve = attributesToRetrieve;
addCropMarker: function () {
var _a;
var value = (_a = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.cropMarker) !== null && _a !== void 0 ? _a : snippetEllipsisText;
if (value !== undefined) {
meiliSearchParams.cropMarker = value;
}

@@ -418,20 +430,23 @@ },

},
addAttributesToRetrieve: function () {
var _a;
var value = (_a = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.attributesToRetrieve) !== null && _a !== void 0 ? _a : attributesToRetrieve;
if (value !== undefined) {
meiliSearchParams.attributesToRetrieve = value;
}
},
addAttributesToHighlight: function () {
meiliSearchParams.attributesToHighlight = attributesToHighlight || ['*'];
var _a, _b;
meiliSearchParams.attributesToHighlight =
(_b = (_a = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.attributesToHighlight) !== null && _a !== void 0 ? _a : attributesToHighlight) !== null && _b !== void 0 ? _b : ['*'];
},
addPreTag: function () {
if (highlightPreTag) {
meiliSearchParams.highlightPreTag = highlightPreTag;
}
else {
meiliSearchParams.highlightPreTag = '__ais-highlight__';
}
var _a, _b;
meiliSearchParams.highlightPreTag =
(_b = (_a = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.highlightPreTag) !== null && _a !== void 0 ? _a : highlightPreTag) !== null && _b !== void 0 ? _b : '__ais-highlight__';
},
addPostTag: function () {
if (highlightPostTag) {
meiliSearchParams.highlightPostTag = highlightPostTag;
}
else {
meiliSearchParams.highlightPostTag = '__/ais-highlight__';
}
var _a, _b;
meiliSearchParams.highlightPostTag =
(_b = (_a = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.highlightPostTag) !== null && _a !== void 0 ? _a : highlightPostTag) !== null && _b !== void 0 ? _b : '__/ais-highlight__';
},

@@ -464,4 +479,4 @@ addPagination: function () {

});
if (filter) {
if (meiliSearchParams.filter) {
if (filter !== undefined) {
if (Array.isArray(meiliSearchParams.filter)) {
meiliSearchParams.filter.unshift(filter);

@@ -474,6 +489,27 @@ }

},
addShowMatchesPosition: function () {
var value = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.showMatchesPosition;
if (value !== undefined) {
meiliSearchParams.showMatchesPosition = value;
}
},
addMatchingStrategy: function () {
if (matchingStrategy) {
meiliSearchParams.matchingStrategy = matchingStrategy;
var value = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.matchingStrategy;
if (value !== undefined) {
meiliSearchParams.matchingStrategy = value;
}
},
addShowRankingScore: function () {
var value = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.showRankingScore;
if (value !== undefined) {
meiliSearchParams.showRankingScore = value;
}
},
addAttributesToSearchOn: function () {
var value = (overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.attributesToSearchOn) !== undefined
? overrideParams.attributesToSearchOn
: (restrictSearchableAttributes);
if (value !== undefined) {
meiliSearchParams.attributesToSearchOn = value;
}
}

@@ -492,15 +528,18 @@ };

meilisearchParams.addQuery();
meilisearchParams.addIndexUid();
meilisearchParams.addFacets();
meilisearchParams.addAttributesToCrop();
meilisearchParams.addCropLength();
meilisearchParams.addCropMarker();
meilisearchParams.addFilters();
meilisearchParams.addAttributesToRetrieve();
meilisearchParams.addAttributesToHighlight();
meilisearchParams.addPreTag();
meilisearchParams.addPostTag();
meilisearchParams.addAttributesToRetrieve();
meilisearchParams.addAttributesToCrop();
meilisearchParams.addCropMarker();
meilisearchParams.addPagination();
meilisearchParams.addFilters();
meilisearchParams.addSort();
meilisearchParams.addGeoSearchFilter();
meilisearchParams.addShowMatchesPosition();
meilisearchParams.addMatchingStrategy();
meilisearchParams.addShowRankingScore();
meilisearchParams.addAttributesToSearchOn();
return meilisearchParams.getParams();

@@ -906,3 +945,2 @@ }

meilisearchParams.addFacets();
meilisearchParams.addIndexUid();
meilisearchParams.addPagination();

@@ -951,3 +989,3 @@ return meilisearchParams.getParams();

var PACKAGE_VERSION = '0.13.6';
var PACKAGE_VERSION = '0.14.0';

@@ -962,6 +1000,7 @@ var constructClientAgents = function (clientAgents) {

* Instantiate SearchClient required by instantsearch.js.
*
* @param {string} hostUrl
* @param {string | apiKeyCallback} apiKey
* @param {InstantMeiliSearchOptions={}} meiliSearchOptions
* @returns {InstantMeiliSearchInstance}
* @param {string | ApiKeyCallback} [apiKey='']
* @param {InstantMeiliSearchOptions} [instantMeiliSearchOptions={}]
* @returns {InstantMeiliSearchObject}
*/

@@ -994,90 +1033,99 @@ function instantMeiliSearch(hostUrl, apiKey, instantMeiliSearchOptions) {

return {
clearCache: function () { return searchCache.clearCache(); },
/**
* @param {readonlyAlgoliaMultipleQueriesQuery[]} instantSearchRequests
* @returns {Array}
*/
search: function (instantSearchRequests) {
return __awaiter(this, void 0, void 0, function () {
var meilisearchRequests, instantSearchPagination, initialFacetDistributionsRequests, _i, instantSearchRequests_1, searchRequest, searchContext, meilisearchSearchQuery, defaultSearchQuery, meilisearchResults, instantSearchResponse, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
meilisearchRequests = [];
instantSearchPagination = [];
initialFacetDistributionsRequests = [];
for (_i = 0, instantSearchRequests_1 = instantSearchRequests; _i < instantSearchRequests_1.length; _i++) {
searchRequest = instantSearchRequests_1[_i];
searchContext = createSearchContext(searchRequest, instantMeiliSearchOptions);
meilisearchSearchQuery = adaptSearchParams(searchContext);
meilisearchRequests.push(meilisearchSearchQuery);
defaultSearchQuery = getParametersWithoutFilters(searchContext);
initialFacetDistributionsRequests.push(defaultSearchQuery);
// Keep information about the pagination parameters of instantsearch as
// they are needed to adapt the search response of Meilisearch
instantSearchPagination.push(searchContext.pagination);
}
return [4 /*yield*/, initFacetDistribution(searchResolver, initialFacetDistributionsRequests, initialFacetDistribution)
// Search request to Meilisearch happens here
];
case 1:
initialFacetDistribution = _a.sent();
return [4 /*yield*/, searchResolver.multiSearch(meilisearchRequests, instantSearchPagination // Create issue on pagination
)
setMeiliSearchParams: function (params) {
var meiliSearchParams = instantMeiliSearchOptions.meiliSearchParams;
instantMeiliSearchOptions.meiliSearchParams =
meiliSearchParams === undefined
? params
: __assign(__assign({}, meiliSearchParams), params);
},
searchClient: {
clearCache: function () { return searchCache.clearCache(); },
/**
* @param {readonlyAlgoliaMultipleQueriesQuery[]} instantSearchRequests
* @returns {Array}
*/
search: function (instantSearchRequests) {
return __awaiter(this, void 0, void 0, function () {
var meilisearchRequests, instantSearchPagination, initialFacetDistributionsRequests, _i, instantSearchRequests_1, searchRequest, searchContext, meilisearchSearchQuery, defaultSearchQuery, meilisearchResults, instantSearchResponse, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
meilisearchRequests = [];
instantSearchPagination = [];
initialFacetDistributionsRequests = [];
for (_i = 0, instantSearchRequests_1 = instantSearchRequests; _i < instantSearchRequests_1.length; _i++) {
searchRequest = instantSearchRequests_1[_i];
searchContext = createSearchContext(searchRequest, instantMeiliSearchOptions);
meilisearchSearchQuery = adaptSearchParams(searchContext);
meilisearchRequests.push(meilisearchSearchQuery);
defaultSearchQuery = getParametersWithoutFilters(searchContext);
initialFacetDistributionsRequests.push(defaultSearchQuery);
// Keep information about the pagination parameters of instantsearch as
// they are needed to adapt the search response of Meilisearch
instantSearchPagination.push(searchContext.pagination);
}
return [4 /*yield*/, initFacetDistribution(searchResolver, initialFacetDistributionsRequests, initialFacetDistribution)
// Search request to Meilisearch happens here
];
case 1:
initialFacetDistribution = _a.sent();
return [4 /*yield*/, searchResolver.multiSearch(meilisearchRequests, instantSearchPagination // Create issue on pagination
)
// Fill the missing facet values if keepZeroFacets is true
];
case 2:
meilisearchResults = _a.sent();
// Fill the missing facet values if keepZeroFacets is true
];
case 2:
meilisearchResults = _a.sent();
// Fill the missing facet values if keepZeroFacets is true
initialFacetDistribution = fillMissingFacets(initialFacetDistribution, meilisearchResults);
instantSearchResponse = adaptSearchResults(meilisearchResults, initialFacetDistribution, instantMeilisearchConfig);
return [2 /*return*/, instantSearchResponse];
case 3:
e_1 = _a.sent();
console.error(e_1);
throw new Error(e_1);
case 4: return [2 /*return*/];
}
initialFacetDistribution = fillMissingFacets(initialFacetDistribution, meilisearchResults);
instantSearchResponse = adaptSearchResults(meilisearchResults, initialFacetDistribution, instantMeilisearchConfig);
return [2 /*return*/, instantSearchResponse];
case 3:
e_1 = _a.sent();
console.error(e_1);
throw new Error(e_1);
case 4: return [2 /*return*/];
}
});
});
});
},
searchForFacetValues: function (requests) {
return __awaiter(this, void 0, void 0, function () {
var results, _i, requests_1, request, searchContext, meilisearchSearchQuery, meilisearchRequest, meilisearchResponse, facetHits, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
results = [];
_i = 0, requests_1 = requests;
_a.label = 1;
case 1:
if (!(_i < requests_1.length)) return [3 /*break*/, 4];
request = requests_1[_i];
searchContext = createFacetSearchContext(request, instantMeiliSearchOptions);
meilisearchSearchQuery = adaptSearchParams(searchContext);
meilisearchRequest = __assign(__assign({}, meilisearchSearchQuery), { facetQuery: request.params.facetQuery, facetName: request.params.facetName });
delete meilisearchRequest.indexUid;
return [4 /*yield*/, meilisearchClient
.index(searchContext.indexUid)
.searchForFacetValues(meilisearchRequest)];
case 2:
meilisearchResponse = _a.sent();
facetHits = meilisearchResponse.facetHits.map(function (facetHit) { return (__assign(__assign({}, facetHit), {
// not currently supported
highlighted: facetHit.value })); });
result = {
facetHits: facetHits,
exhaustiveFacetsCount: false,
processingTimeMS: meilisearchResponse.processingTimeMs
};
results.push(result);
_a.label = 3;
case 3:
_i++;
return [3 /*break*/, 1];
case 4: return [2 /*return*/, results];
}
},
searchForFacetValues: function (requests) {
return __awaiter(this, void 0, void 0, function () {
var results, _i, requests_1, request, searchContext, meilisearchSearchQuery, meilisearchRequest, meilisearchResponse, facetHits, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
results = [];
_i = 0, requests_1 = requests;
_a.label = 1;
case 1:
if (!(_i < requests_1.length)) return [3 /*break*/, 4];
request = requests_1[_i];
searchContext = createFacetSearchContext(request, instantMeiliSearchOptions);
meilisearchSearchQuery = adaptSearchParams(searchContext);
meilisearchRequest = __assign(__assign({}, meilisearchSearchQuery), { facetQuery: request.params.facetQuery, facetName: request.params.facetName });
delete meilisearchRequest.indexUid;
return [4 /*yield*/, meilisearchClient
.index(searchContext.indexUid)
.searchForFacetValues(meilisearchRequest)];
case 2:
meilisearchResponse = _a.sent();
facetHits = meilisearchResponse.facetHits.map(function (facetHit) { return (__assign(__assign({}, facetHit), {
// not currently supported
highlighted: facetHit.value })); });
result = {
facetHits: facetHits,
exhaustiveFacetsCount: false,
processingTimeMS: meilisearchResponse.processingTimeMs
};
results.push(result);
_a.label = 3;
case 3:
_i++;
return [3 /*break*/, 1];
case 4: return [2 /*return*/, results];
}
});
});
});
}
}

@@ -1087,8 +1135,2 @@ };

exports.MatchingStrategies = void 0;
(function (MatchingStrategies) {
MatchingStrategies["ALL"] = "all";
MatchingStrategies["LAST"] = "last";
})(exports.MatchingStrategies || (exports.MatchingStrategies = {}));
exports.instantMeiliSearch = instantMeiliSearch;

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("meilisearch"),e=function(){return e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},e.apply(this,arguments)};function r(t,e,r,n){return new(r||(r=Promise))((function(i,a){function o(t){try{s(n.next(t))}catch(t){a(t)}}function u(t){try{s(n.throw(t))}catch(t){a(t)}}function s(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,u)}s((n=n.apply(t,e||[])).next())}))}function n(t,e){var r,n,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(u){return function(s){return function(u){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(o=0)),o;)try{if(r=1,n&&(i=2&u[0]?n.return:u[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,u[1])).done)return i;switch(n=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,n=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(6===u[0]&&o.label<i[1]){o.label=i[1],i=u;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(u);break}i[2]&&o.ops.pop(),o.trys.pop();continue}u=e.call(t,o)}catch(t){u=[6,t],n=0}finally{r=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}function i(t,e,r){if(r||2===arguments.length)for(var n,i=0,a=e.length;i<a;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}function a(t){return"object"==typeof t&&!Array.isArray(t)&&null!==t}function o(t){return t.replace(/(.*):(.*)/i,'"$1"="$2"')}function u(t){return"string"==typeof t?o(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return o(t)})).filter((function(t){return t})):o(t)})).filter((function(t){return t})):[]}function s(t){return""===t?[]:"string"==typeof t?[t]:t}function c(t,e,r){return function(t,e,r){var n=r.trim(),a=s(t),o=s(e);return i(i(i([],a,!0),o,!0),[n],!1).filter((function(t){return Array.isArray(t)?t.length:t}))}(u(r||[]),u(e||[]),t||"")}function l(t){var e={},r=t.facets,n=t.attributesToSnippet,i=t.snippetEllipsisText,a=t.attributesToRetrieve,o=t.attributesToHighlight,u=t.highlightPreTag,s=t.highlightPostTag,l=t.placeholderSearch,f=t.query,d=t.sort,g=t.pagination,h=t.matchingStrategy,p=t.filters,v=t.numericFilters,y=t.facetFilters,m=t.indexUid,b=c(p,v,y);return{getParams:function(){return e},addQuery:function(){e.q=f},addIndexUid:function(){e.indexUid=m},addFacets:function(){Array.isArray(r)?e.facets=r:"string"==typeof r&&(e.facets=[r])},addAttributesToCrop:function(){n&&(e.attributesToCrop=n)},addCropMarker:function(){null!=i&&(e.cropMarker=i)},addAttributesToRetrieve:function(){a&&(e.attributesToRetrieve=a)},addFilters:function(){b.length&&(e.filter=b)},addAttributesToHighlight:function(){e.attributesToHighlight=o||["*"]},addPreTag:function(){e.highlightPreTag=u||"__ais-highlight__"},addPostTag:function(){e.highlightPostTag=s||"__/ais-highlight__"},addPagination:function(){var t=function(t,e,r){return!!(r||e||t&&0!==t.length)}(b,f,l);if(g.finite){var r=function(t,e){var r=t.page,n=t.hitsPerPage;return e?{hitsPerPage:n,page:r+1}:{hitsPerPage:0,page:r+1}}(g,t),n=r.hitsPerPage,i=r.page;e.hitsPerPage=n,e.page=i}else{var a=function(t,e){var r=t.page,n=t.hitsPerPage;return e?{limit:n+1,offset:r*n}:{limit:0,offset:0}}(g,t),o=a.limit,u=a.offset;e.limit=o,e.offset=u}},addSort:function(){(null==d?void 0:d.length)&&(e.sort=Array.isArray(d)?d:[d])},addGeoSearchFilter:function(){var r=function(t){var e,r,n,i=t.insideBoundingBox,a=t.aroundLatLng,o=t.aroundRadius,u=t.minimumAroundRadius;if(a){var s=a.split(",").map((function(t){return Number.parseFloat(t).toFixed(5)}));e=[h=s[0],p=s[1]]}if(null==o&&null==u||("all"===o?console.warn("instant-meilisearch is not compatible with the `all` value on the aroundRadius parameter"):r=null!=o?o:u),i&&"string"==typeof i){var c=i.split(",").map((function(t){return parseFloat(t)})),l=c[0],f=c[1],d=c[2],g=c[3];n="_geoBoundingBox([".concat(l,", ").concat(f,"], [").concat(d,", ").concat(g,"])")}else if(null!=e&&null!=r){var h=e[0],p=e[1];n="_geoRadius(".concat(h,", ").concat(p,", ").concat(r,")")}return n}({insideBoundingBox:t.insideBoundingBox,aroundLatLng:t.aroundLatLng,aroundRadius:t.aroundRadius,minimumAroundRadius:t.minimumAroundRadius});r&&(e.filter?e.filter.unshift(r):e.filter=[r])},addMatchingStrategy:function(){h&&(e.matchingStrategy=h)}}}function f(t){var e=l(t);return e.addQuery(),e.addIndexUid(),e.addFacets(),e.addAttributesToHighlight(),e.addPreTag(),e.addPostTag(),e.addAttributesToRetrieve(),e.addAttributesToCrop(),e.addCropMarker(),e.addPagination(),e.addFilters(),e.addSort(),e.addGeoSearchFilter(),e.addMatchingStrategy(),e.getParams()}function d(t){return"string"==typeof t?t:void 0===t?JSON.stringify(null):JSON.stringify(t)}function g(t){return Array.isArray(t)?t.map((function(t){return g(t)})):a(t)?Object.keys(t).reduce((function(e,r){return e[r]=g(t[r]),e}),{}):{value:d(t)}}function h(t){if(!t)return{};var e=g(t);return{_highlightResult:e,_snippetResult:e}}function p(t,e){var r=t.hits,n=t.pagination.hitsPerPage,i=e.finitePagination,a=e.primaryKey;!i&&r.length>n&&r.splice(r.length-1,1);var o=r.map((function(t){if(Object.keys(t).length>0){var e=t._formatted;t._matchesPosition;var r=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r}(t,["_formatted","_matchesPosition"]),n=Object.assign(r,h(e));return a&&(n.objectID=t[a]),n}return t}));return o=function(t){for(var e,r=0;r<t.length;r++){var n="".concat(r+1e6*Math.random());t[r]._geo&&(t[r]._geoloc=t[r]._geo,t[r].objectID=n),(null===(e=t[r]._formatted)||void 0===e?void 0:e._geo)&&(t[r]._formatted._geoloc=t[r]._formatted._geo,t[r]._formatted.objectID=n)}return t}(o),o}function v(t){return Object.keys(t).reduce((function(r,n){return r[n]=e(e({},t[n]),{avg:0,sum:0}),r}),{})}function y(t,e,r){var n=t.map((function(t){return function(t,e,r){var n=t.processingTimeMs,i=t.query,a=t.indexUid,o=t.facetDistribution,u=void 0===o?{}:o,s=t.facetStats,c=void 0===s?{}:s,l=Object.keys(u),f=function(t,e){var r=e.hitsPerPage,n=e.page,i=function(t,e){if(null!=t.totalPages)return t.totalPages;if(0===e)return 0;var r=t.limit,n=void 0===r?20:r,i=t.offset;return(void 0===i?0:i)/e+1+(t.hits.length>=n?1:0)}(t,r);return{page:n,nbPages:i,hitsPerPage:r}}(t,t.pagination),d=f.hitsPerPage,g=f.page,h=f.nbPages,y=p(t,r),m=function(t){var e=t.hitsPerPage,r=void 0===e?0:e,n=t.totalPages,i=void 0===n?0:n,a=t.estimatedTotalHits,o=t.totalHits;return null!=a?a:null!=o?o:r*i}(t),b=function(t,e,r,n){return t?function(t,e,r){for(var n=function(t){return t?"string"==typeof t?[t]:t:[]}(t),i={},a=0,o=n;a<o.length;a++){var u=o[a];for(var s in e[u])i[u]||(i[u]=r[u]||{}),i[u][s]?i[u][s]=r[u][s]:i[u][s]=0}return i}(e,r,n=n||{}):n}(r.keepZeroFacets,l,e,u);return{index:a,hitsPerPage:d,page:g,facets:b,nbPages:h,nbHits:m,processingTimeMS:n,query:i,hits:y,params:"",exhaustiveNbHits:!1,facets_stats:v(c)}}(t,e[t.indexUid],r)}));return{results:n}}function m(t){return t?t.split(/,(?=\w+:(?:asc|desc))/):[]}function b(t,e,r){return{hitsPerPage:void 0===e?20:e,page:r||0,finite:!!t}}function P(t){var e=t.indexOf(":");return-1===e?{indexUid:t,sortBy:""}:{indexUid:t.substring(0,e),sortBy:t.substring(e+1)}}function x(t,r){var n=t.query,i=t.indexName,a=t.params,o=P(i),u=o.indexUid,s=o.sortBy,c=b(r.finitePagination,null==a?void 0:a.hitsPerPage,null==a?void 0:a.page);return e(e(e(e({},r),{query:n}),a),{sort:m(s),indexUid:u,pagination:c,placeholderSearch:!1!==r.placeholderSearch,keepZeroFacets:!!r.keepZeroFacets})}function S(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(t){return}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,r){e[t]=JSON.stringify(r)},clearCache:function(){e={}}}}function w(t){var r=l(e(e({},t),{placeholderSearch:!0,query:""}));return r.addFacets(),r.addIndexUid(),r.addPagination(),r.getParams()}function T(t,e,i){return r(this,void 0,void 0,(function(){var r,a,o,u,s,c;return n(this,(function(n){switch(n.label){case 0:return l="indexUid",f=[],r=function(t){return!f.includes(t[l])&&(f.push(t[l]),!0)},a=e.filter(r).filter((function(t){var e=t.indexUid;return!Object.keys(i).includes(e)})),0===a.length?[2,i]:[4,t.multiSearch(a,[])];case 1:for(o=n.sent(),u=0,s=o;u<s.length;u++)c=s[u],i[c.indexUid]=c.facetDistribution||{};return[2,i]}var l,f}))}))}"function"==typeof SuppressedError&&SuppressedError;var A;exports.MatchingStrategies=void 0,(A=exports.MatchingStrategies||(exports.MatchingStrategies={})).ALL="all",A.LAST="last",exports.instantMeiliSearch=function(i,o,u){void 0===o&&(o=""),void 0===u&&(u={}),function(t,e,r){var n=r.requestConfig,i=r.httpClient;if("string"!=typeof t)throw new TypeError("Provided hostUrl value (1st parameter) is not a string, expected string");if("string"!=typeof e&&"function"!=typeof e)throw new TypeError("Provided apiKey value (2nd parameter) is not a string or a function, expected string or function");if(void 0!==n&&!a(n))throw new TypeError("Provided requestConfig should be an object");if(i&&"function"!=typeof i)throw new TypeError("Provided custom httpClient should be a function")}(i,o,u);var s={host:i,apiKey:o=function(t){if("function"==typeof t){var e=t();if("string"!=typeof e)throw new TypeError("Provided apiKey function (2nd parameter) did not return a string, expected string");return e}return t}(o),clientAgents:function(t){void 0===t&&(t=[]);var e="Meilisearch instant-meilisearch (v".concat("0.13.6",")");return t.concat(e)}(u.clientAgents)};void 0!==u.httpClient&&(s.httpClient=u.httpClient),void 0!==u.requestConfig&&(s.requestConfig=u.requestConfig);var c,l,d,g=new t.MeiliSearch(s),h=S(),p=(c=g,l=h,{multiSearch:function(t,i){return r(this,void 0,void 0,(function(){var r,a,o,u;return n(this,(function(n){switch(n.label){case 0:return r=l.formatKey([t]),(a=l.getEntry(r))?[2,a]:[4,c.multiSearch({queries:t})];case 1:return o=n.sent(),u=o.results.map((function(t,r){return e(e({},t),{pagination:i[r]||{}})})),l.setEntry(r,u),[2,u]}}))}))}}),v={},A=(d=u,e(e({},{placeholderSearch:!0,keepZeroFacets:!1,clientAgents:[],finitePagination:!1}),d));return{clearCache:function(){return h.clearCache()},search:function(t){return r(this,void 0,void 0,(function(){var r,i,a,o,s,c,l,d,g,h,m;return n(this,(function(n){switch(n.label){case 0:for(n.trys.push([0,3,,4]),r=[],i=[],a=[],o=0,s=t;o<s.length;o++)c=s[o],l=x(c,u),d=f(l),r.push(d),g=w(l),a.push(g),i.push(l.pagination);return[4,T(p,a,v)];case 1:return v=n.sent(),[4,p.multiSearch(r,i)];case 2:return h=n.sent(),v=function(t,r){for(var n=0,i=r;n<i.length;n++){var a=i[n];t[a.indexUid]=e(e({},a.facetDistribution||{}),t[a.indexUid]||{})}return t}(v,h),[2,y(h,v,A)];case 3:throw m=n.sent(),console.error(m),new Error(m);case 4:return[2]}}))}))},searchForFacetValues:function(t){return r(this,void 0,void 0,(function(){var r,i,a,o,s,c,l,d,h,p;return n(this,(function(n){switch(n.label){case 0:r=[],i=0,a=t,n.label=1;case 1:return i<a.length?(o=a[i],s=function(t,r){var n=P(t.indexName),i=n.indexUid,a=n.sortBy,o=t.params,u=b(r.finitePagination,null==o?void 0:o.hitsPerPage,null==o?void 0:o.page);return e(e(e({},r),o),{sort:m(a),indexUid:i,pagination:u,placeholderSearch:!1!==r.placeholderSearch,keepZeroFacets:!!r.keepZeroFacets})}(o,u),c=f(s),delete(l=e(e({},c),{facetQuery:o.params.facetQuery,facetName:o.params.facetName})).indexUid,[4,g.index(s.indexUid).searchForFacetValues(l)]):[3,4];case 2:d=n.sent(),h=d.facetHits.map((function(t){return e(e({},t),{highlighted:t.value})})),p={facetHits:h,exhaustiveFacetsCount:!1,processingTimeMS:d.processingTimeMs},r.push(p),n.label=3;case 3:return i++,[3,1];case 4:return[2,r]}}))}))}}};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("meilisearch"),e=function(){return e=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},e.apply(this,arguments)};function n(t,e,n,r){return new(n||(n=Promise))((function(i,a){function o(t){try{c(r.next(t))}catch(t){a(t)}}function u(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,u)}c((r=r.apply(t,e||[])).next())}))}function r(t,e){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(u){return function(c){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&u[0]?r.return:u[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,u[1])).done)return i;switch(r=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(6===u[0]&&o.label<i[1]){o.label=i[1],i=u;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(u);break}i[2]&&o.ops.pop(),o.trys.pop();continue}u=e.call(t,o)}catch(t){u=[6,t],r=0}finally{n=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}}function i(t){return"object"==typeof t&&!Array.isArray(t)&&null!==t}"function"==typeof SuppressedError&&SuppressedError;var a=/([\\"])/g;function o(t){return t.replace(a,"\\$1")}function u(t){var e=o(t),n=e.indexOf(":"),r=e.slice(0,n),i=e.slice(n+1);return'"'.concat(r,'"="').concat(i,'"')}var c=/(?<!(?:[<!>]?=|<|>|:).*)([<!>]?=|<|>|:)/;function s(t){var e=t.split(c),n=e[0],r=e[1],i=e[2],a=o(n);return'"'.concat(a.trim(),'"').concat(":"===r?" ":r).concat(i.trim())}function l(t,e){return"string"==typeof e?t(e):e.map((function(e){return"string"==typeof e?t(e):e.map((function(e){return t(e)}))}))}function d(t){return"string"==typeof t?[t]:t}function f(t,e,n){return function(t,e,n){var r=d(e),i=d(n),a=[];return void 0!==t&&a.push(t),void 0!==r&&a.push.apply(a,r),void 0!==i&&a.push.apply(a,i),a}(t,void 0!==e?l(s,e):e,void 0!==n?l(u,n):n)}function h(t){var e=t.query,n=t.indexUid,r=t.facets,i=t.attributesToSnippet,a=t.snippetEllipsisText,o=t.filters,u=t.numericFilters,c=t.facetFilters,s=t.attributesToRetrieve,l=t.attributesToHighlight,d=t.highlightPreTag,h=t.highlightPostTag,g=t.placeholderSearch,p=t.pagination,v=t.sort,y=t.restrictSearchableAttributes,m=t.meiliSearchParams,b={indexUid:n},P=f(o,u,c);return{getParams:function(){return b},addQuery:function(){b.q=e},addFacets:function(){var t=r;void 0!==t&&(b.facets="string"==typeof t?[t]:t)},addAttributesToCrop:function(){var t,e=null!==(t=null==m?void 0:m.attributesToCrop)&&void 0!==t?t:i;void 0!==e&&(b.attributesToCrop=e)},addCropLength:function(){var t=null==m?void 0:m.cropLength;void 0!==t&&(b.cropLength=t)},addCropMarker:function(){var t,e=null!==(t=null==m?void 0:m.cropMarker)&&void 0!==t?t:a;void 0!==e&&(b.cropMarker=e)},addFilters:function(){P.length&&(b.filter=P)},addAttributesToRetrieve:function(){var t,e=null!==(t=null==m?void 0:m.attributesToRetrieve)&&void 0!==t?t:s;void 0!==e&&(b.attributesToRetrieve=e)},addAttributesToHighlight:function(){var t,e;b.attributesToHighlight=null!==(e=null!==(t=null==m?void 0:m.attributesToHighlight)&&void 0!==t?t:l)&&void 0!==e?e:["*"]},addPreTag:function(){var t,e;b.highlightPreTag=null!==(e=null!==(t=null==m?void 0:m.highlightPreTag)&&void 0!==t?t:d)&&void 0!==e?e:"__ais-highlight__"},addPostTag:function(){var t,e;b.highlightPostTag=null!==(e=null!==(t=null==m?void 0:m.highlightPostTag)&&void 0!==t?t:h)&&void 0!==e?e:"__/ais-highlight__"},addPagination:function(){var t=function(t,e,n){return!!(n||e||t&&0!==t.length)}(P,e,g);if(p.finite){var n=function(t,e){var n=t.page,r=t.hitsPerPage;return e?{hitsPerPage:r,page:n+1}:{hitsPerPage:0,page:n+1}}(p,t),r=n.hitsPerPage,i=n.page;b.hitsPerPage=r,b.page=i}else{var a=function(t,e){var n=t.page,r=t.hitsPerPage;return e?{limit:r+1,offset:n*r}:{limit:0,offset:0}}(p,t),o=a.limit,u=a.offset;b.limit=o,b.offset=u}},addSort:function(){(null==v?void 0:v.length)&&(b.sort=Array.isArray(v)?v:[v])},addGeoSearchFilter:function(){var e=function(t){var e,n,r,i=t.insideBoundingBox,a=t.aroundLatLng,o=t.aroundRadius,u=t.minimumAroundRadius;if(a){var c=a.split(",").map((function(t){return Number.parseFloat(t).toFixed(5)}));e=[g=c[0],p=c[1]]}if(null==o&&null==u||("all"===o?console.warn("instant-meilisearch is not compatible with the `all` value on the aroundRadius parameter"):n=null!=o?o:u),i&&"string"==typeof i){var s=i.split(",").map((function(t){return parseFloat(t)})),l=s[0],d=s[1],f=s[2],h=s[3];r="_geoBoundingBox([".concat(l,", ").concat(d,"], [").concat(f,", ").concat(h,"])")}else if(null!=e&&null!=n){var g=e[0],p=e[1];r="_geoRadius(".concat(g,", ").concat(p,", ").concat(n,")")}return r}({insideBoundingBox:t.insideBoundingBox,aroundLatLng:t.aroundLatLng,aroundRadius:t.aroundRadius,minimumAroundRadius:t.minimumAroundRadius});void 0!==e&&(Array.isArray(b.filter)?b.filter.unshift(e):b.filter=[e])},addShowMatchesPosition:function(){var t=null==m?void 0:m.showMatchesPosition;void 0!==t&&(b.showMatchesPosition=t)},addMatchingStrategy:function(){var t=null==m?void 0:m.matchingStrategy;void 0!==t&&(b.matchingStrategy=t)},addShowRankingScore:function(){var t=null==m?void 0:m.showRankingScore;void 0!==t&&(b.showRankingScore=t)},addAttributesToSearchOn:function(){var t=void 0!==(null==m?void 0:m.attributesToSearchOn)?m.attributesToSearchOn:y;void 0!==t&&(b.attributesToSearchOn=t)}}}function g(t){var e=h(t);return e.addQuery(),e.addFacets(),e.addAttributesToCrop(),e.addCropLength(),e.addCropMarker(),e.addFilters(),e.addAttributesToRetrieve(),e.addAttributesToHighlight(),e.addPreTag(),e.addPostTag(),e.addPagination(),e.addSort(),e.addGeoSearchFilter(),e.addShowMatchesPosition(),e.addMatchingStrategy(),e.addShowRankingScore(),e.addAttributesToSearchOn(),e.getParams()}function p(t){return"string"==typeof t?t:void 0===t?JSON.stringify(null):JSON.stringify(t)}function v(t){return Array.isArray(t)?t.map((function(t){return v(t)})):i(t)?Object.keys(t).reduce((function(e,n){return e[n]=v(t[n]),e}),{}):{value:p(t)}}function y(t){if(!t)return{};var e=v(t);return{_highlightResult:e,_snippetResult:e}}function m(t,e){var n=t.hits,r=t.pagination.hitsPerPage,i=e.finitePagination,a=e.primaryKey;!i&&n.length>r&&n.splice(n.length-1,1);var o=n.map((function(t){if(Object.keys(t).length>0){var e=t._formatted;t._matchesPosition;var n=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(t,["_formatted","_matchesPosition"]),r=Object.assign(n,y(e));return a&&(r.objectID=t[a]),r}return t}));return o=function(t){for(var e,n=0;n<t.length;n++){var r="".concat(n+1e6*Math.random());t[n]._geo&&(t[n]._geoloc=t[n]._geo,t[n].objectID=r),(null===(e=t[n]._formatted)||void 0===e?void 0:e._geo)&&(t[n]._formatted._geoloc=t[n]._formatted._geo,t[n]._formatted.objectID=r)}return t}(o),o}function b(t){return Object.keys(t).reduce((function(n,r){return n[r]=e(e({},t[r]),{avg:0,sum:0}),n}),{})}function P(t,e,n){var r=t.map((function(t){return function(t,e,n){var r=t.processingTimeMs,i=t.query,a=t.indexUid,o=t.facetDistribution,u=void 0===o?{}:o,c=t.facetStats,s=void 0===c?{}:c,l=Object.keys(u),d=function(t,e){var n=e.hitsPerPage,r=e.page,i=function(t,e){if(null!=t.totalPages)return t.totalPages;if(0===e)return 0;var n=t.limit,r=void 0===n?20:n,i=t.offset;return(void 0===i?0:i)/e+1+(t.hits.length>=r?1:0)}(t,n);return{page:r,nbPages:i,hitsPerPage:n}}(t,t.pagination),f=d.hitsPerPage,h=d.page,g=d.nbPages,p=m(t,n),v=function(t){var e=t.hitsPerPage,n=void 0===e?0:e,r=t.totalPages,i=void 0===r?0:r,a=t.estimatedTotalHits,o=t.totalHits;return null!=a?a:null!=o?o:n*i}(t),y=function(t,e,n,r){return t?function(t,e,n){for(var r=function(t){return t?"string"==typeof t?[t]:t:[]}(t),i={},a=0,o=r;a<o.length;a++){var u=o[a];for(var c in e[u])i[u]||(i[u]=n[u]||{}),i[u][c]?i[u][c]=n[u][c]:i[u][c]=0}return i}(e,n,r=r||{}):r}(n.keepZeroFacets,l,e,u);return{index:a,hitsPerPage:f,page:h,facets:y,nbPages:g,nbHits:v,processingTimeMS:r,query:i,hits:p,params:"",exhaustiveNbHits:!1,facets_stats:b(s)}}(t,e[t.indexUid],n)}));return{results:r}}function S(t){return t?t.split(/,(?=\w+:(?:asc|desc))/):[]}function x(t,e,n){return{hitsPerPage:void 0===e?20:e,page:n||0,finite:!!t}}function w(t){var e=t.indexOf(":");return-1===e?{indexUid:t,sortBy:""}:{indexUid:t.substring(0,e),sortBy:t.substring(e+1)}}function T(t,n){var r=t.query,i=t.indexName,a=t.params,o=w(i),u=o.indexUid,c=o.sortBy,s=x(n.finitePagination,null==a?void 0:a.hitsPerPage,null==a?void 0:a.page);return e(e(e(e({},n),{query:r}),a),{sort:S(c),indexUid:u,pagination:s,placeholderSearch:!1!==n.placeholderSearch,keepZeroFacets:!!n.keepZeroFacets})}function O(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(t){return}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,n){e[t]=JSON.stringify(n)},clearCache:function(){e={}}}}function _(t){var n=h(e(e({},t),{placeholderSearch:!0,query:""}));return n.addFacets(),n.addPagination(),n.getParams()}function k(t,e,i){return n(this,void 0,void 0,(function(){var n,a,o,u,c,s;return r(this,(function(r){switch(r.label){case 0:return l="indexUid",d=[],n=function(t){return!d.includes(t[l])&&(d.push(t[l]),!0)},a=e.filter(n).filter((function(t){var e=t.indexUid;return!Object.keys(i).includes(e)})),0===a.length?[2,i]:[4,t.multiSearch(a,[])];case 1:for(o=r.sent(),u=0,c=o;u<c.length;u++)s=c[u],i[s.indexUid]=s.facetDistribution||{};return[2,i]}var l,d}))}))}exports.instantMeiliSearch=function(a,o,u){void 0===o&&(o=""),void 0===u&&(u={}),function(t,e,n){var r=n.requestConfig,a=n.httpClient;if("string"!=typeof t)throw new TypeError("Provided hostUrl value (1st parameter) is not a string, expected string");if("string"!=typeof e&&"function"!=typeof e)throw new TypeError("Provided apiKey value (2nd parameter) is not a string or a function, expected string or function");if(void 0!==r&&!i(r))throw new TypeError("Provided requestConfig should be an object");if(a&&"function"!=typeof a)throw new TypeError("Provided custom httpClient should be a function")}(a,o,u);var c={host:a,apiKey:o=function(t){if("function"==typeof t){var e=t();if("string"!=typeof e)throw new TypeError("Provided apiKey function (2nd parameter) did not return a string, expected string");return e}return t}(o),clientAgents:function(t){void 0===t&&(t=[]);var e="Meilisearch instant-meilisearch (v".concat("0.14.0",")");return t.concat(e)}(u.clientAgents)};void 0!==u.httpClient&&(c.httpClient=u.httpClient),void 0!==u.requestConfig&&(c.requestConfig=u.requestConfig);var s,l,d,f=new t.MeiliSearch(c),h=O(),p=(s=f,l=h,{multiSearch:function(t,i){return n(this,void 0,void 0,(function(){var n,a,o,u;return r(this,(function(r){switch(r.label){case 0:return n=l.formatKey([t]),(a=l.getEntry(n))?[2,a]:[4,s.multiSearch({queries:t})];case 1:return o=r.sent(),u=o.results.map((function(t,n){return e(e({},t),{pagination:i[n]||{}})})),l.setEntry(n,u),[2,u]}}))}))}}),v={},y=(d=u,e(e({},{placeholderSearch:!0,keepZeroFacets:!1,clientAgents:[],finitePagination:!1}),d));return{setMeiliSearchParams:function(t){var n=u.meiliSearchParams;u.meiliSearchParams=void 0===n?t:e(e({},n),t)},searchClient:{clearCache:function(){return h.clearCache()},search:function(t){return n(this,void 0,void 0,(function(){var n,i,a,o,c,s,l,d,f,h,m;return r(this,(function(r){switch(r.label){case 0:for(r.trys.push([0,3,,4]),n=[],i=[],a=[],o=0,c=t;o<c.length;o++)s=c[o],l=T(s,u),d=g(l),n.push(d),f=_(l),a.push(f),i.push(l.pagination);return[4,k(p,a,v)];case 1:return v=r.sent(),[4,p.multiSearch(n,i)];case 2:return h=r.sent(),v=function(t,n){for(var r=0,i=n;r<i.length;r++){var a=i[r];t[a.indexUid]=e(e({},a.facetDistribution||{}),t[a.indexUid]||{})}return t}(v,h),[2,P(h,v,y)];case 3:throw m=r.sent(),console.error(m),new Error(m);case 4:return[2]}}))}))},searchForFacetValues:function(t){return n(this,void 0,void 0,(function(){var n,i,a,o,c,s,l,d,h,p;return r(this,(function(r){switch(r.label){case 0:n=[],i=0,a=t,r.label=1;case 1:return i<a.length?(o=a[i],c=function(t,n){var r=w(t.indexName),i=r.indexUid,a=r.sortBy,o=t.params,u=x(n.finitePagination,null==o?void 0:o.hitsPerPage,null==o?void 0:o.page);return e(e(e({},n),o),{sort:S(a),indexUid:i,pagination:u,placeholderSearch:!1!==n.placeholderSearch,keepZeroFacets:!!n.keepZeroFacets})}(o,u),s=g(c),delete(l=e(e({},s),{facetQuery:o.params.facetQuery,facetName:o.params.facetName})).indexUid,[4,f.index(c.indexUid).searchForFacetValues(l)]):[3,4];case 2:d=r.sent(),h=d.facetHits.map((function(t){return e(e({},t),{highlighted:t.value})})),p={facetHits:h,exhaustiveFacetsCount:!1,processingTimeMS:d.processingTimeMs},n.push(p),r.label=3;case 3:return i++,[3,1];case 4:return[2,n]}}))}))}}}};
//# sourceMappingURL=instant-meilisearch.cjs.min.js.map

@@ -79,12 +79,2 @@ import { MeiliSearch } from 'meilisearch';

function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {

@@ -116,3 +106,3 @@ var e = new Error(message);

* Resolves apiKey if it is a function
* @param {string | apiKeyCallback} apiKey
* @param {string | ApiKeyCallback} apiKey
* @returns {string} api key value

@@ -225,4 +215,9 @@ */

var filterEscapeRegExp = /([\\"])/g;
function getValueWithEscapedBackslashesAndQuotes(value) {
return value.replace(filterEscapeRegExp, '\\$1');
}
/**
* Transform InstantSearch filter to Meilisearch compatible filter format.
* Transform InstantSearch [facet filter](https://www.algolia.com/doc/api-reference/api-parameters/facetFilters/)
* to Meilisearch compatible filter format.
* Change sign from `:` to `=`

@@ -232,36 +227,56 @@ * "facet:facetValue" becomes "facet=facetValue"

* Wrap both the facet and its facet value between quotes.
* This avoid formating issues on facets containing multiple words.
* This avoids formatting issues on facets containing multiple words.
* Escape backslash \\ and quote " characters.
*
* 'My facet:My facet value' becomes '"My facet":"My facet value"'
*
* @param {string} filter?
* @returns {Filter}
* @param {string} filter
* @returns {string}
*/
function transformFilter(filter) {
return filter.replace(/(.*):(.*)/i, '"$1"="$2"');
function transformFacetFilter(filter) {
var escapedFilter = getValueWithEscapedBackslashesAndQuotes(filter);
var colonIndex = escapedFilter.indexOf(':');
var attribute = escapedFilter.slice(0, colonIndex);
var value = escapedFilter.slice(colonIndex + 1);
return "\"".concat(attribute, "\"=\"").concat(value, "\"");
}
// Matches first occurrence of an operator
var numericSplitRegExp = /(?<!(?:[<!>]?=|<|>|:).*)([<!>]?=|<|>|:)/;
/**
* Itterate over all filters.
* Transform InstantSearch [numeric filter](https://www.algolia.com/doc/api-reference/api-parameters/numericFilters/)
* to Meilisearch compatible filter format.
*
* 'price:5.99 TO 100' becomes '"price" 5.99 TO 100'
*
* 'price = 5.99' becomes '"price"=5.99'
*
* Wrap the attribute between quotes.
* Escape backslash (\\) and quote (") characters.
*
* @param {string} filter
* @returns {string}
*/
function transformNumericFilter(filter) {
// TODO: Warn users to not enable facet values escape for negative numbers.
// https://github.com/algolia/instantsearch/blob/da701529ed325bb7a1d782e80cb994711e20d94a/packages/instantsearch.js/src/lib/utils/escapeFacetValue.ts#L13-L21
var _a = filter.split(numericSplitRegExp), attribute = _a[0], operator = _a[1], value = _a[2];
var escapedAttribute = getValueWithEscapedBackslashesAndQuotes(attribute);
return "\"".concat(escapedAttribute.trim(), "\"").concat(operator === ':' ? ' ' : operator).concat(value.trim());
}
/**
* Iterate over all filters.
* Return the filters in a Meilisearch compatible format.
*
* @param {SearchContext['facetFilters']} filters?
* @param {(filter: string) => string} transformCallback
* @param {SearchContext['facetFilters']} filters
* @returns {Filter}
*/
function transformFilters(filters) {
if (typeof filters === 'string') {
return transformFilter(filters);
}
else if (Array.isArray(filters))
return filters
.map(function (filter) {
if (Array.isArray(filter))
return filter
.map(function (nestedFilter) { return transformFilter(nestedFilter); })
.filter(function (elem) { return elem; });
else {
return transformFilter(filter);
}
})
.filter(function (elem) { return elem; });
return [];
function transformFilters(transformCallback, filters) {
return typeof filters === 'string'
? transformCallback(filters)
: filters.map(function (filter) {
return typeof filter === 'string'
? transformCallback(filter)
: filter.map(function (nestedFilter) { return transformCallback(nestedFilter); });
});
}

@@ -272,36 +287,31 @@ /**

*
* @param {Filter} filter
* @returns {Array}
* @param {Filter} [filter]
* @returns {Array|undefined}
*/
function filterToArray(filter) {
// Filter is a string
if (filter === '')
return [];
else if (typeof filter === 'string')
return [filter];
// Filter is either an array of strings, or an array of array of strings
return filter;
return typeof filter === 'string' ? [filter] : filter;
}
/**
* Merge facetFilters, numericFilters and filters together.
* Merge filters, transformedNumericFilters and transformedFacetFilters
* together.
*
* @param {Filter} facetFilters
* @param {Filter} numericFilters
* @param {string} filters
* @param {Filter} transformedNumericFilters
* @param {Filter} transformedFacetFilters
* @returns {Filter}
*/
function mergeFilters(facetFilters, numericFilters, filters) {
var adaptedFilters = filters.trim();
var adaptedFacetFilters = filterToArray(facetFilters);
var adaptedNumericFilters = filterToArray(numericFilters);
var adaptedFilter = __spreadArray(__spreadArray(__spreadArray([], adaptedFacetFilters, true), adaptedNumericFilters, true), [
adaptedFilters,
], false);
var cleanedFilters = adaptedFilter.filter(function (filter) {
if (Array.isArray(filter)) {
return filter.length;
}
return filter;
});
return cleanedFilters;
function mergeFilters(filters, transformedNumericFilters, transformedFacetFilters) {
var adaptedNumericFilters = filterToArray(transformedNumericFilters);
var adaptedFacetFilters = filterToArray(transformedFacetFilters);
var adaptedFilters = [];
if (filters !== undefined) {
adaptedFilters.push(filters);
}
if (adaptedNumericFilters !== undefined) {
adaptedFilters.push.apply(adaptedFilters, adaptedNumericFilters);
}
if (adaptedFacetFilters !== undefined) {
adaptedFilters.push.apply(adaptedFilters, adaptedFacetFilters);
}
return adaptedFilters;
}

@@ -318,5 +328,9 @@ /**

function adaptFilters(filters, numericFilters, facetFilters) {
var transformedFilter = transformFilters(facetFilters || []);
var transformedNumericFilter = transformFilters(numericFilters || []);
return mergeFilters(transformedFilter, transformedNumericFilter, filters || '');
var transformedNumericFilters = numericFilters !== undefined
? transformFilters(transformNumericFilter, numericFilters)
: numericFilters;
var transformedFacetFilters = facetFilters !== undefined
? transformFilters(transformFacetFilter, facetFilters)
: facetFilters;
return mergeFilters(filters, transformedNumericFilters, transformedFacetFilters);
}

@@ -329,6 +343,3 @@

// There must be no filters
if (!placeholderSearch && !query && (!filter || filter.length === 0)) {
return false;
}
return true;
return !(!placeholderSearch && !query && (!filter || filter.length === 0));
}

@@ -370,4 +381,4 @@ function setScrollPagination(pagination, paginationRequired) {

function MeiliParamsCreator(searchContext) {
var meiliSearchParams = {};
var facets = searchContext.facets, attributesToSnippet = searchContext.attributesToSnippet, snippetEllipsisText = searchContext.snippetEllipsisText, attributesToRetrieve = searchContext.attributesToRetrieve, attributesToHighlight = searchContext.attributesToHighlight, highlightPreTag = searchContext.highlightPreTag, highlightPostTag = searchContext.highlightPostTag, placeholderSearch = searchContext.placeholderSearch, query = searchContext.query, sort = searchContext.sort, pagination = searchContext.pagination, matchingStrategy = searchContext.matchingStrategy, filters = searchContext.filters, numericFilters = searchContext.numericFilters, facetFilters = searchContext.facetFilters, indexUid = searchContext.indexUid;
var query = searchContext.query, indexUid = searchContext.indexUid, facets = searchContext.facets, attributesToSnippet = searchContext.attributesToSnippet, snippetEllipsisText = searchContext.snippetEllipsisText, filters = searchContext.filters, numericFilters = searchContext.numericFilters, facetFilters = searchContext.facetFilters, attributesToRetrieve = searchContext.attributesToRetrieve, attributesToHighlight = searchContext.attributesToHighlight, highlightPreTag = searchContext.highlightPreTag, highlightPostTag = searchContext.highlightPostTag, placeholderSearch = searchContext.placeholderSearch, pagination = searchContext.pagination, sort = searchContext.sort, restrictSearchableAttributes = searchContext.restrictSearchableAttributes, overrideParams = searchContext.meiliSearchParams;
var meiliSearchParams = { indexUid: indexUid };
var meilisearchFilters = adaptFilters(filters, numericFilters, facetFilters);

@@ -381,27 +392,28 @@ return {

},
addIndexUid: function () {
meiliSearchParams.indexUid = indexUid;
},
addFacets: function () {
if (Array.isArray(facets)) {
meiliSearchParams.facets = facets;
var value = facets;
if (value !== undefined) {
// despite Instantsearch.js typing it as `string[]`,
// it still can send `string`
meiliSearchParams.facets = typeof value === 'string' ? [value] : value;
}
else if (typeof facets === 'string') {
meiliSearchParams.facets = [facets];
}
},
addAttributesToCrop: function () {
if (attributesToSnippet) {
meiliSearchParams.attributesToCrop = attributesToSnippet;
var _a;
var value = (_a = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.attributesToCrop) !== null && _a !== void 0 ? _a : attributesToSnippet;
if (value !== undefined) {
meiliSearchParams.attributesToCrop = value;
}
},
addCropMarker: function () {
// Attributes To Crop marker
if (snippetEllipsisText != null) {
meiliSearchParams.cropMarker = snippetEllipsisText;
addCropLength: function () {
var value = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.cropLength;
if (value !== undefined) {
meiliSearchParams.cropLength = value;
}
},
addAttributesToRetrieve: function () {
if (attributesToRetrieve) {
meiliSearchParams.attributesToRetrieve = attributesToRetrieve;
addCropMarker: function () {
var _a;
var value = (_a = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.cropMarker) !== null && _a !== void 0 ? _a : snippetEllipsisText;
if (value !== undefined) {
meiliSearchParams.cropMarker = value;
}

@@ -414,20 +426,23 @@ },

},
addAttributesToRetrieve: function () {
var _a;
var value = (_a = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.attributesToRetrieve) !== null && _a !== void 0 ? _a : attributesToRetrieve;
if (value !== undefined) {
meiliSearchParams.attributesToRetrieve = value;
}
},
addAttributesToHighlight: function () {
meiliSearchParams.attributesToHighlight = attributesToHighlight || ['*'];
var _a, _b;
meiliSearchParams.attributesToHighlight =
(_b = (_a = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.attributesToHighlight) !== null && _a !== void 0 ? _a : attributesToHighlight) !== null && _b !== void 0 ? _b : ['*'];
},
addPreTag: function () {
if (highlightPreTag) {
meiliSearchParams.highlightPreTag = highlightPreTag;
}
else {
meiliSearchParams.highlightPreTag = '__ais-highlight__';
}
var _a, _b;
meiliSearchParams.highlightPreTag =
(_b = (_a = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.highlightPreTag) !== null && _a !== void 0 ? _a : highlightPreTag) !== null && _b !== void 0 ? _b : '__ais-highlight__';
},
addPostTag: function () {
if (highlightPostTag) {
meiliSearchParams.highlightPostTag = highlightPostTag;
}
else {
meiliSearchParams.highlightPostTag = '__/ais-highlight__';
}
var _a, _b;
meiliSearchParams.highlightPostTag =
(_b = (_a = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.highlightPostTag) !== null && _a !== void 0 ? _a : highlightPostTag) !== null && _b !== void 0 ? _b : '__/ais-highlight__';
},

@@ -460,4 +475,4 @@ addPagination: function () {

});
if (filter) {
if (meiliSearchParams.filter) {
if (filter !== undefined) {
if (Array.isArray(meiliSearchParams.filter)) {
meiliSearchParams.filter.unshift(filter);

@@ -470,6 +485,27 @@ }

},
addShowMatchesPosition: function () {
var value = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.showMatchesPosition;
if (value !== undefined) {
meiliSearchParams.showMatchesPosition = value;
}
},
addMatchingStrategy: function () {
if (matchingStrategy) {
meiliSearchParams.matchingStrategy = matchingStrategy;
var value = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.matchingStrategy;
if (value !== undefined) {
meiliSearchParams.matchingStrategy = value;
}
},
addShowRankingScore: function () {
var value = overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.showRankingScore;
if (value !== undefined) {
meiliSearchParams.showRankingScore = value;
}
},
addAttributesToSearchOn: function () {
var value = (overrideParams === null || overrideParams === void 0 ? void 0 : overrideParams.attributesToSearchOn) !== undefined
? overrideParams.attributesToSearchOn
: (restrictSearchableAttributes);
if (value !== undefined) {
meiliSearchParams.attributesToSearchOn = value;
}
}

@@ -488,15 +524,18 @@ };

meilisearchParams.addQuery();
meilisearchParams.addIndexUid();
meilisearchParams.addFacets();
meilisearchParams.addAttributesToCrop();
meilisearchParams.addCropLength();
meilisearchParams.addCropMarker();
meilisearchParams.addFilters();
meilisearchParams.addAttributesToRetrieve();
meilisearchParams.addAttributesToHighlight();
meilisearchParams.addPreTag();
meilisearchParams.addPostTag();
meilisearchParams.addAttributesToRetrieve();
meilisearchParams.addAttributesToCrop();
meilisearchParams.addCropMarker();
meilisearchParams.addPagination();
meilisearchParams.addFilters();
meilisearchParams.addSort();
meilisearchParams.addGeoSearchFilter();
meilisearchParams.addShowMatchesPosition();
meilisearchParams.addMatchingStrategy();
meilisearchParams.addShowRankingScore();
meilisearchParams.addAttributesToSearchOn();
return meilisearchParams.getParams();

@@ -902,3 +941,2 @@ }

meilisearchParams.addFacets();
meilisearchParams.addIndexUid();
meilisearchParams.addPagination();

@@ -947,3 +985,3 @@ return meilisearchParams.getParams();

var PACKAGE_VERSION = '0.13.6';
var PACKAGE_VERSION = '0.14.0';

@@ -958,6 +996,7 @@ var constructClientAgents = function (clientAgents) {

* Instantiate SearchClient required by instantsearch.js.
*
* @param {string} hostUrl
* @param {string | apiKeyCallback} apiKey
* @param {InstantMeiliSearchOptions={}} meiliSearchOptions
* @returns {InstantMeiliSearchInstance}
* @param {string | ApiKeyCallback} [apiKey='']
* @param {InstantMeiliSearchOptions} [instantMeiliSearchOptions={}]
* @returns {InstantMeiliSearchObject}
*/

@@ -990,90 +1029,99 @@ function instantMeiliSearch(hostUrl, apiKey, instantMeiliSearchOptions) {

return {
clearCache: function () { return searchCache.clearCache(); },
/**
* @param {readonlyAlgoliaMultipleQueriesQuery[]} instantSearchRequests
* @returns {Array}
*/
search: function (instantSearchRequests) {
return __awaiter(this, void 0, void 0, function () {
var meilisearchRequests, instantSearchPagination, initialFacetDistributionsRequests, _i, instantSearchRequests_1, searchRequest, searchContext, meilisearchSearchQuery, defaultSearchQuery, meilisearchResults, instantSearchResponse, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
meilisearchRequests = [];
instantSearchPagination = [];
initialFacetDistributionsRequests = [];
for (_i = 0, instantSearchRequests_1 = instantSearchRequests; _i < instantSearchRequests_1.length; _i++) {
searchRequest = instantSearchRequests_1[_i];
searchContext = createSearchContext(searchRequest, instantMeiliSearchOptions);
meilisearchSearchQuery = adaptSearchParams(searchContext);
meilisearchRequests.push(meilisearchSearchQuery);
defaultSearchQuery = getParametersWithoutFilters(searchContext);
initialFacetDistributionsRequests.push(defaultSearchQuery);
// Keep information about the pagination parameters of instantsearch as
// they are needed to adapt the search response of Meilisearch
instantSearchPagination.push(searchContext.pagination);
}
return [4 /*yield*/, initFacetDistribution(searchResolver, initialFacetDistributionsRequests, initialFacetDistribution)
// Search request to Meilisearch happens here
];
case 1:
initialFacetDistribution = _a.sent();
return [4 /*yield*/, searchResolver.multiSearch(meilisearchRequests, instantSearchPagination // Create issue on pagination
)
setMeiliSearchParams: function (params) {
var meiliSearchParams = instantMeiliSearchOptions.meiliSearchParams;
instantMeiliSearchOptions.meiliSearchParams =
meiliSearchParams === undefined
? params
: __assign(__assign({}, meiliSearchParams), params);
},
searchClient: {
clearCache: function () { return searchCache.clearCache(); },
/**
* @param {readonlyAlgoliaMultipleQueriesQuery[]} instantSearchRequests
* @returns {Array}
*/
search: function (instantSearchRequests) {
return __awaiter(this, void 0, void 0, function () {
var meilisearchRequests, instantSearchPagination, initialFacetDistributionsRequests, _i, instantSearchRequests_1, searchRequest, searchContext, meilisearchSearchQuery, defaultSearchQuery, meilisearchResults, instantSearchResponse, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
meilisearchRequests = [];
instantSearchPagination = [];
initialFacetDistributionsRequests = [];
for (_i = 0, instantSearchRequests_1 = instantSearchRequests; _i < instantSearchRequests_1.length; _i++) {
searchRequest = instantSearchRequests_1[_i];
searchContext = createSearchContext(searchRequest, instantMeiliSearchOptions);
meilisearchSearchQuery = adaptSearchParams(searchContext);
meilisearchRequests.push(meilisearchSearchQuery);
defaultSearchQuery = getParametersWithoutFilters(searchContext);
initialFacetDistributionsRequests.push(defaultSearchQuery);
// Keep information about the pagination parameters of instantsearch as
// they are needed to adapt the search response of Meilisearch
instantSearchPagination.push(searchContext.pagination);
}
return [4 /*yield*/, initFacetDistribution(searchResolver, initialFacetDistributionsRequests, initialFacetDistribution)
// Search request to Meilisearch happens here
];
case 1:
initialFacetDistribution = _a.sent();
return [4 /*yield*/, searchResolver.multiSearch(meilisearchRequests, instantSearchPagination // Create issue on pagination
)
// Fill the missing facet values if keepZeroFacets is true
];
case 2:
meilisearchResults = _a.sent();
// Fill the missing facet values if keepZeroFacets is true
];
case 2:
meilisearchResults = _a.sent();
// Fill the missing facet values if keepZeroFacets is true
initialFacetDistribution = fillMissingFacets(initialFacetDistribution, meilisearchResults);
instantSearchResponse = adaptSearchResults(meilisearchResults, initialFacetDistribution, instantMeilisearchConfig);
return [2 /*return*/, instantSearchResponse];
case 3:
e_1 = _a.sent();
console.error(e_1);
throw new Error(e_1);
case 4: return [2 /*return*/];
}
initialFacetDistribution = fillMissingFacets(initialFacetDistribution, meilisearchResults);
instantSearchResponse = adaptSearchResults(meilisearchResults, initialFacetDistribution, instantMeilisearchConfig);
return [2 /*return*/, instantSearchResponse];
case 3:
e_1 = _a.sent();
console.error(e_1);
throw new Error(e_1);
case 4: return [2 /*return*/];
}
});
});
});
},
searchForFacetValues: function (requests) {
return __awaiter(this, void 0, void 0, function () {
var results, _i, requests_1, request, searchContext, meilisearchSearchQuery, meilisearchRequest, meilisearchResponse, facetHits, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
results = [];
_i = 0, requests_1 = requests;
_a.label = 1;
case 1:
if (!(_i < requests_1.length)) return [3 /*break*/, 4];
request = requests_1[_i];
searchContext = createFacetSearchContext(request, instantMeiliSearchOptions);
meilisearchSearchQuery = adaptSearchParams(searchContext);
meilisearchRequest = __assign(__assign({}, meilisearchSearchQuery), { facetQuery: request.params.facetQuery, facetName: request.params.facetName });
delete meilisearchRequest.indexUid;
return [4 /*yield*/, meilisearchClient
.index(searchContext.indexUid)
.searchForFacetValues(meilisearchRequest)];
case 2:
meilisearchResponse = _a.sent();
facetHits = meilisearchResponse.facetHits.map(function (facetHit) { return (__assign(__assign({}, facetHit), {
// not currently supported
highlighted: facetHit.value })); });
result = {
facetHits: facetHits,
exhaustiveFacetsCount: false,
processingTimeMS: meilisearchResponse.processingTimeMs
};
results.push(result);
_a.label = 3;
case 3:
_i++;
return [3 /*break*/, 1];
case 4: return [2 /*return*/, results];
}
},
searchForFacetValues: function (requests) {
return __awaiter(this, void 0, void 0, function () {
var results, _i, requests_1, request, searchContext, meilisearchSearchQuery, meilisearchRequest, meilisearchResponse, facetHits, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
results = [];
_i = 0, requests_1 = requests;
_a.label = 1;
case 1:
if (!(_i < requests_1.length)) return [3 /*break*/, 4];
request = requests_1[_i];
searchContext = createFacetSearchContext(request, instantMeiliSearchOptions);
meilisearchSearchQuery = adaptSearchParams(searchContext);
meilisearchRequest = __assign(__assign({}, meilisearchSearchQuery), { facetQuery: request.params.facetQuery, facetName: request.params.facetName });
delete meilisearchRequest.indexUid;
return [4 /*yield*/, meilisearchClient
.index(searchContext.indexUid)
.searchForFacetValues(meilisearchRequest)];
case 2:
meilisearchResponse = _a.sent();
facetHits = meilisearchResponse.facetHits.map(function (facetHit) { return (__assign(__assign({}, facetHit), {
// not currently supported
highlighted: facetHit.value })); });
result = {
facetHits: facetHits,
exhaustiveFacetsCount: false,
processingTimeMS: meilisearchResponse.processingTimeMs
};
results.push(result);
_a.label = 3;
case 3:
_i++;
return [3 /*break*/, 1];
case 4: return [2 /*return*/, results];
}
});
});
});
}
}

@@ -1083,8 +1131,2 @@ };

var MatchingStrategies;
(function (MatchingStrategies) {
MatchingStrategies["ALL"] = "all";
MatchingStrategies["LAST"] = "last";
})(MatchingStrategies || (MatchingStrategies = {}));
export { MatchingStrategies, instantMeiliSearch };
export { instantMeiliSearch };

@@ -1,2 +0,2 @@

import{MeiliSearch as t}from"meilisearch";var e=function(){return e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},e.apply(this,arguments)};function r(t,e,r,n){return new(r||(r=Promise))((function(i,a){function o(t){try{c(n.next(t))}catch(t){a(t)}}function u(t){try{c(n.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,u)}c((n=n.apply(t,e||[])).next())}))}function n(t,e){var r,n,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(u){return function(c){return function(u){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(o=0)),o;)try{if(r=1,n&&(i=2&u[0]?n.return:u[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,u[1])).done)return i;switch(n=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,n=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(6===u[0]&&o.label<i[1]){o.label=i[1],i=u;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(u);break}i[2]&&o.ops.pop(),o.trys.pop();continue}u=e.call(t,o)}catch(t){u=[6,t],n=0}finally{r=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}}function i(t,e,r){if(r||2===arguments.length)for(var n,i=0,a=e.length;i<a;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}function a(t){return"object"==typeof t&&!Array.isArray(t)&&null!==t}function o(t){return t.replace(/(.*):(.*)/i,'"$1"="$2"')}function u(t){return"string"==typeof t?o(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return o(t)})).filter((function(t){return t})):o(t)})).filter((function(t){return t})):[]}function c(t){return""===t?[]:"string"==typeof t?[t]:t}function s(t,e,r){return function(t,e,r){var n=r.trim(),a=c(t),o=c(e);return i(i(i([],a,!0),o,!0),[n],!1).filter((function(t){return Array.isArray(t)?t.length:t}))}(u(r||[]),u(e||[]),t||"")}function f(t){var e={},r=t.facets,n=t.attributesToSnippet,i=t.snippetEllipsisText,a=t.attributesToRetrieve,o=t.attributesToHighlight,u=t.highlightPreTag,c=t.highlightPostTag,f=t.placeholderSearch,l=t.query,d=t.sort,g=t.pagination,h=t.matchingStrategy,p=t.filters,v=t.numericFilters,y=t.facetFilters,m=t.indexUid,b=s(p,v,y);return{getParams:function(){return e},addQuery:function(){e.q=l},addIndexUid:function(){e.indexUid=m},addFacets:function(){Array.isArray(r)?e.facets=r:"string"==typeof r&&(e.facets=[r])},addAttributesToCrop:function(){n&&(e.attributesToCrop=n)},addCropMarker:function(){null!=i&&(e.cropMarker=i)},addAttributesToRetrieve:function(){a&&(e.attributesToRetrieve=a)},addFilters:function(){b.length&&(e.filter=b)},addAttributesToHighlight:function(){e.attributesToHighlight=o||["*"]},addPreTag:function(){e.highlightPreTag=u||"__ais-highlight__"},addPostTag:function(){e.highlightPostTag=c||"__/ais-highlight__"},addPagination:function(){var t=function(t,e,r){return!!(r||e||t&&0!==t.length)}(b,l,f);if(g.finite){var r=function(t,e){var r=t.page,n=t.hitsPerPage;return e?{hitsPerPage:n,page:r+1}:{hitsPerPage:0,page:r+1}}(g,t),n=r.hitsPerPage,i=r.page;e.hitsPerPage=n,e.page=i}else{var a=function(t,e){var r=t.page,n=t.hitsPerPage;return e?{limit:n+1,offset:r*n}:{limit:0,offset:0}}(g,t),o=a.limit,u=a.offset;e.limit=o,e.offset=u}},addSort:function(){(null==d?void 0:d.length)&&(e.sort=Array.isArray(d)?d:[d])},addGeoSearchFilter:function(){var r=function(t){var e,r,n,i=t.insideBoundingBox,a=t.aroundLatLng,o=t.aroundRadius,u=t.minimumAroundRadius;if(a){var c=a.split(",").map((function(t){return Number.parseFloat(t).toFixed(5)}));e=[h=c[0],p=c[1]]}if(null==o&&null==u||("all"===o?console.warn("instant-meilisearch is not compatible with the `all` value on the aroundRadius parameter"):r=null!=o?o:u),i&&"string"==typeof i){var s=i.split(",").map((function(t){return parseFloat(t)})),f=s[0],l=s[1],d=s[2],g=s[3];n="_geoBoundingBox([".concat(f,", ").concat(l,"], [").concat(d,", ").concat(g,"])")}else if(null!=e&&null!=r){var h=e[0],p=e[1];n="_geoRadius(".concat(h,", ").concat(p,", ").concat(r,")")}return n}({insideBoundingBox:t.insideBoundingBox,aroundLatLng:t.aroundLatLng,aroundRadius:t.aroundRadius,minimumAroundRadius:t.minimumAroundRadius});r&&(e.filter?e.filter.unshift(r):e.filter=[r])},addMatchingStrategy:function(){h&&(e.matchingStrategy=h)}}}function l(t){var e=f(t);return e.addQuery(),e.addIndexUid(),e.addFacets(),e.addAttributesToHighlight(),e.addPreTag(),e.addPostTag(),e.addAttributesToRetrieve(),e.addAttributesToCrop(),e.addCropMarker(),e.addPagination(),e.addFilters(),e.addSort(),e.addGeoSearchFilter(),e.addMatchingStrategy(),e.getParams()}function d(t){return"string"==typeof t?t:void 0===t?JSON.stringify(null):JSON.stringify(t)}function g(t){return Array.isArray(t)?t.map((function(t){return g(t)})):a(t)?Object.keys(t).reduce((function(e,r){return e[r]=g(t[r]),e}),{}):{value:d(t)}}function h(t){if(!t)return{};var e=g(t);return{_highlightResult:e,_snippetResult:e}}function p(t,e){var r=t.hits,n=t.pagination.hitsPerPage,i=e.finitePagination,a=e.primaryKey;!i&&r.length>n&&r.splice(r.length-1,1);var o=r.map((function(t){if(Object.keys(t).length>0){var e=t._formatted;t._matchesPosition;var r=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r}(t,["_formatted","_matchesPosition"]),n=Object.assign(r,h(e));return a&&(n.objectID=t[a]),n}return t}));return o=function(t){for(var e,r=0;r<t.length;r++){var n="".concat(r+1e6*Math.random());t[r]._geo&&(t[r]._geoloc=t[r]._geo,t[r].objectID=n),(null===(e=t[r]._formatted)||void 0===e?void 0:e._geo)&&(t[r]._formatted._geoloc=t[r]._formatted._geo,t[r]._formatted.objectID=n)}return t}(o),o}function v(t){return Object.keys(t).reduce((function(r,n){return r[n]=e(e({},t[n]),{avg:0,sum:0}),r}),{})}function y(t,e,r){var n=t.map((function(t){return function(t,e,r){var n=t.processingTimeMs,i=t.query,a=t.indexUid,o=t.facetDistribution,u=void 0===o?{}:o,c=t.facetStats,s=void 0===c?{}:c,f=Object.keys(u),l=function(t,e){var r=e.hitsPerPage,n=e.page,i=function(t,e){if(null!=t.totalPages)return t.totalPages;if(0===e)return 0;var r=t.limit,n=void 0===r?20:r,i=t.offset;return(void 0===i?0:i)/e+1+(t.hits.length>=n?1:0)}(t,r);return{page:n,nbPages:i,hitsPerPage:r}}(t,t.pagination),d=l.hitsPerPage,g=l.page,h=l.nbPages,y=p(t,r),m=function(t){var e=t.hitsPerPage,r=void 0===e?0:e,n=t.totalPages,i=void 0===n?0:n,a=t.estimatedTotalHits,o=t.totalHits;return null!=a?a:null!=o?o:r*i}(t),b=function(t,e,r,n){return t?function(t,e,r){for(var n=function(t){return t?"string"==typeof t?[t]:t:[]}(t),i={},a=0,o=n;a<o.length;a++){var u=o[a];for(var c in e[u])i[u]||(i[u]=r[u]||{}),i[u][c]?i[u][c]=r[u][c]:i[u][c]=0}return i}(e,r,n=n||{}):n}(r.keepZeroFacets,f,e,u);return{index:a,hitsPerPage:d,page:g,facets:b,nbPages:h,nbHits:m,processingTimeMS:n,query:i,hits:y,params:"",exhaustiveNbHits:!1,facets_stats:v(s)}}(t,e[t.indexUid],r)}));return{results:n}}function m(t){return t?t.split(/,(?=\w+:(?:asc|desc))/):[]}function b(t,e,r){return{hitsPerPage:void 0===e?20:e,page:r||0,finite:!!t}}function P(t){var e=t.indexOf(":");return-1===e?{indexUid:t,sortBy:""}:{indexUid:t.substring(0,e),sortBy:t.substring(e+1)}}function x(t,r){var n=t.query,i=t.indexName,a=t.params,o=P(i),u=o.indexUid,c=o.sortBy,s=b(r.finitePagination,null==a?void 0:a.hitsPerPage,null==a?void 0:a.page);return e(e(e(e({},r),{query:n}),a),{sort:m(c),indexUid:u,pagination:s,placeholderSearch:!1!==r.placeholderSearch,keepZeroFacets:!!r.keepZeroFacets})}function S(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(t){return}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,r){e[t]=JSON.stringify(r)},clearCache:function(){e={}}}}function w(t){var r=f(e(e({},t),{placeholderSearch:!0,query:""}));return r.addFacets(),r.addIndexUid(),r.addPagination(),r.getParams()}function T(t,e,i){return r(this,void 0,void 0,(function(){var r,a,o,u,c,s;return n(this,(function(n){switch(n.label){case 0:return f="indexUid",l=[],r=function(t){return!l.includes(t[f])&&(l.push(t[f]),!0)},a=e.filter(r).filter((function(t){var e=t.indexUid;return!Object.keys(i).includes(e)})),0===a.length?[2,i]:[4,t.multiSearch(a,[])];case 1:for(o=n.sent(),u=0,c=o;u<c.length;u++)s=c[u],i[s.indexUid]=s.facetDistribution||{};return[2,i]}var f,l}))}))}"function"==typeof SuppressedError&&SuppressedError;var A;function _(i,o,u){void 0===o&&(o=""),void 0===u&&(u={}),function(t,e,r){var n=r.requestConfig,i=r.httpClient;if("string"!=typeof t)throw new TypeError("Provided hostUrl value (1st parameter) is not a string, expected string");if("string"!=typeof e&&"function"!=typeof e)throw new TypeError("Provided apiKey value (2nd parameter) is not a string or a function, expected string or function");if(void 0!==n&&!a(n))throw new TypeError("Provided requestConfig should be an object");if(i&&"function"!=typeof i)throw new TypeError("Provided custom httpClient should be a function")}(i,o,u);var c={host:i,apiKey:o=function(t){if("function"==typeof t){var e=t();if("string"!=typeof e)throw new TypeError("Provided apiKey function (2nd parameter) did not return a string, expected string");return e}return t}(o),clientAgents:function(t){void 0===t&&(t=[]);var e="Meilisearch instant-meilisearch (v".concat("0.13.6",")");return t.concat(e)}(u.clientAgents)};void 0!==u.httpClient&&(c.httpClient=u.httpClient),void 0!==u.requestConfig&&(c.requestConfig=u.requestConfig);var s,f,d,g=new t(c),h=S(),p=(s=g,f=h,{multiSearch:function(t,i){return r(this,void 0,void 0,(function(){var r,a,o,u;return n(this,(function(n){switch(n.label){case 0:return r=f.formatKey([t]),(a=f.getEntry(r))?[2,a]:[4,s.multiSearch({queries:t})];case 1:return o=n.sent(),u=o.results.map((function(t,r){return e(e({},t),{pagination:i[r]||{}})})),f.setEntry(r,u),[2,u]}}))}))}}),v={},A=(d=u,e(e({},{placeholderSearch:!0,keepZeroFacets:!1,clientAgents:[],finitePagination:!1}),d));return{clearCache:function(){return h.clearCache()},search:function(t){return r(this,void 0,void 0,(function(){var r,i,a,o,c,s,f,d,g,h,m;return n(this,(function(n){switch(n.label){case 0:for(n.trys.push([0,3,,4]),r=[],i=[],a=[],o=0,c=t;o<c.length;o++)s=c[o],f=x(s,u),d=l(f),r.push(d),g=w(f),a.push(g),i.push(f.pagination);return[4,T(p,a,v)];case 1:return v=n.sent(),[4,p.multiSearch(r,i)];case 2:return h=n.sent(),v=function(t,r){for(var n=0,i=r;n<i.length;n++){var a=i[n];t[a.indexUid]=e(e({},a.facetDistribution||{}),t[a.indexUid]||{})}return t}(v,h),[2,y(h,v,A)];case 3:throw m=n.sent(),console.error(m),new Error(m);case 4:return[2]}}))}))},searchForFacetValues:function(t){return r(this,void 0,void 0,(function(){var r,i,a,o,c,s,f,d,h,p;return n(this,(function(n){switch(n.label){case 0:r=[],i=0,a=t,n.label=1;case 1:return i<a.length?(o=a[i],c=function(t,r){var n=P(t.indexName),i=n.indexUid,a=n.sortBy,o=t.params,u=b(r.finitePagination,null==o?void 0:o.hitsPerPage,null==o?void 0:o.page);return e(e(e({},r),o),{sort:m(a),indexUid:i,pagination:u,placeholderSearch:!1!==r.placeholderSearch,keepZeroFacets:!!r.keepZeroFacets})}(o,u),s=l(c),delete(f=e(e({},s),{facetQuery:o.params.facetQuery,facetName:o.params.facetName})).indexUid,[4,g.index(c.indexUid).searchForFacetValues(f)]):[3,4];case 2:d=n.sent(),h=d.facetHits.map((function(t){return e(e({},t),{highlighted:t.value})})),p={facetHits:h,exhaustiveFacetsCount:!1,processingTimeMS:d.processingTimeMs},r.push(p),n.label=3;case 3:return i++,[3,1];case 4:return[2,r]}}))}))}}}!function(t){t.ALL="all",t.LAST="last"}(A||(A={}));export{A as MatchingStrategies,_ as instantMeiliSearch};
import{MeiliSearch as t}from"meilisearch";var e=function(){return e=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},e.apply(this,arguments)};function n(t,e,n,r){return new(n||(n=Promise))((function(i,a){function o(t){try{c(r.next(t))}catch(t){a(t)}}function u(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,u)}c((r=r.apply(t,e||[])).next())}))}function r(t,e){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(u){return function(c){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&u[0]?r.return:u[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,u[1])).done)return i;switch(r=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(6===u[0]&&o.label<i[1]){o.label=i[1],i=u;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(u);break}i[2]&&o.ops.pop(),o.trys.pop();continue}u=e.call(t,o)}catch(t){u=[6,t],r=0}finally{n=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}}function i(t){return"object"==typeof t&&!Array.isArray(t)&&null!==t}"function"==typeof SuppressedError&&SuppressedError;var a=/([\\"])/g;function o(t){return t.replace(a,"\\$1")}function u(t){var e=o(t),n=e.indexOf(":"),r=e.slice(0,n),i=e.slice(n+1);return'"'.concat(r,'"="').concat(i,'"')}var c=/(?<!(?:[<!>]?=|<|>|:).*)([<!>]?=|<|>|:)/;function s(t){var e=t.split(c),n=e[0],r=e[1],i=e[2],a=o(n);return'"'.concat(a.trim(),'"').concat(":"===r?" ":r).concat(i.trim())}function l(t,e){return"string"==typeof e?t(e):e.map((function(e){return"string"==typeof e?t(e):e.map((function(e){return t(e)}))}))}function d(t){return"string"==typeof t?[t]:t}function f(t,e,n){return function(t,e,n){var r=d(e),i=d(n),a=[];return void 0!==t&&a.push(t),void 0!==r&&a.push.apply(a,r),void 0!==i&&a.push.apply(a,i),a}(t,void 0!==e?l(s,e):e,void 0!==n?l(u,n):n)}function h(t){var e=t.query,n=t.indexUid,r=t.facets,i=t.attributesToSnippet,a=t.snippetEllipsisText,o=t.filters,u=t.numericFilters,c=t.facetFilters,s=t.attributesToRetrieve,l=t.attributesToHighlight,d=t.highlightPreTag,h=t.highlightPostTag,g=t.placeholderSearch,p=t.pagination,v=t.sort,y=t.restrictSearchableAttributes,m=t.meiliSearchParams,b={indexUid:n},P=f(o,u,c);return{getParams:function(){return b},addQuery:function(){b.q=e},addFacets:function(){var t=r;void 0!==t&&(b.facets="string"==typeof t?[t]:t)},addAttributesToCrop:function(){var t,e=null!==(t=null==m?void 0:m.attributesToCrop)&&void 0!==t?t:i;void 0!==e&&(b.attributesToCrop=e)},addCropLength:function(){var t=null==m?void 0:m.cropLength;void 0!==t&&(b.cropLength=t)},addCropMarker:function(){var t,e=null!==(t=null==m?void 0:m.cropMarker)&&void 0!==t?t:a;void 0!==e&&(b.cropMarker=e)},addFilters:function(){P.length&&(b.filter=P)},addAttributesToRetrieve:function(){var t,e=null!==(t=null==m?void 0:m.attributesToRetrieve)&&void 0!==t?t:s;void 0!==e&&(b.attributesToRetrieve=e)},addAttributesToHighlight:function(){var t,e;b.attributesToHighlight=null!==(e=null!==(t=null==m?void 0:m.attributesToHighlight)&&void 0!==t?t:l)&&void 0!==e?e:["*"]},addPreTag:function(){var t,e;b.highlightPreTag=null!==(e=null!==(t=null==m?void 0:m.highlightPreTag)&&void 0!==t?t:d)&&void 0!==e?e:"__ais-highlight__"},addPostTag:function(){var t,e;b.highlightPostTag=null!==(e=null!==(t=null==m?void 0:m.highlightPostTag)&&void 0!==t?t:h)&&void 0!==e?e:"__/ais-highlight__"},addPagination:function(){var t=function(t,e,n){return!!(n||e||t&&0!==t.length)}(P,e,g);if(p.finite){var n=function(t,e){var n=t.page,r=t.hitsPerPage;return e?{hitsPerPage:r,page:n+1}:{hitsPerPage:0,page:n+1}}(p,t),r=n.hitsPerPage,i=n.page;b.hitsPerPage=r,b.page=i}else{var a=function(t,e){var n=t.page,r=t.hitsPerPage;return e?{limit:r+1,offset:n*r}:{limit:0,offset:0}}(p,t),o=a.limit,u=a.offset;b.limit=o,b.offset=u}},addSort:function(){(null==v?void 0:v.length)&&(b.sort=Array.isArray(v)?v:[v])},addGeoSearchFilter:function(){var e=function(t){var e,n,r,i=t.insideBoundingBox,a=t.aroundLatLng,o=t.aroundRadius,u=t.minimumAroundRadius;if(a){var c=a.split(",").map((function(t){return Number.parseFloat(t).toFixed(5)}));e=[g=c[0],p=c[1]]}if(null==o&&null==u||("all"===o?console.warn("instant-meilisearch is not compatible with the `all` value on the aroundRadius parameter"):n=null!=o?o:u),i&&"string"==typeof i){var s=i.split(",").map((function(t){return parseFloat(t)})),l=s[0],d=s[1],f=s[2],h=s[3];r="_geoBoundingBox([".concat(l,", ").concat(d,"], [").concat(f,", ").concat(h,"])")}else if(null!=e&&null!=n){var g=e[0],p=e[1];r="_geoRadius(".concat(g,", ").concat(p,", ").concat(n,")")}return r}({insideBoundingBox:t.insideBoundingBox,aroundLatLng:t.aroundLatLng,aroundRadius:t.aroundRadius,minimumAroundRadius:t.minimumAroundRadius});void 0!==e&&(Array.isArray(b.filter)?b.filter.unshift(e):b.filter=[e])},addShowMatchesPosition:function(){var t=null==m?void 0:m.showMatchesPosition;void 0!==t&&(b.showMatchesPosition=t)},addMatchingStrategy:function(){var t=null==m?void 0:m.matchingStrategy;void 0!==t&&(b.matchingStrategy=t)},addShowRankingScore:function(){var t=null==m?void 0:m.showRankingScore;void 0!==t&&(b.showRankingScore=t)},addAttributesToSearchOn:function(){var t=void 0!==(null==m?void 0:m.attributesToSearchOn)?m.attributesToSearchOn:y;void 0!==t&&(b.attributesToSearchOn=t)}}}function g(t){var e=h(t);return e.addQuery(),e.addFacets(),e.addAttributesToCrop(),e.addCropLength(),e.addCropMarker(),e.addFilters(),e.addAttributesToRetrieve(),e.addAttributesToHighlight(),e.addPreTag(),e.addPostTag(),e.addPagination(),e.addSort(),e.addGeoSearchFilter(),e.addShowMatchesPosition(),e.addMatchingStrategy(),e.addShowRankingScore(),e.addAttributesToSearchOn(),e.getParams()}function p(t){return"string"==typeof t?t:void 0===t?JSON.stringify(null):JSON.stringify(t)}function v(t){return Array.isArray(t)?t.map((function(t){return v(t)})):i(t)?Object.keys(t).reduce((function(e,n){return e[n]=v(t[n]),e}),{}):{value:p(t)}}function y(t){if(!t)return{};var e=v(t);return{_highlightResult:e,_snippetResult:e}}function m(t,e){var n=t.hits,r=t.pagination.hitsPerPage,i=e.finitePagination,a=e.primaryKey;!i&&n.length>r&&n.splice(n.length-1,1);var o=n.map((function(t){if(Object.keys(t).length>0){var e=t._formatted;t._matchesPosition;var n=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(t,["_formatted","_matchesPosition"]),r=Object.assign(n,y(e));return a&&(r.objectID=t[a]),r}return t}));return o=function(t){for(var e,n=0;n<t.length;n++){var r="".concat(n+1e6*Math.random());t[n]._geo&&(t[n]._geoloc=t[n]._geo,t[n].objectID=r),(null===(e=t[n]._formatted)||void 0===e?void 0:e._geo)&&(t[n]._formatted._geoloc=t[n]._formatted._geo,t[n]._formatted.objectID=r)}return t}(o),o}function b(t){return Object.keys(t).reduce((function(n,r){return n[r]=e(e({},t[r]),{avg:0,sum:0}),n}),{})}function P(t,e,n){var r=t.map((function(t){return function(t,e,n){var r=t.processingTimeMs,i=t.query,a=t.indexUid,o=t.facetDistribution,u=void 0===o?{}:o,c=t.facetStats,s=void 0===c?{}:c,l=Object.keys(u),d=function(t,e){var n=e.hitsPerPage,r=e.page,i=function(t,e){if(null!=t.totalPages)return t.totalPages;if(0===e)return 0;var n=t.limit,r=void 0===n?20:n,i=t.offset;return(void 0===i?0:i)/e+1+(t.hits.length>=r?1:0)}(t,n);return{page:r,nbPages:i,hitsPerPage:n}}(t,t.pagination),f=d.hitsPerPage,h=d.page,g=d.nbPages,p=m(t,n),v=function(t){var e=t.hitsPerPage,n=void 0===e?0:e,r=t.totalPages,i=void 0===r?0:r,a=t.estimatedTotalHits,o=t.totalHits;return null!=a?a:null!=o?o:n*i}(t),y=function(t,e,n,r){return t?function(t,e,n){for(var r=function(t){return t?"string"==typeof t?[t]:t:[]}(t),i={},a=0,o=r;a<o.length;a++){var u=o[a];for(var c in e[u])i[u]||(i[u]=n[u]||{}),i[u][c]?i[u][c]=n[u][c]:i[u][c]=0}return i}(e,n,r=r||{}):r}(n.keepZeroFacets,l,e,u);return{index:a,hitsPerPage:f,page:h,facets:y,nbPages:g,nbHits:v,processingTimeMS:r,query:i,hits:p,params:"",exhaustiveNbHits:!1,facets_stats:b(s)}}(t,e[t.indexUid],n)}));return{results:r}}function S(t){return t?t.split(/,(?=\w+:(?:asc|desc))/):[]}function w(t,e,n){return{hitsPerPage:void 0===e?20:e,page:n||0,finite:!!t}}function x(t){var e=t.indexOf(":");return-1===e?{indexUid:t,sortBy:""}:{indexUid:t.substring(0,e),sortBy:t.substring(e+1)}}function T(t,n){var r=t.query,i=t.indexName,a=t.params,o=x(i),u=o.indexUid,c=o.sortBy,s=w(n.finitePagination,null==a?void 0:a.hitsPerPage,null==a?void 0:a.page);return e(e(e(e({},n),{query:r}),a),{sort:S(c),indexUid:u,pagination:s,placeholderSearch:!1!==n.placeholderSearch,keepZeroFacets:!!n.keepZeroFacets})}function O(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(t){return}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,n){e[t]=JSON.stringify(n)},clearCache:function(){e={}}}}function _(t){var n=h(e(e({},t),{placeholderSearch:!0,query:""}));return n.addFacets(),n.addPagination(),n.getParams()}function k(t,e,i){return n(this,void 0,void 0,(function(){var n,a,o,u,c,s;return r(this,(function(r){switch(r.label){case 0:return l="indexUid",d=[],n=function(t){return!d.includes(t[l])&&(d.push(t[l]),!0)},a=e.filter(n).filter((function(t){var e=t.indexUid;return!Object.keys(i).includes(e)})),0===a.length?[2,i]:[4,t.multiSearch(a,[])];case 1:for(o=r.sent(),u=0,c=o;u<c.length;u++)s=c[u],i[s.indexUid]=s.facetDistribution||{};return[2,i]}var l,d}))}))}function A(a,o,u){void 0===o&&(o=""),void 0===u&&(u={}),function(t,e,n){var r=n.requestConfig,a=n.httpClient;if("string"!=typeof t)throw new TypeError("Provided hostUrl value (1st parameter) is not a string, expected string");if("string"!=typeof e&&"function"!=typeof e)throw new TypeError("Provided apiKey value (2nd parameter) is not a string or a function, expected string or function");if(void 0!==r&&!i(r))throw new TypeError("Provided requestConfig should be an object");if(a&&"function"!=typeof a)throw new TypeError("Provided custom httpClient should be a function")}(a,o,u);var c={host:a,apiKey:o=function(t){if("function"==typeof t){var e=t();if("string"!=typeof e)throw new TypeError("Provided apiKey function (2nd parameter) did not return a string, expected string");return e}return t}(o),clientAgents:function(t){void 0===t&&(t=[]);var e="Meilisearch instant-meilisearch (v".concat("0.14.0",")");return t.concat(e)}(u.clientAgents)};void 0!==u.httpClient&&(c.httpClient=u.httpClient),void 0!==u.requestConfig&&(c.requestConfig=u.requestConfig);var s,l,d,f=new t(c),h=O(),p=(s=f,l=h,{multiSearch:function(t,i){return n(this,void 0,void 0,(function(){var n,a,o,u;return r(this,(function(r){switch(r.label){case 0:return n=l.formatKey([t]),(a=l.getEntry(n))?[2,a]:[4,s.multiSearch({queries:t})];case 1:return o=r.sent(),u=o.results.map((function(t,n){return e(e({},t),{pagination:i[n]||{}})})),l.setEntry(n,u),[2,u]}}))}))}}),v={},y=(d=u,e(e({},{placeholderSearch:!0,keepZeroFacets:!1,clientAgents:[],finitePagination:!1}),d));return{setMeiliSearchParams:function(t){var n=u.meiliSearchParams;u.meiliSearchParams=void 0===n?t:e(e({},n),t)},searchClient:{clearCache:function(){return h.clearCache()},search:function(t){return n(this,void 0,void 0,(function(){var n,i,a,o,c,s,l,d,f,h,m;return r(this,(function(r){switch(r.label){case 0:for(r.trys.push([0,3,,4]),n=[],i=[],a=[],o=0,c=t;o<c.length;o++)s=c[o],l=T(s,u),d=g(l),n.push(d),f=_(l),a.push(f),i.push(l.pagination);return[4,k(p,a,v)];case 1:return v=r.sent(),[4,p.multiSearch(n,i)];case 2:return h=r.sent(),v=function(t,n){for(var r=0,i=n;r<i.length;r++){var a=i[r];t[a.indexUid]=e(e({},a.facetDistribution||{}),t[a.indexUid]||{})}return t}(v,h),[2,P(h,v,y)];case 3:throw m=r.sent(),console.error(m),new Error(m);case 4:return[2]}}))}))},searchForFacetValues:function(t){return n(this,void 0,void 0,(function(){var n,i,a,o,c,s,l,d,h,p;return r(this,(function(r){switch(r.label){case 0:n=[],i=0,a=t,r.label=1;case 1:return i<a.length?(o=a[i],c=function(t,n){var r=x(t.indexName),i=r.indexUid,a=r.sortBy,o=t.params,u=w(n.finitePagination,null==o?void 0:o.hitsPerPage,null==o?void 0:o.page);return e(e(e({},n),o),{sort:S(a),indexUid:i,pagination:u,placeholderSearch:!1!==n.placeholderSearch,keepZeroFacets:!!n.keepZeroFacets})}(o,u),s=g(c),delete(l=e(e({},s),{facetQuery:o.params.facetQuery,facetName:o.params.facetName})).indexUid,[4,f.index(c.indexUid).searchForFacetValues(l)]):[3,4];case 2:d=r.sent(),h=d.facetHits.map((function(t){return e(e({},t),{highlighted:t.value})})),p={facetHits:h,exhaustiveFacetsCount:!1,processingTimeMS:d.processingTimeMs},n.push(p),r.label=3;case 3:return i++,[3,1];case 4:return[2,n]}}))}))}}}}export{A as instantMeiliSearch};
//# sourceMappingURL=instant-meilisearch.esm.min.js.map

@@ -11,8 +11,8 @@ import type { SearchContext, MeiliSearchMultiSearchParams } from '../../types';

addQuery(): void;
addIndexUid(): void;
addFacets(): void;
addAttributesToCrop(): void;
addCropLength(): void;
addCropMarker(): void;
addFilters(): void;
addAttributesToRetrieve(): void;
addFilters(): void;
addAttributesToHighlight(): void;

@@ -24,3 +24,6 @@ addPreTag(): void;

addGeoSearchFilter(): void;
addShowMatchesPosition(): void;
addMatchingStrategy(): void;
addShowRankingScore(): void;
addAttributesToSearchOn(): void;
};

@@ -27,0 +30,0 @@ /**

@@ -1,2 +0,2 @@

import { InstantMeiliSearchOptions, InstantMeiliSearchConfig } from '../../types';
import { InstantMeiliSearchOptions, InstantMeiliSearchConfig, ApiKeyCallback } from '../../types';
/**

@@ -11,6 +11,6 @@ * Get the configuration of instant meilisearch

* Resolves apiKey if it is a function
* @param {string | apiKeyCallback} apiKey
* @param {string | ApiKeyCallback} apiKey
* @returns {string} api key value
*/
export declare function getApiKey(apiKey: string | (() => string)): string;
export declare function getApiKey(apiKey: string | ApiKeyCallback): string;
/**

@@ -17,0 +17,0 @@ * Validates host and apiKey parameters, throws if invalid

@@ -1,10 +0,11 @@

import { InstantMeiliSearchOptions, InstantMeiliSearchInstance } from '../types';
import { InstantMeiliSearchOptions, InstantMeiliSearchObject, ApiKeyCallback } from '../types';
/**
* Instantiate SearchClient required by instantsearch.js.
*
* @param {string} hostUrl
* @param {string | apiKeyCallback} apiKey
* @param {InstantMeiliSearchOptions={}} meiliSearchOptions
* @returns {InstantMeiliSearchInstance}
* @param {string | ApiKeyCallback} [apiKey='']
* @param {InstantMeiliSearchOptions} [instantMeiliSearchOptions={}]
* @returns {InstantMeiliSearchObject}
*/
export declare function instantMeiliSearch(hostUrl: string, apiKey?: string | (() => string), instantMeiliSearchOptions?: InstantMeiliSearchOptions): InstantMeiliSearchInstance;
export declare function instantMeiliSearch(hostUrl: string, apiKey?: string | ApiKeyCallback, instantMeiliSearchOptions?: InstantMeiliSearchOptions): InstantMeiliSearchObject;
//# sourceMappingURL=instant-meilisearch-client.d.ts.map

@@ -1,2 +0,2 @@

export declare const PACKAGE_VERSION = "0.13.6";
export declare const PACKAGE_VERSION = "0.14.0";
//# sourceMappingURL=package-version.d.ts.map
import type { SearchClient } from 'instantsearch.js';
import type { MultipleQueriesQuery as AlgoliaMultipleQueriesQuery, multipleSearchForFacetValues } from '@algolia/client-search';
import type { MultiSearchQuery as MeiliSearchMultiSearchParams, MultiSearchResult, Config as MeilisearchConfig } from 'meilisearch';
export type Mutable<TVal> = {
-readonly [TKey in keyof TVal]: TVal[TKey];
};
export type { AlgoliaMultipleQueriesQuery, MultiSearchResult };

@@ -9,8 +12,6 @@ export type { SearchResponse as AlgoliaSearchResponse, SearchForFacetValuesResponse as AlgoliaSearchForFacetValuesResponse, } from '@algolia/client-search';

export type { Filter, FacetDistribution, MeiliSearch, FacetStats as MeiliFacetStats, MultiSearchQuery as MeiliSearchMultiSearchParams, Config as MeilisearchConfig, } from 'meilisearch';
export type InstantSearchParams = AlgoliaMultipleQueriesQuery['params'];
export declare const enum MatchingStrategies {
ALL = "all",
LAST = "last"
}
export type InstantMeiliSearchOptions = Pick<MeilisearchConfig, 'requestConfig' | 'httpClient'> & {
export type ApiKeyCallback = () => string;
export type InstantSearchParams = NonNullable<AlgoliaMultipleQueriesQuery['params']>;
export type OverridableMeiliSearchSearchParameters = Pick<MeiliSearchMultiSearchParams, 'attributesToRetrieve' | 'attributesToCrop' | 'cropLength' | 'cropMarker' | 'attributesToHighlight' | 'highlightPreTag' | 'highlightPostTag' | 'showMatchesPosition' | 'matchingStrategy' | 'showRankingScore' | 'attributesToSearchOn'>;
type BaseInstantMeiliSearchOptions = {
placeholderSearch?: boolean;

@@ -20,13 +21,7 @@ primaryKey?: string;

clientAgents?: string[];
matchingStrategy?: MatchingStrategies;
finitePagination?: boolean;
meiliSearchParams?: OverridableMeiliSearchSearchParameters;
};
export type InstantMeiliSearchConfig = {
placeholderSearch: boolean;
keepZeroFacets: boolean;
clientAgents: string[];
finitePagination: boolean;
primaryKey?: string;
matchingStrategy?: MatchingStrategies;
};
export type InstantMeiliSearchOptions = Pick<MeilisearchConfig, 'requestConfig' | 'httpClient'> & BaseInstantMeiliSearchOptions;
export type InstantMeiliSearchConfig = Required<Pick<InstantMeiliSearchOptions, 'placeholderSearch' | 'keepZeroFacets' | 'clientAgents' | 'finitePagination'>> & BaseInstantMeiliSearchOptions;
export type SearchCacheInterface = {

@@ -52,12 +47,6 @@ getEntry: <T>(key: string) => T | undefined;

};
export type SearchContext = Omit<InstantSearchParams, 'insideBoundingBox'> & InstantSearchParams & {
export type SearchContext = InstantMeiliSearchOptions & InstantSearchParams & {
pagination: PaginationState;
indexUid: string;
placeholderSearch: boolean;
keepZeroFacets: boolean;
insideBoundingBox?: InsideBoundingBox;
cropMarker?: string;
sort?: string | string[];
primaryKey?: string;
matchingStrategy?: MatchingStrategies;
};

@@ -76,2 +65,6 @@ export type InstantSearchGeoParams = {

};
export type InstantMeiliSearchObject = {
setMeiliSearchParams: (params: OverridableMeiliSearchSearchParameters) => void;
searchClient: InstantMeiliSearchInstance;
};
export type MultiSearchResolver = {

@@ -78,0 +71,0 @@ multiSearch: (searchQueries: MeiliSearchMultiSearchParams[], instantSearchPagination: PaginationState[]) => Promise<MeilisearchMultiSearchResult[]>;

{
"name": "@meilisearch/instant-meilisearch",
"version": "0.13.6",
"version": "0.14.0",
"private": false,

@@ -53,3 +53,3 @@ "description": "The search client to use Meilisearch with InstantSearch.",

"dependencies": {
"meilisearch": "^0.35.0"
"meilisearch": "^0.36.0"
},

@@ -82,2 +82,2 @@ "devDependencies": {

}
}
}

@@ -83,3 +83,3 @@ <p align="center">

const searchClient = instantMeiliSearch(
const { searchClient, setMeiliSearchParams } = instantMeiliSearch(
'https://ms-adf78ae33284-106.lon.meilisearch.io', // Host

@@ -90,2 +90,4 @@ 'a63da4928426f12639e19d62886f621130f3fa9ff3c7534c5d179f0f51c4f303' // API key

where `searchClient` is to be passed to instantsearch.js or its many framework adaptations, and [`setMeiliSearchParams`](#modify-meilisearch-search-parameters) is a function used to set/modify certain Meilisearch search parameters to be overridden.
### Parameters

@@ -101,8 +103,8 @@

- [`placeholderSearch`](#placeholder-search): Enable or disable placeholder search (default: `true`).
- [`finitePagination`](#finite-pagination): Enable finite pagination when using the the [`pagination`](#-pagination) widget (default: `false`) .
- [`finitePagination`](#finite-pagination): Enable finite pagination when using the [`pagination`](#-pagination) widget (default: `false`) .
- [`primaryKey`](#primary-key): Specify the primary key of your documents (default `undefined`).
- [`keepZeroFacets`](#keep-zero-facets): Show the facets value even when they have 0 matches (default `false`).
- [`matchingStrategy`](#matching-strategy): Determine the search strategy on words matching (default `last`).
- [`requestConfig`](#request-config): Use custom request configurations.
- ['httpClient'](#custom-http-client): Use a custom HTTP client.
- [`httpClient`](#custom-http-client): Use a custom HTTP client.
- [`meiliSearchParams`](#meilisearch-search-parameters): Override a selection of Meilisearch search parameters (default `undefined`).

@@ -114,3 +116,3 @@ The options are added as the third parameter of the `instantMeilisearch` function.

const searchClient = instantMeiliSearch(
const { searchClient } = instantMeiliSearch(
'https://ms-adf78ae33284-106.lon.meilisearch.io',

@@ -179,16 +181,2 @@ 'a63da4928426f12639e19d62886f621130f3fa9ff3c7534c5d179f0f51c4f303',

### Matching strategy
`matchingStrategy` gives you the possibility to choose how Meilisearch should handle the presence of multiple query words, see [documentation](https://www.meilisearch.com/docs/reference/api/search#matching-strategy).
For example, if your query is `hello world` by default Meilisearch returns documents containing either both `hello` and `world` or documents that only contain `hello`. This is the `last` strategy, where words are stripped from the right.
The other strategy is `all`, where both `hello` and `world` **must** be present in a document for it to be returned.
```js
{
matchingStrategy: 'all' // default last
}
```
### Request Config

@@ -229,2 +217,62 @@

### Meilisearch search parameters
`meiliSearchParams` lets you override a set of search parameters that are sent off to Meilisearch.
The following options can be overridden:
[`attributesToRetrieve`](https://www.meilisearch.com/docs/reference/api/search#attributes-to-retrieve),
[`attributesToCrop`](https://www.meilisearch.com/docs/reference/api/search#attributes-to-crop),
[`cropLength`](https://www.meilisearch.com/docs/reference/api/search#crop-length),
[`cropMarker`](https://www.meilisearch.com/docs/reference/api/search#crop-marker),
[`attributesToHighlight`](https://www.meilisearch.com/docs/reference/api/search#attributes-to-highlight),
[`highlightPreTag`, `highlightPostTag`](https://www.meilisearch.com/docs/reference/api/search#highlight-tags),
[`showMatchesPosition`](https://www.meilisearch.com/docs/reference/api/search#show-matches-position),
[`matchingStrategy`](https://www.meilisearch.com/docs/reference/api/search#matching-strategy),
[`showRankingScore`](https://www.meilisearch.com/docs/reference/api/search#ranking-score),
[`attributesToSearchOn`](https://www.meilisearch.com/docs/reference/api/search#customize-attributes-to-search-on-at-search-time).
```js
instantMeiliSearch(
// ...
{
meiliSearchParams: {
attributesToHighlight: ['overview'],
highlightPreTag: '<em>',
highlightPostTag: '</em>',
attributesToSearchOn: ['overview'],
},
}
)
```
### Modify Meilisearch search parameters
`instantMeiliSearch` returns an instance with two properties on it, one of them being `setMeiliSearchParams`.
```js
const { searchClient, setMeiliSearchParams } = instantMeiliSearch(/*...*/)
```
It modifies (or sets if not already set) the [overridden Meilisearch search parameters](#meilisearch-search-parameters).
It only modifies parameters that are defined on the provided object, the following will not change `attributesToHighlight`.
```js
const { setMeiliSearchParams } = instantMeiliSearch(
// ...
{
meiliSearchParams: {
attributesToHighlight: ['overview'],
highlightPreTag: '<em>',
highlightPostTag: '</em>',
attributesToSearchOn: ['overview'],
},
}
)
setMeiliSearchParams({
highlightPreTag: '<mark>',
highlightPostTag: '</mark>',
attributesToSearchOn: ['overview', 'title'],
})
```
## 🪡 Example with InstantSearch

@@ -261,8 +309,10 @@

```js
const { searchClient } = instantMeiliSearch(
'https://ms-adf78ae33284-106.lon.meilisearch.io',
'a63da4928426f12639e19d62886f621130f3fa9ff3c7534c5d179f0f51c4f303'
)
const search = instantsearch({
indexName: 'steam-video-games',
searchClient: instantMeiliSearch(
'https://ms-adf78ae33284-106.lon.meilisearch.io',
'a63da4928426f12639e19d62886f621130f3fa9ff3c7534c5d179f0f51c4f303'
),
searchClient,
})

@@ -391,3 +441,3 @@

}
),
).searchClient,
// ... InstantSearch options

@@ -394,0 +444,0 @@ routing: true // for example

@@ -0,3 +1,7 @@

import { MatchingStrategies } from 'meilisearch'
import { adaptSearchParams } from '../search-params-adapter'
import { MatchingStrategies, SearchContext } from '../../../types'
import {
OverridableMeiliSearchSearchParameters,
SearchContext,
} from '../../../types'

@@ -9,2 +13,5 @@ const DEFAULT_CONTEXT: SearchContext = {

keepZeroFacets: false,
attributesToHighlight: ['*'],
highlightPreTag: '<mark>',
highlightPostTag: '</mark>',
}

@@ -49,9 +56,27 @@

test('adapting a searchContext with matching strategy', () => {
test('adapting a searchContext with overridden Meilisearch parameters', () => {
const meiliSearchParams: OverridableMeiliSearchSearchParameters = {
attributesToHighlight: ['movies', 'genres'],
highlightPreTag: '<em>',
highlightPostTag: '</em>',
matchingStrategy: MatchingStrategies.ALL,
}
const searchParams = adaptSearchParams({
...DEFAULT_CONTEXT,
matchingStrategy: MatchingStrategies.ALL,
meiliSearchParams,
})
expect(searchParams.matchingStrategy).toEqual('all')
expect(searchParams.attributesToHighlight).toEqual(
meiliSearchParams.attributesToHighlight
)
expect(searchParams.highlightPreTag).toEqual(
meiliSearchParams.highlightPreTag
)
expect(searchParams.highlightPostTag).toEqual(
meiliSearchParams.highlightPostTag
)
expect(searchParams.matchingStrategy).toEqual(
meiliSearchParams.matchingStrategy
)
})

@@ -58,0 +83,0 @@ })

import type { Filter, SearchContext } from '../../types'
const filterEscapeRegExp = /([\\"])/g
function getValueWithEscapedBackslashesAndQuotes(value: string): string {
return value.replace(filterEscapeRegExp, '\\$1')
}
/**
* Transform InstantSearch filter to Meilisearch compatible filter format.
* Transform InstantSearch [facet filter](https://www.algolia.com/doc/api-reference/api-parameters/facetFilters/)
* to Meilisearch compatible filter format.
* Change sign from `:` to `=`

@@ -9,36 +16,64 @@ * "facet:facetValue" becomes "facet=facetValue"

* Wrap both the facet and its facet value between quotes.
* This avoid formating issues on facets containing multiple words.
* This avoids formatting issues on facets containing multiple words.
* Escape backslash \\ and quote " characters.
*
* 'My facet:My facet value' becomes '"My facet":"My facet value"'
*
* @param {string} filter?
* @returns {Filter}
* @param {string} filter
* @returns {string}
*/
function transformFilter(filter: string): string {
return filter.replace(/(.*):(.*)/i, '"$1"="$2"')
function transformFacetFilter(filter: string): string {
const escapedFilter = getValueWithEscapedBackslashesAndQuotes(filter)
const colonIndex = escapedFilter.indexOf(':')
const attribute = escapedFilter.slice(0, colonIndex)
const value = escapedFilter.slice(colonIndex + 1)
return `"${attribute}"="${value}"`
}
// Matches first occurrence of an operator
const numericSplitRegExp = /(?<!(?:[<!>]?=|<|>|:).*)([<!>]?=|<|>|:)/
/**
* Itterate over all filters.
* Transform InstantSearch [numeric filter](https://www.algolia.com/doc/api-reference/api-parameters/numericFilters/)
* to Meilisearch compatible filter format.
*
* 'price:5.99 TO 100' becomes '"price" 5.99 TO 100'
*
* 'price = 5.99' becomes '"price"=5.99'
*
* Wrap the attribute between quotes.
* Escape backslash (\\) and quote (") characters.
*
* @param {string} filter
* @returns {string}
*/
function transformNumericFilter(filter: string): string {
// TODO: Warn users to not enable facet values escape for negative numbers.
// https://github.com/algolia/instantsearch/blob/da701529ed325bb7a1d782e80cb994711e20d94a/packages/instantsearch.js/src/lib/utils/escapeFacetValue.ts#L13-L21
const [attribute, operator, value] = filter.split(numericSplitRegExp)
const escapedAttribute = getValueWithEscapedBackslashesAndQuotes(attribute)
return `"${escapedAttribute.trim()}"${
operator === ':' ? ' ' : operator
}${value.trim()}`
}
/**
* Iterate over all filters.
* Return the filters in a Meilisearch compatible format.
*
* @param {SearchContext['facetFilters']} filters?
* @param {(filter: string) => string} transformCallback
* @param {SearchContext['facetFilters']} filters
* @returns {Filter}
*/
function transformFilters(filters?: SearchContext['facetFilters']): Filter {
if (typeof filters === 'string') {
return transformFilter(filters)
} else if (Array.isArray(filters))
return filters
.map((filter) => {
if (Array.isArray(filter))
return filter
.map((nestedFilter) => transformFilter(nestedFilter))
.filter((elem) => elem)
else {
return transformFilter(filter)
}
})
.filter((elem) => elem)
return []
function transformFilters(
transformCallback: (filter: string) => string,
filters: NonNullable<SearchContext['facetFilters']>
): Filter {
return typeof filters === 'string'
? transformCallback(filters)
: filters.map((filter) =>
typeof filter === 'string'
? transformCallback(filter)
: filter.map((nestedFilter) => transformCallback(nestedFilter))
)
}

@@ -50,44 +85,41 @@

*
* @param {Filter} filter
* @returns {Array}
* @param {Filter} [filter]
* @returns {Array|undefined}
*/
function filterToArray(filter: Filter): Array<string | string[]> {
// Filter is a string
if (filter === '') return []
else if (typeof filter === 'string') return [filter]
// Filter is either an array of strings, or an array of array of strings
return filter
function filterToArray(filter?: Filter): Array<string | string[]> | undefined {
return typeof filter === 'string' ? [filter] : filter
}
/**
* Merge facetFilters, numericFilters and filters together.
* Merge filters, transformedNumericFilters and transformedFacetFilters
* together.
*
* @param {Filter} facetFilters
* @param {Filter} numericFilters
* @param {string} filters
* @param {Filter} transformedNumericFilters
* @param {Filter} transformedFacetFilters
* @returns {Filter}
*/
function mergeFilters(
facetFilters: Filter,
numericFilters: Filter,
filters: string
filters?: string,
transformedNumericFilters?: Filter,
transformedFacetFilters?: Filter
): Filter {
const adaptedFilters = filters.trim()
const adaptedFacetFilters = filterToArray(facetFilters)
const adaptedNumericFilters = filterToArray(numericFilters)
const adaptedNumericFilters = filterToArray(transformedNumericFilters)
const adaptedFacetFilters = filterToArray(transformedFacetFilters)
const adaptedFilter = [
...adaptedFacetFilters,
...adaptedNumericFilters,
adaptedFilters,
]
const adaptedFilters: Filter = []
const cleanedFilters = adaptedFilter.filter((filter) => {
if (Array.isArray(filter)) {
return filter.length
}
return filter
})
return cleanedFilters
if (filters !== undefined) {
adaptedFilters.push(filters)
}
if (adaptedNumericFilters !== undefined) {
adaptedFilters.push(...adaptedNumericFilters)
}
if (adaptedFacetFilters !== undefined) {
adaptedFilters.push(...adaptedFacetFilters)
}
return adaptedFilters
}

@@ -109,10 +141,16 @@

): Filter {
const transformedFilter = transformFilters(facetFilters || [])
const transformedNumericFilter = transformFilters(numericFilters || [])
const transformedNumericFilters =
numericFilters !== undefined
? transformFilters(transformNumericFilter, numericFilters)
: numericFilters
const transformedFacetFilters =
facetFilters !== undefined
? transformFilters(transformFacetFilter, facetFilters)
: facetFilters
return mergeFilters(
transformedFilter,
transformedNumericFilter,
filters || ''
filters,
transformedNumericFilters,
transformedFacetFilters
)
}

@@ -6,2 +6,3 @@ import type {

MeiliSearchMultiSearchParams,
Mutable,
} from '../../types'

@@ -21,6 +22,3 @@

// There must be no filters
if (!placeholderSearch && !query && (!filter || filter.length === 0)) {
return false
}
return true
return !(!placeholderSearch && !query && (!filter || filter.length === 0))
}

@@ -72,7 +70,11 @@

export function MeiliParamsCreator(searchContext: SearchContext) {
const meiliSearchParams: any = {}
const {
query,
indexUid,
facets,
attributesToSnippet,
snippetEllipsisText,
filters,
numericFilters,
facetFilters,
attributesToRetrieve,

@@ -83,11 +85,8 @@ attributesToHighlight,

placeholderSearch,
query,
pagination,
sort,
pagination,
matchingStrategy,
filters,
numericFilters,
facetFilters,
indexUid,
restrictSearchableAttributes,
meiliSearchParams: overrideParams,
} = searchContext
const meiliSearchParams: MeiliSearchMultiSearchParams = { indexUid }

@@ -103,26 +102,28 @@ const meilisearchFilters = adaptFilters(filters, numericFilters, facetFilters)

},
addIndexUid() {
meiliSearchParams.indexUid = indexUid
},
addFacets() {
if (Array.isArray(facets)) {
meiliSearchParams.facets = facets
} else if (typeof facets === 'string') {
meiliSearchParams.facets = [facets]
const value = <Mutable<typeof facets>>facets
if (value !== undefined) {
// despite Instantsearch.js typing it as `string[]`,
// it still can send `string`
meiliSearchParams.facets = typeof value === 'string' ? [value] : value
}
},
addAttributesToCrop() {
if (attributesToSnippet) {
meiliSearchParams.attributesToCrop = attributesToSnippet
const value =
overrideParams?.attributesToCrop ??
<Mutable<typeof attributesToSnippet>>attributesToSnippet
if (value !== undefined) {
meiliSearchParams.attributesToCrop = value
}
},
addCropMarker() {
// Attributes To Crop marker
if (snippetEllipsisText != null) {
meiliSearchParams.cropMarker = snippetEllipsisText
addCropLength() {
const value = overrideParams?.cropLength
if (value !== undefined) {
meiliSearchParams.cropLength = value
}
},
addAttributesToRetrieve() {
if (attributesToRetrieve) {
meiliSearchParams.attributesToRetrieve = attributesToRetrieve
addCropMarker() {
const value = overrideParams?.cropMarker ?? snippetEllipsisText
if (value !== undefined) {
meiliSearchParams.cropMarker = value
}

@@ -135,18 +136,26 @@ },

},
addAttributesToRetrieve() {
const value =
overrideParams?.attributesToRetrieve ??
<Mutable<typeof attributesToRetrieve>>attributesToRetrieve
if (value !== undefined) {
meiliSearchParams.attributesToRetrieve = value
}
},
addAttributesToHighlight() {
meiliSearchParams.attributesToHighlight = attributesToHighlight || ['*']
meiliSearchParams.attributesToHighlight =
overrideParams?.attributesToHighlight ??
<Mutable<typeof attributesToHighlight>>attributesToHighlight ?? ['*']
},
addPreTag() {
if (highlightPreTag) {
meiliSearchParams.highlightPreTag = highlightPreTag
} else {
meiliSearchParams.highlightPreTag = '__ais-highlight__'
}
meiliSearchParams.highlightPreTag =
overrideParams?.highlightPreTag ??
highlightPreTag ??
'__ais-highlight__'
},
addPostTag() {
if (highlightPostTag) {
meiliSearchParams.highlightPostTag = highlightPostTag
} else {
meiliSearchParams.highlightPostTag = '__/ais-highlight__'
}
meiliSearchParams.highlightPostTag =
overrideParams?.highlightPostTag ??
highlightPostTag ??
'__/ais-highlight__'
},

@@ -195,4 +204,4 @@ addPagination() {

if (filter) {
if (meiliSearchParams.filter) {
if (filter !== undefined) {
if (Array.isArray(meiliSearchParams.filter)) {
meiliSearchParams.filter.unshift(filter)

@@ -204,7 +213,31 @@ } else {

},
addShowMatchesPosition() {
const value = overrideParams?.showMatchesPosition
if (value !== undefined) {
meiliSearchParams.showMatchesPosition = value
}
},
addMatchingStrategy() {
if (matchingStrategy) {
meiliSearchParams.matchingStrategy = matchingStrategy
const value = overrideParams?.matchingStrategy
if (value !== undefined) {
meiliSearchParams.matchingStrategy = value
}
},
addShowRankingScore() {
const value = overrideParams?.showRankingScore
if (value !== undefined) {
meiliSearchParams.showRankingScore = value
}
},
addAttributesToSearchOn() {
const value =
overrideParams?.attributesToSearchOn !== undefined
? overrideParams.attributesToSearchOn
: <Mutable<typeof restrictSearchableAttributes>>(
restrictSearchableAttributes
)
if (value !== undefined) {
meiliSearchParams.attributesToSearchOn = value
}
},
}

@@ -225,17 +258,20 @@ }

meilisearchParams.addQuery()
meilisearchParams.addIndexUid()
meilisearchParams.addFacets()
meilisearchParams.addAttributesToCrop()
meilisearchParams.addCropLength()
meilisearchParams.addCropMarker()
meilisearchParams.addFilters()
meilisearchParams.addAttributesToRetrieve()
meilisearchParams.addAttributesToHighlight()
meilisearchParams.addPreTag()
meilisearchParams.addPostTag()
meilisearchParams.addAttributesToRetrieve()
meilisearchParams.addAttributesToCrop()
meilisearchParams.addCropMarker()
meilisearchParams.addPagination()
meilisearchParams.addFilters()
meilisearchParams.addSort()
meilisearchParams.addGeoSearchFilter()
meilisearchParams.addShowMatchesPosition()
meilisearchParams.addMatchingStrategy()
meilisearchParams.addShowRankingScore()
meilisearchParams.addAttributesToSearchOn()
return meilisearchParams.getParams()
}

@@ -23,3 +23,2 @@ import {

meilisearchParams.addFacets()
meilisearchParams.addIndexUid()
meilisearchParams.addPagination()

@@ -26,0 +25,0 @@

import {
InstantMeiliSearchOptions,
InstantMeiliSearchConfig,
ApiKeyCallback,
} from '../../types'

@@ -32,6 +33,6 @@ import { isPureObject } from '../../utils/object'

* Resolves apiKey if it is a function
* @param {string | apiKeyCallback} apiKey
* @param {string | ApiKeyCallback} apiKey
* @returns {string} api key value
*/
export function getApiKey(apiKey: string | (() => string)): string {
export function getApiKey(apiKey: string | ApiKeyCallback): string {
// If apiKey is function, call it to get the apiKey

@@ -38,0 +39,0 @@ if (typeof apiKey === 'function') {

import { MeiliSearch } from 'meilisearch'
import {
InstantMeiliSearchOptions,
InstantMeiliSearchInstance,
AlgoliaSearchResponse,

@@ -13,2 +12,4 @@ AlgoliaMultipleQueriesQuery,

AlgoliaSearchForFacetValuesResponse,
InstantMeiliSearchObject,
ApiKeyCallback,
} from '../types'

@@ -36,12 +37,13 @@ import {

* Instantiate SearchClient required by instantsearch.js.
*
* @param {string} hostUrl
* @param {string | apiKeyCallback} apiKey
* @param {InstantMeiliSearchOptions={}} meiliSearchOptions
* @returns {InstantMeiliSearchInstance}
* @param {string | ApiKeyCallback} [apiKey='']
* @param {InstantMeiliSearchOptions} [instantMeiliSearchOptions={}]
* @returns {InstantMeiliSearchObject}
*/
export function instantMeiliSearch(
hostUrl: string,
apiKey: string | (() => string) = '',
apiKey: string | ApiKeyCallback = '',
instantMeiliSearchOptions: InstantMeiliSearchOptions = {}
): InstantMeiliSearchInstance {
): InstantMeiliSearchObject {
// Validate parameters

@@ -83,107 +85,120 @@ validateInstantMeiliSearchParams(hostUrl, apiKey, instantMeiliSearchOptions)

return {
clearCache: () => searchCache.clearCache(),
/**
* @param {readonlyAlgoliaMultipleQueriesQuery[]} instantSearchRequests
* @returns {Array}
*/
search: async function <T = Record<string, any>>(
instantSearchRequests: readonly AlgoliaMultipleQueriesQuery[]
): Promise<{ results: Array<AlgoliaSearchResponse<T>> }> {
try {
const meilisearchRequests = []
const instantSearchPagination: PaginationState[] = []
const initialFacetDistributionsRequests = []
setMeiliSearchParams: (params): void => {
const { meiliSearchParams } = instantMeiliSearchOptions
instantMeiliSearchOptions.meiliSearchParams =
meiliSearchParams === undefined
? params
: {
...meiliSearchParams,
...params,
}
},
searchClient: {
clearCache: () => searchCache.clearCache(),
/**
* @param {readonlyAlgoliaMultipleQueriesQuery[]} instantSearchRequests
* @returns {Array}
*/
search: async function <T = Record<string, any>>(
instantSearchRequests: readonly AlgoliaMultipleQueriesQuery[]
): Promise<{ results: Array<AlgoliaSearchResponse<T>> }> {
try {
const meilisearchRequests = []
const instantSearchPagination: PaginationState[] = []
const initialFacetDistributionsRequests = []
for (const searchRequest of instantSearchRequests) {
const searchContext: SearchContext = createSearchContext(
searchRequest,
instantMeiliSearchOptions
)
for (const searchRequest of instantSearchRequests) {
const searchContext: SearchContext = createSearchContext(
searchRequest,
instantMeiliSearchOptions
)
// Adapt the search parameters provided by instantsearch to
// search parameters that are compliant with Meilisearch
const meilisearchSearchQuery = adaptSearchParams(searchContext)
meilisearchRequests.push(meilisearchSearchQuery)
// Adapt the search parameters provided by instantsearch to
// search parameters that are compliant with Meilisearch
const meilisearchSearchQuery = adaptSearchParams(searchContext)
meilisearchRequests.push(meilisearchSearchQuery)
// Create a parameter without any filters to be able to store the default facet distribution
const defaultSearchQuery = getParametersWithoutFilters(searchContext)
initialFacetDistributionsRequests.push(defaultSearchQuery)
// Create a parameter without any filters to be able to store the default facet distribution
const defaultSearchQuery =
getParametersWithoutFilters(searchContext)
initialFacetDistributionsRequests.push(defaultSearchQuery)
// Keep information about the pagination parameters of instantsearch as
// they are needed to adapt the search response of Meilisearch
instantSearchPagination.push(searchContext.pagination)
}
// Keep information about the pagination parameters of instantsearch as
// they are needed to adapt the search response of Meilisearch
instantSearchPagination.push(searchContext.pagination)
}
initialFacetDistribution = await initFacetDistribution(
searchResolver,
initialFacetDistributionsRequests,
initialFacetDistribution
)
initialFacetDistribution = await initFacetDistribution(
searchResolver,
initialFacetDistributionsRequests,
initialFacetDistribution
)
// Search request to Meilisearch happens here
const meilisearchResults = await searchResolver.multiSearch(
meilisearchRequests,
instantSearchPagination // Create issue on pagination
)
// Search request to Meilisearch happens here
const meilisearchResults = await searchResolver.multiSearch(
meilisearchRequests,
instantSearchPagination // Create issue on pagination
)
// Fill the missing facet values if keepZeroFacets is true
initialFacetDistribution = fillMissingFacets(
initialFacetDistribution,
meilisearchResults
)
// Fill the missing facet values if keepZeroFacets is true
initialFacetDistribution = fillMissingFacets(
initialFacetDistribution,
meilisearchResults
)
const instantSearchResponse = adaptSearchResults<T>(
meilisearchResults,
initialFacetDistribution,
instantMeilisearchConfig
)
const instantSearchResponse = adaptSearchResults<T>(
meilisearchResults,
initialFacetDistribution,
instantMeilisearchConfig
)
return instantSearchResponse
} catch (e: any) {
console.error(e)
throw new Error(e)
}
},
searchForFacetValues: async function (
requests: AlgoliaSearchForFacetValuesRequests
): Promise<AlgoliaSearchForFacetValuesResponse[]> {
const results = []
for (const request of requests) {
const searchContext: SearchContext = createFacetSearchContext(
request,
instantMeiliSearchOptions
)
return instantSearchResponse
} catch (e: any) {
console.error(e)
throw new Error(e)
}
},
searchForFacetValues: async function (
requests: AlgoliaSearchForFacetValuesRequests
): Promise<AlgoliaSearchForFacetValuesResponse[]> {
const results = []
for (const request of requests) {
const searchContext: SearchContext = createFacetSearchContext(
request,
instantMeiliSearchOptions
)
const meilisearchSearchQuery = adaptSearchParams(searchContext)
const meilisearchSearchQuery = adaptSearchParams(searchContext)
const meilisearchRequest: any = {
...meilisearchSearchQuery,
facetQuery: request.params.facetQuery,
facetName: request.params.facetName,
}
const meilisearchRequest: any = {
...meilisearchSearchQuery,
facetQuery: request.params.facetQuery,
facetName: request.params.facetName,
}
delete meilisearchRequest.indexUid
delete meilisearchRequest.indexUid
const meilisearchResponse = await meilisearchClient
.index(searchContext.indexUid)
.searchForFacetValues(meilisearchRequest)
const meilisearchResponse = await meilisearchClient
.index(searchContext.indexUid)
.searchForFacetValues(meilisearchRequest)
const facetHits = meilisearchResponse.facetHits.map((facetHit) => ({
...facetHit,
// not currently supported
highlighted: facetHit.value,
}))
const facetHits = meilisearchResponse.facetHits.map((facetHit) => ({
...facetHit,
// not currently supported
highlighted: facetHit.value,
}))
const result = {
facetHits,
exhaustiveFacetsCount: false,
processingTimeMS: meilisearchResponse.processingTimeMs,
const result = {
facetHits,
exhaustiveFacetsCount: false,
processingTimeMS: meilisearchResponse.processingTimeMs,
}
results.push(result)
}
results.push(result)
}
return results
return results
},
},
}
}

@@ -1,1 +0,1 @@

export const PACKAGE_VERSION = '0.13.6'
export const PACKAGE_VERSION = '0.14.0'

@@ -12,2 +12,5 @@ import type { SearchClient } from 'instantsearch.js'

// Turns readonly types into mutable ones
export type Mutable<TVal> = { -readonly [TKey in keyof TVal]: TVal[TKey] }
export type { AlgoliaMultipleQueriesQuery, MultiSearchResult }

@@ -35,13 +38,24 @@ export type {

export type InstantSearchParams = AlgoliaMultipleQueriesQuery['params']
export type ApiKeyCallback = () => string
export const enum MatchingStrategies {
ALL = 'all',
LAST = 'last',
}
export type InstantSearchParams = NonNullable<
AlgoliaMultipleQueriesQuery['params']
>
export type InstantMeiliSearchOptions = Pick<
MeilisearchConfig,
'requestConfig' | 'httpClient'
> & {
export type OverridableMeiliSearchSearchParameters = Pick<
MeiliSearchMultiSearchParams,
| 'attributesToRetrieve'
| 'attributesToCrop'
| 'cropLength'
| 'cropMarker'
| 'attributesToHighlight'
| 'highlightPreTag'
| 'highlightPostTag'
| 'showMatchesPosition'
| 'matchingStrategy'
| 'showRankingScore'
| 'attributesToSearchOn'
>
type BaseInstantMeiliSearchOptions = {
placeholderSearch?: boolean

@@ -51,15 +65,20 @@ primaryKey?: string

clientAgents?: string[]
matchingStrategy?: MatchingStrategies
finitePagination?: boolean
meiliSearchParams?: OverridableMeiliSearchSearchParameters
}
export type InstantMeiliSearchConfig = {
placeholderSearch: boolean
keepZeroFacets: boolean
clientAgents: string[]
finitePagination: boolean
primaryKey?: string
matchingStrategy?: MatchingStrategies
}
export type InstantMeiliSearchOptions = Pick<
MeilisearchConfig,
'requestConfig' | 'httpClient'
> &
BaseInstantMeiliSearchOptions
export type InstantMeiliSearchConfig = Required<
Pick<
InstantMeiliSearchOptions,
'placeholderSearch' | 'keepZeroFacets' | 'clientAgents' | 'finitePagination'
>
> &
BaseInstantMeiliSearchOptions
export type SearchCacheInterface = {

@@ -92,13 +111,7 @@ getEntry: <T>(key: string) => T | undefined

export type SearchContext = Omit<InstantSearchParams, 'insideBoundingBox'> &
export type SearchContext = InstantMeiliSearchOptions &
InstantSearchParams & {
pagination: PaginationState
indexUid: string
placeholderSearch: boolean
keepZeroFacets: boolean
insideBoundingBox?: InsideBoundingBox
cropMarker?: string
sort?: string | string[]
primaryKey?: string
matchingStrategy?: MatchingStrategies
}

@@ -120,2 +133,7 @@

export type InstantMeiliSearchObject = {
setMeiliSearchParams: (params: OverridableMeiliSearchSearchParameters) => void
searchClient: InstantMeiliSearchInstance
}
export type MultiSearchResolver = {

@@ -122,0 +140,0 @@ multiSearch: (

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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