plugin-elastic-report 0.7.0 → 0.9.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.
Files changed (70) hide show
  1. package/client-v2.d.ts +2 -2
  2. package/client-v2.js +1 -1
  3. package/client.d.ts +2 -2
  4. package/client.js +1 -1
  5. package/{ai → dist/ai}/skills/elastic-report/SKILLS.md +52 -34
  6. package/dist/client-v2/851.35e416bfb3fb565f.js +10 -0
  7. package/dist/client-v2/877.81b10beb7b7f4bd7.js +10 -0
  8. package/dist/client-v2/index.js +1 -1
  9. package/dist/externalVersion.js +2 -1
  10. package/dist/locale/en-US.json +213 -198
  11. package/dist/locale/vi-VN.json +213 -198
  12. package/dist/locale/zh-CN.json +213 -198
  13. package/dist/node_modules/@elastic/elasticsearch/package.json +1 -1
  14. package/dist/server/mcp/ElasticReportToolCatalog.js +6 -4
  15. package/dist/server/plugin.js +4 -4
  16. package/dist/server/report-block-tools.js +340 -0
  17. package/dist/server/services/ElasticReportService.js +12 -6
  18. package/dist/shared/constants.js +9 -0
  19. package/package.json +2 -3
  20. package/server.d.ts +2 -2
  21. package/server.js +1 -1
  22. package/src/ai/skills/elastic-report/SKILLS.md +52 -0
  23. package/src/client/index.tsx +34 -34
  24. package/src/client/workflow-instructions.tsx +44 -44
  25. package/src/client-v2/__tests__/elastic-report.test.tsx +879 -791
  26. package/src/client-v2/__tests__/kql-autocomplete.test.ts +178 -178
  27. package/src/client-v2/api.ts +320 -320
  28. package/src/client-v2/bus/DashboardFilterBus.ts +212 -212
  29. package/src/client-v2/components/ElasticBasicCharts.tsx +652 -652
  30. package/src/client-v2/components/ElasticFilterBar.tsx +372 -372
  31. package/src/client-v2/components/ElasticKqlInput.tsx +421 -421
  32. package/src/client-v2/components/ElasticReportBlock.tsx +306 -306
  33. package/src/client-v2/components/ElasticReportRenderer.tsx +1257 -1257
  34. package/src/client-v2/components/HighlightText.tsx +50 -50
  35. package/src/client-v2/components/ReportSelect.tsx +85 -85
  36. package/src/client-v2/index.tsx +14 -14
  37. package/src/client-v2/locale.ts +23 -23
  38. package/src/client-v2/models/ElasticFilterBarBlockModel.tsx +115 -115
  39. package/src/client-v2/models/ElasticReportBlockModel.tsx +118 -118
  40. package/src/client-v2/pages/ElasticReportManager.tsx +1453 -1453
  41. package/src/client-v2/plugin.tsx +107 -72
  42. package/src/client-v2/report-destination.tsx +126 -0
  43. package/src/client-v2/utils/kqlAutocomplete.ts +861 -861
  44. package/src/client-v2/workflow/instructions.tsx +149 -149
  45. package/src/index.ts +11 -11
  46. package/src/locale/en-US.json +213 -198
  47. package/src/locale/vi-VN.json +213 -198
  48. package/src/locale/zh-CN.json +213 -198
  49. package/src/server/__tests__/ai-blocks.integration.test.ts +292 -0
  50. package/src/server/__tests__/query-compiler.test.ts +620 -620
  51. package/src/server/__tests__/report-mcp-acl.integration.test.ts +645 -645
  52. package/src/server/acl-guard.ts +194 -194
  53. package/src/server/collections/es-report-data-views.ts +64 -64
  54. package/src/server/collections/es-reports.ts +80 -80
  55. package/src/server/index.ts +15 -15
  56. package/src/server/mcp/ElasticReportMcpServer.ts +391 -391
  57. package/src/server/mcp/ElasticReportToolCatalog.ts +667 -663
  58. package/src/server/plugin.ts +599 -599
  59. package/src/server/report-block-tools.ts +400 -0
  60. package/src/server/services/ElasticReportService.ts +494 -486
  61. package/src/server/services/ElasticsearchConnectionService.ts +728 -728
  62. package/src/server/services/ReportExportService.ts +282 -282
  63. package/src/server/services/ReportQueryCompiler.ts +1552 -1552
  64. package/src/server/workflow/ElasticReportQueryInstruction.ts +124 -124
  65. package/src/shared/constants.ts +39 -36
  66. package/src/shared/types.ts +272 -272
  67. package/dist/client-v2/851.142c93fc6d666b28.js +0 -10
  68. package/dist/client-v2/877.f4095a3dbcadf98f.js +0 -10
  69. package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv +0 -15
  70. package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv.cmd +0 -7
@@ -1,194 +1,194 @@
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 { REPORTS_COLLECTION, SERVICE_RESOURCE } from '../shared/constants';
13
- import type { EsDataViewRecord, EsReportRecord } from '../shared/types';
14
- import { extractCurrentUserId } from './services/ElasticReportService';
15
-
16
- export function normalizeRoleList(raw: unknown): string[] {
17
- if (!Array.isArray(raw)) return [];
18
- const seen = new Set<string>();
19
- for (const item of raw) {
20
- if (typeof item === 'string' && item.trim()) {
21
- seen.add(item.trim());
22
- }
23
- }
24
- return Array.from(seen);
25
- }
26
-
27
- /**
28
- * Return ONLY the authenticated effective role(s) validated by NocoBase's auth/ACL
29
- * middleware (`ctx.state.currentRole` / `ctx.state.currentRoles`).
30
- * Never merge `currentUser.roles` or unvalidated `x-role` headers, so role-scoped
31
- * requests and API keys cannot escalate to dormant roles on the same user account.
32
- */
33
- export function getEffectiveRoles(ctx?: Partial<Context>): string[] {
34
- const roles = new Set<string>();
35
- const state = ctx?.state as
36
- | {
37
- currentRole?: unknown;
38
- currentRoles?: unknown;
39
- }
40
- | undefined;
41
-
42
- if (typeof state?.currentRole === 'string' && state.currentRole.trim()) {
43
- roles.add(state.currentRole.trim());
44
- }
45
- if (Array.isArray(state?.currentRoles)) {
46
- for (const r of state.currentRoles) {
47
- if (typeof r === 'string' && r.trim()) {
48
- roles.add(r.trim());
49
- }
50
- }
51
- }
52
- return Array.from(roles);
53
- }
54
-
55
- export function assertAuthenticated(ctx?: Partial<Context>): void {
56
- const userId = extractCurrentUserId(ctx);
57
- if (userId === undefined || userId === null || String(userId).trim() === '') {
58
- const err = new Error('Authentication required') as Error & { status?: number };
59
- err.status = 401;
60
- throw err;
61
- }
62
- }
63
-
64
- export function canManageReports(app: Application, ctx?: Partial<Context>): boolean {
65
- const userId = extractCurrentUserId(ctx);
66
- if (userId === undefined || userId === null || String(userId).trim() === '') {
67
- return false;
68
- }
69
-
70
- const roles = getEffectiveRoles(ctx);
71
- if (roles.includes('root') || roles.includes('admin')) {
72
- return true;
73
- }
74
-
75
- const aclLike = app.acl as unknown as {
76
- can?: (opts: { role: string; resource: string; action: string }) => unknown;
77
- };
78
- if (typeof aclLike?.can !== 'function') {
79
- return false;
80
- }
81
-
82
- if (roles.length === 0) {
83
- return Boolean(aclLike.can({ role: 'member', resource: SERVICE_RESOURCE, action: 'saveReport' }));
84
- }
85
-
86
- return roles.some(
87
- (role) =>
88
- Boolean(aclLike.can({ role, resource: SERVICE_RESOURCE, action: 'saveReport' })) ||
89
- Boolean(aclLike.can({ role, resource: REPORTS_COLLECTION, action: 'create' })),
90
- );
91
- }
92
-
93
- export function assertCanManageReports(app: Application, ctx?: Partial<Context>): void {
94
- assertAuthenticated(ctx);
95
- if (!canManageReports(app, ctx)) {
96
- const err = new Error('Permission denied: Elastic Report management access is required') as Error & {
97
- status?: number;
98
- };
99
- err.status = 403;
100
- throw err;
101
- }
102
- }
103
-
104
- function matchesAllowedRoles(effectiveRoles: string[], allowedRoles?: string[] | null): boolean {
105
- const normalized = normalizeRoleList(allowedRoles);
106
- if (normalized.length === 0) {
107
- return true;
108
- }
109
- if (effectiveRoles.length === 0) {
110
- return false;
111
- }
112
- return effectiveRoles.some((role) => normalized.includes(role));
113
- }
114
-
115
- export function canAccessDataView(
116
- app: Application,
117
- ctx: Partial<Context> | undefined,
118
- dataView: Pick<EsDataViewRecord, 'allowedRoles'>,
119
- ): boolean {
120
- const userId = extractCurrentUserId(ctx);
121
- if (userId === undefined || userId === null || String(userId).trim() === '') {
122
- return false;
123
- }
124
- if (canManageReports(app, ctx)) {
125
- return true;
126
- }
127
- return matchesAllowedRoles(getEffectiveRoles(ctx), dataView.allowedRoles);
128
- }
129
-
130
- export function assertCanAccessDataView(
131
- app: Application,
132
- ctx: Partial<Context> | undefined,
133
- dataView: Pick<EsDataViewRecord, 'allowedRoles'>,
134
- ): void {
135
- assertAuthenticated(ctx);
136
- if (!canAccessDataView(app, ctx, dataView)) {
137
- const err = new Error('Permission denied: current role does not have access to this Data View') as Error & {
138
- status?: number;
139
- };
140
- err.status = 403;
141
- throw err;
142
- }
143
- }
144
-
145
- export function canAccessReport(
146
- app: Application,
147
- ctx: Partial<Context> | undefined,
148
- report: Pick<EsReportRecord, 'published' | 'allowedRoles' | 'dataView'>,
149
- dataView?: Pick<EsDataViewRecord, 'allowedRoles'> | null,
150
- ): boolean {
151
- const userId = extractCurrentUserId(ctx);
152
- if (userId === undefined || userId === null || String(userId).trim() === '') {
153
- return false;
154
- }
155
- if (canManageReports(app, ctx)) {
156
- return true;
157
- }
158
- if (!report.published) {
159
- return false;
160
- }
161
- const effectiveRoles = getEffectiveRoles(ctx);
162
- if (!matchesAllowedRoles(effectiveRoles, report.allowedRoles)) {
163
- return false;
164
- }
165
- const targetDv = dataView ?? report.dataView;
166
- if (targetDv && !matchesAllowedRoles(effectiveRoles, targetDv.allowedRoles)) {
167
- return false;
168
- }
169
- return true;
170
- }
171
-
172
- export function assertCanAccessReport(
173
- app: Application,
174
- ctx: Partial<Context> | undefined,
175
- report: Pick<EsReportRecord, 'published' | 'allowedRoles' | 'dataView'>,
176
- dataView?: Pick<EsDataViewRecord, 'allowedRoles'> | null,
177
- ): void {
178
- assertAuthenticated(ctx);
179
- if (canManageReports(app, ctx)) {
180
- return;
181
- }
182
- if (!report.published) {
183
- const notFound = new Error('Report not found') as Error & { status?: number };
184
- notFound.status = 404;
185
- throw notFound;
186
- }
187
- if (!canAccessReport(app, ctx, report, dataView)) {
188
- const err = new Error('Permission denied: current role does not have access to this report') as Error & {
189
- status?: number;
190
- };
191
- err.status = 403;
192
- throw err;
193
- }
194
- }
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 { REPORTS_COLLECTION, SERVICE_RESOURCE } from '../shared/constants';
13
+ import type { EsDataViewRecord, EsReportRecord } from '../shared/types';
14
+ import { extractCurrentUserId } from './services/ElasticReportService';
15
+
16
+ export function normalizeRoleList(raw: unknown): string[] {
17
+ if (!Array.isArray(raw)) return [];
18
+ const seen = new Set<string>();
19
+ for (const item of raw) {
20
+ if (typeof item === 'string' && item.trim()) {
21
+ seen.add(item.trim());
22
+ }
23
+ }
24
+ return Array.from(seen);
25
+ }
26
+
27
+ /**
28
+ * Return ONLY the authenticated effective role(s) validated by NocoBase's auth/ACL
29
+ * middleware (`ctx.state.currentRole` / `ctx.state.currentRoles`).
30
+ * Never merge `currentUser.roles` or unvalidated `x-role` headers, so role-scoped
31
+ * requests and API keys cannot escalate to dormant roles on the same user account.
32
+ */
33
+ export function getEffectiveRoles(ctx?: Partial<Context>): string[] {
34
+ const roles = new Set<string>();
35
+ const state = ctx?.state as
36
+ | {
37
+ currentRole?: unknown;
38
+ currentRoles?: unknown;
39
+ }
40
+ | undefined;
41
+
42
+ if (typeof state?.currentRole === 'string' && state.currentRole.trim()) {
43
+ roles.add(state.currentRole.trim());
44
+ }
45
+ if (Array.isArray(state?.currentRoles)) {
46
+ for (const r of state.currentRoles) {
47
+ if (typeof r === 'string' && r.trim()) {
48
+ roles.add(r.trim());
49
+ }
50
+ }
51
+ }
52
+ return Array.from(roles);
53
+ }
54
+
55
+ export function assertAuthenticated(ctx?: Partial<Context>): void {
56
+ const userId = extractCurrentUserId(ctx);
57
+ if (userId === undefined || userId === null || String(userId).trim() === '') {
58
+ const err = new Error('Authentication required') as Error & { status?: number };
59
+ err.status = 401;
60
+ throw err;
61
+ }
62
+ }
63
+
64
+ export function canManageReports(app: Application, ctx?: Partial<Context>): boolean {
65
+ const userId = extractCurrentUserId(ctx);
66
+ if (userId === undefined || userId === null || String(userId).trim() === '') {
67
+ return false;
68
+ }
69
+
70
+ const roles = getEffectiveRoles(ctx);
71
+ if (roles.includes('root') || roles.includes('admin')) {
72
+ return true;
73
+ }
74
+
75
+ const aclLike = app.acl as unknown as {
76
+ can?: (opts: { role: string; resource: string; action: string }) => unknown;
77
+ };
78
+ if (typeof aclLike?.can !== 'function') {
79
+ return false;
80
+ }
81
+
82
+ if (roles.length === 0) {
83
+ return Boolean(aclLike.can({ role: 'member', resource: SERVICE_RESOURCE, action: 'saveReport' }));
84
+ }
85
+
86
+ return roles.some(
87
+ (role) =>
88
+ Boolean(aclLike.can({ role, resource: SERVICE_RESOURCE, action: 'saveReport' })) ||
89
+ Boolean(aclLike.can({ role, resource: REPORTS_COLLECTION, action: 'create' })),
90
+ );
91
+ }
92
+
93
+ export function assertCanManageReports(app: Application, ctx?: Partial<Context>): void {
94
+ assertAuthenticated(ctx);
95
+ if (!canManageReports(app, ctx)) {
96
+ const err = new Error('Permission denied: Elastic Report management access is required') as Error & {
97
+ status?: number;
98
+ };
99
+ err.status = 403;
100
+ throw err;
101
+ }
102
+ }
103
+
104
+ function matchesAllowedRoles(effectiveRoles: string[], allowedRoles?: string[] | null): boolean {
105
+ const normalized = normalizeRoleList(allowedRoles);
106
+ if (normalized.length === 0) {
107
+ return true;
108
+ }
109
+ if (effectiveRoles.length === 0) {
110
+ return false;
111
+ }
112
+ return effectiveRoles.some((role) => normalized.includes(role));
113
+ }
114
+
115
+ export function canAccessDataView(
116
+ app: Application,
117
+ ctx: Partial<Context> | undefined,
118
+ dataView: Pick<EsDataViewRecord, 'allowedRoles'>,
119
+ ): boolean {
120
+ const userId = extractCurrentUserId(ctx);
121
+ if (userId === undefined || userId === null || String(userId).trim() === '') {
122
+ return false;
123
+ }
124
+ if (canManageReports(app, ctx)) {
125
+ return true;
126
+ }
127
+ return matchesAllowedRoles(getEffectiveRoles(ctx), dataView.allowedRoles);
128
+ }
129
+
130
+ export function assertCanAccessDataView(
131
+ app: Application,
132
+ ctx: Partial<Context> | undefined,
133
+ dataView: Pick<EsDataViewRecord, 'allowedRoles'>,
134
+ ): void {
135
+ assertAuthenticated(ctx);
136
+ if (!canAccessDataView(app, ctx, dataView)) {
137
+ const err = new Error('Permission denied: current role does not have access to this Data View') as Error & {
138
+ status?: number;
139
+ };
140
+ err.status = 403;
141
+ throw err;
142
+ }
143
+ }
144
+
145
+ export function canAccessReport(
146
+ app: Application,
147
+ ctx: Partial<Context> | undefined,
148
+ report: Pick<EsReportRecord, 'published' | 'allowedRoles' | 'dataView'>,
149
+ dataView?: Pick<EsDataViewRecord, 'allowedRoles'> | null,
150
+ ): boolean {
151
+ const userId = extractCurrentUserId(ctx);
152
+ if (userId === undefined || userId === null || String(userId).trim() === '') {
153
+ return false;
154
+ }
155
+ if (canManageReports(app, ctx)) {
156
+ return true;
157
+ }
158
+ if (!report.published) {
159
+ return false;
160
+ }
161
+ const effectiveRoles = getEffectiveRoles(ctx);
162
+ if (!matchesAllowedRoles(effectiveRoles, report.allowedRoles)) {
163
+ return false;
164
+ }
165
+ const targetDv = dataView ?? report.dataView;
166
+ if (targetDv && !matchesAllowedRoles(effectiveRoles, targetDv.allowedRoles)) {
167
+ return false;
168
+ }
169
+ return true;
170
+ }
171
+
172
+ export function assertCanAccessReport(
173
+ app: Application,
174
+ ctx: Partial<Context> | undefined,
175
+ report: Pick<EsReportRecord, 'published' | 'allowedRoles' | 'dataView'>,
176
+ dataView?: Pick<EsDataViewRecord, 'allowedRoles'> | null,
177
+ ): void {
178
+ assertAuthenticated(ctx);
179
+ if (canManageReports(app, ctx)) {
180
+ return;
181
+ }
182
+ if (!report.published) {
183
+ const notFound = new Error('Report not found') as Error & { status?: number };
184
+ notFound.status = 404;
185
+ throw notFound;
186
+ }
187
+ if (!canAccessReport(app, ctx, report, dataView)) {
188
+ const err = new Error('Permission denied: current role does not have access to this report') as Error & {
189
+ status?: number;
190
+ };
191
+ err.status = 403;
192
+ throw err;
193
+ }
194
+ }
@@ -1,64 +1,64 @@
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 { defineCollection } from '@nocobase/database';
11
- import { DATA_VIEWS_COLLECTION } from '../../shared/constants';
12
-
13
- export default defineCollection({
14
- name: DATA_VIEWS_COLLECTION,
15
- title: 'Elasticsearch Report Data Views',
16
- filterTargetKey: 'id',
17
- autoGenId: true,
18
- timestamps: true,
19
- fields: [
20
- {
21
- type: 'string',
22
- name: 'title',
23
- allowNull: false,
24
- },
25
- {
26
- type: 'string',
27
- name: 'dataSourceKey',
28
- allowNull: false,
29
- index: true,
30
- },
31
- {
32
- type: 'string',
33
- name: 'indexPattern',
34
- allowNull: false,
35
- },
36
- {
37
- type: 'string',
38
- name: 'timeField',
39
- allowNull: true,
40
- },
41
- {
42
- type: 'text',
43
- name: 'description',
44
- allowNull: true,
45
- },
46
- {
47
- type: 'json',
48
- name: 'cachedFields',
49
- allowNull: true,
50
- },
51
- {
52
- type: 'json',
53
- name: 'allowedRoles',
54
- allowNull: true,
55
- defaultValue: [],
56
- },
57
- {
58
- type: 'context',
59
- name: 'createdById',
60
- dataIndex: 'state.currentUser.id',
61
- createOnly: true,
62
- },
63
- ],
64
- });
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 { defineCollection } from '@nocobase/database';
11
+ import { DATA_VIEWS_COLLECTION } from '../../shared/constants';
12
+
13
+ export default defineCollection({
14
+ name: DATA_VIEWS_COLLECTION,
15
+ title: 'Elasticsearch Report Data Views',
16
+ filterTargetKey: 'id',
17
+ autoGenId: true,
18
+ timestamps: true,
19
+ fields: [
20
+ {
21
+ type: 'string',
22
+ name: 'title',
23
+ allowNull: false,
24
+ },
25
+ {
26
+ type: 'string',
27
+ name: 'dataSourceKey',
28
+ allowNull: false,
29
+ index: true,
30
+ },
31
+ {
32
+ type: 'string',
33
+ name: 'indexPattern',
34
+ allowNull: false,
35
+ },
36
+ {
37
+ type: 'string',
38
+ name: 'timeField',
39
+ allowNull: true,
40
+ },
41
+ {
42
+ type: 'text',
43
+ name: 'description',
44
+ allowNull: true,
45
+ },
46
+ {
47
+ type: 'json',
48
+ name: 'cachedFields',
49
+ allowNull: true,
50
+ },
51
+ {
52
+ type: 'json',
53
+ name: 'allowedRoles',
54
+ allowNull: true,
55
+ defaultValue: [],
56
+ },
57
+ {
58
+ type: 'context',
59
+ name: 'createdById',
60
+ dataIndex: 'state.currentUser.id',
61
+ createOnly: true,
62
+ },
63
+ ],
64
+ });
@@ -1,80 +1,80 @@
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 { defineCollection } from '@nocobase/database';
11
- import { DATA_VIEWS_COLLECTION, REPORTS_COLLECTION } from '../../shared/constants';
12
-
13
- export default defineCollection({
14
- name: REPORTS_COLLECTION,
15
- title: 'Elasticsearch Reports',
16
- filterTargetKey: 'id',
17
- autoGenId: true,
18
- timestamps: true,
19
- fields: [
20
- {
21
- type: 'string',
22
- name: 'title',
23
- allowNull: false,
24
- },
25
- {
26
- type: 'text',
27
- name: 'description',
28
- allowNull: true,
29
- },
30
- {
31
- type: 'bigInt',
32
- name: 'dataViewId',
33
- allowNull: false,
34
- index: true,
35
- },
36
- {
37
- type: 'belongsTo',
38
- name: 'dataView',
39
- target: DATA_VIEWS_COLLECTION,
40
- foreignKey: 'dataViewId',
41
- targetKey: 'id',
42
- constraints: false,
43
- },
44
- {
45
- type: 'string',
46
- name: 'visualization',
47
- allowNull: false,
48
- defaultValue: 'table',
49
- },
50
- {
51
- type: 'json',
52
- name: 'spec',
53
- allowNull: false,
54
- },
55
- {
56
- type: 'boolean',
57
- name: 'published',
58
- allowNull: false,
59
- defaultValue: true,
60
- index: true,
61
- },
62
- {
63
- type: 'json',
64
- name: 'allowedRoles',
65
- allowNull: true,
66
- defaultValue: [],
67
- },
68
- {
69
- type: 'context',
70
- name: 'createdById',
71
- dataIndex: 'state.currentUser.id',
72
- createOnly: true,
73
- },
74
- {
75
- type: 'context',
76
- name: 'updatedById',
77
- dataIndex: 'state.currentUser.id',
78
- },
79
- ],
80
- });
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 { defineCollection } from '@nocobase/database';
11
+ import { DATA_VIEWS_COLLECTION, REPORTS_COLLECTION } from '../../shared/constants';
12
+
13
+ export default defineCollection({
14
+ name: REPORTS_COLLECTION,
15
+ title: 'Elasticsearch Reports',
16
+ filterTargetKey: 'id',
17
+ autoGenId: true,
18
+ timestamps: true,
19
+ fields: [
20
+ {
21
+ type: 'string',
22
+ name: 'title',
23
+ allowNull: false,
24
+ },
25
+ {
26
+ type: 'text',
27
+ name: 'description',
28
+ allowNull: true,
29
+ },
30
+ {
31
+ type: 'bigInt',
32
+ name: 'dataViewId',
33
+ allowNull: false,
34
+ index: true,
35
+ },
36
+ {
37
+ type: 'belongsTo',
38
+ name: 'dataView',
39
+ target: DATA_VIEWS_COLLECTION,
40
+ foreignKey: 'dataViewId',
41
+ targetKey: 'id',
42
+ constraints: false,
43
+ },
44
+ {
45
+ type: 'string',
46
+ name: 'visualization',
47
+ allowNull: false,
48
+ defaultValue: 'table',
49
+ },
50
+ {
51
+ type: 'json',
52
+ name: 'spec',
53
+ allowNull: false,
54
+ },
55
+ {
56
+ type: 'boolean',
57
+ name: 'published',
58
+ allowNull: false,
59
+ defaultValue: true,
60
+ index: true,
61
+ },
62
+ {
63
+ type: 'json',
64
+ name: 'allowedRoles',
65
+ allowNull: true,
66
+ defaultValue: [],
67
+ },
68
+ {
69
+ type: 'context',
70
+ name: 'createdById',
71
+ dataIndex: 'state.currentUser.id',
72
+ createOnly: true,
73
+ },
74
+ {
75
+ type: 'context',
76
+ name: 'updatedById',
77
+ dataIndex: 'state.currentUser.id',
78
+ },
79
+ ],
80
+ });