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

@meilisearch/instant-meilisearch

Package Overview
Dependencies
Maintainers
6
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.6.2 to 0.7.0

dist/types/contexts/index.d.ts

97

dist/instant-meilisearch.cjs.js

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

var emptySearch = {
hits: [],
query: '',
facetsDistribution: {},
limit: 0,
offset: 0,
exhaustiveNbHits: false,
nbHits: 0,
processingTimeMs: 0
};
/**

@@ -244,6 +254,14 @@ * @param {ResponseCacher} cache

return __awaiter(this, void 0, void 0, function () {
var key, entry, facetsCache, searchResponse;
var placeholderSearch, query, pagination, paginationCache, key, cachedResponse, facetsCache, searchResponse;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
placeholderSearch = searchContext.placeholderSearch, query = searchContext.query;
// query can be: empty string, undefined or null
// all of them are falsy's
if (!placeholderSearch && !query) {
return [2 /*return*/, emptySearch];
}
pagination = searchContext.pagination;
paginationCache = searchContext.finitePagination ? {} : pagination;
key = cache.formatKey([

@@ -253,9 +271,8 @@ searchParams,

searchContext.query,
paginationCache,
]);
entry = cache.getEntry(key);
// Request is cached.
if (entry)
return [2 /*return*/, entry
// Cache filters: todo components
];
cachedResponse = cache.getEntry(key);
// Check if specific request is already cached with its associated search response.
if (cachedResponse)
return [2 /*return*/, cachedResponse];
facetsCache = extractFacets(searchContext, searchParams);

@@ -546,9 +563,22 @@ return [4 /*yield*/, client

var query = searchContext.query;
var paginationTotalHits = searchContext.paginationTotalHits;
// Limit
if ((!placeholderSearch && query === '') || paginationTotalHits === 0) {
// Pagination
var pagination = searchContext.pagination;
// Limit based on pagination preferences
if ((!placeholderSearch && query === '') ||
pagination.paginationTotalHits === 0) {
meiliSearchParams.limit = 0;
}
else if (searchContext.finitePagination) {
meiliSearchParams.limit = pagination.paginationTotalHits;
}
else {
meiliSearchParams.limit = paginationTotalHits;
var limit = (pagination.page + 1) * pagination.hitsPerPage + 1;
// If the limit is bigger than the total hits accepted
// force the limit to that amount
if (limit > pagination.paginationTotalHits) {
meiliSearchParams.limit = pagination.paginationTotalHits;
}
else {
meiliSearchParams.limit = limit;
}
}

@@ -588,14 +618,2 @@ var sort = searchContext.sort;

}
/**
* @param {AlgoliaMultipleQueriesQuery} searchRequest
* @param {Context} options
* @returns {SearchContext}
*/
function createPaginationContext(searchContext) {
return {
paginationTotalHits: searchContext.paginationTotalHits || 200,
hitsPerPage: searchContext.hitsPerPage === undefined ? 20 : searchContext.hitsPerPage,
page: (searchContext === null || searchContext === void 0 ? void 0 : searchContext.page) || 0
};
}

@@ -807,2 +825,3 @@ /**

var facets = searchResponse.facetsDistribution;
var pagination = searchContext.pagination;
var exhaustiveFacetsCount = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.exhaustiveFacetsCount;

@@ -812,5 +831,4 @@ if (exhaustiveFacetsCount) {

}
var paginationContext = createPaginationContext(searchContext);
var nbPages = ceiledDivision(searchResponse.hits.length, paginationContext.hitsPerPage);
var hits = adaptHits(searchResponse.hits, searchContext, paginationContext);
var nbPages = ceiledDivision(searchResponse.hits.length, pagination.hitsPerPage);
var hits = adaptHits(searchResponse.hits, searchContext, pagination);
var exhaustiveNbHits = searchResponse.exhaustiveNbHits;

@@ -820,3 +838,3 @@ var nbHits = searchResponse.nbHits;

var query = searchResponse.query;
var hitsPerPage = paginationContext.hitsPerPage, page = paginationContext.page;
var hitsPerPage = pagination.hitsPerPage, page = pagination.page;
// Create response object compliant with InstantSearch

@@ -834,2 +852,16 @@ var adaptedSearchResponse = __assign({ index: searchContext.indexUid, hitsPerPage: hitsPerPage, page: page, facets: facets, nbPages: nbPages, exhaustiveNbHits: exhaustiveNbHits, nbHits: nbHits, processingTimeMS: processingTimeMs, query: query, hits: hits, params: '' }, searchResponseOptionals);

*/
function createPaginationContext(_a) {
var paginationTotalHits = _a.paginationTotalHits, hitsPerPage = _a.hitsPerPage, page = _a.page;
return {
paginationTotalHits: paginationTotalHits != null ? paginationTotalHits : 200,
hitsPerPage: hitsPerPage === undefined ? 20 : hitsPerPage,
page: page || 0
};
}
/**
* @param {AlgoliaMultipleQueriesQuery} searchRequest
* @param {Context} options
* @returns {SearchContext}
*/
function createSearchContext(searchRequest, options, defaultFacetDistribution) {

@@ -839,3 +871,8 @@ // Split index name and possible sorting rules

var instantSearchParams = searchRequest.params;
var searchContext = __assign(__assign(__assign({}, options), instantSearchParams), { sort: sortByArray.join(':') || '', indexUid: indexUid, defaultFacetDistribution: defaultFacetDistribution, placeholderSearch: !options.placeholderSearch, paginationTotalHits: options.paginationTotalHits != null ? options.paginationTotalHits : 200, keepZeroFacets: !!options.keepZeroFacets });
var pagination = createPaginationContext({
paginationTotalHits: options.paginationTotalHits,
hitsPerPage: instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.hitsPerPage,
page: instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.page
});
var searchContext = __assign(__assign(__assign({}, options), instantSearchParams), { sort: sortByArray.join(':') || '', indexUid: indexUid, pagination: pagination, defaultFacetDistribution: defaultFacetDistribution, placeholderSearch: options.placeholderSearch !== false, keepZeroFacets: !!options.keepZeroFacets, finitePagination: !!options.finitePagination });
return searchContext;

@@ -895,4 +932,4 @@ }

var defaultFacetDistribution = {};
var meilisearchClient = new meilisearch.MeiliSearch({ host: hostUrl, apiKey: apiKey });
return {
MeiliSearchClient: new meilisearch.MeiliSearch({ host: hostUrl, apiKey: apiKey }),
/**

@@ -912,3 +949,3 @@ * @param {readonlyAlgoliaMultipleQueriesQuery[]} instantSearchRequests

adaptedSearchRequest = adaptSearchParams(searchContext);
return [4 /*yield*/, searchResolver.searchResponse(searchContext, adaptedSearchRequest, this.MeiliSearchClient)
return [4 /*yield*/, searchResolver.searchResponse(searchContext, adaptedSearchRequest, meilisearchClient)
// Cache first facets distribution of the instantMeilisearch instance

@@ -915,0 +952,0 @@ // Needed to add in the facetsDistribution the fields that were not returned

@@ -15,3 +15,3 @@ "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}).apply(this,arguments)};

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function n(t,e,n,r){return new(n||(n=Promise))((function(i,a){function o(t){try{s(r.next(t))}catch(t){a(t)}}function u(t){try{s(r.throw(t))}catch(t){a(t)}}function s(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,u)}s((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(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function i(t,e){for(var n=0,r=e.length,i=t.length;n<r;n++,i++)t[i]=e[n];return t}function a(t){return"string"==typeof t||t instanceof String}function o(t){return t.replace(/:(.*)/i,'="$1"')}var u=function(t){var e=t.match(/([^=]*)="?([^\\"]*)"?$/);return e?(e[0],[{filterName:e[1],value:e[2]}]):[]};function s(t){var n=function(t){return"string"==typeof t?u(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return u(t)})):u(t)})).flat(2):[]}(t);return n.filter((function(t){return void 0!==t})).reduce((function(t,n){var r,a=n.filterName,o=n.value,u=t[a]||[];return t=e(e({},t),((r={})[a]=i(i([],u),[o]),r))}),{})}function c(t,n){return t.keepZeroFacets?(r=t.defaultFacetDistribution,Object.keys(r).reduce((function(t,n){var i,a=Object.keys(r[n]);return e(e({},t),((i={})[n]=a,i))}),{})):s(null==n?void 0:n.filter);var r}function l(t){return{searchResponse:function(e,i,a){return n(this,void 0,void 0,(function(){var n,o,u,s;return r(this,(function(r){switch(r.label){case 0:return n=t.formatKey([i,e.indexUid,e.query]),(o=t.getEntry(n))?[2,o]:(u=c(e,i),[4,a.index(e.indexUid).search(e.query,i)]);case 1:return(s=r.sent()).facetsDistribution=function(t,e){if(e=e||{},t&&Object.keys(t).length>0)for(var n in t){e[n]||(e[n]={});for(var r=0,i=t[n];r<i.length;r++){var a=i[r];Object.keys(e[n]).includes(a)||(e[n][a]=0)}}return e}(u,s.facetsDistribution),t.setEntry(n,s),[2,s]}}))}))}}}function f(t){return 180*t/Math.PI}function h(t){return t*Math.PI/180}function p(t){if(t){var e,n,r=t.insideBoundingBox,i=t.aroundLatLng,a=t.aroundRadius,o=t.minimumAroundRadius;if(i&&(e=i),null==a&&null==o||(n=null!=a?a:o),r&&"string"==typeof r){var u=r.split(","),s=u[0],c=u[1],l=u[2],p=u[3],d=[parseFloat(s),parseFloat(c),parseFloat(l),parseFloat(p)],g=d[0],v=d[1],y=d[2],m=d[3];n=function(t,e,n,r){var i=t*Math.PI/180,a=n*Math.PI/180,o=(n-t)*Math.PI/180,u=(r-e)*Math.PI/180,s=Math.sin(o/2)*Math.sin(o/2)+Math.cos(i)*Math.cos(a)*Math.sin(u/2)*Math.sin(u/2);return 2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s))*6371e3}(g,v,y,m)/2,e=function(t,e,n,r){t=h(t),e=h(e);var i=Math.cos(t)*Math.cos(e),a=Math.cos(t)*Math.sin(e),o=Math.sin(t);n=h(n),r=h(r);var u=i+Math.cos(n)*Math.cos(r),s=a+Math.cos(n)*Math.sin(r),c=o+Math.sin(n),l=Math.sqrt(u*u+s*s),p=Math.atan2(s,u),d=Math.atan2(c,l);return e<r||e>r&&e>Math.PI&&r<-Math.PI?(d+=Math.PI,p+=Math.PI):(d=f(d),p=f(p)),Math.abs(u)<Math.pow(10,-9)&&Math.abs(s)<Math.pow(10,-9)&&Math.abs(c)<Math.pow(10,-9)&&(d=0,p=0),"".concat(d,",").concat(p)}(g,v,y,m)}if(null!=e&&null!=n){var b=e.split(","),M=b[0],P=b[1];return M=Number.parseFloat(M).toFixed(5),P=Number.parseFloat(P).toFixed(5),{filter:"_geoRadius(".concat(M,", ").concat(P,", ").concat(n,")")}}}}function d(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 g(t){return""===t?[]:"string"==typeof t?[t]:t}function v(t,e,n){return function(t,e,n){var r=n.trim(),a=g(t),o=g(e);return i(i(i([],a),o),[r]).filter((function(t){return Array.isArray(t)?t.length:t}))}(d(n||[]),d(e||[]),t||"")}function y(t){var e={},n=null==t?void 0:t.facets;(null==n?void 0:n.length)&&(e.facetsDistribution=n);var r=null==t?void 0:t.attributesToSnippet;r&&(e.attributesToCrop=r);var i=null==t?void 0:t.attributesToRetrieve;i&&(e.attributesToRetrieve=i);var a=v(null==t?void 0:t.filters,null==t?void 0:t.numericFilters,null==t?void 0:t.facetFilters);a.length&&(e.filter=a),i&&(e.attributesToCrop=i),e.attributesToHighlight=(null==t?void 0:t.attributesToHighlight)||["*"];var o=t.placeholderSearch,u=t.query,s=t.paginationTotalHits;e.limit=!o&&""===u||0===s?0:s;var c=t.sort;(null==c?void 0:c.length)&&(e.sort=[c]);var l=p(function(t){var e={},n=t.aroundLatLng,r=t.aroundLatLngViaIP,i=t.aroundRadius,a=t.aroundPrecision,o=t.minimumAroundRadius,u=t.insideBoundingBox,s=t.insidePolygon;return n&&(e.aroundLatLng=n),r&&console.warn("instant-meilisearch: `aroundLatLngViaIP` is not supported."),i&&(e.aroundRadius=i),a&&console.warn("instant-meilisearch: `aroundPrecision` is not supported.\n See this discussion to track its implementation https://github.com/meilisearch/product/discussions/264"),o&&(e.minimumAroundRadius=o),u&&(e.insideBoundingBox=u),s&&console.warn("instant-meilisearch: `insidePolygon` is not implented in instant-meilisearch."),e}(t));return(null==l?void 0:l.filter)&&(e.filter?e.filter.unshift(l.filter):e.filter=[l.filter]),e}function m(t,e,n){return"string"==typeof t?function(t,e,n){return void 0===e&&(e="__ais-highlight__"),void 0===n&&(n="__/ais-highlight__"),(a(t)?t:JSON.stringify(t)).replace(/<em>/g,e).replace(/<\/em>/g,n)}(t,e,n):void 0===t?JSON.stringify(null):JSON.stringify(t)}function b(t,e,n){return t._formatted?Object.keys(t._formatted).reduce((function(r,i){var a=t._formatted[i];return r[i]=function(t,e,n){return Array.isArray(t)?t.map((function(t){return{value:m(t,e,n)}})):{value:m(t,e,n)}}(a,e,n),r}),{}):t._formatted}function M(t,e,n){var r,i=e;return a(e)&&t.toString().length>(r=e,r.replace(/<em>/g,"").replace(/<\/em>/g,"")).length&&(e[0]===e[0].toLowerCase()&&!1===e.startsWith("<em>")&&(i="".concat(n).concat(e.trim())),!1==!!e.match(/[.!?]$/)&&(i="".concat(e.trim()).concat(n))),i}function P(t,e,n){return n&&"string"==typeof e?Array.isArray(t)?t.map((function(t){return M(t,e,n)})):M(t,e,n):e}function w(t,e){var n=null==e?void 0:e.attributesToSnippet,r=null==e?void 0:e.snippetEllipsisText,i=null==e?void 0:e.highlightPreTag,a=null==e?void 0:e.highlightPostTag;return t._formatted?{_highlightResult:b(t,i,a),_snippetResult:b(function(t,e,n){var r=t._formatted,i=t._formatted;if(void 0===e)return t;var a=e.map((function(t){return t.split(":")[0]}));if(a.includes("*"))for(var o in r)i[o]=P(t[o],r[o],n);else for(var u=0,s=a;u<s.length;u++)i[o=s[u]]=P(t[o],r[o],n);return t._formatted=i,t}(t,n,r),i,a)}:{}}function _(t,n,r){var i=n.primaryKey,a=r.hitsPerPage,o=function(t,e,n){if(n<0)throw new TypeError('Value too small for "hitsPerPage" parameter, expected integer between 0 and 9223372036854775807');var r=e*n;return t.slice(r,r+n)}(t,r.page,a).map((function(t){if(Object.keys(t).length>0){t._formatted,t._matchesInfo;var r=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","_matchesInfo"]);return e(e(e({},r),w(t,n)),i&&{objectID:t[i]})}return t}));return o=function(t){for(var e=0;e<t.length;e++)t[e]._geo&&(t[e]._geoloc={lat:t[e]._geo.lat,lng:t[e]._geo.lng},t[e].objectID="".concat(e+1e6*Math.random()),delete t[e]._geo);return t}(o)}function x(t,n){var r={},i=t.facetsDistribution,a=null==t?void 0:t.exhaustiveFacetsCount;a&&(r.exhaustiveFacetsCount=a);var o,u,s=function(t){return{paginationTotalHits:t.paginationTotalHits||200,hitsPerPage:void 0===t.hitsPerPage?20:t.hitsPerPage,page:(null==t?void 0:t.page)||0}}(n),c=(o=t.hits.length,(u=s.hitsPerPage)>0?Math.ceil(o/u):0),l=_(t.hits,n,s),f=t.exhaustiveNbHits,h=t.nbHits,p=t.processingTimeMs,d=t.query,g=s.hitsPerPage,v=s.page;return{results:[e({index:n.indexUid,hitsPerPage:g,page:v,facets:i,nbPages:c,exhaustiveNbHits:f,nbHits:h,processingTimeMS:p,query:d,hits:l,params:""},r)]}}function O(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(n){return e[t]}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,n){e[t]=JSON.stringify(n)}}}exports.instantMeiliSearch=function(i,a,o){void 0===a&&(a=""),void 0===o&&(o={});var u=l(O()),s={};return{MeiliSearchClient:new t.MeiliSearch({host:i,apiKey:a}),search:function(t){return n(this,void 0,void 0,(function(){var n,i,a,c,l;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),n=t[0],i=function(t,n,r){var i=t.indexName.split(":"),a=i[0],o=i.slice(1),u=t.params;return e(e(e({},n),u),{sort:o.join(":")||"",indexUid:a,defaultFacetDistribution:r,placeholderSearch:!n.placeholderSearch,paginationTotalHits:null!=n.paginationTotalHits?n.paginationTotalHits:200,keepZeroFacets:!!n.keepZeroFacets})}(n,o,s),a=y(i),[4,u.searchResponse(i,a,this.MeiliSearchClient)];case 1:return c=r.sent(),s=function(t,e){return""===e.query&&0===Object.keys(t).length?e.facetsDistribution:t}(s,c),[2,x(c,i)];case 2:throw l=r.sent(),console.error(l),new Error(l);case 3:return[2]}}))}))},searchForFacetValues:function(t){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,new Promise((function(t,e){e(new Error("SearchForFacetValues is not compatible with Meilisearch")),t([])}))];case 1:return[2,t.sent()]}}))}))}}};
***************************************************************************** */function n(t,e,n,r){return new(n||(n=Promise))((function(i,a){function o(t){try{s(r.next(t))}catch(t){a(t)}}function u(t){try{s(r.throw(t))}catch(t){a(t)}}function s(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,u)}s((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(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function i(t,e){for(var n=0,r=e.length,i=t.length;n<r;n++,i++)t[i]=e[n];return t}function a(t){return"string"==typeof t||t instanceof String}function o(t){return t.replace(/:(.*)/i,'="$1"')}var u=function(t){var e=t.match(/([^=]*)="?([^\\"]*)"?$/);return e?(e[0],[{filterName:e[1],value:e[2]}]):[]};function s(t){var n=function(t){return"string"==typeof t?u(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return u(t)})):u(t)})).flat(2):[]}(t);return n.filter((function(t){return void 0!==t})).reduce((function(t,n){var r,a=n.filterName,o=n.value,u=t[a]||[];return t=e(e({},t),((r={})[a]=i(i([],u),[o]),r))}),{})}function c(t,n){return t.keepZeroFacets?(r=t.defaultFacetDistribution,Object.keys(r).reduce((function(t,n){var i,a=Object.keys(r[n]);return e(e({},t),((i={})[n]=a,i))}),{})):s(null==n?void 0:n.filter);var r}var l={hits:[],query:"",facetsDistribution:{},limit:0,offset:0,exhaustiveNbHits:!1,nbHits:0,processingTimeMs:0};function f(t){return{searchResponse:function(e,i,a){return n(this,void 0,void 0,(function(){var n,o,u,s,f,h,p,d;return r(this,(function(r){switch(r.label){case 0:return n=e.placeholderSearch,o=e.query,n||o?(u=e.pagination,s=e.finitePagination?{}:u,f=t.formatKey([i,e.indexUid,e.query,s]),(h=t.getEntry(f))?[2,h]:(p=c(e,i),[4,a.index(e.indexUid).search(e.query,i)])):[2,l];case 1:return(d=r.sent()).facetsDistribution=function(t,e){if(e=e||{},t&&Object.keys(t).length>0)for(var n in t){e[n]||(e[n]={});for(var r=0,i=t[n];r<i.length;r++){var a=i[r];Object.keys(e[n]).includes(a)||(e[n][a]=0)}}return e}(p,d.facetsDistribution),t.setEntry(f,d),[2,d]}}))}))}}}function h(t){return 180*t/Math.PI}function p(t){return t*Math.PI/180}function d(t){if(t){var e,n,r=t.insideBoundingBox,i=t.aroundLatLng,a=t.aroundRadius,o=t.minimumAroundRadius;if(i&&(e=i),null==a&&null==o||(n=null!=a?a:o),r&&"string"==typeof r){var u=r.split(","),s=u[0],c=u[1],l=u[2],f=u[3],d=[parseFloat(s),parseFloat(c),parseFloat(l),parseFloat(f)],g=d[0],v=d[1],y=d[2],m=d[3];n=function(t,e,n,r){var i=t*Math.PI/180,a=n*Math.PI/180,o=(n-t)*Math.PI/180,u=(r-e)*Math.PI/180,s=Math.sin(o/2)*Math.sin(o/2)+Math.cos(i)*Math.cos(a)*Math.sin(u/2)*Math.sin(u/2);return 2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s))*6371e3}(g,v,y,m)/2,e=function(t,e,n,r){t=p(t),e=p(e);var i=Math.cos(t)*Math.cos(e),a=Math.cos(t)*Math.sin(e),o=Math.sin(t);n=p(n),r=p(r);var u=i+Math.cos(n)*Math.cos(r),s=a+Math.cos(n)*Math.sin(r),c=o+Math.sin(n),l=Math.sqrt(u*u+s*s),f=Math.atan2(s,u),d=Math.atan2(c,l);return e<r||e>r&&e>Math.PI&&r<-Math.PI?(d+=Math.PI,f+=Math.PI):(d=h(d),f=h(f)),Math.abs(u)<Math.pow(10,-9)&&Math.abs(s)<Math.pow(10,-9)&&Math.abs(c)<Math.pow(10,-9)&&(d=0,f=0),"".concat(d,",").concat(f)}(g,v,y,m)}if(null!=e&&null!=n){var b=e.split(","),P=b[0],M=b[1];return P=Number.parseFloat(P).toFixed(5),M=Number.parseFloat(M).toFixed(5),{filter:"_geoRadius(".concat(P,", ").concat(M,", ").concat(n,")")}}}}function g(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 v(t){return""===t?[]:"string"==typeof t?[t]:t}function y(t,e,n){return function(t,e,n){var r=n.trim(),a=v(t),o=v(e);return i(i(i([],a),o),[r]).filter((function(t){return Array.isArray(t)?t.length:t}))}(g(n||[]),g(e||[]),t||"")}function m(t){var e={},n=null==t?void 0:t.facets;(null==n?void 0:n.length)&&(e.facetsDistribution=n);var r=null==t?void 0:t.attributesToSnippet;r&&(e.attributesToCrop=r);var i=null==t?void 0:t.attributesToRetrieve;i&&(e.attributesToRetrieve=i);var a=y(null==t?void 0:t.filters,null==t?void 0:t.numericFilters,null==t?void 0:t.facetFilters);a.length&&(e.filter=a),i&&(e.attributesToCrop=i),e.attributesToHighlight=(null==t?void 0:t.attributesToHighlight)||["*"];var o=t.placeholderSearch,u=t.query,s=t.pagination;if(!o&&""===u||0===s.paginationTotalHits)e.limit=0;else if(t.finitePagination)e.limit=s.paginationTotalHits;else{var c=(s.page+1)*s.hitsPerPage+1;c>s.paginationTotalHits?e.limit=s.paginationTotalHits:e.limit=c}var l=t.sort;(null==l?void 0:l.length)&&(e.sort=[l]);var f=d(function(t){var e={},n=t.aroundLatLng,r=t.aroundLatLngViaIP,i=t.aroundRadius,a=t.aroundPrecision,o=t.minimumAroundRadius,u=t.insideBoundingBox,s=t.insidePolygon;return n&&(e.aroundLatLng=n),r&&console.warn("instant-meilisearch: `aroundLatLngViaIP` is not supported."),i&&(e.aroundRadius=i),a&&console.warn("instant-meilisearch: `aroundPrecision` is not supported.\n See this discussion to track its implementation https://github.com/meilisearch/product/discussions/264"),o&&(e.minimumAroundRadius=o),u&&(e.insideBoundingBox=u),s&&console.warn("instant-meilisearch: `insidePolygon` is not implented in instant-meilisearch."),e}(t));return(null==f?void 0:f.filter)&&(e.filter?e.filter.unshift(f.filter):e.filter=[f.filter]),e}function b(t,e,n){return"string"==typeof t?function(t,e,n){return void 0===e&&(e="__ais-highlight__"),void 0===n&&(n="__/ais-highlight__"),(a(t)?t:JSON.stringify(t)).replace(/<em>/g,e).replace(/<\/em>/g,n)}(t,e,n):void 0===t?JSON.stringify(null):JSON.stringify(t)}function P(t,e,n){return t._formatted?Object.keys(t._formatted).reduce((function(r,i){var a=t._formatted[i];return r[i]=function(t,e,n){return Array.isArray(t)?t.map((function(t){return{value:b(t,e,n)}})):{value:b(t,e,n)}}(a,e,n),r}),{}):t._formatted}function M(t,e,n){var r,i=e;return a(e)&&t.toString().length>(r=e,r.replace(/<em>/g,"").replace(/<\/em>/g,"")).length&&(e[0]===e[0].toLowerCase()&&!1===e.startsWith("<em>")&&(i="".concat(n).concat(e.trim())),!1==!!e.match(/[.!?]$/)&&(i="".concat(e.trim()).concat(n))),i}function w(t,e,n){return n&&"string"==typeof e?Array.isArray(t)?t.map((function(t){return M(t,e,n)})):M(t,e,n):e}function _(t,e){var n=null==e?void 0:e.attributesToSnippet,r=null==e?void 0:e.snippetEllipsisText,i=null==e?void 0:e.highlightPreTag,a=null==e?void 0:e.highlightPostTag;return t._formatted?{_highlightResult:P(t,i,a),_snippetResult:P(function(t,e,n){var r=t._formatted,i=t._formatted;if(void 0===e)return t;var a=e.map((function(t){return t.split(":")[0]}));if(a.includes("*"))for(var o in r)i[o]=w(t[o],r[o],n);else for(var u=0,s=a;u<s.length;u++)i[o=s[u]]=w(t[o],r[o],n);return t._formatted=i,t}(t,n,r),i,a)}:{}}function x(t,n,r){var i=n.primaryKey,a=r.hitsPerPage,o=function(t,e,n){if(n<0)throw new TypeError('Value too small for "hitsPerPage" parameter, expected integer between 0 and 9223372036854775807');var r=e*n;return t.slice(r,r+n)}(t,r.page,a).map((function(t){if(Object.keys(t).length>0){t._formatted,t._matchesInfo;var r=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","_matchesInfo"]);return e(e(e({},r),_(t,n)),i&&{objectID:t[i]})}return t}));return o=function(t){for(var e=0;e<t.length;e++)t[e]._geo&&(t[e]._geoloc={lat:t[e]._geo.lat,lng:t[e]._geo.lng},t[e].objectID="".concat(e+1e6*Math.random()),delete t[e]._geo);return t}(o)}function O(t,n){var r={},i=t.facetsDistribution,a=n.pagination,o=null==t?void 0:t.exhaustiveFacetsCount;o&&(r.exhaustiveFacetsCount=o);var u,s,c=(u=t.hits.length,(s=a.hitsPerPage)>0?Math.ceil(u/s):0),l=x(t.hits,n,a),f=t.exhaustiveNbHits,h=t.nbHits,p=t.processingTimeMs,d=t.query,g=a.hitsPerPage,v=a.page;return{results:[e({index:n.indexUid,hitsPerPage:g,page:v,facets:i,nbPages:c,exhaustiveNbHits:f,nbHits:h,processingTimeMS:p,query:d,hits:l,params:""},r)]}}function T(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(n){return e[t]}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,n){e[t]=JSON.stringify(n)}}}exports.instantMeiliSearch=function(i,a,o){void 0===a&&(a=""),void 0===o&&(o={});var u=f(T()),s={},c=new t.MeiliSearch({host:i,apiKey:a});return{search:function(t){return n(this,void 0,void 0,(function(){var n,i,a,l,f;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),n=t[0],i=function(t,n,r){var i=t.indexName.split(":"),a=i[0],o=i.slice(1),u=t.params,s=function(t){var e=t.paginationTotalHits,n=t.hitsPerPage;return{paginationTotalHits:null!=e?e:200,hitsPerPage:void 0===n?20:n,page:t.page||0}}({paginationTotalHits:n.paginationTotalHits,hitsPerPage:null==u?void 0:u.hitsPerPage,page:null==u?void 0:u.page});return e(e(e({},n),u),{sort:o.join(":")||"",indexUid:a,pagination:s,defaultFacetDistribution:r,placeholderSearch:!1!==n.placeholderSearch,keepZeroFacets:!!n.keepZeroFacets,finitePagination:!!n.finitePagination})}(n,o,s),a=m(i),[4,u.searchResponse(i,a,c)];case 1:return l=r.sent(),s=function(t,e){return""===e.query&&0===Object.keys(t).length?e.facetsDistribution:t}(s,l),[2,O(l,i)];case 2:throw f=r.sent(),console.error(f),new Error(f);case 3:return[2]}}))}))},searchForFacetValues:function(t){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,new Promise((function(t,e){e(new Error("SearchForFacetValues is not compatible with Meilisearch")),t([])}))];case 1:return[2,t.sent()]}}))}))}}};
//# sourceMappingURL=instant-meilisearch.cjs.min.js.map

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

var emptySearch = {
hits: [],
query: '',
facetsDistribution: {},
limit: 0,
offset: 0,
exhaustiveNbHits: false,
nbHits: 0,
processingTimeMs: 0
};
/**

@@ -240,6 +250,14 @@ * @param {ResponseCacher} cache

return __awaiter(this, void 0, void 0, function () {
var key, entry, facetsCache, searchResponse;
var placeholderSearch, query, pagination, paginationCache, key, cachedResponse, facetsCache, searchResponse;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
placeholderSearch = searchContext.placeholderSearch, query = searchContext.query;
// query can be: empty string, undefined or null
// all of them are falsy's
if (!placeholderSearch && !query) {
return [2 /*return*/, emptySearch];
}
pagination = searchContext.pagination;
paginationCache = searchContext.finitePagination ? {} : pagination;
key = cache.formatKey([

@@ -249,9 +267,8 @@ searchParams,

searchContext.query,
paginationCache,
]);
entry = cache.getEntry(key);
// Request is cached.
if (entry)
return [2 /*return*/, entry
// Cache filters: todo components
];
cachedResponse = cache.getEntry(key);
// Check if specific request is already cached with its associated search response.
if (cachedResponse)
return [2 /*return*/, cachedResponse];
facetsCache = extractFacets(searchContext, searchParams);

@@ -542,9 +559,22 @@ return [4 /*yield*/, client

var query = searchContext.query;
var paginationTotalHits = searchContext.paginationTotalHits;
// Limit
if ((!placeholderSearch && query === '') || paginationTotalHits === 0) {
// Pagination
var pagination = searchContext.pagination;
// Limit based on pagination preferences
if ((!placeholderSearch && query === '') ||
pagination.paginationTotalHits === 0) {
meiliSearchParams.limit = 0;
}
else if (searchContext.finitePagination) {
meiliSearchParams.limit = pagination.paginationTotalHits;
}
else {
meiliSearchParams.limit = paginationTotalHits;
var limit = (pagination.page + 1) * pagination.hitsPerPage + 1;
// If the limit is bigger than the total hits accepted
// force the limit to that amount
if (limit > pagination.paginationTotalHits) {
meiliSearchParams.limit = pagination.paginationTotalHits;
}
else {
meiliSearchParams.limit = limit;
}
}

@@ -584,14 +614,2 @@ var sort = searchContext.sort;

}
/**
* @param {AlgoliaMultipleQueriesQuery} searchRequest
* @param {Context} options
* @returns {SearchContext}
*/
function createPaginationContext(searchContext) {
return {
paginationTotalHits: searchContext.paginationTotalHits || 200,
hitsPerPage: searchContext.hitsPerPage === undefined ? 20 : searchContext.hitsPerPage,
page: (searchContext === null || searchContext === void 0 ? void 0 : searchContext.page) || 0
};
}

@@ -803,2 +821,3 @@ /**

var facets = searchResponse.facetsDistribution;
var pagination = searchContext.pagination;
var exhaustiveFacetsCount = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.exhaustiveFacetsCount;

@@ -808,5 +827,4 @@ if (exhaustiveFacetsCount) {

}
var paginationContext = createPaginationContext(searchContext);
var nbPages = ceiledDivision(searchResponse.hits.length, paginationContext.hitsPerPage);
var hits = adaptHits(searchResponse.hits, searchContext, paginationContext);
var nbPages = ceiledDivision(searchResponse.hits.length, pagination.hitsPerPage);
var hits = adaptHits(searchResponse.hits, searchContext, pagination);
var exhaustiveNbHits = searchResponse.exhaustiveNbHits;

@@ -816,3 +834,3 @@ var nbHits = searchResponse.nbHits;

var query = searchResponse.query;
var hitsPerPage = paginationContext.hitsPerPage, page = paginationContext.page;
var hitsPerPage = pagination.hitsPerPage, page = pagination.page;
// Create response object compliant with InstantSearch

@@ -830,2 +848,16 @@ var adaptedSearchResponse = __assign({ index: searchContext.indexUid, hitsPerPage: hitsPerPage, page: page, facets: facets, nbPages: nbPages, exhaustiveNbHits: exhaustiveNbHits, nbHits: nbHits, processingTimeMS: processingTimeMs, query: query, hits: hits, params: '' }, searchResponseOptionals);

*/
function createPaginationContext(_a) {
var paginationTotalHits = _a.paginationTotalHits, hitsPerPage = _a.hitsPerPage, page = _a.page;
return {
paginationTotalHits: paginationTotalHits != null ? paginationTotalHits : 200,
hitsPerPage: hitsPerPage === undefined ? 20 : hitsPerPage,
page: page || 0
};
}
/**
* @param {AlgoliaMultipleQueriesQuery} searchRequest
* @param {Context} options
* @returns {SearchContext}
*/
function createSearchContext(searchRequest, options, defaultFacetDistribution) {

@@ -835,3 +867,8 @@ // Split index name and possible sorting rules

var instantSearchParams = searchRequest.params;
var searchContext = __assign(__assign(__assign({}, options), instantSearchParams), { sort: sortByArray.join(':') || '', indexUid: indexUid, defaultFacetDistribution: defaultFacetDistribution, placeholderSearch: !options.placeholderSearch, paginationTotalHits: options.paginationTotalHits != null ? options.paginationTotalHits : 200, keepZeroFacets: !!options.keepZeroFacets });
var pagination = createPaginationContext({
paginationTotalHits: options.paginationTotalHits,
hitsPerPage: instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.hitsPerPage,
page: instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.page
});
var searchContext = __assign(__assign(__assign({}, options), instantSearchParams), { sort: sortByArray.join(':') || '', indexUid: indexUid, pagination: pagination, defaultFacetDistribution: defaultFacetDistribution, placeholderSearch: options.placeholderSearch !== false, keepZeroFacets: !!options.keepZeroFacets, finitePagination: !!options.finitePagination });
return searchContext;

@@ -891,4 +928,4 @@ }

var defaultFacetDistribution = {};
var meilisearchClient = new MeiliSearch({ host: hostUrl, apiKey: apiKey });
return {
MeiliSearchClient: new MeiliSearch({ host: hostUrl, apiKey: apiKey }),
/**

@@ -908,3 +945,3 @@ * @param {readonlyAlgoliaMultipleQueriesQuery[]} instantSearchRequests

adaptedSearchRequest = adaptSearchParams(searchContext);
return [4 /*yield*/, searchResolver.searchResponse(searchContext, adaptedSearchRequest, this.MeiliSearchClient)
return [4 /*yield*/, searchResolver.searchResponse(searchContext, adaptedSearchRequest, meilisearchClient)
// Cache first facets distribution of the instantMeilisearch instance

@@ -911,0 +948,0 @@ // Needed to add in the facetsDistribution the fields that were not returned

@@ -15,3 +15,3 @@ import{MeiliSearch as t}from"meilisearch";

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var n=function(){return(n=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var i in n=arguments[e])Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i]);return t}).apply(this,arguments)};function e(t,n,e,r){return new(e||(e=Promise))((function(i,a){function o(t){try{s(r.next(t))}catch(t){a(t)}}function u(t){try{s(r.throw(t))}catch(t){a(t)}}function s(t){var n;t.done?i(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(o,u)}s((r=r.apply(t,n||[])).next())}))}function r(t,n){var e,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(a){return function(u){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;o;)try{if(e=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=n.call(t,o)}catch(t){a=[6,t],r=0}finally{e=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function i(t,n){for(var e=0,r=n.length,i=t.length;e<r;e++,i++)t[i]=n[e];return t}function a(t){return"string"==typeof t||t instanceof String}function o(t){return t.replace(/:(.*)/i,'="$1"')}var u=function(t){var n=t.match(/([^=]*)="?([^\\"]*)"?$/);return n?(n[0],[{filterName:n[1],value:n[2]}]):[]};function s(t){var e=function(t){return"string"==typeof t?u(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return u(t)})):u(t)})).flat(2):[]}(t);return e.filter((function(t){return void 0!==t})).reduce((function(t,e){var r,a=e.filterName,o=e.value,u=t[a]||[];return t=n(n({},t),((r={})[a]=i(i([],u),[o]),r))}),{})}function c(t,e){return t.keepZeroFacets?(r=t.defaultFacetDistribution,Object.keys(r).reduce((function(t,e){var i,a=Object.keys(r[e]);return n(n({},t),((i={})[e]=a,i))}),{})):s(null==e?void 0:e.filter);var r}function l(t){return{searchResponse:function(n,i,a){return e(this,void 0,void 0,(function(){var e,o,u,s;return r(this,(function(r){switch(r.label){case 0:return e=t.formatKey([i,n.indexUid,n.query]),(o=t.getEntry(e))?[2,o]:(u=c(n,i),[4,a.index(n.indexUid).search(n.query,i)]);case 1:return(s=r.sent()).facetsDistribution=function(t,n){if(n=n||{},t&&Object.keys(t).length>0)for(var e in t){n[e]||(n[e]={});for(var r=0,i=t[e];r<i.length;r++){var a=i[r];Object.keys(n[e]).includes(a)||(n[e][a]=0)}}return n}(u,s.facetsDistribution),t.setEntry(e,s),[2,s]}}))}))}}}function f(t){return 180*t/Math.PI}function h(t){return t*Math.PI/180}function p(t){if(t){var n,e,r=t.insideBoundingBox,i=t.aroundLatLng,a=t.aroundRadius,o=t.minimumAroundRadius;if(i&&(n=i),null==a&&null==o||(e=null!=a?a:o),r&&"string"==typeof r){var u=r.split(","),s=u[0],c=u[1],l=u[2],p=u[3],d=[parseFloat(s),parseFloat(c),parseFloat(l),parseFloat(p)],g=d[0],v=d[1],y=d[2],m=d[3];e=function(t,n,e,r){var i=t*Math.PI/180,a=e*Math.PI/180,o=(e-t)*Math.PI/180,u=(r-n)*Math.PI/180,s=Math.sin(o/2)*Math.sin(o/2)+Math.cos(i)*Math.cos(a)*Math.sin(u/2)*Math.sin(u/2);return 2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s))*6371e3}(g,v,y,m)/2,n=function(t,n,e,r){t=h(t),n=h(n);var i=Math.cos(t)*Math.cos(n),a=Math.cos(t)*Math.sin(n),o=Math.sin(t);e=h(e),r=h(r);var u=i+Math.cos(e)*Math.cos(r),s=a+Math.cos(e)*Math.sin(r),c=o+Math.sin(e),l=Math.sqrt(u*u+s*s),p=Math.atan2(s,u),d=Math.atan2(c,l);return n<r||n>r&&n>Math.PI&&r<-Math.PI?(d+=Math.PI,p+=Math.PI):(d=f(d),p=f(p)),Math.abs(u)<Math.pow(10,-9)&&Math.abs(s)<Math.pow(10,-9)&&Math.abs(c)<Math.pow(10,-9)&&(d=0,p=0),"".concat(d,",").concat(p)}(g,v,y,m)}if(null!=n&&null!=e){var b=n.split(","),M=b[0],P=b[1];return M=Number.parseFloat(M).toFixed(5),P=Number.parseFloat(P).toFixed(5),{filter:"_geoRadius(".concat(M,", ").concat(P,", ").concat(e,")")}}}}function d(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 g(t){return""===t?[]:"string"==typeof t?[t]:t}function v(t,n,e){return function(t,n,e){var r=e.trim(),a=g(t),o=g(n);return i(i(i([],a),o),[r]).filter((function(t){return Array.isArray(t)?t.length:t}))}(d(e||[]),d(n||[]),t||"")}function y(t){var n={},e=null==t?void 0:t.facets;(null==e?void 0:e.length)&&(n.facetsDistribution=e);var r=null==t?void 0:t.attributesToSnippet;r&&(n.attributesToCrop=r);var i=null==t?void 0:t.attributesToRetrieve;i&&(n.attributesToRetrieve=i);var a=v(null==t?void 0:t.filters,null==t?void 0:t.numericFilters,null==t?void 0:t.facetFilters);a.length&&(n.filter=a),i&&(n.attributesToCrop=i),n.attributesToHighlight=(null==t?void 0:t.attributesToHighlight)||["*"];var o=t.placeholderSearch,u=t.query,s=t.paginationTotalHits;n.limit=!o&&""===u||0===s?0:s;var c=t.sort;(null==c?void 0:c.length)&&(n.sort=[c]);var l=p(function(t){var n={},e=t.aroundLatLng,r=t.aroundLatLngViaIP,i=t.aroundRadius,a=t.aroundPrecision,o=t.minimumAroundRadius,u=t.insideBoundingBox,s=t.insidePolygon;return e&&(n.aroundLatLng=e),r&&console.warn("instant-meilisearch: `aroundLatLngViaIP` is not supported."),i&&(n.aroundRadius=i),a&&console.warn("instant-meilisearch: `aroundPrecision` is not supported.\n See this discussion to track its implementation https://github.com/meilisearch/product/discussions/264"),o&&(n.minimumAroundRadius=o),u&&(n.insideBoundingBox=u),s&&console.warn("instant-meilisearch: `insidePolygon` is not implented in instant-meilisearch."),n}(t));return(null==l?void 0:l.filter)&&(n.filter?n.filter.unshift(l.filter):n.filter=[l.filter]),n}function m(t,n,e){return"string"==typeof t?function(t,n,e){return void 0===n&&(n="__ais-highlight__"),void 0===e&&(e="__/ais-highlight__"),(a(t)?t:JSON.stringify(t)).replace(/<em>/g,n).replace(/<\/em>/g,e)}(t,n,e):void 0===t?JSON.stringify(null):JSON.stringify(t)}function b(t,n,e){return t._formatted?Object.keys(t._formatted).reduce((function(r,i){var a=t._formatted[i];return r[i]=function(t,n,e){return Array.isArray(t)?t.map((function(t){return{value:m(t,n,e)}})):{value:m(t,n,e)}}(a,n,e),r}),{}):t._formatted}function M(t,n,e){var r,i=n;return a(n)&&t.toString().length>(r=n,r.replace(/<em>/g,"").replace(/<\/em>/g,"")).length&&(n[0]===n[0].toLowerCase()&&!1===n.startsWith("<em>")&&(i="".concat(e).concat(n.trim())),!1==!!n.match(/[.!?]$/)&&(i="".concat(n.trim()).concat(e))),i}function P(t,n,e){return e&&"string"==typeof n?Array.isArray(t)?t.map((function(t){return M(t,n,e)})):M(t,n,e):n}function w(t,n){var e=null==n?void 0:n.attributesToSnippet,r=null==n?void 0:n.snippetEllipsisText,i=null==n?void 0:n.highlightPreTag,a=null==n?void 0:n.highlightPostTag;return t._formatted?{_highlightResult:b(t,i,a),_snippetResult:b(function(t,n,e){var r=t._formatted,i=t._formatted;if(void 0===n)return t;var a=n.map((function(t){return t.split(":")[0]}));if(a.includes("*"))for(var o in r)i[o]=P(t[o],r[o],e);else for(var u=0,s=a;u<s.length;u++)i[o=s[u]]=P(t[o],r[o],e);return t._formatted=i,t}(t,e,r),i,a)}:{}}function _(t,e,r){var i=e.primaryKey,a=r.hitsPerPage,o=function(t,n,e){if(e<0)throw new TypeError('Value too small for "hitsPerPage" parameter, expected integer between 0 and 9223372036854775807');var r=n*e;return t.slice(r,r+e)}(t,r.page,a).map((function(t){if(Object.keys(t).length>0){t._formatted,t._matchesInfo;var r=function(t,n){var e={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&n.indexOf(r)<0&&(e[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)n.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(e[r[i]]=t[r[i]])}return e}(t,["_formatted","_matchesInfo"]);return n(n(n({},r),w(t,e)),i&&{objectID:t[i]})}return t}));return o=function(t){for(var n=0;n<t.length;n++)t[n]._geo&&(t[n]._geoloc={lat:t[n]._geo.lat,lng:t[n]._geo.lng},t[n].objectID="".concat(n+1e6*Math.random()),delete t[n]._geo);return t}(o)}function x(t,e){var r={},i=t.facetsDistribution,a=null==t?void 0:t.exhaustiveFacetsCount;a&&(r.exhaustiveFacetsCount=a);var o,u,s=function(t){return{paginationTotalHits:t.paginationTotalHits||200,hitsPerPage:void 0===t.hitsPerPage?20:t.hitsPerPage,page:(null==t?void 0:t.page)||0}}(e),c=(o=t.hits.length,(u=s.hitsPerPage)>0?Math.ceil(o/u):0),l=_(t.hits,e,s),f=t.exhaustiveNbHits,h=t.nbHits,p=t.processingTimeMs,d=t.query,g=s.hitsPerPage,v=s.page;return{results:[n({index:e.indexUid,hitsPerPage:g,page:v,facets:i,nbPages:c,exhaustiveNbHits:f,nbHits:h,processingTimeMS:p,query:d,hits:l,params:""},r)]}}function O(t){void 0===t&&(t={});var n=t;return{getEntry:function(t){if(n[t])try{return JSON.parse(n[t])}catch(e){return n[t]}},formatKey:function(t){return t.reduce((function(t,n){return t+JSON.stringify(n)}),"")},setEntry:function(t,e){n[t]=JSON.stringify(e)}}}function S(i,a,o){void 0===a&&(a=""),void 0===o&&(o={});var u=l(O()),s={};return{MeiliSearchClient:new t({host:i,apiKey:a}),search:function(t){return e(this,void 0,void 0,(function(){var e,i,a,c,l;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),e=t[0],i=function(t,e,r){var i=t.indexName.split(":"),a=i[0],o=i.slice(1),u=t.params;return n(n(n({},e),u),{sort:o.join(":")||"",indexUid:a,defaultFacetDistribution:r,placeholderSearch:!e.placeholderSearch,paginationTotalHits:null!=e.paginationTotalHits?e.paginationTotalHits:200,keepZeroFacets:!!e.keepZeroFacets})}(e,o,s),a=y(i),[4,u.searchResponse(i,a,this.MeiliSearchClient)];case 1:return c=r.sent(),s=function(t,n){return""===n.query&&0===Object.keys(t).length?n.facetsDistribution:t}(s,c),[2,x(c,i)];case 2:throw l=r.sent(),console.error(l),new Error(l);case 3:return[2]}}))}))},searchForFacetValues:function(t){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,new Promise((function(t,n){n(new Error("SearchForFacetValues is not compatible with Meilisearch")),t([])}))];case 1:return[2,t.sent()]}}))}))}}}export{S as instantMeiliSearch};
***************************************************************************** */var n=function(){return(n=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var i in n=arguments[e])Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i]);return t}).apply(this,arguments)};function e(t,n,e,r){return new(e||(e=Promise))((function(i,a){function o(t){try{s(r.next(t))}catch(t){a(t)}}function u(t){try{s(r.throw(t))}catch(t){a(t)}}function s(t){var n;t.done?i(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(o,u)}s((r=r.apply(t,n||[])).next())}))}function r(t,n){var e,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(a){return function(u){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;o;)try{if(e=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=n.call(t,o)}catch(t){a=[6,t],r=0}finally{e=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function i(t,n){for(var e=0,r=n.length,i=t.length;e<r;e++,i++)t[i]=n[e];return t}function a(t){return"string"==typeof t||t instanceof String}function o(t){return t.replace(/:(.*)/i,'="$1"')}var u=function(t){var n=t.match(/([^=]*)="?([^\\"]*)"?$/);return n?(n[0],[{filterName:n[1],value:n[2]}]):[]};function s(t){var e=function(t){return"string"==typeof t?u(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return u(t)})):u(t)})).flat(2):[]}(t);return e.filter((function(t){return void 0!==t})).reduce((function(t,e){var r,a=e.filterName,o=e.value,u=t[a]||[];return t=n(n({},t),((r={})[a]=i(i([],u),[o]),r))}),{})}function c(t,e){return t.keepZeroFacets?(r=t.defaultFacetDistribution,Object.keys(r).reduce((function(t,e){var i,a=Object.keys(r[e]);return n(n({},t),((i={})[e]=a,i))}),{})):s(null==e?void 0:e.filter);var r}var l={hits:[],query:"",facetsDistribution:{},limit:0,offset:0,exhaustiveNbHits:!1,nbHits:0,processingTimeMs:0};function f(t){return{searchResponse:function(n,i,a){return e(this,void 0,void 0,(function(){var e,o,u,s,f,h,p,g;return r(this,(function(r){switch(r.label){case 0:return e=n.placeholderSearch,o=n.query,e||o?(u=n.pagination,s=n.finitePagination?{}:u,f=t.formatKey([i,n.indexUid,n.query,s]),(h=t.getEntry(f))?[2,h]:(p=c(n,i),[4,a.index(n.indexUid).search(n.query,i)])):[2,l];case 1:return(g=r.sent()).facetsDistribution=function(t,n){if(n=n||{},t&&Object.keys(t).length>0)for(var e in t){n[e]||(n[e]={});for(var r=0,i=t[e];r<i.length;r++){var a=i[r];Object.keys(n[e]).includes(a)||(n[e][a]=0)}}return n}(p,g.facetsDistribution),t.setEntry(f,g),[2,g]}}))}))}}}function h(t){return 180*t/Math.PI}function p(t){return t*Math.PI/180}function g(t){if(t){var n,e,r=t.insideBoundingBox,i=t.aroundLatLng,a=t.aroundRadius,o=t.minimumAroundRadius;if(i&&(n=i),null==a&&null==o||(e=null!=a?a:o),r&&"string"==typeof r){var u=r.split(","),s=u[0],c=u[1],l=u[2],f=u[3],g=[parseFloat(s),parseFloat(c),parseFloat(l),parseFloat(f)],d=g[0],v=g[1],m=g[2],y=g[3];e=function(t,n,e,r){var i=t*Math.PI/180,a=e*Math.PI/180,o=(e-t)*Math.PI/180,u=(r-n)*Math.PI/180,s=Math.sin(o/2)*Math.sin(o/2)+Math.cos(i)*Math.cos(a)*Math.sin(u/2)*Math.sin(u/2);return 2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s))*6371e3}(d,v,m,y)/2,n=function(t,n,e,r){t=p(t),n=p(n);var i=Math.cos(t)*Math.cos(n),a=Math.cos(t)*Math.sin(n),o=Math.sin(t);e=p(e),r=p(r);var u=i+Math.cos(e)*Math.cos(r),s=a+Math.cos(e)*Math.sin(r),c=o+Math.sin(e),l=Math.sqrt(u*u+s*s),f=Math.atan2(s,u),g=Math.atan2(c,l);return n<r||n>r&&n>Math.PI&&r<-Math.PI?(g+=Math.PI,f+=Math.PI):(g=h(g),f=h(f)),Math.abs(u)<Math.pow(10,-9)&&Math.abs(s)<Math.pow(10,-9)&&Math.abs(c)<Math.pow(10,-9)&&(g=0,f=0),"".concat(g,",").concat(f)}(d,v,m,y)}if(null!=n&&null!=e){var b=n.split(","),P=b[0],M=b[1];return P=Number.parseFloat(P).toFixed(5),M=Number.parseFloat(M).toFixed(5),{filter:"_geoRadius(".concat(P,", ").concat(M,", ").concat(e,")")}}}}function d(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 v(t){return""===t?[]:"string"==typeof t?[t]:t}function m(t,n,e){return function(t,n,e){var r=e.trim(),a=v(t),o=v(n);return i(i(i([],a),o),[r]).filter((function(t){return Array.isArray(t)?t.length:t}))}(d(e||[]),d(n||[]),t||"")}function y(t){var n={},e=null==t?void 0:t.facets;(null==e?void 0:e.length)&&(n.facetsDistribution=e);var r=null==t?void 0:t.attributesToSnippet;r&&(n.attributesToCrop=r);var i=null==t?void 0:t.attributesToRetrieve;i&&(n.attributesToRetrieve=i);var a=m(null==t?void 0:t.filters,null==t?void 0:t.numericFilters,null==t?void 0:t.facetFilters);a.length&&(n.filter=a),i&&(n.attributesToCrop=i),n.attributesToHighlight=(null==t?void 0:t.attributesToHighlight)||["*"];var o=t.placeholderSearch,u=t.query,s=t.pagination;if(!o&&""===u||0===s.paginationTotalHits)n.limit=0;else if(t.finitePagination)n.limit=s.paginationTotalHits;else{var c=(s.page+1)*s.hitsPerPage+1;c>s.paginationTotalHits?n.limit=s.paginationTotalHits:n.limit=c}var l=t.sort;(null==l?void 0:l.length)&&(n.sort=[l]);var f=g(function(t){var n={},e=t.aroundLatLng,r=t.aroundLatLngViaIP,i=t.aroundRadius,a=t.aroundPrecision,o=t.minimumAroundRadius,u=t.insideBoundingBox,s=t.insidePolygon;return e&&(n.aroundLatLng=e),r&&console.warn("instant-meilisearch: `aroundLatLngViaIP` is not supported."),i&&(n.aroundRadius=i),a&&console.warn("instant-meilisearch: `aroundPrecision` is not supported.\n See this discussion to track its implementation https://github.com/meilisearch/product/discussions/264"),o&&(n.minimumAroundRadius=o),u&&(n.insideBoundingBox=u),s&&console.warn("instant-meilisearch: `insidePolygon` is not implented in instant-meilisearch."),n}(t));return(null==f?void 0:f.filter)&&(n.filter?n.filter.unshift(f.filter):n.filter=[f.filter]),n}function b(t,n,e){return"string"==typeof t?function(t,n,e){return void 0===n&&(n="__ais-highlight__"),void 0===e&&(e="__/ais-highlight__"),(a(t)?t:JSON.stringify(t)).replace(/<em>/g,n).replace(/<\/em>/g,e)}(t,n,e):void 0===t?JSON.stringify(null):JSON.stringify(t)}function P(t,n,e){return t._formatted?Object.keys(t._formatted).reduce((function(r,i){var a=t._formatted[i];return r[i]=function(t,n,e){return Array.isArray(t)?t.map((function(t){return{value:b(t,n,e)}})):{value:b(t,n,e)}}(a,n,e),r}),{}):t._formatted}function M(t,n,e){var r,i=n;return a(n)&&t.toString().length>(r=n,r.replace(/<em>/g,"").replace(/<\/em>/g,"")).length&&(n[0]===n[0].toLowerCase()&&!1===n.startsWith("<em>")&&(i="".concat(e).concat(n.trim())),!1==!!n.match(/[.!?]$/)&&(i="".concat(n.trim()).concat(e))),i}function w(t,n,e){return e&&"string"==typeof n?Array.isArray(t)?t.map((function(t){return M(t,n,e)})):M(t,n,e):n}function _(t,n){var e=null==n?void 0:n.attributesToSnippet,r=null==n?void 0:n.snippetEllipsisText,i=null==n?void 0:n.highlightPreTag,a=null==n?void 0:n.highlightPostTag;return t._formatted?{_highlightResult:P(t,i,a),_snippetResult:P(function(t,n,e){var r=t._formatted,i=t._formatted;if(void 0===n)return t;var a=n.map((function(t){return t.split(":")[0]}));if(a.includes("*"))for(var o in r)i[o]=w(t[o],r[o],e);else for(var u=0,s=a;u<s.length;u++)i[o=s[u]]=w(t[o],r[o],e);return t._formatted=i,t}(t,e,r),i,a)}:{}}function x(t,e,r){var i=e.primaryKey,a=r.hitsPerPage,o=function(t,n,e){if(e<0)throw new TypeError('Value too small for "hitsPerPage" parameter, expected integer between 0 and 9223372036854775807');var r=n*e;return t.slice(r,r+e)}(t,r.page,a).map((function(t){if(Object.keys(t).length>0){t._formatted,t._matchesInfo;var r=function(t,n){var e={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&n.indexOf(r)<0&&(e[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)n.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(e[r[i]]=t[r[i]])}return e}(t,["_formatted","_matchesInfo"]);return n(n(n({},r),_(t,e)),i&&{objectID:t[i]})}return t}));return o=function(t){for(var n=0;n<t.length;n++)t[n]._geo&&(t[n]._geoloc={lat:t[n]._geo.lat,lng:t[n]._geo.lng},t[n].objectID="".concat(n+1e6*Math.random()),delete t[n]._geo);return t}(o)}function O(t,e){var r={},i=t.facetsDistribution,a=e.pagination,o=null==t?void 0:t.exhaustiveFacetsCount;o&&(r.exhaustiveFacetsCount=o);var u,s,c=(u=t.hits.length,(s=a.hitsPerPage)>0?Math.ceil(u/s):0),l=x(t.hits,e,a),f=t.exhaustiveNbHits,h=t.nbHits,p=t.processingTimeMs,g=t.query,d=a.hitsPerPage,v=a.page;return{results:[n({index:e.indexUid,hitsPerPage:d,page:v,facets:i,nbPages:c,exhaustiveNbHits:f,nbHits:h,processingTimeMS:p,query:g,hits:l,params:""},r)]}}function T(t){void 0===t&&(t={});var n=t;return{getEntry:function(t){if(n[t])try{return JSON.parse(n[t])}catch(e){return n[t]}},formatKey:function(t){return t.reduce((function(t,n){return t+JSON.stringify(n)}),"")},setEntry:function(t,e){n[t]=JSON.stringify(e)}}}function F(i,a,o){void 0===a&&(a=""),void 0===o&&(o={});var u=f(T()),s={},c=new t({host:i,apiKey:a});return{search:function(t){return e(this,void 0,void 0,(function(){var e,i,a,l,f;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),e=t[0],i=function(t,e,r){var i=t.indexName.split(":"),a=i[0],o=i.slice(1),u=t.params,s=function(t){var n=t.paginationTotalHits,e=t.hitsPerPage;return{paginationTotalHits:null!=n?n:200,hitsPerPage:void 0===e?20:e,page:t.page||0}}({paginationTotalHits:e.paginationTotalHits,hitsPerPage:null==u?void 0:u.hitsPerPage,page:null==u?void 0:u.page});return n(n(n({},e),u),{sort:o.join(":")||"",indexUid:a,pagination:s,defaultFacetDistribution:r,placeholderSearch:!1!==e.placeholderSearch,keepZeroFacets:!!e.keepZeroFacets,finitePagination:!!e.finitePagination})}(e,o,s),a=y(i),[4,u.searchResponse(i,a,c)];case 1:return l=r.sent(),s=function(t,n){return""===n.query&&0===Object.keys(t).length?n.facetsDistribution:t}(s,l),[2,O(l,i)];case 2:throw f=r.sent(),console.error(f),new Error(f);case 3:return[2]}}))}))},searchForFacetValues:function(t){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,new Promise((function(t,n){n(new Error("SearchForFacetValues is not compatible with Meilisearch")),t([])}))];case 1:return[2,t.sent()]}}))}))}}}export{F as instantMeiliSearch};
//# sourceMappingURL=instant-meilisearch.esm.min.js.map

@@ -28,3 +28,3 @@ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).window=t.window||{})}(this,(function(t){"use strict";

***************************************************************************** */
var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,n)};function n(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r=function(){return(r=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}).apply(this,arguments)};function i(t,e,n,r){function i(t){return t instanceof n?t:new n((function(e){e(t)}))}return new(n||(n=Promise))((function(n,s){function o(t){try{a(r.next(t))}catch(t){s(t)}}function u(t){try{a(r.throw(t))}catch(t){s(t)}}function a(t){t.done?n(t.value):i(t.value).then(o,u)}a((r=r.apply(t,e||[])).next())}))}function s(t,e){var n,r,i,s,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(t){return function(e){return a([t,e])}}function a(s){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,r=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],r=0}finally{n=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}}var o=function(t){function e(n,r,i,s){var o,u,a,c=this;return(c=t.call(this,n)||this).name="MeiliSearchCommunicationError",c.type="MeiliSearchCommunicationError",r instanceof Response&&(c.message=r.statusText,c.statusCode=r.status),r instanceof Error&&(c.errno=r.errno,c.code=r.code),s?(c.stack=s,c.stack=null===(o=c.stack)||void 0===o?void 0:o.replace(/(TypeError|FetchError)/,c.name),c.stack=null===(u=c.stack)||void 0===u?void 0:u.replace("Failed to fetch","request to ".concat(i," failed, reason: connect ECONNREFUSED")),c.stack=null===(a=c.stack)||void 0===a?void 0:a.replace("Not Found","Not Found: ".concat(i))):Error.captureStackTrace&&Error.captureStackTrace(c,e),c}return n(e,t),e}(Error),u=function(t){function e(e,n){var r=t.call(this,e.message)||this;return r.name="MeiliSearchApiError",r.code=e.code,r.type=e.type,r.link=e.link,r.message=e.message,r.httpStatus=n,Object.setPrototypeOf(r,u.prototype),Error.captureStackTrace&&Error.captureStackTrace(r,u),r}return n(e,t),e}(Error);function a(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:if(t.ok)return[3,5];e=void 0,n.label=1;case 1:return n.trys.push([1,3,,4]),[4,t.json()];case 2:return e=n.sent(),[3,4];case 3:throw n.sent(),new o(t.statusText,t,t.url);case 4:throw new u(e,t.status);case 5:return[2,t]}}))}))}function c(t,e,n){if("MeiliSearchApiError"!==t.type)throw new o(t.message,t,n,e);throw t}var h=function(t){function e(n){var r=t.call(this,n)||this;return r.name="MeiliSearchError",r.type="MeiliSearchError",Error.captureStackTrace&&Error.captureStackTrace(r,e),r}return n(e,t),e}(Error),l=function(t){function e(n){var r=t.call(this,n)||this;return r.name="MeiliSearchTimeOutError",r.type=r.constructor.name,Error.captureStackTrace&&Error.captureStackTrace(r,e),r}return n(e,t),e}(Error);function d(t){return Object.entries(t).reduce((function(t,e){var n=e[0],r=e[1];return void 0!==r&&(t[n]=r),t}),{})}function f(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,new Promise((function(e){return setTimeout(e,t)}))];case 1:return[2,e.sent()]}}))}))}function p(t){return t.startsWith("https://")||t.startsWith("http://")?t:"http://".concat(t)}function v(t){return t.endsWith("/")||(t+="/"),t}function y(t){try{return t=v(t=p(t))}catch(t){throw new h("The provided host is not valid.")}}var b=function(){function t(t){this.headers=Object.assign({},t.headers||{}),this.headers["Content-Type"]="application/json",t.apiKey&&(this.headers.Authorization="Bearer ".concat(t.apiKey));try{var e=y(t.host);this.url=new URL(e)}catch(t){throw new h("The provided host is not valid.")}}return t.prototype.request=function(t){var e=t.method,n=t.url,o=t.params,u=t.body,h=t.config;return i(this,void 0,void 0,(function(){var t,i,l,d,f;return s(this,(function(s){switch(s.label){case 0:t=new URL(n,this.url),o&&(i=new URLSearchParams,Object.keys(o).filter((function(t){return null!==o[t]})).map((function(t){return i.set(t,o[t])})),t.search=i.toString()),s.label=1;case 1:return s.trys.push([1,4,,5]),[4,fetch(t.toString(),r(r({},h),{method:e,body:JSON.stringify(u),headers:this.headers})).then((function(t){return a(t)}))];case 2:return[4,s.sent().text()];case 3:l=s.sent();try{return[2,JSON.parse(l)]}catch(t){return[2]}return[3,5];case 4:return d=s.sent(),f=d.stack,c(d,f,t.toString()),[3,5];case 5:return[2]}}))}))},t.prototype.get=function(t,e,n){return i(this,void 0,void 0,(function(){return s(this,(function(r){switch(r.label){case 0:return[4,this.request({method:"GET",url:t,params:e,config:n})];case 1:return[2,r.sent()]}}))}))},t.prototype.post=function(t,e,n,r){return i(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"POST",url:t,body:e,params:n,config:r})];case 1:return[2,i.sent()]}}))}))},t.prototype.put=function(t,e,n,r){return i(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"PUT",url:t,body:e,params:n,config:r})];case 1:return[2,i.sent()]}}))}))},t.prototype.patch=function(t,e,n,r){return i(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"PATCH",url:t,body:e,params:n,config:r})];case 1:return[2,i.sent()]}}))}))},t.prototype.delete=function(t,e,n,r){return i(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"DELETE",url:t,body:e,params:n,config:r})];case 1:return[2,i.sent()]}}))}))},t}(),g=function(){function t(t){this.httpRequest=new b(t)}return t.prototype.getClientTask=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="tasks/".concat(t),[4,this.httpRequest.get(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.getClientTasks=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="tasks",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getIndexTask=function(t,e){return i(this,void 0,void 0,(function(){var n;return s(this,(function(r){switch(r.label){case 0:return n="indexes/".concat(t,"/tasks/").concat(e),[4,this.httpRequest.get(n)];case 1:return[2,r.sent()]}}))}))},t.prototype.getIndexTasks=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(t,"/tasks"),[4,this.httpRequest.get(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.waitForClientTask=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,o=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return i(this,void 0,void 0,(function(){var e,n;return s(this,(function(r){switch(r.label){case 0:e=Date.now(),r.label=1;case 1:return Date.now()-e<o?[4,this.getClientTask(t)]:[3,4];case 2:return n=r.sent(),["enqueued","processing"].includes(n.status)?[4,f(a)]:[2,n];case 3:return r.sent(),[3,1];case 4:throw new l("timeout of ".concat(o,"ms has exceeded on process ").concat(t," when waiting a task to be resolved."))}}))}))},t.prototype.waitForClientTasks=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,o=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return i(this,void 0,void 0,(function(){var e,n,r,i,u;return s(this,(function(s){switch(s.label){case 0:e=[],n=0,r=t,s.label=1;case 1:return n<r.length?(i=r[n],[4,this.waitForClientTask(i,{timeOutMs:o,intervalMs:a})]):[3,4];case 2:u=s.sent(),e.push(u),s.label=3;case 3:return n++,[3,1];case 4:return[2,{results:e}]}}))}))},t.prototype.waitForIndexTask=function(t,e,n){var r=void 0===n?{}:n,o=r.timeOutMs,u=void 0===o?5e3:o,a=r.intervalMs,c=void 0===a?50:a;return i(this,void 0,void 0,(function(){var n,r;return s(this,(function(i){switch(i.label){case 0:n=Date.now(),i.label=1;case 1:return Date.now()-n<u?[4,this.getIndexTask(t,e)]:[3,4];case 2:return r=i.sent(),["enqueued","processing"].includes(r.status)?[4,f(c)]:[2,r];case 3:return i.sent(),[3,1];case 4:throw new l("timeout of ".concat(u,"ms has exceeded on process ").concat(e," when waiting for pending update to resolve."))}}))}))},t}(),w=function(){function t(t,e,n){this.uid=e,this.primaryKey=n,this.httpRequest=new b(t),this.tasks=new g(t)}return t.prototype.search=function(t,e,n){return i(this,void 0,void 0,(function(){var i;return s(this,(function(s){switch(s.label){case 0:return i="indexes/".concat(this.uid,"/search"),[4,this.httpRequest.post(i,d(r(r({},e),{q:t})),void 0,n)];case 1:return[2,s.sent()]}}))}))},t.prototype.searchGet=function(t,e,n){return i(this,void 0,void 0,(function(){var i,o,u;return s(this,(function(s){switch(s.label){case 0:return i="indexes/".concat(this.uid,"/search"),o=function(t){if("string"==typeof t)return t;if(Array.isArray(t))throw new h("The filter query parameter should be in string format when using searchGet")},u=r(r({q:t},e),{filter:o(null==e?void 0:e.filter),sort:(null==e?void 0:e.sort)?e.sort.join(","):void 0,facetsDistribution:(null==e?void 0:e.facetsDistribution)?e.facetsDistribution.join(","):void 0,attributesToRetrieve:(null==e?void 0:e.attributesToRetrieve)?e.attributesToRetrieve.join(","):void 0,attributesToCrop:(null==e?void 0:e.attributesToCrop)?e.attributesToCrop.join(","):void 0,attributesToHighlight:(null==e?void 0:e.attributesToHighlight)?e.attributesToHighlight.join(","):void 0}),[4,this.httpRequest.get(i,d(u),n)];case 1:return[2,s.sent()]}}))}))},t.prototype.getRawInfo=function(){return i(this,void 0,void 0,(function(){var t,e;return s(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid),[4,this.httpRequest.get(t)];case 1:return e=n.sent(),this.primaryKey=e.primaryKey,[2,e]}}))}))},t.prototype.fetchInfo=function(){return i(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.getRawInfo()];case 1:return t.sent(),[2,this]}}))}))},t.prototype.fetchPrimaryKey=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t=this,[4,this.getRawInfo()];case 1:return t.primaryKey=e.sent().primaryKey,[2,this.primaryKey]}}))}))},t.create=function(t,e,n){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){var i;return s(this,(function(s){return i="indexes",[2,new b(n).post(i,r(r({},e),{uid:t}))]}))}))},t.prototype.update=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid),[4,this.httpRequest.put(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.delete=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getTasks=function(){return i(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.tasks.getIndexTasks(this.uid)];case 1:return[2,t.sent()]}}))}))},t.prototype.getTask=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.tasks.getIndexTask(this.uid,t)];case 1:return[2,e.sent()]}}))}))},t.prototype.waitForTasks=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,o=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.tasks.waitForClientTasks(t,{timeOutMs:o,intervalMs:a})];case 1:return[2,e.sent()]}}))}))},t.prototype.waitForTask=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,o=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.tasks.waitForClientTask(t,{timeOutMs:o,intervalMs:a})];case 1:return[2,e.sent()]}}))}))},t.prototype.getStats=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/stats"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDocuments=function(t){return i(this,void 0,void 0,(function(){var e,n;return s(this,(function(i){switch(i.label){case 0:return e="indexes/".concat(this.uid,"/documents"),void 0!==t&&Array.isArray(t.attributesToRetrieve)&&(n=t.attributesToRetrieve.join(",")),[4,this.httpRequest.get(e,r(r({},t),void 0!==n?{attributesToRetrieve:n}:{}))];case 1:return[2,i.sent()]}}))}))},t.prototype.getDocument=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/documents/").concat(t),[4,this.httpRequest.get(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.addDocuments=function(t,e){return i(this,void 0,void 0,(function(){var n;return s(this,(function(r){switch(r.label){case 0:return n="indexes/".concat(this.uid,"/documents"),[4,this.httpRequest.post(n,t,e)];case 1:return[2,r.sent()]}}))}))},t.prototype.addDocumentsInBatches=function(t,e,n){return void 0===e&&(e=1e3),i(this,void 0,void 0,(function(){var r,i,o,u;return s(this,(function(s){switch(s.label){case 0:r=[],i=0,s.label=1;case 1:return i<t.length?(u=(o=r).push,[4,this.addDocuments(t.slice(i,i+e),n)]):[3,4];case 2:u.apply(o,[s.sent()]),s.label=3;case 3:return i+=e,[3,1];case 4:return[2,r]}}))}))},t.prototype.updateDocuments=function(t,e){return i(this,void 0,void 0,(function(){var n;return s(this,(function(r){switch(r.label){case 0:return n="indexes/".concat(this.uid,"/documents"),[4,this.httpRequest.put(n,t,e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateDocumentsInBatches=function(t,e,n){return void 0===e&&(e=1e3),i(this,void 0,void 0,(function(){var r,i,o,u;return s(this,(function(s){switch(s.label){case 0:r=[],i=0,s.label=1;case 1:return i<t.length?(u=(o=r).push,[4,this.updateDocuments(t.slice(i,i+e),n)]):[3,4];case 2:u.apply(o,[s.sent()]),s.label=3;case 3:return i+=e,[3,1];case 4:return[2,r]}}))}))},t.prototype.deleteDocument=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/documents/").concat(t),[4,this.httpRequest.delete(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteDocuments=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/documents/delete-batch"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteAllDocuments=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/documents"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSettings=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSettings=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/settings"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSettings=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSynonyms=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/synonyms"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSynonyms=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/settings/synonyms"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSynonyms=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/synonyms"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getStopWords=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/stop-words"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateStopWords=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/settings/stop-words"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetStopWords=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/stop-words"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getRankingRules=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/ranking-rules"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateRankingRules=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/settings/ranking-rules"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetRankingRules=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/ranking-rules"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDistinctAttribute=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/distinct-attribute"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateDistinctAttribute=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/settings/distinct-attribute"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetDistinctAttribute=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/distinct-attribute"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getFilterableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/filterable-attributes"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateFilterableAttributes=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/settings/filterable-attributes"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetFilterableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/filterable-attributes"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSortableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/sortable-attributes"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSortableAttributes=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/settings/sortable-attributes"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSortableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/sortable-attributes"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSearchableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/searchable-attributes"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSearchableAttributes=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/settings/searchable-attributes"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSearchableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/searchable-attributes"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDisplayedAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/displayed-attributes"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateDisplayedAttributes=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/settings/displayed-attributes"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetDisplayedAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/displayed-attributes"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t}(),m=function(t){function e(e){return t.call(this,e)||this}return n(e,t),e}(function(){function t(t){this.config=t,this.httpRequest=new b(t),this.tasks=new g(t)}return t.prototype.index=function(t){return new w(this.config,t)},t.prototype.getIndex=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){return[2,new w(this.config,t).fetchInfo()]}))}))},t.prototype.getRawIndex=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){return[2,new w(this.config,t).getRawInfo()]}))}))},t.prototype.getIndexes=function(){return i(this,void 0,void 0,(function(){var t=this;return s(this,(function(e){switch(e.label){case 0:return[4,this.getRawIndexes()];case 1:return[2,e.sent().map((function(e){return new w(t.config,e.uid,e.primaryKey)}))]}}))}))},t.prototype.getRawIndexes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.createIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){return s(this,(function(n){switch(n.label){case 0:return[4,w.create(t,e,this.config)];case 1:return[2,n.sent()]}}))}))},t.prototype.updateIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){return s(this,(function(n){switch(n.label){case 0:return[4,new w(this.config,t).update(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteIndex=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,new w(this.config,t).delete()];case 1:return[2,e.sent()]}}))}))},t.prototype.deleteIndexIfExists=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.deleteIndex(t)];case 1:return n.sent(),[2,!0];case 2:if("index_not_found"===(e=n.sent()).code)return[2,!1];throw e;case 3:return[2]}}))}))},t.prototype.getTasks=function(){return i(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.tasks.getClientTasks()];case 1:return[2,t.sent()]}}))}))},t.prototype.getTask=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.tasks.getClientTask(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.waitForTasks=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,o=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.tasks.waitForClientTasks(t,{timeOutMs:o,intervalMs:a})];case 1:return[2,e.sent()]}}))}))},t.prototype.waitForTask=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,o=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.tasks.waitForClientTask(t,{timeOutMs:o,intervalMs:a})];case 1:return[2,e.sent()]}}))}))},t.prototype.getKeys=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="keys",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getKey=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="keys/".concat(t),[4,this.httpRequest.get(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.createKey=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="keys",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.updateKey=function(t,e){return i(this,void 0,void 0,(function(){var n;return s(this,(function(r){switch(r.label){case 0:return n="keys/".concat(t),[4,this.httpRequest.patch(n,e)];case 1:return[2,r.sent()]}}))}))},t.prototype.deleteKey=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="keys/".concat(t),[4,this.httpRequest.delete(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.health=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="health",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.isHealthy=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t="health",[4,this.httpRequest.get(t)];case 1:return e.sent(),[2,!0];case 2:return e.sent(),[2,!1];case 3:return[2]}}))}))},t.prototype.getStats=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="stats",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getVersion=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="version",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.createDump=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="dumps",[4,this.httpRequest.post(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDumpStatus=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="dumps/".concat(t,"/status"),[4,this.httpRequest.get(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.generateTenantToken=function(t,e){var n=new Error;throw new Error("Meilisearch: failed to generate a tenant token. Generation of a token only works in a node environment \n ".concat(n.stack,"."))},t}());t.HttpRequests=b,t.Index=w,t.MeiliSearch=m,t.MeiliSearchApiError=u,t.MeiliSearchCommunicationError=o,t.MeiliSearchError=h,t.MeiliSearchTimeOutError=l,t.addProtocolIfNotPresent=p,t.addTrailingSlash=v,t.default=m,t.httpErrorHandler=c,t.httpResponseErrorHandler=a,t.removeUndefinedFromObject=d,t.sleep=f,Object.defineProperty(t,"__esModule",{value:!0})}(e)}));function a(t){return"string"==typeof t||t instanceof String}function c(t){return t.replace(/:(.*)/i,'="$1"')}var h=function(t){var e=t.match(/([^=]*)="?([^\\"]*)"?$/);return e?(e[0],[{filterName:e[1],value:e[2]}]):[]};function l(t){var n=function(t){return"string"==typeof t?h(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return h(t)})):h(t)})).flat(2):[]}(t);return n.filter((function(t){return void 0!==t})).reduce((function(t,n){var r,s=n.filterName,o=n.value,u=t[s]||[];return t=e(e({},t),((r={})[s]=i(i([],u),[o]),r))}),{})}function d(t,n){return t.keepZeroFacets?(r=t.defaultFacetDistribution,Object.keys(r).reduce((function(t,n){var i,s=Object.keys(r[n]);return e(e({},t),((i={})[n]=s,i))}),{})):l(null==n?void 0:n.filter);var r}function f(t){return{searchResponse:function(e,i,s){return n(this,void 0,void 0,(function(){var n,o,u,a;return r(this,(function(r){switch(r.label){case 0:return n=t.formatKey([i,e.indexUid,e.query]),(o=t.getEntry(n))?[2,o]:(u=d(e,i),[4,s.index(e.indexUid).search(e.query,i)]);case 1:return(a=r.sent()).facetsDistribution=function(t,e){if(e=e||{},t&&Object.keys(t).length>0)for(var n in t){e[n]||(e[n]={});for(var r=0,i=t[n];r<i.length;r++){var s=i[r];Object.keys(e[n]).includes(s)||(e[n][s]=0)}}return e}(u,a.facetsDistribution),t.setEntry(n,a),[2,a]}}))}))}}}function p(t){return 180*t/Math.PI}function v(t){return t*Math.PI/180}function y(t){if(t){var e,n,r=t.insideBoundingBox,i=t.aroundLatLng,s=t.aroundRadius,o=t.minimumAroundRadius;if(i&&(e=i),null==s&&null==o||(n=null!=s?s:o),r&&"string"==typeof r){var u=r.split(","),a=u[0],c=u[1],h=u[2],l=u[3],d=[parseFloat(a),parseFloat(c),parseFloat(h),parseFloat(l)],f=d[0],y=d[1],b=d[2],g=d[3];n=function(t,e,n,r){var i=t*Math.PI/180,s=n*Math.PI/180,o=(n-t)*Math.PI/180,u=(r-e)*Math.PI/180,a=Math.sin(o/2)*Math.sin(o/2)+Math.cos(i)*Math.cos(s)*Math.sin(u/2)*Math.sin(u/2);return 2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a))*6371e3}(f,y,b,g)/2,e=function(t,e,n,r){t=v(t),e=v(e);var i=Math.cos(t)*Math.cos(e),s=Math.cos(t)*Math.sin(e),o=Math.sin(t);n=v(n),r=v(r);var u=i+Math.cos(n)*Math.cos(r),a=s+Math.cos(n)*Math.sin(r),c=o+Math.sin(n),h=Math.sqrt(u*u+a*a),l=Math.atan2(a,u),d=Math.atan2(c,h);return e<r||e>r&&e>Math.PI&&r<-Math.PI?(d+=Math.PI,l+=Math.PI):(d=p(d),l=p(l)),Math.abs(u)<Math.pow(10,-9)&&Math.abs(a)<Math.pow(10,-9)&&Math.abs(c)<Math.pow(10,-9)&&(d=0,l=0),"".concat(d,",").concat(l)}(f,y,b,g)}if(null!=e&&null!=n){var w=e.split(","),m=w[0],x=w[1];return m=Number.parseFloat(m).toFixed(5),x=Number.parseFloat(x).toFixed(5),{filter:"_geoRadius(".concat(m,", ").concat(x,", ").concat(n,")")}}}}function b(t){return"string"==typeof t?c(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return c(t)})).filter((function(t){return t})):c(t)})).filter((function(t){return t})):[]}function g(t){return""===t?[]:"string"==typeof t?[t]:t}function w(t,e,n){return function(t,e,n){var r=n.trim(),s=g(t),o=g(e);return i(i(i([],s),o),[r]).filter((function(t){return Array.isArray(t)?t.length:t}))}(b(n||[]),b(e||[]),t||"")}function m(t){var e={},n=null==t?void 0:t.facets;(null==n?void 0:n.length)&&(e.facetsDistribution=n);var r=null==t?void 0:t.attributesToSnippet;r&&(e.attributesToCrop=r);var i=null==t?void 0:t.attributesToRetrieve;i&&(e.attributesToRetrieve=i);var s=w(null==t?void 0:t.filters,null==t?void 0:t.numericFilters,null==t?void 0:t.facetFilters);s.length&&(e.filter=s),i&&(e.attributesToCrop=i),e.attributesToHighlight=(null==t?void 0:t.attributesToHighlight)||["*"];var o=t.placeholderSearch,u=t.query,a=t.paginationTotalHits;e.limit=!o&&""===u||0===a?0:a;var c=t.sort;(null==c?void 0:c.length)&&(e.sort=[c]);var h=y(function(t){var e={},n=t.aroundLatLng,r=t.aroundLatLngViaIP,i=t.aroundRadius,s=t.aroundPrecision,o=t.minimumAroundRadius,u=t.insideBoundingBox,a=t.insidePolygon;return n&&(e.aroundLatLng=n),r&&console.warn("instant-meilisearch: `aroundLatLngViaIP` is not supported."),i&&(e.aroundRadius=i),s&&console.warn("instant-meilisearch: `aroundPrecision` is not supported.\n See this discussion to track its implementation https://github.com/meilisearch/product/discussions/264"),o&&(e.minimumAroundRadius=o),u&&(e.insideBoundingBox=u),a&&console.warn("instant-meilisearch: `insidePolygon` is not implented in instant-meilisearch."),e}(t));return(null==h?void 0:h.filter)&&(e.filter?e.filter.unshift(h.filter):e.filter=[h.filter]),e}function x(t,e,n){return"string"==typeof t?function(t,e,n){return void 0===e&&(e="__ais-highlight__"),void 0===n&&(n="__/ais-highlight__"),(a(t)?t:JSON.stringify(t)).replace(/<em>/g,e).replace(/<\/em>/g,n)}(t,e,n):void 0===t?JSON.stringify(null):JSON.stringify(t)}function T(t,e,n){return t._formatted?Object.keys(t._formatted).reduce((function(r,i){var s=t._formatted[i];return r[i]=function(t,e,n){return Array.isArray(t)?t.map((function(t){return{value:x(t,e,n)}})):{value:x(t,e,n)}}(s,e,n),r}),{}):t._formatted}function R(t,e,n){var r,i=e;return a(e)&&t.toString().length>(r=e,r.replace(/<em>/g,"").replace(/<\/em>/g,"")).length&&(e[0]===e[0].toLowerCase()&&!1===e.startsWith("<em>")&&(i="".concat(n).concat(e.trim())),!1==!!e.match(/[.!?]$/)&&(i="".concat(e.trim()).concat(n))),i}function k(t,e,n){return n&&"string"==typeof e?Array.isArray(t)?t.map((function(t){return R(t,e,n)})):R(t,e,n):e}function M(t,e){var n=null==e?void 0:e.attributesToSnippet,r=null==e?void 0:e.snippetEllipsisText,i=null==e?void 0:e.highlightPreTag,s=null==e?void 0:e.highlightPostTag;return t._formatted?{_highlightResult:T(t,i,s),_snippetResult:T(function(t,e,n){var r=t._formatted,i=t._formatted;if(void 0===e)return t;var s=e.map((function(t){return t.split(":")[0]}));if(s.includes("*"))for(var o in r)i[o]=k(t[o],r[o],n);else for(var u=0,a=s;u<a.length;u++)i[o=a[u]]=k(t[o],r[o],n);return t._formatted=i,t}(t,n,r),i,s)}:{}}function E(t,n,r){var i=n.primaryKey,s=r.hitsPerPage,o=function(t,e,n){if(n<0)throw new TypeError('Value too small for "hitsPerPage" parameter, expected integer between 0 and 9223372036854775807');var r=e*n;return t.slice(r,r+n)}(t,r.page,s).map((function(t){if(Object.keys(t).length>0){t._formatted,t._matchesInfo;var r=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","_matchesInfo"]);return e(e(e({},r),M(t,n)),i&&{objectID:t[i]})}return t}));return o=function(t){for(var e=0;e<t.length;e++)t[e]._geo&&(t[e]._geoloc={lat:t[e]._geo.lat,lng:t[e]._geo.lng},t[e].objectID="".concat(e+1e6*Math.random()),delete t[e]._geo);return t}(o)}function S(t,n){var r={},i=t.facetsDistribution,s=null==t?void 0:t.exhaustiveFacetsCount;s&&(r.exhaustiveFacetsCount=s);var o,u,a=function(t){return{paginationTotalHits:t.paginationTotalHits||200,hitsPerPage:void 0===t.hitsPerPage?20:t.hitsPerPage,page:(null==t?void 0:t.page)||0}}(n),c=(o=t.hits.length,(u=a.hitsPerPage)>0?Math.ceil(o/u):0),h=E(t.hits,n,a),l=t.exhaustiveNbHits,d=t.nbHits,f=t.processingTimeMs,p=t.query,v=a.hitsPerPage,y=a.page;return{results:[e({index:n.indexUid,hitsPerPage:v,page:y,facets:i,nbPages:c,exhaustiveNbHits:l,nbHits:d,processingTimeMS:f,query:p,hits:h,params:""},r)]}}function O(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(n){return e[t]}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,n){e[t]=JSON.stringify(n)}}}t.instantMeiliSearch=function(t,i,s){void 0===i&&(i=""),void 0===s&&(s={});var o=f(O()),a={};return{MeiliSearchClient:new u.MeiliSearch({host:t,apiKey:i}),search:function(t){return n(this,void 0,void 0,(function(){var n,i,u,c,h;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),n=t[0],i=function(t,n,r){var i=t.indexName.split(":"),s=i[0],o=i.slice(1),u=t.params;return e(e(e({},n),u),{sort:o.join(":")||"",indexUid:s,defaultFacetDistribution:r,placeholderSearch:!n.placeholderSearch,paginationTotalHits:null!=n.paginationTotalHits?n.paginationTotalHits:200,keepZeroFacets:!!n.keepZeroFacets})}(n,s,a),u=m(i),[4,o.searchResponse(i,u,this.MeiliSearchClient)];case 1:return c=r.sent(),a=function(t,e){return""===e.query&&0===Object.keys(t).length?e.facetsDistribution:t}(a,c),[2,S(c,i)];case 2:throw h=r.sent(),console.error(h),new Error(h);case 3:return[2]}}))}))},searchForFacetValues:function(t){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,new Promise((function(t,e){e(new Error("SearchForFacetValues is not compatible with Meilisearch")),t([])}))];case 1:return[2,t.sent()]}}))}))}}},Object.defineProperty(t,"__esModule",{value:!0})}));
var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,n)};function n(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r=function(){return(r=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}).apply(this,arguments)};function i(t,e,n,r){function i(t){return t instanceof n?t:new n((function(e){e(t)}))}return new(n||(n=Promise))((function(n,s){function o(t){try{a(r.next(t))}catch(t){s(t)}}function u(t){try{a(r.throw(t))}catch(t){s(t)}}function a(t){t.done?n(t.value):i(t.value).then(o,u)}a((r=r.apply(t,e||[])).next())}))}function s(t,e){var n,r,i,s,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(t){return function(e){return a([t,e])}}function a(s){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,r=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],r=0}finally{n=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}}var o=function(t){function e(n,r,i,s){var o,u,a,c=this;return(c=t.call(this,n)||this).name="MeiliSearchCommunicationError",c.type="MeiliSearchCommunicationError",r instanceof Response&&(c.message=r.statusText,c.statusCode=r.status),r instanceof Error&&(c.errno=r.errno,c.code=r.code),s?(c.stack=s,c.stack=null===(o=c.stack)||void 0===o?void 0:o.replace(/(TypeError|FetchError)/,c.name),c.stack=null===(u=c.stack)||void 0===u?void 0:u.replace("Failed to fetch","request to ".concat(i," failed, reason: connect ECONNREFUSED")),c.stack=null===(a=c.stack)||void 0===a?void 0:a.replace("Not Found","Not Found: ".concat(i))):Error.captureStackTrace&&Error.captureStackTrace(c,e),c}return n(e,t),e}(Error),u=function(t){function e(e,n){var r=t.call(this,e.message)||this;return r.name="MeiliSearchApiError",r.code=e.code,r.type=e.type,r.link=e.link,r.message=e.message,r.httpStatus=n,Object.setPrototypeOf(r,u.prototype),Error.captureStackTrace&&Error.captureStackTrace(r,u),r}return n(e,t),e}(Error);function a(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:if(t.ok)return[3,5];e=void 0,n.label=1;case 1:return n.trys.push([1,3,,4]),[4,t.json()];case 2:return e=n.sent(),[3,4];case 3:throw n.sent(),new o(t.statusText,t,t.url);case 4:throw new u(e,t.status);case 5:return[2,t]}}))}))}function c(t,e,n){if("MeiliSearchApiError"!==t.type)throw new o(t.message,t,n,e);throw t}var h=function(t){function e(n){var r=t.call(this,n)||this;return r.name="MeiliSearchError",r.type="MeiliSearchError",Error.captureStackTrace&&Error.captureStackTrace(r,e),r}return n(e,t),e}(Error),l=function(t){function e(n){var r=t.call(this,n)||this;return r.name="MeiliSearchTimeOutError",r.type=r.constructor.name,Error.captureStackTrace&&Error.captureStackTrace(r,e),r}return n(e,t),e}(Error);function d(t){return Object.entries(t).reduce((function(t,e){var n=e[0],r=e[1];return void 0!==r&&(t[n]=r),t}),{})}function f(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,new Promise((function(e){return setTimeout(e,t)}))];case 1:return[2,e.sent()]}}))}))}function p(t){return t.startsWith("https://")||t.startsWith("http://")?t:"http://".concat(t)}function v(t){return t.endsWith("/")||(t+="/"),t}function y(t){try{return t=v(t=p(t))}catch(t){throw new h("The provided host is not valid.")}}var b=function(){function t(t){this.headers=Object.assign({},t.headers||{}),this.headers["Content-Type"]="application/json",t.apiKey&&(this.headers.Authorization="Bearer ".concat(t.apiKey));try{var e=y(t.host);this.url=new URL(e)}catch(t){throw new h("The provided host is not valid.")}}return t.prototype.request=function(t){var e=t.method,n=t.url,o=t.params,u=t.body,h=t.config;return i(this,void 0,void 0,(function(){var t,i,l,d,f;return s(this,(function(s){switch(s.label){case 0:t=new URL(n,this.url),o&&(i=new URLSearchParams,Object.keys(o).filter((function(t){return null!==o[t]})).map((function(t){return i.set(t,o[t])})),t.search=i.toString()),s.label=1;case 1:return s.trys.push([1,4,,5]),[4,fetch(t.toString(),r(r({},h),{method:e,body:JSON.stringify(u),headers:this.headers})).then((function(t){return a(t)}))];case 2:return[4,s.sent().text()];case 3:l=s.sent();try{return[2,JSON.parse(l)]}catch(t){return[2]}return[3,5];case 4:return d=s.sent(),f=d.stack,c(d,f,t.toString()),[3,5];case 5:return[2]}}))}))},t.prototype.get=function(t,e,n){return i(this,void 0,void 0,(function(){return s(this,(function(r){switch(r.label){case 0:return[4,this.request({method:"GET",url:t,params:e,config:n})];case 1:return[2,r.sent()]}}))}))},t.prototype.post=function(t,e,n,r){return i(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"POST",url:t,body:e,params:n,config:r})];case 1:return[2,i.sent()]}}))}))},t.prototype.put=function(t,e,n,r){return i(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"PUT",url:t,body:e,params:n,config:r})];case 1:return[2,i.sent()]}}))}))},t.prototype.patch=function(t,e,n,r){return i(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"PATCH",url:t,body:e,params:n,config:r})];case 1:return[2,i.sent()]}}))}))},t.prototype.delete=function(t,e,n,r){return i(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"DELETE",url:t,body:e,params:n,config:r})];case 1:return[2,i.sent()]}}))}))},t}(),g=function(){function t(t){this.httpRequest=new b(t)}return t.prototype.getClientTask=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="tasks/".concat(t),[4,this.httpRequest.get(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.getClientTasks=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="tasks",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getIndexTask=function(t,e){return i(this,void 0,void 0,(function(){var n;return s(this,(function(r){switch(r.label){case 0:return n="indexes/".concat(t,"/tasks/").concat(e),[4,this.httpRequest.get(n)];case 1:return[2,r.sent()]}}))}))},t.prototype.getIndexTasks=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(t,"/tasks"),[4,this.httpRequest.get(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.waitForClientTask=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,o=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return i(this,void 0,void 0,(function(){var e,n;return s(this,(function(r){switch(r.label){case 0:e=Date.now(),r.label=1;case 1:return Date.now()-e<o?[4,this.getClientTask(t)]:[3,4];case 2:return n=r.sent(),["enqueued","processing"].includes(n.status)?[4,f(a)]:[2,n];case 3:return r.sent(),[3,1];case 4:throw new l("timeout of ".concat(o,"ms has exceeded on process ").concat(t," when waiting a task to be resolved."))}}))}))},t.prototype.waitForClientTasks=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,o=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return i(this,void 0,void 0,(function(){var e,n,r,i,u;return s(this,(function(s){switch(s.label){case 0:e=[],n=0,r=t,s.label=1;case 1:return n<r.length?(i=r[n],[4,this.waitForClientTask(i,{timeOutMs:o,intervalMs:a})]):[3,4];case 2:u=s.sent(),e.push(u),s.label=3;case 3:return n++,[3,1];case 4:return[2,{results:e}]}}))}))},t.prototype.waitForIndexTask=function(t,e,n){var r=void 0===n?{}:n,o=r.timeOutMs,u=void 0===o?5e3:o,a=r.intervalMs,c=void 0===a?50:a;return i(this,void 0,void 0,(function(){var n,r;return s(this,(function(i){switch(i.label){case 0:n=Date.now(),i.label=1;case 1:return Date.now()-n<u?[4,this.getIndexTask(t,e)]:[3,4];case 2:return r=i.sent(),["enqueued","processing"].includes(r.status)?[4,f(c)]:[2,r];case 3:return i.sent(),[3,1];case 4:throw new l("timeout of ".concat(u,"ms has exceeded on process ").concat(e," when waiting for pending update to resolve."))}}))}))},t}(),w=function(){function t(t,e,n){this.uid=e,this.primaryKey=n,this.httpRequest=new b(t),this.tasks=new g(t)}return t.prototype.search=function(t,e,n){return i(this,void 0,void 0,(function(){var i;return s(this,(function(s){switch(s.label){case 0:return i="indexes/".concat(this.uid,"/search"),[4,this.httpRequest.post(i,d(r(r({},e),{q:t})),void 0,n)];case 1:return[2,s.sent()]}}))}))},t.prototype.searchGet=function(t,e,n){return i(this,void 0,void 0,(function(){var i,o,u;return s(this,(function(s){switch(s.label){case 0:return i="indexes/".concat(this.uid,"/search"),o=function(t){if("string"==typeof t)return t;if(Array.isArray(t))throw new h("The filter query parameter should be in string format when using searchGet")},u=r(r({q:t},e),{filter:o(null==e?void 0:e.filter),sort:(null==e?void 0:e.sort)?e.sort.join(","):void 0,facetsDistribution:(null==e?void 0:e.facetsDistribution)?e.facetsDistribution.join(","):void 0,attributesToRetrieve:(null==e?void 0:e.attributesToRetrieve)?e.attributesToRetrieve.join(","):void 0,attributesToCrop:(null==e?void 0:e.attributesToCrop)?e.attributesToCrop.join(","):void 0,attributesToHighlight:(null==e?void 0:e.attributesToHighlight)?e.attributesToHighlight.join(","):void 0}),[4,this.httpRequest.get(i,d(u),n)];case 1:return[2,s.sent()]}}))}))},t.prototype.getRawInfo=function(){return i(this,void 0,void 0,(function(){var t,e;return s(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid),[4,this.httpRequest.get(t)];case 1:return e=n.sent(),this.primaryKey=e.primaryKey,[2,e]}}))}))},t.prototype.fetchInfo=function(){return i(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.getRawInfo()];case 1:return t.sent(),[2,this]}}))}))},t.prototype.fetchPrimaryKey=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t=this,[4,this.getRawInfo()];case 1:return t.primaryKey=e.sent().primaryKey,[2,this.primaryKey]}}))}))},t.create=function(t,e,n){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){var i;return s(this,(function(s){return i="indexes",[2,new b(n).post(i,r(r({},e),{uid:t}))]}))}))},t.prototype.update=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid),[4,this.httpRequest.put(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.delete=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getTasks=function(){return i(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.tasks.getIndexTasks(this.uid)];case 1:return[2,t.sent()]}}))}))},t.prototype.getTask=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.tasks.getIndexTask(this.uid,t)];case 1:return[2,e.sent()]}}))}))},t.prototype.waitForTasks=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,o=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.tasks.waitForClientTasks(t,{timeOutMs:o,intervalMs:a})];case 1:return[2,e.sent()]}}))}))},t.prototype.waitForTask=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,o=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.tasks.waitForClientTask(t,{timeOutMs:o,intervalMs:a})];case 1:return[2,e.sent()]}}))}))},t.prototype.getStats=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/stats"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDocuments=function(t){return i(this,void 0,void 0,(function(){var e,n;return s(this,(function(i){switch(i.label){case 0:return e="indexes/".concat(this.uid,"/documents"),void 0!==t&&Array.isArray(t.attributesToRetrieve)&&(n=t.attributesToRetrieve.join(",")),[4,this.httpRequest.get(e,r(r({},t),void 0!==n?{attributesToRetrieve:n}:{}))];case 1:return[2,i.sent()]}}))}))},t.prototype.getDocument=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/documents/").concat(t),[4,this.httpRequest.get(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.addDocuments=function(t,e){return i(this,void 0,void 0,(function(){var n;return s(this,(function(r){switch(r.label){case 0:return n="indexes/".concat(this.uid,"/documents"),[4,this.httpRequest.post(n,t,e)];case 1:return[2,r.sent()]}}))}))},t.prototype.addDocumentsInBatches=function(t,e,n){return void 0===e&&(e=1e3),i(this,void 0,void 0,(function(){var r,i,o,u;return s(this,(function(s){switch(s.label){case 0:r=[],i=0,s.label=1;case 1:return i<t.length?(u=(o=r).push,[4,this.addDocuments(t.slice(i,i+e),n)]):[3,4];case 2:u.apply(o,[s.sent()]),s.label=3;case 3:return i+=e,[3,1];case 4:return[2,r]}}))}))},t.prototype.updateDocuments=function(t,e){return i(this,void 0,void 0,(function(){var n;return s(this,(function(r){switch(r.label){case 0:return n="indexes/".concat(this.uid,"/documents"),[4,this.httpRequest.put(n,t,e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateDocumentsInBatches=function(t,e,n){return void 0===e&&(e=1e3),i(this,void 0,void 0,(function(){var r,i,o,u;return s(this,(function(s){switch(s.label){case 0:r=[],i=0,s.label=1;case 1:return i<t.length?(u=(o=r).push,[4,this.updateDocuments(t.slice(i,i+e),n)]):[3,4];case 2:u.apply(o,[s.sent()]),s.label=3;case 3:return i+=e,[3,1];case 4:return[2,r]}}))}))},t.prototype.deleteDocument=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/documents/").concat(t),[4,this.httpRequest.delete(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteDocuments=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/documents/delete-batch"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteAllDocuments=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/documents"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSettings=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSettings=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/settings"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSettings=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSynonyms=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/synonyms"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSynonyms=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/settings/synonyms"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSynonyms=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/synonyms"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getStopWords=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/stop-words"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateStopWords=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/settings/stop-words"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetStopWords=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/stop-words"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getRankingRules=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/ranking-rules"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateRankingRules=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/settings/ranking-rules"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetRankingRules=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/ranking-rules"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDistinctAttribute=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/distinct-attribute"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateDistinctAttribute=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/settings/distinct-attribute"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetDistinctAttribute=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/distinct-attribute"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getFilterableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/filterable-attributes"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateFilterableAttributes=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/settings/filterable-attributes"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetFilterableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/filterable-attributes"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSortableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/sortable-attributes"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSortableAttributes=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/settings/sortable-attributes"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSortableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/sortable-attributes"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSearchableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/searchable-attributes"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSearchableAttributes=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/settings/searchable-attributes"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSearchableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/searchable-attributes"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDisplayedAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/displayed-attributes"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateDisplayedAttributes=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/".concat(this.uid,"/settings/displayed-attributes"),[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetDisplayedAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/displayed-attributes"),[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t}(),m=function(t){function e(e){return t.call(this,e)||this}return n(e,t),e}(function(){function t(t){this.config=t,this.httpRequest=new b(t),this.tasks=new g(t)}return t.prototype.index=function(t){return new w(this.config,t)},t.prototype.getIndex=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){return[2,new w(this.config,t).fetchInfo()]}))}))},t.prototype.getRawIndex=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){return[2,new w(this.config,t).getRawInfo()]}))}))},t.prototype.getIndexes=function(){return i(this,void 0,void 0,(function(){var t=this;return s(this,(function(e){switch(e.label){case 0:return[4,this.getRawIndexes()];case 1:return[2,e.sent().map((function(e){return new w(t.config,e.uid,e.primaryKey)}))]}}))}))},t.prototype.getRawIndexes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.createIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){return s(this,(function(n){switch(n.label){case 0:return[4,w.create(t,e,this.config)];case 1:return[2,n.sent()]}}))}))},t.prototype.updateIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){return s(this,(function(n){switch(n.label){case 0:return[4,new w(this.config,t).update(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteIndex=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,new w(this.config,t).delete()];case 1:return[2,e.sent()]}}))}))},t.prototype.deleteIndexIfExists=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.deleteIndex(t)];case 1:return n.sent(),[2,!0];case 2:if("index_not_found"===(e=n.sent()).code)return[2,!1];throw e;case 3:return[2]}}))}))},t.prototype.getTasks=function(){return i(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.tasks.getClientTasks()];case 1:return[2,t.sent()]}}))}))},t.prototype.getTask=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.tasks.getClientTask(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.waitForTasks=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,o=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.tasks.waitForClientTasks(t,{timeOutMs:o,intervalMs:a})];case 1:return[2,e.sent()]}}))}))},t.prototype.waitForTask=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,o=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.tasks.waitForClientTask(t,{timeOutMs:o,intervalMs:a})];case 1:return[2,e.sent()]}}))}))},t.prototype.getKeys=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="keys",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getKey=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="keys/".concat(t),[4,this.httpRequest.get(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.createKey=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="keys",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.updateKey=function(t,e){return i(this,void 0,void 0,(function(){var n;return s(this,(function(r){switch(r.label){case 0:return n="keys/".concat(t),[4,this.httpRequest.patch(n,e)];case 1:return[2,r.sent()]}}))}))},t.prototype.deleteKey=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="keys/".concat(t),[4,this.httpRequest.delete(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.health=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="health",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.isHealthy=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t="health",[4,this.httpRequest.get(t)];case 1:return e.sent(),[2,!0];case 2:return e.sent(),[2,!1];case 3:return[2]}}))}))},t.prototype.getStats=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="stats",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getVersion=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="version",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.createDump=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="dumps",[4,this.httpRequest.post(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDumpStatus=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="dumps/".concat(t,"/status"),[4,this.httpRequest.get(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.generateTenantToken=function(t,e){var n=new Error;throw new Error("Meilisearch: failed to generate a tenant token. Generation of a token only works in a node environment \n ".concat(n.stack,"."))},t}());t.HttpRequests=b,t.Index=w,t.MeiliSearch=m,t.MeiliSearchApiError=u,t.MeiliSearchCommunicationError=o,t.MeiliSearchError=h,t.MeiliSearchTimeOutError=l,t.addProtocolIfNotPresent=p,t.addTrailingSlash=v,t.default=m,t.httpErrorHandler=c,t.httpResponseErrorHandler=a,t.removeUndefinedFromObject=d,t.sleep=f,Object.defineProperty(t,"__esModule",{value:!0})}(e)}));function a(t){return"string"==typeof t||t instanceof String}function c(t){return t.replace(/:(.*)/i,'="$1"')}var h=function(t){var e=t.match(/([^=]*)="?([^\\"]*)"?$/);return e?(e[0],[{filterName:e[1],value:e[2]}]):[]};function l(t){var n=function(t){return"string"==typeof t?h(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return h(t)})):h(t)})).flat(2):[]}(t);return n.filter((function(t){return void 0!==t})).reduce((function(t,n){var r,s=n.filterName,o=n.value,u=t[s]||[];return t=e(e({},t),((r={})[s]=i(i([],u),[o]),r))}),{})}function d(t,n){return t.keepZeroFacets?(r=t.defaultFacetDistribution,Object.keys(r).reduce((function(t,n){var i,s=Object.keys(r[n]);return e(e({},t),((i={})[n]=s,i))}),{})):l(null==n?void 0:n.filter);var r}var f={hits:[],query:"",facetsDistribution:{},limit:0,offset:0,exhaustiveNbHits:!1,nbHits:0,processingTimeMs:0};function p(t){return{searchResponse:function(e,i,s){return n(this,void 0,void 0,(function(){var n,o,u,a,c,h,l,p;return r(this,(function(r){switch(r.label){case 0:return n=e.placeholderSearch,o=e.query,n||o?(u=e.pagination,a=e.finitePagination?{}:u,c=t.formatKey([i,e.indexUid,e.query,a]),(h=t.getEntry(c))?[2,h]:(l=d(e,i),[4,s.index(e.indexUid).search(e.query,i)])):[2,f];case 1:return(p=r.sent()).facetsDistribution=function(t,e){if(e=e||{},t&&Object.keys(t).length>0)for(var n in t){e[n]||(e[n]={});for(var r=0,i=t[n];r<i.length;r++){var s=i[r];Object.keys(e[n]).includes(s)||(e[n][s]=0)}}return e}(l,p.facetsDistribution),t.setEntry(c,p),[2,p]}}))}))}}}function v(t){return 180*t/Math.PI}function y(t){return t*Math.PI/180}function b(t){if(t){var e,n,r=t.insideBoundingBox,i=t.aroundLatLng,s=t.aroundRadius,o=t.minimumAroundRadius;if(i&&(e=i),null==s&&null==o||(n=null!=s?s:o),r&&"string"==typeof r){var u=r.split(","),a=u[0],c=u[1],h=u[2],l=u[3],d=[parseFloat(a),parseFloat(c),parseFloat(h),parseFloat(l)],f=d[0],p=d[1],b=d[2],g=d[3];n=function(t,e,n,r){var i=t*Math.PI/180,s=n*Math.PI/180,o=(n-t)*Math.PI/180,u=(r-e)*Math.PI/180,a=Math.sin(o/2)*Math.sin(o/2)+Math.cos(i)*Math.cos(s)*Math.sin(u/2)*Math.sin(u/2);return 2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a))*6371e3}(f,p,b,g)/2,e=function(t,e,n,r){t=y(t),e=y(e);var i=Math.cos(t)*Math.cos(e),s=Math.cos(t)*Math.sin(e),o=Math.sin(t);n=y(n),r=y(r);var u=i+Math.cos(n)*Math.cos(r),a=s+Math.cos(n)*Math.sin(r),c=o+Math.sin(n),h=Math.sqrt(u*u+a*a),l=Math.atan2(a,u),d=Math.atan2(c,h);return e<r||e>r&&e>Math.PI&&r<-Math.PI?(d+=Math.PI,l+=Math.PI):(d=v(d),l=v(l)),Math.abs(u)<Math.pow(10,-9)&&Math.abs(a)<Math.pow(10,-9)&&Math.abs(c)<Math.pow(10,-9)&&(d=0,l=0),"".concat(d,",").concat(l)}(f,p,b,g)}if(null!=e&&null!=n){var w=e.split(","),m=w[0],x=w[1];return m=Number.parseFloat(m).toFixed(5),x=Number.parseFloat(x).toFixed(5),{filter:"_geoRadius(".concat(m,", ").concat(x,", ").concat(n,")")}}}}function g(t){return"string"==typeof t?c(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return c(t)})).filter((function(t){return t})):c(t)})).filter((function(t){return t})):[]}function w(t){return""===t?[]:"string"==typeof t?[t]:t}function m(t,e,n){return function(t,e,n){var r=n.trim(),s=w(t),o=w(e);return i(i(i([],s),o),[r]).filter((function(t){return Array.isArray(t)?t.length:t}))}(g(n||[]),g(e||[]),t||"")}function x(t){var e={},n=null==t?void 0:t.facets;(null==n?void 0:n.length)&&(e.facetsDistribution=n);var r=null==t?void 0:t.attributesToSnippet;r&&(e.attributesToCrop=r);var i=null==t?void 0:t.attributesToRetrieve;i&&(e.attributesToRetrieve=i);var s=m(null==t?void 0:t.filters,null==t?void 0:t.numericFilters,null==t?void 0:t.facetFilters);s.length&&(e.filter=s),i&&(e.attributesToCrop=i),e.attributesToHighlight=(null==t?void 0:t.attributesToHighlight)||["*"];var o=t.placeholderSearch,u=t.query,a=t.pagination;if(!o&&""===u||0===a.paginationTotalHits)e.limit=0;else if(t.finitePagination)e.limit=a.paginationTotalHits;else{var c=(a.page+1)*a.hitsPerPage+1;c>a.paginationTotalHits?e.limit=a.paginationTotalHits:e.limit=c}var h=t.sort;(null==h?void 0:h.length)&&(e.sort=[h]);var l=b(function(t){var e={},n=t.aroundLatLng,r=t.aroundLatLngViaIP,i=t.aroundRadius,s=t.aroundPrecision,o=t.minimumAroundRadius,u=t.insideBoundingBox,a=t.insidePolygon;return n&&(e.aroundLatLng=n),r&&console.warn("instant-meilisearch: `aroundLatLngViaIP` is not supported."),i&&(e.aroundRadius=i),s&&console.warn("instant-meilisearch: `aroundPrecision` is not supported.\n See this discussion to track its implementation https://github.com/meilisearch/product/discussions/264"),o&&(e.minimumAroundRadius=o),u&&(e.insideBoundingBox=u),a&&console.warn("instant-meilisearch: `insidePolygon` is not implented in instant-meilisearch."),e}(t));return(null==l?void 0:l.filter)&&(e.filter?e.filter.unshift(l.filter):e.filter=[l.filter]),e}function T(t,e,n){return"string"==typeof t?function(t,e,n){return void 0===e&&(e="__ais-highlight__"),void 0===n&&(n="__/ais-highlight__"),(a(t)?t:JSON.stringify(t)).replace(/<em>/g,e).replace(/<\/em>/g,n)}(t,e,n):void 0===t?JSON.stringify(null):JSON.stringify(t)}function R(t,e,n){return t._formatted?Object.keys(t._formatted).reduce((function(r,i){var s=t._formatted[i];return r[i]=function(t,e,n){return Array.isArray(t)?t.map((function(t){return{value:T(t,e,n)}})):{value:T(t,e,n)}}(s,e,n),r}),{}):t._formatted}function k(t,e,n){var r,i=e;return a(e)&&t.toString().length>(r=e,r.replace(/<em>/g,"").replace(/<\/em>/g,"")).length&&(e[0]===e[0].toLowerCase()&&!1===e.startsWith("<em>")&&(i="".concat(n).concat(e.trim())),!1==!!e.match(/[.!?]$/)&&(i="".concat(e.trim()).concat(n))),i}function M(t,e,n){return n&&"string"==typeof e?Array.isArray(t)?t.map((function(t){return k(t,e,n)})):k(t,e,n):e}function E(t,e){var n=null==e?void 0:e.attributesToSnippet,r=null==e?void 0:e.snippetEllipsisText,i=null==e?void 0:e.highlightPreTag,s=null==e?void 0:e.highlightPostTag;return t._formatted?{_highlightResult:R(t,i,s),_snippetResult:R(function(t,e,n){var r=t._formatted,i=t._formatted;if(void 0===e)return t;var s=e.map((function(t){return t.split(":")[0]}));if(s.includes("*"))for(var o in r)i[o]=M(t[o],r[o],n);else for(var u=0,a=s;u<a.length;u++)i[o=a[u]]=M(t[o],r[o],n);return t._formatted=i,t}(t,n,r),i,s)}:{}}function S(t,n,r){var i=n.primaryKey,s=r.hitsPerPage,o=function(t,e,n){if(n<0)throw new TypeError('Value too small for "hitsPerPage" parameter, expected integer between 0 and 9223372036854775807');var r=e*n;return t.slice(r,r+n)}(t,r.page,s).map((function(t){if(Object.keys(t).length>0){t._formatted,t._matchesInfo;var r=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","_matchesInfo"]);return e(e(e({},r),E(t,n)),i&&{objectID:t[i]})}return t}));return o=function(t){for(var e=0;e<t.length;e++)t[e]._geo&&(t[e]._geoloc={lat:t[e]._geo.lat,lng:t[e]._geo.lng},t[e].objectID="".concat(e+1e6*Math.random()),delete t[e]._geo);return t}(o)}function q(t,n){var r={},i=t.facetsDistribution,s=n.pagination,o=null==t?void 0:t.exhaustiveFacetsCount;o&&(r.exhaustiveFacetsCount=o);var u,a,c=(u=t.hits.length,(a=s.hitsPerPage)>0?Math.ceil(u/a):0),h=S(t.hits,n,s),l=t.exhaustiveNbHits,d=t.nbHits,f=t.processingTimeMs,p=t.query,v=s.hitsPerPage,y=s.page;return{results:[e({index:n.indexUid,hitsPerPage:v,page:y,facets:i,nbPages:c,exhaustiveNbHits:l,nbHits:d,processingTimeMS:f,query:p,hits:h,params:""},r)]}}function O(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(n){return e[t]}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,n){e[t]=JSON.stringify(n)}}}t.instantMeiliSearch=function(t,i,s){void 0===i&&(i=""),void 0===s&&(s={});var o=p(O()),a={},c=new u.MeiliSearch({host:t,apiKey:i});return{search:function(t){return n(this,void 0,void 0,(function(){var n,i,u,h,l;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),n=t[0],i=function(t,n,r){var i=t.indexName.split(":"),s=i[0],o=i.slice(1),u=t.params,a=function(t){var e=t.paginationTotalHits,n=t.hitsPerPage;return{paginationTotalHits:null!=e?e:200,hitsPerPage:void 0===n?20:n,page:t.page||0}}({paginationTotalHits:n.paginationTotalHits,hitsPerPage:null==u?void 0:u.hitsPerPage,page:null==u?void 0:u.page});return e(e(e({},n),u),{sort:o.join(":")||"",indexUid:s,pagination:a,defaultFacetDistribution:r,placeholderSearch:!1!==n.placeholderSearch,keepZeroFacets:!!n.keepZeroFacets,finitePagination:!!n.finitePagination})}(n,s,a),u=x(i),[4,o.searchResponse(i,u,c)];case 1:return h=r.sent(),a=function(t,e){return""===e.query&&0===Object.keys(t).length?e.facetsDistribution:t}(a,h),[2,q(h,i)];case 2:throw l=r.sent(),console.error(l),new Error(l);case 3:return[2]}}))}))},searchForFacetValues:function(t){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,new Promise((function(t,e){e(new Error("SearchForFacetValues is not compatible with Meilisearch")),t([])}))];case 1:return[2,t.sent()]}}))}))}}},Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=instant-meilisearch.umd.min.js.map

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

import { SearchContext, PaginationContext } from '../../types';
/**

@@ -11,8 +10,2 @@ * Slice the requested hits based on the pagination position.

export declare function adaptPagination(hits: Record<string, any>, page: number, hitsPerPage: number): Array<Record<string, any>>;
/**
* @param {AlgoliaMultipleQueriesQuery} searchRequest
* @param {Context} options
* @returns {SearchContext}
*/
export declare function createPaginationContext(searchContext: SearchContext): PaginationContext;
//# sourceMappingURL=pagination-adapter.d.ts.map

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

// Type definitions for @meilisearch/instant-meilisearch 0.6.2
// Type definitions for @meilisearch/instant-meilisearch 0.7.0
// Project: https://github.com/meilisearch/instant-meilisearch.git
// Definitions by: Clementine Urquizar <https://github.com/meilisearch>
// Definitions: https://github.com/meilisearch/instant-meilisearch.git
// TypeScript Version: ^4.6.2
// TypeScript Version: ^4.6.3

@@ -7,0 +7,0 @@ export * from './client';

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

import type { MeiliSearch, SearchResponse as MeiliSearchResponse, FacetsDistribution } from 'meilisearch';
import type { SearchResponse as MeiliSearchResponse, FacetsDistribution } from 'meilisearch';
import type { SearchClient } from 'instantsearch.js';

@@ -20,2 +20,3 @@ import type { MultipleQueriesQuery as AlgoliaMultipleQueriesQuery } from '@algolia/client-search';

keepZeroFacets?: boolean;
finitePagination?: boolean;
};

@@ -34,2 +35,3 @@ export declare type SearchCacheInterface = {

paginationTotalHits: number;
finitePagination: boolean;
};

@@ -45,7 +47,2 @@ export declare type GeoSearchContext = {

};
export declare type SearchContext = Omit<InstantSearchParams & ClientParams, 'insideBoundingBox'> & {
insideBoundingBox?: InsideBoundingBox;
keepZeroFacets?: boolean;
defaultFacetDistribution: FacetsDistribution;
};
export declare type PaginationContext = {

@@ -56,5 +53,14 @@ paginationTotalHits: number;

};
export declare type InstantMeiliSearchInstance = SearchClient & {
MeiliSearchClient: MeiliSearch;
export declare type PaginationParams = {
paginationTotalHits?: number;
hitsPerPage?: number;
page?: number;
};
export declare type SearchContext = Omit<InstantSearchParams & ClientParams, 'insideBoundingBox' | 'paginationTotalHits'> & {
insideBoundingBox?: InsideBoundingBox;
keepZeroFacets?: boolean;
defaultFacetDistribution: FacetsDistribution;
pagination: PaginationContext;
};
export declare type InstantMeiliSearchInstance = SearchClient;
//# sourceMappingURL=types.d.ts.map
{
"name": "@meilisearch/instant-meilisearch",
"version": "0.6.2",
"version": "0.7.0",
"private": false,
"description": "The search client to use Meilisearch with InstantSearch.",
"scripts": {
"clear_jest": "jest --clearCache",
"cleanup": "shx rm -rf dist/",

@@ -13,3 +14,3 @@ "test:watch": "yarn test --watch",

"test:e2e:watch": "yarn local:env:setup && concurrently --kill-others -s first \"yarn local:env:react\" \"cypress open --env playground=local\"",
"test:all": "yarn test:e2e:all && yarn test && test:build",
"test:all": "yarn test:e2e && yarn test && yarn test:build",
"cy:open": "cypress open",

@@ -76,3 +77,3 @@ "playground:vue": "yarn --cwd ./playgrounds/vue && yarn --cwd ./playgrounds/vue serve",

"babel-jest": "^27.2.2",
"concurrently": "^7.0.0",
"concurrently": "^7.1.0",
"cssnano": "^4.1.10",

@@ -95,3 +96,3 @@ "cypress": "^8.6.0",

"eslint-plugin-vue": "^7.7.0",
"instantsearch.js": "^4.39.1",
"instantsearch.js": "^4.40.2",
"jest": "^27.2.2",

@@ -109,4 +110,4 @@ "jest-watch-typeahead": "^0.6.3",

"tslib": "^2.3.1",
"typescript": "^4.6.2"
"typescript": "^4.6.3"
}
}

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

- [`paginationTotalHits`](#pagination-total-hits): Maximum total number of hits to create a finite pagination (default: `200`).
- [`finitePagination`](#finite-pagination): Used to work with the [`pagination`](#-pagination) widget (default: `false`) .
- [`primaryKey`](#primary-key): Specify the primary key of your documents (default `undefined`).

@@ -115,13 +116,27 @@ - [`keepZeroFacets`](#keep-zero-facets): Show the facets value even when they have 0 matches (default `false`).

The total (and finite) number of hits you can browse during pagination when using the [pagination widget](https://www.algolia.com/doc/api-reference/widgets/pagination/js/). If the pagination widget is not used, `paginationTotalHits` is ignored.<br>
The total (and finite) number of hits (default: `200`) you can browse during pagination when using the [pagination widget](https://www.algolia.com/doc/api-reference/widgets/pagination/js/) or the [`infiniteHits` widget](#-infinitehits). If none of these widgets are used, `paginationTotalHits` is ignored.<br>
Which means that, with a `paginationTotalHits` default value of 200, and `hitsPerPage` default value of 20, you can browse `paginationTotalHits / hitsPerPage` => `200 / 20 = 10` pages during pagination. Each of the 10 pages containing 20 results.<br>
For example, using the `infiniteHits` widget, and a `paginationTotalHits` of 9. On the first search request 6 hits are shown, by clicking a second time on `load more` only 3 more hits are added. This is because `paginationTotalHits` is `9`.
The default value of `hitsPerPage` is set to `20` but it can be changed with [`InsantSearch.configure`](https://www.algolia.com/doc/api-reference/widgets/configure/js/#examples).<br>
Usage:
```js
{ paginationTotalHits : 20 } // default: 200
{ paginationTotalHits: 50 } // default: 200
```
⚠️ Meilisearch is not designed for pagination and this can lead to performances issues, so the usage of the pagination widget is not encouraged. However, the `paginationTotalHits` parameter lets you implement this pagination with less performance issue as possible: depending on your dataset (the size of each document and the number of documents) you might decrease the value of `paginationTotalHits`.<br>
`hitsPerPage` has a value of `20` by default and can [be customized](#-hitsperpage).
### Finite Pagination
Finite pagination is used when you want to add a numbered pagination at the bottom of your hits (for example: `< << 1, 2, 3 > >>`).
To be able to know the amount of page numbers you have, a search is done requesting `paginationTotalHits` documents (default: `200`).
With the amount of documents returned, instantsearch is able to render the correct amount of numbers in the pagination widget.
Example:
```js
{ finitePagination: true } // default: false
```
⚠️ Meilisearch is not designed for pagination and this can lead to performances issues, so the usage `finitePagination` but also of the pagination widgets are not recommended.<br>
More information about Meilisearch and the pagination [here](https://github.com/meilisearch/documentation/issues/561).

@@ -375,3 +390,3 @@

instantsearch.widgets.configure({
hitsPerPage: 6,
hitsPerPage: 20,
// other algoliasearch parameters

@@ -378,0 +393,0 @@ })

@@ -6,4 +6,5 @@ import { adaptSearchParams } from '../search-params-adapter'

indexUid: 'test',
paginationTotalHits: 20,
pagination: { paginationTotalHits: 20, page: 0, hitsPerPage: 6 },
defaultFacetDistribution: {},
finitePagination: false,
})

@@ -17,6 +18,7 @@ expect(searchParams.attributesToHighlight).toContain('*')

indexUid: 'test',
paginationTotalHits: 20,
pagination: { paginationTotalHits: 20, page: 0, hitsPerPage: 6 },
facetFilters: [['genres:Drama', 'genres:Thriller'], ['title:Ariel']],
sort: 'id < 1',
defaultFacetDistribution: {},
finitePagination: false,
})

@@ -36,3 +38,3 @@

indexUid: 'test',
paginationTotalHits: 20,
pagination: { paginationTotalHits: 20, page: 0, hitsPerPage: 6 },
facetFilters: [['genres:Drama', 'genres:Thriller'], ['title:Ariel']],

@@ -42,2 +44,3 @@ insideBoundingBox: '0,0,0,0',

defaultFacetDistribution: {},
finitePagination: false,
})

@@ -58,6 +61,7 @@

indexUid: 'test',
paginationTotalHits: 20,
pagination: { paginationTotalHits: 20, page: 0, hitsPerPage: 6 },
facetFilters: [['genres:Drama', 'genres:Thriller'], ['title:Ariel']],
insideBoundingBox: '0,0,0,0',
defaultFacetDistribution: {},
finitePagination: false,
})

@@ -77,6 +81,7 @@

indexUid: 'test',
paginationTotalHits: 20,
pagination: { paginationTotalHits: 20, page: 0, hitsPerPage: 6 },
insideBoundingBox: '0,0,0,0',
sort: 'id < 1',
defaultFacetDistribution: {},
finitePagination: false,
})

@@ -93,5 +98,6 @@

indexUid: 'test',
paginationTotalHits: 20,
pagination: { paginationTotalHits: 20, page: 0, hitsPerPage: 6 },
insideBoundingBox: '0,0,0,0',
defaultFacetDistribution: {},
finitePagination: false,
})

@@ -103,1 +109,111 @@

})
test('Adapt SearchContext with finite pagination', () => {
const searchParams = adaptSearchParams({
indexUid: 'test',
pagination: { paginationTotalHits: 20, page: 0, hitsPerPage: 6 },
insideBoundingBox: '0,0,0,0',
defaultFacetDistribution: {},
finitePagination: true,
})
expect(searchParams.limit).toBe(20)
})
test('Adapt SearchContext with finite pagination on a later page', () => {
const searchParams = adaptSearchParams({
indexUid: 'test',
pagination: { paginationTotalHits: 20, page: 10, hitsPerPage: 6 },
insideBoundingBox: '0,0,0,0',
defaultFacetDistribution: {},
finitePagination: true,
})
expect(searchParams.limit).toBe(20)
})
test('Adapt SearchContext with finite pagination and pagination total hits lower than hitsPerPage', () => {
const searchParams = adaptSearchParams({
indexUid: 'test',
pagination: { paginationTotalHits: 4, page: 0, hitsPerPage: 6 },
insideBoundingBox: '0,0,0,0',
defaultFacetDistribution: {},
finitePagination: true,
})
expect(searchParams.limit).toBe(4)
})
test('Adapt SearchContext with no finite pagination', () => {
const searchParams = adaptSearchParams({
indexUid: 'test',
pagination: { paginationTotalHits: 20, page: 0, hitsPerPage: 6 },
insideBoundingBox: '0,0,0,0',
defaultFacetDistribution: {},
finitePagination: false,
})
expect(searchParams.limit).toBe(7)
})
test('Adapt SearchContext with no finite pagination on page 2', () => {
const searchParams = adaptSearchParams({
indexUid: 'test',
pagination: { paginationTotalHits: 20, page: 1, hitsPerPage: 6 },
insideBoundingBox: '0,0,0,0',
defaultFacetDistribution: {},
finitePagination: false,
})
expect(searchParams.limit).toBe(13)
})
test('Adapt SearchContext with no finite pagination on page higher than paginationTotalHits', () => {
const searchParams = adaptSearchParams({
indexUid: 'test',
pagination: { paginationTotalHits: 20, page: 40, hitsPerPage: 6 },
insideBoundingBox: '0,0,0,0',
defaultFacetDistribution: {},
finitePagination: false,
})
expect(searchParams.limit).toBe(20)
})
test('Adapt SearchContext with no finite pagination and pagination total hits lower than hitsPerPage', () => {
const searchParams = adaptSearchParams({
indexUid: 'test',
pagination: { paginationTotalHits: 4, page: 0, hitsPerPage: 6 },
insideBoundingBox: '0,0,0,0',
defaultFacetDistribution: {},
finitePagination: false,
})
expect(searchParams.limit).toBe(4)
})
test('Adapt SearchContext placeholderSearch set to false', () => {
const searchParams = adaptSearchParams({
indexUid: 'test',
query: '',
pagination: { paginationTotalHits: 4, page: 0, hitsPerPage: 6 },
defaultFacetDistribution: {},
finitePagination: false,
placeholderSearch: false,
})
expect(searchParams.limit).toBe(0)
})
test('Adapt SearchContext placeholderSearch set to false', () => {
const searchParams = adaptSearchParams({
indexUid: 'test',
query: '',
pagination: { paginationTotalHits: 200, page: 0, hitsPerPage: 6 },
defaultFacetDistribution: {},
finitePagination: false,
placeholderSearch: true,
})
expect(searchParams.limit).toBe(7)
})

@@ -62,9 +62,23 @@ import type { MeiliSearchParams, SearchContext } from '../../types'

const query = searchContext.query
const paginationTotalHits = searchContext.paginationTotalHits
// Limit
if ((!placeholderSearch && query === '') || paginationTotalHits === 0) {
// Pagination
const { pagination } = searchContext
// Limit based on pagination preferences
if (
(!placeholderSearch && query === '') ||
pagination.paginationTotalHits === 0
) {
meiliSearchParams.limit = 0
} else if (searchContext.finitePagination) {
meiliSearchParams.limit = pagination.paginationTotalHits
} else {
meiliSearchParams.limit = paginationTotalHits
const limit = (pagination.page + 1) * pagination.hitsPerPage + 1
// If the limit is bigger than the total hits accepted
// force the limit to that amount
if (limit > pagination.paginationTotalHits) {
meiliSearchParams.limit = pagination.paginationTotalHits
} else {
meiliSearchParams.limit = limit
}
}

@@ -71,0 +85,0 @@

@@ -10,2 +10,13 @@ import {

const emptySearch: MeiliSearchResponse<Record<string, any>> = {
hits: [],
query: '',
facetsDistribution: {},
limit: 0,
offset: 0,
exhaustiveNbHits: false,
nbHits: 0,
processingTimeMs: 0,
}
/**

@@ -27,3 +38,19 @@ * @param {ResponseCacher} cache

): Promise<MeiliSearchResponse<Record<string, any>>> {
// Create key with relevant informations
const { placeholderSearch, query } = searchContext
// query can be: empty string, undefined or null
// all of them are falsy's
if (!placeholderSearch && !query) {
return emptySearch
}
const { pagination } = searchContext
// In case we are in a `finitePagination`, only one big request is made
// containing a total of max the paginationTotalHits (default: 200).
// Thus we dont want the pagination to impact the cache as every
// hits are already cached.
const paginationCache = searchContext.finitePagination ? {} : pagination
// Create cache key containing a unique set of search parameters
const key = cache.formatKey([

@@ -33,9 +60,9 @@ searchParams,

searchContext.query,
paginationCache,
])
const entry = cache.getEntry(key)
const cachedResponse = cache.getEntry(key)
// Request is cached.
if (entry) return entry
// Check if specific request is already cached with its associated search response.
if (cachedResponse) return cachedResponse
// Cache filters: todo components
const facetsCache = extractFacets(searchContext, searchParams)

@@ -42,0 +69,0 @@

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

import { SearchContext, PaginationContext } from '../../types'
/**

@@ -24,17 +22,1 @@ * Slice the requested hits based on the pagination position.

}
/**
* @param {AlgoliaMultipleQueriesQuery} searchRequest
* @param {Context} options
* @returns {SearchContext}
*/
export function createPaginationContext(
searchContext: SearchContext
): PaginationContext {
return {
paginationTotalHits: searchContext.paginationTotalHits || 200,
hitsPerPage:
searchContext.hitsPerPage === undefined ? 20 : searchContext.hitsPerPage, // 20 is the Meilisearch's default limit value. `hitsPerPage` can be changed with `InsantSearch.configure`.
page: searchContext?.page || 0, // default page is 0 if none is provided
}
}

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

import { adaptHits } from './hits-adapter'
import { createPaginationContext } from './pagination-adapter'

@@ -27,2 +26,3 @@ /**

const facets = searchResponse.facetsDistribution
const { pagination } = searchContext

@@ -34,9 +34,7 @@ const exhaustiveFacetsCount = searchResponse?.exhaustiveFacetsCount

const paginationContext = createPaginationContext(searchContext)
const nbPages = ceiledDivision(
searchResponse.hits.length,
paginationContext.hitsPerPage
pagination.hitsPerPage
)
const hits = adaptHits(searchResponse.hits, searchContext, paginationContext)
const hits = adaptHits(searchResponse.hits, searchContext, pagination)

@@ -48,3 +46,3 @@ const exhaustiveNbHits = searchResponse.exhaustiveNbHits

const { hitsPerPage, page } = paginationContext
const { hitsPerPage, page } = pagination

@@ -51,0 +49,0 @@ // Create response object compliant with InstantSearch

@@ -14,3 +14,3 @@ import { MeiliSearch } from 'meilisearch'

} from '../adapter'
import { createSearchContext } from './contexts'
import { createSearchContext } from '../contexts'
import { SearchCache, cacheFirstFacetsDistribution } from '../cache/'

@@ -35,6 +35,5 @@

let defaultFacetDistribution: any = {}
const meilisearchClient = new MeiliSearch({ host: hostUrl, apiKey: apiKey })
return {
MeiliSearchClient: new MeiliSearch({ host: hostUrl, apiKey: apiKey }),
/**

@@ -62,3 +61,3 @@ * @param {readonlyAlgoliaMultipleQueriesQuery[]} instantSearchRequests

adaptedSearchRequest,
this.MeiliSearchClient
meilisearchClient
)

@@ -85,3 +84,3 @@

},
searchForFacetValues: async function (_) {
searchForFacetValues: async function (_: any) {
return await new Promise((resolve, reject) => {

@@ -88,0 +87,0 @@ reject(

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

keepZeroFacets?: boolean
finitePagination?: boolean
}

@@ -53,2 +54,3 @@

paginationTotalHits: number
finitePagination: boolean
}

@@ -66,5 +68,17 @@

export type PaginationContext = {
paginationTotalHits: number
hitsPerPage: number
page: number
}
export type PaginationParams = {
paginationTotalHits?: number
hitsPerPage?: number
page?: number
}
export type SearchContext = Omit<
InstantSearchParams & ClientParams,
'insideBoundingBox'
'insideBoundingBox' | 'paginationTotalHits'
> & {

@@ -74,12 +88,5 @@ insideBoundingBox?: InsideBoundingBox

defaultFacetDistribution: FacetsDistribution
pagination: PaginationContext
}
export type PaginationContext = {
paginationTotalHits: number
hitsPerPage: number
page: number
}
export type InstantMeiliSearchInstance = SearchClient & {
MeiliSearchClient: MeiliSearch
}
export type InstantMeiliSearchInstance = SearchClient

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

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