@nocobase/plugin-workflow-sql 0.19.0-alpha.4 → 0.19.0-alpha.5

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.
@@ -1,4 +1,5 @@
1
1
  import { Instruction, WorkflowVariableRawTextArea } from '@nocobase/plugin-workflow/client';
2
+ import React from 'react';
2
3
  export default class extends Instruction {
3
4
  title: string;
4
5
  type: string;
@@ -18,6 +19,9 @@ export default class extends Instruction {
18
19
  };
19
20
  };
20
21
  };
22
+ scope: {
23
+ sqlDescription(): React.JSX.Element;
24
+ };
21
25
  components: {
22
26
  WorkflowVariableRawTextArea: typeof WorkflowVariableRawTextArea;
23
27
  };
@@ -1,4 +1,4 @@
1
- (function(e,o){typeof exports=="object"&&typeof module!="undefined"?o(exports,require("@nocobase/client"),require("@nocobase/plugin-workflow/client"),require("react-i18next")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","@nocobase/plugin-workflow/client","react-i18next"],o):(e=typeof globalThis!="undefined"?globalThis:e||self,o(e["@nocobase/plugin-workflow-sql"]={},e["@nocobase/client"],e["@nocobase/plugin-workflow"]))})(this,function(e,o,t){"use strict";var p=Object.defineProperty;var w=(e,o,t)=>o in e?p(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t;var s=(e,o,t)=>(w(e,typeof o!="symbol"?o+"":o,t),t);var c=(e,o,t)=>new Promise((r,l)=>{var u=n=>{try{i(t.next(n))}catch(a){l(a)}},f=n=>{try{i(t.throw(n))}catch(a){l(a)}},i=n=>n.done?r(n.value):Promise.resolve(n.value).then(u,f);i((t=t.apply(e,o)).next())});const r="workflow-sql";class l extends t.Instruction{constructor(){super(...arguments);s(this,"title",`{{t("SQL action", { ns: "${r}" })}}`);s(this,"type","sql");s(this,"group","collection");s(this,"description",`{{t("Execute a SQL statement in database.", { ns: "${r}" })}}`);s(this,"fieldset",{sql:{type:"string",required:!0,title:"SQL",description:`{{t("Usage of SQL query result is not supported yet.", { ns: "${r}" })}}`,"x-decorator":"FormItem","x-component":"WorkflowVariableRawTextArea","x-component-props":{rows:20,className:o.css`
1
+ (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,n,s,c){"use strict";var x=Object.defineProperty;var b=(e,o,n)=>o in e?x(e,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[o]=n;var r=(e,o,n)=>(b(e,typeof o!="symbol"?o+"":o,n),n);var u=(e,o,n)=>new Promise((s,c)=>{var i=t=>{try{a(n.next(t))}catch(l){c(l)}},d=t=>{try{a(n.throw(t))}catch(l){c(l)}},a=t=>t.done?s(t.value):Promise.resolve(t.value).then(i,d);a((n=n.apply(e,o)).next())});const i="@nocobase/plugin-workflow-sql";class d extends s.Instruction{constructor(){super(...arguments);r(this,"title",`{{t("SQL action", { ns: "${i}" })}}`);r(this,"type","sql");r(this,"group","collection");r(this,"description",`{{t("Execute a SQL statement in database.", { ns: "${i}" })}}`);r(this,"fieldset",{sql:{type:"string",required:!0,title:"SQL",description:"{{sqlDescription()}}","x-decorator":"FormItem","x-component":"WorkflowVariableRawTextArea","x-component-props":{rows:20,className:o.css`
2
2
  font-size: 80%;
3
3
  font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
4
- `}}});s(this,"components",{WorkflowVariableRawTextArea:t.WorkflowVariableRawTextArea})}useVariables({key:n,title:a},{types:b,fieldNames:d=t.defaultFieldNames}){return{[d.value]:n,[d.label]:a}}}class u extends o.Plugin{afterAdd(){return c(this,null,function*(){})}beforeLoad(){return c(this,null,function*(){})}load(){return c(this,null,function*(){this.app.pm.get("workflow").registerInstruction("sql",l)})}}e.default=u,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
4
+ `}}});r(this,"scope",{sqlDescription(){return n.jsxs(c.Trans,{ns:i,children:["SQL query result could be used through ",n.jsx("a",{href:"https://docs-cn.nocobase.com/plugins/workflow-json-query",target:"_blank",rel:"noreferrer",children:"JSON query node"})," (Commercial plugin)."]})}});r(this,"components",{WorkflowVariableRawTextArea:s.WorkflowVariableRawTextArea})}useVariables({key:p,title:w},{types:m,fieldNames:f=s.defaultFieldNames}){return{[f.value]:p,[f.label]:w}}}class a extends o.Plugin{afterAdd(){return u(this,null,function*(){})}beforeLoad(){return u(this,null,function*(){})}load(){return u(this,null,function*(){this.app.pm.get("workflow").registerInstruction("sql",d)})}}e.default=a,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,9 +1,10 @@
1
1
  module.exports = {
2
- "@nocobase/client": "0.19.0-alpha.4",
3
- "@nocobase/plugin-workflow": "0.19.0-alpha.4",
2
+ "@nocobase/client": "0.19.0-alpha.5",
3
+ "@nocobase/plugin-workflow": "0.19.0-alpha.5",
4
4
  "react-i18next": "11.18.6",
5
- "@nocobase/server": "0.19.0-alpha.4",
6
- "@nocobase/plugin-workflow-test": "0.19.0-alpha.4",
7
- "@nocobase/test": "0.19.0-alpha.4",
8
- "@nocobase/utils": "0.19.0-alpha.4"
5
+ "react": "18.2.0",
6
+ "@nocobase/server": "0.19.0-alpha.5",
7
+ "@nocobase/plugin-workflow-test": "0.19.0-alpha.5",
8
+ "@nocobase/test": "0.19.0-alpha.5",
9
+ "@nocobase/utils": "0.19.0-alpha.5"
9
10
  };
@@ -1,3 +1,3 @@
1
- export declare const NAMESPACE = "workflow-sql";
1
+ export declare const NAMESPACE = "@nocobase/plugin-workflow-sql";
2
2
  export declare function useLang(key: string, options?: {}): string;
3
- export declare function usePluginTranslation(options: any): import("react-i18next").UseTranslationResponse<"workflow-sql", undefined>;
3
+ export declare function usePluginTranslation(options: any): import("react-i18next").UseTranslationResponse<"@nocobase/plugin-workflow-sql", undefined>;
@@ -23,7 +23,7 @@ __export(locale_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(locale_exports);
25
25
  var import_react_i18next = require("react-i18next");
26
- const NAMESPACE = "workflow-sql";
26
+ const NAMESPACE = "@nocobase/plugin-workflow-sql";
27
27
  function useLang(key, options = {}) {
28
28
  const { t } = usePluginTranslation(options);
29
29
  return t(key);
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "SQL action": "SQL 操作",
3
- "Execute a SQL statement in database": "在数据库中执行一个 SQL 语句",
4
- "Usage of SQL query result is not supported yet.": "SQL 执行的结果暂不支持使用。"
3
+ "Execute a SQL statement in database.": "在数据库中执行一个 SQL 语句",
4
+ "SQL query result could be used through <1>JSON query node</1> (Commercial plugin).": "SQL 执行的结果可在 <1>JSON 解析节点</1> 中使用(商业插件)。"
5
5
  }
@@ -31,7 +31,7 @@ class SQLInstruction_default extends import_plugin_workflow.Instruction {
31
31
  };
32
32
  }
33
33
  const result = await sequelize.query(sql, {
34
- // transaction: processor.transaction,
34
+ transaction: processor.transaction
35
35
  // plain: true,
36
36
  // model: db.getCollection(node.config.collection).model
37
37
  });
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": "0.19.0-alpha.4",
7
+ "version": "0.19.0-alpha.5",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "devDependencies": {
@@ -19,5 +19,5 @@
19
19
  "@nocobase/server": "0.x",
20
20
  "@nocobase/test": "0.x"
21
21
  },
22
- "gitHead": "9583023f7bea828da5192384a5c002782c341b65"
22
+ "gitHead": "580eca25451ec731d17ddef285d0b8c52c48d501"
23
23
  }
@@ -3,6 +3,8 @@ import { css } from '@nocobase/client';
3
3
  import { Instruction, WorkflowVariableRawTextArea, defaultFieldNames } from '@nocobase/plugin-workflow/client';
4
4
 
5
5
  import { NAMESPACE } from '../locale';
6
+ import { Trans } from 'react-i18next';
7
+ import React from 'react';
6
8
 
7
9
  export default class extends Instruction {
8
10
  title = `{{t("SQL action", { ns: "${NAMESPACE}" })}}`;
@@ -14,7 +16,7 @@ export default class extends Instruction {
14
16
  type: 'string',
15
17
  required: true,
16
18
  title: 'SQL',
17
- description: `{{t("Usage of SQL query result is not supported yet.", { ns: "${NAMESPACE}" })}}`,
19
+ description: '{{sqlDescription()}}',
18
20
  'x-decorator': 'FormItem',
19
21
  'x-component': 'WorkflowVariableRawTextArea',
20
22
  'x-component-props': {
@@ -26,6 +28,19 @@ export default class extends Instruction {
26
28
  },
27
29
  },
28
30
  };
31
+ scope = {
32
+ sqlDescription() {
33
+ return (
34
+ <Trans ns={NAMESPACE}>
35
+ {'SQL query result could be used through '}
36
+ <a href="https://docs-cn.nocobase.com/plugins/workflow-json-query" target="_blank" rel="noreferrer">
37
+ {'JSON query node'}
38
+ </a>
39
+ {' (Commercial plugin).'}
40
+ </Trans>
41
+ );
42
+ },
43
+ };
29
44
  components = {
30
45
  WorkflowVariableRawTextArea,
31
46
  };
@@ -1,6 +1,6 @@
1
1
  import { useTranslation } from 'react-i18next';
2
2
 
3
- export const NAMESPACE = 'workflow-sql';
3
+ export const NAMESPACE = '@nocobase/plugin-workflow-sql';
4
4
 
5
5
  export function useLang(key: string, options = {}) {
6
6
  const { t } = usePluginTranslation(options);
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "SQL action": "SQL 操作",
3
- "Execute a SQL statement in database": "在数据库中执行一个 SQL 语句",
4
- "Usage of SQL query result is not supported yet.": "SQL 执行的结果暂不支持使用。"
3
+ "Execute a SQL statement in database.": "在数据库中执行一个 SQL 语句",
4
+ "SQL query result could be used through <1>JSON query node</1> (Commercial plugin).": "SQL 执行的结果可在 <1>JSON 解析节点</1> 中使用(商业插件)。"
5
5
  }
@@ -11,7 +11,7 @@ export default class extends Instruction {
11
11
  }
12
12
 
13
13
  const result = await sequelize.query(sql, {
14
- // transaction: processor.transaction,
14
+ transaction: processor.transaction,
15
15
  // plain: true,
16
16
  // model: db.getCollection(node.config.collection).model
17
17
  });
@@ -1,4 +1,4 @@
1
- import Database from '@nocobase/database';
1
+ import Database, { fn } from '@nocobase/database';
2
2
  import { Application } from '@nocobase/server';
3
3
  import { EXECUTION_STATUS, JOB_STATUS } from '@nocobase/plugin-workflow';
4
4
  import { getApp, sleep } from '@nocobase/plugin-workflow-test';
@@ -166,4 +166,33 @@ describe('workflow > instructions > sql', () => {
166
166
  expect(queryJob.result).toBeNull();
167
167
  });
168
168
  });
169
+
170
+ describe('run in sync mode', () => {
171
+ it('sync workflow', async () => {
172
+ const w2 = await WorkflowModel.create({
173
+ enabled: true,
174
+ sync: true,
175
+ type: 'collection',
176
+ config: {
177
+ mode: 1,
178
+ collection: 'categories',
179
+ },
180
+ });
181
+
182
+ const n1 = await w2.createNode({
183
+ type: 'sql',
184
+ config: {
185
+ sql: `select count(id) from ${PostCollection.quotedTableName()}`,
186
+ },
187
+ });
188
+
189
+ const CategoryRepo = db.getCollection('categories').repository;
190
+ const category = await CategoryRepo.create({ values: { title: 't1' } });
191
+
192
+ const [execution] = await w2.getExecutions();
193
+ expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
194
+ const [job] = await execution.getJobs();
195
+ expect(job.status).toBe(JOB_STATUS.RESOLVED);
196
+ });
197
+ });
169
198
  });