meilisearch
Advanced tools
Comparing version 0.18.2 to 0.19.0
@@ -33,2 +33,10 @@ # Contributing | ||
### Requirements | ||
To run this project, you will need: | ||
- Node.js >= v12 and node < 15 | ||
- Yarn | ||
### Setup | ||
@@ -35,0 +43,0 @@ |
@@ -232,3 +232,3 @@ import 'cross-fetch/polyfill'; | ||
} | ||
return [4 /*yield*/, fetch(constructURL.toString(), __assign(__assign({}, config), { method: method, body: body ? JSON.stringify(body) : undefined, headers: this.headers })).then(function (res) { return httpResponseErrorHandler(res); })]; | ||
return [4 /*yield*/, fetch(constructURL.toString(), __assign(__assign({}, config), { method: method, body: JSON.stringify(body), headers: this.headers })).then(function (res) { return httpResponseErrorHandler(res); })]; | ||
case 1: | ||
@@ -335,31 +335,4 @@ response = _b.sent(); | ||
/// | ||
/// STATIC | ||
/// UTILS | ||
/// | ||
Index.getApiRoutes = function () { | ||
return Index.apiRoutes; | ||
}; | ||
Index.getRouteConstructors = function () { | ||
return Index.routeConstructors; | ||
}; | ||
/// | ||
/// UPDATES | ||
/// | ||
/** | ||
* Get the informations about an update status | ||
* @memberof Index | ||
* @method getUpdateStatus | ||
*/ | ||
Index.prototype.getUpdateStatus = function (updateId) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = Index.routeConstructors.getUpdateStatus(this.uid, updateId); | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
Index.prototype.waitForPendingUpdate = function (updateId, _a) { | ||
@@ -390,20 +363,2 @@ var _b = _a === void 0 ? {} : _a, _c = _b.timeOutMs, timeOutMs = _c === void 0 ? 5000 : _c, _d = _b.intervalMs, intervalMs = _d === void 0 ? 50 : _d; | ||
}; | ||
/** | ||
* Get the list of all updates | ||
* @memberof Index | ||
* @method getAllUpdateStatus | ||
*/ | ||
Index.prototype.getAllUpdateStatus = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = Index.routeConstructors.getAllUpdateStatus(this.uid); | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/// | ||
@@ -424,3 +379,3 @@ /// SEARCH | ||
case 0: | ||
url = Index.routeConstructors.search(this.uid); | ||
url = "indexes/" + this.uid + "/search"; | ||
params = { | ||
@@ -476,3 +431,3 @@ q: query, | ||
case 0: | ||
url = Index.routeConstructors.indexRoute(this.uid); | ||
url = "indexes/" + this.uid; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
@@ -536,3 +491,3 @@ case 1: | ||
case 0: | ||
url = Index.apiRoutes.indexes; | ||
url = "indexes"; | ||
req = new HttpRequests(config); | ||
@@ -558,3 +513,3 @@ return [4 /*yield*/, req.post(url, __assign(__assign({}, options), { uid: uid }))]; | ||
case 0: | ||
url = Index.routeConstructors.update(this.uid); | ||
url = "indexes/" + this.uid; | ||
return [4 /*yield*/, this.httpRequest.put(url, data)]; | ||
@@ -580,3 +535,3 @@ case 1: | ||
case 0: | ||
url = Index.routeConstructors["delete"](this.uid); | ||
url = "indexes/" + this.uid; | ||
return [4 /*yield*/, this.httpRequest["delete"](url)]; | ||
@@ -588,3 +543,69 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
}; | ||
/** | ||
* Deletes an index if it already exists. | ||
* @memberof Index | ||
* @method deleteIfExists | ||
*/ | ||
Index.prototype.deleteIfExists = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var e_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, this["delete"]()]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/, true]; | ||
case 2: | ||
e_1 = _a.sent(); | ||
if (e_1.errorCode === 'index_not_found') { | ||
return [2 /*return*/, false]; | ||
} | ||
throw e_1; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/// | ||
/// UPDATES | ||
/// | ||
/** | ||
* Get the list of all updates | ||
* @memberof Index | ||
* @method getAllUpdateStatus | ||
*/ | ||
Index.prototype.getAllUpdateStatus = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = "indexes/" + this.uid + "/updates"; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Get the informations about an update status | ||
* @memberof Index | ||
* @method getUpdateStatus | ||
*/ | ||
Index.prototype.getUpdateStatus = function (updateId) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = "indexes/" + this.uid + "/updates/" + updateId; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/// | ||
/// STATS | ||
@@ -603,3 +624,3 @@ /// | ||
case 0: | ||
url = "/indexes/" + this.uid + "/stats"; | ||
url = "indexes/" + this.uid + "/stats"; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
@@ -625,3 +646,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.getDocuments(this.uid); | ||
url = "indexes/" + this.uid + "/documents"; | ||
if (options !== undefined && Array.isArray(options.attributesToRetrieve)) { | ||
@@ -647,3 +668,3 @@ attr = options.attributesToRetrieve.join(','); | ||
case 0: | ||
url = Index.routeConstructors.getDocument(this.uid, documentId); | ||
url = "indexes/" + this.uid + "/documents/" + documentId; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
@@ -666,3 +687,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.addDocuments(this.uid); | ||
url = "indexes/" + this.uid + "/documents"; | ||
return [4 /*yield*/, this.httpRequest.post(url, documents, options)]; | ||
@@ -685,3 +706,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.updateDocuments(this.uid); | ||
url = "indexes/" + this.uid + "/documents"; | ||
return [4 /*yield*/, this.httpRequest.put(url, documents, options)]; | ||
@@ -704,3 +725,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.deleteDocument(this.uid, documentId); | ||
url = "indexes/" + this.uid + "/documents/" + documentId; | ||
return [4 /*yield*/, this.httpRequest["delete"](url)]; | ||
@@ -723,3 +744,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.deleteDocuments(this.uid); | ||
url = "indexes/" + this.uid + "/documents/delete-batch"; | ||
return [4 /*yield*/, this.httpRequest.post(url, documentsIds)]; | ||
@@ -742,3 +763,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.deleteAllDocuments(this.uid); | ||
url = "indexes/" + this.uid + "/documents"; | ||
return [4 /*yield*/, this.httpRequest["delete"](url)]; | ||
@@ -764,3 +785,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.getSettings(this.uid); | ||
url = "indexes/" + this.uid + "/settings"; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
@@ -784,3 +805,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.updateSettings(this.uid); | ||
url = "indexes/" + this.uid + "/settings"; | ||
return [4 /*yield*/, this.httpRequest.post(url, settings)]; | ||
@@ -803,3 +824,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.resetSettings(this.uid); | ||
url = "indexes/" + this.uid + "/settings"; | ||
return [4 /*yield*/, this.httpRequest["delete"](url)]; | ||
@@ -825,3 +846,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.getSynonyms(this.uid); | ||
url = "indexes/" + this.uid + "/settings/synonyms"; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
@@ -844,3 +865,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.updateSynonyms(this.uid); | ||
url = "indexes/" + this.uid + "/settings/synonyms"; | ||
return [4 /*yield*/, this.httpRequest.post(url, synonyms)]; | ||
@@ -863,3 +884,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.resetSynonyms(this.uid); | ||
url = "indexes/" + this.uid + "/settings/synonyms"; | ||
return [4 /*yield*/, this.httpRequest["delete"](url)]; | ||
@@ -885,3 +906,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.getStopWords(this.uid); | ||
url = "indexes/" + this.uid + "/settings/stop-words"; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
@@ -904,3 +925,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.updateStopWords(this.uid); | ||
url = "indexes/" + this.uid + "/settings/stop-words"; | ||
return [4 /*yield*/, this.httpRequest.post(url, stopWords)]; | ||
@@ -923,3 +944,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.resetStopWords(this.uid); | ||
url = "indexes/" + this.uid + "/settings/stop-words"; | ||
return [4 /*yield*/, this.httpRequest["delete"](url)]; | ||
@@ -945,3 +966,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.getRankingRules(this.uid); | ||
url = "indexes/" + this.uid + "/settings/ranking-rules"; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
@@ -964,3 +985,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.updateRankingRules(this.uid); | ||
url = "indexes/" + this.uid + "/settings/ranking-rules"; | ||
return [4 /*yield*/, this.httpRequest.post(url, rankingRules)]; | ||
@@ -983,3 +1004,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.resetRankingRules(this.uid); | ||
url = "indexes/" + this.uid + "/settings/ranking-rules"; | ||
return [4 /*yield*/, this.httpRequest["delete"](url)]; | ||
@@ -1005,3 +1026,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.getDistinctAttribute(this.uid); | ||
url = "indexes/" + this.uid + "/settings/distinct-attribute"; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
@@ -1024,3 +1045,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.updateDistinctAttribute(this.uid); | ||
url = "indexes/" + this.uid + "/settings/distinct-attribute"; | ||
return [4 /*yield*/, this.httpRequest.post(url, distinctAttribute)]; | ||
@@ -1043,3 +1064,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.resetDistinctAttribute(this.uid); | ||
url = "indexes/" + this.uid + "/settings/distinct-attribute"; | ||
return [4 /*yield*/, this.httpRequest["delete"](url)]; | ||
@@ -1065,3 +1086,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.getAttributesForFaceting(this.uid); | ||
url = "indexes/" + this.uid + "/settings/attributes-for-faceting"; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
@@ -1084,3 +1105,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.updateAttributesForFaceting(this.uid); | ||
url = "indexes/" + this.uid + "/settings/attributes-for-faceting"; | ||
return [4 /*yield*/, this.httpRequest.post(url, attributesForFaceting)]; | ||
@@ -1103,3 +1124,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.resetAttributesForFaceting(this.uid); | ||
url = "indexes/" + this.uid + "/settings/attributes-for-faceting"; | ||
return [4 /*yield*/, this.httpRequest["delete"](url)]; | ||
@@ -1125,3 +1146,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.getSearchableAttributes(this.uid); | ||
url = "indexes/" + this.uid + "/settings/searchable-attributes"; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
@@ -1144,3 +1165,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.updateSearchableAttributes(this.uid); | ||
url = "indexes/" + this.uid + "/settings/searchable-attributes"; | ||
return [4 /*yield*/, this.httpRequest.post(url, searchableAttributes)]; | ||
@@ -1163,3 +1184,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.resetSearchableAttributes(this.uid); | ||
url = "indexes/" + this.uid + "/settings/searchable-attributes"; | ||
return [4 /*yield*/, this.httpRequest["delete"](url)]; | ||
@@ -1185,3 +1206,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.getDisplayedAttributes(this.uid); | ||
url = "indexes/" + this.uid + "/settings/displayed-attributes"; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
@@ -1204,3 +1225,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.updateDisplayedAttributes(this.uid); | ||
url = "indexes/" + this.uid + "/settings/displayed-attributes"; | ||
return [4 /*yield*/, this.httpRequest.post(url, displayedAttributes)]; | ||
@@ -1223,3 +1244,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = Index.routeConstructors.resetDisplayedAttributes(this.uid); | ||
url = "indexes/" + this.uid + "/settings/displayed-attributes"; | ||
return [4 /*yield*/, this.httpRequest["delete"](url)]; | ||
@@ -1231,144 +1252,2 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
}; | ||
Index.apiRoutes = { | ||
indexes: 'indexes', | ||
}; | ||
Index.routeConstructors = { | ||
indexRoute: function (indexUid) { | ||
return Index.apiRoutes.indexes + "/" + indexUid; | ||
}, | ||
getUpdateStatus: function (indexUid, updateId) { | ||
return (Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
("updates/" + updateId)); | ||
}, | ||
getAllUpdateStatus: function (indexUid) { | ||
return Index.routeConstructors.indexRoute(indexUid) + '/' + "updates"; | ||
}, | ||
search: function (indexUid) { | ||
return Index.routeConstructors.indexRoute(indexUid) + '/' + "search"; | ||
}, | ||
getRawInfo: function (indexUid) { | ||
return "indexes/" + indexUid; | ||
}, | ||
update: function (indexUid) { | ||
return Index.routeConstructors.indexRoute(indexUid); | ||
}, | ||
"delete": function (indexUid) { | ||
return Index.routeConstructors.indexRoute(indexUid); | ||
}, | ||
getStats: function (indexUid) { | ||
return Index.routeConstructors.indexRoute(indexUid) + '/' + "stats"; | ||
}, | ||
getDocument: function (indexUid, documentId) { | ||
return (Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
("documents/" + documentId)); | ||
}, | ||
getDocuments: function (indexUid) { | ||
return Index.routeConstructors.indexRoute(indexUid) + '/' + "documents"; | ||
}, | ||
addDocuments: function (indexUid) { | ||
return Index.routeConstructors.getDocuments(indexUid); | ||
}, | ||
updateDocuments: function (indexUid) { | ||
return Index.routeConstructors.getDocuments(indexUid); | ||
}, | ||
deleteAllDocuments: function (indexUid) { | ||
return Index.routeConstructors.getDocuments(indexUid); | ||
}, | ||
deleteDocument: function (indexUid, documentId) { | ||
return (Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
("documents/" + documentId)); | ||
}, | ||
deleteDocuments: function (indexUid) { | ||
return (Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
"documents/delete-batch"); | ||
}, | ||
getSettings: function (indexUid) { | ||
return Index.routeConstructors.indexRoute(indexUid) + '/' + "settings"; | ||
}, | ||
updateSettings: function (indexUid) { | ||
return Index.routeConstructors.getSettings(indexUid); | ||
}, | ||
resetSettings: function (indexUid) { | ||
return Index.routeConstructors.getSettings(indexUid); | ||
}, | ||
getSynonyms: function (indexUid) { | ||
return (Index.routeConstructors.indexRoute(indexUid) + '/' + "settings/synonyms"); | ||
}, | ||
updateSynonyms: function (indexUid) { | ||
return Index.routeConstructors.getSynonyms(indexUid); | ||
}, | ||
resetSynonyms: function (indexUid) { | ||
return Index.routeConstructors.getSynonyms(indexUid); | ||
}, | ||
getStopWords: function (indexUid) { | ||
return (Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
"settings/stop-words"); | ||
}, | ||
updateStopWords: function (indexUid) { | ||
return Index.routeConstructors.getStopWords(indexUid); | ||
}, | ||
resetStopWords: function (indexUid) { | ||
return Index.routeConstructors.getStopWords(indexUid); | ||
}, | ||
getRankingRules: function (indexUid) { | ||
return (Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
"settings/ranking-rules"); | ||
}, | ||
updateRankingRules: function (indexUid) { | ||
return Index.routeConstructors.getRankingRules(indexUid); | ||
}, | ||
resetRankingRules: function (indexUid) { | ||
return Index.routeConstructors.getRankingRules(indexUid); | ||
}, | ||
getDistinctAttribute: function (indexUid) { | ||
return (Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
"settings/distinct-attribute"); | ||
}, | ||
updateDistinctAttribute: function (indexUid) { | ||
return Index.routeConstructors.getDistinctAttribute(indexUid); | ||
}, | ||
resetDistinctAttribute: function (indexUid) { | ||
return Index.routeConstructors.getDistinctAttribute(indexUid); | ||
}, | ||
getAttributesForFaceting: function (indexUid) { | ||
return (Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
"settings/attributes-for-faceting"); | ||
}, | ||
updateAttributesForFaceting: function (indexUid) { | ||
return Index.routeConstructors.getAttributesForFaceting(indexUid); | ||
}, | ||
resetAttributesForFaceting: function (indexUid) { | ||
return Index.routeConstructors.getAttributesForFaceting(indexUid); | ||
}, | ||
getSearchableAttributes: function (indexUid) { | ||
return (Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
"settings/searchable-attributes"); | ||
}, | ||
updateSearchableAttributes: function (indexUid) { | ||
return Index.routeConstructors.getSearchableAttributes(indexUid); | ||
}, | ||
resetSearchableAttributes: function (indexUid) { | ||
return Index.routeConstructors.getSearchableAttributes(indexUid); | ||
}, | ||
getDisplayedAttributes: function (indexUid) { | ||
return (Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
"settings/displayed-attributes"); | ||
}, | ||
updateDisplayedAttributes: function (indexUid) { | ||
return Index.routeConstructors.getDisplayedAttributes(indexUid); | ||
}, | ||
resetDisplayedAttributes: function (indexUid) { | ||
return Index.routeConstructors.getDisplayedAttributes(indexUid); | ||
}, | ||
}; | ||
return Index; | ||
@@ -1389,8 +1268,2 @@ }()); | ||
} | ||
MeiliSearch.getApiRoutes = function () { | ||
return MeiliSearch.apiRoutes; | ||
}; | ||
MeiliSearch.getRouteConstructors = function () { | ||
return MeiliSearch.routeConstructors; | ||
}; | ||
/** | ||
@@ -1456,3 +1329,3 @@ * Return an Index instance | ||
case 0: | ||
url = MeiliSearch.apiRoutes.listIndexes; | ||
url = "indexes"; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
@@ -1505,2 +1378,29 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
}; | ||
/** | ||
* Deletes an index if it already exists. | ||
* @memberof MeiliSearch | ||
* @method deleteIndexIfExists | ||
*/ | ||
MeiliSearch.prototype.deleteIndexIfExists = function (uid) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var e_2; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, this.deleteIndex(uid)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/, true]; | ||
case 2: | ||
e_2 = _a.sent(); | ||
if (e_2.errorCode === 'index_not_found') { | ||
return [2 /*return*/, false]; | ||
} | ||
throw e_2; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/// | ||
@@ -1520,3 +1420,3 @@ /// KEYS | ||
case 0: | ||
url = MeiliSearch.apiRoutes.getKeys; | ||
url = "keys"; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
@@ -1539,5 +1439,8 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.httpRequest.get(MeiliSearch.apiRoutes.health)]; | ||
case 0: | ||
url = "health"; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -1556,2 +1459,3 @@ } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url; | ||
return __generator(this, function (_a) { | ||
@@ -1561,3 +1465,4 @@ switch (_a.label) { | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, this.httpRequest.get(MeiliSearch.apiRoutes.health)]; | ||
url = "health"; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
case 1: | ||
@@ -1588,3 +1493,3 @@ _a.sent(); | ||
case 0: | ||
url = MeiliSearch.apiRoutes.stats; | ||
url = "stats"; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
@@ -1596,2 +1501,5 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
}; | ||
/// | ||
/// VERSION | ||
/// | ||
/** | ||
@@ -1608,3 +1516,3 @@ * Get the version of MeiliSearch | ||
case 0: | ||
url = MeiliSearch.apiRoutes.version; | ||
url = "version"; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
@@ -1630,3 +1538,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = MeiliSearch.apiRoutes.createDump; | ||
url = "dumps"; | ||
return [4 /*yield*/, this.httpRequest.post(url)]; | ||
@@ -1649,3 +1557,3 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
case 0: | ||
url = MeiliSearch.routeConstructors.getDumpStatus(dumpUid); | ||
url = "dumps/" + dumpUid + "/status"; | ||
return [4 /*yield*/, this.httpRequest.get(url)]; | ||
@@ -1657,15 +1565,2 @@ case 1: return [2 /*return*/, _a.sent()]; | ||
}; | ||
MeiliSearch.apiRoutes = { | ||
listIndexes: 'indexes', | ||
getKeys: 'keys', | ||
health: 'health', | ||
stats: 'stats', | ||
version: 'version', | ||
createDump: 'dumps', | ||
}; | ||
MeiliSearch.routeConstructors = { | ||
getDumpStatus: function (dumpUid) { | ||
return "dumps/" + dumpUid + "/status"; | ||
}, | ||
}; | ||
return MeiliSearch; | ||
@@ -1672,0 +1567,0 @@ }()); |
@@ -15,3 +15,3 @@ import"cross-fetch/polyfill"; | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(e,r)};function e(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var r=function(){return(r=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var u in e=arguments[r])Object.prototype.hasOwnProperty.call(e,u)&&(t[u]=e[u]);return t}).apply(this,arguments)};function n(t,e,r,n){return new(r||(r=Promise))((function(u,i){function o(t){try{c(n.next(t))}catch(t){i(t)}}function s(t){try{c(n.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?u(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,s)}c((n=n.apply(t,e||[])).next())}))}function u(t,e){var r,n,u,i,o={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(u=2&i[0]?n.return:i[0]?n.throw||((u=n.return)&&u.call(n),0):n.next)&&!(u=u.call(n,i[1])).done)return u;switch(n=0,u&&(i=[2&i[0],u.value]),i[0]){case 0:case 1:u=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,n=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!(u=o.trys,(u=u.length>0&&u[u.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!u||i[1]>u[0]&&i[1]<u[3])){o.label=i[1];break}if(6===i[0]&&o.label<u[1]){o.label=u[1],u=i;break}if(u&&o.label<u[2]){o.label=u[2],o.ops.push(i);break}u[2]&&o.ops.pop(),o.trys.pop();continue}i=e.call(t,o)}catch(t){i=[6,t],n=0}finally{r=u=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}var i=function(t){function r(e){var n=t.call(this,e)||this;return n.name="MeiliSearchError",n.type="MeiliSearchError",Error.captureStackTrace&&Error.captureStackTrace(n,r),n}return e(r,t),r}(Error),o=function(t){function r(e){var n=t.call(this,e)||this;return n.name="MeiliSearchTimeOutError",n.type=n.constructor.name,Error.captureStackTrace&&Error.captureStackTrace(n,r),n}return e(r,t),r}(Error);function s(t){return Object.entries(t).reduce((function(t,e){var r=e[0],n=e[1];return void 0!==n&&(t[r]=n),t}),{})}function c(t){return n(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,new Promise((function(e){return setTimeout(e,t)}))];case 1:return[2,e.sent()]}}))}))}var a=function(t){function r(e,n){var u=t.call(this,e)||this;return u.name="MeiliSearchCommunicationError",u.type="MeiliSearchCommunicationError",n instanceof Response&&(u.message=n.statusText,u.statusCode=n.status),n instanceof Error&&(u.errno=n.errno,u.code=n.code),Error.captureStackTrace&&Error.captureStackTrace(u,r),u}return e(r,t),r}(Error),h=function(t){function r(e,r){var n=t.call(this,e.message)||this;return n.type="MeiliSearchApiError",n.name="MeiliSearchApiError",n.errorCode=e.errorCode,n.errorType=e.errorType,n.errorLink=e.errorLink,n.message=e.message,n.httpStatus=r,Error.captureStackTrace&&Error.captureStackTrace(n,h),n}return e(r,t),r}(Error);var d=function(){function t(t){this.headers=r(r(r({},t.headers||{}),{"Content-Type":"application/json"}),t.apiKey?{"X-Meili-API-Key":t.apiKey}:{}),this.url=new URL(t.host)}return t.addTrailingSlash=function(t){return t.endsWith("/")||(t+="/"),t},t.prototype.request=function(t){var e=t.method,i=t.url,o=t.params,s=t.body,c=t.config;return n(this,void 0,void 0,(function(){var t,d,p;return u(this,(function(f){switch(f.label){case 0:return f.trys.push([0,3,,4]),t=new URL(i,this.url),o&&(d=new URLSearchParams,Object.keys(o).filter((function(t){return null!==o[t]})).map((function(t){return d.set(t,o[t])})),t.search=d.toString()),[4,fetch(t.toString(),r(r({},c),{method:e,body:s?JSON.stringify(s):void 0,headers:this.headers})).then((function(t){return function(t){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:if(t.ok)return[3,5];e=void 0,r.label=1;case 1:return r.trys.push([1,3,,4]),[4,t.json()];case 2:return e=r.sent(),[3,4];case 3:throw r.sent(),new a(t.statusText,t);case 4:throw new h(e,t.status);case 5:return[2,t]}}))}))}(t)}))];case 1:return[4,f.sent().text()];case 2:p=f.sent();try{return[2,JSON.parse(p)]}catch(t){return[2]}return[3,4];case 3:return function(t){if("MeiliSearchApiError"!==t.type)throw new a(t.message,t);throw t}(f.sent()),[3,4];case 4:return[2]}}))}))},t.prototype.get=function(t,e,r){return n(this,void 0,void 0,(function(){return u(this,(function(n){switch(n.label){case 0:return[4,this.request({method:"GET",url:t,params:e,config:r})];case 1:return[2,n.sent()]}}))}))},t.prototype.post=function(t,e,r,i){return n(this,void 0,void 0,(function(){return u(this,(function(n){switch(n.label){case 0:return[4,this.request({method:"POST",url:t,body:e,params:r,config:i})];case 1:return[2,n.sent()]}}))}))},t.prototype.put=function(t,e,r,i){return n(this,void 0,void 0,(function(){return u(this,(function(n){switch(n.label){case 0:return[4,this.request({method:"PUT",url:t,body:e,params:r,config:i})];case 1:return[2,n.sent()]}}))}))},t.prototype.delete=function(t,e,r,i){return n(this,void 0,void 0,(function(){return u(this,(function(n){switch(n.label){case 0:return[4,this.request({method:"DELETE",url:t,body:e,params:r,config:i})];case 1:return[2,n.sent()]}}))}))},t}(),p=function(){function t(t,e,r){this.uid=e,this.primaryKey=r,this.httpRequest=new d(t)}return t.getApiRoutes=function(){return t.apiRoutes},t.getRouteConstructors=function(){return t.routeConstructors},t.prototype.getUpdateStatus=function(e){return n(this,void 0,void 0,(function(){var r;return u(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.getUpdateStatus(this.uid,e),[4,this.httpRequest.get(r)];case 1:return[2,n.sent()]}}))}))},t.prototype.waitForPendingUpdate=function(t,e){var r=void 0===e?{}:e,i=r.timeOutMs,s=void 0===i?5e3:i,a=r.intervalMs,h=void 0===a?50:a;return n(this,void 0,void 0,(function(){var e,r;return u(this,(function(n){switch(n.label){case 0:e=Date.now(),n.label=1;case 1:return Date.now()-e<s?[4,this.getUpdateStatus(t)]:[3,4];case 2:return"enqueued"!==(r=n.sent()).status?[2,r]:[4,c(h)];case 3:return n.sent(),[3,1];case 4:throw new o("timeout of "+s+"ms has exceeded on process "+t+" when waiting for pending update to resolve.")}}))}))},t.prototype.getAllUpdateStatus=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getAllUpdateStatus(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.search=function(e,o,c,a){return void 0===c&&(c="POST"),n(this,void 0,void 0,(function(){var n,h,d;return u(this,(function(u){switch(u.label){case 0:return n=t.routeConstructors.search(this.uid),h={q:e,offset:null==o?void 0:o.offset,limit:null==o?void 0:o.limit,cropLength:null==o?void 0:o.cropLength,filters:null==o?void 0:o.filters,matches:null==o?void 0:o.matches,facetFilters:null==o?void 0:o.facetFilters,facetsDistribution:null==o?void 0:o.facetsDistribution,attributesToRetrieve:null==o?void 0:o.attributesToRetrieve,attributesToCrop:null==o?void 0:o.attributesToCrop,attributesToHighlight:null==o?void 0:o.attributesToHighlight},"POST"!==c.toUpperCase()?[3,2]:[4,this.httpRequest.post(n,s(h),void 0,a)];case 1:return[2,u.sent()];case 2:return"GET"!==c.toUpperCase()?[3,4]:(d=r(r({},h),{facetFilters:Array.isArray(null==o?void 0:o.facetFilters)&&(null==o?void 0:o.facetFilters)?JSON.stringify(o.facetFilters):void 0,facetsDistribution:(null==o?void 0:o.facetsDistribution)?JSON.stringify(o.facetsDistribution):void 0,attributesToRetrieve:(null==o?void 0:o.attributesToRetrieve)?o.attributesToRetrieve.join(","):void 0,attributesToCrop:(null==o?void 0:o.attributesToCrop)?o.attributesToCrop.join(","):void 0,attributesToHighlight:(null==o?void 0:o.attributesToHighlight)?o.attributesToHighlight.join(","):void 0}),[4,this.httpRequest.get(n,s(d),a)]);case 3:return[2,u.sent()];case 4:throw new i("method parameter should be either POST or GET")}}))}))},t.prototype.getRawInfo=function(){return n(this,void 0,void 0,(function(){var e,r;return u(this,(function(n){switch(n.label){case 0:return e=t.routeConstructors.indexRoute(this.uid),[4,this.httpRequest.get(e)];case 1:return r=n.sent(),this.primaryKey=r.primaryKey,[2,r]}}))}))},t.prototype.fetchInfo=function(){return n(this,void 0,void 0,(function(){return u(this,(function(t){switch(t.label){case 0:return[4,this.getRawInfo()];case 1:return t.sent(),[2,this]}}))}))},t.prototype.fetchPrimaryKey=function(){return n(this,void 0,void 0,(function(){var t;return u(this,(function(e){switch(e.label){case 0:return t=this,[4,this.getRawInfo()];case 1:return t.primaryKey=e.sent().primaryKey,[2,this.primaryKey]}}))}))},t.create=function(e,i,o){return void 0===o&&(o={}),n(this,void 0,void 0,(function(){var n,s;return u(this,(function(u){switch(u.label){case 0:return n=t.apiRoutes.indexes,[4,new d(e).post(n,r(r({},o),{uid:i}))];case 1:return s=u.sent(),[2,new t(e,i,s.primaryKey)]}}))}))},t.prototype.update=function(e){return n(this,void 0,void 0,(function(){var r,n;return u(this,(function(u){switch(u.label){case 0:return r=t.routeConstructors.update(this.uid),[4,this.httpRequest.put(r,e)];case 1:return n=u.sent(),this.primaryKey=n.primaryKey,[2,this]}}))}))},t.prototype.delete=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.delete(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getStats=function(){return n(this,void 0,void 0,(function(){var t;return u(this,(function(e){switch(e.label){case 0:return t="/indexes/"+this.uid+"/stats",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDocuments=function(e){return n(this,void 0,void 0,(function(){var n,i;return u(this,(function(u){switch(u.label){case 0:return n=t.routeConstructors.getDocuments(this.uid),void 0!==e&&Array.isArray(e.attributesToRetrieve)&&(i=e.attributesToRetrieve.join(",")),[4,this.httpRequest.get(n,r(r({},e),void 0!==i?{attributesToRetrieve:i}:{}))];case 1:return[2,u.sent()]}}))}))},t.prototype.getDocument=function(e){return n(this,void 0,void 0,(function(){var r;return u(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.getDocument(this.uid,e),[4,this.httpRequest.get(r)];case 1:return[2,n.sent()]}}))}))},t.prototype.addDocuments=function(e,r){return n(this,void 0,void 0,(function(){var n;return u(this,(function(u){switch(u.label){case 0:return n=t.routeConstructors.addDocuments(this.uid),[4,this.httpRequest.post(n,e,r)];case 1:return[2,u.sent()]}}))}))},t.prototype.updateDocuments=function(e,r){return n(this,void 0,void 0,(function(){var n;return u(this,(function(u){switch(u.label){case 0:return n=t.routeConstructors.updateDocuments(this.uid),[4,this.httpRequest.put(n,e,r)];case 1:return[2,u.sent()]}}))}))},t.prototype.deleteDocument=function(e){return n(this,void 0,void 0,(function(){var r;return u(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.deleteDocument(this.uid,e),[4,this.httpRequest.delete(r)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteDocuments=function(e){return n(this,void 0,void 0,(function(){var r;return u(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.deleteDocuments(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteAllDocuments=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.deleteAllDocuments(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getSettings=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getSettings(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateSettings=function(e){return n(this,void 0,void 0,(function(){var r;return u(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateSettings(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSettings=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetSettings(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getSynonyms=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getSynonyms(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateSynonyms=function(e){return n(this,void 0,void 0,(function(){var r;return u(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateSynonyms(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSynonyms=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetSynonyms(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getStopWords=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getStopWords(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateStopWords=function(e){return n(this,void 0,void 0,(function(){var r;return u(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateStopWords(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetStopWords=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetStopWords(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getRankingRules=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getRankingRules(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateRankingRules=function(e){return n(this,void 0,void 0,(function(){var r;return u(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateRankingRules(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetRankingRules=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetRankingRules(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getDistinctAttribute=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getDistinctAttribute(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateDistinctAttribute=function(e){return n(this,void 0,void 0,(function(){var r;return u(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateDistinctAttribute(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetDistinctAttribute=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetDistinctAttribute(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getAttributesForFaceting=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getAttributesForFaceting(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateAttributesForFaceting=function(e){return n(this,void 0,void 0,(function(){var r;return u(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateAttributesForFaceting(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetAttributesForFaceting=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetAttributesForFaceting(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getSearchableAttributes=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getSearchableAttributes(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateSearchableAttributes=function(e){return n(this,void 0,void 0,(function(){var r;return u(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateSearchableAttributes(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSearchableAttributes=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetSearchableAttributes(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getDisplayedAttributes=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getDisplayedAttributes(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateDisplayedAttributes=function(e){return n(this,void 0,void 0,(function(){var r;return u(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateDisplayedAttributes(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetDisplayedAttributes=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetDisplayedAttributes(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.apiRoutes={indexes:"indexes"},t.routeConstructors={indexRoute:function(e){return t.apiRoutes.indexes+"/"+e},getUpdateStatus:function(e,r){return t.routeConstructors.indexRoute(e)+"/updates/"+r},getAllUpdateStatus:function(e){return t.routeConstructors.indexRoute(e)+"/updates"},search:function(e){return t.routeConstructors.indexRoute(e)+"/search"},getRawInfo:function(t){return"indexes/"+t},update:function(e){return t.routeConstructors.indexRoute(e)},delete:function(e){return t.routeConstructors.indexRoute(e)},getStats:function(e){return t.routeConstructors.indexRoute(e)+"/stats"},getDocument:function(e,r){return t.routeConstructors.indexRoute(e)+"/documents/"+r},getDocuments:function(e){return t.routeConstructors.indexRoute(e)+"/documents"},addDocuments:function(e){return t.routeConstructors.getDocuments(e)},updateDocuments:function(e){return t.routeConstructors.getDocuments(e)},deleteAllDocuments:function(e){return t.routeConstructors.getDocuments(e)},deleteDocument:function(e,r){return t.routeConstructors.indexRoute(e)+"/documents/"+r},deleteDocuments:function(e){return t.routeConstructors.indexRoute(e)+"/documents/delete-batch"},getSettings:function(e){return t.routeConstructors.indexRoute(e)+"/settings"},updateSettings:function(e){return t.routeConstructors.getSettings(e)},resetSettings:function(e){return t.routeConstructors.getSettings(e)},getSynonyms:function(e){return t.routeConstructors.indexRoute(e)+"/settings/synonyms"},updateSynonyms:function(e){return t.routeConstructors.getSynonyms(e)},resetSynonyms:function(e){return t.routeConstructors.getSynonyms(e)},getStopWords:function(e){return t.routeConstructors.indexRoute(e)+"/settings/stop-words"},updateStopWords:function(e){return t.routeConstructors.getStopWords(e)},resetStopWords:function(e){return t.routeConstructors.getStopWords(e)},getRankingRules:function(e){return t.routeConstructors.indexRoute(e)+"/settings/ranking-rules"},updateRankingRules:function(e){return t.routeConstructors.getRankingRules(e)},resetRankingRules:function(e){return t.routeConstructors.getRankingRules(e)},getDistinctAttribute:function(e){return t.routeConstructors.indexRoute(e)+"/settings/distinct-attribute"},updateDistinctAttribute:function(e){return t.routeConstructors.getDistinctAttribute(e)},resetDistinctAttribute:function(e){return t.routeConstructors.getDistinctAttribute(e)},getAttributesForFaceting:function(e){return t.routeConstructors.indexRoute(e)+"/settings/attributes-for-faceting"},updateAttributesForFaceting:function(e){return t.routeConstructors.getAttributesForFaceting(e)},resetAttributesForFaceting:function(e){return t.routeConstructors.getAttributesForFaceting(e)},getSearchableAttributes:function(e){return t.routeConstructors.indexRoute(e)+"/settings/searchable-attributes"},updateSearchableAttributes:function(e){return t.routeConstructors.getSearchableAttributes(e)},resetSearchableAttributes:function(e){return t.routeConstructors.getSearchableAttributes(e)},getDisplayedAttributes:function(e){return t.routeConstructors.indexRoute(e)+"/settings/displayed-attributes"},updateDisplayedAttributes:function(e){return t.routeConstructors.getDisplayedAttributes(e)},resetDisplayedAttributes:function(e){return t.routeConstructors.getDisplayedAttributes(e)}},t}(),f=function(){function t(t){t.host=d.addTrailingSlash(t.host),this.config=t,this.httpRequest=new d(t)}return t.getApiRoutes=function(){return t.apiRoutes},t.getRouteConstructors=function(){return t.routeConstructors},t.prototype.index=function(t){return new p(this.config,t)},t.prototype.getIndex=function(t){return n(this,void 0,void 0,(function(){return u(this,(function(e){return[2,new p(this.config,t).fetchInfo()]}))}))},t.prototype.getOrCreateIndex=function(t,e){return void 0===e&&(e={}),n(this,void 0,void 0,(function(){var r;return u(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.getIndex(t)];case 1:return[2,n.sent()];case 2:if("index_not_found"===(r=n.sent()).errorCode)return[2,this.createIndex(t,e)];throw new h(r,r.status);case 3:return[2]}}))}))},t.prototype.listIndexes=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.listIndexes,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.createIndex=function(t,e){return void 0===e&&(e={}),n(this,void 0,void 0,(function(){return u(this,(function(r){switch(r.label){case 0:return[4,p.create(this.config,t,e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateIndex=function(t,e){return void 0===e&&(e={}),n(this,void 0,void 0,(function(){return u(this,(function(r){return[2,new p(this.config,t).update(e)]}))}))},t.prototype.deleteIndex=function(t){return n(this,void 0,void 0,(function(){return u(this,(function(e){return[2,new p(this.config,t).delete()]}))}))},t.prototype.getKeys=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.getKeys,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.health=function(){return n(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,this.httpRequest.get(t.apiRoutes.health)];case 1:return[2,e.sent()]}}))}))},t.prototype.isHealthy=function(){return n(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.httpRequest.get(t.apiRoutes.health)];case 1:return e.sent(),[2,!0];case 2:return e.sent(),[2,!1];case 3:return[2]}}))}))},t.prototype.stats=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.stats,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.version=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.version,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.createDump=function(){return n(this,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.createDump,[4,this.httpRequest.post(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getDumpStatus=function(e){return n(this,void 0,void 0,(function(){var r;return u(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.getDumpStatus(e),[4,this.httpRequest.get(r)];case 1:return[2,n.sent()]}}))}))},t.apiRoutes={listIndexes:"indexes",getKeys:"keys",health:"health",stats:"stats",version:"version",createDump:"dumps"},t.routeConstructors={getDumpStatus:function(t){return"dumps/"+t+"/status"}},t}();export{f as MeiliSearch}; | ||
***************************************************************************** */var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(e,n)};function e(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return(n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function r(t,e,n,r){return new(n||(n=Promise))((function(i,s){function u(t){try{c(r.next(t))}catch(t){s(t)}}function o(t){try{c(r.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,o)}c((r=r.apply(t,e||[])).next())}))}function i(t,e){var n,r,i,s,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function o(s){return function(o){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return u.label++,{value:s[1],done:!1};case 5:u.label++,r=s[1],s=[0];continue;case 7:s=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){u=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){u.label=s[1];break}if(6===s[0]&&u.label<i[1]){u.label=i[1],i=s;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(s);break}i[2]&&u.ops.pop(),u.trys.pop();continue}s=e.call(t,u)}catch(t){s=[6,t],r=0}finally{n=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,o])}}}var s=function(t){function n(e){var r=t.call(this,e)||this;return r.name="MeiliSearchError",r.type="MeiliSearchError",Error.captureStackTrace&&Error.captureStackTrace(r,n),r}return e(n,t),n}(Error),u=function(t){function n(e){var r=t.call(this,e)||this;return r.name="MeiliSearchTimeOutError",r.type=r.constructor.name,Error.captureStackTrace&&Error.captureStackTrace(r,n),r}return e(n,t),n}(Error);function o(t){return Object.entries(t).reduce((function(t,e){var n=e[0],r=e[1];return void 0!==r&&(t[n]=r),t}),{})}function c(t){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,new Promise((function(e){return setTimeout(e,t)}))];case 1:return[2,e.sent()]}}))}))}var a=function(t){function n(e,r){var i=t.call(this,e)||this;return i.name="MeiliSearchCommunicationError",i.type="MeiliSearchCommunicationError",r instanceof Response&&(i.message=r.statusText,i.statusCode=r.status),r instanceof Error&&(i.errno=r.errno,i.code=r.code),Error.captureStackTrace&&Error.captureStackTrace(i,n),i}return e(n,t),n}(Error),h=function(t){function n(e,n){var r=t.call(this,e.message)||this;return r.type="MeiliSearchApiError",r.name="MeiliSearchApiError",r.errorCode=e.errorCode,r.errorType=e.errorType,r.errorLink=e.errorLink,r.message=e.message,r.httpStatus=n,Error.captureStackTrace&&Error.captureStackTrace(r,h),r}return e(n,t),n}(Error);var d=function(){function t(t){this.headers=n(n(n({},t.headers||{}),{"Content-Type":"application/json"}),t.apiKey?{"X-Meili-API-Key":t.apiKey}:{}),this.url=new URL(t.host)}return t.addTrailingSlash=function(t){return t.endsWith("/")||(t+="/"),t},t.prototype.request=function(t){var e=t.method,s=t.url,u=t.params,o=t.body,c=t.config;return r(this,void 0,void 0,(function(){var t,d,p;return i(this,(function(f){switch(f.label){case 0:return f.trys.push([0,3,,4]),t=new URL(s,this.url),u&&(d=new URLSearchParams,Object.keys(u).filter((function(t){return null!==u[t]})).map((function(t){return d.set(t,u[t])})),t.search=d.toString()),[4,fetch(t.toString(),n(n({},c),{method:e,body:JSON.stringify(o),headers:this.headers})).then((function(t){return function(t){return r(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:if(t.ok)return[3,5];e=void 0,n.label=1;case 1:return n.trys.push([1,3,,4]),[4,t.json()];case 2:return e=n.sent(),[3,4];case 3:throw n.sent(),new a(t.statusText,t);case 4:throw new h(e,t.status);case 5:return[2,t]}}))}))}(t)}))];case 1:return[4,f.sent().text()];case 2:p=f.sent();try{return[2,JSON.parse(p)]}catch(t){return[2]}return[3,4];case 3:return function(t){if("MeiliSearchApiError"!==t.type)throw new a(t.message,t);throw t}(f.sent()),[3,4];case 4:return[2]}}))}))},t.prototype.get=function(t,e,n){return r(this,void 0,void 0,(function(){return i(this,(function(r){switch(r.label){case 0:return[4,this.request({method:"GET",url:t,params:e,config:n})];case 1:return[2,r.sent()]}}))}))},t.prototype.post=function(t,e,n,s){return r(this,void 0,void 0,(function(){return i(this,(function(r){switch(r.label){case 0:return[4,this.request({method:"POST",url:t,body:e,params:n,config:s})];case 1:return[2,r.sent()]}}))}))},t.prototype.put=function(t,e,n,s){return r(this,void 0,void 0,(function(){return i(this,(function(r){switch(r.label){case 0:return[4,this.request({method:"PUT",url:t,body:e,params:n,config:s})];case 1:return[2,r.sent()]}}))}))},t.prototype.delete=function(t,e,n,s){return r(this,void 0,void 0,(function(){return i(this,(function(r){switch(r.label){case 0:return[4,this.request({method:"DELETE",url:t,body:e,params:n,config:s})];case 1:return[2,r.sent()]}}))}))},t}(),p=function(){function t(t,e,n){this.uid=e,this.primaryKey=n,this.httpRequest=new d(t)}return t.prototype.waitForPendingUpdate=function(t,e){var n=void 0===e?{}:e,s=n.timeOutMs,o=void 0===s?5e3:s,a=n.intervalMs,h=void 0===a?50:a;return r(this,void 0,void 0,(function(){var e,n;return i(this,(function(r){switch(r.label){case 0:e=Date.now(),r.label=1;case 1:return Date.now()-e<o?[4,this.getUpdateStatus(t)]:[3,4];case 2:return"enqueued"!==(n=r.sent()).status?[2,n]:[4,c(h)];case 3:return r.sent(),[3,1];case 4:throw new u("timeout of "+o+"ms has exceeded on process "+t+" when waiting for pending update to resolve.")}}))}))},t.prototype.search=function(t,e,u,c){return void 0===u&&(u="POST"),r(this,void 0,void 0,(function(){var r,a,h;return i(this,(function(i){switch(i.label){case 0:return r="indexes/"+this.uid+"/search",a={q:t,offset:null==e?void 0:e.offset,limit:null==e?void 0:e.limit,cropLength:null==e?void 0:e.cropLength,filters:null==e?void 0:e.filters,matches:null==e?void 0:e.matches,facetFilters:null==e?void 0:e.facetFilters,facetsDistribution:null==e?void 0:e.facetsDistribution,attributesToRetrieve:null==e?void 0:e.attributesToRetrieve,attributesToCrop:null==e?void 0:e.attributesToCrop,attributesToHighlight:null==e?void 0:e.attributesToHighlight},"POST"!==u.toUpperCase()?[3,2]:[4,this.httpRequest.post(r,o(a),void 0,c)];case 1:return[2,i.sent()];case 2:return"GET"!==u.toUpperCase()?[3,4]:(h=n(n({},a),{facetFilters:Array.isArray(null==e?void 0:e.facetFilters)&&(null==e?void 0:e.facetFilters)?JSON.stringify(e.facetFilters):void 0,facetsDistribution:(null==e?void 0:e.facetsDistribution)?JSON.stringify(e.facetsDistribution):void 0,attributesToRetrieve:(null==e?void 0:e.attributesToRetrieve)?e.attributesToRetrieve.join(","):void 0,attributesToCrop:(null==e?void 0:e.attributesToCrop)?e.attributesToCrop.join(","):void 0,attributesToHighlight:(null==e?void 0:e.attributesToHighlight)?e.attributesToHighlight.join(","):void 0}),[4,this.httpRequest.get(r,o(h),c)]);case 3:return[2,i.sent()];case 4:throw new s("method parameter should be either POST or GET")}}))}))},t.prototype.getRawInfo=function(){return r(this,void 0,void 0,(function(){var t,e;return i(this,(function(n){switch(n.label){case 0:return t="indexes/"+this.uid,[4,this.httpRequest.get(t)];case 1:return e=n.sent(),this.primaryKey=e.primaryKey,[2,e]}}))}))},t.prototype.fetchInfo=function(){return r(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.getRawInfo()];case 1:return t.sent(),[2,this]}}))}))},t.prototype.fetchPrimaryKey=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t=this,[4,this.getRawInfo()];case 1:return t.primaryKey=e.sent().primaryKey,[2,this.primaryKey]}}))}))},t.create=function(e,s,u){return void 0===u&&(u={}),r(this,void 0,void 0,(function(){var r;return i(this,(function(i){switch(i.label){case 0:return"indexes",[4,new d(e).post("indexes",n(n({},u),{uid:s}))];case 1:return r=i.sent(),[2,new t(e,s,r.primaryKey)]}}))}))},t.prototype.update=function(t){return r(this,void 0,void 0,(function(){var e,n;return i(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid,[4,this.httpRequest.put(e,t)];case 1:return n=r.sent(),this.primaryKey=n.primaryKey,[2,this]}}))}))},t.prototype.delete=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid,[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.deleteIfExists=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.delete()];case 1:return e.sent(),[2,!0];case 2:if("index_not_found"===(t=e.sent()).errorCode)return[2,!1];throw t;case 3:return[2]}}))}))},t.prototype.getAllUpdateStatus=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/updates",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getUpdateStatus=function(t){return r(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/updates/"+t,[4,this.httpRequest.get(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.getStats=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/stats",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDocuments=function(t){return r(this,void 0,void 0,(function(){var e,r;return i(this,(function(i){switch(i.label){case 0:return e="indexes/"+this.uid+"/documents",void 0!==t&&Array.isArray(t.attributesToRetrieve)&&(r=t.attributesToRetrieve.join(",")),[4,this.httpRequest.get(e,n(n({},t),void 0!==r?{attributesToRetrieve:r}:{}))];case 1:return[2,i.sent()]}}))}))},t.prototype.getDocument=function(t){return r(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/documents/"+t,[4,this.httpRequest.get(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.addDocuments=function(t,e){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return n="indexes/"+this.uid+"/documents",[4,this.httpRequest.post(n,t,e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateDocuments=function(t,e){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return n="indexes/"+this.uid+"/documents",[4,this.httpRequest.put(n,t,e)];case 1:return[2,r.sent()]}}))}))},t.prototype.deleteDocument=function(t){return r(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/documents/"+t,[4,this.httpRequest.delete(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteDocuments=function(t){return r(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/documents/delete-batch",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteAllDocuments=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/documents",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSettings=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSettings=function(t){return r(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/settings",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSettings=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSynonyms=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/synonyms",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSynonyms=function(t){return r(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/settings/synonyms",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSynonyms=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/synonyms",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getStopWords=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/stop-words",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateStopWords=function(t){return r(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/settings/stop-words",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetStopWords=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/stop-words",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getRankingRules=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/ranking-rules",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateRankingRules=function(t){return r(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/settings/ranking-rules",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetRankingRules=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/ranking-rules",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDistinctAttribute=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/distinct-attribute",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateDistinctAttribute=function(t){return r(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/settings/distinct-attribute",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetDistinctAttribute=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/distinct-attribute",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getAttributesForFaceting=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/attributes-for-faceting",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateAttributesForFaceting=function(t){return r(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/settings/attributes-for-faceting",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetAttributesForFaceting=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/attributes-for-faceting",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSearchableAttributes=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/searchable-attributes",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSearchableAttributes=function(t){return r(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/settings/searchable-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSearchableAttributes=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/searchable-attributes",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDisplayedAttributes=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/displayed-attributes",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateDisplayedAttributes=function(t){return r(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/settings/displayed-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetDisplayedAttributes=function(){return r(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/displayed-attributes",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t}(),f=function(){function t(t){t.host=d.addTrailingSlash(t.host),this.config=t,this.httpRequest=new d(t)}return t.prototype.index=function(t){return new p(this.config,t)},t.prototype.getIndex=function(t){return r(this,void 0,void 0,(function(){return i(this,(function(e){return[2,new p(this.config,t).fetchInfo()]}))}))},t.prototype.getOrCreateIndex=function(t,e){return void 0===e&&(e={}),r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.getIndex(t)];case 1:return[2,r.sent()];case 2:if("index_not_found"===(n=r.sent()).errorCode)return[2,this.createIndex(t,e)];throw new h(n,n.status);case 3:return[2]}}))}))},t.prototype.listIndexes=function(){return r(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return"indexes",[4,this.httpRequest.get("indexes")];case 1:return[2,t.sent()]}}))}))},t.prototype.createIndex=function(t,e){return void 0===e&&(e={}),r(this,void 0,void 0,(function(){return i(this,(function(n){switch(n.label){case 0:return[4,p.create(this.config,t,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.updateIndex=function(t,e){return void 0===e&&(e={}),r(this,void 0,void 0,(function(){return i(this,(function(n){return[2,new p(this.config,t).update(e)]}))}))},t.prototype.deleteIndex=function(t){return r(this,void 0,void 0,(function(){return i(this,(function(e){return[2,new p(this.config,t).delete()]}))}))},t.prototype.deleteIndexIfExists=function(t){return r(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.deleteIndex(t)];case 1:return n.sent(),[2,!0];case 2:if("index_not_found"===(e=n.sent()).errorCode)return[2,!1];throw e;case 3:return[2]}}))}))},t.prototype.getKeys=function(){return r(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return"keys",[4,this.httpRequest.get("keys")];case 1:return[2,t.sent()]}}))}))},t.prototype.health=function(){return r(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return"health",[4,this.httpRequest.get("health")];case 1:return[2,t.sent()]}}))}))},t.prototype.isHealthy=function(){return r(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),"health",[4,this.httpRequest.get("health")];case 1:return t.sent(),[2,!0];case 2:return t.sent(),[2,!1];case 3:return[2]}}))}))},t.prototype.stats=function(){return r(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return"stats",[4,this.httpRequest.get("stats")];case 1:return[2,t.sent()]}}))}))},t.prototype.version=function(){return r(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return"version",[4,this.httpRequest.get("version")];case 1:return[2,t.sent()]}}))}))},t.prototype.createDump=function(){return r(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return"dumps",[4,this.httpRequest.post("dumps")];case 1:return[2,t.sent()]}}))}))},t.prototype.getDumpStatus=function(t){return r(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return e="dumps/"+t+"/status",[4,this.httpRequest.get(e)];case 1:return[2,n.sent()]}}))}))},t}();export{f as MeiliSearch}; | ||
//# sourceMappingURL=meilisearch.esm.min.js.map |
@@ -15,3 +15,3 @@ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("cross-fetch/polyfill")):"function"==typeof define&&define.amd?define(["exports","cross-fetch/polyfill"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).window=t.window||{})}(this,(function(t){"use strict"; | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,r)};function r(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var n=function(){return(n=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function i(t,e,r,n){return new(r||(r=Promise))((function(i,o){function u(t){try{c(n.next(t))}catch(t){o(t)}}function s(t){try{c(n.throw(t))}catch(t){o(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(u,s)}c((n=n.apply(t,e||[])).next())}))}function o(t,e){var r,n,i,o,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return u.label++,{value:o[1],done:!1};case 5:u.label++,n=o[1],o=[0];continue;case 7:o=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){u=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){u.label=o[1];break}if(6===o[0]&&u.label<i[1]){u.label=i[1],i=o;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(o);break}i[2]&&u.ops.pop(),u.trys.pop();continue}o=e.call(t,u)}catch(t){o=[6,t],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}var u=function(t){function e(r){var n=t.call(this,r)||this;return n.name="MeiliSearchError",n.type="MeiliSearchError",Error.captureStackTrace&&Error.captureStackTrace(n,e),n}return r(e,t),e}(Error),s=function(t){function e(r){var n=t.call(this,r)||this;return n.name="MeiliSearchTimeOutError",n.type=n.constructor.name,Error.captureStackTrace&&Error.captureStackTrace(n,e),n}return r(e,t),e}(Error);function c(t){return Object.entries(t).reduce((function(t,e){var r=e[0],n=e[1];return void 0!==n&&(t[r]=n),t}),{})}function a(t){return i(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,new Promise((function(e){return setTimeout(e,t)}))];case 1:return[2,e.sent()]}}))}))}var h=function(t){function e(r,n){var i=t.call(this,r)||this;return i.name="MeiliSearchCommunicationError",i.type="MeiliSearchCommunicationError",n instanceof Response&&(i.message=n.statusText,i.statusCode=n.status),n instanceof Error&&(i.errno=n.errno,i.code=n.code),Error.captureStackTrace&&Error.captureStackTrace(i,e),i}return r(e,t),e}(Error),d=function(t){function e(e,r){var n=t.call(this,e.message)||this;return n.type="MeiliSearchApiError",n.name="MeiliSearchApiError",n.errorCode=e.errorCode,n.errorType=e.errorType,n.errorLink=e.errorLink,n.message=e.message,n.httpStatus=r,Error.captureStackTrace&&Error.captureStackTrace(n,d),n}return r(e,t),e}(Error);var p=function(){function t(t){this.headers=n(n(n({},t.headers||{}),{"Content-Type":"application/json"}),t.apiKey?{"X-Meili-API-Key":t.apiKey}:{}),this.url=new URL(t.host)}return t.addTrailingSlash=function(t){return t.endsWith("/")||(t+="/"),t},t.prototype.request=function(t){var e=t.method,r=t.url,u=t.params,s=t.body,c=t.config;return i(this,void 0,void 0,(function(){var t,a,p;return o(this,(function(f){switch(f.label){case 0:return f.trys.push([0,3,,4]),t=new URL(r,this.url),u&&(a=new URLSearchParams,Object.keys(u).filter((function(t){return null!==u[t]})).map((function(t){return a.set(t,u[t])})),t.search=a.toString()),[4,fetch(t.toString(),n(n({},c),{method:e,body:s?JSON.stringify(s):void 0,headers:this.headers})).then((function(t){return function(t){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:if(t.ok)return[3,5];e=void 0,r.label=1;case 1:return r.trys.push([1,3,,4]),[4,t.json()];case 2:return e=r.sent(),[3,4];case 3:throw r.sent(),new h(t.statusText,t);case 4:throw new d(e,t.status);case 5:return[2,t]}}))}))}(t)}))];case 1:return[4,f.sent().text()];case 2:p=f.sent();try{return[2,JSON.parse(p)]}catch(t){return[2]}return[3,4];case 3:return function(t){if("MeiliSearchApiError"!==t.type)throw new h(t.message,t);throw t}(f.sent()),[3,4];case 4:return[2]}}))}))},t.prototype.get=function(t,e,r){return i(this,void 0,void 0,(function(){return o(this,(function(n){switch(n.label){case 0:return[4,this.request({method:"GET",url:t,params:e,config:r})];case 1:return[2,n.sent()]}}))}))},t.prototype.post=function(t,e,r,n){return i(this,void 0,void 0,(function(){return o(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"POST",url:t,body:e,params:r,config:n})];case 1:return[2,i.sent()]}}))}))},t.prototype.put=function(t,e,r,n){return i(this,void 0,void 0,(function(){return o(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"PUT",url:t,body:e,params:r,config:n})];case 1:return[2,i.sent()]}}))}))},t.prototype.delete=function(t,e,r,n){return i(this,void 0,void 0,(function(){return o(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"DELETE",url:t,body:e,params:r,config:n})];case 1:return[2,i.sent()]}}))}))},t}(),f=function(){function t(t,e,r){this.uid=e,this.primaryKey=r,this.httpRequest=new p(t)}return t.getApiRoutes=function(){return t.apiRoutes},t.getRouteConstructors=function(){return t.routeConstructors},t.prototype.getUpdateStatus=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.getUpdateStatus(this.uid,e),[4,this.httpRequest.get(r)];case 1:return[2,n.sent()]}}))}))},t.prototype.waitForPendingUpdate=function(t,e){var r=void 0===e?{}:e,n=r.timeOutMs,u=void 0===n?5e3:n,c=r.intervalMs,h=void 0===c?50:c;return i(this,void 0,void 0,(function(){var e,r;return o(this,(function(n){switch(n.label){case 0:e=Date.now(),n.label=1;case 1:return Date.now()-e<u?[4,this.getUpdateStatus(t)]:[3,4];case 2:return"enqueued"!==(r=n.sent()).status?[2,r]:[4,a(h)];case 3:return n.sent(),[3,1];case 4:throw new s("timeout of "+u+"ms has exceeded on process "+t+" when waiting for pending update to resolve.")}}))}))},t.prototype.getAllUpdateStatus=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getAllUpdateStatus(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.search=function(e,r,s,a){return void 0===s&&(s="POST"),i(this,void 0,void 0,(function(){var i,h,d;return o(this,(function(o){switch(o.label){case 0:return i=t.routeConstructors.search(this.uid),h={q:e,offset:null==r?void 0:r.offset,limit:null==r?void 0:r.limit,cropLength:null==r?void 0:r.cropLength,filters:null==r?void 0:r.filters,matches:null==r?void 0:r.matches,facetFilters:null==r?void 0:r.facetFilters,facetsDistribution:null==r?void 0:r.facetsDistribution,attributesToRetrieve:null==r?void 0:r.attributesToRetrieve,attributesToCrop:null==r?void 0:r.attributesToCrop,attributesToHighlight:null==r?void 0:r.attributesToHighlight},"POST"!==s.toUpperCase()?[3,2]:[4,this.httpRequest.post(i,c(h),void 0,a)];case 1:return[2,o.sent()];case 2:return"GET"!==s.toUpperCase()?[3,4]:(d=n(n({},h),{facetFilters:Array.isArray(null==r?void 0:r.facetFilters)&&(null==r?void 0:r.facetFilters)?JSON.stringify(r.facetFilters):void 0,facetsDistribution:(null==r?void 0:r.facetsDistribution)?JSON.stringify(r.facetsDistribution):void 0,attributesToRetrieve:(null==r?void 0:r.attributesToRetrieve)?r.attributesToRetrieve.join(","):void 0,attributesToCrop:(null==r?void 0:r.attributesToCrop)?r.attributesToCrop.join(","):void 0,attributesToHighlight:(null==r?void 0:r.attributesToHighlight)?r.attributesToHighlight.join(","):void 0}),[4,this.httpRequest.get(i,c(d),a)]);case 3:return[2,o.sent()];case 4:throw new u("method parameter should be either POST or GET")}}))}))},t.prototype.getRawInfo=function(){return i(this,void 0,void 0,(function(){var e,r;return o(this,(function(n){switch(n.label){case 0:return e=t.routeConstructors.indexRoute(this.uid),[4,this.httpRequest.get(e)];case 1:return r=n.sent(),this.primaryKey=r.primaryKey,[2,r]}}))}))},t.prototype.fetchInfo=function(){return i(this,void 0,void 0,(function(){return o(this,(function(t){switch(t.label){case 0:return[4,this.getRawInfo()];case 1:return t.sent(),[2,this]}}))}))},t.prototype.fetchPrimaryKey=function(){return i(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t=this,[4,this.getRawInfo()];case 1:return t.primaryKey=e.sent().primaryKey,[2,this.primaryKey]}}))}))},t.create=function(e,r,u){return void 0===u&&(u={}),i(this,void 0,void 0,(function(){var i,s;return o(this,(function(o){switch(o.label){case 0:return i=t.apiRoutes.indexes,[4,new p(e).post(i,n(n({},u),{uid:r}))];case 1:return s=o.sent(),[2,new t(e,r,s.primaryKey)]}}))}))},t.prototype.update=function(e){return i(this,void 0,void 0,(function(){var r,n;return o(this,(function(i){switch(i.label){case 0:return r=t.routeConstructors.update(this.uid),[4,this.httpRequest.put(r,e)];case 1:return n=i.sent(),this.primaryKey=n.primaryKey,[2,this]}}))}))},t.prototype.delete=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.delete(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getStats=function(){return i(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return t="/indexes/"+this.uid+"/stats",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDocuments=function(e){return i(this,void 0,void 0,(function(){var r,i;return o(this,(function(o){switch(o.label){case 0:return r=t.routeConstructors.getDocuments(this.uid),void 0!==e&&Array.isArray(e.attributesToRetrieve)&&(i=e.attributesToRetrieve.join(",")),[4,this.httpRequest.get(r,n(n({},e),void 0!==i?{attributesToRetrieve:i}:{}))];case 1:return[2,o.sent()]}}))}))},t.prototype.getDocument=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.getDocument(this.uid,e),[4,this.httpRequest.get(r)];case 1:return[2,n.sent()]}}))}))},t.prototype.addDocuments=function(e,r){return i(this,void 0,void 0,(function(){var n;return o(this,(function(i){switch(i.label){case 0:return n=t.routeConstructors.addDocuments(this.uid),[4,this.httpRequest.post(n,e,r)];case 1:return[2,i.sent()]}}))}))},t.prototype.updateDocuments=function(e,r){return i(this,void 0,void 0,(function(){var n;return o(this,(function(i){switch(i.label){case 0:return n=t.routeConstructors.updateDocuments(this.uid),[4,this.httpRequest.put(n,e,r)];case 1:return[2,i.sent()]}}))}))},t.prototype.deleteDocument=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.deleteDocument(this.uid,e),[4,this.httpRequest.delete(r)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteDocuments=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.deleteDocuments(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteAllDocuments=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.deleteAllDocuments(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getSettings=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getSettings(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateSettings=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateSettings(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSettings=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetSettings(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getSynonyms=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getSynonyms(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateSynonyms=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateSynonyms(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSynonyms=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetSynonyms(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getStopWords=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getStopWords(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateStopWords=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateStopWords(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetStopWords=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetStopWords(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getRankingRules=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getRankingRules(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateRankingRules=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateRankingRules(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetRankingRules=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetRankingRules(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getDistinctAttribute=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getDistinctAttribute(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateDistinctAttribute=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateDistinctAttribute(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetDistinctAttribute=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetDistinctAttribute(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getAttributesForFaceting=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getAttributesForFaceting(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateAttributesForFaceting=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateAttributesForFaceting(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetAttributesForFaceting=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetAttributesForFaceting(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getSearchableAttributes=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getSearchableAttributes(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateSearchableAttributes=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateSearchableAttributes(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSearchableAttributes=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetSearchableAttributes(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getDisplayedAttributes=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.getDisplayedAttributes(this.uid),[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateDisplayedAttributes=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.updateDisplayedAttributes(this.uid),[4,this.httpRequest.post(r,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetDisplayedAttributes=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.routeConstructors.resetDisplayedAttributes(this.uid),[4,this.httpRequest.delete(e)];case 1:return[2,r.sent()]}}))}))},t.apiRoutes={indexes:"indexes"},t.routeConstructors={indexRoute:function(e){return t.apiRoutes.indexes+"/"+e},getUpdateStatus:function(e,r){return t.routeConstructors.indexRoute(e)+"/updates/"+r},getAllUpdateStatus:function(e){return t.routeConstructors.indexRoute(e)+"/updates"},search:function(e){return t.routeConstructors.indexRoute(e)+"/search"},getRawInfo:function(t){return"indexes/"+t},update:function(e){return t.routeConstructors.indexRoute(e)},delete:function(e){return t.routeConstructors.indexRoute(e)},getStats:function(e){return t.routeConstructors.indexRoute(e)+"/stats"},getDocument:function(e,r){return t.routeConstructors.indexRoute(e)+"/documents/"+r},getDocuments:function(e){return t.routeConstructors.indexRoute(e)+"/documents"},addDocuments:function(e){return t.routeConstructors.getDocuments(e)},updateDocuments:function(e){return t.routeConstructors.getDocuments(e)},deleteAllDocuments:function(e){return t.routeConstructors.getDocuments(e)},deleteDocument:function(e,r){return t.routeConstructors.indexRoute(e)+"/documents/"+r},deleteDocuments:function(e){return t.routeConstructors.indexRoute(e)+"/documents/delete-batch"},getSettings:function(e){return t.routeConstructors.indexRoute(e)+"/settings"},updateSettings:function(e){return t.routeConstructors.getSettings(e)},resetSettings:function(e){return t.routeConstructors.getSettings(e)},getSynonyms:function(e){return t.routeConstructors.indexRoute(e)+"/settings/synonyms"},updateSynonyms:function(e){return t.routeConstructors.getSynonyms(e)},resetSynonyms:function(e){return t.routeConstructors.getSynonyms(e)},getStopWords:function(e){return t.routeConstructors.indexRoute(e)+"/settings/stop-words"},updateStopWords:function(e){return t.routeConstructors.getStopWords(e)},resetStopWords:function(e){return t.routeConstructors.getStopWords(e)},getRankingRules:function(e){return t.routeConstructors.indexRoute(e)+"/settings/ranking-rules"},updateRankingRules:function(e){return t.routeConstructors.getRankingRules(e)},resetRankingRules:function(e){return t.routeConstructors.getRankingRules(e)},getDistinctAttribute:function(e){return t.routeConstructors.indexRoute(e)+"/settings/distinct-attribute"},updateDistinctAttribute:function(e){return t.routeConstructors.getDistinctAttribute(e)},resetDistinctAttribute:function(e){return t.routeConstructors.getDistinctAttribute(e)},getAttributesForFaceting:function(e){return t.routeConstructors.indexRoute(e)+"/settings/attributes-for-faceting"},updateAttributesForFaceting:function(e){return t.routeConstructors.getAttributesForFaceting(e)},resetAttributesForFaceting:function(e){return t.routeConstructors.getAttributesForFaceting(e)},getSearchableAttributes:function(e){return t.routeConstructors.indexRoute(e)+"/settings/searchable-attributes"},updateSearchableAttributes:function(e){return t.routeConstructors.getSearchableAttributes(e)},resetSearchableAttributes:function(e){return t.routeConstructors.getSearchableAttributes(e)},getDisplayedAttributes:function(e){return t.routeConstructors.indexRoute(e)+"/settings/displayed-attributes"},updateDisplayedAttributes:function(e){return t.routeConstructors.getDisplayedAttributes(e)},resetDisplayedAttributes:function(e){return t.routeConstructors.getDisplayedAttributes(e)}},t}(),l=function(){function t(t){t.host=p.addTrailingSlash(t.host),this.config=t,this.httpRequest=new p(t)}return t.getApiRoutes=function(){return t.apiRoutes},t.getRouteConstructors=function(){return t.routeConstructors},t.prototype.index=function(t){return new f(this.config,t)},t.prototype.getIndex=function(t){return i(this,void 0,void 0,(function(){return o(this,(function(e){return[2,new f(this.config,t).fetchInfo()]}))}))},t.prototype.getOrCreateIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.getIndex(t)];case 1:return[2,n.sent()];case 2:if("index_not_found"===(r=n.sent()).errorCode)return[2,this.createIndex(t,e)];throw new d(r,r.status);case 3:return[2]}}))}))},t.prototype.listIndexes=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.listIndexes,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.createIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){return o(this,(function(r){switch(r.label){case 0:return[4,f.create(this.config,t,e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){return o(this,(function(r){return[2,new f(this.config,t).update(e)]}))}))},t.prototype.deleteIndex=function(t){return i(this,void 0,void 0,(function(){return o(this,(function(e){return[2,new f(this.config,t).delete()]}))}))},t.prototype.getKeys=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.getKeys,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.health=function(){return i(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.httpRequest.get(t.apiRoutes.health)];case 1:return[2,e.sent()]}}))}))},t.prototype.isHealthy=function(){return i(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.httpRequest.get(t.apiRoutes.health)];case 1:return e.sent(),[2,!0];case 2:return e.sent(),[2,!1];case 3:return[2]}}))}))},t.prototype.stats=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.stats,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.version=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.version,[4,this.httpRequest.get(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.createDump=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return e=t.apiRoutes.createDump,[4,this.httpRequest.post(e)];case 1:return[2,r.sent()]}}))}))},t.prototype.getDumpStatus=function(e){return i(this,void 0,void 0,(function(){var r;return o(this,(function(n){switch(n.label){case 0:return r=t.routeConstructors.getDumpStatus(e),[4,this.httpRequest.get(r)];case 1:return[2,n.sent()]}}))}))},t.apiRoutes={listIndexes:"indexes",getKeys:"keys",health:"health",stats:"stats",version:"version",createDump:"dumps"},t.routeConstructors={getDumpStatus:function(t){return"dumps/"+t+"/status"}},t}();t.MeiliSearch=l,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
***************************************************************************** */var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,n)};function n(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r=function(){return(r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function i(t,e,n,r){return new(n||(n=Promise))((function(i,s){function u(t){try{c(r.next(t))}catch(t){s(t)}}function o(t){try{c(r.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,o)}c((r=r.apply(t,e||[])).next())}))}function s(t,e){var n,r,i,s,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return s={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function o(s){return function(o){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return u.label++,{value:s[1],done:!1};case 5:u.label++,r=s[1],s=[0];continue;case 7:s=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){u=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){u.label=s[1];break}if(6===s[0]&&u.label<i[1]){u.label=i[1],i=s;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(s);break}i[2]&&u.ops.pop(),u.trys.pop();continue}s=e.call(t,u)}catch(t){s=[6,t],r=0}finally{n=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,o])}}}var u=function(t){function e(n){var r=t.call(this,n)||this;return r.name="MeiliSearchError",r.type="MeiliSearchError",Error.captureStackTrace&&Error.captureStackTrace(r,e),r}return n(e,t),e}(Error),o=function(t){function e(n){var r=t.call(this,n)||this;return r.name="MeiliSearchTimeOutError",r.type=r.constructor.name,Error.captureStackTrace&&Error.captureStackTrace(r,e),r}return n(e,t),e}(Error);function c(t){return Object.entries(t).reduce((function(t,e){var n=e[0],r=e[1];return void 0!==r&&(t[n]=r),t}),{})}function a(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,new Promise((function(e){return setTimeout(e,t)}))];case 1:return[2,e.sent()]}}))}))}var h=function(t){function e(n,r){var i=t.call(this,n)||this;return i.name="MeiliSearchCommunicationError",i.type="MeiliSearchCommunicationError",r instanceof Response&&(i.message=r.statusText,i.statusCode=r.status),r instanceof Error&&(i.errno=r.errno,i.code=r.code),Error.captureStackTrace&&Error.captureStackTrace(i,e),i}return n(e,t),e}(Error),d=function(t){function e(e,n){var r=t.call(this,e.message)||this;return r.type="MeiliSearchApiError",r.name="MeiliSearchApiError",r.errorCode=e.errorCode,r.errorType=e.errorType,r.errorLink=e.errorLink,r.message=e.message,r.httpStatus=n,Error.captureStackTrace&&Error.captureStackTrace(r,d),r}return n(e,t),e}(Error);var f=function(){function t(t){this.headers=r(r(r({},t.headers||{}),{"Content-Type":"application/json"}),t.apiKey?{"X-Meili-API-Key":t.apiKey}:{}),this.url=new URL(t.host)}return t.addTrailingSlash=function(t){return t.endsWith("/")||(t+="/"),t},t.prototype.request=function(t){var e=t.method,n=t.url,u=t.params,o=t.body,c=t.config;return i(this,void 0,void 0,(function(){var t,a,f;return s(this,(function(p){switch(p.label){case 0:return p.trys.push([0,3,,4]),t=new URL(n,this.url),u&&(a=new URLSearchParams,Object.keys(u).filter((function(t){return null!==u[t]})).map((function(t){return a.set(t,u[t])})),t.search=a.toString()),[4,fetch(t.toString(),r(r({},c),{method:e,body:JSON.stringify(o),headers:this.headers})).then((function(t){return function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:if(t.ok)return[3,5];e=void 0,n.label=1;case 1:return n.trys.push([1,3,,4]),[4,t.json()];case 2:return e=n.sent(),[3,4];case 3:throw n.sent(),new h(t.statusText,t);case 4:throw new d(e,t.status);case 5:return[2,t]}}))}))}(t)}))];case 1:return[4,p.sent().text()];case 2:f=p.sent();try{return[2,JSON.parse(f)]}catch(t){return[2]}return[3,4];case 3:return function(t){if("MeiliSearchApiError"!==t.type)throw new h(t.message,t);throw t}(p.sent()),[3,4];case 4:return[2]}}))}))},t.prototype.get=function(t,e,n){return i(this,void 0,void 0,(function(){return s(this,(function(r){switch(r.label){case 0:return[4,this.request({method:"GET",url:t,params:e,config:n})];case 1:return[2,r.sent()]}}))}))},t.prototype.post=function(t,e,n,r){return i(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"POST",url:t,body:e,params:n,config:r})];case 1:return[2,i.sent()]}}))}))},t.prototype.put=function(t,e,n,r){return i(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"PUT",url:t,body:e,params:n,config:r})];case 1:return[2,i.sent()]}}))}))},t.prototype.delete=function(t,e,n,r){return i(this,void 0,void 0,(function(){return s(this,(function(i){switch(i.label){case 0:return[4,this.request({method:"DELETE",url:t,body:e,params:n,config:r})];case 1:return[2,i.sent()]}}))}))},t}(),p=function(){function t(t,e,n){this.uid=e,this.primaryKey=n,this.httpRequest=new f(t)}return t.prototype.waitForPendingUpdate=function(t,e){var n=void 0===e?{}:e,r=n.timeOutMs,u=void 0===r?5e3:r,c=n.intervalMs,h=void 0===c?50:c;return i(this,void 0,void 0,(function(){var e,n;return s(this,(function(r){switch(r.label){case 0:e=Date.now(),r.label=1;case 1:return Date.now()-e<u?[4,this.getUpdateStatus(t)]:[3,4];case 2:return"enqueued"!==(n=r.sent()).status?[2,n]:[4,a(h)];case 3:return r.sent(),[3,1];case 4:throw new o("timeout of "+u+"ms has exceeded on process "+t+" when waiting for pending update to resolve.")}}))}))},t.prototype.search=function(t,e,n,o){return void 0===n&&(n="POST"),i(this,void 0,void 0,(function(){var i,a,h;return s(this,(function(s){switch(s.label){case 0:return i="indexes/"+this.uid+"/search",a={q:t,offset:null==e?void 0:e.offset,limit:null==e?void 0:e.limit,cropLength:null==e?void 0:e.cropLength,filters:null==e?void 0:e.filters,matches:null==e?void 0:e.matches,facetFilters:null==e?void 0:e.facetFilters,facetsDistribution:null==e?void 0:e.facetsDistribution,attributesToRetrieve:null==e?void 0:e.attributesToRetrieve,attributesToCrop:null==e?void 0:e.attributesToCrop,attributesToHighlight:null==e?void 0:e.attributesToHighlight},"POST"!==n.toUpperCase()?[3,2]:[4,this.httpRequest.post(i,c(a),void 0,o)];case 1:return[2,s.sent()];case 2:return"GET"!==n.toUpperCase()?[3,4]:(h=r(r({},a),{facetFilters:Array.isArray(null==e?void 0:e.facetFilters)&&(null==e?void 0:e.facetFilters)?JSON.stringify(e.facetFilters):void 0,facetsDistribution:(null==e?void 0:e.facetsDistribution)?JSON.stringify(e.facetsDistribution):void 0,attributesToRetrieve:(null==e?void 0:e.attributesToRetrieve)?e.attributesToRetrieve.join(","):void 0,attributesToCrop:(null==e?void 0:e.attributesToCrop)?e.attributesToCrop.join(","):void 0,attributesToHighlight:(null==e?void 0:e.attributesToHighlight)?e.attributesToHighlight.join(","):void 0}),[4,this.httpRequest.get(i,c(h),o)]);case 3:return[2,s.sent()];case 4:throw new u("method parameter should be either POST or GET")}}))}))},t.prototype.getRawInfo=function(){return i(this,void 0,void 0,(function(){var t,e;return s(this,(function(n){switch(n.label){case 0:return t="indexes/"+this.uid,[4,this.httpRequest.get(t)];case 1:return e=n.sent(),this.primaryKey=e.primaryKey,[2,e]}}))}))},t.prototype.fetchInfo=function(){return i(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.getRawInfo()];case 1:return t.sent(),[2,this]}}))}))},t.prototype.fetchPrimaryKey=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t=this,[4,this.getRawInfo()];case 1:return t.primaryKey=e.sent().primaryKey,[2,this.primaryKey]}}))}))},t.create=function(e,n,u){return void 0===u&&(u={}),i(this,void 0,void 0,(function(){var i;return s(this,(function(s){switch(s.label){case 0:return"indexes",[4,new f(e).post("indexes",r(r({},u),{uid:n}))];case 1:return i=s.sent(),[2,new t(e,n,i.primaryKey)]}}))}))},t.prototype.update=function(t){return i(this,void 0,void 0,(function(){var e,n;return s(this,(function(r){switch(r.label){case 0:return e="indexes/"+this.uid,[4,this.httpRequest.put(e,t)];case 1:return n=r.sent(),this.primaryKey=n.primaryKey,[2,this]}}))}))},t.prototype.delete=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid,[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.deleteIfExists=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.delete()];case 1:return e.sent(),[2,!0];case 2:if("index_not_found"===(t=e.sent()).errorCode)return[2,!1];throw t;case 3:return[2]}}))}))},t.prototype.getAllUpdateStatus=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/updates",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getUpdateStatus=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/updates/"+t,[4,this.httpRequest.get(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.getStats=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/stats",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDocuments=function(t){return i(this,void 0,void 0,(function(){var e,n;return s(this,(function(i){switch(i.label){case 0:return e="indexes/"+this.uid+"/documents",void 0!==t&&Array.isArray(t.attributesToRetrieve)&&(n=t.attributesToRetrieve.join(",")),[4,this.httpRequest.get(e,r(r({},t),void 0!==n?{attributesToRetrieve:n}:{}))];case 1:return[2,i.sent()]}}))}))},t.prototype.getDocument=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/documents/"+t,[4,this.httpRequest.get(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.addDocuments=function(t,e){return i(this,void 0,void 0,(function(){var n;return s(this,(function(r){switch(r.label){case 0:return n="indexes/"+this.uid+"/documents",[4,this.httpRequest.post(n,t,e)];case 1:return[2,r.sent()]}}))}))},t.prototype.updateDocuments=function(t,e){return i(this,void 0,void 0,(function(){var n;return s(this,(function(r){switch(r.label){case 0:return n="indexes/"+this.uid+"/documents",[4,this.httpRequest.put(n,t,e)];case 1:return[2,r.sent()]}}))}))},t.prototype.deleteDocument=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/documents/"+t,[4,this.httpRequest.delete(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteDocuments=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/documents/delete-batch",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.deleteAllDocuments=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/documents",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSettings=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSettings=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/settings",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSettings=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSynonyms=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/synonyms",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSynonyms=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/settings/synonyms",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSynonyms=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/synonyms",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getStopWords=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/stop-words",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateStopWords=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/settings/stop-words",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetStopWords=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/stop-words",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getRankingRules=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/ranking-rules",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateRankingRules=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/settings/ranking-rules",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetRankingRules=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/ranking-rules",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDistinctAttribute=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/distinct-attribute",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateDistinctAttribute=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/settings/distinct-attribute",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetDistinctAttribute=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/distinct-attribute",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getAttributesForFaceting=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/attributes-for-faceting",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateAttributesForFaceting=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/settings/attributes-for-faceting",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetAttributesForFaceting=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/attributes-for-faceting",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getSearchableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/searchable-attributes",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateSearchableAttributes=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/settings/searchable-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetSearchableAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/searchable-attributes",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getDisplayedAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/displayed-attributes",[4,this.httpRequest.get(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.updateDisplayedAttributes=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="indexes/"+this.uid+"/settings/displayed-attributes",[4,this.httpRequest.post(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.resetDisplayedAttributes=function(){return i(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return t="indexes/"+this.uid+"/settings/displayed-attributes",[4,this.httpRequest.delete(t)];case 1:return[2,e.sent()]}}))}))},t}(),l=function(){function t(t){t.host=f.addTrailingSlash(t.host),this.config=t,this.httpRequest=new f(t)}return t.prototype.index=function(t){return new p(this.config,t)},t.prototype.getIndex=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){return[2,new p(this.config,t).fetchInfo()]}))}))},t.prototype.getOrCreateIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){var n;return s(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.getIndex(t)];case 1:return[2,r.sent()];case 2:if("index_not_found"===(n=r.sent()).errorCode)return[2,this.createIndex(t,e)];throw new d(n,n.status);case 3:return[2]}}))}))},t.prototype.listIndexes=function(){return i(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return"indexes",[4,this.httpRequest.get("indexes")];case 1:return[2,t.sent()]}}))}))},t.prototype.createIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){return s(this,(function(n){switch(n.label){case 0:return[4,p.create(this.config,t,e)];case 1:return[2,n.sent()]}}))}))},t.prototype.updateIndex=function(t,e){return void 0===e&&(e={}),i(this,void 0,void 0,(function(){return s(this,(function(n){return[2,new p(this.config,t).update(e)]}))}))},t.prototype.deleteIndex=function(t){return i(this,void 0,void 0,(function(){return s(this,(function(e){return[2,new p(this.config,t).delete()]}))}))},t.prototype.deleteIndexIfExists=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.deleteIndex(t)];case 1:return n.sent(),[2,!0];case 2:if("index_not_found"===(e=n.sent()).errorCode)return[2,!1];throw e;case 3:return[2]}}))}))},t.prototype.getKeys=function(){return i(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return"keys",[4,this.httpRequest.get("keys")];case 1:return[2,t.sent()]}}))}))},t.prototype.health=function(){return i(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return"health",[4,this.httpRequest.get("health")];case 1:return[2,t.sent()]}}))}))},t.prototype.isHealthy=function(){return i(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),"health",[4,this.httpRequest.get("health")];case 1:return t.sent(),[2,!0];case 2:return t.sent(),[2,!1];case 3:return[2]}}))}))},t.prototype.stats=function(){return i(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return"stats",[4,this.httpRequest.get("stats")];case 1:return[2,t.sent()]}}))}))},t.prototype.version=function(){return i(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return"version",[4,this.httpRequest.get("version")];case 1:return[2,t.sent()]}}))}))},t.prototype.createDump=function(){return i(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return"dumps",[4,this.httpRequest.post("dumps")];case 1:return[2,t.sent()]}}))}))},t.prototype.getDumpStatus=function(t){return i(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return e="dumps/"+t+"/status",[4,this.httpRequest.get(e)];case 1:return[2,n.sent()]}}))}))},t}();t.MeiliSearch=l,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=meilisearch.umd.min.js.map |
import * as Types from './types'; | ||
import HttpRequests from './http-requests'; | ||
declare type objectId = string | number | undefined; | ||
declare type createIndexPath = (indexUid: string, objectId?: objectId) => string; | ||
declare class Index<T> implements Types.IndexInterface<T> { | ||
@@ -9,21 +7,3 @@ uid: string; | ||
httpRequest: HttpRequests; | ||
static apiRoutes: { | ||
[key: string]: string; | ||
}; | ||
static routeConstructors: { | ||
[key: string]: createIndexPath; | ||
}; | ||
constructor(config: Types.Config, uid: string, primaryKey?: string); | ||
static getApiRoutes(): { | ||
[key: string]: string; | ||
}; | ||
static getRouteConstructors(): { | ||
[key: string]: createIndexPath; | ||
}; | ||
/** | ||
* Get the informations about an update status | ||
* @memberof Index | ||
* @method getUpdateStatus | ||
*/ | ||
getUpdateStatus(updateId: number): Promise<Types.Update>; | ||
waitForPendingUpdate(updateId: number, { timeOutMs, intervalMs, }?: { | ||
@@ -34,8 +14,2 @@ timeOutMs?: number; | ||
/** | ||
* Get the list of all updates | ||
* @memberof Index | ||
* @method getAllUpdateStatus | ||
*/ | ||
getAllUpdateStatus(): Promise<Types.Update[]>; | ||
/** | ||
* Search for documents into an index | ||
@@ -83,2 +57,20 @@ * @memberof Index | ||
/** | ||
* Deletes an index if it already exists. | ||
* @memberof Index | ||
* @method deleteIfExists | ||
*/ | ||
deleteIfExists(): Promise<boolean>; | ||
/** | ||
* Get the list of all updates | ||
* @memberof Index | ||
* @method getAllUpdateStatus | ||
*/ | ||
getAllUpdateStatus(): Promise<Types.Update[]>; | ||
/** | ||
* Get the informations about an update status | ||
* @memberof Index | ||
* @method getUpdateStatus | ||
*/ | ||
getUpdateStatus(updateId: number): Promise<Types.Update>; | ||
/** | ||
* get stats of an index | ||
@@ -197,3 +189,3 @@ * @memberof Index | ||
*/ | ||
updateRankingRules(rankingRules: string[]): Promise<Types.EnqueuedUpdate>; | ||
updateRankingRules(rankingRules: string[] | null): Promise<Types.EnqueuedUpdate>; | ||
/** | ||
@@ -216,3 +208,3 @@ * Reset the ranking rules list to its default value | ||
*/ | ||
updateDistinctAttribute(distinctAttribute: string): Promise<Types.EnqueuedUpdate>; | ||
updateDistinctAttribute(distinctAttribute: string | null): Promise<Types.EnqueuedUpdate>; | ||
/** | ||
@@ -235,3 +227,3 @@ * Reset the distinct-attribute. | ||
*/ | ||
updateAttributesForFaceting(attributesForFaceting: string[]): Promise<Types.EnqueuedUpdate>; | ||
updateAttributesForFaceting(attributesForFaceting: string[] | null): Promise<Types.EnqueuedUpdate>; | ||
/** | ||
@@ -254,3 +246,3 @@ * Reset the attributes-for-faceting. | ||
*/ | ||
updateSearchableAttributes(searchableAttributes: string[]): Promise<Types.EnqueuedUpdate>; | ||
updateSearchableAttributes(searchableAttributes: string[] | null): Promise<Types.EnqueuedUpdate>; | ||
/** | ||
@@ -273,3 +265,3 @@ * Reset the searchable-attributes. | ||
*/ | ||
updateDisplayedAttributes(displayedAttributes: string[]): Promise<Types.EnqueuedUpdate>; | ||
updateDisplayedAttributes(displayedAttributes: string[] | null): Promise<Types.EnqueuedUpdate>; | ||
/** | ||
@@ -276,0 +268,0 @@ * Reset the displayed-attributes. |
import { Index } from './index'; | ||
import * as Types from './types'; | ||
import HttpRequests from './http-requests'; | ||
declare type createPath = (x: string | number) => string; | ||
export declare class MeiliSearch implements Types.MeiliSearchInterface { | ||
config: Types.Config; | ||
httpRequest: HttpRequests; | ||
static apiRoutes: { | ||
[key: string]: string; | ||
}; | ||
static routeConstructors: { | ||
[key: string]: createPath; | ||
}; | ||
constructor(config: Types.Config); | ||
static getApiRoutes(): { | ||
[key: string]: string; | ||
}; | ||
static getRouteConstructors(): { | ||
[key: string]: createPath; | ||
}; | ||
/** | ||
@@ -65,2 +52,8 @@ * Return an Index instance | ||
/** | ||
* Deletes an index if it already exists. | ||
* @memberof MeiliSearch | ||
* @method deleteIndexIfExists | ||
*/ | ||
deleteIndexIfExists(uid: string): Promise<boolean>; | ||
/** | ||
* Get private and public key | ||
@@ -110,3 +103,2 @@ * @memberof MeiliSearch | ||
} | ||
export {}; | ||
//# sourceMappingURL=meilisearch.d.ts.map |
@@ -1,6 +0,6 @@ | ||
// Type definitions for meilisearch 0.18.2 | ||
// Type definitions for meilisearch 0.19.0 | ||
// Project: https://github.com/meilisearch/meilisearch-js | ||
// Definitions by: cvermand <charlotte@meilisearch.com> <https://github.com/meilisearch> | ||
// Definitions: https://github.com/meilisearch/meilisearch-js | ||
// TypeScript Version: 4.2.4 | ||
// TypeScript Version: 4.3.2 | ||
@@ -175,2 +175,3 @@ import { Index } from './index'; | ||
deleteIndex: (uid: string) => Promise<void>; | ||
deleteIndexIfExists: (uid: string) => Promise<boolean>; | ||
getKeys: () => Promise<Keys>; | ||
@@ -195,2 +196,3 @@ health: () => Promise<Health>; | ||
delete: () => Promise<void>; | ||
deleteIfExists: () => Promise<boolean>; | ||
getStats: () => Promise<IndexStats>; | ||
@@ -214,15 +216,15 @@ getDocuments: <P extends GetDocumentsParams<T>>(options?: P) => Promise<GetDocumentsResponse<T, P>>; | ||
getRankingRules: () => Promise<string[]>; | ||
updateRankingRules: (rankingRules: string[]) => Promise<EnqueuedUpdate>; | ||
updateRankingRules: (rankingRules: string[] | null) => Promise<EnqueuedUpdate>; | ||
resetRankingRules: () => Promise<EnqueuedUpdate>; | ||
getDistinctAttribute: () => Promise<string | null>; | ||
updateDistinctAttribute: (distinctAttribute: string) => Promise<EnqueuedUpdate>; | ||
updateDistinctAttribute: (distinctAttribute: string | null) => Promise<EnqueuedUpdate>; | ||
resetDistinctAttribute: () => Promise<EnqueuedUpdate>; | ||
getAttributesForFaceting: () => Promise<string[]>; | ||
updateAttributesForFaceting: (attributesForFaceting: string[]) => Promise<EnqueuedUpdate>; | ||
updateAttributesForFaceting: (attributesForFaceting: string[] | null) => Promise<EnqueuedUpdate>; | ||
resetAttributesForFaceting: () => Promise<EnqueuedUpdate>; | ||
getSearchableAttributes: () => Promise<string[]>; | ||
updateSearchableAttributes: (searchableAttributes: string[]) => Promise<EnqueuedUpdate>; | ||
updateSearchableAttributes: (searchableAttributes: string[] | null) => Promise<EnqueuedUpdate>; | ||
resetSearchableAttributes: () => Promise<EnqueuedUpdate>; | ||
getDisplayedAttributes: () => Promise<string[]>; | ||
updateDisplayedAttributes: (displayedAttributes: string[]) => Promise<EnqueuedUpdate>; | ||
updateDisplayedAttributes: (displayedAttributes: string[] | null) => Promise<EnqueuedUpdate>; | ||
resetDisplayedAttributes: () => Promise<EnqueuedUpdate>; | ||
@@ -229,0 +231,0 @@ } |
{ | ||
"name": "meilisearch", | ||
"version": "0.18.2", | ||
"version": "0.19.0", | ||
"description": "The MeiliSearch JS client for Node.js and the browser.", | ||
@@ -65,9 +65,9 @@ "keywords": [ | ||
"devDependencies": { | ||
"@babel/preset-env": "^7.13.15", | ||
"@babel/preset-env": "^7.14.5", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
"@rollup/plugin-commonjs": "18.0.0", | ||
"@rollup/plugin-commonjs": "19.0.0", | ||
"@rollup/plugin-json": "^4.0.2", | ||
"@rollup/plugin-node-resolve": "11.2.1", | ||
"@types/jest": "^26.0.22", | ||
"@types/prettier": "^2.2.0", | ||
"@rollup/plugin-node-resolve": "13.0.0", | ||
"@types/jest": "^26.0.23", | ||
"@types/prettier": "^2.2.3", | ||
"@typescript-eslint/eslint-plugin": "2.34.0", | ||
@@ -89,15 +89,14 @@ "@typescript-eslint/parser": "2.34.0", | ||
"jest": "^26.6.3", | ||
"jest-environment-jsdom": "25.5", | ||
"jest-watch-typeahead": "^0.6.1", | ||
"jest-watch-typeahead": "^0.6.3", | ||
"kleur": "^4.1.4", | ||
"lint-staged": "10.5.1", | ||
"prettier": "^2.0.2", | ||
"lint-staged": "11.0.0", | ||
"prettier": "^2.2.1", | ||
"pretty-bytes": "^5.6.0", | ||
"rollup": "^2.45.1", | ||
"rollup": "^2.51.2", | ||
"rollup-plugin-terser": "^7.0.0", | ||
"rollup-plugin-typescript2": "^0.30.0", | ||
"shx": "^0.3.2", | ||
"ts-jest": "^26.5.3", | ||
"typescript": "4.2.4" | ||
"ts-jest": "^26.5.6", | ||
"typescript": "4.3.2" | ||
} | ||
} |
@@ -46,2 +46,4 @@ <p align="center"> | ||
We only guarantee that the package works with `node` >= 12 and `node` < 15. | ||
With `npm`: | ||
@@ -454,3 +456,3 @@ | ||
- Update Ranking Rules | ||
`index.updateRankingRules(rankingRules: string[]): Promise<EnqueuedUpdate>` | ||
`index.updateRankingRules(rankingRules: string[] | null): Promise<EnqueuedUpdate>` | ||
@@ -466,3 +468,3 @@ - Reset Ranking Rules | ||
- Update Distinct Attribute | ||
`index.updateDistinctAttribute(distinctAttribute: string): Promise<EnqueuedUpdate>` | ||
`index.updateDistinctAttribute(distinctAttribute: string | null): Promise<EnqueuedUpdate>` | ||
@@ -478,3 +480,3 @@ - Reset Distinct Attribute | ||
- Update Searchable Attributes | ||
`index.updateSearchableAttributes(searchableAttributes: string[]): Promise<EnqueuedUpdate>` | ||
`index.updateSearchableAttributes(searchableAttributes: string[] | null): Promise<EnqueuedUpdate>` | ||
@@ -490,3 +492,3 @@ - Reset Searchable Attributes | ||
- Update Displayed Attributes | ||
`index.updateDisplayedAttributes(displayedAttributes: string[]): Promise<EnqueuedUpdate>` | ||
`index.updateDisplayedAttributes(displayedAttributes: string[] | null): Promise<EnqueuedUpdate>` | ||
@@ -493,0 +495,0 @@ - Reset Displayed Attributes |
@@ -53,3 +53,3 @@ import 'cross-fetch/polyfill' | ||
method, | ||
body: body ? JSON.stringify(body) : undefined, | ||
body: JSON.stringify(body), | ||
headers: this.headers, | ||
@@ -56,0 +56,0 @@ }).then((res) => httpResponseErrorHandler(res)) |
329
src/index.ts
@@ -16,5 +16,2 @@ /* | ||
type objectId = string | number | undefined | ||
type createIndexPath = (indexUid: string, objectId?: objectId) => string | ||
class Index<T> implements Types.IndexInterface<T> { | ||
@@ -24,170 +21,2 @@ uid: string | ||
httpRequest: HttpRequests | ||
static apiRoutes: { | ||
[key: string]: string | ||
} = { | ||
indexes: 'indexes', | ||
} | ||
static routeConstructors: { | ||
[key: string]: createIndexPath | ||
} = { | ||
indexRoute: (indexUid: string) => { | ||
return `${Index.apiRoutes.indexes}/${indexUid}` | ||
}, | ||
getUpdateStatus: (indexUid: string, updateId: objectId) => { | ||
return ( | ||
Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
`updates/${updateId}` | ||
) | ||
}, | ||
getAllUpdateStatus: (indexUid: string) => { | ||
return Index.routeConstructors.indexRoute(indexUid) + '/' + `updates` | ||
}, | ||
search: (indexUid: string) => { | ||
return Index.routeConstructors.indexRoute(indexUid) + '/' + `search` | ||
}, | ||
getRawInfo: (indexUid: string) => { | ||
return `indexes/${indexUid}` | ||
}, | ||
update: (indexUid: string) => { | ||
return Index.routeConstructors.indexRoute(indexUid) | ||
}, | ||
delete: (indexUid: string) => { | ||
return Index.routeConstructors.indexRoute(indexUid) | ||
}, | ||
getStats: (indexUid: string) => { | ||
return Index.routeConstructors.indexRoute(indexUid) + '/' + `stats` | ||
}, | ||
getDocument: (indexUid: string, documentId: objectId) => { | ||
return ( | ||
Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
`documents/${documentId}` | ||
) | ||
}, | ||
getDocuments: (indexUid: string) => { | ||
return Index.routeConstructors.indexRoute(indexUid) + '/' + `documents` | ||
}, | ||
addDocuments: (indexUid: string) => { | ||
return Index.routeConstructors.getDocuments(indexUid) | ||
}, | ||
updateDocuments: (indexUid: string) => { | ||
return Index.routeConstructors.getDocuments(indexUid) | ||
}, | ||
deleteAllDocuments: (indexUid: string) => { | ||
return Index.routeConstructors.getDocuments(indexUid) | ||
}, | ||
deleteDocument: (indexUid: string, documentId: objectId) => { | ||
return ( | ||
Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
`documents/${documentId}` | ||
) | ||
}, | ||
deleteDocuments: (indexUid: string) => { | ||
return ( | ||
Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
`documents/delete-batch` | ||
) | ||
}, | ||
getSettings: (indexUid: string) => { | ||
return Index.routeConstructors.indexRoute(indexUid) + '/' + `settings` | ||
}, | ||
updateSettings: (indexUid: string) => { | ||
return Index.routeConstructors.getSettings(indexUid) | ||
}, | ||
resetSettings: (indexUid: string) => { | ||
return Index.routeConstructors.getSettings(indexUid) | ||
}, | ||
getSynonyms: (indexUid: string) => { | ||
return ( | ||
Index.routeConstructors.indexRoute(indexUid) + '/' + `settings/synonyms` | ||
) | ||
}, | ||
updateSynonyms: (indexUid: string) => { | ||
return Index.routeConstructors.getSynonyms(indexUid) | ||
}, | ||
resetSynonyms: (indexUid: string) => { | ||
return Index.routeConstructors.getSynonyms(indexUid) | ||
}, | ||
getStopWords: (indexUid: string) => { | ||
return ( | ||
Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
`settings/stop-words` | ||
) | ||
}, | ||
updateStopWords: (indexUid: string) => { | ||
return Index.routeConstructors.getStopWords(indexUid) | ||
}, | ||
resetStopWords: (indexUid: string) => { | ||
return Index.routeConstructors.getStopWords(indexUid) | ||
}, | ||
getRankingRules: (indexUid: string) => { | ||
return ( | ||
Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
`settings/ranking-rules` | ||
) | ||
}, | ||
updateRankingRules: (indexUid: string) => { | ||
return Index.routeConstructors.getRankingRules(indexUid) | ||
}, | ||
resetRankingRules: (indexUid: string) => { | ||
return Index.routeConstructors.getRankingRules(indexUid) | ||
}, | ||
getDistinctAttribute: (indexUid: string) => { | ||
return ( | ||
Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
`settings/distinct-attribute` | ||
) | ||
}, | ||
updateDistinctAttribute: (indexUid: string) => { | ||
return Index.routeConstructors.getDistinctAttribute(indexUid) | ||
}, | ||
resetDistinctAttribute: (indexUid: string) => { | ||
return Index.routeConstructors.getDistinctAttribute(indexUid) | ||
}, | ||
getAttributesForFaceting: (indexUid: string) => { | ||
return ( | ||
Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
`settings/attributes-for-faceting` | ||
) | ||
}, | ||
updateAttributesForFaceting: (indexUid: string) => { | ||
return Index.routeConstructors.getAttributesForFaceting(indexUid) | ||
}, | ||
resetAttributesForFaceting: (indexUid: string) => { | ||
return Index.routeConstructors.getAttributesForFaceting(indexUid) | ||
}, | ||
getSearchableAttributes: (indexUid: string) => { | ||
return ( | ||
Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
`settings/searchable-attributes` | ||
) | ||
}, | ||
updateSearchableAttributes: (indexUid: string) => { | ||
return Index.routeConstructors.getSearchableAttributes(indexUid) | ||
}, | ||
resetSearchableAttributes: (indexUid: string) => { | ||
return Index.routeConstructors.getSearchableAttributes(indexUid) | ||
}, | ||
getDisplayedAttributes: (indexUid: string) => { | ||
return ( | ||
Index.routeConstructors.indexRoute(indexUid) + | ||
'/' + | ||
`settings/displayed-attributes` | ||
) | ||
}, | ||
updateDisplayedAttributes: (indexUid: string) => { | ||
return Index.routeConstructors.getDisplayedAttributes(indexUid) | ||
}, | ||
resetDisplayedAttributes: (indexUid: string) => { | ||
return Index.routeConstructors.getDisplayedAttributes(indexUid) | ||
}, | ||
} | ||
@@ -199,27 +28,7 @@ constructor(config: Types.Config, uid: string, primaryKey?: string) { | ||
} | ||
/// | ||
/// STATIC | ||
/// | ||
static getApiRoutes(): { [key: string]: string } { | ||
return Index.apiRoutes | ||
} | ||
static getRouteConstructors(): { [key: string]: createIndexPath } { | ||
return Index.routeConstructors | ||
} | ||
/// | ||
/// UPDATES | ||
/// UTILS | ||
/// | ||
/** | ||
* Get the informations about an update status | ||
* @memberof Index | ||
* @method getUpdateStatus | ||
*/ | ||
async getUpdateStatus(updateId: number): Promise<Types.Update> { | ||
const url = Index.routeConstructors.getUpdateStatus(this.uid, updateId) | ||
return await this.httpRequest.get<Types.Update>(url) | ||
} | ||
async waitForPendingUpdate( | ||
@@ -243,12 +52,2 @@ updateId: number, | ||
/** | ||
* Get the list of all updates | ||
* @memberof Index | ||
* @method getAllUpdateStatus | ||
*/ | ||
async getAllUpdateStatus(): Promise<Types.Update[]> { | ||
const url = Index.routeConstructors.getAllUpdateStatus(this.uid) | ||
return await this.httpRequest.get<Types.Update[]>(url) | ||
} | ||
/// | ||
@@ -269,3 +68,3 @@ /// SEARCH | ||
): Promise<Types.SearchResponse<T, P>> { | ||
const url = Index.routeConstructors.search(this.uid) | ||
const url = `indexes/${this.uid}/search` | ||
const params: Types.SearchRequest = { | ||
@@ -327,2 +126,3 @@ q: query, | ||
/// | ||
/** | ||
@@ -334,3 +134,3 @@ * Get index information. | ||
async getRawInfo(): Promise<Types.IndexResponse> { | ||
const url = Index.routeConstructors.indexRoute(this.uid) | ||
const url = `indexes/${this.uid}` | ||
const res = await this.httpRequest.get<Types.IndexResponse>(url) | ||
@@ -371,3 +171,3 @@ this.primaryKey = res.primaryKey | ||
): Promise<Index<T>> { | ||
const url = Index.apiRoutes.indexes | ||
const url = `indexes` | ||
const req = new HttpRequests(config) | ||
@@ -384,3 +184,3 @@ const index = await req.post(url, { ...options, uid }) | ||
async update(data: Types.IndexOptions): Promise<this> { | ||
const url = Index.routeConstructors.update(this.uid) | ||
const url = `indexes/${this.uid}` | ||
const index = await this.httpRequest.put(url, data) | ||
@@ -397,7 +197,48 @@ this.primaryKey = index.primaryKey | ||
async delete(): Promise<void> { | ||
const url = Index.routeConstructors.delete(this.uid) | ||
const url = `indexes/${this.uid}` | ||
return await this.httpRequest.delete(url) | ||
} | ||
/** | ||
* Deletes an index if it already exists. | ||
* @memberof Index | ||
* @method deleteIfExists | ||
*/ | ||
async deleteIfExists(): Promise<boolean> { | ||
try { | ||
await this.delete() | ||
return true | ||
} catch (e) { | ||
if (e.errorCode === 'index_not_found') { | ||
return false | ||
} | ||
throw e | ||
} | ||
} | ||
/// | ||
/// UPDATES | ||
/// | ||
/** | ||
* Get the list of all updates | ||
* @memberof Index | ||
* @method getAllUpdateStatus | ||
*/ | ||
async getAllUpdateStatus(): Promise<Types.Update[]> { | ||
const url = `indexes/${this.uid}/updates` | ||
return await this.httpRequest.get<Types.Update[]>(url) | ||
} | ||
/** | ||
* Get the informations about an update status | ||
* @memberof Index | ||
* @method getUpdateStatus | ||
*/ | ||
async getUpdateStatus(updateId: number): Promise<Types.Update> { | ||
const url = `indexes/${this.uid}/updates/${updateId}` | ||
return await this.httpRequest.get<Types.Update>(url) | ||
} | ||
/// | ||
/// STATS | ||
@@ -412,3 +253,3 @@ /// | ||
async getStats(): Promise<Types.IndexStats> { | ||
const url = `/indexes/${this.uid}/stats` | ||
const url = `indexes/${this.uid}/stats` | ||
return await this.httpRequest.get<Types.IndexStats>(url) | ||
@@ -428,3 +269,3 @@ } | ||
): Promise<Types.GetDocumentsResponse<T, P>> { | ||
const url = Index.routeConstructors.getDocuments(this.uid) | ||
const url = `indexes/${this.uid}/documents` | ||
let attr | ||
@@ -447,3 +288,3 @@ if (options !== undefined && Array.isArray(options.attributesToRetrieve)) { | ||
async getDocument(documentId: string | number): Promise<Types.Document<T>> { | ||
const url = Index.routeConstructors.getDocument(this.uid, documentId) | ||
const url = `indexes/${this.uid}/documents/${documentId}` | ||
return await this.httpRequest.get<Types.Document<T>>(url) | ||
@@ -461,3 +302,3 @@ } | ||
): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.addDocuments(this.uid) | ||
const url = `indexes/${this.uid}/documents` | ||
return await this.httpRequest.post(url, documents, options) | ||
@@ -475,3 +316,3 @@ } | ||
): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.updateDocuments(this.uid) | ||
const url = `indexes/${this.uid}/documents` | ||
return await this.httpRequest.put(url, documents, options) | ||
@@ -488,3 +329,3 @@ } | ||
): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.deleteDocument(this.uid, documentId) | ||
const url = `indexes/${this.uid}/documents/${documentId}` | ||
return await this.httpRequest.delete<Types.EnqueuedUpdate>(url) | ||
@@ -501,3 +342,3 @@ } | ||
): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.deleteDocuments(this.uid) | ||
const url = `indexes/${this.uid}/documents/delete-batch` | ||
@@ -513,3 +354,3 @@ return await this.httpRequest.post(url, documentsIds) | ||
async deleteAllDocuments(): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.deleteAllDocuments(this.uid) | ||
const url = `indexes/${this.uid}/documents` | ||
return await this.httpRequest.delete<Types.EnqueuedUpdate>(url) | ||
@@ -528,3 +369,3 @@ } | ||
async getSettings(): Promise<Types.Settings> { | ||
const url = Index.routeConstructors.getSettings(this.uid) | ||
const url = `indexes/${this.uid}/settings` | ||
return await this.httpRequest.get<Types.Settings>(url) | ||
@@ -542,3 +383,3 @@ } | ||
): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.updateSettings(this.uid) | ||
const url = `indexes/${this.uid}/settings` | ||
return await this.httpRequest.post(url, settings) | ||
@@ -553,3 +394,3 @@ } | ||
async resetSettings(): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.resetSettings(this.uid) | ||
const url = `indexes/${this.uid}/settings` | ||
return await this.httpRequest.delete<Types.EnqueuedUpdate>(url) | ||
@@ -568,3 +409,3 @@ } | ||
async getSynonyms(): Promise<object> { | ||
const url = Index.routeConstructors.getSynonyms(this.uid) | ||
const url = `indexes/${this.uid}/settings/synonyms` | ||
return await this.httpRequest.get<object>(url) | ||
@@ -579,3 +420,3 @@ } | ||
async updateSynonyms(synonyms: object): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.updateSynonyms(this.uid) | ||
const url = `indexes/${this.uid}/settings/synonyms` | ||
return await this.httpRequest.post(url, synonyms) | ||
@@ -590,3 +431,3 @@ } | ||
async resetSynonyms(): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.resetSynonyms(this.uid) | ||
const url = `indexes/${this.uid}/settings/synonyms` | ||
return await this.httpRequest.delete<Types.EnqueuedUpdate>(url) | ||
@@ -605,3 +446,3 @@ } | ||
async getStopWords(): Promise<string[]> { | ||
const url = Index.routeConstructors.getStopWords(this.uid) | ||
const url = `indexes/${this.uid}/settings/stop-words` | ||
return await this.httpRequest.get<string[]>(url) | ||
@@ -616,3 +457,3 @@ } | ||
async updateStopWords(stopWords: string[]): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.updateStopWords(this.uid) | ||
const url = `indexes/${this.uid}/settings/stop-words` | ||
return await this.httpRequest.post(url, stopWords) | ||
@@ -627,3 +468,3 @@ } | ||
async resetStopWords(): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.resetStopWords(this.uid) | ||
const url = `indexes/${this.uid}/settings/stop-words` | ||
return await this.httpRequest.delete<Types.EnqueuedUpdate>(url) | ||
@@ -642,3 +483,3 @@ } | ||
async getRankingRules(): Promise<string[]> { | ||
const url = Index.routeConstructors.getRankingRules(this.uid) | ||
const url = `indexes/${this.uid}/settings/ranking-rules` | ||
return await this.httpRequest.get<string[]>(url) | ||
@@ -653,5 +494,5 @@ } | ||
async updateRankingRules( | ||
rankingRules: string[] | ||
rankingRules: string[] | null | ||
): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.updateRankingRules(this.uid) | ||
const url = `indexes/${this.uid}/settings/ranking-rules` | ||
return await this.httpRequest.post(url, rankingRules) | ||
@@ -666,3 +507,3 @@ } | ||
async resetRankingRules(): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.resetRankingRules(this.uid) | ||
const url = `indexes/${this.uid}/settings/ranking-rules` | ||
return await this.httpRequest.delete<Types.EnqueuedUpdate>(url) | ||
@@ -681,3 +522,3 @@ } | ||
async getDistinctAttribute(): Promise<string | null> { | ||
const url = Index.routeConstructors.getDistinctAttribute(this.uid) | ||
const url = `indexes/${this.uid}/settings/distinct-attribute` | ||
return await this.httpRequest.get<string | null>(url) | ||
@@ -692,5 +533,5 @@ } | ||
async updateDistinctAttribute( | ||
distinctAttribute: string | ||
distinctAttribute: string | null | ||
): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.updateDistinctAttribute(this.uid) | ||
const url = `indexes/${this.uid}/settings/distinct-attribute` | ||
return await this.httpRequest.post(url, distinctAttribute) | ||
@@ -705,3 +546,3 @@ } | ||
async resetDistinctAttribute(): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.resetDistinctAttribute(this.uid) | ||
const url = `indexes/${this.uid}/settings/distinct-attribute` | ||
return await this.httpRequest.delete<Types.EnqueuedUpdate>(url) | ||
@@ -720,3 +561,3 @@ } | ||
async getAttributesForFaceting(): Promise<string[]> { | ||
const url = Index.routeConstructors.getAttributesForFaceting(this.uid) | ||
const url = `indexes/${this.uid}/settings/attributes-for-faceting` | ||
return await this.httpRequest.get<string[]>(url) | ||
@@ -731,5 +572,5 @@ } | ||
async updateAttributesForFaceting( | ||
attributesForFaceting: string[] | ||
attributesForFaceting: string[] | null | ||
): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.updateAttributesForFaceting(this.uid) | ||
const url = `indexes/${this.uid}/settings/attributes-for-faceting` | ||
return await this.httpRequest.post(url, attributesForFaceting) | ||
@@ -744,3 +585,3 @@ } | ||
async resetAttributesForFaceting(): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.resetAttributesForFaceting(this.uid) | ||
const url = `indexes/${this.uid}/settings/attributes-for-faceting` | ||
return await this.httpRequest.delete<Types.EnqueuedUpdate>(url) | ||
@@ -759,3 +600,3 @@ } | ||
async getSearchableAttributes(): Promise<string[]> { | ||
const url = Index.routeConstructors.getSearchableAttributes(this.uid) | ||
const url = `indexes/${this.uid}/settings/searchable-attributes` | ||
return await this.httpRequest.get<string[]>(url) | ||
@@ -770,5 +611,5 @@ } | ||
async updateSearchableAttributes( | ||
searchableAttributes: string[] | ||
searchableAttributes: string[] | null | ||
): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.updateSearchableAttributes(this.uid) | ||
const url = `indexes/${this.uid}/settings/searchable-attributes` | ||
return await this.httpRequest.post(url, searchableAttributes) | ||
@@ -783,3 +624,3 @@ } | ||
async resetSearchableAttributes(): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.resetSearchableAttributes(this.uid) | ||
const url = `indexes/${this.uid}/settings/searchable-attributes` | ||
return await this.httpRequest.delete<Types.EnqueuedUpdate>(url) | ||
@@ -798,3 +639,3 @@ } | ||
async getDisplayedAttributes(): Promise<string[]> { | ||
const url = Index.routeConstructors.getDisplayedAttributes(this.uid) | ||
const url = `indexes/${this.uid}/settings/displayed-attributes` | ||
return await this.httpRequest.get<string[]>(url) | ||
@@ -809,5 +650,5 @@ } | ||
async updateDisplayedAttributes( | ||
displayedAttributes: string[] | ||
displayedAttributes: string[] | null | ||
): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.updateDisplayedAttributes(this.uid) | ||
const url = `indexes/${this.uid}/settings/displayed-attributes` | ||
return await this.httpRequest.post(url, displayedAttributes) | ||
@@ -822,3 +663,3 @@ } | ||
async resetDisplayedAttributes(): Promise<Types.EnqueuedUpdate> { | ||
const url = Index.routeConstructors.resetDisplayedAttributes(this.uid) | ||
const url = `indexes/${this.uid}/settings/displayed-attributes` | ||
return await this.httpRequest.delete<Types.EnqueuedUpdate>(url) | ||
@@ -825,0 +666,0 @@ } |
@@ -15,24 +15,5 @@ /* | ||
type createPath = (x: string | number) => string | ||
export class MeiliSearch implements Types.MeiliSearchInterface { | ||
config: Types.Config | ||
httpRequest: HttpRequests | ||
static apiRoutes: { | ||
[key: string]: string | ||
} = { | ||
listIndexes: 'indexes', | ||
getKeys: 'keys', | ||
health: 'health', | ||
stats: 'stats', | ||
version: 'version', | ||
createDump: 'dumps', | ||
} | ||
static routeConstructors: { | ||
[key: string]: createPath | ||
} = { | ||
getDumpStatus: (dumpUid: string | number) => { | ||
return `dumps/${dumpUid}/status` | ||
}, | ||
} | ||
@@ -45,9 +26,2 @@ constructor(config: Types.Config) { | ||
static getApiRoutes(): { [key: string]: string } { | ||
return MeiliSearch.apiRoutes | ||
} | ||
static getRouteConstructors(): { [key: string]: createPath } { | ||
return MeiliSearch.routeConstructors | ||
} | ||
/** | ||
@@ -98,3 +72,3 @@ * Return an Index instance | ||
async listIndexes(): Promise<Types.IndexResponse[]> { | ||
const url = MeiliSearch.apiRoutes.listIndexes | ||
const url = `indexes` | ||
return await this.httpRequest.get<Types.IndexResponse[]>(url) | ||
@@ -136,2 +110,19 @@ } | ||
/** | ||
* Deletes an index if it already exists. | ||
* @memberof MeiliSearch | ||
* @method deleteIndexIfExists | ||
*/ | ||
async deleteIndexIfExists(uid: string): Promise<boolean> { | ||
try { | ||
await this.deleteIndex(uid) | ||
return true | ||
} catch (e) { | ||
if (e.errorCode === 'index_not_found') { | ||
return false | ||
} | ||
throw e | ||
} | ||
} | ||
/// | ||
@@ -147,3 +138,3 @@ /// KEYS | ||
async getKeys(): Promise<Types.Keys> { | ||
const url = MeiliSearch.apiRoutes.getKeys | ||
const url = `keys` | ||
return await this.httpRequest.get<Types.Keys>(url) | ||
@@ -163,5 +154,4 @@ } | ||
async health(): Promise<Types.Health> { | ||
return await this.httpRequest.get<Types.Health>( | ||
MeiliSearch.apiRoutes.health | ||
) | ||
const url = `health` | ||
return await this.httpRequest.get<Types.Health>(url) | ||
} | ||
@@ -177,3 +167,4 @@ | ||
try { | ||
await this.httpRequest.get(MeiliSearch.apiRoutes.health) | ||
const url = `health` | ||
await this.httpRequest.get(url) | ||
return true | ||
@@ -195,6 +186,10 @@ } catch (e) { | ||
async stats(): Promise<Types.Stats> { | ||
const url = MeiliSearch.apiRoutes.stats | ||
const url = `stats` | ||
return await this.httpRequest.get<Types.Stats>(url) | ||
} | ||
/// | ||
/// VERSION | ||
/// | ||
/** | ||
@@ -206,3 +201,3 @@ * Get the version of MeiliSearch | ||
async version(): Promise<Types.Version> { | ||
const url = MeiliSearch.apiRoutes.version | ||
const url = `version` | ||
return await this.httpRequest.get<Types.Version>(url) | ||
@@ -221,3 +216,3 @@ } | ||
async createDump(): Promise<Types.EnqueuedDump> { | ||
const url = MeiliSearch.apiRoutes.createDump | ||
const url = `dumps` | ||
return await this.httpRequest.post<undefined, Types.EnqueuedDump>(url) | ||
@@ -232,5 +227,5 @@ } | ||
async getDumpStatus(dumpUid: string): Promise<Types.EnqueuedDump> { | ||
const url = MeiliSearch.routeConstructors.getDumpStatus(dumpUid) | ||
const url = `dumps/${dumpUid}/status` | ||
return await this.httpRequest.get<Types.EnqueuedDump>(url) | ||
} | ||
} |
@@ -266,2 +266,3 @@ // Type definitions for meilisearch | ||
deleteIndex: (uid: string) => Promise<void> | ||
deleteIndexIfExists: (uid: string) => Promise<boolean> | ||
getKeys: () => Promise<Keys> | ||
@@ -293,2 +294,3 @@ health: () => Promise<Health> | ||
delete: () => Promise<void> | ||
deleteIfExists: () => Promise<boolean> | ||
getStats: () => Promise<IndexStats> | ||
@@ -322,7 +324,7 @@ getDocuments: <P extends GetDocumentsParams<T>>( | ||
getRankingRules: () => Promise<string[]> | ||
updateRankingRules: (rankingRules: string[]) => Promise<EnqueuedUpdate> | ||
updateRankingRules: (rankingRules: string[] | null) => Promise<EnqueuedUpdate> | ||
resetRankingRules: () => Promise<EnqueuedUpdate> | ||
getDistinctAttribute: () => Promise<string | null> | ||
updateDistinctAttribute: ( | ||
distinctAttribute: string | ||
distinctAttribute: string | null | ||
) => Promise<EnqueuedUpdate> | ||
@@ -332,3 +334,3 @@ resetDistinctAttribute: () => Promise<EnqueuedUpdate> | ||
updateAttributesForFaceting: ( | ||
attributesForFaceting: string[] | ||
attributesForFaceting: string[] | null | ||
) => Promise<EnqueuedUpdate> | ||
@@ -338,3 +340,3 @@ resetAttributesForFaceting: () => Promise<EnqueuedUpdate> | ||
updateSearchableAttributes: ( | ||
searchableAttributes: string[] | ||
searchableAttributes: string[] | null | ||
) => Promise<EnqueuedUpdate> | ||
@@ -344,3 +346,3 @@ resetSearchableAttributes: () => Promise<EnqueuedUpdate> | ||
updateDisplayedAttributes: ( | ||
displayedAttributes: string[] | ||
displayedAttributes: string[] | null | ||
) => Promise<EnqueuedUpdate> | ||
@@ -347,0 +349,0 @@ resetDisplayedAttributes: () => Promise<EnqueuedUpdate> |
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
34
536
4
280976
5759