@nocobase/plugin-workflow-sql 1.3.38-beta → 1.4.0-alpha

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.
@@ -66,4 +66,5 @@ export default class extends Instruction {
66
66
  value: any;
67
67
  label: any;
68
68
  };
69
+ testable: boolean;
69
70
  }
@@ -10,4 +10,4 @@
10
10
  (function(e,o){typeof exports=="object"&&typeof module!="undefined"?o(exports,require("@nocobase/client"),require("react/jsx-runtime"),require("@nocobase/plugin-workflow/client"),require("react-i18next")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react/jsx-runtime","@nocobase/plugin-workflow/client","react-i18next"],o):(e=typeof globalThis!="undefined"?globalThis:e||self,o(e["@nocobase/plugin-workflow-sql"]={},e["@nocobase/client"],e.jsxRuntime,e["@nocobase/plugin-workflow"],e["react-i18next"]))})(this,function(e,o,t,a,l){"use strict";var w=Object.defineProperty;var x=(e,o,t)=>o in e?w(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t;var r=(e,o,t)=>(x(e,typeof o!="symbol"?o+"":o,t),t);var d=(e,o,t)=>new Promise((a,l)=>{var s=n=>{try{i(t.next(n))}catch(c){l(c)}},p=n=>{try{i(t.throw(n))}catch(c){l(c)}},i=n=>n.done?a(n.value):Promise.resolve(n.value).then(s,p);i((t=t.apply(e,o)).next())});const s="@nocobase/plugin-workflow-sql";class p extends a.Instruction{constructor(){super(...arguments);r(this,"title",`{{t("SQL action", { ns: "${s}" })}}`);r(this,"type","sql");r(this,"group","collection");r(this,"description",`{{t("Execute a SQL statement in database.", { ns: "${s}" })}}`);r(this,"fieldset",{dataSource:{type:"string",required:!0,title:'{{t("Data source")}}',description:`{{t("Select a data source to execute SQL.", { ns: "${s}" })}}`,"x-decorator":"FormItem","x-component":"DataSourceSelect","x-component-props":{className:"auto-width",filter(u){return u.options.isDBInstance||u.key===o.DEFAULT_DATA_SOURCE_KEY}},default:"main"},sql:{type:"string",required:!0,title:"SQL",description:"{{sqlDescription()}}","x-decorator":"FormItem","x-component":"WorkflowVariableRawTextArea","x-component-props":{rows:20,className:o.css`
11
11
  font-size: 80%;
12
12
  font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
13
- `}},withMeta:{type:"boolean","x-decorator":"FormItem","x-component":"Checkbox","x-content":`{{t("Include meta information of this query in result", { ns: "${s}" })}}`}});r(this,"scope",{sqlDescription(){return t.jsxs(l.Trans,{ns:s,children:["SQL query result could be used through ",t.jsx("a",{href:"https://docs-cn.nocobase.com/handbook/workflow-json-query",target:"_blank",rel:"noreferrer",children:"JSON query node"})," (Commercial plugin)."]})}});r(this,"components",{WorkflowVariableRawTextArea:a.WorkflowVariableRawTextArea})}useVariables({key:u,title:m},{types:b,fieldNames:f=a.defaultFieldNames}){return{[f.value]:u,[f.label]:m}}}class i extends o.Plugin{afterAdd(){return d(this,null,function*(){})}beforeLoad(){return d(this,null,function*(){})}load(){return d(this,null,function*(){this.app.pm.get("workflow").registerInstruction("sql",p)})}}e.default=i,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
13
+ `}},withMeta:{type:"boolean","x-decorator":"FormItem","x-component":"Checkbox","x-content":`{{t("Include meta information of this query in result", { ns: "${s}" })}}`}});r(this,"scope",{sqlDescription(){return t.jsxs(l.Trans,{ns:s,children:["SQL query result could be used through ",t.jsx("a",{href:"https://docs-cn.nocobase.com/handbook/workflow-json-query",target:"_blank",rel:"noreferrer",children:"JSON query node"})," (Commercial plugin)."]})}});r(this,"components",{WorkflowVariableRawTextArea:a.WorkflowVariableRawTextArea});r(this,"testable",!0)}useVariables({key:u,title:m},{types:b,fieldNames:f=a.defaultFieldNames}){return{[f.value]:u,[f.label]:m}}}class i extends o.Plugin{afterAdd(){return d(this,null,function*(){})}beforeLoad(){return d(this,null,function*(){})}load(){return d(this,null,function*(){this.app.pm.get("workflow").registerInstruction("sql",p)})}}e.default=i,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -8,12 +8,13 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "1.3.38-beta",
12
- "@nocobase/plugin-workflow": "1.3.38-beta",
11
+ "@nocobase/client": "1.4.0-alpha",
12
+ "@nocobase/plugin-workflow": "1.4.0-alpha",
13
13
  "react": "18.2.0",
14
14
  "react-i18next": "11.18.6",
15
- "@nocobase/server": "1.3.38-beta",
16
- "@nocobase/plugin-workflow-test": "1.3.38-beta",
17
- "@nocobase/test": "1.3.38-beta",
18
- "@nocobase/utils": "1.3.38-beta"
15
+ "@nocobase/server": "1.4.0-alpha",
16
+ "@nocobase/data-source-manager": "1.4.0-alpha",
17
+ "@nocobase/plugin-workflow-test": "1.4.0-alpha",
18
+ "@nocobase/test": "1.4.0-alpha",
19
+ "@nocobase/utils": "1.4.0-alpha"
19
20
  };
@@ -7,12 +7,24 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
  import { Processor, Instruction, FlowNodeModel } from '@nocobase/plugin-workflow';
10
+ export type SQLInstructionConfig = {
11
+ dataSource?: string;
12
+ sql?: string;
13
+ withMeta?: boolean;
14
+ };
10
15
  export default class extends Instruction {
11
16
  run(node: FlowNodeModel, input: any, processor: Processor): Promise<{
12
17
  status: 1;
13
18
  result?: undefined;
14
19
  } | {
15
- result: any;
20
+ result: unknown[];
21
+ status: 1;
22
+ }>;
23
+ test({ dataSource, sql, withMeta }?: SQLInstructionConfig): Promise<{
24
+ result: unknown[];
16
25
  status: 1;
26
+ } | {
27
+ result: any;
28
+ status: -2;
17
29
  }>;
18
30
  }
@@ -29,12 +29,13 @@ __export(SQLInstruction_exports, {
29
29
  default: () => SQLInstruction_default
30
30
  });
31
31
  module.exports = __toCommonJS(SQLInstruction_exports);
32
+ var import_data_source_manager = require("@nocobase/data-source-manager");
32
33
  var import_plugin_workflow = require("@nocobase/plugin-workflow");
33
34
  class SQLInstruction_default extends import_plugin_workflow.Instruction {
34
35
  async run(node, input, processor) {
35
36
  const dataSourceName = node.config.dataSource || "main";
36
- const { db } = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName).collectionManager;
37
- if (!db) {
37
+ const { collectionManager } = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName);
38
+ if (!(collectionManager instanceof import_data_source_manager.SequelizeCollectionManager)) {
38
39
  throw new Error(`type of data source "${node.config.dataSource}" is not database`);
39
40
  }
40
41
  const sql = processor.getParsedValue(node.config.sql || "", node.id).trim();
@@ -43,7 +44,7 @@ class SQLInstruction_default extends import_plugin_workflow.Instruction {
43
44
  status: import_plugin_workflow.JOB_STATUS.RESOLVED
44
45
  };
45
46
  }
46
- const [result = null, meta = null] = await db.sequelize.query(sql, {
47
+ const [result = null, meta = null] = await collectionManager.db.sequelize.query(sql, {
47
48
  transaction: this.workflow.useDataSourceTransaction(dataSourceName, processor.transaction)
48
49
  // plain: true,
49
50
  // model: db.getCollection(node.config.collection).model
@@ -53,4 +54,29 @@ class SQLInstruction_default extends import_plugin_workflow.Instruction {
53
54
  status: import_plugin_workflow.JOB_STATUS.RESOLVED
54
55
  };
55
56
  }
57
+ async test({ dataSource, sql, withMeta } = {}) {
58
+ if (!sql) {
59
+ return {
60
+ result: null,
61
+ status: import_plugin_workflow.JOB_STATUS.RESOLVED
62
+ };
63
+ }
64
+ const dataSourceName = dataSource || "main";
65
+ const { collectionManager } = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName);
66
+ if (!(collectionManager instanceof import_data_source_manager.SequelizeCollectionManager)) {
67
+ throw new Error(`type of data source "${dataSource}" is not database`);
68
+ }
69
+ try {
70
+ const [result = null, meta = null] = await collectionManager.db.sequelize.query(sql) ?? [];
71
+ return {
72
+ result: withMeta ? [result, meta] : result,
73
+ status: import_plugin_workflow.JOB_STATUS.RESOLVED
74
+ };
75
+ } catch (error) {
76
+ return {
77
+ result: error.message,
78
+ status: import_plugin_workflow.JOB_STATUS.ERROR
79
+ };
80
+ }
81
+ }
56
82
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "工作流:SQL 节点",
5
5
  "description": "Execute SQL statements in workflow.",
6
6
  "description.zh-CN": "可用于在工作流中对数据库执行任意 SQL 语句。",
7
- "version": "1.3.38-beta",
7
+ "version": "1.4.0-alpha",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "homepage": "https://docs.nocobase.com/handbook/workflow-sql",
@@ -21,7 +21,7 @@
21
21
  "@nocobase/server": "1.x",
22
22
  "@nocobase/test": "1.x"
23
23
  },
24
- "gitHead": "1b9490667c9224cd0b179cbf75e10a581c49b230",
24
+ "gitHead": "f097a2bddec152522b5645bd5d451f4c866d2060",
25
25
  "keywords": [
26
26
  "Workflow"
27
27
  ]
File without changes
File without changes