@meilisearch/instant-meilisearch
Advanced tools
Comparing version 0.5.8 to 0.5.9
@@ -559,4 +559,7 @@ 'use strict'; | ||
function adaptPagination(hits, page, hitsPerPage) { | ||
if (hitsPerPage < 0) { | ||
throw new TypeError('Value too small for "hitsPerPage" parameter, expected integer between 0 and 9223372036854775807'); | ||
} | ||
var start = page * hitsPerPage; | ||
return hits.splice(start, hitsPerPage); | ||
return hits.slice(start, start + hitsPerPage); | ||
} | ||
@@ -578,5 +581,3 @@ | ||
// We replace the <em> by the expected tag for InstantSearch | ||
var stringifiedValue = isString(value) | ||
? value | ||
: JSON.stringify(value, null, 2); | ||
var stringifiedValue = isString(value) ? value : JSON.stringify(value); | ||
return stringifiedValue | ||
@@ -600,5 +601,13 @@ .replace(/<em>/g, highlightPreTag) | ||
var value = formattedHit[key]; | ||
result[key] = Array.isArray(value) | ||
? value.map(toHighlightMatch) | ||
: toHighlightMatch(value); | ||
if (Array.isArray(value)) { | ||
result[key] = value.map(function (val) { return ({ | ||
value: typeof val === 'object' ? JSON.stringify(val) : val, | ||
}); }); | ||
} | ||
else if (typeof value === 'object' && value !== null) { | ||
result[key] = { value: JSON.stringify(value) }; | ||
} | ||
else { | ||
result[key] = toHighlightMatch(value); | ||
} | ||
return result; | ||
@@ -735,4 +744,4 @@ }, {}); | ||
} | ||
var nbPages = ceiledDivision(searchResponse.hits.length, paginationContext.hitsPerPage); | ||
var hits = adaptHits(searchResponse.hits, searchContext, paginationContext); | ||
var nbPages = ceiledDivision(searchResponse.hits.length, paginationContext.hitsPerPage); | ||
var exhaustiveNbHits = searchResponse.exhaustiveNbHits; | ||
@@ -739,0 +748,0 @@ var nbHits = searchResponse.nbHits; |
@@ -1,2 +0,2 @@ | ||
"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)}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("meilisearch"),n=function(){return(n=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var i in n=arguments[e])Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i]);return t}).apply(this,arguments)}; | ||
/*! ***************************************************************************** | ||
@@ -15,3 +15,3 @@ Copyright (c) Microsoft Corporation. | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */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 n<e||n>e&&n>Math.PI&&e<-Math.PI?(d+=Math.PI,p+=Math.PI):(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(","),M=b[0],P=b[1];return{filter:"_geoRadius("+(M=Number.parseFloat(M).toFixed(5))+", "+(P=Number.parseFloat(P).toFixed(5))+", "+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()]}}))}))}}}; | ||
***************************************************************************** */function e(t,n,e,r){return new(e||(e=Promise))((function(i,a){function o(t){try{s(r.next(t))}catch(t){a(t)}}function u(t){try{s(r.throw(t))}catch(t){a(t)}}function s(t){var n;t.done?i(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(o,u)}s((r=r.apply(t,n||[])).next())}))}function r(t,n){var e,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(a){return function(u){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;o;)try{if(e=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=n.call(t,o)}catch(t){a=[6,t],r=0}finally{e=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function i(t,n){for(var e=0,r=n.length,i=t.length;e<r;e++,i++)t[i]=n[e];return t}function a(t){return"string"==typeof t||t instanceof String}function o(t){return t.replace(/:(.*)/i,'="$1"')}var u=function(t){var n=t.match(/([^=]*)="?([^\\"]*)"?$/);return n?(n[0],[{filterName:n[1],value:n[2]}]):[]};function s(t){var e=function(t){return"string"==typeof t?u(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return u(t)})):u(t)})).flat(2):[]}(t);return e.filter((function(t){return void 0!==t})).reduce((function(t,e){var r,a=e.filterName,o=e.value,u=t[a]||[];return t=n(n({},t),((r={})[a]=i(i([],u),[o]),r))}),{})}function l(t){return{searchResponse:function(n,i,a){return e(this,void 0,void 0,(function(){var e,o,u,l;return r(this,(function(r){switch(r.label){case 0:return e=t.formatKey([i,n.indexUid,n.query]),(o=t.getEntry(e))?[2,o]:(u=s(null==i?void 0:i.filter),[4,a.index(n.indexUid).search(n.query,i)]);case 1:return(l=r.sent()).facetsDistribution=function(t,n){if(n=n||{},t&&Object.keys(t).length>0)for(var e in t){n[e]||(n[e]={});for(var r=0,i=t[e];r<i.length;r++){var a=i[r];Object.keys(n[e]).includes(a)||(n[e][a]=0)}}return n}(u,l.facetsDistribution),t.setEntry(e,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,e,r=t.insideBoundingBox,i=t.aroundLatLng,a=t.aroundRadius,o=t.minimumAroundRadius;if(i&&(n=i),null==a&&null==o||(e=null!=a?a:o),r&&"string"==typeof r){var u=r.split(","),s=u[0],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];e=function(t,n,e,r){var i=t*Math.PI/180,a=e*Math.PI/180,o=(e-t)*Math.PI/180,u=(r-n)*Math.PI/180,s=Math.sin(o/2)*Math.sin(o/2)+Math.cos(i)*Math.cos(a)*Math.sin(u/2)*Math.sin(u/2);return 2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s))*6371e3}(v,g,y,m)/2,n=function(t,n,e,r){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);e=f(e),r=f(r);var u=i+Math.cos(e)*Math.cos(r),s=a+Math.cos(e)*Math.sin(r),l=o+Math.sin(e),h=Math.sqrt(u*u+s*s),p=Math.atan2(s,u),d=Math.atan2(l,h);return n<r||n>r&&n>Math.PI&&r<-Math.PI?(d+=Math.PI,p+=Math.PI):(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!=e){var b=n.split(","),M=b[0],P=b[1];return{filter:"_geoRadius("+(M=Number.parseFloat(M).toFixed(5))+", "+(P=Number.parseFloat(P).toFixed(5))+", "+e+")"}}}}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,e){return function(t,n,e){var r=e.trim(),a=d(t),o=d(n);return i(i(i([],a),o),[r]).filter((function(t){return Array.isArray(t)?t.length:t}))}(p(e||[]),p(n||[]),t||"")}function g(t){var n={},e=null==t?void 0:t.facets;(null==e?void 0:e.length)&&(n.facetsDistribution=e);var r=null==t?void 0:t.attributesToSnippet;r&&(n.attributesToCrop=r);var i=null==t?void 0:t.attributesToRetrieve;i&&(n.attributesToRetrieve=i);var a=v(null==t?void 0:t.filters,null==t?void 0:t.numericFilters,null==t?void 0:t.facetFilters);a.length&&(n.filter=a),i&&(n.attributesToCrop=i),n.attributesToHighlight=(null==t?void 0:t.attributesToHighlight)||["*"];var o=t.placeholderSearch,u=t.query,s=t.paginationTotalHits;n.limit=!o&&""===u||0===s?0:s;var l=t.sort;(null==l?void 0:l.length)&&(n.sort=[l]);var c=h(function(t){var n={},e=t.aroundLatLng,r=t.aroundLatLngViaIP,i=t.aroundRadius,a=t.aroundPrecision,o=t.minimumAroundRadius,u=t.insideBoundingBox,s=t.insidePolygon;return e&&(n.aroundLatLng=e),r&&console.warn("instant-meilisearch: `aroundLatLngViaIP` is not supported."),i&&(n.aroundRadius=i),a&&console.warn("instant-meilisearch: `aroundPrecision` is not supported.\n See this discussion to track its implementation https://github.com/meilisearch/product/discussions/264"),o&&(n.minimumAroundRadius=o),u&&(n.insideBoundingBox=u),s&&console.warn("instant-meilisearch: `insidePolygon` is not implented in instant-meilisearch."),n}(t));return(null==c?void 0:c.filter)&&(n.filter?n.filter.unshift(c.filter):n.filter=[c.filter]),n}function y(t,n,e){return n=n||"__ais-highlight__",e=e||"__/ais-highlight__",(a(t)?t:JSON.stringify(t)).replace(/<em>/g,n).replace(/<\/em>/g,e)}function m(t,n,e){return Object.keys(t).reduce((function(r,i){var a=t[i];return Array.isArray(a)?r[i]=a.map((function(t){return{value:"object"==typeof t?JSON.stringify(t):t}})):r[i]="object"==typeof a&&null!==a?{value:JSON.stringify(a)}:function(t){return{value:y(t,n,e)}}(a),r}),{})}function b(t,n,e,r){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,e,r)}function M(t,n,e,r,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,e,r,i)}};return Object.keys(t).reduce((function(e,r){if(a||(null==n?void 0:n.includes(r))){var i=t[r];e[r]=Array.isArray(i)?i.map(o):o(i)}return e}),{})}function P(t,e,r){var i=e.primaryKey,a=r.hitsPerPage,o=function(t,n,e){if(e<0)throw new TypeError('Value too small for "hitsPerPage" parameter, expected integer between 0 and 9223372036854775807');var r=n*e;return t.slice(r,r+e)}(t,r.page,a).map((function(t){if(Object.keys(t).length>0){var r=t._formatted;t._matchesInfo;var a=function(t,n){var e={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&n.indexOf(r)<0&&(e[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)n.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(e[r[i]]=t[r[i]])}return e}(t,["_formatted","_matchesInfo"]);return n(n(n({},a),function(t,n){var e=null==n?void 0:n.attributesToSnippet,r=null==n?void 0:n.snippetEllipsisText,i=null==n?void 0:n.highlightPreTag,a=null==n?void 0:n.highlightPostTag;return!t||t.length?{}:{_highlightResult:m(t,i,a),_snippetResult:M(t,e,r,i,a)}}(r,e)),i&&{objectID:t[i]})}return t}));return o=function(t){for(var n=0;n<t.length;n++)t[n]._geo&&(t[n]._geoloc={lat:t[n]._geo.lat,lng:t[n]._geo.lng},t[n].objectID=""+(n+1e6*Math.random()),delete t[n]._geo);return t}(o)}function w(t,e,r){var i={},a=t.facetsDistribution,o=null==t?void 0:t.exhaustiveFacetsCount;o&&(i.exhaustiveFacetsCount=o);var u,s,l=(u=t.hits.length,(s=r.hitsPerPage)>0?Math.ceil(u/s):0),c=P(t.hits,e,r),f=t.exhaustiveNbHits,h=t.nbHits,p=t.processingTimeMs,d=t.query,v=r.hitsPerPage,g=r.page;return{results:[n({index:e.indexUid,hitsPerPage:v,page:g,facets:a,nbPages:l,exhaustiveNbHits:f,nbHits:h,processingTimeMS:p,query:d,hits:c,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(e){return n[t]}},formatKey:function(t){return t.reduce((function(t,n){return t+JSON.stringify(n)}),"")},setEntry:function(t,e){n[t]=JSON.stringify(e)}}}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 e(this,void 0,void 0,(function(){var e,i,a,o,s,l,f;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),e=t[0],i=e.params,a=function(t,e){var r=t.indexName.split(":"),i=r[0],a=r.slice(1),o=t.params;return n(n(n({},e),o),{sort:a.join(":")||"",indexUid:i})}(e,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=r.sent(),[2,w(l,a,o)];case 2:throw f=r.sent(),console.error(f),new Error(f);case 3:return[2]}}))}))},searchForFacetValues:function(t){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,new Promise((function(t,n){n(new Error("SearchForFacetValues is not compatible with MeiliSearch")),t([])}))];case 1:return[2,t.sent()]}}))}))}}}; | ||
//# sourceMappingURL=instant-meilisearch.cjs.min.js.map |
@@ -555,4 +555,7 @@ import { MeiliSearch } from 'meilisearch'; | ||
function adaptPagination(hits, page, hitsPerPage) { | ||
if (hitsPerPage < 0) { | ||
throw new TypeError('Value too small for "hitsPerPage" parameter, expected integer between 0 and 9223372036854775807'); | ||
} | ||
var start = page * hitsPerPage; | ||
return hits.splice(start, hitsPerPage); | ||
return hits.slice(start, start + hitsPerPage); | ||
} | ||
@@ -574,5 +577,3 @@ | ||
// We replace the <em> by the expected tag for InstantSearch | ||
var stringifiedValue = isString(value) | ||
? value | ||
: JSON.stringify(value, null, 2); | ||
var stringifiedValue = isString(value) ? value : JSON.stringify(value); | ||
return stringifiedValue | ||
@@ -596,5 +597,13 @@ .replace(/<em>/g, highlightPreTag) | ||
var value = formattedHit[key]; | ||
result[key] = Array.isArray(value) | ||
? value.map(toHighlightMatch) | ||
: toHighlightMatch(value); | ||
if (Array.isArray(value)) { | ||
result[key] = value.map(function (val) { return ({ | ||
value: typeof val === 'object' ? JSON.stringify(val) : val, | ||
}); }); | ||
} | ||
else if (typeof value === 'object' && value !== null) { | ||
result[key] = { value: JSON.stringify(value) }; | ||
} | ||
else { | ||
result[key] = toHighlightMatch(value); | ||
} | ||
return result; | ||
@@ -731,4 +740,4 @@ }, {}); | ||
} | ||
var nbPages = ceiledDivision(searchResponse.hits.length, paginationContext.hitsPerPage); | ||
var hits = adaptHits(searchResponse.hits, searchContext, paginationContext); | ||
var nbPages = ceiledDivision(searchResponse.hits.length, paginationContext.hitsPerPage); | ||
var exhaustiveNbHits = searchResponse.exhaustiveNbHits; | ||
@@ -735,0 +744,0 @@ var nbHits = searchResponse.nbHits; |
@@ -15,3 +15,3 @@ import{MeiliSearch as t}from"meilisearch"; | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */var n=function(){return(n=Object.assign||function(t){for(var n,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 n<e||n>e&&n>Math.PI&&e<-Math.PI?(d+=Math.PI,p+=Math.PI):(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(","),M=b[0],P=b[1];return{filter:"_geoRadius("+(M=Number.parseFloat(M).toFixed(5))+", "+(P=Number.parseFloat(P).toFixed(5))+", "+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}; | ||
***************************************************************************** */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 n<e||n>e&&n>Math.PI&&e<-Math.PI?(d+=Math.PI,p+=Math.PI):(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(","),M=b[0],P=b[1];return{filter:"_geoRadius("+(M=Number.parseFloat(M).toFixed(5))+", "+(P=Number.parseFloat(P).toFixed(5))+", "+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)).replace(/<em>/g,n).replace(/<\/em>/g,r)}function m(t,n,r){return Object.keys(t).reduce((function(e,i){var a=t[i];return Array.isArray(a)?e[i]=a.map((function(t){return{value:"object"==typeof t?JSON.stringify(t):t}})):e[i]="object"==typeof a&&null!==a?{value:JSON.stringify(a)}:function(t){return{value:y(t,n,r)}}(a),e}),{})}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){if(r<0)throw new TypeError('Value too small for "hitsPerPage" parameter, expected integer between 0 and 9223372036854775807');var e=n*r;return t.slice(e,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=(u=t.hits.length,(s=e.hitsPerPage)>0?Math.ceil(u/s):0),c=P(t.hits,r,e),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:l,exhaustiveNbHits:f,nbHits:h,processingTimeMS:p,query:d,hits:c,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 |
@@ -28,3 +28,3 @@ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).window=t.window||{})}(this,(function(t){"use strict"; | ||
***************************************************************************** */ | ||
var e=function(t,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 e<n||e>n&&e>Math.PI&&n<-Math.PI?(d+=Math.PI,l+=Math.PI):(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(","),m=w[0],x=w[1];return{filter:"_geoRadius("+(m=Number.parseFloat(m).toFixed(5))+", "+(x=Number.parseFloat(x).toFixed(5))+", "+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})})); | ||
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 e<n||e>n&&e>Math.PI&&n<-Math.PI?(d+=Math.PI,l+=Math.PI):(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(","),m=w[0],x=w[1];return{filter:"_geoRadius("+(m=Number.parseFloat(m).toFixed(5))+", "+(x=Number.parseFloat(x).toFixed(5))+", "+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)).replace(/<em>/g,e).replace(/<\/em>/g,r)}function x(t,e,r){return Object.keys(t).reduce((function(n,i){var s=t[i];return Array.isArray(s)?n[i]=s.map((function(t){return{value:"object"==typeof t?JSON.stringify(t):t}})):n[i]="object"==typeof s&&null!==s?{value:JSON.stringify(s)}:function(t){return{value:m(t,e,r)}}(s),n}),{})}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){if(r<0)throw new TypeError('Value too small for "hitsPerPage" parameter, expected integer between 0 and 9223372036854775807');var n=e*r;return t.slice(n,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=(u=t.hits.length,(a=n.hitsPerPage)>0?Math.ceil(u/a):0),h=T(t.hits,r,n),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:c,exhaustiveNbHits:l,nbHits:d,processingTimeMS:f,query:p,hits:h,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,2 +0,2 @@ | ||
// Type definitions for @meilisearch/instant-meilisearch 0.5.8 | ||
// Type definitions for @meilisearch/instant-meilisearch 0.5.9 | ||
// Project: https://github.com/meilisearch/instant-meilisearch.git | ||
@@ -3,0 +3,0 @@ // Definitions by: Clementine Urquizar <https://github.com/meilisearch> |
{ | ||
"name": "@meilisearch/instant-meilisearch", | ||
"version": "0.5.8", | ||
"version": "0.5.9", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "The search client to use MeiliSearch with InstantSearch.", |
@@ -60,2 +60,5 @@ <p align="center"> | ||
InstantMeiliSearch is a client for `instantsearch.js`. It does not create any UI component by itself.<br> | ||
To be able to create a search interface, you'll need to [install `instantsearch.js`](https://www.algolia.com/doc/guides/building-search-ui/installation/js/) as well. | ||
## Usage | ||
@@ -62,0 +65,0 @@ |
@@ -33,9 +33,2 @@ import { adaptPagination } from '../pagination-adapter' | ||
{ | ||
hitsPerPage: -1, | ||
hitsLength: 20, | ||
numberPages: 0, | ||
}, | ||
// Not an Algolia behavior. Algolia returns an error: | ||
// "Value too small for \"hitsPerPage\" parameter, expected integer between 0 and 9223372036854775807", | ||
{ | ||
hitsPerPage: 1.5, | ||
@@ -133,11 +126,2 @@ hitsLength: 20, | ||
}, | ||
// Wrong types | ||
// Not an Algolia behavior. Algolia returns an error: | ||
// "Value too small for \"hitsPerPage\" parameter, expected integer between 0 and 9223372036854775807", | ||
{ | ||
hits: [{ id: 1 }, { id: 2 }, { id: 3 }], | ||
page: 0, | ||
hitsPerPage: -1, | ||
returnedHits: [], | ||
}, | ||
] | ||
@@ -168,1 +152,15 @@ | ||
) | ||
it('Should throw when hitsPerPage is negative', () => { | ||
try { | ||
const hits: string[] = [] | ||
const hitsPerPage = -1 | ||
const page = 0 | ||
adaptPagination(hits, page, hitsPerPage) | ||
} catch (e: any) { | ||
expect(e.message).toBe( | ||
'Value too small for "hitsPerPage" parameter, expected integer between 0 and 9223372036854775807' | ||
) | ||
expect(e.name).toBe('TypeError') | ||
} | ||
}) |
@@ -22,5 +22,3 @@ import { isString } from '../../utils' | ||
// We replace the <em> by the expected tag for InstantSearch | ||
const stringifiedValue = isString(value) | ||
? value | ||
: JSON.stringify(value, null, 2) | ||
const stringifiedValue = isString(value) ? value : JSON.stringify(value) | ||
@@ -50,5 +48,11 @@ return stringifiedValue | ||
const value = formattedHit[key] | ||
result[key] = Array.isArray(value) | ||
? value.map(toHighlightMatch) | ||
: toHighlightMatch(value) | ||
if (Array.isArray(value)) { | ||
result[key] = value.map((val) => ({ | ||
value: typeof val === 'object' ? JSON.stringify(val) : val, | ||
})) | ||
} else if (typeof value === 'object' && value !== null) { | ||
result[key] = { value: JSON.stringify(value) } | ||
} else { | ||
result[key] = toHighlightMatch(value) | ||
} | ||
return result | ||
@@ -55,0 +59,0 @@ }, {} as any) |
@@ -14,4 +14,9 @@ /** | ||
): Array<Record<string, any>> { | ||
if (hitsPerPage < 0) { | ||
throw new TypeError( | ||
'Value too small for "hitsPerPage" parameter, expected integer between 0 and 9223372036854775807' | ||
) | ||
} | ||
const start = page * hitsPerPage | ||
return hits.splice(start, hitsPerPage) | ||
return hits.slice(start, start + hitsPerPage) | ||
} |
@@ -32,5 +32,2 @@ import type { | ||
} | ||
const hits = adaptHits(searchResponse.hits, searchContext, paginationContext) | ||
const nbPages = ceiledDivision( | ||
@@ -40,2 +37,3 @@ searchResponse.hits.length, | ||
) | ||
const hits = adaptHits(searchResponse.hits, searchContext, paginationContext) | ||
@@ -42,0 +40,0 @@ const exhaustiveNbHits = searchResponse.exhaustiveNbHits |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
516573
7542
956