@meilisearch/instant-meilisearch
Advanced tools
Comparing version 0.5.9 to 0.5.10
@@ -255,3 +255,3 @@ 'use strict'; | ||
}); | ||
}, | ||
} | ||
}; | ||
@@ -314,3 +314,3 @@ } | ||
} | ||
return lat3 + "," + lng3; | ||
return "".concat(lat3, ",").concat(lng3); | ||
} | ||
@@ -373,3 +373,3 @@ /** | ||
lng3 = Number.parseFloat(lng3).toFixed(5); | ||
var filter = "_geoRadius(" + lat3 + ", " + lng3 + ", " + radius + ")"; | ||
var filter = "_geoRadius(".concat(lat3, ", ").concat(lng3, ", ").concat(radius, ")"); | ||
return { filter: filter }; | ||
@@ -578,12 +578,35 @@ } | ||
*/ | ||
function replaceHighlightTags(value, highlightPreTag, highlightPostTag) { | ||
highlightPreTag = highlightPreTag || '__ais-highlight__'; | ||
highlightPostTag = highlightPostTag || '__/ais-highlight__'; | ||
function replaceDefaultEMTag(value, preTag, postTag) { | ||
if (preTag === void 0) { preTag = '__ais-highlight__'; } | ||
if (postTag === void 0) { postTag = '__/ais-highlight__'; } | ||
// Highlight is applied by MeiliSearch (<em> tags) | ||
// We replace the <em> by the expected tag for InstantSearch | ||
var stringifiedValue = isString(value) ? value : JSON.stringify(value); | ||
return stringifiedValue | ||
.replace(/<em>/g, highlightPreTag) | ||
.replace(/<\/em>/g, highlightPostTag); | ||
return stringifiedValue.replace(/<em>/g, preTag).replace(/<\/em>/g, postTag); | ||
} | ||
function addHighlightTags(value, preTag, postTag) { | ||
if (typeof value === 'string') { | ||
// String | ||
return replaceDefaultEMTag(value, preTag, postTag); | ||
} | ||
else if (value === undefined) { | ||
// undefined | ||
return JSON.stringify(null); | ||
} | ||
else { | ||
// Other | ||
return JSON.stringify(value); | ||
} | ||
} | ||
function resolveHighlightValue(value, preTag, postTag) { | ||
if (Array.isArray(value)) { | ||
// Array | ||
return value.map(function (elem) { return ({ | ||
value: addHighlightTags(elem, preTag, postTag) | ||
}); }); | ||
} | ||
else { | ||
return { value: addHighlightTags(value, preTag, postTag) }; | ||
} | ||
} | ||
/** | ||
@@ -595,76 +618,83 @@ * @param {Record<string} formattedHit | ||
*/ | ||
function adaptHighlight(formattedHit, highlightPreTag, highlightPostTag) { | ||
// formattedHit is the `_formatted` object returned by MeiliSearch. | ||
function adaptHighlight(hit, preTag, postTag) { | ||
// hit is the `_formatted` object returned by MeiliSearch. | ||
// It contains all the highlighted and croped attributes | ||
var toHighlightMatch = function (value) { return ({ | ||
value: replaceHighlightTags(value, highlightPreTag, highlightPostTag), | ||
}); }; | ||
return Object.keys(formattedHit).reduce(function (result, key) { | ||
var value = formattedHit[key]; | ||
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); | ||
} | ||
if (!hit._formatted) | ||
return hit._formatted; | ||
return Object.keys(hit._formatted).reduce(function (result, key) { | ||
var value = hit._formatted[key]; | ||
result[key] = resolveHighlightValue(value, preTag, postTag); | ||
return result; | ||
}, {}); | ||
} | ||
/** | ||
* @param {string} value | ||
* @param {string} snippetEllipsisText? | ||
* @param {string} highlightPreTag? | ||
* @param {string} highlightPostTag? | ||
* @returns {string} | ||
*/ | ||
function snippetValue(value, snippetEllipsisText, highlightPreTag, highlightPostTag) { | ||
var newValue = value; | ||
// manage a kind of `...` for the crop until this feature is implemented https://roadmap.meilisearch.com/c/69-policy-for-cropped-values?utm_medium=social&utm_source=portal_share | ||
// `...` is put if we are at the middle of a sentence (instead at the middle of the document field) | ||
if (snippetEllipsisText !== undefined && isString(newValue) && newValue) { | ||
if (newValue[0] === newValue[0].toLowerCase() && // beginning of a sentence | ||
newValue.startsWith('<em>') === false // beginning of the document field, otherwise MeiliSearch would crop around the highligh | ||
function nakedOfTags(str) { | ||
return str.replace(/<em>/g, '').replace(/<\/em>/g, ''); | ||
} | ||
function addEllipsis(value, formatValue, ellipsis) { | ||
// Manage ellpsis on cropped values until this feature is implemented https://roadmap.meilisearch.com/c/69-policy-for-cropped-values?utm_medium=social&utm_source=portal_share in MeiliSearch | ||
var ellipsedValue = formatValue; | ||
if (isString(formatValue) && | ||
value.toString().length > nakedOfTags(formatValue).length) { | ||
if (formatValue[0] === formatValue[0].toLowerCase() && // beginning of a sentence | ||
formatValue.startsWith('<em>') === false // beginning of the document field, otherwise MeiliSearch would crop around the highlight | ||
) { | ||
newValue = "" + snippetEllipsisText + newValue; | ||
ellipsedValue = "".concat(ellipsis).concat(formatValue.trim()); | ||
} | ||
if (!!newValue.match(/[.!?]$/) === false) { | ||
if (!!formatValue.match(/[.!?]$/) === false) { | ||
// end of the sentence | ||
newValue = "" + newValue + snippetEllipsisText; | ||
ellipsedValue = "".concat(formatValue.trim()).concat(ellipsis); | ||
} | ||
} | ||
return replaceHighlightTags(newValue, highlightPreTag, highlightPostTag); | ||
return ellipsedValue; | ||
} | ||
/** | ||
* @param {Record<string} formattedHit | ||
* @param {readonlystring[]|undefined} attributesToSnippet | ||
* @param {string|undefined} snippetEllipsisText | ||
* @param {string|undefined} highlightPreTag | ||
* @param {string|undefined} highlightPostTag | ||
* @param {string} value | ||
* @param {string} ellipsis? | ||
* @returns {string} | ||
*/ | ||
function adaptSnippet(formattedHit, attributesToSnippet, snippetEllipsisText, highlightPreTag, highlightPostTag) { | ||
if (attributesToSnippet === undefined) { | ||
return null; | ||
function resolveSnippet(value, formatValue, ellipsis) { | ||
if (!ellipsis || !(typeof formatValue === 'string')) { | ||
return formatValue; | ||
} | ||
attributesToSnippet = attributesToSnippet.map(function (attribute) { return attribute.split(':')[0]; }); | ||
var snippetAll = attributesToSnippet.includes('*'); | ||
// formattedHit is the `_formatted` object returned by MeiliSearch. | ||
else if (Array.isArray(value)) { | ||
// Array | ||
return value.map(function (elem) { return addEllipsis(elem, formatValue, ellipsis); }); | ||
} | ||
return addEllipsis(value, formatValue, ellipsis); | ||
} | ||
/** | ||
* @param {Record<string} hit | ||
* @param {readonlystring[]|undefined} attributes | ||
* @param {string|undefined} ellipsis | ||
*/ | ||
function adaptSnippet(hit, attributes, ellipsis) { | ||
// hit is the `_formatted` object returned by MeiliSearch. | ||
// It contains all the highlighted and croped attributes | ||
var toSnippetMatch = function (value) { return ({ | ||
value: snippetValue(value, snippetEllipsisText, highlightPreTag, highlightPostTag), | ||
}); }; | ||
return Object.keys(formattedHit).reduce(function (result, key) { | ||
if (snippetAll || (attributesToSnippet === null || attributesToSnippet === void 0 ? void 0 : attributesToSnippet.includes(key))) { | ||
var value = formattedHit[key]; | ||
result[key] = Array.isArray(value) | ||
? value.map(toSnippetMatch) | ||
: toSnippetMatch(value); | ||
var formattedHit = hit._formatted; | ||
var newHit = hit._formatted; | ||
if (attributes === undefined) { | ||
return hit; | ||
} | ||
// All attributes that should be snippeted and their snippet size | ||
var snippets = attributes.map(function (attribute) { return attribute.split(':')[0]; }); | ||
// Find presence of a wildcard * | ||
var wildCard = snippets.includes('*'); | ||
if (wildCard) { | ||
// In case of * | ||
for (var attribute in formattedHit) { | ||
newHit[attribute] = resolveSnippet(hit[attribute], formattedHit[attribute], ellipsis); | ||
} | ||
return result; | ||
}, {}); | ||
} | ||
else { | ||
// Itterate on all attributes that needs snippeting | ||
for (var _i = 0, snippets_1 = snippets; _i < snippets_1.length; _i++) { | ||
var attribute = snippets_1[_i]; | ||
newHit[attribute] = resolveSnippet(hit[attribute], formattedHit[attribute], ellipsis); | ||
} | ||
} | ||
hit._formatted = newHit; | ||
return hit; | ||
} | ||
/** | ||
@@ -677,13 +707,17 @@ * Adapt MeiliSearch formating to formating compliant with instantsearch.js. | ||
*/ | ||
function adaptFormating(formattedHit, searchContext) { | ||
function adaptFormating(hit, searchContext) { | ||
var attributesToSnippet = searchContext === null || searchContext === void 0 ? void 0 : searchContext.attributesToSnippet; | ||
var snippetEllipsisText = searchContext === null || searchContext === void 0 ? void 0 : searchContext.snippetEllipsisText; | ||
var highlightPreTag = searchContext === null || searchContext === void 0 ? void 0 : searchContext.highlightPreTag; | ||
var highlightPostTag = searchContext === null || searchContext === void 0 ? void 0 : searchContext.highlightPostTag; | ||
if (!formattedHit || formattedHit.length) | ||
var ellipsis = searchContext === null || searchContext === void 0 ? void 0 : searchContext.snippetEllipsisText; | ||
var preTag = searchContext === null || searchContext === void 0 ? void 0 : searchContext.highlightPreTag; | ||
var postTag = searchContext === null || searchContext === void 0 ? void 0 : searchContext.highlightPostTag; | ||
if (!hit._formatted) | ||
return {}; | ||
return { | ||
_highlightResult: adaptHighlight(formattedHit, highlightPreTag, highlightPostTag), | ||
_snippetResult: adaptSnippet(formattedHit, attributesToSnippet, snippetEllipsisText, highlightPreTag, highlightPostTag), | ||
var _highlightResult = adaptHighlight(hit, preTag, postTag); | ||
// what is ellipsis by default | ||
var _snippetResult = adaptHighlight(adaptSnippet(hit, attributesToSnippet, ellipsis), preTag, postTag); | ||
var highlightedHit = { | ||
_highlightResult: _highlightResult, | ||
_snippetResult: _snippetResult | ||
}; | ||
return highlightedHit; | ||
} | ||
@@ -700,5 +734,5 @@ | ||
lat: hits[i]._geo.lat, | ||
lng: hits[i]._geo.lng, | ||
lng: hits[i]._geo.lng | ||
}; | ||
hits[i].objectID = "" + (i + Math.random() * 1000000); | ||
hits[i].objectID = "".concat(i + Math.random() * 1000000); | ||
delete hits[i]._geo; | ||
@@ -723,4 +757,4 @@ } | ||
if (Object.keys(hit).length > 0) { | ||
var formattedHit = hit._formatted; hit._matchesInfo; var restOfHit = __rest(hit, ["_formatted", "_matchesInfo"]); | ||
return __assign(__assign(__assign({}, restOfHit), adaptFormating(formattedHit, searchContext)), (primaryKey && { objectID: hit[primaryKey] })); | ||
hit._formatted; hit._matchesInfo; var restOfHit = __rest(hit, ["_formatted", "_matchesInfo"]); | ||
return __assign(__assign(__assign({}, restOfHit), adaptFormating(hit, searchContext)), (primaryKey && { objectID: hit[primaryKey] })); | ||
} | ||
@@ -759,3 +793,3 @@ return hit; | ||
return { | ||
results: [adaptedSearchResponse], | ||
results: [adaptedSearchResponse] | ||
}; | ||
@@ -788,3 +822,3 @@ } | ||
searchCache[key] = JSON.stringify(searchResponse); | ||
}, | ||
} | ||
}; | ||
@@ -811,3 +845,3 @@ } | ||
placeholderSearch: options.placeholderSearch !== false, | ||
paginationTotalHits: paginationTotalHits, | ||
paginationTotalHits: paginationTotalHits | ||
}; | ||
@@ -860,3 +894,3 @@ return { | ||
}); | ||
}, | ||
} | ||
}; | ||
@@ -885,3 +919,3 @@ } | ||
hitsPerPage: searchContext.hitsPerPage === undefined ? 20 : searchContext.hitsPerPage, | ||
page: (params === null || params === void 0 ? void 0 : params.page) || 0, // default page is 0 if none is provided | ||
page: (params === null || params === void 0 ? void 0 : params.page) || 0 | ||
}; | ||
@@ -888,0 +922,0 @@ } |
@@ -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,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)}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("meilisearch"),n=function(){return(n=Object.assign||function(t){for(var n,r=1,e=arguments.length;r<e;r++)for(var i in n=arguments[r])Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i]);return t}).apply(this,arguments)}; | ||
/*! ***************************************************************************** | ||
@@ -15,3 +15,3 @@ Copyright (c) Microsoft Corporation. | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */function 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()]}}))}))}}}; | ||
***************************************************************************** */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 c(t){return{searchResponse:function(n,i,a){return r(this,void 0,void 0,(function(){var r,o,u,c;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(c=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,c.facetsDistribution),t.setEntry(r,c),[2,c]}}))}))}}}function l(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],c=u[1],h=u[2],p=u[3],d=[parseFloat(s),parseFloat(c),parseFloat(h),parseFloat(p)],g=d[0],v=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}(g,v,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),c=o+Math.sin(r),h=Math.sqrt(u*u+s*s),p=Math.atan2(s,u),d=Math.atan2(c,h);return n<e||n>e&&n>Math.PI&&e<-Math.PI?(d+=Math.PI,p+=Math.PI):(d=l(d),p=l(p)),Math.abs(u)<Math.pow(10,-9)&&Math.abs(s)<Math.pow(10,-9)&&Math.abs(c)<Math.pow(10,-9)&&(d=0,p=0),"".concat(d,",").concat(p)}(g,v,y,m)}if(null!=n&&null!=r){var b=n.split(","),M=b[0],P=b[1];return M=Number.parseFloat(M).toFixed(5),P=Number.parseFloat(P).toFixed(5),{filter:"_geoRadius(".concat(M,", ").concat(P,", ").concat(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 g(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 v(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=g(null==t?void 0:t.filters,null==t?void 0:t.numericFilters,null==t?void 0:t.facetFilters);a.length&&(n.filter=a),i&&(n.attributesToCrop=i),n.attributesToHighlight=(null==t?void 0:t.attributesToHighlight)||["*"];var o=t.placeholderSearch,u=t.query,s=t.paginationTotalHits;n.limit=!o&&""===u||0===s?0:s;var c=t.sort;(null==c?void 0:c.length)&&(n.sort=[c]);var l=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==l?void 0:l.filter)&&(n.filter?n.filter.unshift(l.filter):n.filter=[l.filter]),n}function y(t,n,r){return"string"==typeof t?function(t,n,r){return void 0===n&&(n="__ais-highlight__"),void 0===r&&(r="__/ais-highlight__"),(a(t)?t:JSON.stringify(t)).replace(/<em>/g,n).replace(/<\/em>/g,r)}(t,n,r):void 0===t?JSON.stringify(null):JSON.stringify(t)}function m(t,n,r){return t._formatted?Object.keys(t._formatted).reduce((function(e,i){var a=t._formatted[i];return e[i]=function(t,n,r){return Array.isArray(t)?t.map((function(t){return{value:y(t,n,r)}})):{value:y(t,n,r)}}(a,n,r),e}),{}):t._formatted}function b(t,n,r){var e,i=n;return a(n)&&t.toString().length>(e=n,e.replace(/<em>/g,"").replace(/<\/em>/g,"")).length&&(n[0]===n[0].toLowerCase()&&!1===n.startsWith("<em>")&&(i="".concat(r).concat(n.trim())),!1==!!n.match(/[.!?]$/)&&(i="".concat(n.trim()).concat(r))),i}function M(t,n,r){return r&&"string"==typeof n?Array.isArray(t)?t.map((function(t){return b(t,n,r)})):b(t,n,r):n}function P(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._formatted?{_highlightResult:m(t,i,a),_snippetResult:m(function(t,n,r){var e=t._formatted,i=t._formatted;if(void 0===n)return t;var a=n.map((function(t){return t.split(":")[0]}));if(a.includes("*"))for(var o in e)i[o]=M(t[o],e[o],r);else for(var u=0,s=a;u<s.length;u++)i[o=s[u]]=M(t[o],e[o],r);return t._formatted=i,t}(t,r,e),i,a)}:{}}function w(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){t._formatted,t._matchesInfo;var e=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({},e),P(t,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="".concat(n+1e6*Math.random()),delete t[n]._geo);return t}(o)}function _(t,r,e){var i={},a=t.facetsDistribution,o=null==t?void 0:t.exhaustiveFacetsCount;o&&(i.exhaustiveFacetsCount=o);var u,s,c=(u=t.hits.length,(s=e.hitsPerPage)>0?Math.ceil(u/s):0),l=w(t.hits,r,e),f=t.exhaustiveNbHits,h=t.nbHits,p=t.processingTimeMs,d=t.query,g=e.hitsPerPage,v=e.page;return{results:[n({index:r.indexUid,hitsPerPage:g,page:v,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=c(x()),s=null!=o.paginationTotalHits?o.paginationTotalHits:200,l={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,c,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,l),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=v(a),[4,u.searchResponse(a,s,this.MeiliSearchClient)];case 1:return c=e.sent(),[2,_(c,a,o)];case 2:throw f=e.sent(),console.error(f),new Error(f);case 3:return[2]}}))}))},searchForFacetValues:function(t){return r(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,new Promise((function(t,n){n(new Error("SearchForFacetValues is not compatible with MeiliSearch")),t([])}))];case 1:return[2,t.sent()]}}))}))}}}; | ||
//# sourceMappingURL=instant-meilisearch.cjs.min.js.map |
@@ -251,3 +251,3 @@ import { MeiliSearch } from 'meilisearch'; | ||
}); | ||
}, | ||
} | ||
}; | ||
@@ -310,3 +310,3 @@ } | ||
} | ||
return lat3 + "," + lng3; | ||
return "".concat(lat3, ",").concat(lng3); | ||
} | ||
@@ -369,3 +369,3 @@ /** | ||
lng3 = Number.parseFloat(lng3).toFixed(5); | ||
var filter = "_geoRadius(" + lat3 + ", " + lng3 + ", " + radius + ")"; | ||
var filter = "_geoRadius(".concat(lat3, ", ").concat(lng3, ", ").concat(radius, ")"); | ||
return { filter: filter }; | ||
@@ -574,12 +574,35 @@ } | ||
*/ | ||
function replaceHighlightTags(value, highlightPreTag, highlightPostTag) { | ||
highlightPreTag = highlightPreTag || '__ais-highlight__'; | ||
highlightPostTag = highlightPostTag || '__/ais-highlight__'; | ||
function replaceDefaultEMTag(value, preTag, postTag) { | ||
if (preTag === void 0) { preTag = '__ais-highlight__'; } | ||
if (postTag === void 0) { postTag = '__/ais-highlight__'; } | ||
// Highlight is applied by MeiliSearch (<em> tags) | ||
// We replace the <em> by the expected tag for InstantSearch | ||
var stringifiedValue = isString(value) ? value : JSON.stringify(value); | ||
return stringifiedValue | ||
.replace(/<em>/g, highlightPreTag) | ||
.replace(/<\/em>/g, highlightPostTag); | ||
return stringifiedValue.replace(/<em>/g, preTag).replace(/<\/em>/g, postTag); | ||
} | ||
function addHighlightTags(value, preTag, postTag) { | ||
if (typeof value === 'string') { | ||
// String | ||
return replaceDefaultEMTag(value, preTag, postTag); | ||
} | ||
else if (value === undefined) { | ||
// undefined | ||
return JSON.stringify(null); | ||
} | ||
else { | ||
// Other | ||
return JSON.stringify(value); | ||
} | ||
} | ||
function resolveHighlightValue(value, preTag, postTag) { | ||
if (Array.isArray(value)) { | ||
// Array | ||
return value.map(function (elem) { return ({ | ||
value: addHighlightTags(elem, preTag, postTag) | ||
}); }); | ||
} | ||
else { | ||
return { value: addHighlightTags(value, preTag, postTag) }; | ||
} | ||
} | ||
/** | ||
@@ -591,76 +614,83 @@ * @param {Record<string} formattedHit | ||
*/ | ||
function adaptHighlight(formattedHit, highlightPreTag, highlightPostTag) { | ||
// formattedHit is the `_formatted` object returned by MeiliSearch. | ||
function adaptHighlight(hit, preTag, postTag) { | ||
// hit is the `_formatted` object returned by MeiliSearch. | ||
// It contains all the highlighted and croped attributes | ||
var toHighlightMatch = function (value) { return ({ | ||
value: replaceHighlightTags(value, highlightPreTag, highlightPostTag), | ||
}); }; | ||
return Object.keys(formattedHit).reduce(function (result, key) { | ||
var value = formattedHit[key]; | ||
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); | ||
} | ||
if (!hit._formatted) | ||
return hit._formatted; | ||
return Object.keys(hit._formatted).reduce(function (result, key) { | ||
var value = hit._formatted[key]; | ||
result[key] = resolveHighlightValue(value, preTag, postTag); | ||
return result; | ||
}, {}); | ||
} | ||
/** | ||
* @param {string} value | ||
* @param {string} snippetEllipsisText? | ||
* @param {string} highlightPreTag? | ||
* @param {string} highlightPostTag? | ||
* @returns {string} | ||
*/ | ||
function snippetValue(value, snippetEllipsisText, highlightPreTag, highlightPostTag) { | ||
var newValue = value; | ||
// manage a kind of `...` for the crop until this feature is implemented https://roadmap.meilisearch.com/c/69-policy-for-cropped-values?utm_medium=social&utm_source=portal_share | ||
// `...` is put if we are at the middle of a sentence (instead at the middle of the document field) | ||
if (snippetEllipsisText !== undefined && isString(newValue) && newValue) { | ||
if (newValue[0] === newValue[0].toLowerCase() && // beginning of a sentence | ||
newValue.startsWith('<em>') === false // beginning of the document field, otherwise MeiliSearch would crop around the highligh | ||
function nakedOfTags(str) { | ||
return str.replace(/<em>/g, '').replace(/<\/em>/g, ''); | ||
} | ||
function addEllipsis(value, formatValue, ellipsis) { | ||
// Manage ellpsis on cropped values until this feature is implemented https://roadmap.meilisearch.com/c/69-policy-for-cropped-values?utm_medium=social&utm_source=portal_share in MeiliSearch | ||
var ellipsedValue = formatValue; | ||
if (isString(formatValue) && | ||
value.toString().length > nakedOfTags(formatValue).length) { | ||
if (formatValue[0] === formatValue[0].toLowerCase() && // beginning of a sentence | ||
formatValue.startsWith('<em>') === false // beginning of the document field, otherwise MeiliSearch would crop around the highlight | ||
) { | ||
newValue = "" + snippetEllipsisText + newValue; | ||
ellipsedValue = "".concat(ellipsis).concat(formatValue.trim()); | ||
} | ||
if (!!newValue.match(/[.!?]$/) === false) { | ||
if (!!formatValue.match(/[.!?]$/) === false) { | ||
// end of the sentence | ||
newValue = "" + newValue + snippetEllipsisText; | ||
ellipsedValue = "".concat(formatValue.trim()).concat(ellipsis); | ||
} | ||
} | ||
return replaceHighlightTags(newValue, highlightPreTag, highlightPostTag); | ||
return ellipsedValue; | ||
} | ||
/** | ||
* @param {Record<string} formattedHit | ||
* @param {readonlystring[]|undefined} attributesToSnippet | ||
* @param {string|undefined} snippetEllipsisText | ||
* @param {string|undefined} highlightPreTag | ||
* @param {string|undefined} highlightPostTag | ||
* @param {string} value | ||
* @param {string} ellipsis? | ||
* @returns {string} | ||
*/ | ||
function adaptSnippet(formattedHit, attributesToSnippet, snippetEllipsisText, highlightPreTag, highlightPostTag) { | ||
if (attributesToSnippet === undefined) { | ||
return null; | ||
function resolveSnippet(value, formatValue, ellipsis) { | ||
if (!ellipsis || !(typeof formatValue === 'string')) { | ||
return formatValue; | ||
} | ||
attributesToSnippet = attributesToSnippet.map(function (attribute) { return attribute.split(':')[0]; }); | ||
var snippetAll = attributesToSnippet.includes('*'); | ||
// formattedHit is the `_formatted` object returned by MeiliSearch. | ||
else if (Array.isArray(value)) { | ||
// Array | ||
return value.map(function (elem) { return addEllipsis(elem, formatValue, ellipsis); }); | ||
} | ||
return addEllipsis(value, formatValue, ellipsis); | ||
} | ||
/** | ||
* @param {Record<string} hit | ||
* @param {readonlystring[]|undefined} attributes | ||
* @param {string|undefined} ellipsis | ||
*/ | ||
function adaptSnippet(hit, attributes, ellipsis) { | ||
// hit is the `_formatted` object returned by MeiliSearch. | ||
// It contains all the highlighted and croped attributes | ||
var toSnippetMatch = function (value) { return ({ | ||
value: snippetValue(value, snippetEllipsisText, highlightPreTag, highlightPostTag), | ||
}); }; | ||
return Object.keys(formattedHit).reduce(function (result, key) { | ||
if (snippetAll || (attributesToSnippet === null || attributesToSnippet === void 0 ? void 0 : attributesToSnippet.includes(key))) { | ||
var value = formattedHit[key]; | ||
result[key] = Array.isArray(value) | ||
? value.map(toSnippetMatch) | ||
: toSnippetMatch(value); | ||
var formattedHit = hit._formatted; | ||
var newHit = hit._formatted; | ||
if (attributes === undefined) { | ||
return hit; | ||
} | ||
// All attributes that should be snippeted and their snippet size | ||
var snippets = attributes.map(function (attribute) { return attribute.split(':')[0]; }); | ||
// Find presence of a wildcard * | ||
var wildCard = snippets.includes('*'); | ||
if (wildCard) { | ||
// In case of * | ||
for (var attribute in formattedHit) { | ||
newHit[attribute] = resolveSnippet(hit[attribute], formattedHit[attribute], ellipsis); | ||
} | ||
return result; | ||
}, {}); | ||
} | ||
else { | ||
// Itterate on all attributes that needs snippeting | ||
for (var _i = 0, snippets_1 = snippets; _i < snippets_1.length; _i++) { | ||
var attribute = snippets_1[_i]; | ||
newHit[attribute] = resolveSnippet(hit[attribute], formattedHit[attribute], ellipsis); | ||
} | ||
} | ||
hit._formatted = newHit; | ||
return hit; | ||
} | ||
/** | ||
@@ -673,13 +703,17 @@ * Adapt MeiliSearch formating to formating compliant with instantsearch.js. | ||
*/ | ||
function adaptFormating(formattedHit, searchContext) { | ||
function adaptFormating(hit, searchContext) { | ||
var attributesToSnippet = searchContext === null || searchContext === void 0 ? void 0 : searchContext.attributesToSnippet; | ||
var snippetEllipsisText = searchContext === null || searchContext === void 0 ? void 0 : searchContext.snippetEllipsisText; | ||
var highlightPreTag = searchContext === null || searchContext === void 0 ? void 0 : searchContext.highlightPreTag; | ||
var highlightPostTag = searchContext === null || searchContext === void 0 ? void 0 : searchContext.highlightPostTag; | ||
if (!formattedHit || formattedHit.length) | ||
var ellipsis = searchContext === null || searchContext === void 0 ? void 0 : searchContext.snippetEllipsisText; | ||
var preTag = searchContext === null || searchContext === void 0 ? void 0 : searchContext.highlightPreTag; | ||
var postTag = searchContext === null || searchContext === void 0 ? void 0 : searchContext.highlightPostTag; | ||
if (!hit._formatted) | ||
return {}; | ||
return { | ||
_highlightResult: adaptHighlight(formattedHit, highlightPreTag, highlightPostTag), | ||
_snippetResult: adaptSnippet(formattedHit, attributesToSnippet, snippetEllipsisText, highlightPreTag, highlightPostTag), | ||
var _highlightResult = adaptHighlight(hit, preTag, postTag); | ||
// what is ellipsis by default | ||
var _snippetResult = adaptHighlight(adaptSnippet(hit, attributesToSnippet, ellipsis), preTag, postTag); | ||
var highlightedHit = { | ||
_highlightResult: _highlightResult, | ||
_snippetResult: _snippetResult | ||
}; | ||
return highlightedHit; | ||
} | ||
@@ -696,5 +730,5 @@ | ||
lat: hits[i]._geo.lat, | ||
lng: hits[i]._geo.lng, | ||
lng: hits[i]._geo.lng | ||
}; | ||
hits[i].objectID = "" + (i + Math.random() * 1000000); | ||
hits[i].objectID = "".concat(i + Math.random() * 1000000); | ||
delete hits[i]._geo; | ||
@@ -719,4 +753,4 @@ } | ||
if (Object.keys(hit).length > 0) { | ||
var formattedHit = hit._formatted; hit._matchesInfo; var restOfHit = __rest(hit, ["_formatted", "_matchesInfo"]); | ||
return __assign(__assign(__assign({}, restOfHit), adaptFormating(formattedHit, searchContext)), (primaryKey && { objectID: hit[primaryKey] })); | ||
hit._formatted; hit._matchesInfo; var restOfHit = __rest(hit, ["_formatted", "_matchesInfo"]); | ||
return __assign(__assign(__assign({}, restOfHit), adaptFormating(hit, searchContext)), (primaryKey && { objectID: hit[primaryKey] })); | ||
} | ||
@@ -755,3 +789,3 @@ return hit; | ||
return { | ||
results: [adaptedSearchResponse], | ||
results: [adaptedSearchResponse] | ||
}; | ||
@@ -784,3 +818,3 @@ } | ||
searchCache[key] = JSON.stringify(searchResponse); | ||
}, | ||
} | ||
}; | ||
@@ -807,3 +841,3 @@ } | ||
placeholderSearch: options.placeholderSearch !== false, | ||
paginationTotalHits: paginationTotalHits, | ||
paginationTotalHits: paginationTotalHits | ||
}; | ||
@@ -856,3 +890,3 @@ return { | ||
}); | ||
}, | ||
} | ||
}; | ||
@@ -881,3 +915,3 @@ } | ||
hitsPerPage: searchContext.hitsPerPage === undefined ? 20 : searchContext.hitsPerPage, | ||
page: (params === null || params === void 0 ? void 0 : params.page) || 0, // default page is 0 if none is provided | ||
page: (params === null || params === void 0 ? void 0 : params.page) || 0 | ||
}; | ||
@@ -884,0 +918,0 @@ } |
@@ -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)).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}; | ||
***************************************************************************** */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 c(t){return{searchResponse:function(n,i,a){return r(this,void 0,void 0,(function(){var r,o,u,c;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(c=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,c.facetsDistribution),t.setEntry(r,c),[2,c]}}))}))}}}function l(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],c=u[1],h=u[2],p=u[3],d=[parseFloat(s),parseFloat(c),parseFloat(h),parseFloat(p)],g=d[0],v=d[1],m=d[2],y=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}(g,v,m,y)/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),c=o+Math.sin(r),h=Math.sqrt(u*u+s*s),p=Math.atan2(s,u),d=Math.atan2(c,h);return n<e||n>e&&n>Math.PI&&e<-Math.PI?(d+=Math.PI,p+=Math.PI):(d=l(d),p=l(p)),Math.abs(u)<Math.pow(10,-9)&&Math.abs(s)<Math.pow(10,-9)&&Math.abs(c)<Math.pow(10,-9)&&(d=0,p=0),"".concat(d,",").concat(p)}(g,v,m,y)}if(null!=n&&null!=r){var b=n.split(","),M=b[0],P=b[1];return M=Number.parseFloat(M).toFixed(5),P=Number.parseFloat(P).toFixed(5),{filter:"_geoRadius(".concat(M,", ").concat(P,", ").concat(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 g(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 v(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=g(null==t?void 0:t.filters,null==t?void 0:t.numericFilters,null==t?void 0:t.facetFilters);a.length&&(n.filter=a),i&&(n.attributesToCrop=i),n.attributesToHighlight=(null==t?void 0:t.attributesToHighlight)||["*"];var o=t.placeholderSearch,u=t.query,s=t.paginationTotalHits;n.limit=!o&&""===u||0===s?0:s;var c=t.sort;(null==c?void 0:c.length)&&(n.sort=[c]);var l=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==l?void 0:l.filter)&&(n.filter?n.filter.unshift(l.filter):n.filter=[l.filter]),n}function m(t,n,r){return"string"==typeof t?function(t,n,r){return void 0===n&&(n="__ais-highlight__"),void 0===r&&(r="__/ais-highlight__"),(a(t)?t:JSON.stringify(t)).replace(/<em>/g,n).replace(/<\/em>/g,r)}(t,n,r):void 0===t?JSON.stringify(null):JSON.stringify(t)}function y(t,n,r){return t._formatted?Object.keys(t._formatted).reduce((function(e,i){var a=t._formatted[i];return e[i]=function(t,n,r){return Array.isArray(t)?t.map((function(t){return{value:m(t,n,r)}})):{value:m(t,n,r)}}(a,n,r),e}),{}):t._formatted}function b(t,n,r){var e,i=n;return a(n)&&t.toString().length>(e=n,e.replace(/<em>/g,"").replace(/<\/em>/g,"")).length&&(n[0]===n[0].toLowerCase()&&!1===n.startsWith("<em>")&&(i="".concat(r).concat(n.trim())),!1==!!n.match(/[.!?]$/)&&(i="".concat(n.trim()).concat(r))),i}function M(t,n,r){return r&&"string"==typeof n?Array.isArray(t)?t.map((function(t){return b(t,n,r)})):b(t,n,r):n}function P(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._formatted?{_highlightResult:y(t,i,a),_snippetResult:y(function(t,n,r){var e=t._formatted,i=t._formatted;if(void 0===n)return t;var a=n.map((function(t){return t.split(":")[0]}));if(a.includes("*"))for(var o in e)i[o]=M(t[o],e[o],r);else for(var u=0,s=a;u<s.length;u++)i[o=s[u]]=M(t[o],e[o],r);return t._formatted=i,t}(t,r,e),i,a)}:{}}function w(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){t._formatted,t._matchesInfo;var e=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({},e),P(t,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="".concat(n+1e6*Math.random()),delete t[n]._geo);return t}(o)}function _(t,r,e){var i={},a=t.facetsDistribution,o=null==t?void 0:t.exhaustiveFacetsCount;o&&(i.exhaustiveFacetsCount=o);var u,s,c=(u=t.hits.length,(s=e.hitsPerPage)>0?Math.ceil(u/s):0),l=w(t.hits,r,e),f=t.exhaustiveNbHits,h=t.nbHits,p=t.processingTimeMs,d=t.query,g=e.hitsPerPage,v=e.page;return{results:[n({index:r.indexUid,hitsPerPage:g,page:v,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 S(i,a,o){void 0===a&&(a=""),void 0===o&&(o={});var u=c(x()),s=null!=o.paginationTotalHits?o.paginationTotalHits:200,l={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,c,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,l),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=v(a),[4,u.searchResponse(a,s,this.MeiliSearchClient)];case 1:return c=e.sent(),[2,_(c,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{S as instantMeiliSearch}; | ||
//# sourceMappingURL=instant-meilisearch.esm.min.js.map |
@@ -15,3 +15,3 @@ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).window=t.window||{})}(this,(function(t){"use strict"; | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */var e=function(){return(e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function r(t,e,r,n){return new(r||(r=Promise))((function(i,s){function o(t){try{a(n.next(t))}catch(t){s(t)}}function u(t){try{a(n.throw(t))}catch(t){s(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,u)}a((n=n.apply(t,e||[])).next())}))}function n(t,e){var r,n,i,s,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,n=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function i(t,e){for(var r=0,n=e.length,i=t.length;r<n;r++,i++)t[i]=e[r];return t}var s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function o(t){var e={exports:{}};return t(e,e.exports),e.exports}o((function(t){!function(t){!function(e){var r="URLSearchParams"in t,n="Symbol"in t&&"iterator"in Symbol,i="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),s="FormData"in t,o="ArrayBuffer"in t;if(o)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],a=ArrayBuffer.isView||function(t){return t&&u.indexOf(Object.prototype.toString.call(t))>-1};function c(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function h(t){return"string"!=typeof t&&(t=String(t)),t}function l(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n&&(e[Symbol.iterator]=function(){return e}),e}function d(t){this.map={},t instanceof d?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function f(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function p(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function v(t){var e=new FileReader,r=p(e);return e.readAsArrayBuffer(t),r}function y(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function b(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:i&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:s&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():o&&i&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=y(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):o&&(ArrayBuffer.prototype.isPrototypeOf(t)||a(t))?this._bodyArrayBuffer=y(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i&&(this.blob=function(){var t=f(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?f(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(v)}),this.text=function(){var t,e,r,n=f(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,r=p(e),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},s&&(this.formData=function(){return this.text().then(m)}),this.json=function(){return this.text().then(JSON.parse)},this}d.prototype.append=function(t,e){t=c(t),e=h(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},d.prototype.delete=function(t){delete this.map[c(t)]},d.prototype.get=function(t){return t=c(t),this.has(t)?this.map[t]:null},d.prototype.has=function(t){return this.map.hasOwnProperty(c(t))},d.prototype.set=function(t,e){this.map[c(t)]=h(e)},d.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},d.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),l(t)},d.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),l(t)},d.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),l(t)},n&&(d.prototype[Symbol.iterator]=d.prototype.entries);var g=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function w(t,e){var r,n,i=(e=e||{}).body;if(t instanceof w){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new d(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,i||null==t._bodyInit||(i=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new d(e.headers)),this.method=(r=e.method||this.method||"GET",n=r.toUpperCase(),g.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&i)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(i)}function m(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),i=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(i))}})),e}function x(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new d(e.headers),this.url=e.url||"",this._initBody(t)}w.prototype.clone=function(){return new w(this,{body:this._bodyInit})},b.call(w.prototype),b.call(x.prototype),x.prototype.clone=function(){return new x(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new d(this.headers),url:this.url})},x.error=function(){var t=new x(null,{status:0,statusText:""});return t.type="error",t};var R=[301,302,303,307,308];x.redirect=function(t,e){if(-1===R.indexOf(e))throw new RangeError("Invalid status code");return new x(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function S(t,r){return new Promise((function(n,s){var o=new w(t,r);if(o.signal&&o.signal.aborted)return s(new e.DOMException("Aborted","AbortError"));var u=new XMLHttpRequest;function a(){u.abort()}u.onload=function(){var t,e,r={status:u.status,statusText:u.statusText,headers:(t=u.getAllResponseHeaders()||"",e=new d,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var i=r.join(":").trim();e.append(n,i)}})),e)};r.url="responseURL"in u?u.responseURL:r.headers.get("X-Request-URL");var i="response"in u?u.response:u.responseText;n(new x(i,r))},u.onerror=function(){s(new TypeError("Network request failed"))},u.ontimeout=function(){s(new TypeError("Network request failed"))},u.onabort=function(){s(new e.DOMException("Aborted","AbortError"))},u.open(o.method,o.url,!0),"include"===o.credentials?u.withCredentials=!0:"omit"===o.credentials&&(u.withCredentials=!1),"responseType"in u&&i&&(u.responseType="blob"),o.headers.forEach((function(t,e){u.setRequestHeader(e,t)})),o.signal&&(o.signal.addEventListener("abort",a),u.onreadystatechange=function(){4===u.readyState&&o.signal.removeEventListener("abort",a)}),u.send(void 0===o._bodyInit?null:o._bodyInit)}))}S.polyfill=!0,t.fetch||(t.fetch=S,t.Headers=d,t.Request=w,t.Response=x),e.Headers=d,e.Request=w,e.Response=x,e.fetch=S,Object.defineProperty(e,"__esModule",{value:!0})}({})}("undefined"!=typeof self?self:s)}));var u=o((function(t,e){!function(t){ | ||
***************************************************************************** */var e=function(){return(e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function r(t,e,r,n){return new(r||(r=Promise))((function(i,s){function o(t){try{a(n.next(t))}catch(t){s(t)}}function u(t){try{a(n.throw(t))}catch(t){s(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,u)}a((n=n.apply(t,e||[])).next())}))}function n(t,e){var r,n,i,s,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,n=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function i(t,e){for(var r=0,n=e.length,i=t.length;r<n;r++,i++)t[i]=e[r];return t}var s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function o(t){var e={exports:{}};return t(e,e.exports),e.exports}o((function(t){!function(t){!function(e){var r="URLSearchParams"in t,n="Symbol"in t&&"iterator"in Symbol,i="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),s="FormData"in t,o="ArrayBuffer"in t;if(o)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],a=ArrayBuffer.isView||function(t){return t&&u.indexOf(Object.prototype.toString.call(t))>-1};function c(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function h(t){return"string"!=typeof t&&(t=String(t)),t}function l(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n&&(e[Symbol.iterator]=function(){return e}),e}function d(t){this.map={},t instanceof d?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function f(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function p(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function v(t){var e=new FileReader,r=p(e);return e.readAsArrayBuffer(t),r}function y(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function b(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:i&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:s&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():o&&i&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=y(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):o&&(ArrayBuffer.prototype.isPrototypeOf(t)||a(t))?this._bodyArrayBuffer=y(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i&&(this.blob=function(){var t=f(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?f(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(v)}),this.text=function(){var t,e,r,n=f(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,r=p(e),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},s&&(this.formData=function(){return this.text().then(w)}),this.json=function(){return this.text().then(JSON.parse)},this}d.prototype.append=function(t,e){t=c(t),e=h(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},d.prototype.delete=function(t){delete this.map[c(t)]},d.prototype.get=function(t){return t=c(t),this.has(t)?this.map[t]:null},d.prototype.has=function(t){return this.map.hasOwnProperty(c(t))},d.prototype.set=function(t,e){this.map[c(t)]=h(e)},d.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},d.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),l(t)},d.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),l(t)},d.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),l(t)},n&&(d.prototype[Symbol.iterator]=d.prototype.entries);var g=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function m(t,e){var r,n,i=(e=e||{}).body;if(t instanceof m){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new d(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,i||null==t._bodyInit||(i=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new d(e.headers)),this.method=(r=e.method||this.method||"GET",n=r.toUpperCase(),g.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&i)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(i)}function w(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),i=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(i))}})),e}function x(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new d(e.headers),this.url=e.url||"",this._initBody(t)}m.prototype.clone=function(){return new m(this,{body:this._bodyInit})},b.call(m.prototype),b.call(x.prototype),x.prototype.clone=function(){return new x(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new d(this.headers),url:this.url})},x.error=function(){var t=new x(null,{status:0,statusText:""});return t.type="error",t};var R=[301,302,303,307,308];x.redirect=function(t,e){if(-1===R.indexOf(e))throw new RangeError("Invalid status code");return new x(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function S(t,r){return new Promise((function(n,s){var o=new m(t,r);if(o.signal&&o.signal.aborted)return s(new e.DOMException("Aborted","AbortError"));var u=new XMLHttpRequest;function a(){u.abort()}u.onload=function(){var t,e,r={status:u.status,statusText:u.statusText,headers:(t=u.getAllResponseHeaders()||"",e=new d,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var i=r.join(":").trim();e.append(n,i)}})),e)};r.url="responseURL"in u?u.responseURL:r.headers.get("X-Request-URL");var i="response"in u?u.response:u.responseText;n(new x(i,r))},u.onerror=function(){s(new TypeError("Network request failed"))},u.ontimeout=function(){s(new TypeError("Network request failed"))},u.onabort=function(){s(new e.DOMException("Aborted","AbortError"))},u.open(o.method,o.url,!0),"include"===o.credentials?u.withCredentials=!0:"omit"===o.credentials&&(u.withCredentials=!1),"responseType"in u&&i&&(u.responseType="blob"),o.headers.forEach((function(t,e){u.setRequestHeader(e,t)})),o.signal&&(o.signal.addEventListener("abort",a),u.onreadystatechange=function(){4===u.readyState&&o.signal.removeEventListener("abort",a)}),u.send(void 0===o._bodyInit?null:o._bodyInit)}))}S.polyfill=!0,t.fetch||(t.fetch=S,t.Headers=d,t.Request=m,t.Response=x),e.Headers=d,e.Request=m,e.Response=x,e.fetch=S,Object.defineProperty(e,"__esModule",{value:!0})}({})}("undefined"!=typeof self?self:s)}));var u=o((function(t,e){!function(t){ | ||
/*! ***************************************************************************** | ||
@@ -29,3 +29,3 @@ Copyright (c) Microsoft Corporation. | ||
***************************************************************************** */ | ||
var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,r)};function r(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var n=function(){return(n=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function i(t,e,r,n){function i(t){return t instanceof r?t:new r((function(e){e(t)}))}return new(r||(r=Promise))((function(r,s){function o(t){try{a(n.next(t))}catch(t){s(t)}}function u(t){try{a(n.throw(t))}catch(t){s(t)}}function a(t){t.done?r(t.value):i(t.value).then(o,u)}a((n=n.apply(t,e||[])).next())}))}function s(t,e){var r,n,i,s,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(t){return function(e){return a([t,e])}}function a(s){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,n=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}}var o=function(t){function e(r,n,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})})); | ||
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,c=t.call(this,r)||this;return c.name="MeiliSearchCommunicationError",c.type="MeiliSearchCommunicationError",n instanceof Response&&(c.message=n.statusText,c.statusCode=n.status),n instanceof Error&&(c.errno=n.errno,c.code=n.code),s?(c.stack=s,c.stack=null===(o=c.stack)||void 0===o?void 0:o.replace(/(TypeError|FetchError)/,c.name),c.stack=null===(u=c.stack)||void 0===u?void 0:u.replace("Failed to fetch","request to "+i+" failed, reason: connect ECONNREFUSED"),c.stack=null===(a=c.stack)||void 0===a?void 0:a.replace("Not Found","Not Found: "+i)):Error.captureStackTrace&&Error.captureStackTrace(c,e),c}return r(e,t),e}(Error),u=function(t){function e(e,r){var n=t.call(this,e.message)||this;return n.name="MeiliSearchApiError",n.code=e.code,n.type=e.type,n.link=e.link,n.message=e.message,n.httpStatus=r,Object.setPrototypeOf(n,u.prototype),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()).code)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()).code)return[2,this.createIndex(t,e)];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()).code)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),"".concat(d,",").concat(l)}(v,y,b,g)}if(null!=e&&null!=r){var m=e.split(","),w=m[0],x=m[1];return w=Number.parseFloat(w).toFixed(5),x=Number.parseFloat(x).toFixed(5),{filter:"_geoRadius(".concat(w,", ").concat(x,", ").concat(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 m(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 w(t,e,r){return"string"==typeof t?function(t,e,r){return void 0===e&&(e="__ais-highlight__"),void 0===r&&(r="__/ais-highlight__"),(a(t)?t:JSON.stringify(t)).replace(/<em>/g,e).replace(/<\/em>/g,r)}(t,e,r):void 0===t?JSON.stringify(null):JSON.stringify(t)}function x(t,e,r){return t._formatted?Object.keys(t._formatted).reduce((function(n,i){var s=t._formatted[i];return n[i]=function(t,e,r){return Array.isArray(t)?t.map((function(t){return{value:w(t,e,r)}})):{value:w(t,e,r)}}(s,e,r),n}),{}):t._formatted}function R(t,e,r){var n,i=e;return a(e)&&t.toString().length>(n=e,n.replace(/<em>/g,"").replace(/<\/em>/g,"")).length&&(e[0]===e[0].toLowerCase()&&!1===e.startsWith("<em>")&&(i="".concat(r).concat(e.trim())),!1==!!e.match(/[.!?]$/)&&(i="".concat(e.trim()).concat(r))),i}function S(t,e,r){return r&&"string"==typeof e?Array.isArray(t)?t.map((function(t){return R(t,e,r)})):R(t,e,r):e}function T(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._formatted?{_highlightResult:x(t,i,s),_snippetResult:x(function(t,e,r){var n=t._formatted,i=t._formatted;if(void 0===e)return t;var s=e.map((function(t){return t.split(":")[0]}));if(s.includes("*"))for(var o in n)i[o]=S(t[o],n[o],r);else for(var u=0,a=s;u<a.length;u++)i[o=a[u]]=S(t[o],n[o],r);return t._formatted=i,t}(t,r,n),i,s)}:{}}function E(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){t._formatted,t._matchesInfo;var n=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({},n),T(t,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="".concat(e+1e6*Math.random()),delete t[e]._geo);return t}(o)}function _(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=E(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=m(s),[4,o.searchResponse(s,a,this.MeiliSearchClient)];case 1:return h=n.sent(),[2,_(h,s,u)];case 2:throw l=n.sent(),console.error(l),new Error(l);case 3:return[2]}}))}))},searchForFacetValues:function(t){return r(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,new Promise((function(t,e){e(new Error("SearchForFacetValues is not compatible with MeiliSearch")),t([])}))];case 1:return[2,t.sent()]}}))}))}}},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=instant-meilisearch.umd.min.js.map |
@@ -1,6 +0,6 @@ | ||
// Type definitions for @meilisearch/instant-meilisearch 0.5.9 | ||
// Type definitions for @meilisearch/instant-meilisearch 0.5.10 | ||
// Project: https://github.com/meilisearch/instant-meilisearch.git | ||
// Definitions by: Clementine Urquizar <https://github.com/meilisearch> | ||
// Definitions: https://github.com/meilisearch/instant-meilisearch.git | ||
// TypeScript Version: ^4.4.4 | ||
// TypeScript Version: ^4.5.2 | ||
@@ -7,0 +7,0 @@ export * from './client'; |
{ | ||
"name": "@meilisearch/instant-meilisearch", | ||
"version": "0.5.9", | ||
"version": "0.5.10", | ||
"private": false, | ||
@@ -57,8 +57,8 @@ "description": "The search client to use MeiliSearch with InstantSearch.", | ||
"dependencies": { | ||
"meilisearch": "^0.22.1" | ||
"meilisearch": "^0.23.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.15.7", | ||
"@babel/core": "^7.15.8", | ||
"@babel/preset-env": "^7.15.8", | ||
"@babel/cli": "^7.16.0", | ||
"@babel/core": "^7.16.0", | ||
"@babel/preset-env": "^7.16.4", | ||
"@rollup/plugin-commonjs": "^17.1.0", | ||
@@ -71,6 +71,6 @@ "@rollup/plugin-node-resolve": "^11.2.0", | ||
"@vue/eslint-plugin": "^4.2.0", | ||
"algoliasearch": "^4.10.5", | ||
"algoliasearch": "^4.11.0", | ||
"babel-eslint": "^10.1.0", | ||
"babel-jest": "^27.2.2", | ||
"concurrently": "^6.3.0", | ||
"concurrently": "^6.4.0", | ||
"cssnano": "^4.1.10", | ||
@@ -93,3 +93,3 @@ "cypress": "^8.6.0", | ||
"eslint-plugin-vue": "^7.7.0", | ||
"instantsearch.js": "^4.31.0", | ||
"instantsearch.js": "^4.33.2", | ||
"jest": "^27.2.2", | ||
@@ -107,4 +107,4 @@ "jest-watch-typeahead": "^0.6.3", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.4.4" | ||
"typescript": "^4.5.2" | ||
} | ||
} |
@@ -184,3 +184,3 @@ <p align="center"> | ||
This package only guarantees the compatibility with the [version v0.23.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.23.0). | ||
This package only guarantees the compatibility with the [version v0.24.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.24.0). | ||
@@ -588,3 +588,3 @@ **Node / NPM versions**: | ||
- ✅ attribute: The facet to display _required_ | ||
- ✅ operator: How to apply facets, "AND" or "OR" | ||
- ❌ operator: How to apply facets, "AND" or "OR". For the moment it only works with "AND" | ||
- ✅ limit: How many facet values to retrieve. | ||
@@ -591,0 +591,0 @@ - ✅ showMore: Whether to display a button that expands the number of items. |
import type { PaginationContext, SearchContext } from '../../types' | ||
import { adaptPagination } from './pagination-adapter' | ||
import { adaptFormating } from './highlight-adapter' | ||
import { adaptFormating } from './format-adapter' | ||
import { adaptGeoResponse } from './geo-reponse-adapter' | ||
@@ -25,5 +25,6 @@ | ||
const { _formatted: formattedHit, _matchesInfo, ...restOfHit } = hit | ||
return { | ||
...restOfHit, | ||
...adaptFormating(formattedHit, searchContext), | ||
...adaptFormating(hit, searchContext), | ||
...(primaryKey && { objectID: hit[primaryKey] }), | ||
@@ -30,0 +31,0 @@ } |
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
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
542082
109
7827
+ Addedmeilisearch@0.23.0(transitive)
- Removedmeilisearch@0.22.3(transitive)
Updatedmeilisearch@^0.23.0