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

@meilisearch/instant-meilisearch

Package Overview
Dependencies
Maintainers
6
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@meilisearch/instant-meilisearch - npm Package Compare versions

Comparing version 0.5.5 to 0.5.6

dist/types/adapter/search-request-adapter/filter-adapter.d.ts

428

dist/instant-meilisearch.cjs.js

@@ -95,3 +95,3 @@ 'use strict';

* @param {any} str
* @returns boolean
* @returns {boolean}
*/

@@ -103,3 +103,3 @@ function isString(str) {

* @param {string} filter
* @returns string
* @returns {string}
*/

@@ -110,2 +110,11 @@ function replaceColonByEqualSign(filter) {

}
/**
* @param {any[]} arr
* @returns {string}
*/
function stringifyArray(arr) {
return arr.reduce(function (acc, curr) {
return (acc += JSON.stringify(curr));
}, '');
}

@@ -126,2 +135,130 @@ /**

/**
* @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 {FilterCache}
*/
function cacheFilters(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]), _a));
return cache;
}, {});
}
/**
* Assign missing filters to facetsDistribution.
* All facet passed as filter should appear in the facetsDistribution.
* If not present, the facet is added with 0 as value.
*
*
* @param {FilterCache} cache?
* @param {FacetsDistribution} distribution?
* @returns {FacetsDistribution}
*/
function assignMissingFilters(cachedFilters, distribution) {
distribution = distribution || {};
// If cachedFilters contains something
if (cachedFilters && Object.keys(cachedFilters).length > 0) {
// for all filters in cached filters
for (var cachedFacet in cachedFilters) {
// 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 = cachedFilters[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
*/
function SearchResolver(cache) {
return {
/**
* @param {SearchContext} searchContext
* @param {MeiliSearchParams} searchParams
* @param {MeiliSearch} client
* @returns {Promise}
*/
searchResponse: function (searchContext, searchParams, client) {
return __awaiter(this, void 0, void 0, function () {
var key, entry, filterCache, searchResponse;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
key = cache.formatKey([
searchParams,
searchContext.indexUid,
searchContext.query,
]);
entry = cache.getEntry(key);
// Request is cached.
if (entry)
return [2 /*return*/, entry
// Cache filters: todo components
];
filterCache = cacheFilters(searchParams === null || searchParams === void 0 ? void 0 : searchParams.filter);
return [4 /*yield*/, client
.index(searchContext.indexUid)
.search(searchContext.query, searchParams)
// Add facets back into facetsDistribution
];
case 1:
searchResponse = _a.sent();
// Add facets back into facetsDistribution
searchResponse.facetsDistribution = assignMissingFilters(filterCache, searchResponse.facetsDistribution);
// Cache response
cache.setEntry(key, searchResponse);
return [2 /*return*/, searchResponse];
}
});
});
},
};
}
/**
* Transform InstantSearch filter to MeiliSearch filter.

@@ -131,4 +268,4 @@ * Change sign from `:` to `=` in nested filter object.

*
* @param {AlgoliaSearchOptions['facetFilters']} filters?
* @returns Filter
* @param {SearchContext['facetFilters']} filters?
* @returns {Filter}
*/

@@ -158,3 +295,3 @@ function transformFilter(filters) {

* @param {Filter} filter
* @returns Array
* @returns {Array}
*/

@@ -176,3 +313,3 @@ function filterToArray(filter) {

* @param {string} filters
* @returns Filter
* @returns {Filter}
*/

@@ -199,5 +336,5 @@ function mergeFilters(facetFilters, numericFilters, filters) {

* @param {string|undefined} filters
* @param {AlgoliaSearchOptions['numericFilters']} numericFilters
* @param {AlgoliaSearchOptions['facetFilters']} facetFilters
* @returns Filter
* @param {SearchContext['numericFilters']} numericFilters
* @param {SearchContext['facetFilters']} facetFilters
* @returns {Filter}
*/

@@ -214,14 +351,10 @@ function adaptFilters(filters, numericFilters, facetFilters) {

*
* @param {InstantSearchParams} instantSearchParams
* @param {number} paginationTotalHits
* @param {boolean} placeholderSearch
* @param {string} sort?
* @param {string} query?
* @returns MeiliSearchParams
* @param {SearchContext} searchContext
* @returns {MeiliSearchParams}
*/
function adaptSearchRequest(instantSearchParams, paginationTotalHits, placeholderSearch, sort, query) {
function adaptSearchParams(searchContext) {
// Creates search params object compliant with MeiliSearch
var meiliSearchParams = {};
// Facets
var facets = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.facets;
var facets = searchContext === null || searchContext === void 0 ? void 0 : searchContext.facets;
if (facets === null || facets === void 0 ? void 0 : facets.length) {

@@ -231,3 +364,3 @@ meiliSearchParams.facetsDistribution = facets;

// Attributes To Crop
var attributesToCrop = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.attributesToSnippet;
var attributesToCrop = searchContext === null || searchContext === void 0 ? void 0 : searchContext.attributesToSnippet;
if (attributesToCrop) {

@@ -237,3 +370,3 @@ meiliSearchParams.attributesToCrop = attributesToCrop;

// Attributes To Retrieve
var attributesToRetrieve = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.attributesToRetrieve;
var attributesToRetrieve = searchContext === null || searchContext === void 0 ? void 0 : searchContext.attributesToRetrieve;
if (attributesToRetrieve) {

@@ -243,3 +376,3 @@ meiliSearchParams.attributesToRetrieve = attributesToRetrieve;

// Filter
var filter = adaptFilters(instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.filters, instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.numericFilters, instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.facetFilters);
var filter = adaptFilters(searchContext === null || searchContext === void 0 ? void 0 : searchContext.filters, searchContext === null || searchContext === void 0 ? void 0 : searchContext.numericFilters, searchContext === null || searchContext === void 0 ? void 0 : searchContext.facetFilters);
if (filter.length) {

@@ -253,5 +386,8 @@ meiliSearchParams.filter = filter;

// Attributes To Highlight
meiliSearchParams.attributesToHighlight = (instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.attributesToHighlight) || [
meiliSearchParams.attributesToHighlight = (searchContext === null || searchContext === void 0 ? void 0 : searchContext.attributesToHighlight) || [
'*',
];
var placeholderSearch = meiliSearchParams.placeholderSearch;
var query = meiliSearchParams.query;
var paginationTotalHits = meiliSearchParams.paginationTotalHits;
if ((!placeholderSearch && query === '') || paginationTotalHits === 0) {

@@ -263,2 +399,3 @@ meiliSearchParams.limit = 0;

}
var sort = searchContext.sort;
// Sort

@@ -277,3 +414,3 @@ if (sort === null || sort === void 0 ? void 0 : sort.length) {

* @param {number} hitsPerPage
* @returns Array
* @returns {Array}
*/

@@ -292,3 +429,3 @@ function adaptPagination(hits, page, hitsPerPage) {

* @param {string} highlightPostTag?
* @returns string
* @returns {string}
*/

@@ -311,3 +448,3 @@ function replaceHighlightTags(value, highlightPreTag, highlightPostTag) {

* @param {string} highlightPostTag?
* @returns Record
* @returns {Record}
*/

@@ -329,3 +466,3 @@ function adaptHighlight(formattedHit, highlightPreTag, highlightPostTag) {

* @param {string} highlightPostTag?
* @returns string
* @returns {string}
*/

@@ -376,10 +513,10 @@ function snippetValue(value, snippetEllipsisText, highlightPreTag, highlightPostTag) {

* @param {Record<string} formattedHit
* @param {InstantSearchParams} instantSearchParams
* @returns Record
* @param {SearchContext} searchContext
* @returns {Record}
*/
function adaptFormating(formattedHit, instantSearchParams) {
var attributesToSnippet = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.attributesToSnippet;
var snippetEllipsisText = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.snippetEllipsisText;
var highlightPreTag = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.highlightPreTag;
var highlightPostTag = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.highlightPostTag;
function adaptFormating(formattedHit, searchContext) {
var attributesToSnippet = searchContext === null || searchContext === void 0 ? void 0 : searchContext.attributesToSnippet;
var snippetEllipsisText = searchContext === null || searchContext === void 0 ? void 0 : searchContext.snippetEllipsisText;
var highlightPreTag = searchContext === null || searchContext === void 0 ? void 0 : searchContext.highlightPreTag;
var highlightPostTag = searchContext === null || searchContext === void 0 ? void 0 : searchContext.highlightPostTag;
if (!formattedHit || formattedHit.length)

@@ -394,11 +531,11 @@ return {};

/**
* @param {Array<Record<string} meiliSearchHits
* @param {InstantSearchParams} instantSearchParams
* @param {SearchContext} instantMeiliSearchContext
* @returns any
* @param {Array<Record<string} hits
* @param {SearchContext} searchContext
* @param {PaginationContext} paginationContext
* @returns {any}
*/
function adaptHits(meiliSearchHits, instantSearchParams, instantMeiliSearchContext) {
var primaryKey = instantMeiliSearchContext.primaryKey;
var page = instantMeiliSearchContext.page, hitsPerPage = instantMeiliSearchContext.hitsPerPage;
var paginatedHits = adaptPagination(meiliSearchHits, page, hitsPerPage);
function adaptHits(hits, searchContext, paginationContext) {
var primaryKey = searchContext.primaryKey;
var hitsPerPage = paginationContext.hitsPerPage, page = paginationContext.page;
var paginatedHits = adaptPagination(hits, page, hitsPerPage);
return paginatedHits.map(function (hit) {

@@ -408,3 +545,3 @@ // Creates Hit object compliant with InstantSearch

var formattedHit = hit._formatted; hit._matchesInfo; var restOfHit = __rest(hit, ["_formatted", "_matchesInfo"]);
return __assign(__assign(__assign({}, restOfHit), adaptFormating(formattedHit, instantSearchParams)), (primaryKey && { objectID: hit[primaryKey] }));
return __assign(__assign(__assign({}, restOfHit), adaptFormating(formattedHit, searchContext)), (primaryKey && { objectID: hit[primaryKey] }));
}

@@ -419,9 +556,8 @@ return hit;

*
* @param {string} indexUid
* @param {MeiliSearchResponse<Record<string} searchResponse
* @param {InstantSearchParams} instantSearchParams
* @param {SearchContext} instantMeiliSearchContext
* @returns Array
* @param {SearchContext} searchContext
* @param {PaginationContext} paginationContext
* @returns {{ results: Array<AlgoliaSearchResponse<T>> }}
*/
function adaptSearchResponse(indexUid, searchResponse, instantSearchParams, instantMeiliSearchContext) {
function adaptSearchResponse(searchResponse, searchContext, paginationContext) {
var searchResponseOptionals = {};

@@ -433,4 +569,4 @@ var facets = searchResponse.facetsDistribution;

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

@@ -440,5 +576,5 @@ var nbHits = searchResponse.nbHits;

var query = searchResponse.query;
var hitsPerPage = instantMeiliSearchContext.hitsPerPage, page = instantMeiliSearchContext.page;
var hitsPerPage = paginationContext.hitsPerPage, page = paginationContext.page;
// Create response object compliant with InstantSearch
var adaptedSearchResponse = __assign({ index: indexUid, hitsPerPage: hitsPerPage, page: page, facets: facets, nbPages: nbPages, exhaustiveNbHits: exhaustiveNbHits, nbHits: nbHits, processingTimeMS: processingTimeMs, query: query, hits: hits, params: '' }, searchResponseOptionals);
var adaptedSearchResponse = __assign({ index: searchContext.indexUid, hitsPerPage: hitsPerPage, page: page, facets: facets, nbPages: nbPages, exhaustiveNbHits: exhaustiveNbHits, nbHits: nbHits, processingTimeMS: processingTimeMs, query: query, hits: hits, params: '' }, searchResponseOptionals);
return {

@@ -450,108 +586,30 @@ results: [adaptedSearchResponse],

/**
* Adapt MeiliSearch facetsDistribution to instantsearch.js facetsDistribution
* by completing the list of distribution with the facets that are checked in the components.
*
* To be aware of which field are checked a cache is provided that was made prior of the search request.
*
* @param {Cache} cache?
* @param {FacetsDistribution} distribution?
* @returns FacetsDistribution
* @param {Record<string} cache
* @returns {SearchCache}
*/
function facetsDistributionAdapter(cache, distribution) {
distribution = distribution || {};
if (cache && Object.keys(cache).length > 0) {
for (var cachedFacet in cache) {
for (var _i = 0, _a = cache[cachedFacet]; _i < _a.length; _i++) {
var cachedField = _a[_i];
// if cached field is not present in the returned distribution
if (!distribution[cachedFacet] ||
!Object.keys(distribution[cachedFacet]).includes(cachedField)) {
// add 0 value
distribution[cachedFacet] = distribution[cachedFacet] || {};
distribution[cachedFacet][cachedField] = 0;
function SearchCache(cache) {
if (cache === void 0) { cache = {}; }
var searchCache = cache;
return {
getEntry: function (key) {
if (searchCache[key]) {
try {
return JSON.parse(searchCache[key]);
}
catch (_) {
return searchCache[key];
}
}
}
}
return distribution;
return undefined;
},
formatKey: function (components) {
return stringifyArray(components);
},
setEntry: function (key, searchResponse) {
searchCache[key] = JSON.stringify(searchResponse);
},
};
}
/**
* @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 [undefined];
};
/**
* @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 [undefined];
}
/**
* @param {Filter} filters?
* @returns Cache
*/
function cacheFilters(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]), _a));
return cache;
}, {});
}
/**
* Create search context.
*
* @param {string} indexName
* @param {InstantSearchParams} params
* @param {InstantMeiliSearchOptions={}} meiliSearchOptions
* @param {MeiliSearch} MeiliSearchClient
* @returns SearchContext
*/
function createContext(indexName, params, meiliSearchOptions, MeiliSearchClient) {
if (meiliSearchOptions === void 0) { meiliSearchOptions = {}; }
var paginationTotalHits = meiliSearchOptions.paginationTotalHits, primaryKey = meiliSearchOptions.primaryKey, placeholderSearch = meiliSearchOptions.placeholderSearch;
var page = params === null || params === void 0 ? void 0 : params.page;
var hitsPerPage = params === null || params === void 0 ? void 0 : params.hitsPerPage;
var query = params === null || params === void 0 ? void 0 : params.query;
// Split index name and possible sorting rules
var _a = indexName.split(':'), indexUid = _a[0], sortByArray = _a.slice(1);
var context = {
client: MeiliSearchClient,
indexUid: indexUid,
paginationTotalHits: paginationTotalHits || 200,
primaryKey: primaryKey || undefined,
placeholderSearch: placeholderSearch !== false,
hitsPerPage: hitsPerPage === undefined ? 20 : hitsPerPage,
page: page || 0,
sort: sortByArray.join(':') || '',
query: query,
};
return context;
}
/**
* Instanciate SearchClient required by instantsearch.js.

@@ -562,13 +620,23 @@ *

* @param {InstantMeiliSearchOptions={}} meiliSearchOptions
* @returns InstantMeiliSearchInstance
* @returns {InstantMeiliSearchInstance}
*/
function instantMeiliSearch(hostUrl, apiKey, meiliSearchOptions) {
if (meiliSearchOptions === void 0) { meiliSearchOptions = {}; }
function instantMeiliSearch(hostUrl, apiKey, options) {
if (apiKey === void 0) { apiKey = ''; }
if (options === void 0) { options = {}; }
// create search resolver with included cache
var searchResolver = SearchResolver(SearchCache());
var context = {
primaryKey: options.primaryKey || undefined,
placeholderSearch: options.placeholderSearch !== false,
paginationTotalHits: options.paginationTotalHits || 200,
};
return {
MeiliSearchClient: new meilisearch.MeiliSearch({ host: hostUrl, apiKey: apiKey }),
search: function (instantSearchRequests
// options?: RequestOptions & MultipleQueriesOptions - When is this used ?
) {
/**
* @param {readonlyAlgoliaMultipleQueriesQuery[]} instantSearchRequests
* @returns {Array}
*/
search: function (instantSearchRequests) {
return __awaiter(this, void 0, void 0, function () {
var searchRequest, instantSearchParams, context, adaptedSearchRequest, cachedFacet, searchResponse, adaptedSearchResponse, e_1;
var searchRequest, instantSearchParams, searchContext, paginationContext, adaptedSearchRequest, searchResponse, adaptedSearchResponse, e_1;
return __generator(this, function (_a) {

@@ -580,15 +648,11 @@ switch (_a.label) {

instantSearchParams = searchRequest.params;
context = createContext(searchRequest.indexName, instantSearchParams, meiliSearchOptions, this.MeiliSearchClient);
adaptedSearchRequest = adaptSearchRequest(instantSearchParams, context.paginationTotalHits, context.placeholderSearch, context.sort, context.query);
cachedFacet = cacheFilters(adaptedSearchRequest === null || adaptedSearchRequest === void 0 ? void 0 : adaptedSearchRequest.filter);
return [4 /*yield*/, context.client
.index(context.indexUid)
.search(context.query, adaptedSearchRequest)
// Add the checked facet attributes in facetsDistribution and give them a value of 0
searchContext = createSearchContext(searchRequest, context);
paginationContext = createPaginationContext(searchContext, instantSearchParams);
adaptedSearchRequest = adaptSearchParams(searchContext);
return [4 /*yield*/, searchResolver.searchResponse(searchContext, adaptedSearchRequest, this.MeiliSearchClient)
// Adapt the MeiliSearch responsne to a compliant instantsearch.js response
];
case 1:
searchResponse = _a.sent();
// Add the checked facet attributes in facetsDistribution and give them a value of 0
searchResponse.facetsDistribution = facetsDistributionAdapter(cachedFacet, searchResponse.facetsDistribution);
adaptedSearchResponse = adaptSearchResponse(context.indexUid, searchResponse, instantSearchParams, context);
adaptedSearchResponse = adaptSearchResponse(searchResponse, searchContext, paginationContext);
return [2 /*return*/, adaptedSearchResponse];

@@ -619,9 +683,27 @@ case 2:

}
/**
* @param {AlgoliaMultipleQueriesQuery} searchRequest
* @param {Context} options
* @returns {SearchContext}
*/
function createSearchContext(searchRequest, options) {
// Split index name and possible sorting rules
var _a = searchRequest.indexName.split(':'), indexUid = _a[0], sortByArray = _a.slice(1);
var instantSearchParams = searchRequest.params;
var searchContext = __assign(__assign(__assign({}, options), instantSearchParams), { sort: sortByArray.join(':') || '', indexUid: indexUid });
return searchContext;
}
/**
* @param {AlgoliaMultipleQueriesQuery} searchRequest
* @param {Context} options
* @returns {SearchContext}
*/
function createPaginationContext(searchContext, params) {
return {
paginationTotalHits: searchContext.paginationTotalHits || 200,
hitsPerPage: searchContext.hitsPerPage === undefined ? 20 : searchContext.hitsPerPage,
page: (params === null || params === void 0 ? void 0 : params.page) || 0, // default page is 0 if none is provided
};
}
exports.adaptFormating = adaptFormating;
exports.adaptHits = adaptHits;
exports.adaptPagination = adaptPagination;
exports.adaptSearchRequest = adaptSearchRequest;
exports.adaptSearchResponse = adaptSearchResponse;
exports.facetsDistributionAdapter = facetsDistributionAdapter;
exports.instantMeiliSearch = instantMeiliSearch;

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

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

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

* @param {any} str
* @returns boolean
* @returns {boolean}
*/

@@ -99,3 +99,3 @@ function isString(str) {

* @param {string} filter
* @returns string
* @returns {string}
*/

@@ -106,2 +106,11 @@ function replaceColonByEqualSign(filter) {

}
/**
* @param {any[]} arr
* @returns {string}
*/
function stringifyArray(arr) {
return arr.reduce(function (acc, curr) {
return (acc += JSON.stringify(curr));
}, '');
}

@@ -122,2 +131,130 @@ /**

/**
* @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 {FilterCache}
*/
function cacheFilters(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]), _a));
return cache;
}, {});
}
/**
* Assign missing filters to facetsDistribution.
* All facet passed as filter should appear in the facetsDistribution.
* If not present, the facet is added with 0 as value.
*
*
* @param {FilterCache} cache?
* @param {FacetsDistribution} distribution?
* @returns {FacetsDistribution}
*/
function assignMissingFilters(cachedFilters, distribution) {
distribution = distribution || {};
// If cachedFilters contains something
if (cachedFilters && Object.keys(cachedFilters).length > 0) {
// for all filters in cached filters
for (var cachedFacet in cachedFilters) {
// 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 = cachedFilters[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
*/
function SearchResolver(cache) {
return {
/**
* @param {SearchContext} searchContext
* @param {MeiliSearchParams} searchParams
* @param {MeiliSearch} client
* @returns {Promise}
*/
searchResponse: function (searchContext, searchParams, client) {
return __awaiter(this, void 0, void 0, function () {
var key, entry, filterCache, searchResponse;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
key = cache.formatKey([
searchParams,
searchContext.indexUid,
searchContext.query,
]);
entry = cache.getEntry(key);
// Request is cached.
if (entry)
return [2 /*return*/, entry
// Cache filters: todo components
];
filterCache = cacheFilters(searchParams === null || searchParams === void 0 ? void 0 : searchParams.filter);
return [4 /*yield*/, client
.index(searchContext.indexUid)
.search(searchContext.query, searchParams)
// Add facets back into facetsDistribution
];
case 1:
searchResponse = _a.sent();
// Add facets back into facetsDistribution
searchResponse.facetsDistribution = assignMissingFilters(filterCache, searchResponse.facetsDistribution);
// Cache response
cache.setEntry(key, searchResponse);
return [2 /*return*/, searchResponse];
}
});
});
},
};
}
/**
* Transform InstantSearch filter to MeiliSearch filter.

@@ -127,4 +264,4 @@ * Change sign from `:` to `=` in nested filter object.

*
* @param {AlgoliaSearchOptions['facetFilters']} filters?
* @returns Filter
* @param {SearchContext['facetFilters']} filters?
* @returns {Filter}
*/

@@ -154,3 +291,3 @@ function transformFilter(filters) {

* @param {Filter} filter
* @returns Array
* @returns {Array}
*/

@@ -172,3 +309,3 @@ function filterToArray(filter) {

* @param {string} filters
* @returns Filter
* @returns {Filter}
*/

@@ -195,5 +332,5 @@ function mergeFilters(facetFilters, numericFilters, filters) {

* @param {string|undefined} filters
* @param {AlgoliaSearchOptions['numericFilters']} numericFilters
* @param {AlgoliaSearchOptions['facetFilters']} facetFilters
* @returns Filter
* @param {SearchContext['numericFilters']} numericFilters
* @param {SearchContext['facetFilters']} facetFilters
* @returns {Filter}
*/

@@ -210,14 +347,10 @@ function adaptFilters(filters, numericFilters, facetFilters) {

*
* @param {InstantSearchParams} instantSearchParams
* @param {number} paginationTotalHits
* @param {boolean} placeholderSearch
* @param {string} sort?
* @param {string} query?
* @returns MeiliSearchParams
* @param {SearchContext} searchContext
* @returns {MeiliSearchParams}
*/
function adaptSearchRequest(instantSearchParams, paginationTotalHits, placeholderSearch, sort, query) {
function adaptSearchParams(searchContext) {
// Creates search params object compliant with MeiliSearch
var meiliSearchParams = {};
// Facets
var facets = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.facets;
var facets = searchContext === null || searchContext === void 0 ? void 0 : searchContext.facets;
if (facets === null || facets === void 0 ? void 0 : facets.length) {

@@ -227,3 +360,3 @@ meiliSearchParams.facetsDistribution = facets;

// Attributes To Crop
var attributesToCrop = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.attributesToSnippet;
var attributesToCrop = searchContext === null || searchContext === void 0 ? void 0 : searchContext.attributesToSnippet;
if (attributesToCrop) {

@@ -233,3 +366,3 @@ meiliSearchParams.attributesToCrop = attributesToCrop;

// Attributes To Retrieve
var attributesToRetrieve = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.attributesToRetrieve;
var attributesToRetrieve = searchContext === null || searchContext === void 0 ? void 0 : searchContext.attributesToRetrieve;
if (attributesToRetrieve) {

@@ -239,3 +372,3 @@ meiliSearchParams.attributesToRetrieve = attributesToRetrieve;

// Filter
var filter = adaptFilters(instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.filters, instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.numericFilters, instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.facetFilters);
var filter = adaptFilters(searchContext === null || searchContext === void 0 ? void 0 : searchContext.filters, searchContext === null || searchContext === void 0 ? void 0 : searchContext.numericFilters, searchContext === null || searchContext === void 0 ? void 0 : searchContext.facetFilters);
if (filter.length) {

@@ -249,5 +382,8 @@ meiliSearchParams.filter = filter;

// Attributes To Highlight
meiliSearchParams.attributesToHighlight = (instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.attributesToHighlight) || [
meiliSearchParams.attributesToHighlight = (searchContext === null || searchContext === void 0 ? void 0 : searchContext.attributesToHighlight) || [
'*',
];
var placeholderSearch = meiliSearchParams.placeholderSearch;
var query = meiliSearchParams.query;
var paginationTotalHits = meiliSearchParams.paginationTotalHits;
if ((!placeholderSearch && query === '') || paginationTotalHits === 0) {

@@ -259,2 +395,3 @@ meiliSearchParams.limit = 0;

}
var sort = searchContext.sort;
// Sort

@@ -273,3 +410,3 @@ if (sort === null || sort === void 0 ? void 0 : sort.length) {

* @param {number} hitsPerPage
* @returns Array
* @returns {Array}
*/

@@ -288,3 +425,3 @@ function adaptPagination(hits, page, hitsPerPage) {

* @param {string} highlightPostTag?
* @returns string
* @returns {string}
*/

@@ -307,3 +444,3 @@ function replaceHighlightTags(value, highlightPreTag, highlightPostTag) {

* @param {string} highlightPostTag?
* @returns Record
* @returns {Record}
*/

@@ -325,3 +462,3 @@ function adaptHighlight(formattedHit, highlightPreTag, highlightPostTag) {

* @param {string} highlightPostTag?
* @returns string
* @returns {string}
*/

@@ -372,10 +509,10 @@ function snippetValue(value, snippetEllipsisText, highlightPreTag, highlightPostTag) {

* @param {Record<string} formattedHit
* @param {InstantSearchParams} instantSearchParams
* @returns Record
* @param {SearchContext} searchContext
* @returns {Record}
*/
function adaptFormating(formattedHit, instantSearchParams) {
var attributesToSnippet = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.attributesToSnippet;
var snippetEllipsisText = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.snippetEllipsisText;
var highlightPreTag = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.highlightPreTag;
var highlightPostTag = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.highlightPostTag;
function adaptFormating(formattedHit, searchContext) {
var attributesToSnippet = searchContext === null || searchContext === void 0 ? void 0 : searchContext.attributesToSnippet;
var snippetEllipsisText = searchContext === null || searchContext === void 0 ? void 0 : searchContext.snippetEllipsisText;
var highlightPreTag = searchContext === null || searchContext === void 0 ? void 0 : searchContext.highlightPreTag;
var highlightPostTag = searchContext === null || searchContext === void 0 ? void 0 : searchContext.highlightPostTag;
if (!formattedHit || formattedHit.length)

@@ -390,11 +527,11 @@ return {};

/**
* @param {Array<Record<string} meiliSearchHits
* @param {InstantSearchParams} instantSearchParams
* @param {SearchContext} instantMeiliSearchContext
* @returns any
* @param {Array<Record<string} hits
* @param {SearchContext} searchContext
* @param {PaginationContext} paginationContext
* @returns {any}
*/
function adaptHits(meiliSearchHits, instantSearchParams, instantMeiliSearchContext) {
var primaryKey = instantMeiliSearchContext.primaryKey;
var page = instantMeiliSearchContext.page, hitsPerPage = instantMeiliSearchContext.hitsPerPage;
var paginatedHits = adaptPagination(meiliSearchHits, page, hitsPerPage);
function adaptHits(hits, searchContext, paginationContext) {
var primaryKey = searchContext.primaryKey;
var hitsPerPage = paginationContext.hitsPerPage, page = paginationContext.page;
var paginatedHits = adaptPagination(hits, page, hitsPerPage);
return paginatedHits.map(function (hit) {

@@ -404,3 +541,3 @@ // Creates Hit object compliant with InstantSearch

var formattedHit = hit._formatted; hit._matchesInfo; var restOfHit = __rest(hit, ["_formatted", "_matchesInfo"]);
return __assign(__assign(__assign({}, restOfHit), adaptFormating(formattedHit, instantSearchParams)), (primaryKey && { objectID: hit[primaryKey] }));
return __assign(__assign(__assign({}, restOfHit), adaptFormating(formattedHit, searchContext)), (primaryKey && { objectID: hit[primaryKey] }));
}

@@ -415,9 +552,8 @@ return hit;

*
* @param {string} indexUid
* @param {MeiliSearchResponse<Record<string} searchResponse
* @param {InstantSearchParams} instantSearchParams
* @param {SearchContext} instantMeiliSearchContext
* @returns Array
* @param {SearchContext} searchContext
* @param {PaginationContext} paginationContext
* @returns {{ results: Array<AlgoliaSearchResponse<T>> }}
*/
function adaptSearchResponse(indexUid, searchResponse, instantSearchParams, instantMeiliSearchContext) {
function adaptSearchResponse(searchResponse, searchContext, paginationContext) {
var searchResponseOptionals = {};

@@ -429,4 +565,4 @@ var facets = searchResponse.facetsDistribution;

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

@@ -436,5 +572,5 @@ var nbHits = searchResponse.nbHits;

var query = searchResponse.query;
var hitsPerPage = instantMeiliSearchContext.hitsPerPage, page = instantMeiliSearchContext.page;
var hitsPerPage = paginationContext.hitsPerPage, page = paginationContext.page;
// Create response object compliant with InstantSearch
var adaptedSearchResponse = __assign({ index: indexUid, hitsPerPage: hitsPerPage, page: page, facets: facets, nbPages: nbPages, exhaustiveNbHits: exhaustiveNbHits, nbHits: nbHits, processingTimeMS: processingTimeMs, query: query, hits: hits, params: '' }, searchResponseOptionals);
var adaptedSearchResponse = __assign({ index: searchContext.indexUid, hitsPerPage: hitsPerPage, page: page, facets: facets, nbPages: nbPages, exhaustiveNbHits: exhaustiveNbHits, nbHits: nbHits, processingTimeMS: processingTimeMs, query: query, hits: hits, params: '' }, searchResponseOptionals);
return {

@@ -446,108 +582,30 @@ results: [adaptedSearchResponse],

/**
* Adapt MeiliSearch facetsDistribution to instantsearch.js facetsDistribution
* by completing the list of distribution with the facets that are checked in the components.
*
* To be aware of which field are checked a cache is provided that was made prior of the search request.
*
* @param {Cache} cache?
* @param {FacetsDistribution} distribution?
* @returns FacetsDistribution
* @param {Record<string} cache
* @returns {SearchCache}
*/
function facetsDistributionAdapter(cache, distribution) {
distribution = distribution || {};
if (cache && Object.keys(cache).length > 0) {
for (var cachedFacet in cache) {
for (var _i = 0, _a = cache[cachedFacet]; _i < _a.length; _i++) {
var cachedField = _a[_i];
// if cached field is not present in the returned distribution
if (!distribution[cachedFacet] ||
!Object.keys(distribution[cachedFacet]).includes(cachedField)) {
// add 0 value
distribution[cachedFacet] = distribution[cachedFacet] || {};
distribution[cachedFacet][cachedField] = 0;
function SearchCache(cache) {
if (cache === void 0) { cache = {}; }
var searchCache = cache;
return {
getEntry: function (key) {
if (searchCache[key]) {
try {
return JSON.parse(searchCache[key]);
}
catch (_) {
return searchCache[key];
}
}
}
}
return distribution;
return undefined;
},
formatKey: function (components) {
return stringifyArray(components);
},
setEntry: function (key, searchResponse) {
searchCache[key] = JSON.stringify(searchResponse);
},
};
}
/**
* @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 [undefined];
};
/**
* @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 [undefined];
}
/**
* @param {Filter} filters?
* @returns Cache
*/
function cacheFilters(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]), _a));
return cache;
}, {});
}
/**
* Create search context.
*
* @param {string} indexName
* @param {InstantSearchParams} params
* @param {InstantMeiliSearchOptions={}} meiliSearchOptions
* @param {MeiliSearch} MeiliSearchClient
* @returns SearchContext
*/
function createContext(indexName, params, meiliSearchOptions, MeiliSearchClient) {
if (meiliSearchOptions === void 0) { meiliSearchOptions = {}; }
var paginationTotalHits = meiliSearchOptions.paginationTotalHits, primaryKey = meiliSearchOptions.primaryKey, placeholderSearch = meiliSearchOptions.placeholderSearch;
var page = params === null || params === void 0 ? void 0 : params.page;
var hitsPerPage = params === null || params === void 0 ? void 0 : params.hitsPerPage;
var query = params === null || params === void 0 ? void 0 : params.query;
// Split index name and possible sorting rules
var _a = indexName.split(':'), indexUid = _a[0], sortByArray = _a.slice(1);
var context = {
client: MeiliSearchClient,
indexUid: indexUid,
paginationTotalHits: paginationTotalHits || 200,
primaryKey: primaryKey || undefined,
placeholderSearch: placeholderSearch !== false,
hitsPerPage: hitsPerPage === undefined ? 20 : hitsPerPage,
page: page || 0,
sort: sortByArray.join(':') || '',
query: query,
};
return context;
}
/**
* Instanciate SearchClient required by instantsearch.js.

@@ -558,13 +616,23 @@ *

* @param {InstantMeiliSearchOptions={}} meiliSearchOptions
* @returns InstantMeiliSearchInstance
* @returns {InstantMeiliSearchInstance}
*/
function instantMeiliSearch(hostUrl, apiKey, meiliSearchOptions) {
if (meiliSearchOptions === void 0) { meiliSearchOptions = {}; }
function instantMeiliSearch(hostUrl, apiKey, options) {
if (apiKey === void 0) { apiKey = ''; }
if (options === void 0) { options = {}; }
// create search resolver with included cache
var searchResolver = SearchResolver(SearchCache());
var context = {
primaryKey: options.primaryKey || undefined,
placeholderSearch: options.placeholderSearch !== false,
paginationTotalHits: options.paginationTotalHits || 200,
};
return {
MeiliSearchClient: new MeiliSearch({ host: hostUrl, apiKey: apiKey }),
search: function (instantSearchRequests
// options?: RequestOptions & MultipleQueriesOptions - When is this used ?
) {
/**
* @param {readonlyAlgoliaMultipleQueriesQuery[]} instantSearchRequests
* @returns {Array}
*/
search: function (instantSearchRequests) {
return __awaiter(this, void 0, void 0, function () {
var searchRequest, instantSearchParams, context, adaptedSearchRequest, cachedFacet, searchResponse, adaptedSearchResponse, e_1;
var searchRequest, instantSearchParams, searchContext, paginationContext, adaptedSearchRequest, searchResponse, adaptedSearchResponse, e_1;
return __generator(this, function (_a) {

@@ -576,15 +644,11 @@ switch (_a.label) {

instantSearchParams = searchRequest.params;
context = createContext(searchRequest.indexName, instantSearchParams, meiliSearchOptions, this.MeiliSearchClient);
adaptedSearchRequest = adaptSearchRequest(instantSearchParams, context.paginationTotalHits, context.placeholderSearch, context.sort, context.query);
cachedFacet = cacheFilters(adaptedSearchRequest === null || adaptedSearchRequest === void 0 ? void 0 : adaptedSearchRequest.filter);
return [4 /*yield*/, context.client
.index(context.indexUid)
.search(context.query, adaptedSearchRequest)
// Add the checked facet attributes in facetsDistribution and give them a value of 0
searchContext = createSearchContext(searchRequest, context);
paginationContext = createPaginationContext(searchContext, instantSearchParams);
adaptedSearchRequest = adaptSearchParams(searchContext);
return [4 /*yield*/, searchResolver.searchResponse(searchContext, adaptedSearchRequest, this.MeiliSearchClient)
// Adapt the MeiliSearch responsne to a compliant instantsearch.js response
];
case 1:
searchResponse = _a.sent();
// Add the checked facet attributes in facetsDistribution and give them a value of 0
searchResponse.facetsDistribution = facetsDistributionAdapter(cachedFacet, searchResponse.facetsDistribution);
adaptedSearchResponse = adaptSearchResponse(context.indexUid, searchResponse, instantSearchParams, context);
adaptedSearchResponse = adaptSearchResponse(searchResponse, searchContext, paginationContext);
return [2 /*return*/, adaptedSearchResponse];

@@ -615,3 +679,27 @@ case 2:

}
/**
* @param {AlgoliaMultipleQueriesQuery} searchRequest
* @param {Context} options
* @returns {SearchContext}
*/
function createSearchContext(searchRequest, options) {
// Split index name and possible sorting rules
var _a = searchRequest.indexName.split(':'), indexUid = _a[0], sortByArray = _a.slice(1);
var instantSearchParams = searchRequest.params;
var searchContext = __assign(__assign(__assign({}, options), instantSearchParams), { sort: sortByArray.join(':') || '', indexUid: indexUid });
return searchContext;
}
/**
* @param {AlgoliaMultipleQueriesQuery} searchRequest
* @param {Context} options
* @returns {SearchContext}
*/
function createPaginationContext(searchContext, params) {
return {
paginationTotalHits: searchContext.paginationTotalHits || 200,
hitsPerPage: searchContext.hitsPerPage === undefined ? 20 : searchContext.hitsPerPage,
page: (params === null || params === void 0 ? void 0 : params.page) || 0, // default page is 0 if none is provided
};
}
export { adaptFormating, adaptHits, adaptPagination, adaptSearchRequest, adaptSearchResponse, facetsDistributionAdapter, instantMeiliSearch };
export { instantMeiliSearch };

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

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

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

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

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

***************************************************************************** */
var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,r)};function r(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var n=function(){return(n=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function i(t,e,r,n){function i(t){return t instanceof r?t:new r((function(e){e(t)}))}return new(r||(r=Promise))((function(r,s){function o(t){try{a(n.next(t))}catch(t){s(t)}}function u(t){try{a(n.throw(t))}catch(t){s(t)}}function a(t){t.done?r(t.value):i(t.value).then(o,u)}a((n=n.apply(t,e||[])).next())}))}function s(t,e){var r,n,i,s,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(t){return function(e){return a([t,e])}}function a(s){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,n=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}}var o=function(t){function e(r,n){var i=t.call(this,r)||this;return i.name="MeiliSearchCommunicationError",i.type="MeiliSearchCommunicationError",n instanceof Response&&(i.message=n.statusText,i.statusCode=n.status),n instanceof Error&&(i.errno=n.errno,i.code=n.code),Error.captureStackTrace&&Error.captureStackTrace(i,e),i}return r(e,t),e}(Error),u=function(t){function e(e,r){var n=t.call(this,e.message)||this;return n.type="MeiliSearchApiError",n.name="MeiliSearchApiError",n.errorCode=e.errorCode,n.errorType=e.errorType,n.errorLink=e.errorLink,n.message=e.message,n.httpStatus=r,n}return r(e,t),e}(Error);function a(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:if(t.ok)return[3,5];e=void 0,r.label=1;case 1:return r.trys.push([1,3,,4]),[4,t.json()];case 2:return e=r.sent(),[3,4];case 3:throw r.sent(),new o(t.statusText,t);case 4:throw new u(e,t.status);case 5:return[2,t]}}))}))}function c(t){if("MeiliSearchApiError"!==t.type)throw new o(t.message,t);throw t}var h=function(t){function e(r){var n=t.call(this,r)||this;return n.name="MeiliSearchError",n.type="MeiliSearchError",Error.captureStackTrace&&Error.captureStackTrace(n,e),n}return r(e,t),e}(Error),l=function(t){function e(r){var n=t.call(this,r)||this;return n.name="MeiliSearchTimeOutError",n.type=n.constructor.name,Error.captureStackTrace&&Error.captureStackTrace(n,e),n}return r(e,t),e}(Error),d=function(){function t(t){this.headers=n(n(n({},t.headers||{}),{"Content-Type":"application/json"}),t.apiKey?{"X-Meili-API-Key":t.apiKey}:{}),this.url=new URL(t.host)}return t.addTrailingSlash=function(t){return t.endsWith("/")||(t+="/"),t},t.prototype.request=function(t){var e=t.method,r=t.url,o=t.params,u=t.body,h=t.config;return i(this,void 0,void 0,(function(){var t,i,l;return s(this,(function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),t=new URL(r,this.url),o&&(i=new URLSearchParams,Object.keys(o).filter((function(t){return null!==o[t]})).map((function(t){return i.set(t,o[t])})),t.search=i.toString()),[4,fetch(t.toString(),n(n({},h),{method:e,body:JSON.stringify(u),headers:this.headers})).then((function(t){return a(t)}))];case 1:return[4,s.sent().text()];case 2:l=s.sent();try{return[2,JSON.parse(l)]}catch(t){return[2]}return[3,4];case 3:return c(s.sent()),[3,4];case 4:return[2]}}))}))},t.prototype.get=function(t,e,r){return i(this,void 0,void 0,(function(){return s(this,(function(n){switch(n.label){case 0:return[4,this.request({method:"GET",url:t,params:e,config:r})];case 1:return[2,n.sent()]}}))}))},t.prototype.post=function(t,e,r,n){return i(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"POST",url:t,body:e,params:r,config:n})];case 1:return[2,i.sent()]}}))}))},t.prototype.put=function(t,e,r,n){return i(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"PUT",url:t,body:e,params:r,config:n})];case 1:return[2,i.sent()]}}))}))},t.prototype.delete=function(t,e,r,n){return i(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"DELETE",url:t,body:e,params:r,config:n})];case 1:return[2,i.sent()]}}))}))},t}();function f(t){return Object.entries(t).reduce((function(t,e){var r=e[0],n=e[1];return void 0!==n&&(t[r]=n),t}),{})}function p(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,new Promise((function(e){return setTimeout(e,t)}))];case 1:return[2,e.sent()]}}))}))}var v=function(){function t(t,e,r){this.uid=e,this.primaryKey=r,this.httpRequest=new d(t)}return t.prototype.waitForPendingUpdate=function(t,e){var r=void 0===e?{}:e,n=r.timeOutMs,o=void 0===n?5e3:n,u=r.intervalMs,a=void 0===u?50:u;return i(this,void 0,void 0,(function(){var e,r;return s(this,(function(n){switch(n.label){case 0:e=Date.now(),n.label=1;case 1:return Date.now()-e<o?[4,this.getUpdateStatus(t)]:[3,4];case 2:return r=n.sent(),["enqueued","processing"].includes(r.status)?[4,p(a)]:[2,r];case 3:return n.sent(),[3,1];case 4:throw new l("timeout of "+o+"ms has exceeded on process "+t+" when waiting for pending update to resolve.")}}))}))},t.prototype.search=function(t,e,r){return i(this,void 0,void 0,(function(){var i;return s(this,(function(s){switch(s.label){case 0:return i="indexes/"+this.uid+"/search",[4,this.httpRequest.post(i,f(n(n({},e),{q:t})),void 0,r)];case 1:return[2,s.sent()]}}))}))},t.prototype.searchGet=function(t,e,r){return i(this,void 0,void 0,(function(){var i,o,u;return s(this,(function(s){switch(s.label){case 0:return i="indexes/"+this.uid+"/search",o=function(t){if("string"==typeof t)return t;if(Array.isArray(t))throw new h("The filter query parameter should be in string format when using searchGet")},u=n(n({q:t},e),{filter:o(null==e?void 0:e.filter),sort:(null==e?void 0:e.sort)?e.sort.join(","):void 0,facetsDistribution:(null==e?void 0:e.facetsDistribution)?e.facetsDistribution.join(","):void 0,attributesToRetrieve:(null==e?void 0:e.attributesToRetrieve)?e.attributesToRetrieve.join(","):void 0,attributesToCrop:(null==e?void 0:e.attributesToCrop)?e.attributesToCrop.join(","):void 0,attributesToHighlight:(null==e?void 0:e.attributesToHighlight)?e.attributesToHighlight.join(","):void 0}),[4,this.httpRequest.get(i,f(u),r)];case 1:return[2,s.sent()]}}))}))},t.prototype.getRawInfo=function(){return i(this,void 0,void 0,(function(){var t,e;return s(this,(function(r){switch(r.label){case 0:return t="indexes/"+this.uid,[4,this.httpRequest.get(t)];case 1:return e=r.sent(),this.primaryKey=e.primaryKey,[2,e]}}))}))},t.prototype.fetchInfo=function(){return i(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.getRawInfo()];case 1:return t.sent(),[2,this]}}))}))},t.prototype.fetchPrimaryKey=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t=this,[4,this.getRawInfo()];case 1:return t.primaryKey=e.sent().primaryKey,[2,this.primaryKey]}}))}))},t.create=function(e,r,o){return void 0===o&&(o={}),i(this,void 0,void 0,(function(){var i,u;return s(this,(function(s){switch(s.label){case 0:return i="indexes",[4,new d(e).post(i,n(n({},o),{uid:r}))];case 1:return u=s.sent(),[2,new t(e,r,u.primaryKey)]}}))}))},t.prototype.update=function(t){return i(this,void 0,void 0,(function(){var e,r;return s(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid,[4,this.httpRequest.put(e,t)];case 1:return r=n.sent(),this.primaryKey=r.primaryKey,[2,this]}}))}))},t.prototype.delete=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid,[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.deleteIfExists=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.delete()];case 1:return e.sent(),[2,!0];case 2:if("index_not_found"===(t=e.sent()).errorCode)return[2,!1];throw t;case 3:return[2]}}))}))},t.prototype.getAllUpdateStatus=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/updates",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getUpdateStatus=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/updates/"+t,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getStats=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/stats",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDocuments=function(t){return i(this,void 0,void 0,(function(){var e,r;return s(this,(function(i){switch(i.label){case 0:return e="indexes/"+this.uid+"/documents",void 0!==t&&Array.isArray(t.attributesToRetrieve)&&(r=t.attributesToRetrieve.join(",")),[4,this.httpRequest.get(e,n(n({},t),void 0!==r?{attributesToRetrieve:r}:{}))];case 1:return[2,i.sent()]}}))}))},t.prototype.getDocument=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/documents/"+t,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.addDocuments=function(t,e){return i(this,void 0,void 0,(function(){var r;return s(this,(function(n){switch(n.label){case 0:return r="indexes/"+this.uid+"/documents",[4,this.httpRequest.post(r,t,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.updateDocuments=function(t,e){return i(this,void 0,void 0,(function(){var r;return s(this,(function(n){switch(n.label){case 0:return r="indexes/"+this.uid+"/documents",[4,this.httpRequest.put(r,t,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteDocument=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/documents/"+t,[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.deleteDocuments=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/documents/delete-batch",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.deleteAllDocuments=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/documents",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSettings=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSettings=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.resetSettings=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSynonyms=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/synonyms",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSynonyms=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/synonyms",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.resetSynonyms=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/synonyms",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getStopWords=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/stop-words",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateStopWords=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/stop-words",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.resetStopWords=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/stop-words",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getRankingRules=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/ranking-rules",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateRankingRules=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/ranking-rules",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.resetRankingRules=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/ranking-rules",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDistinctAttribute=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/distinct-attribute",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateDistinctAttribute=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/distinct-attribute",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.resetDistinctAttribute=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/distinct-attribute",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getFilterableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/filterable-attributes",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateFilterableAttributes=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/filterable-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.resetFilterableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/filterable-attributes",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSortableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/sortable-attributes",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSortableAttributes=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/sortable-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.resetSortableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/sortable-attributes",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSearchableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/searchable-attributes",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSearchableAttributes=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/searchable-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.resetSearchableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/searchable-attributes",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDisplayedAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/displayed-attributes",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateDisplayedAttributes=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/displayed-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.resetDisplayedAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/displayed-attributes",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t}(),y=function(){function t(t){t.host=d.addTrailingSlash(t.host),this.config=t,this.httpRequest=new d(t)}return t.prototype.index=function(t){return new v(this.config,t)},t.prototype.getIndex=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){return[2,new v(this.config,t).fetchInfo()]}))}))},t.prototype.getOrCreateIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){var r;return s(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.getIndex(t)];case 1:return[2,n.sent()];case 2:if("index_not_found"===(r=n.sent()).errorCode)return[2,this.createIndex(t,e)];throw new u(r,r.status);case 3:return[2]}}))}))},t.prototype.listIndexes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.createIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){return s(this,(function(r){switch(r.label){case 0:return[4,v.create(this.config,t,e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){return s(this,(function(r){return[2,new v(this.config,t).update(e)]}))}))},t.prototype.deleteIndex=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){return[2,new v(this.config,t).delete()]}))}))},t.prototype.deleteIndexIfExists=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.deleteIndex(t)];case 1:return r.sent(),[2,!0];case 2:if("index_not_found"===(e=r.sent()).errorCode)return[2,!1];throw e;case 3:return[2]}}))}))},t.prototype.getKeys=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="keys",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.health=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="health",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.isHealthy=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t="health",[4,this.httpRequest.get(t)];case 1:return e.sent(),[2,!0];case 2:return e.sent(),[2,!1];case 3:return[2]}}))}))},t.prototype.stats=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="stats",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.version=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="version",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.createDump=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="dumps",[4,this.httpRequest.post(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDumpStatus=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="dumps/"+t+"/status",[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t}();t.HttpRequests=d,t.Index=v,t.MeiliSearch=y,t.MeiliSearchApiError=u,t.MeiliSearchCommunicationError=o,t.MeiliSearchError=h,t.MeiliSearchTimeOutError=l,t.default=y,t.httpErrorHandler=c,t.httpResponseErrorHandler=a,t.removeUndefinedFromObject=f,t.sleep=p,Object.defineProperty(t,"__esModule",{value:!0})}(e)}));function a(t){return"string"==typeof t||t instanceof String}function c(t){return t.replace(/:(.*)/i,'="$1"')}function h(t){return"string"==typeof t?c(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return c(t)})).filter((function(t){return t})):c(t)})).filter((function(t){return t})):[]}function l(t){return""===t?[]:"string"==typeof t?[t]:t}function d(t,e,r){return function(t,e,r){var n=r.trim(),s=l(t),o=l(e);return i(i(i([],s),o),[n]).filter((function(t){return Array.isArray(t)?t.length:t}))}(h(r||[]),h(e||[]),t||"")}function f(t,e,r,n,i){var s={},o=null==t?void 0:t.facets;(null==o?void 0:o.length)&&(s.facetsDistribution=o);var u=null==t?void 0:t.attributesToSnippet;u&&(s.attributesToCrop=u);var a=null==t?void 0:t.attributesToRetrieve;a&&(s.attributesToRetrieve=a);var c=d(null==t?void 0:t.filters,null==t?void 0:t.numericFilters,null==t?void 0:t.facetFilters);return c.length&&(s.filter=c),a&&(s.attributesToCrop=a),s.attributesToHighlight=(null==t?void 0:t.attributesToHighlight)||["*"],s.limit=!r&&""===i||0===e?0:e,(null==n?void 0:n.length)&&(s.sort=[n]),s}function p(t,e,r){var n=e*r;return t.splice(n,r)}function v(t,e,r){return e=e||"__ais-highlight__",r=r||"__/ais-highlight__",(a(t)?t:JSON.stringify(t,null,2)).replace(/<em>/g,e).replace(/<\/em>/g,r)}function y(t,e,r){return Object.keys(t).reduce((function(n,i){return n[i]={value:v(t[i],e,r)},n}),{})}function b(t,e,r,n){var i=t;return void 0!==e&&a(i)&&i&&(i[0]===i[0].toLowerCase()&&!1===i.startsWith("<em>")&&(i=""+e+i),!1==!!i.match(/[.!?]$/)&&(i=""+i+e)),v(i,r,n)}function g(t,e,r,n,i){return void 0===e?null:(e=e.map((function(t){return t.split(":")[0]})),Object.keys(t).reduce((function(s,o){return(null==e?void 0:e.includes(o))&&(s[o]={value:b(t[o],r,n,i)}),s}),{}))}function w(t,e){var r=null==e?void 0:e.attributesToSnippet,n=null==e?void 0:e.snippetEllipsisText,i=null==e?void 0:e.highlightPreTag,s=null==e?void 0:e.highlightPostTag;return!t||t.length?{}:{_highlightResult:y(t,i,s),_snippetResult:g(t,r,n,i,s)}}function m(t,r,n){var i=n.primaryKey;return p(t,n.page,n.hitsPerPage).map((function(t){if(Object.keys(t).length>0){var n=t._formatted;t._matchesInfo;var s=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r}(t,["_formatted","_matchesInfo"]);return e(e(e({},s),w(n,r)),i&&{objectID:t[i]})}return t}))}function x(t,r,n,i){var s={},o=r.facetsDistribution,u=null==r?void 0:r.exhaustiveFacetsCount;u&&(s.exhaustiveFacetsCount=u);var a,c,h=m(r.hits,n,i),l=(a=r.hits.length,(c=i.hitsPerPage)>0?Math.ceil(a/c):0),d=r.exhaustiveNbHits,f=r.nbHits,p=r.processingTimeMs,v=r.query,y=i.hitsPerPage,b=i.page;return{results:[e({index:t,hitsPerPage:y,page:b,facets:o,nbPages:l,exhaustiveNbHits:d,nbHits:f,processingTimeMS:p,query:v,hits:h,params:""},s)]}}function R(t,e){if(e=e||{},t&&Object.keys(t).length>0)for(var r in t)for(var n=0,i=t[r];n<i.length;n++){var s=i[n];e[r]&&Object.keys(e[r]).includes(s)||(e[r]=e[r]||{},e[r][s]=0)}return e}var T=function(t){var e=t.match(/([^=]*)="?([^\\"]*)"?$/);return e?(e[0],[{filterName:e[1],value:e[2]}]):[void 0]};function S(t){var r=function(t){return"string"==typeof t?T(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return T(t)})):T(t)})).flat(2):[void 0]}(t);return r.filter((function(t){return void 0!==t})).reduce((function(t,r){var n,s=r.filterName,o=r.value,u=t[s]||[];return t=e(e({},t),((n={})[s]=i(i([],u),[o]),n))}),{})}t.adaptFormating=w,t.adaptHits=m,t.adaptPagination=p,t.adaptSearchRequest=f,t.adaptSearchResponse=x,t.facetsDistributionAdapter=R,t.instantMeiliSearch=function(t,e,i){return void 0===i&&(i={}),{MeiliSearchClient:new u.MeiliSearch({host:t,apiKey:e}),search:function(t){return r(this,void 0,void 0,(function(){var e,r,s,o,u,a,c;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),e=t[0],r=e.params,s=function(t,e,r,n){void 0===r&&(r={});var i=r.paginationTotalHits,s=r.primaryKey,o=r.placeholderSearch,u=null==e?void 0:e.page,a=null==e?void 0:e.hitsPerPage,c=null==e?void 0:e.query,h=t.split(":");return{client:n,indexUid:h[0],paginationTotalHits:i||200,primaryKey:s||void 0,placeholderSearch:!1!==o,hitsPerPage:void 0===a?20:a,page:u||0,sort:h.slice(1).join(":")||"",query:c}}(e.indexName,r,i,this.MeiliSearchClient),o=f(r,s.paginationTotalHits,s.placeholderSearch,s.sort,s.query),u=S(null==o?void 0:o.filter),[4,s.client.index(s.indexUid).search(s.query,o)];case 1:return(a=n.sent()).facetsDistribution=R(u,a.facetsDistribution),[2,x(s.indexUid,a,r,s)];case 2:throw c=n.sent(),console.error(c),new Error(c);case 3:return[2]}}))}))},searchForFacetValues:function(t){return r(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,new Promise((function(t,e){e(new Error("SearchForFacetValues is not compatible with MeiliSearch")),t([])}))];case 1:return[2,t.sent()]}}))}))}}},Object.defineProperty(t,"__esModule",{value:!0})}));
var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,r)};function r(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var n=function(){return(n=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function i(t,e,r,n){function i(t){return t instanceof r?t:new r((function(e){e(t)}))}return new(r||(r=Promise))((function(r,s){function o(t){try{a(n.next(t))}catch(t){s(t)}}function u(t){try{a(n.throw(t))}catch(t){s(t)}}function a(t){t.done?r(t.value):i(t.value).then(o,u)}a((n=n.apply(t,e||[])).next())}))}function s(t,e){var r,n,i,s,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(t){return function(e){return a([t,e])}}function a(s){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,n=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}}var o=function(t){function e(r,n){var i=t.call(this,r)||this;return i.name="MeiliSearchCommunicationError",i.type="MeiliSearchCommunicationError",n instanceof Response&&(i.message=n.statusText,i.statusCode=n.status),n instanceof Error&&(i.errno=n.errno,i.code=n.code),Error.captureStackTrace&&Error.captureStackTrace(i,e),i}return r(e,t),e}(Error),u=function(t){function e(e,r){var n=t.call(this,e.message)||this;return n.type="MeiliSearchApiError",n.name="MeiliSearchApiError",n.errorCode=e.errorCode,n.errorType=e.errorType,n.errorLink=e.errorLink,n.message=e.message,n.httpStatus=r,n}return r(e,t),e}(Error);function a(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:if(t.ok)return[3,5];e=void 0,r.label=1;case 1:return r.trys.push([1,3,,4]),[4,t.json()];case 2:return e=r.sent(),[3,4];case 3:throw r.sent(),new o(t.statusText,t);case 4:throw new u(e,t.status);case 5:return[2,t]}}))}))}function c(t){if("MeiliSearchApiError"!==t.type)throw new o(t.message,t);throw t}var h=function(t){function e(r){var n=t.call(this,r)||this;return n.name="MeiliSearchError",n.type="MeiliSearchError",Error.captureStackTrace&&Error.captureStackTrace(n,e),n}return r(e,t),e}(Error),f=function(t){function e(r){var n=t.call(this,r)||this;return n.name="MeiliSearchTimeOutError",n.type=n.constructor.name,Error.captureStackTrace&&Error.captureStackTrace(n,e),n}return r(e,t),e}(Error),l=function(){function t(t){this.headers=n(n(n({},t.headers||{}),{"Content-Type":"application/json"}),t.apiKey?{"X-Meili-API-Key":t.apiKey}:{}),this.url=new URL(t.host)}return t.addTrailingSlash=function(t){return t.endsWith("/")||(t+="/"),t},t.prototype.request=function(t){var e=t.method,r=t.url,o=t.params,u=t.body,h=t.config;return i(this,void 0,void 0,(function(){var t,i,f;return s(this,(function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),t=new URL(r,this.url),o&&(i=new URLSearchParams,Object.keys(o).filter((function(t){return null!==o[t]})).map((function(t){return i.set(t,o[t])})),t.search=i.toString()),[4,fetch(t.toString(),n(n({},h),{method:e,body:JSON.stringify(u),headers:this.headers})).then((function(t){return a(t)}))];case 1:return[4,s.sent().text()];case 2:f=s.sent();try{return[2,JSON.parse(f)]}catch(t){return[2]}return[3,4];case 3:return c(s.sent()),[3,4];case 4:return[2]}}))}))},t.prototype.get=function(t,e,r){return i(this,void 0,void 0,(function(){return s(this,(function(n){switch(n.label){case 0:return[4,this.request({method:"GET",url:t,params:e,config:r})];case 1:return[2,n.sent()]}}))}))},t.prototype.post=function(t,e,r,n){return i(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"POST",url:t,body:e,params:r,config:n})];case 1:return[2,i.sent()]}}))}))},t.prototype.put=function(t,e,r,n){return i(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"PUT",url:t,body:e,params:r,config:n})];case 1:return[2,i.sent()]}}))}))},t.prototype.delete=function(t,e,r,n){return i(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"DELETE",url:t,body:e,params:r,config:n})];case 1:return[2,i.sent()]}}))}))},t}();function d(t){return Object.entries(t).reduce((function(t,e){var r=e[0],n=e[1];return void 0!==n&&(t[r]=n),t}),{})}function p(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,new Promise((function(e){return setTimeout(e,t)}))];case 1:return[2,e.sent()]}}))}))}var y=function(){function t(t,e,r){this.uid=e,this.primaryKey=r,this.httpRequest=new l(t)}return t.prototype.waitForPendingUpdate=function(t,e){var r=void 0===e?{}:e,n=r.timeOutMs,o=void 0===n?5e3:n,u=r.intervalMs,a=void 0===u?50:u;return i(this,void 0,void 0,(function(){var e,r;return s(this,(function(n){switch(n.label){case 0:e=Date.now(),n.label=1;case 1:return Date.now()-e<o?[4,this.getUpdateStatus(t)]:[3,4];case 2:return r=n.sent(),["enqueued","processing"].includes(r.status)?[4,p(a)]:[2,r];case 3:return n.sent(),[3,1];case 4:throw new f("timeout of "+o+"ms has exceeded on process "+t+" when waiting for pending update to resolve.")}}))}))},t.prototype.search=function(t,e,r){return i(this,void 0,void 0,(function(){var i;return s(this,(function(s){switch(s.label){case 0:return i="indexes/"+this.uid+"/search",[4,this.httpRequest.post(i,d(n(n({},e),{q:t})),void 0,r)];case 1:return[2,s.sent()]}}))}))},t.prototype.searchGet=function(t,e,r){return i(this,void 0,void 0,(function(){var i,o,u;return s(this,(function(s){switch(s.label){case 0:return i="indexes/"+this.uid+"/search",o=function(t){if("string"==typeof t)return t;if(Array.isArray(t))throw new h("The filter query parameter should be in string format when using searchGet")},u=n(n({q:t},e),{filter:o(null==e?void 0:e.filter),sort:(null==e?void 0:e.sort)?e.sort.join(","):void 0,facetsDistribution:(null==e?void 0:e.facetsDistribution)?e.facetsDistribution.join(","):void 0,attributesToRetrieve:(null==e?void 0:e.attributesToRetrieve)?e.attributesToRetrieve.join(","):void 0,attributesToCrop:(null==e?void 0:e.attributesToCrop)?e.attributesToCrop.join(","):void 0,attributesToHighlight:(null==e?void 0:e.attributesToHighlight)?e.attributesToHighlight.join(","):void 0}),[4,this.httpRequest.get(i,d(u),r)];case 1:return[2,s.sent()]}}))}))},t.prototype.getRawInfo=function(){return i(this,void 0,void 0,(function(){var t,e;return s(this,(function(r){switch(r.label){case 0:return t="indexes/"+this.uid,[4,this.httpRequest.get(t)];case 1:return e=r.sent(),this.primaryKey=e.primaryKey,[2,e]}}))}))},t.prototype.fetchInfo=function(){return i(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.getRawInfo()];case 1:return t.sent(),[2,this]}}))}))},t.prototype.fetchPrimaryKey=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t=this,[4,this.getRawInfo()];case 1:return t.primaryKey=e.sent().primaryKey,[2,this.primaryKey]}}))}))},t.create=function(e,r,o){return void 0===o&&(o={}),i(this,void 0,void 0,(function(){var i,u;return s(this,(function(s){switch(s.label){case 0:return i="indexes",[4,new l(e).post(i,n(n({},o),{uid:r}))];case 1:return u=s.sent(),[2,new t(e,r,u.primaryKey)]}}))}))},t.prototype.update=function(t){return i(this,void 0,void 0,(function(){var e,r;return s(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid,[4,this.httpRequest.put(e,t)];case 1:return r=n.sent(),this.primaryKey=r.primaryKey,[2,this]}}))}))},t.prototype.delete=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid,[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.deleteIfExists=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.delete()];case 1:return e.sent(),[2,!0];case 2:if("index_not_found"===(t=e.sent()).errorCode)return[2,!1];throw t;case 3:return[2]}}))}))},t.prototype.getAllUpdateStatus=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/updates",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getUpdateStatus=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/updates/"+t,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getStats=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/stats",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDocuments=function(t){return i(this,void 0,void 0,(function(){var e,r;return s(this,(function(i){switch(i.label){case 0:return e="indexes/"+this.uid+"/documents",void 0!==t&&Array.isArray(t.attributesToRetrieve)&&(r=t.attributesToRetrieve.join(",")),[4,this.httpRequest.get(e,n(n({},t),void 0!==r?{attributesToRetrieve:r}:{}))];case 1:return[2,i.sent()]}}))}))},t.prototype.getDocument=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/documents/"+t,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.addDocuments=function(t,e){return i(this,void 0,void 0,(function(){var r;return s(this,(function(n){switch(n.label){case 0:return r="indexes/"+this.uid+"/documents",[4,this.httpRequest.post(r,t,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.updateDocuments=function(t,e){return i(this,void 0,void 0,(function(){var r;return s(this,(function(n){switch(n.label){case 0:return r="indexes/"+this.uid+"/documents",[4,this.httpRequest.put(r,t,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteDocument=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/documents/"+t,[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.deleteDocuments=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/documents/delete-batch",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.deleteAllDocuments=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/documents",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSettings=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSettings=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.resetSettings=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSynonyms=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/synonyms",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSynonyms=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/synonyms",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.resetSynonyms=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/synonyms",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getStopWords=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/stop-words",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateStopWords=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/stop-words",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.resetStopWords=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/stop-words",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getRankingRules=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/ranking-rules",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateRankingRules=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/ranking-rules",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.resetRankingRules=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/ranking-rules",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDistinctAttribute=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/distinct-attribute",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateDistinctAttribute=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/distinct-attribute",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.resetDistinctAttribute=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/distinct-attribute",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getFilterableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/filterable-attributes",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateFilterableAttributes=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/filterable-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.resetFilterableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/filterable-attributes",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSortableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/sortable-attributes",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSortableAttributes=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/sortable-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.resetSortableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/sortable-attributes",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSearchableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/searchable-attributes",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSearchableAttributes=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/searchable-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.resetSearchableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/searchable-attributes",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDisplayedAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/displayed-attributes",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateDisplayedAttributes=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid+"/settings/displayed-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.resetDisplayedAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/displayed-attributes",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t}(),v=function(){function t(t){t.host=l.addTrailingSlash(t.host),this.config=t,this.httpRequest=new l(t)}return t.prototype.index=function(t){return new y(this.config,t)},t.prototype.getIndex=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){return[2,new y(this.config,t).fetchInfo()]}))}))},t.prototype.getOrCreateIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){var r;return s(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.getIndex(t)];case 1:return[2,n.sent()];case 2:if("index_not_found"===(r=n.sent()).errorCode)return[2,this.createIndex(t,e)];throw new u(r,r.status);case 3:return[2]}}))}))},t.prototype.listIndexes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.createIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){return s(this,(function(r){switch(r.label){case 0:return[4,y.create(this.config,t,e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){return s(this,(function(r){return[2,new y(this.config,t).update(e)]}))}))},t.prototype.deleteIndex=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){return[2,new y(this.config,t).delete()]}))}))},t.prototype.deleteIndexIfExists=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.deleteIndex(t)];case 1:return r.sent(),[2,!0];case 2:if("index_not_found"===(e=r.sent()).errorCode)return[2,!1];throw e;case 3:return[2]}}))}))},t.prototype.getKeys=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="keys",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.health=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="health",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.isHealthy=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t="health",[4,this.httpRequest.get(t)];case 1:return e.sent(),[2,!0];case 2:return e.sent(),[2,!1];case 3:return[2]}}))}))},t.prototype.stats=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="stats",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.version=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="version",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.createDump=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="dumps",[4,this.httpRequest.post(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDumpStatus=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return e="dumps/"+t+"/status",[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t}();t.HttpRequests=l,t.Index=y,t.MeiliSearch=v,t.MeiliSearchApiError=u,t.MeiliSearchCommunicationError=o,t.MeiliSearchError=h,t.MeiliSearchTimeOutError=f,t.default=v,t.httpErrorHandler=c,t.httpResponseErrorHandler=a,t.removeUndefinedFromObject=d,t.sleep=p,Object.defineProperty(t,"__esModule",{value:!0})}(e)}));function a(t){return"string"==typeof t||t instanceof String}function c(t){return t.replace(/:(.*)/i,'="$1"')}var h=function(t){var e=t.match(/([^=]*)="?([^\\"]*)"?$/);return e?(e[0],[{filterName:e[1],value:e[2]}]):[]};function f(t){var r=function(t){return"string"==typeof t?h(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return h(t)})):h(t)})).flat(2):[]}(t);return r.filter((function(t){return void 0!==t})).reduce((function(t,r){var n,s=r.filterName,o=r.value,u=t[s]||[];return t=e(e({},t),((n={})[s]=i(i([],u),[o]),n))}),{})}function l(t){return{searchResponse:function(e,i,s){return r(this,void 0,void 0,(function(){var r,o,u,a;return n(this,(function(n){switch(n.label){case 0:return r=t.formatKey([i,e.indexUid,e.query]),(o=t.getEntry(r))?[2,o]:(u=f(null==i?void 0:i.filter),[4,s.index(e.indexUid).search(e.query,i)]);case 1:return(a=n.sent()).facetsDistribution=function(t,e){if(e=e||{},t&&Object.keys(t).length>0)for(var r in t){e[r]||(e[r]={});for(var n=0,i=t[r];n<i.length;n++){var s=i[n];Object.keys(e[r]).includes(s)||(e[r][s]=0)}}return e}(u,a.facetsDistribution),t.setEntry(r,a),[2,a]}}))}))}}}function d(t){return"string"==typeof t?c(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return c(t)})).filter((function(t){return t})):c(t)})).filter((function(t){return t})):[]}function p(t){return""===t?[]:"string"==typeof t?[t]:t}function y(t,e,r){return function(t,e,r){var n=r.trim(),s=p(t),o=p(e);return i(i(i([],s),o),[n]).filter((function(t){return Array.isArray(t)?t.length:t}))}(d(r||[]),d(e||[]),t||"")}function v(t,e,r){return e=e||"__ais-highlight__",r=r||"__/ais-highlight__",(a(t)?t:JSON.stringify(t,null,2)).replace(/<em>/g,e).replace(/<\/em>/g,r)}function b(t,e,r){return Object.keys(t).reduce((function(n,i){return n[i]={value:v(t[i],e,r)},n}),{})}function g(t,e,r,n){var i=t;return void 0!==e&&a(i)&&i&&(i[0]===i[0].toLowerCase()&&!1===i.startsWith("<em>")&&(i=""+e+i),!1==!!i.match(/[.!?]$/)&&(i=""+i+e)),v(i,r,n)}function w(t,e,r,n,i){return void 0===e?null:(e=e.map((function(t){return t.split(":")[0]})),Object.keys(t).reduce((function(s,o){return(null==e?void 0:e.includes(o))&&(s[o]={value:g(t[o],r,n,i)}),s}),{}))}function m(t,r,n){var i=r.primaryKey,s=n.hitsPerPage;return function(t,e,r){var n=e*r;return t.splice(n,r)}(t,n.page,s).map((function(t){if(Object.keys(t).length>0){var n=t._formatted;t._matchesInfo;var s=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r}(t,["_formatted","_matchesInfo"]);return e(e(e({},s),function(t,e){var r=null==e?void 0:e.attributesToSnippet,n=null==e?void 0:e.snippetEllipsisText,i=null==e?void 0:e.highlightPreTag,s=null==e?void 0:e.highlightPostTag;return!t||t.length?{}:{_highlightResult:b(t,i,s),_snippetResult:w(t,r,n,i,s)}}(n,r)),i&&{objectID:t[i]})}return t}))}function x(t,r,n){var i={},s=t.facetsDistribution,o=null==t?void 0:t.exhaustiveFacetsCount;o&&(i.exhaustiveFacetsCount=o);var u,a,c=m(t.hits,r,n),h=(u=t.hits.length,(a=n.hitsPerPage)>0?Math.ceil(u/a):0),f=t.exhaustiveNbHits,l=t.nbHits,d=t.processingTimeMs,p=t.query,y=n.hitsPerPage,v=n.page;return{results:[e({index:r.indexUid,hitsPerPage:y,page:v,facets:s,nbPages:h,exhaustiveNbHits:f,nbHits:l,processingTimeMS:d,query:p,hits:c,params:""},i)]}}function R(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(r){return e[t]}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,r){e[t]=JSON.stringify(r)}}}t.instantMeiliSearch=function(t,i,s){void 0===i&&(i=""),void 0===s&&(s={});var o=l(R()),a={primaryKey:s.primaryKey||void 0,placeholderSearch:!1!==s.placeholderSearch,paginationTotalHits:s.paginationTotalHits||200};return{MeiliSearchClient:new u.MeiliSearch({host:t,apiKey:i}),search:function(t){return r(this,void 0,void 0,(function(){var r,i,s,u,c,h,f;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),r=t[0],i=r.params,s=function(t,r){var n=t.indexName.split(":"),i=n[0],s=n.slice(1),o=t.params;return e(e(e({},r),o),{sort:s.join(":")||"",indexUid:i})}(r,a),u=function(t,e){return{paginationTotalHits:t.paginationTotalHits||200,hitsPerPage:void 0===t.hitsPerPage?20:t.hitsPerPage,page:(null==e?void 0:e.page)||0}}(s,i),c=function(t){var e={},r=null==t?void 0:t.facets;(null==r?void 0:r.length)&&(e.facetsDistribution=r);var n=null==t?void 0:t.attributesToSnippet;n&&(e.attributesToCrop=n);var i=null==t?void 0:t.attributesToRetrieve;i&&(e.attributesToRetrieve=i);var s=y(null==t?void 0:t.filters,null==t?void 0:t.numericFilters,null==t?void 0:t.facetFilters);s.length&&(e.filter=s),i&&(e.attributesToCrop=i),e.attributesToHighlight=(null==t?void 0:t.attributesToHighlight)||["*"];var o=e.placeholderSearch,u=e.query,a=e.paginationTotalHits;e.limit=!o&&""===u||0===a?0:a;var c=t.sort;return(null==c?void 0:c.length)&&(e.sort=[c]),e}(s),[4,o.searchResponse(s,c,this.MeiliSearchClient)];case 1:return h=n.sent(),[2,x(h,s,u)];case 2:throw f=n.sent(),console.error(f),new Error(f);case 3:return[2]}}))}))},searchForFacetValues:function(t){return r(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,new Promise((function(t,e){e(new Error("SearchForFacetValues is not compatible with MeiliSearch")),t([])}))];case 1:return[2,t.sent()]}}))}))}}},Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=instant-meilisearch.umd.min.js.map
export * from './search-request-adapter';
export * from './search-response-adapter';
export * from './hits-adapter';
export * from './highlight-adapter';
export * from './pagination-adapter';
export * from './facets-distribution-adapter';
//# sourceMappingURL=index.d.ts.map

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

export * from './filters';
export * from './search-cache';
//# sourceMappingURL=index.d.ts.map

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

import { InstantMeiliSearchOptions, InstantMeiliSearchInstance } from '../types';
/**
* Instanciate SearchClient required by instantsearch.js.
*
* @param {string} hostUrl
* @param {string} apiKey
* @param {InstantMeiliSearchOptions={}} meiliSearchOptions
* @returns InstantMeiliSearchInstance
*/
export declare function instantMeiliSearch(hostUrl: string, apiKey: string, meiliSearchOptions?: InstantMeiliSearchOptions): InstantMeiliSearchInstance;
export * from './instant-meilisearch-client';
//# sourceMappingURL=index.d.ts.map

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

// Type definitions for @meilisearch/instant-meilisearch 0.5.5
// Type definitions for @meilisearch/instant-meilisearch 0.5.6
// Project: https://github.com/meilisearch/instant-meilisearch.git

@@ -8,4 +8,3 @@ // Definitions by: Clementine Urquizar <https://github.com/meilisearch>

export * from './client';
export * from './adapter';
export * from './types';
//# sourceMappingURL=index.d.ts.map

@@ -1,9 +0,9 @@

import type { MeiliSearch } from 'meilisearch';
import type { MeiliSearch, SearchResponse as MeiliSearchResponse } from 'meilisearch';
import type { SearchClient } from 'instantsearch.js';
import type { SearchOptions as AlgoliaSearchOptions, MultipleQueriesQuery as AlgoliaMultipleQueriesQuery } from '@algolia/client-search';
export type { AlgoliaMultipleQueriesQuery, AlgoliaSearchOptions };
import type { MultipleQueriesQuery as AlgoliaMultipleQueriesQuery } from '@algolia/client-search';
export type { AlgoliaMultipleQueriesQuery };
export type { SearchResponse as AlgoliaSearchResponse } from '@algolia/client-search';
export type { Filter, FacetsDistribution, SearchResponse as MeiliSearchResponse, SearchParams as MeiliSearchParams, } from 'meilisearch';
export type { Filter, FacetsDistribution, SearchResponse as MeiliSearchResponse, SearchParams as MeiliSearchParams, MeiliSearch, } from 'meilisearch';
export declare type InstantSearchParams = AlgoliaMultipleQueriesQuery['params'];
export declare type Cache = {
export declare type FilterCache = {
[category: string]: string[];

@@ -20,14 +20,24 @@ };

};
export declare type SearchContext = {
page: number;
export declare type Context = {
paginationTotalHits: number;
hitsPerPage: number;
placeholderSearch: boolean;
primaryKey?: string;
client: MeiliSearch;
placeholderSearch: boolean;
};
export declare type SearchCacheInterface = {
getEntry: (key: string) => MeiliSearchResponse | undefined;
formatKey: (components: any[]) => string;
setEntry: <T>(key: string, searchResponse: T) => void;
};
export declare type SearchContext = InstantSearchParams & {
primaryKey?: string;
placeholderSearch?: boolean;
sort?: string;
query?: string;
indexUid: string;
paginationTotalHits: number;
};
export declare type AdaptToMeiliSearchParams = (instantSearchParams: InstantSearchParams, instantMeiliSearchContext: SearchContext) => Record<string, any>;
export declare type PaginationContext = {
paginationTotalHits: number;
hitsPerPage: number;
page: number;
};
export declare type InstantMeiliSearchInstance = SearchClient & {

@@ -34,0 +44,0 @@ MeiliSearchClient: MeiliSearch;

/**
* @param {any} str
* @returns boolean
* @returns {boolean}
*/

@@ -8,5 +8,10 @@ export declare function isString(str: any): boolean;

* @param {string} filter
* @returns string
* @returns {string}
*/
export declare function replaceColonByEqualSign(filter: string): string;
/**
* @param {any[]} arr
* @returns {string}
*/
export declare function stringifyArray(arr: any[]): string;
//# sourceMappingURL=string.d.ts.map
{
"name": "@meilisearch/instant-meilisearch",
"version": "0.5.5",
"version": "0.5.6",
"private": false,

@@ -11,5 +11,5 @@ "description": "The search client to use MeiliSearch with InstantSearch.",

"test:build": "yarn build && jest --runInBand --selectProjects build",
"test:e2e": "concurrently --kill-others -s first \"NODE_ENV=test yarn playground:angular\" \"cypress run --env playground=angular\"",
"test:e2e": "concurrently --kill-others -s first \"yarn playground:vue\" \"cypress run --env playground=vue\"",
"test:e2e:all": "sh scripts/e2e.sh",
"test:e2e:watch": "concurrently --kill-others -s first \"NODE_ENV=test yarn playground:angular\" \"cypress open --env playground=angular\"",
"test:e2e:watch": "concurrently --kill-others -s first \"yarn playground:vue\" \"cypress open --env playground=vue\"",
"test:all": "yarn test:e2e:all && yarn test && test:build",

@@ -73,5 +73,5 @@ "cy:open": "cypress open",

"babel-jest": "^27.2.2",
"concurrently": "^6.2.1",
"concurrently": "^6.3.0",
"cssnano": "^4.1.10",
"cypress": "^7.3.0",
"cypress": "^8.5.0",
"eslint": "^7.21.0",

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

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

@@ -95,0 +95,0 @@ "jest-watch-typeahead": "^0.6.3",

export * from './search-request-adapter'
export * from './search-response-adapter'
export * from './hits-adapter'
export * from './highlight-adapter'
export * from './pagination-adapter'
export * from './facets-distribution-adapter'

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

export * from './filters'
export * from './search-cache'

@@ -1,134 +0,1 @@

import { MeiliSearch } from 'meilisearch'
import {
InstantMeiliSearchOptions,
InstantMeiliSearchInstance,
AlgoliaSearchResponse,
AlgoliaMultipleQueriesQuery,
InstantSearchParams,
SearchContext,
} from '../types'
import {
adaptSearchRequest,
adaptSearchResponse,
facetsDistributionAdapter,
} from '../adapter'
import { cacheFilters } from '../cache'
/**
* Create search context.
*
* @param {string} indexName
* @param {InstantSearchParams} params
* @param {InstantMeiliSearchOptions={}} meiliSearchOptions
* @param {MeiliSearch} MeiliSearchClient
* @returns SearchContext
*/
function createContext(
indexName: string,
params: InstantSearchParams,
meiliSearchOptions: InstantMeiliSearchOptions = {},
MeiliSearchClient: MeiliSearch
): SearchContext {
const {
paginationTotalHits,
primaryKey,
placeholderSearch,
} = meiliSearchOptions
const page = params?.page
const hitsPerPage = params?.hitsPerPage
const query = params?.query
// Split index name and possible sorting rules
const [indexUid, ...sortByArray] = indexName.split(':')
const context = {
client: MeiliSearchClient,
indexUid: indexUid,
paginationTotalHits: paginationTotalHits || 200,
primaryKey: primaryKey || undefined,
placeholderSearch: placeholderSearch !== false, // true by default
hitsPerPage: hitsPerPage === undefined ? 20 : hitsPerPage, // 20 is the MeiliSearch's default limit value. `hitsPerPage` can be changed with `InsantSearch.configure`.
page: page || 0, // default page is 0 if none is provided
sort: sortByArray.join(':') || '',
query,
}
return context
}
/**
* Instanciate SearchClient required by instantsearch.js.
*
* @param {string} hostUrl
* @param {string} apiKey
* @param {InstantMeiliSearchOptions={}} meiliSearchOptions
* @returns InstantMeiliSearchInstance
*/
export function instantMeiliSearch(
hostUrl: string,
apiKey: string,
meiliSearchOptions: InstantMeiliSearchOptions = {}
): InstantMeiliSearchInstance {
return {
MeiliSearchClient: new MeiliSearch({ host: hostUrl, apiKey: apiKey }),
search: async function <T = Record<string, any>>(
instantSearchRequests: readonly AlgoliaMultipleQueriesQuery[]
// options?: RequestOptions & MultipleQueriesOptions - When is this used ?
): Promise<{ results: Array<AlgoliaSearchResponse<T>> }> {
try {
const searchRequest = instantSearchRequests[0]
const { params: instantSearchParams } = searchRequest
const context = createContext(
searchRequest.indexName,
instantSearchParams,
meiliSearchOptions,
this.MeiliSearchClient
)
// Adapt search request to MeiliSearch compliant search request
const adaptedSearchRequest = adaptSearchRequest(
instantSearchParams,
context.paginationTotalHits,
context.placeholderSearch,
context.sort,
context.query
)
// Cache filters
const cachedFacet = cacheFilters(adaptedSearchRequest?.filter)
// Executes the search with MeiliSearch
const searchResponse = await context.client
.index(context.indexUid)
.search(context.query, adaptedSearchRequest)
// Add the checked facet attributes in facetsDistribution and give them a value of 0
searchResponse.facetsDistribution = facetsDistributionAdapter(
cachedFacet,
searchResponse.facetsDistribution
)
// Adapt the MeiliSearch responsne to a compliant instantsearch.js response
const adaptedSearchResponse = adaptSearchResponse<T>(
context.indexUid,
searchResponse,
instantSearchParams,
context
)
return adaptedSearchResponse
} catch (e: any) {
console.error(e)
throw new Error(e)
}
},
searchForFacetValues: async function (_) {
return await new Promise((resolve, reject) => {
reject(
new Error('SearchForFacetValues is not compatible with MeiliSearch')
)
resolve([]) // added here to avoid compilation error
})
},
}
}
export * from './instant-meilisearch-client'
export * from './client'
export * from './adapter'
export * from './types'

@@ -1,10 +0,11 @@

import type { MeiliSearch } from 'meilisearch'
import type {
MeiliSearch,
SearchResponse as MeiliSearchResponse,
} from 'meilisearch'
import type { SearchClient } from 'instantsearch.js'
import type {
SearchOptions as AlgoliaSearchOptions,
MultipleQueriesQuery as AlgoliaMultipleQueriesQuery,
} from '@algolia/client-search'
import type { MultipleQueriesQuery as AlgoliaMultipleQueriesQuery } from '@algolia/client-search'
export type { AlgoliaMultipleQueriesQuery, AlgoliaSearchOptions }
export type { AlgoliaMultipleQueriesQuery }
export type { SearchResponse as AlgoliaSearchResponse } from '@algolia/client-search'
export type {

@@ -15,2 +16,3 @@ Filter,

SearchParams as MeiliSearchParams,
MeiliSearch,
} from 'meilisearch'

@@ -20,3 +22,3 @@

export type Cache = {
export type FilterCache = {
[category: string]: string[]

@@ -36,18 +38,27 @@ }

export type SearchContext = {
page: number
export type Context = {
paginationTotalHits: number
hitsPerPage: number
placeholderSearch: boolean
primaryKey?: string
client: MeiliSearch
placeholderSearch: boolean
}
export type SearchCacheInterface = {
getEntry: (key: string) => MeiliSearchResponse | undefined
formatKey: (components: any[]) => string
setEntry: <T>(key: string, searchResponse: T) => void
}
export type SearchContext = InstantSearchParams & {
primaryKey?: string
placeholderSearch?: boolean
sort?: string
query?: string
indexUid: string
paginationTotalHits: number
}
export type AdaptToMeiliSearchParams = (
instantSearchParams: InstantSearchParams,
instantMeiliSearchContext: SearchContext
) => Record<string, any>
export type PaginationContext = {
paginationTotalHits: number
hitsPerPage: number
page: number
}

@@ -54,0 +65,0 @@ export type InstantMeiliSearchInstance = SearchClient & {

/**
* @param {any} str
* @returns boolean
* @returns {boolean}
*/

@@ -11,3 +11,3 @@ export function isString(str: any): boolean {

* @param {string} filter
* @returns string
* @returns {string}
*/

@@ -18,1 +18,11 @@ export function replaceColonByEqualSign(filter: string): string {

}
/**
* @param {any[]} arr
* @returns {string}
*/
export function stringifyArray(arr: any[]): string {
return arr.reduce((acc: string, curr: any) => {
return (acc += JSON.stringify(curr))
}, '')
}

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc