"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.Dataset = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ class Dataset { constructor(dataset, parentIntegration) { var _dataset$title; (0, _defineProperty2.default)(this, "id", void 0); (0, _defineProperty2.default)(this, "iconType", void 0); (0, _defineProperty2.default)(this, "name", void 0); (0, _defineProperty2.default)(this, "title", void 0); (0, _defineProperty2.default)(this, "parentIntegration", void 0); this.id = `dataset-${dataset.name}`; this.iconType = dataset.iconType; this.name = dataset.name; this.title = (_dataset$title = dataset.title) !== null && _dataset$title !== void 0 ? _dataset$title : dataset.name; this.parentIntegration = parentIntegration && { name: parentIntegration.name, title: parentIntegration.title, icons: parentIntegration.icons, version: parentIntegration.version }; } getFullTitle() { var _this$parentIntegrati; return (_this$parentIntegrati = this.parentIntegration) !== null && _this$parentIntegrati !== void 0 && _this$parentIntegrati.title ? `[${this.parentIntegration.title}] ${this.title}` : this.title; } getDatasetWildcard() { const [type, dataset, _namespace] = this.name.split('-'); return `${type}-${dataset}-*`; } toDataviewSpec() { // Invert the property because the API returns the index pattern as `name` and a readable name as `title` return { id: this.id, name: this.getFullTitle(), title: this.name }; } toPlain() { return { name: this.name, title: this.title }; } static create(dataset, parentIntegration) { return new Dataset(dataset, parentIntegration); } static createAllLogsDataset() { return new Dataset({ name: 'logs-*-*', title: 'All log datasets', iconType: 'editorChecklist' }); } static createWildcardDatasetsFrom(datasets) { // Gather unique list of wildcards const wildcards = datasets.reduce((list, dataset) => list.add(dataset.getDatasetWildcard()), new Set()); // Create new datasets for the retrieved wildcards return Array.from(wildcards).map(wildcard => Dataset.create({ name: wildcard })); } } exports.Dataset = Dataset;