plugin-elastic-report 0.0.0-stage → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ai/skills/elastic-report/SKILLS.md +34 -0
- package/client-v2.d.ts +2 -0
- package/client-v2.js +1 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/357.0dd385384cab5dbf.js +10 -0
- package/dist/client/index.js +10 -0
- package/dist/client-v2/851.142c93fc6d666b28.js +10 -0
- package/dist/client-v2/857.a5bf9637d5fd4ef5.js +10 -0
- package/dist/client-v2/877.f4095a3dbcadf98f.js +10 -0
- package/dist/client-v2/index.js +10 -0
- package/dist/externalVersion.js +21 -0
- package/dist/index.js +48 -0
- package/dist/locale/en-US.json +198 -0
- package/dist/locale/vi-VN.json +198 -0
- package/dist/locale/zh-CN.json +198 -0
- package/dist/node_modules/@elastic/elasticsearch/.dockerignore +11 -0
- package/dist/node_modules/@elastic/elasticsearch/LICENSE +202 -0
- package/dist/node_modules/@elastic/elasticsearch/NOTICE.txt +2 -0
- package/dist/node_modules/@elastic/elasticsearch/catalog-info.yaml +50 -0
- package/dist/node_modules/@elastic/elasticsearch/codecov.yml +14 -0
- package/dist/node_modules/@elastic/elasticsearch/index.d.ts +28 -0
- package/dist/node_modules/@elastic/elasticsearch/index.js +85525 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/async_search.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/async_search.js +155 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/autoscaling.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/autoscaling.js +130 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/bulk.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/bulk.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/capabilities.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/capabilities.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cat.d.ts +193 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cat.js +766 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ccr.d.ts +102 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ccr.js +395 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/clear_scroll.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/clear_scroll.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/close_point_in_time.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/close_point_in_time.js +56 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cluster.d.ts +123 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cluster.js +482 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/connector.d.ts +245 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/connector.js +1121 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/count.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/count.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/create.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/create.js +53 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/dangling_indices.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/dangling_indices.js +100 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query_rethrottle.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query_rethrottle.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_script.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_script.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/enrich.d.ts +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/enrich.js +169 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/eql.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/eql.js +139 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/esql.d.ts +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/esql.js +170 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists_source.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists_source.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/explain.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/explain.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/features.d.ts +25 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/features.js +75 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/field_caps.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/field_caps.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/fleet.d.ts +50 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/fleet.js +211 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_context.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_context.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_languages.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_languages.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_source.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_source.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/graph.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/graph.js +70 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/health_report.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/health_report.js +54 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ilm.d.ts +88 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ilm.js +329 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/index.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/index.js +61 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/indices.d.ts +494 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/indices.js +2133 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/inference.d.ts +221 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/inference.js +1167 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/info.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/info.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ingest.d.ts +95 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ingest.js +389 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/knn_search.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/knn_search.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/license.d.ts +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/license.js +194 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/logstash.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/logstash.js +118 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mget.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mget.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/migration.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/migration.js +107 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ml.d.ts +522 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ml.js +2468 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/monitoring.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/monitoring.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch_template.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch_template.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mtermvectors.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mtermvectors.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/nodes.d.ts +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/nodes.js +290 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/open_point_in_time.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/open_point_in_time.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ping.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ping.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/profiling.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/profiling.js +135 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/put_script.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/put_script.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/query_rules.d.ts +67 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/query_rules.js +260 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rank_eval.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rank_eval.js +67 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex.js +56 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex_rethrottle.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex_rethrottle.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/render_search_template.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/render_search_template.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rollup.d.ts +67 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rollup.js +263 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scripts_painless_execute.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scripts_painless_execute.js +57 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scroll.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scroll.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search.js +75 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_application.d.ts +81 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_application.js +313 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_mvt.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_mvt.js +63 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_shards.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_shards.js +54 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_template.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_template.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/searchable_snapshots.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/searchable_snapshots.js +167 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/security.d.ts +459 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/security.js +1982 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/shutdown.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/shutdown.js +125 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/simulate.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/simulate.js +78 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/slm.d.ts +74 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/slm.js +253 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/snapshot.d.ts +102 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/snapshot.js +410 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/sql.d.ts +53 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/sql.js +205 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ssl.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ssl.js +54 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/streams.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/streams.js +96 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/synonyms.d.ts +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/synonyms.js +223 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/tasks.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/tasks.js +109 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/terms_enum.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/terms_enum.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/termvectors.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/termvectors.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/text_structure.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/text_structure.js +148 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/transform.d.ts +101 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/transform.js +386 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query_rethrottle.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query_rethrottle.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/watcher.d.ts +102 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/watcher.js +405 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/xpack.d.ts +25 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/xpack.js +75 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/index.d.ts +265 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/index.js +632 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/types.d.ts +19933 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/types.js +21 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey.d.ts +20606 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey.js +21 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/client.d.ts +152 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/client.js +369 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/helpers.d.ts +184 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/helpers.js +889 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/sniffingTransport.d.ts +4 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/sniffingTransport.js +56 -0
- package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv +15 -0
- package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv.cmd +7 -0
- package/dist/node_modules/@elastic/elasticsearch/package.json +1 -0
- package/dist/node_modules/@elastic/elasticsearch/tsconfig.json +38 -0
- package/dist/server/acl-guard.js +179 -0
- package/dist/server/collections/es-report-data-views.js +85 -0
- package/dist/server/collections/es-reports.js +101 -0
- package/dist/server/index.js +58 -0
- package/dist/server/mcp/ElasticReportMcpServer.js +344 -0
- package/dist/server/mcp/ElasticReportToolCatalog.js +639 -0
- package/dist/server/plugin.js +529 -0
- package/dist/server/services/ElasticReportService.js +377 -0
- package/dist/server/services/ElasticsearchConnectionService.js +572 -0
- package/dist/server/services/ReportExportService.js +243 -0
- package/dist/server/services/ReportQueryCompiler.js +1299 -0
- package/dist/server/workflow/ElasticReportQueryInstruction.js +123 -0
- package/dist/shared/constants.js +96 -0
- package/dist/shared/types.js +24 -0
- package/package.json +62 -4
- package/server.d.ts +2 -0
- package/server.js +1 -0
- package/src/client/index.tsx +34 -0
- package/src/client/workflow-instructions.tsx +44 -0
- package/src/client-v2/__tests__/elastic-report.test.tsx +791 -0
- package/src/client-v2/__tests__/kql-autocomplete.test.ts +178 -0
- package/src/client-v2/api.ts +320 -0
- package/src/client-v2/bus/DashboardFilterBus.ts +212 -0
- package/src/client-v2/components/ElasticBasicCharts.tsx +652 -0
- package/src/client-v2/components/ElasticFilterBar.tsx +372 -0
- package/src/client-v2/components/ElasticKqlInput.tsx +421 -0
- package/src/client-v2/components/ElasticReportBlock.tsx +306 -0
- package/src/client-v2/components/ElasticReportRenderer.tsx +1257 -0
- package/src/client-v2/components/HighlightText.tsx +50 -0
- package/src/client-v2/components/ReportSelect.tsx +85 -0
- package/src/client-v2/index.tsx +14 -0
- package/src/client-v2/locale.ts +23 -0
- package/src/client-v2/models/ElasticFilterBarBlockModel.tsx +115 -0
- package/src/client-v2/models/ElasticReportBlockModel.tsx +118 -0
- package/src/client-v2/pages/ElasticReportManager.tsx +1453 -0
- package/src/client-v2/plugin.tsx +72 -0
- package/src/client-v2/utils/kqlAutocomplete.ts +861 -0
- package/src/client-v2/workflow/instructions.tsx +149 -0
- package/src/index.ts +11 -0
- package/src/locale/en-US.json +198 -0
- package/src/locale/vi-VN.json +198 -0
- package/src/locale/zh-CN.json +198 -0
- package/src/server/__tests__/query-compiler.test.ts +620 -0
- package/src/server/__tests__/report-mcp-acl.integration.test.ts +645 -0
- package/src/server/acl-guard.ts +194 -0
- package/src/server/collections/es-report-data-views.ts +64 -0
- package/src/server/collections/es-reports.ts +80 -0
- package/src/server/index.ts +15 -0
- package/src/server/mcp/ElasticReportMcpServer.ts +391 -0
- package/src/server/mcp/ElasticReportToolCatalog.ts +663 -0
- package/src/server/plugin.ts +599 -0
- package/src/server/services/ElasticReportService.ts +486 -0
- package/src/server/services/ElasticsearchConnectionService.ts +728 -0
- package/src/server/services/ReportExportService.ts +282 -0
- package/src/server/services/ReportQueryCompiler.ts +1552 -0
- package/src/server/workflow/ElasticReportQueryInstruction.ts +124 -0
- package/src/shared/constants.ts +36 -0
- package/src/shared/types.ts +272 -0
- package/README.md +0 -3
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Context } from '@nocobase/actions';
|
|
11
|
+
import type { Application } from '@nocobase/server';
|
|
12
|
+
import {
|
|
13
|
+
DATA_VIEWS_COLLECTION,
|
|
14
|
+
MAX_MCP_PREVIEW_SIZE,
|
|
15
|
+
MAX_UI_PAGE_SIZE,
|
|
16
|
+
REPORTS_COLLECTION,
|
|
17
|
+
} from '../../shared/constants';
|
|
18
|
+
import type {
|
|
19
|
+
EsConnectionHealthResult,
|
|
20
|
+
EsConnectionSummary,
|
|
21
|
+
EsDataViewRecord,
|
|
22
|
+
EsFieldCapability,
|
|
23
|
+
EsReportRecord,
|
|
24
|
+
FieldTopValuesResult,
|
|
25
|
+
ID,
|
|
26
|
+
ReportExecutionResult,
|
|
27
|
+
ReportRuntimeOverrides,
|
|
28
|
+
RoleSummary,
|
|
29
|
+
} from '../../shared/types';
|
|
30
|
+
import { getEffectiveRoles, normalizeRoleList } from '../acl-guard';
|
|
31
|
+
import type { ElasticsearchConnectionService } from './ElasticsearchConnectionService';
|
|
32
|
+
import {
|
|
33
|
+
type ServerUserTokenContext,
|
|
34
|
+
buildFieldCapabilityMap,
|
|
35
|
+
compileKqlToQueryDsl,
|
|
36
|
+
compileSearchRequest,
|
|
37
|
+
normalizeReportSpec,
|
|
38
|
+
parseSearchResponse,
|
|
39
|
+
resolveAggregatableField,
|
|
40
|
+
} from './ReportQueryCompiler';
|
|
41
|
+
|
|
42
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
43
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function toPlainObject(modelOrRow: unknown): Record<string, unknown> {
|
|
47
|
+
if (isRecord(modelOrRow) && typeof modelOrRow.toJSON === 'function') {
|
|
48
|
+
const json = modelOrRow.toJSON();
|
|
49
|
+
return isRecord(json) ? json : {};
|
|
50
|
+
}
|
|
51
|
+
return isRecord(modelOrRow) ? modelOrRow : {};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function serializeDataView(row: unknown): EsDataViewRecord {
|
|
55
|
+
const plain = toPlainObject(row);
|
|
56
|
+
return {
|
|
57
|
+
id: (plain.id as ID) ?? '',
|
|
58
|
+
title: typeof plain.title === 'string' ? plain.title : '',
|
|
59
|
+
dataSourceKey: typeof plain.dataSourceKey === 'string' ? plain.dataSourceKey : '',
|
|
60
|
+
indexPattern: typeof plain.indexPattern === 'string' ? plain.indexPattern : '',
|
|
61
|
+
timeField: typeof plain.timeField === 'string' && plain.timeField.trim() ? plain.timeField.trim() : null,
|
|
62
|
+
description: typeof plain.description === 'string' ? plain.description : null,
|
|
63
|
+
allowedRoles: normalizeRoleList(plain.allowedRoles),
|
|
64
|
+
cachedFields: Array.isArray(plain.cachedFields) ? (plain.cachedFields as EsFieldCapability[]) : null,
|
|
65
|
+
...(typeof plain.createdAt === 'string' ? { createdAt: plain.createdAt } : {}),
|
|
66
|
+
...(typeof plain.updatedAt === 'string' ? { updatedAt: plain.updatedAt } : {}),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function serializeReport(row: unknown): EsReportRecord {
|
|
71
|
+
const plain = toPlainObject(row);
|
|
72
|
+
const spec = normalizeReportSpec(plain.spec, plain.visualization);
|
|
73
|
+
return {
|
|
74
|
+
id: (plain.id as ID) ?? '',
|
|
75
|
+
title: typeof plain.title === 'string' ? plain.title : '',
|
|
76
|
+
description: typeof plain.description === 'string' ? plain.description : null,
|
|
77
|
+
dataViewId: (plain.dataViewId as ID) ?? '',
|
|
78
|
+
dataView: isRecord(plain.dataView) ? serializeDataView(plain.dataView) : null,
|
|
79
|
+
visualization: spec.visualization,
|
|
80
|
+
spec,
|
|
81
|
+
published: plain.published !== false,
|
|
82
|
+
allowedRoles: normalizeRoleList(plain.allowedRoles),
|
|
83
|
+
...(typeof plain.createdAt === 'string' ? { createdAt: plain.createdAt } : {}),
|
|
84
|
+
...(typeof plain.updatedAt === 'string' ? { updatedAt: plain.updatedAt } : {}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface UpsertDataViewInput {
|
|
89
|
+
id?: ID;
|
|
90
|
+
title: string;
|
|
91
|
+
dataSourceKey: string;
|
|
92
|
+
indexPattern: string;
|
|
93
|
+
timeField?: string | null;
|
|
94
|
+
description?: string | null;
|
|
95
|
+
allowedRoles?: string[];
|
|
96
|
+
refreshFields?: boolean;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface SaveReportInput {
|
|
100
|
+
id?: ID;
|
|
101
|
+
title: string;
|
|
102
|
+
description?: string | null;
|
|
103
|
+
dataViewId: ID;
|
|
104
|
+
spec: unknown;
|
|
105
|
+
published?: boolean;
|
|
106
|
+
allowedRoles?: string[];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export class ElasticReportService {
|
|
110
|
+
constructor(
|
|
111
|
+
private readonly app: Application,
|
|
112
|
+
private readonly connections: ElasticsearchConnectionService,
|
|
113
|
+
) {}
|
|
114
|
+
|
|
115
|
+
async listConnections(): Promise<EsConnectionSummary[]> {
|
|
116
|
+
return this.connections.listConnections();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async testConnection(dataSourceKey: string, indexPattern = '*'): Promise<EsConnectionHealthResult> {
|
|
120
|
+
const client = await this.connections.getClient(dataSourceKey);
|
|
121
|
+
return client.testConnection(indexPattern);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async listAvailableRoles(): Promise<RoleSummary[]> {
|
|
125
|
+
if (!this.app.db.hasCollection('roles')) {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
const rows = await this.app.db.getRepository('roles').find({
|
|
129
|
+
sort: ['name'],
|
|
130
|
+
});
|
|
131
|
+
return rows
|
|
132
|
+
.map((row) => {
|
|
133
|
+
const plain = toPlainObject(row);
|
|
134
|
+
const name = typeof plain.name === 'string' ? plain.name.trim() : '';
|
|
135
|
+
const rawTitle = typeof plain.title === 'string' && plain.title.trim() ? plain.title.trim() : name;
|
|
136
|
+
const title = rawTitle.replace(/^\{\{\s*t\(\s*['"](.+?)['"]\s*\)\s*\}\}$/, '$1');
|
|
137
|
+
return { name, title };
|
|
138
|
+
})
|
|
139
|
+
.filter((r) => Boolean(r.name) && r.name !== 'anonymous');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async listIndices(dataSourceKey: string, indexPattern = '*'): Promise<string[]> {
|
|
143
|
+
const client = await this.connections.getClient(dataSourceKey);
|
|
144
|
+
return client.readIndices(indexPattern);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async listDataViews(): Promise<EsDataViewRecord[]> {
|
|
148
|
+
const repo = this.app.db.getRepository(DATA_VIEWS_COLLECTION);
|
|
149
|
+
const rows = await repo.find({ sort: ['-id'] });
|
|
150
|
+
return rows.map(serializeDataView);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async getDataView(dataViewId: ID): Promise<EsDataViewRecord> {
|
|
154
|
+
const repo = this.app.db.getRepository(DATA_VIEWS_COLLECTION);
|
|
155
|
+
const row = await repo.findOne({ filterByTk: dataViewId });
|
|
156
|
+
if (!row) {
|
|
157
|
+
throw new Error(`Data view "${String(dataViewId)}" was not found`);
|
|
158
|
+
}
|
|
159
|
+
return serializeDataView(row);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async inspectFieldsBySource(dataSourceKey: string, indexPattern: string): Promise<EsFieldCapability[]> {
|
|
163
|
+
const client = await this.connections.getClient(dataSourceKey);
|
|
164
|
+
return client.inspectFields(indexPattern);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async inspectDataViewFields(
|
|
168
|
+
dataViewId: ID,
|
|
169
|
+
refresh = false,
|
|
170
|
+
): Promise<{
|
|
171
|
+
dataView: EsDataViewRecord;
|
|
172
|
+
fields: EsFieldCapability[];
|
|
173
|
+
}> {
|
|
174
|
+
const dataView = await this.getDataView(dataViewId);
|
|
175
|
+
if (!refresh && Array.isArray(dataView.cachedFields) && dataView.cachedFields.length > 0) {
|
|
176
|
+
return { dataView, fields: dataView.cachedFields };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const fields = await this.inspectFieldsBySource(dataView.dataSourceKey, dataView.indexPattern);
|
|
180
|
+
const repo = this.app.db.getRepository(DATA_VIEWS_COLLECTION);
|
|
181
|
+
await repo.update({
|
|
182
|
+
filterByTk: dataView.id,
|
|
183
|
+
values: { cachedFields: fields },
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
dataView: { ...dataView, cachedFields: fields },
|
|
188
|
+
fields,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async upsertDataView(input: UpsertDataViewInput, userId?: ID): Promise<EsDataViewRecord> {
|
|
193
|
+
const title = input.title?.trim();
|
|
194
|
+
const dataSourceKey = input.dataSourceKey?.trim();
|
|
195
|
+
const indexPattern = input.indexPattern?.trim();
|
|
196
|
+
if (!title) throw new Error('Data view title is required');
|
|
197
|
+
if (!dataSourceKey) throw new Error('Elasticsearch dataSourceKey is required');
|
|
198
|
+
if (!indexPattern) throw new Error('Index pattern is required');
|
|
199
|
+
|
|
200
|
+
const fields = await this.inspectFieldsBySource(dataSourceKey, indexPattern);
|
|
201
|
+
let timeField = input.timeField?.trim() || null;
|
|
202
|
+
if (!timeField) {
|
|
203
|
+
const autoDate =
|
|
204
|
+
fields.find((f) => f.name === '@timestamp' && (f.type === 'date' || f.type === 'date_nanos')) ??
|
|
205
|
+
fields.find((f) => f.type === 'date' || f.type === 'date_nanos');
|
|
206
|
+
timeField = autoDate?.name ?? null;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const repo = this.app.db.getRepository(DATA_VIEWS_COLLECTION);
|
|
210
|
+
const values: Record<string, unknown> = {
|
|
211
|
+
title,
|
|
212
|
+
dataSourceKey,
|
|
213
|
+
indexPattern,
|
|
214
|
+
timeField,
|
|
215
|
+
description: input.description ?? null,
|
|
216
|
+
cachedFields: fields,
|
|
217
|
+
...(input.allowedRoles !== undefined ? { allowedRoles: normalizeRoleList(input.allowedRoles) } : {}),
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
if (input.id !== undefined && input.id !== null && String(input.id).trim() !== '') {
|
|
221
|
+
await repo.update({
|
|
222
|
+
filterByTk: input.id,
|
|
223
|
+
values,
|
|
224
|
+
});
|
|
225
|
+
return this.getDataView(input.id);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (values.allowedRoles === undefined) {
|
|
229
|
+
values.allowedRoles = [];
|
|
230
|
+
}
|
|
231
|
+
if (userId !== undefined) {
|
|
232
|
+
values.createdById = userId;
|
|
233
|
+
}
|
|
234
|
+
const created = await repo.create({ values });
|
|
235
|
+
return serializeDataView(created);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async listReports(options?: { publishedOnly?: boolean; search?: string }): Promise<EsReportRecord[]> {
|
|
239
|
+
const repo = this.app.db.getRepository(REPORTS_COLLECTION);
|
|
240
|
+
const filter: Record<string, unknown> = {};
|
|
241
|
+
if (options?.publishedOnly) {
|
|
242
|
+
filter.published = true;
|
|
243
|
+
}
|
|
244
|
+
if (options?.search?.trim()) {
|
|
245
|
+
filter.title = { $includes: options.search.trim() };
|
|
246
|
+
}
|
|
247
|
+
const rows = await repo.find({
|
|
248
|
+
filter,
|
|
249
|
+
appends: ['dataView'],
|
|
250
|
+
sort: ['-updatedAt', '-id'],
|
|
251
|
+
});
|
|
252
|
+
return rows.map(serializeReport);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
async getReport(reportId: ID): Promise<EsReportRecord> {
|
|
256
|
+
const repo = this.app.db.getRepository(REPORTS_COLLECTION);
|
|
257
|
+
const row = await repo.findOne({
|
|
258
|
+
filterByTk: reportId,
|
|
259
|
+
appends: ['dataView'],
|
|
260
|
+
});
|
|
261
|
+
if (!row) {
|
|
262
|
+
throw new Error(`Report "${String(reportId)}" was not found`);
|
|
263
|
+
}
|
|
264
|
+
return serializeReport(row);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async saveReport(input: SaveReportInput, userId?: ID): Promise<EsReportRecord> {
|
|
268
|
+
const title = input.title?.trim();
|
|
269
|
+
if (!title) {
|
|
270
|
+
throw new Error('Report title is required');
|
|
271
|
+
}
|
|
272
|
+
const dataView = await this.getDataView(input.dataViewId);
|
|
273
|
+
const spec = normalizeReportSpec(input.spec);
|
|
274
|
+
if (spec.queryMode !== 'simple' && spec.query && spec.query.trim()) {
|
|
275
|
+
compileKqlToQueryDsl(spec.query);
|
|
276
|
+
}
|
|
277
|
+
const repo = this.app.db.getRepository(REPORTS_COLLECTION);
|
|
278
|
+
|
|
279
|
+
const values: Record<string, unknown> = {
|
|
280
|
+
title,
|
|
281
|
+
description: input.description ?? null,
|
|
282
|
+
dataViewId: dataView.id,
|
|
283
|
+
visualization: spec.visualization,
|
|
284
|
+
spec,
|
|
285
|
+
published: input.published !== false,
|
|
286
|
+
...(input.allowedRoles !== undefined ? { allowedRoles: normalizeRoleList(input.allowedRoles) } : {}),
|
|
287
|
+
...(userId !== undefined ? { updatedById: userId } : {}),
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
if (input.id !== undefined && input.id !== null && String(input.id).trim() !== '') {
|
|
291
|
+
await repo.update({
|
|
292
|
+
filterByTk: input.id,
|
|
293
|
+
values,
|
|
294
|
+
});
|
|
295
|
+
return this.getReport(input.id);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (values.allowedRoles === undefined) {
|
|
299
|
+
values.allowedRoles = [];
|
|
300
|
+
}
|
|
301
|
+
if (userId !== undefined) {
|
|
302
|
+
values.createdById = userId;
|
|
303
|
+
}
|
|
304
|
+
const created = await repo.create({ values });
|
|
305
|
+
const plain = toPlainObject(created);
|
|
306
|
+
return this.getReport(plain.id as ID);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
async previewReport(params: {
|
|
310
|
+
dataViewId: ID;
|
|
311
|
+
spec: unknown;
|
|
312
|
+
overrides?: ReportRuntimeOverrides;
|
|
313
|
+
forMcp?: boolean;
|
|
314
|
+
userContext?: ServerUserTokenContext;
|
|
315
|
+
}): Promise<{
|
|
316
|
+
dataView: EsDataViewRecord;
|
|
317
|
+
result: ReportExecutionResult;
|
|
318
|
+
}> {
|
|
319
|
+
const { dataView, fields } = await this.inspectDataViewFields(params.dataViewId, false);
|
|
320
|
+
const normalizedSpec = normalizeReportSpec(params.spec);
|
|
321
|
+
const client = await this.connections.getClient(dataView.dataSourceKey);
|
|
322
|
+
|
|
323
|
+
let activePitId = params.overrides?.pitId;
|
|
324
|
+
const needsDeepCursor =
|
|
325
|
+
normalizedSpec.visualization === 'table' &&
|
|
326
|
+
!activePitId &&
|
|
327
|
+
((params.overrides?.page ?? 1) * (params.overrides?.pageSize ?? normalizedSpec.pageSize ?? 20) > 10000 ||
|
|
328
|
+
Boolean(params.overrides?.searchAfter));
|
|
329
|
+
|
|
330
|
+
if (needsDeepCursor && !params.overrides?.searchAfter) {
|
|
331
|
+
activePitId = (await client.openPit(dataView.indexPattern, '1m')) ?? undefined;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const { body, effectiveSpec } = compileSearchRequest({
|
|
335
|
+
spec: normalizedSpec,
|
|
336
|
+
overrides: params.overrides,
|
|
337
|
+
timeField: dataView.timeField,
|
|
338
|
+
fields,
|
|
339
|
+
maxRowsCap: params.forMcp ? MAX_MCP_PREVIEW_SIZE : MAX_UI_PAGE_SIZE,
|
|
340
|
+
userContext: params.userContext,
|
|
341
|
+
usePit: Boolean(activePitId),
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
const rawSearch = await client.search(
|
|
345
|
+
dataView.indexPattern,
|
|
346
|
+
body,
|
|
347
|
+
activePitId ? { pitId: activePitId } : undefined,
|
|
348
|
+
);
|
|
349
|
+
const result = parseSearchResponse(rawSearch, body, effectiveSpec, dataView.timeField);
|
|
350
|
+
if (activePitId && !result.pitId) {
|
|
351
|
+
result.pitId = activePitId;
|
|
352
|
+
}
|
|
353
|
+
return { dataView, result };
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
async runSavedReport(params: {
|
|
357
|
+
reportId: ID;
|
|
358
|
+
overrides?: ReportRuntimeOverrides;
|
|
359
|
+
requirePublished?: boolean;
|
|
360
|
+
forMcp?: boolean;
|
|
361
|
+
userContext?: ServerUserTokenContext;
|
|
362
|
+
}): Promise<{
|
|
363
|
+
report: EsReportRecord;
|
|
364
|
+
dataView: EsDataViewRecord;
|
|
365
|
+
result: ReportExecutionResult;
|
|
366
|
+
}> {
|
|
367
|
+
const report = await this.getReport(params.reportId);
|
|
368
|
+
if (params.requirePublished && !report.published) {
|
|
369
|
+
throw new Error(`Report "${report.title}" is not published`);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const runtimeOverrides: ReportRuntimeOverrides | undefined =
|
|
373
|
+
report.spec.allowInteractiveControls === false
|
|
374
|
+
? {
|
|
375
|
+
contextFilters: params.overrides?.contextFilters,
|
|
376
|
+
sharedFilters: params.overrides?.sharedFilters,
|
|
377
|
+
timeZone: params.overrides?.timeZone,
|
|
378
|
+
page: params.overrides?.page,
|
|
379
|
+
pageSize: params.overrides?.pageSize,
|
|
380
|
+
searchAfter: params.overrides?.searchAfter,
|
|
381
|
+
pitId: params.overrides?.pitId,
|
|
382
|
+
}
|
|
383
|
+
: params.overrides;
|
|
384
|
+
|
|
385
|
+
const { dataView, result } = await this.previewReport({
|
|
386
|
+
dataViewId: report.dataViewId,
|
|
387
|
+
spec: report.spec,
|
|
388
|
+
overrides: runtimeOverrides,
|
|
389
|
+
forMcp: params.forMcp,
|
|
390
|
+
userContext: params.userContext,
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
return { report, dataView, result };
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
async inspectFieldTopValues(params: {
|
|
397
|
+
dataViewId: ID;
|
|
398
|
+
reportId?: ID;
|
|
399
|
+
field: string;
|
|
400
|
+
size?: number;
|
|
401
|
+
overrides?: ReportRuntimeOverrides;
|
|
402
|
+
userContext?: ServerUserTokenContext;
|
|
403
|
+
}): Promise<FieldTopValuesResult> {
|
|
404
|
+
const rawField = params.field.trim();
|
|
405
|
+
if (!rawField) {
|
|
406
|
+
throw new Error('field is required');
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
let baseSpec = normalizeReportSpec({ visualization: 'bar' });
|
|
410
|
+
let targetDataViewId = params.dataViewId;
|
|
411
|
+
if (params.reportId !== undefined && params.reportId !== null && String(params.reportId).trim() !== '') {
|
|
412
|
+
const report = await this.getReport(params.reportId);
|
|
413
|
+
targetDataViewId = report.dataViewId;
|
|
414
|
+
baseSpec = report.spec;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const { dataView, fields } = await this.inspectDataViewFields(targetDataViewId, false);
|
|
418
|
+
const fieldMap = buildFieldCapabilityMap(fields);
|
|
419
|
+
const resolvedField = resolveAggregatableField(rawField, fieldMap);
|
|
420
|
+
const topSize = Math.max(1, Math.min(25, Math.trunc(params.size ?? 10)));
|
|
421
|
+
|
|
422
|
+
const probeSpec = normalizeReportSpec({
|
|
423
|
+
...baseSpec,
|
|
424
|
+
visualization: 'bar',
|
|
425
|
+
chart: {
|
|
426
|
+
bucketType: 'terms',
|
|
427
|
+
bucketField: resolvedField,
|
|
428
|
+
topN: topSize,
|
|
429
|
+
metricType: 'count',
|
|
430
|
+
},
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
const { body, effectiveSpec } = compileSearchRequest({
|
|
434
|
+
spec: probeSpec,
|
|
435
|
+
overrides: params.overrides,
|
|
436
|
+
timeField: dataView.timeField,
|
|
437
|
+
fields,
|
|
438
|
+
userContext: params.userContext,
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
const client = await this.connections.getClient(dataView.dataSourceKey);
|
|
442
|
+
const rawSearch = await client.search(dataView.indexPattern, body);
|
|
443
|
+
const parsed = parseSearchResponse(rawSearch, body, effectiveSpec, dataView.timeField);
|
|
444
|
+
const totalDocs = parsed.total;
|
|
445
|
+
|
|
446
|
+
return {
|
|
447
|
+
field: rawField,
|
|
448
|
+
resolvedField,
|
|
449
|
+
totalDocs,
|
|
450
|
+
buckets: parsed.series.map((pt) => ({
|
|
451
|
+
value: pt.label,
|
|
452
|
+
count: pt.count,
|
|
453
|
+
percentage: totalDocs > 0 ? Number(((pt.count / totalDocs) * 100).toFixed(1)) : 0,
|
|
454
|
+
})),
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export function extractCurrentUserId(ctx?: Partial<Context>): ID | undefined {
|
|
460
|
+
const stateUser = (ctx?.state as { currentUser?: { id?: ID } } | undefined)?.currentUser?.id;
|
|
461
|
+
if (stateUser !== undefined && stateUser !== null) return stateUser;
|
|
462
|
+
const authUser = (ctx?.auth as { user?: { id?: ID } } | undefined)?.user?.id;
|
|
463
|
+
if (authUser !== undefined && authUser !== null) return authUser;
|
|
464
|
+
return undefined;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
export function extractServerUserContext(ctx?: Partial<Context>): ServerUserTokenContext {
|
|
468
|
+
const stateUser = (
|
|
469
|
+
ctx?.state as
|
|
470
|
+
| {
|
|
471
|
+
currentUser?: {
|
|
472
|
+
id?: ID;
|
|
473
|
+
username?: string;
|
|
474
|
+
email?: string;
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
| undefined
|
|
478
|
+
)?.currentUser;
|
|
479
|
+
const effectiveRole = getEffectiveRoles(ctx)[0];
|
|
480
|
+
return {
|
|
481
|
+
userId: extractCurrentUserId(ctx),
|
|
482
|
+
...(typeof stateUser?.username === 'string' ? { username: stateUser.username } : {}),
|
|
483
|
+
...(typeof stateUser?.email === 'string' ? { email: stateUser.email } : {}),
|
|
484
|
+
...(effectiveRole ? { role: effectiveRole } : {}),
|
|
485
|
+
};
|
|
486
|
+
}
|