UNPKG

@joktec/elastic

Version:

JokTec - ElasticSearch

88 lines 3.92 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ElasticService = void 0; const core_1 = require("@joktec/core"); const http_1 = require("@joktec/http"); const utils_1 = require("@joktec/utils"); const lodash_1 = require("lodash"); const elastic_config_1 = require("./elastic.config"); let ElasticService = class ElasticService extends core_1.AbstractClientService { constructor() { super('elastic', elastic_config_1.ElasticConfig); } async init(config) { config.getRetryConfig(this.logService); return this.httpService; } async start(client, conId = core_1.DEFAULT_CON_ID) { await client.start(client.getClient(conId), conId); } async stop(client, conId = core_1.DEFAULT_CON_ID) { await client.stop(client.getClient(conId), conId); } async search(req, conId = core_1.DEFAULT_CON_ID) { const config = (0, lodash_1.merge)({}, this.getConfig(conId), { url: `${req.index}/_search`, method: 'GET', data: { ...req }, params: { pretty: true }, headers: { 'Content-Type': 'application/json' }, curlirize: (0, utils_1.toBool)(req.curlirize, false), }); const res = await this.getClient(conId).request(config); return res.data; } async index(req, conId = core_1.DEFAULT_CON_ID) { const config = (0, lodash_1.merge)({}, this.getConfig(conId), { url: `${req.index}/_doc/${req.id}`, method: 'POST', data: req.doc, params: { pretty: true }, headers: { 'Content-Type': 'application/json' }, curlirize: (0, utils_1.toBool)(req.curlirize, false), }); const res = await this.getClient(conId).request(config); return res.data; } async get(req, conId = core_1.DEFAULT_CON_ID) { const config = (0, lodash_1.merge)({}, this.getConfig(conId), { url: `${req.index}/_doc/${req.id}`, method: 'GET', params: { pretty: true }, headers: { 'Content-Type': 'application/json' }, curlirize: (0, utils_1.toBool)(req.curlirize, false), }); const res = await this.getClient(conId).request(config); return res.data; } async delete(req, conId = core_1.DEFAULT_CON_ID) { const config = (0, lodash_1.merge)({}, this.getConfig(conId), { url: `${req.index}/_doc/${req.id}`, method: 'DELETE', params: { pretty: true }, headers: { 'Content-Type': 'application/json' }, curlirize: (0, utils_1.toBool)(req.curlirize, false), }); const res = await this.getClient(conId).request(config); return res.data; } }; exports.ElasticService = ElasticService; __decorate([ (0, core_1.Inject)(), __metadata("design:type", http_1.HttpService) ], ElasticService.prototype, "httpService", void 0); exports.ElasticService = ElasticService = __decorate([ (0, core_1.Injectable)(), __metadata("design:paramtypes", []) ], ElasticService); //# sourceMappingURL=elastic.service.js.map