@appbaseio/searchbase
Advanced tools
Comparing version 1.0.1-alpha.5 to 1.1.0-alpha.0
@@ -307,3 +307,3 @@ 'use strict'; | ||
if (this.raw && this.raw.hits) { | ||
return this.raw.hits.hidden; | ||
return this.raw.hits.hidden || 0; | ||
} | ||
@@ -342,2 +342,13 @@ | ||
return []; | ||
} // object of custom data applied through queryRules | ||
// only works when `enableAppbase=true` | ||
}, { | ||
key: "customData", | ||
get: function get() { | ||
if (this.raw && this.raw.customData) { | ||
return this.raw.customData || {}; | ||
} | ||
return {}; | ||
} | ||
@@ -467,2 +478,3 @@ }]); | ||
// es url | ||
// use rs v3 api | ||
// auth credentials if any | ||
@@ -507,2 +519,3 @@ // to enable the recording of analytics | ||
url = _ref.url, | ||
enableAppbase = _ref.enableAppbase, | ||
credentials = _ref.credentials, | ||
@@ -519,3 +532,3 @@ analytics = _ref.analytics, | ||
from = _ref.from, | ||
_dataField = _ref.dataField, | ||
dataField = _ref.dataField, | ||
aggregationField = _ref.aggregationField, | ||
@@ -540,2 +553,4 @@ includeFields = _ref.includeFields, | ||
_defineProperty(this, "enableAppbase", void 0); | ||
_defineProperty(this, "credentials", void 0); | ||
@@ -649,5 +664,8 @@ | ||
var prevStatus = _this._micStatus; | ||
window.SpeechRecognition = window.webkitSpeechRecognition || window.SpeechRecognition || null; | ||
if (window.SpeechRecognition && prevStatus !== MIC_STATUS.denied) { | ||
if (typeof window !== 'undefined') { | ||
window.SpeechRecognition = window.webkitSpeechRecognition || window.SpeechRecognition || null; | ||
} | ||
if (window && window.SpeechRecognition && prevStatus !== MIC_STATUS.denied) { | ||
if (prevStatus === MIC_STATUS.active) { | ||
@@ -735,16 +753,4 @@ _this._setMicStatus(MIC_STATUS.inactive, options); | ||
_defineProperty(this, "_parseSuggestions", function (suggestions) { | ||
var fields = []; | ||
var fields = _this.getDataFields(); | ||
if (_this.dataField === 'string') { | ||
fields = [_this.dataField]; | ||
} else if (Array.isArray(_this.dataField)) { | ||
_this.dataField.forEach(function (dataField) { | ||
if (typeof dataField === 'object') { | ||
fields.push(dataField.field); | ||
} else { | ||
fields.push(dataField); | ||
} | ||
}); | ||
} | ||
return getSuggestions(fields, suggestions, _this.value).slice(0, _this.size); | ||
@@ -761,3 +767,3 @@ }); | ||
if (!_dataField) { | ||
if (!dataField) { | ||
throw new Error('Please provide a valid data field.'); | ||
@@ -768,2 +774,3 @@ } | ||
this.url = url; | ||
this.enableAppbase = enableAppbase || false; | ||
this.analytics = analytics || false; | ||
@@ -779,6 +786,6 @@ | ||
this.dataField = _dataField; | ||
this.dataField = dataField; | ||
this.aggregationField = aggregationField; | ||
this.credentials = credentials || ''; | ||
this.nestedField = nestedField || ''; | ||
this.nestedField = nestedField; | ||
this.queryFormat = queryFormat || 'or'; | ||
@@ -789,7 +796,7 @@ this.fuzziness = fuzziness || 0; | ||
this.from = Number(from) || 0; | ||
this.sortBy = sortBy || ''; | ||
this.sortBy = sortBy; | ||
this.includeFields = includeFields || ['*']; | ||
this.excludeFields = excludeFields || []; | ||
this.sortOptions = sortOptions || null; | ||
this.sortByField = sortByField || ''; | ||
this.sortByField = sortByField; | ||
this.highlight = highlight; | ||
@@ -1061,4 +1068,6 @@ this.highlightField = highlightField; | ||
var prev = _this3.results; | ||
var rawResults = results; | ||
if (_this3.enableAppbase) rawResults = results.SearchResult; | ||
_this3.results.setRaw(results); | ||
_this3.results.setRaw(rawResults); | ||
@@ -1069,3 +1078,3 @@ _this3._applyOptions({ | ||
return Promise.resolve(results); | ||
return Promise.resolve(rawResults); | ||
})["catch"](handleError); | ||
@@ -1107,4 +1116,7 @@ })["catch"](handleError); | ||
if (suggestions.aggregations) { | ||
_this4._handleCompositeAggsResponse(_this4.aggregationField, suggestions.aggregations, options); | ||
var rawSuggestions = suggestions; | ||
if (_this4.enableAppbase) rawSuggestions = suggestions.DataSearch; | ||
if (rawSuggestions.aggregations) { | ||
_this4._handleCompositeAggsResponse(_this4.aggregationField, rawSuggestions.aggregations, options); | ||
} | ||
@@ -1114,3 +1126,3 @@ | ||
_this4.suggestions.setRaw(suggestions); | ||
_this4.suggestions.setRaw(rawSuggestions); | ||
@@ -1121,3 +1133,3 @@ _this4._applyOptions({ | ||
return Promise.resolve(suggestions); | ||
return Promise.resolve(rawSuggestions); | ||
})["catch"](handleError); | ||
@@ -1179,3 +1191,5 @@ })["catch"](handleError); | ||
var timestamp = Date.now(); | ||
return fetch(_this5.url + "/" + _this5.index + "/_search", finalRequestOptions).then(function (res) { | ||
var suffix = '_search'; | ||
if (_this5.enableAppbase) suffix = '_reactivesearch.v3'; | ||
return fetch(_this5.url + "/" + _this5.index + "/" + suffix, finalRequestOptions).then(function (res) { | ||
var responseHeaders = res.headers; // set search id | ||
@@ -1268,2 +1282,41 @@ | ||
_proto._updateQuery = function _updateQuery(query, queryOptions) { | ||
var prevQuery; | ||
if (this.enableAppbase) { | ||
prevQuery = _extends({}, this._query); | ||
this._query = { | ||
query: [_extends({}, this.getAppbaseSuggestionsQuery(), { | ||
execute: false | ||
}), this.getAppbaseResultQuery()], | ||
settings: this.getAppbaseSettings() | ||
}; | ||
} else prevQuery = this.getPreviousQuery(query, queryOptions); | ||
this._applyOptions({ | ||
stateChanges: false | ||
}, 'query', prevQuery, this._query); | ||
}; | ||
_proto.getAppbaseSettings = function getAppbaseSettings() { | ||
return { | ||
recordAnalytics: this.analytics | ||
}; | ||
}; | ||
_proto.getAppbaseResultQuery = function getAppbaseResultQuery() { | ||
return { | ||
id: 'SearchResult', | ||
dataField: this.getDataFields(), | ||
from: this.from, | ||
size: this.size, | ||
sortBy: this.sortBy, | ||
includeFields: this.includeFields, | ||
excludeFields: this.excludeFields, | ||
react: { | ||
and: 'DataSearch' | ||
} | ||
}; | ||
}; | ||
_proto.getPreviousQuery = function getPreviousQuery(query, queryOptions) { | ||
// Set default query here | ||
@@ -1297,13 +1350,46 @@ var finalQueryOptions = Searchbase.generateQueryOptions({ | ||
}, Searchbase.highlightQuery(this.highlight, this.highlightField, this.dataField), {}, finalQueryOptions, {}, queryOptions); | ||
return prevQuery; | ||
}; | ||
_proto._updateSuggestionsQuery = function _updateSuggestionsQuery(query, queryOptions) { | ||
var prevQuery; | ||
if (this.enableAppbase) { | ||
prevQuery = _extends({}, this._suggestionsQuery); | ||
this._suggestionsQuery = { | ||
query: [this.getAppbaseSuggestionsQuery()], | ||
settings: this.getAppbaseSettings() | ||
}; | ||
} else prevQuery = this.getPreviousSuggestionsQuery(query, queryOptions); | ||
this._applyOptions({ | ||
stateChanges: false | ||
}, 'query', prevQuery, this._query); | ||
}, 'suggestionsQuery', prevQuery, this._suggestionsQuery); | ||
}; | ||
_proto._updateSuggestionsQuery = function _updateSuggestionsQuery(query, queryOptions) { | ||
_proto.getAppbaseSuggestionsQuery = function getAppbaseSuggestionsQuery() { | ||
return { | ||
id: 'DataSearch', | ||
dataField: this.getDataFields(), | ||
value: this.value, | ||
queryFormat: this.queryFormat, | ||
nestedField: this.nestedField, | ||
from: this.from, | ||
size: this.size, | ||
sortBy: this.sortBy, | ||
aggregationField: this.aggregationField, | ||
includeFields: this.includeFields, | ||
excludeFields: this.excludeFields, | ||
fuzziness: this.fuzziness, | ||
searchOperators: this.searchOperators, | ||
highlight: this.highlight, | ||
highlightField: this.highlightField | ||
}; | ||
}; | ||
_proto.getPreviousSuggestionsQuery = function getPreviousSuggestionsQuery(query, queryOptions) { | ||
// Set default suggestions query here | ||
var finalQueryOptions = Searchbase.generateQueryOptions({ | ||
aggregationField: this.aggregationField, | ||
size: 10 | ||
size: this.size | ||
}); | ||
@@ -1324,13 +1410,30 @@ /** | ||
}; | ||
var prevQuery = this._suggestionsQuery; | ||
var prevQuery = _extends({}, this._suggestionsQuery); | ||
this._suggestionsQuery = _extends({ | ||
query: finalQuery | ||
}, Searchbase.highlightQuery(this.highlight, this.highlightField, this.dataField), {}, finalQueryOptions, {}, queryOptions); | ||
this._applyOptions({ | ||
stateChanges: false | ||
}, 'suggestionsQuery', prevQuery, this._suggestionsQuery); | ||
return prevQuery; | ||
}; | ||
// Method to apply the changed based on set options | ||
_proto.getDataFields = function getDataFields() { | ||
var fields = []; | ||
if (this.dataField === 'string') { | ||
fields = [this.dataField]; | ||
} else if (Array.isArray(this.dataField)) { | ||
this.dataField.forEach(function (dataField) { | ||
if (typeof dataField === 'object') { | ||
fields.push(dataField.field); | ||
} else { | ||
fields.push(dataField); | ||
} | ||
}); | ||
} | ||
return fields; | ||
} // Method to apply the changed based on set options | ||
; | ||
_proto._applyOptions = function _applyOptions(options, key, prevValue, nextValue) { | ||
@@ -1337,0 +1440,0 @@ // Trigger mic events |
@@ -303,3 +303,3 @@ import fetch from 'cross-fetch'; | ||
if (this.raw && this.raw.hits) { | ||
return this.raw.hits.hidden; | ||
return this.raw.hits.hidden || 0; | ||
} | ||
@@ -338,2 +338,13 @@ | ||
return []; | ||
} // object of custom data applied through queryRules | ||
// only works when `enableAppbase=true` | ||
}, { | ||
key: "customData", | ||
get: function get() { | ||
if (this.raw && this.raw.customData) { | ||
return this.raw.customData || {}; | ||
} | ||
return {}; | ||
} | ||
@@ -463,2 +474,3 @@ }]); | ||
// es url | ||
// use rs v3 api | ||
// auth credentials if any | ||
@@ -503,2 +515,3 @@ // to enable the recording of analytics | ||
url = _ref.url, | ||
enableAppbase = _ref.enableAppbase, | ||
credentials = _ref.credentials, | ||
@@ -515,3 +528,3 @@ analytics = _ref.analytics, | ||
from = _ref.from, | ||
_dataField = _ref.dataField, | ||
dataField = _ref.dataField, | ||
aggregationField = _ref.aggregationField, | ||
@@ -536,2 +549,4 @@ includeFields = _ref.includeFields, | ||
_defineProperty(this, "enableAppbase", void 0); | ||
_defineProperty(this, "credentials", void 0); | ||
@@ -645,5 +660,8 @@ | ||
var prevStatus = _this._micStatus; | ||
window.SpeechRecognition = window.webkitSpeechRecognition || window.SpeechRecognition || null; | ||
if (window.SpeechRecognition && prevStatus !== MIC_STATUS.denied) { | ||
if (typeof window !== 'undefined') { | ||
window.SpeechRecognition = window.webkitSpeechRecognition || window.SpeechRecognition || null; | ||
} | ||
if (window && window.SpeechRecognition && prevStatus !== MIC_STATUS.denied) { | ||
if (prevStatus === MIC_STATUS.active) { | ||
@@ -731,16 +749,4 @@ _this._setMicStatus(MIC_STATUS.inactive, options); | ||
_defineProperty(this, "_parseSuggestions", function (suggestions) { | ||
var fields = []; | ||
var fields = _this.getDataFields(); | ||
if (_this.dataField === 'string') { | ||
fields = [_this.dataField]; | ||
} else if (Array.isArray(_this.dataField)) { | ||
_this.dataField.forEach(function (dataField) { | ||
if (typeof dataField === 'object') { | ||
fields.push(dataField.field); | ||
} else { | ||
fields.push(dataField); | ||
} | ||
}); | ||
} | ||
return getSuggestions(fields, suggestions, _this.value).slice(0, _this.size); | ||
@@ -757,3 +763,3 @@ }); | ||
if (!_dataField) { | ||
if (!dataField) { | ||
throw new Error('Please provide a valid data field.'); | ||
@@ -764,2 +770,3 @@ } | ||
this.url = url; | ||
this.enableAppbase = enableAppbase || false; | ||
this.analytics = analytics || false; | ||
@@ -775,6 +782,6 @@ | ||
this.dataField = _dataField; | ||
this.dataField = dataField; | ||
this.aggregationField = aggregationField; | ||
this.credentials = credentials || ''; | ||
this.nestedField = nestedField || ''; | ||
this.nestedField = nestedField; | ||
this.queryFormat = queryFormat || 'or'; | ||
@@ -785,7 +792,7 @@ this.fuzziness = fuzziness || 0; | ||
this.from = Number(from) || 0; | ||
this.sortBy = sortBy || ''; | ||
this.sortBy = sortBy; | ||
this.includeFields = includeFields || ['*']; | ||
this.excludeFields = excludeFields || []; | ||
this.sortOptions = sortOptions || null; | ||
this.sortByField = sortByField || ''; | ||
this.sortByField = sortByField; | ||
this.highlight = highlight; | ||
@@ -1057,4 +1064,6 @@ this.highlightField = highlightField; | ||
var prev = _this3.results; | ||
var rawResults = results; | ||
if (_this3.enableAppbase) rawResults = results.SearchResult; | ||
_this3.results.setRaw(results); | ||
_this3.results.setRaw(rawResults); | ||
@@ -1065,3 +1074,3 @@ _this3._applyOptions({ | ||
return Promise.resolve(results); | ||
return Promise.resolve(rawResults); | ||
})["catch"](handleError); | ||
@@ -1103,4 +1112,7 @@ })["catch"](handleError); | ||
if (suggestions.aggregations) { | ||
_this4._handleCompositeAggsResponse(_this4.aggregationField, suggestions.aggregations, options); | ||
var rawSuggestions = suggestions; | ||
if (_this4.enableAppbase) rawSuggestions = suggestions.DataSearch; | ||
if (rawSuggestions.aggregations) { | ||
_this4._handleCompositeAggsResponse(_this4.aggregationField, rawSuggestions.aggregations, options); | ||
} | ||
@@ -1110,3 +1122,3 @@ | ||
_this4.suggestions.setRaw(suggestions); | ||
_this4.suggestions.setRaw(rawSuggestions); | ||
@@ -1117,3 +1129,3 @@ _this4._applyOptions({ | ||
return Promise.resolve(suggestions); | ||
return Promise.resolve(rawSuggestions); | ||
})["catch"](handleError); | ||
@@ -1175,3 +1187,5 @@ })["catch"](handleError); | ||
var timestamp = Date.now(); | ||
return fetch(_this5.url + "/" + _this5.index + "/_search", finalRequestOptions).then(function (res) { | ||
var suffix = '_search'; | ||
if (_this5.enableAppbase) suffix = '_reactivesearch.v3'; | ||
return fetch(_this5.url + "/" + _this5.index + "/" + suffix, finalRequestOptions).then(function (res) { | ||
var responseHeaders = res.headers; // set search id | ||
@@ -1264,2 +1278,41 @@ | ||
_proto._updateQuery = function _updateQuery(query, queryOptions) { | ||
var prevQuery; | ||
if (this.enableAppbase) { | ||
prevQuery = _extends({}, this._query); | ||
this._query = { | ||
query: [_extends({}, this.getAppbaseSuggestionsQuery(), { | ||
execute: false | ||
}), this.getAppbaseResultQuery()], | ||
settings: this.getAppbaseSettings() | ||
}; | ||
} else prevQuery = this.getPreviousQuery(query, queryOptions); | ||
this._applyOptions({ | ||
stateChanges: false | ||
}, 'query', prevQuery, this._query); | ||
}; | ||
_proto.getAppbaseSettings = function getAppbaseSettings() { | ||
return { | ||
recordAnalytics: this.analytics | ||
}; | ||
}; | ||
_proto.getAppbaseResultQuery = function getAppbaseResultQuery() { | ||
return { | ||
id: 'SearchResult', | ||
dataField: this.getDataFields(), | ||
from: this.from, | ||
size: this.size, | ||
sortBy: this.sortBy, | ||
includeFields: this.includeFields, | ||
excludeFields: this.excludeFields, | ||
react: { | ||
and: 'DataSearch' | ||
} | ||
}; | ||
}; | ||
_proto.getPreviousQuery = function getPreviousQuery(query, queryOptions) { | ||
// Set default query here | ||
@@ -1293,13 +1346,46 @@ var finalQueryOptions = Searchbase.generateQueryOptions({ | ||
}, Searchbase.highlightQuery(this.highlight, this.highlightField, this.dataField), {}, finalQueryOptions, {}, queryOptions); | ||
return prevQuery; | ||
}; | ||
_proto._updateSuggestionsQuery = function _updateSuggestionsQuery(query, queryOptions) { | ||
var prevQuery; | ||
if (this.enableAppbase) { | ||
prevQuery = _extends({}, this._suggestionsQuery); | ||
this._suggestionsQuery = { | ||
query: [this.getAppbaseSuggestionsQuery()], | ||
settings: this.getAppbaseSettings() | ||
}; | ||
} else prevQuery = this.getPreviousSuggestionsQuery(query, queryOptions); | ||
this._applyOptions({ | ||
stateChanges: false | ||
}, 'query', prevQuery, this._query); | ||
}, 'suggestionsQuery', prevQuery, this._suggestionsQuery); | ||
}; | ||
_proto._updateSuggestionsQuery = function _updateSuggestionsQuery(query, queryOptions) { | ||
_proto.getAppbaseSuggestionsQuery = function getAppbaseSuggestionsQuery() { | ||
return { | ||
id: 'DataSearch', | ||
dataField: this.getDataFields(), | ||
value: this.value, | ||
queryFormat: this.queryFormat, | ||
nestedField: this.nestedField, | ||
from: this.from, | ||
size: this.size, | ||
sortBy: this.sortBy, | ||
aggregationField: this.aggregationField, | ||
includeFields: this.includeFields, | ||
excludeFields: this.excludeFields, | ||
fuzziness: this.fuzziness, | ||
searchOperators: this.searchOperators, | ||
highlight: this.highlight, | ||
highlightField: this.highlightField | ||
}; | ||
}; | ||
_proto.getPreviousSuggestionsQuery = function getPreviousSuggestionsQuery(query, queryOptions) { | ||
// Set default suggestions query here | ||
var finalQueryOptions = Searchbase.generateQueryOptions({ | ||
aggregationField: this.aggregationField, | ||
size: 10 | ||
size: this.size | ||
}); | ||
@@ -1320,13 +1406,30 @@ /** | ||
}; | ||
var prevQuery = this._suggestionsQuery; | ||
var prevQuery = _extends({}, this._suggestionsQuery); | ||
this._suggestionsQuery = _extends({ | ||
query: finalQuery | ||
}, Searchbase.highlightQuery(this.highlight, this.highlightField, this.dataField), {}, finalQueryOptions, {}, queryOptions); | ||
this._applyOptions({ | ||
stateChanges: false | ||
}, 'suggestionsQuery', prevQuery, this._suggestionsQuery); | ||
return prevQuery; | ||
}; | ||
// Method to apply the changed based on set options | ||
_proto.getDataFields = function getDataFields() { | ||
var fields = []; | ||
if (this.dataField === 'string') { | ||
fields = [this.dataField]; | ||
} else if (Array.isArray(this.dataField)) { | ||
this.dataField.forEach(function (dataField) { | ||
if (typeof dataField === 'object') { | ||
fields.push(dataField.field); | ||
} else { | ||
fields.push(dataField); | ||
} | ||
}); | ||
} | ||
return fields; | ||
} // Method to apply the changed based on set options | ||
; | ||
_proto._applyOptions = function _applyOptions(options, key, prevValue, nextValue) { | ||
@@ -1333,0 +1436,0 @@ // Trigger mic events |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Searchbase=e()}(this,function(){"use strict";function t(t,e){for(var s=0;s<e.length;s++){var i=e[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function e(e,s,i){return s&&t(e.prototype,s),i&&t(e,i),e}function s(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}function i(){return(i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(t[i]=s[i])}return t}).apply(this,arguments)}var r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var n=function(t,e){return t(e={exports:{}},e.exports),e.exports}(function(t,e){var s=function(t){function e(){this.fetch=!1,this.DOMException=t.DOMException}return e.prototype=t,new e}("undefined"!=typeof self?self:r);!function(t){!function(e){var s={searchParams:"URLSearchParams"in t,iterable:"Symbol"in t&&"iterator"in Symbol,blob:"FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in t,arrayBuffer:"ArrayBuffer"in t};if(s.arrayBuffer)var i=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],r=ArrayBuffer.isView||function(t){return t&&i.indexOf(Object.prototype.toString.call(t))>-1};function n(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function o(t){return"string"!=typeof t&&(t=String(t)),t}function a(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return s.iterable&&(e[Symbol.iterator]=function(){return e}),e}function u(t){this.map={},t instanceof u?t.forEach(function(t,e){this.append(e,t)},this):Array.isArray(t)?t.forEach(function(t){this.append(t[0],t[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(e){this.append(e,t[e])},this)}function h(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function c(t){return new Promise(function(e,s){t.onload=function(){e(t.result)},t.onerror=function(){s(t.error)}})}function l(t){var e=new FileReader,s=c(e);return e.readAsArrayBuffer(t),s}function d(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function f(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:s.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:s.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:s.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():s.arrayBuffer&&s.blob&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=d(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||r(t))?this._bodyArrayBuffer=d(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):s.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},s.blob&&(this.blob=function(){var t=h(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?h(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(l)}),this.text=function(){var t,e,s,i=h(this);if(i)return i;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,s=c(e),e.readAsText(t),s;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),s=new Array(e.length),i=0;i<e.length;i++)s[i]=String.fromCharCode(e[i]);return s.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},s.formData&&(this.formData=function(){return this.text().then(g)}),this.json=function(){return this.text().then(JSON.parse)},this}u.prototype.append=function(t,e){t=n(t),e=o(e);var s=this.map[t];this.map[t]=s?s+", "+e:e},u.prototype.delete=function(t){delete this.map[n(t)]},u.prototype.get=function(t){return t=n(t),this.has(t)?this.map[t]:null},u.prototype.has=function(t){return this.map.hasOwnProperty(n(t))},u.prototype.set=function(t,e){this.map[n(t)]=o(e)},u.prototype.forEach=function(t,e){for(var s in this.map)this.map.hasOwnProperty(s)&&t.call(e,this.map[s],s,this)},u.prototype.keys=function(){var t=[];return this.forEach(function(e,s){t.push(s)}),a(t)},u.prototype.values=function(){var t=[];return this.forEach(function(e){t.push(e)}),a(t)},u.prototype.entries=function(){var t=[];return this.forEach(function(e,s){t.push([s,e])}),a(t)},s.iterable&&(u.prototype[Symbol.iterator]=u.prototype.entries);var p=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function y(t,e){var s,i,r=(e=e||{}).body;if(t instanceof y){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new u(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,r||null==t._bodyInit||(r=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new u(e.headers)),this.method=(s=e.method||this.method||"GET",i=s.toUpperCase(),p.indexOf(i)>-1?i:s),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&r)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(r)}function g(t){var e=new FormData;return t.trim().split("&").forEach(function(t){if(t){var s=t.split("="),i=s.shift().replace(/\+/g," "),r=s.join("=").replace(/\+/g," ");e.append(decodeURIComponent(i),decodeURIComponent(r))}}),e}function v(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new u(e.headers),this.url=e.url||"",this._initBody(t)}y.prototype.clone=function(){return new y(this,{body:this._bodyInit})},f.call(y.prototype),f.call(v.prototype),v.prototype.clone=function(){return new v(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new u(this.headers),url:this.url})},v.error=function(){var t=new v(null,{status:0,statusText:""});return t.type="error",t};var m=[301,302,303,307,308];v.redirect=function(t,e){if(-1===m.indexOf(e))throw new RangeError("Invalid status code");return new v(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var s=Error(t);this.stack=s.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function b(t,i){return new Promise(function(r,n){var o=new y(t,i);if(o.signal&&o.signal.aborted)return n(new e.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function h(){a.abort()}a.onload=function(){var t,e,s={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",e=new u,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(t){var s=t.split(":"),i=s.shift().trim();if(i){var r=s.join(":").trim();e.append(i,r)}}),e)};s.url="responseURL"in a?a.responseURL:s.headers.get("X-Request-URL");var i="response"in a?a.response:a.responseText;r(new v(i,s))},a.onerror=function(){n(new TypeError("Network request failed"))},a.ontimeout=function(){n(new TypeError("Network request failed"))},a.onabort=function(){n(new e.DOMException("Aborted","AbortError"))},a.open(o.method,o.url,!0),"include"===o.credentials?a.withCredentials=!0:"omit"===o.credentials&&(a.withCredentials=!1),"responseType"in a&&s.blob&&(a.responseType="blob"),o.headers.forEach(function(t,e){a.setRequestHeader(e,t)}),o.signal&&(o.signal.addEventListener("abort",h),a.onreadystatechange=function(){4===a.readyState&&o.signal.removeEventListener("abort",h)}),a.send(void 0===o._bodyInit?null:o._bodyInit)})}b.polyfill=!0,t.fetch||(t.fetch=b,t.Headers=u,t.Request=y,t.Response=v),e.Headers=u,e.Request=y,e.Response=v,e.fetch=b}({})}(s),delete s.fetch.polyfill,(e=s.fetch).default=s.fetch,e.fetch=s.fetch,e.Headers=s.Headers,e.Request=s.Request,e.Response=s.Response,t.exports=e});n.fetch,n.Headers,n.Request,n.Response;function o(){return(o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(t[i]=s[i])}return t}).apply(this,arguments)}function a(t,e){if(null==t)return{};var s,i,r={},n=Object.keys(t);for(i=0;i<n.length;i++)s=n[i],e.indexOf(s)>=0||(r[s]=t[s]);return r}function u(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var s=t[Symbol.toPrimitive];if(void 0!==s){var i=s.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}function h(t){var e="";return t&&Object.keys(t).forEach(function(s,i){e+=s+"="+t[s],i<Object.keys(t).length-1&&(e+=",")}),e}function c(t){return t&&""!==t.trim()?t:"https://scalr.api.appbase.io"}function l(t){void 0===t&&(t="");for(var e,s=t,i="",r=0,n=0,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";s.charAt(0|n)||(o="=",n%1);i+=o.charAt(63&r>>8-n%1*8)){if((e=s.charCodeAt(n+=.75))>255)throw new Error('"btoa" failed: The string to be encoded contains characters outside of the Latin1 range.');r=r<<8|e}return i}function d(t){void 0===t&&(t={}),this.index=t.index,this.credentials=t.credentials,this.url=c(t.url),this.userID=t.userID,this.customEvents=t.customEvents,this.searchQuery=void 0,this.searchID=void 0,this.searchState=null,this.filters=null,this.emptyQuery=void 0===t.emptyQuery||t.emptyQuery,this.headers=null}var f=function(t){var e=[];return t&&(e=[].concat(t).map(function(t){var e={};t._updated?e._updated=t._updated:t._deleted&&(e._deleted=t._deleted);var s=function(t){var e=i({},t);return e.highlight&&Object.keys(e.highlight).forEach(function(t){var s,r=e.highlight[t][0];e._source=i({},e._source,((s={})[t]=r,s))}),e}(t);return Object.keys(s).filter(function(t){return"_source"!==t}).reduce(function(t,e){return t[e]=s[e],t},i({},s._source,{},e))})),e},p=function(t){return"object"==typeof t?Array.isArray(t)?function t(e){return e.reduce(function(e,s){return e.concat(Array.isArray(s)?t(s):s)},[])}(t):null:t},y=function(t,e,s){void 0===t&&(t=[]),void 0===s&&(s="");var r=[],n=[],o=function(t,e,i){if(s.trim().split(" ").some(function(e){return String(t).toLowerCase().includes(e)})&&!n.includes(t)||i._promoted){var o={label:t,value:t,source:i};n=[].concat(n,[t]),r=[].concat(r,[o])}};return e.forEach(function(e){var s=e._score,r=e._index,n=e._type,a=i({},e,{_id:e._id,_index:r,_score:s,_type:n});t.forEach(function(t){!function t(e,s,i){if(void 0===i&&(i=e),"object"==typeof e){var r=s.split("."),n=e[r[0]];if(n)if(r.length>1){var a=s.substring(r[0].length+1);Array.isArray(n)?n.forEach(function(e){t(e,a,i)}):t(n,a,i)}else{var u=p(n);u&&(Array.isArray(u)?u.forEach(function(t){return o(t,0,i)}):o(u,0,i))}}}(a,t)})}),r};var g=function(){function t(t){var e=this;s(this,"data",void 0),s(this,"raw",void 0),s(this,"parseResults",void 0),s(this,"setRaw",function(t){e.raw=t,t.hits&&t.hits.hits&&e.setData(t.hits.hits)}),this.data=t||[]}return t.prototype.setData=function(t){var e=f(t);if(this.promotedData.length){var s=this.promotedData.map(function(t){return t._id}).filter(Boolean);s&&(e=e.filter(function(t){return!s.includes(t._id)})),e=[].concat(this.promotedData.map(function(t){return i({},t,{_promoted:!0})}),e)}this.parseResults?this.data=this.parseResults(e):this.data=e},e(t,[{key:"numberOfResults",get:function(){return this.raw&&this.raw.hits?"object"==typeof this.raw.hits.total?this.raw.hits.total.value:this.raw.hits.total:0}},{key:"time",get:function(){return this.raw?this.raw.took:0}},{key:"hidden",get:function(){return this.raw&&this.raw.hits?this.raw.hits.hidden:0}},{key:"promoted",get:function(){return this.raw&&this.raw.promoted?this.raw.promoted.length:0}},{key:"promotedData",get:function(){return this.raw&&this.raw.promoted&&this.raw.promoted||[]}},{key:"rawData",get:function(){return this.raw&&this.raw.hits&&this.raw.hits&&this.raw.hits.hits||[]}}]),t}(),v=function(){function t(){s(this,"observers",void 0),this.observers=[]}var e=t.prototype;return e.subscribe=function(t,e){this.observers.push({callback:t,properties:e})},e.unsubscribe=function(t){this.observers=t?this.observers.filter(function(e){return e.callback!==t?e:null}):[]},e.next=function(t,e,s){var i=s||window;this.observers.forEach(function(s){void 0===s.properties?s.callback.call(i,t):s.properties instanceof Array&&s.properties.length&&s.properties.includes(e)?s.callback.call(i,t):"string"==typeof s.properties&&s.properties&&s.properties===e&&s.callback.call(i,t)})},t}(),m=function(){function t(t){s(this,"data",void 0),s(this,"afterKey",void 0),s(this,"raw",void 0),this.data=t||[]}var r=t.prototype;return r.setRaw=function(t){this.raw=t,t.after_key&&this.setAfterKey(t.after_key)},r.setAfterKey=function(t){this.afterKey=t},r.setData=function(t,e){var s,r;this.data=(s=t,void 0===(r=e)&&(r=[]),r.map(function(t){var e=t.doc_count,r=t.key,n=t[s];return i({_doc_count:e,_key:r[s]},n.hits.hits[0])}))},e(t,[{key:"rawData",get:function(){return this.raw&&this.raw.buckets||[]}}]),t}(),b={inactive:"INACTIVE",active:"ACTIVE",denied:"DENIED"},_={inactive:"INACTIVE",pending:"PENDING",error:"ERROR"},w={triggerQuery:!0,triggerSuggestionsQuery:!1,stateChanges:!0},S={stateChanges:!0},F=function(){function t(t){var e=this,r=t.index,f=t.url,p=t.credentials,S=t.analytics,F=t.headers,E=t.value,O=t.suggestions,R=t.results,C=t.fuzziness,q=t.searchOperators,A=t.queryFormat,x=t.size,D=t.from,Q=t.dataField,I=t.aggregationField,B=t.includeFields,P=t.excludeFields,T=t.transformQuery,z=t.transformSuggestionsQuery,k=t.transformRequest,j=t.transformResponse,U=t.beforeValueChange,M=t.sortBy,H=t.nestedField,N=t.sortOptions,V=t.sortByField,X=t.highlight,L=t.highlightField;if(s(this,"index",void 0),s(this,"url",void 0),s(this,"credentials",void 0),s(this,"analytics",void 0),s(this,"value",void 0),s(this,"headers",void 0),s(this,"suggestions",void 0),s(this,"aggregationData",void 0),s(this,"suggestionsError",void 0),s(this,"results",void 0),s(this,"error",void 0),s(this,"stateChanges",void 0),s(this,"requestStatus",void 0),s(this,"suggestionsRequestStatus",void 0),s(this,"nestedField",void 0),s(this,"queryFormat",void 0),s(this,"searchOperators",void 0),s(this,"size",void 0),s(this,"from",void 0),s(this,"fuzziness",void 0),s(this,"sortBy",void 0),s(this,"sortByField",void 0),s(this,"dataField",void 0),s(this,"aggregationField",void 0),s(this,"includeFields",void 0),s(this,"excludeFields",void 0),s(this,"sortOptions",void 0),s(this,"highlight",void 0),s(this,"highlightField",void 0),s(this,"analyticsInstance",void 0),s(this,"onValueChange",void 0),s(this,"onResults",void 0),s(this,"onSuggestions",void 0),s(this,"onAggregationData",void 0),s(this,"onError",void 0),s(this,"onSuggestionsError",void 0),s(this,"onRequestStatusChange",void 0),s(this,"onSuggestionsRequestStatusChange",void 0),s(this,"onQueryChange",void 0),s(this,"onSuggestionsQueryChange",void 0),s(this,"onMicStatusChange",void 0),s(this,"transformQuery",void 0),s(this,"transformSuggestionsQuery",void 0),s(this,"transformRequest",void 0),s(this,"transformResponse",void 0),s(this,"beforeValueChange",void 0),s(this,"_query",void 0),s(this,"_suggestionsQuery",void 0),s(this,"_queryOptions",void 0),s(this,"_micStatus",void 0),s(this,"_micInstance",void 0),s(this,"onMicClick",function(t,s){void 0===t&&(t={}),void 0===s&&(s=w);var i=e._micStatus;if(window.SpeechRecognition=window.webkitSpeechRecognition||window.SpeechRecognition||null,window.SpeechRecognition&&i!==b.denied){i===b.active&&e._setMicStatus(b.inactive,s);var r=window.SpeechRecognition;if(e._micInstance)return void e._stopMic();e._micInstance=new r,e._micInstance.continuous=!0,e._micInstance.interimResults=!0,Object.assign(e._micInstance,t),e._micInstance.start(),e._micInstance.onstart=function(){e._setMicStatus(b.active,s)},e._micInstance.onresult=function(t){var i=t.results;i&&i[0]&&i[0].isFinal&&e._stopMic(),e._handleVoiceResults({results:i},s)},e._micInstance.onerror=function(t){"no-speech"===t.error||"audio-capture"===t.error?e._setMicStatus(b.inactive,s):"not-allowed"===t.error&&e._setMicStatus(b.denied,s),console.error(t)}}}),s(this,"_handleVoiceResults",function(t,s){var i=t.results;void 0===s&&(s=w),i&&i[0]&&i[0].isFinal&&i[0][0]&&i[0][0].transcript&&i[0][0].transcript.trim()&&e.setValue(i[0][0].transcript.trim(),s)}),s(this,"_stopMic",function(){e._micInstance&&(e._micInstance.stop(),e._micInstance=null,e._setMicStatus(b.inactive))}),s(this,"_setMicStatus",function(t,s){void 0===s&&(s=w);var i=e._micStatus;e._micStatus=t,e._applyOptions(s,"micStatus",i,e._micStatus)}),s(this,"_parseSuggestions",function(t){var s=[];return"string"===e.dataField?s=[e.dataField]:Array.isArray(e.dataField)&&e.dataField.forEach(function(t){"object"==typeof t?s.push(t.field):s.push(t)}),y(s,t,e.value).slice(0,e.size)}),!r)throw new Error("Please provide a valid index.");if(!f)throw new Error("Please provide a valid url.");if(!Q)throw new Error("Please provide a valid data field.");this.index=r,this.url=f,this.analytics=S||!1,this.analytics&&(this.analyticsInstance=function(t){void 0===t&&(t={});var e=new d(t);return d.prototype.setIndex=function(t){return this.index=t,this},d.prototype.setCredentials=function(t){return this.credentials=t,this},d.prototype.setURL=function(t){return this.url=c(t),this},d.prototype.setHeaders=function(t){return this.headers=t,this},d.prototype.setSearchQuery=function(t){return this.searchQuery=t,this},d.prototype.clearSearchQuery=function(){return this.searchQuery=void 0,this},d.prototype.setSearchID=function(t){return this.searchID=t,this},d.prototype.clearSearchID=function(){return this.searchID=void 0,this},d.prototype.setSearchState=function(t){return this.searchState=t,this},d.prototype.clearSearchState=function(){return this.searchState=null,this},d.prototype.setUserID=function(t){return this.userID=t,this},d.prototype.clearUserID=function(){return this.userID=null,this},d.prototype.setCustomEvents=function(t){return this.customEvents=t,this},d.prototype.clearCustomEvents=function(){return this.customEvents=null,this},d.prototype.addCustomEvent=function(t){return this.customEvents=o({},this.customEvents,{customEvent:t}),this},d.prototype.removeCustomEvent=function(t){var e=this.customEvents,s=(e[t],a(e,[t].map(u)));return this.customEvents=s,this},d.prototype.setFilters=function(t){return this.filters=t,this},d.prototype.clearFilters=function(){return this.filters=null,this},d.prototype.addFilter=function(t){return this.filters=o({},this.filters,{filter:t}),this},d.prototype.removeFilter=function(t){var e=this.filters,s=(e[t],a(e,[t].map(u)));return this.filters=s,this},d.prototype.enableEmptyQuery=function(){return this.emptyQuery=!0,this},d.prototype.disableEmptyQuery=function(){return this.emptyQuery=!1,this},d.prototype.registerClick=function(t,e){if(Number.isNaN(parseInt(t,10)))throw new Error("appbase-analytics: click position must be an integer.");var s=this._recordEventHeaders();return n(this.url+"/"+this.index+"/_analytics",{method:"POST",headers:o({},s,{},e?{"X-Search-Suggestions-Click":!0,"X-Search-Suggestions-ClickPosition":t}:{"X-Search-Click":!0,"X-Search-ClickPosition":t})})},d.prototype.registerConversion=function(){var t=this._recordEventHeaders();return n(this.url+"/"+this.index+"/_analytics",{method:"POST",headers:o({},t,{"X-Search-Conversion":!0})})},d.prototype.getAnalyticsHeaders=function(){return o({},this.searchQuery||this.emptyQuery?{"X-Search-Query":this.searchQuery||""}:null,{},this.searchID?{"X-Search-Id":this.searchID}:null,{},this.searchState?{"X-Search-State":JSON.stringify(this.searchState)}:null,{},this.userID?{"X-User-Id":this.userID}:null,{},this.customEvents?{"X-Search-CustomEvent":h(this.customEvents)}:null,{},this.filters?{"X-Search-Filters":h(this.filters)}:null)},d.prototype._recordEventHeaders=function(){if(!this.index)throw new Error("appbase-analytics: A valid index must be present to record an event.");if(!this.credentials)throw new Error("appbase-analytics: Auth credentials is missing.");if(!this.searchID)throw new Error("appbase-analytics: searchID must be present to record an event.");return o({},this.headers,{"Content-Type":"application/json",Authorization:"Basic "+l(this.credentials),"X-Search-Id":this.searchID},this.userID?{"X-User-Id":this.userID}:null,{},this.customEvents?{"X-Search-CustomEvent":h(this.customEvents)}:null)},e}({index:r,url:f,credentials:p})),this.dataField=Q,this.aggregationField=I,this.credentials=p||"",this.nestedField=H||"",this.queryFormat=A||"or",this.fuzziness=C||0,this.searchOperators=q||!1,this.size=Number(x)||10,this.from=Number(D)||0,this.sortBy=M||"",this.includeFields=B||["*"],this.excludeFields=P||[],this.sortOptions=N||null,this.sortByField=V||"",this.highlight=X,this.highlightField=L,this.requestStatus=_.inactive,this.suggestionsRequestStatus=_.inactive,this.transformRequest=k||null,this.transformResponse=j||null,this.transformQuery=T||null,this.transformSuggestionsQuery=z||null,this.beforeValueChange=U||null,this.stateChanges=new v,this.suggestions=new g(O),this.suggestions.parseResults=this._parseSuggestions,this.results=new g(R),this.aggregationData=new m,this.headers={Accept:"application/json","Content-Type":"application/json"},this.credentials&&(this.headers=i({},this.headers,{Authorization:"Basic "+btoa(this.credentials)})),F&&this.setHeaders(F,{stateChanges:!1}),E?this.setValue(E,{stateChanges:!0}):this.value=""}var r=t.prototype;return r.subscribeToStateChanges=function(t,e){this.stateChanges.subscribe(t,e)},r.unsubscribeToStateChanges=function(t){this.stateChanges.unsubscribe(t)},r.setHeaders=function(t,e){void 0===e&&(e=w);var s=this.headers;this.headers=i({},this.headers,{},t),this._applyOptions(e,"headers",s,this.headers)},r.setSize=function(t,e){void 0===e&&(e=w);var s=this.size;this.size=t,this._applyOptions(e,"size",s,this.size)},r.setFrom=function(t,e){void 0===e&&(e=w);var s=this.from;this.from=t,this._applyOptions(e,"from",s,this.from)},r.setFuzziness=function(t,e){void 0===e&&(e=w);var s=this.fuzziness;this.fuzziness=t,this._applyOptions(e,"fuzziness",s,this.fuzziness)},r.setIncludeFields=function(t,e){void 0===e&&(e=w);var s=this.includeFields;this.includeFields=t,this._applyOptions(e,"includeFields",s,t)},r.setExcludeFields=function(t,e){void 0===e&&(e=w);var s=this.excludeFields;this.excludeFields=t,this._applyOptions(e,"excludeFields",s,t)},r.setSortBy=function(t,e){void 0===e&&(e=w);var s=this.sortBy;this.sortBy=t,this._applyOptions(e,"sortBy",s,t)},r.setSortByField=function(t,e){void 0===e&&(e=w);var s=this.sortByField;this.sortByField=t,this._applyOptions(e,"sortByField",s,t)},r.setNestedField=function(t,e){void 0===e&&(e=w);var s=this.nestedField;this.nestedField=t,this._applyOptions(e,"nestedField",s,t)},r.setDataField=function(t,e){void 0===e&&(e=w);var s=this.dataField;this.dataField=t,this._applyOptions(e,"dataField",s,t)},r.setResults=function(t,e){if(void 0===e&&(e=S),t){var s=this.results;this.results=new g(t),this._applyOptions({stateChanges:e.stateChanges},"results",s,this.results)}},r.setSuggestions=function(t,e){if(void 0===e&&(e=S),t){var s=this.suggestions;this.suggestions=new g(t),this.suggestions.parseResults=this._parseSuggestions,this._applyOptions({stateChanges:e.stateChanges},"suggestions",s,this.suggestions)}},r.setValue=function(t,e){var s=this;void 0===e&&(e=w);var i=function(){var i=s.value;s.value=t,s._applyOptions(e,"value",i,s.value)};this.beforeValueChange?this.beforeValueChange(t).then(i).catch(function(t){console.warn("beforeValueChange rejected the promise with ",t)}):i()},r.triggerQuery=function(t){var e=this;void 0===t&&(t=S);var s=function(s){return e._setError(s,{stateChanges:t.stateChanges}),console.error(s),Promise.reject(s)};try{return this._updateQuery(),this._setRequestStatus(_.pending),(this.transformQuery?this.transformQuery(this.query):new Promise(function(t){return t(e.query)})).then(function(i){e._fetchRequest(i).then(function(s){e._setRequestStatus(_.inactive);var i=e.results;return e.results.setRaw(s),e._applyOptions({stateChanges:t.stateChanges},"results",i,e.results),Promise.resolve(s)}).catch(s)}).catch(s)}catch(t){return s(t)}},r.triggerSuggestionsQuery=function(t){var e=this;void 0===t&&(t=S);var s=function(s){return e._setSuggestionsError(s,{stateChanges:t.stateChanges}),console.error(s),Promise.reject(s)};try{return this._updateSuggestionsQuery(),this._setSuggestionsRequestStatus(_.pending),(this.transformSuggestionsQuery?this.transformSuggestionsQuery(this.suggestionsQuery):new Promise(function(t){return t(e.suggestionsQuery)})).then(function(i){e._fetchRequest(i).then(function(s){e._setSuggestionsRequestStatus(_.inactive),s.aggregations&&e._handleCompositeAggsResponse(e.aggregationField,s.aggregations,t);var i=e.suggestions;return e.suggestions.setRaw(s),e._applyOptions({stateChanges:t.stateChanges},"suggestions",i,e.suggestions),Promise.resolve(s)}).catch(s)}).catch(s)}catch(t){return s(t)}},r._handleCompositeAggsResponse=function(t,e,s){void 0===s&&(s=w);var i=this.aggregationData;this.aggregationData.setRaw(e[t]),this.aggregationData.setData(t,e[t].buckets),this._applyOptions({stateChanges:s.stateChanges},"aggregations",i,this.aggregationData)},r._handleTransformResponse=function(t){return this.transformResponse&&"function"==typeof this.transformResponse?this.transformResponse(t):new Promise(function(e){return e(t)})},r._handleTransformRequest=function(t){return this.transformRequest&&"function"==typeof this.transformRequest?this.transformRequest(t):new Promise(function(e){return e(t)})},r._fetchRequest=function(t){var e=this,s={method:"POST",body:JSON.stringify(t),headers:i({},this.headers,{},this.analytics?this.analyticsInstance.setSearchQuery(this.value).getAnalyticsHeaders():null)};return new Promise(function(t,r){e._handleTransformRequest(s).then(function(s){var o=Date.now();return n(e.url+"/"+e.index+"/_search",s).then(function(s){var n=s.headers;return s.headers&&e.analytics&&e.analyticsInstance.setSearchID(s.headers.get("X-Search-Id")||null),s.status>=500?r(s):s.status>=400?r(s):s.json().then(function(s){e._handleTransformResponse(s).then(function(e){e&&Object.prototype.hasOwnProperty.call(e,"error")&&r(e);var s=i({},e,{_timestamp:o,_headers:n});return t(s)}).catch(function(t){return console.warn("transformResponse rejected the promise with ",t),r(t)})})}).catch(function(t){return r(t)})}).catch(function(t){return console.warn("transformRequest rejected the promise with ",t),r(t)})})},r._setSuggestionsError=function(t,e){void 0===e&&(e=w),this._setSuggestionsRequestStatus(_.error);var s=this.suggestionsError;this.suggestionsError=t,this._applyOptions(e,"suggestionsError",s,this.suggestionsError)},r._setError=function(t,e){void 0===e&&(e=w),this._setRequestStatus(_.error);var s=this.error;this.error=t,this._applyOptions(e,"error",s,this.error)},r._setRequestStatus=function(t){var e=this.requestStatus;this.requestStatus=t,this._applyOptions({stateChanges:!0},"requestStatus",e,this.requestStatus)},r._setSuggestionsRequestStatus=function(t){var e=this.suggestionsRequestStatus;this.suggestionsRequestStatus=t,this._applyOptions({stateChanges:!0},"suggestionsRequestStatus",e,this.suggestionsRequestStatus)},r._updateQuery=function(e,s){var r=t.generateQueryOptions({excludeFields:this.excludeFields,includeFields:this.includeFields,size:this.size,from:this.from,sortBy:this.sortBy,sortByField:this.sortByField,sortOptions:this.sortOptions}),n=e||t.defaultQuery(this.value,{dataField:this.dataField,searchOperators:this.searchOperators,queryFormat:this.queryFormat,fuzziness:this.fuzziness,nestedField:this.nestedField})||{match_all:{}},o=this._query;this._query=i({query:n},t.highlightQuery(this.highlight,this.highlightField,this.dataField),{},r,{},s),this._applyOptions({stateChanges:!1},"query",o,this._query)},r._updateSuggestionsQuery=function(e,s){var r=t.generateQueryOptions({aggregationField:this.aggregationField,size:10}),n=e||t.defaultQuery(this.value,{dataField:this.dataField,searchOperators:this.searchOperators,queryFormat:this.queryFormat,fuzziness:this.fuzziness,nestedField:this.nestedField})||{match_all:{}},o=this._suggestionsQuery;this._suggestionsQuery=i({query:n},t.highlightQuery(this.highlight,this.highlightField,this.dataField),{},r,{},s),this._applyOptions({stateChanges:!1},"suggestionsQuery",o,this._suggestionsQuery)},r._applyOptions=function(t,e,s,i){var r;("micStatus"===e&&this.onMicStatusChange&&this.onMicStatusChange(i,s),"query"===e&&this.onQueryChange&&this.onQueryChange(i,s),"suggestionsQuery"===e&&this.onSuggestionsQueryChange&&this.onSuggestionsQueryChange(i,s),"value"===e&&this.onValueChange&&this.onValueChange(i,s),"error"===e&&this.onError&&this.onError(i),"suggestionsError"===e&&this.onSuggestionsError&&this.onSuggestionsError(i),"results"===e&&this.onResults&&this.onResults(i,s),"suggestions"===e&&this.onSuggestions&&this.onSuggestions(i,s),"aggregations"===e&&this.onAggregationData&&this.onAggregationData(i,s),"requestStatus"===e&&this.onRequestStatusChange&&this.onRequestStatusChange(i,s),"suggestionsRequestStatus"===e&&this.onSuggestionsRequestStatusChange&&this.onSuggestionsRequestStatusChange(i,s),t.triggerQuery&&this.triggerQuery(),t.triggerSuggestionsQuery&&this.triggerSuggestionsQuery(),!1!==t.stateChanges)&&this.stateChanges.next(((r={})[e]={prev:s,next:i},r),e)},e(t,[{key:"micStatus",get:function(){return this._micStatus}},{key:"micInstance",get:function(){return this._micInstance}},{key:"micActive",get:function(){return this._micStatus===b.active}},{key:"micInactive",get:function(){return this._micStatus===b.inactive}},{key:"micDenied",get:function(){return this._micStatus===b.denied}},{key:"query",get:function(){return this._query}},{key:"suggestionsQuery",get:function(){return this._suggestionsQuery}},{key:"requestPending",get:function(){return this.requestStatus===_.pending}},{key:"suggestionsRequestPending",get:function(){return this.suggestionsRequestStatus===_.pending}}]),t}();return s(F,"defaultQuery",void 0),s(F,"shouldQuery",void 0),s(F,"highlightQuery",void 0),s(F,"compositeAggsQuery",void 0),s(F,"generateQueryOptions",void 0),F.defaultQuery=function(t,e){var s,i=null;return t&&(s=Array.isArray(e.dataField)?e.dataField:[e.dataField],i=e.searchOperators?{simple_query_string:F.shouldQuery(t,s,e)}:{bool:{should:F.shouldQuery(t,s,e),minimum_should_match:"1"}}),""===t&&(i=null),i&&e.nestedField&&(i={nested:{path:e.nestedField,query:i}}),i},F.shouldQuery=function(t,e,s){void 0===s&&(s={searchOperators:!1,queryFormat:"or",fuzziness:0});var i=e.map(function(t){return"object"==typeof t?t.field+(t.weight?"^"+t.weight:""):t});return s.searchOperators?{query:t,fields:i,default_operator:s.queryFormat}:"and"===s.queryFormat?[{multi_match:{query:t,fields:i,type:"cross_fields",operator:"and"}},{multi_match:{query:t,fields:i,type:"phrase_prefix",operator:"and"}}]:[{multi_match:{query:t,fields:i,type:"best_fields",operator:"or",fuzziness:s.fuzziness}},{multi_match:{query:t,fields:i,type:"phrase_prefix",operator:"or"}}]},F.highlightQuery=function(t,e,s){if(!t)return null;var r={},n=e||s,o="string"==typeof e?[e]:e;return"string"==typeof n?r[n]={}:Array.isArray(n)&&n.forEach(function(t){"object"==typeof t?r[t.field]={}:r[t]={}}),{highlight:i({pre_tags:["<mark>"],post_tags:["</mark>"],fields:r},o&&{require_field_match:!1})}},F.compositeAggsQuery=function(t,e){var s,i,r;return{aggs:(r={},r[t]={composite:{sources:[(s={},s[t]={terms:{field:t}},s)],size:e},aggs:(i={},i[t]={top_hits:{size:1}},i)},r)}},F.generateQueryOptions=function(t){var e,s={};if(void 0!==t.size&&(s.size=t.size),void 0!==t.from&&(s.from=t.from),t.includeFields||t.excludeFields){var i={};t.includeFields&&(i.includes=t.includeFields),t.excludeFields&&(i.excludes=t.excludeFields),s._source=i}if(t.sortOptions)s.sort=[(e={},e[t.sortOptions[0].dataField]={order:t.sortOptions[0].sortBy},e)];else if(t.sortBy&&t.sortByField){var r;s.sort=[(r={},r[t.sortByField]={order:t.sortBy},r)]}return t.aggregationField&&(s.aggs=F.compositeAggsQuery(t.aggregationField,t.size||0).aggs),s},F}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Searchbase=e()}(this,(function(){"use strict";function t(t,e){for(var s=0;s<e.length;s++){var i=e[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function e(e,s,i){return s&&t(e.prototype,s),i&&t(e,i),e}function s(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}function i(){return(i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(t[i]=s[i])}return t}).apply(this,arguments)}var r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var n=function(t,e){return t(e={exports:{}},e.exports),e.exports}((function(t,e){var s=function(t){function e(){this.fetch=!1,this.DOMException=t.DOMException}return e.prototype=t,new e}("undefined"!=typeof self?self:r);!function(t){!function(e){var s="URLSearchParams"in t,i="Symbol"in t&&"iterator"in Symbol,r="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),n="FormData"in t,o="ArrayBuffer"in t;if(o)var a=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(t){return t&&a.indexOf(Object.prototype.toString.call(t))>-1};function h(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function c(t){return"string"!=typeof t&&(t=String(t)),t}function l(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return i&&(e[Symbol.iterator]=function(){return e}),e}function d(t){this.map={},t instanceof d?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function f(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function p(t){return new Promise((function(e,s){t.onload=function(){e(t.result)},t.onerror=function(){s(t.error)}}))}function g(t){var e=new FileReader,s=p(e);return e.readAsArrayBuffer(t),s}function y(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function v(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:r&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:n&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:s&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():o&&r&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=y(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):o&&(ArrayBuffer.prototype.isPrototypeOf(t)||u(t))?this._bodyArrayBuffer=y(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):s&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},r&&(this.blob=function(){var t=f(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?f(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(g)}),this.text=function(){var t,e,s,i=f(this);if(i)return i;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,s=p(e),e.readAsText(t),s;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),s=new Array(e.length),i=0;i<e.length;i++)s[i]=String.fromCharCode(e[i]);return s.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},n&&(this.formData=function(){return this.text().then(_)}),this.json=function(){return this.text().then(JSON.parse)},this}d.prototype.append=function(t,e){t=h(t),e=c(e);var s=this.map[t];this.map[t]=s?s+", "+e:e},d.prototype.delete=function(t){delete this.map[h(t)]},d.prototype.get=function(t){return t=h(t),this.has(t)?this.map[t]:null},d.prototype.has=function(t){return this.map.hasOwnProperty(h(t))},d.prototype.set=function(t,e){this.map[h(t)]=c(e)},d.prototype.forEach=function(t,e){for(var s in this.map)this.map.hasOwnProperty(s)&&t.call(e,this.map[s],s,this)},d.prototype.keys=function(){var t=[];return this.forEach((function(e,s){t.push(s)})),l(t)},d.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),l(t)},d.prototype.entries=function(){var t=[];return this.forEach((function(e,s){t.push([s,e])})),l(t)},i&&(d.prototype[Symbol.iterator]=d.prototype.entries);var m=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function b(t,e){var s,i,r=(e=e||{}).body;if(t instanceof b){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new d(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,r||null==t._bodyInit||(r=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new d(e.headers)),this.method=(s=e.method||this.method||"GET",i=s.toUpperCase(),m.indexOf(i)>-1?i:s),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&r)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(r)}function _(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var s=t.split("="),i=s.shift().replace(/\+/g," "),r=s.join("=").replace(/\+/g," ");e.append(decodeURIComponent(i),decodeURIComponent(r))}})),e}function S(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new d(e.headers),this.url=e.url||"",this._initBody(t)}b.prototype.clone=function(){return new b(this,{body:this._bodyInit})},v.call(b.prototype),v.call(S.prototype),S.prototype.clone=function(){return new S(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new d(this.headers),url:this.url})},S.error=function(){var t=new S(null,{status:0,statusText:""});return t.type="error",t};var w=[301,302,303,307,308];S.redirect=function(t,e){if(-1===w.indexOf(e))throw new RangeError("Invalid status code");return new S(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var s=Error(t);this.stack=s.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function F(t,s){return new Promise((function(i,n){var o=new b(t,s);if(o.signal&&o.signal.aborted)return n(new e.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function u(){a.abort()}a.onload=function(){var t,e,s={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",e=new d,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var s=t.split(":"),i=s.shift().trim();if(i){var r=s.join(":").trim();e.append(i,r)}})),e)};s.url="responseURL"in a?a.responseURL:s.headers.get("X-Request-URL");var r="response"in a?a.response:a.responseText;i(new S(r,s))},a.onerror=function(){n(new TypeError("Network request failed"))},a.ontimeout=function(){n(new TypeError("Network request failed"))},a.onabort=function(){n(new e.DOMException("Aborted","AbortError"))},a.open(o.method,o.url,!0),"include"===o.credentials?a.withCredentials=!0:"omit"===o.credentials&&(a.withCredentials=!1),"responseType"in a&&r&&(a.responseType="blob"),o.headers.forEach((function(t,e){a.setRequestHeader(e,t)})),o.signal&&(o.signal.addEventListener("abort",u),a.onreadystatechange=function(){4===a.readyState&&o.signal.removeEventListener("abort",u)}),a.send(void 0===o._bodyInit?null:o._bodyInit)}))}F.polyfill=!0,t.fetch||(t.fetch=F,t.Headers=d,t.Request=b,t.Response=S),e.Headers=d,e.Request=b,e.Response=S,e.fetch=F}({})}(s),delete s.fetch.polyfill,(e=s.fetch).default=s.fetch,e.fetch=s.fetch,e.Headers=s.Headers,e.Request=s.Request,e.Response=s.Response,t.exports=e}));n.fetch,n.Headers,n.Request,n.Response;function o(){return(o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(t[i]=s[i])}return t}).apply(this,arguments)}function a(t,e){if(null==t)return{};var s,i,r={},n=Object.keys(t);for(i=0;i<n.length;i++)s=n[i],e.indexOf(s)>=0||(r[s]=t[s]);return r}function u(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var s=t[Symbol.toPrimitive];if(void 0!==s){var i=s.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}function h(t){var e="";return t&&Object.keys(t).forEach((function(s,i){e+=s+"="+t[s],i<Object.keys(t).length-1&&(e+=",")})),e}function c(t){return t&&""!==t.trim()?t:"https://scalr.api.appbase.io"}function l(t){void 0===t&&(t="");for(var e,s=t,i="",r=0,n=0,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";s.charAt(0|n)||(o="=",n%1);i+=o.charAt(63&r>>8-n%1*8)){if((e=s.charCodeAt(n+=.75))>255)throw new Error('"btoa" failed: The string to be encoded contains characters outside of the Latin1 range.');r=r<<8|e}return i}function d(t){void 0===t&&(t={}),this.index=t.index,this.credentials=t.credentials,this.url=c(t.url),this.userID=t.userID,this.customEvents=t.customEvents,this.searchQuery=void 0,this.searchID=void 0,this.searchState=null,this.filters=null,this.emptyQuery=void 0===t.emptyQuery||t.emptyQuery,this.headers=null}var f=function(t){var e=[];return t&&(e=[].concat(t).map((function(t){var e={};t._updated?e._updated=t._updated:t._deleted&&(e._deleted=t._deleted);var s=function(t){var e=i({},t);return e.highlight&&Object.keys(e.highlight).forEach((function(t){var s,r=e.highlight[t][0];e._source=i({},e._source,((s={})[t]=r,s))})),e}(t);return Object.keys(s).filter((function(t){return"_source"!==t})).reduce((function(t,e){return t[e]=s[e],t}),i({},s._source,{},e))}))),e},p=function(t){return"object"==typeof t?Array.isArray(t)?function t(e){return e.reduce((function(e,s){return e.concat(Array.isArray(s)?t(s):s)}),[])}(t):null:t},g=function(t,e,s){void 0===t&&(t=[]),void 0===s&&(s="");var r=[],n=[],o=function(t,e,i){if(s.trim().split(" ").some((function(e){return String(t).toLowerCase().includes(e)}))&&!n.includes(t)||i._promoted){var o={label:t,value:t,source:i};n=[].concat(n,[t]),r=[].concat(r,[o])}};return e.forEach((function(e){var s=e._score,r=e._index,n=e._type,a=i({},e,{_id:e._id,_index:r,_score:s,_type:n});t.forEach((function(t){!function t(e,s,i){if(void 0===i&&(i=e),"object"==typeof e){var r=s.split("."),n=e[r[0]];if(n)if(r.length>1){var a=s.substring(r[0].length+1);Array.isArray(n)?n.forEach((function(e){t(e,a,i)})):t(n,a,i)}else{var u=p(n);u&&(Array.isArray(u)?u.forEach((function(t){return o(t,0,i)})):o(u,0,i))}}}(a,t)}))})),r};var y=function(){function t(t){var e=this;s(this,"data",void 0),s(this,"raw",void 0),s(this,"parseResults",void 0),s(this,"setRaw",(function(t){e.raw=t,t.hits&&t.hits.hits&&e.setData(t.hits.hits)})),this.data=t||[]}return t.prototype.setData=function(t){var e=f(t);if(this.promotedData.length){var s=this.promotedData.map((function(t){return t._id})).filter(Boolean);s&&(e=e.filter((function(t){return!s.includes(t._id)}))),e=[].concat(this.promotedData.map((function(t){return i({},t,{_promoted:!0})})),e)}this.parseResults?this.data=this.parseResults(e):this.data=e},e(t,[{key:"numberOfResults",get:function(){return this.raw&&this.raw.hits?"object"==typeof this.raw.hits.total?this.raw.hits.total.value:this.raw.hits.total:0}},{key:"time",get:function(){return this.raw?this.raw.took:0}},{key:"hidden",get:function(){return this.raw&&this.raw.hits&&this.raw.hits.hidden||0}},{key:"promoted",get:function(){return this.raw&&this.raw.promoted?this.raw.promoted.length:0}},{key:"promotedData",get:function(){return this.raw&&this.raw.promoted&&this.raw.promoted||[]}},{key:"rawData",get:function(){return this.raw&&this.raw.hits&&this.raw.hits&&this.raw.hits.hits||[]}},{key:"customData",get:function(){return this.raw&&this.raw.customData&&this.raw.customData||{}}}]),t}(),v=function(){function t(){s(this,"observers",void 0),this.observers=[]}var e=t.prototype;return e.subscribe=function(t,e){this.observers.push({callback:t,properties:e})},e.unsubscribe=function(t){this.observers=t?this.observers.filter((function(e){return e.callback!==t?e:null})):[]},e.next=function(t,e,s){var i=s||window;this.observers.forEach((function(s){void 0===s.properties?s.callback.call(i,t):s.properties instanceof Array&&s.properties.length&&s.properties.includes(e)?s.callback.call(i,t):"string"==typeof s.properties&&s.properties&&s.properties===e&&s.callback.call(i,t)}))},t}(),m=function(){function t(t){s(this,"data",void 0),s(this,"afterKey",void 0),s(this,"raw",void 0),this.data=t||[]}var r=t.prototype;return r.setRaw=function(t){this.raw=t,t.after_key&&this.setAfterKey(t.after_key)},r.setAfterKey=function(t){this.afterKey=t},r.setData=function(t,e){var s,r;this.data=(s=t,void 0===(r=e)&&(r=[]),r.map((function(t){var e=t.doc_count,r=t.key,n=t[s];return i({_doc_count:e,_key:r[s]},n.hits.hits[0])})))},e(t,[{key:"rawData",get:function(){return this.raw&&this.raw.buckets||[]}}]),t}(),b="INACTIVE",_="ACTIVE",S="DENIED",w="INACTIVE",F="PENDING",E="ERROR",O={triggerQuery:!0,triggerSuggestionsQuery:!1,stateChanges:!0},R={stateChanges:!0},A=function(){function t(t){var e=this,r=t.index,f=t.url,p=t.enableAppbase,F=t.credentials,E=t.analytics,R=t.headers,A=t.value,q=t.suggestions,C=t.results,Q=t.fuzziness,x=t.searchOperators,D=t.queryFormat,I=t.size,B=t.from,z=t.dataField,P=t.aggregationField,T=t.includeFields,k=t.excludeFields,j=t.transformQuery,U=t.transformSuggestionsQuery,M=t.transformRequest,H=t.transformResponse,N=t.beforeValueChange,V=t.sortBy,X=t.nestedField,L=t.sortOptions,G=t.sortByField,K=t.highlight,J=t.highlightField;if(s(this,"index",void 0),s(this,"url",void 0),s(this,"enableAppbase",void 0),s(this,"credentials",void 0),s(this,"analytics",void 0),s(this,"value",void 0),s(this,"headers",void 0),s(this,"suggestions",void 0),s(this,"aggregationData",void 0),s(this,"suggestionsError",void 0),s(this,"results",void 0),s(this,"error",void 0),s(this,"stateChanges",void 0),s(this,"requestStatus",void 0),s(this,"suggestionsRequestStatus",void 0),s(this,"nestedField",void 0),s(this,"queryFormat",void 0),s(this,"searchOperators",void 0),s(this,"size",void 0),s(this,"from",void 0),s(this,"fuzziness",void 0),s(this,"sortBy",void 0),s(this,"sortByField",void 0),s(this,"dataField",void 0),s(this,"aggregationField",void 0),s(this,"includeFields",void 0),s(this,"excludeFields",void 0),s(this,"sortOptions",void 0),s(this,"highlight",void 0),s(this,"highlightField",void 0),s(this,"analyticsInstance",void 0),s(this,"onValueChange",void 0),s(this,"onResults",void 0),s(this,"onSuggestions",void 0),s(this,"onAggregationData",void 0),s(this,"onError",void 0),s(this,"onSuggestionsError",void 0),s(this,"onRequestStatusChange",void 0),s(this,"onSuggestionsRequestStatusChange",void 0),s(this,"onQueryChange",void 0),s(this,"onSuggestionsQueryChange",void 0),s(this,"onMicStatusChange",void 0),s(this,"transformQuery",void 0),s(this,"transformSuggestionsQuery",void 0),s(this,"transformRequest",void 0),s(this,"transformResponse",void 0),s(this,"beforeValueChange",void 0),s(this,"_query",void 0),s(this,"_suggestionsQuery",void 0),s(this,"_queryOptions",void 0),s(this,"_micStatus",void 0),s(this,"_micInstance",void 0),s(this,"onMicClick",(function(t,s){void 0===t&&(t={}),void 0===s&&(s=O);var i=e._micStatus;if("undefined"!=typeof window&&(window.SpeechRecognition=window.webkitSpeechRecognition||window.SpeechRecognition||null),window&&window.SpeechRecognition&&i!==S){i===_&&e._setMicStatus(b,s);var r=window.SpeechRecognition;if(e._micInstance)return void e._stopMic();e._micInstance=new r,e._micInstance.continuous=!0,e._micInstance.interimResults=!0,Object.assign(e._micInstance,t),e._micInstance.start(),e._micInstance.onstart=function(){e._setMicStatus(_,s)},e._micInstance.onresult=function(t){var i=t.results;i&&i[0]&&i[0].isFinal&&e._stopMic(),e._handleVoiceResults({results:i},s)},e._micInstance.onerror=function(t){"no-speech"===t.error||"audio-capture"===t.error?e._setMicStatus(b,s):"not-allowed"===t.error&&e._setMicStatus(S,s),console.error(t)}}})),s(this,"_handleVoiceResults",(function(t,s){var i=t.results;void 0===s&&(s=O),i&&i[0]&&i[0].isFinal&&i[0][0]&&i[0][0].transcript&&i[0][0].transcript.trim()&&e.setValue(i[0][0].transcript.trim(),s)})),s(this,"_stopMic",(function(){e._micInstance&&(e._micInstance.stop(),e._micInstance=null,e._setMicStatus(b))})),s(this,"_setMicStatus",(function(t,s){void 0===s&&(s=O);var i=e._micStatus;e._micStatus=t,e._applyOptions(s,"micStatus",i,e._micStatus)})),s(this,"_parseSuggestions",(function(t){var s=e.getDataFields();return g(s,t,e.value).slice(0,e.size)})),!r)throw new Error("Please provide a valid index.");if(!f)throw new Error("Please provide a valid url.");if(!z)throw new Error("Please provide a valid data field.");this.index=r,this.url=f,this.enableAppbase=p||!1,this.analytics=E||!1,this.analytics&&(this.analyticsInstance=function(t){void 0===t&&(t={});var e=new d(t);return d.prototype.setIndex=function(t){return this.index=t,this},d.prototype.setCredentials=function(t){return this.credentials=t,this},d.prototype.setURL=function(t){return this.url=c(t),this},d.prototype.setHeaders=function(t){return this.headers=t,this},d.prototype.setSearchQuery=function(t){return this.searchQuery=t,this},d.prototype.clearSearchQuery=function(){return this.searchQuery=void 0,this},d.prototype.setSearchID=function(t){return this.searchID=t,this},d.prototype.clearSearchID=function(){return this.searchID=void 0,this},d.prototype.setSearchState=function(t){return this.searchState=t,this},d.prototype.clearSearchState=function(){return this.searchState=null,this},d.prototype.setUserID=function(t){return this.userID=t,this},d.prototype.clearUserID=function(){return this.userID=null,this},d.prototype.setCustomEvents=function(t){return this.customEvents=t,this},d.prototype.clearCustomEvents=function(){return this.customEvents=null,this},d.prototype.addCustomEvent=function(t){return this.customEvents=o({},this.customEvents,{customEvent:t}),this},d.prototype.removeCustomEvent=function(t){var e=this.customEvents,s=(e[t],a(e,[t].map(u)));return this.customEvents=s,this},d.prototype.setFilters=function(t){return this.filters=t,this},d.prototype.clearFilters=function(){return this.filters=null,this},d.prototype.addFilter=function(t){return this.filters=o({},this.filters,{filter:t}),this},d.prototype.removeFilter=function(t){var e=this.filters,s=(e[t],a(e,[t].map(u)));return this.filters=s,this},d.prototype.enableEmptyQuery=function(){return this.emptyQuery=!0,this},d.prototype.disableEmptyQuery=function(){return this.emptyQuery=!1,this},d.prototype.registerClick=function(t,e){if(Number.isNaN(parseInt(t,10)))throw new Error("appbase-analytics: click position must be an integer.");var s=this._recordEventHeaders();return n(this.url+"/"+this.index+"/_analytics",{method:"POST",headers:o({},s,{},e?{"X-Search-Suggestions-Click":!0,"X-Search-Suggestions-ClickPosition":t}:{"X-Search-Click":!0,"X-Search-ClickPosition":t})})},d.prototype.registerConversion=function(){var t=this._recordEventHeaders();return n(this.url+"/"+this.index+"/_analytics",{method:"POST",headers:o({},t,{"X-Search-Conversion":!0})})},d.prototype.getAnalyticsHeaders=function(){return o({},this.searchQuery||this.emptyQuery?{"X-Search-Query":this.searchQuery||""}:null,{},this.searchID?{"X-Search-Id":this.searchID}:null,{},this.searchState?{"X-Search-State":JSON.stringify(this.searchState)}:null,{},this.userID?{"X-User-Id":this.userID}:null,{},this.customEvents?{"X-Search-CustomEvent":h(this.customEvents)}:null,{},this.filters?{"X-Search-Filters":h(this.filters)}:null)},d.prototype._recordEventHeaders=function(){if(!this.index)throw new Error("appbase-analytics: A valid index must be present to record an event.");if(!this.credentials)throw new Error("appbase-analytics: Auth credentials is missing.");if(!this.searchID)throw new Error("appbase-analytics: searchID must be present to record an event.");return o({},this.headers,{"Content-Type":"application/json",Authorization:"Basic "+l(this.credentials),"X-Search-Id":this.searchID},this.userID?{"X-User-Id":this.userID}:null,{},this.customEvents?{"X-Search-CustomEvent":h(this.customEvents)}:null)},e}({index:r,url:f,credentials:F})),this.dataField=z,this.aggregationField=P,this.credentials=F||"",this.nestedField=X,this.queryFormat=D||"or",this.fuzziness=Q||0,this.searchOperators=x||!1,this.size=Number(I)||10,this.from=Number(B)||0,this.sortBy=V,this.includeFields=T||["*"],this.excludeFields=k||[],this.sortOptions=L||null,this.sortByField=G,this.highlight=K,this.highlightField=J,this.requestStatus=w,this.suggestionsRequestStatus=w,this.transformRequest=M||null,this.transformResponse=H||null,this.transformQuery=j||null,this.transformSuggestionsQuery=U||null,this.beforeValueChange=N||null,this.stateChanges=new v,this.suggestions=new y(q),this.suggestions.parseResults=this._parseSuggestions,this.results=new y(C),this.aggregationData=new m,this.headers={Accept:"application/json","Content-Type":"application/json"},this.credentials&&(this.headers=i({},this.headers,{Authorization:"Basic "+btoa(this.credentials)})),R&&this.setHeaders(R,{stateChanges:!1}),A?this.setValue(A,{stateChanges:!0}):this.value=""}var r=t.prototype;return r.subscribeToStateChanges=function(t,e){this.stateChanges.subscribe(t,e)},r.unsubscribeToStateChanges=function(t){this.stateChanges.unsubscribe(t)},r.setHeaders=function(t,e){void 0===e&&(e=O);var s=this.headers;this.headers=i({},this.headers,{},t),this._applyOptions(e,"headers",s,this.headers)},r.setSize=function(t,e){void 0===e&&(e=O);var s=this.size;this.size=t,this._applyOptions(e,"size",s,this.size)},r.setFrom=function(t,e){void 0===e&&(e=O);var s=this.from;this.from=t,this._applyOptions(e,"from",s,this.from)},r.setFuzziness=function(t,e){void 0===e&&(e=O);var s=this.fuzziness;this.fuzziness=t,this._applyOptions(e,"fuzziness",s,this.fuzziness)},r.setIncludeFields=function(t,e){void 0===e&&(e=O);var s=this.includeFields;this.includeFields=t,this._applyOptions(e,"includeFields",s,t)},r.setExcludeFields=function(t,e){void 0===e&&(e=O);var s=this.excludeFields;this.excludeFields=t,this._applyOptions(e,"excludeFields",s,t)},r.setSortBy=function(t,e){void 0===e&&(e=O);var s=this.sortBy;this.sortBy=t,this._applyOptions(e,"sortBy",s,t)},r.setSortByField=function(t,e){void 0===e&&(e=O);var s=this.sortByField;this.sortByField=t,this._applyOptions(e,"sortByField",s,t)},r.setNestedField=function(t,e){void 0===e&&(e=O);var s=this.nestedField;this.nestedField=t,this._applyOptions(e,"nestedField",s,t)},r.setDataField=function(t,e){void 0===e&&(e=O);var s=this.dataField;this.dataField=t,this._applyOptions(e,"dataField",s,t)},r.setResults=function(t,e){if(void 0===e&&(e=R),t){var s=this.results;this.results=new y(t),this._applyOptions({stateChanges:e.stateChanges},"results",s,this.results)}},r.setSuggestions=function(t,e){if(void 0===e&&(e=R),t){var s=this.suggestions;this.suggestions=new y(t),this.suggestions.parseResults=this._parseSuggestions,this._applyOptions({stateChanges:e.stateChanges},"suggestions",s,this.suggestions)}},r.setValue=function(t,e){var s=this;void 0===e&&(e=O);var i=function(){var i=s.value;s.value=t,s._applyOptions(e,"value",i,s.value)};this.beforeValueChange?this.beforeValueChange(t).then(i).catch((function(t){console.warn("beforeValueChange rejected the promise with ",t)})):i()},r.triggerQuery=function(t){var e=this;void 0===t&&(t=R);var s=function(s){return e._setError(s,{stateChanges:t.stateChanges}),console.error(s),Promise.reject(s)};try{return this._updateQuery(),this._setRequestStatus(F),(this.transformQuery?this.transformQuery(this.query):new Promise((function(t){return t(e.query)}))).then((function(i){e._fetchRequest(i).then((function(s){e._setRequestStatus(w);var i=e.results,r=s;return e.enableAppbase&&(r=s.SearchResult),e.results.setRaw(r),e._applyOptions({stateChanges:t.stateChanges},"results",i,e.results),Promise.resolve(r)})).catch(s)})).catch(s)}catch(t){return s(t)}},r.triggerSuggestionsQuery=function(t){var e=this;void 0===t&&(t=R);var s=function(s){return e._setSuggestionsError(s,{stateChanges:t.stateChanges}),console.error(s),Promise.reject(s)};try{return this._updateSuggestionsQuery(),this._setSuggestionsRequestStatus(F),(this.transformSuggestionsQuery?this.transformSuggestionsQuery(this.suggestionsQuery):new Promise((function(t){return t(e.suggestionsQuery)}))).then((function(i){e._fetchRequest(i).then((function(s){e._setSuggestionsRequestStatus(w);var i=s;e.enableAppbase&&(i=s.DataSearch),i.aggregations&&e._handleCompositeAggsResponse(e.aggregationField,i.aggregations,t);var r=e.suggestions;return e.suggestions.setRaw(i),e._applyOptions({stateChanges:t.stateChanges},"suggestions",r,e.suggestions),Promise.resolve(i)})).catch(s)})).catch(s)}catch(t){return s(t)}},r._handleCompositeAggsResponse=function(t,e,s){void 0===s&&(s=O);var i=this.aggregationData;this.aggregationData.setRaw(e[t]),this.aggregationData.setData(t,e[t].buckets),this._applyOptions({stateChanges:s.stateChanges},"aggregations",i,this.aggregationData)},r._handleTransformResponse=function(t){return this.transformResponse&&"function"==typeof this.transformResponse?this.transformResponse(t):new Promise((function(e){return e(t)}))},r._handleTransformRequest=function(t){return this.transformRequest&&"function"==typeof this.transformRequest?this.transformRequest(t):new Promise((function(e){return e(t)}))},r._fetchRequest=function(t){var e=this,s={method:"POST",body:JSON.stringify(t),headers:i({},this.headers,{},this.analytics?this.analyticsInstance.setSearchQuery(this.value).getAnalyticsHeaders():null)};return new Promise((function(t,r){e._handleTransformRequest(s).then((function(s){var o=Date.now(),a="_search";return e.enableAppbase&&(a="_reactivesearch.v3"),n(e.url+"/"+e.index+"/"+a,s).then((function(s){var n=s.headers;return s.headers&&e.analytics&&e.analyticsInstance.setSearchID(s.headers.get("X-Search-Id")||null),s.status>=500?r(s):s.status>=400?r(s):s.json().then((function(s){e._handleTransformResponse(s).then((function(e){e&&Object.prototype.hasOwnProperty.call(e,"error")&&r(e);var s=i({},e,{_timestamp:o,_headers:n});return t(s)})).catch((function(t){return console.warn("transformResponse rejected the promise with ",t),r(t)}))}))})).catch((function(t){return r(t)}))})).catch((function(t){return console.warn("transformRequest rejected the promise with ",t),r(t)}))}))},r._setSuggestionsError=function(t,e){void 0===e&&(e=O),this._setSuggestionsRequestStatus(E);var s=this.suggestionsError;this.suggestionsError=t,this._applyOptions(e,"suggestionsError",s,this.suggestionsError)},r._setError=function(t,e){void 0===e&&(e=O),this._setRequestStatus(E);var s=this.error;this.error=t,this._applyOptions(e,"error",s,this.error)},r._setRequestStatus=function(t){var e=this.requestStatus;this.requestStatus=t,this._applyOptions({stateChanges:!0},"requestStatus",e,this.requestStatus)},r._setSuggestionsRequestStatus=function(t){var e=this.suggestionsRequestStatus;this.suggestionsRequestStatus=t,this._applyOptions({stateChanges:!0},"suggestionsRequestStatus",e,this.suggestionsRequestStatus)},r._updateQuery=function(t,e){var s;this.enableAppbase?(s=i({},this._query),this._query={query:[i({},this.getAppbaseSuggestionsQuery(),{execute:!1}),this.getAppbaseResultQuery()],settings:this.getAppbaseSettings()}):s=this.getPreviousQuery(t,e),this._applyOptions({stateChanges:!1},"query",s,this._query)},r.getAppbaseSettings=function(){return{recordAnalytics:this.analytics}},r.getAppbaseResultQuery=function(){return{id:"SearchResult",dataField:this.getDataFields(),from:this.from,size:this.size,sortBy:this.sortBy,includeFields:this.includeFields,excludeFields:this.excludeFields,react:{and:"DataSearch"}}},r.getPreviousQuery=function(e,s){var r=t.generateQueryOptions({excludeFields:this.excludeFields,includeFields:this.includeFields,size:this.size,from:this.from,sortBy:this.sortBy,sortByField:this.sortByField,sortOptions:this.sortOptions}),n=e||t.defaultQuery(this.value,{dataField:this.dataField,searchOperators:this.searchOperators,queryFormat:this.queryFormat,fuzziness:this.fuzziness,nestedField:this.nestedField})||{match_all:{}},o=this._query;return this._query=i({query:n},t.highlightQuery(this.highlight,this.highlightField,this.dataField),{},r,{},s),o},r._updateSuggestionsQuery=function(t,e){var s;this.enableAppbase?(s=i({},this._suggestionsQuery),this._suggestionsQuery={query:[this.getAppbaseSuggestionsQuery()],settings:this.getAppbaseSettings()}):s=this.getPreviousSuggestionsQuery(t,e),this._applyOptions({stateChanges:!1},"suggestionsQuery",s,this._suggestionsQuery)},r.getAppbaseSuggestionsQuery=function(){return{id:"DataSearch",dataField:this.getDataFields(),value:this.value,queryFormat:this.queryFormat,nestedField:this.nestedField,from:this.from,size:this.size,sortBy:this.sortBy,aggregationField:this.aggregationField,includeFields:this.includeFields,excludeFields:this.excludeFields,fuzziness:this.fuzziness,searchOperators:this.searchOperators,highlight:this.highlight,highlightField:this.highlightField}},r.getPreviousSuggestionsQuery=function(e,s){var r=t.generateQueryOptions({aggregationField:this.aggregationField,size:this.size}),n=e||t.defaultQuery(this.value,{dataField:this.dataField,searchOperators:this.searchOperators,queryFormat:this.queryFormat,fuzziness:this.fuzziness,nestedField:this.nestedField})||{match_all:{}},o=i({},this._suggestionsQuery);return this._suggestionsQuery=i({query:n},t.highlightQuery(this.highlight,this.highlightField,this.dataField),{},r,{},s),o},r.getDataFields=function(){var t=[];return"string"===this.dataField?t=[this.dataField]:Array.isArray(this.dataField)&&this.dataField.forEach((function(e){"object"==typeof e?t.push(e.field):t.push(e)})),t},r._applyOptions=function(t,e,s,i){var r;("micStatus"===e&&this.onMicStatusChange&&this.onMicStatusChange(i,s),"query"===e&&this.onQueryChange&&this.onQueryChange(i,s),"suggestionsQuery"===e&&this.onSuggestionsQueryChange&&this.onSuggestionsQueryChange(i,s),"value"===e&&this.onValueChange&&this.onValueChange(i,s),"error"===e&&this.onError&&this.onError(i),"suggestionsError"===e&&this.onSuggestionsError&&this.onSuggestionsError(i),"results"===e&&this.onResults&&this.onResults(i,s),"suggestions"===e&&this.onSuggestions&&this.onSuggestions(i,s),"aggregations"===e&&this.onAggregationData&&this.onAggregationData(i,s),"requestStatus"===e&&this.onRequestStatusChange&&this.onRequestStatusChange(i,s),"suggestionsRequestStatus"===e&&this.onSuggestionsRequestStatusChange&&this.onSuggestionsRequestStatusChange(i,s),t.triggerQuery&&this.triggerQuery(),t.triggerSuggestionsQuery&&this.triggerSuggestionsQuery(),!1!==t.stateChanges)&&this.stateChanges.next(((r={})[e]={prev:s,next:i},r),e)},e(t,[{key:"micStatus",get:function(){return this._micStatus}},{key:"micInstance",get:function(){return this._micInstance}},{key:"micActive",get:function(){return this._micStatus===_}},{key:"micInactive",get:function(){return this._micStatus===b}},{key:"micDenied",get:function(){return this._micStatus===S}},{key:"query",get:function(){return this._query}},{key:"suggestionsQuery",get:function(){return this._suggestionsQuery}},{key:"requestPending",get:function(){return this.requestStatus===F}},{key:"suggestionsRequestPending",get:function(){return this.suggestionsRequestStatus===F}}]),t}();return s(A,"defaultQuery",void 0),s(A,"shouldQuery",void 0),s(A,"highlightQuery",void 0),s(A,"compositeAggsQuery",void 0),s(A,"generateQueryOptions",void 0),A.defaultQuery=function(t,e){var s,i=null;return t&&(s=Array.isArray(e.dataField)?e.dataField:[e.dataField],i=e.searchOperators?{simple_query_string:A.shouldQuery(t,s,e)}:{bool:{should:A.shouldQuery(t,s,e),minimum_should_match:"1"}}),""===t&&(i=null),i&&e.nestedField&&(i={nested:{path:e.nestedField,query:i}}),i},A.shouldQuery=function(t,e,s){void 0===s&&(s={searchOperators:!1,queryFormat:"or",fuzziness:0});var i=e.map((function(t){return"object"==typeof t?t.field+(t.weight?"^"+t.weight:""):t}));return s.searchOperators?{query:t,fields:i,default_operator:s.queryFormat}:"and"===s.queryFormat?[{multi_match:{query:t,fields:i,type:"cross_fields",operator:"and"}},{multi_match:{query:t,fields:i,type:"phrase_prefix",operator:"and"}}]:[{multi_match:{query:t,fields:i,type:"best_fields",operator:"or",fuzziness:s.fuzziness}},{multi_match:{query:t,fields:i,type:"phrase_prefix",operator:"or"}}]},A.highlightQuery=function(t,e,s){if(!t)return null;var r={},n=e||s,o="string"==typeof e?[e]:e;return"string"==typeof n?r[n]={}:Array.isArray(n)&&n.forEach((function(t){"object"==typeof t?r[t.field]={}:r[t]={}})),{highlight:i({pre_tags:["<mark>"],post_tags:["</mark>"],fields:r},o&&{require_field_match:!1})}},A.compositeAggsQuery=function(t,e){var s,i,r;return{aggs:(r={},r[t]={composite:{sources:[(s={},s[t]={terms:{field:t}},s)],size:e},aggs:(i={},i[t]={top_hits:{size:1}},i)},r)}},A.generateQueryOptions=function(t){var e,s={};if(void 0!==t.size&&(s.size=t.size),void 0!==t.from&&(s.from=t.from),t.includeFields||t.excludeFields){var i={};t.includeFields&&(i.includes=t.includeFields),t.excludeFields&&(i.excludes=t.excludeFields),s._source=i}if(t.sortOptions)s.sort=[(e={},e[t.sortOptions[0].dataField]={order:t.sortOptions[0].sortBy},e)];else if(t.sortBy&&t.sortByField){var r;s.sort=[(r={},r[t.sortByField]={order:t.sortBy},r)]}return t.aggregationField&&(s.aggs=A.compositeAggsQuery(t.aggregationField,t.size||0).aggs),s},A})); | ||
//# sourceMappingURL=searchbase.umd.min.js.map |
{ | ||
"name": "@appbaseio/searchbase", | ||
"version": "1.0.1-alpha.5", | ||
"version": "1.1.0-alpha.0", | ||
"private": false, | ||
@@ -16,3 +16,4 @@ "description": "Headless core + common utilities for search", | ||
"lint": "nps lint", | ||
"prepare": "nps validate" | ||
"prepare": "nps validate", | ||
"postpublish": "node ../../update-searchbase.js" | ||
}, | ||
@@ -19,0 +20,0 @@ "repository": { |
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
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
455979
5031