@meilisearch/instant-meilisearch
Advanced tools
Comparing version 0.13.5 to 0.13.6
@@ -929,4 +929,11 @@ 'use strict'; | ||
} | ||
function fillMissingFacets(initialFacetDistribution, meilisearchResults) { | ||
for (var _i = 0, meilisearchResults_1 = meilisearchResults; _i < meilisearchResults_1.length; _i++) { | ||
var searchResult = meilisearchResults_1[_i]; | ||
initialFacetDistribution[searchResult.indexUid] = __assign(__assign({}, (searchResult.facetDistribution || {})), (initialFacetDistribution[searchResult.indexUid] || {})); | ||
} | ||
return initialFacetDistribution; | ||
} | ||
var PACKAGE_VERSION = '0.13.5'; | ||
var PACKAGE_VERSION = '0.13.6'; | ||
@@ -1004,5 +1011,9 @@ var constructClientAgents = function (clientAgents) { | ||
return [4 /*yield*/, searchResolver.multiSearch(meilisearchRequests, instantSearchPagination // Create issue on pagination | ||
)]; | ||
) | ||
// Fill the missing facet values if keepZeroFacets is true | ||
]; | ||
case 2: | ||
meilisearchResults = _a.sent(); | ||
// Fill the missing facet values if keepZeroFacets is true | ||
initialFacetDistribution = fillMissingFacets(initialFacetDistribution, meilisearchResults); | ||
instantSearchResponse = adaptSearchResults(meilisearchResults, initialFacetDistribution, instantMeilisearchConfig); | ||
@@ -1009,0 +1020,0 @@ return [2 /*return*/, instantSearchResponse]; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("meilisearch"),e=function(){return e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},e.apply(this,arguments)};function r(t,e,r,n){return new(r||(r=Promise))((function(i,a){function o(t){try{s(n.next(t))}catch(t){a(t)}}function u(t){try{s(n.throw(t))}catch(t){a(t)}}function s(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,u)}s((n=n.apply(t,e||[])).next())}))}function n(t,e){var r,n,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(u){return function(s){return function(u){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(o=0)),o;)try{if(r=1,n&&(i=2&u[0]?n.return:u[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,u[1])).done)return i;switch(n=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,n=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(6===u[0]&&o.label<i[1]){o.label=i[1],i=u;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(u);break}i[2]&&o.ops.pop(),o.trys.pop();continue}u=e.call(t,o)}catch(t){u=[6,t],n=0}finally{r=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}function i(t,e,r){if(r||2===arguments.length)for(var n,i=0,a=e.length;i<a;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}function a(t){return"object"==typeof t&&!Array.isArray(t)&&null!==t}function o(t){return t.replace(/(.*):(.*)/i,'"$1"="$2"')}function u(t){return"string"==typeof t?o(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return o(t)})).filter((function(t){return t})):o(t)})).filter((function(t){return t})):[]}function s(t){return""===t?[]:"string"==typeof t?[t]:t}function c(t,e,r){return function(t,e,r){var n=r.trim(),a=s(t),o=s(e);return i(i(i([],a,!0),o,!0),[n],!1).filter((function(t){return Array.isArray(t)?t.length:t}))}(u(r||[]),u(e||[]),t||"")}function l(t){var e={},r=t.facets,n=t.attributesToSnippet,i=t.snippetEllipsisText,a=t.attributesToRetrieve,o=t.attributesToHighlight,u=t.highlightPreTag,s=t.highlightPostTag,l=t.placeholderSearch,f=t.query,d=t.sort,g=t.pagination,h=t.matchingStrategy,p=t.filters,v=t.numericFilters,y=t.facetFilters,m=t.indexUid,P=c(p,v,y);return{getParams:function(){return e},addQuery:function(){e.q=f},addIndexUid:function(){e.indexUid=m},addFacets:function(){Array.isArray(r)?e.facets=r:"string"==typeof r&&(e.facets=[r])},addAttributesToCrop:function(){n&&(e.attributesToCrop=n)},addCropMarker:function(){null!=i&&(e.cropMarker=i)},addAttributesToRetrieve:function(){a&&(e.attributesToRetrieve=a)},addFilters:function(){P.length&&(e.filter=P)},addAttributesToHighlight:function(){e.attributesToHighlight=o||["*"]},addPreTag:function(){e.highlightPreTag=u||"__ais-highlight__"},addPostTag:function(){e.highlightPostTag=s||"__/ais-highlight__"},addPagination:function(){var t=function(t,e,r){return!!(r||e||t&&0!==t.length)}(P,f,l);if(g.finite){var r=function(t,e){var r=t.page,n=t.hitsPerPage;return e?{hitsPerPage:n,page:r+1}:{hitsPerPage:0,page:r+1}}(g,t),n=r.hitsPerPage,i=r.page;e.hitsPerPage=n,e.page=i}else{var a=function(t,e){var r=t.page,n=t.hitsPerPage;return e?{limit:n+1,offset:r*n}:{limit:0,offset:0}}(g,t),o=a.limit,u=a.offset;e.limit=o,e.offset=u}},addSort:function(){(null==d?void 0:d.length)&&(e.sort=Array.isArray(d)?d:[d])},addGeoSearchFilter:function(){var r=function(t){var e,r,n,i=t.insideBoundingBox,a=t.aroundLatLng,o=t.aroundRadius,u=t.minimumAroundRadius;if(a){var s=a.split(",").map((function(t){return Number.parseFloat(t).toFixed(5)}));e=[h=s[0],p=s[1]]}if(null==o&&null==u||("all"===o?console.warn("instant-meilisearch is not compatible with the `all` value on the aroundRadius parameter"):r=null!=o?o:u),i&&"string"==typeof i){var c=i.split(",").map((function(t){return parseFloat(t)})),l=c[0],f=c[1],d=c[2],g=c[3];n="_geoBoundingBox([".concat(l,", ").concat(f,"], [").concat(d,", ").concat(g,"])")}else if(null!=e&&null!=r){var h=e[0],p=e[1];n="_geoRadius(".concat(h,", ").concat(p,", ").concat(r,")")}return n}({insideBoundingBox:t.insideBoundingBox,aroundLatLng:t.aroundLatLng,aroundRadius:t.aroundRadius,minimumAroundRadius:t.minimumAroundRadius});r&&(e.filter?e.filter.unshift(r):e.filter=[r])},addMatchingStrategy:function(){h&&(e.matchingStrategy=h)}}}function f(t){var e=l(t);return e.addQuery(),e.addIndexUid(),e.addFacets(),e.addAttributesToHighlight(),e.addPreTag(),e.addPostTag(),e.addAttributesToRetrieve(),e.addAttributesToCrop(),e.addCropMarker(),e.addPagination(),e.addFilters(),e.addSort(),e.addGeoSearchFilter(),e.addMatchingStrategy(),e.getParams()}function d(t){return"string"==typeof t?t:void 0===t?JSON.stringify(null):JSON.stringify(t)}function g(t){return Array.isArray(t)?t.map((function(t){return g(t)})):a(t)?Object.keys(t).reduce((function(e,r){return e[r]=g(t[r]),e}),{}):{value:d(t)}}function h(t){if(!t)return{};var e=g(t);return{_highlightResult:e,_snippetResult:e}}function p(t,e){var r=t.hits,n=t.pagination.hitsPerPage,i=e.finitePagination,a=e.primaryKey;!i&&r.length>n&&r.splice(r.length-1,1);var o=r.map((function(t){if(Object.keys(t).length>0){var e=t._formatted;t._matchesPosition;var r=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r}(t,["_formatted","_matchesPosition"]),n=Object.assign(r,h(e));return a&&(n.objectID=t[a]),n}return t}));return o=function(t){for(var e,r=0;r<t.length;r++){var n="".concat(r+1e6*Math.random());t[r]._geo&&(t[r]._geoloc=t[r]._geo,t[r].objectID=n),(null===(e=t[r]._formatted)||void 0===e?void 0:e._geo)&&(t[r]._formatted._geoloc=t[r]._formatted._geo,t[r]._formatted.objectID=n)}return t}(o),o}function v(t){return Object.keys(t).reduce((function(r,n){return r[n]=e(e({},t[n]),{avg:0,sum:0}),r}),{})}function y(t,e,r){var n=t.map((function(t){return function(t,e,r){var n=t.processingTimeMs,i=t.query,a=t.indexUid,o=t.facetDistribution,u=void 0===o?{}:o,s=t.facetStats,c=void 0===s?{}:s,l=Object.keys(u),f=function(t,e){var r=e.hitsPerPage,n=e.page,i=function(t,e){if(null!=t.totalPages)return t.totalPages;if(0===e)return 0;var r=t.limit,n=void 0===r?20:r,i=t.offset;return(void 0===i?0:i)/e+1+(t.hits.length>=n?1:0)}(t,r);return{page:n,nbPages:i,hitsPerPage:r}}(t,t.pagination),d=f.hitsPerPage,g=f.page,h=f.nbPages,y=p(t,r),m=function(t){var e=t.hitsPerPage,r=void 0===e?0:e,n=t.totalPages,i=void 0===n?0:n,a=t.estimatedTotalHits,o=t.totalHits;return null!=a?a:null!=o?o:r*i}(t),P=function(t,e,r,n){return t?function(t,e,r){for(var n=function(t){return t?"string"==typeof t?[t]:t:[]}(t),i={},a=0,o=n;a<o.length;a++){var u=o[a];for(var s in e[u])i[u]||(i[u]=r[u]||{}),i[u][s]?i[u][s]=r[u][s]:i[u][s]=0}return i}(e,r,n=n||{}):n}(r.keepZeroFacets,l,e,u);return{index:a,hitsPerPage:d,page:g,facets:P,nbPages:h,nbHits:m,processingTimeMS:n,query:i,hits:y,params:"",exhaustiveNbHits:!1,facets_stats:v(c)}}(t,e[t.indexUid],r)}));return{results:n}}function m(t){return t?t.split(/,(?=\w+:(?:asc|desc))/):[]}function P(t,e,r){return{hitsPerPage:void 0===e?20:e,page:r||0,finite:!!t}}function b(t){var e=t.indexOf(":");return-1===e?{indexUid:t,sortBy:""}:{indexUid:t.substring(0,e),sortBy:t.substring(e+1)}}function x(t,r){var n=t.query,i=t.indexName,a=t.params,o=b(i),u=o.indexUid,s=o.sortBy,c=P(r.finitePagination,null==a?void 0:a.hitsPerPage,null==a?void 0:a.page);return e(e(e(e({},r),{query:n}),a),{sort:m(s),indexUid:u,pagination:c,placeholderSearch:!1!==r.placeholderSearch,keepZeroFacets:!!r.keepZeroFacets})}function S(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(t){return}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,r){e[t]=JSON.stringify(r)},clearCache:function(){e={}}}}function w(t){var r=l(e(e({},t),{placeholderSearch:!0,query:""}));return r.addFacets(),r.addIndexUid(),r.addPagination(),r.getParams()}function T(t,e,i){return r(this,void 0,void 0,(function(){var r,a,o,u,s,c;return n(this,(function(n){switch(n.label){case 0:return l="indexUid",f=[],r=function(t){return!f.includes(t[l])&&(f.push(t[l]),!0)},a=e.filter(r).filter((function(t){var e=t.indexUid;return!Object.keys(i).includes(e)})),0===a.length?[2,i]:[4,t.multiSearch(a,[])];case 1:for(o=n.sent(),u=0,s=o;u<s.length;u++)c=s[u],i[c.indexUid]=c.facetDistribution||{};return[2,i]}var l,f}))}))}"function"==typeof SuppressedError&&SuppressedError;var A;exports.MatchingStrategies=void 0,(A=exports.MatchingStrategies||(exports.MatchingStrategies={})).ALL="all",A.LAST="last",exports.instantMeiliSearch=function(i,o,u){void 0===o&&(o=""),void 0===u&&(u={}),function(t,e,r){var n=r.requestConfig,i=r.httpClient;if("string"!=typeof t)throw new TypeError("Provided hostUrl value (1st parameter) is not a string, expected string");if("string"!=typeof e&&"function"!=typeof e)throw new TypeError("Provided apiKey value (2nd parameter) is not a string or a function, expected string or function");if(void 0!==n&&!a(n))throw new TypeError("Provided requestConfig should be an object");if(i&&"function"!=typeof i)throw new TypeError("Provided custom httpClient should be a function")}(i,o,u);var s={host:i,apiKey:o=function(t){if("function"==typeof t){var e=t();if("string"!=typeof e)throw new TypeError("Provided apiKey function (2nd parameter) did not return a string, expected string");return e}return t}(o),clientAgents:function(t){void 0===t&&(t=[]);var e="Meilisearch instant-meilisearch (v".concat("0.13.5",")");return t.concat(e)}(u.clientAgents)};void 0!==u.httpClient&&(s.httpClient=u.httpClient),void 0!==u.requestConfig&&(s.requestConfig=u.requestConfig);var c,l,d,g=new t.MeiliSearch(s),h=S(),p=(c=g,l=h,{multiSearch:function(t,i){return r(this,void 0,void 0,(function(){var r,a,o,u;return n(this,(function(n){switch(n.label){case 0:return r=l.formatKey([t]),(a=l.getEntry(r))?[2,a]:[4,c.multiSearch({queries:t})];case 1:return o=n.sent(),u=o.results.map((function(t,r){return e(e({},t),{pagination:i[r]||{}})})),l.setEntry(r,u),[2,u]}}))}))}}),v={},A=(d=u,e(e({},{placeholderSearch:!0,keepZeroFacets:!1,clientAgents:[],finitePagination:!1}),d));return{clearCache:function(){return h.clearCache()},search:function(t){return r(this,void 0,void 0,(function(){var e,r,i,a,o,s,c,l,d,g,h;return n(this,(function(n){switch(n.label){case 0:for(n.trys.push([0,3,,4]),e=[],r=[],i=[],a=0,o=t;a<o.length;a++)s=o[a],c=x(s,u),l=f(c),e.push(l),d=w(c),i.push(d),r.push(c.pagination);return[4,T(p,i,v)];case 1:return v=n.sent(),[4,p.multiSearch(e,r)];case 2:return g=n.sent(),[2,y(g,v,A)];case 3:throw h=n.sent(),console.error(h),new Error(h);case 4:return[2]}}))}))},searchForFacetValues:function(t){return r(this,void 0,void 0,(function(){var r,i,a,o,s,c,l,d,h,p;return n(this,(function(n){switch(n.label){case 0:r=[],i=0,a=t,n.label=1;case 1:return i<a.length?(o=a[i],s=function(t,r){var n=b(t.indexName),i=n.indexUid,a=n.sortBy,o=t.params,u=P(r.finitePagination,null==o?void 0:o.hitsPerPage,null==o?void 0:o.page);return e(e(e({},r),o),{sort:m(a),indexUid:i,pagination:u,placeholderSearch:!1!==r.placeholderSearch,keepZeroFacets:!!r.keepZeroFacets})}(o,u),c=f(s),delete(l=e(e({},c),{facetQuery:o.params.facetQuery,facetName:o.params.facetName})).indexUid,[4,g.index(s.indexUid).searchForFacetValues(l)]):[3,4];case 2:d=n.sent(),h=d.facetHits.map((function(t){return e(e({},t),{highlighted:t.value})})),p={facetHits:h,exhaustiveFacetsCount:!1,processingTimeMS:d.processingTimeMs},r.push(p),n.label=3;case 3:return i++,[3,1];case 4:return[2,r]}}))}))}}}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("meilisearch"),e=function(){return e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},e.apply(this,arguments)};function r(t,e,r,n){return new(r||(r=Promise))((function(i,a){function o(t){try{s(n.next(t))}catch(t){a(t)}}function u(t){try{s(n.throw(t))}catch(t){a(t)}}function s(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,u)}s((n=n.apply(t,e||[])).next())}))}function n(t,e){var r,n,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(u){return function(s){return function(u){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(o=0)),o;)try{if(r=1,n&&(i=2&u[0]?n.return:u[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,u[1])).done)return i;switch(n=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,n=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(6===u[0]&&o.label<i[1]){o.label=i[1],i=u;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(u);break}i[2]&&o.ops.pop(),o.trys.pop();continue}u=e.call(t,o)}catch(t){u=[6,t],n=0}finally{r=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}function i(t,e,r){if(r||2===arguments.length)for(var n,i=0,a=e.length;i<a;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}function a(t){return"object"==typeof t&&!Array.isArray(t)&&null!==t}function o(t){return t.replace(/(.*):(.*)/i,'"$1"="$2"')}function u(t){return"string"==typeof t?o(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return o(t)})).filter((function(t){return t})):o(t)})).filter((function(t){return t})):[]}function s(t){return""===t?[]:"string"==typeof t?[t]:t}function c(t,e,r){return function(t,e,r){var n=r.trim(),a=s(t),o=s(e);return i(i(i([],a,!0),o,!0),[n],!1).filter((function(t){return Array.isArray(t)?t.length:t}))}(u(r||[]),u(e||[]),t||"")}function l(t){var e={},r=t.facets,n=t.attributesToSnippet,i=t.snippetEllipsisText,a=t.attributesToRetrieve,o=t.attributesToHighlight,u=t.highlightPreTag,s=t.highlightPostTag,l=t.placeholderSearch,f=t.query,d=t.sort,g=t.pagination,h=t.matchingStrategy,p=t.filters,v=t.numericFilters,y=t.facetFilters,m=t.indexUid,b=c(p,v,y);return{getParams:function(){return e},addQuery:function(){e.q=f},addIndexUid:function(){e.indexUid=m},addFacets:function(){Array.isArray(r)?e.facets=r:"string"==typeof r&&(e.facets=[r])},addAttributesToCrop:function(){n&&(e.attributesToCrop=n)},addCropMarker:function(){null!=i&&(e.cropMarker=i)},addAttributesToRetrieve:function(){a&&(e.attributesToRetrieve=a)},addFilters:function(){b.length&&(e.filter=b)},addAttributesToHighlight:function(){e.attributesToHighlight=o||["*"]},addPreTag:function(){e.highlightPreTag=u||"__ais-highlight__"},addPostTag:function(){e.highlightPostTag=s||"__/ais-highlight__"},addPagination:function(){var t=function(t,e,r){return!!(r||e||t&&0!==t.length)}(b,f,l);if(g.finite){var r=function(t,e){var r=t.page,n=t.hitsPerPage;return e?{hitsPerPage:n,page:r+1}:{hitsPerPage:0,page:r+1}}(g,t),n=r.hitsPerPage,i=r.page;e.hitsPerPage=n,e.page=i}else{var a=function(t,e){var r=t.page,n=t.hitsPerPage;return e?{limit:n+1,offset:r*n}:{limit:0,offset:0}}(g,t),o=a.limit,u=a.offset;e.limit=o,e.offset=u}},addSort:function(){(null==d?void 0:d.length)&&(e.sort=Array.isArray(d)?d:[d])},addGeoSearchFilter:function(){var r=function(t){var e,r,n,i=t.insideBoundingBox,a=t.aroundLatLng,o=t.aroundRadius,u=t.minimumAroundRadius;if(a){var s=a.split(",").map((function(t){return Number.parseFloat(t).toFixed(5)}));e=[h=s[0],p=s[1]]}if(null==o&&null==u||("all"===o?console.warn("instant-meilisearch is not compatible with the `all` value on the aroundRadius parameter"):r=null!=o?o:u),i&&"string"==typeof i){var c=i.split(",").map((function(t){return parseFloat(t)})),l=c[0],f=c[1],d=c[2],g=c[3];n="_geoBoundingBox([".concat(l,", ").concat(f,"], [").concat(d,", ").concat(g,"])")}else if(null!=e&&null!=r){var h=e[0],p=e[1];n="_geoRadius(".concat(h,", ").concat(p,", ").concat(r,")")}return n}({insideBoundingBox:t.insideBoundingBox,aroundLatLng:t.aroundLatLng,aroundRadius:t.aroundRadius,minimumAroundRadius:t.minimumAroundRadius});r&&(e.filter?e.filter.unshift(r):e.filter=[r])},addMatchingStrategy:function(){h&&(e.matchingStrategy=h)}}}function f(t){var e=l(t);return e.addQuery(),e.addIndexUid(),e.addFacets(),e.addAttributesToHighlight(),e.addPreTag(),e.addPostTag(),e.addAttributesToRetrieve(),e.addAttributesToCrop(),e.addCropMarker(),e.addPagination(),e.addFilters(),e.addSort(),e.addGeoSearchFilter(),e.addMatchingStrategy(),e.getParams()}function d(t){return"string"==typeof t?t:void 0===t?JSON.stringify(null):JSON.stringify(t)}function g(t){return Array.isArray(t)?t.map((function(t){return g(t)})):a(t)?Object.keys(t).reduce((function(e,r){return e[r]=g(t[r]),e}),{}):{value:d(t)}}function h(t){if(!t)return{};var e=g(t);return{_highlightResult:e,_snippetResult:e}}function p(t,e){var r=t.hits,n=t.pagination.hitsPerPage,i=e.finitePagination,a=e.primaryKey;!i&&r.length>n&&r.splice(r.length-1,1);var o=r.map((function(t){if(Object.keys(t).length>0){var e=t._formatted;t._matchesPosition;var r=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r}(t,["_formatted","_matchesPosition"]),n=Object.assign(r,h(e));return a&&(n.objectID=t[a]),n}return t}));return o=function(t){for(var e,r=0;r<t.length;r++){var n="".concat(r+1e6*Math.random());t[r]._geo&&(t[r]._geoloc=t[r]._geo,t[r].objectID=n),(null===(e=t[r]._formatted)||void 0===e?void 0:e._geo)&&(t[r]._formatted._geoloc=t[r]._formatted._geo,t[r]._formatted.objectID=n)}return t}(o),o}function v(t){return Object.keys(t).reduce((function(r,n){return r[n]=e(e({},t[n]),{avg:0,sum:0}),r}),{})}function y(t,e,r){var n=t.map((function(t){return function(t,e,r){var n=t.processingTimeMs,i=t.query,a=t.indexUid,o=t.facetDistribution,u=void 0===o?{}:o,s=t.facetStats,c=void 0===s?{}:s,l=Object.keys(u),f=function(t,e){var r=e.hitsPerPage,n=e.page,i=function(t,e){if(null!=t.totalPages)return t.totalPages;if(0===e)return 0;var r=t.limit,n=void 0===r?20:r,i=t.offset;return(void 0===i?0:i)/e+1+(t.hits.length>=n?1:0)}(t,r);return{page:n,nbPages:i,hitsPerPage:r}}(t,t.pagination),d=f.hitsPerPage,g=f.page,h=f.nbPages,y=p(t,r),m=function(t){var e=t.hitsPerPage,r=void 0===e?0:e,n=t.totalPages,i=void 0===n?0:n,a=t.estimatedTotalHits,o=t.totalHits;return null!=a?a:null!=o?o:r*i}(t),b=function(t,e,r,n){return t?function(t,e,r){for(var n=function(t){return t?"string"==typeof t?[t]:t:[]}(t),i={},a=0,o=n;a<o.length;a++){var u=o[a];for(var s in e[u])i[u]||(i[u]=r[u]||{}),i[u][s]?i[u][s]=r[u][s]:i[u][s]=0}return i}(e,r,n=n||{}):n}(r.keepZeroFacets,l,e,u);return{index:a,hitsPerPage:d,page:g,facets:b,nbPages:h,nbHits:m,processingTimeMS:n,query:i,hits:y,params:"",exhaustiveNbHits:!1,facets_stats:v(c)}}(t,e[t.indexUid],r)}));return{results:n}}function m(t){return t?t.split(/,(?=\w+:(?:asc|desc))/):[]}function b(t,e,r){return{hitsPerPage:void 0===e?20:e,page:r||0,finite:!!t}}function P(t){var e=t.indexOf(":");return-1===e?{indexUid:t,sortBy:""}:{indexUid:t.substring(0,e),sortBy:t.substring(e+1)}}function x(t,r){var n=t.query,i=t.indexName,a=t.params,o=P(i),u=o.indexUid,s=o.sortBy,c=b(r.finitePagination,null==a?void 0:a.hitsPerPage,null==a?void 0:a.page);return e(e(e(e({},r),{query:n}),a),{sort:m(s),indexUid:u,pagination:c,placeholderSearch:!1!==r.placeholderSearch,keepZeroFacets:!!r.keepZeroFacets})}function S(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(t){return}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,r){e[t]=JSON.stringify(r)},clearCache:function(){e={}}}}function w(t){var r=l(e(e({},t),{placeholderSearch:!0,query:""}));return r.addFacets(),r.addIndexUid(),r.addPagination(),r.getParams()}function T(t,e,i){return r(this,void 0,void 0,(function(){var r,a,o,u,s,c;return n(this,(function(n){switch(n.label){case 0:return l="indexUid",f=[],r=function(t){return!f.includes(t[l])&&(f.push(t[l]),!0)},a=e.filter(r).filter((function(t){var e=t.indexUid;return!Object.keys(i).includes(e)})),0===a.length?[2,i]:[4,t.multiSearch(a,[])];case 1:for(o=n.sent(),u=0,s=o;u<s.length;u++)c=s[u],i[c.indexUid]=c.facetDistribution||{};return[2,i]}var l,f}))}))}"function"==typeof SuppressedError&&SuppressedError;var A;exports.MatchingStrategies=void 0,(A=exports.MatchingStrategies||(exports.MatchingStrategies={})).ALL="all",A.LAST="last",exports.instantMeiliSearch=function(i,o,u){void 0===o&&(o=""),void 0===u&&(u={}),function(t,e,r){var n=r.requestConfig,i=r.httpClient;if("string"!=typeof t)throw new TypeError("Provided hostUrl value (1st parameter) is not a string, expected string");if("string"!=typeof e&&"function"!=typeof e)throw new TypeError("Provided apiKey value (2nd parameter) is not a string or a function, expected string or function");if(void 0!==n&&!a(n))throw new TypeError("Provided requestConfig should be an object");if(i&&"function"!=typeof i)throw new TypeError("Provided custom httpClient should be a function")}(i,o,u);var s={host:i,apiKey:o=function(t){if("function"==typeof t){var e=t();if("string"!=typeof e)throw new TypeError("Provided apiKey function (2nd parameter) did not return a string, expected string");return e}return t}(o),clientAgents:function(t){void 0===t&&(t=[]);var e="Meilisearch instant-meilisearch (v".concat("0.13.6",")");return t.concat(e)}(u.clientAgents)};void 0!==u.httpClient&&(s.httpClient=u.httpClient),void 0!==u.requestConfig&&(s.requestConfig=u.requestConfig);var c,l,d,g=new t.MeiliSearch(s),h=S(),p=(c=g,l=h,{multiSearch:function(t,i){return r(this,void 0,void 0,(function(){var r,a,o,u;return n(this,(function(n){switch(n.label){case 0:return r=l.formatKey([t]),(a=l.getEntry(r))?[2,a]:[4,c.multiSearch({queries:t})];case 1:return o=n.sent(),u=o.results.map((function(t,r){return e(e({},t),{pagination:i[r]||{}})})),l.setEntry(r,u),[2,u]}}))}))}}),v={},A=(d=u,e(e({},{placeholderSearch:!0,keepZeroFacets:!1,clientAgents:[],finitePagination:!1}),d));return{clearCache:function(){return h.clearCache()},search:function(t){return r(this,void 0,void 0,(function(){var r,i,a,o,s,c,l,d,g,h,m;return n(this,(function(n){switch(n.label){case 0:for(n.trys.push([0,3,,4]),r=[],i=[],a=[],o=0,s=t;o<s.length;o++)c=s[o],l=x(c,u),d=f(l),r.push(d),g=w(l),a.push(g),i.push(l.pagination);return[4,T(p,a,v)];case 1:return v=n.sent(),[4,p.multiSearch(r,i)];case 2:return h=n.sent(),v=function(t,r){for(var n=0,i=r;n<i.length;n++){var a=i[n];t[a.indexUid]=e(e({},a.facetDistribution||{}),t[a.indexUid]||{})}return t}(v,h),[2,y(h,v,A)];case 3:throw m=n.sent(),console.error(m),new Error(m);case 4:return[2]}}))}))},searchForFacetValues:function(t){return r(this,void 0,void 0,(function(){var r,i,a,o,s,c,l,d,h,p;return n(this,(function(n){switch(n.label){case 0:r=[],i=0,a=t,n.label=1;case 1:return i<a.length?(o=a[i],s=function(t,r){var n=P(t.indexName),i=n.indexUid,a=n.sortBy,o=t.params,u=b(r.finitePagination,null==o?void 0:o.hitsPerPage,null==o?void 0:o.page);return e(e(e({},r),o),{sort:m(a),indexUid:i,pagination:u,placeholderSearch:!1!==r.placeholderSearch,keepZeroFacets:!!r.keepZeroFacets})}(o,u),c=f(s),delete(l=e(e({},c),{facetQuery:o.params.facetQuery,facetName:o.params.facetName})).indexUid,[4,g.index(s.indexUid).searchForFacetValues(l)]):[3,4];case 2:d=n.sent(),h=d.facetHits.map((function(t){return e(e({},t),{highlighted:t.value})})),p={facetHits:h,exhaustiveFacetsCount:!1,processingTimeMS:d.processingTimeMs},r.push(p),n.label=3;case 3:return i++,[3,1];case 4:return[2,r]}}))}))}}}; | ||
//# sourceMappingURL=instant-meilisearch.cjs.min.js.map |
@@ -925,4 +925,11 @@ import { MeiliSearch } from 'meilisearch'; | ||
} | ||
function fillMissingFacets(initialFacetDistribution, meilisearchResults) { | ||
for (var _i = 0, meilisearchResults_1 = meilisearchResults; _i < meilisearchResults_1.length; _i++) { | ||
var searchResult = meilisearchResults_1[_i]; | ||
initialFacetDistribution[searchResult.indexUid] = __assign(__assign({}, (searchResult.facetDistribution || {})), (initialFacetDistribution[searchResult.indexUid] || {})); | ||
} | ||
return initialFacetDistribution; | ||
} | ||
var PACKAGE_VERSION = '0.13.5'; | ||
var PACKAGE_VERSION = '0.13.6'; | ||
@@ -1000,5 +1007,9 @@ var constructClientAgents = function (clientAgents) { | ||
return [4 /*yield*/, searchResolver.multiSearch(meilisearchRequests, instantSearchPagination // Create issue on pagination | ||
)]; | ||
) | ||
// Fill the missing facet values if keepZeroFacets is true | ||
]; | ||
case 2: | ||
meilisearchResults = _a.sent(); | ||
// Fill the missing facet values if keepZeroFacets is true | ||
initialFacetDistribution = fillMissingFacets(initialFacetDistribution, meilisearchResults); | ||
instantSearchResponse = adaptSearchResults(meilisearchResults, initialFacetDistribution, instantMeilisearchConfig); | ||
@@ -1005,0 +1016,0 @@ return [2 /*return*/, instantSearchResponse]; |
@@ -1,2 +0,2 @@ | ||
import{MeiliSearch as t}from"meilisearch";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},e.apply(this,arguments)};function r(t,e,r,n){return new(r||(r=Promise))((function(i,a){function o(t){try{c(n.next(t))}catch(t){a(t)}}function u(t){try{c(n.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,u)}c((n=n.apply(t,e||[])).next())}))}function n(t,e){var r,n,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(u){return function(c){return function(u){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(o=0)),o;)try{if(r=1,n&&(i=2&u[0]?n.return:u[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,u[1])).done)return i;switch(n=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,n=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(6===u[0]&&o.label<i[1]){o.label=i[1],i=u;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(u);break}i[2]&&o.ops.pop(),o.trys.pop();continue}u=e.call(t,o)}catch(t){u=[6,t],n=0}finally{r=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}}function i(t,e,r){if(r||2===arguments.length)for(var n,i=0,a=e.length;i<a;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}function a(t){return"object"==typeof t&&!Array.isArray(t)&&null!==t}function o(t){return t.replace(/(.*):(.*)/i,'"$1"="$2"')}function u(t){return"string"==typeof t?o(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return o(t)})).filter((function(t){return t})):o(t)})).filter((function(t){return t})):[]}function c(t){return""===t?[]:"string"==typeof t?[t]:t}function s(t,e,r){return function(t,e,r){var n=r.trim(),a=c(t),o=c(e);return i(i(i([],a,!0),o,!0),[n],!1).filter((function(t){return Array.isArray(t)?t.length:t}))}(u(r||[]),u(e||[]),t||"")}function f(t){var e={},r=t.facets,n=t.attributesToSnippet,i=t.snippetEllipsisText,a=t.attributesToRetrieve,o=t.attributesToHighlight,u=t.highlightPreTag,c=t.highlightPostTag,f=t.placeholderSearch,l=t.query,d=t.sort,g=t.pagination,h=t.matchingStrategy,p=t.filters,v=t.numericFilters,y=t.facetFilters,m=t.indexUid,P=s(p,v,y);return{getParams:function(){return e},addQuery:function(){e.q=l},addIndexUid:function(){e.indexUid=m},addFacets:function(){Array.isArray(r)?e.facets=r:"string"==typeof r&&(e.facets=[r])},addAttributesToCrop:function(){n&&(e.attributesToCrop=n)},addCropMarker:function(){null!=i&&(e.cropMarker=i)},addAttributesToRetrieve:function(){a&&(e.attributesToRetrieve=a)},addFilters:function(){P.length&&(e.filter=P)},addAttributesToHighlight:function(){e.attributesToHighlight=o||["*"]},addPreTag:function(){e.highlightPreTag=u||"__ais-highlight__"},addPostTag:function(){e.highlightPostTag=c||"__/ais-highlight__"},addPagination:function(){var t=function(t,e,r){return!!(r||e||t&&0!==t.length)}(P,l,f);if(g.finite){var r=function(t,e){var r=t.page,n=t.hitsPerPage;return e?{hitsPerPage:n,page:r+1}:{hitsPerPage:0,page:r+1}}(g,t),n=r.hitsPerPage,i=r.page;e.hitsPerPage=n,e.page=i}else{var a=function(t,e){var r=t.page,n=t.hitsPerPage;return e?{limit:n+1,offset:r*n}:{limit:0,offset:0}}(g,t),o=a.limit,u=a.offset;e.limit=o,e.offset=u}},addSort:function(){(null==d?void 0:d.length)&&(e.sort=Array.isArray(d)?d:[d])},addGeoSearchFilter:function(){var r=function(t){var e,r,n,i=t.insideBoundingBox,a=t.aroundLatLng,o=t.aroundRadius,u=t.minimumAroundRadius;if(a){var c=a.split(",").map((function(t){return Number.parseFloat(t).toFixed(5)}));e=[h=c[0],p=c[1]]}if(null==o&&null==u||("all"===o?console.warn("instant-meilisearch is not compatible with the `all` value on the aroundRadius parameter"):r=null!=o?o:u),i&&"string"==typeof i){var s=i.split(",").map((function(t){return parseFloat(t)})),f=s[0],l=s[1],d=s[2],g=s[3];n="_geoBoundingBox([".concat(f,", ").concat(l,"], [").concat(d,", ").concat(g,"])")}else if(null!=e&&null!=r){var h=e[0],p=e[1];n="_geoRadius(".concat(h,", ").concat(p,", ").concat(r,")")}return n}({insideBoundingBox:t.insideBoundingBox,aroundLatLng:t.aroundLatLng,aroundRadius:t.aroundRadius,minimumAroundRadius:t.minimumAroundRadius});r&&(e.filter?e.filter.unshift(r):e.filter=[r])},addMatchingStrategy:function(){h&&(e.matchingStrategy=h)}}}function l(t){var e=f(t);return e.addQuery(),e.addIndexUid(),e.addFacets(),e.addAttributesToHighlight(),e.addPreTag(),e.addPostTag(),e.addAttributesToRetrieve(),e.addAttributesToCrop(),e.addCropMarker(),e.addPagination(),e.addFilters(),e.addSort(),e.addGeoSearchFilter(),e.addMatchingStrategy(),e.getParams()}function d(t){return"string"==typeof t?t:void 0===t?JSON.stringify(null):JSON.stringify(t)}function g(t){return Array.isArray(t)?t.map((function(t){return g(t)})):a(t)?Object.keys(t).reduce((function(e,r){return e[r]=g(t[r]),e}),{}):{value:d(t)}}function h(t){if(!t)return{};var e=g(t);return{_highlightResult:e,_snippetResult:e}}function p(t,e){var r=t.hits,n=t.pagination.hitsPerPage,i=e.finitePagination,a=e.primaryKey;!i&&r.length>n&&r.splice(r.length-1,1);var o=r.map((function(t){if(Object.keys(t).length>0){var e=t._formatted;t._matchesPosition;var r=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r}(t,["_formatted","_matchesPosition"]),n=Object.assign(r,h(e));return a&&(n.objectID=t[a]),n}return t}));return o=function(t){for(var e,r=0;r<t.length;r++){var n="".concat(r+1e6*Math.random());t[r]._geo&&(t[r]._geoloc=t[r]._geo,t[r].objectID=n),(null===(e=t[r]._formatted)||void 0===e?void 0:e._geo)&&(t[r]._formatted._geoloc=t[r]._formatted._geo,t[r]._formatted.objectID=n)}return t}(o),o}function v(t){return Object.keys(t).reduce((function(r,n){return r[n]=e(e({},t[n]),{avg:0,sum:0}),r}),{})}function y(t,e,r){var n=t.map((function(t){return function(t,e,r){var n=t.processingTimeMs,i=t.query,a=t.indexUid,o=t.facetDistribution,u=void 0===o?{}:o,c=t.facetStats,s=void 0===c?{}:c,f=Object.keys(u),l=function(t,e){var r=e.hitsPerPage,n=e.page,i=function(t,e){if(null!=t.totalPages)return t.totalPages;if(0===e)return 0;var r=t.limit,n=void 0===r?20:r,i=t.offset;return(void 0===i?0:i)/e+1+(t.hits.length>=n?1:0)}(t,r);return{page:n,nbPages:i,hitsPerPage:r}}(t,t.pagination),d=l.hitsPerPage,g=l.page,h=l.nbPages,y=p(t,r),m=function(t){var e=t.hitsPerPage,r=void 0===e?0:e,n=t.totalPages,i=void 0===n?0:n,a=t.estimatedTotalHits,o=t.totalHits;return null!=a?a:null!=o?o:r*i}(t),P=function(t,e,r,n){return t?function(t,e,r){for(var n=function(t){return t?"string"==typeof t?[t]:t:[]}(t),i={},a=0,o=n;a<o.length;a++){var u=o[a];for(var c in e[u])i[u]||(i[u]=r[u]||{}),i[u][c]?i[u][c]=r[u][c]:i[u][c]=0}return i}(e,r,n=n||{}):n}(r.keepZeroFacets,f,e,u);return{index:a,hitsPerPage:d,page:g,facets:P,nbPages:h,nbHits:m,processingTimeMS:n,query:i,hits:y,params:"",exhaustiveNbHits:!1,facets_stats:v(s)}}(t,e[t.indexUid],r)}));return{results:n}}function m(t){return t?t.split(/,(?=\w+:(?:asc|desc))/):[]}function P(t,e,r){return{hitsPerPage:void 0===e?20:e,page:r||0,finite:!!t}}function b(t){var e=t.indexOf(":");return-1===e?{indexUid:t,sortBy:""}:{indexUid:t.substring(0,e),sortBy:t.substring(e+1)}}function x(t,r){var n=t.query,i=t.indexName,a=t.params,o=b(i),u=o.indexUid,c=o.sortBy,s=P(r.finitePagination,null==a?void 0:a.hitsPerPage,null==a?void 0:a.page);return e(e(e(e({},r),{query:n}),a),{sort:m(c),indexUid:u,pagination:s,placeholderSearch:!1!==r.placeholderSearch,keepZeroFacets:!!r.keepZeroFacets})}function S(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(t){return}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,r){e[t]=JSON.stringify(r)},clearCache:function(){e={}}}}function w(t){var r=f(e(e({},t),{placeholderSearch:!0,query:""}));return r.addFacets(),r.addIndexUid(),r.addPagination(),r.getParams()}function T(t,e,i){return r(this,void 0,void 0,(function(){var r,a,o,u,c,s;return n(this,(function(n){switch(n.label){case 0:return f="indexUid",l=[],r=function(t){return!l.includes(t[f])&&(l.push(t[f]),!0)},a=e.filter(r).filter((function(t){var e=t.indexUid;return!Object.keys(i).includes(e)})),0===a.length?[2,i]:[4,t.multiSearch(a,[])];case 1:for(o=n.sent(),u=0,c=o;u<c.length;u++)s=c[u],i[s.indexUid]=s.facetDistribution||{};return[2,i]}var f,l}))}))}"function"==typeof SuppressedError&&SuppressedError;var A;function _(i,o,u){void 0===o&&(o=""),void 0===u&&(u={}),function(t,e,r){var n=r.requestConfig,i=r.httpClient;if("string"!=typeof t)throw new TypeError("Provided hostUrl value (1st parameter) is not a string, expected string");if("string"!=typeof e&&"function"!=typeof e)throw new TypeError("Provided apiKey value (2nd parameter) is not a string or a function, expected string or function");if(void 0!==n&&!a(n))throw new TypeError("Provided requestConfig should be an object");if(i&&"function"!=typeof i)throw new TypeError("Provided custom httpClient should be a function")}(i,o,u);var c={host:i,apiKey:o=function(t){if("function"==typeof t){var e=t();if("string"!=typeof e)throw new TypeError("Provided apiKey function (2nd parameter) did not return a string, expected string");return e}return t}(o),clientAgents:function(t){void 0===t&&(t=[]);var e="Meilisearch instant-meilisearch (v".concat("0.13.5",")");return t.concat(e)}(u.clientAgents)};void 0!==u.httpClient&&(c.httpClient=u.httpClient),void 0!==u.requestConfig&&(c.requestConfig=u.requestConfig);var s,f,d,g=new t(c),h=S(),p=(s=g,f=h,{multiSearch:function(t,i){return r(this,void 0,void 0,(function(){var r,a,o,u;return n(this,(function(n){switch(n.label){case 0:return r=f.formatKey([t]),(a=f.getEntry(r))?[2,a]:[4,s.multiSearch({queries:t})];case 1:return o=n.sent(),u=o.results.map((function(t,r){return e(e({},t),{pagination:i[r]||{}})})),f.setEntry(r,u),[2,u]}}))}))}}),v={},A=(d=u,e(e({},{placeholderSearch:!0,keepZeroFacets:!1,clientAgents:[],finitePagination:!1}),d));return{clearCache:function(){return h.clearCache()},search:function(t){return r(this,void 0,void 0,(function(){var e,r,i,a,o,c,s,f,d,g,h;return n(this,(function(n){switch(n.label){case 0:for(n.trys.push([0,3,,4]),e=[],r=[],i=[],a=0,o=t;a<o.length;a++)c=o[a],s=x(c,u),f=l(s),e.push(f),d=w(s),i.push(d),r.push(s.pagination);return[4,T(p,i,v)];case 1:return v=n.sent(),[4,p.multiSearch(e,r)];case 2:return g=n.sent(),[2,y(g,v,A)];case 3:throw h=n.sent(),console.error(h),new Error(h);case 4:return[2]}}))}))},searchForFacetValues:function(t){return r(this,void 0,void 0,(function(){var r,i,a,o,c,s,f,d,h,p;return n(this,(function(n){switch(n.label){case 0:r=[],i=0,a=t,n.label=1;case 1:return i<a.length?(o=a[i],c=function(t,r){var n=b(t.indexName),i=n.indexUid,a=n.sortBy,o=t.params,u=P(r.finitePagination,null==o?void 0:o.hitsPerPage,null==o?void 0:o.page);return e(e(e({},r),o),{sort:m(a),indexUid:i,pagination:u,placeholderSearch:!1!==r.placeholderSearch,keepZeroFacets:!!r.keepZeroFacets})}(o,u),s=l(c),delete(f=e(e({},s),{facetQuery:o.params.facetQuery,facetName:o.params.facetName})).indexUid,[4,g.index(c.indexUid).searchForFacetValues(f)]):[3,4];case 2:d=n.sent(),h=d.facetHits.map((function(t){return e(e({},t),{highlighted:t.value})})),p={facetHits:h,exhaustiveFacetsCount:!1,processingTimeMS:d.processingTimeMs},r.push(p),n.label=3;case 3:return i++,[3,1];case 4:return[2,r]}}))}))}}}!function(t){t.ALL="all",t.LAST="last"}(A||(A={}));export{A as MatchingStrategies,_ as instantMeiliSearch}; | ||
import{MeiliSearch as t}from"meilisearch";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},e.apply(this,arguments)};function r(t,e,r,n){return new(r||(r=Promise))((function(i,a){function o(t){try{c(n.next(t))}catch(t){a(t)}}function u(t){try{c(n.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,u)}c((n=n.apply(t,e||[])).next())}))}function n(t,e){var r,n,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(u){return function(c){return function(u){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(o=0)),o;)try{if(r=1,n&&(i=2&u[0]?n.return:u[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,u[1])).done)return i;switch(n=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,n=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(6===u[0]&&o.label<i[1]){o.label=i[1],i=u;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(u);break}i[2]&&o.ops.pop(),o.trys.pop();continue}u=e.call(t,o)}catch(t){u=[6,t],n=0}finally{r=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}}function i(t,e,r){if(r||2===arguments.length)for(var n,i=0,a=e.length;i<a;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}function a(t){return"object"==typeof t&&!Array.isArray(t)&&null!==t}function o(t){return t.replace(/(.*):(.*)/i,'"$1"="$2"')}function u(t){return"string"==typeof t?o(t):Array.isArray(t)?t.map((function(t){return Array.isArray(t)?t.map((function(t){return o(t)})).filter((function(t){return t})):o(t)})).filter((function(t){return t})):[]}function c(t){return""===t?[]:"string"==typeof t?[t]:t}function s(t,e,r){return function(t,e,r){var n=r.trim(),a=c(t),o=c(e);return i(i(i([],a,!0),o,!0),[n],!1).filter((function(t){return Array.isArray(t)?t.length:t}))}(u(r||[]),u(e||[]),t||"")}function f(t){var e={},r=t.facets,n=t.attributesToSnippet,i=t.snippetEllipsisText,a=t.attributesToRetrieve,o=t.attributesToHighlight,u=t.highlightPreTag,c=t.highlightPostTag,f=t.placeholderSearch,l=t.query,d=t.sort,g=t.pagination,h=t.matchingStrategy,p=t.filters,v=t.numericFilters,y=t.facetFilters,m=t.indexUid,b=s(p,v,y);return{getParams:function(){return e},addQuery:function(){e.q=l},addIndexUid:function(){e.indexUid=m},addFacets:function(){Array.isArray(r)?e.facets=r:"string"==typeof r&&(e.facets=[r])},addAttributesToCrop:function(){n&&(e.attributesToCrop=n)},addCropMarker:function(){null!=i&&(e.cropMarker=i)},addAttributesToRetrieve:function(){a&&(e.attributesToRetrieve=a)},addFilters:function(){b.length&&(e.filter=b)},addAttributesToHighlight:function(){e.attributesToHighlight=o||["*"]},addPreTag:function(){e.highlightPreTag=u||"__ais-highlight__"},addPostTag:function(){e.highlightPostTag=c||"__/ais-highlight__"},addPagination:function(){var t=function(t,e,r){return!!(r||e||t&&0!==t.length)}(b,l,f);if(g.finite){var r=function(t,e){var r=t.page,n=t.hitsPerPage;return e?{hitsPerPage:n,page:r+1}:{hitsPerPage:0,page:r+1}}(g,t),n=r.hitsPerPage,i=r.page;e.hitsPerPage=n,e.page=i}else{var a=function(t,e){var r=t.page,n=t.hitsPerPage;return e?{limit:n+1,offset:r*n}:{limit:0,offset:0}}(g,t),o=a.limit,u=a.offset;e.limit=o,e.offset=u}},addSort:function(){(null==d?void 0:d.length)&&(e.sort=Array.isArray(d)?d:[d])},addGeoSearchFilter:function(){var r=function(t){var e,r,n,i=t.insideBoundingBox,a=t.aroundLatLng,o=t.aroundRadius,u=t.minimumAroundRadius;if(a){var c=a.split(",").map((function(t){return Number.parseFloat(t).toFixed(5)}));e=[h=c[0],p=c[1]]}if(null==o&&null==u||("all"===o?console.warn("instant-meilisearch is not compatible with the `all` value on the aroundRadius parameter"):r=null!=o?o:u),i&&"string"==typeof i){var s=i.split(",").map((function(t){return parseFloat(t)})),f=s[0],l=s[1],d=s[2],g=s[3];n="_geoBoundingBox([".concat(f,", ").concat(l,"], [").concat(d,", ").concat(g,"])")}else if(null!=e&&null!=r){var h=e[0],p=e[1];n="_geoRadius(".concat(h,", ").concat(p,", ").concat(r,")")}return n}({insideBoundingBox:t.insideBoundingBox,aroundLatLng:t.aroundLatLng,aroundRadius:t.aroundRadius,minimumAroundRadius:t.minimumAroundRadius});r&&(e.filter?e.filter.unshift(r):e.filter=[r])},addMatchingStrategy:function(){h&&(e.matchingStrategy=h)}}}function l(t){var e=f(t);return e.addQuery(),e.addIndexUid(),e.addFacets(),e.addAttributesToHighlight(),e.addPreTag(),e.addPostTag(),e.addAttributesToRetrieve(),e.addAttributesToCrop(),e.addCropMarker(),e.addPagination(),e.addFilters(),e.addSort(),e.addGeoSearchFilter(),e.addMatchingStrategy(),e.getParams()}function d(t){return"string"==typeof t?t:void 0===t?JSON.stringify(null):JSON.stringify(t)}function g(t){return Array.isArray(t)?t.map((function(t){return g(t)})):a(t)?Object.keys(t).reduce((function(e,r){return e[r]=g(t[r]),e}),{}):{value:d(t)}}function h(t){if(!t)return{};var e=g(t);return{_highlightResult:e,_snippetResult:e}}function p(t,e){var r=t.hits,n=t.pagination.hitsPerPage,i=e.finitePagination,a=e.primaryKey;!i&&r.length>n&&r.splice(r.length-1,1);var o=r.map((function(t){if(Object.keys(t).length>0){var e=t._formatted;t._matchesPosition;var r=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r}(t,["_formatted","_matchesPosition"]),n=Object.assign(r,h(e));return a&&(n.objectID=t[a]),n}return t}));return o=function(t){for(var e,r=0;r<t.length;r++){var n="".concat(r+1e6*Math.random());t[r]._geo&&(t[r]._geoloc=t[r]._geo,t[r].objectID=n),(null===(e=t[r]._formatted)||void 0===e?void 0:e._geo)&&(t[r]._formatted._geoloc=t[r]._formatted._geo,t[r]._formatted.objectID=n)}return t}(o),o}function v(t){return Object.keys(t).reduce((function(r,n){return r[n]=e(e({},t[n]),{avg:0,sum:0}),r}),{})}function y(t,e,r){var n=t.map((function(t){return function(t,e,r){var n=t.processingTimeMs,i=t.query,a=t.indexUid,o=t.facetDistribution,u=void 0===o?{}:o,c=t.facetStats,s=void 0===c?{}:c,f=Object.keys(u),l=function(t,e){var r=e.hitsPerPage,n=e.page,i=function(t,e){if(null!=t.totalPages)return t.totalPages;if(0===e)return 0;var r=t.limit,n=void 0===r?20:r,i=t.offset;return(void 0===i?0:i)/e+1+(t.hits.length>=n?1:0)}(t,r);return{page:n,nbPages:i,hitsPerPage:r}}(t,t.pagination),d=l.hitsPerPage,g=l.page,h=l.nbPages,y=p(t,r),m=function(t){var e=t.hitsPerPage,r=void 0===e?0:e,n=t.totalPages,i=void 0===n?0:n,a=t.estimatedTotalHits,o=t.totalHits;return null!=a?a:null!=o?o:r*i}(t),b=function(t,e,r,n){return t?function(t,e,r){for(var n=function(t){return t?"string"==typeof t?[t]:t:[]}(t),i={},a=0,o=n;a<o.length;a++){var u=o[a];for(var c in e[u])i[u]||(i[u]=r[u]||{}),i[u][c]?i[u][c]=r[u][c]:i[u][c]=0}return i}(e,r,n=n||{}):n}(r.keepZeroFacets,f,e,u);return{index:a,hitsPerPage:d,page:g,facets:b,nbPages:h,nbHits:m,processingTimeMS:n,query:i,hits:y,params:"",exhaustiveNbHits:!1,facets_stats:v(s)}}(t,e[t.indexUid],r)}));return{results:n}}function m(t){return t?t.split(/,(?=\w+:(?:asc|desc))/):[]}function b(t,e,r){return{hitsPerPage:void 0===e?20:e,page:r||0,finite:!!t}}function P(t){var e=t.indexOf(":");return-1===e?{indexUid:t,sortBy:""}:{indexUid:t.substring(0,e),sortBy:t.substring(e+1)}}function x(t,r){var n=t.query,i=t.indexName,a=t.params,o=P(i),u=o.indexUid,c=o.sortBy,s=b(r.finitePagination,null==a?void 0:a.hitsPerPage,null==a?void 0:a.page);return e(e(e(e({},r),{query:n}),a),{sort:m(c),indexUid:u,pagination:s,placeholderSearch:!1!==r.placeholderSearch,keepZeroFacets:!!r.keepZeroFacets})}function S(t){void 0===t&&(t={});var e=t;return{getEntry:function(t){if(e[t])try{return JSON.parse(e[t])}catch(t){return}},formatKey:function(t){return t.reduce((function(t,e){return t+JSON.stringify(e)}),"")},setEntry:function(t,r){e[t]=JSON.stringify(r)},clearCache:function(){e={}}}}function w(t){var r=f(e(e({},t),{placeholderSearch:!0,query:""}));return r.addFacets(),r.addIndexUid(),r.addPagination(),r.getParams()}function T(t,e,i){return r(this,void 0,void 0,(function(){var r,a,o,u,c,s;return n(this,(function(n){switch(n.label){case 0:return f="indexUid",l=[],r=function(t){return!l.includes(t[f])&&(l.push(t[f]),!0)},a=e.filter(r).filter((function(t){var e=t.indexUid;return!Object.keys(i).includes(e)})),0===a.length?[2,i]:[4,t.multiSearch(a,[])];case 1:for(o=n.sent(),u=0,c=o;u<c.length;u++)s=c[u],i[s.indexUid]=s.facetDistribution||{};return[2,i]}var f,l}))}))}"function"==typeof SuppressedError&&SuppressedError;var A;function _(i,o,u){void 0===o&&(o=""),void 0===u&&(u={}),function(t,e,r){var n=r.requestConfig,i=r.httpClient;if("string"!=typeof t)throw new TypeError("Provided hostUrl value (1st parameter) is not a string, expected string");if("string"!=typeof e&&"function"!=typeof e)throw new TypeError("Provided apiKey value (2nd parameter) is not a string or a function, expected string or function");if(void 0!==n&&!a(n))throw new TypeError("Provided requestConfig should be an object");if(i&&"function"!=typeof i)throw new TypeError("Provided custom httpClient should be a function")}(i,o,u);var c={host:i,apiKey:o=function(t){if("function"==typeof t){var e=t();if("string"!=typeof e)throw new TypeError("Provided apiKey function (2nd parameter) did not return a string, expected string");return e}return t}(o),clientAgents:function(t){void 0===t&&(t=[]);var e="Meilisearch instant-meilisearch (v".concat("0.13.6",")");return t.concat(e)}(u.clientAgents)};void 0!==u.httpClient&&(c.httpClient=u.httpClient),void 0!==u.requestConfig&&(c.requestConfig=u.requestConfig);var s,f,d,g=new t(c),h=S(),p=(s=g,f=h,{multiSearch:function(t,i){return r(this,void 0,void 0,(function(){var r,a,o,u;return n(this,(function(n){switch(n.label){case 0:return r=f.formatKey([t]),(a=f.getEntry(r))?[2,a]:[4,s.multiSearch({queries:t})];case 1:return o=n.sent(),u=o.results.map((function(t,r){return e(e({},t),{pagination:i[r]||{}})})),f.setEntry(r,u),[2,u]}}))}))}}),v={},A=(d=u,e(e({},{placeholderSearch:!0,keepZeroFacets:!1,clientAgents:[],finitePagination:!1}),d));return{clearCache:function(){return h.clearCache()},search:function(t){return r(this,void 0,void 0,(function(){var r,i,a,o,c,s,f,d,g,h,m;return n(this,(function(n){switch(n.label){case 0:for(n.trys.push([0,3,,4]),r=[],i=[],a=[],o=0,c=t;o<c.length;o++)s=c[o],f=x(s,u),d=l(f),r.push(d),g=w(f),a.push(g),i.push(f.pagination);return[4,T(p,a,v)];case 1:return v=n.sent(),[4,p.multiSearch(r,i)];case 2:return h=n.sent(),v=function(t,r){for(var n=0,i=r;n<i.length;n++){var a=i[n];t[a.indexUid]=e(e({},a.facetDistribution||{}),t[a.indexUid]||{})}return t}(v,h),[2,y(h,v,A)];case 3:throw m=n.sent(),console.error(m),new Error(m);case 4:return[2]}}))}))},searchForFacetValues:function(t){return r(this,void 0,void 0,(function(){var r,i,a,o,c,s,f,d,h,p;return n(this,(function(n){switch(n.label){case 0:r=[],i=0,a=t,n.label=1;case 1:return i<a.length?(o=a[i],c=function(t,r){var n=P(t.indexName),i=n.indexUid,a=n.sortBy,o=t.params,u=b(r.finitePagination,null==o?void 0:o.hitsPerPage,null==o?void 0:o.page);return e(e(e({},r),o),{sort:m(a),indexUid:i,pagination:u,placeholderSearch:!1!==r.placeholderSearch,keepZeroFacets:!!r.keepZeroFacets})}(o,u),s=l(c),delete(f=e(e({},s),{facetQuery:o.params.facetQuery,facetName:o.params.facetName})).indexUid,[4,g.index(c.indexUid).searchForFacetValues(f)]):[3,4];case 2:d=n.sent(),h=d.facetHits.map((function(t){return e(e({},t),{highlighted:t.value})})),p={facetHits:h,exhaustiveFacetsCount:!1,processingTimeMS:d.processingTimeMs},r.push(p),n.label=3;case 3:return i++,[3,1];case 4:return[2,r]}}))}))}}}!function(t){t.ALL="all",t.LAST="last"}(A||(A={}));export{A as MatchingStrategies,_ as instantMeiliSearch}; | ||
//# sourceMappingURL=instant-meilisearch.esm.min.js.map |
@@ -1,4 +0,5 @@ | ||
import { FacetDistribution, SearchContext, MeiliSearchMultiSearchParams, MultiSearchResolver } from '../types'; | ||
import { FacetDistribution, SearchContext, MeiliSearchMultiSearchParams, MultiSearchResolver, MeilisearchMultiSearchResult } from '../types'; | ||
export declare function getParametersWithoutFilters(searchContext: SearchContext): MeiliSearchMultiSearchParams; | ||
export declare function initFacetDistribution(searchResolver: MultiSearchResolver, queries: MeiliSearchMultiSearchParams[], initialFacetDistribution: Record<string, FacetDistribution>): Promise<Record<string, FacetDistribution>>; | ||
export declare function fillMissingFacets(initialFacetDistribution: Record<string, FacetDistribution>, meilisearchResults: MeilisearchMultiSearchResult[]): Record<string, FacetDistribution>; | ||
//# sourceMappingURL=init-facets-distribution.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export declare const PACKAGE_VERSION = "0.13.5"; | ||
export declare const PACKAGE_VERSION = "0.13.6"; | ||
//# sourceMappingURL=package-version.d.ts.map |
{ | ||
"name": "@meilisearch/instant-meilisearch", | ||
"version": "0.13.5", | ||
"version": "0.13.6", | ||
"private": false, | ||
@@ -53,3 +53,3 @@ "description": "The search client to use Meilisearch with InstantSearch.", | ||
"dependencies": { | ||
"meilisearch": "^0.34.0" | ||
"meilisearch": "^0.35.0" | ||
}, | ||
@@ -56,0 +56,0 @@ "devDependencies": { |
@@ -6,2 +6,3 @@ import { | ||
MultiSearchResolver, | ||
MeilisearchMultiSearchResult, | ||
} from '../types' | ||
@@ -57,1 +58,14 @@ import { MeiliParamsCreator } from '../adapter' | ||
} | ||
export function fillMissingFacets( | ||
initialFacetDistribution: Record<string, FacetDistribution>, | ||
meilisearchResults: MeilisearchMultiSearchResult[] | ||
) { | ||
for (const searchResult of meilisearchResults) { | ||
initialFacetDistribution[searchResult.indexUid] = { | ||
...(searchResult.facetDistribution || {}), | ||
...(initialFacetDistribution[searchResult.indexUid] || {}), | ||
} | ||
} | ||
return initialFacetDistribution | ||
} |
@@ -29,2 +29,3 @@ import { MeiliSearch } from 'meilisearch' | ||
getParametersWithoutFilters, | ||
fillMissingFacets, | ||
} from '../cache/' | ||
@@ -126,2 +127,8 @@ import { constructClientAgents } from './agents' | ||
// Fill the missing facet values if keepZeroFacets is true | ||
initialFacetDistribution = fillMissingFacets( | ||
initialFacetDistribution, | ||
meilisearchResults | ||
) | ||
const instantSearchResponse = adaptSearchResults<T>( | ||
@@ -128,0 +135,0 @@ meilisearchResults, |
@@ -1,1 +0,1 @@ | ||
export const PACKAGE_VERSION = '0.13.5' | ||
export const PACKAGE_VERSION = '0.13.6' |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
830371
130
10642
+ Addedmeilisearch@0.35.1(transitive)
- Removedmeilisearch@0.34.2(transitive)
Updatedmeilisearch@^0.35.0