@nocobase/plugin-workflow-sql 0.17.0-alpha.4

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/client.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './dist/client';
2
+ export { default } from './dist/client';
package/client.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/client/index.js');
@@ -0,0 +1,33 @@
1
+ import { Instruction, WorkflowVariableRawTextArea } from '@nocobase/plugin-workflow/client';
2
+ export default class extends Instruction {
3
+ title: string;
4
+ type: string;
5
+ group: string;
6
+ description: string;
7
+ fieldset: {
8
+ sql: {
9
+ type: string;
10
+ required: boolean;
11
+ title: string;
12
+ description: string;
13
+ 'x-decorator': string;
14
+ 'x-component': string;
15
+ 'x-component-props': {
16
+ rows: number;
17
+ className: string;
18
+ };
19
+ };
20
+ };
21
+ components: {
22
+ WorkflowVariableRawTextArea: typeof WorkflowVariableRawTextArea;
23
+ };
24
+ useVariables({ key, title }: {
25
+ key: any;
26
+ title: any;
27
+ }, { types, fieldNames }: {
28
+ types: any;
29
+ fieldNames?: import("@nocobase/client").FieldNames;
30
+ }): {
31
+ [x: string]: any;
32
+ };
33
+ }
@@ -0,0 +1,6 @@
1
+ import { Plugin } from '@nocobase/client';
2
+ export default class extends Plugin {
3
+ afterAdd(): Promise<void>;
4
+ beforeLoad(): Promise<void>;
5
+ load(): Promise<void>;
6
+ }
@@ -0,0 +1,4 @@
1
+ (function(o,e){typeof exports=="object"&&typeof module!="undefined"?e(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"],e):(o=typeof globalThis!="undefined"?globalThis:o||self,e(o["@nocobase/plugin-workflow-sql"]={},o["@nocobase/client"],o["@nocobase/plugin-workflow"]))})(this,function(o,e,t){"use strict";var p=Object.defineProperty;var w=(o,e,t)=>e in o?p(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var s=(o,e,t)=>(w(o,typeof e!="symbol"?e+"":e,t),t);var c=(o,e,t)=>new Promise((i,l)=>{var u=n=>{try{r(t.next(n))}catch(a){l(a)}},f=n=>{try{r(t.throw(n))}catch(a){l(a)}},r=n=>n.done?i(n.value):Promise.resolve(n.value).then(u,f);r((t=t.apply(o,e)).next())});const i="workflow-sql";class l extends t.Instruction{constructor(){super(...arguments);s(this,"title",`{{t("SQL action", { ns: "${i}" })}}`);s(this,"type","sql");s(this,"group","collection");s(this,"description",`{{t("Execute a SQL statement in database.", { ns: "${i}" })}}`);s(this,"fieldset",{sql:{type:"string",required:!0,title:"SQL",description:`{{t("Usage of SQL query result is not supported yet.", { ns: "${i}" })}}`,"x-decorator":"FormItem","x-component":"WorkflowVariableRawTextArea","x-component-props":{rows:20,className:e.css`
2
+ font-size: 80%;
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=e.defaultFieldNames}){return{[d.value]:n,[d.label]:a}}}class u extends e.Plugin{afterAdd(){return c(this,null,function*(){})}beforeLoad(){return c(this,null,function*(){})}load(){return c(this,null,function*(){const r=this.app.pm.get("workflow"),n=new l;r.instructions.register(n.type,n)})}}o.default=u,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ "@nocobase/client": "0.17.0-alpha.4",
3
+ "@nocobase/plugin-workflow": "0.17.0-alpha.4",
4
+ "react-i18next": "11.18.6",
5
+ "@nocobase/server": "0.17.0-alpha.4"
6
+ };
@@ -0,0 +1,2 @@
1
+ export * from './server';
2
+ export { default } from './server';
package/dist/index.js ADDED
@@ -0,0 +1,39 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var src_exports = {};
30
+ __export(src_exports, {
31
+ default: () => import_server.default
32
+ });
33
+ module.exports = __toCommonJS(src_exports);
34
+ __reExport(src_exports, require("./server"), module.exports);
35
+ var import_server = __toESM(require("./server"));
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ ...require("./server")
39
+ });
@@ -0,0 +1,5 @@
1
+ {
2
+ "SQL action": "SQL action",
3
+ "Execute a SQL statement in database": "Execute a SQL statement in database",
4
+ "Usage of SQL query result is not supported yet.": "Usage of SQL query result is not supported yet."
5
+ }
@@ -0,0 +1,3 @@
1
+ export declare const NAMESPACE = "workflow-sql";
2
+ export declare function useLang(key: string, options?: {}): string;
3
+ export declare function usePluginTranslation(options: any): import("react-i18next").UseTranslationResponse<"workflow-sql", undefined>;
@@ -0,0 +1,39 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var locale_exports = {};
19
+ __export(locale_exports, {
20
+ NAMESPACE: () => NAMESPACE,
21
+ useLang: () => useLang,
22
+ usePluginTranslation: () => usePluginTranslation
23
+ });
24
+ module.exports = __toCommonJS(locale_exports);
25
+ var import_react_i18next = require("react-i18next");
26
+ const NAMESPACE = "workflow-sql";
27
+ function useLang(key, options = {}) {
28
+ const { t } = usePluginTranslation(options);
29
+ return t(key);
30
+ }
31
+ function usePluginTranslation(options) {
32
+ return (0, import_react_i18next.useTranslation)(NAMESPACE, options);
33
+ }
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ NAMESPACE,
37
+ useLang,
38
+ usePluginTranslation
39
+ });
@@ -0,0 +1,5 @@
1
+ {
2
+ "SQL action": "SQL 操作",
3
+ "Execute a SQL statement in database": "在数据库中执行一个 SQL 语句",
4
+ "Usage of SQL query result is not supported yet.": "SQL 执行的结果暂不支持使用。"
5
+ }
@@ -0,0 +1,6 @@
1
+ import { Plugin } from '@nocobase/server';
2
+ import WorkflowPlugin from '@nocobase/plugin-workflow';
3
+ export default class extends Plugin {
4
+ workflow: WorkflowPlugin;
5
+ load(): Promise<void>;
6
+ }
@@ -0,0 +1,42 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var Plugin_exports = {};
29
+ __export(Plugin_exports, {
30
+ default: () => Plugin_default
31
+ });
32
+ module.exports = __toCommonJS(Plugin_exports);
33
+ var import_server = require("@nocobase/server");
34
+ var import_SQLInstruction = __toESM(require("./SQLInstruction"));
35
+ class Plugin_default extends import_server.Plugin {
36
+ workflow;
37
+ async load() {
38
+ const workflowPlugin = this.app.getPlugin("workflow");
39
+ this.workflow = workflowPlugin;
40
+ workflowPlugin.instructions.register("sql", new import_SQLInstruction.default(workflowPlugin));
41
+ }
42
+ }
@@ -0,0 +1,10 @@
1
+ import { Processor, Instruction, FlowNodeModel } from '@nocobase/plugin-workflow';
2
+ export default class extends Instruction {
3
+ run(node: FlowNodeModel, input: any, processor: Processor): Promise<{
4
+ status: number;
5
+ result?: undefined;
6
+ } | {
7
+ result: [unknown[], unknown];
8
+ status: number;
9
+ }>;
10
+ }
@@ -0,0 +1,43 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var SQLInstruction_exports = {};
19
+ __export(SQLInstruction_exports, {
20
+ default: () => SQLInstruction_default
21
+ });
22
+ module.exports = __toCommonJS(SQLInstruction_exports);
23
+ var import_plugin_workflow = require("@nocobase/plugin-workflow");
24
+ class SQLInstruction_default extends import_plugin_workflow.Instruction {
25
+ async run(node, input, processor) {
26
+ const { sequelize } = node.constructor.database;
27
+ const sql = processor.getParsedValue(node.config.sql ?? "", node.id).trim();
28
+ if (!sql) {
29
+ return {
30
+ status: import_plugin_workflow.JOB_STATUS.RESOLVED
31
+ };
32
+ }
33
+ const result = await sequelize.query(sql, {
34
+ transaction: processor.transaction
35
+ // plain: true,
36
+ // model: db.getCollection(node.config.collection).model
37
+ });
38
+ return {
39
+ result,
40
+ status: import_plugin_workflow.JOB_STATUS.RESOLVED
41
+ };
42
+ }
43
+ }
@@ -0,0 +1 @@
1
+ export { default } from './Plugin';
@@ -0,0 +1,33 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var server_exports = {};
29
+ __export(server_exports, {
30
+ default: () => import_Plugin.default
31
+ });
32
+ module.exports = __toCommonJS(server_exports);
33
+ var import_Plugin = __toESM(require("./Plugin"));
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@nocobase/plugin-workflow-sql",
3
+ "displayName": "Workflow: SQL node",
4
+ "displayName.zh-CN": "工作流:SQL 节点",
5
+ "description": "Execute SQL statements in workflow.",
6
+ "description.zh-CN": "可用于在工作流中对数据库执行任意 SQL 语句。",
7
+ "version": "0.17.0-alpha.4",
8
+ "license": "AGPL-3.0",
9
+ "main": "./dist/server/index.js",
10
+ "devDependencies": {
11
+ "antd": "5.x",
12
+ "react": "18.x",
13
+ "react-i18next": "^11.15.1"
14
+ },
15
+ "peerDependencies": {
16
+ "@nocobase/client": "0.x",
17
+ "@nocobase/database": "0.x",
18
+ "@nocobase/plugin-workflow": ">=0.17.0-alpha.3",
19
+ "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3",
20
+ "@nocobase/server": "0.x",
21
+ "@nocobase/test": "0.x"
22
+ },
23
+ "gitHead": "663b03a3799a70ba1a2bc6a0d686e679331a50ad"
24
+ }
package/server.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './dist/server';
2
+ export { default } from './dist/server';
package/server.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/server/index.js');
@@ -0,0 +1,38 @@
1
+ import { css, defaultFieldNames } from '@nocobase/client';
2
+
3
+ import { Instruction, WorkflowVariableRawTextArea } from '@nocobase/plugin-workflow/client';
4
+
5
+ import { NAMESPACE } from '../locale';
6
+
7
+ export default class extends Instruction {
8
+ title = `{{t("SQL action", { ns: "${NAMESPACE}" })}}`;
9
+ type = 'sql';
10
+ group = 'collection';
11
+ description = `{{t("Execute a SQL statement in database.", { ns: "${NAMESPACE}" })}}`;
12
+ fieldset = {
13
+ sql: {
14
+ type: 'string',
15
+ required: true,
16
+ title: 'SQL',
17
+ description: `{{t("Usage of SQL query result is not supported yet.", { ns: "${NAMESPACE}" })}}`,
18
+ 'x-decorator': 'FormItem',
19
+ 'x-component': 'WorkflowVariableRawTextArea',
20
+ 'x-component-props': {
21
+ rows: 20,
22
+ className: css`
23
+ font-size: 80%;
24
+ font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
25
+ `,
26
+ },
27
+ },
28
+ };
29
+ components = {
30
+ WorkflowVariableRawTextArea,
31
+ };
32
+ useVariables({ key, title }, { types, fieldNames = defaultFieldNames }) {
33
+ return {
34
+ [fieldNames.value]: key,
35
+ [fieldNames.label]: title,
36
+ };
37
+ }
38
+ }
@@ -0,0 +1,19 @@
1
+ import { Plugin } from '@nocobase/client';
2
+ import WorkflowPlugin from '@nocobase/plugin-workflow/client';
3
+
4
+ import SQLInstruction from './SQLInstruction';
5
+
6
+ export default class extends Plugin {
7
+ async afterAdd() {
8
+ // await this.app.pm.add()
9
+ }
10
+
11
+ async beforeLoad() {}
12
+
13
+ // You can get and modify the app instance here
14
+ async load() {
15
+ const workflow = this.app.pm.get('workflow') as WorkflowPlugin;
16
+ const sqlInstruction = new SQLInstruction();
17
+ workflow.instructions.register(sqlInstruction.type, sqlInstruction);
18
+ }
19
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './server';
2
+ export { default } from './server';
@@ -0,0 +1,5 @@
1
+ {
2
+ "SQL action": "SQL action",
3
+ "Execute a SQL statement in database": "Execute a SQL statement in database",
4
+ "Usage of SQL query result is not supported yet.": "Usage of SQL query result is not supported yet."
5
+ }
@@ -0,0 +1,12 @@
1
+ import { useTranslation } from 'react-i18next';
2
+
3
+ export const NAMESPACE = 'workflow-sql';
4
+
5
+ export function useLang(key: string, options = {}) {
6
+ const { t } = usePluginTranslation(options);
7
+ return t(key);
8
+ }
9
+
10
+ export function usePluginTranslation(options) {
11
+ return useTranslation(NAMESPACE, options);
12
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "SQL action": "SQL 操作",
3
+ "Execute a SQL statement in database": "在数据库中执行一个 SQL 语句",
4
+ "Usage of SQL query result is not supported yet.": "SQL 执行的结果暂不支持使用。"
5
+ }
@@ -0,0 +1,14 @@
1
+ import { Plugin } from '@nocobase/server';
2
+ import WorkflowPlugin from '@nocobase/plugin-workflow';
3
+
4
+ import SQLInstruction from './SQLInstruction';
5
+
6
+ export default class extends Plugin {
7
+ workflow: WorkflowPlugin;
8
+
9
+ async load() {
10
+ const workflowPlugin = this.app.getPlugin('workflow') as WorkflowPlugin;
11
+ this.workflow = workflowPlugin;
12
+ workflowPlugin.instructions.register('sql', new SQLInstruction(workflowPlugin));
13
+ }
14
+ }
@@ -0,0 +1,24 @@
1
+ import { Processor, Instruction, JOB_STATUS, FlowNodeModel } from '@nocobase/plugin-workflow';
2
+
3
+ export default class extends Instruction {
4
+ async run(node: FlowNodeModel, input, processor: Processor) {
5
+ const { sequelize } = (<typeof FlowNodeModel>node.constructor).database;
6
+ const sql = processor.getParsedValue(node.config.sql ?? '', node.id).trim();
7
+ if (!sql) {
8
+ return {
9
+ status: JOB_STATUS.RESOLVED,
10
+ };
11
+ }
12
+
13
+ const result = await sequelize.query(sql, {
14
+ transaction: processor.transaction,
15
+ // plain: true,
16
+ // model: db.getCollection(node.config.collection).model
17
+ });
18
+
19
+ return {
20
+ result,
21
+ status: JOB_STATUS.RESOLVED,
22
+ };
23
+ }
24
+ }
@@ -0,0 +1,169 @@
1
+ import Database from '@nocobase/database';
2
+ import { Application } from '@nocobase/server';
3
+ import { EXECUTION_STATUS, JOB_STATUS } from '@nocobase/plugin-workflow';
4
+ import { getApp, sleep } from '@nocobase/plugin-workflow-test';
5
+
6
+ import Plugin from '..';
7
+
8
+ describe('workflow > instructions > sql', () => {
9
+ let app: Application;
10
+ let db: Database;
11
+ let PostRepo;
12
+ let PostCollection;
13
+ let ReplyRepo;
14
+ let WorkflowModel;
15
+ let workflow;
16
+
17
+ beforeEach(async () => {
18
+ app = await getApp({
19
+ plugins: [Plugin],
20
+ });
21
+
22
+ db = app.db;
23
+ WorkflowModel = db.getCollection('workflows').model;
24
+ PostCollection = db.getCollection('posts');
25
+ PostRepo = PostCollection.repository;
26
+ ReplyRepo = db.getCollection('replies').repository;
27
+
28
+ workflow = await WorkflowModel.create({
29
+ enabled: true,
30
+ type: 'collection',
31
+ config: {
32
+ mode: 1,
33
+ collection: 'posts',
34
+ },
35
+ });
36
+ });
37
+
38
+ afterEach(() => app.destroy());
39
+
40
+ describe('invalid', () => {
41
+ it('no sql', async () => {
42
+ const n1 = await workflow.createNode({
43
+ type: 'sql',
44
+ config: {},
45
+ });
46
+
47
+ const post = await PostRepo.create({ values: { title: 't1' } });
48
+
49
+ await sleep(500);
50
+
51
+ const [execution] = await workflow.getExecutions();
52
+ const [sqlJob] = await execution.getJobs({ order: [['id', 'ASC']] });
53
+ expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
54
+ expect(sqlJob.status).toBe(JOB_STATUS.RESOLVED);
55
+ });
56
+
57
+ it('empty sql', async () => {
58
+ const n1 = await workflow.createNode({
59
+ type: 'sql',
60
+ config: {
61
+ sql: '',
62
+ },
63
+ });
64
+
65
+ const post = await PostRepo.create({ values: { title: 't1' } });
66
+
67
+ await sleep(500);
68
+
69
+ const [execution] = await workflow.getExecutions();
70
+ const [sqlJob] = await execution.getJobs({ order: [['id', 'ASC']] });
71
+ expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
72
+ expect(sqlJob.status).toBe(JOB_STATUS.RESOLVED);
73
+ });
74
+
75
+ it('invalid sql', async () => {
76
+ const n1 = await workflow.createNode({
77
+ type: 'sql',
78
+ config: {
79
+ sql: '1',
80
+ },
81
+ });
82
+
83
+ const post = await PostRepo.create({ values: { title: 't1' } });
84
+
85
+ await sleep(500);
86
+
87
+ const [execution] = await workflow.getExecutions();
88
+ const [sqlJob] = await execution.getJobs({ order: [['id', 'ASC']] });
89
+ expect(execution.status).toBe(EXECUTION_STATUS.ERROR);
90
+ expect(sqlJob.status).toBe(JOB_STATUS.ERROR);
91
+ });
92
+ });
93
+
94
+ describe('sql with variables', () => {
95
+ it('update', async () => {
96
+ const queryInterface = db.sequelize.getQueryInterface();
97
+ const n1 = await workflow.createNode({
98
+ type: 'sql',
99
+ config: {
100
+ sql: `update ${PostCollection.quotedTableName()} set ${queryInterface.quoteIdentifier(
101
+ 'read',
102
+ )}={{$context.data.id}} where ${queryInterface.quoteIdentifier('id')}={{$context.data.id}}`,
103
+ },
104
+ });
105
+
106
+ const n2 = await workflow.createNode({
107
+ type: 'query',
108
+ config: {
109
+ collection: 'posts',
110
+ params: {
111
+ filter: {
112
+ id: '{{ $context.data.id }}',
113
+ },
114
+ },
115
+ },
116
+ upstreamId: n1.id,
117
+ });
118
+
119
+ await n1.setDownstream(n2);
120
+
121
+ const post = await PostRepo.create({ values: { title: 't1' } });
122
+
123
+ await sleep(500);
124
+
125
+ const [execution] = await workflow.getExecutions();
126
+ const [sqlJob, queryJob] = await execution.getJobs({ order: [['id', 'ASC']] });
127
+ expect(sqlJob.status).toBe(JOB_STATUS.RESOLVED);
128
+ expect(queryJob.status).toBe(JOB_STATUS.RESOLVED);
129
+ expect(queryJob.result.read).toBe(post.id);
130
+ });
131
+
132
+ it('delete', async () => {
133
+ const queryInterface = db.sequelize.getQueryInterface();
134
+ const n1 = await workflow.createNode({
135
+ type: 'sql',
136
+ config: {
137
+ sql: `delete from ${PostCollection.quotedTableName()} where ${queryInterface.quoteIdentifier(
138
+ 'id',
139
+ )}={{$context.data.id}};`,
140
+ },
141
+ });
142
+
143
+ const n2 = await workflow.createNode({
144
+ type: 'query',
145
+ config: {
146
+ collection: 'posts',
147
+ params: {
148
+ filter: {
149
+ id: '{{ $context.data.id }}',
150
+ },
151
+ },
152
+ },
153
+ upstreamId: n1.id,
154
+ });
155
+
156
+ await n1.setDownstream(n2);
157
+
158
+ const post = await PostRepo.create({ values: { title: 't1' } });
159
+
160
+ await sleep(500);
161
+
162
+ const [execution] = await workflow.getExecutions();
163
+ const [sqlJob, queryJob] = await execution.getJobs({ order: [['id', 'ASC']] });
164
+ expect(sqlJob.status).toBe(JOB_STATUS.RESOLVED);
165
+ expect(queryJob.status).toBe(JOB_STATUS.RESOLVED);
166
+ expect(queryJob.result).toBeNull();
167
+ });
168
+ });
169
+ });
@@ -0,0 +1 @@
1
+ export { default } from './Plugin';