@veridid/workflow-parser 0.4.2 → 0.4.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.
@@ -0,0 +1,82 @@
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
@@ -0,0 +1 @@
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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C,UAAU,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;4BAC1C,CAAC;4BACD,MAAM;wBACV,KAAK,oBAAoB;4BACrB,kBAAkB;4BAClB,IAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;gCACxB,kDAAkD;gCAClD,UAAU,CAAC,IAAI,GAAG,oBAAoB,CAAC;gCACvC,UAAU,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;4BAChD,CAAC;4BACD,MAAM;wBACV,QAAQ;oBACZ,CAAC;gBACL,CAAC;gBACD,uDAAuD;gBACvD,IAAI,cAAc,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,IAAI,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"}
@@ -0,0 +1,93 @@
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
@@ -0,0 +1 @@
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,IAAG,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC;wBACrC,SAAS,CAAG,qCAAqC;oBACrD,CAAC;gBACL,CAAC;gBAED,wDAAwD;gBACxD,IAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;oBACvB,IAAI,QAAQ,GAAG,MAAM,IAAI,CA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,CAAC;QACL,CAAC;QACD,qCAAqC;QACrC,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;IAGD,QAAQ,CAAC,EAAU,EAAE,WAAgB;QACjC,IAAI,YAAiB,EAAE,MAAW,CAAC;QAEnC,IAAI,EAAE,IAAI,WAAW,EAAE,CAAC;YACpB,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC;QAC3B,CAAC;aAAM,CAAC;YACJ,8DAA8D;YAC9D,4CAA4C;YAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,WAAW,CAAC,QAAQ,KAAK,SAAS,EAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC1D,YAAY,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;gBAEvC,8BAA8B;gBAC9B,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC;gBAEzC,+CAA+C;gBAC/C,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;oBACnB,OAAO,MAAM,CAAC;gBAClB,CAAC;YACL,CAAC;YAED,0DAA0D;YAC1D,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;CACJ;AA7FD,wCA6FC"}
@@ -0,0 +1,79 @@
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.DefaultWorkflow = void 0;
13
+ const uuid_1 = require("uuid");
14
+ class DefaultWorkflow {
15
+ constructor(dbClient) {
16
+ this.dbClient = dbClient;
17
+ }
18
+ getWorkflowByID(workflowID) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ var _a;
21
+ console.log("*** getWorkflowByID");
22
+ const res = yield ((_a = this.dbClient) === null || _a === void 0 ? void 0 : _a.query('SELECT * FROM workflows WHERE "workflow_id" = $1', [workflowID]));
23
+ //console.log("WorkflowID=", workflowID);
24
+ //console.log("Workflow=", res.rows[0]);
25
+ return res.rows.length > 0 ? res.rows[0] : null;
26
+ });
27
+ }
28
+ getInstanceByID(clientID, workflowID) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ var _a;
31
+ console.log("*** getInstanceByID");
32
+ let instance = null;
33
+ let query = 'SELECT * FROM instances WHERE "client_id" = $1 AND "workflow_id" = $2';
34
+ let res = yield ((_a = this.dbClient) === null || _a === void 0 ? void 0 : _a.query(query, [clientID, workflowID]));
35
+ //console.log("Look for existing instance clientID=", clientID, " workflowID=", workflowID);
36
+ //console.log("Found ", res.rows);
37
+ if (res.rows.length === 0) {
38
+ // no instance
39
+ //console.log("getInstanceByID - no instance");
40
+ const workflow = yield this.getWorkflowByID(workflowID);
41
+ // Create new instance with new instanceID, the initial state fromt he workflow, and empoty instance data
42
+ instance = yield this.newInstance(clientID, workflowID, workflow.initial_state);
43
+ }
44
+ else {
45
+ instance = res.rows.length > 0 ? res.rows[0] : null;
46
+ }
47
+ //console.log("Instance=", instance);
48
+ return instance;
49
+ });
50
+ }
51
+ newInstance(clientID, workflowID, stateID) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ var _a;
54
+ console.log("*** newInstance=", clientID, workflowID, stateID);
55
+ const query = 'INSERT INTO instances (instance_id, workflow_id, client_id, current_state, state_data) VALUES ($1, $2, $3, $4, $5)';
56
+ let result = yield ((_a = this.dbClient) === null || _a === void 0 ? void 0 : _a.query(query, [(0, uuid_1.v4)(), workflowID, clientID, stateID, {}]));
57
+ let res = yield this.getInstanceByID(clientID, workflowID);
58
+ return res;
59
+ });
60
+ }
61
+ updateInstanceByID(clientID, workflowID, stateID, data) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ var _a;
64
+ console.log("*** updateInstance=", clientID, workflowID, stateID, data);
65
+ // check instance and create new if does not exist
66
+ let instance = yield this.getInstanceByID(clientID, workflowID);
67
+ // update current_state and state_data
68
+ const query = "UPDATE instances SET current_state = $1, state_data = $2 WHERE workflow_id = $3 AND client_id = $4";
69
+ //console.log("query=", query);
70
+ //console.log("stateID=", stateID, " data=", data);
71
+ //console.log("workflowID=", stateID, " clientID=", clientID);
72
+ yield ((_a = this.dbClient) === null || _a === void 0 ? void 0 : _a.query(query, [stateID, JSON.stringify(data), workflowID, clientID]));
73
+ instance = yield this.getInstanceByID(clientID, workflowID);
74
+ return instance;
75
+ });
76
+ }
77
+ }
78
+ exports.DefaultWorkflow = DefaultWorkflow;
79
+ //# sourceMappingURL=workflow.default.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow.default.js","sourceRoot":"","sources":["../../src/implementations/workflow.default.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,+BAAoC;AAEpC,MAAa,eAAe;IAGxB,YAAY,QAAgB;QACxB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAEK,eAAe,CAAC,UAAkB;;;YACpC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;YACnC,MAAM,GAAG,GAAG,MAAM,CAAA,MAAA,IAAI,CAAC,QAAQ,0CAAE,KAAK,CAAC,kDAAkD,EAAE,CAAC,UAAU,CAAC,CAAC,CAAA,CAAC;YACzG,yCAAyC;YACzC,wCAAwC;YACxC,OAAO,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACpD,CAAC;KAAA;IAEK,eAAe,CAAC,QAA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GAAG,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;YAC3D,OAAO,GAAG,CAAC;QACf,CAAC;KAAA;IAEK,kBAAkB,CAAC,QAAgB,EAAE,UAAkB,EAAE,OAAe,EAAE,IAAS;;;YACrF,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;YACxE,kDAAkD;YAClD,IAAI,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;YAChE,sCAAsC;YACtC,MAAM,KAAK,GAAG,oGAAoG,CAAC;YACnH,+BAA+B;YAC/B,mDAAmD;YACnD,8DAA8D;YAC9D,MAAM,CAAA,MAAA,IAAI,CAAC,QAAQ,0CAAE,KAAK,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAA,CAAC;YACzF,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;YAC5D,OAAO,QAAQ,CAAC;QACpB,CAAC;KAAA;CAEJ;AA3DD,0CA2DC"}
package/dist/index.js CHANGED
@@ -1,22 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parse = exports.initDb = exports.loadWorkflowsFromJson = exports.loadWorkflowsFromFile = exports.deleteWorkflowInstances = exports.deleteWorkflowInstanceByID = exports.updateWorkflowInstanceByID = exports.getWorkflowInstanceByID = exports.getWorkflowInstances = exports.setWorkflowInstance = exports.deleteWorkflows = exports.deleteWorkflowByID = exports.updateWorkflowByID = exports.getWorkflowByID = exports.setWorkflows = exports.getWorkflows = exports.workflowExists = void 0;
4
- var dbCrud_1 = require("./dbCrud");
5
- Object.defineProperty(exports, "workflowExists", { enumerable: true, get: function () { return dbCrud_1.workflowExists; } });
6
- Object.defineProperty(exports, "getWorkflows", { enumerable: true, get: function () { return dbCrud_1.getWorkflows; } });
7
- Object.defineProperty(exports, "setWorkflows", { enumerable: true, get: function () { return dbCrud_1.setWorkflows; } });
8
- Object.defineProperty(exports, "getWorkflowByID", { enumerable: true, get: function () { return dbCrud_1.getWorkflowByID; } });
9
- Object.defineProperty(exports, "updateWorkflowByID", { enumerable: true, get: function () { return dbCrud_1.updateWorkflowByID; } });
10
- Object.defineProperty(exports, "deleteWorkflowByID", { enumerable: true, get: function () { return dbCrud_1.deleteWorkflowByID; } });
11
- Object.defineProperty(exports, "deleteWorkflows", { enumerable: true, get: function () { return dbCrud_1.deleteWorkflows; } });
12
- Object.defineProperty(exports, "setWorkflowInstance", { enumerable: true, get: function () { return dbCrud_1.setWorkflowInstance; } });
13
- Object.defineProperty(exports, "getWorkflowInstances", { enumerable: true, get: function () { return dbCrud_1.getWorkflowInstances; } });
14
- Object.defineProperty(exports, "getWorkflowInstanceByID", { enumerable: true, get: function () { return dbCrud_1.getWorkflowInstanceByID; } });
15
- Object.defineProperty(exports, "updateWorkflowInstanceByID", { enumerable: true, get: function () { return dbCrud_1.updateWorkflowInstanceByID; } });
16
- Object.defineProperty(exports, "deleteWorkflowInstanceByID", { enumerable: true, get: function () { return dbCrud_1.deleteWorkflowInstanceByID; } });
17
- Object.defineProperty(exports, "deleteWorkflowInstances", { enumerable: true, get: function () { return dbCrud_1.deleteWorkflowInstances; } });
18
- Object.defineProperty(exports, "loadWorkflowsFromFile", { enumerable: true, get: function () { return dbCrud_1.loadWorkflowsFromFile; } });
19
- Object.defineProperty(exports, "loadWorkflowsFromJson", { enumerable: true, get: function () { return dbCrud_1.loadWorkflowsFromJson; } });
20
- Object.defineProperty(exports, "initDb", { enumerable: true, get: function () { return dbCrud_1.initDb; } });
21
- var parser_1 = require("./parser");
22
- Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parser_1.parse; } });
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; } });
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAG1B,mDAEyB;AADrB,gHAAA,cAAc,OAAA"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=actionextension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actionextension.js","sourceRoot":"","sources":["../../src/interfaces/actionextension.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=actioninterface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actioninterface.js","sourceRoot":"","sources":["../../src/interfaces/actioninterface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=displayextension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"displayextension.js","sourceRoot":"","sources":["../../src/interfaces/displayextension.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=displayinterface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"displayinterface.js","sourceRoot":"","sources":["../../src/interfaces/displayinterface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=workflowinterface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflowinterface.js","sourceRoot":"","sources":["../../src/interfaces/workflowinterface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,59 @@
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.WorkflowParser = void 0;
13
+ class WorkflowParser {
14
+ constructor(display, action, workflow) {
15
+ this.display = display;
16
+ this.action = action;
17
+ this.workflow = workflow;
18
+ }
19
+ parse(clientID, action) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ console.log("=== parse clientID=", clientID, " action=", action);
22
+ // get the workflow as JSON
23
+ let curentWorkflow = yield this.workflow.getWorkflowByID(action === null || action === void 0 ? void 0 : action.workflowID);
24
+ console.log("+++ currentWorkflow");
25
+ // get the instance as JSON
26
+ let instance = yield this.workflow.getInstanceByID(clientID, action === null || action === void 0 ? void 0 : action.workflowID);
27
+ console.log("+++ instance");
28
+ // current state in the workflow
29
+ let currentState = instance.current_state;
30
+ // process the action
31
+ let transition = yield this.action.processAction(curentWorkflow, instance, action);
32
+ console.log("+++ transition");
33
+ if (transition.type != "none") {
34
+ // process the transition
35
+ if (transition.type === 'workflowTransition') {
36
+ // get the new workflow
37
+ curentWorkflow = yield this.workflow.getWorkflowByID(transition === null || transition === void 0 ? void 0 : transition.workflow_id);
38
+ // get the new instance
39
+ instance = yield this.workflow.getInstanceByID(clientID, transition === null || transition === void 0 ? void 0 : transition.workflow_id);
40
+ currentState = instance.current_state;
41
+ }
42
+ if (transition.type === 'stateTransition') {
43
+ // set the new current state
44
+ currentState = transition.state_id;
45
+ }
46
+ }
47
+ // update the instance
48
+ const updatedInstance = yield this.workflow.updateInstanceByID(clientID, curentWorkflow.workflow_id, currentState, instance.state_data);
49
+ console.log("+++ Updated instance");
50
+ // process the display
51
+ const display = yield this.display.processDisplay(clientID, curentWorkflow, updatedInstance, currentState);
52
+ console.log("+++ Prcoessed display");
53
+ // return workflowID and display
54
+ return { workflowID: curentWorkflow.workflow_id, displayData: display.displayData };
55
+ });
56
+ }
57
+ }
58
+ exports.WorkflowParser = WorkflowParser;
59
+ //# sourceMappingURL=workflowparser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflowparser.js","sourceRoot":"","sources":["../src/workflowparser.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,MAAa,cAAc;IAKvB,YACI,OAAiB,EACjB,MAAe,EACf,QAAmB;QAEnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAEK,KAAK,CACP,QAAgB,EAChB,MAGgB;;YAEhB,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;YAEjE,2BAA2B;YAC3B,IAAI,cAAc,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,CAAC,CAAC;YAC7E,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;YAEnC,2BAA2B;YAC3B,IAAI,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,QAAQ,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,CAAC,CAAC;YACjF,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YAE5B,gCAAgC;YAChC,IAAI,YAAY,GAAG,QAAQ,CAAC,aA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AC,UAAU,EAAE,cAAc,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAC,CAAC;QACtF,CAAC;KAAA;CACJ;AAjED,wCAiEC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veridid/workflow-parser",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
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": {