UNPKG

deep-search

Version:
110 lines (81 loc) 3.71 kB
/** * Created by mgoria on 3/4/16. */ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.Elasticsearch = undefined; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); 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 }; } function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Elasticsearch client * @see https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html */ let Elasticsearch = exports.Elasticsearch = function () { /** * @param {String} host * @param {Function|null} decorator * @param {Boolean} useAws4Signature * @param {String} apiVersion */ function Elasticsearch(host) { let decorator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; let useAws4Signature = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; let apiVersion = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : Elasticsearch.API_VERSION; _classCallCheck(this, Elasticsearch); 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 */ _createClass(Elasticsearch, [{ key: '_proxy', value: function _proxy(target, handler, decorator) { let methods = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : Elasticsearch.API_METHODS; let proxy = new _deepCore2.default.Generic.MethodsProxy(target).decorate(decorator); proxy.proxyOverride.apply(proxy, [handler].concat(_toConsumableArray(methods))); proxy.proxyProperties(handler); } /** * @returns {Object[]} */ }], [{ key: 'API_METHODS', get: function get() { 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 */ }, { key: 'API_VERSION', get: function get() { return '2.3'; } }]); return Elasticsearch; }();