@meilisearch/instant-meilisearch
Advanced tools
Comparing version 0.10.0 to 0.10.1-multi-index-search.0
@@ -93,153 +93,3 @@ 'use strict'; | ||
var removeUndefined = function (arr) { | ||
return arr.filter(function (x) { return x !== undefined; }); | ||
}; | ||
/** | ||
* @param {any} str | ||
* @returns {boolean} | ||
*/ | ||
/** | ||
* @param {string} filter | ||
* @returns {string} | ||
*/ | ||
function replaceColonByEqualSign(filter) { | ||
// will only change first occurence of `:` | ||
return filter.replace(/:(.*)/i, '="$1"'); | ||
} | ||
/** | ||
* @param {any[]} arr | ||
* @returns {string} | ||
*/ | ||
function stringifyArray(arr) { | ||
return arr.reduce(function (acc, curr) { | ||
return (acc += JSON.stringify(curr)); | ||
}, ''); | ||
} | ||
function isPureObject(data) { | ||
return typeof data === 'object' && !Array.isArray(data) && data !== null; | ||
} | ||
/** | ||
* apiKey callback definition | ||
* @callback apiKeyCallback | ||
* @returns {string} - The apiKey to use | ||
*/ | ||
/** | ||
* Validates host and apiKey parameters, throws if invalid | ||
* @param hostUrl | ||
* @param apiKey | ||
*/ | ||
function validateInstantMeiliSearchParams(hostUrl, apiKey) { | ||
// Validate host url | ||
if (typeof hostUrl !== 'string') { | ||
throw new TypeError('Provided hostUrl value (1st parameter) is not a string, expected string'); | ||
} | ||
// Validate api key | ||
if (typeof apiKey !== 'string' && typeof apiKey !== 'function') { | ||
throw new TypeError('Provided apiKey value (2nd parameter) is not a string or a function, expected string or function'); | ||
} | ||
} | ||
/** | ||
* @param {string} filter | ||
*/ | ||
var adaptFilterSyntax = function (filter) { | ||
var matches = filter.match(/([^=]*)="?([^\\"]*)"?$/); | ||
if (matches) { | ||
matches[0]; var filterName = matches[1], value = matches[2]; | ||
return [{ filterName: filterName, value: value }]; | ||
} | ||
return []; | ||
}; | ||
/** | ||
* @param {Filter} filters? | ||
* @returns {Array} | ||
*/ | ||
function extractFilters(filters) { | ||
if (typeof filters === 'string') { | ||
return adaptFilterSyntax(filters); | ||
} | ||
else if (Array.isArray(filters)) { | ||
return filters | ||
.map(function (nestedFilter) { | ||
if (Array.isArray(nestedFilter)) { | ||
return nestedFilter.map(function (filter) { return adaptFilterSyntax(filter); }); | ||
} | ||
return adaptFilterSyntax(nestedFilter); | ||
}) | ||
.flat(2); | ||
} | ||
return []; | ||
} | ||
/** | ||
* @param {Filter} filters? | ||
* @returns {FacetsCache} | ||
*/ | ||
function getFacetsFromFilter(filters) { | ||
var extractedFilters = extractFilters(filters); | ||
var cleanFilters = removeUndefined(extractedFilters); | ||
return cleanFilters.reduce(function (cache, parsedFilter) { | ||
var _a; | ||
var filterName = parsedFilter.filterName, value = parsedFilter.value; | ||
var prevFields = cache[filterName] || []; | ||
cache = __assign(__assign({}, cache), (_a = {}, _a[filterName] = __spreadArray(__spreadArray([], prevFields, true), [value], false), _a)); | ||
return cache; | ||
}, {}); | ||
} | ||
function getFacetsFromDefaultDistribution(facetDistribution) { | ||
return Object.keys(facetDistribution).reduce(function (cache, facet) { | ||
var _a; | ||
var facetValues = Object.keys(facetDistribution[facet]); | ||
return __assign(__assign({}, cache), (_a = {}, _a[facet] = facetValues, _a)); | ||
}, {}); | ||
} | ||
/** | ||
* @param {Filter} filters? | ||
* @returns {FacetsCache} | ||
*/ | ||
function extractFacets(searchContext, searchParams) { | ||
if (searchContext.keepZeroFacets) { | ||
return getFacetsFromDefaultDistribution(searchContext.defaultFacetDistribution); | ||
} | ||
else { | ||
return getFacetsFromFilter(searchParams === null || searchParams === void 0 ? void 0 : searchParams.filter); | ||
} | ||
} | ||
/** | ||
* Assign missing filters to facetDistribution. | ||
* All facets passed as filter should appear in the facetDistribution. | ||
* If not present, the facet is added with 0 as value. | ||
* | ||
* | ||
* @param {FacetsCache} cache? | ||
* @param {FacetDistribution} distribution? | ||
* @returns {FacetDistribution} | ||
*/ | ||
function addMissingFacets(cachedFacets, distribution) { | ||
distribution = distribution || {}; | ||
// If cachedFacets contains something | ||
if (cachedFacets && Object.keys(cachedFacets).length > 0) { | ||
// for all filters in cached filters | ||
for (var cachedFacet in cachedFacets) { | ||
// if facet does not exist on returned distribution, add an empty object | ||
if (!distribution[cachedFacet]) | ||
distribution[cachedFacet] = {}; | ||
// for all fields in every filter | ||
for (var _i = 0, _a = cachedFacets[cachedFacet]; _i < _a.length; _i++) { | ||
var cachedField = _a[_i]; | ||
// if the field is not present in the returned distribution | ||
// set it at 0 | ||
if (!Object.keys(distribution[cachedFacet]).includes(cachedField)) { | ||
// add 0 value | ||
distribution[cachedFacet][cachedField] = 0; | ||
} | ||
} | ||
} | ||
} | ||
return distribution; | ||
} | ||
/** | ||
* @param {ResponseCacher} cache | ||
@@ -257,7 +107,6 @@ */ | ||
return __awaiter(this, void 0, void 0, function () { | ||
var placeholderSearch, query, key, cachedResponse, cachedFacets, searchResponse; | ||
var key, cachedResponse, searchResponse; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
placeholderSearch = searchContext.placeholderSearch, query = searchContext.query; | ||
key = cache.formatKey([ | ||
@@ -272,18 +121,12 @@ searchParams, | ||
if (cachedResponse) | ||
return [2 /*return*/, cachedResponse]; | ||
cachedFacets = extractFacets(searchContext, searchParams); | ||
return [2 /*return*/, cachedResponse | ||
// Make search request | ||
]; | ||
return [4 /*yield*/, client | ||
.index(searchContext.indexUid) | ||
.search(searchContext.query, searchParams) | ||
// Add missing facets back into facetDistribution | ||
// Cache response | ||
]; | ||
case 1: | ||
searchResponse = _a.sent(); | ||
// Add missing facets back into facetDistribution | ||
searchResponse.facetDistribution = addMissingFacets(cachedFacets, searchResponse.facetDistribution); | ||
// query can be: empty string, undefined or null | ||
// all of them are falsy's | ||
if (!placeholderSearch && !query) { | ||
searchResponse.hits = []; | ||
} | ||
// Cache response | ||
@@ -445,2 +288,49 @@ cache.setEntry(key, searchResponse); | ||
/** | ||
* @param {any} str | ||
* @returns {boolean} | ||
*/ | ||
/** | ||
* @param {string} filter | ||
* @returns {string} | ||
*/ | ||
function replaceColonByEqualSign(filter) { | ||
// will only change first occurence of `:` | ||
return filter.replace(/:(.*)/i, '="$1"'); | ||
} | ||
/** | ||
* @param {any[]} arr | ||
* @returns {string} | ||
*/ | ||
function stringifyArray(arr) { | ||
return arr.reduce(function (acc, curr) { | ||
return (acc += JSON.stringify(curr)); | ||
}, ''); | ||
} | ||
function isPureObject(data) { | ||
return typeof data === 'object' && !Array.isArray(data) && data !== null; | ||
} | ||
/** | ||
* apiKey callback definition | ||
* @callback apiKeyCallback | ||
* @returns {string} - The apiKey to use | ||
*/ | ||
/** | ||
* Validates host and apiKey parameters, throws if invalid | ||
* @param hostUrl | ||
* @param apiKey | ||
*/ | ||
function validateInstantMeiliSearchParams(hostUrl, apiKey) { | ||
// Validate host url | ||
if (typeof hostUrl !== 'string') { | ||
throw new TypeError('Provided hostUrl value (1st parameter) is not a string, expected string'); | ||
} | ||
// Validate api key | ||
if (typeof apiKey !== 'string' && typeof apiKey !== 'function') { | ||
throw new TypeError('Provided apiKey value (2nd parameter) is not a string or a function, expected string or function'); | ||
} | ||
} | ||
/** | ||
* Transform InstantSearch filter to Meilisearch filter. | ||
@@ -525,4 +415,15 @@ * Change sign from `:` to `=` in nested filter object. | ||
function setScrollPagination(hitsPerPage, page, query, placeholderSearch) { | ||
if (!placeholderSearch && query === '') { | ||
function isPaginationRequired(filter, query, placeholderSearch) { | ||
// To disable pagination: | ||
// placeholderSearch must be disabled | ||
// The search query must be empty | ||
// There must be no filters | ||
if (!placeholderSearch && !query && (!filter || filter.length === 0)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
function setScrollPagination(pagination, paginationRequired) { | ||
var page = pagination.page, hitsPerPage = pagination.hitsPerPage; | ||
if (!paginationRequired) { | ||
return { | ||
@@ -538,4 +439,5 @@ limit: 0, | ||
} | ||
function setFinitePagination(hitsPerPage, page, query, placeholderSearch) { | ||
if (!placeholderSearch && query === '') { | ||
function setFinitePagination(pagination, paginationRequired) { | ||
var page = pagination.page, hitsPerPage = pagination.hitsPerPage; | ||
if (!paginationRequired) { | ||
return { | ||
@@ -563,3 +465,4 @@ hitsPerPage: 0, | ||
var meiliSearchParams = {}; | ||
var facets = searchContext.facets, attributesToSnippet = searchContext.attributesToSnippet, snippetEllipsisText = searchContext.snippetEllipsisText, attributesToRetrieve = searchContext.attributesToRetrieve, filters = searchContext.filters, numericFilters = searchContext.numericFilters, facetFilters = searchContext.facetFilters, attributesToHighlight = searchContext.attributesToHighlight, highlightPreTag = searchContext.highlightPreTag, highlightPostTag = searchContext.highlightPostTag, placeholderSearch = searchContext.placeholderSearch, query = searchContext.query, sort = searchContext.sort, pagination = searchContext.pagination, matchingStrategy = searchContext.matchingStrategy; | ||
var facets = searchContext.facets, attributesToSnippet = searchContext.attributesToSnippet, snippetEllipsisText = searchContext.snippetEllipsisText, attributesToRetrieve = searchContext.attributesToRetrieve, attributesToHighlight = searchContext.attributesToHighlight, highlightPreTag = searchContext.highlightPreTag, highlightPostTag = searchContext.highlightPostTag, placeholderSearch = searchContext.placeholderSearch, query = searchContext.query, sort = searchContext.sort, pagination = searchContext.pagination, matchingStrategy = searchContext.matchingStrategy, filters = searchContext.filters, numericFilters = searchContext.numericFilters, facetFilters = searchContext.facetFilters; | ||
var meilisearchFilters = adaptFilters(filters, numericFilters, facetFilters); | ||
return { | ||
@@ -570,5 +473,8 @@ getParams: function () { | ||
addFacets: function () { | ||
if (facets === null || facets === void 0 ? void 0 : facets.length) { | ||
if (Array.isArray(facets)) { | ||
meiliSearchParams.facets = facets; | ||
} | ||
else if (typeof facets === 'string') { | ||
meiliSearchParams.facets = [facets]; | ||
} | ||
}, | ||
@@ -592,5 +498,4 @@ addAttributesToCrop: function () { | ||
addFilters: function () { | ||
var filter = adaptFilters(filters, numericFilters, facetFilters); | ||
if (filter.length) { | ||
meiliSearchParams.filter = filter; | ||
if (meilisearchFilters.length) { | ||
meiliSearchParams.filter = meilisearchFilters; | ||
} | ||
@@ -618,4 +523,5 @@ }, | ||
addPagination: function () { | ||
var paginationRequired = isPaginationRequired(meilisearchFilters, query, placeholderSearch); | ||
if (pagination.finite) { | ||
var _a = setFinitePagination(pagination.hitsPerPage, pagination.page, query, placeholderSearch), hitsPerPage = _a.hitsPerPage, page = _a.page; | ||
var _a = setFinitePagination(pagination, paginationRequired), hitsPerPage = _a.hitsPerPage, page = _a.page; | ||
meiliSearchParams.hitsPerPage = hitsPerPage; | ||
@@ -625,3 +531,3 @@ meiliSearchParams.page = page; | ||
else { | ||
var _b = setScrollPagination(pagination.hitsPerPage, pagination.page, query, placeholderSearch), limit = _b.limit, offset = _b.offset; | ||
var _b = setScrollPagination(pagination, paginationRequired), limit = _b.limit, offset = _b.offset; | ||
meiliSearchParams.limit = limit; | ||
@@ -754,11 +660,13 @@ meiliSearchParams.offset = offset; | ||
function adaptGeoResponse(hits) { | ||
var _a; | ||
for (var i = 0; i < hits.length; i++) { | ||
var objectID = "".concat(i + Math.random() * 1000000); | ||
if (hits[i]._geo) { | ||
hits[i]._geoloc = { | ||
lat: hits[i]._geo.lat, | ||
lng: hits[i]._geo.lng | ||
}; | ||
hits[i].objectID = "".concat(i + Math.random() * 1000000); | ||
delete hits[i]._geo; | ||
hits[i]._geoloc = hits[i]._geo; | ||
hits[i].objectID = objectID; | ||
} | ||
if ((_a = hits[i]._formatted) === null || _a === void 0 ? void 0 : _a._geo) { | ||
hits[i]._formatted._geoloc = hits[i]._formatted._geo; | ||
hits[i]._formatted.objectID = objectID; | ||
} | ||
} | ||
@@ -833,2 +741,44 @@ return hits; | ||
function getFacetNames(facets) { | ||
if (!facets) | ||
return []; | ||
else if (typeof facets === 'string') | ||
return [facets]; | ||
return facets; | ||
} | ||
// Fills the missing facetValue in the current facet distribution if `keepZeroFacet` is true | ||
// using the initial facet distribution. Ex: | ||
// | ||
// Initial distribution: { genres: { horror: 10, comedy: 4 } } | ||
// Current distribution: { genres: { horror: 3 }} | ||
// Returned distribution: { genres: { horror: 3, comedy: 0 }} | ||
function fillMissingFacetValues(facets, initialFacetDistribution, facetDistribution) { | ||
var facetNames = getFacetNames(facets); | ||
var filledDistribution = {}; | ||
for (var _i = 0, facetNames_1 = facetNames; _i < facetNames_1.length; _i++) { | ||
var facet = facetNames_1[_i]; | ||
for (var facetValue in initialFacetDistribution[facet]) { | ||
if (!filledDistribution[facet]) { | ||
// initialize sub object | ||
filledDistribution[facet] = facetDistribution[facet] || {}; | ||
} | ||
if (!filledDistribution[facet][facetValue]) { | ||
filledDistribution[facet][facetValue] = 0; | ||
} | ||
else { | ||
filledDistribution[facet][facetValue] = | ||
facetDistribution[facet][facetValue]; | ||
} | ||
} | ||
} | ||
return filledDistribution; | ||
} | ||
function adaptFacetDistribution(keepZeroFacets, facets, initialFacetDistribution, facetDistribution) { | ||
if (keepZeroFacets) { | ||
facetDistribution = facetDistribution || {}; | ||
return fillMissingFacetValues(facets, initialFacetDistribution, facetDistribution); | ||
} | ||
return facetDistribution; | ||
} | ||
/** | ||
@@ -842,13 +792,13 @@ * Adapt search response from Meilisearch | ||
*/ | ||
function adaptSearchResponse(searchResponse, searchContext) { | ||
function adaptSearchResponse(searchResponse, searchContext, initialFacetDistribution) { | ||
var searchResponseOptionals = {}; | ||
var processingTimeMs = searchResponse.processingTimeMs, query = searchResponse.query, facets = searchResponse.facetDistribution; | ||
var processingTimeMs = searchResponse.processingTimeMs, query = searchResponse.query, responseFacetDistribution = searchResponse.facetDistribution; | ||
var keepZeroFacets = searchContext.keepZeroFacets, facets = searchContext.facets; | ||
var _a = adaptPaginationParameters(searchResponse, searchContext.pagination), hitsPerPage = _a.hitsPerPage, page = _a.page, nbPages = _a.nbPages; | ||
var hits = adaptHits(searchResponse, searchContext); | ||
var nbHits = adaptTotalHits(searchResponse); | ||
var facetDistribution = adaptFacetDistribution(keepZeroFacets, facets, initialFacetDistribution, responseFacetDistribution); | ||
// Create response object compliant with InstantSearch | ||
var adaptedSearchResponse = __assign({ index: searchContext.indexUid, hitsPerPage: hitsPerPage, page: page, facets: facets, nbPages: nbPages, nbHits: nbHits, processingTimeMS: processingTimeMs, query: query, hits: hits, params: '', exhaustiveNbHits: false }, searchResponseOptionals); | ||
return { | ||
results: [adaptedSearchResponse] | ||
}; | ||
var adaptedSearchResponse = __assign({ index: searchContext.indexUid, hitsPerPage: hitsPerPage, page: page, facets: facetDistribution, nbPages: nbPages, nbHits: nbHits, processingTimeMS: processingTimeMs, query: query, hits: hits, params: '', exhaustiveNbHits: false }, searchResponseOptionals); | ||
return adaptedSearchResponse; | ||
} | ||
@@ -877,3 +827,3 @@ | ||
*/ | ||
function createSearchContext(searchRequest, options, defaultFacetDistribution) { | ||
function createSearchContext(searchRequest, options) { | ||
// Split index name and possible sorting rules | ||
@@ -883,3 +833,3 @@ var _a = searchRequest.indexName.split(':'), indexUid = _a[0], sortByArray = _a.slice(1); | ||
var paginationState = createPaginationState(options.finitePagination, instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.hitsPerPage, instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.page); | ||
var searchContext = __assign(__assign(__assign({}, options), instantSearchParams), { sort: sortByArray.join(':') || '', indexUid: indexUid, pagination: paginationState, defaultFacetDistribution: defaultFacetDistribution || {}, placeholderSearch: options.placeholderSearch !== false, keepZeroFacets: !!options.keepZeroFacets }); | ||
var searchContext = __assign(__assign(__assign({}, options), instantSearchParams), { sort: sortByArray.join(':') || '', indexUid: indexUid, pagination: paginationState, placeholderSearch: options.placeholderSearch !== false, keepZeroFacets: !!options.keepZeroFacets }); | ||
return searchContext; | ||
@@ -919,3 +869,3 @@ } | ||
function cacheFirstFacetDistribution(searchResolver, searchContext) { | ||
function getIndexFacetDistribution(searchResolver, searchContext) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -942,4 +892,22 @@ var defaultSearchContext, meilisearchParams, searchResponse; | ||
} | ||
function initFacetDistribution(searchResolver, searchContext, initialFacetDistribution) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a, _b; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
if (!!initialFacetDistribution[searchContext.indexUid]) return [3 /*break*/, 2]; | ||
_a = initialFacetDistribution; | ||
_b = searchContext.indexUid; | ||
return [4 /*yield*/, getIndexFacetDistribution(searchResolver, searchContext)]; | ||
case 1: | ||
_a[_b] = _c.sent(); | ||
_c.label = 2; | ||
case 2: return [2 /*return*/, initialFacetDistribution]; | ||
} | ||
}); | ||
}); | ||
} | ||
var PACKAGE_VERSION = '0.10.0'; | ||
var PACKAGE_VERSION = '0.10.1-multi-index-search.0'; | ||
@@ -980,3 +948,3 @@ var constructClientAgents = function (clientAgents) { | ||
var searchResolver = SearchResolver(meilisearchClient, searchCache); | ||
var defaultFacetDistribution; | ||
var initialFacetDistribution = {}; | ||
return { | ||
@@ -990,28 +958,40 @@ clearCache: function () { return searchCache.clearCache(); }, | ||
return __awaiter(this, void 0, void 0, function () { | ||
var searchRequest, searchContext, adaptedSearchRequest, searchResponse, adaptedSearchResponse, e_1; | ||
var searchResponses, requests, _i, requests_1, searchRequest, searchContext, adaptedSearchRequest, searchResponse, adaptedSearchResponse, e_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 4, , 5]); | ||
searchRequest = instantSearchRequests[0]; | ||
searchContext = createSearchContext(searchRequest, instantMeiliSearchOptions, defaultFacetDistribution); | ||
_a.trys.push([0, 6, , 7]); | ||
searchResponses = { | ||
results: [] | ||
}; | ||
requests = instantSearchRequests; | ||
_i = 0, requests_1 = requests; | ||
_a.label = 1; | ||
case 1: | ||
if (!(_i < requests_1.length)) return [3 /*break*/, 5]; | ||
searchRequest = requests_1[_i]; | ||
searchContext = createSearchContext(searchRequest, instantMeiliSearchOptions); | ||
adaptedSearchRequest = adaptSearchParams(searchContext); | ||
if (!(defaultFacetDistribution === undefined)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, cacheFirstFacetDistribution(searchResolver, searchContext)]; | ||
case 1: | ||
defaultFacetDistribution = _a.sent(); | ||
searchContext.defaultFacetDistribution = defaultFacetDistribution; | ||
_a.label = 2; | ||
case 2: return [4 /*yield*/, searchResolver.searchResponse(searchContext, adaptedSearchRequest) | ||
// Adapt the Meilisearch responsne to a compliant instantsearch.js response | ||
]; | ||
return [4 /*yield*/, initFacetDistribution(searchResolver, searchContext, initialFacetDistribution) | ||
// Search response from Meilisearch | ||
]; | ||
case 2: | ||
initialFacetDistribution = _a.sent(); | ||
return [4 /*yield*/, searchResolver.searchResponse(searchContext, adaptedSearchRequest) | ||
// Adapt the Meilisearch response to a compliant instantsearch.js response | ||
]; | ||
case 3: | ||
searchResponse = _a.sent(); | ||
adaptedSearchResponse = adaptSearchResponse(searchResponse, searchContext); | ||
return [2 /*return*/, adaptedSearchResponse]; | ||
adaptedSearchResponse = adaptSearchResponse(searchResponse, searchContext, initialFacetDistribution[searchRequest.indexName]); | ||
searchResponses.results.push(adaptedSearchResponse); | ||
_a.label = 4; | ||
case 4: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 5: return [2 /*return*/, searchResponses]; | ||
case 6: | ||
e_1 = _a.sent(); | ||
console.error(e_1); | ||
throw new Error(e_1); | ||
case 5: return [2 /*return*/]; | ||
case 7: return [2 /*return*/]; | ||
} | ||
@@ -1018,0 +998,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("meilisearch"),e=function(){return e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},e.apply(this,arguments)};function r(t,e,r,n){return new(r||(r=Promise))((function(i,a){function o(t){try{u(n.next(t))}catch(t){a(t)}}function s(t){try{u(n.throw(t))}catch(t){a(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,s)}u((n=n.apply(t,e||[])).next())}))}function n(t,e){var r,n,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(o=0)),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,r){if(r||2===arguments.length)for(var n,i=0,a=e.length;i<a;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}function a(t){return t.replace(/:(.*)/i,'="$1"')}var o=function(t){var e=t.match(/([^=]*)="?([^\\"]*)"?$/);return e?(e[0],[{filterName:e[1],value:e[2]}]):[]};function s(t){var r=function(t){return"string"==typeof t?o(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return o(t)})):o(t)})).flat(2):[]}(t);return r.filter((function(t){return void 0!==t})).reduce((function(t,r){var n,a=r.filterName,o=r.value,s=t[a]||[];return t=e(e({},t),((n={})[a]=i(i([],s,!0),[o],!1),n))}),{})}function u(t,r){return t.keepZeroFacets?(n=t.defaultFacetDistribution,Object.keys(n).reduce((function(t,r){var i,a=Object.keys(n[r]);return e(e({},t),((i={})[r]=a,i))}),{})):s(null==r?void 0:r.filter);var n}function c(t,e){return{searchResponse:function(i,a){return r(this,void 0,void 0,(function(){var r,o,s,c,l,f;return n(this,(function(n){switch(n.label){case 0:return r=i.placeholderSearch,o=i.query,s=e.formatKey([a,i.indexUid,i.query,i.pagination]),(c=e.getEntry(s))?[2,c]:(l=u(i,a),[4,t.index(i.indexUid).search(i.query,a)]);case 1:return(f=n.sent()).facetDistribution=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 a=i[n];Object.keys(e[r]).includes(a)||(e[r][a]=0)}}return e}(l,f.facetDistribution),r||o||(f.hits=[]),e.setEntry(s,f),[2,f]}}))}))}}}function l(t){return 180*t/Math.PI}function f(t){return t*Math.PI/180}function h(t){if(t){var e,r,n=t.insideBoundingBox,i=t.aroundLatLng,a=t.aroundRadius,o=t.minimumAroundRadius;if(i&&(e=i),null==a&&null==o||(r=null!=a?a:o),n&&"string"==typeof n){var s=n.split(","),u=s[0],c=s[1],h=s[2],d=s[3],g=[parseFloat(u),parseFloat(c),parseFloat(h),parseFloat(d)],p=g[0],v=g[1],y=g[2],P=g[3];r=function(t,e,r,n){var i=t*Math.PI/180,a=r*Math.PI/180,o=(r-t)*Math.PI/180,s=(n-e)*Math.PI/180,u=Math.sin(o/2)*Math.sin(o/2)+Math.cos(i)*Math.cos(a)*Math.sin(s/2)*Math.sin(s/2);return 2*Math.atan2(Math.sqrt(u),Math.sqrt(1-u))*6371e3}(p,v,y,P)/2,e=function(t,e,r,n){t=f(t),e=f(e);var i=Math.cos(t)*Math.cos(e),a=Math.cos(t)*Math.sin(e),o=Math.sin(t);r=f(r),n=f(n);var s=i+Math.cos(r)*Math.cos(n),u=a+Math.cos(r)*Math.sin(n),c=o+Math.sin(r),h=Math.sqrt(s*s+u*u),d=Math.atan2(u,s),g=Math.atan2(c,h);return e<n||e>n&&e>Math.PI&&n<-Math.PI?(g+=Math.PI,d+=Math.PI):(g=l(g),d=l(d)),Math.abs(s)<Math.pow(10,-9)&&Math.abs(u)<Math.pow(10,-9)&&Math.abs(c)<Math.pow(10,-9)&&(g=0,d=0),"".concat(g,",").concat(d)}(p,v,y,P)}if(null!=e&&null!=r){var b=e.split(","),m=b[0],M=b[1];return m=Number.parseFloat(m).toFixed(5),M=Number.parseFloat(M).toFixed(5),{filter:"_geoRadius(".concat(m,", ").concat(M,", ").concat(r,")")}}}}function d(t){return"string"==typeof t?a(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return a(t)})).filter((function(t){return t})):a(t)})).filter((function(t){return t})):[]}function g(t){return""===t?[]:"string"==typeof t?[t]:t}function p(t,e,r){return function(t,e,r){var n=r.trim(),a=g(t),o=g(e);return i(i(i([],a,!0),o,!0),[n],!1).filter((function(t){return Array.isArray(t)?t.length:t}))}(d(r||[]),d(e||[]),t||"")}function v(t){var e={},r=t.facets,n=t.attributesToSnippet,i=t.snippetEllipsisText,a=t.attributesToRetrieve,o=t.filters,s=t.numericFilters,u=t.facetFilters,c=t.attributesToHighlight,l=t.highlightPreTag,f=t.highlightPostTag,d=t.placeholderSearch,g=t.query,v=t.sort,y=t.pagination,P=t.matchingStrategy;return{getParams:function(){return e},addFacets:function(){(null==r?void 0:r.length)&&(e.facets=r)},addAttributesToCrop:function(){n&&(e.attributesToCrop=n)},addCropMarker:function(){null!=i&&(e.cropMarker=i)},addAttributesToRetrieve:function(){a&&(e.attributesToRetrieve=a)},addFilters:function(){var t=p(o,s,u);t.length&&(e.filter=t)},addAttributesToHighlight:function(){e.attributesToHighlight=c||["*"]},addPreTag:function(){e.highlightPreTag=l||"__ais-highlight__"},addPostTag:function(){e.highlightPostTag=f||"__/ais-highlight__"},addPagination:function(){if(y.finite){var t=function(t,e,r,n){return n||""!==r?{hitsPerPage:t,page:e+1}:{hitsPerPage:0,page:e+1}}(y.hitsPerPage,y.page,g,d),r=t.hitsPerPage,n=t.page;e.hitsPerPage=r,e.page=n}else{var i=function(t,e,r,n){return n||""!==r?{limit:t+1,offset:e*t}:{limit:0,offset:0}}(y.hitsPerPage,y.page,g,d),a=i.limit,o=i.offset;e.limit=a,e.offset=o}},addSort:function(){(null==v?void 0:v.length)&&(e.sort=[v])},addGeoSearchRules:function(){var r=function(t){var e={},r=t.aroundLatLng,n=t.aroundLatLngViaIP,i=t.aroundRadius,a=t.aroundPrecision,o=t.minimumAroundRadius,s=t.insideBoundingBox,u=t.insidePolygon;return r&&(e.aroundLatLng=r),n&&console.warn("instant-meilisearch: `aroundLatLngViaIP` is not supported."),i&&(e.aroundRadius=i),a&&console.warn("instant-meilisearch: `aroundPrecision` is not supported.\n See this discussion to track its implementation https://github.com/meilisearch/product/discussions/264"),o&&(e.minimumAroundRadius=o),s&&(e.insideBoundingBox=s),u&&console.warn("instant-meilisearch: `insidePolygon` is not implented in instant-meilisearch."),e}(t),n=h(r);(null==n?void 0:n.filter)&&(e.filter?e.filter.unshift(n.filter):e.filter=[n.filter])},addMatchingStrategy:function(){P&&(e.matchingStrategy=P)}}}function y(t){return"string"==typeof t?t:void 0===t?JSON.stringify(null):JSON.stringify(t)}function P(t){return Array.isArray(t)?t.map((function(t){return P(t)})):"object"!=typeof(e=t)||Array.isArray(e)||null===e?{value:y(t)}:Object.keys(t).reduce((function(e,r){return e[r]=P(t[r]),e}),{});var e}function b(t,e){var r=e.primaryKey,n=t.hits,i=e.pagination,a=i.finite,o=i.hitsPerPage;!a&&n.length>o&&n.splice(n.length-1,1);var s=n.map((function(t){if(Object.keys(t).length>0){var e=t._formatted;t._matchesPosition;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","_matchesPosition"]),i=Object.assign(n,function(t){if(!t)return{};var e=P(t);return{_highlightResult:e,_snippetResult:e}}(e));return r&&(i.objectID=t[r]),i}return t}));return s=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}(s),s}function m(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(r){return e[t]}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,r){e[t]=JSON.stringify(r)},clearCache:function(){e={}}}}function M(t,i){return r(this,void 0,void 0,(function(){var r,a;return n(this,(function(n){switch(n.label){case 0:return r=e(e({},i),{placeholderSearch:!0,query:""}),(a=v(r)).addFacets(),a.addPagination(),[4,t.searchResponse(r,a.getParams())];case 1:return[2,n.sent().facetDistribution||{}]}}))}))}var w;exports.MatchingStrategies=void 0,(w=exports.MatchingStrategies||(exports.MatchingStrategies={})).ALL="all",w.LAST="last",exports.instantMeiliSearch=function(i,a,o){void 0===a&&(a=""),void 0===o&&(o={}),function(t,e){if("string"!=typeof t)throw new TypeError("Provided hostUrl value (1st parameter) is not a string, expected string");if("string"!=typeof e&&"function"!=typeof e)throw new TypeError("Provided apiKey value (2nd parameter) is not a string or a function, expected string or function")}(i,a),a=function(t){if("function"==typeof t){var e=t();if("string"!=typeof e)throw new TypeError("Provided apiKey function (2nd parameter) did not return a string, expected string");return e}return t}(a);var s,u=function(t){void 0===t&&(t=[]);var e="Meilisearch instant-meilisearch (v".concat("0.10.0",")");return t.concat(e)}(o.clientAgents),l=new t.MeiliSearch({host:i,apiKey:a,clientAgents:u}),f=m(),h=c(l,f);return{clearCache:function(){return f.clearCache()},search:function(t){return r(this,void 0,void 0,(function(){var r,i,a,u,c,l;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,4,,5]),r=t[0],i=function(t,r,n){var i,a,o,s=t.indexName.split(":"),u=s[0],c=s.slice(1),l=t.params,f=(i=r.finitePagination,a=null==l?void 0:l.hitsPerPage,o=null==l?void 0:l.page,{hitsPerPage:void 0===a?20:a,page:o||0,finite:!!i});return e(e(e({},r),l),{sort:c.join(":")||"",indexUid:u,pagination:f,defaultFacetDistribution:n||{},placeholderSearch:!1!==r.placeholderSearch,keepZeroFacets:!!r.keepZeroFacets})}(r,o,s),a=function(t){var e=v(t);return e.addFacets(),e.addAttributesToHighlight(),e.addPreTag(),e.addPostTag(),e.addAttributesToRetrieve(),e.addAttributesToCrop(),e.addCropMarker(),e.addPagination(),e.addFilters(),e.addSort(),e.addGeoSearchRules(),e.addMatchingStrategy(),e.getParams()}(i),void 0!==s?[3,2]:[4,M(h,i)];case 1:s=n.sent(),i.defaultFacetDistribution=s,n.label=2;case 2:return[4,h.searchResponse(i,a)];case 3:return u=n.sent(),c=function(t,r){var n=t.processingTimeMs,i=t.query,a=t.facetDistribution,o=function(t,e){var r=e.hitsPerPage,n=e.page,i=function(t,e){if(null!=t.totalPages)return t.totalPages;if(0===e)return 0;var r=t.limit,n=void 0===r?20:r,i=t.offset;return(void 0===i?0:i)/e+1+(t.hits.length>=n?1:0)}(t,r);return{page:n,nbPages:i,hitsPerPage:r}}(t,r.pagination),s=o.hitsPerPage,u=o.page,c=o.nbPages,l=b(t,r),f=function(t){var e=t.hitsPerPage,r=void 0===e?0:e,n=t.totalPages,i=void 0===n?0:n,a=t.estimatedTotalHits,o=t.totalHits;return null!=a?a:null!=o?o:r*i}(t);return{results:[e({index:r.indexUid,hitsPerPage:s,page:u,facets:a,nbPages:c,nbHits:f,processingTimeMS:n,query:i,hits:l,params:"",exhaustiveNbHits:!1},{})]}}(u,i),[2,c];case 4:throw l=n.sent(),console.error(l),new Error(l);case 5: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()]}}))}))}}}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("meilisearch"),e=function(){return e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},e.apply(this,arguments)};function r(t,e,r,n){return new(r||(r=Promise))((function(i,a){function o(t){try{u(n.next(t))}catch(t){a(t)}}function s(t){try{u(n.throw(t))}catch(t){a(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,s)}u((n=n.apply(t,e||[])).next())}))}function n(t,e){var r,n,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(o=0)),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,r){if(r||2===arguments.length)for(var n,i=0,a=e.length;i<a;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}function a(t){return 180*t/Math.PI}function o(t){return t*Math.PI/180}function s(t){if(t){var e,r,n=t.insideBoundingBox,i=t.aroundLatLng,s=t.aroundRadius,u=t.minimumAroundRadius;if(i&&(e=i),null==s&&null==u||(r=null!=s?s:u),n&&"string"==typeof n){var c=n.split(","),l=c[0],f=c[1],h=c[2],d=c[3],g=[parseFloat(l),parseFloat(f),parseFloat(h),parseFloat(d)],p=g[0],v=g[1],y=g[2],P=g[3];r=function(t,e,r,n){var i=t*Math.PI/180,a=r*Math.PI/180,o=(r-t)*Math.PI/180,s=(n-e)*Math.PI/180,u=Math.sin(o/2)*Math.sin(o/2)+Math.cos(i)*Math.cos(a)*Math.sin(s/2)*Math.sin(s/2);return 2*Math.atan2(Math.sqrt(u),Math.sqrt(1-u))*6371e3}(p,v,y,P)/2,e=function(t,e,r,n){t=o(t),e=o(e);var i=Math.cos(t)*Math.cos(e),s=Math.cos(t)*Math.sin(e),u=Math.sin(t);r=o(r),n=o(n);var c=i+Math.cos(r)*Math.cos(n),l=s+Math.cos(r)*Math.sin(n),f=u+Math.sin(r),h=Math.sqrt(c*c+l*l),d=Math.atan2(l,c),g=Math.atan2(f,h);return e<n||e>n&&e>Math.PI&&n<-Math.PI?(g+=Math.PI,d+=Math.PI):(g=a(g),d=a(d)),Math.abs(c)<Math.pow(10,-9)&&Math.abs(l)<Math.pow(10,-9)&&Math.abs(f)<Math.pow(10,-9)&&(g=0,d=0),"".concat(g,",").concat(d)}(p,v,y,P)}if(null!=e&&null!=r){var m=e.split(","),b=m[0],M=m[1];return b=Number.parseFloat(b).toFixed(5),M=Number.parseFloat(M).toFixed(5),{filter:"_geoRadius(".concat(b,", ").concat(M,", ").concat(r,")")}}}}function u(t){return t.replace(/:(.*)/i,'="$1"')}function c(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)})).filter((function(t){return t})):u(t)})).filter((function(t){return t})):[]}function l(t){return""===t?[]:"string"==typeof t?[t]:t}function f(t,e,r){return function(t,e,r){var n=r.trim(),a=l(t),o=l(e);return i(i(i([],a,!0),o,!0),[n],!1).filter((function(t){return Array.isArray(t)?t.length:t}))}(c(r||[]),c(e||[]),t||"")}function h(t){var e={},r=t.facets,n=t.attributesToSnippet,i=t.snippetEllipsisText,a=t.attributesToRetrieve,o=t.attributesToHighlight,u=t.highlightPreTag,c=t.highlightPostTag,l=t.placeholderSearch,h=t.query,d=t.sort,g=t.pagination,p=t.matchingStrategy,v=f(t.filters,t.numericFilters,t.facetFilters);return{getParams:function(){return e},addFacets:function(){Array.isArray(r)?e.facets=r:"string"==typeof r&&(e.facets=[r])},addAttributesToCrop:function(){n&&(e.attributesToCrop=n)},addCropMarker:function(){null!=i&&(e.cropMarker=i)},addAttributesToRetrieve:function(){a&&(e.attributesToRetrieve=a)},addFilters:function(){v.length&&(e.filter=v)},addAttributesToHighlight:function(){e.attributesToHighlight=o||["*"]},addPreTag:function(){e.highlightPreTag=u||"__ais-highlight__"},addPostTag:function(){e.highlightPostTag=c||"__/ais-highlight__"},addPagination:function(){var t=function(t,e,r){return!!(r||e||t&&0!==t.length)}(v,h,l);if(g.finite){var r=function(t,e){var r=t.page,n=t.hitsPerPage;return e?{hitsPerPage:n,page:r+1}:{hitsPerPage:0,page:r+1}}(g,t),n=r.hitsPerPage,i=r.page;e.hitsPerPage=n,e.page=i}else{var a=function(t,e){var r=t.page,n=t.hitsPerPage;return e?{limit:n+1,offset:r*n}:{limit:0,offset:0}}(g,t),o=a.limit,s=a.offset;e.limit=o,e.offset=s}},addSort:function(){(null==d?void 0:d.length)&&(e.sort=[d])},addGeoSearchRules:function(){var r=function(t){var e={},r=t.aroundLatLng,n=t.aroundLatLngViaIP,i=t.aroundRadius,a=t.aroundPrecision,o=t.minimumAroundRadius,s=t.insideBoundingBox,u=t.insidePolygon;return r&&(e.aroundLatLng=r),n&&console.warn("instant-meilisearch: `aroundLatLngViaIP` is not supported."),i&&(e.aroundRadius=i),a&&console.warn("instant-meilisearch: `aroundPrecision` is not supported.\n See this discussion to track its implementation https://github.com/meilisearch/product/discussions/264"),o&&(e.minimumAroundRadius=o),s&&(e.insideBoundingBox=s),u&&console.warn("instant-meilisearch: `insidePolygon` is not implented in instant-meilisearch."),e}(t),n=s(r);(null==n?void 0:n.filter)&&(e.filter?e.filter.unshift(n.filter):e.filter=[n.filter])},addMatchingStrategy:function(){p&&(e.matchingStrategy=p)}}}function d(t){return"string"==typeof t?t:void 0===t?JSON.stringify(null):JSON.stringify(t)}function g(t){return Array.isArray(t)?t.map((function(t){return g(t)})):"object"!=typeof(e=t)||Array.isArray(e)||null===e?{value:d(t)}:Object.keys(t).reduce((function(e,r){return e[r]=g(t[r]),e}),{});var e}function p(t,e){var r=e.primaryKey,n=t.hits,i=e.pagination,a=i.finite,o=i.hitsPerPage;!a&&n.length>o&&n.splice(n.length-1,1);var s=n.map((function(t){if(Object.keys(t).length>0){var e=t._formatted;t._matchesPosition;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","_matchesPosition"]),i=Object.assign(n,function(t){if(!t)return{};var e=g(t);return{_highlightResult:e,_snippetResult:e}}(e));return r&&(i.objectID=t[r]),i}return t}));return s=function(t){for(var e,r=0;r<t.length;r++){var n="".concat(r+1e6*Math.random());t[r]._geo&&(t[r]._geoloc=t[r]._geo,t[r].objectID=n),(null===(e=t[r]._formatted)||void 0===e?void 0:e._geo)&&(t[r]._formatted._geoloc=t[r]._formatted._geo,t[r]._formatted.objectID=n)}return t}(s),s}function v(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)},clearCache:function(){e={}}}}function y(t,i){return r(this,void 0,void 0,(function(){var r,a;return n(this,(function(n){switch(n.label){case 0:return r=e(e({},i),{placeholderSearch:!0,query:""}),(a=h(r)).addFacets(),a.addPagination(),[4,t.searchResponse(r,a.getParams())];case 1:return[2,n.sent().facetDistribution||{}]}}))}))}function P(t,e,i){return r(this,void 0,void 0,(function(){var r,a;return n(this,(function(n){switch(n.label){case 0:return i[e.indexUid]?[3,2]:(r=i,a=e.indexUid,[4,y(t,e)]);case 1:r[a]=n.sent(),n.label=2;case 2:return[2,i]}}))}))}var m;exports.MatchingStrategies=void 0,(m=exports.MatchingStrategies||(exports.MatchingStrategies={})).ALL="all",m.LAST="last",exports.instantMeiliSearch=function(i,a,o){void 0===a&&(a=""),void 0===o&&(o={}),function(t,e){if("string"!=typeof t)throw new TypeError("Provided hostUrl value (1st parameter) is not a string, expected string");if("string"!=typeof e&&"function"!=typeof e)throw new TypeError("Provided apiKey value (2nd parameter) is not a string or a function, expected string or function")}(i,a),a=function(t){if("function"==typeof t){var e=t();if("string"!=typeof e)throw new TypeError("Provided apiKey function (2nd parameter) did not return a string, expected string");return e}return t}(a);var s,u,c=function(t){void 0===t&&(t=[]);var e="Meilisearch instant-meilisearch (v".concat("0.10.1-multi-index-search.0",")");return t.concat(e)}(o.clientAgents),l=new t.MeiliSearch({host:i,apiKey:a,clientAgents:c}),f=v(),d=(s=l,u=f,{searchResponse:function(t,e){return r(this,void 0,void 0,(function(){var r,i,a;return n(this,(function(n){switch(n.label){case 0:return r=u.formatKey([e,t.indexUid,t.query,t.pagination]),(i=u.getEntry(r))?[2,i]:[4,s.index(t.indexUid).search(t.query,e)];case 1:return a=n.sent(),u.setEntry(r,a),[2,a]}}))}))}}),g={};return{clearCache:function(){return f.clearCache()},search:function(t){return r(this,void 0,void 0,(function(){var r,i,a,s,u,c,l,f,v;return n(this,(function(n){switch(n.label){case 0:n.trys.push([0,6,,7]),r={results:[]},i=0,a=t,n.label=1;case 1:return i<a.length?(s=a[i],u=function(t,r){var n,i,a,o=t.indexName.split(":"),s=o[0],u=o.slice(1),c=t.params,l=(n=r.finitePagination,i=null==c?void 0:c.hitsPerPage,a=null==c?void 0:c.page,{hitsPerPage:void 0===i?20:i,page:a||0,finite:!!n});return e(e(e({},r),c),{sort:u.join(":")||"",indexUid:s,pagination:l,placeholderSearch:!1!==r.placeholderSearch,keepZeroFacets:!!r.keepZeroFacets})}(s,o),c=function(t){var e=h(t);return e.addFacets(),e.addAttributesToHighlight(),e.addPreTag(),e.addPostTag(),e.addAttributesToRetrieve(),e.addAttributesToCrop(),e.addCropMarker(),e.addPagination(),e.addFilters(),e.addSort(),e.addGeoSearchRules(),e.addMatchingStrategy(),e.getParams()}(u),[4,P(d,u,g)]):[3,5];case 2:return g=n.sent(),[4,d.searchResponse(u,c)];case 3:l=n.sent(),f=function(t,r,n){var i=t.processingTimeMs,a=t.query,o=t.facetDistribution,s=r.keepZeroFacets,u=r.facets,c=function(t,e){var r=e.hitsPerPage,n=e.page,i=function(t,e){if(null!=t.totalPages)return t.totalPages;if(0===e)return 0;var r=t.limit,n=void 0===r?20:r,i=t.offset;return(void 0===i?0:i)/e+1+(t.hits.length>=n?1:0)}(t,r);return{page:n,nbPages:i,hitsPerPage:r}}(t,r.pagination),l=c.hitsPerPage,f=c.page,h=c.nbPages,d=p(t,r),g=function(t){var e=t.hitsPerPage,r=void 0===e?0:e,n=t.totalPages,i=void 0===n?0:n,a=t.estimatedTotalHits,o=t.totalHits;return null!=a?a:null!=o?o:r*i}(t),v=function(t,e,r,n){return t?function(t,e,r){for(var n=function(t){return t?"string"==typeof t?[t]:t:[]}(t),i={},a=0,o=n;a<o.length;a++){var s=o[a];for(var u in e[s])i[s]||(i[s]=r[s]||{}),i[s][u]?i[s][u]=r[s][u]:i[s][u]=0}return i}(e,r,n=n||{}):n}(s,u,n,o);return e({index:r.indexUid,hitsPerPage:l,page:f,facets:v,nbPages:h,nbHits:g,processingTimeMS:i,query:a,hits:d,params:"",exhaustiveNbHits:!1},{})}(l,u,g[s.indexName]),r.results.push(f),n.label=4;case 4:return i++,[3,1];case 5:return[2,r];case 6:throw v=n.sent(),console.error(v),new Error(v);case 7: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()]}}))}))}}}; | ||
//# sourceMappingURL=instant-meilisearch.cjs.min.js.map |
@@ -89,153 +89,3 @@ import { MeiliSearch } from 'meilisearch'; | ||
var removeUndefined = function (arr) { | ||
return arr.filter(function (x) { return x !== undefined; }); | ||
}; | ||
/** | ||
* @param {any} str | ||
* @returns {boolean} | ||
*/ | ||
/** | ||
* @param {string} filter | ||
* @returns {string} | ||
*/ | ||
function replaceColonByEqualSign(filter) { | ||
// will only change first occurence of `:` | ||
return filter.replace(/:(.*)/i, '="$1"'); | ||
} | ||
/** | ||
* @param {any[]} arr | ||
* @returns {string} | ||
*/ | ||
function stringifyArray(arr) { | ||
return arr.reduce(function (acc, curr) { | ||
return (acc += JSON.stringify(curr)); | ||
}, ''); | ||
} | ||
function isPureObject(data) { | ||
return typeof data === 'object' && !Array.isArray(data) && data !== null; | ||
} | ||
/** | ||
* apiKey callback definition | ||
* @callback apiKeyCallback | ||
* @returns {string} - The apiKey to use | ||
*/ | ||
/** | ||
* Validates host and apiKey parameters, throws if invalid | ||
* @param hostUrl | ||
* @param apiKey | ||
*/ | ||
function validateInstantMeiliSearchParams(hostUrl, apiKey) { | ||
// Validate host url | ||
if (typeof hostUrl !== 'string') { | ||
throw new TypeError('Provided hostUrl value (1st parameter) is not a string, expected string'); | ||
} | ||
// Validate api key | ||
if (typeof apiKey !== 'string' && typeof apiKey !== 'function') { | ||
throw new TypeError('Provided apiKey value (2nd parameter) is not a string or a function, expected string or function'); | ||
} | ||
} | ||
/** | ||
* @param {string} filter | ||
*/ | ||
var adaptFilterSyntax = function (filter) { | ||
var matches = filter.match(/([^=]*)="?([^\\"]*)"?$/); | ||
if (matches) { | ||
matches[0]; var filterName = matches[1], value = matches[2]; | ||
return [{ filterName: filterName, value: value }]; | ||
} | ||
return []; | ||
}; | ||
/** | ||
* @param {Filter} filters? | ||
* @returns {Array} | ||
*/ | ||
function extractFilters(filters) { | ||
if (typeof filters === 'string') { | ||
return adaptFilterSyntax(filters); | ||
} | ||
else if (Array.isArray(filters)) { | ||
return filters | ||
.map(function (nestedFilter) { | ||
if (Array.isArray(nestedFilter)) { | ||
return nestedFilter.map(function (filter) { return adaptFilterSyntax(filter); }); | ||
} | ||
return adaptFilterSyntax(nestedFilter); | ||
}) | ||
.flat(2); | ||
} | ||
return []; | ||
} | ||
/** | ||
* @param {Filter} filters? | ||
* @returns {FacetsCache} | ||
*/ | ||
function getFacetsFromFilter(filters) { | ||
var extractedFilters = extractFilters(filters); | ||
var cleanFilters = removeUndefined(extractedFilters); | ||
return cleanFilters.reduce(function (cache, parsedFilter) { | ||
var _a; | ||
var filterName = parsedFilter.filterName, value = parsedFilter.value; | ||
var prevFields = cache[filterName] || []; | ||
cache = __assign(__assign({}, cache), (_a = {}, _a[filterName] = __spreadArray(__spreadArray([], prevFields, true), [value], false), _a)); | ||
return cache; | ||
}, {}); | ||
} | ||
function getFacetsFromDefaultDistribution(facetDistribution) { | ||
return Object.keys(facetDistribution).reduce(function (cache, facet) { | ||
var _a; | ||
var facetValues = Object.keys(facetDistribution[facet]); | ||
return __assign(__assign({}, cache), (_a = {}, _a[facet] = facetValues, _a)); | ||
}, {}); | ||
} | ||
/** | ||
* @param {Filter} filters? | ||
* @returns {FacetsCache} | ||
*/ | ||
function extractFacets(searchContext, searchParams) { | ||
if (searchContext.keepZeroFacets) { | ||
return getFacetsFromDefaultDistribution(searchContext.defaultFacetDistribution); | ||
} | ||
else { | ||
return getFacetsFromFilter(searchParams === null || searchParams === void 0 ? void 0 : searchParams.filter); | ||
} | ||
} | ||
/** | ||
* Assign missing filters to facetDistribution. | ||
* All facets passed as filter should appear in the facetDistribution. | ||
* If not present, the facet is added with 0 as value. | ||
* | ||
* | ||
* @param {FacetsCache} cache? | ||
* @param {FacetDistribution} distribution? | ||
* @returns {FacetDistribution} | ||
*/ | ||
function addMissingFacets(cachedFacets, distribution) { | ||
distribution = distribution || {}; | ||
// If cachedFacets contains something | ||
if (cachedFacets && Object.keys(cachedFacets).length > 0) { | ||
// for all filters in cached filters | ||
for (var cachedFacet in cachedFacets) { | ||
// if facet does not exist on returned distribution, add an empty object | ||
if (!distribution[cachedFacet]) | ||
distribution[cachedFacet] = {}; | ||
// for all fields in every filter | ||
for (var _i = 0, _a = cachedFacets[cachedFacet]; _i < _a.length; _i++) { | ||
var cachedField = _a[_i]; | ||
// if the field is not present in the returned distribution | ||
// set it at 0 | ||
if (!Object.keys(distribution[cachedFacet]).includes(cachedField)) { | ||
// add 0 value | ||
distribution[cachedFacet][cachedField] = 0; | ||
} | ||
} | ||
} | ||
} | ||
return distribution; | ||
} | ||
/** | ||
* @param {ResponseCacher} cache | ||
@@ -253,7 +103,6 @@ */ | ||
return __awaiter(this, void 0, void 0, function () { | ||
var placeholderSearch, query, key, cachedResponse, cachedFacets, searchResponse; | ||
var key, cachedResponse, searchResponse; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
placeholderSearch = searchContext.placeholderSearch, query = searchContext.query; | ||
key = cache.formatKey([ | ||
@@ -268,18 +117,12 @@ searchParams, | ||
if (cachedResponse) | ||
return [2 /*return*/, cachedResponse]; | ||
cachedFacets = extractFacets(searchContext, searchParams); | ||
return [2 /*return*/, cachedResponse | ||
// Make search request | ||
]; | ||
return [4 /*yield*/, client | ||
.index(searchContext.indexUid) | ||
.search(searchContext.query, searchParams) | ||
// Add missing facets back into facetDistribution | ||
// Cache response | ||
]; | ||
case 1: | ||
searchResponse = _a.sent(); | ||
// Add missing facets back into facetDistribution | ||
searchResponse.facetDistribution = addMissingFacets(cachedFacets, searchResponse.facetDistribution); | ||
// query can be: empty string, undefined or null | ||
// all of them are falsy's | ||
if (!placeholderSearch && !query) { | ||
searchResponse.hits = []; | ||
} | ||
// Cache response | ||
@@ -441,2 +284,49 @@ cache.setEntry(key, searchResponse); | ||
/** | ||
* @param {any} str | ||
* @returns {boolean} | ||
*/ | ||
/** | ||
* @param {string} filter | ||
* @returns {string} | ||
*/ | ||
function replaceColonByEqualSign(filter) { | ||
// will only change first occurence of `:` | ||
return filter.replace(/:(.*)/i, '="$1"'); | ||
} | ||
/** | ||
* @param {any[]} arr | ||
* @returns {string} | ||
*/ | ||
function stringifyArray(arr) { | ||
return arr.reduce(function (acc, curr) { | ||
return (acc += JSON.stringify(curr)); | ||
}, ''); | ||
} | ||
function isPureObject(data) { | ||
return typeof data === 'object' && !Array.isArray(data) && data !== null; | ||
} | ||
/** | ||
* apiKey callback definition | ||
* @callback apiKeyCallback | ||
* @returns {string} - The apiKey to use | ||
*/ | ||
/** | ||
* Validates host and apiKey parameters, throws if invalid | ||
* @param hostUrl | ||
* @param apiKey | ||
*/ | ||
function validateInstantMeiliSearchParams(hostUrl, apiKey) { | ||
// Validate host url | ||
if (typeof hostUrl !== 'string') { | ||
throw new TypeError('Provided hostUrl value (1st parameter) is not a string, expected string'); | ||
} | ||
// Validate api key | ||
if (typeof apiKey !== 'string' && typeof apiKey !== 'function') { | ||
throw new TypeError('Provided apiKey value (2nd parameter) is not a string or a function, expected string or function'); | ||
} | ||
} | ||
/** | ||
* Transform InstantSearch filter to Meilisearch filter. | ||
@@ -521,4 +411,15 @@ * Change sign from `:` to `=` in nested filter object. | ||
function setScrollPagination(hitsPerPage, page, query, placeholderSearch) { | ||
if (!placeholderSearch && query === '') { | ||
function isPaginationRequired(filter, query, placeholderSearch) { | ||
// To disable pagination: | ||
// placeholderSearch must be disabled | ||
// The search query must be empty | ||
// There must be no filters | ||
if (!placeholderSearch && !query && (!filter || filter.length === 0)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
function setScrollPagination(pagination, paginationRequired) { | ||
var page = pagination.page, hitsPerPage = pagination.hitsPerPage; | ||
if (!paginationRequired) { | ||
return { | ||
@@ -534,4 +435,5 @@ limit: 0, | ||
} | ||
function setFinitePagination(hitsPerPage, page, query, placeholderSearch) { | ||
if (!placeholderSearch && query === '') { | ||
function setFinitePagination(pagination, paginationRequired) { | ||
var page = pagination.page, hitsPerPage = pagination.hitsPerPage; | ||
if (!paginationRequired) { | ||
return { | ||
@@ -559,3 +461,4 @@ hitsPerPage: 0, | ||
var meiliSearchParams = {}; | ||
var facets = searchContext.facets, attributesToSnippet = searchContext.attributesToSnippet, snippetEllipsisText = searchContext.snippetEllipsisText, attributesToRetrieve = searchContext.attributesToRetrieve, filters = searchContext.filters, numericFilters = searchContext.numericFilters, facetFilters = searchContext.facetFilters, attributesToHighlight = searchContext.attributesToHighlight, highlightPreTag = searchContext.highlightPreTag, highlightPostTag = searchContext.highlightPostTag, placeholderSearch = searchContext.placeholderSearch, query = searchContext.query, sort = searchContext.sort, pagination = searchContext.pagination, matchingStrategy = searchContext.matchingStrategy; | ||
var facets = searchContext.facets, attributesToSnippet = searchContext.attributesToSnippet, snippetEllipsisText = searchContext.snippetEllipsisText, attributesToRetrieve = searchContext.attributesToRetrieve, attributesToHighlight = searchContext.attributesToHighlight, highlightPreTag = searchContext.highlightPreTag, highlightPostTag = searchContext.highlightPostTag, placeholderSearch = searchContext.placeholderSearch, query = searchContext.query, sort = searchContext.sort, pagination = searchContext.pagination, matchingStrategy = searchContext.matchingStrategy, filters = searchContext.filters, numericFilters = searchContext.numericFilters, facetFilters = searchContext.facetFilters; | ||
var meilisearchFilters = adaptFilters(filters, numericFilters, facetFilters); | ||
return { | ||
@@ -566,5 +469,8 @@ getParams: function () { | ||
addFacets: function () { | ||
if (facets === null || facets === void 0 ? void 0 : facets.length) { | ||
if (Array.isArray(facets)) { | ||
meiliSearchParams.facets = facets; | ||
} | ||
else if (typeof facets === 'string') { | ||
meiliSearchParams.facets = [facets]; | ||
} | ||
}, | ||
@@ -588,5 +494,4 @@ addAttributesToCrop: function () { | ||
addFilters: function () { | ||
var filter = adaptFilters(filters, numericFilters, facetFilters); | ||
if (filter.length) { | ||
meiliSearchParams.filter = filter; | ||
if (meilisearchFilters.length) { | ||
meiliSearchParams.filter = meilisearchFilters; | ||
} | ||
@@ -614,4 +519,5 @@ }, | ||
addPagination: function () { | ||
var paginationRequired = isPaginationRequired(meilisearchFilters, query, placeholderSearch); | ||
if (pagination.finite) { | ||
var _a = setFinitePagination(pagination.hitsPerPage, pagination.page, query, placeholderSearch), hitsPerPage = _a.hitsPerPage, page = _a.page; | ||
var _a = setFinitePagination(pagination, paginationRequired), hitsPerPage = _a.hitsPerPage, page = _a.page; | ||
meiliSearchParams.hitsPerPage = hitsPerPage; | ||
@@ -621,3 +527,3 @@ meiliSearchParams.page = page; | ||
else { | ||
var _b = setScrollPagination(pagination.hitsPerPage, pagination.page, query, placeholderSearch), limit = _b.limit, offset = _b.offset; | ||
var _b = setScrollPagination(pagination, paginationRequired), limit = _b.limit, offset = _b.offset; | ||
meiliSearchParams.limit = limit; | ||
@@ -750,11 +656,13 @@ meiliSearchParams.offset = offset; | ||
function adaptGeoResponse(hits) { | ||
var _a; | ||
for (var i = 0; i < hits.length; i++) { | ||
var objectID = "".concat(i + Math.random() * 1000000); | ||
if (hits[i]._geo) { | ||
hits[i]._geoloc = { | ||
lat: hits[i]._geo.lat, | ||
lng: hits[i]._geo.lng | ||
}; | ||
hits[i].objectID = "".concat(i + Math.random() * 1000000); | ||
delete hits[i]._geo; | ||
hits[i]._geoloc = hits[i]._geo; | ||
hits[i].objectID = objectID; | ||
} | ||
if ((_a = hits[i]._formatted) === null || _a === void 0 ? void 0 : _a._geo) { | ||
hits[i]._formatted._geoloc = hits[i]._formatted._geo; | ||
hits[i]._formatted.objectID = objectID; | ||
} | ||
} | ||
@@ -829,2 +737,44 @@ return hits; | ||
function getFacetNames(facets) { | ||
if (!facets) | ||
return []; | ||
else if (typeof facets === 'string') | ||
return [facets]; | ||
return facets; | ||
} | ||
// Fills the missing facetValue in the current facet distribution if `keepZeroFacet` is true | ||
// using the initial facet distribution. Ex: | ||
// | ||
// Initial distribution: { genres: { horror: 10, comedy: 4 } } | ||
// Current distribution: { genres: { horror: 3 }} | ||
// Returned distribution: { genres: { horror: 3, comedy: 0 }} | ||
function fillMissingFacetValues(facets, initialFacetDistribution, facetDistribution) { | ||
var facetNames = getFacetNames(facets); | ||
var filledDistribution = {}; | ||
for (var _i = 0, facetNames_1 = facetNames; _i < facetNames_1.length; _i++) { | ||
var facet = facetNames_1[_i]; | ||
for (var facetValue in initialFacetDistribution[facet]) { | ||
if (!filledDistribution[facet]) { | ||
// initialize sub object | ||
filledDistribution[facet] = facetDistribution[facet] || {}; | ||
} | ||
if (!filledDistribution[facet][facetValue]) { | ||
filledDistribution[facet][facetValue] = 0; | ||
} | ||
else { | ||
filledDistribution[facet][facetValue] = | ||
facetDistribution[facet][facetValue]; | ||
} | ||
} | ||
} | ||
return filledDistribution; | ||
} | ||
function adaptFacetDistribution(keepZeroFacets, facets, initialFacetDistribution, facetDistribution) { | ||
if (keepZeroFacets) { | ||
facetDistribution = facetDistribution || {}; | ||
return fillMissingFacetValues(facets, initialFacetDistribution, facetDistribution); | ||
} | ||
return facetDistribution; | ||
} | ||
/** | ||
@@ -838,13 +788,13 @@ * Adapt search response from Meilisearch | ||
*/ | ||
function adaptSearchResponse(searchResponse, searchContext) { | ||
function adaptSearchResponse(searchResponse, searchContext, initialFacetDistribution) { | ||
var searchResponseOptionals = {}; | ||
var processingTimeMs = searchResponse.processingTimeMs, query = searchResponse.query, facets = searchResponse.facetDistribution; | ||
var processingTimeMs = searchResponse.processingTimeMs, query = searchResponse.query, responseFacetDistribution = searchResponse.facetDistribution; | ||
var keepZeroFacets = searchContext.keepZeroFacets, facets = searchContext.facets; | ||
var _a = adaptPaginationParameters(searchResponse, searchContext.pagination), hitsPerPage = _a.hitsPerPage, page = _a.page, nbPages = _a.nbPages; | ||
var hits = adaptHits(searchResponse, searchContext); | ||
var nbHits = adaptTotalHits(searchResponse); | ||
var facetDistribution = adaptFacetDistribution(keepZeroFacets, facets, initialFacetDistribution, responseFacetDistribution); | ||
// Create response object compliant with InstantSearch | ||
var adaptedSearchResponse = __assign({ index: searchContext.indexUid, hitsPerPage: hitsPerPage, page: page, facets: facets, nbPages: nbPages, nbHits: nbHits, processingTimeMS: processingTimeMs, query: query, hits: hits, params: '', exhaustiveNbHits: false }, searchResponseOptionals); | ||
return { | ||
results: [adaptedSearchResponse] | ||
}; | ||
var adaptedSearchResponse = __assign({ index: searchContext.indexUid, hitsPerPage: hitsPerPage, page: page, facets: facetDistribution, nbPages: nbPages, nbHits: nbHits, processingTimeMS: processingTimeMs, query: query, hits: hits, params: '', exhaustiveNbHits: false }, searchResponseOptionals); | ||
return adaptedSearchResponse; | ||
} | ||
@@ -873,3 +823,3 @@ | ||
*/ | ||
function createSearchContext(searchRequest, options, defaultFacetDistribution) { | ||
function createSearchContext(searchRequest, options) { | ||
// Split index name and possible sorting rules | ||
@@ -879,3 +829,3 @@ var _a = searchRequest.indexName.split(':'), indexUid = _a[0], sortByArray = _a.slice(1); | ||
var paginationState = createPaginationState(options.finitePagination, instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.hitsPerPage, instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.page); | ||
var searchContext = __assign(__assign(__assign({}, options), instantSearchParams), { sort: sortByArray.join(':') || '', indexUid: indexUid, pagination: paginationState, defaultFacetDistribution: defaultFacetDistribution || {}, placeholderSearch: options.placeholderSearch !== false, keepZeroFacets: !!options.keepZeroFacets }); | ||
var searchContext = __assign(__assign(__assign({}, options), instantSearchParams), { sort: sortByArray.join(':') || '', indexUid: indexUid, pagination: paginationState, placeholderSearch: options.placeholderSearch !== false, keepZeroFacets: !!options.keepZeroFacets }); | ||
return searchContext; | ||
@@ -915,3 +865,3 @@ } | ||
function cacheFirstFacetDistribution(searchResolver, searchContext) { | ||
function getIndexFacetDistribution(searchResolver, searchContext) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -938,4 +888,22 @@ var defaultSearchContext, meilisearchParams, searchResponse; | ||
} | ||
function initFacetDistribution(searchResolver, searchContext, initialFacetDistribution) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a, _b; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
if (!!initialFacetDistribution[searchContext.indexUid]) return [3 /*break*/, 2]; | ||
_a = initialFacetDistribution; | ||
_b = searchContext.indexUid; | ||
return [4 /*yield*/, getIndexFacetDistribution(searchResolver, searchContext)]; | ||
case 1: | ||
_a[_b] = _c.sent(); | ||
_c.label = 2; | ||
case 2: return [2 /*return*/, initialFacetDistribution]; | ||
} | ||
}); | ||
}); | ||
} | ||
var PACKAGE_VERSION = '0.10.0'; | ||
var PACKAGE_VERSION = '0.10.1-multi-index-search.0'; | ||
@@ -976,3 +944,3 @@ var constructClientAgents = function (clientAgents) { | ||
var searchResolver = SearchResolver(meilisearchClient, searchCache); | ||
var defaultFacetDistribution; | ||
var initialFacetDistribution = {}; | ||
return { | ||
@@ -986,28 +954,40 @@ clearCache: function () { return searchCache.clearCache(); }, | ||
return __awaiter(this, void 0, void 0, function () { | ||
var searchRequest, searchContext, adaptedSearchRequest, searchResponse, adaptedSearchResponse, e_1; | ||
var searchResponses, requests, _i, requests_1, searchRequest, searchContext, adaptedSearchRequest, searchResponse, adaptedSearchResponse, e_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 4, , 5]); | ||
searchRequest = instantSearchRequests[0]; | ||
searchContext = createSearchContext(searchRequest, instantMeiliSearchOptions, defaultFacetDistribution); | ||
_a.trys.push([0, 6, , 7]); | ||
searchResponses = { | ||
results: [] | ||
}; | ||
requests = instantSearchRequests; | ||
_i = 0, requests_1 = requests; | ||
_a.label = 1; | ||
case 1: | ||
if (!(_i < requests_1.length)) return [3 /*break*/, 5]; | ||
searchRequest = requests_1[_i]; | ||
searchContext = createSearchContext(searchRequest, instantMeiliSearchOptions); | ||
adaptedSearchRequest = adaptSearchParams(searchContext); | ||
if (!(defaultFacetDistribution === undefined)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, cacheFirstFacetDistribution(searchResolver, searchContext)]; | ||
case 1: | ||
defaultFacetDistribution = _a.sent(); | ||
searchContext.defaultFacetDistribution = defaultFacetDistribution; | ||
_a.label = 2; | ||
case 2: return [4 /*yield*/, searchResolver.searchResponse(searchContext, adaptedSearchRequest) | ||
// Adapt the Meilisearch responsne to a compliant instantsearch.js response | ||
]; | ||
return [4 /*yield*/, initFacetDistribution(searchResolver, searchContext, initialFacetDistribution) | ||
// Search response from Meilisearch | ||
]; | ||
case 2: | ||
initialFacetDistribution = _a.sent(); | ||
return [4 /*yield*/, searchResolver.searchResponse(searchContext, adaptedSearchRequest) | ||
// Adapt the Meilisearch response to a compliant instantsearch.js response | ||
]; | ||
case 3: | ||
searchResponse = _a.sent(); | ||
adaptedSearchResponse = adaptSearchResponse(searchResponse, searchContext); | ||
return [2 /*return*/, adaptedSearchResponse]; | ||
adaptedSearchResponse = adaptSearchResponse(searchResponse, searchContext, initialFacetDistribution[searchRequest.indexName]); | ||
searchResponses.results.push(adaptedSearchResponse); | ||
_a.label = 4; | ||
case 4: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 5: return [2 /*return*/, searchResponses]; | ||
case 6: | ||
e_1 = _a.sent(); | ||
console.error(e_1); | ||
throw new Error(e_1); | ||
case 5: return [2 /*return*/]; | ||
case 7: return [2 /*return*/]; | ||
} | ||
@@ -1014,0 +994,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
import{MeiliSearch as t}from"meilisearch";var e=function(){return e=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},e.apply(this,arguments)};function n(t,e,n,r){return new(n||(n=Promise))((function(i,a){function o(t){try{s(r.next(t))}catch(t){a(t)}}function u(t){try{s(r.throw(t))}catch(t){a(t)}}function s(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,u)}s((r=r.apply(t,e||[])).next())}))}function r(t,e){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&u[0]?r.return:u[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,u[1])).done)return i;switch(r=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(6===u[0]&&o.label<i[1]){o.label=i[1],i=u;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(u);break}i[2]&&o.ops.pop(),o.trys.pop();continue}u=e.call(t,o)}catch(t){u=[6,t],r=0}finally{n=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}function i(t,e,n){if(n||2===arguments.length)for(var r,i=0,a=e.length;i<a;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}function a(t){return t.replace(/:(.*)/i,'="$1"')}var o=function(t){var e=t.match(/([^=]*)="?([^\\"]*)"?$/);return e?(e[0],[{filterName:e[1],value:e[2]}]):[]};function u(t){var n=function(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)})):o(t)})).flat(2):[]}(t);return n.filter((function(t){return void 0!==t})).reduce((function(t,n){var r,a=n.filterName,o=n.value,u=t[a]||[];return t=e(e({},t),((r={})[a]=i(i([],u,!0),[o],!1),r))}),{})}function s(t,n){return t.keepZeroFacets?(r=t.defaultFacetDistribution,Object.keys(r).reduce((function(t,n){var i,a=Object.keys(r[n]);return e(e({},t),((i={})[n]=a,i))}),{})):u(null==n?void 0:n.filter);var r}function c(t,e){return{searchResponse:function(i,a){return n(this,void 0,void 0,(function(){var n,o,u,c,l,f;return r(this,(function(r){switch(r.label){case 0:return n=i.placeholderSearch,o=i.query,u=e.formatKey([a,i.indexUid,i.query,i.pagination]),(c=e.getEntry(u))?[2,c]:(l=s(i,a),[4,t.index(i.indexUid).search(i.query,a)]);case 1:return(f=r.sent()).facetDistribution=function(t,e){if(e=e||{},t&&Object.keys(t).length>0)for(var n in t){e[n]||(e[n]={});for(var r=0,i=t[n];r<i.length;r++){var a=i[r];Object.keys(e[n]).includes(a)||(e[n][a]=0)}}return e}(l,f.facetDistribution),n||o||(f.hits=[]),e.setEntry(u,f),[2,f]}}))}))}}}function l(t){return 180*t/Math.PI}function f(t){return t*Math.PI/180}function h(t){if(t){var e,n,r=t.insideBoundingBox,i=t.aroundLatLng,a=t.aroundRadius,o=t.minimumAroundRadius;if(i&&(e=i),null==a&&null==o||(n=null!=a?a:o),r&&"string"==typeof r){var u=r.split(","),s=u[0],c=u[1],h=u[2],d=u[3],g=[parseFloat(s),parseFloat(c),parseFloat(h),parseFloat(d)],p=g[0],v=g[1],y=g[2],P=g[3];n=function(t,e,n,r){var i=t*Math.PI/180,a=n*Math.PI/180,o=(n-t)*Math.PI/180,u=(r-e)*Math.PI/180,s=Math.sin(o/2)*Math.sin(o/2)+Math.cos(i)*Math.cos(a)*Math.sin(u/2)*Math.sin(u/2);return 2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s))*6371e3}(p,v,y,P)/2,e=function(t,e,n,r){t=f(t),e=f(e);var i=Math.cos(t)*Math.cos(e),a=Math.cos(t)*Math.sin(e),o=Math.sin(t);n=f(n),r=f(r);var u=i+Math.cos(n)*Math.cos(r),s=a+Math.cos(n)*Math.sin(r),c=o+Math.sin(n),h=Math.sqrt(u*u+s*s),d=Math.atan2(s,u),g=Math.atan2(c,h);return e<r||e>r&&e>Math.PI&&r<-Math.PI?(g+=Math.PI,d+=Math.PI):(g=l(g),d=l(d)),Math.abs(u)<Math.pow(10,-9)&&Math.abs(s)<Math.pow(10,-9)&&Math.abs(c)<Math.pow(10,-9)&&(g=0,d=0),"".concat(g,",").concat(d)}(p,v,y,P)}if(null!=e&&null!=n){var m=e.split(","),b=m[0],M=m[1];return b=Number.parseFloat(b).toFixed(5),M=Number.parseFloat(M).toFixed(5),{filter:"_geoRadius(".concat(b,", ").concat(M,", ").concat(n,")")}}}}function d(t){return"string"==typeof t?a(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return a(t)})).filter((function(t){return t})):a(t)})).filter((function(t){return t})):[]}function g(t){return""===t?[]:"string"==typeof t?[t]:t}function p(t,e,n){return function(t,e,n){var r=n.trim(),a=g(t),o=g(e);return i(i(i([],a,!0),o,!0),[r],!1).filter((function(t){return Array.isArray(t)?t.length:t}))}(d(n||[]),d(e||[]),t||"")}function v(t){var e={},n=t.facets,r=t.attributesToSnippet,i=t.snippetEllipsisText,a=t.attributesToRetrieve,o=t.filters,u=t.numericFilters,s=t.facetFilters,c=t.attributesToHighlight,l=t.highlightPreTag,f=t.highlightPostTag,d=t.placeholderSearch,g=t.query,v=t.sort,y=t.pagination,P=t.matchingStrategy;return{getParams:function(){return e},addFacets:function(){(null==n?void 0:n.length)&&(e.facets=n)},addAttributesToCrop:function(){r&&(e.attributesToCrop=r)},addCropMarker:function(){null!=i&&(e.cropMarker=i)},addAttributesToRetrieve:function(){a&&(e.attributesToRetrieve=a)},addFilters:function(){var t=p(o,u,s);t.length&&(e.filter=t)},addAttributesToHighlight:function(){e.attributesToHighlight=c||["*"]},addPreTag:function(){e.highlightPreTag=l||"__ais-highlight__"},addPostTag:function(){e.highlightPostTag=f||"__/ais-highlight__"},addPagination:function(){if(y.finite){var t=function(t,e,n,r){return r||""!==n?{hitsPerPage:t,page:e+1}:{hitsPerPage:0,page:e+1}}(y.hitsPerPage,y.page,g,d),n=t.hitsPerPage,r=t.page;e.hitsPerPage=n,e.page=r}else{var i=function(t,e,n,r){return r||""!==n?{limit:t+1,offset:e*t}:{limit:0,offset:0}}(y.hitsPerPage,y.page,g,d),a=i.limit,o=i.offset;e.limit=a,e.offset=o}},addSort:function(){(null==v?void 0:v.length)&&(e.sort=[v])},addGeoSearchRules:function(){var n=function(t){var e={},n=t.aroundLatLng,r=t.aroundLatLngViaIP,i=t.aroundRadius,a=t.aroundPrecision,o=t.minimumAroundRadius,u=t.insideBoundingBox,s=t.insidePolygon;return n&&(e.aroundLatLng=n),r&&console.warn("instant-meilisearch: `aroundLatLngViaIP` is not supported."),i&&(e.aroundRadius=i),a&&console.warn("instant-meilisearch: `aroundPrecision` is not supported.\n See this discussion to track its implementation https://github.com/meilisearch/product/discussions/264"),o&&(e.minimumAroundRadius=o),u&&(e.insideBoundingBox=u),s&&console.warn("instant-meilisearch: `insidePolygon` is not implented in instant-meilisearch."),e}(t),r=h(n);(null==r?void 0:r.filter)&&(e.filter?e.filter.unshift(r.filter):e.filter=[r.filter])},addMatchingStrategy:function(){P&&(e.matchingStrategy=P)}}}function y(t){return"string"==typeof t?t:void 0===t?JSON.stringify(null):JSON.stringify(t)}function P(t){return Array.isArray(t)?t.map((function(t){return P(t)})):"object"!=typeof(e=t)||Array.isArray(e)||null===e?{value:y(t)}:Object.keys(t).reduce((function(e,n){return e[n]=P(t[n]),e}),{});var e}function m(t,e){var n=e.primaryKey,r=t.hits,i=e.pagination,a=i.finite,o=i.hitsPerPage;!a&&r.length>o&&r.splice(r.length-1,1);var u=r.map((function(t){if(Object.keys(t).length>0){var e=t._formatted;t._matchesPosition;var r=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(t,["_formatted","_matchesPosition"]),i=Object.assign(r,function(t){if(!t)return{};var e=P(t);return{_highlightResult:e,_snippetResult:e}}(e));return n&&(i.objectID=t[n]),i}return t}));return u=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}(u),u}function b(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(n){return e[t]}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,n){e[t]=JSON.stringify(n)},clearCache:function(){e={}}}}function M(t,i){return n(this,void 0,void 0,(function(){var n,a;return r(this,(function(r){switch(r.label){case 0:return n=e(e({},i),{placeholderSearch:!0,query:""}),(a=v(n)).addFacets(),a.addPagination(),[4,t.searchResponse(n,a.getParams())];case 1:return[2,r.sent().facetDistribution||{}]}}))}))}var w;function A(i,a,o){void 0===a&&(a=""),void 0===o&&(o={}),function(t,e){if("string"!=typeof t)throw new TypeError("Provided hostUrl value (1st parameter) is not a string, expected string");if("string"!=typeof e&&"function"!=typeof e)throw new TypeError("Provided apiKey value (2nd parameter) is not a string or a function, expected string or function")}(i,a),a=function(t){if("function"==typeof t){var e=t();if("string"!=typeof e)throw new TypeError("Provided apiKey function (2nd parameter) did not return a string, expected string");return e}return t}(a);var u,s=function(t){void 0===t&&(t=[]);var e="Meilisearch instant-meilisearch (v".concat("0.10.0",")");return t.concat(e)}(o.clientAgents),l=new t({host:i,apiKey:a,clientAgents:s}),f=b(),h=c(l,f);return{clearCache:function(){return f.clearCache()},search:function(t){return n(this,void 0,void 0,(function(){var n,i,a,s,c,l;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),n=t[0],i=function(t,n,r){var i,a,o,u=t.indexName.split(":"),s=u[0],c=u.slice(1),l=t.params,f=(i=n.finitePagination,a=null==l?void 0:l.hitsPerPage,o=null==l?void 0:l.page,{hitsPerPage:void 0===a?20:a,page:o||0,finite:!!i});return e(e(e({},n),l),{sort:c.join(":")||"",indexUid:s,pagination:f,defaultFacetDistribution:r||{},placeholderSearch:!1!==n.placeholderSearch,keepZeroFacets:!!n.keepZeroFacets})}(n,o,u),a=function(t){var e=v(t);return e.addFacets(),e.addAttributesToHighlight(),e.addPreTag(),e.addPostTag(),e.addAttributesToRetrieve(),e.addAttributesToCrop(),e.addCropMarker(),e.addPagination(),e.addFilters(),e.addSort(),e.addGeoSearchRules(),e.addMatchingStrategy(),e.getParams()}(i),void 0!==u?[3,2]:[4,M(h,i)];case 1:u=r.sent(),i.defaultFacetDistribution=u,r.label=2;case 2:return[4,h.searchResponse(i,a)];case 3:return s=r.sent(),c=function(t,n){var r=t.processingTimeMs,i=t.query,a=t.facetDistribution,o=function(t,e){var n=e.hitsPerPage,r=e.page,i=function(t,e){if(null!=t.totalPages)return t.totalPages;if(0===e)return 0;var n=t.limit,r=void 0===n?20:n,i=t.offset;return(void 0===i?0:i)/e+1+(t.hits.length>=r?1:0)}(t,n);return{page:r,nbPages:i,hitsPerPage:n}}(t,n.pagination),u=o.hitsPerPage,s=o.page,c=o.nbPages,l=m(t,n),f=function(t){var e=t.hitsPerPage,n=void 0===e?0:e,r=t.totalPages,i=void 0===r?0:r,a=t.estimatedTotalHits,o=t.totalHits;return null!=a?a:null!=o?o:n*i}(t);return{results:[e({index:n.indexUid,hitsPerPage:u,page:s,facets:a,nbPages:c,nbHits:f,processingTimeMS:r,query:i,hits:l,params:"",exhaustiveNbHits:!1},{})]}}(s,i),[2,c];case 4:throw l=r.sent(),console.error(l),new Error(l);case 5:return[2]}}))}))},searchForFacetValues:function(t){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,new Promise((function(t,e){e(new Error("SearchForFacetValues is not compatible with Meilisearch")),t([])}))];case 1:return[2,t.sent()]}}))}))}}}!function(t){t.ALL="all",t.LAST="last"}(w||(w={}));export{w as MatchingStrategies,A as instantMeiliSearch}; | ||
import{MeiliSearch as t}from"meilisearch";var e=function(){return e=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},e.apply(this,arguments)};function n(t,e,n,r){return new(n||(n=Promise))((function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,s)}u((r=r.apply(t,e||[])).next())}))}function r(t,e){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,r=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(i=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],r=0}finally{n=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,n){if(n||2===arguments.length)for(var r,i=0,a=e.length;i<a;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}function a(t){return 180*t/Math.PI}function o(t){return t*Math.PI/180}function s(t){if(t){var e,n,r=t.insideBoundingBox,i=t.aroundLatLng,s=t.aroundRadius,u=t.minimumAroundRadius;if(i&&(e=i),null==s&&null==u||(n=null!=s?s:u),r&&"string"==typeof r){var c=r.split(","),l=c[0],f=c[1],h=c[2],d=c[3],g=[parseFloat(l),parseFloat(f),parseFloat(h),parseFloat(d)],p=g[0],v=g[1],y=g[2],P=g[3];n=function(t,e,n,r){var i=t*Math.PI/180,a=n*Math.PI/180,o=(n-t)*Math.PI/180,s=(r-e)*Math.PI/180,u=Math.sin(o/2)*Math.sin(o/2)+Math.cos(i)*Math.cos(a)*Math.sin(s/2)*Math.sin(s/2);return 2*Math.atan2(Math.sqrt(u),Math.sqrt(1-u))*6371e3}(p,v,y,P)/2,e=function(t,e,n,r){t=o(t),e=o(e);var i=Math.cos(t)*Math.cos(e),s=Math.cos(t)*Math.sin(e),u=Math.sin(t);n=o(n),r=o(r);var c=i+Math.cos(n)*Math.cos(r),l=s+Math.cos(n)*Math.sin(r),f=u+Math.sin(n),h=Math.sqrt(c*c+l*l),d=Math.atan2(l,c),g=Math.atan2(f,h);return e<r||e>r&&e>Math.PI&&r<-Math.PI?(g+=Math.PI,d+=Math.PI):(g=a(g),d=a(d)),Math.abs(c)<Math.pow(10,-9)&&Math.abs(l)<Math.pow(10,-9)&&Math.abs(f)<Math.pow(10,-9)&&(g=0,d=0),"".concat(g,",").concat(d)}(p,v,y,P)}if(null!=e&&null!=n){var m=e.split(","),b=m[0],M=m[1];return b=Number.parseFloat(b).toFixed(5),M=Number.parseFloat(M).toFixed(5),{filter:"_geoRadius(".concat(b,", ").concat(M,", ").concat(n,")")}}}}function u(t){return t.replace(/:(.*)/i,'="$1"')}function c(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)})).filter((function(t){return t})):u(t)})).filter((function(t){return t})):[]}function l(t){return""===t?[]:"string"==typeof t?[t]:t}function f(t,e,n){return function(t,e,n){var r=n.trim(),a=l(t),o=l(e);return i(i(i([],a,!0),o,!0),[r],!1).filter((function(t){return Array.isArray(t)?t.length:t}))}(c(n||[]),c(e||[]),t||"")}function h(t){var e={},n=t.facets,r=t.attributesToSnippet,i=t.snippetEllipsisText,a=t.attributesToRetrieve,o=t.attributesToHighlight,u=t.highlightPreTag,c=t.highlightPostTag,l=t.placeholderSearch,h=t.query,d=t.sort,g=t.pagination,p=t.matchingStrategy,v=f(t.filters,t.numericFilters,t.facetFilters);return{getParams:function(){return e},addFacets:function(){Array.isArray(n)?e.facets=n:"string"==typeof n&&(e.facets=[n])},addAttributesToCrop:function(){r&&(e.attributesToCrop=r)},addCropMarker:function(){null!=i&&(e.cropMarker=i)},addAttributesToRetrieve:function(){a&&(e.attributesToRetrieve=a)},addFilters:function(){v.length&&(e.filter=v)},addAttributesToHighlight:function(){e.attributesToHighlight=o||["*"]},addPreTag:function(){e.highlightPreTag=u||"__ais-highlight__"},addPostTag:function(){e.highlightPostTag=c||"__/ais-highlight__"},addPagination:function(){var t=function(t,e,n){return!!(n||e||t&&0!==t.length)}(v,h,l);if(g.finite){var n=function(t,e){var n=t.page,r=t.hitsPerPage;return e?{hitsPerPage:r,page:n+1}:{hitsPerPage:0,page:n+1}}(g,t),r=n.hitsPerPage,i=n.page;e.hitsPerPage=r,e.page=i}else{var a=function(t,e){var n=t.page,r=t.hitsPerPage;return e?{limit:r+1,offset:n*r}:{limit:0,offset:0}}(g,t),o=a.limit,s=a.offset;e.limit=o,e.offset=s}},addSort:function(){(null==d?void 0:d.length)&&(e.sort=[d])},addGeoSearchRules:function(){var n=function(t){var e={},n=t.aroundLatLng,r=t.aroundLatLngViaIP,i=t.aroundRadius,a=t.aroundPrecision,o=t.minimumAroundRadius,s=t.insideBoundingBox,u=t.insidePolygon;return n&&(e.aroundLatLng=n),r&&console.warn("instant-meilisearch: `aroundLatLngViaIP` is not supported."),i&&(e.aroundRadius=i),a&&console.warn("instant-meilisearch: `aroundPrecision` is not supported.\n See this discussion to track its implementation https://github.com/meilisearch/product/discussions/264"),o&&(e.minimumAroundRadius=o),s&&(e.insideBoundingBox=s),u&&console.warn("instant-meilisearch: `insidePolygon` is not implented in instant-meilisearch."),e}(t),r=s(n);(null==r?void 0:r.filter)&&(e.filter?e.filter.unshift(r.filter):e.filter=[r.filter])},addMatchingStrategy:function(){p&&(e.matchingStrategy=p)}}}function d(t){return"string"==typeof t?t:void 0===t?JSON.stringify(null):JSON.stringify(t)}function g(t){return Array.isArray(t)?t.map((function(t){return g(t)})):"object"!=typeof(e=t)||Array.isArray(e)||null===e?{value:d(t)}:Object.keys(t).reduce((function(e,n){return e[n]=g(t[n]),e}),{});var e}function p(t,e){var n=e.primaryKey,r=t.hits,i=e.pagination,a=i.finite,o=i.hitsPerPage;!a&&r.length>o&&r.splice(r.length-1,1);var s=r.map((function(t){if(Object.keys(t).length>0){var e=t._formatted;t._matchesPosition;var r=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(t,["_formatted","_matchesPosition"]),i=Object.assign(r,function(t){if(!t)return{};var e=g(t);return{_highlightResult:e,_snippetResult:e}}(e));return n&&(i.objectID=t[n]),i}return t}));return s=function(t){for(var e,n=0;n<t.length;n++){var r="".concat(n+1e6*Math.random());t[n]._geo&&(t[n]._geoloc=t[n]._geo,t[n].objectID=r),(null===(e=t[n]._formatted)||void 0===e?void 0:e._geo)&&(t[n]._formatted._geoloc=t[n]._formatted._geo,t[n]._formatted.objectID=r)}return t}(s),s}function v(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(n){return e[t]}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,n){e[t]=JSON.stringify(n)},clearCache:function(){e={}}}}function y(t,i){return n(this,void 0,void 0,(function(){var n,a;return r(this,(function(r){switch(r.label){case 0:return n=e(e({},i),{placeholderSearch:!0,query:""}),(a=h(n)).addFacets(),a.addPagination(),[4,t.searchResponse(n,a.getParams())];case 1:return[2,r.sent().facetDistribution||{}]}}))}))}function P(t,e,i){return n(this,void 0,void 0,(function(){var n,a;return r(this,(function(r){switch(r.label){case 0:return i[e.indexUid]?[3,2]:(n=i,a=e.indexUid,[4,y(t,e)]);case 1:n[a]=r.sent(),r.label=2;case 2:return[2,i]}}))}))}var m;function b(i,a,o){void 0===a&&(a=""),void 0===o&&(o={}),function(t,e){if("string"!=typeof t)throw new TypeError("Provided hostUrl value (1st parameter) is not a string, expected string");if("string"!=typeof e&&"function"!=typeof e)throw new TypeError("Provided apiKey value (2nd parameter) is not a string or a function, expected string or function")}(i,a),a=function(t){if("function"==typeof t){var e=t();if("string"!=typeof e)throw new TypeError("Provided apiKey function (2nd parameter) did not return a string, expected string");return e}return t}(a);var s,u,c=function(t){void 0===t&&(t=[]);var e="Meilisearch instant-meilisearch (v".concat("0.10.1-multi-index-search.0",")");return t.concat(e)}(o.clientAgents),l=new t({host:i,apiKey:a,clientAgents:c}),f=v(),d=(s=l,u=f,{searchResponse:function(t,e){return n(this,void 0,void 0,(function(){var n,i,a;return r(this,(function(r){switch(r.label){case 0:return n=u.formatKey([e,t.indexUid,t.query,t.pagination]),(i=u.getEntry(n))?[2,i]:[4,s.index(t.indexUid).search(t.query,e)];case 1:return a=r.sent(),u.setEntry(n,a),[2,a]}}))}))}}),g={};return{clearCache:function(){return f.clearCache()},search:function(t){return n(this,void 0,void 0,(function(){var n,i,a,s,u,c,l,f,v;return r(this,(function(r){switch(r.label){case 0:r.trys.push([0,6,,7]),n={results:[]},i=0,a=t,r.label=1;case 1:return i<a.length?(s=a[i],u=function(t,n){var r,i,a,o=t.indexName.split(":"),s=o[0],u=o.slice(1),c=t.params,l=(r=n.finitePagination,i=null==c?void 0:c.hitsPerPage,a=null==c?void 0:c.page,{hitsPerPage:void 0===i?20:i,page:a||0,finite:!!r});return e(e(e({},n),c),{sort:u.join(":")||"",indexUid:s,pagination:l,placeholderSearch:!1!==n.placeholderSearch,keepZeroFacets:!!n.keepZeroFacets})}(s,o),c=function(t){var e=h(t);return e.addFacets(),e.addAttributesToHighlight(),e.addPreTag(),e.addPostTag(),e.addAttributesToRetrieve(),e.addAttributesToCrop(),e.addCropMarker(),e.addPagination(),e.addFilters(),e.addSort(),e.addGeoSearchRules(),e.addMatchingStrategy(),e.getParams()}(u),[4,P(d,u,g)]):[3,5];case 2:return g=r.sent(),[4,d.searchResponse(u,c)];case 3:l=r.sent(),f=function(t,n,r){var i=t.processingTimeMs,a=t.query,o=t.facetDistribution,s=n.keepZeroFacets,u=n.facets,c=function(t,e){var n=e.hitsPerPage,r=e.page,i=function(t,e){if(null!=t.totalPages)return t.totalPages;if(0===e)return 0;var n=t.limit,r=void 0===n?20:n,i=t.offset;return(void 0===i?0:i)/e+1+(t.hits.length>=r?1:0)}(t,n);return{page:r,nbPages:i,hitsPerPage:n}}(t,n.pagination),l=c.hitsPerPage,f=c.page,h=c.nbPages,d=p(t,n),g=function(t){var e=t.hitsPerPage,n=void 0===e?0:e,r=t.totalPages,i=void 0===r?0:r,a=t.estimatedTotalHits,o=t.totalHits;return null!=a?a:null!=o?o:n*i}(t),v=function(t,e,n,r){return t?function(t,e,n){for(var r=function(t){return t?"string"==typeof t?[t]:t:[]}(t),i={},a=0,o=r;a<o.length;a++){var s=o[a];for(var u in e[s])i[s]||(i[s]=n[s]||{}),i[s][u]?i[s][u]=n[s][u]:i[s][u]=0}return i}(e,n,r=r||{}):r}(s,u,r,o);return e({index:n.indexUid,hitsPerPage:l,page:f,facets:v,nbPages:h,nbHits:g,processingTimeMS:i,query:a,hits:d,params:"",exhaustiveNbHits:!1},{})}(l,u,g[s.indexName]),n.results.push(f),r.label=4;case 4:return i++,[3,1];case 5:return[2,n];case 6:throw v=r.sent(),console.error(v),new Error(v);case 7:return[2]}}))}))},searchForFacetValues:function(t){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,new Promise((function(t,e){e(new Error("SearchForFacetValues is not compatible with Meilisearch")),t([])}))];case 1:return[2,t.sent()]}}))}))}}}!function(t){t.ALL="all",t.LAST="last"}(m||(m={}));export{m as MatchingStrategies,b as instantMeiliSearch}; | ||
//# sourceMappingURL=instant-meilisearch.esm.min.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).window=t.window||{})}(this,(function(t){"use strict";var e=function(){return e=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},e.apply(this,arguments)};function n(t,e,n,r){return new(n||(n=Promise))((function(i,s){function o(t){try{a(r.next(t))}catch(t){s(t)}}function u(t){try{a(r.throw(t))}catch(t){s(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,u)}a((r=r.apply(t,e||[])).next())}))}function r(t,e){var n,r,i,s,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(u){return function(a){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,u[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&u[0]?r.return:u[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,u[1])).done)return i;switch(r=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(6===u[0]&&o.label<i[1]){o.label=i[1],i=u;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(u);break}i[2]&&o.ops.pop(),o.trys.pop();continue}u=e.call(t,o)}catch(t){u=[6,t],r=0}finally{n=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,a])}}}function i(t,e,n){if(n||2===arguments.length)for(var r,i=0,s=e.length;i<s;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}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 n="URLSearchParams"in t,r="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 d(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return r&&(e[Symbol.iterator]=function(){return e}),e}function l(t){this.map={},t instanceof l?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function f(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function p(t){return new Promise((function(e,n){t.onload=function(){e(t.result)},t.onerror=function(){n(t.error)}}))}function v(t){var e=new FileReader,n=p(e);return e.readAsArrayBuffer(t),n}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 g(){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:n&&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):n&&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,n,r=f(this);if(r)return r;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,n=p(e),e.readAsText(t),n;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),n=new Array(e.length),r=0;r<e.length;r++)n[r]=String.fromCharCode(e[r]);return n.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},s&&(this.formData=function(){return this.text().then(m)}),this.json=function(){return this.text().then(JSON.parse)},this}l.prototype.append=function(t,e){t=c(t),e=h(e);var n=this.map[t];this.map[t]=n?n+", "+e:e},l.prototype.delete=function(t){delete this.map[c(t)]},l.prototype.get=function(t){return t=c(t),this.has(t)?this.map[t]:null},l.prototype.has=function(t){return this.map.hasOwnProperty(c(t))},l.prototype.set=function(t,e){this.map[c(t)]=h(e)},l.prototype.forEach=function(t,e){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(e,this.map[n],n,this)},l.prototype.keys=function(){var t=[];return this.forEach((function(e,n){t.push(n)})),d(t)},l.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),d(t)},l.prototype.entries=function(){var t=[];return this.forEach((function(e,n){t.push([n,e])})),d(t)},r&&(l.prototype[Symbol.iterator]=l.prototype.entries);var b=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function w(t,e){var n,r,i=(e=e||{}).body;if(t instanceof w){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new l(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,i||null==t._bodyInit||(i=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new l(e.headers)),this.method=(n=e.method||this.method||"GET",r=n.toUpperCase(),b.indexOf(r)>-1?r:n),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 n=t.split("="),r=n.shift().replace(/\+/g," "),i=n.join("=").replace(/\+/g," ");e.append(decodeURIComponent(r),decodeURIComponent(i))}})),e}function A(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new l(e.headers),this.url=e.url||"",this._initBody(t)}w.prototype.clone=function(){return new w(this,{body:this._bodyInit})},g.call(w.prototype),g.call(A.prototype),A.prototype.clone=function(){return new A(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new l(this.headers),url:this.url})},A.error=function(){var t=new A(null,{status:0,statusText:""});return t.type="error",t};var x=[301,302,303,307,308];A.redirect=function(t,e){if(-1===x.indexOf(e))throw new RangeError("Invalid status code");return new A(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 n=Error(t);this.stack=n.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function T(t,n){return new Promise((function(r,s){var o=new w(t,n);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,n={status:u.status,statusText:u.statusText,headers:(t=u.getAllResponseHeaders()||"",e=new l,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var n=t.split(":"),r=n.shift().trim();if(r){var i=n.join(":").trim();e.append(r,i)}})),e)};n.url="responseURL"in u?u.responseURL:n.headers.get("X-Request-URL");var i="response"in u?u.response:u.responseText;r(new A(i,n))},u.onerror=function(){s(new TypeError("Network request failed"))},u.ontimeout=function(){s(new TypeError("Network request failed"))},u.onabort=function(){s(new e.DOMException("Aborted","AbortError"))},u.open(o.method,o.url,!0),"include"===o.credentials?u.withCredentials=!0:"omit"===o.credentials&&(u.withCredentials=!1),"responseType"in u&&i&&(u.responseType="blob"),o.headers.forEach((function(t,e){u.setRequestHeader(e,t)})),o.signal&&(o.signal.addEventListener("abort",a),u.onreadystatechange=function(){4===u.readyState&&o.signal.removeEventListener("abort",a)}),u.send(void 0===o._bodyInit?null:o._bodyInit)}))}T.polyfill=!0,t.fetch||(t.fetch=T,t.Headers=l,t.Request=w,t.Response=A),e.Headers=l,e.Request=w,e.Response=A,e.fetch=T,Object.defineProperty(e,"__esModule",{value:!0})}({})}("undefined"!=typeof self?self:s)}));var u=o((function(t,e){!function(t){var e={ALL:"all",LAST:"last"},n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},n(t,e)};function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var i=function(){return i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},i.apply(this,arguments)};function s(t,e,n,r){function i(t){return t instanceof n?t:new n((function(e){e(t)}))}return new(n||(n=Promise))((function(n,s){function o(t){try{a(r.next(t))}catch(t){s(t)}}function u(t){try{a(r.throw(t))}catch(t){s(t)}}function a(t){t.done?n(t.value):i(t.value).then(o,u)}a((r=r.apply(t,e||[])).next())}))}function o(t,e){var n,r,i,s,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(t){return function(e){return a([t,e])}}function a(s){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,r=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],r=0}finally{n=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}}var u=function(t){function e(n,r,i,s){var o,u,a,c=this;return c=t.call(this,n)||this,Object.setPrototypeOf(c,e.prototype),c.name="MeiliSearchCommunicationError",r instanceof Response&&(c.message=r.statusText,c.statusCode=r.status),r instanceof Error&&(c.errno=r.errno,c.code=r.code),s?(c.stack=s,c.stack=null===(o=c.stack)||void 0===o?void 0:o.replace(/(TypeError|FetchError)/,c.name),c.stack=null===(u=c.stack)||void 0===u?void 0:u.replace("Failed to fetch","request to ".concat(i," failed, reason: connect ECONNREFUSED")),c.stack=null===(a=c.stack)||void 0===a?void 0:a.replace("Not Found","Not Found: ".concat(i))):Error.captureStackTrace&&Error.captureStackTrace(c,e),c}return r(e,t),e}(Error),a=function(t){function e(e,n){var r=t.call(this,e.message)||this;return Object.setPrototypeOf(r,a.prototype),r.name="MeiliSearchApiError",r.code=e.code,r.type=e.type,r.link=e.link,r.message=e.message,r.httpStatus=n,Error.captureStackTrace&&Error.captureStackTrace(r,a),r}return r(e,t),e}(Error);function c(t){return s(this,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:if(t.ok)return[3,5];e=void 0,n.label=1;case 1:return n.trys.push([1,3,,4]),[4,t.json()];case 2:return e=n.sent(),[3,4];case 3:throw n.sent(),new u(t.statusText,t,t.url);case 4:throw new a(e,t.status);case 5:return[2,t]}}))}))}function h(t,e,n){if("MeiliSearchApiError"!==t.name)throw new u(t.message,t,n,e);throw t}var d=function(t){function e(n){var r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r.name="MeiliSearchError",Error.captureStackTrace&&Error.captureStackTrace(r,e),r}return r(e,t),e}(Error),l=function(t){function e(n){var r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r.name="MeiliSearchTimeOutError",Error.captureStackTrace&&Error.captureStackTrace(r,e),r}return r(e,t),e}(Error);function f(t){return Object.entries(t).reduce((function(t,e){var n=e[0],r=e[1];return void 0!==r&&(t[n]=r),t}),{})}function p(t){return s(this,void 0,void 0,(function(){return o(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://".concat(t)}function y(t){return t.endsWith("/")||(t+="/"),t}var g="0.30.0";function b(t){return Object.keys(t).reduce((function(e,n){var r,s,o,u=t[n];return void 0===u?e:Array.isArray(u)?i(i({},e),((r={})[n]=u.join(","),r)):u instanceof Date?i(i({},e),((s={})[n]=u.toISOString(),s)):i(i({},e),((o={})[n]=u,o))}),{})}function w(t){try{return t=y(t=v(t))}catch(t){throw new d("The provided host is not valid.")}}function m(t){var e="X-Meilisearch-Client",n="Meilisearch JavaScript (v".concat(g,")"),r="Content-Type";t.headers=t.headers||{};var i=Object.assign({},t.headers);if(t.apiKey&&(i.Authorization="Bearer ".concat(t.apiKey)),t.headers[r]||(i["Content-Type"]="application/json"),t.clientAgents&&Array.isArray(t.clientAgents)){var s=t.clientAgents.concat(n);i[e]=s.join(" ; ")}else{if(t.clientAgents&&!Array.isArray(t.clientAgents))throw new d('Meilisearch: The header "'.concat(e,'" should be an array of string(s).\n'));i[e]=n}return i}var A=function(){function t(t){this.headers=m(t);try{var e=w(t.host);this.url=new URL(e)}catch(t){throw new d("The provided host is not valid.")}}return t.prototype.request=function(t){var e=t.method,n=t.url,r=t.params,u=t.body,a=t.config;return s(this,void 0,void 0,(function(){var t,s,d,l;return o(this,(function(o){switch(o.label){case 0:t=new URL(n,this.url),r&&(s=new URLSearchParams,Object.keys(r).filter((function(t){return null!==r[t]})).map((function(t){return s.set(t,r[t])})),t.search=s.toString()),o.label=1;case 1:return o.trys.push([1,4,,5]),[4,fetch(t.toString(),i(i({},a),{method:e,body:JSON.stringify(u),headers:this.headers})).then((function(t){return c(t)}))];case 2:return[4,o.sent().json().catch((function(){}))];case 3:return[2,o.sent()];case 4:return d=o.sent(),l=d.stack,h(d,l,t.toString()),[3,5];case 5:return[2]}}))}))},t.prototype.get=function(t,e,n){return s(this,void 0,void 0,(function(){return o(this,(function(r){switch(r.label){case 0:return[4,this.request({method:"GET",url:t,params:e,config:n})];case 1:return[2,r.sent()]}}))}))},t.prototype.post=function(t,e,n,r){return s(this,void 0,void 0,(function(){return o(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"POST",url:t,body:e,params:n,config:r})];case 1:return[2,i.sent()]}}))}))},t.prototype.put=function(t,e,n,r){return s(this,void 0,void 0,(function(){return o(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"PUT",url:t,body:e,params:n,config:r})];case 1:return[2,i.sent()]}}))}))},t.prototype.patch=function(t,e,n,r){return s(this,void 0,void 0,(function(){return o(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"PATCH",url:t,body:e,params:n,config:r})];case 1:return[2,i.sent()]}}))}))},t.prototype.delete=function(t,e,n,r){return s(this,void 0,void 0,(function(){return o(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"DELETE",url:t,body:e,params:n,config:r})];case 1:return[2,i.sent()]}}))}))},t}(),x=function(){function t(t){this.taskUid=t.taskUid,this.indexUid=t.indexUid,this.status=t.status,this.type=t.type,this.enqueuedAt=new Date(t.enqueuedAt)}return t}(),T=function(){function t(t){this.indexUid=t.indexUid,this.status=t.status,this.type=t.type,this.uid=t.uid,this.details=t.details,this.canceledBy=t.canceledBy,this.error=t.error,this.duration=t.duration,this.startedAt=new Date(t.startedAt),this.enqueuedAt=new Date(t.enqueuedAt),this.finishedAt=new Date(t.finishedAt)}return t}(),q=function(){function t(t){this.httpRequest=new A(t)}return t.prototype.getTask=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="tasks/".concat(t),[4,this.httpRequest.get(e)];case 1:return n=r.sent(),[2,new T(n)]}}))}))},t.prototype.getTasks=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="tasks",[4,this.httpRequest.get(e,b(t))];case 1:return n=r.sent(),[2,i(i({},n),{results:n.results.map((function(t){return new T(t)}))})]}}))}))},t.prototype.waitForTask=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,i=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:e=Date.now(),r.label=1;case 1:return Date.now()-e<i?[4,this.getTask(t)]:[3,4];case 2:return n=r.sent(),["enqueued","processing"].includes(n.status)?[4,p(a)]:[2,n];case 3:return r.sent(),[3,1];case 4:throw new l("timeout of ".concat(i,"ms has exceeded on process ").concat(t," when waiting a task to be resolved."))}}))}))},t.prototype.waitForTasks=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,i=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return s(this,void 0,void 0,(function(){var e,n,r,s,u;return o(this,(function(o){switch(o.label){case 0:e=[],n=0,r=t,o.label=1;case 1:return n<r.length?(s=r[n],[4,this.waitForTask(s,{timeOutMs:i,intervalMs:a})]):[3,4];case 2:u=o.sent(),e.push(u),o.label=3;case 3:return n++,[3,1];case 4:return[2,e]}}))}))},t.prototype.cancelTasks=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="tasks/cancel",[4,this.httpRequest.post(e,{},b(t))];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.deleteTasks=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="tasks",[4,this.httpRequest.delete(e,{},b(t))];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t}(),R=function(){function t(t,e,n){this.uid=e,this.primaryKey=n,this.httpRequest=new A(t),this.tasks=new q(t)}return t.prototype.search=function(t,e,n){return s(this,void 0,void 0,(function(){var r;return o(this,(function(s){switch(s.label){case 0:return r="indexes/".concat(this.uid,"/search"),[4,this.httpRequest.post(r,f(i({q:t},e)),void 0,n)];case 1:return[2,s.sent()]}}))}))},t.prototype.searchGet=function(t,e,n){var r,u,a,c,h;return s(this,void 0,void 0,(function(){var s,l,p;return o(this,(function(o){switch(o.label){case 0:return s="indexes/".concat(this.uid,"/search"),l=function(t){if("string"==typeof t)return t;if(Array.isArray(t))throw new d("The filter query parameter should be in string format when using searchGet")},p=i(i({q:t},e),{filter:l(null==e?void 0:e.filter),sort:null===(r=null==e?void 0:e.sort)||void 0===r?void 0:r.join(","),facets:null===(u=null==e?void 0:e.facets)||void 0===u?void 0:u.join(","),attributesToRetrieve:null===(a=null==e?void 0:e.attributesToRetrieve)||void 0===a?void 0:a.join(","),attributesToCrop:null===(c=null==e?void 0:e.attributesToCrop)||void 0===c?void 0:c.join(","),attributesToHighlight:null===(h=null==e?void 0:e.attributesToHighlight)||void 0===h?void 0:h.join(",")}),[4,this.httpRequest.get(s,f(p),n)];case 1:return[2,o.sent()]}}))}))},t.prototype.getRawInfo=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid),[4,this.httpRequest.get(t)];case 1:return e=n.sent(),this.primaryKey=e.primaryKey,this.updatedAt=new Date(e.updatedAt),this.createdAt=new Date(e.createdAt),[2,e]}}))}))},t.prototype.fetchInfo=function(){return s(this,void 0,void 0,(function(){return o(this,(function(t){switch(t.label){case 0:return[4,this.getRawInfo()];case 1:return t.sent(),[2,this]}}))}))},t.prototype.fetchPrimaryKey=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t=this,[4,this.getRawInfo()];case 1:return t.primaryKey=e.sent().primaryKey,[2,this.primaryKey]}}))}))},t.create=function(t,e,n){return void 0===e&&(e={}),s(this,void 0,void 0,(function(){var r,s;return o(this,(function(o){switch(o.label){case 0:return r="indexes",[4,new A(n).post(r,i(i({},e),{uid:t}))];case 1:return s=o.sent(),[2,new x(s)]}}))}))},t.prototype.update=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid),[4,this.httpRequest.patch(e,t)];case 1:return(n=r.sent()).enqueuedAt=new Date(n.enqueuedAt),[2,n]}}))}))},t.prototype.delete=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid),[4,this.httpRequest.delete(t)];case 1:return e=n.sent(),[2,new x(e)]}}))}))},t.prototype.getTasks=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.getTasks(i(i({},t),{indexUids:[this.uid]}))];case 1:return[2,e.sent()]}}))}))},t.prototype.getTask=function(t){return s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.getTask(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.waitForTasks=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,i=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.waitForTasks(t,{timeOutMs:i,intervalMs:a})];case 1:return[2,e.sent()]}}))}))},t.prototype.waitForTask=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,i=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.waitForTask(t,{timeOutMs:i,intervalMs:a})];case 1:return[2,e.sent()]}}))}))},t.prototype.getStats=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/stats"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDocuments=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/documents"),n=function(){var e;if(Array.isArray(null==t?void 0:t.fields))return null===(e=null==t?void 0:t.fields)||void 0===e?void 0:e.join(",")}(),[4,this.httpRequest.get(e,f(i(i({},t),{fields:n})))];case 1:return[2,r.sent()]}}))}))},t.prototype.getDocument=function(t,e){return s(this,void 0,void 0,(function(){var n,r;return o(this,(function(s){switch(s.label){case 0:return n="indexes/".concat(this.uid,"/documents/").concat(t),r=function(){var t;if(Array.isArray(null==e?void 0:e.fields))return null===(t=null==e?void 0:e.fields)||void 0===t?void 0:t.join(",")}(),[4,this.httpRequest.get(n,f(i(i({},e),{fields:r})))];case 1:return[2,s.sent()]}}))}))},t.prototype.addDocuments=function(t,e){return s(this,void 0,void 0,(function(){var n,r;return o(this,(function(i){switch(i.label){case 0:return n="indexes/".concat(this.uid,"/documents"),[4,this.httpRequest.post(n,t,e)];case 1:return r=i.sent(),[2,new x(r)]}}))}))},t.prototype.addDocumentsInBatches=function(t,e,n){return void 0===e&&(e=1e3),s(this,void 0,void 0,(function(){var r,i,s,u;return o(this,(function(o){switch(o.label){case 0:r=[],i=0,o.label=1;case 1:return i<t.length?(u=(s=r).push,[4,this.addDocuments(t.slice(i,i+e),n)]):[3,4];case 2:u.apply(s,[o.sent()]),o.label=3;case 3:return i+=e,[3,1];case 4:return[2,r]}}))}))},t.prototype.updateDocuments=function(t,e){return s(this,void 0,void 0,(function(){var n,r;return o(this,(function(i){switch(i.label){case 0:return n="indexes/".concat(this.uid,"/documents"),[4,this.httpRequest.put(n,t,e)];case 1:return r=i.sent(),[2,new x(r)]}}))}))},t.prototype.updateDocumentsInBatches=function(t,e,n){return void 0===e&&(e=1e3),s(this,void 0,void 0,(function(){var r,i,s,u;return o(this,(function(o){switch(o.label){case 0:r=[],i=0,o.label=1;case 1:return i<t.length?(u=(s=r).push,[4,this.updateDocuments(t.slice(i,i+e),n)]):[3,4];case 2:u.apply(s,[o.sent()]),o.label=3;case 3:return i+=e,[3,1];case 4:return[2,r]}}))}))},t.prototype.deleteDocument=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/documents/").concat(t),[4,this.httpRequest.delete(e)];case 1:return(n=r.sent()).enqueuedAt=new Date(n.enqueuedAt),[2,n]}}))}))},t.prototype.deleteDocuments=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/documents/delete-batch"),[4,this.httpRequest.post(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.deleteAllDocuments=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/documents"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getSettings=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSettings=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings"),[4,this.httpRequest.patch(e,t)];case 1:return(n=r.sent()).enqueued=new Date(n.enqueuedAt),[2,n]}}))}))},t.prototype.resetSettings=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getPagination=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/pagination"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updatePagination=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/pagination"),[4,this.httpRequest.patch(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetPagination=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/pagination"),[4,this.httpRequest.delete(t)];case 1:return e=n.sent(),[2,new x(e)]}}))}))},t.prototype.getSynonyms=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/synonyms"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSynonyms=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/synonyms"),[4,this.httpRequest.put(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetSynonyms=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/synonyms"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getStopWords=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/stop-words"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateStopWords=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/stop-words"),[4,this.httpRequest.put(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetStopWords=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/stop-words"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getRankingRules=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/ranking-rules"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateRankingRules=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/ranking-rules"),[4,this.httpRequest.put(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetRankingRules=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/ranking-rules"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getDistinctAttribute=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/distinct-attribute"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateDistinctAttribute=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/distinct-attribute"),[4,this.httpRequest.put(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetDistinctAttribute=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/distinct-attribute"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getFilterableAttributes=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/filterable-attributes"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateFilterableAttributes=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/filterable-attributes"),[4,this.httpRequest.put(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetFilterableAttributes=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/filterable-attributes"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getSortableAttributes=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/sortable-attributes"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSortableAttributes=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/sortable-attributes"),[4,this.httpRequest.put(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetSortableAttributes=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/sortable-attributes"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getSearchableAttributes=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/searchable-attributes"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSearchableAttributes=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/searchable-attributes"),[4,this.httpRequest.put(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetSearchableAttributes=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/searchable-attributes"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getDisplayedAttributes=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/displayed-attributes"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateDisplayedAttributes=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/displayed-attributes"),[4,this.httpRequest.put(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetDisplayedAttributes=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/displayed-attributes"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getTypoTolerance=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/typo-tolerance"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateTypoTolerance=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/typo-tolerance"),[4,this.httpRequest.patch(e,t)];case 1:return(n=r.sent()).enqueuedAt=new Date(n.enqueuedAt),[2,n]}}))}))},t.prototype.resetTypoTolerance=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/typo-tolerance"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getFaceting=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/faceting"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateFaceting=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/faceting"),[4,this.httpRequest.patch(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetFaceting=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/faceting"),[4,this.httpRequest.delete(t)];case 1:return e=n.sent(),[2,new x(e)]}}))}))},t}(),P=function(t){function e(e){return t.call(this,e)||this}return r(e,t),e}(function(){function t(t){this.config=t,this.httpRequest=new A(t),this.tasks=new q(t)}return t.prototype.index=function(t){return new R(this.config,t)},t.prototype.getIndex=function(t){return s(this,void 0,void 0,(function(){return o(this,(function(e){return[2,new R(this.config,t).fetchInfo()]}))}))},t.prototype.getRawIndex=function(t){return s(this,void 0,void 0,(function(){return o(this,(function(e){return[2,new R(this.config,t).getRawInfo()]}))}))},t.prototype.getIndexes=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){var e,n,r=this;return o(this,(function(s){switch(s.label){case 0:return[4,this.getRawIndexes(t)];case 1:return e=s.sent(),n=e.results.map((function(t){return new R(r.config,t.uid,t.primaryKey)})),[2,i(i({},e),{results:n})]}}))}))},t.prototype.getRawIndexes=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:return e="indexes",[4,this.httpRequest.get(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.createIndex=function(t,e){return void 0===e&&(e={}),s(this,void 0,void 0,(function(){return o(this,(function(n){switch(n.label){case 0:return[4,R.create(t,e,this.config)];case 1:return[2,n.sent()]}}))}))},t.prototype.updateIndex=function(t,e){return void 0===e&&(e={}),s(this,void 0,void 0,(function(){return o(this,(function(n){switch(n.label){case 0:return[4,new R(this.config,t).update(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteIndex=function(t){return s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,new R(this.config,t).delete()];case 1:return[2,e.sent()]}}))}))},t.prototype.deleteIndexIfExists=function(t){return s(this,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.deleteIndex(t)];case 1:return n.sent(),[2,!0];case 2:if("index_not_found"===(e=n.sent()).code)return[2,!1];throw e;case 3:return[2]}}))}))},t.prototype.swapIndexes=function(t){return s(this,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:return e="/swap-indexes",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.getTasks=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.getTasks(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getTask=function(t){return s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.getTask(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.waitForTasks=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,i=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.waitForTasks(t,{timeOutMs:i,intervalMs:a})];case 1:return[2,e.sent()]}}))}))},t.prototype.waitForTask=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,i=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.waitForTask(t,{timeOutMs:i,intervalMs:a})];case 1:return[2,e.sent()]}}))}))},t.prototype.cancelTasks=function(t){return s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.cancelTasks(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.deleteTasks=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.deleteTasks(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getKeys=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="keys",[4,this.httpRequest.get(e,t)];case 1:return(n=r.sent()).results=n.results.map((function(t){return i(i({},t),{createdAt:new Date(t.createdAt),updateAt:new Date(t.updateAt)})})),[2,n]}}))}))},t.prototype.getKey=function(t){return s(this,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:return e="keys/".concat(t),[4,this.httpRequest.get(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.createKey=function(t){return s(this,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:return e="keys",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.updateKey=function(t,e){return s(this,void 0,void 0,(function(){var n;return o(this,(function(r){switch(r.label){case 0:return n="keys/".concat(t),[4,this.httpRequest.patch(n,e)];case 1:return[2,r.sent()]}}))}))},t.prototype.deleteKey=function(t){return s(this,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:return e="keys/".concat(t),[4,this.httpRequest.delete(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.health=function(){return s(this,void 0,void 0,(function(){var t;return o(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 s(this,void 0,void 0,(function(){var t;return o(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 s(this,void 0,void 0,(function(){var t;return o(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 s(this,void 0,void 0,(function(){var t;return o(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 s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="dumps",[4,this.httpRequest.post(t)];case 1:return e=n.sent(),[2,new x(e)]}}))}))},t.prototype.generateTenantToken=function(t,e,n){var r=new Error;throw new Error("Meilisearch: failed to generate a tenant token. Generation of a token only works in a node environment \n ".concat(r.stack,"."))},t}());t.Index=R,t.MatchingStrategies=e,t.MeiliSearch=P,t.MeiliSearchApiError=a,t.MeiliSearchCommunicationError=u,t.MeiliSearchError=d,t.MeiliSearchTimeOutError=l,t.default=P,t.httpErrorHandler=h,t.httpResponseErrorHandler=c,Object.defineProperty(t,"__esModule",{value:!0})}(e)}));function a(t){return t.replace(/:(.*)/i,'="$1"')}var c=function(t){var e=t.match(/([^=]*)="?([^\\"]*)"?$/);return e?(e[0],[{filterName:e[1],value:e[2]}]):[]};function h(t){var n=function(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)})):c(t)})).flat(2):[]}(t);return n.filter((function(t){return void 0!==t})).reduce((function(t,n){var r,s=n.filterName,o=n.value,u=t[s]||[];return t=e(e({},t),((r={})[s]=i(i([],u,!0),[o],!1),r))}),{})}function d(t,n){return t.keepZeroFacets?(r=t.defaultFacetDistribution,Object.keys(r).reduce((function(t,n){var i,s=Object.keys(r[n]);return e(e({},t),((i={})[n]=s,i))}),{})):h(null==n?void 0:n.filter);var r}function l(t,e){return{searchResponse:function(i,s){return n(this,void 0,void 0,(function(){var n,o,u,a,c,h;return r(this,(function(r){switch(r.label){case 0:return n=i.placeholderSearch,o=i.query,u=e.formatKey([s,i.indexUid,i.query,i.pagination]),(a=e.getEntry(u))?[2,a]:(c=d(i,s),[4,t.index(i.indexUid).search(i.query,s)]);case 1:return(h=r.sent()).facetDistribution=function(t,e){if(e=e||{},t&&Object.keys(t).length>0)for(var n in t){e[n]||(e[n]={});for(var r=0,i=t[n];r<i.length;r++){var s=i[r];Object.keys(e[n]).includes(s)||(e[n][s]=0)}}return e}(c,h.facetDistribution),n||o||(h.hits=[]),e.setEntry(u,h),[2,h]}}))}))}}}function f(t){return 180*t/Math.PI}function p(t){return t*Math.PI/180}function v(t){if(t){var e,n,r=t.insideBoundingBox,i=t.aroundLatLng,s=t.aroundRadius,o=t.minimumAroundRadius;if(i&&(e=i),null==s&&null==o||(n=null!=s?s:o),r&&"string"==typeof r){var u=r.split(","),a=u[0],c=u[1],h=u[2],d=u[3],l=[parseFloat(a),parseFloat(c),parseFloat(h),parseFloat(d)],v=l[0],y=l[1],g=l[2],b=l[3];n=function(t,e,n,r){var i=t*Math.PI/180,s=n*Math.PI/180,o=(n-t)*Math.PI/180,u=(r-e)*Math.PI/180,a=Math.sin(o/2)*Math.sin(o/2)+Math.cos(i)*Math.cos(s)*Math.sin(u/2)*Math.sin(u/2);return 2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a))*6371e3}(v,y,g,b)/2,e=function(t,e,n,r){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);n=p(n),r=p(r);var u=i+Math.cos(n)*Math.cos(r),a=s+Math.cos(n)*Math.sin(r),c=o+Math.sin(n),h=Math.sqrt(u*u+a*a),d=Math.atan2(a,u),l=Math.atan2(c,h);return e<r||e>r&&e>Math.PI&&r<-Math.PI?(l+=Math.PI,d+=Math.PI):(l=f(l),d=f(d)),Math.abs(u)<Math.pow(10,-9)&&Math.abs(a)<Math.pow(10,-9)&&Math.abs(c)<Math.pow(10,-9)&&(l=0,d=0),"".concat(l,",").concat(d)}(v,y,g,b)}if(null!=e&&null!=n){var w=e.split(","),m=w[0],A=w[1];return m=Number.parseFloat(m).toFixed(5),A=Number.parseFloat(A).toFixed(5),{filter:"_geoRadius(".concat(m,", ").concat(A,", ").concat(n,")")}}}}function y(t){return"string"==typeof t?a(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return a(t)})).filter((function(t){return t})):a(t)})).filter((function(t){return t})):[]}function g(t){return""===t?[]:"string"==typeof t?[t]:t}function b(t,e,n){return function(t,e,n){var r=n.trim(),s=g(t),o=g(e);return i(i(i([],s,!0),o,!0),[r],!1).filter((function(t){return Array.isArray(t)?t.length:t}))}(y(n||[]),y(e||[]),t||"")}function w(t){var e={},n=t.facets,r=t.attributesToSnippet,i=t.snippetEllipsisText,s=t.attributesToRetrieve,o=t.filters,u=t.numericFilters,a=t.facetFilters,c=t.attributesToHighlight,h=t.highlightPreTag,d=t.highlightPostTag,l=t.placeholderSearch,f=t.query,p=t.sort,y=t.pagination,g=t.matchingStrategy;return{getParams:function(){return e},addFacets:function(){(null==n?void 0:n.length)&&(e.facets=n)},addAttributesToCrop:function(){r&&(e.attributesToCrop=r)},addCropMarker:function(){null!=i&&(e.cropMarker=i)},addAttributesToRetrieve:function(){s&&(e.attributesToRetrieve=s)},addFilters:function(){var t=b(o,u,a);t.length&&(e.filter=t)},addAttributesToHighlight:function(){e.attributesToHighlight=c||["*"]},addPreTag:function(){e.highlightPreTag=h||"__ais-highlight__"},addPostTag:function(){e.highlightPostTag=d||"__/ais-highlight__"},addPagination:function(){if(y.finite){var t=function(t,e,n,r){return r||""!==n?{hitsPerPage:t,page:e+1}:{hitsPerPage:0,page:e+1}}(y.hitsPerPage,y.page,f,l),n=t.hitsPerPage,r=t.page;e.hitsPerPage=n,e.page=r}else{var i=function(t,e,n,r){return r||""!==n?{limit:t+1,offset:e*t}:{limit:0,offset:0}}(y.hitsPerPage,y.page,f,l),s=i.limit,o=i.offset;e.limit=s,e.offset=o}},addSort:function(){(null==p?void 0:p.length)&&(e.sort=[p])},addGeoSearchRules:function(){var n=function(t){var e={},n=t.aroundLatLng,r=t.aroundLatLngViaIP,i=t.aroundRadius,s=t.aroundPrecision,o=t.minimumAroundRadius,u=t.insideBoundingBox,a=t.insidePolygon;return n&&(e.aroundLatLng=n),r&&console.warn("instant-meilisearch: `aroundLatLngViaIP` is not supported."),i&&(e.aroundRadius=i),s&&console.warn("instant-meilisearch: `aroundPrecision` is not supported.\n See this discussion to track its implementation https://github.com/meilisearch/product/discussions/264"),o&&(e.minimumAroundRadius=o),u&&(e.insideBoundingBox=u),a&&console.warn("instant-meilisearch: `insidePolygon` is not implented in instant-meilisearch."),e}(t),r=v(n);(null==r?void 0:r.filter)&&(e.filter?e.filter.unshift(r.filter):e.filter=[r.filter])},addMatchingStrategy:function(){g&&(e.matchingStrategy=g)}}}function m(t){return"string"==typeof t?t:void 0===t?JSON.stringify(null):JSON.stringify(t)}function A(t){return Array.isArray(t)?t.map((function(t){return A(t)})):"object"!=typeof(e=t)||Array.isArray(e)||null===e?{value:m(t)}:Object.keys(t).reduce((function(e,n){return e[n]=A(t[n]),e}),{});var e}function x(t,e){var n=e.primaryKey,r=t.hits,i=e.pagination,s=i.finite,o=i.hitsPerPage;!s&&r.length>o&&r.splice(r.length-1,1);var u=r.map((function(t){if(Object.keys(t).length>0){var e=t._formatted;t._matchesPosition;var r=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(t,["_formatted","_matchesPosition"]),i=Object.assign(r,function(t){if(!t)return{};var e=A(t);return{_highlightResult:e,_snippetResult:e}}(e));return n&&(i.objectID=t[n]),i}return t}));return u=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}(u),u}function T(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(n){return e[t]}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,n){e[t]=JSON.stringify(n)},clearCache:function(){e={}}}}function q(t,i){return n(this,void 0,void 0,(function(){var n,s;return r(this,(function(r){switch(r.label){case 0:return n=e(e({},i),{placeholderSearch:!0,query:""}),(s=w(n)).addFacets(),s.addPagination(),[4,t.searchResponse(n,s.getParams())];case 1:return[2,r.sent().facetDistribution||{}]}}))}))}var R;t.MatchingStrategies=void 0,(R=t.MatchingStrategies||(t.MatchingStrategies={})).ALL="all",R.LAST="last",t.instantMeiliSearch=function(t,i,s){void 0===i&&(i=""),void 0===s&&(s={}),function(t,e){if("string"!=typeof t)throw new TypeError("Provided hostUrl value (1st parameter) is not a string, expected string");if("string"!=typeof e&&"function"!=typeof e)throw new TypeError("Provided apiKey value (2nd parameter) is not a string or a function, expected string or function")}(t,i),i=function(t){if("function"==typeof t){var e=t();if("string"!=typeof e)throw new TypeError("Provided apiKey function (2nd parameter) did not return a string, expected string");return e}return t}(i);var o,a=function(t){void 0===t&&(t=[]);var e="Meilisearch instant-meilisearch (v".concat("0.10.0",")");return t.concat(e)}(s.clientAgents),c=new u.MeiliSearch({host:t,apiKey:i,clientAgents:a}),h=T(),d=l(c,h);return{clearCache:function(){return h.clearCache()},search:function(t){return n(this,void 0,void 0,(function(){var n,i,u,a,c,h;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),n=t[0],i=function(t,n,r){var i,s,o,u=t.indexName.split(":"),a=u[0],c=u.slice(1),h=t.params,d=(i=n.finitePagination,s=null==h?void 0:h.hitsPerPage,o=null==h?void 0:h.page,{hitsPerPage:void 0===s?20:s,page:o||0,finite:!!i});return e(e(e({},n),h),{sort:c.join(":")||"",indexUid:a,pagination:d,defaultFacetDistribution:r||{},placeholderSearch:!1!==n.placeholderSearch,keepZeroFacets:!!n.keepZeroFacets})}(n,s,o),u=function(t){var e=w(t);return e.addFacets(),e.addAttributesToHighlight(),e.addPreTag(),e.addPostTag(),e.addAttributesToRetrieve(),e.addAttributesToCrop(),e.addCropMarker(),e.addPagination(),e.addFilters(),e.addSort(),e.addGeoSearchRules(),e.addMatchingStrategy(),e.getParams()}(i),void 0!==o?[3,2]:[4,q(d,i)];case 1:o=r.sent(),i.defaultFacetDistribution=o,r.label=2;case 2:return[4,d.searchResponse(i,u)];case 3:return a=r.sent(),c=function(t,n){var r=t.processingTimeMs,i=t.query,s=t.facetDistribution,o=function(t,e){var n=e.hitsPerPage,r=e.page,i=function(t,e){if(null!=t.totalPages)return t.totalPages;if(0===e)return 0;var n=t.limit,r=void 0===n?20:n,i=t.offset;return(void 0===i?0:i)/e+1+(t.hits.length>=r?1:0)}(t,n);return{page:r,nbPages:i,hitsPerPage:n}}(t,n.pagination),u=o.hitsPerPage,a=o.page,c=o.nbPages,h=x(t,n),d=function(t){var e=t.hitsPerPage,n=void 0===e?0:e,r=t.totalPages,i=void 0===r?0:r,s=t.estimatedTotalHits,o=t.totalHits;return null!=s?s:null!=o?o:n*i}(t);return{results:[e({index:n.indexUid,hitsPerPage:u,page:a,facets:s,nbPages:c,nbHits:d,processingTimeMS:r,query:i,hits:h,params:"",exhaustiveNbHits:!1},{})]}}(a,i),[2,c];case 4:throw h=r.sent(),console.error(h),new Error(h);case 5:return[2]}}))}))},searchForFacetValues:function(t){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,new Promise((function(t,e){e(new Error("SearchForFacetValues is not compatible with Meilisearch")),t([])}))];case 1:return[2,t.sent()]}}))}))}}},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).window=t.window||{})}(this,(function(t){"use strict";var e=function(){return e=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},e.apply(this,arguments)};function n(t,e,n,r){return new(n||(n=Promise))((function(i,s){function o(t){try{a(r.next(t))}catch(t){s(t)}}function u(t){try{a(r.throw(t))}catch(t){s(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,u)}a((r=r.apply(t,e||[])).next())}))}function r(t,e){var n,r,i,s,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(u){return function(a){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,u[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&u[0]?r.return:u[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,u[1])).done)return i;switch(r=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(6===u[0]&&o.label<i[1]){o.label=i[1],i=u;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(u);break}i[2]&&o.ops.pop(),o.trys.pop();continue}u=e.call(t,o)}catch(t){u=[6,t],r=0}finally{n=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,a])}}}function i(t,e,n){if(n||2===arguments.length)for(var r,i=0,s=e.length;i<s;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}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 n="URLSearchParams"in t,r="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 d(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return r&&(e[Symbol.iterator]=function(){return e}),e}function l(t){this.map={},t instanceof l?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function f(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function p(t){return new Promise((function(e,n){t.onload=function(){e(t.result)},t.onerror=function(){n(t.error)}}))}function v(t){var e=new FileReader,n=p(e);return e.readAsArrayBuffer(t),n}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 g(){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:n&&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):n&&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,n,r=f(this);if(r)return r;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,n=p(e),e.readAsText(t),n;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),n=new Array(e.length),r=0;r<e.length;r++)n[r]=String.fromCharCode(e[r]);return n.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},s&&(this.formData=function(){return this.text().then(m)}),this.json=function(){return this.text().then(JSON.parse)},this}l.prototype.append=function(t,e){t=c(t),e=h(e);var n=this.map[t];this.map[t]=n?n+", "+e:e},l.prototype.delete=function(t){delete this.map[c(t)]},l.prototype.get=function(t){return t=c(t),this.has(t)?this.map[t]:null},l.prototype.has=function(t){return this.map.hasOwnProperty(c(t))},l.prototype.set=function(t,e){this.map[c(t)]=h(e)},l.prototype.forEach=function(t,e){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(e,this.map[n],n,this)},l.prototype.keys=function(){var t=[];return this.forEach((function(e,n){t.push(n)})),d(t)},l.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),d(t)},l.prototype.entries=function(){var t=[];return this.forEach((function(e,n){t.push([n,e])})),d(t)},r&&(l.prototype[Symbol.iterator]=l.prototype.entries);var b=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function w(t,e){var n,r,i=(e=e||{}).body;if(t instanceof w){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new l(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,i||null==t._bodyInit||(i=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new l(e.headers)),this.method=(n=e.method||this.method||"GET",r=n.toUpperCase(),b.indexOf(r)>-1?r:n),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 n=t.split("="),r=n.shift().replace(/\+/g," "),i=n.join("=").replace(/\+/g," ");e.append(decodeURIComponent(r),decodeURIComponent(i))}})),e}function A(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new l(e.headers),this.url=e.url||"",this._initBody(t)}w.prototype.clone=function(){return new w(this,{body:this._bodyInit})},g.call(w.prototype),g.call(A.prototype),A.prototype.clone=function(){return new A(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new l(this.headers),url:this.url})},A.error=function(){var t=new A(null,{status:0,statusText:""});return t.type="error",t};var x=[301,302,303,307,308];A.redirect=function(t,e){if(-1===x.indexOf(e))throw new RangeError("Invalid status code");return new A(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 n=Error(t);this.stack=n.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function T(t,n){return new Promise((function(r,s){var o=new w(t,n);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,n={status:u.status,statusText:u.statusText,headers:(t=u.getAllResponseHeaders()||"",e=new l,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var n=t.split(":"),r=n.shift().trim();if(r){var i=n.join(":").trim();e.append(r,i)}})),e)};n.url="responseURL"in u?u.responseURL:n.headers.get("X-Request-URL");var i="response"in u?u.response:u.responseText;r(new A(i,n))},u.onerror=function(){s(new TypeError("Network request failed"))},u.ontimeout=function(){s(new TypeError("Network request failed"))},u.onabort=function(){s(new e.DOMException("Aborted","AbortError"))},u.open(o.method,o.url,!0),"include"===o.credentials?u.withCredentials=!0:"omit"===o.credentials&&(u.withCredentials=!1),"responseType"in u&&i&&(u.responseType="blob"),o.headers.forEach((function(t,e){u.setRequestHeader(e,t)})),o.signal&&(o.signal.addEventListener("abort",a),u.onreadystatechange=function(){4===u.readyState&&o.signal.removeEventListener("abort",a)}),u.send(void 0===o._bodyInit?null:o._bodyInit)}))}T.polyfill=!0,t.fetch||(t.fetch=T,t.Headers=l,t.Request=w,t.Response=A),e.Headers=l,e.Request=w,e.Response=A,e.fetch=T,Object.defineProperty(e,"__esModule",{value:!0})}({})}("undefined"!=typeof self?self:s)}));var u=o((function(t,e){!function(t){var e={ALL:"all",LAST:"last"},n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},n(t,e)};function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var i=function(){return i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},i.apply(this,arguments)};function s(t,e,n,r){function i(t){return t instanceof n?t:new n((function(e){e(t)}))}return new(n||(n=Promise))((function(n,s){function o(t){try{a(r.next(t))}catch(t){s(t)}}function u(t){try{a(r.throw(t))}catch(t){s(t)}}function a(t){t.done?n(t.value):i(t.value).then(o,u)}a((r=r.apply(t,e||[])).next())}))}function o(t,e){var n,r,i,s,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(t){return function(e){return a([t,e])}}function a(s){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,r=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],r=0}finally{n=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}}var u=function(t){function e(n,r,i,s){var o,u,a,c=this;return c=t.call(this,n)||this,Object.setPrototypeOf(c,e.prototype),c.name="MeiliSearchCommunicationError",r instanceof Response&&(c.message=r.statusText,c.statusCode=r.status),r instanceof Error&&(c.errno=r.errno,c.code=r.code),s?(c.stack=s,c.stack=null===(o=c.stack)||void 0===o?void 0:o.replace(/(TypeError|FetchError)/,c.name),c.stack=null===(u=c.stack)||void 0===u?void 0:u.replace("Failed to fetch","request to ".concat(i," failed, reason: connect ECONNREFUSED")),c.stack=null===(a=c.stack)||void 0===a?void 0:a.replace("Not Found","Not Found: ".concat(i))):Error.captureStackTrace&&Error.captureStackTrace(c,e),c}return r(e,t),e}(Error),a=function(t){function e(e,n){var r=t.call(this,e.message)||this;return Object.setPrototypeOf(r,a.prototype),r.name="MeiliSearchApiError",r.code=e.code,r.type=e.type,r.link=e.link,r.message=e.message,r.httpStatus=n,Error.captureStackTrace&&Error.captureStackTrace(r,a),r}return r(e,t),e}(Error);function c(t){return s(this,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:if(t.ok)return[3,5];e=void 0,n.label=1;case 1:return n.trys.push([1,3,,4]),[4,t.json()];case 2:return e=n.sent(),[3,4];case 3:throw n.sent(),new u(t.statusText,t,t.url);case 4:throw new a(e,t.status);case 5:return[2,t]}}))}))}function h(t,e,n){if("MeiliSearchApiError"!==t.name)throw new u(t.message,t,n,e);throw t}var d=function(t){function e(n){var r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r.name="MeiliSearchError",Error.captureStackTrace&&Error.captureStackTrace(r,e),r}return r(e,t),e}(Error),l=function(t){function e(n){var r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r.name="MeiliSearchTimeOutError",Error.captureStackTrace&&Error.captureStackTrace(r,e),r}return r(e,t),e}(Error);function f(t){return Object.entries(t).reduce((function(t,e){var n=e[0],r=e[1];return void 0!==r&&(t[n]=r),t}),{})}function p(t){return s(this,void 0,void 0,(function(){return o(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://".concat(t)}function y(t){return t.endsWith("/")||(t+="/"),t}var g="0.30.0";function b(t){return Object.keys(t).reduce((function(e,n){var r,s,o,u=t[n];return void 0===u?e:Array.isArray(u)?i(i({},e),((r={})[n]=u.join(","),r)):u instanceof Date?i(i({},e),((s={})[n]=u.toISOString(),s)):i(i({},e),((o={})[n]=u,o))}),{})}function w(t){try{return t=y(t=v(t))}catch(t){throw new d("The provided host is not valid.")}}function m(t){var e="X-Meilisearch-Client",n="Meilisearch JavaScript (v".concat(g,")"),r="Content-Type";t.headers=t.headers||{};var i=Object.assign({},t.headers);if(t.apiKey&&(i.Authorization="Bearer ".concat(t.apiKey)),t.headers[r]||(i["Content-Type"]="application/json"),t.clientAgents&&Array.isArray(t.clientAgents)){var s=t.clientAgents.concat(n);i[e]=s.join(" ; ")}else{if(t.clientAgents&&!Array.isArray(t.clientAgents))throw new d('Meilisearch: The header "'.concat(e,'" should be an array of string(s).\n'));i[e]=n}return i}var A=function(){function t(t){this.headers=m(t);try{var e=w(t.host);this.url=new URL(e)}catch(t){throw new d("The provided host is not valid.")}}return t.prototype.request=function(t){var e=t.method,n=t.url,r=t.params,u=t.body,a=t.config;return s(this,void 0,void 0,(function(){var t,s,d,l;return o(this,(function(o){switch(o.label){case 0:t=new URL(n,this.url),r&&(s=new URLSearchParams,Object.keys(r).filter((function(t){return null!==r[t]})).map((function(t){return s.set(t,r[t])})),t.search=s.toString()),o.label=1;case 1:return o.trys.push([1,4,,5]),[4,fetch(t.toString(),i(i({},a),{method:e,body:JSON.stringify(u),headers:this.headers})).then((function(t){return c(t)}))];case 2:return[4,o.sent().json().catch((function(){}))];case 3:return[2,o.sent()];case 4:return d=o.sent(),l=d.stack,h(d,l,t.toString()),[3,5];case 5:return[2]}}))}))},t.prototype.get=function(t,e,n){return s(this,void 0,void 0,(function(){return o(this,(function(r){switch(r.label){case 0:return[4,this.request({method:"GET",url:t,params:e,config:n})];case 1:return[2,r.sent()]}}))}))},t.prototype.post=function(t,e,n,r){return s(this,void 0,void 0,(function(){return o(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"POST",url:t,body:e,params:n,config:r})];case 1:return[2,i.sent()]}}))}))},t.prototype.put=function(t,e,n,r){return s(this,void 0,void 0,(function(){return o(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"PUT",url:t,body:e,params:n,config:r})];case 1:return[2,i.sent()]}}))}))},t.prototype.patch=function(t,e,n,r){return s(this,void 0,void 0,(function(){return o(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"PATCH",url:t,body:e,params:n,config:r})];case 1:return[2,i.sent()]}}))}))},t.prototype.delete=function(t,e,n,r){return s(this,void 0,void 0,(function(){return o(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"DELETE",url:t,body:e,params:n,config:r})];case 1:return[2,i.sent()]}}))}))},t}(),x=function(){function t(t){this.taskUid=t.taskUid,this.indexUid=t.indexUid,this.status=t.status,this.type=t.type,this.enqueuedAt=new Date(t.enqueuedAt)}return t}(),T=function(){function t(t){this.indexUid=t.indexUid,this.status=t.status,this.type=t.type,this.uid=t.uid,this.details=t.details,this.canceledBy=t.canceledBy,this.error=t.error,this.duration=t.duration,this.startedAt=new Date(t.startedAt),this.enqueuedAt=new Date(t.enqueuedAt),this.finishedAt=new Date(t.finishedAt)}return t}(),q=function(){function t(t){this.httpRequest=new A(t)}return t.prototype.getTask=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="tasks/".concat(t),[4,this.httpRequest.get(e)];case 1:return n=r.sent(),[2,new T(n)]}}))}))},t.prototype.getTasks=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="tasks",[4,this.httpRequest.get(e,b(t))];case 1:return n=r.sent(),[2,i(i({},n),{results:n.results.map((function(t){return new T(t)}))})]}}))}))},t.prototype.waitForTask=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,i=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:e=Date.now(),r.label=1;case 1:return Date.now()-e<i?[4,this.getTask(t)]:[3,4];case 2:return n=r.sent(),["enqueued","processing"].includes(n.status)?[4,p(a)]:[2,n];case 3:return r.sent(),[3,1];case 4:throw new l("timeout of ".concat(i,"ms has exceeded on process ").concat(t," when waiting a task to be resolved."))}}))}))},t.prototype.waitForTasks=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,i=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return s(this,void 0,void 0,(function(){var e,n,r,s,u;return o(this,(function(o){switch(o.label){case 0:e=[],n=0,r=t,o.label=1;case 1:return n<r.length?(s=r[n],[4,this.waitForTask(s,{timeOutMs:i,intervalMs:a})]):[3,4];case 2:u=o.sent(),e.push(u),o.label=3;case 3:return n++,[3,1];case 4:return[2,e]}}))}))},t.prototype.cancelTasks=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="tasks/cancel",[4,this.httpRequest.post(e,{},b(t))];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.deleteTasks=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="tasks",[4,this.httpRequest.delete(e,{},b(t))];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t}(),R=function(){function t(t,e,n){this.uid=e,this.primaryKey=n,this.httpRequest=new A(t),this.tasks=new q(t)}return t.prototype.search=function(t,e,n){return s(this,void 0,void 0,(function(){var r;return o(this,(function(s){switch(s.label){case 0:return r="indexes/".concat(this.uid,"/search"),[4,this.httpRequest.post(r,f(i({q:t},e)),void 0,n)];case 1:return[2,s.sent()]}}))}))},t.prototype.searchGet=function(t,e,n){var r,u,a,c,h;return s(this,void 0,void 0,(function(){var s,l,p;return o(this,(function(o){switch(o.label){case 0:return s="indexes/".concat(this.uid,"/search"),l=function(t){if("string"==typeof t)return t;if(Array.isArray(t))throw new d("The filter query parameter should be in string format when using searchGet")},p=i(i({q:t},e),{filter:l(null==e?void 0:e.filter),sort:null===(r=null==e?void 0:e.sort)||void 0===r?void 0:r.join(","),facets:null===(u=null==e?void 0:e.facets)||void 0===u?void 0:u.join(","),attributesToRetrieve:null===(a=null==e?void 0:e.attributesToRetrieve)||void 0===a?void 0:a.join(","),attributesToCrop:null===(c=null==e?void 0:e.attributesToCrop)||void 0===c?void 0:c.join(","),attributesToHighlight:null===(h=null==e?void 0:e.attributesToHighlight)||void 0===h?void 0:h.join(",")}),[4,this.httpRequest.get(s,f(p),n)];case 1:return[2,o.sent()]}}))}))},t.prototype.getRawInfo=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid),[4,this.httpRequest.get(t)];case 1:return e=n.sent(),this.primaryKey=e.primaryKey,this.updatedAt=new Date(e.updatedAt),this.createdAt=new Date(e.createdAt),[2,e]}}))}))},t.prototype.fetchInfo=function(){return s(this,void 0,void 0,(function(){return o(this,(function(t){switch(t.label){case 0:return[4,this.getRawInfo()];case 1:return t.sent(),[2,this]}}))}))},t.prototype.fetchPrimaryKey=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t=this,[4,this.getRawInfo()];case 1:return t.primaryKey=e.sent().primaryKey,[2,this.primaryKey]}}))}))},t.create=function(t,e,n){return void 0===e&&(e={}),s(this,void 0,void 0,(function(){var r,s;return o(this,(function(o){switch(o.label){case 0:return r="indexes",[4,new A(n).post(r,i(i({},e),{uid:t}))];case 1:return s=o.sent(),[2,new x(s)]}}))}))},t.prototype.update=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid),[4,this.httpRequest.patch(e,t)];case 1:return(n=r.sent()).enqueuedAt=new Date(n.enqueuedAt),[2,n]}}))}))},t.prototype.delete=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid),[4,this.httpRequest.delete(t)];case 1:return e=n.sent(),[2,new x(e)]}}))}))},t.prototype.getTasks=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.getTasks(i(i({},t),{indexUids:[this.uid]}))];case 1:return[2,e.sent()]}}))}))},t.prototype.getTask=function(t){return s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.getTask(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.waitForTasks=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,i=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.waitForTasks(t,{timeOutMs:i,intervalMs:a})];case 1:return[2,e.sent()]}}))}))},t.prototype.waitForTask=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,i=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.waitForTask(t,{timeOutMs:i,intervalMs:a})];case 1:return[2,e.sent()]}}))}))},t.prototype.getStats=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/stats"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDocuments=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/documents"),n=function(){var e;if(Array.isArray(null==t?void 0:t.fields))return null===(e=null==t?void 0:t.fields)||void 0===e?void 0:e.join(",")}(),[4,this.httpRequest.get(e,f(i(i({},t),{fields:n})))];case 1:return[2,r.sent()]}}))}))},t.prototype.getDocument=function(t,e){return s(this,void 0,void 0,(function(){var n,r;return o(this,(function(s){switch(s.label){case 0:return n="indexes/".concat(this.uid,"/documents/").concat(t),r=function(){var t;if(Array.isArray(null==e?void 0:e.fields))return null===(t=null==e?void 0:e.fields)||void 0===t?void 0:t.join(",")}(),[4,this.httpRequest.get(n,f(i(i({},e),{fields:r})))];case 1:return[2,s.sent()]}}))}))},t.prototype.addDocuments=function(t,e){return s(this,void 0,void 0,(function(){var n,r;return o(this,(function(i){switch(i.label){case 0:return n="indexes/".concat(this.uid,"/documents"),[4,this.httpRequest.post(n,t,e)];case 1:return r=i.sent(),[2,new x(r)]}}))}))},t.prototype.addDocumentsInBatches=function(t,e,n){return void 0===e&&(e=1e3),s(this,void 0,void 0,(function(){var r,i,s,u;return o(this,(function(o){switch(o.label){case 0:r=[],i=0,o.label=1;case 1:return i<t.length?(u=(s=r).push,[4,this.addDocuments(t.slice(i,i+e),n)]):[3,4];case 2:u.apply(s,[o.sent()]),o.label=3;case 3:return i+=e,[3,1];case 4:return[2,r]}}))}))},t.prototype.updateDocuments=function(t,e){return s(this,void 0,void 0,(function(){var n,r;return o(this,(function(i){switch(i.label){case 0:return n="indexes/".concat(this.uid,"/documents"),[4,this.httpRequest.put(n,t,e)];case 1:return r=i.sent(),[2,new x(r)]}}))}))},t.prototype.updateDocumentsInBatches=function(t,e,n){return void 0===e&&(e=1e3),s(this,void 0,void 0,(function(){var r,i,s,u;return o(this,(function(o){switch(o.label){case 0:r=[],i=0,o.label=1;case 1:return i<t.length?(u=(s=r).push,[4,this.updateDocuments(t.slice(i,i+e),n)]):[3,4];case 2:u.apply(s,[o.sent()]),o.label=3;case 3:return i+=e,[3,1];case 4:return[2,r]}}))}))},t.prototype.deleteDocument=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/documents/").concat(t),[4,this.httpRequest.delete(e)];case 1:return(n=r.sent()).enqueuedAt=new Date(n.enqueuedAt),[2,n]}}))}))},t.prototype.deleteDocuments=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/documents/delete-batch"),[4,this.httpRequest.post(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.deleteAllDocuments=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/documents"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getSettings=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSettings=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings"),[4,this.httpRequest.patch(e,t)];case 1:return(n=r.sent()).enqueued=new Date(n.enqueuedAt),[2,n]}}))}))},t.prototype.resetSettings=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getPagination=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/pagination"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updatePagination=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/pagination"),[4,this.httpRequest.patch(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetPagination=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/pagination"),[4,this.httpRequest.delete(t)];case 1:return e=n.sent(),[2,new x(e)]}}))}))},t.prototype.getSynonyms=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/synonyms"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSynonyms=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/synonyms"),[4,this.httpRequest.put(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetSynonyms=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/synonyms"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getStopWords=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/stop-words"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateStopWords=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/stop-words"),[4,this.httpRequest.put(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetStopWords=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/stop-words"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getRankingRules=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/ranking-rules"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateRankingRules=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/ranking-rules"),[4,this.httpRequest.put(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetRankingRules=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/ranking-rules"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getDistinctAttribute=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/distinct-attribute"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateDistinctAttribute=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/distinct-attribute"),[4,this.httpRequest.put(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetDistinctAttribute=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/distinct-attribute"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getFilterableAttributes=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/filterable-attributes"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateFilterableAttributes=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/filterable-attributes"),[4,this.httpRequest.put(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetFilterableAttributes=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/filterable-attributes"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getSortableAttributes=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/sortable-attributes"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSortableAttributes=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/sortable-attributes"),[4,this.httpRequest.put(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetSortableAttributes=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/sortable-attributes"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getSearchableAttributes=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/searchable-attributes"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSearchableAttributes=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/searchable-attributes"),[4,this.httpRequest.put(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetSearchableAttributes=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/searchable-attributes"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getDisplayedAttributes=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/displayed-attributes"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateDisplayedAttributes=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/displayed-attributes"),[4,this.httpRequest.put(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetDisplayedAttributes=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/displayed-attributes"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getTypoTolerance=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/typo-tolerance"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateTypoTolerance=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/typo-tolerance"),[4,this.httpRequest.patch(e,t)];case 1:return(n=r.sent()).enqueuedAt=new Date(n.enqueuedAt),[2,n]}}))}))},t.prototype.resetTypoTolerance=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/typo-tolerance"),[4,this.httpRequest.delete(t)];case 1:return(e=n.sent()).enqueuedAt=new Date(e.enqueuedAt),[2,e]}}))}))},t.prototype.getFaceting=function(){return s(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="indexes/".concat(this.uid,"/settings/faceting"),[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateFaceting=function(t){return s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="indexes/".concat(this.uid,"/settings/faceting"),[4,this.httpRequest.patch(e,t)];case 1:return n=r.sent(),[2,new x(n)]}}))}))},t.prototype.resetFaceting=function(){return s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="indexes/".concat(this.uid,"/settings/faceting"),[4,this.httpRequest.delete(t)];case 1:return e=n.sent(),[2,new x(e)]}}))}))},t}(),P=function(t){function e(e){return t.call(this,e)||this}return r(e,t),e}(function(){function t(t){this.config=t,this.httpRequest=new A(t),this.tasks=new q(t)}return t.prototype.index=function(t){return new R(this.config,t)},t.prototype.getIndex=function(t){return s(this,void 0,void 0,(function(){return o(this,(function(e){return[2,new R(this.config,t).fetchInfo()]}))}))},t.prototype.getRawIndex=function(t){return s(this,void 0,void 0,(function(){return o(this,(function(e){return[2,new R(this.config,t).getRawInfo()]}))}))},t.prototype.getIndexes=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){var e,n,r=this;return o(this,(function(s){switch(s.label){case 0:return[4,this.getRawIndexes(t)];case 1:return e=s.sent(),n=e.results.map((function(t){return new R(r.config,t.uid,t.primaryKey)})),[2,i(i({},e),{results:n})]}}))}))},t.prototype.getRawIndexes=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:return e="indexes",[4,this.httpRequest.get(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.createIndex=function(t,e){return void 0===e&&(e={}),s(this,void 0,void 0,(function(){return o(this,(function(n){switch(n.label){case 0:return[4,R.create(t,e,this.config)];case 1:return[2,n.sent()]}}))}))},t.prototype.updateIndex=function(t,e){return void 0===e&&(e={}),s(this,void 0,void 0,(function(){return o(this,(function(n){switch(n.label){case 0:return[4,new R(this.config,t).update(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteIndex=function(t){return s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,new R(this.config,t).delete()];case 1:return[2,e.sent()]}}))}))},t.prototype.deleteIndexIfExists=function(t){return s(this,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.deleteIndex(t)];case 1:return n.sent(),[2,!0];case 2:if("index_not_found"===(e=n.sent()).code)return[2,!1];throw e;case 3:return[2]}}))}))},t.prototype.swapIndexes=function(t){return s(this,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:return e="/swap-indexes",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.getTasks=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.getTasks(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getTask=function(t){return s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.getTask(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.waitForTasks=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,i=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.waitForTasks(t,{timeOutMs:i,intervalMs:a})];case 1:return[2,e.sent()]}}))}))},t.prototype.waitForTask=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,i=void 0===r?5e3:r,u=n.intervalMs,a=void 0===u?50:u;return s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.waitForTask(t,{timeOutMs:i,intervalMs:a})];case 1:return[2,e.sent()]}}))}))},t.prototype.cancelTasks=function(t){return s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.cancelTasks(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.deleteTasks=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.tasks.deleteTasks(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getKeys=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e="keys",[4,this.httpRequest.get(e,t)];case 1:return(n=r.sent()).results=n.results.map((function(t){return i(i({},t),{createdAt:new Date(t.createdAt),updateAt:new Date(t.updateAt)})})),[2,n]}}))}))},t.prototype.getKey=function(t){return s(this,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:return e="keys/".concat(t),[4,this.httpRequest.get(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.createKey=function(t){return s(this,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:return e="keys",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.updateKey=function(t,e){return s(this,void 0,void 0,(function(){var n;return o(this,(function(r){switch(r.label){case 0:return n="keys/".concat(t),[4,this.httpRequest.patch(n,e)];case 1:return[2,r.sent()]}}))}))},t.prototype.deleteKey=function(t){return s(this,void 0,void 0,(function(){var e;return o(this,(function(n){switch(n.label){case 0:return e="keys/".concat(t),[4,this.httpRequest.delete(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.health=function(){return s(this,void 0,void 0,(function(){var t;return o(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 s(this,void 0,void 0,(function(){var t;return o(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 s(this,void 0,void 0,(function(){var t;return o(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 s(this,void 0,void 0,(function(){var t;return o(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 s(this,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return t="dumps",[4,this.httpRequest.post(t)];case 1:return e=n.sent(),[2,new x(e)]}}))}))},t.prototype.generateTenantToken=function(t,e,n){var r=new Error;throw new Error("Meilisearch: failed to generate a tenant token. Generation of a token only works in a node environment \n ".concat(r.stack,"."))},t}());t.Index=R,t.MatchingStrategies=e,t.MeiliSearch=P,t.MeiliSearchApiError=a,t.MeiliSearchCommunicationError=u,t.MeiliSearchError=d,t.MeiliSearchTimeOutError=l,t.default=P,t.httpErrorHandler=h,t.httpResponseErrorHandler=c,Object.defineProperty(t,"__esModule",{value:!0})}(e)}));function a(t){return 180*t/Math.PI}function c(t){return t*Math.PI/180}function h(t){if(t){var e,n,r=t.insideBoundingBox,i=t.aroundLatLng,s=t.aroundRadius,o=t.minimumAroundRadius;if(i&&(e=i),null==s&&null==o||(n=null!=s?s:o),r&&"string"==typeof r){var u=r.split(","),h=u[0],d=u[1],l=u[2],f=u[3],p=[parseFloat(h),parseFloat(d),parseFloat(l),parseFloat(f)],v=p[0],y=p[1],g=p[2],b=p[3];n=function(t,e,n,r){var i=t*Math.PI/180,s=n*Math.PI/180,o=(n-t)*Math.PI/180,u=(r-e)*Math.PI/180,a=Math.sin(o/2)*Math.sin(o/2)+Math.cos(i)*Math.cos(s)*Math.sin(u/2)*Math.sin(u/2);return 2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a))*6371e3}(v,y,g,b)/2,e=function(t,e,n,r){t=c(t),e=c(e);var i=Math.cos(t)*Math.cos(e),s=Math.cos(t)*Math.sin(e),o=Math.sin(t);n=c(n),r=c(r);var u=i+Math.cos(n)*Math.cos(r),h=s+Math.cos(n)*Math.sin(r),d=o+Math.sin(n),l=Math.sqrt(u*u+h*h),f=Math.atan2(h,u),p=Math.atan2(d,l);return e<r||e>r&&e>Math.PI&&r<-Math.PI?(p+=Math.PI,f+=Math.PI):(p=a(p),f=a(f)),Math.abs(u)<Math.pow(10,-9)&&Math.abs(h)<Math.pow(10,-9)&&Math.abs(d)<Math.pow(10,-9)&&(p=0,f=0),"".concat(p,",").concat(f)}(v,y,g,b)}if(null!=e&&null!=n){var w=e.split(","),m=w[0],A=w[1];return m=Number.parseFloat(m).toFixed(5),A=Number.parseFloat(A).toFixed(5),{filter:"_geoRadius(".concat(m,", ").concat(A,", ").concat(n,")")}}}}function d(t){return t.replace(/:(.*)/i,'="$1"')}function l(t){return"string"==typeof t?d(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return d(t)})).filter((function(t){return t})):d(t)})).filter((function(t){return t})):[]}function f(t){return""===t?[]:"string"==typeof t?[t]:t}function p(t,e,n){return function(t,e,n){var r=n.trim(),s=f(t),o=f(e);return i(i(i([],s,!0),o,!0),[r],!1).filter((function(t){return Array.isArray(t)?t.length:t}))}(l(n||[]),l(e||[]),t||"")}function v(t){var e={},n=t.facets,r=t.attributesToSnippet,i=t.snippetEllipsisText,s=t.attributesToRetrieve,o=t.attributesToHighlight,u=t.highlightPreTag,a=t.highlightPostTag,c=t.placeholderSearch,d=t.query,l=t.sort,f=t.pagination,v=t.matchingStrategy,y=p(t.filters,t.numericFilters,t.facetFilters);return{getParams:function(){return e},addFacets:function(){Array.isArray(n)?e.facets=n:"string"==typeof n&&(e.facets=[n])},addAttributesToCrop:function(){r&&(e.attributesToCrop=r)},addCropMarker:function(){null!=i&&(e.cropMarker=i)},addAttributesToRetrieve:function(){s&&(e.attributesToRetrieve=s)},addFilters:function(){y.length&&(e.filter=y)},addAttributesToHighlight:function(){e.attributesToHighlight=o||["*"]},addPreTag:function(){e.highlightPreTag=u||"__ais-highlight__"},addPostTag:function(){e.highlightPostTag=a||"__/ais-highlight__"},addPagination:function(){var t=function(t,e,n){return!!(n||e||t&&0!==t.length)}(y,d,c);if(f.finite){var n=function(t,e){var n=t.page,r=t.hitsPerPage;return e?{hitsPerPage:r,page:n+1}:{hitsPerPage:0,page:n+1}}(f,t),r=n.hitsPerPage,i=n.page;e.hitsPerPage=r,e.page=i}else{var s=function(t,e){var n=t.page,r=t.hitsPerPage;return e?{limit:r+1,offset:n*r}:{limit:0,offset:0}}(f,t),o=s.limit,u=s.offset;e.limit=o,e.offset=u}},addSort:function(){(null==l?void 0:l.length)&&(e.sort=[l])},addGeoSearchRules:function(){var n=function(t){var e={},n=t.aroundLatLng,r=t.aroundLatLngViaIP,i=t.aroundRadius,s=t.aroundPrecision,o=t.minimumAroundRadius,u=t.insideBoundingBox,a=t.insidePolygon;return n&&(e.aroundLatLng=n),r&&console.warn("instant-meilisearch: `aroundLatLngViaIP` is not supported."),i&&(e.aroundRadius=i),s&&console.warn("instant-meilisearch: `aroundPrecision` is not supported.\n See this discussion to track its implementation https://github.com/meilisearch/product/discussions/264"),o&&(e.minimumAroundRadius=o),u&&(e.insideBoundingBox=u),a&&console.warn("instant-meilisearch: `insidePolygon` is not implented in instant-meilisearch."),e}(t),r=h(n);(null==r?void 0:r.filter)&&(e.filter?e.filter.unshift(r.filter):e.filter=[r.filter])},addMatchingStrategy:function(){v&&(e.matchingStrategy=v)}}}function y(t){return"string"==typeof t?t:void 0===t?JSON.stringify(null):JSON.stringify(t)}function g(t){return Array.isArray(t)?t.map((function(t){return g(t)})):"object"!=typeof(e=t)||Array.isArray(e)||null===e?{value:y(t)}:Object.keys(t).reduce((function(e,n){return e[n]=g(t[n]),e}),{});var e}function b(t,e){var n=e.primaryKey,r=t.hits,i=e.pagination,s=i.finite,o=i.hitsPerPage;!s&&r.length>o&&r.splice(r.length-1,1);var u=r.map((function(t){if(Object.keys(t).length>0){var e=t._formatted;t._matchesPosition;var r=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(t,["_formatted","_matchesPosition"]),i=Object.assign(r,function(t){if(!t)return{};var e=g(t);return{_highlightResult:e,_snippetResult:e}}(e));return n&&(i.objectID=t[n]),i}return t}));return u=function(t){for(var e,n=0;n<t.length;n++){var r="".concat(n+1e6*Math.random());t[n]._geo&&(t[n]._geoloc=t[n]._geo,t[n].objectID=r),(null===(e=t[n]._formatted)||void 0===e?void 0:e._geo)&&(t[n]._formatted._geoloc=t[n]._formatted._geo,t[n]._formatted.objectID=r)}return t}(u),u}function w(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(n){return e[t]}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,n){e[t]=JSON.stringify(n)},clearCache:function(){e={}}}}function m(t,i){return n(this,void 0,void 0,(function(){var n,s;return r(this,(function(r){switch(r.label){case 0:return n=e(e({},i),{placeholderSearch:!0,query:""}),(s=v(n)).addFacets(),s.addPagination(),[4,t.searchResponse(n,s.getParams())];case 1:return[2,r.sent().facetDistribution||{}]}}))}))}function A(t,e,i){return n(this,void 0,void 0,(function(){var n,s;return r(this,(function(r){switch(r.label){case 0:return i[e.indexUid]?[3,2]:(n=i,s=e.indexUid,[4,m(t,e)]);case 1:n[s]=r.sent(),r.label=2;case 2:return[2,i]}}))}))}var x;t.MatchingStrategies=void 0,(x=t.MatchingStrategies||(t.MatchingStrategies={})).ALL="all",x.LAST="last",t.instantMeiliSearch=function(t,i,s){void 0===i&&(i=""),void 0===s&&(s={}),function(t,e){if("string"!=typeof t)throw new TypeError("Provided hostUrl value (1st parameter) is not a string, expected string");if("string"!=typeof e&&"function"!=typeof e)throw new TypeError("Provided apiKey value (2nd parameter) is not a string or a function, expected string or function")}(t,i),i=function(t){if("function"==typeof t){var e=t();if("string"!=typeof e)throw new TypeError("Provided apiKey function (2nd parameter) did not return a string, expected string");return e}return t}(i);var o,a,c=function(t){void 0===t&&(t=[]);var e="Meilisearch instant-meilisearch (v".concat("0.10.1-multi-index-search.0",")");return t.concat(e)}(s.clientAgents),h=new u.MeiliSearch({host:t,apiKey:i,clientAgents:c}),d=w(),l=(o=h,a=d,{searchResponse:function(t,e){return n(this,void 0,void 0,(function(){var n,i,s;return r(this,(function(r){switch(r.label){case 0:return n=a.formatKey([e,t.indexUid,t.query,t.pagination]),(i=a.getEntry(n))?[2,i]:[4,o.index(t.indexUid).search(t.query,e)];case 1:return s=r.sent(),a.setEntry(n,s),[2,s]}}))}))}}),f={};return{clearCache:function(){return d.clearCache()},search:function(t){return n(this,void 0,void 0,(function(){var n,i,o,u,a,c,h,d,p;return r(this,(function(r){switch(r.label){case 0:r.trys.push([0,6,,7]),n={results:[]},i=0,o=t,r.label=1;case 1:return i<o.length?(u=o[i],a=function(t,n){var r,i,s,o=t.indexName.split(":"),u=o[0],a=o.slice(1),c=t.params,h=(r=n.finitePagination,i=null==c?void 0:c.hitsPerPage,s=null==c?void 0:c.page,{hitsPerPage:void 0===i?20:i,page:s||0,finite:!!r});return e(e(e({},n),c),{sort:a.join(":")||"",indexUid:u,pagination:h,placeholderSearch:!1!==n.placeholderSearch,keepZeroFacets:!!n.keepZeroFacets})}(u,s),c=function(t){var e=v(t);return e.addFacets(),e.addAttributesToHighlight(),e.addPreTag(),e.addPostTag(),e.addAttributesToRetrieve(),e.addAttributesToCrop(),e.addCropMarker(),e.addPagination(),e.addFilters(),e.addSort(),e.addGeoSearchRules(),e.addMatchingStrategy(),e.getParams()}(a),[4,A(l,a,f)]):[3,5];case 2:return f=r.sent(),[4,l.searchResponse(a,c)];case 3:h=r.sent(),d=function(t,n,r){var i=t.processingTimeMs,s=t.query,o=t.facetDistribution,u=n.keepZeroFacets,a=n.facets,c=function(t,e){var n=e.hitsPerPage,r=e.page,i=function(t,e){if(null!=t.totalPages)return t.totalPages;if(0===e)return 0;var n=t.limit,r=void 0===n?20:n,i=t.offset;return(void 0===i?0:i)/e+1+(t.hits.length>=r?1:0)}(t,n);return{page:r,nbPages:i,hitsPerPage:n}}(t,n.pagination),h=c.hitsPerPage,d=c.page,l=c.nbPages,f=b(t,n),p=function(t){var e=t.hitsPerPage,n=void 0===e?0:e,r=t.totalPages,i=void 0===r?0:r,s=t.estimatedTotalHits,o=t.totalHits;return null!=s?s:null!=o?o:n*i}(t),v=function(t,e,n,r){return t?function(t,e,n){for(var r=function(t){return t?"string"==typeof t?[t]:t:[]}(t),i={},s=0,o=r;s<o.length;s++){var u=o[s];for(var a in e[u])i[u]||(i[u]=n[u]||{}),i[u][a]?i[u][a]=n[u][a]:i[u][a]=0}return i}(e,n,r=r||{}):r}(u,a,r,o);return e({index:n.indexUid,hitsPerPage:h,page:d,facets:v,nbPages:l,nbHits:p,processingTimeMS:i,query:s,hits:f,params:"",exhaustiveNbHits:!1},{})}(h,a,f[u.indexName]),n.results.push(d),r.label=4;case 4:return i++,[3,1];case 5:return[2,n];case 6:throw p=r.sent(),console.error(p),new Error(p);case 7:return[2]}}))}))},searchForFacetValues:function(t){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,new Promise((function(t,e){e(new Error("SearchForFacetValues is not compatible with Meilisearch")),t([])}))];case 1:return[2,t.sent()]}}))}))}}},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=instant-meilisearch.umd.min.js.map |
@@ -1,2 +0,2 @@ | ||
import type { SearchContext, MeiliSearchResponse, AlgoliaSearchResponse } from '../../types'; | ||
import type { SearchContext, MeiliSearchResponse, AlgoliaSearchResponse, FacetDistribution } from '../../types'; | ||
/** | ||
@@ -10,5 +10,3 @@ * Adapt search response from Meilisearch | ||
*/ | ||
export declare function adaptSearchResponse<T>(searchResponse: MeiliSearchResponse<Record<string, any>>, searchContext: SearchContext): { | ||
results: Array<AlgoliaSearchResponse<T>>; | ||
}; | ||
export declare function adaptSearchResponse<T>(searchResponse: MeiliSearchResponse<Record<string, any>>, searchContext: SearchContext, initialFacetDistribution: FacetDistribution): AlgoliaSearchResponse<T>; | ||
//# sourceMappingURL=search-response-adapter.d.ts.map |
export * from './search-cache'; | ||
export * from './first-facets-distribution'; | ||
export * from './init-facets-distribution'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { InstantMeiliSearchOptions, AlgoliaMultipleQueriesQuery, SearchContext, FacetDistribution } from '../types'; | ||
import { InstantMeiliSearchOptions, AlgoliaMultipleQueriesQuery, SearchContext } from '../types'; | ||
/** | ||
@@ -7,3 +7,3 @@ * @param {AlgoliaMultipleQueriesQuery} searchRequest | ||
*/ | ||
export declare function createSearchContext(searchRequest: AlgoliaMultipleQueriesQuery, options: InstantMeiliSearchOptions, defaultFacetDistribution: FacetDistribution): SearchContext; | ||
export declare function createSearchContext(searchRequest: AlgoliaMultipleQueriesQuery, options: InstantMeiliSearchOptions): SearchContext; | ||
//# sourceMappingURL=search-context.d.ts.map |
@@ -1,2 +0,2 @@ | ||
// Type definitions for @meilisearch/instant-meilisearch 0.10.0 | ||
// Type definitions for @meilisearch/instant-meilisearch 0.10.1-multi-index-search.0 | ||
// Project: https://github.com/meilisearch/instant-meilisearch.git | ||
@@ -3,0 +3,0 @@ // Definitions by: Clementine Urquizar <https://github.com/meilisearch> |
@@ -1,2 +0,2 @@ | ||
export declare const PACKAGE_VERSION = "0.10.0"; | ||
export declare const PACKAGE_VERSION = "0.10.1-multi-index-search.0"; | ||
//# sourceMappingURL=package-version.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import type { SearchResponse as MeiliSearchResponse, FacetDistribution } from 'meilisearch'; | ||
import type { SearchResponse as MeiliSearchResponse } from 'meilisearch'; | ||
import type { SearchClient } from 'instantsearch.js'; | ||
@@ -8,9 +8,2 @@ import type { MultipleQueriesQuery as AlgoliaMultipleQueriesQuery } from '@algolia/client-search'; | ||
export type InstantSearchParams = AlgoliaMultipleQueriesQuery['params']; | ||
export type FacetsCache = { | ||
[category: string]: string[]; | ||
}; | ||
export type ParsedFilter = { | ||
filterName: string; | ||
value: string; | ||
}; | ||
export declare const enum MatchingStrategies { | ||
@@ -54,11 +47,11 @@ ALL = "all", | ||
}; | ||
export type Facets = string | string[] | undefined; | ||
export type SearchContext = Omit<InstantSearchParams, 'insideBoundingBox'> & InstantSearchParams & { | ||
defaultFacetDistribution: FacetDistribution; | ||
pagination: PaginationState; | ||
indexUid: string; | ||
placeholderSearch: boolean; | ||
keepZeroFacets: boolean; | ||
insideBoundingBox?: InsideBoundingBox; | ||
keepZeroFacets?: boolean; | ||
cropMarker?: string; | ||
sort?: string; | ||
placeholderSearch?: boolean; | ||
primaryKey?: string; | ||
@@ -65,0 +58,0 @@ matchingStrategy?: MatchingStrategies; |
{ | ||
"name": "@meilisearch/instant-meilisearch", | ||
"version": "0.10.0", | ||
"version": "0.10.1-multi-index-search.0", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "The search client to use Meilisearch with InstantSearch.", |
@@ -273,3 +273,3 @@ <p align="center"> | ||
- ✅ [InstantSearch](#-instantsearch) | ||
- ❌ [index](#-index) | ||
- ✅ [index](#-index) | ||
- ✅ [SearchBox](#-searchbox) | ||
@@ -343,3 +343,3 @@ - ✅ [Configure](#-configure) | ||
### ❌ Index | ||
### ✅ Index | ||
@@ -350,6 +350,4 @@ [Index references](https://www.algolia.com/doc/api-reference/widgets/index-widget/js/) | ||
Not compatible as Meilisearch does not support federated search on multiple indexes. | ||
Using this component, instant-meilisearch does an http-request for each different `Index` widget added. More http requests are made when using the [`RefinementList`](#✅-refinementlist) widget. | ||
If you'd like to see federated search implemented please vote for it in the [roadmap](https://roadmap.meilisearch.com/c/74-multi-index-search?utm_medium=social&utm_source=portal_share). | ||
### ✅ SearchBox | ||
@@ -678,2 +676,5 @@ | ||
The `RefinementList` widget uses the `disjunctive facet search` principle when using the `or` operator. For each different facet category used, an additional http call is made. | ||
For example, if I ask for `color=green` and `size=2`, three http requests are made. One for the hits, one for the `color` distribution and one for the `size` distribution. To provide any feedback on the subject, refer to [this discussion](https://github.com/meilisearch/product/issues/54). | ||
The following example will create a UI component with the a list of genres on which you will be able to facet. | ||
@@ -680,0 +681,0 @@ |
import { adaptSearchParams } from '../search-params-adapter' | ||
import { MatchingStrategies } from '../../../types' | ||
import { MatchingStrategies, SearchContext } from '../../../types' | ||
const DEFAULT_CONTEXT = { | ||
const DEFAULT_CONTEXT: SearchContext = { | ||
indexUid: 'test', | ||
pagination: { page: 0, hitsPerPage: 6, finite: false }, | ||
defaultFacetDistribution: {}, | ||
placeholderSearch: true, | ||
keepZeroFacets: false, | ||
} | ||
@@ -158,2 +159,27 @@ | ||
test('adapting a finite pagination with no placeholderSearch and a query', () => { | ||
const searchParams = adaptSearchParams({ | ||
...DEFAULT_CONTEXT, | ||
query: 'a', | ||
pagination: { page: 4, hitsPerPage: 6, finite: true }, | ||
placeholderSearch: false, | ||
}) | ||
expect(searchParams.page).toBe(5) | ||
expect(searchParams.hitsPerPage).toBeGreaterThan(0) | ||
}) | ||
test('adapting a finite pagination with no placeholderSearch and a facetFilter', () => { | ||
const searchParams = adaptSearchParams({ | ||
...DEFAULT_CONTEXT, | ||
query: '', | ||
pagination: { page: 4, hitsPerPage: 6, finite: true }, | ||
placeholderSearch: false, | ||
facetFilters: ['genres:Action'], | ||
}) | ||
expect(searchParams.page).toBe(5) | ||
expect(searchParams.hitsPerPage).toBeGreaterThan(0) | ||
}) | ||
test('adapting a scroll pagination with no placeholderSearch', () => { | ||
@@ -170,2 +196,27 @@ const searchParams = adaptSearchParams({ | ||
}) | ||
test('adapting a scroll pagination with no placeholderSearch and a query', () => { | ||
const searchParams = adaptSearchParams({ | ||
...DEFAULT_CONTEXT, | ||
query: 'a', | ||
pagination: { page: 4, hitsPerPage: 6, finite: false }, | ||
placeholderSearch: false, | ||
}) | ||
expect(searchParams.limit).toBeGreaterThan(0) | ||
expect(searchParams.offset).toBeGreaterThan(0) | ||
}) | ||
test('adapting a scroll pagination with no placeholderSearch and a facetFilter', () => { | ||
const searchParams = adaptSearchParams({ | ||
...DEFAULT_CONTEXT, | ||
query: 'a', | ||
pagination: { page: 4, hitsPerPage: 6, finite: false }, | ||
placeholderSearch: false, | ||
facetFilters: ['genres:Action'], | ||
}) | ||
expect(searchParams.limit).toBeGreaterThan(0) | ||
expect(searchParams.offset).toBeGreaterThan(0) | ||
}) | ||
}) |
@@ -1,2 +0,7 @@ | ||
import type { MeiliSearchParams, SearchContext } from '../../types' | ||
import type { | ||
MeiliSearchParams, | ||
SearchContext, | ||
Filter, | ||
PaginationState, | ||
} from '../../types' | ||
@@ -9,9 +14,24 @@ import { | ||
function setScrollPagination( | ||
hitsPerPage: number, | ||
page: number, | ||
function isPaginationRequired( | ||
filter: Filter, | ||
query?: string, | ||
placeholderSearch?: boolean | ||
): boolean { | ||
// To disable pagination: | ||
// placeholderSearch must be disabled | ||
// The search query must be empty | ||
// There must be no filters | ||
if (!placeholderSearch && !query && (!filter || filter.length === 0)) { | ||
return false | ||
} | ||
return true | ||
} | ||
function setScrollPagination( | ||
pagination: PaginationState, | ||
paginationRequired: boolean | ||
): { limit: number; offset: number } { | ||
if (!placeholderSearch && query === '') { | ||
const { page, hitsPerPage } = pagination | ||
if (!paginationRequired) { | ||
return { | ||
@@ -30,8 +50,8 @@ limit: 0, | ||
function setFinitePagination( | ||
hitsPerPage: number, | ||
page: number, | ||
query?: string, | ||
placeholderSearch?: boolean | ||
pagination: PaginationState, | ||
paginationRequired: boolean | ||
): { hitsPerPage: number; page: number } { | ||
if (!placeholderSearch && query === '') { | ||
const { page, hitsPerPage } = pagination | ||
if (!paginationRequired) { | ||
return { | ||
@@ -63,5 +83,2 @@ hitsPerPage: 0, | ||
attributesToRetrieve, | ||
filters, | ||
numericFilters, | ||
facetFilters, | ||
attributesToHighlight, | ||
@@ -75,4 +92,9 @@ highlightPreTag, | ||
matchingStrategy, | ||
filters, | ||
numericFilters, | ||
facetFilters, | ||
} = searchContext | ||
const meilisearchFilters = adaptFilters(filters, numericFilters, facetFilters) | ||
return { | ||
@@ -83,4 +105,6 @@ getParams() { | ||
addFacets() { | ||
if (facets?.length) { | ||
if (Array.isArray(facets)) { | ||
meiliSearchParams.facets = facets | ||
} else if (typeof facets === 'string') { | ||
meiliSearchParams.facets = [facets] | ||
} | ||
@@ -105,5 +129,4 @@ }, | ||
addFilters() { | ||
const filter = adaptFilters(filters, numericFilters, facetFilters) | ||
if (filter.length) { | ||
meiliSearchParams.filter = filter | ||
if (meilisearchFilters.length) { | ||
meiliSearchParams.filter = meilisearchFilters | ||
} | ||
@@ -129,8 +152,11 @@ }, | ||
addPagination() { | ||
const paginationRequired = isPaginationRequired( | ||
meilisearchFilters, | ||
query, | ||
placeholderSearch | ||
) | ||
if (pagination.finite) { | ||
const { hitsPerPage, page } = setFinitePagination( | ||
pagination.hitsPerPage, | ||
pagination.page, | ||
query, | ||
placeholderSearch | ||
pagination, | ||
paginationRequired | ||
) | ||
@@ -141,6 +167,4 @@ meiliSearchParams.hitsPerPage = hitsPerPage | ||
const { limit, offset } = setScrollPagination( | ||
pagination.hitsPerPage, | ||
pagination.page, | ||
query, | ||
placeholderSearch | ||
pagination, | ||
paginationRequired | ||
) | ||
@@ -147,0 +171,0 @@ meiliSearchParams.limit = limit |
@@ -8,3 +8,2 @@ import { | ||
} from '../../types' | ||
import { addMissingFacets, extractFacets } from './filters' | ||
@@ -29,4 +28,2 @@ /** | ||
): Promise<MeiliSearchResponse<Record<string, any>>> { | ||
const { placeholderSearch, query } = searchContext | ||
// Create cache key containing a unique set of search parameters | ||
@@ -44,4 +41,2 @@ const key = cache.formatKey([ | ||
const cachedFacets = extractFacets(searchContext, searchParams) | ||
// Make search request | ||
@@ -52,15 +47,5 @@ const searchResponse = await client | ||
// Add missing facets back into facetDistribution | ||
searchResponse.facetDistribution = addMissingFacets( | ||
cachedFacets, | ||
searchResponse.facetDistribution | ||
) | ||
// query can be: empty string, undefined or null | ||
// all of them are falsy's | ||
if (!placeholderSearch && !query) { | ||
searchResponse.hits = [] | ||
} | ||
// Cache response | ||
cache.setEntry<MeiliSearchResponse>(key, searchResponse) | ||
return searchResponse | ||
@@ -67,0 +52,0 @@ }, |
@@ -7,10 +7,11 @@ /** | ||
for (let i = 0; i < hits.length; i++) { | ||
const objectID = `${i + Math.random() * 1000000}` | ||
if (hits[i]._geo) { | ||
hits[i]._geoloc = { | ||
lat: hits[i]._geo.lat, | ||
lng: hits[i]._geo.lng, | ||
} | ||
hits[i]._geoloc = hits[i]._geo | ||
hits[i].objectID = objectID | ||
} | ||
hits[i].objectID = `${i + Math.random() * 1000000}` | ||
delete hits[i]._geo | ||
if (hits[i]._formatted?._geo) { | ||
hits[i]._formatted._geoloc = hits[i]._formatted._geo | ||
hits[i]._formatted.objectID = objectID | ||
} | ||
@@ -17,0 +18,0 @@ } |
@@ -5,2 +5,3 @@ import type { | ||
AlgoliaSearchResponse, | ||
FacetDistribution, | ||
} from '../../types' | ||
@@ -10,2 +11,3 @@ import { adaptHits } from './hits-adapter' | ||
import { adaptPaginationParameters } from './pagination-adapter' | ||
import { adaptFacetDistribution } from './facet-distribution-adapter' | ||
@@ -22,7 +24,14 @@ /** | ||
searchResponse: MeiliSearchResponse<Record<string, any>>, | ||
searchContext: SearchContext | ||
): { results: Array<AlgoliaSearchResponse<T>> } { | ||
searchContext: SearchContext, | ||
initialFacetDistribution: FacetDistribution | ||
): AlgoliaSearchResponse<T> { | ||
const searchResponseOptionals: Record<string, any> = {} | ||
const { processingTimeMs, query, facetDistribution: facets } = searchResponse | ||
const { | ||
processingTimeMs, | ||
query, | ||
facetDistribution: responseFacetDistribution, | ||
} = searchResponse | ||
const { keepZeroFacets, facets } = searchContext | ||
const { hitsPerPage, page, nbPages } = adaptPaginationParameters( | ||
@@ -36,2 +45,9 @@ searchResponse, | ||
const facetDistribution = adaptFacetDistribution( | ||
keepZeroFacets, | ||
facets, | ||
initialFacetDistribution, | ||
responseFacetDistribution | ||
) | ||
// Create response object compliant with InstantSearch | ||
@@ -42,3 +58,3 @@ const adaptedSearchResponse = { | ||
page, | ||
facets, | ||
facets: facetDistribution, | ||
nbPages, | ||
@@ -53,5 +69,3 @@ nbHits, | ||
} | ||
return { | ||
results: [adaptedSearchResponse], | ||
} | ||
return adaptedSearchResponse | ||
} |
export * from './search-cache' | ||
export * from './first-facets-distribution' | ||
export * from './init-facets-distribution' |
@@ -16,3 +16,3 @@ import { MeiliSearch } from 'meilisearch' | ||
import { createSearchContext } from '../contexts' | ||
import { SearchCache, cacheFirstFacetDistribution } from '../cache/' | ||
import { SearchCache, initFacetDistribution } from '../cache/' | ||
import { constructClientAgents } from './agents' | ||
@@ -59,3 +59,3 @@ import { validateInstantMeiliSearchParams } from '../utils' | ||
let defaultFacetDistribution: FacetDistribution | ||
let initialFacetDistribution: Record<string, FacetDistribution> = {} | ||
@@ -72,36 +72,40 @@ return { | ||
try { | ||
const searchRequest = instantSearchRequests[0] | ||
const searchContext: SearchContext = createSearchContext( | ||
searchRequest, | ||
instantMeiliSearchOptions, | ||
defaultFacetDistribution | ||
) | ||
const searchResponses: { results: Array<AlgoliaSearchResponse<T>> } = { | ||
results: [], | ||
} | ||
// Adapt search request to Meilisearch compliant search request | ||
const adaptedSearchRequest = adaptSearchParams(searchContext) | ||
const requests = instantSearchRequests | ||
// Cache first facets distribution of the instantMeilisearch instance | ||
// Needed to add in the facetDistribution the fields that were not returned | ||
// When the user sets `keepZeroFacets` to true. | ||
if (defaultFacetDistribution === undefined) { | ||
defaultFacetDistribution = await cacheFirstFacetDistribution( | ||
for (const searchRequest of requests) { | ||
const searchContext: SearchContext = createSearchContext( | ||
searchRequest, | ||
instantMeiliSearchOptions | ||
) | ||
// Adapt search request to Meilisearch compliant search request | ||
const adaptedSearchRequest = adaptSearchParams(searchContext) | ||
initialFacetDistribution = await initFacetDistribution( | ||
searchResolver, | ||
searchContext | ||
searchContext, | ||
initialFacetDistribution | ||
) | ||
searchContext.defaultFacetDistribution = defaultFacetDistribution | ||
} | ||
// Search response from Meilisearch | ||
const searchResponse = await searchResolver.searchResponse( | ||
searchContext, | ||
adaptedSearchRequest | ||
) | ||
// Search response from Meilisearch | ||
const searchResponse = await searchResolver.searchResponse( | ||
searchContext, | ||
adaptedSearchRequest | ||
) | ||
// Adapt the Meilisearch responsne to a compliant instantsearch.js response | ||
const adaptedSearchResponse = adaptSearchResponse<T>( | ||
searchResponse, | ||
searchContext | ||
) | ||
// Adapt the Meilisearch response to a compliant instantsearch.js response | ||
const adaptedSearchResponse = adaptSearchResponse<T>( | ||
searchResponse, | ||
searchContext, | ||
initialFacetDistribution[searchRequest.indexName] | ||
) | ||
return adaptedSearchResponse | ||
searchResponses.results.push(adaptedSearchResponse) | ||
} | ||
return searchResponses | ||
} catch (e: any) { | ||
@@ -108,0 +112,0 @@ console.error(e) |
@@ -5,3 +5,2 @@ import { | ||
SearchContext, | ||
FacetDistribution, | ||
} from '../types' | ||
@@ -18,4 +17,3 @@ | ||
searchRequest: AlgoliaMultipleQueriesQuery, | ||
options: InstantMeiliSearchOptions, | ||
defaultFacetDistribution: FacetDistribution | ||
options: InstantMeiliSearchOptions | ||
): SearchContext { | ||
@@ -38,3 +36,2 @@ // Split index name and possible sorting rules | ||
pagination: paginationState, | ||
defaultFacetDistribution: defaultFacetDistribution || {}, | ||
placeholderSearch: options.placeholderSearch !== false, // true by default | ||
@@ -41,0 +38,0 @@ keepZeroFacets: !!options.keepZeroFacets, // false by default |
@@ -1,1 +0,1 @@ | ||
export const PACKAGE_VERSION = '0.10.0' | ||
export const PACKAGE_VERSION = '0.10.1-multi-index-search.0' |
@@ -1,5 +0,2 @@ | ||
import type { | ||
SearchResponse as MeiliSearchResponse, | ||
FacetDistribution, | ||
} from 'meilisearch' | ||
import type { SearchResponse as MeiliSearchResponse } from 'meilisearch' | ||
import type { SearchClient } from 'instantsearch.js' | ||
@@ -21,11 +18,2 @@ import type { MultipleQueriesQuery as AlgoliaMultipleQueriesQuery } from '@algolia/client-search' | ||
export type FacetsCache = { | ||
[category: string]: string[] | ||
} | ||
export type ParsedFilter = { | ||
filterName: string | ||
value: string | ||
} | ||
export const enum MatchingStrategies { | ||
@@ -77,12 +65,13 @@ ALL = 'all', | ||
export type Facets = string | string[] | undefined | ||
export type SearchContext = Omit<InstantSearchParams, 'insideBoundingBox'> & | ||
InstantSearchParams & { | ||
defaultFacetDistribution: FacetDistribution | ||
pagination: PaginationState | ||
indexUid: string | ||
placeholderSearch: boolean | ||
keepZeroFacets: boolean | ||
insideBoundingBox?: InsideBoundingBox | ||
keepZeroFacets?: boolean | ||
cropMarker?: string | ||
sort?: string | ||
placeholderSearch?: boolean | ||
primaryKey?: string | ||
@@ -89,0 +78,0 @@ matchingStrategy?: MatchingStrategies |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
1079
663960
9434