@nocobase/plugin-workflow-sql 2.1.0-beta.2 → 2.1.0-beta.21
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/LICENSE +201 -661
- package/README.md +79 -10
- package/dist/client/SQLInstruction.d.ts +76 -2
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +11 -7
- package/dist/locale/de-DE.json +9 -2
- package/dist/locale/en-US.json +9 -1
- package/dist/locale/es-ES.json +9 -2
- package/dist/locale/fr-FR.json +9 -2
- package/dist/locale/hu-HU.json +9 -2
- package/dist/locale/id-ID.json +9 -2
- package/dist/locale/it-IT.json +9 -2
- package/dist/locale/ja-JP.json +9 -2
- package/dist/locale/ko-KR.json +9 -2
- package/dist/locale/nl-NL.json +9 -2
- package/dist/locale/pt-BR.json +9 -2
- package/dist/locale/ru-RU.json +9 -2
- package/dist/locale/tr-TR.json +9 -2
- package/dist/locale/uk-UA.json +9 -2
- package/dist/locale/vi-VN.json +9 -2
- package/dist/locale/zh-CN.json +10 -2
- package/dist/locale/zh-TW.json +10 -3
- package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
- package/dist/node_modules/joi/lib/annotate.js +175 -0
- package/dist/node_modules/joi/lib/base.js +1069 -0
- package/dist/node_modules/joi/lib/cache.js +143 -0
- package/dist/node_modules/joi/lib/common.js +216 -0
- package/dist/node_modules/joi/lib/compile.js +283 -0
- package/dist/node_modules/joi/lib/errors.js +271 -0
- package/dist/node_modules/joi/lib/extend.js +312 -0
- package/dist/node_modules/joi/lib/index.d.ts +2365 -0
- package/dist/node_modules/joi/lib/index.js +1 -0
- package/dist/node_modules/joi/lib/manifest.js +476 -0
- package/dist/node_modules/joi/lib/messages.js +178 -0
- package/dist/node_modules/joi/lib/modify.js +267 -0
- package/dist/node_modules/joi/lib/ref.js +414 -0
- package/dist/node_modules/joi/lib/schemas.js +302 -0
- package/dist/node_modules/joi/lib/state.js +166 -0
- package/dist/node_modules/joi/lib/template.js +463 -0
- package/dist/node_modules/joi/lib/trace.js +346 -0
- package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
- package/dist/node_modules/joi/lib/types/any.js +174 -0
- package/dist/node_modules/joi/lib/types/array.js +809 -0
- package/dist/node_modules/joi/lib/types/binary.js +100 -0
- package/dist/node_modules/joi/lib/types/boolean.js +150 -0
- package/dist/node_modules/joi/lib/types/date.js +233 -0
- package/dist/node_modules/joi/lib/types/function.js +93 -0
- package/dist/node_modules/joi/lib/types/keys.js +1067 -0
- package/dist/node_modules/joi/lib/types/link.js +168 -0
- package/dist/node_modules/joi/lib/types/number.js +363 -0
- package/dist/node_modules/joi/lib/types/object.js +22 -0
- package/dist/node_modules/joi/lib/types/string.js +850 -0
- package/dist/node_modules/joi/lib/types/symbol.js +102 -0
- package/dist/node_modules/joi/lib/validator.js +750 -0
- package/dist/node_modules/joi/lib/values.js +263 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
- package/dist/node_modules/joi/package.json +1 -0
- package/dist/server/SQLInstruction.d.ts +8 -1
- package/dist/server/SQLInstruction.js +62 -5
- package/dist/server/migrations/20260327120000-add-unsafe-injection-flag.d.ts +13 -0
- package/dist/server/migrations/20260327120000-add-unsafe-injection-flag.js +65 -0
- package/package.json +4 -3
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
var __create = Object.create;
|
|
10
11
|
var __defProp = Object.defineProperty;
|
|
11
12
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
13
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
15
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
16
|
var __export = (target, all) => {
|
|
15
17
|
for (var name in all)
|
|
@@ -23,6 +25,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
23
25
|
}
|
|
24
26
|
return to;
|
|
25
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
|
+
));
|
|
26
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
37
|
var SQLInstruction_exports = {};
|
|
28
38
|
__export(SQLInstruction_exports, {
|
|
@@ -31,21 +41,49 @@ __export(SQLInstruction_exports, {
|
|
|
31
41
|
module.exports = __toCommonJS(SQLInstruction_exports);
|
|
32
42
|
var import_data_source_manager = require("@nocobase/data-source-manager");
|
|
33
43
|
var import_plugin_workflow = require("@nocobase/plugin-workflow");
|
|
44
|
+
var import_joi = __toESM(require("joi"));
|
|
34
45
|
class SQLInstruction_default extends import_plugin_workflow.Instruction {
|
|
46
|
+
configSchema = import_joi.default.object({
|
|
47
|
+
dataSource: import_joi.default.string(),
|
|
48
|
+
sql: import_joi.default.string(),
|
|
49
|
+
withMeta: import_joi.default.boolean().default(false),
|
|
50
|
+
unsafeInjection: import_joi.default.boolean().default(false),
|
|
51
|
+
variables: import_joi.default.array().items(
|
|
52
|
+
import_joi.default.object({
|
|
53
|
+
name: import_joi.default.string().required(),
|
|
54
|
+
value: import_joi.default.any()
|
|
55
|
+
})
|
|
56
|
+
)
|
|
57
|
+
});
|
|
35
58
|
async run(node, input, processor) {
|
|
36
59
|
const dataSourceName = node.config.dataSource || "main";
|
|
37
60
|
const { collectionManager } = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName);
|
|
38
61
|
if (!(collectionManager instanceof import_data_source_manager.SequelizeCollectionManager)) {
|
|
39
62
|
throw new Error(`type of data source "${node.config.dataSource}" is not database`);
|
|
40
63
|
}
|
|
41
|
-
const
|
|
64
|
+
const { unsafeInjection = false, variables = [] } = node.config;
|
|
65
|
+
let sql = "";
|
|
66
|
+
let replacements = null;
|
|
67
|
+
if (unsafeInjection) {
|
|
68
|
+
sql = processor.getParsedValue(node.config.sql || "", node.id).trim();
|
|
69
|
+
} else {
|
|
70
|
+
sql = (node.config.sql || "").trim();
|
|
71
|
+
const parameters = processor.getParsedValue(variables, node.id);
|
|
72
|
+
replacements = {};
|
|
73
|
+
for (const { name, value } of parameters) {
|
|
74
|
+
if (name) {
|
|
75
|
+
replacements[name] = value;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
42
79
|
if (!sql) {
|
|
43
80
|
return {
|
|
44
81
|
status: import_plugin_workflow.JOB_STATUS.RESOLVED
|
|
45
82
|
};
|
|
46
83
|
}
|
|
47
84
|
const [result = null, meta = null] = await collectionManager.db.sequelize.query(sql, {
|
|
48
|
-
transaction: this.workflow.useDataSourceTransaction(dataSourceName, processor.transaction)
|
|
85
|
+
transaction: this.workflow.useDataSourceTransaction(dataSourceName, processor.transaction),
|
|
86
|
+
replacements
|
|
49
87
|
// plain: true,
|
|
50
88
|
// model: db.getCollection(node.config.collection).model
|
|
51
89
|
}) ?? [];
|
|
@@ -54,8 +92,14 @@ class SQLInstruction_default extends import_plugin_workflow.Instruction {
|
|
|
54
92
|
status: import_plugin_workflow.JOB_STATUS.RESOLVED
|
|
55
93
|
};
|
|
56
94
|
}
|
|
57
|
-
async test({
|
|
58
|
-
|
|
95
|
+
async test({
|
|
96
|
+
dataSource,
|
|
97
|
+
sql: sqlConfig,
|
|
98
|
+
withMeta,
|
|
99
|
+
unsafeInjection = false,
|
|
100
|
+
variables = []
|
|
101
|
+
} = {}) {
|
|
102
|
+
if (!sqlConfig) {
|
|
59
103
|
return {
|
|
60
104
|
result: null,
|
|
61
105
|
status: import_plugin_workflow.JOB_STATUS.RESOLVED
|
|
@@ -67,7 +111,20 @@ class SQLInstruction_default extends import_plugin_workflow.Instruction {
|
|
|
67
111
|
throw new Error(`type of data source "${dataSource}" is not database`);
|
|
68
112
|
}
|
|
69
113
|
try {
|
|
70
|
-
|
|
114
|
+
let sql = "";
|
|
115
|
+
let replacements = null;
|
|
116
|
+
if (unsafeInjection) {
|
|
117
|
+
sql = sqlConfig.trim();
|
|
118
|
+
} else {
|
|
119
|
+
sql = sqlConfig.trim();
|
|
120
|
+
replacements = {};
|
|
121
|
+
for (const { name, value } of variables) {
|
|
122
|
+
if (name) {
|
|
123
|
+
replacements[name] = value;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const [result = null, meta = null] = await collectionManager.db.sequelize.query(sql, { replacements }) ?? [];
|
|
71
128
|
return {
|
|
72
129
|
result: withMeta ? [result, meta] : result,
|
|
73
130
|
status: import_plugin_workflow.JOB_STATUS.RESOLVED
|
|
@@ -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 { Migration } from '@nocobase/server';
|
|
10
|
+
export default class extends Migration {
|
|
11
|
+
appVersion: string;
|
|
12
|
+
up(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 add_unsafe_injection_flag_exports = {};
|
|
28
|
+
__export(add_unsafe_injection_flag_exports, {
|
|
29
|
+
default: () => add_unsafe_injection_flag_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(add_unsafe_injection_flag_exports);
|
|
32
|
+
var import_server = require("@nocobase/server");
|
|
33
|
+
var import_utils = require("@nocobase/utils");
|
|
34
|
+
class add_unsafe_injection_flag_default extends import_server.Migration {
|
|
35
|
+
appVersion = "<2.0.30";
|
|
36
|
+
async up() {
|
|
37
|
+
const { db } = this.context;
|
|
38
|
+
const NodeRepo = db.getRepository("flow_nodes");
|
|
39
|
+
await db.sequelize.transaction(async (transaction) => {
|
|
40
|
+
const nodes = await NodeRepo.find({
|
|
41
|
+
filter: {
|
|
42
|
+
type: "sql"
|
|
43
|
+
},
|
|
44
|
+
transaction
|
|
45
|
+
});
|
|
46
|
+
await nodes.reduce(
|
|
47
|
+
(promise, node) => promise.then(() => {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
const sql = ((_a = node.config) == null ? void 0 : _a.sql) || "";
|
|
50
|
+
const template = (0, import_utils.parse)(sql);
|
|
51
|
+
if (!((_b = template.parameters) == null ? void 0 : _b.length)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
node.set("config", { ...node.config, unsafeInjection: true });
|
|
55
|
+
node.changed("config", true);
|
|
56
|
+
return node.save({
|
|
57
|
+
silent: true,
|
|
58
|
+
transaction
|
|
59
|
+
});
|
|
60
|
+
}),
|
|
61
|
+
Promise.resolve()
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
package/package.json
CHANGED
|
@@ -6,14 +6,15 @@
|
|
|
6
6
|
"description": "Execute SQL statements in workflow.",
|
|
7
7
|
"description.ru-RU": "Выполняет SQL-запросы в рамках рабочего процесса.",
|
|
8
8
|
"description.zh-CN": "可用于在工作流中对数据库执行任意 SQL 语句。",
|
|
9
|
-
"version": "2.1.0-beta.
|
|
10
|
-
"license": "
|
|
9
|
+
"version": "2.1.0-beta.21",
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
11
|
"main": "./dist/server/index.js",
|
|
12
12
|
"homepage": "https://docs.nocobase.com/handbook/workflow-sql",
|
|
13
13
|
"homepage.ru-RU": "https://docs-ru.nocobase.com/handbook/workflow-sql",
|
|
14
14
|
"homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/workflow-sql",
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"antd": "5.x",
|
|
17
|
+
"joi": "^17.13.3",
|
|
17
18
|
"react": "18.x",
|
|
18
19
|
"react-i18next": "^11.15.1"
|
|
19
20
|
},
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
"@nocobase/server": "2.x",
|
|
25
26
|
"@nocobase/test": "2.x"
|
|
26
27
|
},
|
|
27
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "324bd82f33fca58e98711688a17ceb65c186b65e",
|
|
28
29
|
"keywords": [
|
|
29
30
|
"Workflow"
|
|
30
31
|
]
|