UNPKG

@meilisearch/meili-api

Version:

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

143 lines 3.43 kB
/* * Bundle: Meili * Project: Meili - Javascript API * Author: Quentin de Quelen <quentin@meilisearch.com> * Copyright: 2019, Meili */ 'use strict'; import instance from 'axios'; import { Indexes } from './indexes'; class Meili { constructor(config) { this.baseURL = config.host; this.apiKey = config.apiKey; if (config.apiKey) { this.instance = instance.create({ baseURL: this.baseURL, timeout: 1000, headers: { 'X-Meili-API-Key': config.apiKey, }, }); } else { this.instance = instance.create({ baseURL: this.baseURL, timeout: 1000, }); } this.instance.interceptors.response.use((response) => response.data); } /** * Return an Index instance * @memberof Meili * @method Index */ Index(indexUid) { return new Indexes(this.instance, indexUid); } /** * List all indexes in the database * @memberof Meili * @method listIndexes */ listIndexes() { const url = '/indexes'; return this.instance.get(url); } /** * Create a new index with am optional schema * @memberof Meili * @method createIndex */ createIndex(data) { const url = `/indexes`; return this.instance.post(url, data); } /// /// HEALTH /// /** * Check if the server is healhty * @memberof Admin * @method isHealthy */ isHealthy() { const url = '/health'; return this.instance.get(url).then((res) => true); } /** * Change the healthyness to healthy * @memberof Admin * @method setHealthy */ setHealthy() { const url = '/health'; return this.instance.put(url, { health: true, }); } /** * Change the healthyness to unhealthy * @memberof Admin * @method setUnhealthy */ setUnhealthy() { const url = '/health'; return this.instance.put(url, { health: false, }); } /** * Change the healthyness to unhealthy * @memberof Admin * @method setUnhealthy */ changeHealthTo(health) { const url = '/health'; return this.instance.put(url, { health, }); } /// /// STATS /// /** * Get the stats of all the database * @memberof Admin * @method databaseStats */ databaseStats() { const url = '/stats'; return this.instance.get(url); } /** * Get the version of the server * @memberof Admin * @method version */ version() { const url = '/version'; return this.instance.get(url); } /** * Get the server consuption, RAM / CPU / Network * @memberof Admin * @method systemInformation */ systemInformation() { const url = '/sys-info'; return this.instance.get(url); } /** * Get the server consuption, RAM / CPU / Network. All information as human readable * @memberof Admin * @method systemInformationPretty */ systemInformationPretty() { const url = '/sys-info/pretty'; return this.instance.get(url); } } export default Meili; //# sourceMappingURL=index.js.map