typesense-instantsearch-adapter 2.9.0 → 2.9.1-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/typesense-instantsearch-adapter.js +212 -172
- package/dist/typesense-instantsearch-adapter.js.map +1 -1
- package/dist/typesense-instantsearch-adapter.min.js +1 -1
- package/dist/typesense-instantsearch-adapter.min.js.map +1 -1
- package/index.d.ts +18 -19
- package/lib/FacetSearchResponseAdapter.js +10 -8
- package/lib/FacetSearchResponseAdapter.js.map +1 -1
- package/package.json +2 -2
- package/src/FacetSearchResponseAdapter.js +12 -10
|
@@ -147,17 +147,19 @@ var FacetSearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
147
147
|
key: "_adaptFacetHits",
|
|
148
148
|
value: function _adaptFacetHits(typesenseFacetCounts) {
|
|
149
149
|
var _this = this;
|
|
150
|
-
var adaptedResult =
|
|
150
|
+
var adaptedResult = [];
|
|
151
151
|
var facet = typesenseFacetCounts.find(function (facet) {
|
|
152
152
|
return facet.field_name === _this.instantsearchRequest.params.facetName;
|
|
153
153
|
});
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
154
|
+
if (typeof facet !== 'undefined') {
|
|
155
|
+
adaptedResult = facet.counts.map(function (facetCount) {
|
|
156
|
+
return {
|
|
157
|
+
value: facetCount.value,
|
|
158
|
+
highlighted: _this._adaptHighlightTag(facetCount.highlighted, _this.instantsearchRequest.params.highlightPreTag, _this.instantsearchRequest.params.highlightPostTag),
|
|
159
|
+
count: facetCount.count
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
}
|
|
161
163
|
return adaptedResult;
|
|
162
164
|
}
|
|
163
165
|
}, {
|
|
@@ -1743,12 +1745,14 @@ var http_1 = __webpack_require__(/*! http */ "?92a5");
|
|
|
1743
1745
|
var https_1 = __webpack_require__(/*! https */ "?ba77");
|
|
1744
1746
|
var Errors_1 = __webpack_require__(/*! ./Errors */ "./node_modules/typesense/lib/Typesense/Errors/index.js");
|
|
1745
1747
|
var TypesenseError_1 = tslib_1.__importDefault(__webpack_require__(/*! ./Errors/TypesenseError */ "./node_modules/typesense/lib/Typesense/Errors/TypesenseError.js"));
|
|
1748
|
+
var Utils_1 = __webpack_require__(/*! ./Utils */ "./node_modules/typesense/lib/Typesense/Utils.js");
|
|
1746
1749
|
var APIKEYHEADERNAME = "X-TYPESENSE-API-KEY";
|
|
1747
1750
|
var HEALTHY = true;
|
|
1748
1751
|
var UNHEALTHY = false;
|
|
1749
1752
|
var isNodeJSEnvironment = typeof process !== "undefined" &&
|
|
1750
1753
|
process.versions != null &&
|
|
1751
|
-
process.versions.node != null
|
|
1754
|
+
process.versions.node != null &&
|
|
1755
|
+
typeof window === "undefined";
|
|
1752
1756
|
var ApiCall = /** @class */ (function () {
|
|
1753
1757
|
function ApiCall(configuration) {
|
|
1754
1758
|
this.configuration = configuration;
|
|
@@ -1774,13 +1778,15 @@ var ApiCall = /** @class */ (function () {
|
|
|
1774
1778
|
}
|
|
1775
1779
|
ApiCall.prototype.get = function (endpoint, queryParameters, _a) {
|
|
1776
1780
|
if (queryParameters === void 0) { queryParameters = {}; }
|
|
1777
|
-
var _b = _a === void 0 ? {} : _a, _c = _b.abortSignal, abortSignal = _c === void 0 ? null : _c, _d = _b.responseType, responseType = _d === void 0 ? undefined : _d;
|
|
1781
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.abortSignal, abortSignal = _c === void 0 ? null : _c, _d = _b.responseType, responseType = _d === void 0 ? undefined : _d, _e = _b.streamConfig, streamConfig = _e === void 0 ? undefined : _e, isStreamingRequest = _b.isStreamingRequest;
|
|
1778
1782
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1779
|
-
return tslib_1.__generator(this, function (
|
|
1783
|
+
return tslib_1.__generator(this, function (_f) {
|
|
1780
1784
|
return [2 /*return*/, this.performRequest("get", endpoint, {
|
|
1781
1785
|
queryParameters: queryParameters,
|
|
1782
1786
|
abortSignal: abortSignal,
|
|
1783
1787
|
responseType: responseType,
|
|
1788
|
+
streamConfig: streamConfig,
|
|
1789
|
+
isStreamingRequest: isStreamingRequest,
|
|
1784
1790
|
})];
|
|
1785
1791
|
});
|
|
1786
1792
|
});
|
|
@@ -1789,20 +1795,28 @@ var ApiCall = /** @class */ (function () {
|
|
|
1789
1795
|
if (queryParameters === void 0) { queryParameters = {}; }
|
|
1790
1796
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1791
1797
|
return tslib_1.__generator(this, function (_a) {
|
|
1792
|
-
return [2 /*return*/, this.performRequest("delete", endpoint, {
|
|
1798
|
+
return [2 /*return*/, this.performRequest("delete", endpoint, {
|
|
1799
|
+
queryParameters: queryParameters,
|
|
1800
|
+
isStreamingRequest: false,
|
|
1801
|
+
})];
|
|
1793
1802
|
});
|
|
1794
1803
|
});
|
|
1795
1804
|
};
|
|
1796
|
-
ApiCall.prototype.post = function (endpoint, bodyParameters, queryParameters, additionalHeaders) {
|
|
1805
|
+
ApiCall.prototype.post = function (endpoint, bodyParameters, queryParameters, additionalHeaders, _a) {
|
|
1797
1806
|
if (bodyParameters === void 0) { bodyParameters = {}; }
|
|
1798
1807
|
if (queryParameters === void 0) { queryParameters = {}; }
|
|
1799
1808
|
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
1809
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.abortSignal, abortSignal = _c === void 0 ? null : _c, _d = _b.responseType, responseType = _d === void 0 ? undefined : _d, _e = _b.streamConfig, streamConfig = _e === void 0 ? undefined : _e, isStreamingRequest = _b.isStreamingRequest;
|
|
1800
1810
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1801
|
-
return tslib_1.__generator(this, function (
|
|
1811
|
+
return tslib_1.__generator(this, function (_f) {
|
|
1802
1812
|
return [2 /*return*/, this.performRequest("post", endpoint, {
|
|
1803
1813
|
queryParameters: queryParameters,
|
|
1804
1814
|
bodyParameters: bodyParameters,
|
|
1805
1815
|
additionalHeaders: additionalHeaders,
|
|
1816
|
+
abortSignal: abortSignal,
|
|
1817
|
+
responseType: responseType,
|
|
1818
|
+
streamConfig: streamConfig,
|
|
1819
|
+
isStreamingRequest: isStreamingRequest,
|
|
1806
1820
|
})];
|
|
1807
1821
|
});
|
|
1808
1822
|
});
|
|
@@ -1815,6 +1829,7 @@ var ApiCall = /** @class */ (function () {
|
|
|
1815
1829
|
return [2 /*return*/, this.performRequest("put", endpoint, {
|
|
1816
1830
|
queryParameters: queryParameters,
|
|
1817
1831
|
bodyParameters: bodyParameters,
|
|
1832
|
+
isStreamingRequest: false,
|
|
1818
1833
|
})];
|
|
1819
1834
|
});
|
|
1820
1835
|
});
|
|
@@ -1827,6 +1842,7 @@ var ApiCall = /** @class */ (function () {
|
|
|
1827
1842
|
return [2 /*return*/, this.performRequest("patch", endpoint, {
|
|
1828
1843
|
queryParameters: queryParameters,
|
|
1829
1844
|
bodyParameters: bodyParameters,
|
|
1845
|
+
isStreamingRequest: false,
|
|
1830
1846
|
})];
|
|
1831
1847
|
});
|
|
1832
1848
|
});
|
|
@@ -1844,15 +1860,13 @@ var ApiCall = /** @class */ (function () {
|
|
|
1844
1860
|
};
|
|
1845
1861
|
ApiCall.prototype.performRequest = function (requestType, endpoint, _a) {
|
|
1846
1862
|
var _b, _c, _d, _e;
|
|
1847
|
-
var _f = _a.queryParameters, queryParameters = _f === void 0 ? null : _f, _g = _a.bodyParameters, bodyParameters = _g === void 0 ? null : _g, _h = _a.additionalHeaders, additionalHeaders = _h === void 0 ? {} : _h, _j = _a.abortSignal, abortSignal = _j === void 0 ? null : _j, _k = _a.responseType, responseType = _k === void 0 ? undefined : _k, _l = _a.skipConnectionTimeout, skipConnectionTimeout = _l === void 0 ? false : _l, _m = _a.enableKeepAlive, enableKeepAlive = _m === void 0 ? undefined : _m;
|
|
1863
|
+
var _f = _a.queryParameters, queryParameters = _f === void 0 ? null : _f, _g = _a.bodyParameters, bodyParameters = _g === void 0 ? null : _g, _h = _a.additionalHeaders, additionalHeaders = _h === void 0 ? {} : _h, _j = _a.abortSignal, abortSignal = _j === void 0 ? null : _j, _k = _a.responseType, responseType = _k === void 0 ? undefined : _k, _l = _a.skipConnectionTimeout, skipConnectionTimeout = _l === void 0 ? false : _l, _m = _a.enableKeepAlive, enableKeepAlive = _m === void 0 ? undefined : _m, _o = _a.streamConfig, streamConfig = _o === void 0 ? undefined : _o, isStreamingRequest = _a.isStreamingRequest;
|
|
1848
1864
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1849
|
-
var
|
|
1850
|
-
return tslib_1.__generator(this, function (
|
|
1851
|
-
switch (
|
|
1865
|
+
var requestNumber, lastException, wasAborted, _loop_1, this_1, numTries, state_1;
|
|
1866
|
+
return tslib_1.__generator(this, function (_p) {
|
|
1867
|
+
switch (_p.label) {
|
|
1852
1868
|
case 0:
|
|
1853
1869
|
this.configuration.validate();
|
|
1854
|
-
isStreamingRequest = (queryParameters === null || queryParameters === void 0 ? void 0 : queryParameters.conversation_stream) === true &&
|
|
1855
|
-
requestType.toLowerCase() === "get";
|
|
1856
1870
|
if (isStreamingRequest) {
|
|
1857
1871
|
this.logger.debug("Request: Performing streaming request to ".concat(endpoint));
|
|
1858
1872
|
// For browser streaming, always use responseType: "stream" and adapter: "fetch"
|
|
@@ -1866,8 +1880,8 @@ var ApiCall = /** @class */ (function () {
|
|
|
1866
1880
|
this.logger.debug("Request #".concat(requestNumber, ": Performing ").concat(requestType.toUpperCase(), " request: ").concat(endpoint));
|
|
1867
1881
|
_loop_1 = function (numTries) {
|
|
1868
1882
|
var node, abortListener, requestOptions, cancelToken, source_1, response, error_1;
|
|
1869
|
-
return tslib_1.__generator(this, function (
|
|
1870
|
-
switch (
|
|
1883
|
+
return tslib_1.__generator(this, function (_q) {
|
|
1884
|
+
switch (_q.label) {
|
|
1871
1885
|
case 0:
|
|
1872
1886
|
node = this_1.getNextNode(requestNumber);
|
|
1873
1887
|
this_1.logger.debug("Request #".concat(requestNumber, ": Attempting ").concat(requestType.toUpperCase(), " request Try #").concat(numTries, " to Node ").concat(node.index));
|
|
@@ -1875,9 +1889,9 @@ var ApiCall = /** @class */ (function () {
|
|
|
1875
1889
|
return [2 /*return*/, { value: Promise.reject(new Error("Request aborted by caller.")) }];
|
|
1876
1890
|
}
|
|
1877
1891
|
abortListener = void 0;
|
|
1878
|
-
|
|
1892
|
+
_q.label = 1;
|
|
1879
1893
|
case 1:
|
|
1880
|
-
|
|
1894
|
+
_q.trys.push([1, 3, 5, 6]);
|
|
1881
1895
|
requestOptions = {
|
|
1882
1896
|
method: requestType,
|
|
1883
1897
|
url: this_1.uriFor(endpoint, node),
|
|
@@ -1978,7 +1992,7 @@ var ApiCall = /** @class */ (function () {
|
|
|
1978
1992
|
}
|
|
1979
1993
|
return [4 /*yield*/, (0, axios_1.default)(requestOptions)];
|
|
1980
1994
|
case 2:
|
|
1981
|
-
response =
|
|
1995
|
+
response = _q.sent();
|
|
1982
1996
|
if (response.status >= 1 && response.status <= 499) {
|
|
1983
1997
|
// Treat any status code > 0 and < 500 to be an indication that node is healthy
|
|
1984
1998
|
// We exclude 0 since some clients return 0 when request fails
|
|
@@ -1986,8 +2000,9 @@ var ApiCall = /** @class */ (function () {
|
|
|
1986
2000
|
}
|
|
1987
2001
|
this_1.logger.debug("Request #".concat(requestNumber, ": Request to Node ").concat(node.index, " was made. Response Code was ").concat(response.status, "."));
|
|
1988
2002
|
if (response.status >= 200 && response.status < 300) {
|
|
1989
|
-
if (isStreamingRequest)
|
|
1990
|
-
return [2 /*return*/, { value: this_1.handleStreamingResponse(response) }];
|
|
2003
|
+
if (isStreamingRequest) {
|
|
2004
|
+
return [2 /*return*/, { value: this_1.handleStreamingResponse(response, streamConfig) }];
|
|
2005
|
+
}
|
|
1991
2006
|
return [2 /*return*/, { value: Promise.resolve(response.data) }];
|
|
1992
2007
|
}
|
|
1993
2008
|
else if (response.status < 500) {
|
|
@@ -2000,7 +2015,7 @@ var ApiCall = /** @class */ (function () {
|
|
|
2000
2015
|
}
|
|
2001
2016
|
return [3 /*break*/, 6];
|
|
2002
2017
|
case 3:
|
|
2003
|
-
error_1 =
|
|
2018
|
+
error_1 = _q.sent();
|
|
2004
2019
|
// This block handles retries for HTTPStatus > 500 and network layer issues like connection timeouts
|
|
2005
2020
|
if (!wasAborted) {
|
|
2006
2021
|
this_1.setNodeHealthcheck(node, UNHEALTHY);
|
|
@@ -2013,7 +2028,7 @@ var ApiCall = /** @class */ (function () {
|
|
|
2013
2028
|
return [2 /*return*/, { value: Promise.reject(new Error("Request aborted by caller.")) }];
|
|
2014
2029
|
}
|
|
2015
2030
|
if (isStreamingRequest) {
|
|
2016
|
-
this_1.invokeOnErrorCallback(error_1);
|
|
2031
|
+
this_1.invokeOnErrorCallback(error_1, streamConfig);
|
|
2017
2032
|
}
|
|
2018
2033
|
if (numTries < this_1.numRetriesPerRequest + 1) {
|
|
2019
2034
|
this_1.logger.warn("Request #".concat(requestNumber, ": Sleeping for ").concat(this_1.retryIntervalSeconds, "s and then retrying request..."));
|
|
@@ -2024,7 +2039,7 @@ var ApiCall = /** @class */ (function () {
|
|
|
2024
2039
|
}
|
|
2025
2040
|
return [4 /*yield*/, this_1.timer(this_1.retryIntervalSeconds)];
|
|
2026
2041
|
case 4:
|
|
2027
|
-
|
|
2042
|
+
_q.sent();
|
|
2028
2043
|
return [3 /*break*/, 6];
|
|
2029
2044
|
case 5:
|
|
2030
2045
|
if (abortSignal && abortListener) {
|
|
@@ -2037,15 +2052,15 @@ var ApiCall = /** @class */ (function () {
|
|
|
2037
2052
|
};
|
|
2038
2053
|
this_1 = this;
|
|
2039
2054
|
numTries = 1;
|
|
2040
|
-
|
|
2055
|
+
_p.label = 1;
|
|
2041
2056
|
case 1:
|
|
2042
2057
|
if (!(numTries <= this.numRetriesPerRequest + 1)) return [3 /*break*/, 4];
|
|
2043
2058
|
return [5 /*yield**/, _loop_1(numTries)];
|
|
2044
2059
|
case 2:
|
|
2045
|
-
state_1 =
|
|
2060
|
+
state_1 = _p.sent();
|
|
2046
2061
|
if (typeof state_1 === "object")
|
|
2047
2062
|
return [2 /*return*/, state_1.value];
|
|
2048
|
-
|
|
2063
|
+
_p.label = 3;
|
|
2049
2064
|
case 3:
|
|
2050
2065
|
numTries++;
|
|
2051
2066
|
return [3 /*break*/, 1];
|
|
@@ -2130,23 +2145,23 @@ var ApiCall = /** @class */ (function () {
|
|
|
2130
2145
|
message: dataContent,
|
|
2131
2146
|
};
|
|
2132
2147
|
};
|
|
2133
|
-
ApiCall.prototype.handleStreamingResponse = function (response) {
|
|
2148
|
+
ApiCall.prototype.handleStreamingResponse = function (response, streamConfig) {
|
|
2134
2149
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
2135
2150
|
return tslib_1.__generator(this, function (_a) {
|
|
2136
2151
|
this.logger.debug("Handling streaming response. Environment: ".concat(isNodeJSEnvironment ? "Node.js" : "Browser"));
|
|
2137
2152
|
if (isNodeJSEnvironment && response.data) {
|
|
2138
|
-
return [2 /*return*/, this.handleNodeStreaming(response)];
|
|
2153
|
+
return [2 /*return*/, this.handleNodeStreaming(response, streamConfig)];
|
|
2139
2154
|
}
|
|
2140
2155
|
if (!isNodeJSEnvironment) {
|
|
2141
|
-
return [2 /*return*/, this.handleBrowserStreaming(response)];
|
|
2156
|
+
return [2 /*return*/, this.handleBrowserStreaming(response, streamConfig)];
|
|
2142
2157
|
}
|
|
2143
2158
|
this.logger.debug("Processing non-streaming response");
|
|
2144
|
-
this.invokeOnCompleteCallback(response.data);
|
|
2159
|
+
this.invokeOnCompleteCallback(response.data, streamConfig);
|
|
2145
2160
|
return [2 /*return*/, Promise.resolve(response.data)];
|
|
2146
2161
|
});
|
|
2147
2162
|
});
|
|
2148
2163
|
};
|
|
2149
|
-
ApiCall.prototype.handleNodeStreaming = function (response) {
|
|
2164
|
+
ApiCall.prototype.handleNodeStreaming = function (response, streamConfig) {
|
|
2150
2165
|
var _this = this;
|
|
2151
2166
|
this.logger.debug("Processing Node.js stream");
|
|
2152
2167
|
return new Promise(function (resolve, reject) {
|
|
@@ -2160,7 +2175,7 @@ var ApiCall = /** @class */ (function () {
|
|
|
2160
2175
|
buffer += data;
|
|
2161
2176
|
var lines = buffer.split("\n");
|
|
2162
2177
|
buffer = (_a = lines.pop()) !== null && _a !== void 0 ? _a : "";
|
|
2163
|
-
_this.processStreamLines(lines, allChunks);
|
|
2178
|
+
_this.processStreamLines(lines, allChunks, streamConfig);
|
|
2164
2179
|
}
|
|
2165
2180
|
catch (error) {
|
|
2166
2181
|
reject(error);
|
|
@@ -2169,32 +2184,32 @@ var ApiCall = /** @class */ (function () {
|
|
|
2169
2184
|
stream.on("end", function () {
|
|
2170
2185
|
if (buffer.trim().length > 0) {
|
|
2171
2186
|
var lines = buffer.split("\n");
|
|
2172
|
-
_this.processStreamLines(lines, allChunks);
|
|
2187
|
+
_this.processStreamLines(lines, allChunks, streamConfig);
|
|
2173
2188
|
}
|
|
2174
|
-
_this.finalizeStreamResult(allChunks, resolve, response);
|
|
2189
|
+
_this.finalizeStreamResult(allChunks, resolve, response, streamConfig);
|
|
2175
2190
|
});
|
|
2176
2191
|
stream.on("error", function (error) {
|
|
2177
2192
|
_this.logger.error("Stream error: ".concat(error));
|
|
2178
|
-
_this.invokeOnErrorCallback(error);
|
|
2193
|
+
_this.invokeOnErrorCallback(error, streamConfig);
|
|
2179
2194
|
reject(error);
|
|
2180
2195
|
});
|
|
2181
2196
|
});
|
|
2182
2197
|
};
|
|
2183
|
-
ApiCall.prototype.handleBrowserStreaming = function (response) {
|
|
2198
|
+
ApiCall.prototype.handleBrowserStreaming = function (response, streamConfig) {
|
|
2184
2199
|
var _this = this;
|
|
2185
2200
|
this.logger.debug("Processing browser stream");
|
|
2186
2201
|
return new Promise(function (resolve, reject) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
2187
2202
|
return tslib_1.__generator(this, function (_a) {
|
|
2188
2203
|
try {
|
|
2189
2204
|
if (response.data && typeof response.data.getReader === "function") {
|
|
2190
|
-
return [2 /*return*/, this.handleBrowserReadableStream(response.data, resolve, reject, response)];
|
|
2205
|
+
return [2 /*return*/, this.handleBrowserReadableStream(response.data, resolve, reject, response, streamConfig)];
|
|
2191
2206
|
}
|
|
2192
2207
|
if (typeof response.data === "string") {
|
|
2193
|
-
return [2 /*return*/, this.handleBrowserStringResponse(response.data, resolve, response)];
|
|
2208
|
+
return [2 /*return*/, this.handleBrowserStringResponse(response.data, resolve, response, streamConfig)];
|
|
2194
2209
|
}
|
|
2195
2210
|
if (typeof response.data === "object" && response.data !== null) {
|
|
2196
2211
|
this.logger.debug("No stream found, but data object is available");
|
|
2197
|
-
this.invokeOnCompleteCallback(response.data);
|
|
2212
|
+
this.invokeOnCompleteCallback(response.data, streamConfig);
|
|
2198
2213
|
return [2 /*return*/, resolve(response.data)];
|
|
2199
2214
|
}
|
|
2200
2215
|
this.logger.error("No usable data found in response");
|
|
@@ -2202,14 +2217,14 @@ var ApiCall = /** @class */ (function () {
|
|
|
2202
2217
|
}
|
|
2203
2218
|
catch (error) {
|
|
2204
2219
|
this.logger.error("Error processing streaming response: ".concat(error));
|
|
2205
|
-
this.invokeOnErrorCallback(error);
|
|
2220
|
+
this.invokeOnErrorCallback(error, streamConfig);
|
|
2206
2221
|
reject(error);
|
|
2207
2222
|
}
|
|
2208
2223
|
return [2 /*return*/];
|
|
2209
2224
|
});
|
|
2210
2225
|
}); });
|
|
2211
2226
|
};
|
|
2212
|
-
ApiCall.prototype.handleBrowserReadableStream = function (stream, resolve, reject, response) {
|
|
2227
|
+
ApiCall.prototype.handleBrowserReadableStream = function (stream, resolve, reject, response, streamConfig) {
|
|
2213
2228
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
2214
2229
|
var reader, allChunks, buffer, _a, done, value, lines_1, chunk, lines, error_2;
|
|
2215
2230
|
return tslib_1.__generator(this, function (_b) {
|
|
@@ -2232,7 +2247,7 @@ var ApiCall = /** @class */ (function () {
|
|
|
2232
2247
|
this.logger.debug("Stream reading complete");
|
|
2233
2248
|
if (buffer.trim()) {
|
|
2234
2249
|
lines_1 = buffer.split("\n");
|
|
2235
|
-
this.processStreamLines(lines_1, allChunks);
|
|
2250
|
+
this.processStreamLines(lines_1, allChunks, streamConfig);
|
|
2236
2251
|
}
|
|
2237
2252
|
return [3 /*break*/, 4];
|
|
2238
2253
|
}
|
|
@@ -2241,13 +2256,15 @@ var ApiCall = /** @class */ (function () {
|
|
|
2241
2256
|
buffer += chunk;
|
|
2242
2257
|
lines = buffer.split("\n");
|
|
2243
2258
|
buffer = lines.pop() || "";
|
|
2244
|
-
this.processStreamLines(lines, allChunks);
|
|
2259
|
+
this.processStreamLines(lines, allChunks, streamConfig);
|
|
2245
2260
|
return [3 /*break*/, 2];
|
|
2246
2261
|
case 4:
|
|
2247
|
-
this.finalizeStreamResult(allChunks, resolve, response);
|
|
2262
|
+
this.finalizeStreamResult(allChunks, resolve, response, streamConfig);
|
|
2248
2263
|
return [3 /*break*/, 6];
|
|
2249
2264
|
case 5:
|
|
2250
2265
|
error_2 = _b.sent();
|
|
2266
|
+
this.logger.error("Stream error: ".concat(error_2));
|
|
2267
|
+
this.invokeOnErrorCallback(error_2, streamConfig);
|
|
2251
2268
|
reject(error_2);
|
|
2252
2269
|
return [3 /*break*/, 6];
|
|
2253
2270
|
case 6: return [2 /*return*/];
|
|
@@ -2255,45 +2272,45 @@ var ApiCall = /** @class */ (function () {
|
|
|
2255
2272
|
});
|
|
2256
2273
|
});
|
|
2257
2274
|
};
|
|
2258
|
-
ApiCall.prototype.handleBrowserStringResponse = function (data, resolve, response) {
|
|
2275
|
+
ApiCall.prototype.handleBrowserStringResponse = function (data, resolve, response, streamConfig) {
|
|
2259
2276
|
this.logger.debug("Processing text response as stream data");
|
|
2260
2277
|
var allChunks = [];
|
|
2261
2278
|
var lines = data.split("\n");
|
|
2262
|
-
this.processStreamLines(lines, allChunks);
|
|
2279
|
+
this.processStreamLines(lines, allChunks, streamConfig);
|
|
2263
2280
|
if (allChunks.length > 0) {
|
|
2264
2281
|
var finalResult = this.combineStreamingChunks(allChunks);
|
|
2265
|
-
this.invokeOnCompleteCallback(finalResult);
|
|
2282
|
+
this.invokeOnCompleteCallback(finalResult, streamConfig);
|
|
2266
2283
|
resolve(finalResult);
|
|
2267
2284
|
}
|
|
2268
2285
|
else {
|
|
2269
2286
|
// If no chunks were processed, use the original response
|
|
2270
2287
|
this.logger.debug("No chunks processed, returning original API response");
|
|
2271
|
-
this.invokeOnCompleteCallback(response.data);
|
|
2288
|
+
this.invokeOnCompleteCallback(response.data, streamConfig);
|
|
2272
2289
|
resolve(response.data);
|
|
2273
2290
|
}
|
|
2274
2291
|
};
|
|
2275
|
-
ApiCall.prototype.processStreamLines = function (lines, allChunks) {
|
|
2292
|
+
ApiCall.prototype.processStreamLines = function (lines, allChunks, streamConfig) {
|
|
2276
2293
|
for (var _i = 0, lines_2 = lines; _i < lines_2.length; _i++) {
|
|
2277
2294
|
var line = lines_2[_i];
|
|
2278
2295
|
if (line.trim() && line !== "data: [DONE]") {
|
|
2279
2296
|
var processed = this.processStreamingLine(line);
|
|
2280
2297
|
if (processed !== null) {
|
|
2281
|
-
this.invokeOnChunkCallback(processed);
|
|
2298
|
+
this.invokeOnChunkCallback(processed, streamConfig);
|
|
2282
2299
|
allChunks.push(processed);
|
|
2283
2300
|
}
|
|
2284
2301
|
}
|
|
2285
2302
|
}
|
|
2286
2303
|
};
|
|
2287
|
-
ApiCall.prototype.finalizeStreamResult = function (allChunks, resolve, response) {
|
|
2304
|
+
ApiCall.prototype.finalizeStreamResult = function (allChunks, resolve, response, streamConfig) {
|
|
2288
2305
|
if (allChunks.length > 0) {
|
|
2289
2306
|
var finalResult = this.combineStreamingChunks(allChunks);
|
|
2290
2307
|
this.logger.debug("Stream processing complete");
|
|
2291
|
-
this.invokeOnCompleteCallback(finalResult);
|
|
2308
|
+
this.invokeOnCompleteCallback(finalResult, streamConfig);
|
|
2292
2309
|
resolve(finalResult);
|
|
2293
2310
|
}
|
|
2294
2311
|
else {
|
|
2295
2312
|
this.logger.debug("No chunks processed, returning original API response");
|
|
2296
|
-
this.invokeOnCompleteCallback(response.data);
|
|
2313
|
+
this.invokeOnCompleteCallback(response.data, streamConfig);
|
|
2297
2314
|
resolve(response.data);
|
|
2298
2315
|
}
|
|
2299
2316
|
};
|
|
@@ -2313,76 +2330,44 @@ var ApiCall = /** @class */ (function () {
|
|
|
2313
2330
|
}
|
|
2314
2331
|
// For regular search responses
|
|
2315
2332
|
var lastChunk = chunks[chunks.length - 1];
|
|
2316
|
-
if (this.isCompleteSearchResponse(lastChunk)) {
|
|
2317
|
-
|
|
2333
|
+
if (!this.isCompleteSearchResponse(lastChunk)) {
|
|
2334
|
+
throw new Error("Last chunk is not a complete search response");
|
|
2318
2335
|
}
|
|
2319
|
-
|
|
2320
|
-
return this.attemptChunksMerge(chunks, lastChunk);
|
|
2336
|
+
return lastChunk;
|
|
2321
2337
|
};
|
|
2322
2338
|
ApiCall.prototype.getMessageChunks = function (chunks) {
|
|
2323
|
-
return chunks.filter(
|
|
2324
|
-
|
|
2325
|
-
|
|
2339
|
+
return chunks.filter(this.isChunkMessage);
|
|
2340
|
+
};
|
|
2341
|
+
ApiCall.prototype.isChunkMessage = function (chunk) {
|
|
2342
|
+
return (typeof chunk === "object" &&
|
|
2343
|
+
chunk !== null &&
|
|
2344
|
+
"message" in chunk &&
|
|
2345
|
+
"conversation_id" in chunk);
|
|
2326
2346
|
};
|
|
2327
2347
|
ApiCall.prototype.combineMessageChunks = function (chunks, messagesChunks) {
|
|
2328
2348
|
this.logger.debug("Found ".concat(messagesChunks.length, " message chunks to combine"));
|
|
2329
|
-
// Check if the last chunk contains the complete response
|
|
2330
2349
|
var lastChunk = chunks[chunks.length - 1];
|
|
2331
|
-
if (
|
|
2332
|
-
lastChunk !== null &&
|
|
2333
|
-
("hits" in lastChunk || "found" in lastChunk)) {
|
|
2334
|
-
this.logger.debug("Last chunk appears to be a complete search response");
|
|
2350
|
+
if (this.isCompleteSearchResponse(lastChunk)) {
|
|
2335
2351
|
return lastChunk;
|
|
2336
2352
|
}
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
.join("");
|
|
2341
|
-
// Look for a chunk with search metadata
|
|
2342
|
-
var metadataChunk = chunks.find(function (chunk) {
|
|
2343
|
-
return typeof chunk === "object" &&
|
|
2344
|
-
chunk !== null &&
|
|
2345
|
-
("hits" in chunk || "found" in chunk || "request_params" in chunk);
|
|
2346
|
-
});
|
|
2347
|
-
if (metadataChunk) {
|
|
2348
|
-
// If we found metadata, merge it with the combined message
|
|
2349
|
-
return tslib_1.__assign(tslib_1.__assign({}, metadataChunk), { message: combinedMessage });
|
|
2353
|
+
var metadataChunk = chunks.find(this.isCompleteSearchResponse);
|
|
2354
|
+
if (!metadataChunk) {
|
|
2355
|
+
throw new Error("No metadata chunk found");
|
|
2350
2356
|
}
|
|
2351
|
-
|
|
2352
|
-
return { message: combinedMessage };
|
|
2357
|
+
return metadataChunk;
|
|
2353
2358
|
};
|
|
2354
2359
|
ApiCall.prototype.isCompleteSearchResponse = function (chunk) {
|
|
2355
2360
|
if (typeof chunk === "object" &&
|
|
2356
2361
|
chunk !== null &&
|
|
2357
2362
|
Object.keys(chunk).length > 0) {
|
|
2358
|
-
|
|
2359
|
-
|
|
2363
|
+
return ("results" in chunk ||
|
|
2364
|
+
"found" in chunk ||
|
|
2360
2365
|
"hits" in chunk ||
|
|
2361
2366
|
"page" in chunk ||
|
|
2362
2367
|
"search_time_ms" in chunk);
|
|
2363
2368
|
}
|
|
2364
2369
|
return false;
|
|
2365
2370
|
};
|
|
2366
|
-
ApiCall.prototype.attemptChunksMerge = function (chunks, lastChunk) {
|
|
2367
|
-
try {
|
|
2368
|
-
// Attempt to merge chunks that might be parts of the same structure
|
|
2369
|
-
var mergedResult = {};
|
|
2370
|
-
for (var _i = 0, chunks_1 = chunks; _i < chunks_1.length; _i++) {
|
|
2371
|
-
var chunk = chunks_1[_i];
|
|
2372
|
-
if (typeof chunk === "object" && chunk !== null) {
|
|
2373
|
-
mergedResult = tslib_1.__assign(tslib_1.__assign({}, mergedResult), chunk);
|
|
2374
|
-
}
|
|
2375
|
-
}
|
|
2376
|
-
if (Object.keys(mergedResult).length > 0) {
|
|
2377
|
-
return mergedResult;
|
|
2378
|
-
}
|
|
2379
|
-
}
|
|
2380
|
-
catch (e) {
|
|
2381
|
-
this.logger.warn("Failed to merge chunks: ".concat(e));
|
|
2382
|
-
}
|
|
2383
|
-
// Fallback to the last chunk if merging fails
|
|
2384
|
-
return lastChunk;
|
|
2385
|
-
};
|
|
2386
2371
|
// Attempts to find the next healthy node, looping through the list of nodes once.
|
|
2387
2372
|
// But if no healthy nodes are found, it will just return the next node, even if it's unhealthy
|
|
2388
2373
|
// so we can try the request for good measure, in case that node has become healthy since
|
|
@@ -2472,56 +2457,53 @@ var ApiCall = /** @class */ (function () {
|
|
|
2472
2457
|
}
|
|
2473
2458
|
var error = new TypesenseError_1.default(errorMessage, httpBody, response.status);
|
|
2474
2459
|
if (response.status === 400) {
|
|
2475
|
-
error = new Errors_1.RequestMalformed(errorMessage);
|
|
2460
|
+
error = new Errors_1.RequestMalformed(errorMessage, httpBody, response.status);
|
|
2476
2461
|
}
|
|
2477
2462
|
else if (response.status === 401) {
|
|
2478
|
-
error = new Errors_1.RequestUnauthorized(errorMessage);
|
|
2463
|
+
error = new Errors_1.RequestUnauthorized(errorMessage, httpBody, response.status);
|
|
2479
2464
|
}
|
|
2480
2465
|
else if (response.status === 404) {
|
|
2481
|
-
error = new Errors_1.ObjectNotFound(errorMessage);
|
|
2466
|
+
error = new Errors_1.ObjectNotFound(errorMessage, httpBody, response.status);
|
|
2482
2467
|
}
|
|
2483
2468
|
else if (response.status === 409) {
|
|
2484
|
-
error = new Errors_1.ObjectAlreadyExists(errorMessage);
|
|
2469
|
+
error = new Errors_1.ObjectAlreadyExists(errorMessage, httpBody, response.status);
|
|
2485
2470
|
}
|
|
2486
2471
|
else if (response.status === 422) {
|
|
2487
|
-
error = new Errors_1.ObjectUnprocessable(errorMessage);
|
|
2472
|
+
error = new Errors_1.ObjectUnprocessable(errorMessage, httpBody, response.status);
|
|
2488
2473
|
}
|
|
2489
2474
|
else if (response.status >= 500 && response.status <= 599) {
|
|
2490
|
-
error = new Errors_1.ServerError(errorMessage);
|
|
2475
|
+
error = new Errors_1.ServerError(errorMessage, httpBody, response.status);
|
|
2491
2476
|
}
|
|
2492
2477
|
else {
|
|
2493
|
-
error = new Errors_1.HTTPError(errorMessage);
|
|
2478
|
+
error = new Errors_1.HTTPError(errorMessage, httpBody, response.status);
|
|
2494
2479
|
}
|
|
2495
2480
|
return error;
|
|
2496
2481
|
};
|
|
2497
|
-
ApiCall.prototype.invokeOnChunkCallback = function (data) {
|
|
2498
|
-
|
|
2499
|
-
if ((_a = this.configuration.streamConfig) === null || _a === void 0 ? void 0 : _a.onChunk) {
|
|
2482
|
+
ApiCall.prototype.invokeOnChunkCallback = function (data, streamConfig) {
|
|
2483
|
+
if (streamConfig === null || streamConfig === void 0 ? void 0 : streamConfig.onChunk) {
|
|
2500
2484
|
try {
|
|
2501
|
-
|
|
2485
|
+
streamConfig.onChunk(data);
|
|
2502
2486
|
}
|
|
2503
2487
|
catch (error) {
|
|
2504
2488
|
this.logger.warn("Error in onChunk callback: ".concat(error));
|
|
2505
2489
|
}
|
|
2506
2490
|
}
|
|
2507
2491
|
};
|
|
2508
|
-
ApiCall.prototype.invokeOnCompleteCallback = function (data) {
|
|
2509
|
-
|
|
2510
|
-
if ((_a = this.configuration.streamConfig) === null || _a === void 0 ? void 0 : _a.onComplete) {
|
|
2492
|
+
ApiCall.prototype.invokeOnCompleteCallback = function (data, streamConfig) {
|
|
2493
|
+
if (streamConfig === null || streamConfig === void 0 ? void 0 : streamConfig.onComplete) {
|
|
2511
2494
|
try {
|
|
2512
|
-
|
|
2495
|
+
streamConfig.onComplete(data);
|
|
2513
2496
|
}
|
|
2514
2497
|
catch (error) {
|
|
2515
2498
|
this.logger.warn("Error in onComplete callback: ".concat(error));
|
|
2516
2499
|
}
|
|
2517
2500
|
}
|
|
2518
2501
|
};
|
|
2519
|
-
ApiCall.prototype.invokeOnErrorCallback = function (error) {
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
var errorObj = error instanceof Error ? error : new Error(String(error));
|
|
2502
|
+
ApiCall.prototype.invokeOnErrorCallback = function (error, streamConfig) {
|
|
2503
|
+
if (streamConfig === null || streamConfig === void 0 ? void 0 : streamConfig.onError) {
|
|
2504
|
+
var errorObj = (0, Utils_1.toErrorWithMessage)(error);
|
|
2523
2505
|
try {
|
|
2524
|
-
|
|
2506
|
+
streamConfig.onError(errorObj);
|
|
2525
2507
|
}
|
|
2526
2508
|
catch (callbackError) {
|
|
2527
2509
|
this.logger.warn("Error in onError callback: ".concat(callbackError));
|
|
@@ -2881,7 +2863,6 @@ var Configuration = /** @class */ (function () {
|
|
|
2881
2863
|
this.httpAgent = options.httpAgent;
|
|
2882
2864
|
this.httpsAgent = options.httpsAgent;
|
|
2883
2865
|
this.paramsSerializer = options.paramsSerializer;
|
|
2884
|
-
this.streamConfig = options.streamConfig;
|
|
2885
2866
|
this.showDeprecationWarnings(options);
|
|
2886
2867
|
this.validate();
|
|
2887
2868
|
}
|
|
@@ -3816,7 +3797,7 @@ var Keys = /** @class */ (function () {
|
|
|
3816
3797
|
};
|
|
3817
3798
|
Keys.prototype.generateScopedSearchKey = function (searchKey, parameters) {
|
|
3818
3799
|
// Note: only a key generated with the `documents:search` action will be
|
|
3819
|
-
// accepted by the server, when
|
|
3800
|
+
// accepted by the server, when used with the search endpoint.
|
|
3820
3801
|
var normalizedParams = (0, Utils_1.normalizeArrayableParams)(parameters);
|
|
3821
3802
|
var paramsJSON = JSON.stringify(normalizedParams);
|
|
3822
3803
|
var digest = Buffer.from((0, crypto_1.createHmac)("sha256", searchKey).update(paramsJSON).digest("base64"));
|
|
@@ -3892,32 +3873,37 @@ var MultiSearch = /** @class */ (function () {
|
|
|
3892
3873
|
this.requestWithCache.clearCache();
|
|
3893
3874
|
};
|
|
3894
3875
|
MultiSearch.prototype.perform = function (searchRequests, commonParams, _a) {
|
|
3895
|
-
if (commonParams === void 0) { commonParams = {}; }
|
|
3896
3876
|
var _b = _a === void 0 ? {} : _a, _c = _b.cacheSearchResultsForSeconds, cacheSearchResultsForSeconds = _c === void 0 ? this.configuration
|
|
3897
3877
|
.cacheSearchResultsForSeconds : _c;
|
|
3898
3878
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
3899
|
-
var
|
|
3879
|
+
var params, normalizedSearchRequests, streamConfig, paramsWithoutStream, normalizedQueryParams;
|
|
3900
3880
|
return tslib_1.__generator(this, function (_d) {
|
|
3901
|
-
|
|
3902
|
-
if (this.useTextContentType) {
|
|
3903
|
-
additionalHeaders["content-type"] = "text/plain";
|
|
3904
|
-
}
|
|
3905
|
-
additionalQueryParams = {};
|
|
3881
|
+
params = commonParams ? tslib_1.__assign({}, commonParams) : {};
|
|
3906
3882
|
if (this.configuration.useServerSideSearchCache === true) {
|
|
3907
|
-
|
|
3883
|
+
params.use_cache = true;
|
|
3908
3884
|
}
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3885
|
+
normalizedSearchRequests = {
|
|
3886
|
+
union: searchRequests.union,
|
|
3887
|
+
searches: searchRequests.searches.map((Utils_1.normalizeArrayableParams)),
|
|
3888
|
+
};
|
|
3889
|
+
streamConfig = params.streamConfig, paramsWithoutStream = tslib_1.__rest(params, ["streamConfig"]);
|
|
3890
|
+
normalizedQueryParams = (0, Utils_1.normalizeArrayableParams)(paramsWithoutStream);
|
|
3891
|
+
return [2 /*return*/, this.requestWithCache.perform(this.apiCall, "post", {
|
|
3892
|
+
path: RESOURCEPATH,
|
|
3893
|
+
body: normalizedSearchRequests,
|
|
3894
|
+
queryParams: normalizedQueryParams,
|
|
3895
|
+
headers: this.useTextContentType
|
|
3896
|
+
? { "content-type": "text/plain" }
|
|
3897
|
+
: {},
|
|
3898
|
+
streamConfig: streamConfig,
|
|
3899
|
+
isStreamingRequest: this.isStreamingRequest(params),
|
|
3900
|
+
}, { cacheResponseForSeconds: cacheSearchResultsForSeconds })];
|
|
3918
3901
|
});
|
|
3919
3902
|
});
|
|
3920
3903
|
};
|
|
3904
|
+
MultiSearch.prototype.isStreamingRequest = function (commonParams) {
|
|
3905
|
+
return commonParams.streamConfig !== undefined;
|
|
3906
|
+
};
|
|
3921
3907
|
return MultiSearch;
|
|
3922
3908
|
}());
|
|
3923
3909
|
exports["default"] = MultiSearch;
|
|
@@ -4165,54 +4151,54 @@ var RequestWithCache = /** @class */ (function () {
|
|
|
4165
4151
|
this.responseCache = new Map();
|
|
4166
4152
|
this.responsePromiseCache = new Map();
|
|
4167
4153
|
};
|
|
4168
|
-
|
|
4169
|
-
RequestWithCache.prototype.perform = function (requestContext, requestFunction, requestFunctionArguments, cacheOptions) {
|
|
4154
|
+
RequestWithCache.prototype.perform = function (requestContext, methodName, requestParams, cacheOptions) {
|
|
4170
4155
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
4171
|
-
var _a, cacheResponseForSeconds, _b, maxSize, isCacheDisabled,
|
|
4156
|
+
var _a, cacheResponseForSeconds, _b, maxSize, isCacheDisabled, path, queryParams, body, headers, streamConfig, abortSignal, responseType, isStreamingRequest, requestParamsJSON, cacheEntry, now, isEntryValid, cachePromiseEntry, isEntryValid, responsePromise, response, isCacheOverMaxSize, oldestEntry, isResponsePromiseCacheOverMaxSize, oldestEntry;
|
|
4172
4157
|
return tslib_1.__generator(this, function (_c) {
|
|
4173
4158
|
switch (_c.label) {
|
|
4174
4159
|
case 0:
|
|
4175
4160
|
_a = cacheOptions.cacheResponseForSeconds, cacheResponseForSeconds = _a === void 0 ? defaultCacheResponseForSeconds : _a, _b = cacheOptions.maxSize, maxSize = _b === void 0 ? defaultMaxSize : _b;
|
|
4176
4161
|
isCacheDisabled = cacheResponseForSeconds <= 0 || maxSize <= 0;
|
|
4162
|
+
path = requestParams.path, queryParams = requestParams.queryParams, body = requestParams.body, headers = requestParams.headers, streamConfig = requestParams.streamConfig, abortSignal = requestParams.abortSignal, responseType = requestParams.responseType, isStreamingRequest = requestParams.isStreamingRequest;
|
|
4177
4163
|
if (isCacheDisabled) {
|
|
4178
|
-
return [2 /*return*/,
|
|
4164
|
+
return [2 /*return*/, this.executeRequest(requestContext, methodName, path, queryParams, body, headers, { abortSignal: abortSignal, responseType: responseType, streamConfig: streamConfig, isStreamingRequest: isStreamingRequest })];
|
|
4179
4165
|
}
|
|
4180
|
-
|
|
4181
|
-
cacheEntry = this.responseCache.get(
|
|
4166
|
+
requestParamsJSON = JSON.stringify(requestParams);
|
|
4167
|
+
cacheEntry = this.responseCache.get(requestParamsJSON);
|
|
4182
4168
|
now = Date.now();
|
|
4183
4169
|
if (cacheEntry) {
|
|
4184
4170
|
isEntryValid = now - cacheEntry.requestTimestamp < cacheResponseForSeconds * 1000;
|
|
4185
4171
|
if (isEntryValid) {
|
|
4186
|
-
this.responseCache.delete(
|
|
4187
|
-
this.responseCache.set(
|
|
4188
|
-
return [2 /*return*/,
|
|
4172
|
+
this.responseCache.delete(requestParamsJSON);
|
|
4173
|
+
this.responseCache.set(requestParamsJSON, cacheEntry);
|
|
4174
|
+
return [2 /*return*/, cacheEntry.response];
|
|
4189
4175
|
}
|
|
4190
4176
|
else {
|
|
4191
|
-
this.responseCache.delete(
|
|
4177
|
+
this.responseCache.delete(requestParamsJSON);
|
|
4192
4178
|
}
|
|
4193
4179
|
}
|
|
4194
|
-
cachePromiseEntry = this.responsePromiseCache.get(
|
|
4180
|
+
cachePromiseEntry = this.responsePromiseCache.get(requestParamsJSON);
|
|
4195
4181
|
if (cachePromiseEntry) {
|
|
4196
4182
|
isEntryValid = now - cachePromiseEntry.requestTimestamp <
|
|
4197
4183
|
cacheResponseForSeconds * 1000;
|
|
4198
4184
|
if (isEntryValid) {
|
|
4199
|
-
this.responsePromiseCache.delete(
|
|
4200
|
-
this.responsePromiseCache.set(
|
|
4185
|
+
this.responsePromiseCache.delete(requestParamsJSON);
|
|
4186
|
+
this.responsePromiseCache.set(requestParamsJSON, cachePromiseEntry);
|
|
4201
4187
|
return [2 /*return*/, cachePromiseEntry.responsePromise];
|
|
4202
4188
|
}
|
|
4203
4189
|
else {
|
|
4204
|
-
this.responsePromiseCache.delete(
|
|
4190
|
+
this.responsePromiseCache.delete(requestParamsJSON);
|
|
4205
4191
|
}
|
|
4206
4192
|
}
|
|
4207
|
-
responsePromise =
|
|
4208
|
-
this.responsePromiseCache.set(
|
|
4193
|
+
responsePromise = this.executeRequest(requestContext, methodName, path, queryParams, body, headers, { abortSignal: abortSignal, responseType: responseType, streamConfig: streamConfig, isStreamingRequest: isStreamingRequest });
|
|
4194
|
+
this.responsePromiseCache.set(requestParamsJSON, {
|
|
4209
4195
|
requestTimestamp: now,
|
|
4210
4196
|
responsePromise: responsePromise,
|
|
4211
4197
|
});
|
|
4212
4198
|
return [4 /*yield*/, responsePromise];
|
|
4213
4199
|
case 1:
|
|
4214
4200
|
response = _c.sent();
|
|
4215
|
-
this.responseCache.set(
|
|
4201
|
+
this.responseCache.set(requestParamsJSON, {
|
|
4216
4202
|
requestTimestamp: now,
|
|
4217
4203
|
response: response,
|
|
4218
4204
|
});
|
|
@@ -4235,6 +4221,33 @@ var RequestWithCache = /** @class */ (function () {
|
|
|
4235
4221
|
});
|
|
4236
4222
|
});
|
|
4237
4223
|
};
|
|
4224
|
+
RequestWithCache.prototype.executeRequest = function (context, methodName, path, queryParams, body, headers, options) {
|
|
4225
|
+
if (queryParams === void 0) { queryParams = {}; }
|
|
4226
|
+
var method = context[methodName];
|
|
4227
|
+
switch (methodName) {
|
|
4228
|
+
case "get":
|
|
4229
|
+
return method.call(context, path, queryParams, {
|
|
4230
|
+
abortSignal: options === null || options === void 0 ? void 0 : options.abortSignal,
|
|
4231
|
+
responseType: options === null || options === void 0 ? void 0 : options.responseType,
|
|
4232
|
+
streamConfig: options === null || options === void 0 ? void 0 : options.streamConfig,
|
|
4233
|
+
isStreamingRequest: options === null || options === void 0 ? void 0 : options.isStreamingRequest,
|
|
4234
|
+
});
|
|
4235
|
+
case "delete":
|
|
4236
|
+
return method.call(context, path, queryParams);
|
|
4237
|
+
case "post":
|
|
4238
|
+
return method.call(context, path, body, queryParams, headers || {}, {
|
|
4239
|
+
abortSignal: options === null || options === void 0 ? void 0 : options.abortSignal,
|
|
4240
|
+
responseType: options === null || options === void 0 ? void 0 : options.responseType,
|
|
4241
|
+
streamConfig: options === null || options === void 0 ? void 0 : options.streamConfig,
|
|
4242
|
+
isStreamingRequest: options === null || options === void 0 ? void 0 : options.isStreamingRequest,
|
|
4243
|
+
});
|
|
4244
|
+
case "put":
|
|
4245
|
+
case "patch":
|
|
4246
|
+
return method.call(context, path, body, queryParams);
|
|
4247
|
+
default:
|
|
4248
|
+
throw new Error("Unsupported method: ".concat(String(methodName)));
|
|
4249
|
+
}
|
|
4250
|
+
};
|
|
4238
4251
|
return RequestWithCache;
|
|
4239
4252
|
}());
|
|
4240
4253
|
exports["default"] = RequestWithCache;
|
|
@@ -4354,22 +4367,29 @@ var SearchOnlyDocuments = /** @class */ (function () {
|
|
|
4354
4367
|
var _b = _a === void 0 ? {} : _a, _c = _b.cacheSearchResultsForSeconds, cacheSearchResultsForSeconds = _c === void 0 ? this.configuration
|
|
4355
4368
|
.cacheSearchResultsForSeconds : _c, _d = _b.abortSignal, abortSignal = _d === void 0 ? null : _d;
|
|
4356
4369
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
4357
|
-
var additionalQueryParams,
|
|
4358
|
-
return tslib_1.__generator(this, function (
|
|
4370
|
+
var additionalQueryParams, _e, streamConfig, rest, queryParams, isStreamingRequest;
|
|
4371
|
+
return tslib_1.__generator(this, function (_f) {
|
|
4359
4372
|
additionalQueryParams = {};
|
|
4360
4373
|
if (this.configuration.useServerSideSearchCache === true) {
|
|
4361
4374
|
additionalQueryParams["use_cache"] = true;
|
|
4362
4375
|
}
|
|
4363
|
-
|
|
4364
|
-
queryParams =
|
|
4365
|
-
|
|
4376
|
+
_e = (0, Utils_1.normalizeArrayableParams)(searchParameters), streamConfig = _e.streamConfig, rest = tslib_1.__rest(_e, ["streamConfig"]);
|
|
4377
|
+
queryParams = tslib_1.__assign(tslib_1.__assign({}, additionalQueryParams), rest);
|
|
4378
|
+
isStreamingRequest = queryParams.conversation_stream === true;
|
|
4379
|
+
return [2 /*return*/, this.requestWithCache.perform(this.apiCall, "get", {
|
|
4380
|
+
path: this.endpointPath("search"),
|
|
4381
|
+
queryParams: queryParams,
|
|
4382
|
+
streamConfig: streamConfig,
|
|
4383
|
+
abortSignal: abortSignal,
|
|
4384
|
+
isStreamingRequest: isStreamingRequest,
|
|
4385
|
+
}, {
|
|
4366
4386
|
cacheResponseForSeconds: cacheSearchResultsForSeconds,
|
|
4367
4387
|
})];
|
|
4368
4388
|
});
|
|
4369
4389
|
});
|
|
4370
4390
|
};
|
|
4371
4391
|
SearchOnlyDocuments.prototype.endpointPath = function (operation) {
|
|
4372
|
-
return "".concat(Collections_1.default.RESOURCEPATH, "/").concat(this.collectionName).concat(RESOURCEPATH).concat(operation === undefined ? "" : "/" + operation);
|
|
4392
|
+
return "".concat(Collections_1.default.RESOURCEPATH, "/").concat(encodeURIComponent(this.collectionName)).concat(RESOURCEPATH).concat(operation === undefined ? "" : "/" + operation);
|
|
4373
4393
|
};
|
|
4374
4394
|
Object.defineProperty(SearchOnlyDocuments, "RESOURCEPATH", {
|
|
4375
4395
|
get: function () {
|
|
@@ -4776,7 +4796,7 @@ exports.arrayableParams = {
|
|
|
4776
4796
|
"use strict";
|
|
4777
4797
|
|
|
4778
4798
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
4779
|
-
exports.normalizeArrayableParams = void 0;
|
|
4799
|
+
exports.toErrorWithMessage = exports.normalizeArrayableParams = void 0;
|
|
4780
4800
|
var tslib_1 = __webpack_require__(/*! tslib */ "./node_modules/typesense/node_modules/tslib/tslib.es6.mjs");
|
|
4781
4801
|
var Types_1 = __webpack_require__(/*! ./Types */ "./node_modules/typesense/lib/Typesense/Types.js");
|
|
4782
4802
|
function hasNoArrayValues(params) {
|
|
@@ -4804,6 +4824,26 @@ exports.normalizeArrayableParams = normalizeArrayableParams;
|
|
|
4804
4824
|
function isNonArrayValue(value) {
|
|
4805
4825
|
return !Array.isArray(value);
|
|
4806
4826
|
}
|
|
4827
|
+
function isErrorWithMessage(error) {
|
|
4828
|
+
return (typeof error === "object" &&
|
|
4829
|
+
error !== null &&
|
|
4830
|
+
"message" in error &&
|
|
4831
|
+
typeof error.message === "string");
|
|
4832
|
+
}
|
|
4833
|
+
function toErrorWithMessage(couldBeError) {
|
|
4834
|
+
if (isErrorWithMessage(couldBeError))
|
|
4835
|
+
return couldBeError;
|
|
4836
|
+
try {
|
|
4837
|
+
if (typeof couldBeError === "string") {
|
|
4838
|
+
return new Error(couldBeError);
|
|
4839
|
+
}
|
|
4840
|
+
return new Error(JSON.stringify(couldBeError));
|
|
4841
|
+
}
|
|
4842
|
+
catch (_a) {
|
|
4843
|
+
return new Error(String(couldBeError));
|
|
4844
|
+
}
|
|
4845
|
+
}
|
|
4846
|
+
exports.toErrorWithMessage = toErrorWithMessage;
|
|
4807
4847
|
//# sourceMappingURL=Utils.js.map
|
|
4808
4848
|
|
|
4809
4849
|
/***/ }),
|