@veridid/workflow-parser 0.3.2 → 0.4.0
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/package.json +17 -32
- package/src/implementations/action.default.js +114 -0
- package/src/implementations/action.default.ts +74 -0
- package/src/implementations/display.default.js +132 -0
- package/src/implementations/display.default.ts +98 -0
- package/src/implementations/workflow.default.js +146 -0
- package/src/implementations/workflow.default.ts +64 -0
- package/src/index.js +6 -0
- package/src/index.ts +6 -0
- package/src/interfaces/actionextension.js +2 -0
- package/src/interfaces/actionextension.ts +7 -0
- package/src/interfaces/actioninterface.js +2 -0
- package/src/interfaces/actioninterface.ts +11 -0
- package/src/interfaces/displayextension.js +2 -0
- package/src/interfaces/displayextension.ts +7 -0
- package/src/interfaces/displayinterface.js +2 -0
- package/src/interfaces/displayinterface.ts +13 -0
- package/src/interfaces/workflowinterface.js +2 -0
- package/src/interfaces/workflowinterface.ts +24 -0
- package/{dist/schema.sql → src/support/Schema.sql} +2 -2
- package/src/workflowparser.js +100 -0
- package/src/workflowparser.ts +70 -0
- package/test/action.extension.js +65 -0
- package/test/action.extension.ts +22 -0
- package/test/display.extension.js +60 -0
- package/test/display.extension.ts +16 -0
- package/test/docker-compose.yml +33 -0
- package/test/pg_hba.conf +14 -0
- package/test/postgresql.conf +42 -0
- package/test/tables.sql +17 -0
- package/test/test.js +233 -0
- package/test/test.ts +159 -0
- package/test/testworkflows.json +223 -0
- package/tsconfig.json +15 -0
- package/dist/db.js +0 -40
- package/dist/dbCrud.js +0 -210
- package/dist/index.js +0 -22
- package/dist/parser.js +0 -125
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Instance, IWorkflow, Workflow } from '../interfaces/workflowinterface'
|
|
2
|
+
import { Client } from 'pg';
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
+
|
|
5
|
+
export class DefaultWorkflow implements IWorkflow {
|
|
6
|
+
dbClient: Client;
|
|
7
|
+
|
|
8
|
+
constructor(dbClient: Client) {
|
|
9
|
+
this.dbClient = dbClient;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async getWorkflowByID(workflowID: string): Promise<Workflow> {
|
|
13
|
+
console.log("*** getWorkflowByID");
|
|
14
|
+
const res = await this.dbClient?.query('SELECT * FROM workflows WHERE "workflow_id" = $1', [workflowID]);
|
|
15
|
+
//console.log("WorkflowID=", workflowID);
|
|
16
|
+
//console.log("Workflow=", res.rows[0]);
|
|
17
|
+
return res.rows.length > 0 ? res.rows[0] : null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async getInstanceByID(clientID: string, workflowID: string): Promise<Instance> {
|
|
21
|
+
console.log("*** getInstanceByID");
|
|
22
|
+
let instance = null;
|
|
23
|
+
let query = 'SELECT * FROM instances WHERE "client_id" = $1 AND "workflow_id" = $2';
|
|
24
|
+
let res = await this.dbClient?.query(query, [clientID, workflowID]);
|
|
25
|
+
//console.log("Look for existing instance clientID=", clientID, " workflowID=", workflowID);
|
|
26
|
+
//console.log("Found ", res.rows);
|
|
27
|
+
if(res.rows.length === 0) {
|
|
28
|
+
// no instance
|
|
29
|
+
//console.log("getInstanceByID - no instance");
|
|
30
|
+
const workflow = await this.getWorkflowByID(workflowID);
|
|
31
|
+
// Create new instance with new instanceID, the initial state fromt he workflow, and empoty instance data
|
|
32
|
+
instance = await this.newInstance(clientID, workflowID, workflow.initial_state);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
instance = res.rows.length > 0 ? res.rows[0] : null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//console.log("Instance=", instance);
|
|
39
|
+
return instance;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async newInstance(clientID: string, workflowID: string, stateID: string): Promise<Instance> {
|
|
43
|
+
console.log("*** newInstance=", clientID, workflowID, stateID);
|
|
44
|
+
const query = 'INSERT INTO instances (instance_id, workflow_id, client_id, current_state, state_data) VALUES ($1, $2, $3, $4, $5)';
|
|
45
|
+
let result = await this.dbClient?.query(query, [uuidv4(), workflowID, clientID, stateID, {}]);
|
|
46
|
+
let res = await this.getInstanceByID(clientID, workflowID);
|
|
47
|
+
return res;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async updateInstanceByID(clientID: string, workflowID: string, stateID: string, data: any): Promise<Instance> {
|
|
51
|
+
console.log("*** updateInstance=", clientID, workflowID, stateID, data);
|
|
52
|
+
// check instance and create new if does not exist
|
|
53
|
+
let instance = await this.getInstanceByID(clientID, workflowID);
|
|
54
|
+
// update current_state and state_data
|
|
55
|
+
const query = "UPDATE instances SET current_state = $1, state_data = $2 WHERE workflow_id = $3 AND client_id = $4";
|
|
56
|
+
//console.log("query=", query);
|
|
57
|
+
//console.log("stateID=", stateID, " data=", data);
|
|
58
|
+
//console.log("workflowID=", stateID, " clientID=", clientID);
|
|
59
|
+
await this.dbClient?.query(query, [stateID, JSON.stringify(data), workflowID, clientID]);
|
|
60
|
+
instance = await this.getInstanceByID(clientID, workflowID);
|
|
61
|
+
return instance;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkflowParser = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
var workflowparser_1 = require("./workflowparser");
|
|
6
|
+
Object.defineProperty(exports, "WorkflowParser", { enumerable: true, get: function () { return workflowparser_1.WorkflowParser; } });
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Instance, IWorkflow, Workflow } from "./workflowinterface";
|
|
2
|
+
import { IAction, Transition } from "./actioninterface"
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export interface IActionExtension {
|
|
6
|
+
actions: (actionInput: any, instance: Instance, action: any, transtion: Transition) => Promise<Transition>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Instance, IWorkflow, Workflow } from "./workflowinterface";
|
|
2
|
+
|
|
3
|
+
export interface IAction {
|
|
4
|
+
processAction: (currentWorkflow: Workflow, instance: Instance, action: any) => Promise<Transition>;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface Transition {
|
|
8
|
+
type: string,
|
|
9
|
+
workflow_id: string,
|
|
10
|
+
state_id: string
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Workflow, Instance } from "./workflowinterface";
|
|
2
|
+
|
|
3
|
+
export interface IDisplay {
|
|
4
|
+
processDisplay: (
|
|
5
|
+
clientID: string,
|
|
6
|
+
curentWorkflow: Workflow,
|
|
7
|
+
instance: Instance,
|
|
8
|
+
currentState: string) => Promise<DisplayData>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface DisplayData {
|
|
12
|
+
displayData: any[]
|
|
13
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface IWorkflow {
|
|
2
|
+
|
|
3
|
+
getWorkflowByID: (workflowID: string) => Promise<Workflow>;
|
|
4
|
+
getInstanceByID: (workflowID: string, clientID: string) => Promise<Instance>;
|
|
5
|
+
updateInstanceByID: (clientID: string, workflowID: string, stateID: string, data: any) => Promise<Instance>;
|
|
6
|
+
newInstance: (clientID: string, workflowID: string, stateID: string, data: any) => Promise<Instance>;
|
|
7
|
+
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface Workflow {
|
|
11
|
+
workflow_id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
initial_state: string;
|
|
14
|
+
render: any[];
|
|
15
|
+
states: [{state_id: string, display_data: any, actions: any, transitions: any}]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface Instance {
|
|
19
|
+
instance_id: string;
|
|
20
|
+
workflow_id: string;
|
|
21
|
+
client_id: string,
|
|
22
|
+
current_state: string;
|
|
23
|
+
state_data: any;
|
|
24
|
+
}
|
|
@@ -10,7 +10,7 @@ CREATE TABLE workflows (
|
|
|
10
10
|
CREATE TABLE instances (
|
|
11
11
|
"instanceID" UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
12
12
|
"workflowID" VARCHAR(255) REFERENCES workflows("workflowID"),
|
|
13
|
-
"
|
|
13
|
+
"clientID" VARCHAR(255),
|
|
14
14
|
"currentState" VARCHAR(255),
|
|
15
15
|
"stateData" JSONB
|
|
16
|
-
);
|
|
16
|
+
);
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.WorkflowParser = void 0;
|
|
40
|
+
var WorkflowParser = /** @class */ (function () {
|
|
41
|
+
function WorkflowParser(display, action, workflow) {
|
|
42
|
+
this.display = display;
|
|
43
|
+
this.action = action;
|
|
44
|
+
this.workflow = workflow;
|
|
45
|
+
}
|
|
46
|
+
WorkflowParser.prototype.parse = function (clientID, action) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
+
var curentWorkflow, instance, currentState, transition, updatedInstance, display;
|
|
49
|
+
return __generator(this, function (_a) {
|
|
50
|
+
switch (_a.label) {
|
|
51
|
+
case 0:
|
|
52
|
+
console.log("=== parse clientID=", clientID, " action=", action);
|
|
53
|
+
return [4 /*yield*/, this.workflow.getWorkflowByID(action === null || action === void 0 ? void 0 : action.workflowID)];
|
|
54
|
+
case 1:
|
|
55
|
+
curentWorkflow = _a.sent();
|
|
56
|
+
console.log("+++ currentWorkflow");
|
|
57
|
+
return [4 /*yield*/, this.workflow.getInstanceByID(clientID, action === null || action === void 0 ? void 0 : action.workflowID)];
|
|
58
|
+
case 2:
|
|
59
|
+
instance = _a.sent();
|
|
60
|
+
console.log("+++ instance");
|
|
61
|
+
currentState = instance.current_state;
|
|
62
|
+
return [4 /*yield*/, this.action.processAction(curentWorkflow, instance, action)];
|
|
63
|
+
case 3:
|
|
64
|
+
transition = _a.sent();
|
|
65
|
+
console.log("+++ transition");
|
|
66
|
+
if (!(transition.type != "none")) return [3 /*break*/, 7];
|
|
67
|
+
if (!(transition.type === 'workflowTransition')) return [3 /*break*/, 6];
|
|
68
|
+
return [4 /*yield*/, this.workflow.getWorkflowByID(transition === null || transition === void 0 ? void 0 : transition.workflow_id)];
|
|
69
|
+
case 4:
|
|
70
|
+
// get the new workflow
|
|
71
|
+
curentWorkflow = _a.sent();
|
|
72
|
+
return [4 /*yield*/, this.workflow.getInstanceByID(clientID, transition === null || transition === void 0 ? void 0 : transition.workflow_id)];
|
|
73
|
+
case 5:
|
|
74
|
+
// get the new instance
|
|
75
|
+
instance = _a.sent();
|
|
76
|
+
currentState = instance.current_state;
|
|
77
|
+
_a.label = 6;
|
|
78
|
+
case 6:
|
|
79
|
+
if (transition.type === 'stateTransition') {
|
|
80
|
+
// set the new current state
|
|
81
|
+
currentState = transition.state_id;
|
|
82
|
+
}
|
|
83
|
+
_a.label = 7;
|
|
84
|
+
case 7: return [4 /*yield*/, this.workflow.updateInstanceByID(clientID, curentWorkflow.workflow_id, currentState, instance.state_data)];
|
|
85
|
+
case 8:
|
|
86
|
+
updatedInstance = _a.sent();
|
|
87
|
+
console.log("+++ Updated instance");
|
|
88
|
+
return [4 /*yield*/, this.display.processDisplay(clientID, curentWorkflow, updatedInstance, currentState)];
|
|
89
|
+
case 9:
|
|
90
|
+
display = _a.sent();
|
|
91
|
+
console.log("+++ Prcoessed display");
|
|
92
|
+
// return workflowID and display
|
|
93
|
+
return [2 /*return*/, { workflowID: curentWorkflow.workflow_id, displayData: display.displayData }];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
return WorkflowParser;
|
|
99
|
+
}());
|
|
100
|
+
exports.WorkflowParser = WorkflowParser;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { IDisplay } from "./interfaces/displayinterface";
|
|
2
|
+
import { IAction } from "./interfaces/actioninterface";
|
|
3
|
+
import { IWorkflow } from "./interfaces/workflowinterface";
|
|
4
|
+
|
|
5
|
+
export class WorkflowParser {
|
|
6
|
+
display: IDisplay;
|
|
7
|
+
action: IAction;
|
|
8
|
+
workflow: IWorkflow;
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
display: IDisplay,
|
|
12
|
+
action: IAction,
|
|
13
|
+
workflow: IWorkflow
|
|
14
|
+
) {
|
|
15
|
+
this.display = display;
|
|
16
|
+
this.action = action;
|
|
17
|
+
this.workflow = workflow;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async parse(
|
|
21
|
+
clientID: string,
|
|
22
|
+
action: {
|
|
23
|
+
workflowID: string;
|
|
24
|
+
actionID: string;
|
|
25
|
+
data?: any }
|
|
26
|
+
): Promise<any> {
|
|
27
|
+
console.log("=== parse clientID=", clientID, " action=", action);
|
|
28
|
+
|
|
29
|
+
// get the workflow as JSON
|
|
30
|
+
let curentWorkflow = await this.workflow.getWorkflowByID(action?.workflowID);
|
|
31
|
+
console.log("+++ currentWorkflow");
|
|
32
|
+
|
|
33
|
+
// get the instance as JSON
|
|
34
|
+
let instance = await this.workflow.getInstanceByID(clientID, action?.workflowID);
|
|
35
|
+
console.log("+++ instance");
|
|
36
|
+
|
|
37
|
+
// current state in the workflow
|
|
38
|
+
let currentState = instance.current_state;
|
|
39
|
+
|
|
40
|
+
// process the action
|
|
41
|
+
let transition = await this.action.processAction(curentWorkflow, instance, action);
|
|
42
|
+
console.log("+++ transition");
|
|
43
|
+
|
|
44
|
+
if(transition.type != "none") {
|
|
45
|
+
// process the transition
|
|
46
|
+
if(transition.type === 'workflowTransition') {
|
|
47
|
+
// get the new workflow
|
|
48
|
+
curentWorkflow = await this.workflow.getWorkflowByID(transition?.workflow_id);
|
|
49
|
+
// get the new instance
|
|
50
|
+
instance = await this.workflow.getInstanceByID(clientID, transition?.workflow_id);
|
|
51
|
+
currentState = instance.current_state;
|
|
52
|
+
}
|
|
53
|
+
if(transition.type === 'stateTransition') {
|
|
54
|
+
// set the new current state
|
|
55
|
+
currentState = transition.state_id;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// update the instance
|
|
60
|
+
const updatedInstance = await this.workflow.updateInstanceByID(clientID, curentWorkflow.workflow_id, currentState, instance.state_data);
|
|
61
|
+
console.log("+++ Updated instance");
|
|
62
|
+
|
|
63
|
+
// process the display
|
|
64
|
+
const display = await this.display.processDisplay(clientID, curentWorkflow, updatedInstance, currentState)
|
|
65
|
+
console.log("+++ Prcoessed display");
|
|
66
|
+
|
|
67
|
+
// return workflowID and display
|
|
68
|
+
return {workflowID: curentWorkflow.workflow_id, displayData: display.displayData};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ExtendedAction = void 0;
|
|
40
|
+
var ExtendedAction = /** @class */ (function () {
|
|
41
|
+
function ExtendedAction() {
|
|
42
|
+
}
|
|
43
|
+
ExtendedAction.prototype.actions = function (actionInput, instance, action, transition) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
45
|
+
return __generator(this, function (_a) {
|
|
46
|
+
console.log("^^^ Extension -> actions");
|
|
47
|
+
// handle the types of actions
|
|
48
|
+
switch (action === null || action === void 0 ? void 0 : action.type) {
|
|
49
|
+
case "extension":
|
|
50
|
+
// check condition
|
|
51
|
+
if (eval(action.condition)) {
|
|
52
|
+
// save the data from the workflow action to the instance data
|
|
53
|
+
instance.state_data = Object.assign(instance.state_data, action.value);
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
}
|
|
58
|
+
return [2 /*return*/, transition];
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
;
|
|
63
|
+
return ExtendedAction;
|
|
64
|
+
}());
|
|
65
|
+
exports.ExtendedAction = ExtendedAction;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IActionExtension } from "../src/interfaces/actionextension";
|
|
2
|
+
import { Transition } from "../src/interfaces/actioninterface";
|
|
3
|
+
import { Instance, Workflow } from "../src/interfaces/workflowinterface";
|
|
4
|
+
|
|
5
|
+
export class ExtendedAction implements IActionExtension {
|
|
6
|
+
async actions(actionInput: any, instance: Instance, action: any, transition: Transition): Promise<Transition>{
|
|
7
|
+
console.log("^^^ Extension -> actions");
|
|
8
|
+
// handle the types of actions
|
|
9
|
+
switch(action?.type) {
|
|
10
|
+
case "extension":
|
|
11
|
+
// check condition
|
|
12
|
+
if(eval(action.condition)) {
|
|
13
|
+
// save the data from the workflow action to the instance data
|
|
14
|
+
instance.state_data = Object.assign(instance.state_data, action.value);
|
|
15
|
+
}
|
|
16
|
+
break;
|
|
17
|
+
default:
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return transition;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ExtendedDisplay = void 0;
|
|
40
|
+
var ExtendedDisplay = /** @class */ (function () {
|
|
41
|
+
function ExtendedDisplay() {
|
|
42
|
+
}
|
|
43
|
+
ExtendedDisplay.prototype.displays = function (instance, template) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
45
|
+
return __generator(this, function (_a) {
|
|
46
|
+
console.log("^^^ Extension -> displays");
|
|
47
|
+
// handle the types of actions
|
|
48
|
+
switch (template.type) {
|
|
49
|
+
case "extended":
|
|
50
|
+
template.text = "Extended display render!!";
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
return [2 /*return*/, template];
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
;
|
|
58
|
+
return ExtendedDisplay;
|
|
59
|
+
}());
|
|
60
|
+
exports.ExtendedDisplay = ExtendedDisplay;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Transition } from "../src/interfaces/actioninterface";
|
|
2
|
+
import { IDisplayExtension } from "../src/interfaces/displayextension";
|
|
3
|
+
import { Instance, Workflow } from "../src/interfaces/workflowinterface";
|
|
4
|
+
|
|
5
|
+
export class ExtendedDisplay implements IDisplayExtension {
|
|
6
|
+
async displays(instance: Instance, template: any): Promise<any>{
|
|
7
|
+
console.log("^^^ Extension -> displays");
|
|
8
|
+
// handle the types of actions
|
|
9
|
+
switch(template.type) {
|
|
10
|
+
case "extended":
|
|
11
|
+
template.text= "Extended display render!!";
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
return template;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
version: '3.8'
|
|
2
|
+
services:
|
|
3
|
+
postgres:
|
|
4
|
+
container_name: container-pg
|
|
5
|
+
image: postgres:16.2
|
|
6
|
+
command: -c config_file=/etc/postgresql.conf
|
|
7
|
+
hostname: localhost
|
|
8
|
+
ports:
|
|
9
|
+
- "5432:5432"
|
|
10
|
+
environment:
|
|
11
|
+
POSTGRES_USER: admin
|
|
12
|
+
POSTGRES_PASSWORD: root
|
|
13
|
+
POSTGRES_DB: test_workflows
|
|
14
|
+
volumes:
|
|
15
|
+
- postgres-data:/var/lib/postgresql/data
|
|
16
|
+
- ./postgresql.conf:/etc/postgresql.conf
|
|
17
|
+
- ./pg_hba.conf:/etc/pg_hba.conf
|
|
18
|
+
restart: unless-stopped
|
|
19
|
+
|
|
20
|
+
pgadmin:
|
|
21
|
+
container_name: container-pgadmin
|
|
22
|
+
image: dpage/pgadmin4
|
|
23
|
+
depends_on:
|
|
24
|
+
- postgres
|
|
25
|
+
ports:
|
|
26
|
+
- "5050:80"
|
|
27
|
+
environment:
|
|
28
|
+
PGADMIN_DEFAULT_EMAIL: admin@admin.com
|
|
29
|
+
PGADMIN_DEFAULT_PASSWORD: root
|
|
30
|
+
restart: unless-stopped
|
|
31
|
+
|
|
32
|
+
volumes:
|
|
33
|
+
postgres-data:
|
package/test/pg_hba.conf
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# TYPE DATABASE USER ADDRESS METHOD
|
|
2
|
+
|
|
3
|
+
# "local" is for Unix domain socket connections only
|
|
4
|
+
local all all trust
|
|
5
|
+
# IPv4 local connections:
|
|
6
|
+
host all all 0.0.0.0/0 trust
|
|
7
|
+
host all all all trust
|
|
8
|
+
# IPv6 local connections:
|
|
9
|
+
host all all ::1/128 trust
|
|
10
|
+
# Allow replication connections from localhost, by a user with the
|
|
11
|
+
# replication privilege.
|
|
12
|
+
#local replication postgres trust
|
|
13
|
+
#host replication postgres 127.0.0.1/32 trust
|
|
14
|
+
#host replication postgres ::1/128 trust
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#------------------------------------------------------------------------------
|
|
2
|
+
# FILE LOCATIONS
|
|
3
|
+
#------------------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
# The default values of these variables are driven from the -D command-line
|
|
6
|
+
# option or PGDATA environment variable, represented here as ConfigDir.
|
|
7
|
+
|
|
8
|
+
#data_directory = 'ConfigDir' # use data in another directory
|
|
9
|
+
# (change requires restart)
|
|
10
|
+
hba_file = '/etc/pg_hba.conf' # host-based authentication file
|
|
11
|
+
# (change requires restart)
|
|
12
|
+
#ident_file = 'ConfigDir/pg_ident.conf' # ident configuration file
|
|
13
|
+
# (change requires restart)
|
|
14
|
+
|
|
15
|
+
# If external_pid_file is not explicitly set, no extra PID file is written.
|
|
16
|
+
#external_pid_file = '' # write an extra PID file
|
|
17
|
+
# (change requires restart)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
#------------------------------------------------------------------------------
|
|
21
|
+
# CONNECTIONS AND AUTHENTICATION
|
|
22
|
+
#------------------------------------------------------------------------------
|
|
23
|
+
|
|
24
|
+
# - Connection Settings -
|
|
25
|
+
|
|
26
|
+
listen_addresses = '*' # what IP address(es) to listen on;
|
|
27
|
+
# comma-separated list of addresses;
|
|
28
|
+
# defaults to 'localhost'; use '*' for all
|
|
29
|
+
# (change requires restart)
|
|
30
|
+
port = 5432 # (change requires restart)
|
|
31
|
+
#max_connections = 100 # (change requires restart)
|
|
32
|
+
#reserved_connections = 0 # (change requires restart)
|
|
33
|
+
#superuser_reserved_connections = 3 # (change requires restart)
|
|
34
|
+
#unix_socket_directories = '/tmp' # comma-separated list of directories
|
|
35
|
+
# (change requires restart)
|
|
36
|
+
#unix_socket_group = '' # (change requires restart)
|
|
37
|
+
#unix_socket_permissions = 0777 # begin with 0 to use octal notation
|
|
38
|
+
# (change requires restart)
|
|
39
|
+
#bonjour = off # advertise server via Bonjour
|
|
40
|
+
# (change requires restart)
|
|
41
|
+
#bonjour_name = '' # defaults to the computer name
|
|
42
|
+
# (change requires restart)
|
package/test/tables.sql
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
CREATE TABLE workflows (
|
|
2
|
+
workflowID VARCHAR(255) PRIMARY KEY,
|
|
3
|
+
name VARCHAR(255),
|
|
4
|
+
formatVersion VARCHAR(50),
|
|
5
|
+
initialState VARCHAR(255),
|
|
6
|
+
render JSONB,
|
|
7
|
+
states JSONB
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
CREATE TABLE instances (
|
|
11
|
+
instanceID UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
12
|
+
workflowID VARCHAR(255),
|
|
13
|
+
clientID VARCHAR(255),
|
|
14
|
+
connectionID VARCHAR(255),
|
|
15
|
+
currentState VARCHAR(255),
|
|
16
|
+
stateData JSONB
|
|
17
|
+
);
|