UNPKG

meilisearch

Version:

The Meilisearch JS client for Node.js and the browser.

1,137 lines (1,136 loc) 32.9 kB
//#region src/types/types.ts var e = { ALL: "all", LAST: "last", FREQUENCY: "frequency" }, t = { JSON: "application/json", CSV: "text/csv", NDJSON: "application/x-ndjson" }, n = { INDEX_CREATION_FAILED: "index_creation_failed", MISSING_INDEX_UID: "missing_index_uid", INDEX_ALREADY_EXISTS: "index_already_exists", INDEX_NOT_FOUND: "index_not_found", INVALID_INDEX_UID: "invalid_index_uid", INDEX_NOT_ACCESSIBLE: "index_not_accessible", INVALID_INDEX_OFFSET: "invalid_index_offset", INVALID_INDEX_LIMIT: "invalid_index_limit", INVALID_STATE: "invalid_state", PRIMARY_KEY_INFERENCE_FAILED: "primary_key_inference_failed", INDEX_PRIMARY_KEY_ALREADY_EXISTS: "index_primary_key_already_exists", INVALID_INDEX_PRIMARY_KEY: "invalid_index_primary_key", DOCUMENTS_FIELDS_LIMIT_REACHED: "document_fields_limit_reached", MISSING_DOCUMENT_ID: "missing_document_id", INVALID_DOCUMENT_ID: "invalid_document_id", INVALID_CONTENT_TYPE: "invalid_content_type", MISSING_CONTENT_TYPE: "missing_content_type", INVALID_DOCUMENT_FIELDS: "invalid_document_fields", INVALID_DOCUMENT_LIMIT: "invalid_document_limit", INVALID_DOCUMENT_OFFSET: "invalid_document_offset", INVALID_DOCUMENT_FILTER: "invalid_document_filter", MISSING_DOCUMENT_FILTER: "missing_document_filter", INVALID_DOCUMENT_VECTORS_FIELD: "invalid_document_vectors_field", PAYLOAD_TOO_LARGE: "payload_too_large", MISSING_PAYLOAD: "missing_payload", MALFORMED_PAYLOAD: "malformed_payload", NO_SPACE_LEFT_ON_DEVICE: "no_space_left_on_device", INVALID_STORE_FILE: "invalid_store_file", INVALID_RANKING_RULES: "missing_document_id", INVALID_REQUEST: "invalid_request", INVALID_DOCUMENT_GEO_FIELD: "invalid_document_geo_field", INVALID_SEARCH_Q: "invalid_search_q", INVALID_SEARCH_OFFSET: "invalid_search_offset", INVALID_SEARCH_LIMIT: "invalid_search_limit", INVALID_SEARCH_PAGE: "invalid_search_page", INVALID_SEARCH_HITS_PER_PAGE: "invalid_search_hits_per_page", INVALID_SEARCH_ATTRIBUTES_TO_RETRIEVE: "invalid_search_attributes_to_retrieve", INVALID_SEARCH_ATTRIBUTES_TO_CROP: "invalid_search_attributes_to_crop", INVALID_SEARCH_CROP_LENGTH: "invalid_search_crop_length", INVALID_SEARCH_ATTRIBUTES_TO_HIGHLIGHT: "invalid_search_attributes_to_highlight", INVALID_SEARCH_SHOW_MATCHES_POSITION: "invalid_search_show_matches_position", INVALID_SEARCH_FILTER: "invalid_search_filter", INVALID_SEARCH_SORT: "invalid_search_sort", INVALID_SEARCH_FACETS: "invalid_search_facets", INVALID_SEARCH_HIGHLIGHT_PRE_TAG: "invalid_search_highlight_pre_tag", INVALID_SEARCH_HIGHLIGHT_POST_TAG: "invalid_search_highlight_post_tag", INVALID_SEARCH_CROP_MARKER: "invalid_search_crop_marker", INVALID_SEARCH_MATCHING_STRATEGY: "invalid_search_matching_strategy", INVALID_SEARCH_VECTOR: "invalid_search_vector", INVALID_SEARCH_ATTRIBUTES_TO_SEARCH_ON: "invalid_search_attributes_to_search_on", BAD_REQUEST: "bad_request", DOCUMENT_NOT_FOUND: "document_not_found", INTERNAL: "internal", INVALID_API_KEY: "invalid_api_key", INVALID_API_KEY_DESCRIPTION: "invalid_api_key_description", INVALID_API_KEY_ACTIONS: "invalid_api_key_actions", INVALID_API_KEY_INDEXES: "invalid_api_key_indexes", INVALID_API_KEY_EXPIRES_AT: "invalid_api_key_expires_at", API_KEY_NOT_FOUND: "api_key_not_found", IMMUTABLE_API_KEY_UID: "immutable_api_key_uid", IMMUTABLE_API_KEY_ACTIONS: "immutable_api_key_actions", IMMUTABLE_API_KEY_INDEXES: "immutable_api_key_indexes", IMMUTABLE_API_KEY_EXPIRES_AT: "immutable_api_key_expires_at", IMMUTABLE_API_KEY_CREATED_AT: "immutable_api_key_created_at", IMMUTABLE_API_KEY_UPDATED_AT: "immutable_api_key_updated_at", MISSING_AUTHORIZATION_HEADER: "missing_authorization_header", UNRETRIEVABLE_DOCUMENT: "unretrievable_document", MAX_DATABASE_SIZE_LIMIT_REACHED: "database_size_limit_reached", TASK_NOT_FOUND: "task_not_found", DUMP_PROCESS_FAILED: "dump_process_failed", DUMP_NOT_FOUND: "dump_not_found", INVALID_SWAP_DUPLICATE_INDEX_FOUND: "invalid_swap_duplicate_index_found", INVALID_SWAP_INDEXES: "invalid_swap_indexes", MISSING_SWAP_INDEXES: "missing_swap_indexes", MISSING_MASTER_KEY: "missing_master_key", INVALID_TASK_TYPES: "invalid_task_types", INVALID_TASK_UIDS: "invalid_task_uids", INVALID_TASK_STATUSES: "invalid_task_statuses", INVALID_TASK_LIMIT: "invalid_task_limit", INVALID_TASK_FROM: "invalid_task_from", INVALID_TASK_CANCELED_BY: "invalid_task_canceled_by", MISSING_TASK_FILTERS: "missing_task_filters", TOO_MANY_OPEN_FILES: "too_many_open_files", IO_ERROR: "io_error", INVALID_TASK_INDEX_UIDS: "invalid_task_index_uids", IMMUTABLE_INDEX_UID: "immutable_index_uid", IMMUTABLE_INDEX_CREATED_AT: "immutable_index_created_at", IMMUTABLE_INDEX_UPDATED_AT: "immutable_index_updated_at", INVALID_SETTINGS_DISPLAYED_ATTRIBUTES: "invalid_settings_displayed_attributes", INVALID_SETTINGS_SEARCHABLE_ATTRIBUTES: "invalid_settings_searchable_attributes", INVALID_SETTINGS_FILTERABLE_ATTRIBUTES: "invalid_settings_filterable_attributes", INVALID_SETTINGS_SORTABLE_ATTRIBUTES: "invalid_settings_sortable_attributes", INVALID_SETTINGS_RANKING_RULES: "invalid_settings_ranking_rules", INVALID_SETTINGS_STOP_WORDS: "invalid_settings_stop_words", INVALID_SETTINGS_SYNONYMS: "invalid_settings_synonyms", INVALID_SETTINGS_DISTINCT_ATTRIBUTE: "invalid_settings_distinct_attribute", INVALID_SETTINGS_TYPO_TOLERANCE: "invalid_settings_typo_tolerance", INVALID_SETTINGS_FACETING: "invalid_settings_faceting", INVALID_SETTINGS_PAGINATION: "invalid_settings_pagination", INVALID_SETTINGS_SEARCH_CUTOFF_MS: "invalid_settings_search_cutoff_ms", INVALID_SETTINGS_LOCALIZED_ATTRIBUTES: "invalid_settings_localized_attributes", INVALID_TASK_BEFORE_ENQUEUED_AT: "invalid_task_before_enqueued_at", INVALID_TASK_AFTER_ENQUEUED_AT: "invalid_task_after_enqueued_at", INVALID_TASK_BEFORE_STARTED_AT: "invalid_task_before_started_at", INVALID_TASK_AFTER_STARTED_AT: "invalid_task_after_started_at", INVALID_TASK_BEFORE_FINISHED_AT: "invalid_task_before_finished_at", INVALID_TASK_AFTER_FINISHED_AT: "invalid_task_after_finished_at", MISSING_API_KEY_ACTIONS: "missing_api_key_actions", MISSING_API_KEY_INDEXES: "missing_api_key_indexes", MISSING_API_KEY_EXPIRES_AT: "missing_api_key_expires_at", INVALID_API_KEY_LIMIT: "invalid_api_key_limit", INVALID_API_KEY_OFFSET: "invalid_api_key_offset", INVALID_FACET_SEARCH_FACET_NAME: "invalid_facet_search_facet_name", MISSING_FACET_SEARCH_FACET_NAME: "missing_facet_search_facet_name", INVALID_FACET_SEARCH_FACET_QUERY: "invalid_facet_search_facet_query", INVALID_SEARCH_RANKING_SCORE_THRESHOLD: "invalid_search_ranking_score_threshold", INVALID_SIMILAR_RANKING_SCORE_THRESHOLD: "invalid_similar_ranking_score_threshold" }, r = class extends Error { name = "MeilisearchError"; }, i = class extends r { name = "MeilisearchApiError"; cause; response; constructor(e, t) { super(t?.message ?? `${e.status}: ${e.statusText}`), this.response = e, t !== void 0 && (this.cause = t); } }, a = class extends r { name = "MeilisearchRequestError"; constructor(e, t) { super(`Request to ${e} has failed`, { cause: t }); } }, o = class extends r { name = "MeilisearchRequestTimeOutError"; cause; constructor(e, t) { super(`request timed out after ${e}ms`), this.cause = { timeout: e, requestInit: t }; } }, s = class extends r { name = "MeilisearchTaskTimeOutError"; cause; constructor(e, t) { super(`timeout of ${t}ms has exceeded on task ${e} when waiting for it to be resolved.`), this.cause = { taskUid: e, timeout: t }; } }, c = { name: "meilisearch", version: "0.57.0", description: "The Meilisearch JS client for Node.js and the browser.", keywords: [ "meilisearch", "search", "instant", "relevant", "client", "wrapper", "meili" ], author: "cvermand <charlotte@meilisearch.com>", contributors: ["qdequele <quentin@meilisearch.com>"], license: "MIT", type: "module", exports: { ".": "./src/index.ts", "./*": "./src/*.ts" }, publishConfig: { exports: { ".": "./dist/index.js", "./token": "./dist/token.js", "./package.json": "./package.json" } }, sideEffects: !1, files: [ "src", "dist", "CONTRIBUTING.md" ], engines: { node: "^20.19.0 || >=22.12.0" }, repository: { type: "git", url: "https://github.com/meilisearch/meilisearch-js.git" }, scripts: { "playground:javascript": "vite serve playgrounds/javascript --open", "build:docs": "typedoc", build: "vite build && tsc -p tsconfig.build.json", test: "vitest run", "test:watch": "vitest watch", types: "tsc -p tsconfig.json --noEmit", "types:watch": "pnpm types --watch", fmt: "prettier -c .", "fmt:fix": "prettier -w .", lint: "oxlint --type-aware", "lint:fix": "oxlint --type-aware --fix", style: "pnpm fmt && pnpm lint", "style:fix": "pnpm fmt:fix && pnpm lint:fix", prepare: "husky" }, devDependencies: { "@types/node": "24.10.13", "@vitest/coverage-v8": "4.1.0", "eslint-plugin-tsdoc": "0.5.0", globals: "^16.5.0", husky: "^9.1.7", "lint-staged": "16.2.7", oxlint: "1.50.0", "oxlint-tsgolint": "0.14.2", prettier: "^3.8.1", "prettier-plugin-jsdoc": "^1.8.0", typedoc: "^0.28.14", typescript: "5.9.3", vite: "8.0.0", vitest: "4.1.0" }, packageManager: "pnpm@10.32.1" }; //#endregion //#region src/utils.ts function l(e) { return e.startsWith("https://") || e.startsWith("http://") ? e : `http://${e}`; } function u(e) { return e.endsWith("/") || (e += "/"), e; } //#endregion //#region src/http-requests.ts function d(e, t) { for (let [n, r] of Object.entries(t)) r != null && e.set(n, Array.isArray(r) ? r.join() : r instanceof Date ? r.toISOString() : String(r)); } function f(e, t) { let n = "X-Meilisearch-Client", r = `Meilisearch JavaScript (v${c.version})`, i = "Content-Type", a = "Authorization", o = new Headers(t); if (e.apiKey && !o.has(a) && o.set(a, `Bearer ${e.apiKey}`), o.has(i) || o.set(i, "application/json"), e.clientAgents !== void 0) { let t = e.clientAgents.concat(r); o.set(n, t.join(" ; ")); } else o.set(n, r); return o; } var p = Symbol("<timeout>"); function m(e, t) { let { signal: n } = e, r = new AbortController(); if (n != null) { let e = null; if (n.aborted) r.abort(n.reason); else { let t = () => r.abort(n.reason); n.addEventListener("abort", t, { once: !0 }), e = () => n.removeEventListener("abort", t), r.signal.addEventListener("abort", e, { once: !0 }); } return () => { if (n.aborted) return; let i = setTimeout(() => r.abort(p), t), a = () => { clearTimeout(i), e !== null && r.signal.removeEventListener("abort", e); }; return n.addEventListener("abort", a, { once: !0 }), () => { n.removeEventListener("abort", a), a(); }; }; } return e.signal = r.signal, () => { let e = setTimeout(() => r.abort(p), t); return () => clearTimeout(e); }; } var h = class { #e; #t; #n; #r; constructor(e) { let t = u(l(e.host)); try { this.#e = new URL(t); } catch (e) { throw new r("The provided host is not valid", { cause: e }); } this.#t = { ...e.requestInit, headers: f(e, e.requestInit?.headers) }, this.#n = e.httpClient, this.#r = e.timeout; } #i(e, t) { if (e === void 0 && t === void 0) return this.#t.headers; let n = new Headers(e); t !== void 0 && !n.has("Content-Type") && n.set("Content-Type", t); for (let [e, t] of this.#t.headers) n.has(e) || n.set(e, t); return n; } #a({ path: e, method: t, params: n, contentType: r, body: i, extraRequestInit: a }) { let o = new URL(e, this.#e); return n !== void 0 && d(o.searchParams, n), { url: o, init: { method: t, body: r === void 0 || typeof i != "string" ? JSON.stringify(i) : i, ...a, ...this.#t, headers: this.#i(a?.headers, r) } }; } async #o(e) { let { url: t, init: n } = this.#a(e), r = (this.#r === void 0 ? null : m(n, this.#r))?.(), s, c; try { if (this.#n !== void 0) return await this.#n(t, n); s = await fetch(t, n), c = await s.text(); } catch (e) { throw new a(t.toString(), Object.is(e, p) ? new o(this.#r, n) : e); } finally { r?.(); } let l = c === "" ? void 0 : JSON.parse(c); if (!s.ok) throw new i(s, l); return l; } get(e) { return this.#o(e); } post(e) { return this.#o({ ...e, method: "POST" }); } put(e) { return this.#o({ ...e, method: "PUT" }); } patch(e) { return this.#o({ ...e, method: "PATCH" }); } delete(e) { return this.#o({ ...e, method: "DELETE" }); } postStream(e) { return this.#s({ ...e, method: "POST" }); } async #s(e) { let { url: t, init: n } = this.#a(e), s = (this.#r === void 0 ? null : m(n, this.#r))?.(), c; try { if (this.#n !== void 0) { let e = await this.#n(t, n); if (!(e instanceof ReadableStream)) throw new r("Custom HTTP client must return a ReadableStream for streaming requests"); return e; } c = await fetch(t, n); } catch (e) { throw new a(t.toString(), Object.is(e, p) ? new o(this.#r, n) : e); } finally { s?.(); } if (!c.ok) { let e = await c.text(), t = e === "" ? void 0 : JSON.parse(e); throw new i(c, t); } if (!c.body) throw new r("Response body is null - server did not return a readable stream"); return c.body; } }, g = Symbol("<task timeout>"); function _(e) { return function(t) { return Object.defineProperty(t, "waitTask", { async value(n) { return await e.waitForTask(await t, n); } }); }; } var v = (e) => typeof e == "number" ? e : e.taskUid, y = class { #e; #t; #n; #r; constructor(e, t) { this.#e = e, this.#t = t?.timeout ?? 5e3, this.#n = t?.interval ?? 50, this.#r = _(this); } async getTask(e, t) { return await this.#e.get({ path: `tasks/${e}`, extraRequestInit: t }); } async getTasks(e) { return await this.#e.get({ path: "tasks", params: e }); } async waitForTask(e, t) { let n = v(e), r = t?.timeout ?? this.#t, i = t?.interval ?? this.#n, a = r > 0 ? new AbortController() : null, o = a === null ? void 0 : setTimeout(() => void a.abort(g), r); try { for (;;) { let e = await this.getTask(n, { signal: a?.signal }); if (e.status !== "enqueued" && e.status !== "processing") return clearTimeout(o), e; i > 0 && await new Promise((e) => setTimeout(e, i)); } } catch (e) { throw Object.is(e.cause, g) ? new s(n, r) : e; } } async *waitForTasksIter(e, t) { for await (let n of e) yield await this.waitForTask(n, t); } async waitForTasks(...e) { let t = []; for await (let n of this.waitForTasksIter(...e)) t.push(n); return t; } cancelTasks(e) { return this.#r(this.#e.post({ path: "tasks/cancel", params: e })); } deleteTasks(e) { return this.#r(this.#e.delete({ path: "tasks", params: e })); } }; function b(e, t) { let n = _(t); return { post: (...t) => n(e.post(...t)), put: (...t) => n(e.put(...t)), patch: (...t) => n(e.patch(...t)), delete: (...t) => n(e.delete(...t)) }; } //#endregion //#region src/indexes.ts var x = class { uid; primaryKey; createdAt; updatedAt; httpRequest; tasks; #e; constructor(e, t, n) { this.uid = t, this.primaryKey = n, this.httpRequest = new h(e), this.tasks = new y(this.httpRequest, e.defaultWaitOptions), this.#e = b(this.httpRequest, this.tasks); } async search(e, t, n) { return await this.httpRequest.post({ path: `indexes/${this.uid}/search`, body: { q: e, ...t }, extraRequestInit: n }); } async searchGet(e, t, n) { let i = (e) => { if (typeof e == "string") return e; if (Array.isArray(e)) throw new r("The filter query parameter should be in string format when using searchGet"); }, a = { q: e, ...t, filter: i(t?.filter), sort: t?.sort?.join(","), facets: t?.facets?.join(","), attributesToRetrieve: t?.attributesToRetrieve?.join(","), attributesToCrop: t?.attributesToCrop?.join(","), attributesToHighlight: t?.attributesToHighlight?.join(","), vector: t?.vector?.join(","), attributesToSearchOn: t?.attributesToSearchOn?.join(",") }; return await this.httpRequest.get({ path: `indexes/${this.uid}/search`, params: a, extraRequestInit: n }); } async searchForFacetValues(e, t) { return await this.httpRequest.post({ path: `indexes/${this.uid}/facet-search`, body: e, extraRequestInit: t }); } async searchSimilarDocuments(e) { return await this.httpRequest.post({ path: `indexes/${this.uid}/similar`, body: e }); } async getRawInfo() { let e = await this.httpRequest.get({ path: `indexes/${this.uid}` }); return this.primaryKey = e.primaryKey, this.updatedAt = new Date(e.updatedAt), this.createdAt = new Date(e.createdAt), e; } async fetchInfo() { return await this.getRawInfo(), this; } async fetchPrimaryKey() { return this.primaryKey = (await this.getRawInfo()).primaryKey, this.primaryKey; } static create(e, t = {}, n) { let r = new h(n); return b(r, new y(r)).post({ path: "indexes", body: { ...t, uid: e } }); } update(e) { return this.#e.patch({ path: `indexes/${this.uid}`, body: e }); } delete() { return this.#e.delete({ path: `indexes/${this.uid}` }); } async getStats() { return await this.httpRequest.get({ path: `indexes/${this.uid}/stats` }); } async getDocuments(e) { let t = `indexes/${this.uid}/documents`, n = e ? { ...e } : void 0; return n && Array.isArray(n.sort) && n.sort.length === 0 && delete n.sort, n?.filter === void 0 ? await this.httpRequest.get({ path: t, params: n }) : await this.httpRequest.post({ path: `${t}/fetch`, body: n }); } async getDocument(e, t) { let n = Array.isArray(t?.fields) ? t.fields.join() : void 0; return await this.httpRequest.get({ path: `indexes/${this.uid}/documents/${e}`, params: { ...t, fields: n } }); } addDocuments(e, t) { return this.#e.post({ path: `indexes/${this.uid}/documents`, params: t, body: e }); } addDocumentsFromString(e, t, n) { return this.#e.post({ path: `indexes/${this.uid}/documents`, body: e, params: n, contentType: t }); } addDocumentsInBatches(e, t = 1e3, n) { let r = []; for (let i = 0; i < e.length; i += t) r.push(this.addDocuments(e.slice(i, i + t), n)); return r; } updateDocuments(e, t) { return this.#e.put({ path: `indexes/${this.uid}/documents`, params: t, body: e }); } updateDocumentsInBatches(e, t = 1e3, n) { let r = []; for (let i = 0; i < e.length; i += t) r.push(this.updateDocuments(e.slice(i, i + t), n)); return r; } updateDocumentsFromString(e, t, n) { return this.#e.put({ path: `indexes/${this.uid}/documents`, body: e, params: n, contentType: t }); } deleteDocument(e, t) { return this.#e.delete({ path: `indexes/${this.uid}/documents/${e}`, params: t }); } deleteDocuments(e, t) { let n = !Array.isArray(e) && typeof e == "object" ? "documents/delete" : "documents/delete-batch"; return this.#e.post({ path: `indexes/${this.uid}/${n}`, body: e, params: t }); } deleteAllDocuments(e) { return this.#e.delete({ path: `indexes/${this.uid}/documents`, params: e }); } updateDocumentsByFunction(e, t) { return this.#e.post({ path: `indexes/${this.uid}/documents/edit`, body: e, params: t }); } async getSettings() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings` }); } updateSettings(e) { return this.#e.patch({ path: `indexes/${this.uid}/settings`, body: e }); } resetSettings() { return this.#e.delete({ path: `indexes/${this.uid}/settings` }); } async getPagination() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/pagination` }); } updatePagination(e) { return this.#e.patch({ path: `indexes/${this.uid}/settings/pagination`, body: e }); } resetPagination() { return this.#e.delete({ path: `indexes/${this.uid}/settings/pagination` }); } async getSynonyms() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/synonyms` }); } updateSynonyms(e) { return this.#e.put({ path: `indexes/${this.uid}/settings/synonyms`, body: e }); } resetSynonyms() { return this.#e.delete({ path: `indexes/${this.uid}/settings/synonyms` }); } async getStopWords() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/stop-words` }); } updateStopWords(e) { return this.#e.put({ path: `indexes/${this.uid}/settings/stop-words`, body: e }); } resetStopWords() { return this.#e.delete({ path: `indexes/${this.uid}/settings/stop-words` }); } async getRankingRules() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/ranking-rules` }); } updateRankingRules(e) { return this.#e.put({ path: `indexes/${this.uid}/settings/ranking-rules`, body: e }); } resetRankingRules() { return this.#e.delete({ path: `indexes/${this.uid}/settings/ranking-rules` }); } async getDistinctAttribute() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/distinct-attribute` }); } updateDistinctAttribute(e) { return this.#e.put({ path: `indexes/${this.uid}/settings/distinct-attribute`, body: e }); } resetDistinctAttribute() { return this.#e.delete({ path: `indexes/${this.uid}/settings/distinct-attribute` }); } async getFilterableAttributes() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/filterable-attributes` }); } updateFilterableAttributes(e) { return this.#e.put({ path: `indexes/${this.uid}/settings/filterable-attributes`, body: e }); } resetFilterableAttributes() { return this.#e.delete({ path: `indexes/${this.uid}/settings/filterable-attributes` }); } async getSortableAttributes() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/sortable-attributes` }); } updateSortableAttributes(e) { return this.#e.put({ path: `indexes/${this.uid}/settings/sortable-attributes`, body: e }); } resetSortableAttributes() { return this.#e.delete({ path: `indexes/${this.uid}/settings/sortable-attributes` }); } async getSearchableAttributes() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/searchable-attributes` }); } updateSearchableAttributes(e) { return this.#e.put({ path: `indexes/${this.uid}/settings/searchable-attributes`, body: e }); } resetSearchableAttributes() { return this.#e.delete({ path: `indexes/${this.uid}/settings/searchable-attributes` }); } async getDisplayedAttributes() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/displayed-attributes` }); } updateDisplayedAttributes(e) { return this.#e.put({ path: `indexes/${this.uid}/settings/displayed-attributes`, body: e }); } resetDisplayedAttributes() { return this.#e.delete({ path: `indexes/${this.uid}/settings/displayed-attributes` }); } async getTypoTolerance() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/typo-tolerance` }); } updateTypoTolerance(e) { return this.#e.patch({ path: `indexes/${this.uid}/settings/typo-tolerance`, body: e }); } resetTypoTolerance() { return this.#e.delete({ path: `indexes/${this.uid}/settings/typo-tolerance` }); } async getFaceting() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/faceting` }); } updateFaceting(e) { return this.#e.patch({ path: `indexes/${this.uid}/settings/faceting`, body: e }); } resetFaceting() { return this.#e.delete({ path: `indexes/${this.uid}/settings/faceting` }); } async getSeparatorTokens() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/separator-tokens` }); } updateSeparatorTokens(e) { return this.#e.put({ path: `indexes/${this.uid}/settings/separator-tokens`, body: e }); } resetSeparatorTokens() { return this.#e.delete({ path: `indexes/${this.uid}/settings/separator-tokens` }); } async getNonSeparatorTokens() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/non-separator-tokens` }); } updateNonSeparatorTokens(e) { return this.#e.put({ path: `indexes/${this.uid}/settings/non-separator-tokens`, body: e }); } resetNonSeparatorTokens() { return this.#e.delete({ path: `indexes/${this.uid}/settings/non-separator-tokens` }); } async getDictionary() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/dictionary` }); } updateDictionary(e) { return this.#e.put({ path: `indexes/${this.uid}/settings/dictionary`, body: e }); } resetDictionary() { return this.#e.delete({ path: `indexes/${this.uid}/settings/dictionary` }); } async getProximityPrecision() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/proximity-precision` }); } updateProximityPrecision(e) { return this.#e.put({ path: `indexes/${this.uid}/settings/proximity-precision`, body: e }); } resetProximityPrecision() { return this.#e.delete({ path: `indexes/${this.uid}/settings/proximity-precision` }); } async getEmbedders() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/embedders` }); } updateEmbedders(e) { return this.#e.patch({ path: `indexes/${this.uid}/settings/embedders`, body: e }); } resetEmbedders() { return this.#e.delete({ path: `indexes/${this.uid}/settings/embedders` }); } async getSearchCutoffMs() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/search-cutoff-ms` }); } updateSearchCutoffMs(e) { return this.#e.put({ path: `indexes/${this.uid}/settings/search-cutoff-ms`, body: e }); } resetSearchCutoffMs() { return this.#e.delete({ path: `indexes/${this.uid}/settings/search-cutoff-ms` }); } async getLocalizedAttributes() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/localized-attributes` }); } updateLocalizedAttributes(e) { return this.#e.put({ path: `indexes/${this.uid}/settings/localized-attributes`, body: e }); } resetLocalizedAttributes() { return this.#e.delete({ path: `indexes/${this.uid}/settings/localized-attributes` }); } async getFacetSearch() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/facet-search` }); } updateFacetSearch(e) { return this.#e.put({ path: `indexes/${this.uid}/settings/facet-search`, body: e }); } resetFacetSearch() { return this.#e.delete({ path: `indexes/${this.uid}/settings/facet-search` }); } async getPrefixSearch() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/prefix-search` }); } updatePrefixSearch(e) { return this.#e.put({ path: `indexes/${this.uid}/settings/prefix-search`, body: e }); } resetPrefixSearch() { return this.#e.delete({ path: `indexes/${this.uid}/settings/prefix-search` }); } async getChat() { return await this.httpRequest.get({ path: `indexes/${this.uid}/settings/chat` }); } updateChat(e) { return this.#e.patch({ path: `indexes/${this.uid}/settings/chat`, body: e }); } async getFields(e, t) { return await this.httpRequest.post({ path: `indexes/${this.uid}/fields`, body: e || {}, extraRequestInit: t }); } }, S = class { #e; constructor(e) { this.#e = e; } async getBatch(e) { return await this.#e.get({ path: `batches/${e}` }); } async getBatches(e) { return await this.#e.get({ path: "batches", params: e }); } }, C = class { #e; #t; constructor(e, t) { this.#e = e, this.#t = t; } async get() { return await this.#e.get({ path: `chats/${this.#t}/settings` }); } async update(e) { return await this.#e.patch({ path: `chats/${this.#t}/settings`, body: e }); } async reset() { await this.#e.delete({ path: `chats/${this.#t}/settings` }); } async streamCompletion(e) { if (!e.stream) throw Error("The SDK only supports streaming"); return await this.#e.postStream({ path: `chats/${this.#t}/chat/completions`, body: e }); } }, w = class { config; httpRequest; #e; get tasks() { return this.#e; } #t; get batches() { return this.#t; } #n; constructor(e) { this.config = e, this.httpRequest = new h(e), this.#e = new y(this.httpRequest, e.defaultWaitOptions), this.#t = new S(this.httpRequest), this.#n = b(this.httpRequest, this.tasks); } index(e) { return new x(this.config, e); } async getIndex(e) { return new x(this.config, e).fetchInfo(); } async getRawIndex(e) { return new x(this.config, e).getRawInfo(); } async getIndexes(e) { let t = await this.getRawIndexes(e), n = t.results.map((e) => new x(this.config, e.uid, e.primaryKey)); return { ...t, results: n }; } async getRawIndexes(e) { return await this.httpRequest.get({ path: "indexes", params: e }); } createIndex(e, t) { return x.create(e, t, this.config); } updateIndex(e, t) { return new x(this.config, e).update(t); } deleteIndex(e) { return new x(this.config, e).delete(); } async deleteIndexIfExists(e) { try { return await this.deleteIndex(e), !0; } catch (e) { if (e?.cause?.code === n.INDEX_NOT_FOUND) return !1; throw e; } } swapIndexes(e) { return this.#n.post({ path: "swap-indexes", body: e }); } async multiSearch(e, t) { return await this.httpRequest.post({ path: "multi-search", body: e, extraRequestInit: t }); } chat(e) { return new C(this.httpRequest, e); } async getChatWorkspaces() { return await this.httpRequest.get({ path: "chats" }); } async getWebhooks() { return await this.httpRequest.get({ path: "webhooks" }); } async getWebhook(e) { return await this.httpRequest.get({ path: `webhooks/${e}` }); } async createWebhook(e) { return await this.httpRequest.post({ path: "webhooks", body: e }); } async updateWebhook(e, t) { return await this.httpRequest.patch({ path: `webhooks/${e}`, body: t }); } async deleteWebhook(e) { await this.httpRequest.delete({ path: `webhooks/${e}` }); } #r(e) { return this.#n.patch({ path: "network", body: e }); } #i(e, t) { let n = Object.entries(t); if (n.length === 0) throw TypeError("initializeNetwork requires at least one shard when leader is set."); let r = {}; for (let [t, i] of n) { if (!Array.isArray(i.remotes) || i.remotes.length === 0) throw TypeError(`Shard "${t}" must have at least one remote.`); let n = i.remotes.filter((t) => e[t] === void 0); if (n.length > 0) throw TypeError(`Shard "${t}" references unknown remotes: ${n.join(", ")}`); r[t] = { remotes: [...i.remotes] }; } return r; } async getNetwork() { return await this.httpRequest.get({ path: "network" }); } initializeNetwork(e) { let t = this.#i(e.remotes, e.shards); return this.#r({ self: e.self, leader: e.self, remotes: e.remotes, shards: t }); } addRemote(e) { return this.#r({ remotes: { [e.name]: e.remote } }); } removeRemote(e) { return this.#r({ remotes: { [e.name]: null } }); } addRemotesToShard(e, t) { return this.#r({ shards: { [e]: { addRemotes: t } } }); } removeRemotesFromShard(e, t) { return this.#r({ shards: { [e]: { removeRemotes: t } } }); } async getKeys(e) { let t = await this.httpRequest.get({ path: "keys", params: e }); return t.results = t.results.map((e) => ({ ...e, createdAt: new Date(e.createdAt), updatedAt: new Date(e.updatedAt) })), t; } async getKey(e) { return await this.httpRequest.get({ path: `keys/${e}` }); } async createKey(e) { return await this.httpRequest.post({ path: "keys", body: e }); } async updateKey(e, t) { return await this.httpRequest.patch({ path: `keys/${e}`, body: t }); } async deleteKey(e) { await this.httpRequest.delete({ path: `keys/${e}` }); } async health() { return await this.httpRequest.get({ path: "health" }); } async isHealthy() { try { let { status: e } = await this.health(); return e === "available"; } catch { return !1; } } async getStats() { return await this.httpRequest.get({ path: "stats" }); } async getVersion() { return await this.httpRequest.get({ path: "version" }); } createDump() { return this.#n.post({ path: "dumps" }); } createSnapshot() { return this.#n.post({ path: "snapshots" }); } async getExperimentalFeatures() { return await this.httpRequest.get({ path: "experimental-features" }); } async updateExperimentalFeatures(e) { return await this.httpRequest.patch({ path: "experimental-features", body: e }); } }; //#endregion export { t as ContentTypeEnum, n as ErrorStatusCode, x as Index, e as MatchingStrategies, w as Meilisearch, i as MeilisearchApiError, r as MeilisearchError, a as MeilisearchRequestError, o as MeilisearchRequestTimeOutError, s as MeilisearchTaskTimeOutError }; //# sourceMappingURL=index.js.map