UNPKG

deep-search

Version:
84 lines (66 loc) 2.19 kB
/** * Created by mgoria on 3/4/16. */ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.Elasticsearch = undefined; var _deepCore = require('deep-core'); var _deepCore2 = _interopRequireDefault(_deepCore); var _elasticsearch = require('elasticsearch'); var _elasticsearch2 = _interopRequireDefault(_elasticsearch); var _Aws4SignedHttpConnection = require('./Connection/Aws4SignedHttpConnection'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Elasticsearch client * @see https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html */ class Elasticsearch { /** * @param {String} host * @param {Function|null} decorator * @param {Boolean} useAws4Signature * @param {String} apiVersion */ constructor(host, decorator = null, useAws4Signature = true, apiVersion = Elasticsearch.API_VERSION) { this._host = host; this._decorator = decorator; let clientOpts = {}; clientOpts.host = this._host; clientOpts.apiVersion = apiVersion; if (useAws4Signature) { clientOpts.connectionClass = _Aws4SignedHttpConnection.Aws4SignedHttpConnection.createPrototype(); } this._esClient = new _elasticsearch2.default.Client(clientOpts); this._proxy(this, this._esClient, this._decorator); } /** * @param {Elasticsearch} target * @param {elasticsearch} handler * @param {Function} decorator * @param {Array} methods * @private */ _proxy(target, handler, decorator, methods = Elasticsearch.API_METHODS) { let proxy = new _deepCore2.default.Generic.MethodsProxy(target).decorate(decorator); proxy.proxyOverride(handler, ...methods); proxy.proxyProperties(handler); } /** * @returns {Object[]} */ static get API_METHODS() { let esApis = require('elasticsearch/src/lib/apis'); return Object.keys(esApis[Elasticsearch.API_VERSION]); } /** * @returns {String} * * @note - If you want to change this version do update deep-search/node-bin/cleanup.sh also */ static get API_VERSION() { return '2.3'; } } exports.Elasticsearch = Elasticsearch;