meilisearch
Version:
The Meilisearch JS client for Node.js and the browser.
5 lines (4 loc) • 34.1 kB
JavaScript
(function(c,_){typeof exports=="object"&&typeof module!="undefined"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(c=typeof globalThis!="undefined"?globalThis:c||self,_(c.meilisearch={}))})(this,function(c){"use strict";var z=Object.defineProperty,J=Object.defineProperties;var Z=Object.getOwnPropertyDescriptors;var F=Object.getOwnPropertySymbols;var tt=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable;var P=(c,_,h)=>_ in c?z(c,_,{enumerable:!0,configurable:!0,writable:!0,value:h}):c[_]=h,o=(c,_)=>{for(var h in _||(_={}))tt.call(_,h)&&P(c,h,_[h]);if(F)for(var h of F(_))et.call(_,h)&&P(c,h,_[h]);return c},A=(c,_)=>J(c,Z(_));var u=(c,_,h)=>P(c,typeof _!="symbol"?_+"":_,h);var i=(c,_,h)=>new Promise((D,f)=>{var S=E=>{try{T(h.next(E))}catch(m){f(m)}},O=E=>{try{T(h.throw(E))}catch(m){f(m)}},T=E=>E.done?D(E.value):Promise.resolve(E.value).then(S,O);T((h=h.apply(c,_)).next())});class _ extends Error{constructor(...e){super(...e);u(this,"name","MeiliSearchError")}}class h extends _{constructor(e,s){var n;super((n=s==null?void 0:s.message)!=null?n:`${e.status}: ${e.statusText}`);u(this,"name","MeiliSearchApiError");u(this,"cause");u(this,"response");this.response=e,s!==void 0&&(this.cause=s)}}class D extends _{constructor(e,s){super(`Request to ${e} has failed`,{cause:s});u(this,"name","MeiliSearchRequestError")}}class f extends _{constructor(e){super(e);u(this,"name","MeiliSearchTimeOutError")}}function S(r,t){return`${r}
Hint: It might not be working because maybe you're not up to date with the Meilisearch version that ${t} call requires.`}const O="0.49.0";function T(r){return Object.entries(r).reduce((t,e)=>{const[s,n]=e;return n!==void 0&&(t[s]=n),t},{})}function E(r){return i(this,null,function*(){return yield new Promise(t=>setTimeout(t,r))})}function m(r){return r.startsWith("https://")||r.startsWith("http://")?r:`http://${r}`}function K(r){return r.endsWith("/")||(r+="/"),r}function x(r){return Object.keys(r).reduce((s,n)=>{const a=r[n];return a===void 0?s:Array.isArray(a)?A(o({},s),{[n]:a.join(",")}):a instanceof Date?A(o({},s),{[n]:a.toISOString()}):A(o({},s),{[n]:a})},{})}function H(r){try{return r=m(r),r=K(r),r}catch(t){throw new _("The provided host is not valid.")}}function G(r){if(Array.isArray(r))return r.reduce((t,e)=>(t[e[0]]=e[1],t),{});if("has"in r){const t={};return r.forEach((e,s)=>t[s]=e),t}else return Object.assign({},r)}function Y(r){var I,l;const t="X-Meilisearch-Client",e=`Meilisearch JavaScript (v${O})`,s="Content-Type",n="Authorization",a=G((l=(I=r.requestConfig)==null?void 0:I.headers)!=null?l:{});if(r.apiKey&&!a[n]&&(a[n]=`Bearer ${r.apiKey}`),a[s]||(a["Content-Type"]="application/json"),r.clientAgents&&Array.isArray(r.clientAgents)){const p=r.clientAgents.concat(e);a[t]=p.join(" ; ")}else{if(r.clientAgents&&!Array.isArray(r.clientAgents))throw new _(`Meilisearch: The header "${t}" should be an array of string(s).
`);a[t]=e}return a}class k{constructor(t){u(this,"headers");u(this,"url");u(this,"requestConfig");u(this,"httpClient");u(this,"requestTimeout");this.headers=Y(t),this.requestConfig=t.requestConfig,this.httpClient=t.httpClient,this.requestTimeout=t.timeout;try{const e=H(t.host);this.url=new URL(e)}catch(e){throw new _("The provided host is not valid.")}}request(I){return i(this,arguments,function*({method:t,url:e,params:s,body:n,config:a={}}){var L;const l=new URL(e,this.url);if(s){const g=new URLSearchParams;Object.keys(s).filter(C=>s[C]!==null).map(C=>g.set(C,s[C])),l.search=g.toString()}(L=a.headers)!=null&&L["Content-Type"]||(n=JSON.stringify(n));const p=o(o({},this.headers),a.headers),y=yield this.fetchWithTimeout(l.toString(),A(o(o({},a),this.requestConfig),{method:t,body:n,headers:p}),this.requestTimeout).catch(g=>{throw new D(l.toString(),g)});if(this.httpClient!==void 0)return y;const q=yield y.text(),R=q===""?void 0:JSON.parse(q);if(!y.ok)throw new h(y,R);return R})}fetchWithTimeout(t,e,s){return i(this,null,function*(){return new Promise((n,a)=>{const p=[(this.httpClient?this.httpClient:fetch)(t,e)];let N;if(s){const y=new Promise((q,R)=>{N=setTimeout(()=>{R(new Error("Error: Request Timed Out"))},s)});p.push(y)}Promise.race(p).then(n).catch(a).finally(()=>{clearTimeout(N)})})})}get(t,e,s){return i(this,null,function*(){return yield this.request({method:"GET",url:t,params:e,config:s})})}post(t,e,s,n){return i(this,null,function*(){return yield this.request({method:"POST",url:t,body:e,params:s,config:n})})}put(t,e,s,n){return i(this,null,function*(){return yield this.request({method:"PUT",url:t,body:e,params:s,config:n})})}patch(t,e,s,n){return i(this,null,function*(){return yield this.request({method:"PATCH",url:t,body:e,params:s,config:n})})}delete(t,e,s,n){return i(this,null,function*(){return yield this.request({method:"DELETE",url:t,body:e,params:s,config:n})})}}class d{constructor(t){u(this,"taskUid");u(this,"indexUid");u(this,"status");u(this,"type");u(this,"enqueuedAt");this.taskUid=t.taskUid,this.indexUid=t.indexUid,this.status=t.status,this.type=t.type,this.enqueuedAt=new Date(t.enqueuedAt)}}class b{constructor(t){u(this,"indexUid");u(this,"status");u(this,"type");u(this,"uid");u(this,"batchUid");u(this,"canceledBy");u(this,"details");u(this,"error");u(this,"duration");u(this,"startedAt");u(this,"enqueuedAt");u(this,"finishedAt");this.indexUid=t.indexUid,this.status=t.status,this.type=t.type,this.uid=t.uid,this.batchUid=t.batchUid,this.details=t.details,this.canceledBy=t.canceledBy,this.error=t.error,this.duration=t.duration,this.startedAt=new Date(t.startedAt),this.enqueuedAt=new Date(t.enqueuedAt),this.finishedAt=new Date(t.finishedAt)}}class v{constructor(t){u(this,"httpRequest");this.httpRequest=new k(t)}getTask(t){return i(this,null,function*(){const e=`tasks/${t}`,s=yield this.httpRequest.get(e);return new b(s)})}getTasks(){return i(this,arguments,function*(t={}){const s=yield this.httpRequest.get("tasks",x(t));return A(o({},s),{results:s.results.map(n=>new b(n))})})}waitForTask(n){return i(this,arguments,function*(t,{timeOutMs:e=5e3,intervalMs:s=50}={}){const a=Date.now();for(;Date.now()-a<e;){const I=yield this.getTask(t);if(![$.TASK_ENQUEUED,$.TASK_PROCESSING].includes(I.status))return I;yield E(s)}throw new f(`timeout of ${e}ms has exceeded on process ${t} when waiting a task to be resolved.`)})}waitForTasks(n){return i(this,arguments,function*(t,{timeOutMs:e=5e3,intervalMs:s=50}={}){const a=[];for(const I of t){const l=yield this.waitForTask(I,{timeOutMs:e,intervalMs:s});a.push(l)}return a})}cancelTasks(){return i(this,arguments,function*(t={}){const s=yield this.httpRequest.post("tasks/cancel",{},x(t));return new d(s)})}deleteTasks(){return i(this,arguments,function*(t={}){const s=yield this.httpRequest.delete("tasks",{},x(t));return new d(s)})}}class U{constructor(t){u(this,"uid");u(this,"details");u(this,"stats");u(this,"startedAt");u(this,"finishedAt");u(this,"duration");u(this,"progress");this.uid=t.uid,this.details=t.details,this.stats=t.stats,this.startedAt=t.startedAt,this.finishedAt=t.finishedAt,this.duration=t.duration,this.progress=t.progress}}class B{constructor(t){u(this,"httpRequest");this.httpRequest=new k(t)}getBatch(t){return i(this,null,function*(){const e=`batches/${t}`,s=yield this.httpRequest.get(e);return new U(s)})}getBatches(){return i(this,arguments,function*(t={}){const s=yield this.httpRequest.get("batches",x(t));return A(o({},s),{results:s.results.map(n=>new U(n))})})}}const X={ALL:"all",LAST:"last",FREQUENCY:"frequency"},j={JSON:"application/json",CSV:"text/csv",NDJSON:"application/x-ndjson"},$={TASK_SUCCEEDED:"succeeded",TASK_PROCESSING:"processing",TASK_FAILED:"failed",TASK_ENQUEUED:"enqueued",TASK_CANCELED:"canceled"},W={DOCUMENTS_ADDITION_OR_UPDATE:"documentAdditionOrUpdate",DOCUMENT_DELETION:"documentDeletion",DUMP_CREATION:"dumpCreation",INDEX_CREATION:"indexCreation",INDEX_DELETION:"indexDeletion",INDEXES_SWAP:"indexSwap",INDEX_UPDATE:"indexUpdate",SETTINGS_UPDATE:"settingsUpdate",SNAPSHOT_CREATION:"snapshotCreation",TASK_CANCELATION:"taskCancelation",TASK_DELETION:"taskDeletion"},V={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"};class w{constructor(t,e,s){u(this,"uid");u(this,"primaryKey");u(this,"createdAt");u(this,"updatedAt");u(this,"httpRequest");u(this,"tasks");this.uid=e,this.primaryKey=s,this.httpRequest=new k(t),this.tasks=new v(t)}search(t,e,s){return i(this,null,function*(){const n=`indexes/${this.uid}/search`;return yield this.httpRequest.post(n,T(o({q:t},e)),void 0,s)})}searchGet(t,e,s){return i(this,null,function*(){var l,p,N,y,q,R,L;const n=`indexes/${this.uid}/search`,a=g=>{if(typeof g=="string")return g;if(Array.isArray(g))throw new _("The filter query parameter should be in string format when using searchGet")},I=A(o({q:t},e),{filter:a(e==null?void 0:e.filter),sort:(l=e==null?void 0:e.sort)==null?void 0:l.join(","),facets:(p=e==null?void 0:e.facets)==null?void 0:p.join(","),attributesToRetrieve:(N=e==null?void 0:e.attributesToRetrieve)==null?void 0:N.join(","),attributesToCrop:(y=e==null?void 0:e.attributesToCrop)==null?void 0:y.join(","),attributesToHighlight:(q=e==null?void 0:e.attributesToHighlight)==null?void 0:q.join(","),vector:(R=e==null?void 0:e.vector)==null?void 0:R.join(","),attributesToSearchOn:(L=e==null?void 0:e.attributesToSearchOn)==null?void 0:L.join(",")});return yield this.httpRequest.get(n,T(I),s)})}searchForFacetValues(t,e){return i(this,null,function*(){const s=`indexes/${this.uid}/facet-search`;return yield this.httpRequest.post(s,T(t),void 0,e)})}searchSimilarDocuments(t){return i(this,null,function*(){const e=`indexes/${this.uid}/similar`;return yield this.httpRequest.post(e,T(t),void 0)})}getRawInfo(){return i(this,null,function*(){const t=`indexes/${this.uid}`,e=yield this.httpRequest.get(t);return this.primaryKey=e.primaryKey,this.updatedAt=new Date(e.updatedAt),this.createdAt=new Date(e.createdAt),e})}fetchInfo(){return i(this,null,function*(){return yield this.getRawInfo(),this})}fetchPrimaryKey(){return i(this,null,function*(){return this.primaryKey=(yield this.getRawInfo()).primaryKey,this.primaryKey})}static create(n){return i(this,arguments,function*(t,e={},s){const l=yield new k(s).post("indexes",A(o({},e),{uid:t}));return new d(l)})}update(t){return i(this,null,function*(){const e=`indexes/${this.uid}`,s=yield this.httpRequest.patch(e,t);return s.enqueuedAt=new Date(s.enqueuedAt),s})}delete(){return i(this,null,function*(){const t=`indexes/${this.uid}`,e=yield this.httpRequest.delete(t);return new d(e)})}getTasks(){return i(this,arguments,function*(t={}){return yield this.tasks.getTasks(A(o({},t),{indexUids:[this.uid]}))})}getTask(t){return i(this,null,function*(){return yield this.tasks.getTask(t)})}waitForTasks(n){return i(this,arguments,function*(t,{timeOutMs:e=5e3,intervalMs:s=50}={}){return yield this.tasks.waitForTasks(t,{timeOutMs:e,intervalMs:s})})}waitForTask(n){return i(this,arguments,function*(t,{timeOutMs:e=5e3,intervalMs:s=50}={}){return yield this.tasks.waitForTask(t,{timeOutMs:e,intervalMs:s})})}getStats(){return i(this,null,function*(){const t=`indexes/${this.uid}/stats`;return yield this.httpRequest.get(t)})}getDocuments(){return i(this,arguments,function*(t={}){var e;if(t=T(t),t.filter!==void 0)try{const s=`indexes/${this.uid}/documents/fetch`;return yield this.httpRequest.post(s,t)}catch(s){throw(s instanceof D||s instanceof h)&&(s.message=S(s.message,"getDocuments")),s}else{const s=`indexes/${this.uid}/documents`,n=Array.isArray(t==null?void 0:t.fields)?{fields:(e=t==null?void 0:t.fields)==null?void 0:e.join(",")}:{};return yield this.httpRequest.get(s,o(o({},t),n))}})}getDocument(t,e){return i(this,null,function*(){const s=`indexes/${this.uid}/documents/${t}`,n=(()=>{var a;if(Array.isArray(e==null?void 0:e.fields))return(a=e==null?void 0:e.fields)==null?void 0:a.join(",")})();return yield this.httpRequest.get(s,T(A(o({},e),{fields:n})))})}addDocuments(t,e){return i(this,null,function*(){const s=`indexes/${this.uid}/documents`,n=yield this.httpRequest.post(s,t,e);return new d(n)})}addDocumentsFromString(t,e,s){return i(this,null,function*(){const n=`indexes/${this.uid}/documents`,a=yield this.httpRequest.post(n,t,s,{headers:{"Content-Type":e}});return new d(a)})}addDocumentsInBatches(t,e=1e3,s){return i(this,null,function*(){const n=[];for(let a=0;a<t.length;a+=e)n.push(yield this.addDocuments(t.slice(a,a+e),s));return n})}updateDocuments(t,e){return i(this,null,function*(){const s=`indexes/${this.uid}/documents`,n=yield this.httpRequest.put(s,t,e);return new d(n)})}updateDocumentsInBatches(t,e=1e3,s){return i(this,null,function*(){const n=[];for(let a=0;a<t.length;a+=e)n.push(yield this.updateDocuments(t.slice(a,a+e),s));return n})}updateDocumentsFromString(t,e,s){return i(this,null,function*(){const n=`indexes/${this.uid}/documents`,a=yield this.httpRequest.put(n,t,s,{headers:{"Content-Type":e}});return new d(a)})}deleteDocument(t){return i(this,null,function*(){const e=`indexes/${this.uid}/documents/${t}`,s=yield this.httpRequest.delete(e);return s.enqueuedAt=new Date(s.enqueuedAt),s})}deleteDocuments(t){return i(this,null,function*(){const e=!Array.isArray(t)&&typeof t=="object",s=e?"documents/delete":"documents/delete-batch",n=`indexes/${this.uid}/${s}`;try{const a=yield this.httpRequest.post(n,t);return new d(a)}catch(a){throw(a instanceof D&&e||a instanceof h)&&(a.message=S(a.message,"deleteDocuments")),a}})}deleteAllDocuments(){return i(this,null,function*(){const t=`indexes/${this.uid}/documents`,e=yield this.httpRequest.delete(t);return e.enqueuedAt=new Date(e.enqueuedAt),e})}updateDocumentsByFunction(t){return i(this,null,function*(){const e=`indexes/${this.uid}/documents/edit`,s=yield this.httpRequest.post(e,t);return new d(s)})}getSettings(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings`;return yield this.httpRequest.get(t)})}updateSettings(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings`,s=yield this.httpRequest.patch(e,t);return s.enqueued=new Date(s.enqueuedAt),s})}resetSettings(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings`,e=yield this.httpRequest.delete(t);return e.enqueuedAt=new Date(e.enqueuedAt),e})}getPagination(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/pagination`;return yield this.httpRequest.get(t)})}updatePagination(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/pagination`,s=yield this.httpRequest.patch(e,t);return new d(s)})}resetPagination(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/pagination`,e=yield this.httpRequest.delete(t);return new d(e)})}getSynonyms(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/synonyms`;return yield this.httpRequest.get(t)})}updateSynonyms(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/synonyms`,s=yield this.httpRequest.put(e,t);return new d(s)})}resetSynonyms(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/synonyms`,e=yield this.httpRequest.delete(t);return e.enqueuedAt=new Date(e.enqueuedAt),e})}getStopWords(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/stop-words`;return yield this.httpRequest.get(t)})}updateStopWords(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/stop-words`,s=yield this.httpRequest.put(e,t);return new d(s)})}resetStopWords(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/stop-words`,e=yield this.httpRequest.delete(t);return e.enqueuedAt=new Date(e.enqueuedAt),e})}getRankingRules(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/ranking-rules`;return yield this.httpRequest.get(t)})}updateRankingRules(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/ranking-rules`,s=yield this.httpRequest.put(e,t);return new d(s)})}resetRankingRules(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/ranking-rules`,e=yield this.httpRequest.delete(t);return e.enqueuedAt=new Date(e.enqueuedAt),e})}getDistinctAttribute(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/distinct-attribute`;return yield this.httpRequest.get(t)})}updateDistinctAttribute(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/distinct-attribute`,s=yield this.httpRequest.put(e,t);return new d(s)})}resetDistinctAttribute(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/distinct-attribute`,e=yield this.httpRequest.delete(t);return e.enqueuedAt=new Date(e.enqueuedAt),e})}getFilterableAttributes(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/filterable-attributes`;return yield this.httpRequest.get(t)})}updateFilterableAttributes(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/filterable-attributes`,s=yield this.httpRequest.put(e,t);return new d(s)})}resetFilterableAttributes(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/filterable-attributes`,e=yield this.httpRequest.delete(t);return e.enqueuedAt=new Date(e.enqueuedAt),e})}getSortableAttributes(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/sortable-attributes`;return yield this.httpRequest.get(t)})}updateSortableAttributes(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/sortable-attributes`,s=yield this.httpRequest.put(e,t);return new d(s)})}resetSortableAttributes(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/sortable-attributes`,e=yield this.httpRequest.delete(t);return e.enqueuedAt=new Date(e.enqueuedAt),e})}getSearchableAttributes(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/searchable-attributes`;return yield this.httpRequest.get(t)})}updateSearchableAttributes(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/searchable-attributes`,s=yield this.httpRequest.put(e,t);return new d(s)})}resetSearchableAttributes(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/searchable-attributes`,e=yield this.httpRequest.delete(t);return e.enqueuedAt=new Date(e.enqueuedAt),e})}getDisplayedAttributes(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/displayed-attributes`;return yield this.httpRequest.get(t)})}updateDisplayedAttributes(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/displayed-attributes`,s=yield this.httpRequest.put(e,t);return new d(s)})}resetDisplayedAttributes(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/displayed-attributes`,e=yield this.httpRequest.delete(t);return e.enqueuedAt=new Date(e.enqueuedAt),e})}getTypoTolerance(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/typo-tolerance`;return yield this.httpRequest.get(t)})}updateTypoTolerance(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/typo-tolerance`,s=yield this.httpRequest.patch(e,t);return s.enqueuedAt=new Date(s.enqueuedAt),s})}resetTypoTolerance(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/typo-tolerance`,e=yield this.httpRequest.delete(t);return e.enqueuedAt=new Date(e.enqueuedAt),e})}getFaceting(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/faceting`;return yield this.httpRequest.get(t)})}updateFaceting(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/faceting`,s=yield this.httpRequest.patch(e,t);return new d(s)})}resetFaceting(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/faceting`,e=yield this.httpRequest.delete(t);return new d(e)})}getSeparatorTokens(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/separator-tokens`;return yield this.httpRequest.get(t)})}updateSeparatorTokens(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/separator-tokens`,s=yield this.httpRequest.put(e,t);return new d(s)})}resetSeparatorTokens(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/separator-tokens`,e=yield this.httpRequest.delete(t);return e.enqueuedAt=new Date(e.enqueuedAt),e})}getNonSeparatorTokens(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/non-separator-tokens`;return yield this.httpRequest.get(t)})}updateNonSeparatorTokens(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/non-separator-tokens`,s=yield this.httpRequest.put(e,t);return new d(s)})}resetNonSeparatorTokens(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/non-separator-tokens`,e=yield this.httpRequest.delete(t);return e.enqueuedAt=new Date(e.enqueuedAt),e})}getDictionary(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/dictionary`;return yield this.httpRequest.get(t)})}updateDictionary(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/dictionary`,s=yield this.httpRequest.put(e,t);return new d(s)})}resetDictionary(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/dictionary`,e=yield this.httpRequest.delete(t);return e.enqueuedAt=new Date(e.enqueuedAt),e})}getProximityPrecision(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/proximity-precision`;return yield this.httpRequest.get(t)})}updateProximityPrecision(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/proximity-precision`,s=yield this.httpRequest.put(e,t);return new d(s)})}resetProximityPrecision(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/proximity-precision`,e=yield this.httpRequest.delete(t);return e.enqueuedAt=new Date(e.enqueuedAt),e})}getEmbedders(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/embedders`;return yield this.httpRequest.get(t)})}updateEmbedders(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/embedders`,s=yield this.httpRequest.patch(e,t);return new d(s)})}resetEmbedders(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/embedders`,e=yield this.httpRequest.delete(t);return e.enqueuedAt=new Date(e.enqueuedAt),e})}getSearchCutoffMs(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/search-cutoff-ms`;return yield this.httpRequest.get(t)})}updateSearchCutoffMs(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/search-cutoff-ms`,s=yield this.httpRequest.put(e,t);return new d(s)})}resetSearchCutoffMs(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/search-cutoff-ms`,e=yield this.httpRequest.delete(t);return new d(e)})}getLocalizedAttributes(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/localized-attributes`;return yield this.httpRequest.get(t)})}updateLocalizedAttributes(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/localized-attributes`,s=yield this.httpRequest.put(e,t);return new d(s)})}resetLocalizedAttributes(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/localized-attributes`,e=yield this.httpRequest.delete(t);return new d(e)})}getFacetSearch(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/facet-search`;return yield this.httpRequest.get(t)})}updateFacetSearch(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/facet-search`,s=yield this.httpRequest.put(e,t);return new d(s)})}resetFacetSearch(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/facet-search`,e=yield this.httpRequest.delete(t);return new d(e)})}getPrefixSearch(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/prefix-search`;return yield this.httpRequest.get(t)})}updatePrefixSearch(t){return i(this,null,function*(){const e=`indexes/${this.uid}/settings/prefix-search`,s=yield this.httpRequest.put(e,t);return new d(s)})}resetPrefixSearch(){return i(this,null,function*(){const t=`indexes/${this.uid}/settings/prefix-search`,e=yield this.httpRequest.delete(t);return new d(e)})}}class M{constructor(t){u(this,"config");u(this,"httpRequest");u(this,"tasks");u(this,"batches");this.config=t,this.httpRequest=new k(t),this.tasks=new v(t),this.batches=new B(t)}index(t){return new w(this.config,t)}getIndex(t){return i(this,null,function*(){return new w(this.config,t).fetchInfo()})}getRawIndex(t){return i(this,null,function*(){return new w(this.config,t).getRawInfo()})}getIndexes(){return i(this,arguments,function*(t={}){const e=yield this.getRawIndexes(t),s=e.results.map(n=>new w(this.config,n.uid,n.primaryKey));return A(o({},e),{results:s})})}getRawIndexes(){return i(this,arguments,function*(t={}){return yield this.httpRequest.get("indexes",t)})}createIndex(s){return i(this,arguments,function*(t,e={}){return yield w.create(t,e,this.config)})}updateIndex(s){return i(this,arguments,function*(t,e={}){return yield new w(this.config,t).update(e)})}deleteIndex(t){return i(this,null,function*(){return yield new w(this.config,t).delete()})}deleteIndexIfExists(t){return i(this,null,function*(){try{return yield this.deleteIndex(t),!0}catch(e){if(e.code===V.INDEX_NOT_FOUND)return!1;throw e}})}swapIndexes(t){return i(this,null,function*(){return yield this.httpRequest.post("/swap-indexes",t)})}multiSearch(t,e){return i(this,null,function*(){return yield this.httpRequest.post("multi-search",t,void 0,e)})}getTasks(){return i(this,arguments,function*(t={}){return yield this.tasks.getTasks(t)})}getTask(t){return i(this,null,function*(){return yield this.tasks.getTask(t)})}waitForTasks(n){return i(this,arguments,function*(t,{timeOutMs:e=5e3,intervalMs:s=50}={}){return yield this.tasks.waitForTasks(t,{timeOutMs:e,intervalMs:s})})}waitForTask(n){return i(this,arguments,function*(t,{timeOutMs:e=5e3,intervalMs:s=50}={}){return yield this.tasks.waitForTask(t,{timeOutMs:e,intervalMs:s})})}cancelTasks(t){return i(this,null,function*(){return yield this.tasks.cancelTasks(t)})}deleteTasks(){return i(this,arguments,function*(t={}){return yield this.tasks.deleteTasks(t)})}getBatches(){return i(this,arguments,function*(t={}){return yield this.batches.getBatches(t)})}getBatch(t){return i(this,null,function*(){return yield this.batches.getBatch(t)})}getKeys(){return i(this,arguments,function*(t={}){const s=yield this.httpRequest.get("keys",t);return s.results=s.results.map(n=>A(o({},n),{createdAt:new Date(n.createdAt),updatedAt:new Date(n.updatedAt)})),s})}getKey(t){return i(this,null,function*(){const e=`keys/${t}`;return yield this.httpRequest.get(e)})}createKey(t){return i(this,null,function*(){return yield this.httpRequest.post("keys",t)})}updateKey(t,e){return i(this,null,function*(){const s=`keys/${t}`;return yield this.httpRequest.patch(s,e)})}deleteKey(t){return i(this,null,function*(){const e=`keys/${t}`;return yield this.httpRequest.delete(e)})}health(){return i(this,null,function*(){return yield this.httpRequest.get("health")})}isHealthy(){return i(this,null,function*(){try{return yield this.httpRequest.get("health"),!0}catch(t){return!1}})}getStats(){return i(this,null,function*(){return yield this.httpRequest.get("stats")})}getVersion(){return i(this,null,function*(){return yield this.httpRequest.get("version")})}createDump(){return i(this,null,function*(){const e=yield this.httpRequest.post("dumps");return new d(e)})}createSnapshot(){return i(this,null,function*(){const e=yield this.httpRequest.post("snapshots");return new d(e)})}}const Q=M;c.ContentTypeEnum=j,c.EnqueuedTask=d,c.ErrorStatusCode=V,c.Index=w,c.MatchingStrategies=X,c.MeiliSearch=M,c.MeiliSearchApiError=h,c.MeiliSearchError=_,c.MeiliSearchRequestError=D,c.MeiliSearchTimeOutError=f,c.Meilisearch=M,c.Task=b,c.TaskClient=v,c.TaskStatus=$,c.TaskTypes=W,c.default=Q,c.versionErrorHintMessage=S,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});(function(){if(typeof self!="undefined"){var c=Object.assign({},self.meilisearch);delete c.default,Object.assign(self,c)}})();
//# sourceMappingURL=index.min.js.map