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

@meilisearch/instant-meilisearch

Package Overview
Dependencies
Maintainers
4
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@meilisearch/instant-meilisearch - npm Package Compare versions

Comparing version 0.4.2 to 0.5.0

dist/types/adapter/index.d.ts

156

dist/instant-meilisearch.cjs.js

@@ -83,2 +83,28 @@ 'use strict';

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;
var limit = paginationTotalHits;
var filter = [numericFilters.join(' AND '), filters.trim()]
.filter(function (x) { return x; })
.join(' AND ')
.trim();
// 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 })), (facetFilters && { facetFilters: facetFilters })), (attributesToCrop && { attributesToCrop: attributesToCrop })), (attributesToRetrieve && { attributesToRetrieve: attributesToRetrieve })), (filter && { filters: filter })), { attributesToHighlight: attributesToHighlight || ['*'], limit: (!placeholderSearch && query === '') || !limit ? 0 : limit });
};
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;
var start = page * hitsPerPage;
return hits.splice(start, hitsPerPage);
};
function isString(str) {

@@ -88,3 +114,3 @@ return typeof str === 'string' || str instanceof String;

function replaceHighlightTags(value, highlightPreTag, highlightPostTag) {
var replaceHighlightTags = function (value, highlightPreTag, highlightPostTag) {
// Value has to be a string to have highlight.

@@ -102,4 +128,4 @@ // Highlight is applied by MeiliSearch (<em> tags)

return JSON.stringify(value);
}
function createHighlighResult(_a) {
};
var createHighlighResult = function (_a) {
var formattedHit = _a.formattedHit, highlightPreTag = _a.highlightPreTag, highlightPostTag = _a.highlightPostTag;

@@ -114,8 +140,8 @@ // formattedHit is the `_formatted` object returned by MeiliSearch.

}, {});
}
function snippetFinalValue(value, snippetEllipsisText, highlightPreTag, highlightPostTag) {
};
var snippetValue = function (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
// `...` is put if we are at the middle of a sentence (instead at the middle of the document field)
if (snippetEllipsisText !== undefined && isString(newValue)) {
if (snippetEllipsisText !== undefined && isString(newValue) && newValue) {
if (newValue[0] === newValue[0].toLowerCase() && // beginning of a sentence

@@ -132,4 +158,4 @@ newValue.startsWith('<em>') === false // beginning of the document field, otherwise MeiliSearch would crop around the highligh

return replaceHighlightTags(newValue, highlightPreTag, highlightPostTag);
}
function createSnippetResult(_a) {
};
var createSnippetResult = function (_a) {
var formattedHit = _a.formattedHit, attributesToSnippet = _a.attributesToSnippet, snippetEllipsisText = _a.snippetEllipsisText, highlightPreTag = _a.highlightPreTag, highlightPostTag = _a.highlightPostTag;

@@ -145,3 +171,3 @@ if (attributesToSnippet === undefined) {

result[key] = {
value: snippetFinalValue(formattedHit[key], snippetEllipsisText, highlightPreTag, highlightPostTag),
value: snippetValue(formattedHit[key], snippetEllipsisText, highlightPreTag, highlightPostTag),
};

@@ -151,64 +177,36 @@ }

}, {});
}
};
var adaptToISHits = function (meiliSearchHits, instantSearchParams, instantMeiliSearchContext) {
var primaryKey = instantMeiliSearchContext.primaryKey;
var paginatedHits = paginateHits(meiliSearchHits, instantMeiliSearchContext);
return paginatedHits.map(function (hit) {
// Creates Hit object compliant with InstantSearch
if (Object.keys(hit).length > 0) {
var formattedHit = hit._formatted; hit._matchesInfo; var restOfHit = __rest(hit, ["_formatted", "_matchesInfo"]);
return __assign(__assign(__assign({}, restOfHit), { _highlightResult: createHighlighResult(__assign({ formattedHit: formattedHit }, instantSearchParams)), _snippetResult: createSnippetResult(__assign({ formattedHit: 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;
// 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) });
return {
results: [ISResponse],
};
};
function instantMeiliSearch(hostUrl, apiKey, options) {
if (options === void 0) { options = {}; }
return {
client: new meilisearch.MeiliSearch({ host: hostUrl, apiKey: apiKey }),
paginationTotalHits: options.paginationTotalHits || 200,
primaryKey: options.primaryKey || undefined,
placeholderSearch: options.placeholderSearch !== false,
hitsPerPage: 20,
page: 0,
/*
REQUEST
*/
transformToMeiliSearchParams: function (_a) {
var query = _a.query, facets = _a.facets, facetFilters = _a.facetFilters, attributesToCrop = _a.attributesToSnippet, attributesToRetrieve = _a.attributesToRetrieve, attributesToHighlight = _a.attributesToHighlight, _b = _a.filters, filters = _b === void 0 ? '' : _b, _c = _a.numericFilters, numericFilters = _c === void 0 ? [] : _c;
var limit = this.paginationTotalHits;
var filter = [numericFilters.join(' AND '), filters.trim()]
.filter(function (x) { return x; })
.join(' AND ')
.trim();
// 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 })), (facetFilters && { facetFilters: facetFilters })), (attributesToCrop && { attributesToCrop: attributesToCrop })), (attributesToRetrieve && { attributesToRetrieve: attributesToRetrieve })), (filter && { filters: filter })), { attributesToHighlight: attributesToHighlight || ['*'], limit: (!this.placeholderSearch && query === '') || !limit ? 0 : limit });
},
/*
RESPONSE
*/
getNumberPages: function (hitsLength) {
var adjust = hitsLength % this.hitsPerPage === 0 ? 0 : 1;
return Math.floor(hitsLength / this.hitsPerPage) + adjust; // total number of pages
},
paginateHits: function (hits) {
var start = this.page * this.hitsPerPage;
return hits.splice(start, this.hitsPerPage);
},
transformToISHits: function (meiliSearchHits, instantSearchParams) {
var _this = this;
var paginatedHits = this.paginateHits(meiliSearchHits);
return paginatedHits.map(function (hit) {
var formattedHit = hit._formatted, restOfHit = __rest(hit
// Creates Hit object compliant with InstantSearch
, ["_formatted"]);
// Creates Hit object compliant with InstantSearch
return __assign(__assign(__assign({}, restOfHit), { _highlightResult: createHighlighResult(__assign({ formattedHit: formattedHit }, instantSearchParams)), _snippetResult: createSnippetResult(__assign({ formattedHit: formattedHit }, instantSearchParams)) }), (_this.primaryKey && { objectID: hit[_this.primaryKey] }));
});
},
transformToISResponse: function (indexUid, _a, instantSearchParams) {
var exhaustiveFacetsCount = _a.exhaustiveFacetsCount, exhaustiveNbHits = _a.exhaustiveNbHits, facets = _a.facetsDistribution, nbHits = _a.nbHits, processingTimeMs = _a.processingTimeMs, query = _a.query, hits = _a.hits;
// Create response object compliant with InstantSearch
var ISResponse = __assign(__assign(__assign({ index: indexUid, hitsPerPage: this.hitsPerPage }, (facets && { facets: facets })), (exhaustiveFacetsCount && { exhaustiveFacetsCount: exhaustiveFacetsCount })), { page: this.page, nbPages: this.getNumberPages(hits.length), exhaustiveNbHits: exhaustiveNbHits,
nbHits: nbHits, processingTimeMS: processingTimeMs, query: query, hits: this.transformToISHits(hits, instantSearchParams) });
return {
results: [ISResponse],
};
},
/*
SEARCH
*/
MeiliSearchClient: new meilisearch.MeiliSearch({ host: hostUrl, apiKey: apiKey }),
search: function (_a) {
var isSearchRequest = _a[0];
return __awaiter(this, void 0, void 0, function () {
var instantSearchParams, indexUid, page, hitsPerPage, msSearchParams, searchResponse, e_1;
var instantSearchParams, indexUid, paginationTotalHits, primaryKey, placeholderSearch, page, hitsPerPage, client, context, msSearchParams, searchResponse, ISresponse, e_1;
return __generator(this, function (_b) {

@@ -219,7 +217,15 @@ switch (_b.label) {

instantSearchParams = isSearchRequest.params, indexUid = isSearchRequest.indexName;
paginationTotalHits = options.paginationTotalHits, primaryKey = options.primaryKey, placeholderSearch = options.placeholderSearch;
page = instantSearchParams.page, hitsPerPage = instantSearchParams.hitsPerPage;
this.page = page || 0; // default page is 0 if none is provided
this.hitsPerPage = hitsPerPage || 20; // 20 is the MeiliSearch's default limit value. `hitsPerPage` can be changed with `InsantSearch.configure`.
msSearchParams = this.transformToMeiliSearchParams(instantSearchParams);
return [4 /*yield*/, this.client
client = this.MeiliSearchClient;
context = {
client: client,
paginationTotalHits: paginationTotalHits || 200,
primaryKey: primaryKey || undefined,
placeholderSearch: placeholderSearch !== false,
hitsPerPage: hitsPerPage === undefined ? 20 : hitsPerPage,
page: page || 0, // default page is 0 if none is provided
};
msSearchParams = adaptToMeiliSearchParams(instantSearchParams, context);
return [4 /*yield*/, client
.index(indexUid)

@@ -231,4 +237,4 @@ .search(msSearchParams.q, msSearchParams)

searchResponse = _b.sent();
// Parses the MeiliSearch response and returns it for InstantSearch
return [2 /*return*/, this.transformToISResponse(indexUid, searchResponse, instantSearchParams)];
ISresponse = adaptToISResponse(indexUid, searchResponse, instantSearchParams, context);
return [2 /*return*/, ISresponse];
case 2:

@@ -246,2 +252,12 @@ e_1 = _b.sent();

exports.adaptToISHits = adaptToISHits;
exports.adaptToISResponse = adaptToISResponse;
exports.adaptToMeiliSearchParams = adaptToMeiliSearchParams;
exports.createHighlighResult = createHighlighResult;
exports.createSnippetResult = createSnippetResult;
exports.getNumberPages = getNumberPages;
exports.instantMeiliSearch = instantMeiliSearch;
exports.isString = isString;
exports.paginateHits = paginateHits;
exports.replaceHighlightTags = replaceHighlightTags;
exports.snippetValue = snippetValue;

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

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

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

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function r(t,e,r,i){return new(r||(r=Promise))((function(n,a){function o(t){try{u(i.next(t))}catch(t){a(t)}}function s(t){try{u(i.throw(t))}catch(t){a(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,s)}u((i=i.apply(t,e||[])).next())}))}function i(t,e){var r,i,n,a,o={label:0,sent:function(){if(1&n[0])throw n[1];return n[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,i&&(n=2&a[0]?i.return:a[0]?i.throw||((n=i.return)&&n.call(i),0):i.next)&&!(n=n.call(i,a[1])).done)return n;switch(i=0,n&&(a=[2&a[0],n.value]),a[0]){case 0:case 1:n=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,i=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(n=o.trys,(n=n.length>0&&n[n.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){o.label=a[1];break}if(6===a[0]&&o.label<n[1]){o.label=n[1],n=a;break}if(n&&o.label<n[2]){o.label=n[2],o.ops.push(a);break}n[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],i=0}finally{r=n=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}function n(t){return"string"==typeof t||t instanceof String}function a(t,e,r){return e=e||"__ais-highlight__",r=r||"__/ais-highlight__",n(t)?t.replace(/<em>/g,e).replace(/<\/em>/g,r):JSON.stringify(t)}function o(t){var e=t.formattedHit,r=t.highlightPreTag,i=t.highlightPostTag;return Object.keys(e).reduce((function(t,n){return t[n]={value:a(e[n],r,i)},t}),{})}function s(t,e,r,i){var o=t;return void 0!==e&&n(o)&&(o[0]===o[0].toLowerCase()&&!1===o.startsWith("<em>")&&(o=""+e+o),!1==!!o.match(/[.!?]$/)&&(o=""+o+e)),a(o,r,i)}function u(t){var e=t.formattedHit,r=t.attributesToSnippet,i=t.snippetEllipsisText,n=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:s(e[o],i,n,a)}),t}),{}))}exports.instantMeiliSearch=function(n,a,s){return void 0===s&&(s={}),{client:new t.MeiliSearch({host:n,apiKey:a}),paginationTotalHits:s.paginationTotalHits||200,primaryKey:s.primaryKey||void 0,placeholderSearch:!1!==s.placeholderSearch,hitsPerPage:20,page:0,transformToMeiliSearchParams:function(t){var r=t.query,i=t.facets,n=t.facetFilters,a=t.attributesToSnippet,o=t.attributesToRetrieve,s=t.attributesToHighlight,u=t.filters,c=void 0===u?"":u,l=t.numericFilters,h=void 0===l?[]:l,f=this.paginationTotalHits,p=[h.join(" AND "),c.trim()].filter((function(t){return t})).join(" AND ").trim();return e(e(e(e(e(e({q:r},(null==i?void 0:i.length)&&{facetsDistribution:i}),n&&{facetFilters:n}),a&&{attributesToCrop:a}),o&&{attributesToRetrieve:o}),p&&{filters:p}),{attributesToHighlight:s||["*"],limit:!this.placeholderSearch&&""===r||!f?0:f})},getNumberPages:function(t){var e=t%this.hitsPerPage==0?0:1;return Math.floor(t/this.hitsPerPage)+e},paginateHits:function(t){var e=this.page*this.hitsPerPage;return t.splice(e,this.hitsPerPage)},transformToISHits:function(t,r){var i=this;return this.paginateHits(t).map((function(t){var n=t._formatted,a=function(t,e){var r={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(r[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(t);n<i.length;n++)e.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(t,i[n])&&(r[i[n]]=t[i[n]])}return r}(t,["_formatted"]);return e(e(e({},a),{_highlightResult:o(e({formattedHit:n},r)),_snippetResult:u(e({formattedHit:n},r))}),i.primaryKey&&{objectID:t[i.primaryKey]})}))},transformToISResponse:function(t,r,i){var n=r.exhaustiveFacetsCount,a=r.exhaustiveNbHits,o=r.facetsDistribution,s=r.nbHits,u=r.processingTimeMs,c=r.query,l=r.hits;return{results:[e(e(e({index:t,hitsPerPage:this.hitsPerPage},o&&{facets:o}),n&&{exhaustiveFacetsCount:n}),{page:this.page,nbPages:this.getNumberPages(l.length),exhaustiveNbHits:a,nbHits:s,processingTimeMS:u,query:c,hits:this.transformToISHits(l,i)})]}},search:function(t){var e=t[0];return r(this,void 0,void 0,(function(){var t,r,n,a,o,s,u;return i(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),t=e.params,r=e.indexName,n=t.page,a=t.hitsPerPage,this.page=n||0,this.hitsPerPage=a||20,o=this.transformToMeiliSearchParams(t),[4,this.client.index(r).search(o.q,o)];case 1:return s=i.sent(),[2,this.transformToISResponse(r,s,t)];case 2:throw u=i.sent(),console.error(u),new Error(u);case 3:return[2]}}))}))}}};
***************************************************************************** */function r(e,t,r,i){return new(r||(r=Promise))((function(n,a){function o(e){try{u(i.next(e))}catch(e){a(e)}}function s(e){try{u(i.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,s)}u((i=i.apply(e,t||[])).next())}))}function i(e,t){var r,i,n,a,o={label:0,sent:function(){if(1&n[0])throw n[1];return n[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,i&&(n=2&a[0]?i.return:a[0]?i.throw||((n=i.return)&&n.call(i),0):i.next)&&!(n=n.call(i,a[1])).done)return n;switch(i=0,n&&(a=[2&a[0],n.value]),a[0]){case 0:case 1:n=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,i=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(n=o.trys,(n=n.length>0&&n[n.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){o.label=a[1];break}if(6===a[0]&&o.label<n[1]){o.label=n[1],n=a;break}if(n&&o.label<n[2]){o.label=n[2],o.ops.push(a);break}n[2]&&o.ops.pop(),o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e],i=0}finally{r=n=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}var n=function(e,r){var i=e.query,n=e.facets,a=e.facetFilters,o=e.attributesToSnippet,s=e.attributesToRetrieve,u=e.attributesToHighlight,c=e.filters,l=void 0===c?"":c,p=e.numericFilters,h=void 0===p?[]:p,f=r.paginationTotalHits,g=r.placeholderSearch,v=f,b=[h.join(" AND "),l.trim()].filter((function(e){return e})).join(" AND ").trim();return t(t(t(t(t(t({q:i},(null==n?void 0:n.length)&&{facetsDistribution:n}),a&&{facetFilters:a}),o&&{attributesToCrop:o}),s&&{attributesToRetrieve:s}),b&&{filters:b}),{attributesToHighlight:u||["*"],limit:!g&&""===i||!v?0:v})},a=function(e,t){var r=t.hitsPerPage;return r>0?Math.ceil(e/r):0},o=function(e,t){var r=t.page,i=t.hitsPerPage,n=r*i;return e.splice(n,i)};function s(e){return"string"==typeof e||e instanceof String}var u=function(e,t,r){return t=t||"__ais-highlight__",r=r||"__/ais-highlight__",s(e)?e.replace(/<em>/g,t).replace(/<\/em>/g,r):JSON.stringify(e)},c=function(e){var t=e.formattedHit,r=e.highlightPreTag,i=e.highlightPostTag;return Object.keys(t).reduce((function(e,n){return e[n]={value:u(t[n],r,i)},e}),{})},l=function(e,t,r,i){var n=e;return void 0!==t&&s(n)&&n&&(n[0]===n[0].toLowerCase()&&!1===n.startsWith("<em>")&&(n=""+t+n),!1==!!n.match(/[.!?]$/)&&(n=""+n+t)),u(n,r,i)},p=function(e){var t=e.formattedHit,r=e.attributesToSnippet,i=e.snippetEllipsisText,n=e.highlightPreTag,a=e.highlightPostTag;return void 0===r?null:(r=r.map((function(e){return e.split(":")[0]})),Object.keys(t).reduce((function(e,o){return r.includes(o)&&(e[o]={value:l(t[o],i,n,a)}),e}),{}))},h=function(e,r,i){var n=i.primaryKey;return o(e,i).map((function(e){if(Object.keys(e).length>0){var i=e._formatted;e._matchesInfo;var a=function(e,t){var r={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(r[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(r[i[n]]=e[i[n]])}return r}(e,["_formatted","_matchesInfo"]);return t(t(t({},a),{_highlightResult:c(t({formattedHit:i},r)),_snippetResult:p(t({formattedHit:i},r))}),n&&{objectID:e[n]})}return e}))},f=function(e,r,i,n){var o=r.exhaustiveFacetsCount,s=r.exhaustiveNbHits,u=r.facetsDistribution,c=r.nbHits,l=r.processingTimeMs,p=r.query,f=r.hits,g=n.hitsPerPage,v=n.page;return{results:[t(t(t({index:e,hitsPerPage:g},u&&{facets:u}),o&&{exhaustiveFacetsCount:o}),{page:v,nbPages:a(f.length,n),exhaustiveNbHits:s,nbHits:c,processingTimeMS:l,query:p,hits:h(f,i,n)})]}};exports.adaptToISHits=h,exports.adaptToISResponse=f,exports.adaptToMeiliSearchParams=n,exports.createHighlighResult=c,exports.createSnippetResult=p,exports.getNumberPages=a,exports.instantMeiliSearch=function(t,a,o){return void 0===o&&(o={}),{MeiliSearchClient:new e.MeiliSearch({host:t,apiKey:a}),search:function(e){var t=e[0];return r(this,void 0,void 0,(function(){var e,r,a,s,u,c,l,p,h,g,v,b;return i(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),e=t.params,r=t.indexName,a=o.paginationTotalHits,s=o.primaryKey,u=o.placeholderSearch,c=e.page,l=e.hitsPerPage,p=this.MeiliSearchClient,g=n(e,h={client:p,paginationTotalHits:a||200,primaryKey:s||void 0,placeholderSearch:!1!==u,hitsPerPage:void 0===l?20:l,page:c||0}),[4,p.index(r).search(g.q,g)];case 1:return v=i.sent(),[2,f(r,v,e,h)];case 2:throw b=i.sent(),console.error(b),new Error(b);case 3:return[2]}}))}))}}},exports.isString=s,exports.paginateHits=o,exports.replaceHighlightTags=u,exports.snippetValue=l;
//# sourceMappingURL=instant-meilisearch.cjs.min.js.map

@@ -79,2 +79,28 @@ import { MeiliSearch } from 'meilisearch';

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;
var limit = paginationTotalHits;
var filter = [numericFilters.join(' AND '), filters.trim()]
.filter(function (x) { return x; })
.join(' AND ')
.trim();
// 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 })), (facetFilters && { facetFilters: facetFilters })), (attributesToCrop && { attributesToCrop: attributesToCrop })), (attributesToRetrieve && { attributesToRetrieve: attributesToRetrieve })), (filter && { filters: filter })), { attributesToHighlight: attributesToHighlight || ['*'], limit: (!placeholderSearch && query === '') || !limit ? 0 : limit });
};
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;
var start = page * hitsPerPage;
return hits.splice(start, hitsPerPage);
};
function isString(str) {

@@ -84,3 +110,3 @@ return typeof str === 'string' || str instanceof String;

function replaceHighlightTags(value, highlightPreTag, highlightPostTag) {
var replaceHighlightTags = function (value, highlightPreTag, highlightPostTag) {
// Value has to be a string to have highlight.

@@ -98,4 +124,4 @@ // Highlight is applied by MeiliSearch (<em> tags)

return JSON.stringify(value);
}
function createHighlighResult(_a) {
};
var createHighlighResult = function (_a) {
var formattedHit = _a.formattedHit, highlightPreTag = _a.highlightPreTag, highlightPostTag = _a.highlightPostTag;

@@ -110,8 +136,8 @@ // formattedHit is the `_formatted` object returned by MeiliSearch.

}, {});
}
function snippetFinalValue(value, snippetEllipsisText, highlightPreTag, highlightPostTag) {
};
var snippetValue = function (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
// `...` is put if we are at the middle of a sentence (instead at the middle of the document field)
if (snippetEllipsisText !== undefined && isString(newValue)) {
if (snippetEllipsisText !== undefined && isString(newValue) && newValue) {
if (newValue[0] === newValue[0].toLowerCase() && // beginning of a sentence

@@ -128,4 +154,4 @@ newValue.startsWith('<em>') === false // beginning of the document field, otherwise MeiliSearch would crop around the highligh

return replaceHighlightTags(newValue, highlightPreTag, highlightPostTag);
}
function createSnippetResult(_a) {
};
var createSnippetResult = function (_a) {
var formattedHit = _a.formattedHit, attributesToSnippet = _a.attributesToSnippet, snippetEllipsisText = _a.snippetEllipsisText, highlightPreTag = _a.highlightPreTag, highlightPostTag = _a.highlightPostTag;

@@ -141,3 +167,3 @@ if (attributesToSnippet === undefined) {

result[key] = {
value: snippetFinalValue(formattedHit[key], snippetEllipsisText, highlightPreTag, highlightPostTag),
value: snippetValue(formattedHit[key], snippetEllipsisText, highlightPreTag, highlightPostTag),
};

@@ -147,64 +173,36 @@ }

}, {});
}
};
var adaptToISHits = function (meiliSearchHits, instantSearchParams, instantMeiliSearchContext) {
var primaryKey = instantMeiliSearchContext.primaryKey;
var paginatedHits = paginateHits(meiliSearchHits, instantMeiliSearchContext);
return paginatedHits.map(function (hit) {
// Creates Hit object compliant with InstantSearch
if (Object.keys(hit).length > 0) {
var formattedHit = hit._formatted; hit._matchesInfo; var restOfHit = __rest(hit, ["_formatted", "_matchesInfo"]);
return __assign(__assign(__assign({}, restOfHit), { _highlightResult: createHighlighResult(__assign({ formattedHit: formattedHit }, instantSearchParams)), _snippetResult: createSnippetResult(__assign({ formattedHit: 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;
// 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) });
return {
results: [ISResponse],
};
};
function instantMeiliSearch(hostUrl, apiKey, options) {
if (options === void 0) { options = {}; }
return {
client: new MeiliSearch({ host: hostUrl, apiKey: apiKey }),
paginationTotalHits: options.paginationTotalHits || 200,
primaryKey: options.primaryKey || undefined,
placeholderSearch: options.placeholderSearch !== false,
hitsPerPage: 20,
page: 0,
/*
REQUEST
*/
transformToMeiliSearchParams: function (_a) {
var query = _a.query, facets = _a.facets, facetFilters = _a.facetFilters, attributesToCrop = _a.attributesToSnippet, attributesToRetrieve = _a.attributesToRetrieve, attributesToHighlight = _a.attributesToHighlight, _b = _a.filters, filters = _b === void 0 ? '' : _b, _c = _a.numericFilters, numericFilters = _c === void 0 ? [] : _c;
var limit = this.paginationTotalHits;
var filter = [numericFilters.join(' AND '), filters.trim()]
.filter(function (x) { return x; })
.join(' AND ')
.trim();
// 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 })), (facetFilters && { facetFilters: facetFilters })), (attributesToCrop && { attributesToCrop: attributesToCrop })), (attributesToRetrieve && { attributesToRetrieve: attributesToRetrieve })), (filter && { filters: filter })), { attributesToHighlight: attributesToHighlight || ['*'], limit: (!this.placeholderSearch && query === '') || !limit ? 0 : limit });
},
/*
RESPONSE
*/
getNumberPages: function (hitsLength) {
var adjust = hitsLength % this.hitsPerPage === 0 ? 0 : 1;
return Math.floor(hitsLength / this.hitsPerPage) + adjust; // total number of pages
},
paginateHits: function (hits) {
var start = this.page * this.hitsPerPage;
return hits.splice(start, this.hitsPerPage);
},
transformToISHits: function (meiliSearchHits, instantSearchParams) {
var _this = this;
var paginatedHits = this.paginateHits(meiliSearchHits);
return paginatedHits.map(function (hit) {
var formattedHit = hit._formatted, restOfHit = __rest(hit
// Creates Hit object compliant with InstantSearch
, ["_formatted"]);
// Creates Hit object compliant with InstantSearch
return __assign(__assign(__assign({}, restOfHit), { _highlightResult: createHighlighResult(__assign({ formattedHit: formattedHit }, instantSearchParams)), _snippetResult: createSnippetResult(__assign({ formattedHit: formattedHit }, instantSearchParams)) }), (_this.primaryKey && { objectID: hit[_this.primaryKey] }));
});
},
transformToISResponse: function (indexUid, _a, instantSearchParams) {
var exhaustiveFacetsCount = _a.exhaustiveFacetsCount, exhaustiveNbHits = _a.exhaustiveNbHits, facets = _a.facetsDistribution, nbHits = _a.nbHits, processingTimeMs = _a.processingTimeMs, query = _a.query, hits = _a.hits;
// Create response object compliant with InstantSearch
var ISResponse = __assign(__assign(__assign({ index: indexUid, hitsPerPage: this.hitsPerPage }, (facets && { facets: facets })), (exhaustiveFacetsCount && { exhaustiveFacetsCount: exhaustiveFacetsCount })), { page: this.page, nbPages: this.getNumberPages(hits.length), exhaustiveNbHits: exhaustiveNbHits,
nbHits: nbHits, processingTimeMS: processingTimeMs, query: query, hits: this.transformToISHits(hits, instantSearchParams) });
return {
results: [ISResponse],
};
},
/*
SEARCH
*/
MeiliSearchClient: new MeiliSearch({ host: hostUrl, apiKey: apiKey }),
search: function (_a) {
var isSearchRequest = _a[0];
return __awaiter(this, void 0, void 0, function () {
var instantSearchParams, indexUid, page, hitsPerPage, msSearchParams, searchResponse, e_1;
var instantSearchParams, indexUid, paginationTotalHits, primaryKey, placeholderSearch, page, hitsPerPage, client, context, msSearchParams, searchResponse, ISresponse, e_1;
return __generator(this, function (_b) {

@@ -215,7 +213,15 @@ switch (_b.label) {

instantSearchParams = isSearchRequest.params, indexUid = isSearchRequest.indexName;
paginationTotalHits = options.paginationTotalHits, primaryKey = options.primaryKey, placeholderSearch = options.placeholderSearch;
page = instantSearchParams.page, hitsPerPage = instantSearchParams.hitsPerPage;
this.page = page || 0; // default page is 0 if none is provided
this.hitsPerPage = hitsPerPage || 20; // 20 is the MeiliSearch's default limit value. `hitsPerPage` can be changed with `InsantSearch.configure`.
msSearchParams = this.transformToMeiliSearchParams(instantSearchParams);
return [4 /*yield*/, this.client
client = this.MeiliSearchClient;
context = {
client: client,
paginationTotalHits: paginationTotalHits || 200,
primaryKey: primaryKey || undefined,
placeholderSearch: placeholderSearch !== false,
hitsPerPage: hitsPerPage === undefined ? 20 : hitsPerPage,
page: page || 0, // default page is 0 if none is provided
};
msSearchParams = adaptToMeiliSearchParams(instantSearchParams, context);
return [4 /*yield*/, client
.index(indexUid)

@@ -227,4 +233,4 @@ .search(msSearchParams.q, msSearchParams)

searchResponse = _b.sent();
// Parses the MeiliSearch response and returns it for InstantSearch
return [2 /*return*/, this.transformToISResponse(indexUid, searchResponse, instantSearchParams)];
ISresponse = adaptToISResponse(indexUid, searchResponse, instantSearchParams, context);
return [2 /*return*/, ISresponse];
case 2:

@@ -242,2 +248,2 @@ e_1 = _b.sent();

export { instantMeiliSearch };
export { adaptToISHits, adaptToISResponse, adaptToMeiliSearchParams, createHighlighResult, createSnippetResult, getNumberPages, instantMeiliSearch, isString, paginateHits, replaceHighlightTags, snippetValue };

@@ -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,i=arguments.length;r<i;r++)for(var n in e=arguments[r])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)};function r(t,e,r,i){return new(r||(r=Promise))((function(n,a){function o(t){try{u(i.next(t))}catch(t){a(t)}}function s(t){try{u(i.throw(t))}catch(t){a(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,s)}u((i=i.apply(t,e||[])).next())}))}function i(t,e){var r,i,n,a,o={label:0,sent:function(){if(1&n[0])throw n[1];return n[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,i&&(n=2&a[0]?i.return:a[0]?i.throw||((n=i.return)&&n.call(i),0):i.next)&&!(n=n.call(i,a[1])).done)return n;switch(i=0,n&&(a=[2&a[0],n.value]),a[0]){case 0:case 1:n=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,i=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(n=o.trys,(n=n.length>0&&n[n.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){o.label=a[1];break}if(6===a[0]&&o.label<n[1]){o.label=n[1],n=a;break}if(n&&o.label<n[2]){o.label=n[2],o.ops.push(a);break}n[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],i=0}finally{r=n=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}function n(t){return"string"==typeof t||t instanceof String}function a(t,e,r){return e=e||"__ais-highlight__",r=r||"__/ais-highlight__",n(t)?t.replace(/<em>/g,e).replace(/<\/em>/g,r):JSON.stringify(t)}function o(t){var e=t.formattedHit,r=t.highlightPreTag,i=t.highlightPostTag;return Object.keys(e).reduce((function(t,n){return t[n]={value:a(e[n],r,i)},t}),{})}function s(t,e,r,i){var o=t;return void 0!==e&&n(o)&&(o[0]===o[0].toLowerCase()&&!1===o.startsWith("<em>")&&(o=""+e+o),!1==!!o.match(/[.!?]$/)&&(o=""+o+e)),a(o,r,i)}function u(t){var e=t.formattedHit,r=t.attributesToSnippet,i=t.snippetEllipsisText,n=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:s(e[o],i,n,a)}),t}),{}))}function c(n,a,s){return void 0===s&&(s={}),{client:new t({host:n,apiKey:a}),paginationTotalHits:s.paginationTotalHits||200,primaryKey:s.primaryKey||void 0,placeholderSearch:!1!==s.placeholderSearch,hitsPerPage:20,page:0,transformToMeiliSearchParams:function(t){var r=t.query,i=t.facets,n=t.facetFilters,a=t.attributesToSnippet,o=t.attributesToRetrieve,s=t.attributesToHighlight,u=t.filters,c=void 0===u?"":u,l=t.numericFilters,h=void 0===l?[]:l,f=this.paginationTotalHits,p=[h.join(" AND "),c.trim()].filter((function(t){return t})).join(" AND ").trim();return e(e(e(e(e(e({q:r},(null==i?void 0:i.length)&&{facetsDistribution:i}),n&&{facetFilters:n}),a&&{attributesToCrop:a}),o&&{attributesToRetrieve:o}),p&&{filters:p}),{attributesToHighlight:s||["*"],limit:!this.placeholderSearch&&""===r||!f?0:f})},getNumberPages:function(t){var e=t%this.hitsPerPage==0?0:1;return Math.floor(t/this.hitsPerPage)+e},paginateHits:function(t){var e=this.page*this.hitsPerPage;return t.splice(e,this.hitsPerPage)},transformToISHits:function(t,r){var i=this;return this.paginateHits(t).map((function(t){var n=t._formatted,a=function(t,e){var r={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(r[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(t);n<i.length;n++)e.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(t,i[n])&&(r[i[n]]=t[i[n]])}return r}(t,["_formatted"]);return e(e(e({},a),{_highlightResult:o(e({formattedHit:n},r)),_snippetResult:u(e({formattedHit:n},r))}),i.primaryKey&&{objectID:t[i.primaryKey]})}))},transformToISResponse:function(t,r,i){var n=r.exhaustiveFacetsCount,a=r.exhaustiveNbHits,o=r.facetsDistribution,s=r.nbHits,u=r.processingTimeMs,c=r.query,l=r.hits;return{results:[e(e(e({index:t,hitsPerPage:this.hitsPerPage},o&&{facets:o}),n&&{exhaustiveFacetsCount:n}),{page:this.page,nbPages:this.getNumberPages(l.length),exhaustiveNbHits:a,nbHits:s,processingTimeMS:u,query:c,hits:this.transformToISHits(l,i)})]}},search:function(t){var e=t[0];return r(this,void 0,void 0,(function(){var t,r,n,a,o,s,u;return i(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),t=e.params,r=e.indexName,n=t.page,a=t.hitsPerPage,this.page=n||0,this.hitsPerPage=a||20,o=this.transformToMeiliSearchParams(t),[4,this.client.index(r).search(o.q,o)];case 1:return s=i.sent(),[2,this.transformToISResponse(r,s,t)];case 2:throw u=i.sent(),console.error(u),new Error(u);case 3:return[2]}}))}))}}}export{c as instantMeiliSearch};
***************************************************************************** */var e=function(){return(e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function r(t,e,r,n){return new(r||(r=Promise))((function(i,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])}}}var i=function(t,r){var n=t.query,i=t.facets,a=t.facetFilters,o=t.attributesToSnippet,s=t.attributesToRetrieve,u=t.attributesToHighlight,c=t.filters,l=void 0===c?"":c,h=t.numericFilters,f=void 0===h?[]:h,p=r.paginationTotalHits,g=r.placeholderSearch,v=p,b=[f.join(" AND "),l.trim()].filter((function(t){return t})).join(" AND ").trim();return e(e(e(e(e(e({q:n},(null==i?void 0:i.length)&&{facetsDistribution:i}),a&&{facetFilters:a}),o&&{attributesToCrop:o}),s&&{attributesToRetrieve:s}),b&&{filters:b}),{attributesToHighlight:u||["*"],limit:!g&&""===n||!v?0:v})},a=function(t,e){var r=e.hitsPerPage;return r>0?Math.ceil(t/r):0},o=function(t,e){var r=e.page,n=e.hitsPerPage,i=r*n;return t.splice(i,n)};function s(t){return"string"==typeof t||t instanceof String}var u=function(t,e,r){return e=e||"__ais-highlight__",r=r||"__/ais-highlight__",s(t)?t.replace(/<em>/g,e).replace(/<\/em>/g,r):JSON.stringify(t)},c=function(t){var e=t.formattedHit,r=t.highlightPreTag,n=t.highlightPostTag;return Object.keys(e).reduce((function(t,i){return t[i]={value:u(e[i],r,n)},t}),{})},l=function(t,e,r,n){var i=t;return void 0!==e&&s(i)&&i&&(i[0]===i[0].toLowerCase()&&!1===i.startsWith("<em>")&&(i=""+e+i),!1==!!i.match(/[.!?]$/)&&(i=""+i+e)),u(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:l(e[o],n,i,a)}),t}),{}))},f=function(t,r,n){var i=n.primaryKey;return o(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),{_highlightResult:c(e({formattedHit:n},r)),_snippetResult:h(e({formattedHit:n},r))}),i&&{objectID:t[i]})}return t}))},p=function(t,r,n,i){var o=r.exhaustiveFacetsCount,s=r.exhaustiveNbHits,u=r.facetsDistribution,c=r.nbHits,l=r.processingTimeMs,h=r.query,p=r.hits,g=i.hitsPerPage,v=i.page;return{results:[e(e(e({index:t,hitsPerPage:g},u&&{facets:u}),o&&{exhaustiveFacetsCount:o}),{page:v,nbPages:a(p.length,i),exhaustiveNbHits:s,nbHits:c,processingTimeMS:l,query:h,hits:f(p,n,i)})]}};function g(e,a,o){return void 0===o&&(o={}),{MeiliSearchClient:new t({host:e,apiKey:a}),search:function(t){var e=t[0];return r(this,void 0,void 0,(function(){var t,r,a,s,u,c,l,h,f,g,v,b;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=e.params,r=e.indexName,a=o.paginationTotalHits,s=o.primaryKey,u=o.placeholderSearch,c=t.page,l=t.hitsPerPage,h=this.MeiliSearchClient,g=i(t,f={client:h,paginationTotalHits:a||200,primaryKey:s||void 0,placeholderSearch:!1!==u,hitsPerPage:void 0===l?20:l,page:c||0}),[4,h.index(r).search(g.q,g)];case 1:return v=n.sent(),[2,p(r,v,t,f)];case 2:throw b=n.sent(),console.error(b),new Error(b);case 3:return[2]}}))}))}}}export{f as adaptToISHits,p as adaptToISResponse,i as adaptToMeiliSearchParams,c as createHighlighResult,h as createSnippetResult,a as getNumberPages,g as instantMeiliSearch,s as isString,o as paginateHits,u as replaceHighlightTags,l as snippetValue};
//# sourceMappingURL=instant-meilisearch.esm.min.js.map

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

***************************************************************************** */
var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,r)};function r(t,r){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,o){function s(t){try{a(n.next(t))}catch(t){o(t)}}function u(t){try{a(n.throw(t))}catch(t){o(t)}}function a(t){t.done?r(t.value):i(t.value).then(s,u)}a((n=n.apply(t,e||[])).next())}))}function o(t,e){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(t){return function(e){return a([t,e])}}function a(o){if(r)throw new TypeError("Generator is already executing.");for(;s;)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 s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}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}}}var s=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 o(this,(function(e){switch(e.label){case 0:return[4,new Promise((function(e){return setTimeout(e,t)}))];case 1:return[2,e.sent()]}}))}))}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 o(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 p(t){if("MeiliSearchApiError"!==t.type)throw new h(t.message,t);throw t}var l=function(){function t(t){this.headers=n(n(n({},t.headers||{}),{"Content-Type":"application/json"}),t.apiKey?{"X-Meili-API-Key":t.apiKey}:{}),this.url=new URL(t.host)}return t.addTrailingSlash=function(t){return t.endsWith("/")||(t+="/"),t},t.prototype.request=function(t){var e=t.method,r=t.url,s=t.params,u=t.body,a=t.config;return i(this,void 0,void 0,(function(){var t,i,c;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),t=new URL(r,this.url),s&&(i=new URLSearchParams,Object.keys(s).filter((function(t){return null!==s[t]})).map((function(t){return i.set(t,s[t])})),t.search=i.toString()),[4,fetch(t.toString(),n(n({},a),{method:e,body:u?JSON.stringify(u):void 0,headers:this.headers})).then((function(t){return d(t)}))];case 1:return[4,o.sent().text()];case 2:c=o.sent();try{return[2,JSON.parse(c)]}catch(t){return[2]}return[3,4];case 3:return p(o.sent()),[3,4];case 4:return[2]}}))}))},t.prototype.get=function(t,e,r){return i(this,void 0,void 0,(function(){return o(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 o(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 o(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 o(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 l(t)}return t.getApiRoutes=function(){return t.apiRoutes},t.getRouteConstructors=function(){return t.routeConstructors},t.prototype.getUpdateStatus=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.getUpdateStatus(this.uid,e),[4,this.httpRequest.get(r)];case 1:return[2,n.sent()]}}))}))},t.prototype.waitForPendingUpdate=function(t,e){var r=void 0===e?{}:e,n=r.timeOutMs,s=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 o(this,(function(n){switch(n.label){case 0:e=Date.now(),n.label=1;case 1:return Date.now()-e<s?[4,this.getUpdateStatus(t)]:[3,4];case 2:return"enqueued"!==(r=n.sent()).status?[2,r]:[4,c(h)];case 3:return n.sent(),[3,1];case 4:throw new u("timeout of "+s+"ms has exceeded on process "+t+" when waiting for pending update to resolve.")}}))}))},t.prototype.getAllUpdateStatus=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getAllUpdateStatus(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.search=function(e,r,u,c){return void 0===u&&(u="POST"),i(this,void 0,void 0,(function(){var i,h,f;return o(this,(function(o){switch(o.label){case 0:return i=t.routeConstructors.search(this.uid),h={q:e,offset:null==r?void 0:r.offset,limit:null==r?void 0:r.limit,cropLength:null==r?void 0:r.cropLength,filters:null==r?void 0:r.filters,matches:null==r?void 0:r.matches,facetFilters:null==r?void 0:r.facetFilters,facetsDistribution:null==r?void 0:r.facetsDistribution,attributesToRetrieve:null==r?void 0:r.attributesToRetrieve,attributesToCrop:null==r?void 0:r.attributesToCrop,attributesToHighlight:null==r?void 0:r.attributesToHighlight},"POST"!==u.toUpperCase()?[3,2]:[4,this.httpRequest.post(i,a(h),void 0,c)];case 1:return[2,o.sent()];case 2:return"GET"!==u.toUpperCase()?[3,4]:(f=n(n({},h),{facetFilters:Array.isArray(null==r?void 0:r.facetFilters)&&(null==r?void 0:r.facetFilters)?JSON.stringify(r.facetFilters):void 0,facetsDistribution:(null==r?void 0:r.facetsDistribution)?JSON.stringify(r.facetsDistribution):void 0,attributesToRetrieve:(null==r?void 0:r.attributesToRetrieve)?r.attributesToRetrieve.join(","):void 0,attributesToCrop:(null==r?void 0:r.attributesToCrop)?r.attributesToCrop.join(","):void 0,attributesToHighlight:(null==r?void 0:r.attributesToHighlight)?r.attributesToHighlight.join(","):void 0}),[4,this.httpRequest.get(i,a(f),c)]);case 3:return[2,o.sent()];case 4:throw new s("method parameter should be either POST or GET")}}))}))},t.prototype.getRawInfo=function(){return i(this,void 0,void 0,(function(){var e,r;return o(this,(function(n){switch(n.label){case 0:return e=t.routeConstructors.indexRoute(this.uid),[4,this.httpRequest.get(e)];case 1:return r=n.sent(),this.primaryKey=r.primaryKey,[2,r]}}))}))},t.prototype.fetchInfo=function(){return i(this,void 0,void 0,(function(){return o(this,(function(t){switch(t.label){case 0:return[4,this.getRawInfo()];case 1:return t.sent(),[2,this]}}))}))},t.prototype.fetchPrimaryKey=function(){return i(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t=this,[4,this.getRawInfo()];case 1:return t.primaryKey=e.sent().primaryKey,[2,this.primaryKey]}}))}))},t.create=function(e,r,s){return void 0===s&&(s={}),i(this,void 0,void 0,(function(){var i,u;return o(this,(function(o){switch(o.label){case 0:return i=t.apiRoutes.indexes,[4,new l(e).post(i,n(n({},s),{uid:r}))];case 1:return u=o.sent(),[2,new t(e,r,u.primaryKey)]}}))}))},t.prototype.update=function(e){return i(this,void 0,void 0,(function(){var r,n;return o(this,(function(i){switch(i.label){case 0:return r=t.routeConstructors.update(this.uid),[4,this.httpRequest.put(r,e)];case 1:return n=i.sent(),this.primaryKey=n.primaryKey,[2,this]}}))}))},t.prototype.delete=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.delete(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getStats=function(){return i(this,void 0,void 0,(function(){var t;return o(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(e){return i(this,void 0,void 0,(function(){var r,i;return o(this,(function(o){switch(o.label){case 0:return r=t.routeConstructors.getDocuments(this.uid),void 0!==e&&Array.isArray(e.attributesToRetrieve)&&(i=e.attributesToRetrieve.join(",")),[4,this.httpRequest.get(r,n(n({},e),void 0!==i?{attributesToRetrieve:i}:{}))];case 1:return[2,o.sent()]}}))}))},t.prototype.getDocument=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.getDocument(this.uid,e),[4,this.httpRequest.get(r)];case 1:return[2,n.sent()]}}))}))},t.prototype.addDocuments=function(e,r){return i(this,void 0,void 0,(function(){var n;return o(this,(function(i){switch(i.label){case 0:return n=t.routeConstructors.addDocuments(this.uid),[4,this.httpRequest.post(n,e,r)];case 1:return[2,i.sent()]}}))}))},t.prototype.updateDocuments=function(e,r){return i(this,void 0,void 0,(function(){var n;return o(this,(function(i){switch(i.label){case 0:return n=t.routeConstructors.updateDocuments(this.uid),[4,this.httpRequest.put(n,e,r)];case 1:return[2,i.sent()]}}))}))},t.prototype.deleteDocument=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.deleteDocument(this.uid,e),[4,this.httpRequest.delete(r)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteDocuments=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.deleteDocuments(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteAllDocuments=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.deleteAllDocuments(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getSettings=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getSettings(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateSettings=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateSettings(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSettings=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetSettings(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getSynonyms=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getSynonyms(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateSynonyms=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateSynonyms(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSynonyms=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetSynonyms(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getStopWords=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getStopWords(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateStopWords=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateStopWords(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetStopWords=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetStopWords(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getRankingRules=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getRankingRules(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateRankingRules=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateRankingRules(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetRankingRules=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetRankingRules(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getDistinctAttribute=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getDistinctAttribute(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateDistinctAttribute=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateDistinctAttribute(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetDistinctAttribute=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetDistinctAttribute(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getAttributesForFaceting=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getAttributesForFaceting(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateAttributesForFaceting=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateAttributesForFaceting(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetAttributesForFaceting=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetAttributesForFaceting(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getSearchableAttributes=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getSearchableAttributes(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateSearchableAttributes=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateSearchableAttributes(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSearchableAttributes=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetSearchableAttributes(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getDisplayedAttributes=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getDisplayedAttributes(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateDisplayedAttributes=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateDisplayedAttributes(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetDisplayedAttributes=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetDisplayedAttributes(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.apiRoutes={indexes:"indexes"},t.routeConstructors={indexRoute:function(e){return t.apiRoutes.indexes+"/"+e},getUpdateStatus:function(e,r){return t.routeConstructors.indexRoute(e)+"/updates/"+r},getAllUpdateStatus:function(e){return t.routeConstructors.indexRoute(e)+"/updates"},search:function(e){return t.routeConstructors.indexRoute(e)+"/search"},getRawInfo:function(t){return"indexes/"+t},update:function(e){return t.routeConstructors.indexRoute(e)},delete:function(e){return t.routeConstructors.indexRoute(e)},getStats:function(e){return t.routeConstructors.indexRoute(e)+"/stats"},getDocument:function(e,r){return t.routeConstructors.indexRoute(e)+"/documents/"+r},getDocuments:function(e){return t.routeConstructors.indexRoute(e)+"/documents"},addDocuments:function(e){return t.routeConstructors.getDocuments(e)},updateDocuments:function(e){return t.routeConstructors.getDocuments(e)},deleteAllDocuments:function(e){return t.routeConstructors.getDocuments(e)},deleteDocument:function(e,r){return t.routeConstructors.indexRoute(e)+"/documents/"+r},deleteDocuments:function(e){return t.routeConstructors.indexRoute(e)+"/documents/delete-batch"},getSettings:function(e){return t.routeConstructors.indexRoute(e)+"/settings"},updateSettings:function(e){return t.routeConstructors.getSettings(e)},resetSettings:function(e){return t.routeConstructors.getSettings(e)},getSynonyms:function(e){return t.routeConstructors.indexRoute(e)+"/settings/synonyms"},updateSynonyms:function(e){return t.routeConstructors.getSynonyms(e)},resetSynonyms:function(e){return t.routeConstructors.getSynonyms(e)},getStopWords:function(e){return t.routeConstructors.indexRoute(e)+"/settings/stop-words"},updateStopWords:function(e){return t.routeConstructors.getStopWords(e)},resetStopWords:function(e){return t.routeConstructors.getStopWords(e)},getRankingRules:function(e){return t.routeConstructors.indexRoute(e)+"/settings/ranking-rules"},updateRankingRules:function(e){return t.routeConstructors.getRankingRules(e)},resetRankingRules:function(e){return t.routeConstructors.getRankingRules(e)},getDistinctAttribute:function(e){return t.routeConstructors.indexRoute(e)+"/settings/distinct-attribute"},updateDistinctAttribute:function(e){return t.routeConstructors.getDistinctAttribute(e)},resetDistinctAttribute:function(e){return t.routeConstructors.getDistinctAttribute(e)},getAttributesForFaceting:function(e){return t.routeConstructors.indexRoute(e)+"/settings/attributes-for-faceting"},updateAttributesForFaceting:function(e){return t.routeConstructors.getAttributesForFaceting(e)},resetAttributesForFaceting:function(e){return t.routeConstructors.getAttributesForFaceting(e)},getSearchableAttributes:function(e){return t.routeConstructors.indexRoute(e)+"/settings/searchable-attributes"},updateSearchableAttributes:function(e){return t.routeConstructors.getSearchableAttributes(e)},resetSearchableAttributes:function(e){return t.routeConstructors.getSearchableAttributes(e)},getDisplayedAttributes:function(e){return t.routeConstructors.indexRoute(e)+"/settings/displayed-attributes"},updateDisplayedAttributes:function(e){return t.routeConstructors.getDisplayedAttributes(e)},resetDisplayedAttributes:function(e){return t.routeConstructors.getDisplayedAttributes(e)}},t}(),v=function(){function t(t){t.host=l.addTrailingSlash(t.host),this.config=t,this.httpRequest=new l(t)}return t.getApiRoutes=function(){return t.apiRoutes},t.getRouteConstructors=function(){return t.routeConstructors},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 o(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 o(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 e;return o(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.listIndexes,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.createIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){return o(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 o(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 o(this,(function(e){return[2,new y(this.config,t).delete()]}))}))},t.prototype.getKeys=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.getKeys,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.isHealthy=function(){return i(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.httpRequest.get(t.apiRoutes.isHealthy).then((function(){return!0}))];case 1:return[2,e.sent()]}}))}))},t.prototype.stats=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.stats,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.version=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.version,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.createDump=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.createDump,[4,this.httpRequest.post(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getDumpStatus=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.getDumpStatus(e),[4,this.httpRequest.get(r)];case 1:return[2,n.sent()]}}))}))},t.apiRoutes={listIndexes:"indexes",getKeys:"keys",isHealthy:"health",stats:"stats",version:"version",createDump:"dumps"},t.routeConstructors={getDumpStatus:function(t){return"dumps/"+t+"/status"}},t}();t.MeiliSearch=v,Object.defineProperty(t,"__esModule",{value:!0})}(e)}));function s(t){return"string"==typeof t||t instanceof String}function u(t,e,r){return e=e||"__ais-highlight__",r=r||"__/ais-highlight__",s(t)?t.replace(/<em>/g,e).replace(/<\/em>/g,r):JSON.stringify(t)}function a(t){var e=t.formattedHit,r=t.highlightPreTag,n=t.highlightPostTag;return Object.keys(e).reduce((function(t,i){return t[i]={value:u(e[i],r,n)},t}),{})}function c(t,e,r,n){var i=t;return void 0!==e&&s(i)&&(i[0]===i[0].toLowerCase()&&!1===i.startsWith("<em>")&&(i=""+e+i),!1==!!i.match(/[.!?]$/)&&(i=""+i+e)),u(i,r,n)}function h(t){var e=t.formattedHit,r=t.attributesToSnippet,n=t.snippetEllipsisText,i=t.highlightPreTag,o=t.highlightPostTag;return void 0===r?null:(r=r.map((function(t){return t.split(":")[0]})),Object.keys(e).reduce((function(t,s){return r.includes(s)&&(t[s]={value:c(e[s],n,i,o)}),t}),{}))}t.instantMeiliSearch=function(t,i,s){return void 0===s&&(s={}),{client:new o.MeiliSearch({host:t,apiKey:i}),paginationTotalHits:s.paginationTotalHits||200,primaryKey:s.primaryKey||void 0,placeholderSearch:!1!==s.placeholderSearch,hitsPerPage:20,page:0,transformToMeiliSearchParams:function(t){var r=t.query,n=t.facets,i=t.facetFilters,o=t.attributesToSnippet,s=t.attributesToRetrieve,u=t.attributesToHighlight,a=t.filters,c=void 0===a?"":a,h=t.numericFilters,f=void 0===h?[]:h,d=this.paginationTotalHits,p=[f.join(" AND "),c.trim()].filter((function(t){return t})).join(" AND ").trim();return e(e(e(e(e(e({q:r},(null==n?void 0:n.length)&&{facetsDistribution:n}),i&&{facetFilters:i}),o&&{attributesToCrop:o}),s&&{attributesToRetrieve:s}),p&&{filters:p}),{attributesToHighlight:u||["*"],limit:!this.placeholderSearch&&""===r||!d?0:d})},getNumberPages:function(t){var e=t%this.hitsPerPage==0?0:1;return Math.floor(t/this.hitsPerPage)+e},paginateHits:function(t){var e=this.page*this.hitsPerPage;return t.splice(e,this.hitsPerPage)},transformToISHits:function(t,r){var n=this;return this.paginateHits(t).map((function(t){var i=t._formatted,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"]);return e(e(e({},o),{_highlightResult:a(e({formattedHit:i},r)),_snippetResult:h(e({formattedHit:i},r))}),n.primaryKey&&{objectID:t[n.primaryKey]})}))},transformToISResponse:function(t,r,n){var i=r.exhaustiveFacetsCount,o=r.exhaustiveNbHits,s=r.facetsDistribution,u=r.nbHits,a=r.processingTimeMs,c=r.query,h=r.hits;return{results:[e(e(e({index:t,hitsPerPage:this.hitsPerPage},s&&{facets:s}),i&&{exhaustiveFacetsCount:i}),{page:this.page,nbPages:this.getNumberPages(h.length),exhaustiveNbHits:o,nbHits:u,processingTimeMS:a,query:c,hits:this.transformToISHits(h,n)})]}},search:function(t){var e=t[0];return r(this,void 0,void 0,(function(){var t,r,i,o,s,u,a;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=e.params,r=e.indexName,i=t.page,o=t.hitsPerPage,this.page=i||0,this.hitsPerPage=o||20,s=this.transformToMeiliSearchParams(t),[4,this.client.index(r).search(s.q,s)];case 1:return u=n.sent(),[2,this.transformToISResponse(r,u,t)];case 2:throw a=n.sent(),console.error(a),new Error(a);case 3:return[2]}}))}))}}},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){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,o){function s(t){try{a(n.next(t))}catch(t){o(t)}}function u(t){try{a(n.throw(t))}catch(t){o(t)}}function a(t){t.done?r(t.value):i(t.value).then(s,u)}a((n=n.apply(t,e||[])).next())}))}function o(t,e){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(t){return function(e){return a([t,e])}}function a(o){if(r)throw new TypeError("Generator is already executing.");for(;s;)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 s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}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}}}var s=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 o(this,(function(e){switch(e.label){case 0:return[4,new Promise((function(e){return setTimeout(e,t)}))];case 1:return[2,e.sent()]}}))}))}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 o(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 p(t){if("MeiliSearchApiError"!==t.type)throw new h(t.message,t);throw t}var l=function(){function t(t){this.headers=n(n(n({},t.headers||{}),{"Content-Type":"application/json"}),t.apiKey?{"X-Meili-API-Key":t.apiKey}:{}),this.url=new URL(t.host)}return t.addTrailingSlash=function(t){return t.endsWith("/")||(t+="/"),t},t.prototype.request=function(t){var e=t.method,r=t.url,s=t.params,u=t.body,a=t.config;return i(this,void 0,void 0,(function(){var t,i,c;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),t=new URL(r,this.url),s&&(i=new URLSearchParams,Object.keys(s).filter((function(t){return null!==s[t]})).map((function(t){return i.set(t,s[t])})),t.search=i.toString()),[4,fetch(t.toString(),n(n({},a),{method:e,body:u?JSON.stringify(u):void 0,headers:this.headers})).then((function(t){return d(t)}))];case 1:return[4,o.sent().text()];case 2:c=o.sent();try{return[2,JSON.parse(c)]}catch(t){return[2]}return[3,4];case 3:return p(o.sent()),[3,4];case 4:return[2]}}))}))},t.prototype.get=function(t,e,r){return i(this,void 0,void 0,(function(){return o(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 o(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 o(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 o(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 l(t)}return t.getApiRoutes=function(){return t.apiRoutes},t.getRouteConstructors=function(){return t.routeConstructors},t.prototype.getUpdateStatus=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.getUpdateStatus(this.uid,e),[4,this.httpRequest.get(r)];case 1:return[2,n.sent()]}}))}))},t.prototype.waitForPendingUpdate=function(t,e){var r=void 0===e?{}:e,n=r.timeOutMs,s=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 o(this,(function(n){switch(n.label){case 0:e=Date.now(),n.label=1;case 1:return Date.now()-e<s?[4,this.getUpdateStatus(t)]:[3,4];case 2:return"enqueued"!==(r=n.sent()).status?[2,r]:[4,c(h)];case 3:return n.sent(),[3,1];case 4:throw new u("timeout of "+s+"ms has exceeded on process "+t+" when waiting for pending update to resolve.")}}))}))},t.prototype.getAllUpdateStatus=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getAllUpdateStatus(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.search=function(e,r,u,c){return void 0===u&&(u="POST"),i(this,void 0,void 0,(function(){var i,h,f;return o(this,(function(o){switch(o.label){case 0:return i=t.routeConstructors.search(this.uid),h={q:e,offset:null==r?void 0:r.offset,limit:null==r?void 0:r.limit,cropLength:null==r?void 0:r.cropLength,filters:null==r?void 0:r.filters,matches:null==r?void 0:r.matches,facetFilters:null==r?void 0:r.facetFilters,facetsDistribution:null==r?void 0:r.facetsDistribution,attributesToRetrieve:null==r?void 0:r.attributesToRetrieve,attributesToCrop:null==r?void 0:r.attributesToCrop,attributesToHighlight:null==r?void 0:r.attributesToHighlight},"POST"!==u.toUpperCase()?[3,2]:[4,this.httpRequest.post(i,a(h),void 0,c)];case 1:return[2,o.sent()];case 2:return"GET"!==u.toUpperCase()?[3,4]:(f=n(n({},h),{facetFilters:Array.isArray(null==r?void 0:r.facetFilters)&&(null==r?void 0:r.facetFilters)?JSON.stringify(r.facetFilters):void 0,facetsDistribution:(null==r?void 0:r.facetsDistribution)?JSON.stringify(r.facetsDistribution):void 0,attributesToRetrieve:(null==r?void 0:r.attributesToRetrieve)?r.attributesToRetrieve.join(","):void 0,attributesToCrop:(null==r?void 0:r.attributesToCrop)?r.attributesToCrop.join(","):void 0,attributesToHighlight:(null==r?void 0:r.attributesToHighlight)?r.attributesToHighlight.join(","):void 0}),[4,this.httpRequest.get(i,a(f),c)]);case 3:return[2,o.sent()];case 4:throw new s("method parameter should be either POST or GET")}}))}))},t.prototype.getRawInfo=function(){return i(this,void 0,void 0,(function(){var e,r;return o(this,(function(n){switch(n.label){case 0:return e=t.routeConstructors.indexRoute(this.uid),[4,this.httpRequest.get(e)];case 1:return r=n.sent(),this.primaryKey=r.primaryKey,[2,r]}}))}))},t.prototype.fetchInfo=function(){return i(this,void 0,void 0,(function(){return o(this,(function(t){switch(t.label){case 0:return[4,this.getRawInfo()];case 1:return t.sent(),[2,this]}}))}))},t.prototype.fetchPrimaryKey=function(){return i(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t=this,[4,this.getRawInfo()];case 1:return t.primaryKey=e.sent().primaryKey,[2,this.primaryKey]}}))}))},t.create=function(e,r,s){return void 0===s&&(s={}),i(this,void 0,void 0,(function(){var i,u;return o(this,(function(o){switch(o.label){case 0:return i=t.apiRoutes.indexes,[4,new l(e).post(i,n(n({},s),{uid:r}))];case 1:return u=o.sent(),[2,new t(e,r,u.primaryKey)]}}))}))},t.prototype.update=function(e){return i(this,void 0,void 0,(function(){var r,n;return o(this,(function(i){switch(i.label){case 0:return r=t.routeConstructors.update(this.uid),[4,this.httpRequest.put(r,e)];case 1:return n=i.sent(),this.primaryKey=n.primaryKey,[2,this]}}))}))},t.prototype.delete=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.delete(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getStats=function(){return i(this,void 0,void 0,(function(){var t;return o(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(e){return i(this,void 0,void 0,(function(){var r,i;return o(this,(function(o){switch(o.label){case 0:return r=t.routeConstructors.getDocuments(this.uid),void 0!==e&&Array.isArray(e.attributesToRetrieve)&&(i=e.attributesToRetrieve.join(",")),[4,this.httpRequest.get(r,n(n({},e),void 0!==i?{attributesToRetrieve:i}:{}))];case 1:return[2,o.sent()]}}))}))},t.prototype.getDocument=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.getDocument(this.uid,e),[4,this.httpRequest.get(r)];case 1:return[2,n.sent()]}}))}))},t.prototype.addDocuments=function(e,r){return i(this,void 0,void 0,(function(){var n;return o(this,(function(i){switch(i.label){case 0:return n=t.routeConstructors.addDocuments(this.uid),[4,this.httpRequest.post(n,e,r)];case 1:return[2,i.sent()]}}))}))},t.prototype.updateDocuments=function(e,r){return i(this,void 0,void 0,(function(){var n;return o(this,(function(i){switch(i.label){case 0:return n=t.routeConstructors.updateDocuments(this.uid),[4,this.httpRequest.put(n,e,r)];case 1:return[2,i.sent()]}}))}))},t.prototype.deleteDocument=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.deleteDocument(this.uid,e),[4,this.httpRequest.delete(r)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteDocuments=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.deleteDocuments(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteAllDocuments=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.deleteAllDocuments(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getSettings=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getSettings(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateSettings=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateSettings(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSettings=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetSettings(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getSynonyms=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getSynonyms(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateSynonyms=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateSynonyms(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSynonyms=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetSynonyms(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getStopWords=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getStopWords(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateStopWords=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateStopWords(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetStopWords=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetStopWords(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getRankingRules=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getRankingRules(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateRankingRules=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateRankingRules(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetRankingRules=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetRankingRules(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getDistinctAttribute=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getDistinctAttribute(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateDistinctAttribute=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateDistinctAttribute(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetDistinctAttribute=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetDistinctAttribute(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getAttributesForFaceting=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getAttributesForFaceting(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateAttributesForFaceting=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateAttributesForFaceting(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetAttributesForFaceting=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetAttributesForFaceting(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getSearchableAttributes=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getSearchableAttributes(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateSearchableAttributes=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateSearchableAttributes(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSearchableAttributes=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetSearchableAttributes(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getDisplayedAttributes=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getDisplayedAttributes(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateDisplayedAttributes=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateDisplayedAttributes(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetDisplayedAttributes=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetDisplayedAttributes(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.apiRoutes={indexes:"indexes"},t.routeConstructors={indexRoute:function(e){return t.apiRoutes.indexes+"/"+e},getUpdateStatus:function(e,r){return t.routeConstructors.indexRoute(e)+"/updates/"+r},getAllUpdateStatus:function(e){return t.routeConstructors.indexRoute(e)+"/updates"},search:function(e){return t.routeConstructors.indexRoute(e)+"/search"},getRawInfo:function(t){return"indexes/"+t},update:function(e){return t.routeConstructors.indexRoute(e)},delete:function(e){return t.routeConstructors.indexRoute(e)},getStats:function(e){return t.routeConstructors.indexRoute(e)+"/stats"},getDocument:function(e,r){return t.routeConstructors.indexRoute(e)+"/documents/"+r},getDocuments:function(e){return t.routeConstructors.indexRoute(e)+"/documents"},addDocuments:function(e){return t.routeConstructors.getDocuments(e)},updateDocuments:function(e){return t.routeConstructors.getDocuments(e)},deleteAllDocuments:function(e){return t.routeConstructors.getDocuments(e)},deleteDocument:function(e,r){return t.routeConstructors.indexRoute(e)+"/documents/"+r},deleteDocuments:function(e){return t.routeConstructors.indexRoute(e)+"/documents/delete-batch"},getSettings:function(e){return t.routeConstructors.indexRoute(e)+"/settings"},updateSettings:function(e){return t.routeConstructors.getSettings(e)},resetSettings:function(e){return t.routeConstructors.getSettings(e)},getSynonyms:function(e){return t.routeConstructors.indexRoute(e)+"/settings/synonyms"},updateSynonyms:function(e){return t.routeConstructors.getSynonyms(e)},resetSynonyms:function(e){return t.routeConstructors.getSynonyms(e)},getStopWords:function(e){return t.routeConstructors.indexRoute(e)+"/settings/stop-words"},updateStopWords:function(e){return t.routeConstructors.getStopWords(e)},resetStopWords:function(e){return t.routeConstructors.getStopWords(e)},getRankingRules:function(e){return t.routeConstructors.indexRoute(e)+"/settings/ranking-rules"},updateRankingRules:function(e){return t.routeConstructors.getRankingRules(e)},resetRankingRules:function(e){return t.routeConstructors.getRankingRules(e)},getDistinctAttribute:function(e){return t.routeConstructors.indexRoute(e)+"/settings/distinct-attribute"},updateDistinctAttribute:function(e){return t.routeConstructors.getDistinctAttribute(e)},resetDistinctAttribute:function(e){return t.routeConstructors.getDistinctAttribute(e)},getAttributesForFaceting:function(e){return t.routeConstructors.indexRoute(e)+"/settings/attributes-for-faceting"},updateAttributesForFaceting:function(e){return t.routeConstructors.getAttributesForFaceting(e)},resetAttributesForFaceting:function(e){return t.routeConstructors.getAttributesForFaceting(e)},getSearchableAttributes:function(e){return t.routeConstructors.indexRoute(e)+"/settings/searchable-attributes"},updateSearchableAttributes:function(e){return t.routeConstructors.getSearchableAttributes(e)},resetSearchableAttributes:function(e){return t.routeConstructors.getSearchableAttributes(e)},getDisplayedAttributes:function(e){return t.routeConstructors.indexRoute(e)+"/settings/displayed-attributes"},updateDisplayedAttributes:function(e){return t.routeConstructors.getDisplayedAttributes(e)},resetDisplayedAttributes:function(e){return t.routeConstructors.getDisplayedAttributes(e)}},t}(),v=function(){function t(t){t.host=l.addTrailingSlash(t.host),this.config=t,this.httpRequest=new l(t)}return t.getApiRoutes=function(){return t.apiRoutes},t.getRouteConstructors=function(){return t.routeConstructors},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 o(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 o(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 e;return o(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.listIndexes,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.createIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){return o(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 o(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 o(this,(function(e){return[2,new y(this.config,t).delete()]}))}))},t.prototype.getKeys=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.getKeys,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.isHealthy=function(){return i(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.httpRequest.get(t.apiRoutes.isHealthy).then((function(){return!0}))];case 1:return[2,e.sent()]}}))}))},t.prototype.stats=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.stats,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.version=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.version,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.createDump=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.createDump,[4,this.httpRequest.post(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getDumpStatus=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.getDumpStatus(e),[4,this.httpRequest.get(r)];case 1:return[2,n.sent()]}}))}))},t.apiRoutes={listIndexes:"indexes",getKeys:"keys",isHealthy:"health",stats:"stats",version:"version",createDump:"dumps"},t.routeConstructors={getDumpStatus:function(t){return"dumps/"+t+"/status"}},t}();t.MeiliSearch=v,Object.defineProperty(t,"__esModule",{value:!0})}(e)})),s=function(t,r){var n=t.query,i=t.facets,o=t.facetFilters,s=t.attributesToSnippet,u=t.attributesToRetrieve,a=t.attributesToHighlight,c=t.filters,h=void 0===c?"":c,f=t.numericFilters,d=void 0===f?[]:f,p=r.paginationTotalHits,l=r.placeholderSearch,y=p,v=[d.join(" AND "),h.trim()].filter((function(t){return t})).join(" AND ").trim();return e(e(e(e(e(e({q:n},(null==i?void 0:i.length)&&{facetsDistribution:i}),o&&{facetFilters:o}),s&&{attributesToCrop:s}),u&&{attributesToRetrieve:u}),v&&{filters:v}),{attributesToHighlight:a||["*"],limit:!l&&""===n||!y?0:y})},u=function(t,e){var r=e.hitsPerPage;return r>0?Math.ceil(t/r):0},a=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 h=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:h(e[i],r,n)},t}),{})},d=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)),h(i,r,n)},p=function(t){var e=t.formattedHit,r=t.attributesToSnippet,n=t.snippetEllipsisText,i=t.highlightPreTag,o=t.highlightPostTag;return void 0===r?null:(r=r.map((function(t){return t.split(":")[0]})),Object.keys(e).reduce((function(t,s){return r.includes(s)&&(t[s]={value:d(e[s],n,i,o)}),t}),{}))},l=function(t,r,n){var i=n.primaryKey;return a(t,n).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),{_highlightResult:f(e({formattedHit:n},r)),_snippetResult:p(e({formattedHit:n},r))}),i&&{objectID:t[i]})}return t}))},y=function(t,r,n,i){var o=r.exhaustiveFacetsCount,s=r.exhaustiveNbHits,a=r.facetsDistribution,c=r.nbHits,h=r.processingTimeMs,f=r.query,d=r.hits,p=i.hitsPerPage,y=i.page;return{results:[e(e(e({index:t,hitsPerPage:p},a&&{facets:a}),o&&{exhaustiveFacetsCount:o}),{page:y,nbPages:u(d.length,i),exhaustiveNbHits:s,nbHits:c,processingTimeMS:h,query:f,hits:l(d,n,i)})]}};t.adaptToISHits=l,t.adaptToISResponse=y,t.adaptToMeiliSearchParams=s,t.createHighlighResult=f,t.createSnippetResult=p,t.getNumberPages=u,t.instantMeiliSearch=function(t,e,i){return void 0===i&&(i={}),{MeiliSearchClient:new o.MeiliSearch({host:t,apiKey:e}),search:function(t){var e=t[0];return r(this,void 0,void 0,(function(){var t,r,o,u,a,c,h,f,d,p,l,v;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=e.params,r=e.indexName,o=i.paginationTotalHits,u=i.primaryKey,a=i.placeholderSearch,c=t.page,h=t.hitsPerPage,f=this.MeiliSearchClient,p=s(t,d={client:f,paginationTotalHits:o||200,primaryKey:u||void 0,placeholderSearch:!1!==a,hitsPerPage:void 0===h?20:h,page:c||0}),[4,f.index(r).search(p.q,p)];case 1:return l=n.sent(),[2,y(r,l,t,d)];case 2:throw v=n.sent(),console.error(v),new Error(v);case 3:return[2]}}))}))}}},t.isString=c,t.paginateHits=a,t.replaceHighlightTags=h,t.snippetValue=d,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=instant-meilisearch.umd.min.js.map

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

// Type definitions for @meilisearch/instant-meilisearch 0.4.2
// Type definitions for @meilisearch/instant-meilisearch 0.5.0
// Project: https://github.com/meilisearch/instant-meilisearch.git

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

import { InstantMeiliSearchOptions, InstantMeiliSearchInstance } from './types';
export declare function instantMeiliSearch(hostUrl: string, apiKey: string, options?: InstantMeiliSearchOptions): InstantMeiliSearchInstance;
export * from './client';
export * from './adapter';
export * from './types';
//# sourceMappingURL=index.d.ts.map
{
"name": "@meilisearch/instant-meilisearch",
"version": "0.4.2",
"version": "0.5.0",
"private": false,

@@ -8,3 +8,4 @@ "description": "The search client to use MeiliSearch with InstantSearch.",

"cleanup": "shx rm -rf dist/",
"test": "yarn build && jest",
"test:watch": "yarn test --watch",
"test": "jest --runInBand",
"test:all": "yarn test && yarn test:env && yarn test:playgrounds && yarn test:e2e",

@@ -96,3 +97,3 @@ "test:env": "yarn build && yarn test:env:browser && yarn test:env:nodejs && yarn test:env:esm && yarn test:env:ts",

"jest-environment-jsdom": "25.5",
"jest-watch-typeahead": "^0.6.0",
"jest-watch-typeahead": "^0.6.3",
"prettier": "^2.0.0",

@@ -99,0 +100,0 @@ "regenerator-runtime": "^0.13.7",

@@ -1,162 +0,3 @@

import { MeiliSearch } from 'meilisearch'
import { createHighlighResult, createSnippetResult } from './format'
import {
InstantMeiliSearchOptions,
InstantMeiliSearchInstance,
InstantSearchTypes,
} from './types'
export function instantMeiliSearch(
hostUrl: string,
apiKey: string,
options: InstantMeiliSearchOptions = {}
): InstantMeiliSearchInstance {
return {
client: new MeiliSearch({ host: hostUrl, apiKey: apiKey }),
paginationTotalHits: options.paginationTotalHits || 200,
primaryKey: options.primaryKey || undefined,
placeholderSearch: options.placeholderSearch !== false, // true by default
hitsPerPage: 20,
page: 0,
/*
REQUEST
*/
transformToMeiliSearchParams: function ({
query,
facets,
facetFilters,
attributesToSnippet: attributesToCrop,
attributesToRetrieve,
attributesToHighlight,
filters = '',
numericFilters = [],
}) {
const limit = this.paginationTotalHits
const filter = [numericFilters.join(' AND '), filters.trim()]
.filter((x) => x)
.join(' AND ')
.trim()
// Creates search params object compliant with MeiliSearch
return {
q: query,
...(facets?.length && { facetsDistribution: facets }),
...(facetFilters && { facetFilters }),
...(attributesToCrop && { attributesToCrop }),
...(attributesToRetrieve && { attributesToRetrieve }),
...(filter && { filters: filter }),
attributesToHighlight: attributesToHighlight || ['*'],
limit: (!this.placeholderSearch && query === '') || !limit ? 0 : limit,
}
},
/*
RESPONSE
*/
getNumberPages: function (hitsLength) {
const adjust = hitsLength % this.hitsPerPage! === 0 ? 0 : 1
return Math.floor(hitsLength / this.hitsPerPage!) + adjust // total number of pages
},
paginateHits: function (hits) {
const start = this.page * this.hitsPerPage!
return hits.splice(start, this.hitsPerPage)
},
transformToISHits: function (meiliSearchHits, instantSearchParams) {
const paginatedHits = this.paginateHits(meiliSearchHits)
return paginatedHits.map((hit: Record<string, any>) => {
const { _formatted: formattedHit, ...restOfHit } = hit
// Creates Hit object compliant with InstantSearch
return {
...restOfHit,
_highlightResult: createHighlighResult({
formattedHit,
...instantSearchParams,
}),
_snippetResult: createSnippetResult({
formattedHit,
...instantSearchParams,
}),
...(this.primaryKey && { objectID: hit[this.primaryKey] }),
}
})
},
transformToISResponse: function (
indexUid,
{
exhaustiveFacetsCount,
exhaustiveNbHits,
facetsDistribution: facets,
nbHits,
processingTimeMs,
query,
hits,
},
instantSearchParams
) {
// Create response object compliant with InstantSearch
const ISResponse = {
index: indexUid,
hitsPerPage: this.hitsPerPage,
...(facets && { facets }),
...(exhaustiveFacetsCount && { exhaustiveFacetsCount }),
page: this.page,
nbPages: this.getNumberPages(hits.length),
exhaustiveNbHits,
nbHits,
processingTimeMS: processingTimeMs,
query,
hits: this.transformToISHits(hits, instantSearchParams),
}
return {
results: [ISResponse],
}
},
/*
SEARCH
*/
search: async function ([
isSearchRequest,
]: InstantSearchTypes.SearchRequest[]) {
try {
// Params got from InstantSearch
const {
params: instantSearchParams,
indexName: indexUid,
} = isSearchRequest
const { page, hitsPerPage } = instantSearchParams
this.page = page || 0 // default page is 0 if none is provided
this.hitsPerPage = hitsPerPage || 20 // 20 is the MeiliSearch's default limit value. `hitsPerPage` can be changed with `InsantSearch.configure`.
// Transform IS params to MeiliSearch params
const msSearchParams = this.transformToMeiliSearchParams(
instantSearchParams
)
// Executes the search with MeiliSearch
const searchResponse = await this.client
.index(indexUid)
.search(msSearchParams.q, msSearchParams)
// Parses the MeiliSearch response and returns it for InstantSearch
return this.transformToISResponse(
indexUid,
searchResponse,
instantSearchParams
)
} catch (e) {
console.error(e)
throw new Error(e)
}
},
}
}
export * from './client'
export * from './adapter'
export * from './types'

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

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