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.5.6 to 0.5.7

dist/types/adapter/search-request-adapter/geo-rules-adapter.d.ts

203

dist/instant-meilisearch.cjs.js

@@ -260,2 +260,139 @@ 'use strict';

/**
* @param {number} rad
* @returns {number}
*/
function rad2degr(rad) {
return (rad * 180) / Math.PI;
}
/**
* @param {number} degr
* @returns {number}
*/
function degr2rad(degr) {
return (degr * Math.PI) / 180;
}
/**
* @param {number} lat1
* @param {number} lng1
* @param {number} lat2
* @param {number} lng2
* @returns {string}
*/
function middleGeoPoints(lat1, lng1, lat2, lng2) {
// convert to radians
lat1 = degr2rad(lat1);
lng1 = degr2rad(lng1);
var x1 = Math.cos(lat1) * Math.cos(lng1);
var y1 = Math.cos(lat1) * Math.sin(lng1);
var z1 = Math.sin(lat1);
// convert to radians
lat2 = degr2rad(lat2);
lng2 = degr2rad(lng2);
var x2 = Math.cos(lat2) * Math.cos(lng2);
var y2 = Math.cos(lat2) * Math.sin(lng2);
var z2 = Math.sin(lat2);
var x = x1 + x2;
var y = y1 + y2;
var z = z1 + z2;
var Hyp = Math.sqrt(x * x + y * y);
var lng3 = Math.atan2(y, x);
var lat3 = Math.atan2(z, Hyp);
lat3 = rad2degr(lat3);
lng3 = rad2degr(lng3);
if (Math.abs(x) < Math.pow(10, -9) &&
Math.abs(y) < Math.pow(10, -9) &&
Math.abs(z) < Math.pow(10, -9)) {
lat3 = 0;
lng3 = 0;
}
return lat3 + "," + lng3;
}
/**
* @param {number} lat1
* @param {number} lng1
* @param {number} lat2
* @param {number} lng2
* @returns {number}
*/
function getDistanceInMeter(lat1, lng1, lat2, lng2) {
// Haversine Algorithm
var R = 6371e3; // metres
var latRad1 = (lat1 * Math.PI) / 180;
var latRad2 = (lat2 * Math.PI) / 180;
var latCenterRad = ((lat2 - lat1) * Math.PI) / 180;
var lngCenterRad = ((lng2 - lng1) * Math.PI) / 180;
var a = Math.sin(latCenterRad / 2) * Math.sin(latCenterRad / 2) +
Math.cos(latRad1) *
Math.cos(latRad2) *
Math.sin(lngCenterRad / 2) *
Math.sin(lngCenterRad / 2);
var bearing = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
var distance = R * bearing; // in metres
return distance;
}
function adaptGeoPointsRules(geoSearchContext) {
if (!geoSearchContext) {
return undefined;
}
var insideBoundingBox = geoSearchContext.insideBoundingBox, aroundLatLng = geoSearchContext.aroundLatLng, aroundRadius = geoSearchContext.aroundRadius, minimumAroundRadius = geoSearchContext.minimumAroundRadius;
var middlePoint;
var radius;
if (aroundLatLng) {
middlePoint = aroundLatLng;
}
if (aroundRadius != null || minimumAroundRadius != null) {
if (aroundRadius != null)
radius = aroundRadius;
else
radius = minimumAroundRadius;
}
// If insideBoundingBox is provided it takes precedent over all other options
if (insideBoundingBox && typeof insideBoundingBox === 'string') {
var _a = insideBoundingBox.split(','), lat1Raw = _a[0], lng1Raw = _a[1], lat2Raw = _a[2], lng2Raw = _a[3];
var _b = [
parseFloat(lat1Raw),
parseFloat(lng1Raw),
parseFloat(lat2Raw),
parseFloat(lng2Raw),
], lat1 = _b[0], lng1 = _b[1], lat2 = _b[2], lng2 = _b[3];
radius = getDistanceInMeter(lat1, lng1, lat2, lng2) / 2;
middlePoint = middleGeoPoints(lat1, lng1, lat2, lng2);
}
if (middlePoint != null && radius != null) {
var _c = middlePoint.split(','), lat3 = _c[0], lng3 = _c[1];
var filter = "_geoRadius(" + lat3 + ", " + lng3 + ", " + radius + ")";
return { filter: filter };
}
return undefined;
}
function createGeoSearchContext(searchContext) {
var geoContext = {};
var aroundLatLng = searchContext.aroundLatLng, aroundLatLngViaIP = searchContext.aroundLatLngViaIP, aroundRadius = searchContext.aroundRadius, aroundPrecision = searchContext.aroundPrecision, minimumAroundRadius = searchContext.minimumAroundRadius, insideBoundingBox = searchContext.insideBoundingBox, insidePolygon = searchContext.insidePolygon;
if (aroundLatLng) {
geoContext.aroundLatLng = aroundLatLng;
}
if (aroundLatLngViaIP) {
console.warn('instant-meilisearch: `aroundLatLngViaIP` is not supported.');
}
if (aroundRadius) {
geoContext.aroundRadius = aroundRadius;
}
if (aroundPrecision) {
console.warn("instant-meilisearch: `aroundPrecision` is not supported.\n See this discussion to track its implementation https://github.com/meilisearch/product/discussions/264");
}
if (minimumAroundRadius) {
geoContext.minimumAroundRadius = minimumAroundRadius;
}
if (insideBoundingBox) {
geoContext.insideBoundingBox = insideBoundingBox;
}
// See related issue: https://github.com/meilisearch/instant-meilisearch/issues/555
if (insidePolygon) {
console.warn("instant-meilisearch: `insidePolygon` is not implented in instant-meilisearch.");
}
return geoContext;
}
/**
* Transform InstantSearch filter to MeiliSearch filter.

@@ -378,5 +515,6 @@ * Change sign from `:` to `=` in nested filter object.

];
var placeholderSearch = meiliSearchParams.placeholderSearch;
var query = meiliSearchParams.query;
var paginationTotalHits = meiliSearchParams.paginationTotalHits;
var placeholderSearch = searchContext.placeholderSearch;
var query = searchContext.query;
var paginationTotalHits = searchContext.paginationTotalHits;
// Limit
if ((!placeholderSearch && query === '') || paginationTotalHits === 0) {

@@ -393,2 +531,12 @@ meiliSearchParams.limit = 0;

}
var geoSearchContext = createGeoSearchContext(searchContext);
var geoRules = adaptGeoPointsRules(geoSearchContext);
if (geoRules === null || geoRules === void 0 ? void 0 : geoRules.filter) {
if (meiliSearchParams.filter) {
meiliSearchParams.filter.unshift(geoRules.filter);
}
else {
meiliSearchParams.filter = [geoRules.filter];
}
}
return meiliSearchParams;

@@ -440,6 +588,10 @@ }

// It contains all the highlighted and croped attributes
var toHighlightMatch = function (value) { return ({
value: replaceHighlightTags(value, highlightPreTag, highlightPostTag),
}); };
return Object.keys(formattedHit).reduce(function (result, key) {
result[key] = {
value: replaceHighlightTags(formattedHit[key], highlightPreTag, highlightPostTag),
};
var value = formattedHit[key];
result[key] = Array.isArray(value)
? value.map(toHighlightMatch)
: toHighlightMatch(value);
return result;

@@ -484,9 +636,14 @@ }, {});

attributesToSnippet = attributesToSnippet.map(function (attribute) { return attribute.split(':')[0]; });
var snippetAll = attributesToSnippet.includes('*');
// formattedHit is the `_formatted` object returned by MeiliSearch.
// It contains all the highlighted and croped attributes
var toSnippetMatch = function (value) { return ({
value: snippetValue(value, snippetEllipsisText, highlightPreTag, highlightPostTag),
}); };
return Object.keys(formattedHit).reduce(function (result, key) {
if (attributesToSnippet === null || attributesToSnippet === void 0 ? void 0 : attributesToSnippet.includes(key)) {
result[key] = {
value: snippetValue(formattedHit[key], snippetEllipsisText, highlightPreTag, highlightPostTag),
};
if (snippetAll || (attributesToSnippet === null || attributesToSnippet === void 0 ? void 0 : attributesToSnippet.includes(key))) {
var value = formattedHit[key];
result[key] = Array.isArray(value)
? value.map(toSnippetMatch)
: toSnippetMatch(value);
}

@@ -517,2 +674,20 @@ return result;

/**
* @param {any[]} hits
* @returns {Array<Record<string, any>>}
*/
function adaptGeoResponse(hits) {
for (var i = 0; i < hits.length; i++) {
if (hits[i]._geo) {
hits[i]._geoloc = {
lat: hits[i]._geo.lat,
lng: hits[i]._geo.lng,
};
hits[i].objectID = "" + (i + Math.random() * 1000000);
delete hits[i]._geo;
}
}
return hits;
}
/**
* @param {Array<Record<string} hits

@@ -527,3 +702,3 @@ * @param {SearchContext} searchContext

var paginatedHits = adaptPagination(hits, page, hitsPerPage);
return paginatedHits.map(function (hit) {
var formattedHits = paginatedHits.map(function (hit) {
// Creates Hit object compliant with InstantSearch

@@ -536,2 +711,4 @@ if (Object.keys(hit).length > 0) {

});
formattedHits = adaptGeoResponse(formattedHits);
return formattedHits;
}

@@ -610,6 +787,8 @@

var searchResolver = SearchResolver(SearchCache());
// paginationTotalHits can be 0 as it is a valid number
var paginationTotalHits = options.paginationTotalHits != null ? options.paginationTotalHits : 200;
var context = {
primaryKey: options.primaryKey || undefined,
placeholderSearch: options.placeholderSearch !== false,
paginationTotalHits: options.paginationTotalHits || 200,
paginationTotalHits: paginationTotalHits,
};

@@ -616,0 +795,0 @@ return {

4

dist/instant-meilisearch.cjs.min.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("meilisearch"),e=function(){return(e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("meilisearch"),n=function(){return(n=Object.assign||function(t){for(var n,r=1,e=arguments.length;r<e;r++)for(var i in n=arguments[r])Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i]);return t}).apply(this,arguments)};
/*! *****************************************************************************

@@ -15,3 +15,3 @@ Copyright (c) Microsoft Corporation.

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function r(t,e,r,n){return new(r||(r=Promise))((function(i,o){function a(t){try{s(n.next(t))}catch(t){o(t)}}function u(t){try{s(n.throw(t))}catch(t){o(t)}}function s(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,u)}s((n=n.apply(t,e||[])).next())}))}function n(t,e){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}}function i(t,e){for(var r=0,n=e.length,i=t.length;r<n;r++,i++)t[i]=e[r];return t}function o(t){return"string"==typeof t||t instanceof String}function a(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 r=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 r.filter((function(t){return void 0!==t})).reduce((function(t,r){var n,o=r.filterName,a=r.value,u=t[o]||[];return t=e(e({},t),((n={})[o]=i(i([],u),[a]),n))}),{})}function c(t){return{searchResponse:function(e,i,o){return r(this,void 0,void 0,(function(){var r,a,u,c;return n(this,(function(n){switch(n.label){case 0:return r=t.formatKey([i,e.indexUid,e.query]),(a=t.getEntry(r))?[2,a]:(u=s(null==i?void 0:i.filter),[4,o.index(e.indexUid).search(e.query,i)]);case 1:return(c=n.sent()).facetsDistribution=function(t,e){if(e=e||{},t&&Object.keys(t).length>0)for(var r in t){e[r]||(e[r]={});for(var n=0,i=t[r];n<i.length;n++){var o=i[n];Object.keys(e[r]).includes(o)||(e[r][o]=0)}}return e}(u,c.facetsDistribution),t.setEntry(r,c),[2,c]}}))}))}}}function l(t){return"string"==typeof t?a(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return a(t)})).filter((function(t){return t})):a(t)})).filter((function(t){return t})):[]}function f(t){return""===t?[]:"string"==typeof t?[t]:t}function h(t,e,r){return function(t,e,r){var n=r.trim(),o=f(t),a=f(e);return i(i(i([],o),a),[n]).filter((function(t){return Array.isArray(t)?t.length:t}))}(l(r||[]),l(e||[]),t||"")}function p(t,e,r){return e=e||"__ais-highlight__",r=r||"__/ais-highlight__",(o(t)?t:JSON.stringify(t,null,2)).replace(/<em>/g,e).replace(/<\/em>/g,r)}function v(t,e,r){return Object.keys(t).reduce((function(n,i){return n[i]={value:p(t[i],e,r)},n}),{})}function y(t,e,r,n){var i=t;return void 0!==e&&o(i)&&i&&(i[0]===i[0].toLowerCase()&&!1===i.startsWith("<em>")&&(i=""+e+i),!1==!!i.match(/[.!?]$/)&&(i=""+i+e)),p(i,r,n)}function g(t,e,r,n,i){return void 0===e?null:(e=e.map((function(t){return t.split(":")[0]})),Object.keys(t).reduce((function(o,a){return(null==e?void 0:e.includes(a))&&(o[a]={value:y(t[a],r,n,i)}),o}),{}))}function d(t,r,n){var i=r.primaryKey,o=n.hitsPerPage;return function(t,e,r){var n=e*r;return t.splice(n,r)}(t,n.page,o).map((function(t){if(Object.keys(t).length>0){var n=t._formatted;t._matchesInfo;var o=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r}(t,["_formatted","_matchesInfo"]);return e(e(e({},o),function(t,e){var r=null==e?void 0:e.attributesToSnippet,n=null==e?void 0:e.snippetEllipsisText,i=null==e?void 0:e.highlightPreTag,o=null==e?void 0:e.highlightPostTag;return!t||t.length?{}:{_highlightResult:v(t,i,o),_snippetResult:g(t,r,n,i,o)}}(n,r)),i&&{objectID:t[i]})}return t}))}function b(t,r,n){var i={},o=t.facetsDistribution,a=null==t?void 0:t.exhaustiveFacetsCount;a&&(i.exhaustiveFacetsCount=a);var u,s,c=d(t.hits,r,n),l=(u=t.hits.length,(s=n.hitsPerPage)>0?Math.ceil(u/s):0),f=t.exhaustiveNbHits,h=t.nbHits,p=t.processingTimeMs,v=t.query,y=n.hitsPerPage,g=n.page;return{results:[e({index:r.indexUid,hitsPerPage:y,page:g,facets:o,nbPages:l,exhaustiveNbHits:f,nbHits:h,processingTimeMS:p,query:v,hits:c,params:""},i)]}}function m(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(r){return e[t]}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,r){e[t]=JSON.stringify(r)}}}exports.instantMeiliSearch=function(i,o,a){void 0===o&&(o=""),void 0===a&&(a={});var u=c(m()),s={primaryKey:a.primaryKey||void 0,placeholderSearch:!1!==a.placeholderSearch,paginationTotalHits:a.paginationTotalHits||200};return{MeiliSearchClient:new t.MeiliSearch({host:i,apiKey:o}),search:function(t){return r(this,void 0,void 0,(function(){var r,i,o,a,c,l,f;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),r=t[0],i=r.params,o=function(t,r){var n=t.indexName.split(":"),i=n[0],o=n.slice(1),a=t.params;return e(e(e({},r),a),{sort:o.join(":")||"",indexUid:i})}(r,s),a=function(t,e){return{paginationTotalHits:t.paginationTotalHits||200,hitsPerPage:void 0===t.hitsPerPage?20:t.hitsPerPage,page:(null==e?void 0:e.page)||0}}(o,i),c=function(t){var e={},r=null==t?void 0:t.facets;(null==r?void 0:r.length)&&(e.facetsDistribution=r);var n=null==t?void 0:t.attributesToSnippet;n&&(e.attributesToCrop=n);var i=null==t?void 0:t.attributesToRetrieve;i&&(e.attributesToRetrieve=i);var o=h(null==t?void 0:t.filters,null==t?void 0:t.numericFilters,null==t?void 0:t.facetFilters);o.length&&(e.filter=o),i&&(e.attributesToCrop=i),e.attributesToHighlight=(null==t?void 0:t.attributesToHighlight)||["*"];var a=e.placeholderSearch,u=e.query,s=e.paginationTotalHits;e.limit=!a&&""===u||0===s?0:s;var c=t.sort;return(null==c?void 0:c.length)&&(e.sort=[c]),e}(o),[4,u.searchResponse(o,c,this.MeiliSearchClient)];case 1:return l=n.sent(),[2,b(l,o,a)];case 2:throw f=n.sent(),console.error(f),new Error(f);case 3:return[2]}}))}))},searchForFacetValues:function(t){return r(this,void 0,void 0,(function(){return n(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 r(t,n,r,e){return new(r||(r=Promise))((function(i,a){function o(t){try{s(e.next(t))}catch(t){a(t)}}function u(t){try{s(e.throw(t))}catch(t){a(t)}}function s(t){var n;t.done?i(t.value):(n=t.value,n instanceof r?n:new r((function(t){t(n)}))).then(o,u)}s((e=e.apply(t,n||[])).next())}))}function e(t,n){var r,e,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(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,e&&(i=2&a[0]?e.return:a[0]?e.throw||((i=e.return)&&i.call(e),0):e.next)&&!(i=i.call(e,a[1])).done)return i;switch(e=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++,e=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],e=0}finally{r=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 r=0,e=n.length,i=t.length;r<e;r++,i++)t[i]=n[r];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 r=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 r.filter((function(t){return void 0!==t})).reduce((function(t,r){var e,a=r.filterName,o=r.value,u=t[a]||[];return t=n(n({},t),((e={})[a]=i(i([],u),[o]),e))}),{})}function l(t){return{searchResponse:function(n,i,a){return r(this,void 0,void 0,(function(){var r,o,u,l;return e(this,(function(e){switch(e.label){case 0:return r=t.formatKey([i,n.indexUid,n.query]),(o=t.getEntry(r))?[2,o]:(u=s(null==i?void 0:i.filter),[4,a.index(n.indexUid).search(n.query,i)]);case 1:return(l=e.sent()).facetsDistribution=function(t,n){if(n=n||{},t&&Object.keys(t).length>0)for(var r in t){n[r]||(n[r]={});for(var e=0,i=t[r];e<i.length;e++){var a=i[e];Object.keys(n[r]).includes(a)||(n[r][a]=0)}}return n}(u,l.facetsDistribution),t.setEntry(r,l),[2,l]}}))}))}}}function c(t){return 180*t/Math.PI}function f(t){return t*Math.PI/180}function h(t){if(t){var n,r,e=t.insideBoundingBox,i=t.aroundLatLng,a=t.aroundRadius,o=t.minimumAroundRadius;if(i&&(n=i),null==a&&null==o||(r=null!=a?a:o),e&&"string"==typeof e){var u=e.split(","),s=u[0],l=u[1],h=u[2],p=u[3],d=[parseFloat(s),parseFloat(l),parseFloat(h),parseFloat(p)],v=d[0],g=d[1],y=d[2],m=d[3];r=function(t,n,r,e){var i=t*Math.PI/180,a=r*Math.PI/180,o=(r-t)*Math.PI/180,u=(e-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}(v,g,y,m)/2,n=function(t,n,r,e){t=f(t),n=f(n);var i=Math.cos(t)*Math.cos(n),a=Math.cos(t)*Math.sin(n),o=Math.sin(t);r=f(r),e=f(e);var u=i+Math.cos(r)*Math.cos(e),s=a+Math.cos(r)*Math.sin(e),l=o+Math.sin(r),h=Math.sqrt(u*u+s*s),p=Math.atan2(s,u),d=Math.atan2(l,h);return d=c(d),p=c(p),Math.abs(u)<Math.pow(10,-9)&&Math.abs(s)<Math.pow(10,-9)&&Math.abs(l)<Math.pow(10,-9)&&(d=0,p=0),d+","+p}(v,g,y,m)}if(null!=n&&null!=r){var b=n.split(",");return{filter:"_geoRadius("+b[0]+", "+b[1]+", "+r+")"}}}}function p(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 d(t){return""===t?[]:"string"==typeof t?[t]:t}function v(t,n,r){return function(t,n,r){var e=r.trim(),a=d(t),o=d(n);return i(i(i([],a),o),[e]).filter((function(t){return Array.isArray(t)?t.length:t}))}(p(r||[]),p(n||[]),t||"")}function g(t){var n={},r=null==t?void 0:t.facets;(null==r?void 0:r.length)&&(n.facetsDistribution=r);var e=null==t?void 0:t.attributesToSnippet;e&&(n.attributesToCrop=e);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 l=t.sort;(null==l?void 0:l.length)&&(n.sort=[l]);var c=h(function(t){var n={},r=t.aroundLatLng,e=t.aroundLatLngViaIP,i=t.aroundRadius,a=t.aroundPrecision,o=t.minimumAroundRadius,u=t.insideBoundingBox,s=t.insidePolygon;return r&&(n.aroundLatLng=r),e&&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==c?void 0:c.filter)&&(n.filter?n.filter.unshift(c.filter):n.filter=[c.filter]),n}function y(t,n,r){return n=n||"__ais-highlight__",r=r||"__/ais-highlight__",(a(t)?t:JSON.stringify(t,null,2)).replace(/<em>/g,n).replace(/<\/em>/g,r)}function m(t,n,r){var e=function(t){return{value:y(t,n,r)}};return Object.keys(t).reduce((function(n,r){var i=t[r];return n[r]=Array.isArray(i)?i.map(e):e(i),n}),{})}function b(t,n,r,e){var i=t;return void 0!==n&&a(i)&&i&&(i[0]===i[0].toLowerCase()&&!1===i.startsWith("<em>")&&(i=""+n+i),!1==!!i.match(/[.!?]$/)&&(i=""+i+n)),y(i,r,e)}function M(t,n,r,e,i){if(void 0===n)return null;var a=(n=n.map((function(t){return t.split(":")[0]}))).includes("*"),o=function(t){return{value:b(t,r,e,i)}};return Object.keys(t).reduce((function(r,e){if(a||(null==n?void 0:n.includes(e))){var i=t[e];r[e]=Array.isArray(i)?i.map(o):o(i)}return r}),{})}function P(t,r,e){var i=r.primaryKey,a=e.hitsPerPage,o=function(t,n,r){var e=n*r;return t.splice(e,r)}(t,e.page,a).map((function(t){if(Object.keys(t).length>0){var e=t._formatted;t._matchesInfo;var a=function(t,n){var r={};for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&n.indexOf(e)<0&&(r[e]=t[e]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(e=Object.getOwnPropertySymbols(t);i<e.length;i++)n.indexOf(e[i])<0&&Object.prototype.propertyIsEnumerable.call(t,e[i])&&(r[e[i]]=t[e[i]])}return r}(t,["_formatted","_matchesInfo"]);return n(n(n({},a),function(t,n){var r=null==n?void 0:n.attributesToSnippet,e=null==n?void 0:n.snippetEllipsisText,i=null==n?void 0:n.highlightPreTag,a=null==n?void 0:n.highlightPostTag;return!t||t.length?{}:{_highlightResult:m(t,i,a),_snippetResult:M(t,r,e,i,a)}}(e,r)),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=""+(n+1e6*Math.random()),delete t[n]._geo);return t}(o)}function w(t,r,e){var i={},a=t.facetsDistribution,o=null==t?void 0:t.exhaustiveFacetsCount;o&&(i.exhaustiveFacetsCount=o);var u,s,l=P(t.hits,r,e),c=(u=t.hits.length,(s=e.hitsPerPage)>0?Math.ceil(u/s):0),f=t.exhaustiveNbHits,h=t.nbHits,p=t.processingTimeMs,d=t.query,v=e.hitsPerPage,g=e.page;return{results:[n({index:r.indexUid,hitsPerPage:v,page:g,facets:a,nbPages:c,exhaustiveNbHits:f,nbHits:h,processingTimeMS:p,query:d,hits:l,params:""},i)]}}function x(t){void 0===t&&(t={});var n=t;return{getEntry:function(t){if(n[t])try{return JSON.parse(n[t])}catch(r){return n[t]}},formatKey:function(t){return t.reduce((function(t,n){return t+JSON.stringify(n)}),"")},setEntry:function(t,r){n[t]=JSON.stringify(r)}}}exports.instantMeiliSearch=function(i,a,o){void 0===a&&(a=""),void 0===o&&(o={});var u=l(x()),s=null!=o.paginationTotalHits?o.paginationTotalHits:200,c={primaryKey:o.primaryKey||void 0,placeholderSearch:!1!==o.placeholderSearch,paginationTotalHits:s};return{MeiliSearchClient:new t.MeiliSearch({host:i,apiKey:a}),search:function(t){return r(this,void 0,void 0,(function(){var r,i,a,o,s,l,f;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),r=t[0],i=r.params,a=function(t,r){var e=t.indexName.split(":"),i=e[0],a=e.slice(1),o=t.params;return n(n(n({},r),o),{sort:a.join(":")||"",indexUid:i})}(r,c),o=function(t,n){return{paginationTotalHits:t.paginationTotalHits||200,hitsPerPage:void 0===t.hitsPerPage?20:t.hitsPerPage,page:(null==n?void 0:n.page)||0}}(a,i),s=g(a),[4,u.searchResponse(a,s,this.MeiliSearchClient)];case 1:return l=e.sent(),[2,w(l,a,o)];case 2:throw f=e.sent(),console.error(f),new Error(f);case 3:return[2]}}))}))},searchForFacetValues:function(t){return r(this,void 0,void 0,(function(){return e(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()]}}))}))}}};
//# sourceMappingURL=instant-meilisearch.cjs.min.js.map

@@ -256,2 +256,139 @@ import { MeiliSearch } from 'meilisearch';

/**
* @param {number} rad
* @returns {number}
*/
function rad2degr(rad) {
return (rad * 180) / Math.PI;
}
/**
* @param {number} degr
* @returns {number}
*/
function degr2rad(degr) {
return (degr * Math.PI) / 180;
}
/**
* @param {number} lat1
* @param {number} lng1
* @param {number} lat2
* @param {number} lng2
* @returns {string}
*/
function middleGeoPoints(lat1, lng1, lat2, lng2) {
// convert to radians
lat1 = degr2rad(lat1);
lng1 = degr2rad(lng1);
var x1 = Math.cos(lat1) * Math.cos(lng1);
var y1 = Math.cos(lat1) * Math.sin(lng1);
var z1 = Math.sin(lat1);
// convert to radians
lat2 = degr2rad(lat2);
lng2 = degr2rad(lng2);
var x2 = Math.cos(lat2) * Math.cos(lng2);
var y2 = Math.cos(lat2) * Math.sin(lng2);
var z2 = Math.sin(lat2);
var x = x1 + x2;
var y = y1 + y2;
var z = z1 + z2;
var Hyp = Math.sqrt(x * x + y * y);
var lng3 = Math.atan2(y, x);
var lat3 = Math.atan2(z, Hyp);
lat3 = rad2degr(lat3);
lng3 = rad2degr(lng3);
if (Math.abs(x) < Math.pow(10, -9) &&
Math.abs(y) < Math.pow(10, -9) &&
Math.abs(z) < Math.pow(10, -9)) {
lat3 = 0;
lng3 = 0;
}
return lat3 + "," + lng3;
}
/**
* @param {number} lat1
* @param {number} lng1
* @param {number} lat2
* @param {number} lng2
* @returns {number}
*/
function getDistanceInMeter(lat1, lng1, lat2, lng2) {
// Haversine Algorithm
var R = 6371e3; // metres
var latRad1 = (lat1 * Math.PI) / 180;
var latRad2 = (lat2 * Math.PI) / 180;
var latCenterRad = ((lat2 - lat1) * Math.PI) / 180;
var lngCenterRad = ((lng2 - lng1) * Math.PI) / 180;
var a = Math.sin(latCenterRad / 2) * Math.sin(latCenterRad / 2) +
Math.cos(latRad1) *
Math.cos(latRad2) *
Math.sin(lngCenterRad / 2) *
Math.sin(lngCenterRad / 2);
var bearing = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
var distance = R * bearing; // in metres
return distance;
}
function adaptGeoPointsRules(geoSearchContext) {
if (!geoSearchContext) {
return undefined;
}
var insideBoundingBox = geoSearchContext.insideBoundingBox, aroundLatLng = geoSearchContext.aroundLatLng, aroundRadius = geoSearchContext.aroundRadius, minimumAroundRadius = geoSearchContext.minimumAroundRadius;
var middlePoint;
var radius;
if (aroundLatLng) {
middlePoint = aroundLatLng;
}
if (aroundRadius != null || minimumAroundRadius != null) {
if (aroundRadius != null)
radius = aroundRadius;
else
radius = minimumAroundRadius;
}
// If insideBoundingBox is provided it takes precedent over all other options
if (insideBoundingBox && typeof insideBoundingBox === 'string') {
var _a = insideBoundingBox.split(','), lat1Raw = _a[0], lng1Raw = _a[1], lat2Raw = _a[2], lng2Raw = _a[3];
var _b = [
parseFloat(lat1Raw),
parseFloat(lng1Raw),
parseFloat(lat2Raw),
parseFloat(lng2Raw),
], lat1 = _b[0], lng1 = _b[1], lat2 = _b[2], lng2 = _b[3];
radius = getDistanceInMeter(lat1, lng1, lat2, lng2) / 2;
middlePoint = middleGeoPoints(lat1, lng1, lat2, lng2);
}
if (middlePoint != null && radius != null) {
var _c = middlePoint.split(','), lat3 = _c[0], lng3 = _c[1];
var filter = "_geoRadius(" + lat3 + ", " + lng3 + ", " + radius + ")";
return { filter: filter };
}
return undefined;
}
function createGeoSearchContext(searchContext) {
var geoContext = {};
var aroundLatLng = searchContext.aroundLatLng, aroundLatLngViaIP = searchContext.aroundLatLngViaIP, aroundRadius = searchContext.aroundRadius, aroundPrecision = searchContext.aroundPrecision, minimumAroundRadius = searchContext.minimumAroundRadius, insideBoundingBox = searchContext.insideBoundingBox, insidePolygon = searchContext.insidePolygon;
if (aroundLatLng) {
geoContext.aroundLatLng = aroundLatLng;
}
if (aroundLatLngViaIP) {
console.warn('instant-meilisearch: `aroundLatLngViaIP` is not supported.');
}
if (aroundRadius) {
geoContext.aroundRadius = aroundRadius;
}
if (aroundPrecision) {
console.warn("instant-meilisearch: `aroundPrecision` is not supported.\n See this discussion to track its implementation https://github.com/meilisearch/product/discussions/264");
}
if (minimumAroundRadius) {
geoContext.minimumAroundRadius = minimumAroundRadius;
}
if (insideBoundingBox) {
geoContext.insideBoundingBox = insideBoundingBox;
}
// See related issue: https://github.com/meilisearch/instant-meilisearch/issues/555
if (insidePolygon) {
console.warn("instant-meilisearch: `insidePolygon` is not implented in instant-meilisearch.");
}
return geoContext;
}
/**
* Transform InstantSearch filter to MeiliSearch filter.

@@ -374,5 +511,6 @@ * Change sign from `:` to `=` in nested filter object.

];
var placeholderSearch = meiliSearchParams.placeholderSearch;
var query = meiliSearchParams.query;
var paginationTotalHits = meiliSearchParams.paginationTotalHits;
var placeholderSearch = searchContext.placeholderSearch;
var query = searchContext.query;
var paginationTotalHits = searchContext.paginationTotalHits;
// Limit
if ((!placeholderSearch && query === '') || paginationTotalHits === 0) {

@@ -389,2 +527,12 @@ meiliSearchParams.limit = 0;

}
var geoSearchContext = createGeoSearchContext(searchContext);
var geoRules = adaptGeoPointsRules(geoSearchContext);
if (geoRules === null || geoRules === void 0 ? void 0 : geoRules.filter) {
if (meiliSearchParams.filter) {
meiliSearchParams.filter.unshift(geoRules.filter);
}
else {
meiliSearchParams.filter = [geoRules.filter];
}
}
return meiliSearchParams;

@@ -436,6 +584,10 @@ }

// It contains all the highlighted and croped attributes
var toHighlightMatch = function (value) { return ({
value: replaceHighlightTags(value, highlightPreTag, highlightPostTag),
}); };
return Object.keys(formattedHit).reduce(function (result, key) {
result[key] = {
value: replaceHighlightTags(formattedHit[key], highlightPreTag, highlightPostTag),
};
var value = formattedHit[key];
result[key] = Array.isArray(value)
? value.map(toHighlightMatch)
: toHighlightMatch(value);
return result;

@@ -480,9 +632,14 @@ }, {});

attributesToSnippet = attributesToSnippet.map(function (attribute) { return attribute.split(':')[0]; });
var snippetAll = attributesToSnippet.includes('*');
// formattedHit is the `_formatted` object returned by MeiliSearch.
// It contains all the highlighted and croped attributes
var toSnippetMatch = function (value) { return ({
value: snippetValue(value, snippetEllipsisText, highlightPreTag, highlightPostTag),
}); };
return Object.keys(formattedHit).reduce(function (result, key) {
if (attributesToSnippet === null || attributesToSnippet === void 0 ? void 0 : attributesToSnippet.includes(key)) {
result[key] = {
value: snippetValue(formattedHit[key], snippetEllipsisText, highlightPreTag, highlightPostTag),
};
if (snippetAll || (attributesToSnippet === null || attributesToSnippet === void 0 ? void 0 : attributesToSnippet.includes(key))) {
var value = formattedHit[key];
result[key] = Array.isArray(value)
? value.map(toSnippetMatch)
: toSnippetMatch(value);
}

@@ -513,2 +670,20 @@ return result;

/**
* @param {any[]} hits
* @returns {Array<Record<string, any>>}
*/
function adaptGeoResponse(hits) {
for (var i = 0; i < hits.length; i++) {
if (hits[i]._geo) {
hits[i]._geoloc = {
lat: hits[i]._geo.lat,
lng: hits[i]._geo.lng,
};
hits[i].objectID = "" + (i + Math.random() * 1000000);
delete hits[i]._geo;
}
}
return hits;
}
/**
* @param {Array<Record<string} hits

@@ -523,3 +698,3 @@ * @param {SearchContext} searchContext

var paginatedHits = adaptPagination(hits, page, hitsPerPage);
return paginatedHits.map(function (hit) {
var formattedHits = paginatedHits.map(function (hit) {
// Creates Hit object compliant with InstantSearch

@@ -532,2 +707,4 @@ if (Object.keys(hit).length > 0) {

});
formattedHits = adaptGeoResponse(formattedHits);
return formattedHits;
}

@@ -606,6 +783,8 @@

var searchResolver = SearchResolver(SearchCache());
// paginationTotalHits can be 0 as it is a valid number
var paginationTotalHits = options.paginationTotalHits != null ? options.paginationTotalHits : 200;
var context = {
primaryKey: options.primaryKey || undefined,
placeholderSearch: options.placeholderSearch !== false,
paginationTotalHits: options.paginationTotalHits || 200,
paginationTotalHits: paginationTotalHits,
};

@@ -612,0 +791,0 @@ return {

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

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

@@ -15,3 +15,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";

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var e=function(){return(e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function r(t,e,r,n){return new(r||(r=Promise))((function(i,s){function o(t){try{a(n.next(t))}catch(t){s(t)}}function u(t){try{a(n.throw(t))}catch(t){s(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,u)}a((n=n.apply(t,e||[])).next())}))}function n(t,e){var r,n,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(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=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++,n=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.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],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function i(t,e){for(var r=0,n=e.length,i=t.length;r<n;r++,i++)t[i]=e[r];return t}var s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function o(t){var e={exports:{}};return t(e,e.exports),e.exports}o((function(t){!function(t){!function(e){var r="URLSearchParams"in t,n="Symbol"in t&&"iterator"in Symbol,i="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),s="FormData"in t,o="ArrayBuffer"in t;if(o)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],a=ArrayBuffer.isView||function(t){return t&&u.indexOf(Object.prototype.toString.call(t))>-1};function c(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function h(t){return"string"!=typeof t&&(t=String(t)),t}function f(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n&&(e[Symbol.iterator]=function(){return e}),e}function l(t){this.map={},t instanceof l?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function d(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function p(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function y(t){var e=new FileReader,r=p(e);return e.readAsArrayBuffer(t),r}function v(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function b(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:i&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:s&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():o&&i&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=v(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):o&&(ArrayBuffer.prototype.isPrototypeOf(t)||a(t))?this._bodyArrayBuffer=v(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i&&(this.blob=function(){var t=d(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?d(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var t,e,r,n=d(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,r=p(e),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},s&&(this.formData=function(){return this.text().then(m)}),this.json=function(){return this.text().then(JSON.parse)},this}l.prototype.append=function(t,e){t=c(t),e=h(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},l.prototype.delete=function(t){delete this.map[c(t)]},l.prototype.get=function(t){return t=c(t),this.has(t)?this.map[t]:null},l.prototype.has=function(t){return this.map.hasOwnProperty(c(t))},l.prototype.set=function(t,e){this.map[c(t)]=h(e)},l.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},l.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),f(t)},l.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),f(t)},l.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),f(t)},n&&(l.prototype[Symbol.iterator]=l.prototype.entries);var g=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function w(t,e){var r,n,i=(e=e||{}).body;if(t instanceof w){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new l(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,i||null==t._bodyInit||(i=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new l(e.headers)),this.method=(r=e.method||this.method||"GET",n=r.toUpperCase(),g.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&i)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(i)}function m(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),i=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(i))}})),e}function x(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new l(e.headers),this.url=e.url||"",this._initBody(t)}w.prototype.clone=function(){return new w(this,{body:this._bodyInit})},b.call(w.prototype),b.call(x.prototype),x.prototype.clone=function(){return new x(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new l(this.headers),url:this.url})},x.error=function(){var t=new x(null,{status:0,statusText:""});return t.type="error",t};var R=[301,302,303,307,308];x.redirect=function(t,e){if(-1===R.indexOf(e))throw new RangeError("Invalid status code");return new x(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function T(t,r){return new Promise((function(n,s){var o=new w(t,r);if(o.signal&&o.signal.aborted)return s(new e.DOMException("Aborted","AbortError"));var u=new XMLHttpRequest;function a(){u.abort()}u.onload=function(){var t,e,r={status:u.status,statusText:u.statusText,headers:(t=u.getAllResponseHeaders()||"",e=new l,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var i=r.join(":").trim();e.append(n,i)}})),e)};r.url="responseURL"in u?u.responseURL:r.headers.get("X-Request-URL");var i="response"in u?u.response:u.responseText;n(new x(i,r))},u.onerror=function(){s(new TypeError("Network request failed"))},u.ontimeout=function(){s(new TypeError("Network request failed"))},u.onabort=function(){s(new e.DOMException("Aborted","AbortError"))},u.open(o.method,o.url,!0),"include"===o.credentials?u.withCredentials=!0:"omit"===o.credentials&&(u.withCredentials=!1),"responseType"in u&&i&&(u.responseType="blob"),o.headers.forEach((function(t,e){u.setRequestHeader(e,t)})),o.signal&&(o.signal.addEventListener("abort",a),u.onreadystatechange=function(){4===u.readyState&&o.signal.removeEventListener("abort",a)}),u.send(void 0===o._bodyInit?null:o._bodyInit)}))}T.polyfill=!0,t.fetch||(t.fetch=T,t.Headers=l,t.Request=w,t.Response=x),e.Headers=l,e.Request=w,e.Response=x,e.fetch=T,Object.defineProperty(e,"__esModule",{value:!0})}({})}("undefined"!=typeof self?self:s)}));var u=o((function(t,e){!function(t){
***************************************************************************** */var e=function(){return(e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function r(t,e,r,n){return new(r||(r=Promise))((function(i,s){function o(t){try{a(n.next(t))}catch(t){s(t)}}function u(t){try{a(n.throw(t))}catch(t){s(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,u)}a((n=n.apply(t,e||[])).next())}))}function n(t,e){var r,n,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(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=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++,n=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.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],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function i(t,e){for(var r=0,n=e.length,i=t.length;r<n;r++,i++)t[i]=e[r];return t}var s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function o(t){var e={exports:{}};return t(e,e.exports),e.exports}o((function(t){!function(t){!function(e){var r="URLSearchParams"in t,n="Symbol"in t&&"iterator"in Symbol,i="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),s="FormData"in t,o="ArrayBuffer"in t;if(o)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],a=ArrayBuffer.isView||function(t){return t&&u.indexOf(Object.prototype.toString.call(t))>-1};function c(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function h(t){return"string"!=typeof t&&(t=String(t)),t}function l(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n&&(e[Symbol.iterator]=function(){return e}),e}function d(t){this.map={},t instanceof d?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function f(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function p(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function v(t){var e=new FileReader,r=p(e);return e.readAsArrayBuffer(t),r}function y(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function b(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:i&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:s&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():o&&i&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=y(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):o&&(ArrayBuffer.prototype.isPrototypeOf(t)||a(t))?this._bodyArrayBuffer=y(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i&&(this.blob=function(){var t=f(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?f(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(v)}),this.text=function(){var t,e,r,n=f(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,r=p(e),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},s&&(this.formData=function(){return this.text().then(m)}),this.json=function(){return this.text().then(JSON.parse)},this}d.prototype.append=function(t,e){t=c(t),e=h(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},d.prototype.delete=function(t){delete this.map[c(t)]},d.prototype.get=function(t){return t=c(t),this.has(t)?this.map[t]:null},d.prototype.has=function(t){return this.map.hasOwnProperty(c(t))},d.prototype.set=function(t,e){this.map[c(t)]=h(e)},d.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},d.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),l(t)},d.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),l(t)},d.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),l(t)},n&&(d.prototype[Symbol.iterator]=d.prototype.entries);var g=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function w(t,e){var r,n,i=(e=e||{}).body;if(t instanceof w){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new d(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,i||null==t._bodyInit||(i=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new d(e.headers)),this.method=(r=e.method||this.method||"GET",n=r.toUpperCase(),g.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&i)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(i)}function m(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),i=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(i))}})),e}function x(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new d(e.headers),this.url=e.url||"",this._initBody(t)}w.prototype.clone=function(){return new w(this,{body:this._bodyInit})},b.call(w.prototype),b.call(x.prototype),x.prototype.clone=function(){return new x(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new d(this.headers),url:this.url})},x.error=function(){var t=new x(null,{status:0,statusText:""});return t.type="error",t};var R=[301,302,303,307,308];x.redirect=function(t,e){if(-1===R.indexOf(e))throw new RangeError("Invalid status code");return new x(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function S(t,r){return new Promise((function(n,s){var o=new w(t,r);if(o.signal&&o.signal.aborted)return s(new e.DOMException("Aborted","AbortError"));var u=new XMLHttpRequest;function a(){u.abort()}u.onload=function(){var t,e,r={status:u.status,statusText:u.statusText,headers:(t=u.getAllResponseHeaders()||"",e=new d,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var i=r.join(":").trim();e.append(n,i)}})),e)};r.url="responseURL"in u?u.responseURL:r.headers.get("X-Request-URL");var i="response"in u?u.response:u.responseText;n(new x(i,r))},u.onerror=function(){s(new TypeError("Network request failed"))},u.ontimeout=function(){s(new TypeError("Network request failed"))},u.onabort=function(){s(new e.DOMException("Aborted","AbortError"))},u.open(o.method,o.url,!0),"include"===o.credentials?u.withCredentials=!0:"omit"===o.credentials&&(u.withCredentials=!1),"responseType"in u&&i&&(u.responseType="blob"),o.headers.forEach((function(t,e){u.setRequestHeader(e,t)})),o.signal&&(o.signal.addEventListener("abort",a),u.onreadystatechange=function(){4===u.readyState&&o.signal.removeEventListener("abort",a)}),u.send(void 0===o._bodyInit?null:o._bodyInit)}))}S.polyfill=!0,t.fetch||(t.fetch=S,t.Headers=d,t.Request=w,t.Response=x),e.Headers=d,e.Request=w,e.Response=x,e.fetch=S,Object.defineProperty(e,"__esModule",{value:!0})}({})}("undefined"!=typeof self?self:s)}));var u=o((function(t,e){!function(t){
/*! *****************************************************************************

@@ -29,3 +29,3 @@ Copyright (c) Microsoft Corporation.

***************************************************************************** */
var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,r)};function r(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var n=function(){return(n=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function i(t,e,r,n){function i(t){return t instanceof r?t:new r((function(e){e(t)}))}return new(r||(r=Promise))((function(r,s){function o(t){try{a(n.next(t))}catch(t){s(t)}}function u(t){try{a(n.throw(t))}catch(t){s(t)}}function a(t){t.done?r(t.value):i(t.value).then(o,u)}a((n=n.apply(t,e||[])).next())}))}function s(t,e){var r,n,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(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=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++,n=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],n=0}finally{r=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(r,n){var i=t.call(this,r)||this;return i.name="MeiliSearchCommunicationError",i.type="MeiliSearchCommunicationError",n instanceof Response&&(i.message=n.statusText,i.statusCode=n.status),n instanceof Error&&(i.errno=n.errno,i.code=n.code),Error.captureStackTrace&&Error.captureStackTrace(i,e),i}return r(e,t),e}(Error),u=function(t){function e(e,r){var n=t.call(this,e.message)||this;return n.type="MeiliSearchApiError",n.name="MeiliSearchApiError",n.errorCode=e.errorCode,n.errorType=e.errorType,n.errorLink=e.errorLink,n.message=e.message,n.httpStatus=r,n}return r(e,t),e}(Error);function a(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:if(t.ok)return[3,5];e=void 0,r.label=1;case 1:return r.trys.push([1,3,,4]),[4,t.json()];case 2:return e=r.sent(),[3,4];case 3:throw r.sent(),new o(t.statusText,t);case 4:throw new u(e,t.status);case 5:return[2,t]}}))}))}function c(t){if("MeiliSearchApiError"!==t.type)throw new o(t.message,t);throw t}var h=function(t){function e(r){var n=t.call(this,r)||this;return n.name="MeiliSearchError",n.type="MeiliSearchError",Error.captureStackTrace&&Error.captureStackTrace(n,e),n}return r(e,t),e}(Error),f=function(t){function e(r){var n=t.call(this,r)||this;return n.name="MeiliSearchTimeOutError",n.type=n.constructor.name,Error.captureStackTrace&&Error.captureStackTrace(n,e),n}return r(e,t),e}(Error),l=function(){function t(t){this.headers=n(n(n({},t.headers||{}),{"Content-Type":"application/json"}),t.apiKey?{"X-Meili-API-Key":t.apiKey}:{}),this.url=new URL(t.host)}return t.addTrailingSlash=function(t){return t.endsWith("/")||(t+="/"),t},t.prototype.request=function(t){var e=t.method,r=t.url,o=t.params,u=t.body,h=t.config;return i(this,void 0,void 0,(function(){var t,i,f;return s(this,(function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),t=new URL(r,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()),[4,fetch(t.toString(),n(n({},h),{method:e,body:JSON.stringify(u),headers:this.headers})).then((function(t){return a(t)}))];case 1:return[4,s.sent().text()];case 2:f=s.sent();try{return[2,JSON.parse(f)]}catch(t){return[2]}return[3,4];case 3:return c(s.sent()),[3,4];case 4:return[2]}}))}))},t.prototype.get=function(t,e,r){return i(this,void 0,void 0,(function(){return s(this,(function(n){switch(n.label){case 0:return[4,this.request({method:"GET",url:t,params:e,config:r})];case 1:return[2,n.sent()]}}))}))},t.prototype.post=function(t,e,r,n){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:r,config:n})];case 1:return[2,i.sent()]}}))}))},t.prototype.put=function(t,e,r,n){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:r,config:n})];case 1:return[2,i.sent()]}}))}))},t.prototype.delete=function(t,e,r,n){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:r,config:n})];case 1:return[2,i.sent()]}}))}))},t}();function d(t){return Object.entries(t).reduce((function(t,e){var r=e[0],n=e[1];return void 0!==n&&(t[r]=n),t}),{})}function p(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()]}}))}))}var y=function(){function t(t,e,r){this.uid=e,this.primaryKey=r,this.httpRequest=new l(t)}return t.prototype.waitForPendingUpdate=function(t,e){var r=void 0===e?{}:e,n=r.timeOutMs,o=void 0===n?5e3:n,u=r.intervalMs,a=void 0===u?50:u;return i(this,void 0,void 0,(function(){var e,r;return s(this,(function(n){switch(n.label){case 0:e=Date.now(),n.label=1;case 1:return Date.now()-e<o?[4,this.getUpdateStatus(t)]:[3,4];case 2:return r=n.sent(),["enqueued","processing"].includes(r.status)?[4,p(a)]:[2,r];case 3:return n.sent(),[3,1];case 4:throw new f("timeout of "+o+"ms has exceeded on process "+t+" when waiting for pending update to resolve.")}}))}))},t.prototype.search=function(t,e,r){return i(this,void 0,void 0,(function(){var i;return s(this,(function(s){switch(s.label){case 0:return i="indexes/"+this.uid+"/search",[4,this.httpRequest.post(i,d(n(n({},e),{q:t})),void 0,r)];case 1:return[2,s.sent()]}}))}))},t.prototype.searchGet=function(t,e,r){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/"+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=n(n({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),r)];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(r){switch(r.label){case 0:return t="indexes/"+this.uid,[4,this.httpRequest.get(t)];case 1:return e=r.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(e,r,o){return void 0===o&&(o={}),i(this,void 0,void 0,(function(){var i,u;return s(this,(function(s){switch(s.label){case 0:return i="indexes",[4,new l(e).post(i,n(n({},o),{uid:r}))];case 1:return u=s.sent(),[2,new t(e,r,u.primaryKey)]}}))}))},t.prototype.update=function(t){return i(this,void 0,void 0,(function(){var e,r;return s(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid,[4,this.httpRequest.put(e,t)];case 1:return r=n.sent(),this.primaryKey=r.primaryKey,[2,this]}}))}))},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/"+this.uid,[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.deleteIfExists=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]),[4,this.delete()];case 1:return e.sent(),[2,!0];case 2:if("index_not_found"===(t=e.sent()).errorCode)return[2,!1];throw t;case 3:return[2]}}))}))},t.prototype.getAllUpdateStatus=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/updates",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getUpdateStatus=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/updates/"+t,[4,this.httpRequest.get(e)];case 1:return[2,r.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/"+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,r;return s(this,(function(i){switch(i.label){case 0:return e="indexes/"+this.uid+"/documents",void 0!==t&&Array.isArray(t.attributesToRetrieve)&&(r=t.attributesToRetrieve.join(",")),[4,this.httpRequest.get(e,n(n({},t),void 0!==r?{attributesToRetrieve:r}:{}))];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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/documents/"+t,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.addDocuments=function(t,e){return i(this,void 0,void 0,(function(){var r;return s(this,(function(n){switch(n.label){case 0:return r="indexes/"+this.uid+"/documents",[4,this.httpRequest.post(r,t,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.updateDocuments=function(t,e){return i(this,void 0,void 0,(function(){var r;return s(this,(function(n){switch(n.label){case 0:return r="indexes/"+this.uid+"/documents",[4,this.httpRequest.put(r,t,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteDocument=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/documents/"+t,[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.deleteDocuments=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/documents/delete-batch",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+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/"+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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+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/"+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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/synonyms",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+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/"+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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/stop-words",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+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/"+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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/ranking-rules",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+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/"+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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/distinct-attribute",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+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/"+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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/filterable-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+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/"+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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/sortable-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+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/"+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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/searchable-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+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/"+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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/displayed-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+this.uid+"/settings/displayed-attributes",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t}(),v=function(){function t(t){t.host=l.addTrailingSlash(t.host),this.config=t,this.httpRequest=new l(t)}return t.prototype.index=function(t){return new y(this.config,t)},t.prototype.getIndex=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){return[2,new y(this.config,t).fetchInfo()]}))}))},t.prototype.getOrCreateIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){var r;return s(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.getIndex(t)];case 1:return[2,n.sent()];case 2:if("index_not_found"===(r=n.sent()).errorCode)return[2,this.createIndex(t,e)];throw new u(r,r.status);case 3:return[2]}}))}))},t.prototype.listIndexes=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(r){switch(r.label){case 0:return[4,y.create(this.config,t,e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){return s(this,(function(r){return[2,new y(this.config,t).update(e)]}))}))},t.prototype.deleteIndex=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){return[2,new y(this.config,t).delete()]}))}))},t.prototype.deleteIndexIfExists=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.deleteIndex(t)];case 1:return r.sent(),[2,!0];case 2:if("index_not_found"===(e=r.sent()).errorCode)return[2,!1];throw e;case 3:return[2]}}))}))},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.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.stats=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.version=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(r){switch(r.label){case 0:return e="dumps/"+t+"/status",[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t}();t.HttpRequests=l,t.Index=y,t.MeiliSearch=v,t.MeiliSearchApiError=u,t.MeiliSearchCommunicationError=o,t.MeiliSearchError=h,t.MeiliSearchTimeOutError=f,t.default=v,t.httpErrorHandler=c,t.httpResponseErrorHandler=a,t.removeUndefinedFromObject=d,t.sleep=p,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 f(t){var r=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 r.filter((function(t){return void 0!==t})).reduce((function(t,r){var n,s=r.filterName,o=r.value,u=t[s]||[];return t=e(e({},t),((n={})[s]=i(i([],u),[o]),n))}),{})}function l(t){return{searchResponse:function(e,i,s){return r(this,void 0,void 0,(function(){var r,o,u,a;return n(this,(function(n){switch(n.label){case 0:return r=t.formatKey([i,e.indexUid,e.query]),(o=t.getEntry(r))?[2,o]:(u=f(null==i?void 0:i.filter),[4,s.index(e.indexUid).search(e.query,i)]);case 1:return(a=n.sent()).facetsDistribution=function(t,e){if(e=e||{},t&&Object.keys(t).length>0)for(var r in t){e[r]||(e[r]={});for(var n=0,i=t[r];n<i.length;n++){var s=i[n];Object.keys(e[r]).includes(s)||(e[r][s]=0)}}return e}(u,a.facetsDistribution),t.setEntry(r,a),[2,a]}}))}))}}}function d(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 p(t){return""===t?[]:"string"==typeof t?[t]:t}function y(t,e,r){return function(t,e,r){var n=r.trim(),s=p(t),o=p(e);return i(i(i([],s),o),[n]).filter((function(t){return Array.isArray(t)?t.length:t}))}(d(r||[]),d(e||[]),t||"")}function v(t,e,r){return e=e||"__ais-highlight__",r=r||"__/ais-highlight__",(a(t)?t:JSON.stringify(t,null,2)).replace(/<em>/g,e).replace(/<\/em>/g,r)}function b(t,e,r){return Object.keys(t).reduce((function(n,i){return n[i]={value:v(t[i],e,r)},n}),{})}function g(t,e,r,n){var i=t;return void 0!==e&&a(i)&&i&&(i[0]===i[0].toLowerCase()&&!1===i.startsWith("<em>")&&(i=""+e+i),!1==!!i.match(/[.!?]$/)&&(i=""+i+e)),v(i,r,n)}function w(t,e,r,n,i){return void 0===e?null:(e=e.map((function(t){return t.split(":")[0]})),Object.keys(t).reduce((function(s,o){return(null==e?void 0:e.includes(o))&&(s[o]={value:g(t[o],r,n,i)}),s}),{}))}function m(t,r,n){var i=r.primaryKey,s=n.hitsPerPage;return function(t,e,r){var n=e*r;return t.splice(n,r)}(t,n.page,s).map((function(t){if(Object.keys(t).length>0){var n=t._formatted;t._matchesInfo;var s=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r}(t,["_formatted","_matchesInfo"]);return e(e(e({},s),function(t,e){var r=null==e?void 0:e.attributesToSnippet,n=null==e?void 0:e.snippetEllipsisText,i=null==e?void 0:e.highlightPreTag,s=null==e?void 0:e.highlightPostTag;return!t||t.length?{}:{_highlightResult:b(t,i,s),_snippetResult:w(t,r,n,i,s)}}(n,r)),i&&{objectID:t[i]})}return t}))}function x(t,r,n){var i={},s=t.facetsDistribution,o=null==t?void 0:t.exhaustiveFacetsCount;o&&(i.exhaustiveFacetsCount=o);var u,a,c=m(t.hits,r,n),h=(u=t.hits.length,(a=n.hitsPerPage)>0?Math.ceil(u/a):0),f=t.exhaustiveNbHits,l=t.nbHits,d=t.processingTimeMs,p=t.query,y=n.hitsPerPage,v=n.page;return{results:[e({index:r.indexUid,hitsPerPage:y,page:v,facets:s,nbPages:h,exhaustiveNbHits:f,nbHits:l,processingTimeMS:d,query:p,hits:c,params:""},i)]}}function R(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(r){return e[t]}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,r){e[t]=JSON.stringify(r)}}}t.instantMeiliSearch=function(t,i,s){void 0===i&&(i=""),void 0===s&&(s={});var o=l(R()),a={primaryKey:s.primaryKey||void 0,placeholderSearch:!1!==s.placeholderSearch,paginationTotalHits:s.paginationTotalHits||200};return{MeiliSearchClient:new u.MeiliSearch({host:t,apiKey:i}),search:function(t){return r(this,void 0,void 0,(function(){var r,i,s,u,c,h,f;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),r=t[0],i=r.params,s=function(t,r){var n=t.indexName.split(":"),i=n[0],s=n.slice(1),o=t.params;return e(e(e({},r),o),{sort:s.join(":")||"",indexUid:i})}(r,a),u=function(t,e){return{paginationTotalHits:t.paginationTotalHits||200,hitsPerPage:void 0===t.hitsPerPage?20:t.hitsPerPage,page:(null==e?void 0:e.page)||0}}(s,i),c=function(t){var e={},r=null==t?void 0:t.facets;(null==r?void 0:r.length)&&(e.facetsDistribution=r);var n=null==t?void 0:t.attributesToSnippet;n&&(e.attributesToCrop=n);var i=null==t?void 0:t.attributesToRetrieve;i&&(e.attributesToRetrieve=i);var s=y(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=e.placeholderSearch,u=e.query,a=e.paginationTotalHits;e.limit=!o&&""===u||0===a?0:a;var c=t.sort;return(null==c?void 0:c.length)&&(e.sort=[c]),e}(s),[4,o.searchResponse(s,c,this.MeiliSearchClient)];case 1:return h=n.sent(),[2,x(h,s,u)];case 2:throw f=n.sent(),console.error(f),new Error(f);case 3:return[2]}}))}))},searchForFacetValues:function(t){return r(this,void 0,void 0,(function(){return n(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,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,r)};function r(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var n=function(){return(n=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function i(t,e,r,n){function i(t){return t instanceof r?t:new r((function(e){e(t)}))}return new(r||(r=Promise))((function(r,s){function o(t){try{a(n.next(t))}catch(t){s(t)}}function u(t){try{a(n.throw(t))}catch(t){s(t)}}function a(t){t.done?r(t.value):i(t.value).then(o,u)}a((n=n.apply(t,e||[])).next())}))}function s(t,e){var r,n,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(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=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++,n=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],n=0}finally{r=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(r,n,i,s){var o,u,a=t.call(this,r)||this;return a.name="MeiliSearchCommunicationError",a.type="MeiliSearchCommunicationError",n instanceof Response&&(a.message=n.statusText,a.statusCode=n.status),n instanceof Error&&(a.errno=n.errno,a.code=n.code),s?(a.stack=s,a.stack=null===(o=a.stack)||void 0===o?void 0:o.replace(/(TypeError|FetchError)/,a.name),a.stack=null===(u=a.stack)||void 0===u?void 0:u.replace("Failed to fetch","request to "+i+" failed, reason: connect ECONNREFUSED")):Error.captureStackTrace&&Error.captureStackTrace(a,e),a}return r(e,t),e}(Error),u=function(t){function e(e,r){var n=t.call(this,e.message)||this;return n.type="MeiliSearchApiError",n.name="MeiliSearchApiError",n.errorCode=e.errorCode,n.errorType=e.errorType,n.errorLink=e.errorLink,n.message=e.message,n.httpStatus=r,Error.captureStackTrace&&Error.captureStackTrace(n,u),n}return r(e,t),e}(Error);function a(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:if(t.ok)return[3,5];e=void 0,r.label=1;case 1:return r.trys.push([1,3,,4]),[4,t.json()];case 2:return e=r.sent(),[3,4];case 3:throw r.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,r){if("MeiliSearchApiError"!==t.type)throw new o(t.message,t,r,e);throw t}var h=function(t){function e(r){var n=t.call(this,r)||this;return n.name="MeiliSearchError",n.type="MeiliSearchError",Error.captureStackTrace&&Error.captureStackTrace(n,e),n}return r(e,t),e}(Error),l=function(t){function e(r){var n=t.call(this,r)||this;return n.name="MeiliSearchTimeOutError",n.type=n.constructor.name,Error.captureStackTrace&&Error.captureStackTrace(n,e),n}return r(e,t),e}(Error),d=function(){function t(t){this.headers=n(n(n({},t.headers||{}),{"Content-Type":"application/json"}),t.apiKey?{"X-Meili-API-Key":t.apiKey}:{}),this.url=new URL(t.host)}return t.addTrailingSlash=function(t){return t.endsWith("/")||(t+="/"),t},t.prototype.request=function(t){var e=t.method,r=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(r,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(),n(n({},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,r){return i(this,void 0,void 0,(function(){return s(this,(function(n){switch(n.label){case 0:return[4,this.request({method:"GET",url:t,params:e,config:r})];case 1:return[2,n.sent()]}}))}))},t.prototype.post=function(t,e,r,n){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:r,config:n})];case 1:return[2,i.sent()]}}))}))},t.prototype.put=function(t,e,r,n){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:r,config:n})];case 1:return[2,i.sent()]}}))}))},t.prototype.delete=function(t,e,r,n){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:r,config:n})];case 1:return[2,i.sent()]}}))}))},t}();function f(t){return Object.entries(t).reduce((function(t,e){var r=e[0],n=e[1];return void 0!==n&&(t[r]=n),t}),{})}function p(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 v(t){return t.startsWith("https://")||t.startsWith("http://")?t:"http://"+t}var y=function(){function t(t,e,r){this.uid=e,this.primaryKey=r,this.httpRequest=new d(t)}return t.prototype.waitForPendingUpdate=function(t,e){var r=void 0===e?{}:e,n=r.timeOutMs,o=void 0===n?5e3:n,u=r.intervalMs,a=void 0===u?50:u;return i(this,void 0,void 0,(function(){var e,r;return s(this,(function(n){switch(n.label){case 0:e=Date.now(),n.label=1;case 1:return Date.now()-e<o?[4,this.getUpdateStatus(t)]:[3,4];case 2:return r=n.sent(),["enqueued","processing"].includes(r.status)?[4,p(a)]:[2,r];case 3:return n.sent(),[3,1];case 4:throw new l("timeout of "+o+"ms has exceeded on process "+t+" when waiting for pending update to resolve.")}}))}))},t.prototype.search=function(t,e,r){return i(this,void 0,void 0,(function(){var i;return s(this,(function(s){switch(s.label){case 0:return i="indexes/"+this.uid+"/search",[4,this.httpRequest.post(i,f(n(n({},e),{q:t})),void 0,r)];case 1:return[2,s.sent()]}}))}))},t.prototype.searchGet=function(t,e,r){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/"+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=n(n({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,f(u),r)];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(r){switch(r.label){case 0:return t="indexes/"+this.uid,[4,this.httpRequest.get(t)];case 1:return e=r.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(e,r,o){return void 0===r&&(r={}),i(this,void 0,void 0,(function(){var i,u;return s(this,(function(s){switch(s.label){case 0:return i="indexes",[4,new d(o).post(i,n(n({},r),{uid:e}))];case 1:return u=s.sent(),[2,new t(o,e,u.primaryKey)]}}))}))},t.prototype.update=function(t){return i(this,void 0,void 0,(function(){var e,r;return s(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid,[4,this.httpRequest.put(e,t)];case 1:return r=n.sent(),this.primaryKey=r.primaryKey,[2,this]}}))}))},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/"+this.uid,[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.deleteIfExists=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]),[4,this.delete()];case 1:return e.sent(),[2,!0];case 2:if("index_not_found"===(t=e.sent()).errorCode)return[2,!1];throw t;case 3:return[2]}}))}))},t.prototype.getAllUpdateStatus=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/updates",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getUpdateStatus=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/updates/"+t,[4,this.httpRequest.get(e)];case 1:return[2,r.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/"+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,r;return s(this,(function(i){switch(i.label){case 0:return e="indexes/"+this.uid+"/documents",void 0!==t&&Array.isArray(t.attributesToRetrieve)&&(r=t.attributesToRetrieve.join(",")),[4,this.httpRequest.get(e,n(n({},t),void 0!==r?{attributesToRetrieve:r}:{}))];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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/documents/"+t,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.addDocuments=function(t,e){return i(this,void 0,void 0,(function(){var r;return s(this,(function(n){switch(n.label){case 0:return r="indexes/"+this.uid+"/documents",[4,this.httpRequest.post(r,t,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.addDocumentsInBatches=function(t,e,r){return void 0===e&&(e=1e3),i(this,void 0,void 0,(function(){var n,i,o,u;return s(this,(function(s){switch(s.label){case 0:n=[],i=0,s.label=1;case 1:return i<t.length?(u=(o=n).push,[4,this.addDocuments(t.slice(i,i+e),r)]):[3,4];case 2:u.apply(o,[s.sent()]),s.label=3;case 3:return i+=e,[3,1];case 4:return[2,n]}}))}))},t.prototype.updateDocuments=function(t,e){return i(this,void 0,void 0,(function(){var r;return s(this,(function(n){switch(n.label){case 0:return r="indexes/"+this.uid+"/documents",[4,this.httpRequest.put(r,t,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.updateDocumentsInBatches=function(t,e,r){return void 0===e&&(e=1e3),i(this,void 0,void 0,(function(){var n,i,o,u;return s(this,(function(s){switch(s.label){case 0:n=[],i=0,s.label=1;case 1:return i<t.length?(u=(o=n).push,[4,this.updateDocuments(t.slice(i,i+e),r)]):[3,4];case 2:u.apply(o,[s.sent()]),s.label=3;case 3:return i+=e,[3,1];case 4:return[2,n]}}))}))},t.prototype.deleteDocument=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/documents/"+t,[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.deleteDocuments=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/documents/delete-batch",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+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/"+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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+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/"+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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/synonyms",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+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/"+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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/stop-words",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+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/"+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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/ranking-rules",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+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/"+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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/distinct-attribute",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+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/"+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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/filterable-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+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/"+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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/sortable-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+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/"+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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/searchable-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+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/"+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(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/displayed-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,r.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/"+this.uid+"/settings/displayed-attributes",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t}(),b=function(){function t(t){t.host=v(t.host),t.host=d.addTrailingSlash(t.host),this.config=t,this.httpRequest=new d(t)}return t.prototype.index=function(t){return new y(this.config,t)},t.prototype.getIndex=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){return[2,new y(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 y(this.config,t).getRawInfo()]}))}))},t.prototype.getOrCreateIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){var r;return s(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.getIndex(t)];case 1:return[2,n.sent()];case 2:if("index_not_found"===(r=n.sent()).errorCode)return[2,this.createIndex(t,e)];if("MeiliSearchCommunicationError"!==r.type)throw new u(r,r.status);if("MeiliSearchCommunicationError"===r.type)throw new o(r.message,r,r.stack);throw r;case 3:return[2]}}))}))},t.prototype.getIndexes=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(r){switch(r.label){case 0:return[4,y.create(t,e,this.config)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){return s(this,(function(r){return[2,new y(this.config,t).update(e)]}))}))},t.prototype.deleteIndex=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){return[2,new y(this.config,t).delete()]}))}))},t.prototype.deleteIndexIfExists=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.deleteIndex(t)];case 1:return r.sent(),[2,!0];case 2:if("index_not_found"===(e=r.sent()).errorCode)return[2,!1];throw e;case 3:return[2]}}))}))},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.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(r){switch(r.label){case 0:return e="dumps/"+t+"/status",[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t}();t.HttpRequests=d,t.Index=y,t.MeiliSearch=b,t.MeiliSearchApiError=u,t.MeiliSearchCommunicationError=o,t.MeiliSearchError=h,t.MeiliSearchTimeOutError=l,t.addProtocolIfNotPresent=v,t.default=b,t.httpErrorHandler=c,t.httpResponseErrorHandler=a,t.removeUndefinedFromObject=f,t.sleep=p,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 r=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 r.filter((function(t){return void 0!==t})).reduce((function(t,r){var n,s=r.filterName,o=r.value,u=t[s]||[];return t=e(e({},t),((n={})[s]=i(i([],u),[o]),n))}),{})}function d(t){return{searchResponse:function(e,i,s){return r(this,void 0,void 0,(function(){var r,o,u,a;return n(this,(function(n){switch(n.label){case 0:return r=t.formatKey([i,e.indexUid,e.query]),(o=t.getEntry(r))?[2,o]:(u=l(null==i?void 0:i.filter),[4,s.index(e.indexUid).search(e.query,i)]);case 1:return(a=n.sent()).facetsDistribution=function(t,e){if(e=e||{},t&&Object.keys(t).length>0)for(var r in t){e[r]||(e[r]={});for(var n=0,i=t[r];n<i.length;n++){var s=i[n];Object.keys(e[r]).includes(s)||(e[r][s]=0)}}return e}(u,a.facetsDistribution),t.setEntry(r,a),[2,a]}}))}))}}}function f(t){return 180*t/Math.PI}function p(t){return t*Math.PI/180}function v(t){if(t){var e,r,n=t.insideBoundingBox,i=t.aroundLatLng,s=t.aroundRadius,o=t.minimumAroundRadius;if(i&&(e=i),null==s&&null==o||(r=null!=s?s:o),n&&"string"==typeof n){var u=n.split(","),a=u[0],c=u[1],h=u[2],l=u[3],d=[parseFloat(a),parseFloat(c),parseFloat(h),parseFloat(l)],v=d[0],y=d[1],b=d[2],g=d[3];r=function(t,e,r,n){var i=t*Math.PI/180,s=r*Math.PI/180,o=(r-t)*Math.PI/180,u=(n-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}(v,y,b,g)/2,e=function(t,e,r,n){t=p(t),e=p(e);var i=Math.cos(t)*Math.cos(e),s=Math.cos(t)*Math.sin(e),o=Math.sin(t);r=p(r),n=p(n);var u=i+Math.cos(r)*Math.cos(n),a=s+Math.cos(r)*Math.sin(n),c=o+Math.sin(r),h=Math.sqrt(u*u+a*a),l=Math.atan2(a,u),d=Math.atan2(c,h);return d=f(d),l=f(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),d+","+l}(v,y,b,g)}if(null!=e&&null!=r){var w=e.split(",");return{filter:"_geoRadius("+w[0]+", "+w[1]+", "+r+")"}}}}function y(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 b(t){return""===t?[]:"string"==typeof t?[t]:t}function g(t,e,r){return function(t,e,r){var n=r.trim(),s=b(t),o=b(e);return i(i(i([],s),o),[n]).filter((function(t){return Array.isArray(t)?t.length:t}))}(y(r||[]),y(e||[]),t||"")}function w(t){var e={},r=null==t?void 0:t.facets;(null==r?void 0:r.length)&&(e.facetsDistribution=r);var n=null==t?void 0:t.attributesToSnippet;n&&(e.attributesToCrop=n);var i=null==t?void 0:t.attributesToRetrieve;i&&(e.attributesToRetrieve=i);var s=g(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=v(function(t){var e={},r=t.aroundLatLng,n=t.aroundLatLngViaIP,i=t.aroundRadius,s=t.aroundPrecision,o=t.minimumAroundRadius,u=t.insideBoundingBox,a=t.insidePolygon;return r&&(e.aroundLatLng=r),n&&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 m(t,e,r){return e=e||"__ais-highlight__",r=r||"__/ais-highlight__",(a(t)?t:JSON.stringify(t,null,2)).replace(/<em>/g,e).replace(/<\/em>/g,r)}function x(t,e,r){var n=function(t){return{value:m(t,e,r)}};return Object.keys(t).reduce((function(e,r){var i=t[r];return e[r]=Array.isArray(i)?i.map(n):n(i),e}),{})}function R(t,e,r,n){var i=t;return void 0!==e&&a(i)&&i&&(i[0]===i[0].toLowerCase()&&!1===i.startsWith("<em>")&&(i=""+e+i),!1==!!i.match(/[.!?]$/)&&(i=""+i+e)),m(i,r,n)}function S(t,e,r,n,i){if(void 0===e)return null;var s=(e=e.map((function(t){return t.split(":")[0]}))).includes("*"),o=function(t){return{value:R(t,r,n,i)}};return Object.keys(t).reduce((function(r,n){if(s||(null==e?void 0:e.includes(n))){var i=t[n];r[n]=Array.isArray(i)?i.map(o):o(i)}return r}),{})}function T(t,r,n){var i=r.primaryKey,s=n.hitsPerPage,o=function(t,e,r){var n=e*r;return t.splice(n,r)}(t,n.page,s).map((function(t){if(Object.keys(t).length>0){var n=t._formatted;t._matchesInfo;var s=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r}(t,["_formatted","_matchesInfo"]);return e(e(e({},s),function(t,e){var r=null==e?void 0:e.attributesToSnippet,n=null==e?void 0:e.snippetEllipsisText,i=null==e?void 0:e.highlightPreTag,s=null==e?void 0:e.highlightPostTag;return!t||t.length?{}:{_highlightResult:x(t,i,s),_snippetResult:S(t,r,n,i,s)}}(n,r)),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=""+(e+1e6*Math.random()),delete t[e]._geo);return t}(o)}function E(t,r,n){var i={},s=t.facetsDistribution,o=null==t?void 0:t.exhaustiveFacetsCount;o&&(i.exhaustiveFacetsCount=o);var u,a,c=T(t.hits,r,n),h=(u=t.hits.length,(a=n.hitsPerPage)>0?Math.ceil(u/a):0),l=t.exhaustiveNbHits,d=t.nbHits,f=t.processingTimeMs,p=t.query,v=n.hitsPerPage,y=n.page;return{results:[e({index:r.indexUid,hitsPerPage:v,page:y,facets:s,nbPages:h,exhaustiveNbHits:l,nbHits:d,processingTimeMS:f,query:p,hits:c,params:""},i)]}}function A(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(r){return e[t]}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,r){e[t]=JSON.stringify(r)}}}t.instantMeiliSearch=function(t,i,s){void 0===i&&(i=""),void 0===s&&(s={});var o=d(A()),a=null!=s.paginationTotalHits?s.paginationTotalHits:200,c={primaryKey:s.primaryKey||void 0,placeholderSearch:!1!==s.placeholderSearch,paginationTotalHits:a};return{MeiliSearchClient:new u.MeiliSearch({host:t,apiKey:i}),search:function(t){return r(this,void 0,void 0,(function(){var r,i,s,u,a,h,l;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),r=t[0],i=r.params,s=function(t,r){var n=t.indexName.split(":"),i=n[0],s=n.slice(1),o=t.params;return e(e(e({},r),o),{sort:s.join(":")||"",indexUid:i})}(r,c),u=function(t,e){return{paginationTotalHits:t.paginationTotalHits||200,hitsPerPage:void 0===t.hitsPerPage?20:t.hitsPerPage,page:(null==e?void 0:e.page)||0}}(s,i),a=w(s),[4,o.searchResponse(s,a,this.MeiliSearchClient)];case 1:return h=n.sent(),[2,E(h,s,u)];case 2:throw l=n.sent(),console.error(l),new Error(l);case 3:return[2]}}))}))},searchForFacetValues:function(t){return r(this,void 0,void 0,(function(){return n(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,6 +0,6 @@

// Type definitions for @meilisearch/instant-meilisearch 0.5.6
// Type definitions for @meilisearch/instant-meilisearch 0.5.7
// 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.4.3
// TypeScript Version: ^4.4.4

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

@@ -30,3 +30,4 @@ import type { MeiliSearch, SearchResponse as MeiliSearchResponse } from 'meilisearch';

};
export declare type SearchContext = InstantSearchParams & {
export declare type InsideBoundingBox = string | ReadonlyArray<readonly number[]>;
declare type ClientParams = {
primaryKey?: string;

@@ -38,2 +39,14 @@ placeholderSearch?: boolean;

};
export declare type GeoSearchContext = {
aroundLatLng?: string;
aroundLatLngViaIP?: boolean;
aroundRadius?: number | 'all';
aroundPrecision?: number;
minimumAroundRadius?: number;
insideBoundingBox?: InsideBoundingBox;
insidePolygon?: ReadonlyArray<readonly number[]>;
};
export declare type SearchContext = Omit<InstantSearchParams & ClientParams, 'insideBoundingBox'> & {
insideBoundingBox?: InsideBoundingBox;
};
export declare type PaginationContext = {

@@ -40,0 +53,0 @@ paginationTotalHits: number;

{
"name": "@meilisearch/instant-meilisearch",
"version": "0.5.6",
"version": "0.5.7",
"private": false,

@@ -19,2 +19,3 @@ "description": "The search client to use MeiliSearch with InstantSearch.",

"playground:javascript": "yarn --cwd ./playgrounds/javascript && yarn --cwd ./playgrounds/javascript start",
"playground:geo-javascript": "yarn --cwd ./playgrounds/geo-javascript && yarn --cwd ./playgrounds/geo-javascript start",
"playground:html": "yarn --cwd ./playgrounds/html && yarn --cwd ./playgrounds/html start",

@@ -57,8 +58,8 @@ "playground:angular": "yarn --cwd ./playgrounds/angular && yarn --cwd ./playgrounds/angular start",

"dependencies": {
"meilisearch": "^0.21.0"
"meilisearch": "^0.22.1"
},
"devDependencies": {
"@babel/cli": "^7.15.7",
"@babel/core": "^7.15.5",
"@babel/preset-env": "^7.15.6",
"@babel/core": "^7.15.8",
"@babel/preset-env": "^7.15.8",
"@rollup/plugin-commonjs": "^17.1.0",

@@ -76,3 +77,3 @@ "@rollup/plugin-node-resolve": "^11.2.0",

"cssnano": "^4.1.10",
"cypress": "^8.5.0",
"cypress": "^8.6.0",
"eslint": "^7.21.0",

@@ -93,3 +94,3 @@ "eslint-config-prettier": "^8.1.0",

"eslint-plugin-vue": "^7.7.0",
"instantsearch.js": "^4.30.2",
"instantsearch.js": "^4.31.0",
"jest": "^27.2.2",

@@ -105,6 +106,6 @@ "jest-watch-typeahead": "^0.6.3",

"shx": "^0.3.3",
"ts-jest": "^27.0.5",
"ts-jest": "^27.0.7",
"tslib": "^2.3.1",
"typescript": "^4.4.3"
"typescript": "^4.4.4"
}
}

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

This package only guarantees the compatibility with the [version v0.22.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.22.0).
This package only guarantees the compatibility with the [version v0.23.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.23.0).

@@ -191,3 +191,3 @@ **Node / NPM versions**:

List of all the components that are available in [instantSearch](https://github.com/algolia/instantsearch.js) and their compatibilty with [MeiliSearch](https://github.com/meilisearch/meilisearch/).
List of all the components that are available in [instantSearch](https://github.com/algolia/instantsearch.js) and their compatibility with [MeiliSearch](https://github.com/meilisearch/meilisearch/).

@@ -210,3 +210,3 @@ ### Table Of Widgets

- ✅ [Snippet](#-snippet)
- ❌[Geo Search](#-geo-search)
- ✅ [Geo Search](#-geo-search)
- ❌[Answers](#-answers)

@@ -480,10 +480,95 @@ - ✅ [RefinementList](#-refinementlist)

### ❌ Geo Search
### ✅ Geo Search
[Geo search references](https://www.algolia.com/doc/api-reference/widgets/geo-search/js/)
No compatibility because MeiliSearch does not support Geo Search.
The `geoSearch` widget displays search results on a Google Map. It lets you search for results based on their position and provides some common usage patterns such as “search on map interactions”.
If you'd like to see it implemented please vote for it in the [roadmap](https://roadmap.meilisearch.com/c/33-geo-search?utm_medium=social&utm_source=portal_share).
- ✅ container: The CSS Selector or HTMLElement to insert the Google maps into. _required_
- ✅ googleReference: The reference to the global window.google object. See the [Google Maps](https://developers.google.com/maps/documentation/javascript/overview) documentation for more information. _required_
- ✅ initialZoom: When no search results are found, google map will default to this zoom.
- ✅ initialPosition: When no search results are found, google map will default to this position.
- ✅ mapOptions: The options forwarded to the Google Maps constructor.
- ❔ builtInMarker: Used to customize Google Maps markers. Because of lack of tests we cannot guarantee its compatibility. For more information please visit [InstantSearch related documentation](https://www.algolia.com/doc/api-reference/widgets/geo-search/js/#widget-param-builtinmarker).
- customHTMLMarker: Same as `builtInMarker`. Because of lack of tests, we cannot guarantee its compatibility. For more information please visit [InstantSearch related documentation](https://www.algolia.com/doc/api-reference/widgets/geo-search/js/#widget-param-customhtmlmarker).
- ✅ enableRefine: If true, the map is used for refining the search. Otherwise, it’s only for display purposes.
- ✅ enableClearMapRefinement: If `true`, a button is displayed on the map when the refinement is coming from interacting with it, to remove it.
- ✅ enableRefineControl: If `true`, the map is used for refining the search. Otherwise, it’s only for display purposes.
- ✅ enableRefineOnMapMove: If `true`, a button is displayed on the map when the refinement is coming from interacting with it, to remove it.,
- ✅ templates: The templates to use for the widget.
- ✅ cssClasses: The CSS classes to override.
[See our playground for a working exemple](./playgrounds/geo-javascript/src/app.js) and this section in our [contributing guide](./CONTRIBUTING.md#-geo-search-playground) to set up your `MeiliSearch`.
#### Requirements
The Geosearch widgey only works with a valid Google API key.
In order to communicate your Google API key, your `instantSearch` widget should be surrounded by the following function:
```js
import injectScript from 'scriptjs'
injectScript(
`https://maps.googleapis.com/maps/api/js?v=quarterly&key=${GOOGLE_API}`,
() => {
const search = instantsearch({
indexName: 'geo',
// ...
})
// ...
})
```
Replace `${GOOGLE_API}` with you google api key.
See [code example in the playground](./playgrounds/geo-javascript/src/app.js)
### Usage
The classic usage, with only the `required` elements, renders an embedded Google Map on which you can move and refine search based on the position maps.
```js
instantsearch.widgets.geoSearch({
container: '#maps',
googleReference: window.google,
}),
```
For further customization, for example to determine an initial position for the map. Contrary to `initialZoom` and `initialPosition`, triggers a search request with the provided information.
The following parameters exist:
- `boundingBox`: The Google Map window box. It is used as parameter in a search request. It takes precedent on all the following parameters.
- `aroundLatLng`: The middle point of the Google Map. If `insideBoundingBox` or `boundingBox` is present, it is ignored.
- `aroundRadius`: The radius around a Geo Point, used for sorting in the search request. It only works if `aroundLatLng` is present as well. If `insideBoundingBox` or `boundingBox` is present, it is ignored.
For exemple, by adding `boundingBox` in the [`instantSearch`](#-instantsearch) widget parameters, the parameter will be used as a search parameter for the first request.
```js
initialUiState: {
geo: {
geoSearch: {
boundingBox:
'50.680720183653065, 3.273798366642514,50.55969330590075, 2.9625244444490253',
},
},
},
```
Without providing this parameter, Google Maps will default to a window containing all markers from the provided search results.
Alternatively, the parameters can be passed through the [`searchFunction`](https://www.algolia.com/doc/api-reference/widgets/instantsearch/js/#widget-param-searchfunction) parameter of the [`instantSearch`](#-instantsearch) widget. Contrary to `initialUiState` these parameters overwrite the values on each search.
```js
searchFunction: function (helper) {
helper.setQueryParameter('aroundRadius', 75000)
helper.setQueryParameter('aroundLatLng', '51.1241999, 9.662499900000057');
helper.search()
},
```
[Read the guide on how GeoSearch works in MeiliSearch](https://docs.meilisearch.com/reference/features/geosearch.html#geosearch).
### ❌ Answers

@@ -490,0 +575,0 @@

import type { MeiliSearchParams, SearchContext } from '../../types'
import {
adaptGeoPointsRules,
createGeoSearchContext,
} from './geo-rules-adapter'
import { adaptFilters } from './filter-adapter'

@@ -56,6 +60,7 @@

const placeholderSearch = meiliSearchParams.placeholderSearch
const query = meiliSearchParams.query
const paginationTotalHits = meiliSearchParams.paginationTotalHits
const placeholderSearch = searchContext.placeholderSearch
const query = searchContext.query
const paginationTotalHits = searchContext.paginationTotalHits
// Limit
if ((!placeholderSearch && query === '') || paginationTotalHits === 0) {

@@ -68,2 +73,3 @@ meiliSearchParams.limit = 0

const sort = searchContext.sort
// Sort

@@ -74,3 +80,14 @@ if (sort?.length) {

const geoSearchContext = createGeoSearchContext(searchContext)
const geoRules = adaptGeoPointsRules(geoSearchContext)
if (geoRules?.filter) {
if (meiliSearchParams.filter) {
meiliSearchParams.filter.unshift(geoRules.filter)
} else {
meiliSearchParams.filter = [geoRules.filter]
}
}
return meiliSearchParams
}

@@ -44,10 +44,10 @@ import { isString } from '../../utils'

// It contains all the highlighted and croped attributes
const toHighlightMatch = (value: any) => ({
value: replaceHighlightTags(value, highlightPreTag, highlightPostTag),
})
return Object.keys(formattedHit).reduce((result, key) => {
;(result[key] as any) = {
value: replaceHighlightTags(
formattedHit[key],
highlightPreTag,
highlightPostTag
),
}
const value = formattedHit[key]
result[key] = Array.isArray(value)
? value.map(toHighlightMatch)
: toHighlightMatch(value)
return result

@@ -108,14 +108,19 @@ }, {} as any)

) as any[]
const snippetAll = attributesToSnippet.includes('*')
// formattedHit is the `_formatted` object returned by MeiliSearch.
// It contains all the highlighted and croped attributes
const toSnippetMatch = (value: any) => ({
value: snippetValue(
value,
snippetEllipsisText,
highlightPreTag,
highlightPostTag
),
})
return (Object.keys(formattedHit) as any[]).reduce((result, key) => {
if (attributesToSnippet?.includes(key)) {
;(result[key] as any) = {
value: snippetValue(
formattedHit[key],
snippetEllipsisText,
highlightPreTag,
highlightPostTag
),
}
if (snippetAll || attributesToSnippet?.includes(key)) {
const value = formattedHit[key]
result[key] = Array.isArray(value)
? value.map(toSnippetMatch)
: toSnippetMatch(value)
}

@@ -122,0 +127,0 @@ return result

import type { PaginationContext, SearchContext } from '../../types'
import { adaptPagination } from './pagination-adapter'
import { adaptFormating } from './highlight-adapter'
import { adaptGeoResponse } from './geo-reponse-adapter'

@@ -20,3 +21,3 @@ /**

return paginatedHits.map((hit: any) => {
let formattedHits = paginatedHits.map((hit: Record<string, any>) => {
// Creates Hit object compliant with InstantSearch

@@ -33,2 +34,4 @@ if (Object.keys(hit).length > 0) {

})
formattedHits = adaptGeoResponse(formattedHits)
return formattedHits
}

@@ -34,7 +34,9 @@ import { MeiliSearch } from 'meilisearch'

const searchResolver = SearchResolver(SearchCache())
// paginationTotalHits can be 0 as it is a valid number
const paginationTotalHits =
options.paginationTotalHits != null ? options.paginationTotalHits : 200
const context: Context = {
primaryKey: options.primaryKey || undefined,
placeholderSearch: options.placeholderSearch !== false, // true by default
paginationTotalHits: options.paginationTotalHits || 200,
paginationTotalHits,
}

@@ -41,0 +43,0 @@

@@ -48,3 +48,5 @@ import type {

export type SearchContext = InstantSearchParams & {
export type InsideBoundingBox = string | ReadonlyArray<readonly number[]>
type ClientParams = {
primaryKey?: string

@@ -57,2 +59,19 @@ placeholderSearch?: boolean

export type GeoSearchContext = {
aroundLatLng?: string
aroundLatLngViaIP?: boolean
aroundRadius?: number | 'all'
aroundPrecision?: number
minimumAroundRadius?: number
insideBoundingBox?: InsideBoundingBox
insidePolygon?: ReadonlyArray<readonly number[]>
}
export type SearchContext = Omit<
InstantSearchParams & ClientParams,
'insideBoundingBox'
> & {
insideBoundingBox?: InsideBoundingBox
}
export type PaginationContext = {

@@ -59,0 +78,0 @@ paginationTotalHits: number

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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