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