UNPKG

@jungle-commerce/typesense-react

Version:

React hooks and components for building search interfaces with Typesense

1,431 lines 376 kB
import { jsx } from "react/jsx-runtime"; import React, { createContext, useMemo, useReducer, useEffect, useRef, useCallback, useState, useContext } from "react"; var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {}; function getAugmentedNamespace(n) { if (n.__esModule) return n; var f = n.default; if (typeof f == "function") { var a = function a2() { if (this instanceof a2) { return Reflect.construct(f, arguments, this.constructor); } return f.apply(this, arguments); }; a.prototype = f.prototype; } else a = {}; Object.defineProperty(a, "__esModule", { value: true }); Object.keys(n).forEach(function(k) { var d = Object.getOwnPropertyDescriptor(n, k); Object.defineProperty(a, k, d.get ? d : { enumerable: true, get: function() { return n[k]; } }); }); return a; } var Typesense = {}; var Client$1 = {}; var Configuration$1 = {}; var loglevel = { exports: {} }; (function(module) { (function(root, definition) { if (module.exports) { module.exports = definition(); } else { root.log = definition(); } })(commonjsGlobal, function() { var noop2 = function() { }; var undefinedType = "undefined"; var isIE = typeof window !== undefinedType && typeof window.navigator !== undefinedType && /Trident\/|MSIE /.test(window.navigator.userAgent); var logMethods = [ "trace", "debug", "info", "warn", "error" ]; var _loggersByName = {}; var defaultLogger = null; function bindMethod(obj, methodName) { var method = obj[methodName]; if (typeof method.bind === "function") { return method.bind(obj); } else { try { return Function.prototype.bind.call(method, obj); } catch (e) { return function() { return Function.prototype.apply.apply(method, [obj, arguments]); }; } } } function traceForIE() { if (console.log) { if (console.log.apply) { console.log.apply(console, arguments); } else { Function.prototype.apply.apply(console.log, [console, arguments]); } } if (console.trace) console.trace(); } function realMethod(methodName) { if (methodName === "debug") { methodName = "log"; } if (typeof console === undefinedType) { return false; } else if (methodName === "trace" && isIE) { return traceForIE; } else if (console[methodName] !== void 0) { return bindMethod(console, methodName); } else if (console.log !== void 0) { return bindMethod(console, "log"); } else { return noop2; } } function replaceLoggingMethods() { var level = this.getLevel(); for (var i = 0; i < logMethods.length; i++) { var methodName = logMethods[i]; this[methodName] = i < level ? noop2 : this.methodFactory(methodName, level, this.name); } this.log = this.debug; if (typeof console === undefinedType && level < this.levels.SILENT) { return "No console available for logging"; } } function enableLoggingWhenConsoleArrives(methodName) { return function() { if (typeof console !== undefinedType) { replaceLoggingMethods.call(this); this[methodName].apply(this, arguments); } }; } function defaultMethodFactory(methodName, _level, _loggerName) { return realMethod(methodName) || enableLoggingWhenConsoleArrives.apply(this, arguments); } function Logger(name, factory) { var self2 = this; var inheritedLevel; var defaultLevel; var userLevel; var storageKey = "loglevel"; if (typeof name === "string") { storageKey += ":" + name; } else if (typeof name === "symbol") { storageKey = void 0; } function persistLevelIfPossible(levelNum) { var levelName = (logMethods[levelNum] || "silent").toUpperCase(); if (typeof window === undefinedType || !storageKey) return; try { window.localStorage[storageKey] = levelName; return; } catch (ignore) { } try { window.document.cookie = encodeURIComponent(storageKey) + "=" + levelName + ";"; } catch (ignore) { } } function getPersistedLevel() { var storedLevel; if (typeof window === undefinedType || !storageKey) return; try { storedLevel = window.localStorage[storageKey]; } catch (ignore) { } if (typeof storedLevel === undefinedType) { try { var cookie = window.document.cookie; var cookieName = encodeURIComponent(storageKey); var location = cookie.indexOf(cookieName + "="); if (location !== -1) { storedLevel = /^([^;]+)/.exec( cookie.slice(location + cookieName.length + 1) )[1]; } } catch (ignore) { } } if (self2.levels[storedLevel] === void 0) { storedLevel = void 0; } return storedLevel; } function clearPersistedLevel() { if (typeof window === undefinedType || !storageKey) return; try { window.localStorage.removeItem(storageKey); } catch (ignore) { } try { window.document.cookie = encodeURIComponent(storageKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC"; } catch (ignore) { } } function normalizeLevel(input) { var level = input; if (typeof level === "string" && self2.levels[level.toUpperCase()] !== void 0) { level = self2.levels[level.toUpperCase()]; } if (typeof level === "number" && level >= 0 && level <= self2.levels.SILENT) { return level; } else { throw new TypeError("log.setLevel() called with invalid level: " + input); } } self2.name = name; self2.levels = { "TRACE": 0, "DEBUG": 1, "INFO": 2, "WARN": 3, "ERROR": 4, "SILENT": 5 }; self2.methodFactory = factory || defaultMethodFactory; self2.getLevel = function() { if (userLevel != null) { return userLevel; } else if (defaultLevel != null) { return defaultLevel; } else { return inheritedLevel; } }; self2.setLevel = function(level, persist) { userLevel = normalizeLevel(level); if (persist !== false) { persistLevelIfPossible(userLevel); } return replaceLoggingMethods.call(self2); }; self2.setDefaultLevel = function(level) { defaultLevel = normalizeLevel(level); if (!getPersistedLevel()) { self2.setLevel(level, false); } }; self2.resetLevel = function() { userLevel = null; clearPersistedLevel(); replaceLoggingMethods.call(self2); }; self2.enableAll = function(persist) { self2.setLevel(self2.levels.TRACE, persist); }; self2.disableAll = function(persist) { self2.setLevel(self2.levels.SILENT, persist); }; self2.rebuild = function() { if (defaultLogger !== self2) { inheritedLevel = normalizeLevel(defaultLogger.getLevel()); } replaceLoggingMethods.call(self2); if (defaultLogger === self2) { for (var childName in _loggersByName) { _loggersByName[childName].rebuild(); } } }; inheritedLevel = normalizeLevel( defaultLogger ? defaultLogger.getLevel() : "WARN" ); var initialLevel = getPersistedLevel(); if (initialLevel != null) { userLevel = normalizeLevel(initialLevel); } replaceLoggingMethods.call(self2); } defaultLogger = new Logger(); defaultLogger.getLogger = function getLogger(name) { if (typeof name !== "symbol" && typeof name !== "string" || name === "") { throw new TypeError("You must supply a name when creating a logger."); } var logger2 = _loggersByName[name]; if (!logger2) { logger2 = _loggersByName[name] = new Logger( name, defaultLogger.methodFactory ); } return logger2; }; var _log = typeof window !== undefinedType ? window.log : void 0; defaultLogger.noConflict = function() { if (typeof window !== undefinedType && window.log === defaultLogger) { window.log = _log; } return defaultLogger; }; defaultLogger.getLoggers = function getLoggers() { return _loggersByName; }; defaultLogger["default"] = defaultLogger; return defaultLogger; }); })(loglevel); var loglevelExports = loglevel.exports; var Errors$1 = {}; var HTTPError$1 = {}; var TypesenseError$1 = {}; var __extends$a = commonjsGlobal && commonjsGlobal.__extends || /* @__PURE__ */ function() { var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) { d2.__proto__ = b2; } || function(d2, b2) { for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p]; }; return extendStatics(d, b); }; return function(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); Object.defineProperty(TypesenseError$1, "__esModule", { value: true }); var TypesenseError = ( /** @class */ function(_super) { __extends$a(TypesenseError2, _super); function TypesenseError2(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; _this.name = _newTarget.name; Object.setPrototypeOf(_this, _newTarget.prototype); return _this; } return TypesenseError2; }(Error) ); TypesenseError$1.default = TypesenseError; var __extends$9 = commonjsGlobal && commonjsGlobal.__extends || /* @__PURE__ */ function() { var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) { d2.__proto__ = b2; } || function(d2, b2) { for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p]; }; return extendStatics(d, b); }; return function(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); var __importDefault$u = commonjsGlobal && commonjsGlobal.__importDefault || function(mod) { return mod && mod.__esModule ? mod : { "default": mod }; }; Object.defineProperty(HTTPError$1, "__esModule", { value: true }); var TypesenseError_1$a = __importDefault$u(TypesenseError$1); var HTTPError = ( /** @class */ function(_super) { __extends$9(HTTPError2, _super); function HTTPError2() { return _super !== null && _super.apply(this, arguments) || this; } return HTTPError2; }(TypesenseError_1$a.default) ); HTTPError$1.default = HTTPError; var MissingConfigurationError$1 = {}; var __extends$8 = commonjsGlobal && commonjsGlobal.__extends || /* @__PURE__ */ function() { var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) { d2.__proto__ = b2; } || function(d2, b2) { for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p]; }; return extendStatics(d, b); }; return function(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); var __importDefault$t = commonjsGlobal && commonjsGlobal.__importDefault || function(mod) { return mod && mod.__esModule ? mod : { "default": mod }; }; Object.defineProperty(MissingConfigurationError$1, "__esModule", { value: true }); var TypesenseError_1$9 = __importDefault$t(TypesenseError$1); var MissingConfigurationError = ( /** @class */ function(_super) { __extends$8(MissingConfigurationError2, _super); function MissingConfigurationError2() { return _super !== null && _super.apply(this, arguments) || this; } return MissingConfigurationError2; }(TypesenseError_1$9.default) ); MissingConfigurationError$1.default = MissingConfigurationError; var ObjectAlreadyExists$1 = {}; var __extends$7 = commonjsGlobal && commonjsGlobal.__extends || /* @__PURE__ */ function() { var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) { d2.__proto__ = b2; } || function(d2, b2) { for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p]; }; return extendStatics(d, b); }; return function(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); var __importDefault$s = commonjsGlobal && commonjsGlobal.__importDefault || function(mod) { return mod && mod.__esModule ? mod : { "default": mod }; }; Object.defineProperty(ObjectAlreadyExists$1, "__esModule", { value: true }); var TypesenseError_1$8 = __importDefault$s(TypesenseError$1); var ObjectAlreadyExists = ( /** @class */ function(_super) { __extends$7(ObjectAlreadyExists2, _super); function ObjectAlreadyExists2() { return _super !== null && _super.apply(this, arguments) || this; } return ObjectAlreadyExists2; }(TypesenseError_1$8.default) ); ObjectAlreadyExists$1.default = ObjectAlreadyExists; var ObjectNotFound$1 = {}; var __extends$6 = commonjsGlobal && commonjsGlobal.__extends || /* @__PURE__ */ function() { var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) { d2.__proto__ = b2; } || function(d2, b2) { for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p]; }; return extendStatics(d, b); }; return function(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); var __importDefault$r = commonjsGlobal && commonjsGlobal.__importDefault || function(mod) { return mod && mod.__esModule ? mod : { "default": mod }; }; Object.defineProperty(ObjectNotFound$1, "__esModule", { value: true }); var TypesenseError_1$7 = __importDefault$r(TypesenseError$1); var ObjectNotFound = ( /** @class */ function(_super) { __extends$6(ObjectNotFound2, _super); function ObjectNotFound2() { return _super !== null && _super.apply(this, arguments) || this; } return ObjectNotFound2; }(TypesenseError_1$7.default) ); ObjectNotFound$1.default = ObjectNotFound; var ObjectUnprocessable$1 = {}; var __extends$5 = commonjsGlobal && commonjsGlobal.__extends || /* @__PURE__ */ function() { var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) { d2.__proto__ = b2; } || function(d2, b2) { for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p]; }; return extendStatics(d, b); }; return function(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); var __importDefault$q = commonjsGlobal && commonjsGlobal.__importDefault || function(mod) { return mod && mod.__esModule ? mod : { "default": mod }; }; Object.defineProperty(ObjectUnprocessable$1, "__esModule", { value: true }); var TypesenseError_1$6 = __importDefault$q(TypesenseError$1); var ObjectUnprocessable = ( /** @class */ function(_super) { __extends$5(ObjectUnprocessable2, _super); function ObjectUnprocessable2() { return _super !== null && _super.apply(this, arguments) || this; } return ObjectUnprocessable2; }(TypesenseError_1$6.default) ); ObjectUnprocessable$1.default = ObjectUnprocessable; var RequestMalformed$1 = {}; var __extends$4 = commonjsGlobal && commonjsGlobal.__extends || /* @__PURE__ */ function() { var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) { d2.__proto__ = b2; } || function(d2, b2) { for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p]; }; return extendStatics(d, b); }; return function(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); var __importDefault$p = commonjsGlobal && commonjsGlobal.__importDefault || function(mod) { return mod && mod.__esModule ? mod : { "default": mod }; }; Object.defineProperty(RequestMalformed$1, "__esModule", { value: true }); var TypesenseError_1$5 = __importDefault$p(TypesenseError$1); var RequestMalformed = ( /** @class */ function(_super) { __extends$4(RequestMalformed2, _super); function RequestMalformed2() { return _super !== null && _super.apply(this, arguments) || this; } return RequestMalformed2; }(TypesenseError_1$5.default) ); RequestMalformed$1.default = RequestMalformed; var RequestUnauthorized$1 = {}; var __extends$3 = commonjsGlobal && commonjsGlobal.__extends || /* @__PURE__ */ function() { var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) { d2.__proto__ = b2; } || function(d2, b2) { for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p]; }; return extendStatics(d, b); }; return function(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); var __importDefault$o = commonjsGlobal && commonjsGlobal.__importDefault || function(mod) { return mod && mod.__esModule ? mod : { "default": mod }; }; Object.defineProperty(RequestUnauthorized$1, "__esModule", { value: true }); var TypesenseError_1$4 = __importDefault$o(TypesenseError$1); var RequestUnauthorized = ( /** @class */ function(_super) { __extends$3(RequestUnauthorized2, _super); function RequestUnauthorized2() { return _super !== null && _super.apply(this, arguments) || this; } return RequestUnauthorized2; }(TypesenseError_1$4.default) ); RequestUnauthorized$1.default = RequestUnauthorized; var ServerError$1 = {}; var __extends$2 = commonjsGlobal && commonjsGlobal.__extends || /* @__PURE__ */ function() { var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) { d2.__proto__ = b2; } || function(d2, b2) { for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p]; }; return extendStatics(d, b); }; return function(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); var __importDefault$n = commonjsGlobal && commonjsGlobal.__importDefault || function(mod) { return mod && mod.__esModule ? mod : { "default": mod }; }; Object.defineProperty(ServerError$1, "__esModule", { value: true }); var TypesenseError_1$3 = __importDefault$n(TypesenseError$1); var ServerError = ( /** @class */ function(_super) { __extends$2(ServerError2, _super); function ServerError2() { return _super !== null && _super.apply(this, arguments) || this; } return ServerError2; }(TypesenseError_1$3.default) ); ServerError$1.default = ServerError; var ImportError$1 = {}; var __extends$1 = commonjsGlobal && commonjsGlobal.__extends || /* @__PURE__ */ function() { var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) { d2.__proto__ = b2; } || function(d2, b2) { for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p]; }; return extendStatics(d, b); }; return function(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); var __importDefault$m = commonjsGlobal && commonjsGlobal.__importDefault || function(mod) { return mod && mod.__esModule ? mod : { "default": mod }; }; Object.defineProperty(ImportError$1, "__esModule", { value: true }); var TypesenseError_1$2 = __importDefault$m(TypesenseError$1); var ImportError = ( /** @class */ function(_super) { __extends$1(ImportError2, _super); function ImportError2(message, importResults) { var _this = _super.call(this, message) || this; _this.importResults = importResults; return _this; } return ImportError2; }(TypesenseError_1$2.default) ); ImportError$1.default = ImportError; var __importDefault$l = commonjsGlobal && commonjsGlobal.__importDefault || function(mod) { return mod && mod.__esModule ? mod : { "default": mod }; }; Object.defineProperty(Errors$1, "__esModule", { value: true }); Errors$1.ImportError = Errors$1.TypesenseError = Errors$1.ServerError = Errors$1.RequestUnauthorized = Errors$1.RequestMalformed = Errors$1.ObjectUnprocessable = Errors$1.ObjectNotFound = Errors$1.ObjectAlreadyExists = Errors$1.MissingConfigurationError = Errors$1.HTTPError = void 0; var HTTPError_1 = __importDefault$l(HTTPError$1); Errors$1.HTTPError = HTTPError_1.default; var MissingConfigurationError_1 = __importDefault$l(MissingConfigurationError$1); Errors$1.MissingConfigurationError = MissingConfigurationError_1.default; var ObjectAlreadyExists_1 = __importDefault$l(ObjectAlreadyExists$1); Errors$1.ObjectAlreadyExists = ObjectAlreadyExists_1.default; var ObjectNotFound_1 = __importDefault$l(ObjectNotFound$1); Errors$1.ObjectNotFound = ObjectNotFound_1.default; var ObjectUnprocessable_1 = __importDefault$l(ObjectUnprocessable$1); Errors$1.ObjectUnprocessable = ObjectUnprocessable_1.default; var RequestMalformed_1 = __importDefault$l(RequestMalformed$1); Errors$1.RequestMalformed = RequestMalformed_1.default; var RequestUnauthorized_1 = __importDefault$l(RequestUnauthorized$1); Errors$1.RequestUnauthorized = RequestUnauthorized_1.default; var ServerError_1 = __importDefault$l(ServerError$1); Errors$1.ServerError = ServerError_1.default; var ImportError_1 = __importDefault$l(ImportError$1); Errors$1.ImportError = ImportError_1.default; var TypesenseError_1$1 = __importDefault$l(TypesenseError$1); Errors$1.TypesenseError = TypesenseError_1$1.default; var __assign = commonjsGlobal && commonjsGlobal.__assign || function() { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __createBinding$1 = commonjsGlobal && commonjsGlobal.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); } : function(o, m, k, k2) { if (k2 === void 0) k2 = k; o[k2] = m[k]; }); var __setModuleDefault$1 = commonjsGlobal && commonjsGlobal.__setModuleDefault || (Object.create ? function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); } : function(o, v) { o["default"] = v; }); var __importStar$1 = commonjsGlobal && commonjsGlobal.__importStar || function(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) { for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding$1(result, mod, k); } __setModuleDefault$1(result, mod); return result; }; Object.defineProperty(Configuration$1, "__esModule", { value: true }); var logger = __importStar$1(loglevelExports); var Errors_1$3 = Errors$1; var Configuration = ( /** @class */ function() { function Configuration2(options) { var _this = this; this.nodes = options.nodes || []; this.nodes = this.nodes.map(function(node) { return _this.setDefaultPathInNode(node); }).map(function(node) { return _this.setDefaultPortInNode(node); }).map(function(node) { return __assign({}, node); }); if (options.randomizeNodes == null) { options.randomizeNodes = true; } if (options.randomizeNodes === true) { this.shuffleArray(this.nodes); } this.nearestNode = options.nearestNode; this.nearestNode = this.setDefaultPathInNode(this.nearestNode); this.nearestNode = this.setDefaultPortInNode(this.nearestNode); this.connectionTimeoutSeconds = options.connectionTimeoutSeconds || options.timeoutSeconds || 5; this.healthcheckIntervalSeconds = options.healthcheckIntervalSeconds || 60; this.numRetries = options.numRetries || this.nodes.length + (this.nearestNode == null ? 0 : 1) || 3; this.retryIntervalSeconds = options.retryIntervalSeconds || 0.1; this.apiKey = options.apiKey; this.sendApiKeyAsQueryParam = options.sendApiKeyAsQueryParam; this.cacheSearchResultsForSeconds = options.cacheSearchResultsForSeconds || 0; this.useServerSideSearchCache = options.useServerSideSearchCache || false; this.logger = options.logger || logger; this.logLevel = options.logLevel || "warn"; this.logger.setLevel(this.logLevel); this.additionalHeaders = options.additionalHeaders; this.httpAgent = options.httpAgent; this.httpsAgent = options.httpsAgent; this.showDeprecationWarnings(options); this.validate(); } Configuration2.prototype.validate = function() { if (this.nodes == null || this.nodes.length === 0 || this.validateNodes()) { throw new Errors_1$3.MissingConfigurationError("Ensure that nodes[].protocol, nodes[].host and nodes[].port are set"); } if (this.nearestNode != null && this.isNodeMissingAnyParameters(this.nearestNode)) { throw new Errors_1$3.MissingConfigurationError("Ensure that nearestNodes.protocol, nearestNodes.host and nearestNodes.port are set"); } if (this.apiKey == null) { throw new Errors_1$3.MissingConfigurationError("Ensure that apiKey is set"); } return true; }; Configuration2.prototype.validateNodes = function() { var _this = this; return this.nodes.some(function(node) { return _this.isNodeMissingAnyParameters(node); }); }; Configuration2.prototype.isNodeMissingAnyParameters = function(node) { return !["protocol", "host", "port", "path"].every(function(key) { return node.hasOwnProperty(key); }) && node["url"] == null; }; Configuration2.prototype.setDefaultPathInNode = function(node) { if (node != null && !node.hasOwnProperty("path")) { node["path"] = ""; } return node; }; Configuration2.prototype.setDefaultPortInNode = function(node) { if (node != null && !node.hasOwnProperty("port") && node.hasOwnProperty("protocol")) { switch (node["protocol"]) { case "https": node["port"] = 443; break; case "http": node["port"] = 80; break; } } return node; }; Configuration2.prototype.showDeprecationWarnings = function(options) { if (options.timeoutSeconds) { this.logger.warn("Deprecation warning: timeoutSeconds is now renamed to connectionTimeoutSeconds"); } if (options.masterNode) { this.logger.warn("Deprecation warning: masterNode is now consolidated to nodes, starting with Typesense Server v0.12"); } if (options.readReplicaNodes) { this.logger.warn("Deprecation warning: readReplicaNodes is now consolidated to nodes, starting with Typesense Server v0.12"); } }; Configuration2.prototype.shuffleArray = function(array) { var _a; for (var i = array.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); _a = [array[j], array[i]], array[i] = _a[0], array[j] = _a[1]; } }; return Configuration2; }() ); Configuration$1.default = Configuration; var ApiCall$1 = {}; /*! Axios v1.10.0 Copyright (c) 2025 Matt Zabriskie and contributors */ function bind(fn, thisArg) { return function wrap() { return fn.apply(thisArg, arguments); }; } const { toString } = Object.prototype; const { getPrototypeOf } = Object; const { iterator, toStringTag } = Symbol; const kindOf = /* @__PURE__ */ ((cache) => (thing) => { const str = toString.call(thing); return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase()); })(/* @__PURE__ */ Object.create(null)); const kindOfTest = (type) => { type = type.toLowerCase(); return (thing) => kindOf(thing) === type; }; const typeOfTest = (type) => (thing) => typeof thing === type; const { isArray } = Array; const isUndefined = typeOfTest("undefined"); function isBuffer(val) { return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor) && isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val); } const isArrayBuffer = kindOfTest("ArrayBuffer"); function isArrayBufferView(val) { let result; if (typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView) { result = ArrayBuffer.isView(val); } else { result = val && val.buffer && isArrayBuffer(val.buffer); } return result; } const isString = typeOfTest("string"); const isFunction = typeOfTest("function"); const isNumber = typeOfTest("number"); const isObject = (thing) => thing !== null && typeof thing === "object"; const isBoolean = (thing) => thing === true || thing === false; const isPlainObject = (val) => { if (kindOf(val) !== "object") { return false; } const prototype2 = getPrototypeOf(val); return (prototype2 === null || prototype2 === Object.prototype || Object.getPrototypeOf(prototype2) === null) && !(toStringTag in val) && !(iterator in val); }; const isDate = kindOfTest("Date"); const isFile = kindOfTest("File"); const isBlob = kindOfTest("Blob"); const isFileList = kindOfTest("FileList"); const isStream = (val) => isObject(val) && isFunction(val.pipe); const isFormData = (thing) => { let kind; return thing && (typeof FormData === "function" && thing instanceof FormData || isFunction(thing.append) && ((kind = kindOf(thing)) === "formdata" || // detect form-data instance kind === "object" && isFunction(thing.toString) && thing.toString() === "[object FormData]")); }; const isURLSearchParams = kindOfTest("URLSearchParams"); const [isReadableStream, isRequest, isResponse, isHeaders] = ["ReadableStream", "Request", "Response", "Headers"].map(kindOfTest); const trim = (str) => str.trim ? str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ""); function forEach(obj, fn, { allOwnKeys = false } = {}) { if (obj === null || typeof obj === "undefined") { return; } let i; let l; if (typeof obj !== "object") { obj = [obj]; } if (isArray(obj)) { for (i = 0, l = obj.length; i < l; i++) { fn.call(null, obj[i], i, obj); } } else { const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj); const len = keys.length; let key; for (i = 0; i < len; i++) { key = keys[i]; fn.call(null, obj[key], key, obj); } } } function findKey(obj, key) { key = key.toLowerCase(); const keys = Object.keys(obj); let i = keys.length; let _key; while (i-- > 0) { _key = keys[i]; if (key === _key.toLowerCase()) { return _key; } } return null; } const _global = (() => { if (typeof globalThis !== "undefined") return globalThis; return typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : commonjsGlobal; })(); const isContextDefined = (context) => !isUndefined(context) && context !== _global; function merge() { const { caseless } = isContextDefined(this) && this || {}; const result = {}; const assignValue = (val, key) => { const targetKey = caseless && findKey(result, key) || key; if (isPlainObject(result[targetKey]) && isPlainObject(val)) { result[targetKey] = merge(result[targetKey], val); } else if (isPlainObject(val)) { result[targetKey] = merge({}, val); } else if (isArray(val)) { result[targetKey] = val.slice(); } else { result[targetKey] = val; } }; for (let i = 0, l = arguments.length; i < l; i++) { arguments[i] && forEach(arguments[i], assignValue); } return result; } const extend = (a, b, thisArg, { allOwnKeys } = {}) => { forEach(b, (val, key) => { if (thisArg && isFunction(val)) { a[key] = bind(val, thisArg); } else { a[key] = val; } }, { allOwnKeys }); return a; }; const stripBOM = (content) => { if (content.charCodeAt(0) === 65279) { content = content.slice(1); } return content; }; const inherits = (constructor, superConstructor, props, descriptors2) => { constructor.prototype = Object.create(superConstructor.prototype, descriptors2); constructor.prototype.constructor = constructor; Object.defineProperty(constructor, "super", { value: superConstructor.prototype }); props && Object.assign(constructor.prototype, props); }; const toFlatObject = (sourceObj, destObj, filter2, propFilter) => { let props; let i; let prop; const merged = {}; destObj = destObj || {}; if (sourceObj == null) return destObj; do { props = Object.getOwnPropertyNames(sourceObj); i = props.length; while (i-- > 0) { prop = props[i]; if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) { destObj[prop] = sourceObj[prop]; merged[prop] = true; } } sourceObj = filter2 !== false && getPrototypeOf(sourceObj); } while (sourceObj && (!filter2 || filter2(sourceObj, destObj)) && sourceObj !== Object.prototype); return destObj; }; const endsWith = (str, searchString, position) => { str = String(str); if (position === void 0 || position > str.length) { position = str.length; } position -= searchString.length; const lastIndex = str.indexOf(searchString, position); return lastIndex !== -1 && lastIndex === position; }; const toArray = (thing) => { if (!thing) return null; if (isArray(thing)) return thing; let i = thing.length; if (!isNumber(i)) return null; const arr = new Array(i); while (i-- > 0) { arr[i] = thing[i]; } return arr; }; const isTypedArray = /* @__PURE__ */ ((TypedArray) => { return (thing) => { return TypedArray && thing instanceof TypedArray; }; })(typeof Uint8Array !== "undefined" && getPrototypeOf(Uint8Array)); const forEachEntry = (obj, fn) => { const generator = obj && obj[iterator]; const _iterator = generator.call(obj); let result; while ((result = _iterator.next()) && !result.done) { const pair = result.value; fn.call(obj, pair[0], pair[1]); } }; const matchAll = (regExp, str) => { let matches; const arr = []; while ((matches = regExp.exec(str)) !== null) { arr.push(matches); } return arr; }; const isHTMLForm = kindOfTest("HTMLFormElement"); const toCamelCase = (str) => { return str.toLowerCase().replace( /[-_\s]([a-z\d])(\w*)/g, function replacer(m, p1, p2) { return p1.toUpperCase() + p2; } ); }; const hasOwnProperty = (({ hasOwnProperty: hasOwnProperty2 }) => (obj, prop) => hasOwnProperty2.call(obj, prop))(Object.prototype); const isRegExp = kindOfTest("RegExp"); const reduceDescriptors = (obj, reducer) => { const descriptors2 = Object.getOwnPropertyDescriptors(obj); const reducedDescriptors = {}; forEach(descriptors2, (descriptor, name) => { let ret; if ((ret = reducer(descriptor, name, obj)) !== false) { reducedDescriptors[name] = ret || descriptor; } }); Object.defineProperties(obj, reducedDescriptors); }; const freezeMethods = (obj) => { reduceDescriptors(obj, (descriptor, name) => { if (isFunction(obj) && ["arguments", "caller", "callee"].indexOf(name) !== -1) { return false; } const value = obj[name]; if (!isFunction(value)) return; descriptor.enumerable = false; if ("writable" in descriptor) { descriptor.writable = false; return; } if (!descriptor.set) { descriptor.set = () => { throw Error("Can not rewrite read-only method '" + name + "'"); }; } }); }; const toObjectSet = (arrayOrString, delimiter) => { const obj = {}; const define = (arr) => { arr.forEach((value) => { obj[value] = true; }); }; isArray(arrayOrString) ? define(arrayOrString) : define(String(arrayOrString).split(delimiter)); return obj; }; const noop = () => { }; const toFiniteNumber = (value, defaultValue) => { return value != null && Number.isFinite(value = +value) ? value : defaultValue; }; function isSpecCompliantForm(thing) { return !!(thing && isFunction(thing.append) && thing[toStringTag] === "FormData" && thing[iterator]); } const toJSONObject = (obj) => { const stack = new Array(10); const visit = (source, i) => { if (isObject(source)) { if (stack.indexOf(source) >= 0) { return; } if (!("toJSON" in source)) { stack[i] = source; const target = isArray(source) ? [] : {}; forEach(source, (value, key) => { const reducedValue = visit(value, i + 1); !isUndefined(reducedValue) && (target[key] = reducedValue); }); stack[i] = void 0; return target; } } return source; }; return visit(obj, 0); }; const isAsyncFn = kindOfTest("AsyncFunction"); const isThenable = (thing) => thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch); const _setImmediate = ((setImmediateSupported, postMessageSupported) => { if (setImmediateSupported) { return setImmediate; } return postMessageSupported ? ((token, callbacks) => { _global.addEventListener("message", ({ source, data }) => { if (source === _global && data === token) { callbacks.length && callbacks.shift()(); } }, false); return (cb) => { callbacks.push(cb); _global.postMessage(token, "*"); }; })(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb); })( typeof setImmediate === "function", isFunction(_global.postMessage) ); const asap = typeof queueMicrotask !== "undefined" ? queueMicrotask.bind(_global) : typeof process !== "undefined" && process.nextTick || _setImmediate; const isIterable = (thing) => thing != null && isFunction(thing[iterator]); var utils$1 = { isArray, isArrayBuffer, isBuffer, isFormData, isArrayBufferView, isString, isNumber, isBoolean, isObject, isPlainObject, isReadableStream, isRequest, isResponse, isHeaders, isUndefined, isDate, isFile, isBlob, isRegExp, isFunction, isStream, isURLSearchParams, isTypedArray, isFileList, forEach, merge, extend, trim, stripBOM, inherits, toFlatObject, kindOf, kindOfTest, endsWith, toArray, forEachEntry, matchAll, isHTMLForm, hasOwnProperty, hasOwnProp: hasOwnProperty, // an alias to avoid ESLint no-prototype-builtins detection reduceDescriptors, freezeMethods, toObjectSet, toCamelCase, noop, toFiniteNumber, findKey, global: _global, isContextDefined, isSpecCompliantForm, toJSONObject, isAsyncFn, isThenable, setImmediate: _setImmediate, asap, isIterable }; function AxiosError(message, code, config, request, response) { Error.call(this); if (Error.captureStackTrace) { Error.captureStackTrace(this, this.constructor); } else { this.stack = new Error().stack; } this.message = message; this.name = "AxiosError"; code && (this.code = code); config && (this.config = config); request && (this.request = request); if (response) { this.response = response; this.status = response.status ? response.status : null; } } utils$1.inherits(AxiosError, Error, { toJSON: function toJSON() { return { // Standard message: this.message, name: this.name, // Microsoft description: this.description, number: this.number, // Mozilla fileName: this.fileName, lineNumber: this.lineNumber, columnNumber: this.columnNumber, stack: this.stack, // Axios config: utils$1.toJSONObject(this.config), code: this.code, status: this.status }; } }); const prototype$1 = AxiosError.prototype; const descriptors = {}; [ "ERR_BAD_OPTION_VALUE", "ERR_BAD_OPTION", "ECONNABORTED", "ETIMEDOUT", "ERR_NETWORK", "ERR_FR_TOO_MANY_REDIRECTS", "ERR_DEPRECATED", "ERR_BAD_RESPONSE", "ERR_BAD_REQUEST", "ERR_CANCELED", "ERR_NOT_SUPPORT", "ERR_INVALID_URL" // eslint-disable-next-line func-names ].forEach((code) => { descriptors[code] = { value: code }; }); Object.defineProperties(AxiosError, descriptors); Object.defineProperty(prototype$1, "isAxiosError", { value: true }); AxiosError.from = (error, code, config, request, response, customProps) => { const axiosError = Object.create(prototype$1); utils$1.toFlatObject(error, axiosError, function filter2(obj) { return obj !== Error.prototype; }, (prop) => { return prop !== "isAxiosError"; }); AxiosError.call(axiosError, error.message, code, config, request, response); axiosError.cause = error; axiosError.name = error.name; customProps && Object.assign(axiosError, customProps); return axiosError; }; var httpAdapter = null; function isVisitable(thing) { return utils$1.isPlainObject(thing) || utils$1.isArray(thing); } function removeBrackets(key) { return utils$1.endsWith(key, "[]") ? key.slice(0, -2) : key; } function renderKey(path, key, dots) { if (!path) return key; return path.concat(key).map(function each(token, i) { token = removeBrackets(token); return !dots && i ? "[" + token + "]" : token; }).join(dots ? "." : ""); } function isFlatArray(arr) { return utils$1.isArray(arr) && !arr.some(isVisitable); } const predicates = utils$1.toFlatObject(utils$1, {}, null, function filter(prop) { return /^is[A-Z]/.test(prop); }); function toFormData(obj, formData, options) { if (!utils$1.isObject(obj)) { throw new TypeError("target must be an object"); } formData = formData || new FormData(); options = utils$1.toFlatObject(options, { metaTokens: true, dots: false, indexes: false }, false, function defined(option, source) { return !utils$1.isUndefined(source[option]); }); const metaTokens = options.metaTokens; const visitor = options.visitor || defaultVisitor; const dots = options.dots; const indexes = options.indexes; const _Blob = options.Blob || typeof Blob !== "undefined" && Blob; const useBlob = _Blob && utils$1.isSpecCompliantForm(formData); if (!utils$1.isFunction(visitor)) { throw new TypeError("visitor must be a function"); } function convertValue(value) { if (value === null) return ""; if (utils$1.isDate(value)) { return value.toISOString(); } if (utils$1.isBoolean(value)) { return value.toString(); } if (!useBlob && utils$1.isBlob(value)) { throw new AxiosError("Blob is not supported. Use a Buffer instead."); } if (utils$1.isArrayBuffer(value) || utils$1.isTypedArray(value)) { return useBlob && typeof Blob === "function" ? new Blob([value]) : Buffer.from(value); } return value; } function defaultVisitor(value, key, path) { let arr = value; if (value && !path && typeof value === "object") { if (utils$1.endsWith(key, "{}")) { key = metaTokens ? key : key.slice(0, -2); value = JSON.stringify(value); } else if (utils$1.isArray(value) && isFlatArray(value) || (utils$1.isFileList(value) || utils$1.endsWith(key, "[]")) && (arr = utils$1.toArray(value))) { key = removeBrackets(key); arr.forEach(function each(el, index) { !(utils$1.isUndefined(el) || el === null) && formData.append( // eslint-disable-next-line no-nested-ternary indexes === true ? renderKey([key], index, dots) : indexes === null ? key : key + "[]", convertValue(el) ); }); return false; } } if (isVisitable(value)) { return true; } formData.append(renderKey(path, key, dots), convertValue(value)); return false; } const stack = []; const exposedHelpers = Object.assign(predicates, { defaultVisitor, convertValue, isVisitable }); function build(value, path) { if (utils$1.isUndefined(value)) return; if (stack.indexOf(value) !== -1) { throw Error("Circular reference detected in " + path.join(".")); } stack.push(value); utils$1.forEach(value, function each(el, key) { const result = !(utils$1.isUndefined(el) || el === null) && visitor.call( formData, el, utils$1.isString(key) ? key.trim() : key, path, exposedHelpers ); if (result === true) { build(el, path ? path.concat(key) : [key]); } }); stack.pop(); } if (!utils$1.isObject(obj)) { throw new TypeError("data must be an object"); } build(obj); return formData; } function encode$1(str) { const charMap = { "!": "%21", "'": "%27", "(": "%28", ")": "%29", "~": "%7E", "%20": "+", "%00": "\0" }; return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) { return charMap[match]; }); } function AxiosURLSearchParams(params, options) { this._pairs = []; params && toFormData(params, this, options); } const prototype = AxiosURLSearchParams.prototype; prototype.append = function append(name, value) { this._pairs.push([name, value]); }; prototype.toString = function toString2(encoder) { const _encode = encoder ? function(value) { return encoder.call(this, value, encode$1); } : encode$1; return this._pairs.map(function each(pair) { return _encode(pair[0]) + "=" + _encode(pair[1]); }, "").join("&"); }; function encode(val) { return encodeURIComponent(val).replace(/%3A/gi, ":").replace(/%24/g, "$").replace(/%2C/gi, ",").replace(/%20/g, "+").replace(/%5B/gi, "[").replace(/%5D/gi, "]"); } function buildURL(url, params, options) { if (!params) { return url; } const _encode = options && options.encode || encode; if (utils$1.isFunction(options)) { options = { serialize: options }; } const serializeFn = options && options.serialize; let serializedParams; if (serializeFn) { serializedParams = serializeFn(params, options); } else { serializedParams = utils$1.isURLSearchParams(params) ? params.toString() : new AxiosURLSearchParams(params, options).toString(_encode); } if (serializedParams) { const hashmarkIndex = url.indexOf("#"); if (hashmarkIndex !== -1) { url = url.slice(0, hashmarkIndex); } url += (url.indexOf("?") === -1 ? "?" : "&") + serializedParams; } return url; } class InterceptorManager { constructor() { this.handlers = []; } /** * Add a new interceptor to the stack * * @param {Function} fulfilled The function to handle `the