@nocobase/plugin-data-visualization 1.4.0-alpha.20241020033334 → 1.4.0-alpha.20241024133132

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.
@@ -8,24 +8,24 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "1.4.0-alpha.20241020033334",
11
+ "@nocobase/client": "1.4.0-alpha.20241024133132",
12
12
  "dayjs": "1.11.10",
13
13
  "@formily/react": "2.3.0",
14
14
  "@formily/shared": "2.3.0",
15
15
  "lodash": "4.17.21",
16
16
  "react": "18.2.0",
17
- "@nocobase/cache": "1.4.0-alpha.20241020033334",
18
- "@nocobase/server": "1.4.0-alpha.20241020033334",
19
- "@nocobase/test": "1.4.0-alpha.20241020033334",
17
+ "@nocobase/cache": "1.4.0-alpha.20241024133132",
18
+ "@nocobase/server": "1.4.0-alpha.20241024133132",
19
+ "@nocobase/test": "1.4.0-alpha.20241024133132",
20
20
  "@emotion/css": "11.13.0",
21
21
  "@ant-design/icons": "5.2.6",
22
22
  "ahooks": "3.7.8",
23
23
  "antd": "5.12.8",
24
24
  "@formily/antd-v5": "1.1.9",
25
25
  "@formily/core": "2.3.0",
26
- "@nocobase/utils": "1.4.0-alpha.20241020033334",
26
+ "@nocobase/utils": "1.4.0-alpha.20241024133132",
27
27
  "react-i18next": "11.18.6",
28
- "@nocobase/actions": "1.4.0-alpha.20241020033334",
29
- "@nocobase/database": "1.4.0-alpha.20241020033334",
28
+ "@nocobase/actions": "1.4.0-alpha.20241024133132",
29
+ "@nocobase/database": "1.4.0-alpha.20241024133132",
30
30
  "sequelize": "6.35.2"
31
31
  };
@@ -1 +1 @@
1
- {"name":"koa-compose","description":"compose Koa middleware","repository":"koajs/compose","version":"4.1.0","keywords":["koa","middleware","compose"],"files":["index.js"],"dependencies":{},"devDependencies":{"codecov":"^3.0.0","jest":"^21.0.0","matcha":"^0.7.0","standard":"^10.0.3"},"scripts":{"bench":"matcha bench/bench.js","lint":"standard --fix .","test":"jest --forceExit --coverage"},"jest":{"testEnvironment":"node"},"license":"MIT","_lastModified":"2024-10-20T03:45:07.039Z"}
1
+ {"name":"koa-compose","description":"compose Koa middleware","repository":"koajs/compose","version":"4.1.0","keywords":["koa","middleware","compose"],"files":["index.js"],"dependencies":{},"devDependencies":{"codecov":"^3.0.0","jest":"^21.0.0","matcha":"^0.7.0","standard":"^10.0.3"},"scripts":{"bench":"matcha bench/bench.js","lint":"standard --fix .","test":"jest --forceExit --coverage"},"jest":{"testEnvironment":"node"},"license":"MIT","_lastModified":"2024-10-24T13:44:06.837Z"}
@@ -1 +1 @@
1
- {"name":"moment-timezone","version":"0.5.43","description":"Parse and display moments in any timezone.","homepage":"http://momentjs.com/timezone/","author":"Tim Wood <washwithcare@gmail.com> (http://timwoodcreates.com/)","keywords":["moment","date","time","timezone","olson","iana","zone","tz"],"main":"./index.js","typings":"./index.d.ts","engines":{"node":"*"},"repository":{"type":"git","url":"https://github.com/moment/moment-timezone.git"},"bugs":{"url":"https://github.com/moment/moment-timezone/issues"},"license":"MIT","dependencies":{"moment":"^2.29.4"},"devDependencies":{"grunt":"^1.5.3","grunt-contrib-clean":"^2.0.1","grunt-contrib-jshint":"^3.2.0","grunt-contrib-nodeunit":"^4.0.0","grunt-contrib-uglify":"^5.2.2","grunt-exec":"^3.0.0","typescript":"^3.5.1"},"jspm":{"main":"builds/moment-timezone-with-data","shim":{"moment-timezone":{"deps":["moment"]}}},"scripts":{"test":"grunt"},"_lastModified":"2024-10-20T03:45:07.723Z"}
1
+ {"name":"moment-timezone","version":"0.5.43","description":"Parse and display moments in any timezone.","homepage":"http://momentjs.com/timezone/","author":"Tim Wood <washwithcare@gmail.com> (http://timwoodcreates.com/)","keywords":["moment","date","time","timezone","olson","iana","zone","tz"],"main":"./index.js","typings":"./index.d.ts","engines":{"node":"*"},"repository":{"type":"git","url":"https://github.com/moment/moment-timezone.git"},"bugs":{"url":"https://github.com/moment/moment-timezone/issues"},"license":"MIT","dependencies":{"moment":"^2.29.4"},"devDependencies":{"grunt":"^1.5.3","grunt-contrib-clean":"^2.0.1","grunt-contrib-jshint":"^3.2.0","grunt-contrib-nodeunit":"^4.0.0","grunt-contrib-uglify":"^5.2.2","grunt-exec":"^3.0.0","typescript":"^3.5.1"},"jspm":{"main":"builds/moment-timezone-with-data","shim":{"moment-timezone":{"deps":["moment"]}}},"scripts":{"test":"grunt"},"_lastModified":"2024-10-24T13:44:07.644Z"}
@@ -9,7 +9,6 @@
9
9
  import { Context, Next } from '@nocobase/actions';
10
10
  export declare const postProcess: (ctx: Context, next: Next) => Promise<void>;
11
11
  export declare const queryData: (ctx: Context, next: Next) => Promise<void>;
12
- export declare const parseBuilder: (ctx: Context, next: Next) => Promise<void>;
13
12
  export declare const parseFieldAndAssociations: (ctx: Context, next: Next) => Promise<void>;
14
13
  export declare const parseVariables: (ctx: Context, next: Next) => Promise<void>;
15
14
  export declare const cacheMiddleware: (ctx: Context, next: Next) => Promise<void>;
@@ -38,7 +38,6 @@ var query_exports = {};
38
38
  __export(query_exports, {
39
39
  cacheMiddleware: () => cacheMiddleware,
40
40
  checkPermission: () => checkPermission,
41
- parseBuilder: () => parseBuilder,
42
41
  parseFieldAndAssociations: () => parseFieldAndAssociations,
43
42
  parseVariables: () => parseVariables,
44
43
  postProcess: () => postProcess,
@@ -49,8 +48,7 @@ module.exports = __toCommonJS(query_exports);
49
48
  var import_database = require("@nocobase/database");
50
49
  var import_koa_compose = __toESM(require("koa-compose"));
51
50
  var import_server = require("@nocobase/server");
52
- var import_formatter = require("../formatter");
53
- const AllowedAggFuncs = ["sum", "count", "avg", "min", "max"];
51
+ var import_query_parser = require("../query-parser");
54
52
  const getDB = (ctx, dataSource) => {
55
53
  const ds = ctx.app.dataSourceManager.dataSources.get(dataSource);
56
54
  return ds == null ? void 0 : ds.collectionManager.db;
@@ -88,74 +86,6 @@ const queryData = async (ctx, next) => {
88
86
  };
89
87
  await next();
90
88
  };
91
- const parseBuilder = async (ctx, next) => {
92
- const { dataSource, measures, dimensions, orders, include, where, limit } = ctx.action.params.values;
93
- const db = getDB(ctx, dataSource) || ctx.db;
94
- const { sequelize } = db;
95
- const attributes = [];
96
- const group = [];
97
- const order = [];
98
- const fieldMap = {};
99
- let hasAgg = false;
100
- measures.forEach((measure) => {
101
- const { field, aggregation, alias, distinct } = measure;
102
- const attribute = [];
103
- const col = sequelize.col(field);
104
- if (aggregation) {
105
- if (!AllowedAggFuncs.includes(aggregation)) {
106
- throw new Error(`Invalid aggregation function: ${aggregation}`);
107
- }
108
- hasAgg = true;
109
- attribute.push(sequelize.fn(aggregation, distinct ? sequelize.fn("DISTINCT", col) : col));
110
- } else {
111
- attribute.push(col);
112
- }
113
- if (alias) {
114
- attribute.push(alias);
115
- }
116
- attributes.push(attribute.length > 1 ? attribute : attribute[0]);
117
- fieldMap[alias || field] = measure;
118
- });
119
- dimensions.forEach((dimension) => {
120
- const { field, format, alias, type, options } = dimension;
121
- const attribute = [];
122
- const col = sequelize.col(field);
123
- if (format) {
124
- const formatter = (0, import_formatter.createFormatter)(sequelize);
125
- attribute.push(formatter.format({ type, field, format, timezone: ctx.timezone, options }));
126
- } else {
127
- attribute.push(col);
128
- }
129
- if (alias) {
130
- attribute.push(alias);
131
- }
132
- attributes.push(attribute.length > 1 ? attribute : attribute[0]);
133
- if (hasAgg) {
134
- group.push(attribute[0]);
135
- }
136
- fieldMap[alias || field] = dimension;
137
- });
138
- orders.forEach((item) => {
139
- const alias = sequelize.getQueryInterface().quoteIdentifier(item.alias);
140
- const name = hasAgg ? sequelize.literal(alias) : sequelize.col(item.field);
141
- order.push([name, item.order || "ASC"]);
142
- });
143
- ctx.action.params.values = {
144
- ...ctx.action.params.values,
145
- queryParams: {
146
- where,
147
- attributes,
148
- include,
149
- group,
150
- order,
151
- limit: limit || 2e3,
152
- subQuery: false,
153
- raw: true
154
- },
155
- fieldMap
156
- };
157
- await next();
158
- };
159
89
  const parseFieldAndAssociations = async (ctx, next) => {
160
90
  const {
161
91
  dataSource,
@@ -288,13 +218,16 @@ const checkPermission = (ctx, next) => {
288
218
  return next();
289
219
  };
290
220
  const query = async (ctx, next) => {
221
+ const { dataSource } = ctx.action.params.values;
222
+ const db = getDB(ctx, dataSource) || ctx.db;
223
+ const queryParser = (0, import_query_parser.createQueryParser)(db);
291
224
  try {
292
225
  await (0, import_koa_compose.default)([
293
226
  checkPermission,
294
227
  cacheMiddleware,
295
228
  parseVariables,
296
229
  parseFieldAndAssociations,
297
- parseBuilder,
230
+ queryParser.parse(),
298
231
  queryData,
299
232
  postProcess
300
233
  ])(ctx, next);
@@ -306,7 +239,6 @@ const query = async (ctx, next) => {
306
239
  0 && (module.exports = {
307
240
  cacheMiddleware,
308
241
  checkPermission,
309
- parseBuilder,
310
242
  parseFieldAndAssociations,
311
243
  parseVariables,
312
244
  postProcess,
@@ -0,0 +1,14 @@
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
+ import { Col, Formatter } from './formatter';
10
+ export declare class OracleFormatter extends Formatter {
11
+ convertFormat(format: string): string;
12
+ formatDate(field: Col, format: string, timezoneOffset?: string): import("sequelize/types/utils").Fn;
13
+ formatUnixTimeStamp(field: string, format: string, accuracy?: 'second' | 'millisecond', timezoneOffset?: string): import("sequelize/types/utils").Fn;
14
+ }
@@ -0,0 +1,74 @@
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
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var oracle_formatter_exports = {};
28
+ __export(oracle_formatter_exports, {
29
+ OracleFormatter: () => OracleFormatter
30
+ });
31
+ module.exports = __toCommonJS(oracle_formatter_exports);
32
+ var import_formatter = require("./formatter");
33
+ class OracleFormatter extends import_formatter.Formatter {
34
+ convertFormat(format) {
35
+ return format.replace(/hh/g, "HH24").replace(/mm/g, "MI").replace(/ss/g, "SS");
36
+ }
37
+ formatDate(field, format, timezoneOffset) {
38
+ format = this.convertFormat(format);
39
+ const timezone = this.getTimezoneByOffset(timezoneOffset);
40
+ if (timezone) {
41
+ const col = this.sequelize.getQueryInterface().quoteIdentifiers(field.col);
42
+ const fieldWithTZ = this.sequelize.literal(`(${col} AT TIME ZONE '${timezone}')`);
43
+ return this.sequelize.fn("to_char", fieldWithTZ, format);
44
+ }
45
+ return this.sequelize.fn("to_char", field, format);
46
+ }
47
+ formatUnixTimeStamp(field, format, accuracy = "second", timezoneOffset) {
48
+ format = this.convertFormat(format);
49
+ const col = this.sequelize.getQueryInterface().quoteIdentifiers(field);
50
+ const timezone = this.getTimezoneByOffset(timezoneOffset);
51
+ if (timezone) {
52
+ if (accuracy === "millisecond") {
53
+ return this.sequelize.fn(
54
+ "to_char",
55
+ this.sequelize.literal(`to_timestamp(ROUND(${col} / 1000)) AT TIME ZONE '${timezone}'`),
56
+ format
57
+ );
58
+ }
59
+ return this.sequelize.fn(
60
+ "to_char",
61
+ this.sequelize.literal(`to_timestamp(${col}) AT TIME ZONE '${timezone}'`),
62
+ format
63
+ );
64
+ }
65
+ if (accuracy === "millisecond") {
66
+ return this.sequelize.fn("to_char", this.sequelize.literal(`to_timestamp(ROUND(${col} / 1000)`), format);
67
+ }
68
+ return this.sequelize.fn("to_char", this.sequelize.literal(`to_timestamp(${col})`), format);
69
+ }
70
+ }
71
+ // Annotate the CommonJS export names for ESM import in node:
72
+ 0 && (module.exports = {
73
+ OracleFormatter
74
+ });
@@ -37,7 +37,7 @@ class PluginDataVisualizationServer extends import_server.Plugin {
37
37
  afterAdd() {
38
38
  }
39
39
  beforeLoad() {
40
- this.app.resource({
40
+ this.app.resourceManager.define({
41
41
  name: "charts",
42
42
  actions: {
43
43
  query: import_query.query
@@ -0,0 +1,11 @@
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
+ import { Database } from '@nocobase/database';
10
+ import { QueryParser } from './query-parser';
11
+ export declare const createQueryParser: (db: Database) => QueryParser;
@@ -0,0 +1,56 @@
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
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var query_parser_exports = {};
28
+ __export(query_parser_exports, {
29
+ createQueryParser: () => createQueryParser
30
+ });
31
+ module.exports = __toCommonJS(query_parser_exports);
32
+ var import_sqlite_query_parser = require("./sqlite-query-parser");
33
+ var import_postgres_query_parser = require("./postgres-query-parser");
34
+ var import_mysql_query_parser = require("./mysql-query-parser");
35
+ var import_query_parser = require("./query-parser");
36
+ var import_oracle_query_parser = require("./oracle-query-parser");
37
+ const createQueryParser = (db) => {
38
+ const dialect = db.sequelize.getDialect();
39
+ switch (dialect) {
40
+ case "sqlite":
41
+ return new import_sqlite_query_parser.SQLiteQueryParser(db);
42
+ case "postgres":
43
+ return new import_postgres_query_parser.PostgresQueryParser(db);
44
+ case "mysql":
45
+ case "mariadb":
46
+ return new import_mysql_query_parser.MySQLQueryParser(db);
47
+ case "oracle":
48
+ return new import_oracle_query_parser.OracleQueryParser(db);
49
+ default:
50
+ return new import_query_parser.QueryParser(db);
51
+ }
52
+ };
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ createQueryParser
56
+ });
@@ -0,0 +1,15 @@
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
+ import { Database } from '@nocobase/database';
10
+ import { MySQLFormatter } from '../formatter/mysql-formatter';
11
+ import { QueryParser } from './query-parser';
12
+ export declare class MySQLQueryParser extends QueryParser {
13
+ formatter: MySQLFormatter;
14
+ constructor(db: Database);
15
+ }
@@ -24,27 +24,20 @@ var __copyProps = (to, from, except, desc) => {
24
24
  return to;
25
25
  };
26
26
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
- var formatter_exports = {};
28
- __export(formatter_exports, {
29
- createFormatter: () => createFormatter
27
+ var mysql_query_parser_exports = {};
28
+ __export(mysql_query_parser_exports, {
29
+ MySQLQueryParser: () => MySQLQueryParser
30
30
  });
31
- module.exports = __toCommonJS(formatter_exports);
32
- var import_sqlite_formatter = require("./sqlite-formatter");
33
- var import_postgres_formatter = require("./postgres-formatter");
34
- var import_mysql_formatter = require("./mysql-formatter");
35
- const createFormatter = (sequelize) => {
36
- const dialect = sequelize.getDialect();
37
- switch (dialect) {
38
- case "sqlite":
39
- return new import_sqlite_formatter.SQLiteFormatter(sequelize);
40
- case "postgres":
41
- return new import_postgres_formatter.PostgresFormatter(sequelize);
42
- case "mysql":
43
- case "mariadb":
44
- return new import_mysql_formatter.MySQLFormatter(sequelize);
31
+ module.exports = __toCommonJS(mysql_query_parser_exports);
32
+ var import_mysql_formatter = require("../formatter/mysql-formatter");
33
+ var import_query_parser = require("./query-parser");
34
+ class MySQLQueryParser extends import_query_parser.QueryParser {
35
+ constructor(db) {
36
+ super(db);
37
+ this.formatter = new import_mysql_formatter.MySQLFormatter(db.sequelize);
45
38
  }
46
- };
39
+ }
47
40
  // Annotate the CommonJS export names for ESM import in node:
48
41
  0 && (module.exports = {
49
- createFormatter
42
+ MySQLQueryParser
50
43
  });
@@ -0,0 +1,18 @@
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
+ import { QueryParser } from './query-parser';
10
+ import { OrderProps } from '../types';
11
+ import { Context } from '@nocobase/actions';
12
+ import { OracleFormatter } from '../formatter/oracle-formatter';
13
+ import { Database } from '@nocobase/database';
14
+ export declare class OracleQueryParser extends QueryParser {
15
+ formatter: OracleFormatter;
16
+ constructor(db: Database);
17
+ parseOrders(ctx: Context, orders: OrderProps[], hasAgg: boolean): any[];
18
+ }
@@ -0,0 +1,60 @@
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
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var oracle_query_parser_exports = {};
28
+ __export(oracle_query_parser_exports, {
29
+ OracleQueryParser: () => OracleQueryParser
30
+ });
31
+ module.exports = __toCommonJS(oracle_query_parser_exports);
32
+ var import_query_parser = require("./query-parser");
33
+ var import_oracle_formatter = require("../formatter/oracle-formatter");
34
+ class OracleQueryParser extends import_query_parser.QueryParser {
35
+ constructor(db) {
36
+ super(db);
37
+ this.formatter = new import_oracle_formatter.OracleFormatter(db.sequelize);
38
+ }
39
+ parseOrders(ctx, orders, hasAgg) {
40
+ const { collection: collectionName, dimensions } = ctx.action.params.values;
41
+ const collection = this.db.getCollection(collectionName);
42
+ if (!orders.length) {
43
+ if (dimensions.length) {
44
+ orders.push(dimensions[0]);
45
+ } else {
46
+ let filterTks = collection.filterTargetKey;
47
+ if (!Array.isArray(filterTks)) {
48
+ filterTks = [filterTks];
49
+ }
50
+ orders.push(...filterTks.map((field) => ({ field, alias: field })));
51
+ }
52
+ }
53
+ const order = super.parseOrders(ctx, orders, hasAgg);
54
+ return order;
55
+ }
56
+ }
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ OracleQueryParser
60
+ });
@@ -0,0 +1,15 @@
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
+ import { Database } from '@nocobase/database';
10
+ import { PostgresFormatter } from '../formatter/postgres-formatter';
11
+ import { QueryParser } from './query-parser';
12
+ export declare class PostgresQueryParser extends QueryParser {
13
+ formatter: PostgresFormatter;
14
+ constructor(db: Database);
15
+ }
@@ -0,0 +1,43 @@
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
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var postgres_query_parser_exports = {};
28
+ __export(postgres_query_parser_exports, {
29
+ PostgresQueryParser: () => PostgresQueryParser
30
+ });
31
+ module.exports = __toCommonJS(postgres_query_parser_exports);
32
+ var import_postgres_formatter = require("../formatter/postgres-formatter");
33
+ var import_query_parser = require("./query-parser");
34
+ class PostgresQueryParser extends import_query_parser.QueryParser {
35
+ constructor(db) {
36
+ super(db);
37
+ this.formatter = new import_postgres_formatter.PostgresFormatter(db.sequelize);
38
+ }
39
+ }
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ PostgresQueryParser
43
+ });
@@ -0,0 +1,31 @@
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
+ import { Context, Next } from '@nocobase/actions';
10
+ import { DimensionProps, MeasureProps, OrderProps } from '../types';
11
+ import { Formatter } from '../formatter/formatter';
12
+ import { Database } from '@nocobase/database';
13
+ export declare class QueryParser {
14
+ db: Database;
15
+ formatter: Formatter;
16
+ constructor(db: Database);
17
+ parseMeasures(ctx: Context, measures: MeasureProps[]): {
18
+ attributes: any[];
19
+ fieldMap: {};
20
+ hasAgg: boolean;
21
+ };
22
+ parseDimensions(ctx: Context, dimensions: (DimensionProps & {
23
+ field: string;
24
+ })[], hasAgg: boolean, timezone: string): {
25
+ attributes: any[];
26
+ group: any[];
27
+ fieldMap: {};
28
+ };
29
+ parseOrders(ctx: Context, orders: OrderProps[], hasAgg: boolean): any[];
30
+ parse(): (ctx: Context, next: Next) => Promise<void>;
31
+ }
@@ -0,0 +1,134 @@
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
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var query_parser_exports = {};
28
+ __export(query_parser_exports, {
29
+ QueryParser: () => QueryParser
30
+ });
31
+ module.exports = __toCommonJS(query_parser_exports);
32
+ const AllowedAggFuncs = ["sum", "count", "avg", "min", "max"];
33
+ class QueryParser {
34
+ db;
35
+ formatter;
36
+ constructor(db) {
37
+ this.db = db;
38
+ this.formatter = {
39
+ format: ({ field }) => db.sequelize.col(field)
40
+ };
41
+ }
42
+ parseMeasures(ctx, measures) {
43
+ let hasAgg = false;
44
+ const sequelize = this.db.sequelize;
45
+ const attributes = [];
46
+ const fieldMap = {};
47
+ measures.forEach((measure) => {
48
+ const { field, aggregation, alias, distinct } = measure;
49
+ const attribute = [];
50
+ const col = sequelize.col(field);
51
+ if (aggregation) {
52
+ if (!AllowedAggFuncs.includes(aggregation)) {
53
+ throw new Error(`Invalid aggregation function: ${aggregation}`);
54
+ }
55
+ hasAgg = true;
56
+ attribute.push(sequelize.fn(aggregation, distinct ? sequelize.fn("DISTINCT", col) : col));
57
+ } else {
58
+ attribute.push(col);
59
+ }
60
+ if (alias) {
61
+ attribute.push(alias);
62
+ }
63
+ attributes.push(attribute.length > 1 ? attribute : attribute[0]);
64
+ fieldMap[alias || field] = measure;
65
+ });
66
+ return { attributes, fieldMap, hasAgg };
67
+ }
68
+ parseDimensions(ctx, dimensions, hasAgg, timezone) {
69
+ const sequelize = this.db.sequelize;
70
+ const attributes = [];
71
+ const group = [];
72
+ const fieldMap = {};
73
+ dimensions.forEach((dimension) => {
74
+ const { field, format, alias, type, options } = dimension;
75
+ const attribute = [];
76
+ const col = sequelize.col(field);
77
+ if (format) {
78
+ attribute.push(this.formatter.format({ type, field, format, timezone, options }));
79
+ } else {
80
+ attribute.push(col);
81
+ }
82
+ if (alias) {
83
+ attribute.push(alias);
84
+ }
85
+ attributes.push(attribute.length > 1 ? attribute : attribute[0]);
86
+ if (hasAgg) {
87
+ group.push(attribute[0]);
88
+ }
89
+ fieldMap[alias || field] = dimension;
90
+ });
91
+ return { attributes, group, fieldMap };
92
+ }
93
+ parseOrders(ctx, orders, hasAgg) {
94
+ const sequelize = this.db.sequelize;
95
+ const order = [];
96
+ orders.forEach((item) => {
97
+ const alias = sequelize.getQueryInterface().quoteIdentifier(item.alias);
98
+ const name = hasAgg ? sequelize.literal(alias) : sequelize.col(item.field);
99
+ order.push([name, item.order || "ASC"]);
100
+ });
101
+ return order;
102
+ }
103
+ parse() {
104
+ return async (ctx, next) => {
105
+ const { measures, dimensions, orders, include, where, limit } = ctx.action.params.values;
106
+ const { attributes: measureAttributes, fieldMap: measureFieldMap, hasAgg } = this.parseMeasures(ctx, measures);
107
+ const {
108
+ attributes: dimensionAttributes,
109
+ group,
110
+ fieldMap: dimensionFieldMap
111
+ } = this.parseDimensions(ctx, dimensions, hasAgg, ctx.timezone);
112
+ const order = this.parseOrders(ctx, orders, hasAgg);
113
+ ctx.action.params.values = {
114
+ ...ctx.action.params.values,
115
+ queryParams: {
116
+ where,
117
+ attributes: [...measureAttributes, ...dimensionAttributes],
118
+ include,
119
+ group,
120
+ order,
121
+ limit: limit || 2e3,
122
+ subQuery: false,
123
+ raw: true
124
+ },
125
+ fieldMap: { ...measureFieldMap, ...dimensionFieldMap }
126
+ };
127
+ await next();
128
+ };
129
+ }
130
+ }
131
+ // Annotate the CommonJS export names for ESM import in node:
132
+ 0 && (module.exports = {
133
+ QueryParser
134
+ });
@@ -0,0 +1,15 @@
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
+ import { Database } from '@nocobase/database';
10
+ import { SQLiteFormatter } from '../formatter/sqlite-formatter';
11
+ import { QueryParser } from './query-parser';
12
+ export declare class SQLiteQueryParser extends QueryParser {
13
+ formatter: SQLiteFormatter;
14
+ constructor(db: Database);
15
+ }
@@ -0,0 +1,43 @@
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
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var sqlite_query_parser_exports = {};
28
+ __export(sqlite_query_parser_exports, {
29
+ SQLiteQueryParser: () => SQLiteQueryParser
30
+ });
31
+ module.exports = __toCommonJS(sqlite_query_parser_exports);
32
+ var import_sqlite_formatter = require("../formatter/sqlite-formatter");
33
+ var import_query_parser = require("./query-parser");
34
+ class SQLiteQueryParser extends import_query_parser.QueryParser {
35
+ constructor(db) {
36
+ super(db);
37
+ this.formatter = new import_sqlite_formatter.SQLiteFormatter(db.sequelize);
38
+ }
39
+ }
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ SQLiteQueryParser
43
+ });
@@ -0,0 +1,46 @@
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
+ export type MeasureProps = {
10
+ field: string | string[];
11
+ type?: string;
12
+ aggregation?: string;
13
+ alias?: string;
14
+ distinct?: boolean;
15
+ };
16
+ export type DimensionProps = {
17
+ field: string | string[];
18
+ type?: string;
19
+ alias?: string;
20
+ format?: string;
21
+ options?: any;
22
+ };
23
+ export type OrderProps = {
24
+ field: string | string[];
25
+ alias?: string;
26
+ order?: 'asc' | 'desc';
27
+ };
28
+ export type QueryParams = Partial<{
29
+ uid: string;
30
+ dataSource: string;
31
+ collection: string;
32
+ measures: MeasureProps[];
33
+ dimensions: DimensionProps[];
34
+ orders: OrderProps[];
35
+ filter: any;
36
+ limit: number;
37
+ sql: {
38
+ fields?: string;
39
+ clauses?: string;
40
+ };
41
+ cache: {
42
+ enabled: boolean;
43
+ ttl: number;
44
+ };
45
+ refresh: boolean;
46
+ }>;
@@ -0,0 +1,24 @@
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
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
+ var types_exports = {};
24
+ module.exports = __toCommonJS(types_exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-data-visualization",
3
- "version": "1.4.0-alpha.20241020033334",
3
+ "version": "1.4.0-alpha.20241024133132",
4
4
  "displayName": "Data visualization",
5
5
  "displayName.zh-CN": "数据可视化",
6
6
  "description": "Provides data visualization feature, including chart block and chart filter block, support line charts, area charts, bar charts and more than a dozen kinds of charts, you can also extend more chart types.",
@@ -34,7 +34,7 @@
34
34
  "@nocobase/test": "1.x",
35
35
  "@nocobase/utils": "1.x"
36
36
  },
37
- "gitHead": "e99a8cf94fd0cf26db7fe7f82745d6345d80c48b",
37
+ "gitHead": "d127161994b06678d2d41f406fe73221242a1a05",
38
38
  "keywords": [
39
39
  "Blocks"
40
40
  ]
@@ -1,13 +0,0 @@
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
- import { Sequelize } from 'sequelize';
10
- import { SQLiteFormatter } from './sqlite-formatter';
11
- import { PostgresFormatter } from './postgres-formatter';
12
- import { MySQLFormatter } from './mysql-formatter';
13
- export declare const createFormatter: (sequelize: Sequelize) => SQLiteFormatter | PostgresFormatter | MySQLFormatter;
File without changes
File without changes