@nocobase/plugin-data-visualization 1.4.0-alpha.20240910145333 → 1.4.0-alpha.20240914084300
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/dist/client/filter/utils.d.ts +2 -1
- package/dist/client/index.js +24 -24
- package/dist/externalVersion.js +7 -7
- package/dist/node_modules/koa-compose/package.json +1 -1
- package/dist/node_modules/moment-timezone/LICENSE +20 -0
- package/dist/node_modules/moment-timezone/builds/moment-timezone-with-data-10-year-range.js +1548 -0
- package/dist/node_modules/moment-timezone/builds/moment-timezone-with-data-10-year-range.min.js +1 -0
- package/dist/node_modules/moment-timezone/builds/moment-timezone-with-data-1970-2030.js +1548 -0
- package/dist/node_modules/moment-timezone/builds/moment-timezone-with-data-1970-2030.min.js +1 -0
- package/dist/node_modules/moment-timezone/builds/moment-timezone-with-data-2012-2022.js +1560 -0
- package/dist/node_modules/moment-timezone/builds/moment-timezone-with-data-2012-2022.min.js +1 -0
- package/dist/node_modules/moment-timezone/builds/moment-timezone-with-data.js +1548 -0
- package/dist/node_modules/moment-timezone/builds/moment-timezone-with-data.min.js +1 -0
- package/dist/node_modules/moment-timezone/builds/moment-timezone.min.js +1 -0
- package/dist/node_modules/moment-timezone/composer.json +43 -0
- package/dist/node_modules/moment-timezone/data/meta/latest.json +5889 -0
- package/dist/node_modules/moment-timezone/data/packed/latest.json +852 -0
- package/dist/node_modules/moment-timezone/index.d.ts +78 -0
- package/dist/node_modules/moment-timezone/index.js +15 -0
- package/dist/node_modules/moment-timezone/moment-timezone-utils.d.ts +70 -0
- package/dist/node_modules/moment-timezone/moment-timezone-utils.js +339 -0
- package/dist/node_modules/moment-timezone/moment-timezone.js +696 -0
- package/dist/node_modules/moment-timezone/package.json +1 -0
- package/dist/server/actions/query.js +10 -6
- package/dist/server/formatter/formatter.d.ts +27 -0
- package/dist/server/formatter/formatter.js +85 -0
- package/dist/server/formatter/index.d.ts +13 -0
- package/dist/server/formatter/index.js +50 -0
- package/dist/server/formatter/mysql-formatter.d.ts +14 -0
- package/dist/server/formatter/mysql-formatter.js +86 -0
- package/dist/server/formatter/postgres-formatter.d.ts +14 -0
- package/dist/server/formatter/postgres-formatter.js +74 -0
- package/dist/server/formatter/sqlite-formatter.d.ts +15 -0
- package/dist/server/formatter/sqlite-formatter.js +83 -0
- package/package.json +2 -2
- package/dist/server/actions/formatter.d.ts +0 -12
- package/dist/server/actions/formatter.js +0 -101
|
@@ -47,9 +47,9 @@ __export(query_exports, {
|
|
|
47
47
|
});
|
|
48
48
|
module.exports = __toCommonJS(query_exports);
|
|
49
49
|
var import_database = require("@nocobase/database");
|
|
50
|
-
var import_formatter = require("./formatter");
|
|
51
50
|
var import_koa_compose = __toESM(require("koa-compose"));
|
|
52
51
|
var import_server = require("@nocobase/server");
|
|
52
|
+
var import_formatter = require("../formatter");
|
|
53
53
|
const AllowedAggFuncs = ["sum", "count", "avg", "min", "max"];
|
|
54
54
|
const getDB = (ctx, dataSource) => {
|
|
55
55
|
const ds = ctx.app.dataSourceManager.dataSources.get(dataSource);
|
|
@@ -117,11 +117,12 @@ const parseBuilder = async (ctx, next) => {
|
|
|
117
117
|
fieldMap[alias || field] = measure;
|
|
118
118
|
});
|
|
119
119
|
dimensions.forEach((dimension) => {
|
|
120
|
-
const { field, format, alias, type } = dimension;
|
|
120
|
+
const { field, format, alias, type, options } = dimension;
|
|
121
121
|
const attribute = [];
|
|
122
122
|
const col = sequelize.col(field);
|
|
123
123
|
if (format) {
|
|
124
|
-
|
|
124
|
+
const formatter = (0, import_formatter.createFormatter)(sequelize);
|
|
125
|
+
attribute.push(formatter.format({ type, field, format, timezone: ctx.timezone, options }));
|
|
125
126
|
} else {
|
|
126
127
|
attribute.push(col);
|
|
127
128
|
}
|
|
@@ -170,7 +171,7 @@ const parseFieldAndAssociations = async (ctx, next) => {
|
|
|
170
171
|
const associations = collection.model.associations;
|
|
171
172
|
const models = {};
|
|
172
173
|
const parseField = (selected) => {
|
|
173
|
-
var _a, _b, _c, _d;
|
|
174
|
+
var _a, _b, _c, _d, _e, _f;
|
|
174
175
|
let target;
|
|
175
176
|
let name;
|
|
176
177
|
if (!Array.isArray(selected.field)) {
|
|
@@ -183,14 +184,16 @@ const parseFieldAndAssociations = async (ctx, next) => {
|
|
|
183
184
|
const rawAttributes = collection.model.getAttributes();
|
|
184
185
|
let field = ((_a = rawAttributes[name]) == null ? void 0 : _a.field) || name;
|
|
185
186
|
let fieldType = (_b = fields.get(name)) == null ? void 0 : _b.type;
|
|
187
|
+
let fieldOptions = (_c = fields.get(name)) == null ? void 0 : _c.options;
|
|
186
188
|
if (target) {
|
|
187
189
|
const targetField = fields.get(target);
|
|
188
190
|
const targetCollection = db.getCollection(targetField.target);
|
|
189
191
|
const targetFields = targetCollection.fields;
|
|
190
|
-
fieldType = (
|
|
192
|
+
fieldType = (_d = targetFields.get(name)) == null ? void 0 : _d.type;
|
|
193
|
+
fieldOptions = (_e = targetFields.get(name)) == null ? void 0 : _e.options;
|
|
191
194
|
field = `${target}.${field}`;
|
|
192
195
|
name = `${target}.${name}`;
|
|
193
|
-
const targetType = (
|
|
196
|
+
const targetType = (_f = fields.get(target)) == null ? void 0 : _f.type;
|
|
194
197
|
if (!models[target]) {
|
|
195
198
|
models[target] = { type: targetType };
|
|
196
199
|
}
|
|
@@ -202,6 +205,7 @@ const parseFieldAndAssociations = async (ctx, next) => {
|
|
|
202
205
|
field,
|
|
203
206
|
name,
|
|
204
207
|
type: fieldType,
|
|
208
|
+
options: fieldOptions,
|
|
205
209
|
alias: selected.alias || name
|
|
206
210
|
};
|
|
207
211
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
export type Col = ReturnType<typeof Sequelize.col>;
|
|
11
|
+
export type Literal = ReturnType<typeof Sequelize.literal>;
|
|
12
|
+
export type Fn = ReturnType<typeof Sequelize.fn>;
|
|
13
|
+
export declare abstract class Formatter {
|
|
14
|
+
sequelize: Sequelize;
|
|
15
|
+
constructor(sequelize: Sequelize);
|
|
16
|
+
abstract formatDate(field: Col, format: string, timezone?: string): Fn | Col;
|
|
17
|
+
abstract formatUnixTimeStamp(field: string, format: string, accuracy?: 'second' | 'millisecond', timezone?: string): Fn | Literal;
|
|
18
|
+
getTimezoneByOffset(offset: string): string;
|
|
19
|
+
convertFormat(format: string): string;
|
|
20
|
+
format(options: {
|
|
21
|
+
type: string;
|
|
22
|
+
field: string;
|
|
23
|
+
format: string;
|
|
24
|
+
options?: any;
|
|
25
|
+
timezone?: string;
|
|
26
|
+
}): import("sequelize/types/utils").Col | import("sequelize/types/utils").Literal | import("sequelize/types/utils").Fn;
|
|
27
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
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 __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
var formatter_exports = {};
|
|
38
|
+
__export(formatter_exports, {
|
|
39
|
+
Formatter: () => Formatter
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(formatter_exports);
|
|
42
|
+
var import_moment_timezone = __toESM(require("moment-timezone"));
|
|
43
|
+
class Formatter {
|
|
44
|
+
sequelize;
|
|
45
|
+
constructor(sequelize) {
|
|
46
|
+
this.sequelize = sequelize;
|
|
47
|
+
}
|
|
48
|
+
getTimezoneByOffset(offset) {
|
|
49
|
+
if (!/^[+-]\d{1,2}:\d{2}$/.test(offset)) {
|
|
50
|
+
return offset;
|
|
51
|
+
}
|
|
52
|
+
const offsetMinutes = import_moment_timezone.default.duration(offset).asMinutes();
|
|
53
|
+
return import_moment_timezone.default.tz.names().find((timezone) => {
|
|
54
|
+
return import_moment_timezone.default.tz(timezone).utcOffset() === offsetMinutes;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
convertFormat(format) {
|
|
58
|
+
return format;
|
|
59
|
+
}
|
|
60
|
+
format(options) {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
const { type, field, format, timezone, options: fieldOptions } = options;
|
|
63
|
+
const col = this.sequelize.col(field);
|
|
64
|
+
switch (type) {
|
|
65
|
+
case "date":
|
|
66
|
+
case "datetime":
|
|
67
|
+
case "datetimeTz":
|
|
68
|
+
return this.formatDate(col, format, timezone);
|
|
69
|
+
case "datetimeNoTz":
|
|
70
|
+
case "dateOnly":
|
|
71
|
+
case "time":
|
|
72
|
+
return this.formatDate(col, format);
|
|
73
|
+
case "unixTimestamp": {
|
|
74
|
+
const accuracy = ((_b = (_a = fieldOptions == null ? void 0 : fieldOptions.uiSchema) == null ? void 0 : _a["x-component-props"]) == null ? void 0 : _b.accuracy) || (fieldOptions == null ? void 0 : fieldOptions.accuracy) || "second";
|
|
75
|
+
return this.formatUnixTimeStamp(field, format, accuracy, timezone);
|
|
76
|
+
}
|
|
77
|
+
default:
|
|
78
|
+
return this.sequelize.col(field);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
+
0 && (module.exports = {
|
|
84
|
+
Formatter
|
|
85
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
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;
|
|
@@ -0,0 +1,50 @@
|
|
|
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 formatter_exports = {};
|
|
28
|
+
__export(formatter_exports, {
|
|
29
|
+
createFormatter: () => createFormatter
|
|
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);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
createFormatter
|
|
50
|
+
});
|
|
@@ -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 MySQLFormatter 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,86 @@
|
|
|
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 mysql_formatter_exports = {};
|
|
28
|
+
__export(mysql_formatter_exports, {
|
|
29
|
+
MySQLFormatter: () => MySQLFormatter
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(mysql_formatter_exports);
|
|
32
|
+
var import_formatter = require("./formatter");
|
|
33
|
+
class MySQLFormatter extends import_formatter.Formatter {
|
|
34
|
+
convertFormat(format) {
|
|
35
|
+
return format.replace(/YYYY/g, "%Y").replace(/MM/g, "%m").replace(/DD/g, "%d").replace(/hh/g, "%H").replace(/mm/g, "%i").replace(/ss/g, "%S");
|
|
36
|
+
}
|
|
37
|
+
formatDate(field, format, timezoneOffset) {
|
|
38
|
+
const timezone = this.getTimezoneByOffset(timezoneOffset);
|
|
39
|
+
format = this.convertFormat(format);
|
|
40
|
+
if (timezone) {
|
|
41
|
+
return this.sequelize.fn(
|
|
42
|
+
"date_format",
|
|
43
|
+
this.sequelize.fn("convert_tz", field, process.env.TZ || "UTC", timezone),
|
|
44
|
+
format
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return this.sequelize.fn("date_format", field, format);
|
|
48
|
+
}
|
|
49
|
+
formatUnixTimeStamp(field, format, accuracy = "second", timezoneOffset) {
|
|
50
|
+
const col = this.sequelize.getQueryInterface().quoteIdentifiers(field);
|
|
51
|
+
const timezone = this.getTimezoneByOffset(timezoneOffset);
|
|
52
|
+
format = this.convertFormat(format);
|
|
53
|
+
if (timezone) {
|
|
54
|
+
if (accuracy === "millisecond") {
|
|
55
|
+
return this.sequelize.fn(
|
|
56
|
+
"date_format",
|
|
57
|
+
this.sequelize.fn(
|
|
58
|
+
"convert_tz",
|
|
59
|
+
this.sequelize.fn("from_unixtime", this.sequelize.literal(`ROUND(${col} / 1000)`)),
|
|
60
|
+
process.env.TZ || "UTC",
|
|
61
|
+
timezone
|
|
62
|
+
),
|
|
63
|
+
format
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return this.sequelize.fn(
|
|
67
|
+
"date_format",
|
|
68
|
+
this.sequelize.fn(
|
|
69
|
+
"convert_tz",
|
|
70
|
+
this.sequelize.fn("from_unixtime", this.sequelize.col(field)),
|
|
71
|
+
process.env.TZ || "UTC",
|
|
72
|
+
timezone
|
|
73
|
+
),
|
|
74
|
+
format
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
if (accuracy === "millisecond") {
|
|
78
|
+
return this.sequelize.fn("from_unixtime", this.sequelize.literal(`ROUND(${col} / 1000)`), format);
|
|
79
|
+
}
|
|
80
|
+
return this.sequelize.fn("from_unixtime", this.sequelize.col(field), format);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
MySQLFormatter
|
|
86
|
+
});
|
|
@@ -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 PostgresFormatter 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 postgres_formatter_exports = {};
|
|
28
|
+
__export(postgres_formatter_exports, {
|
|
29
|
+
PostgresFormatter: () => PostgresFormatter
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(postgres_formatter_exports);
|
|
32
|
+
var import_formatter = require("./formatter");
|
|
33
|
+
class PostgresFormatter 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
|
+
PostgresFormatter
|
|
74
|
+
});
|
|
@@ -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 { Col, Formatter } from './formatter';
|
|
10
|
+
export declare class SQLiteFormatter extends Formatter {
|
|
11
|
+
convertFormat(format: string): string;
|
|
12
|
+
getOffsetMinutesFromTimezone(timezone: string): string;
|
|
13
|
+
formatDate(field: Col, format: string, timezone?: string): import("sequelize/types/utils").Fn;
|
|
14
|
+
formatUnixTimeStamp(field: string, format: string, accuracy?: 'second' | 'millisecond', timezone?: string): import("sequelize/types/utils").Fn;
|
|
15
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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_formatter_exports = {};
|
|
28
|
+
__export(sqlite_formatter_exports, {
|
|
29
|
+
SQLiteFormatter: () => SQLiteFormatter
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(sqlite_formatter_exports);
|
|
32
|
+
var import_formatter = require("./formatter");
|
|
33
|
+
class SQLiteFormatter extends import_formatter.Formatter {
|
|
34
|
+
convertFormat(format) {
|
|
35
|
+
return format.replace(/YYYY/g, "%Y").replace(/MM/g, "%m").replace(/DD/g, "%d").replace(/hh/g, "%H").replace(/mm/g, "%M").replace(/ss/g, "%S");
|
|
36
|
+
}
|
|
37
|
+
getOffsetMinutesFromTimezone(timezone) {
|
|
38
|
+
const sign = timezone.charAt(0);
|
|
39
|
+
timezone = timezone.slice(1);
|
|
40
|
+
const [hours, minutes] = timezone.split(":");
|
|
41
|
+
const hoursNum = Number(hours);
|
|
42
|
+
const minutesNum = Number(minutes);
|
|
43
|
+
const offset = hoursNum * 60 + minutesNum;
|
|
44
|
+
return `${sign}${offset} minutes`;
|
|
45
|
+
}
|
|
46
|
+
formatDate(field, format, timezone) {
|
|
47
|
+
format = this.convertFormat(format);
|
|
48
|
+
if (timezone) {
|
|
49
|
+
return this.sequelize.fn("strftime", format, field, this.getOffsetMinutesFromTimezone(timezone));
|
|
50
|
+
}
|
|
51
|
+
return this.sequelize.fn("strftime", format, field);
|
|
52
|
+
}
|
|
53
|
+
formatUnixTimeStamp(field, format, accuracy = "second", timezone) {
|
|
54
|
+
format = this.convertFormat(format);
|
|
55
|
+
const col = this.sequelize.getQueryInterface().quoteIdentifiers(field);
|
|
56
|
+
if (accuracy === "millisecond") {
|
|
57
|
+
return this.sequelize.fn(
|
|
58
|
+
"strftime",
|
|
59
|
+
format,
|
|
60
|
+
this.sequelize.fn(
|
|
61
|
+
"DATETIME",
|
|
62
|
+
this.sequelize.literal(`ROUND(${col} / 1000)`),
|
|
63
|
+
"unixepoch",
|
|
64
|
+
this.getOffsetMinutesFromTimezone(timezone)
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
return this.sequelize.fn(
|
|
69
|
+
"strftime",
|
|
70
|
+
format,
|
|
71
|
+
this.sequelize.fn(
|
|
72
|
+
"DATETIME",
|
|
73
|
+
this.sequelize.col(field),
|
|
74
|
+
"unixepoch",
|
|
75
|
+
this.getOffsetMinutesFromTimezone(timezone)
|
|
76
|
+
)
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
SQLiteFormatter
|
|
83
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-data-visualization",
|
|
3
|
-
"version": "1.4.0-alpha.
|
|
3
|
+
"version": "1.4.0-alpha.20240914084300",
|
|
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": "
|
|
37
|
+
"gitHead": "9134514363875955f57ad07a311bb84783fc3399",
|
|
38
38
|
"keywords": [
|
|
39
39
|
"Blocks"
|
|
40
40
|
]
|
|
@@ -1,12 +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
|
-
export declare const dateFormatFn: (sequelize: Sequelize, dialect: string, field: string, format: string, timezone?: string) => import("sequelize/types/utils").Col | import("sequelize/types/utils").Fn;
|
|
11
|
-
export declare const formatFn: (sequelize: Sequelize, dialect: string, field: string, format: string) => string | import("sequelize/types/utils").Fn;
|
|
12
|
-
export declare const formatter: (sequelize: Sequelize, type: string, field: string, format: string, timezone?: string) => string | import("sequelize/types/utils").Col | import("sequelize/types/utils").Fn;
|
|
@@ -1,101 +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
|
-
|
|
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 formatter_exports = {};
|
|
28
|
-
__export(formatter_exports, {
|
|
29
|
-
dateFormatFn: () => dateFormatFn,
|
|
30
|
-
formatFn: () => formatFn,
|
|
31
|
-
formatter: () => formatter
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(formatter_exports);
|
|
34
|
-
const getOffsetMinutesFromTimezone = (timezone) => {
|
|
35
|
-
const sign = timezone.charAt(0);
|
|
36
|
-
timezone = timezone.slice(1);
|
|
37
|
-
const [hours, minutes] = timezone.split(":");
|
|
38
|
-
const hoursNum = Number(hours);
|
|
39
|
-
const minutesNum = Number(minutes);
|
|
40
|
-
const offset = hoursNum * 60 + minutesNum;
|
|
41
|
-
return `${sign}${offset} minutes`;
|
|
42
|
-
};
|
|
43
|
-
const dateFormatFn = (sequelize, dialect, field, format, timezone) => {
|
|
44
|
-
switch (dialect) {
|
|
45
|
-
case "sqlite":
|
|
46
|
-
format = format.replace(/YYYY/g, "%Y").replace(/MM/g, "%m").replace(/DD/g, "%d").replace(/hh/g, "%H").replace(/mm/g, "%M").replace(/ss/g, "%S");
|
|
47
|
-
if (timezone) {
|
|
48
|
-
return sequelize.fn("strftime", format, sequelize.col(field), getOffsetMinutesFromTimezone(timezone));
|
|
49
|
-
}
|
|
50
|
-
return sequelize.fn("strftime", format, sequelize.col(field));
|
|
51
|
-
case "mysql":
|
|
52
|
-
case "mariadb":
|
|
53
|
-
format = format.replace(/YYYY/g, "%Y").replace(/MM/g, "%m").replace(/DD/g, "%d").replace(/hh/g, "%H").replace(/mm/g, "%i").replace(/ss/g, "%S");
|
|
54
|
-
if (timezone) {
|
|
55
|
-
return sequelize.fn(
|
|
56
|
-
"date_format",
|
|
57
|
-
sequelize.fn("convert_tz", sequelize.col(field), process.env.DB_TIMEZONE || "+00:00", timezone),
|
|
58
|
-
format
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
return sequelize.fn("date_format", sequelize.col(field), format);
|
|
62
|
-
case "postgres":
|
|
63
|
-
format = format.replace(/hh/g, "HH24").replace(/mm/g, "MI").replace(/ss/g, "SS");
|
|
64
|
-
if (timezone) {
|
|
65
|
-
const fieldWithTZ = sequelize.literal(
|
|
66
|
-
`(${sequelize.getQueryInterface().quoteIdentifiers(field)} AT TIME ZONE CURRENT_SETTING('TIMEZONE') AT TIME ZONE '${timezone}')`
|
|
67
|
-
);
|
|
68
|
-
return sequelize.fn("to_char", fieldWithTZ, format);
|
|
69
|
-
}
|
|
70
|
-
return sequelize.fn("to_char", sequelize.col(field), format);
|
|
71
|
-
default:
|
|
72
|
-
return sequelize.col(field);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
/* istanbul ignore next -- @preserve */
|
|
76
|
-
const formatFn = (sequelize, dialect, field, format) => {
|
|
77
|
-
switch (dialect) {
|
|
78
|
-
case "sqlite":
|
|
79
|
-
case "postgres":
|
|
80
|
-
return sequelize.fn("format", format, sequelize.col(field));
|
|
81
|
-
default:
|
|
82
|
-
return field;
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
const formatter = (sequelize, type, field, format, timezone) => {
|
|
86
|
-
const dialect = sequelize.getDialect();
|
|
87
|
-
switch (type) {
|
|
88
|
-
case "date":
|
|
89
|
-
case "datetime":
|
|
90
|
-
case "time":
|
|
91
|
-
return dateFormatFn(sequelize, dialect, field, format, timezone);
|
|
92
|
-
default:
|
|
93
|
-
return formatFn(sequelize, dialect, field, format);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
97
|
-
0 && (module.exports = {
|
|
98
|
-
dateFormatFn,
|
|
99
|
-
formatFn,
|
|
100
|
-
formatter
|
|
101
|
-
});
|