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,178 @@
|
|
|
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 { describe, expect, it } from 'vitest';
|
|
11
|
+
import { buildFieldCapabilityMap, compileKqlToQueryDsl } from '../../server/services/ReportQueryCompiler';
|
|
12
|
+
import type { EsFieldCapability } from '../../shared/types';
|
|
13
|
+
import {
|
|
14
|
+
type KqlSuggestionItem,
|
|
15
|
+
analyzeKqlCursorContext,
|
|
16
|
+
buildKqlSuggestions,
|
|
17
|
+
formatKqlValueLiteral,
|
|
18
|
+
} from '../utils/kqlAutocomplete';
|
|
19
|
+
|
|
20
|
+
const SAMPLE_FIELDS: EsFieldCapability[] = [
|
|
21
|
+
{ name: '@timestamp', type: 'date', searchable: true, aggregatable: true },
|
|
22
|
+
{ name: 'service', type: 'keyword', searchable: true, aggregatable: true },
|
|
23
|
+
{ name: 'service.keyword', type: 'keyword', searchable: true, aggregatable: true, isSubfield: true },
|
|
24
|
+
{ name: 'status', type: 'integer', searchable: true, aggregatable: true },
|
|
25
|
+
{ name: 'latency_ms', type: 'double', searchable: true, aggregatable: true },
|
|
26
|
+
{ name: 'published', type: 'boolean', searchable: true, aggregatable: true },
|
|
27
|
+
{ name: 'message', type: 'text', searchable: true, aggregatable: false },
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
const identityT = (k: string) => k;
|
|
31
|
+
|
|
32
|
+
function mustFind(items: KqlSuggestionItem[], token: string): KqlSuggestionItem {
|
|
33
|
+
const found = items.find((i) => i.displayToken === token);
|
|
34
|
+
if (!found) {
|
|
35
|
+
throw new Error(`Expected suggestion "${token}" in [${items.map((i) => i.displayToken).join(', ')}]`);
|
|
36
|
+
}
|
|
37
|
+
return found;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe('kqlAutocomplete', () => {
|
|
41
|
+
it('guides a beginner step-by-step from empty input through numeric, connector, keyword, and group clauses', () => {
|
|
42
|
+
const fieldMap = buildFieldCapabilityMap(SAMPLE_FIELDS);
|
|
43
|
+
|
|
44
|
+
// 1. Empty input -> primary fields (hiding .keyword subfield)
|
|
45
|
+
const step1 = buildKqlSuggestions({ input: '', fields: SAMPLE_FIELDS, t: identityT });
|
|
46
|
+
expect(step1.context.stage).toBe('field');
|
|
47
|
+
expect(step1.items.some((i) => i.displayToken === 'service')).toBe(true);
|
|
48
|
+
expect(step1.items.some((i) => i.displayToken === 'service.keyword')).toBe(false);
|
|
49
|
+
|
|
50
|
+
// Pick numeric field `status` -> inserts `status ` and enters `operator` stage
|
|
51
|
+
const pickStatus = mustFind(step1.items, 'status');
|
|
52
|
+
expect(pickStatus.nextQuery).toBe('status ');
|
|
53
|
+
|
|
54
|
+
// 2. Operator stage for `status `
|
|
55
|
+
const step2 = buildKqlSuggestions({ input: pickStatus.nextQuery, fields: SAMPLE_FIELDS, t: identityT });
|
|
56
|
+
expect(step2.context.stage).toBe('operator');
|
|
57
|
+
const pickGte = mustFind(step2.items, 'status >=');
|
|
58
|
+
expect(pickGte.nextQuery).toBe('status >= ');
|
|
59
|
+
|
|
60
|
+
// 3. Value stage for `status >= ` with real top values
|
|
61
|
+
const step3 = buildKqlSuggestions({
|
|
62
|
+
input: pickGte.nextQuery,
|
|
63
|
+
fields: SAMPLE_FIELDS,
|
|
64
|
+
topValueBuckets: [
|
|
65
|
+
{ value: '500', count: 42 },
|
|
66
|
+
{ value: '404', count: 15 },
|
|
67
|
+
],
|
|
68
|
+
t: identityT,
|
|
69
|
+
});
|
|
70
|
+
expect(step3.context.stage).toBe('value');
|
|
71
|
+
const pick500 = mustFind(step3.items, '500');
|
|
72
|
+
expect(pick500.nextQuery).toBe('status >= 500 ');
|
|
73
|
+
|
|
74
|
+
// 4. Connector stage after completed clause `status >= 500 `
|
|
75
|
+
const step4 = buildKqlSuggestions({ input: pick500.nextQuery, fields: SAMPLE_FIELDS, t: identityT });
|
|
76
|
+
expect(step4.context.stage).toBe('connector');
|
|
77
|
+
const pickAnd = mustFind(step4.items, 'AND');
|
|
78
|
+
expect(pickAnd.nextQuery).toBe('status >= 500 AND ');
|
|
79
|
+
|
|
80
|
+
// 5. Pick keyword field `service` -> jumps straight to `service: `
|
|
81
|
+
const step5 = buildKqlSuggestions({ input: pickAnd.nextQuery, fields: SAMPLE_FIELDS, t: identityT });
|
|
82
|
+
const pickService = mustFind(step5.items, 'service');
|
|
83
|
+
expect(pickService.nextQuery).toBe('status >= 500 AND service: ');
|
|
84
|
+
|
|
85
|
+
// 6. Pick multi-value group `(` -> `status >= 500 AND service: (`
|
|
86
|
+
const step6 = buildKqlSuggestions({
|
|
87
|
+
input: pickService.nextQuery,
|
|
88
|
+
fields: SAMPLE_FIELDS,
|
|
89
|
+
topValueBuckets: [
|
|
90
|
+
{ value: 'api gateway', count: 30 },
|
|
91
|
+
{ value: 'auth:v2', count: 12 },
|
|
92
|
+
],
|
|
93
|
+
t: identityT,
|
|
94
|
+
});
|
|
95
|
+
const pickGroup = mustFind(step6.items, '(');
|
|
96
|
+
expect(pickGroup.nextQuery).toBe('status >= 500 AND service: (');
|
|
97
|
+
|
|
98
|
+
// 7. Inside group, pick value containing space -> quoted safely
|
|
99
|
+
const step7 = buildKqlSuggestions({
|
|
100
|
+
input: pickGroup.nextQuery,
|
|
101
|
+
fields: SAMPLE_FIELDS,
|
|
102
|
+
topValueBuckets: [
|
|
103
|
+
{ value: 'api gateway', count: 30 },
|
|
104
|
+
{ value: 'auth:v2', count: 12 },
|
|
105
|
+
],
|
|
106
|
+
t: identityT,
|
|
107
|
+
});
|
|
108
|
+
expect(step7.context.insideFieldGroup).toBe(true);
|
|
109
|
+
const pickFirstGroupVal = mustFind(step7.items, '"api gateway"');
|
|
110
|
+
expect(pickFirstGroupVal.nextQuery).toBe('status >= 500 AND service: ("api gateway" ');
|
|
111
|
+
|
|
112
|
+
// 8. Group connector -> `OR ` -> second value with colon -> close `)`
|
|
113
|
+
const step8 = buildKqlSuggestions({ input: pickFirstGroupVal.nextQuery, fields: SAMPLE_FIELDS, t: identityT });
|
|
114
|
+
expect(step8.context.stage).toBe('group_connector');
|
|
115
|
+
const pickGroupOr = mustFind(step8.items, 'OR');
|
|
116
|
+
const step9 = buildKqlSuggestions({
|
|
117
|
+
input: pickGroupOr.nextQuery,
|
|
118
|
+
fields: SAMPLE_FIELDS,
|
|
119
|
+
topValueBuckets: [{ value: 'auth:v2', count: 12 }],
|
|
120
|
+
t: identityT,
|
|
121
|
+
});
|
|
122
|
+
const pickSecondGroupVal = mustFind(step9.items, '"auth:v2"');
|
|
123
|
+
const step10 = buildKqlSuggestions({ input: pickSecondGroupVal.nextQuery, fields: SAMPLE_FIELDS, t: identityT });
|
|
124
|
+
const pickCloseGroup = mustFind(step10.items, ')');
|
|
125
|
+
expect(pickCloseGroup.nextQuery).toBe('status >= 500 AND service: ("api gateway" OR "auth:v2") ');
|
|
126
|
+
|
|
127
|
+
// Resulting KQL must compile cleanly through ReportQueryCompiler without syntax errors
|
|
128
|
+
const compiled = compileKqlToQueryDsl(pickCloseGroup.nextQuery, fieldMap);
|
|
129
|
+
expect(compiled).toEqual({
|
|
130
|
+
bool: {
|
|
131
|
+
must: [
|
|
132
|
+
{ range: { status: { gte: 500 } } },
|
|
133
|
+
{
|
|
134
|
+
bool: {
|
|
135
|
+
should: [{ term: { service: 'api gateway' } }, { term: { service: 'auth:v2' } }],
|
|
136
|
+
minimum_should_match: 1,
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('auto-inserts AND when user starts typing a new field after a completed clause without a boolean connector', () => {
|
|
145
|
+
const res = buildKqlSuggestions({
|
|
146
|
+
input: 'status >= 500 ser',
|
|
147
|
+
fields: SAMPLE_FIELDS,
|
|
148
|
+
t: identityT,
|
|
149
|
+
});
|
|
150
|
+
expect(res.context.stage).toBe('connector');
|
|
151
|
+
expect(res.context.needsLeadingAnd).toBe(true);
|
|
152
|
+
const autoAndService = mustFind(res.items, 'AND service');
|
|
153
|
+
expect(autoAndService.nextQuery).toBe('status >= 500 AND service: ');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('consumes adjacent closing quote when editing inside an existing quoted value and formats literals safely', () => {
|
|
157
|
+
const input = 'service: "gat" AND status >= 400';
|
|
158
|
+
// Cursor right after `gat` (index 13, before closing `"`)
|
|
159
|
+
const ctx = analyzeKqlCursorContext(input, 13, SAMPLE_FIELDS);
|
|
160
|
+
expect(ctx.stage).toBe('value');
|
|
161
|
+
expect(ctx.field).toBe('service');
|
|
162
|
+
expect(ctx.partial).toBe('gat');
|
|
163
|
+
|
|
164
|
+
const res = buildKqlSuggestions({
|
|
165
|
+
input,
|
|
166
|
+
cursorPos: 13,
|
|
167
|
+
fields: SAMPLE_FIELDS,
|
|
168
|
+
topValueBuckets: [{ value: 'gateway', count: 10 }],
|
|
169
|
+
t: identityT,
|
|
170
|
+
});
|
|
171
|
+
const pickGateway = mustFind(res.items, '"gateway"');
|
|
172
|
+
expect(pickGateway.nextQuery).toBe('service: "gateway" AND status >= 400');
|
|
173
|
+
|
|
174
|
+
expect(formatKqlValueLiteral('true', SAMPLE_FIELDS[5])).toBe('true');
|
|
175
|
+
expect(formatKqlValueLiteral('250.5', SAMPLE_FIELDS[4])).toBe('250.5');
|
|
176
|
+
expect(formatKqlValueLiteral('say "hi"', SAMPLE_FIELDS[1])).toBe('"say \\"hi\\""');
|
|
177
|
+
});
|
|
178
|
+
});
|
|
@@ -0,0 +1,320 @@
|
|
|
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 { DATA_VIEWS_COLLECTION, REPORTS_COLLECTION, SERVICE_RESOURCE } from '../shared/constants';
|
|
11
|
+
import type {
|
|
12
|
+
EsConnectionHealthResult,
|
|
13
|
+
EsConnectionSummary,
|
|
14
|
+
EsDataViewRecord,
|
|
15
|
+
EsFieldCapability,
|
|
16
|
+
EsReportRecord,
|
|
17
|
+
ExportFormat,
|
|
18
|
+
FieldTopValuesResult,
|
|
19
|
+
ID,
|
|
20
|
+
ReportExecutionResult,
|
|
21
|
+
ReportRuntimeOverrides,
|
|
22
|
+
ReportSpec,
|
|
23
|
+
RoleSummary,
|
|
24
|
+
} from '../shared/types';
|
|
25
|
+
|
|
26
|
+
export interface ApiClientLike {
|
|
27
|
+
request: (config: {
|
|
28
|
+
url: string;
|
|
29
|
+
method?: 'get' | 'post';
|
|
30
|
+
params?: Record<string, unknown>;
|
|
31
|
+
data?: Record<string, unknown>;
|
|
32
|
+
responseType?: 'blob' | 'text' | 'json';
|
|
33
|
+
}) => Promise<unknown>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface McpInfoPayload {
|
|
37
|
+
serverName: string;
|
|
38
|
+
endpointPath: string;
|
|
39
|
+
internalUrl: string;
|
|
40
|
+
useUserContext: boolean;
|
|
41
|
+
tools: Array<{
|
|
42
|
+
name: string;
|
|
43
|
+
description: string;
|
|
44
|
+
inputSchema: Record<string, unknown>;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
49
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function unwrapApiData<T>(raw: unknown): T {
|
|
53
|
+
if (!isRecord(raw)) return raw as T;
|
|
54
|
+
const outer = raw.data;
|
|
55
|
+
if (isRecord(outer) && 'data' in outer) {
|
|
56
|
+
return outer.data as T;
|
|
57
|
+
}
|
|
58
|
+
return (outer ?? raw) as T;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function fetchEsConnections(api: ApiClientLike): Promise<EsConnectionSummary[]> {
|
|
62
|
+
const res = await api.request({
|
|
63
|
+
url: `${SERVICE_RESOURCE}:listConnections`,
|
|
64
|
+
method: 'get',
|
|
65
|
+
});
|
|
66
|
+
const data = unwrapApiData<unknown>(res);
|
|
67
|
+
return Array.isArray(data) ? (data as EsConnectionSummary[]) : [];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function testEsConnection(
|
|
71
|
+
api: ApiClientLike,
|
|
72
|
+
dataSourceKey: string,
|
|
73
|
+
indexPattern = '*',
|
|
74
|
+
): Promise<EsConnectionHealthResult> {
|
|
75
|
+
const res = await api.request({
|
|
76
|
+
url: `${SERVICE_RESOURCE}:testConnection`,
|
|
77
|
+
method: 'post',
|
|
78
|
+
data: { dataSourceKey, indexPattern },
|
|
79
|
+
});
|
|
80
|
+
return unwrapApiData<EsConnectionHealthResult>(res);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export async function fetchAvailableRoles(api: ApiClientLike): Promise<RoleSummary[]> {
|
|
84
|
+
const res = await api.request({
|
|
85
|
+
url: `${SERVICE_RESOURCE}:listRoles`,
|
|
86
|
+
method: 'get',
|
|
87
|
+
});
|
|
88
|
+
const data = unwrapApiData<unknown>(res);
|
|
89
|
+
return Array.isArray(data) ? (data as RoleSummary[]) : [];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export async function fetchEsIndices(api: ApiClientLike, dataSourceKey: string, indexPattern = '*'): Promise<string[]> {
|
|
93
|
+
const res = await api.request({
|
|
94
|
+
url: `${SERVICE_RESOURCE}:listIndices`,
|
|
95
|
+
method: 'post',
|
|
96
|
+
data: { dataSourceKey, indexPattern },
|
|
97
|
+
});
|
|
98
|
+
const data = unwrapApiData<unknown>(res);
|
|
99
|
+
return Array.isArray(data) ? data.filter((v): v is string => typeof v === 'string') : [];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export async function fetchDataViews(api: ApiClientLike): Promise<EsDataViewRecord[]> {
|
|
103
|
+
const res = await api.request({
|
|
104
|
+
url: `${DATA_VIEWS_COLLECTION}:list`,
|
|
105
|
+
method: 'get',
|
|
106
|
+
params: { pageSize: 200, sort: ['-id'] },
|
|
107
|
+
});
|
|
108
|
+
const data = unwrapApiData<unknown>(res);
|
|
109
|
+
return Array.isArray(data) ? (data as EsDataViewRecord[]) : [];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export async function saveDataView(
|
|
113
|
+
api: ApiClientLike,
|
|
114
|
+
payload: {
|
|
115
|
+
id?: ID;
|
|
116
|
+
title: string;
|
|
117
|
+
dataSourceKey: string;
|
|
118
|
+
indexPattern: string;
|
|
119
|
+
timeField?: string | null;
|
|
120
|
+
description?: string | null;
|
|
121
|
+
allowedRoles?: string[];
|
|
122
|
+
},
|
|
123
|
+
): Promise<EsDataViewRecord> {
|
|
124
|
+
const res = await api.request({
|
|
125
|
+
url: `${SERVICE_RESOURCE}:upsertDataView`,
|
|
126
|
+
method: 'post',
|
|
127
|
+
data: payload as Record<string, unknown>,
|
|
128
|
+
});
|
|
129
|
+
return unwrapApiData<EsDataViewRecord>(res);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export async function removeDataView(api: ApiClientLike, id: ID): Promise<void> {
|
|
133
|
+
await api.request({
|
|
134
|
+
url: `${DATA_VIEWS_COLLECTION}:destroy`,
|
|
135
|
+
method: 'post',
|
|
136
|
+
params: { filterByTk: id },
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export async function fetchDataViewFields(
|
|
141
|
+
api: ApiClientLike,
|
|
142
|
+
dataViewId: ID,
|
|
143
|
+
refresh = false,
|
|
144
|
+
): Promise<{ dataView: EsDataViewRecord; fields: EsFieldCapability[] }> {
|
|
145
|
+
const res = await api.request({
|
|
146
|
+
url: `${SERVICE_RESOURCE}:inspectFields`,
|
|
147
|
+
method: 'post',
|
|
148
|
+
data: { dataViewId, refresh },
|
|
149
|
+
});
|
|
150
|
+
return unwrapApiData<{ dataView: EsDataViewRecord; fields: EsFieldCapability[] }>(res);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export async function fetchAllReports(api: ApiClientLike): Promise<EsReportRecord[]> {
|
|
154
|
+
const res = await api.request({
|
|
155
|
+
url: `${REPORTS_COLLECTION}:list`,
|
|
156
|
+
method: 'get',
|
|
157
|
+
params: { pageSize: 200, appends: ['dataView'], sort: ['-updatedAt', '-id'] },
|
|
158
|
+
});
|
|
159
|
+
const data = unwrapApiData<unknown>(res);
|
|
160
|
+
return Array.isArray(data) ? (data as EsReportRecord[]) : [];
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export async function fetchPublishedReports(api: ApiClientLike, search?: string): Promise<EsReportRecord[]> {
|
|
164
|
+
const res = await api.request({
|
|
165
|
+
url: `${SERVICE_RESOURCE}:listPublishedReports`,
|
|
166
|
+
method: 'get',
|
|
167
|
+
params: search ? { search } : undefined,
|
|
168
|
+
});
|
|
169
|
+
const data = unwrapApiData<unknown>(res);
|
|
170
|
+
return Array.isArray(data) ? (data as EsReportRecord[]) : [];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export async function persistReport(
|
|
174
|
+
api: ApiClientLike,
|
|
175
|
+
payload: {
|
|
176
|
+
id?: ID;
|
|
177
|
+
title: string;
|
|
178
|
+
description?: string | null;
|
|
179
|
+
dataViewId: ID;
|
|
180
|
+
spec: ReportSpec;
|
|
181
|
+
published: boolean;
|
|
182
|
+
allowedRoles?: string[];
|
|
183
|
+
},
|
|
184
|
+
): Promise<EsReportRecord> {
|
|
185
|
+
const res = await api.request({
|
|
186
|
+
url: `${SERVICE_RESOURCE}:saveReport`,
|
|
187
|
+
method: 'post',
|
|
188
|
+
data: payload as unknown as Record<string, unknown>,
|
|
189
|
+
});
|
|
190
|
+
return unwrapApiData<EsReportRecord>(res);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export async function removeReport(api: ApiClientLike, id: ID): Promise<void> {
|
|
194
|
+
await api.request({
|
|
195
|
+
url: `${REPORTS_COLLECTION}:destroy`,
|
|
196
|
+
method: 'post',
|
|
197
|
+
params: { filterByTk: id },
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export async function executeReportPreview(
|
|
202
|
+
api: ApiClientLike,
|
|
203
|
+
dataViewId: ID,
|
|
204
|
+
spec: ReportSpec,
|
|
205
|
+
overrides?: ReportRuntimeOverrides,
|
|
206
|
+
): Promise<{ dataView: EsDataViewRecord; result: ReportExecutionResult }> {
|
|
207
|
+
const res = await api.request({
|
|
208
|
+
url: `${SERVICE_RESOURCE}:previewReport`,
|
|
209
|
+
method: 'post',
|
|
210
|
+
data: {
|
|
211
|
+
dataViewId,
|
|
212
|
+
spec,
|
|
213
|
+
...(overrides ? { overrides } : {}),
|
|
214
|
+
} as unknown as Record<string, unknown>,
|
|
215
|
+
});
|
|
216
|
+
return unwrapApiData<{ dataView: EsDataViewRecord; result: ReportExecutionResult }>(res);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export async function fetchReportMeta(
|
|
220
|
+
api: ApiClientLike,
|
|
221
|
+
reportId: ID,
|
|
222
|
+
): Promise<{ report: EsReportRecord; dataView: EsDataViewRecord; fields: EsFieldCapability[] }> {
|
|
223
|
+
const res = await api.request({
|
|
224
|
+
url: `${SERVICE_RESOURCE}:getReportMeta`,
|
|
225
|
+
method: 'get',
|
|
226
|
+
params: { reportId },
|
|
227
|
+
});
|
|
228
|
+
return unwrapApiData<{ report: EsReportRecord; dataView: EsDataViewRecord; fields: EsFieldCapability[] }>(res);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export async function executeSavedReport(
|
|
232
|
+
api: ApiClientLike,
|
|
233
|
+
reportId: ID,
|
|
234
|
+
overrides?: ReportRuntimeOverrides,
|
|
235
|
+
): Promise<{ report: EsReportRecord; dataView: EsDataViewRecord; result: ReportExecutionResult }> {
|
|
236
|
+
const res = await api.request({
|
|
237
|
+
url: `${SERVICE_RESOURCE}:runReport`,
|
|
238
|
+
method: 'post',
|
|
239
|
+
data: {
|
|
240
|
+
reportId,
|
|
241
|
+
...(overrides ? { overrides } : {}),
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
return unwrapApiData<{ report: EsReportRecord; dataView: EsDataViewRecord; result: ReportExecutionResult }>(res);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export async function fetchMcpInfo(api: ApiClientLike): Promise<McpInfoPayload> {
|
|
248
|
+
const res = await api.request({
|
|
249
|
+
url: `${SERVICE_RESOURCE}:getMcpInfo`,
|
|
250
|
+
method: 'get',
|
|
251
|
+
});
|
|
252
|
+
return unwrapApiData<McpInfoPayload>(res);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export async function fetchFieldTopValues(
|
|
256
|
+
api: ApiClientLike,
|
|
257
|
+
params: {
|
|
258
|
+
dataViewId?: ID;
|
|
259
|
+
reportId?: ID;
|
|
260
|
+
field: string;
|
|
261
|
+
size?: number;
|
|
262
|
+
overrides?: ReportRuntimeOverrides;
|
|
263
|
+
},
|
|
264
|
+
): Promise<FieldTopValuesResult> {
|
|
265
|
+
const res = await api.request({
|
|
266
|
+
url: `${SERVICE_RESOURCE}:inspectTopValues`,
|
|
267
|
+
method: 'post',
|
|
268
|
+
data: params as unknown as Record<string, unknown>,
|
|
269
|
+
});
|
|
270
|
+
return unwrapApiData<FieldTopValuesResult>(res);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export async function downloadReportExport(
|
|
274
|
+
api: ApiClientLike,
|
|
275
|
+
params: {
|
|
276
|
+
reportId: ID;
|
|
277
|
+
reportTitle?: string;
|
|
278
|
+
format: ExportFormat;
|
|
279
|
+
overrides?: ReportRuntimeOverrides;
|
|
280
|
+
columns?: string[];
|
|
281
|
+
},
|
|
282
|
+
): Promise<void> {
|
|
283
|
+
const res = await api.request({
|
|
284
|
+
url: `${SERVICE_RESOURCE}:exportReport`,
|
|
285
|
+
method: 'post',
|
|
286
|
+
responseType: 'blob',
|
|
287
|
+
data: {
|
|
288
|
+
reportId: params.reportId,
|
|
289
|
+
format: params.format,
|
|
290
|
+
...(params.overrides ? { overrides: params.overrides } : {}),
|
|
291
|
+
...(params.columns && params.columns.length > 0 ? { columns: params.columns } : {}),
|
|
292
|
+
},
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
const rawPayload = isRecord(res) && 'data' in res ? res.data : res;
|
|
296
|
+
const mime = params.format === 'ndjson' ? 'application/x-ndjson;charset=utf-8' : 'text/csv;charset=utf-8';
|
|
297
|
+
const blob =
|
|
298
|
+
typeof Blob !== 'undefined' && rawPayload instanceof Blob
|
|
299
|
+
? rawPayload
|
|
300
|
+
: new Blob([typeof rawPayload === 'string' ? rawPayload : JSON.stringify(rawPayload ?? '')], { type: mime });
|
|
301
|
+
|
|
302
|
+
if (typeof window === 'undefined' || typeof document === 'undefined' || typeof URL.createObjectURL !== 'function') {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const slug =
|
|
307
|
+
(params.reportTitle || `report-${String(params.reportId)}`)
|
|
308
|
+
.toLowerCase()
|
|
309
|
+
.replace(/[^a-z0-9_-]+/g, '-')
|
|
310
|
+
.replace(/^-+|-+$/g, '')
|
|
311
|
+
.slice(0, 48) || 'report';
|
|
312
|
+
const objectUrl = URL.createObjectURL(blob);
|
|
313
|
+
const anchor = document.createElement('a');
|
|
314
|
+
anchor.href = objectUrl;
|
|
315
|
+
anchor.download = `${slug}.${params.format}`;
|
|
316
|
+
document.body.appendChild(anchor);
|
|
317
|
+
anchor.click();
|
|
318
|
+
document.body.removeChild(anchor);
|
|
319
|
+
URL.revokeObjectURL(objectUrl);
|
|
320
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
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 { useCallback, useSyncExternalStore } from 'react';
|
|
11
|
+
import type {
|
|
12
|
+
AutoRefreshInterval,
|
|
13
|
+
RecordContextBinding,
|
|
14
|
+
ReportFilterItem,
|
|
15
|
+
ReportTimeRange,
|
|
16
|
+
ScalarFilterValue,
|
|
17
|
+
SharedDashboardState,
|
|
18
|
+
} from '../../shared/types';
|
|
19
|
+
|
|
20
|
+
interface FlowModelNodeLike {
|
|
21
|
+
uid?: string;
|
|
22
|
+
parent?: unknown;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const EMPTY_DASHBOARD_STATE: SharedDashboardState = Object.freeze({
|
|
26
|
+
filters: [],
|
|
27
|
+
refreshTick: 0,
|
|
28
|
+
updatedAt: 0,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const scopes = new Map<string, SharedDashboardState>();
|
|
32
|
+
const listenersByScope = new Map<string, Set<() => void>>();
|
|
33
|
+
|
|
34
|
+
function notifyScope(scopeKey: string): void {
|
|
35
|
+
const listeners = listenersByScope.get(scopeKey);
|
|
36
|
+
if (!listeners) return;
|
|
37
|
+
for (const listener of listeners) {
|
|
38
|
+
listener();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function resolveFlowRootScopeId(model?: FlowModelNodeLike, syncGroup?: string): string {
|
|
43
|
+
let rootUid = '';
|
|
44
|
+
let current: unknown = model;
|
|
45
|
+
let guard = 0;
|
|
46
|
+
while (current && typeof current === 'object' && guard < 32) {
|
|
47
|
+
const node = current as FlowModelNodeLike;
|
|
48
|
+
if (typeof node.uid === 'string' && node.uid) {
|
|
49
|
+
rootUid = node.uid;
|
|
50
|
+
}
|
|
51
|
+
if (!node.parent) {
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
current = node.parent;
|
|
55
|
+
guard++;
|
|
56
|
+
}
|
|
57
|
+
const baseScope = rootUid || (typeof window !== 'undefined' ? window.location.pathname : 'default-page');
|
|
58
|
+
const cleanGroup = syncGroup?.trim();
|
|
59
|
+
return cleanGroup ? `${baseScope}:${cleanGroup}` : baseScope;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function getDashboardScopeState(scopeKey: string): SharedDashboardState {
|
|
63
|
+
return scopes.get(scopeKey) ?? EMPTY_DASHBOARD_STATE;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function patchDashboardScope(
|
|
67
|
+
scopeKey: string,
|
|
68
|
+
patch: {
|
|
69
|
+
query?: string;
|
|
70
|
+
timeRange?: ReportTimeRange;
|
|
71
|
+
filters?: ReportFilterItem[];
|
|
72
|
+
autoRefreshSec?: AutoRefreshInterval;
|
|
73
|
+
},
|
|
74
|
+
): void {
|
|
75
|
+
if (!scopeKey) return;
|
|
76
|
+
const prev = getDashboardScopeState(scopeKey);
|
|
77
|
+
const next: SharedDashboardState = {
|
|
78
|
+
...prev,
|
|
79
|
+
...(patch.query !== undefined ? { query: patch.query } : {}),
|
|
80
|
+
...(patch.timeRange !== undefined ? { timeRange: patch.timeRange } : {}),
|
|
81
|
+
...(patch.filters !== undefined ? { filters: patch.filters } : {}),
|
|
82
|
+
...(patch.autoRefreshSec !== undefined ? { autoRefreshSec: patch.autoRefreshSec } : {}),
|
|
83
|
+
updatedAt: Date.now(),
|
|
84
|
+
};
|
|
85
|
+
scopes.set(scopeKey, next);
|
|
86
|
+
notifyScope(scopeKey);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function upsertDashboardFilter(scopeKey: string, item: ReportFilterItem): void {
|
|
90
|
+
if (!scopeKey) return;
|
|
91
|
+
const prev = getDashboardScopeState(scopeKey);
|
|
92
|
+
const existingIdx = prev.filters.findIndex((f) => f.field === item.field && f.operator === item.operator);
|
|
93
|
+
const withId: ReportFilterItem = {
|
|
94
|
+
...item,
|
|
95
|
+
id: item.id ?? `shared-${Date.now()}`,
|
|
96
|
+
enabled: true,
|
|
97
|
+
};
|
|
98
|
+
const nextFilters =
|
|
99
|
+
existingIdx >= 0 ? prev.filters.map((f, idx) => (idx === existingIdx ? withId : f)) : [...prev.filters, withId];
|
|
100
|
+
patchDashboardScope(scopeKey, { filters: nextFilters });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function removeDashboardFilterByField(scopeKey: string, field: string): void {
|
|
104
|
+
if (!scopeKey) return;
|
|
105
|
+
const prev = getDashboardScopeState(scopeKey);
|
|
106
|
+
patchDashboardScope(scopeKey, {
|
|
107
|
+
filters: prev.filters.filter((f) => f.field !== field),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function removeDashboardFilterAt(scopeKey: string, index: number): void {
|
|
112
|
+
if (!scopeKey) return;
|
|
113
|
+
const prev = getDashboardScopeState(scopeKey);
|
|
114
|
+
patchDashboardScope(scopeKey, {
|
|
115
|
+
filters: prev.filters.filter((_, idx) => idx !== index),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function triggerDashboardRefresh(scopeKey: string): void {
|
|
120
|
+
if (!scopeKey) return;
|
|
121
|
+
const prev = getDashboardScopeState(scopeKey);
|
|
122
|
+
scopes.set(scopeKey, {
|
|
123
|
+
...prev,
|
|
124
|
+
refreshTick: prev.refreshTick + 1,
|
|
125
|
+
updatedAt: Date.now(),
|
|
126
|
+
});
|
|
127
|
+
notifyScope(scopeKey);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function clearDashboardScope(scopeKey: string): void {
|
|
131
|
+
if (!scopeKey) return;
|
|
132
|
+
const prev = getDashboardScopeState(scopeKey);
|
|
133
|
+
scopes.set(scopeKey, {
|
|
134
|
+
filters: [],
|
|
135
|
+
refreshTick: prev.refreshTick + 1,
|
|
136
|
+
updatedAt: Date.now(),
|
|
137
|
+
});
|
|
138
|
+
notifyScope(scopeKey);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function useDashboardScope(scopeKey?: string | null): SharedDashboardState {
|
|
142
|
+
const subscribe = useCallback(
|
|
143
|
+
(onStoreChange: () => void) => {
|
|
144
|
+
if (!scopeKey) {
|
|
145
|
+
return () => undefined;
|
|
146
|
+
}
|
|
147
|
+
let set = listenersByScope.get(scopeKey);
|
|
148
|
+
if (!set) {
|
|
149
|
+
set = new Set();
|
|
150
|
+
listenersByScope.set(scopeKey, set);
|
|
151
|
+
}
|
|
152
|
+
set.add(onStoreChange);
|
|
153
|
+
return () => {
|
|
154
|
+
set?.delete(onStoreChange);
|
|
155
|
+
};
|
|
156
|
+
},
|
|
157
|
+
[scopeKey],
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
const getSnapshot = useCallback(
|
|
161
|
+
() => (scopeKey ? getDashboardScopeState(scopeKey) : EMPTY_DASHBOARD_STATE),
|
|
162
|
+
[scopeKey],
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function readNestedScalar(record: unknown, path: string): ScalarFilterValue | undefined {
|
|
169
|
+
if (!record || typeof record !== 'object') return undefined;
|
|
170
|
+
const parts = path.split('.').filter(Boolean);
|
|
171
|
+
let cur: unknown = record;
|
|
172
|
+
for (const part of parts) {
|
|
173
|
+
if (cur && typeof cur === 'object' && !Array.isArray(cur) && part in (cur as Record<string, unknown>)) {
|
|
174
|
+
cur = (cur as Record<string, unknown>)[part];
|
|
175
|
+
} else {
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (typeof cur === 'string' && cur.trim()) return cur.trim();
|
|
180
|
+
if (typeof cur === 'number' && Number.isFinite(cur)) return cur;
|
|
181
|
+
if (typeof cur === 'boolean') return cur;
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function buildRecordContextFilters(
|
|
186
|
+
bindings: RecordContextBinding[] | undefined,
|
|
187
|
+
record: unknown,
|
|
188
|
+
): ReportFilterItem[] {
|
|
189
|
+
if (!bindings || bindings.length === 0 || !record) return [];
|
|
190
|
+
const items: ReportFilterItem[] = [];
|
|
191
|
+
for (const binding of bindings) {
|
|
192
|
+
const val = readNestedScalar(record, binding.recordFieldPath);
|
|
193
|
+
if (val !== undefined) {
|
|
194
|
+
items.push({
|
|
195
|
+
id: `ctx-${binding.esField}`,
|
|
196
|
+
field: binding.esField,
|
|
197
|
+
operator: 'eq',
|
|
198
|
+
value: val,
|
|
199
|
+
enabled: true,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return items;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function detectBrowserTimeZone(): string | undefined {
|
|
207
|
+
try {
|
|
208
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone || undefined;
|
|
209
|
+
} catch {
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
}
|