@veridid/workflow-parser 0.4.4 → 0.4.6
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/dist/index.d.ts +1 -0
- package/package.json +2 -2
- package/dist/db.js +0 -40
- package/dist/dbCrud.js +0 -210
- package/dist/parser.js +0 -125
- package/dist/schema.sql +0 -16
- package/dist/src/implementations/action.default.js +0 -82
- package/dist/src/implementations/action.default.js.map +0 -1
- package/dist/src/implementations/display.default.js +0 -93
- package/dist/src/implementations/display.default.js.map +0 -1
- package/dist/src/implementations/workflow.default.js +0 -79
- package/dist/src/implementations/workflow.default.js.map +0 -1
- package/dist/src/index.js +0 -7
- package/dist/src/index.js.map +0 -1
- package/dist/src/interfaces/actionextension.js +0 -3
- package/dist/src/interfaces/actionextension.js.map +0 -1
- package/dist/src/interfaces/actioninterface.js +0 -3
- package/dist/src/interfaces/actioninterface.js.map +0 -1
- package/dist/src/interfaces/displayextension.js +0 -3
- package/dist/src/interfaces/displayextension.js.map +0 -1
- package/dist/src/interfaces/displayinterface.js +0 -3
- package/dist/src/interfaces/displayinterface.js.map +0 -1
- package/dist/src/interfaces/workflowinterface.js +0 -3
- package/dist/src/interfaces/workflowinterface.js.map +0 -1
- package/dist/src/workflowparser.js +0 -59
- package/dist/src/workflowparser.js.map +0 -1
- package/dist/test/action.extension.js +0 -34
- package/dist/test/action.extension.js.map +0 -1
- package/dist/test/display.extension.js +0 -29
- package/dist/test/display.extension.js.map +0 -1
- package/dist/test/test.js +0 -178
- package/dist/test/test.js.map +0 -1
- package/dist/test/testworkflows.json +0 -221
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module '@veridid/workflow-parser'
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veridid/workflow-parser",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.4.6",
|
|
4
|
+
"description": "For parsing JOSN data that represents data-driven state machines and delivering the display data for clients to render.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc",
|
package/dist/db.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const pg_1 = require("pg");
|
|
16
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
17
|
-
dotenv_1.default.config();
|
|
18
|
-
const initializeClient = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
-
console.log('DB User:', process.env.WORKFLOW_DB_USER);
|
|
20
|
-
console.log('DB Host:', process.env.WORKFLOW_DB_HOST);
|
|
21
|
-
console.log('DB Name:', process.env.WORKFLOW_DB_NAME);
|
|
22
|
-
console.log('DB Password:', process.env.WORKFLOW_DB_PASSWORD);
|
|
23
|
-
console.log('DB Port:', process.env.WORKFLOW_DB_PORT);
|
|
24
|
-
const client = new pg_1.Client({
|
|
25
|
-
user: process.env.WORKFLOW_DB_USER,
|
|
26
|
-
host: process.env.WORKFLOW_DB_HOST,
|
|
27
|
-
database: process.env.WORKFLOW_DB_NAME,
|
|
28
|
-
password: process.env.WORKFLOW_DB_PASSWORD,
|
|
29
|
-
port: Number(process.env.WORKFLOW_DB_PORT),
|
|
30
|
-
});
|
|
31
|
-
yield client.connect().then(() => {
|
|
32
|
-
console.log('Connected to PostgreSQL database');
|
|
33
|
-
}).catch((err) => {
|
|
34
|
-
console.error('Connection error', err.stack);
|
|
35
|
-
process.exit(1);
|
|
36
|
-
});
|
|
37
|
-
return client;
|
|
38
|
-
});
|
|
39
|
-
const clientPromise = initializeClient();
|
|
40
|
-
exports.default = clientPromise;
|
package/dist/dbCrud.js
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.ensureClient = void 0;
|
|
16
|
-
exports.workflowExists = workflowExists;
|
|
17
|
-
exports.setWorkflows = setWorkflows;
|
|
18
|
-
exports.getWorkflows = getWorkflows;
|
|
19
|
-
exports.getWorkflowByID = getWorkflowByID;
|
|
20
|
-
exports.updateWorkflowByID = updateWorkflowByID;
|
|
21
|
-
exports.deleteWorkflowByID = deleteWorkflowByID;
|
|
22
|
-
exports.deleteWorkflows = deleteWorkflows;
|
|
23
|
-
exports.setWorkflowInstance = setWorkflowInstance;
|
|
24
|
-
exports.getWorkflowInstances = getWorkflowInstances;
|
|
25
|
-
exports.getWorkflowInstanceByID = getWorkflowInstanceByID;
|
|
26
|
-
exports.getWorkflowInstance = getWorkflowInstance;
|
|
27
|
-
exports.updateWorkflowInstanceByID = updateWorkflowInstanceByID;
|
|
28
|
-
exports.deleteWorkflowInstanceByID = deleteWorkflowInstanceByID;
|
|
29
|
-
exports.deleteWorkflowInstances = deleteWorkflowInstances;
|
|
30
|
-
exports.initDb = initDb;
|
|
31
|
-
exports.loadWorkflowsFromFile = loadWorkflowsFromFile;
|
|
32
|
-
exports.loadWorkflowsFromJson = loadWorkflowsFromJson;
|
|
33
|
-
const db_1 = __importDefault(require("./db"));
|
|
34
|
-
const fs_1 = require("fs");
|
|
35
|
-
const path_1 = require("path");
|
|
36
|
-
let client;
|
|
37
|
-
const ensureClient = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
-
if (!client) {
|
|
39
|
-
client = yield db_1.default;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
exports.ensureClient = ensureClient;
|
|
43
|
-
function workflowExists(workflowID) {
|
|
44
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
yield (0, exports.ensureClient)();
|
|
46
|
-
const res = yield client.query('SELECT 1 FROM workflows WHERE "workflowID" = $1', [workflowID]);
|
|
47
|
-
return res.rowCount > 0;
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
function setWorkflows(workflows) {
|
|
51
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
yield (0, exports.ensureClient)();
|
|
53
|
-
const query = 'INSERT INTO workflows ("workflowID", name, "formatVersion", "initialState", render, states) VALUES ($1, $2, $3, $4, $5, $6)';
|
|
54
|
-
for (const workflow of workflows) {
|
|
55
|
-
const exists = yield workflowExists(workflow.workflowID);
|
|
56
|
-
if (exists) {
|
|
57
|
-
console.log(`Workflow ${workflow.workflowID} already exists. Skipping insertion.`);
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
console.log("Inserting workflow:", workflow);
|
|
61
|
-
yield client.query(query, [
|
|
62
|
-
workflow.workflowID,
|
|
63
|
-
workflow.name,
|
|
64
|
-
workflow.formatVersion,
|
|
65
|
-
workflow.initialState,
|
|
66
|
-
JSON.stringify(workflow.render),
|
|
67
|
-
JSON.stringify(workflow.states)
|
|
68
|
-
]);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
function getWorkflows() {
|
|
73
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
yield (0, exports.ensureClient)();
|
|
75
|
-
const res = yield client.query('SELECT * FROM workflows');
|
|
76
|
-
return res.rows;
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
function getWorkflowByID(workflowID) {
|
|
80
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
yield (0, exports.ensureClient)();
|
|
82
|
-
const res = yield client.query('SELECT * FROM workflows WHERE "workflowID" = $1', [workflowID]);
|
|
83
|
-
return res.rows[0];
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
function updateWorkflowByID(workflowID, workflow) {
|
|
87
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
yield (0, exports.ensureClient)();
|
|
89
|
-
const query = 'UPDATE workflows SET name = $1, "formatVersion" = $2, "initialState" = $3, render = $4, states = $5 WHERE "workflowID" = $6';
|
|
90
|
-
yield client.query(query, [workflow.name, workflow.formatVersion, workflow.initialState, workflow.render, workflow.states, workflowID]);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
function deleteWorkflowByID(workflowID) {
|
|
94
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
-
yield (0, exports.ensureClient)();
|
|
96
|
-
yield client.query('DELETE FROM workflows WHERE "workflowID" = $1', [workflowID]);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
function deleteWorkflows() {
|
|
100
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
yield (0, exports.ensureClient)();
|
|
102
|
-
yield client.query('DELETE FROM workflows');
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
function setWorkflowInstance(instance) {
|
|
106
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
-
yield (0, exports.ensureClient)();
|
|
108
|
-
const query = 'INSERT INTO instances ("instanceID", "workflowID", "connectionID", "currentState", "stateData") VALUES ($1, $2, $3, $4, $5)';
|
|
109
|
-
yield client.query(query, [instance.instanceID, instance.workflowID, instance.connectionID, instance.currentState, instance.stateData]);
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
function getWorkflowInstances() {
|
|
113
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
yield (0, exports.ensureClient)();
|
|
115
|
-
const res = yield client.query('SELECT * FROM instances');
|
|
116
|
-
return res.rows;
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
function getWorkflowInstanceByID(instanceID) {
|
|
120
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
-
yield (0, exports.ensureClient)();
|
|
122
|
-
const res = yield client.query('SELECT * FROM instances WHERE "instanceID" = $1', [instanceID]);
|
|
123
|
-
return res.rows[0];
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
function getWorkflowInstance(connectionID, workflowID) {
|
|
127
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
yield (0, exports.ensureClient)();
|
|
129
|
-
const res = yield client.query('SELECT * FROM instances WHERE "connectionID" = $1 AND "workflowID" = $2', [connectionID, workflowID]);
|
|
130
|
-
return res.rows.length > 0 ? res.rows[0] : null;
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
function updateWorkflowInstanceByID(instanceID, instance) {
|
|
134
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
yield (0, exports.ensureClient)();
|
|
136
|
-
const query = 'UPDATE instances SET "workflowID" = $1, "connectionID" = $2, "currentState" = $3, "stateData" = $4 WHERE "instanceID" = $5';
|
|
137
|
-
yield client.query(query, [instance.workflowID, instance.connectionID, instance.currentState, instance.stateData, instanceID]);
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
function deleteWorkflowInstanceByID(instanceID) {
|
|
141
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
yield (0, exports.ensureClient)();
|
|
143
|
-
yield client.query('DELETE FROM instances WHERE "instanceID" = $1', [instanceID]);
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
function deleteWorkflowInstances() {
|
|
147
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
-
yield (0, exports.ensureClient)();
|
|
149
|
-
yield client.query('DELETE FROM instances');
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
function initDb() {
|
|
153
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
-
yield (0, exports.ensureClient)();
|
|
155
|
-
try {
|
|
156
|
-
const schema = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, 'schema.sql')).toString();
|
|
157
|
-
yield client.query(schema);
|
|
158
|
-
console.log('Database initialized');
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
if (error.code === '42P07') {
|
|
162
|
-
console.log('Database already initialized');
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
console.error('Error initializing database', error);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
function loadWorkflowsFromFile(filePath) {
|
|
171
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
-
yield (0, exports.ensureClient)();
|
|
173
|
-
try {
|
|
174
|
-
const workflowsData = (0, fs_1.readFileSync)(filePath, 'utf-8');
|
|
175
|
-
const workflows = JSON.parse(workflowsData);
|
|
176
|
-
let insertedCount = 0;
|
|
177
|
-
let skippedCount = 0;
|
|
178
|
-
for (const workflow of workflows) {
|
|
179
|
-
const exists = yield workflowExists(workflow.workflowID);
|
|
180
|
-
if (exists) {
|
|
181
|
-
console.log(`Workflow ${workflow.workflowID} already exists. Skipping insertion.`);
|
|
182
|
-
skippedCount++;
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
console.log(`Inserting workflow: ${JSON.stringify(workflow)}`);
|
|
186
|
-
yield client.query('INSERT INTO workflows ("workflowID", name, "formatVersion", "initialState", render, states) VALUES ($1, $2, $3, $4, $5, $6)', [
|
|
187
|
-
workflow.workflowID,
|
|
188
|
-
workflow.name,
|
|
189
|
-
workflow.formatVersion,
|
|
190
|
-
workflow.initialState,
|
|
191
|
-
JSON.stringify(workflow.render),
|
|
192
|
-
JSON.stringify(workflow.states)
|
|
193
|
-
]);
|
|
194
|
-
insertedCount++;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
console.log(`Workflows loaded successfully. Inserted: ${insertedCount}, Skipped: ${skippedCount}`);
|
|
198
|
-
}
|
|
199
|
-
catch (error) {
|
|
200
|
-
console.error('Error loading workflows from file:', error.message);
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
function loadWorkflowsFromJson(jsonContent) {
|
|
205
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
206
|
-
yield (0, exports.ensureClient)();
|
|
207
|
-
const workflows = JSON.parse(jsonContent);
|
|
208
|
-
yield setWorkflows(workflows);
|
|
209
|
-
});
|
|
210
|
-
}
|
package/dist/parser.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.parse = parse;
|
|
13
|
-
const uuid_1 = require("uuid");
|
|
14
|
-
const dbCrud_1 = require("./dbCrud");
|
|
15
|
-
function parse(connectionID, action) {
|
|
16
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
yield (0, dbCrud_1.ensureClient)();
|
|
18
|
-
const { workflowID, actionID, data } = action;
|
|
19
|
-
const workflow = yield (0, dbCrud_1.getWorkflowByID)(workflowID);
|
|
20
|
-
if (!workflow) {
|
|
21
|
-
throw new Error('Workflow not found');
|
|
22
|
-
}
|
|
23
|
-
let instance = yield (0, dbCrud_1.getWorkflowInstance)(connectionID, workflowID);
|
|
24
|
-
if (!instance) {
|
|
25
|
-
instance = {
|
|
26
|
-
instanceID: (0, uuid_1.v4)(),
|
|
27
|
-
workflowID,
|
|
28
|
-
connectionID,
|
|
29
|
-
currentState: workflow.initialState,
|
|
30
|
-
stateData: {},
|
|
31
|
-
};
|
|
32
|
-
yield (0, dbCrud_1.setWorkflowInstance)(instance);
|
|
33
|
-
console.log(`New instance created: ${instance.instanceID}`);
|
|
34
|
-
const initialState = workflow.states.find((state) => state.stateID === workflow.initialState);
|
|
35
|
-
if (!initialState) {
|
|
36
|
-
throw new Error('Initial state not found in workflow');
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
workflowID: workflow.workflowID,
|
|
40
|
-
displayData: initialState.displayData,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
console.log("instance", instance);
|
|
44
|
-
const currentState = workflow.states.find((state) => state.stateID === instance.currentState);
|
|
45
|
-
if (!currentState) {
|
|
46
|
-
console.error(`Current state not found: ${instance.currentState}`);
|
|
47
|
-
throw new Error('Current state not found in workflow');
|
|
48
|
-
}
|
|
49
|
-
console.log(`Current state: ${currentState.stateID}`);
|
|
50
|
-
if (actionID) {
|
|
51
|
-
const transition = currentState.transitions.find((t) => t.actionID === actionID);
|
|
52
|
-
console.log("transition", transition);
|
|
53
|
-
if (!transition) {
|
|
54
|
-
console.error(`Action not found in current state transitions: ${actionID}`);
|
|
55
|
-
return {
|
|
56
|
-
workflowID: workflow.workflowID,
|
|
57
|
-
displayData: currentState.displayData,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
console.log(`Transition found: ${transition.actionID}`);
|
|
61
|
-
if (transition.type === 'workflow') {
|
|
62
|
-
const newWorkflowID = transition.value;
|
|
63
|
-
const newWorkflow = yield (0, dbCrud_1.getWorkflowByID)(newWorkflowID);
|
|
64
|
-
if (!newWorkflow) {
|
|
65
|
-
console.log(`New workflow not found: ${newWorkflowID}`);
|
|
66
|
-
return {
|
|
67
|
-
workflowID: `${newWorkflowID}`,
|
|
68
|
-
displayData: [
|
|
69
|
-
{ text: 'Note: Workflow NOT found', type: 'title' },
|
|
70
|
-
{
|
|
71
|
-
text: 'We are working on it. Please explore other options. Type :menu to view home menu',
|
|
72
|
-
type: 'text'
|
|
73
|
-
}
|
|
74
|
-
],
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
let newInstance = yield (0, dbCrud_1.getWorkflowInstance)(connectionID, newWorkflowID);
|
|
78
|
-
if (!newInstance) {
|
|
79
|
-
newInstance = {
|
|
80
|
-
instanceID: (0, uuid_1.v4)(),
|
|
81
|
-
workflowID: newWorkflowID,
|
|
82
|
-
connectionID,
|
|
83
|
-
currentState: newWorkflow.initialState,
|
|
84
|
-
stateData: {},
|
|
85
|
-
};
|
|
86
|
-
yield (0, dbCrud_1.setWorkflowInstance)(newInstance);
|
|
87
|
-
console.log(`New instance created for workflow ${newWorkflowID}: ${newInstance.instanceID}`);
|
|
88
|
-
}
|
|
89
|
-
const currentState = newWorkflow.states.find((state) => state.stateID === newInstance.currentState);
|
|
90
|
-
if (!currentState) {
|
|
91
|
-
console.error(`Current state not found: ${instance.currentState}`);
|
|
92
|
-
throw new Error('Current state not found in workflow');
|
|
93
|
-
}
|
|
94
|
-
console.log(`Current state: ${currentState.stateID}`);
|
|
95
|
-
return {
|
|
96
|
-
workflowID: newWorkflow.workflowID,
|
|
97
|
-
displayData: currentState.displayData,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
else if (transition.type === 'state') {
|
|
101
|
-
instance.currentState = transition.value;
|
|
102
|
-
yield (0, dbCrud_1.updateWorkflowInstanceByID)(instance.instanceID, instance);
|
|
103
|
-
console.log(`Instance state updated: ${instance.currentState}`);
|
|
104
|
-
const nextState = workflow.states.find((state) => state.stateID === instance.currentState);
|
|
105
|
-
if (!nextState) {
|
|
106
|
-
console.error(`Next state not found: ${instance.currentState}`);
|
|
107
|
-
throw new Error('Next state not found in workflow');
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
workflowID: workflow.workflowID,
|
|
111
|
-
displayData: nextState.displayData,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
throw new Error(`Unknown transition type: ${transition.type}`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
return {
|
|
120
|
-
workflowID: workflow.workflowID,
|
|
121
|
-
displayData: currentState.displayData,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}
|
package/dist/schema.sql
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
CREATE TABLE workflows (
|
|
2
|
-
"workflowID" VARCHAR(255) PRIMARY KEY,
|
|
3
|
-
name VARCHAR(255) NOT NULL,
|
|
4
|
-
"formatVersion" VARCHAR(50) NOT NULL,
|
|
5
|
-
"initialState" VARCHAR(255) NOT NULL,
|
|
6
|
-
render JSONB NOT NULL,
|
|
7
|
-
states JSONB NOT NULL
|
|
8
|
-
);
|
|
9
|
-
|
|
10
|
-
CREATE TABLE instances (
|
|
11
|
-
"instanceID" UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
12
|
-
"workflowID" VARCHAR(255) REFERENCES workflows("workflowID"),
|
|
13
|
-
"connectionID" VARCHAR(255),
|
|
14
|
-
"currentState" VARCHAR(255),
|
|
15
|
-
"stateData" JSONB
|
|
16
|
-
);
|
|
@@ -1,82 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.DefaultAction = void 0;
|
|
13
|
-
class DefaultAction {
|
|
14
|
-
constructor(actionExtension) {
|
|
15
|
-
this.actionExtension = actionExtension;
|
|
16
|
-
}
|
|
17
|
-
processAction(currentWorkflow, instance, actionInput) {
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
console.log("*** processAction action=", actionInput);
|
|
20
|
-
// start with a blank transition
|
|
21
|
-
let transition = {
|
|
22
|
-
type: "none",
|
|
23
|
-
workflow_id: instance.workflow_id,
|
|
24
|
-
state_id: instance.current_state
|
|
25
|
-
};
|
|
26
|
-
if (actionInput.actionID != "") {
|
|
27
|
-
// find the state
|
|
28
|
-
const state = currentWorkflow.states.find(item => { return item.state_id == instance.current_state; });
|
|
29
|
-
// Only process actions if there are any
|
|
30
|
-
if (state.actions.length > 0) {
|
|
31
|
-
const action = state.actions.find(item => { return item.action_id == actionInput.actionID; });
|
|
32
|
-
// handle the types of actions from the extension first
|
|
33
|
-
if (this.actionExtension) {
|
|
34
|
-
transition = yield this.actionExtension.actions(actionInput, instance, action, transition);
|
|
35
|
-
}
|
|
36
|
-
// handle the types of actions
|
|
37
|
-
switch (action === null || action === void 0 ? void 0 : action.type) {
|
|
38
|
-
case "saveData":
|
|
39
|
-
// check condition
|
|
40
|
-
if (eval(action.condition)) {
|
|
41
|
-
// save the data from the workflow action to the instance data
|
|
42
|
-
instance.state_data = Object.assign(instance.state_data, action.value);
|
|
43
|
-
}
|
|
44
|
-
break;
|
|
45
|
-
case "stateData":
|
|
46
|
-
// check condition
|
|
47
|
-
if (eval(action.condition)) {
|
|
48
|
-
// save the data from the actionInput to the instance data
|
|
49
|
-
instance.state_data = Object.assign(instance.state_data, actionInput.data);
|
|
50
|
-
}
|
|
51
|
-
break;
|
|
52
|
-
case "stateTransition":
|
|
53
|
-
// check condition
|
|
54
|
-
if (eval(action.condition)) {
|
|
55
|
-
// set the transition condition for a new state
|
|
56
|
-
transition.type = "stateTransition";
|
|
57
|
-
transition.state_id = action.state_id;
|
|
58
|
-
}
|
|
59
|
-
break;
|
|
60
|
-
case "workflowTransition":
|
|
61
|
-
// check condition
|
|
62
|
-
if (eval(action.condition)) {
|
|
63
|
-
// set the transition condition for a new workflow
|
|
64
|
-
transition.type = "workflowTransition";
|
|
65
|
-
transition.workflow_id = action.workflow_id;
|
|
66
|
-
}
|
|
67
|
-
break;
|
|
68
|
-
default:
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
// check the transitions until the first true condition
|
|
72
|
-
let findtransition = state.transitions.find(item => { return eval(item.condition); });
|
|
73
|
-
if (findtransition) {
|
|
74
|
-
transition = findtransition;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return transition;
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
exports.DefaultAction = DefaultAction;
|
|
82
|
-
//# sourceMappingURL=action.default.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"action.default.js","sourceRoot":"","sources":["../../../src/implementations/action.default.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,MAAa,aAAa;IAGtB,YAAY,eAAiC;QACzC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IAC3C,CAAC;IAEK,aAAa,CAAC,eAAyB,EAAE,QAAkB,EAAE,WAAgB;;YAC/E,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,WAAW,CAAC,CAAC;YACtD,gCAAgC;YAChC,IAAI,UAAU,GAAc;gBACxB,IAAI,EAAE,MAAM;gBACZ,WAAW,EAAE,QAAQ,CAAC,WAAW;gBACjC,QAAQ,EAAE,QAAQ,CAAC,aAAa;aACnC,CAAC;YAEF,IAAG,WAAW,CAAC,QAAQ,IAAE,EAAE,EAAE,CAAC;gBAC1B,iBAAiB;gBACjB,MAAM,KAAK,GAAG,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,aAAa,CAAA,CAAC,CAAC,CAAC,CAAC;gBACtG,wCAAwC;gBACxC,IAAG,KAAK,CAAC,OAAO,CAAC,MAAM,GAAC,CAAC,EAAE,CAAC;oBACxB,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,IAAI,CAAC,SAAS,IAAI,WAAW,CAAC,QAAQ,CAAA,CAAC,CAAC,CAAC,CAAA;oBAC5F,uDAAuD;oBACvD,IAAG,IAAI,CAAC,eAAe,EAAE,CAAC;wBACtB,UAAU,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,CAA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AI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA,CAAC,CAAC,CAAC,CAAA;gBACpF,IAAG,cAAc,EAAE,CAAC;oBAChB,UAAU,GAAG,cAAc,CAAC;gBAChC,CAAC;YACL,CAAC;YACD,OAAO,UAAU,CAAC;QACtB,CAAC;KAAA;CACJ;AArED,sCAqEC"}
|
|
@@ -1,93 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.DefaultDisplay = void 0;
|
|
13
|
-
class DefaultDisplay {
|
|
14
|
-
constructor(displayExtension) {
|
|
15
|
-
this.displayExtension = displayExtension;
|
|
16
|
-
}
|
|
17
|
-
processDisplay(clientID, curentWorkflow, instance, currentState) {
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
var _a;
|
|
20
|
-
console.log("*** processDisplay");
|
|
21
|
-
// build the display data to return
|
|
22
|
-
let displayData = { displayData: [] };
|
|
23
|
-
// for each display entry check condition and process if required
|
|
24
|
-
const display = curentWorkflow.states.find(item => { return item.state_id == currentState; });
|
|
25
|
-
const displayTemplate = display.display_data;
|
|
26
|
-
for (var i = 0; i < displayTemplate.length; i++) {
|
|
27
|
-
// condition can use instance.stateData
|
|
28
|
-
if ((_a = displayTemplate[i]) === null || _a === void 0 ? void 0 : _a.condition) {
|
|
29
|
-
if (!eval(displayTemplate[i].condition)) {
|
|
30
|
-
continue; // don't process if condition not met
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
// handle the types of displays from the extension first
|
|
34
|
-
if (this.displayExtension) {
|
|
35
|
-
let newValue = yield this.displayExtension.displays(instance, displayTemplate[i]);
|
|
36
|
-
if (newValue) {
|
|
37
|
-
displayTemplate[i] = newValue;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
switch (displayTemplate[i].type) {
|
|
41
|
-
case "text":
|
|
42
|
-
displayTemplate[i].text = this.parseString(displayTemplate[i].text, instance.state_data);
|
|
43
|
-
break;
|
|
44
|
-
case "control":
|
|
45
|
-
displayTemplate[i].text = this.parseString(displayTemplate[i].text, instance.state_data);
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
displayData.displayData[i] = displayTemplate[i];
|
|
49
|
-
}
|
|
50
|
-
return displayData;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
parseString(text, data) {
|
|
54
|
-
// Split out the string
|
|
55
|
-
const parts = text.split(/[{,}]/);
|
|
56
|
-
// check every other string segment looking for a key in data
|
|
57
|
-
// Text for parsing should not start with a variable "{variable} hello!"
|
|
58
|
-
// *** repalce this code with a more comprehensive parser
|
|
59
|
-
for (var i = 1; i < parts.length; i += 2) {
|
|
60
|
-
// find this value in the data
|
|
61
|
-
let value = this.findNode(parts[i], data);
|
|
62
|
-
if (value) {
|
|
63
|
-
// if there is a value, replace the entry
|
|
64
|
-
parts[i] = value;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
// put the string back together again
|
|
68
|
-
return parts.join("");
|
|
69
|
-
}
|
|
70
|
-
findNode(id, currentNode) {
|
|
71
|
-
var currentChild, result;
|
|
72
|
-
if (id in currentNode) {
|
|
73
|
-
return currentNode[id];
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
// use a for loop instead of forEach to avoid nested functions
|
|
77
|
-
// otherwise "return" will not work properly
|
|
78
|
-
for (var i = 0; currentNode.children !== undefined; i += 1) {
|
|
79
|
-
currentChild = currentNode.children[i];
|
|
80
|
-
// Search in the current child
|
|
81
|
-
result = this.findNode(id, currentChild);
|
|
82
|
-
// Return the result if the node has been found
|
|
83
|
-
if (result !== false) {
|
|
84
|
-
return result;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
// the node has not been found and we have no more options
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
exports.DefaultDisplay = DefaultDisplay;
|
|
93
|
-
//# sourceMappingURL=display.default.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"display.default.js","sourceRoot":"","sources":["../../../src/implementations/display.default.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,MAAa,cAAc;IAGvB,YAAY,gBAAmC;QAC3C,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC7C,CAAC;IAEK,cAAc,CAChB,QAAgB,EAChB,cAAwB,EACxB,QAAkB,EAClB,YAAoB;;;YAEpB,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;YAClC,mCAAmC;YACnC,IAAI,WAAW,GAAgB,EAAC,WAAW,EAAE,EAAE,EAAC,CAAC;YACjD,iEAAiE;YACjE,MAAM,OAAO,GAAG,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,IAAI,CAAC,QAAQ,IAAI,YAAY,CAAA,CAAA,CAAC,CAAC,CAAC;YAC5F,MAAM,eAAe,GAAG,OAAO,CAAC,YAAY,CAAC;YAC7C,KAAI,IAAI,CAAC,GAAC,CAAC,EAAE,CAAC,GAAC,eAAe,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACzC,uCAAuC;gBACvC,IAAG,MAAA,eAAe,CAAC,CAAC,CAAC,0CAAE,SAAS,EAAE,CAAC;oBAC/B,IAA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