@nocobase/plugin-collection-sql 1.6.0-alpha.6 → 1.6.0-alpha.7
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/externalVersion.js
CHANGED
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "1.6.0-alpha.
|
|
12
|
-
"@nocobase/server": "1.6.0-alpha.
|
|
13
|
-
"@nocobase/database": "1.6.0-alpha.
|
|
14
|
-
"@nocobase/actions": "1.6.0-alpha.
|
|
11
|
+
"@nocobase/client": "1.6.0-alpha.7",
|
|
12
|
+
"@nocobase/server": "1.6.0-alpha.7",
|
|
13
|
+
"@nocobase/database": "1.6.0-alpha.7",
|
|
14
|
+
"@nocobase/actions": "1.6.0-alpha.7",
|
|
15
15
|
"sequelize": "6.35.2",
|
|
16
|
-
"@nocobase/utils": "1.6.0-alpha.
|
|
16
|
+
"@nocobase/utils": "1.6.0-alpha.7"
|
|
17
17
|
};
|
package/dist/server/plugin.js
CHANGED
|
@@ -43,6 +43,7 @@ module.exports = __toCommonJS(plugin_exports);
|
|
|
43
43
|
var import_server = require("@nocobase/server");
|
|
44
44
|
var import_sql_collection = require("./sql-collection");
|
|
45
45
|
var import_sql = __toESM(require("./resources/sql"));
|
|
46
|
+
var import_utils = require("./utils");
|
|
46
47
|
class PluginCollectionSQLServer extends import_server.Plugin {
|
|
47
48
|
async beforeLoad() {
|
|
48
49
|
this.app.db.collectionFactory.registerCollectionType(import_sql_collection.SQLCollection, {
|
|
@@ -61,6 +62,20 @@ class PluginCollectionSQLServer extends import_server.Plugin {
|
|
|
61
62
|
name: `pm.data-source-manager.collection-sql `,
|
|
62
63
|
actions: ["sqlCollection:*"]
|
|
63
64
|
});
|
|
65
|
+
this.app.resourceManager.use(async (ctx, next) => {
|
|
66
|
+
const { resourceName, actionName } = ctx.action;
|
|
67
|
+
if (resourceName === "collections" && actionName === "create") {
|
|
68
|
+
const { sql } = ctx.action.params.values || {};
|
|
69
|
+
if (sql) {
|
|
70
|
+
try {
|
|
71
|
+
(0, import_utils.checkSQL)(sql);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
ctx.throw(400, ctx.t(e.message));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return next();
|
|
78
|
+
});
|
|
64
79
|
}
|
|
65
80
|
}
|
|
66
81
|
var plugin_default = PluginCollectionSQLServer;
|
|
@@ -30,6 +30,7 @@ __export(sql_exports, {
|
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(sql_exports);
|
|
32
32
|
var import_sql_collection = require("../sql-collection");
|
|
33
|
+
var import_utils = require("../utils");
|
|
33
34
|
const updateCollection = async (ctx, transaction) => {
|
|
34
35
|
var _a;
|
|
35
36
|
const { filterByTk, values } = ctx.action.params;
|
|
@@ -66,13 +67,14 @@ var sql_default = {
|
|
|
66
67
|
name: "sqlCollection",
|
|
67
68
|
actions: {
|
|
68
69
|
execute: async (ctx, next) => {
|
|
69
|
-
|
|
70
|
+
const { sql } = ctx.action.params.values || {};
|
|
70
71
|
if (!sql) {
|
|
71
72
|
ctx.throw(400, ctx.t("Please enter a SQL statement"));
|
|
72
73
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
try {
|
|
75
|
+
(0, import_utils.checkSQL)(sql);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
ctx.throw(400, ctx.t(e.message));
|
|
76
78
|
}
|
|
77
79
|
const tmpCollection = new import_sql_collection.SQLCollection({ name: "tmp", sql }, { database: ctx.db });
|
|
78
80
|
const model = tmpCollection.model;
|
|
@@ -0,0 +1,9 @@
|
|
|
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 declare const checkSQL: (sql: string) => void;
|
|
@@ -0,0 +1,67 @@
|
|
|
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 utils_exports = {};
|
|
28
|
+
__export(utils_exports, {
|
|
29
|
+
checkSQL: () => checkSQL
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(utils_exports);
|
|
32
|
+
const checkSQL = (sql) => {
|
|
33
|
+
const dangerKeywords = [
|
|
34
|
+
// PostgreSQL
|
|
35
|
+
"pg_read_file",
|
|
36
|
+
"pg_read_binary_file",
|
|
37
|
+
"pg_stat_file",
|
|
38
|
+
"pg_ls_dir",
|
|
39
|
+
"pg_logdir_ls",
|
|
40
|
+
"pg_terminate_backend",
|
|
41
|
+
"pg_cancel_backend",
|
|
42
|
+
"current_setting",
|
|
43
|
+
"set_config",
|
|
44
|
+
"pg_reload_conf",
|
|
45
|
+
"pg_sleep",
|
|
46
|
+
"generate_series",
|
|
47
|
+
// MySQL
|
|
48
|
+
"LOAD_FILE",
|
|
49
|
+
"BENCHMARK",
|
|
50
|
+
"@@global.",
|
|
51
|
+
"@@session.",
|
|
52
|
+
// SQLite
|
|
53
|
+
"sqlite3_load_extension",
|
|
54
|
+
"load_extension"
|
|
55
|
+
];
|
|
56
|
+
sql = sql.trim().split(";").shift();
|
|
57
|
+
if (!/^select/i.test(sql) && !/^with([\s\S]+)select([\s\S]+)/i.test(sql)) {
|
|
58
|
+
throw new Error("Only supports SELECT statements or WITH clauses");
|
|
59
|
+
}
|
|
60
|
+
if (dangerKeywords.some((keyword) => sql.toLowerCase().includes(keyword.toLowerCase()))) {
|
|
61
|
+
throw new Error("SQL statements contain dangerous keywords");
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
checkSQL
|
|
67
|
+
});
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"displayName.zh-CN": "数据表: SQL",
|
|
5
5
|
"description": "Provides SQL collection template",
|
|
6
6
|
"description.zh-CN": "提供 SQL 数据表模板",
|
|
7
|
-
"version": "1.6.0-alpha.
|
|
7
|
+
"version": "1.6.0-alpha.7",
|
|
8
8
|
"homepage": "https://docs-cn.nocobase.com/handbook/collection-sql",
|
|
9
9
|
"homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/collection-sql",
|
|
10
10
|
"main": "dist/server/index.js",
|
|
@@ -17,5 +17,5 @@
|
|
|
17
17
|
"keywords": [
|
|
18
18
|
"Collections"
|
|
19
19
|
],
|
|
20
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "d9552440f5e3ce2795c9f2f23a1b04f5376a1550"
|
|
21
21
|
}
|