Socket
Socket
Sign inDemoInstall

@meilisearch/instant-meilisearch

Package Overview
Dependencies
Maintainers
6
Versions
74
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.4 to 0.5.5

dist/types/adapter/facets-distribution-adapter.d.ts

552

dist/instant-meilisearch.cjs.js

@@ -89,80 +89,211 @@ 'use strict';

var replaceFilterSyntax = function (filter) {
var removeUndefined = function (arr) {
return arr.filter(function (x) { return x !== undefined; });
};
/**
* @param {any} str
* @returns boolean
*/
function isString(str) {
return typeof str === 'string' || str instanceof String;
}
/**
* @param {string} filter
* @returns string
*/
function replaceColonByEqualSign(filter) {
// will only change first occurence of `:`
return filter.replace(/:(.*)/i, '="$1"');
};
/*
* Adapt InstantSearch filters to MeiliSearch filters
* changes equal comparison sign from `:` to `=` in nested filter object
}
/**
* @param {number} dividend
* @param {number} divisor
* @returns number
*/
function ceiledDivision(dividend, divisor) {
if (divisor > 0) {
var NumberPages = Math.ceil(dividend / divisor); // total number of pages rounded up to the next largest integer.
return NumberPages;
}
return 0;
}
/**
* Transform InstantSearch filter to MeiliSearch filter.
* Change sign from `:` to `=` in nested filter object.
* example: [`genres:comedy`] becomes [`genres=comedy`]
*
* @param {AlgoliaSearchOptions['facetFilters']} filters?
* @returns Filter
*/
var facetFiltersToMeiliSearchFilter = function (filters) {
function transformFilter(filters) {
if (typeof filters === 'string') {
// will only change first occurence of `:`
return replaceFilterSyntax(filters);
return replaceColonByEqualSign(filters);
}
else if (Array.isArray(filters))
return filters.map(function (filter) {
return filters
.map(function (filter) {
if (Array.isArray(filter))
return filter.map(function (nestedFilter) { return replaceFilterSyntax(nestedFilter); });
return filter
.map(function (nestedFilter) { return replaceColonByEqualSign(nestedFilter); })
.filter(function (elem) { return elem; });
else {
return replaceFilterSyntax(filter);
return replaceColonByEqualSign(filter);
}
});
})
.filter(function (elem) { return elem; });
return [];
};
var mergeFilters = function (facetFilters, filters, numericFilters) {
var mergedFilters = [numericFilters.join(' AND '), filters.trim()]
.filter(function (x) { return x; })
.join(' AND ')
.trim();
if (Array.isArray(facetFilters) && mergedFilters)
return __spreadArray(__spreadArray([], facetFilters), [[mergedFilters]]);
if (typeof facetFilters === 'string' && mergedFilters)
return [facetFilters, [mergedFilters]];
return facetFilters;
};
var adaptToMeiliSearchParams = function (_a, _b) {
var query = _a.query, facets = _a.facets, facetFilters = _a.facetFilters, attributesToCrop = _a.attributesToSnippet, attributesToRetrieve = _a.attributesToRetrieve, attributesToHighlight = _a.attributesToHighlight, _c = _a.filters, filters = _c === void 0 ? '' : _c, _d = _a.numericFilters, numericFilters = _d === void 0 ? [] : _d;
var paginationTotalHits = _b.paginationTotalHits, placeholderSearch = _b.placeholderSearch, sort = _b.sort;
var limit = paginationTotalHits;
var meilisearchFilters = facetFiltersToMeiliSearchFilter(facetFilters);
var filter = mergeFilters(meilisearchFilters, filters, numericFilters);
}
/**
* Return the filter in an array if it is a string
* If filter is array, return without change.
*
* @param {Filter} filter
* @returns Array
*/
function filterToArray(filter) {
// Filter is a string
if (filter === '')
return [];
else if (typeof filter === 'string')
return [filter];
// Filter is either an array of strings, or an array of array of strings
return filter;
}
/**
* Merge facetFilters, numericFilters and filters together.
*
* @param {Filter} facetFilters
* @param {Filter} numericFilters
* @param {string} filters
* @returns Filter
*/
function mergeFilters(facetFilters, numericFilters, filters) {
var adaptedFilters = filters.trim();
var adaptedFacetFilters = filterToArray(facetFilters);
var adaptedNumericFilters = filterToArray(numericFilters);
var adaptedFilter = __spreadArray(__spreadArray(__spreadArray([], adaptedFacetFilters, true), adaptedNumericFilters, true), [
adaptedFilters,
]);
var cleanedFilters = adaptedFilter.filter(function (filter) {
if (Array.isArray(filter)) {
return filter.length;
}
return filter;
});
return cleanedFilters;
}
/**
* Adapt instantsearch.js filters to MeiliSearch filters by
* combining and transforming all provided filters.
*
* @param {string|undefined} filters
* @param {AlgoliaSearchOptions['numericFilters']} numericFilters
* @param {AlgoliaSearchOptions['facetFilters']} facetFilters
* @returns Filter
*/
function adaptFilters(filters, numericFilters, facetFilters) {
var transformedFilter = transformFilter(facetFilters || []);
var transformedNumericFilter = transformFilter(numericFilters || []);
return mergeFilters(transformedFilter, transformedNumericFilter, filters || '');
}
/**
* Adapt search request from instantsearch.js
* to search request compliant with MeiliSearch
*
* @param {InstantSearchParams} instantSearchParams
* @param {number} paginationTotalHits
* @param {boolean} placeholderSearch
* @param {string} sort?
* @param {string} query?
* @returns MeiliSearchParams
*/
function adaptSearchRequest(instantSearchParams, paginationTotalHits, placeholderSearch, sort, query) {
// Creates search params object compliant with MeiliSearch
return __assign(__assign(__assign(__assign(__assign(__assign({ q: query }, ((facets === null || facets === void 0 ? void 0 : facets.length) && { facetsDistribution: facets })), (attributesToCrop && { attributesToCrop: attributesToCrop })), (attributesToRetrieve && { attributesToRetrieve: attributesToRetrieve })), (filter.length && { filter: filter })), { attributesToHighlight: attributesToHighlight || ['*'], limit: (!placeholderSearch && query === '') || !limit ? 0 : limit }), ((sort === null || sort === void 0 ? void 0 : sort.length) && { sort: [sort] }));
};
var meiliSearchParams = {};
// Facets
var facets = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.facets;
if (facets === null || facets === void 0 ? void 0 : facets.length) {
meiliSearchParams.facetsDistribution = facets;
}
// Attributes To Crop
var attributesToCrop = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.attributesToSnippet;
if (attributesToCrop) {
meiliSearchParams.attributesToCrop = attributesToCrop;
}
// Attributes To Retrieve
var attributesToRetrieve = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.attributesToRetrieve;
if (attributesToRetrieve) {
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);
if (filter.length) {
meiliSearchParams.filter = filter;
}
// Attributes To Retrieve
if (attributesToRetrieve) {
meiliSearchParams.attributesToCrop = attributesToRetrieve;
}
// Attributes To Highlight
meiliSearchParams.attributesToHighlight = (instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.attributesToHighlight) || [
'*',
];
if ((!placeholderSearch && query === '') || paginationTotalHits === 0) {
meiliSearchParams.limit = 0;
}
else {
meiliSearchParams.limit = paginationTotalHits;
}
// Sort
if (sort === null || sort === void 0 ? void 0 : sort.length) {
meiliSearchParams.sort = [sort];
}
return meiliSearchParams;
}
var getNumberPages = function (hitsLength, _a) {
var hitsPerPage = _a.hitsPerPage;
if (hitsPerPage > 0) {
var NumberPages = Math.ceil(hitsLength / hitsPerPage); // total number of pages rounded up to the next largest integer.
return NumberPages;
}
return 0;
};
var paginateHits = function (hits, _a) {
var page = _a.page, hitsPerPage = _a.hitsPerPage;
/**
* Slice the requested hits based on the pagination position.
*
* @param {Record<string} hits
* @param {number} page
* @param {number} hitsPerPage
* @returns Array
*/
function adaptPagination(hits, page, hitsPerPage) {
var start = page * hitsPerPage;
return hits.splice(start, hitsPerPage);
};
function isString(str) {
return typeof str === 'string' || str instanceof String;
}
var replaceHighlightTags = function (value, highlightPreTag, highlightPostTag) {
// Value has to be a string to have highlight.
/**
* Replace `em` tags in highlighted MeiliSearch hits to
* provided tags by instantsearch.js.
*
* @param {string} value
* @param {string} highlightPreTag?
* @param {string} highlightPostTag?
* @returns string
*/
function replaceHighlightTags(value, highlightPreTag, highlightPostTag) {
highlightPreTag = highlightPreTag || '__ais-highlight__';
highlightPostTag = highlightPostTag || '__/ais-highlight__';
// Highlight is applied by MeiliSearch (<em> tags)
// We replace the <em> by the expected tag for InstantSearch
highlightPreTag = highlightPreTag || '__ais-highlight__';
highlightPostTag = highlightPostTag || '__/ais-highlight__';
if (isString(value)) {
return value
.replace(/<em>/g, highlightPreTag)
.replace(/<\/em>/g, highlightPostTag);
}
// We JSON stringify to avoid loss of nested information
return JSON.stringify(value);
};
var createHighlighResult = function (_a) {
var formattedHit = _a.formattedHit, highlightPreTag = _a.highlightPreTag, highlightPostTag = _a.highlightPostTag;
var stringifiedValue = isString(value)
? value
: JSON.stringify(value, null, 2);
return stringifiedValue
.replace(/<em>/g, highlightPreTag)
.replace(/<\/em>/g, highlightPostTag);
}
/**
* @param {Record<string} formattedHit
* @param {string} highlightPreTag?
* @param {string} highlightPostTag?
* @returns Record
*/
function adaptHighlight(formattedHit, highlightPreTag, highlightPostTag) {
// formattedHit is the `_formatted` object returned by MeiliSearch.

@@ -176,6 +307,13 @@ // It contains all the highlighted and croped attributes

}, {});
};
var snippetValue = function (value, snippetEllipsisText, highlightPreTag, highlightPostTag) {
}
/**
* @param {string} value
* @param {string} snippetEllipsisText?
* @param {string} highlightPreTag?
* @param {string} highlightPostTag?
* @returns string
*/
function snippetValue(value, snippetEllipsisText, highlightPreTag, highlightPostTag) {
var newValue = value;
// manage a kind of `...` for the crop until this issue is solved: https://github.com/meilisearch/MeiliSearch/issues/923
// manage a kind of `...` for the crop until this feature is implemented https://roadmap.meilisearch.com/c/69-policy-for-cropped-values?utm_medium=social&utm_source=portal_share
// `...` is put if we are at the middle of a sentence (instead at the middle of the document field)

@@ -194,5 +332,11 @@ if (snippetEllipsisText !== undefined && isString(newValue) && newValue) {

return replaceHighlightTags(newValue, highlightPreTag, highlightPostTag);
};
var createSnippetResult = function (_a) {
var formattedHit = _a.formattedHit, attributesToSnippet = _a.attributesToSnippet, snippetEllipsisText = _a.snippetEllipsisText, highlightPreTag = _a.highlightPreTag, highlightPostTag = _a.highlightPostTag;
}
/**
* @param {Record<string} formattedHit
* @param {readonlystring[]|undefined} attributesToSnippet
* @param {string|undefined} snippetEllipsisText
* @param {string|undefined} highlightPreTag
* @param {string|undefined} highlightPostTag
*/
function adaptSnippet(formattedHit, attributesToSnippet, snippetEllipsisText, highlightPreTag, highlightPostTag) {
if (attributesToSnippet === undefined) {

@@ -205,3 +349,3 @@ return null;

return Object.keys(formattedHit).reduce(function (result, key) {
if (attributesToSnippet.includes(key)) {
if (attributesToSnippet === null || attributesToSnippet === void 0 ? void 0 : attributesToSnippet.includes(key)) {
result[key] = {

@@ -213,15 +357,33 @@ value: snippetValue(formattedHit[key], snippetEllipsisText, highlightPreTag, highlightPostTag),

}, {});
};
var parseFormatting = function (formattedHit, instantSearchParams) {
}
/**
* Adapt MeiliSearch formating to formating compliant with instantsearch.js.
*
* @param {Record<string} formattedHit
* @param {InstantSearchParams} instantSearchParams
* @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;
if (!formattedHit || formattedHit.length)
return {};
return {
_highlightResult: createHighlighResult(__assign({ formattedHit: formattedHit }, instantSearchParams)),
_snippetResult: createSnippetResult(__assign({ formattedHit: formattedHit }, instantSearchParams)),
_highlightResult: adaptHighlight(formattedHit, highlightPreTag, highlightPostTag),
_snippetResult: adaptSnippet(formattedHit, attributesToSnippet, snippetEllipsisText, highlightPreTag, highlightPostTag),
};
};
var adaptToISHits = function (meiliSearchHits, instantSearchParams, instantMeiliSearchContext) {
}
/**
* @param {Array<Record<string} meiliSearchHits
* @param {InstantSearchParams} instantSearchParams
* @param {SearchContext} instantMeiliSearchContext
* @returns any
*/
function adaptHits(meiliSearchHits, instantSearchParams, instantMeiliSearchContext) {
var primaryKey = instantMeiliSearchContext.primaryKey;
var paginatedHits = paginateHits(meiliSearchHits, instantMeiliSearchContext);
var page = instantMeiliSearchContext.page, hitsPerPage = instantMeiliSearchContext.hitsPerPage;
var paginatedHits = adaptPagination(meiliSearchHits, page, hitsPerPage);
return paginatedHits.map(function (hit) {

@@ -231,23 +393,72 @@ // Creates Hit object compliant with InstantSearch

var formattedHit = hit._formatted; hit._matchesInfo; var restOfHit = __rest(hit, ["_formatted", "_matchesInfo"]);
return __assign(__assign(__assign({}, restOfHit), parseFormatting(formattedHit, instantSearchParams)), (primaryKey && { objectID: hit[primaryKey] }));
return __assign(__assign(__assign({}, restOfHit), adaptFormating(formattedHit, instantSearchParams)), (primaryKey && { objectID: hit[primaryKey] }));
}
return hit;
});
};
}
var adaptToISResponse = function (indexUid, _a, instantSearchParams, instantMeiliSearchContext) {
var exhaustiveFacetsCount = _a.exhaustiveFacetsCount, exhaustiveNbHits = _a.exhaustiveNbHits, facets = _a.facetsDistribution, nbHits = _a.nbHits, processingTimeMs = _a.processingTimeMs, query = _a.query, hits = _a.hits;
/**
* Adapt search response from MeiliSearch
* to search response compliant with instantsearch.js
*
* @param {string} indexUid
* @param {MeiliSearchResponse<Record<string} searchResponse
* @param {InstantSearchParams} instantSearchParams
* @param {SearchContext} instantMeiliSearchContext
* @returns Array
*/
function adaptSearchResponse(indexUid, searchResponse, instantSearchParams, instantMeiliSearchContext) {
var searchResponseOptionals = {};
var facets = searchResponse.facetsDistribution;
var exhaustiveFacetsCount = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.exhaustiveFacetsCount;
if (exhaustiveFacetsCount) {
searchResponseOptionals.exhaustiveFacetsCount = exhaustiveFacetsCount;
}
var hits = adaptHits(searchResponse.hits, instantSearchParams, instantMeiliSearchContext);
var nbPages = ceiledDivision(searchResponse.hits.length, instantMeiliSearchContext.hitsPerPage);
var exhaustiveNbHits = searchResponse.exhaustiveNbHits;
var nbHits = searchResponse.nbHits;
var processingTimeMs = searchResponse.processingTimeMs;
var query = searchResponse.query;
var hitsPerPage = instantMeiliSearchContext.hitsPerPage, page = instantMeiliSearchContext.page;
// Create response object compliant with InstantSearch
var hitsPerPage = instantMeiliSearchContext.hitsPerPage, page = instantMeiliSearchContext.page;
var ISResponse = __assign(__assign(__assign({ index: indexUid, hitsPerPage: hitsPerPage }, (facets && { facets: facets })), (exhaustiveFacetsCount && { exhaustiveFacetsCount: exhaustiveFacetsCount })), { page: page, nbPages: getNumberPages(hits.length, instantMeiliSearchContext), exhaustiveNbHits: exhaustiveNbHits, nbHits: nbHits, processingTimeMS: processingTimeMs, query: query, hits: adaptToISHits(hits, instantSearchParams, instantMeiliSearchContext) });
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);
return {
results: [ISResponse],
results: [adaptedSearchResponse],
};
};
}
var removeUndefined = function (arr) {
return arr.filter(function (x) { return x !== undefined; });
};
/**
* 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
*/
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;
}
}
}
}
return distribution;
}
var parseFilter = function (filter) {
/**
* @param {string} filter
*/
var adaptFilterSyntax = function (filter) {
var matches = filter.match(/([^=]*)="?([^\\"]*)"?$/);

@@ -260,5 +471,9 @@ if (matches) {

};
var parseFilters = function (filters) {
/**
* @param {Filter} filters?
* @returns Array
*/
function extractFilters(filters) {
if (typeof filters === 'string') {
return parseFilter(filters);
return adaptFilterSyntax(filters);
}

@@ -269,5 +484,5 @@ else if (Array.isArray(filters)) {

if (Array.isArray(nestedFilter)) {
return nestedFilter.map(function (filter) { return parseFilter(filter); });
return nestedFilter.map(function (filter) { return adaptFilterSyntax(filter); });
}
return parseFilter(nestedFilter);
return adaptFilterSyntax(nestedFilter);
})

@@ -277,6 +492,10 @@ .flat(2);

return [undefined];
};
var cacheFilters = function (filters) {
var parsedFilters = parseFilters(filters);
var cleanFilters = removeUndefined(parsedFilters);
}
/**
* @param {Filter} filters?
* @returns Cache
*/
function cacheFilters(filters) {
var extractedFilters = extractFilters(filters);
var cleanFilters = removeUndefined(extractedFilters);
return cleanFilters.reduce(function (cache, parsedFilter) {

@@ -286,66 +505,76 @@ var _a;

var prevFields = cache[filterName] || [];
cache = __assign(__assign({}, cache), (_a = {}, _a[filterName] = __spreadArray(__spreadArray([], prevFields), [value]), _a));
cache = __assign(__assign({}, cache), (_a = {}, _a[filterName] = __spreadArray(__spreadArray([], prevFields, true), [value]), _a));
return cache;
}, {});
};
var addMissingFacetZeroFields = function (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;
}
}
}
}
return distribution;
};
}
function instantMeiliSearch(hostUrl, apiKey, options) {
if (options === void 0) { options = {}; }
/**
* 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.
*
* @param {string} hostUrl
* @param {string} apiKey
* @param {InstantMeiliSearchOptions={}} meiliSearchOptions
* @returns InstantMeiliSearchInstance
*/
function instantMeiliSearch(hostUrl, apiKey, meiliSearchOptions) {
if (meiliSearchOptions === void 0) { meiliSearchOptions = {}; }
return {
MeiliSearchClient: new meilisearch.MeiliSearch({ host: hostUrl, apiKey: apiKey }),
search: function (instantSearchRequests) {
search: function (instantSearchRequests
// options?: RequestOptions & MultipleQueriesOptions - When is this used ?
) {
return __awaiter(this, void 0, void 0, function () {
var isSearchRequest, instantSearchParams, indexName, _a, indexUid, sortByArray, paginationTotalHits, primaryKey, placeholderSearch, page, hitsPerPage, client, context, msSearchParams, cachedFacet, searchResponse, ISresponse, e_1;
return __generator(this, function (_b) {
switch (_b.label) {
var searchRequest, instantSearchParams, context, adaptedSearchRequest, cachedFacet, searchResponse, adaptedSearchResponse, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_b.trys.push([0, 2, , 3]);
isSearchRequest = instantSearchRequests[0];
instantSearchParams = isSearchRequest.params, indexName = isSearchRequest.indexName;
_a = indexName.split(':'), indexUid = _a[0], sortByArray = _a.slice(1);
paginationTotalHits = options.paginationTotalHits, primaryKey = options.primaryKey, placeholderSearch = options.placeholderSearch;
page = instantSearchParams.page, hitsPerPage = instantSearchParams.hitsPerPage;
client = this.MeiliSearchClient;
context = {
client: client,
paginationTotalHits: paginationTotalHits || 200,
primaryKey: primaryKey || undefined,
placeholderSearch: placeholderSearch !== false,
hitsPerPage: hitsPerPage === undefined ? 20 : hitsPerPage,
page: page || 0,
sort: sortByArray.join(':') || '',
};
msSearchParams = adaptToMeiliSearchParams(instantSearchParams, context);
cachedFacet = cacheFilters(msSearchParams.filter);
return [4 /*yield*/, client
.index(indexUid)
.search(msSearchParams.q, msSearchParams)
_a.trys.push([0, 2, , 3]);
searchRequest = instantSearchRequests[0];
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
];
case 1:
searchResponse = _b.sent();
searchResponse = _a.sent();
// Add the checked facet attributes in facetsDistribution and give them a value of 0
searchResponse.facetsDistribution = addMissingFacetZeroFields(cachedFacet, searchResponse.facetsDistribution);
ISresponse = adaptToISResponse(indexUid, searchResponse, instantSearchParams, context);
return [2 /*return*/, ISresponse];
searchResponse.facetsDistribution = facetsDistributionAdapter(cachedFacet, searchResponse.facetsDistribution);
adaptedSearchResponse = adaptSearchResponse(context.indexUid, searchResponse, instantSearchParams, context);
return [2 /*return*/, adaptedSearchResponse];
case 2:
e_1 = _b.sent();
e_1 = _a.sent();
console.error(e_1);

@@ -358,15 +587,24 @@ throw new Error(e_1);

},
searchForFacetValues: function (_) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
reject(new Error('SearchForFacetValues is not compatible with MeiliSearch'));
resolve([]); // added here to avoid compilation error
})];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
},
};
}
exports.adaptToISHits = adaptToISHits;
exports.adaptToISResponse = adaptToISResponse;
exports.adaptToMeiliSearchParams = adaptToMeiliSearchParams;
exports.createHighlighResult = createHighlighResult;
exports.createSnippetResult = createSnippetResult;
exports.getNumberPages = getNumberPages;
exports.adaptFormating = adaptFormating;
exports.adaptHits = adaptHits;
exports.adaptPagination = adaptPagination;
exports.adaptSearchRequest = adaptSearchRequest;
exports.adaptSearchResponse = adaptSearchResponse;
exports.facetsDistributionAdapter = facetsDistributionAdapter;
exports.instantMeiliSearch = instantMeiliSearch;
exports.isString = isString;
exports.paginateHits = paginateHits;
exports.replaceHighlightTags = replaceHighlightTags;
exports.snippetValue = snippetValue;

@@ -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{u(n.next(t))}catch(t){a(t)}}function s(t){try{u(n.throw(t))}catch(t){a(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,s)}u((n=n.apply(t,e||[])).next())}))}function n(t,e){var r,n,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){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,s])}}}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 a=function(t){return t.replace(/:(.*)/i,'="$1"')},o=function(t,r){var n=t.query,o=t.facets,s=t.facetFilters,u=t.attributesToSnippet,c=t.attributesToRetrieve,l=t.attributesToHighlight,f=t.filters,p=void 0===f?"":f,h=t.numericFilters,g=void 0===h?[]:h,v=r.paginationTotalHits,y=r.placeholderSearch,b=r.sort,d=v,m=function(t,e,r){var n=[r.join(" AND "),e.trim()].filter((function(t){return t})).join(" AND ").trim();return Array.isArray(t)&&n?i(i([],t),[[n]]):"string"==typeof t&&n?[t,[n]]:t}(function(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)})):a(t)})):[]}(s),p,g);return e(e(e(e(e(e({q:n},(null==o?void 0:o.length)&&{facetsDistribution:o}),u&&{attributesToCrop:u}),c&&{attributesToRetrieve:c}),m.length&&{filter:m}),{attributesToHighlight:l||["*"],limit:!y&&""===n||!d?0:d}),(null==b?void 0:b.length)&&{sort:[b]})},s=function(t,e){var r=e.hitsPerPage;return r>0?Math.ceil(t/r):0},u=function(t,e){var r=e.page,n=e.hitsPerPage,i=r*n;return t.splice(i,n)};function c(t){return"string"==typeof t||t instanceof String}var l=function(t,e,r){return e=e||"__ais-highlight__",r=r||"__/ais-highlight__",c(t)?t.replace(/<em>/g,e).replace(/<\/em>/g,r):JSON.stringify(t)},f=function(t){var e=t.formattedHit,r=t.highlightPreTag,n=t.highlightPostTag;return Object.keys(e).reduce((function(t,i){return t[i]={value:l(e[i],r,n)},t}),{})},p=function(t,e,r,n){var i=t;return void 0!==e&&c(i)&&i&&(i[0]===i[0].toLowerCase()&&!1===i.startsWith("<em>")&&(i=""+e+i),!1==!!i.match(/[.!?]$/)&&(i=""+i+e)),l(i,r,n)},h=function(t){var e=t.formattedHit,r=t.attributesToSnippet,n=t.snippetEllipsisText,i=t.highlightPreTag,a=t.highlightPostTag;return void 0===r?null:(r=r.map((function(t){return t.split(":")[0]})),Object.keys(e).reduce((function(t,o){return r.includes(o)&&(t[o]={value:p(e[o],n,i,a)}),t}),{}))},g=function(t,r,n){var i=n.primaryKey;return u(t,n).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),function(t,r){return!t||t.length?{}:{_highlightResult:f(e({formattedHit:t},r)),_snippetResult:h(e({formattedHit:t},r))}}(n,r)),i&&{objectID:t[i]})}return t}))},v=function(t,r,n,i){var a=r.exhaustiveFacetsCount,o=r.exhaustiveNbHits,u=r.facetsDistribution,c=r.nbHits,l=r.processingTimeMs,f=r.query,p=r.hits,h=i.hitsPerPage,v=i.page;return{results:[e(e(e({index:t,hitsPerPage:h},u&&{facets:u}),a&&{exhaustiveFacetsCount:a}),{page:v,nbPages:s(p.length,i),exhaustiveNbHits:o,nbHits:c,processingTimeMS:l,query:f,hits:g(p,n,i)})]}},y=function(t){var e=t.match(/([^=]*)="?([^\\"]*)"?$/);return e?(e[0],[{filterName:e[1],value:e[2]}]):[void 0]},b=function(t){var r=function(t){return"string"==typeof t?y(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return y(t)})):y(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,s=t[a]||[];return t=e(e({},t),((n={})[a]=i(i([],s),[o]),n))}),{})};exports.adaptToISHits=g,exports.adaptToISResponse=v,exports.adaptToMeiliSearchParams=o,exports.createHighlighResult=f,exports.createSnippetResult=h,exports.getNumberPages=s,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,s,u,c,l,f,p,h,g,y,d,m,x,P,T;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),e=t[0],r=e.params,i=e.indexName,s=i.split(":"),u=s[0],c=s.slice(1),l=a.paginationTotalHits,f=a.primaryKey,p=a.placeholderSearch,h=r.page,g=r.hitsPerPage,y=this.MeiliSearchClient,d={client:y,paginationTotalHits:l||200,primaryKey:f||void 0,placeholderSearch:!1!==p,hitsPerPage:void 0===g?20:g,page:h||0,sort:c.join(":")||""},m=o(r,d),x=b(m.filter),[4,y.index(u).search(m.q,m)];case 1:return(P=n.sent()).facetsDistribution=function(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}(x,P.facetsDistribution),[2,v(u,P,r,d)];case 2:throw T=n.sent(),console.error(T),new Error(T);case 3:return[2]}}))}))}}},exports.isString=c,exports.paginateHits=u,exports.replaceHighlightTags=l,exports.snippetValue=p;
***************************************************************************** */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()]}}))}))}}};
//# sourceMappingURL=instant-meilisearch.cjs.min.js.map

@@ -85,80 +85,211 @@ import { MeiliSearch } from 'meilisearch';

var replaceFilterSyntax = function (filter) {
var removeUndefined = function (arr) {
return arr.filter(function (x) { return x !== undefined; });
};
/**
* @param {any} str
* @returns boolean
*/
function isString(str) {
return typeof str === 'string' || str instanceof String;
}
/**
* @param {string} filter
* @returns string
*/
function replaceColonByEqualSign(filter) {
// will only change first occurence of `:`
return filter.replace(/:(.*)/i, '="$1"');
};
/*
* Adapt InstantSearch filters to MeiliSearch filters
* changes equal comparison sign from `:` to `=` in nested filter object
}
/**
* @param {number} dividend
* @param {number} divisor
* @returns number
*/
function ceiledDivision(dividend, divisor) {
if (divisor > 0) {
var NumberPages = Math.ceil(dividend / divisor); // total number of pages rounded up to the next largest integer.
return NumberPages;
}
return 0;
}
/**
* Transform InstantSearch filter to MeiliSearch filter.
* Change sign from `:` to `=` in nested filter object.
* example: [`genres:comedy`] becomes [`genres=comedy`]
*
* @param {AlgoliaSearchOptions['facetFilters']} filters?
* @returns Filter
*/
var facetFiltersToMeiliSearchFilter = function (filters) {
function transformFilter(filters) {
if (typeof filters === 'string') {
// will only change first occurence of `:`
return replaceFilterSyntax(filters);
return replaceColonByEqualSign(filters);
}
else if (Array.isArray(filters))
return filters.map(function (filter) {
return filters
.map(function (filter) {
if (Array.isArray(filter))
return filter.map(function (nestedFilter) { return replaceFilterSyntax(nestedFilter); });
return filter
.map(function (nestedFilter) { return replaceColonByEqualSign(nestedFilter); })
.filter(function (elem) { return elem; });
else {
return replaceFilterSyntax(filter);
return replaceColonByEqualSign(filter);
}
});
})
.filter(function (elem) { return elem; });
return [];
};
var mergeFilters = function (facetFilters, filters, numericFilters) {
var mergedFilters = [numericFilters.join(' AND '), filters.trim()]
.filter(function (x) { return x; })
.join(' AND ')
.trim();
if (Array.isArray(facetFilters) && mergedFilters)
return __spreadArray(__spreadArray([], facetFilters), [[mergedFilters]]);
if (typeof facetFilters === 'string' && mergedFilters)
return [facetFilters, [mergedFilters]];
return facetFilters;
};
var adaptToMeiliSearchParams = function (_a, _b) {
var query = _a.query, facets = _a.facets, facetFilters = _a.facetFilters, attributesToCrop = _a.attributesToSnippet, attributesToRetrieve = _a.attributesToRetrieve, attributesToHighlight = _a.attributesToHighlight, _c = _a.filters, filters = _c === void 0 ? '' : _c, _d = _a.numericFilters, numericFilters = _d === void 0 ? [] : _d;
var paginationTotalHits = _b.paginationTotalHits, placeholderSearch = _b.placeholderSearch, sort = _b.sort;
var limit = paginationTotalHits;
var meilisearchFilters = facetFiltersToMeiliSearchFilter(facetFilters);
var filter = mergeFilters(meilisearchFilters, filters, numericFilters);
}
/**
* Return the filter in an array if it is a string
* If filter is array, return without change.
*
* @param {Filter} filter
* @returns Array
*/
function filterToArray(filter) {
// Filter is a string
if (filter === '')
return [];
else if (typeof filter === 'string')
return [filter];
// Filter is either an array of strings, or an array of array of strings
return filter;
}
/**
* Merge facetFilters, numericFilters and filters together.
*
* @param {Filter} facetFilters
* @param {Filter} numericFilters
* @param {string} filters
* @returns Filter
*/
function mergeFilters(facetFilters, numericFilters, filters) {
var adaptedFilters = filters.trim();
var adaptedFacetFilters = filterToArray(facetFilters);
var adaptedNumericFilters = filterToArray(numericFilters);
var adaptedFilter = __spreadArray(__spreadArray(__spreadArray([], adaptedFacetFilters, true), adaptedNumericFilters, true), [
adaptedFilters,
]);
var cleanedFilters = adaptedFilter.filter(function (filter) {
if (Array.isArray(filter)) {
return filter.length;
}
return filter;
});
return cleanedFilters;
}
/**
* Adapt instantsearch.js filters to MeiliSearch filters by
* combining and transforming all provided filters.
*
* @param {string|undefined} filters
* @param {AlgoliaSearchOptions['numericFilters']} numericFilters
* @param {AlgoliaSearchOptions['facetFilters']} facetFilters
* @returns Filter
*/
function adaptFilters(filters, numericFilters, facetFilters) {
var transformedFilter = transformFilter(facetFilters || []);
var transformedNumericFilter = transformFilter(numericFilters || []);
return mergeFilters(transformedFilter, transformedNumericFilter, filters || '');
}
/**
* Adapt search request from instantsearch.js
* to search request compliant with MeiliSearch
*
* @param {InstantSearchParams} instantSearchParams
* @param {number} paginationTotalHits
* @param {boolean} placeholderSearch
* @param {string} sort?
* @param {string} query?
* @returns MeiliSearchParams
*/
function adaptSearchRequest(instantSearchParams, paginationTotalHits, placeholderSearch, sort, query) {
// Creates search params object compliant with MeiliSearch
return __assign(__assign(__assign(__assign(__assign(__assign({ q: query }, ((facets === null || facets === void 0 ? void 0 : facets.length) && { facetsDistribution: facets })), (attributesToCrop && { attributesToCrop: attributesToCrop })), (attributesToRetrieve && { attributesToRetrieve: attributesToRetrieve })), (filter.length && { filter: filter })), { attributesToHighlight: attributesToHighlight || ['*'], limit: (!placeholderSearch && query === '') || !limit ? 0 : limit }), ((sort === null || sort === void 0 ? void 0 : sort.length) && { sort: [sort] }));
};
var meiliSearchParams = {};
// Facets
var facets = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.facets;
if (facets === null || facets === void 0 ? void 0 : facets.length) {
meiliSearchParams.facetsDistribution = facets;
}
// Attributes To Crop
var attributesToCrop = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.attributesToSnippet;
if (attributesToCrop) {
meiliSearchParams.attributesToCrop = attributesToCrop;
}
// Attributes To Retrieve
var attributesToRetrieve = instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.attributesToRetrieve;
if (attributesToRetrieve) {
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);
if (filter.length) {
meiliSearchParams.filter = filter;
}
// Attributes To Retrieve
if (attributesToRetrieve) {
meiliSearchParams.attributesToCrop = attributesToRetrieve;
}
// Attributes To Highlight
meiliSearchParams.attributesToHighlight = (instantSearchParams === null || instantSearchParams === void 0 ? void 0 : instantSearchParams.attributesToHighlight) || [
'*',
];
if ((!placeholderSearch && query === '') || paginationTotalHits === 0) {
meiliSearchParams.limit = 0;
}
else {
meiliSearchParams.limit = paginationTotalHits;
}
// Sort
if (sort === null || sort === void 0 ? void 0 : sort.length) {
meiliSearchParams.sort = [sort];
}
return meiliSearchParams;
}
var getNumberPages = function (hitsLength, _a) {
var hitsPerPage = _a.hitsPerPage;
if (hitsPerPage > 0) {
var NumberPages = Math.ceil(hitsLength / hitsPerPage); // total number of pages rounded up to the next largest integer.
return NumberPages;
}
return 0;
};
var paginateHits = function (hits, _a) {
var page = _a.page, hitsPerPage = _a.hitsPerPage;
/**
* Slice the requested hits based on the pagination position.
*
* @param {Record<string} hits
* @param {number} page
* @param {number} hitsPerPage
* @returns Array
*/
function adaptPagination(hits, page, hitsPerPage) {
var start = page * hitsPerPage;
return hits.splice(start, hitsPerPage);
};
function isString(str) {
return typeof str === 'string' || str instanceof String;
}
var replaceHighlightTags = function (value, highlightPreTag, highlightPostTag) {
// Value has to be a string to have highlight.
/**
* Replace `em` tags in highlighted MeiliSearch hits to
* provided tags by instantsearch.js.
*
* @param {string} value
* @param {string} highlightPreTag?
* @param {string} highlightPostTag?
* @returns string
*/
function replaceHighlightTags(value, highlightPreTag, highlightPostTag) {
highlightPreTag = highlightPreTag || '__ais-highlight__';
highlightPostTag = highlightPostTag || '__/ais-highlight__';
// Highlight is applied by MeiliSearch (<em> tags)
// We replace the <em> by the expected tag for InstantSearch
highlightPreTag = highlightPreTag || '__ais-highlight__';
highlightPostTag = highlightPostTag || '__/ais-highlight__';
if (isString(value)) {
return value
.replace(/<em>/g, highlightPreTag)
.replace(/<\/em>/g, highlightPostTag);
}
// We JSON stringify to avoid loss of nested information
return JSON.stringify(value);
};
var createHighlighResult = function (_a) {
var formattedHit = _a.formattedHit, highlightPreTag = _a.highlightPreTag, highlightPostTag = _a.highlightPostTag;
var stringifiedValue = isString(value)
? value
: JSON.stringify(value, null, 2);
return stringifiedValue
.replace(/<em>/g, highlightPreTag)
.replace(/<\/em>/g, highlightPostTag);
}
/**
* @param {Record<string} formattedHit
* @param {string} highlightPreTag?
* @param {string} highlightPostTag?
* @returns Record
*/
function adaptHighlight(formattedHit, highlightPreTag, highlightPostTag) {
// formattedHit is the `_formatted` object returned by MeiliSearch.

@@ -172,6 +303,13 @@ // It contains all the highlighted and croped attributes

}, {});
};
var snippetValue = function (value, snippetEllipsisText, highlightPreTag, highlightPostTag) {
}
/**
* @param {string} value
* @param {string} snippetEllipsisText?
* @param {string} highlightPreTag?
* @param {string} highlightPostTag?
* @returns string
*/
function snippetValue(value, snippetEllipsisText, highlightPreTag, highlightPostTag) {
var newValue = value;
// manage a kind of `...` for the crop until this issue is solved: https://github.com/meilisearch/MeiliSearch/issues/923
// manage a kind of `...` for the crop until this feature is implemented https://roadmap.meilisearch.com/c/69-policy-for-cropped-values?utm_medium=social&utm_source=portal_share
// `...` is put if we are at the middle of a sentence (instead at the middle of the document field)

@@ -190,5 +328,11 @@ if (snippetEllipsisText !== undefined && isString(newValue) && newValue) {

return replaceHighlightTags(newValue, highlightPreTag, highlightPostTag);
};
var createSnippetResult = function (_a) {
var formattedHit = _a.formattedHit, attributesToSnippet = _a.attributesToSnippet, snippetEllipsisText = _a.snippetEllipsisText, highlightPreTag = _a.highlightPreTag, highlightPostTag = _a.highlightPostTag;
}
/**
* @param {Record<string} formattedHit
* @param {readonlystring[]|undefined} attributesToSnippet
* @param {string|undefined} snippetEllipsisText
* @param {string|undefined} highlightPreTag
* @param {string|undefined} highlightPostTag
*/
function adaptSnippet(formattedHit, attributesToSnippet, snippetEllipsisText, highlightPreTag, highlightPostTag) {
if (attributesToSnippet === undefined) {

@@ -201,3 +345,3 @@ return null;

return Object.keys(formattedHit).reduce(function (result, key) {
if (attributesToSnippet.includes(key)) {
if (attributesToSnippet === null || attributesToSnippet === void 0 ? void 0 : attributesToSnippet.includes(key)) {
result[key] = {

@@ -209,15 +353,33 @@ value: snippetValue(formattedHit[key], snippetEllipsisText, highlightPreTag, highlightPostTag),

}, {});
};
var parseFormatting = function (formattedHit, instantSearchParams) {
}
/**
* Adapt MeiliSearch formating to formating compliant with instantsearch.js.
*
* @param {Record<string} formattedHit
* @param {InstantSearchParams} instantSearchParams
* @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;
if (!formattedHit || formattedHit.length)
return {};
return {
_highlightResult: createHighlighResult(__assign({ formattedHit: formattedHit }, instantSearchParams)),
_snippetResult: createSnippetResult(__assign({ formattedHit: formattedHit }, instantSearchParams)),
_highlightResult: adaptHighlight(formattedHit, highlightPreTag, highlightPostTag),
_snippetResult: adaptSnippet(formattedHit, attributesToSnippet, snippetEllipsisText, highlightPreTag, highlightPostTag),
};
};
var adaptToISHits = function (meiliSearchHits, instantSearchParams, instantMeiliSearchContext) {
}
/**
* @param {Array<Record<string} meiliSearchHits
* @param {InstantSearchParams} instantSearchParams
* @param {SearchContext} instantMeiliSearchContext
* @returns any
*/
function adaptHits(meiliSearchHits, instantSearchParams, instantMeiliSearchContext) {
var primaryKey = instantMeiliSearchContext.primaryKey;
var paginatedHits = paginateHits(meiliSearchHits, instantMeiliSearchContext);
var page = instantMeiliSearchContext.page, hitsPerPage = instantMeiliSearchContext.hitsPerPage;
var paginatedHits = adaptPagination(meiliSearchHits, page, hitsPerPage);
return paginatedHits.map(function (hit) {

@@ -227,23 +389,72 @@ // Creates Hit object compliant with InstantSearch

var formattedHit = hit._formatted; hit._matchesInfo; var restOfHit = __rest(hit, ["_formatted", "_matchesInfo"]);
return __assign(__assign(__assign({}, restOfHit), parseFormatting(formattedHit, instantSearchParams)), (primaryKey && { objectID: hit[primaryKey] }));
return __assign(__assign(__assign({}, restOfHit), adaptFormating(formattedHit, instantSearchParams)), (primaryKey && { objectID: hit[primaryKey] }));
}
return hit;
});
};
}
var adaptToISResponse = function (indexUid, _a, instantSearchParams, instantMeiliSearchContext) {
var exhaustiveFacetsCount = _a.exhaustiveFacetsCount, exhaustiveNbHits = _a.exhaustiveNbHits, facets = _a.facetsDistribution, nbHits = _a.nbHits, processingTimeMs = _a.processingTimeMs, query = _a.query, hits = _a.hits;
/**
* Adapt search response from MeiliSearch
* to search response compliant with instantsearch.js
*
* @param {string} indexUid
* @param {MeiliSearchResponse<Record<string} searchResponse
* @param {InstantSearchParams} instantSearchParams
* @param {SearchContext} instantMeiliSearchContext
* @returns Array
*/
function adaptSearchResponse(indexUid, searchResponse, instantSearchParams, instantMeiliSearchContext) {
var searchResponseOptionals = {};
var facets = searchResponse.facetsDistribution;
var exhaustiveFacetsCount = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.exhaustiveFacetsCount;
if (exhaustiveFacetsCount) {
searchResponseOptionals.exhaustiveFacetsCount = exhaustiveFacetsCount;
}
var hits = adaptHits(searchResponse.hits, instantSearchParams, instantMeiliSearchContext);
var nbPages = ceiledDivision(searchResponse.hits.length, instantMeiliSearchContext.hitsPerPage);
var exhaustiveNbHits = searchResponse.exhaustiveNbHits;
var nbHits = searchResponse.nbHits;
var processingTimeMs = searchResponse.processingTimeMs;
var query = searchResponse.query;
var hitsPerPage = instantMeiliSearchContext.hitsPerPage, page = instantMeiliSearchContext.page;
// Create response object compliant with InstantSearch
var hitsPerPage = instantMeiliSearchContext.hitsPerPage, page = instantMeiliSearchContext.page;
var ISResponse = __assign(__assign(__assign({ index: indexUid, hitsPerPage: hitsPerPage }, (facets && { facets: facets })), (exhaustiveFacetsCount && { exhaustiveFacetsCount: exhaustiveFacetsCount })), { page: page, nbPages: getNumberPages(hits.length, instantMeiliSearchContext), exhaustiveNbHits: exhaustiveNbHits, nbHits: nbHits, processingTimeMS: processingTimeMs, query: query, hits: adaptToISHits(hits, instantSearchParams, instantMeiliSearchContext) });
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);
return {
results: [ISResponse],
results: [adaptedSearchResponse],
};
};
}
var removeUndefined = function (arr) {
return arr.filter(function (x) { return x !== undefined; });
};
/**
* 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
*/
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;
}
}
}
}
return distribution;
}
var parseFilter = function (filter) {
/**
* @param {string} filter
*/
var adaptFilterSyntax = function (filter) {
var matches = filter.match(/([^=]*)="?([^\\"]*)"?$/);

@@ -256,5 +467,9 @@ if (matches) {

};
var parseFilters = function (filters) {
/**
* @param {Filter} filters?
* @returns Array
*/
function extractFilters(filters) {
if (typeof filters === 'string') {
return parseFilter(filters);
return adaptFilterSyntax(filters);
}

@@ -265,5 +480,5 @@ else if (Array.isArray(filters)) {

if (Array.isArray(nestedFilter)) {
return nestedFilter.map(function (filter) { return parseFilter(filter); });
return nestedFilter.map(function (filter) { return adaptFilterSyntax(filter); });
}
return parseFilter(nestedFilter);
return adaptFilterSyntax(nestedFilter);
})

@@ -273,6 +488,10 @@ .flat(2);

return [undefined];
};
var cacheFilters = function (filters) {
var parsedFilters = parseFilters(filters);
var cleanFilters = removeUndefined(parsedFilters);
}
/**
* @param {Filter} filters?
* @returns Cache
*/
function cacheFilters(filters) {
var extractedFilters = extractFilters(filters);
var cleanFilters = removeUndefined(extractedFilters);
return cleanFilters.reduce(function (cache, parsedFilter) {

@@ -282,66 +501,76 @@ var _a;

var prevFields = cache[filterName] || [];
cache = __assign(__assign({}, cache), (_a = {}, _a[filterName] = __spreadArray(__spreadArray([], prevFields), [value]), _a));
cache = __assign(__assign({}, cache), (_a = {}, _a[filterName] = __spreadArray(__spreadArray([], prevFields, true), [value]), _a));
return cache;
}, {});
};
var addMissingFacetZeroFields = function (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;
}
}
}
}
return distribution;
};
}
function instantMeiliSearch(hostUrl, apiKey, options) {
if (options === void 0) { options = {}; }
/**
* 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.
*
* @param {string} hostUrl
* @param {string} apiKey
* @param {InstantMeiliSearchOptions={}} meiliSearchOptions
* @returns InstantMeiliSearchInstance
*/
function instantMeiliSearch(hostUrl, apiKey, meiliSearchOptions) {
if (meiliSearchOptions === void 0) { meiliSearchOptions = {}; }
return {
MeiliSearchClient: new MeiliSearch({ host: hostUrl, apiKey: apiKey }),
search: function (instantSearchRequests) {
search: function (instantSearchRequests
// options?: RequestOptions & MultipleQueriesOptions - When is this used ?
) {
return __awaiter(this, void 0, void 0, function () {
var isSearchRequest, instantSearchParams, indexName, _a, indexUid, sortByArray, paginationTotalHits, primaryKey, placeholderSearch, page, hitsPerPage, client, context, msSearchParams, cachedFacet, searchResponse, ISresponse, e_1;
return __generator(this, function (_b) {
switch (_b.label) {
var searchRequest, instantSearchParams, context, adaptedSearchRequest, cachedFacet, searchResponse, adaptedSearchResponse, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_b.trys.push([0, 2, , 3]);
isSearchRequest = instantSearchRequests[0];
instantSearchParams = isSearchRequest.params, indexName = isSearchRequest.indexName;
_a = indexName.split(':'), indexUid = _a[0], sortByArray = _a.slice(1);
paginationTotalHits = options.paginationTotalHits, primaryKey = options.primaryKey, placeholderSearch = options.placeholderSearch;
page = instantSearchParams.page, hitsPerPage = instantSearchParams.hitsPerPage;
client = this.MeiliSearchClient;
context = {
client: client,
paginationTotalHits: paginationTotalHits || 200,
primaryKey: primaryKey || undefined,
placeholderSearch: placeholderSearch !== false,
hitsPerPage: hitsPerPage === undefined ? 20 : hitsPerPage,
page: page || 0,
sort: sortByArray.join(':') || '',
};
msSearchParams = adaptToMeiliSearchParams(instantSearchParams, context);
cachedFacet = cacheFilters(msSearchParams.filter);
return [4 /*yield*/, client
.index(indexUid)
.search(msSearchParams.q, msSearchParams)
_a.trys.push([0, 2, , 3]);
searchRequest = instantSearchRequests[0];
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
];
case 1:
searchResponse = _b.sent();
searchResponse = _a.sent();
// Add the checked facet attributes in facetsDistribution and give them a value of 0
searchResponse.facetsDistribution = addMissingFacetZeroFields(cachedFacet, searchResponse.facetsDistribution);
ISresponse = adaptToISResponse(indexUid, searchResponse, instantSearchParams, context);
return [2 /*return*/, ISresponse];
searchResponse.facetsDistribution = facetsDistributionAdapter(cachedFacet, searchResponse.facetsDistribution);
adaptedSearchResponse = adaptSearchResponse(context.indexUid, searchResponse, instantSearchParams, context);
return [2 /*return*/, adaptedSearchResponse];
case 2:
e_1 = _b.sent();
e_1 = _a.sent();
console.error(e_1);

@@ -354,5 +583,18 @@ throw new Error(e_1);

},
searchForFacetValues: function (_) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
reject(new Error('SearchForFacetValues is not compatible with MeiliSearch'));
resolve([]); // added here to avoid compilation error
})];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
},
};
}
export { adaptToISHits, adaptToISResponse, adaptToMeiliSearchParams, createHighlighResult, createSnippetResult, getNumberPages, instantMeiliSearch, isString, paginateHits, replaceHighlightTags, snippetValue };
export { adaptFormating, adaptHits, adaptPagination, adaptSearchRequest, adaptSearchResponse, facetsDistributionAdapter, 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,a){function o(t){try{s(n.next(t))}catch(t){a(t)}}function u(t){try{s(n.throw(t))}catch(t){a(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(o,u)}s((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}var a=function(t){return t.replace(/:(.*)/i,'="$1"')},o=function(t,r){var n=t.query,o=t.facets,u=t.facetFilters,s=t.attributesToSnippet,c=t.attributesToRetrieve,l=t.attributesToHighlight,f=t.filters,h=void 0===f?"":f,p=t.numericFilters,g=void 0===p?[]:p,v=r.paginationTotalHits,y=r.placeholderSearch,b=r.sort,m=v,d=function(t,e,r){var n=[r.join(" AND "),e.trim()].filter((function(t){return t})).join(" AND ").trim();return Array.isArray(t)&&n?i(i([],t),[[n]]):"string"==typeof t&&n?[t,[n]]:t}(function(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)})):a(t)})):[]}(u),h,g);return e(e(e(e(e(e({q:n},(null==o?void 0:o.length)&&{facetsDistribution:o}),s&&{attributesToCrop:s}),c&&{attributesToRetrieve:c}),d.length&&{filter:d}),{attributesToHighlight:l||["*"],limit:!y&&""===n||!m?0:m}),(null==b?void 0:b.length)&&{sort:[b]})},u=function(t,e){var r=e.hitsPerPage;return r>0?Math.ceil(t/r):0},s=function(t,e){var r=e.page,n=e.hitsPerPage,i=r*n;return t.splice(i,n)};function c(t){return"string"==typeof t||t instanceof String}var l=function(t,e,r){return e=e||"__ais-highlight__",r=r||"__/ais-highlight__",c(t)?t.replace(/<em>/g,e).replace(/<\/em>/g,r):JSON.stringify(t)},f=function(t){var e=t.formattedHit,r=t.highlightPreTag,n=t.highlightPostTag;return Object.keys(e).reduce((function(t,i){return t[i]={value:l(e[i],r,n)},t}),{})},h=function(t,e,r,n){var i=t;return void 0!==e&&c(i)&&i&&(i[0]===i[0].toLowerCase()&&!1===i.startsWith("<em>")&&(i=""+e+i),!1==!!i.match(/[.!?]$/)&&(i=""+i+e)),l(i,r,n)},p=function(t){var e=t.formattedHit,r=t.attributesToSnippet,n=t.snippetEllipsisText,i=t.highlightPreTag,a=t.highlightPostTag;return void 0===r?null:(r=r.map((function(t){return t.split(":")[0]})),Object.keys(e).reduce((function(t,o){return r.includes(o)&&(t[o]={value:h(e[o],n,i,a)}),t}),{}))},g=function(t,r,n){var i=n.primaryKey;return s(t,n).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),function(t,r){return!t||t.length?{}:{_highlightResult:f(e({formattedHit:t},r)),_snippetResult:p(e({formattedHit:t},r))}}(n,r)),i&&{objectID:t[i]})}return t}))},v=function(t,r,n,i){var a=r.exhaustiveFacetsCount,o=r.exhaustiveNbHits,s=r.facetsDistribution,c=r.nbHits,l=r.processingTimeMs,f=r.query,h=r.hits,p=i.hitsPerPage,v=i.page;return{results:[e(e(e({index:t,hitsPerPage:p},s&&{facets:s}),a&&{exhaustiveFacetsCount:a}),{page:v,nbPages:u(h.length,i),exhaustiveNbHits:o,nbHits:c,processingTimeMS:l,query:f,hits:g(h,n,i)})]}},y=function(t){var e=t.match(/([^=]*)="?([^\\"]*)"?$/);return e?(e[0],[{filterName:e[1],value:e[2]}]):[void 0]},b=function(t){var r=function(t){return"string"==typeof t?y(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return y(t)})):y(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))}),{})};function m(e,i,a){return void 0===a&&(a={}),{MeiliSearchClient:new t({host:e,apiKey:i}),search:function(t){return r(this,void 0,void 0,(function(){var e,r,i,u,s,c,l,f,h,p,g,y,m,d,P,w,O;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),e=t[0],r=e.params,i=e.indexName,u=i.split(":"),s=u[0],c=u.slice(1),l=a.paginationTotalHits,f=a.primaryKey,h=a.placeholderSearch,p=r.page,g=r.hitsPerPage,y=this.MeiliSearchClient,m={client:y,paginationTotalHits:l||200,primaryKey:f||void 0,placeholderSearch:!1!==h,hitsPerPage:void 0===g?20:g,page:p||0,sort:c.join(":")||""},d=o(r,m),P=b(d.filter),[4,y.index(s).search(d.q,d)];case 1:return(w=n.sent()).facetsDistribution=function(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}(P,w.facetsDistribution),[2,v(s,w,r,m)];case 2:throw O=n.sent(),console.error(O),new Error(O);case 3:return[2]}}))}))}}}export{g as adaptToISHits,v as adaptToISResponse,o as adaptToMeiliSearchParams,f as createHighlighResult,p as createSnippetResult,u as getNumberPages,m as instantMeiliSearch,c as isString,s as paginateHits,l as replaceHighlightTags,h as snippetValue};
***************************************************************************** */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};
//# sourceMappingURL=instant-meilisearch.esm.min.js.map

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

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var e=function(){return(e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function r(t,e,r,n){return new(r||(r=Promise))((function(i,s){function o(t){try{a(n.next(t))}catch(t){s(t)}}function u(t){try{a(n.throw(t))}catch(t){s(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,u)}a((n=n.apply(t,e||[])).next())}))}function n(t,e){var r,n,i,s,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,n=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function i(t,e){for(var r=0,n=e.length,i=t.length;r<n;r++,i++)t[i]=e[r];return t}var s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function o(t){var e={exports:{}};return t(e,e.exports),e.exports}o((function(t){!function(t){!function(e){var r="URLSearchParams"in t,n="Symbol"in t&&"iterator"in Symbol,i="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),s="FormData"in t,o="ArrayBuffer"in t;if(o)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],a=ArrayBuffer.isView||function(t){return t&&u.indexOf(Object.prototype.toString.call(t))>-1};function c(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function h(t){return"string"!=typeof t&&(t=String(t)),t}function f(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n&&(e[Symbol.iterator]=function(){return e}),e}function 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 l(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=l(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?l(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var t,e,r,n=l(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)})),f(t)},d.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),f(t)},d.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),f(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 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){
/*! *****************************************************************************

@@ -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){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),u=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);function a(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 c(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 h=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),f=function(t){function e(e,r){var n=t.call(this,e.message)||this;return n.type="MeiliSearchApiError",n.name="MeiliSearchApiError",n.errorCode=e.errorCode,n.errorType=e.errorType,n.errorLink=e.errorLink,n.message=e.message,n.httpStatus=r,Error.captureStackTrace&&Error.captureStackTrace(n,f),n}return r(e,t),e}(Error);function d(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 h(t.statusText,t);case 4:throw new f(e,t.status);case 5:return[2,t]}}))}))}function l(t){if("MeiliSearchApiError"!==t.type)throw new h(t.message,t);throw t}var p=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,a=t.config;return i(this,void 0,void 0,(function(){var t,i,c;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({},a),{method:e,body:JSON.stringify(u),headers:this.headers})).then((function(t){return d(t)}))];case 1:return[4,s.sent().text()];case 2:c=s.sent();try{return[2,JSON.parse(c)]}catch(t){return[2]}return[3,4];case 3:return l(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}(),y=function(){function t(t,e,r){this.uid=e,this.primaryKey=r,this.httpRequest=new p(t)}return t.prototype.waitForPendingUpdate=function(t,e){var r=void 0===e?{}:e,n=r.timeOutMs,o=void 0===n?5e3:n,a=r.intervalMs,h=void 0===a?50:a;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,c(h)]:[2,r];case 3:return n.sent(),[3,1];case 4:throw new u("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,a(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,u,c;return s(this,(function(s){switch(s.label){case 0:return i="indexes/"+this.uid+"/search",u=function(t){if("string"==typeof t)return t;if(Array.isArray(t))throw new o("The filter query parameter should be in string format when using searchGet")},c=n(n({q:t},e),{filter:u(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,a(c),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 p(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=p.addTrailingSlash(t.host),this.config=t,this.httpRequest=new p(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 f(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.MeiliSearch=v,Object.defineProperty(t,"__esModule",{value:!0})}(e)})),a=function(t){return t.replace(/:(.*)/i,'="$1"')},c=function(t,r){var n=t.query,s=t.facets,o=t.facetFilters,u=t.attributesToSnippet,c=t.attributesToRetrieve,h=t.attributesToHighlight,f=t.filters,d=void 0===f?"":f,l=t.numericFilters,p=void 0===l?[]:l,y=r.paginationTotalHits,v=r.placeholderSearch,b=r.sort,g=y,w=function(t,e,r){var n=[r.join(" AND "),e.trim()].filter((function(t){return t})).join(" AND ").trim();return Array.isArray(t)&&n?i(i([],t),[[n]]):"string"==typeof t&&n?[t,[n]]:t}(function(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)})):a(t)})):[]}(o),d,p);return e(e(e(e(e(e({q:n},(null==s?void 0:s.length)&&{facetsDistribution:s}),u&&{attributesToCrop:u}),c&&{attributesToRetrieve:c}),w.length&&{filter:w}),{attributesToHighlight:h||["*"],limit:!v&&""===n||!g?0:g}),(null==b?void 0:b.length)&&{sort:[b]})},h=function(t,e){var r=e.hitsPerPage;return r>0?Math.ceil(t/r):0},f=function(t,e){var r=e.page,n=e.hitsPerPage,i=r*n;return t.splice(i,n)};function d(t){return"string"==typeof t||t instanceof String}var l=function(t,e,r){return e=e||"__ais-highlight__",r=r||"__/ais-highlight__",d(t)?t.replace(/<em>/g,e).replace(/<\/em>/g,r):JSON.stringify(t)},p=function(t){var e=t.formattedHit,r=t.highlightPreTag,n=t.highlightPostTag;return Object.keys(e).reduce((function(t,i){return t[i]={value:l(e[i],r,n)},t}),{})},y=function(t,e,r,n){var i=t;return void 0!==e&&d(i)&&i&&(i[0]===i[0].toLowerCase()&&!1===i.startsWith("<em>")&&(i=""+e+i),!1==!!i.match(/[.!?]$/)&&(i=""+i+e)),l(i,r,n)},v=function(t){var e=t.formattedHit,r=t.attributesToSnippet,n=t.snippetEllipsisText,i=t.highlightPreTag,s=t.highlightPostTag;return void 0===r?null:(r=r.map((function(t){return t.split(":")[0]})),Object.keys(e).reduce((function(t,o){return r.includes(o)&&(t[o]={value:y(e[o],n,i,s)}),t}),{}))},b=function(t,r,n){var i=n.primaryKey;return f(t,n).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,r){return!t||t.length?{}:{_highlightResult:p(e({formattedHit:t},r)),_snippetResult:v(e({formattedHit:t},r))}}(n,r)),i&&{objectID:t[i]})}return t}))},g=function(t,r,n,i){var s=r.exhaustiveFacetsCount,o=r.exhaustiveNbHits,u=r.facetsDistribution,a=r.nbHits,c=r.processingTimeMs,f=r.query,d=r.hits,l=i.hitsPerPage,p=i.page;return{results:[e(e(e({index:t,hitsPerPage:l},u&&{facets:u}),s&&{exhaustiveFacetsCount:s}),{page:p,nbPages:h(d.length,i),exhaustiveNbHits:o,nbHits:a,processingTimeMS:c,query:f,hits:b(d,n,i)})]}},w=function(t){var e=t.match(/([^=]*)="?([^\\"]*)"?$/);return e?(e[0],[{filterName:e[1],value:e[2]}]):[void 0]},m=function(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,s=r.filterName,o=r.value,u=t[s]||[];return t=e(e({},t),((n={})[s]=i(i([],u),[o]),n))}),{})};t.adaptToISHits=b,t.adaptToISResponse=g,t.adaptToMeiliSearchParams=c,t.createHighlighResult=p,t.createSnippetResult=v,t.getNumberPages=h,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,h,f,d,l,p,y,v,b,w,x,R;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),e=t[0],r=e.params,s=e.indexName,o=s.split(":"),u=o[0],a=o.slice(1),h=i.paginationTotalHits,f=i.primaryKey,d=i.placeholderSearch,l=r.page,p=r.hitsPerPage,y=this.MeiliSearchClient,v={client:y,paginationTotalHits:h||200,primaryKey:f||void 0,placeholderSearch:!1!==d,hitsPerPage:void 0===p?20:p,page:l||0,sort:a.join(":")||""},b=c(r,v),w=m(b.filter),[4,y.index(u).search(b.q,b)];case 1:return(x=n.sent()).facetsDistribution=function(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}(w,x.facetsDistribution),[2,g(u,x,r,v)];case 2:throw R=n.sent(),console.error(R),new Error(R);case 3:return[2]}}))}))}}},t.isString=d,t.paginateHits=f,t.replaceHighlightTags=l,t.snippetValue=y,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),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})}));
//# sourceMappingURL=instant-meilisearch.umd.min.js.map

@@ -1,6 +0,7 @@

export * from './to-meilisearch-params';
export * from './to-instantsearch-response';
export * from './to-instantsearch-hits';
export * from './to-instantsearch-highlight';
export * from './pagination';
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
import { Filter, Cache } from '../types';
export declare const cacheFilters: (filters?: Filter | undefined) => Cache;
export declare const addMissingFacetZeroFields: (cache?: Cache | undefined, distribution?: import("meilisearch").FacetsDistribution | undefined) => import("meilisearch").FacetsDistribution;
/**
* @param {Filter} filters?
* @returns Cache
*/
export declare function cacheFilters(filters?: Filter): Cache;
//# sourceMappingURL=filters.d.ts.map
import { InstantMeiliSearchOptions, InstantMeiliSearchInstance } from '../types';
export declare function instantMeiliSearch(hostUrl: string, apiKey: string, options?: InstantMeiliSearchOptions): InstantMeiliSearchInstance;
/**
* 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;
//# sourceMappingURL=index.d.ts.map

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

// Type definitions for @meilisearch/instant-meilisearch 0.5.4
// Type definitions for @meilisearch/instant-meilisearch 0.5.5
// Project: https://github.com/meilisearch/instant-meilisearch.git
// Definitions by: Clementine Urquizar <https://github.com/meilisearch>
// Definitions: https://github.com/meilisearch/instant-meilisearch.git
// TypeScript Version: ^4.3.5
// TypeScript Version: ^4.4.3

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

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

@@ -1,3 +0,8 @@

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

@@ -10,17 +15,2 @@ [category: string]: string[];

};
export declare type FacetsDistribution = MStypes.FacetsDistribution;
export declare type Filter = string | Array<string | string[]>;
export declare type IMSearchParams = Omit<IStypes.SearchParameters, 'facetFilters' | 'filters'> & {
query?: string;
filter?: Filter;
};
export declare type ISSearchParams = Omit<IStypes.SearchParameters, 'facetFilters'> & {
query?: string;
facetFilters?: Filter;
sort?: string;
};
export declare type ISSearchRequest = {
indexName: string;
params: ISSearchParams;
};
export declare type InstantMeiliSearchOptions = {

@@ -31,59 +21,17 @@ paginationTotalHits?: number;

};
export declare type ISHits<T = Record<string, any>> = T & {
_highlightResult: Record<keyof T, {
value: string;
}>;
};
export declare type IMResponse = {
facets?: Record<string, Record<string, number> | undefined>;
exhaustiveFacetsCount?: boolean;
exhaustiveNbHits: boolean;
nbPages?: number;
};
export declare type SearchResponse = Omit<IStypes.SearchResponse, 'hits'> & IStypes.SearchResponse & IMResponse & {
hits: ISHits[];
};
export declare type InstantMeiliSearchContext = {
export declare type SearchContext = {
page: number;
paginationTotalHits: number;
hitsPerPage: number;
primaryKey: string | undefined;
client: MStypes.MeiliSearch;
primaryKey?: string;
client: MeiliSearch;
placeholderSearch: boolean;
sort?: string;
query?: string;
indexUid: string;
};
export declare type FormattedHit = {
formattedHit: any;
export declare type AdaptToMeiliSearchParams = (instantSearchParams: InstantSearchParams, instantMeiliSearchContext: SearchContext) => Record<string, any>;
export declare type InstantMeiliSearchInstance = SearchClient & {
MeiliSearchClient: MeiliSearch;
};
export declare type HighLightParams = {
formattedHit: any;
highlightPreTag?: string;
highlightPostTag?: string;
};
export declare type SnippetsParams = {
snippetEllipsisText?: string;
attributesToSnippet?: string[];
};
export declare type CreateHighlighResult = (highLightParams: HighLightParams & FormattedHit) => {
formattedHit: any;
} & IMSearchParams;
export declare type ReplaceHighlightTags = (value: string, highlightPreTag?: string, highlightPostTag?: string) => string;
export declare type CreateSnippetResult = (snippetsParams: HighLightParams & SnippetsParams & FormattedHit) => {
formattedHit: any;
} & IMSearchParams;
export declare type SnippetValue = (value: string, snippetEllipsisText?: string, highlightPreTag?: string, highlightPostTag?: string) => string;
export declare type AdaptToMeiliSearchParams = (instantSearchParams: ISSearchParams, instantMeiliSearchContext: InstantMeiliSearchContext) => Record<string, any>;
export declare type AdaptToISResponse = (indexUid: string, meiliSearchResponse: MStypes.SearchResponse<any, any>, instantSearchParams: IMSearchParams, instantMeiliSearchContext: InstantMeiliSearchContext) => {
results: SearchResponse[];
};
export declare type AdaptToISHitsm = (meiliSearchHits: Array<Record<string, any>>, instantSearchParams: IMSearchParams, instantMeiliSearchContext: InstantMeiliSearchContext) => ISHits[];
export declare type GetNumberPages = (hitsLength: number, instantMeiliSearchContext: InstantMeiliSearchContext) => number;
export declare type PaginateHits = (meiliSearchHits: Array<Record<string, any>>, instantMeiliSearchContext: InstantMeiliSearchContext) => Array<Record<string, any>>;
export declare type InstantMeiliSearchInstance = {
MeiliSearchClient: MStypes.MeiliSearch;
search: (requests: ISSearchRequest[]) => Promise<{
results: SearchResponse[];
}>;
};
export declare type InstantMeiliSearchClient = (hostUrl: string, apiKey: string, options: InstantMeiliSearchOptions) => InstantMeiliSearchInstance;
//# sourceMappingURL=types.d.ts.map
export * from './array';
export * from './string';
export * from './number';
//# sourceMappingURL=index.d.ts.map
{
"name": "@meilisearch/instant-meilisearch",
"version": "0.5.4",
"version": "0.5.5",
"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:javascript\" \"cypress run --env playground=javascript\"",
"test:e2e": "concurrently --kill-others -s first \"NODE_ENV=test yarn playground:angular\" \"cypress run --env playground=angular\"",
"test:e2e:all": "sh scripts/e2e.sh",
"test:e2e:watch": "concurrently --kill-others -s first \"NODE_ENV=test yarn playground:javascript\" \"cypress open --env playground=javascript\"",
"test:e2e:watch": "concurrently --kill-others -s first \"NODE_ENV=test yarn playground:angular\" \"cypress open --env playground=angular\"",
"test:all": "yarn test:e2e:all && yarn test && test:build",

@@ -57,3 +57,3 @@ "cy:open": "cypress open",

"dependencies": {
"meilisearch": "^0.20.1"
"meilisearch": "^0.21.0"
},

@@ -66,8 +66,10 @@ "devDependencies": {

"@rollup/plugin-node-resolve": "^11.2.0",
"@typescript-eslint/eslint-plugin": "^4.16.1",
"@typescript-eslint/parser": "^4.16.1",
"@types/jest": "^27.0.2",
"@typescript-eslint/eslint-plugin": "^4.32.0",
"@typescript-eslint/parser": "^4.32.0",
"@vue/eslint-config-typescript": "^7.0.0",
"@vue/eslint-plugin": "^4.2.0",
"algoliasearch": "^4.10.5",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.1.0",
"babel-jest": "^27.2.2",
"concurrently": "^6.2.1",

@@ -92,3 +94,3 @@ "cssnano": "^4.1.10",

"instantsearch.js": "^4.30.1",
"jest": "^26.6.3",
"jest": "^27.2.2",
"jest-watch-typeahead": "^0.6.3",

@@ -103,6 +105,6 @@ "prettier": "^2.0.0",

"shx": "^0.3.3",
"ts-jest": "^26.5.2",
"ts-jest": "^27.0.5",
"tslib": "^2.3.1",
"typescript": "^4.3.5"
"typescript": "^4.4.3"
}
}

@@ -1,5 +0,6 @@

export * from './to-meilisearch-params'
export * from './to-instantsearch-response'
export * from './to-instantsearch-hits'
export * from './to-instantsearch-highlight'
export * from './pagination'
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,5 +0,8 @@

import { FacetsDistribution, Filter, Cache, ParsedFilter } from '../types'
import { Filter, Cache, ParsedFilter } from '../types'
import { removeUndefined } from '../utils'
const parseFilter = (filter: string) => {
/**
* @param {string} filter
*/
const adaptFilterSyntax = (filter: string) => {
const matches = filter.match(/([^=]*)="?([^\\"]*)"?$/)

@@ -13,5 +16,9 @@ if (matches) {

const parseFilters = (filters?: Filter): Array<ParsedFilter | undefined> => {
/**
* @param {Filter} filters?
* @returns Array
*/
function extractFilters(filters?: Filter): Array<ParsedFilter | undefined> {
if (typeof filters === 'string') {
return parseFilter(filters)
return adaptFilterSyntax(filters)
} else if (Array.isArray(filters)) {

@@ -21,5 +28,5 @@ return filters

if (Array.isArray(nestedFilter)) {
return nestedFilter.map((filter) => parseFilter(filter))
return nestedFilter.map((filter) => adaptFilterSyntax(filter))
}
return parseFilter(nestedFilter)
return adaptFilterSyntax(nestedFilter)
})

@@ -31,5 +38,9 @@ .flat(2)

export const cacheFilters = (filters?: Filter): Cache => {
const parsedFilters = parseFilters(filters)
const cleanFilters = removeUndefined(parsedFilters)
/**
* @param {Filter} filters?
* @returns Cache
*/
export function cacheFilters(filters?: Filter): Cache {
const extractedFilters = extractFilters(filters)
const cleanFilters = removeUndefined(extractedFilters)
return cleanFilters.reduce<Cache>((cache, parsedFilter: ParsedFilter) => {

@@ -45,25 +56,1 @@ const { filterName, value } = parsedFilter

}
export const addMissingFacetZeroFields = (
cache?: Cache,
distribution?: FacetsDistribution
) => {
distribution = distribution || {}
if (cache && Object.keys(cache).length > 0) {
for (const cachedFacet in cache) {
for (const cachedField of cache[cachedFacet]) {
// 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
}
}
}
}
return distribution
}
import { MeiliSearch } from 'meilisearch'
import { InstantMeiliSearchOptions, InstantMeiliSearchInstance } from '../types'
import { adaptToMeiliSearchParams, adaptToISResponse } from '../adapter'
import { addMissingFacetZeroFields, cacheFilters } from '../cache'
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,
options: InstantMeiliSearchOptions = {}
meiliSearchOptions: InstantMeiliSearchOptions = {}
): InstantMeiliSearchInstance {
return {
MeiliSearchClient: new MeiliSearch({ host: hostUrl, apiKey: apiKey }),
search: async function (instantSearchRequests) {
search: async function <T = Record<string, any>>(
instantSearchRequests: readonly AlgoliaMultipleQueriesQuery[]
// options?: RequestOptions & MultipleQueriesOptions - When is this used ?
): Promise<{ results: Array<AlgoliaSearchResponse<T>> }> {
try {
const isSearchRequest = instantSearchRequests[0]
const { params: instantSearchParams, indexName } = isSearchRequest
const searchRequest = instantSearchRequests[0]
const { params: instantSearchParams } = searchRequest
// Split index name and possible sorting rules
const [indexUid, ...sortByArray] = indexName.split(':')
const context = createContext(
searchRequest.indexName,
instantSearchParams,
meiliSearchOptions,
this.MeiliSearchClient
)
const { paginationTotalHits, primaryKey, placeholderSearch } = options
const { page, hitsPerPage } = instantSearchParams
const client = this.MeiliSearchClient
const context = {
client,
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(':') || '',
}
// Adapt IS params to MeiliSearch params
const msSearchParams = adaptToMeiliSearchParams(
// Adapt search request to MeiliSearch compliant search request
const adaptedSearchRequest = adaptSearchRequest(
instantSearchParams,
context
context.paginationTotalHits,
context.placeholderSearch,
context.sort,
context.query
)
const cachedFacet = cacheFilters(msSearchParams.filter)
// Cache filters
const cachedFacet = cacheFilters(adaptedSearchRequest?.filter)
// Executes the search with MeiliSearch
const searchResponse = await client
.index(indexUid)
.search(msSearchParams.q, msSearchParams)
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 = addMissingFacetZeroFields(
searchResponse.facetsDistribution = facetsDistributionAdapter(
cachedFacet,

@@ -52,5 +112,5 @@ searchResponse.facetsDistribution

// Parses the MeiliSearch response and returns it for InstantSearch
const ISresponse = adaptToISResponse(
indexUid,
// Adapt the MeiliSearch responsne to a compliant instantsearch.js response
const adaptedSearchResponse = adaptSearchResponse<T>(
context.indexUid,
searchResponse,

@@ -60,5 +120,4 @@ instantSearchParams,

)
return ISresponse
} catch (e) {
return adaptedSearchResponse
} catch (e: any) {
console.error(e)

@@ -68,3 +127,11 @@ 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 './types'
export * from './utils'

@@ -1,4 +0,19 @@

import * as MStypes from 'meilisearch'
import * as IStypes from './instantsearch-types'
import type { MeiliSearch } from 'meilisearch'
import type { SearchClient } from 'instantsearch.js'
import type {
SearchOptions as AlgoliaSearchOptions,
MultipleQueriesQuery as AlgoliaMultipleQueriesQuery,
} from '@algolia/client-search'
export type { AlgoliaMultipleQueriesQuery, AlgoliaSearchOptions }
export type { SearchResponse as AlgoliaSearchResponse } from '@algolia/client-search'
export type {
Filter,
FacetsDistribution,
SearchResponse as MeiliSearchResponse,
SearchParams as MeiliSearchParams,
} from 'meilisearch'
export type InstantSearchParams = AlgoliaMultipleQueriesQuery['params']
export type Cache = {

@@ -13,23 +28,2 @@ [category: string]: string[]

export type FacetsDistribution = MStypes.FacetsDistribution
export type Filter = string | Array<string | string[]>
export type IMSearchParams = Omit<
IStypes.SearchParameters,
'facetFilters' | 'filters'
> & {
query?: string
filter?: Filter
}
export type ISSearchParams = Omit<IStypes.SearchParameters, 'facetFilters'> & {
query?: string
facetFilters?: Filter
sort?: string
}
export type ISSearchRequest = {
indexName: string
params: ISSearchParams
}
export type InstantMeiliSearchOptions = {

@@ -41,109 +35,21 @@ paginationTotalHits?: number

export type ISHits<T = Record<string, any>> = T & {
_highlightResult: Record<
keyof T,
{
value: string
}
>
}
export type IMResponse = {
facets?: Record<string, Record<string, number> | undefined>
exhaustiveFacetsCount?: boolean
exhaustiveNbHits: boolean
nbPages?: number
}
export type SearchResponse = Omit<IStypes.SearchResponse, 'hits'> &
IStypes.SearchResponse &
IMResponse & {
hits: ISHits[]
}
export type InstantMeiliSearchContext = {
export type SearchContext = {
page: number
paginationTotalHits: number
hitsPerPage: number
primaryKey: string | undefined
client: MStypes.MeiliSearch
primaryKey?: string
client: MeiliSearch
placeholderSearch: boolean
sort?: string
query?: string
indexUid: string
}
export type FormattedHit = {
formattedHit: any
}
export type HighLightParams = {
formattedHit: any
highlightPreTag?: string
highlightPostTag?: string
}
export type SnippetsParams = {
snippetEllipsisText?: string
attributesToSnippet?: string[]
}
export type CreateHighlighResult = (
highLightParams: HighLightParams & FormattedHit
) => { formattedHit: any } & IMSearchParams
export type ReplaceHighlightTags = (
value: string,
highlightPreTag?: string,
highlightPostTag?: string
) => string
export type CreateSnippetResult = (
snippetsParams: HighLightParams & SnippetsParams & FormattedHit
) => { formattedHit: any } & IMSearchParams
export type SnippetValue = (
value: string,
snippetEllipsisText?: string,
highlightPreTag?: string,
highlightPostTag?: string
) => string
export type AdaptToMeiliSearchParams = (
instantSearchParams: ISSearchParams,
instantMeiliSearchContext: InstantMeiliSearchContext
instantSearchParams: InstantSearchParams,
instantMeiliSearchContext: SearchContext
) => Record<string, any>
export type AdaptToISResponse = (
indexUid: string,
meiliSearchResponse: MStypes.SearchResponse<any, any>,
instantSearchParams: IMSearchParams,
instantMeiliSearchContext: InstantMeiliSearchContext
) => { results: SearchResponse[] }
export type AdaptToISHitsm = (
meiliSearchHits: Array<Record<string, any>>,
instantSearchParams: IMSearchParams,
instantMeiliSearchContext: InstantMeiliSearchContext
) => ISHits[]
export type GetNumberPages = (
hitsLength: number,
instantMeiliSearchContext: InstantMeiliSearchContext
) => number
export type PaginateHits = (
meiliSearchHits: Array<Record<string, any>>,
instantMeiliSearchContext: InstantMeiliSearchContext
) => Array<Record<string, any>>
export type InstantMeiliSearchInstance = {
MeiliSearchClient: MStypes.MeiliSearch
search: (
requests: ISSearchRequest[]
) => Promise<{ results: SearchResponse[] }>
export type InstantMeiliSearchInstance = SearchClient & {
MeiliSearchClient: MeiliSearch
}
export type InstantMeiliSearchClient = (
hostUrl: string,
apiKey: string,
options: InstantMeiliSearchOptions
) => InstantMeiliSearchInstance
export * from './array'
export * from './string'
export * from './number'

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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