bpmn-client 2.1.0 → 2.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BPMNClient.js +10 -0
- package/dist/cli.js +102 -66
- package/package.json +1 -1
package/dist/BPMNClient.js
CHANGED
|
@@ -153,6 +153,16 @@ class ClientEngine {
|
|
|
153
153
|
return ret;
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
|
+
startEvent(instanceId, startNodeId, data = {}) {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
const ret = yield this.client.put('engine/startEvent', { "instanceId": instanceId, "startNodeId": startNodeId, "data": data });
|
|
159
|
+
if (ret['errors']) {
|
|
160
|
+
console.log(ret['errors']);
|
|
161
|
+
throw new Error(ret['errors']);
|
|
162
|
+
}
|
|
163
|
+
return ret;
|
|
164
|
+
});
|
|
165
|
+
}
|
|
156
166
|
get(query) {
|
|
157
167
|
return __awaiter(this, void 0, void 0, function* () {
|
|
158
168
|
const ret = yield this.client.get('engine/get', query);
|
package/dist/cli.js
CHANGED
|
@@ -16,14 +16,29 @@ const readline = require("readline");
|
|
|
16
16
|
const dotenv = require('dotenv');
|
|
17
17
|
const res = dotenv.config();
|
|
18
18
|
const server = new _1.BPMNClient(process.env.HOST, process.env.PORT, process.env.API_KEY);
|
|
19
|
-
const cl = readline.createInterface(process.stdin, process.stdout);
|
|
20
19
|
const question = function (q) {
|
|
20
|
+
const cl = readline.createInterface(process.stdin, process.stdout);
|
|
21
|
+
console.log(q);
|
|
22
|
+
cl.setPrompt('>');
|
|
23
|
+
cl.prompt();
|
|
21
24
|
return new Promise((res, rej) => {
|
|
22
|
-
cl.
|
|
25
|
+
cl.on('line', answer => {
|
|
26
|
+
answer = removeBS(answer);
|
|
23
27
|
res(answer);
|
|
28
|
+
cl.close();
|
|
24
29
|
});
|
|
25
30
|
});
|
|
26
31
|
};
|
|
32
|
+
function removeBS(str) {
|
|
33
|
+
if (str.indexOf('\b') === -1)
|
|
34
|
+
return str;
|
|
35
|
+
let l;
|
|
36
|
+
while (str.indexOf('\b') > -1) {
|
|
37
|
+
l = str.indexOf('\b');
|
|
38
|
+
str = str.substring(0, l - 1) + str.substring(l + 1);
|
|
39
|
+
}
|
|
40
|
+
return str;
|
|
41
|
+
}
|
|
27
42
|
completeUserTask();
|
|
28
43
|
function menu() {
|
|
29
44
|
console.log('Commands:');
|
|
@@ -36,7 +51,10 @@ function menu() {
|
|
|
36
51
|
console.log(' i Invoke Task');
|
|
37
52
|
console.log(' sgl Signal Task');
|
|
38
53
|
console.log(' msg Message Task');
|
|
54
|
+
console.log(' se Start Event');
|
|
55
|
+
console.log(' rs Restart an Instance');
|
|
39
56
|
console.log(' d delete instnaces');
|
|
57
|
+
console.log(' lm List of Models');
|
|
40
58
|
console.log(' ? repeat this list');
|
|
41
59
|
}
|
|
42
60
|
function completeUserTask() {
|
|
@@ -45,7 +63,7 @@ function completeUserTask() {
|
|
|
45
63
|
let option = '';
|
|
46
64
|
var command;
|
|
47
65
|
while (option !== 'q') {
|
|
48
|
-
command = yield question('Enter Command, q to quit\n\r
|
|
66
|
+
command = yield question('Enter Command, q to quit\n\r');
|
|
49
67
|
let opts = command.split(' ');
|
|
50
68
|
option = opts[0];
|
|
51
69
|
switch (option) {
|
|
@@ -84,6 +102,19 @@ function completeUserTask() {
|
|
|
84
102
|
console.log("Message Process");
|
|
85
103
|
yield message();
|
|
86
104
|
break;
|
|
105
|
+
case 'rs':
|
|
106
|
+
console.log("restarting a workflow");
|
|
107
|
+
yield restart();
|
|
108
|
+
break;
|
|
109
|
+
case 'se':
|
|
110
|
+
console.log("Start Event");
|
|
111
|
+
yield startEvent();
|
|
112
|
+
break;
|
|
113
|
+
case 'lm':
|
|
114
|
+
console.log("listing Models");
|
|
115
|
+
var list = yield server.definitions.list();
|
|
116
|
+
list.forEach(m => { console.log(m['name']); });
|
|
117
|
+
break;
|
|
87
118
|
case 'd':
|
|
88
119
|
console.log("deleting");
|
|
89
120
|
yield delInstances();
|
|
@@ -91,26 +122,40 @@ function completeUserTask() {
|
|
|
91
122
|
}
|
|
92
123
|
}
|
|
93
124
|
console.log("bye");
|
|
94
|
-
cl.close();
|
|
95
125
|
});
|
|
96
126
|
}
|
|
97
|
-
function
|
|
127
|
+
function getCriteria(prompt) {
|
|
98
128
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
-
const
|
|
100
|
-
let
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
129
|
+
const answer = yield question(prompt + ',in name value pair; example: items.status wait ');
|
|
130
|
+
let str = '' + answer;
|
|
131
|
+
if (str.trim() === '')
|
|
132
|
+
return {};
|
|
133
|
+
//const list = str.match(/li(".*?"|[^"\s]+)+(?=\s*|\s*$)/g);//.match(/(?:[^\s"]+|"[^"]*")+/g);//str.split(' ');
|
|
134
|
+
const list = str.split(/ +(?=(?:(?:[^"]*"){2})*[^"]*$)/g);
|
|
135
|
+
if ((list.length % 2) !== 0) {
|
|
136
|
+
console.log("must be pairs");
|
|
137
|
+
return yield getCriteria(prompt);
|
|
109
138
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
139
|
+
let criteria = {};
|
|
140
|
+
console.log(list);
|
|
141
|
+
for (var i = 0; i < list.length; i += 2) {
|
|
142
|
+
let key = list[i];
|
|
143
|
+
if (key.startsWith('"'))
|
|
144
|
+
key = key.substring(1, key.length - 1);
|
|
145
|
+
let val = list[i + 1];
|
|
146
|
+
if (val.startsWith('"'))
|
|
147
|
+
val = val.substring(1, val.length - 1);
|
|
148
|
+
console.log(key, val);
|
|
149
|
+
criteria[key] = val;
|
|
113
150
|
}
|
|
151
|
+
console.log(criteria);
|
|
152
|
+
return criteria;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function start() {
|
|
156
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
+
const name = yield question('Please provide your process name: ');
|
|
158
|
+
let taskData = yield getCriteria('Please provide your Task Data ');
|
|
114
159
|
let response = yield server.engine.start(name, taskData);
|
|
115
160
|
console.log("Process " + name + " started:", 'InstanceId', response.id);
|
|
116
161
|
return yield displayInstance(response.id);
|
|
@@ -128,16 +173,7 @@ function findItems(query) {
|
|
|
128
173
|
}
|
|
129
174
|
function listItems() {
|
|
130
175
|
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
const
|
|
132
|
-
let str = '' + answer;
|
|
133
|
-
const list = str.split(' ');
|
|
134
|
-
let criteria = {};
|
|
135
|
-
console.log(list);
|
|
136
|
-
for (var i = 0; i < list.length; i += 2) {
|
|
137
|
-
console.log(list[i], list[i + 1]);
|
|
138
|
-
criteria[list[i]] = list[i + 1];
|
|
139
|
-
}
|
|
140
|
-
console.log(criteria);
|
|
176
|
+
const criteria = yield getCriteria('provide items criteria');
|
|
141
177
|
var items = yield server.datastore.findItems(criteria);
|
|
142
178
|
console.log(items.length);
|
|
143
179
|
for (var j = 0; j < items.length; j++) {
|
|
@@ -148,8 +184,8 @@ function listItems() {
|
|
|
148
184
|
}
|
|
149
185
|
function listInstances() {
|
|
150
186
|
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
-
const
|
|
152
|
-
let insts = yield server.datastore.findInstances(
|
|
187
|
+
const criteria = yield getCriteria('provide instance criteria');
|
|
188
|
+
let insts = yield server.datastore.findInstances(criteria);
|
|
153
189
|
for (var i = 0; i < insts.length; i++) {
|
|
154
190
|
let inst = insts[i];
|
|
155
191
|
console.log(`name: ${inst.name} status: ${inst.status} instanceId: ${inst.id}
|
|
@@ -176,58 +212,45 @@ function displayInstance(instanceId = null) {
|
|
|
176
212
|
}
|
|
177
213
|
function invoke() {
|
|
178
214
|
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
-
const
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
215
|
+
const criteria = yield getCriteria('provide item criteria');
|
|
216
|
+
const taskData = yield getCriteria('provide task data');
|
|
217
|
+
try {
|
|
218
|
+
let response = yield server.engine.invoke(criteria, taskData);
|
|
219
|
+
console.log("Completed UserTask:", criteria);
|
|
220
|
+
return yield displayInstance(response.id);
|
|
184
221
|
}
|
|
185
|
-
|
|
186
|
-
|
|
222
|
+
catch (exc) {
|
|
223
|
+
console.log("Invoking task failed for:", criteria);
|
|
187
224
|
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
function startEvent() {
|
|
228
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
const instanceId = yield question('Please provide your Instance ID: ');
|
|
230
|
+
const nodeId = yield question('Please provide start Event ID: ');
|
|
231
|
+
const data = yield getCriteria('provide input data');
|
|
188
232
|
try {
|
|
189
|
-
let response = yield server.engine.
|
|
190
|
-
console.log("Completed UserTask:", taskId);
|
|
233
|
+
let response = yield server.engine.startEvent(instanceId, nodeId, data);
|
|
191
234
|
return yield displayInstance(response.id);
|
|
192
235
|
}
|
|
193
236
|
catch (exc) {
|
|
194
|
-
console.log("Invoking task failed for:",
|
|
195
|
-
yield findItems({ id: instanceId, "items.elementId": taskId });
|
|
237
|
+
console.log("Invoking task failed for:", nodeId, instanceId);
|
|
196
238
|
}
|
|
197
239
|
});
|
|
198
240
|
}
|
|
199
241
|
function signal() {
|
|
200
242
|
return __awaiter(this, void 0, void 0, function* () {
|
|
201
243
|
const signalId = yield question('Please provide signal ID: ');
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (signalData === "") {
|
|
205
|
-
signalData = {};
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
try {
|
|
209
|
-
signalData = JSON.parse(signalData.toString());
|
|
210
|
-
}
|
|
211
|
-
catch (exc) {
|
|
212
|
-
console.log(exc);
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
let response = yield server.engine.throwSignal(signalId, signalData);
|
|
244
|
+
const data = yield getCriteria('provide input data');
|
|
245
|
+
let response = yield server.engine.throwSignal(signalId, data);
|
|
217
246
|
console.log("Signal Response:", response);
|
|
218
247
|
});
|
|
219
248
|
}
|
|
220
249
|
function message() {
|
|
221
250
|
return __awaiter(this, void 0, void 0, function* () {
|
|
222
251
|
const messageId = yield question('Please provide message ID: ');
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
messageData = {};
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
messageData = JSON.parse(messageData.toString());
|
|
229
|
-
}
|
|
230
|
-
let response = yield server.engine.throwMessage(messageId, messageData);
|
|
252
|
+
const data = yield getCriteria('provide input data');
|
|
253
|
+
let response = yield server.engine.throwMessage(messageId, data);
|
|
231
254
|
if (response['id'])
|
|
232
255
|
return yield displayInstance(response['id']);
|
|
233
256
|
else {
|
|
@@ -236,10 +259,23 @@ function message() {
|
|
|
236
259
|
}
|
|
237
260
|
});
|
|
238
261
|
}
|
|
262
|
+
function restart() {
|
|
263
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
264
|
+
const query = yield getCriteria("Instance Search criteria");
|
|
265
|
+
try {
|
|
266
|
+
let response = yield server.engine.restart(query, {}, '');
|
|
267
|
+
console.log(' Instance restarted: new Instance follows:');
|
|
268
|
+
return yield displayInstance(response.id);
|
|
269
|
+
}
|
|
270
|
+
catch (exc) {
|
|
271
|
+
console.log("Invoking task failed for:", exc);
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
239
275
|
function delInstances() {
|
|
240
276
|
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
-
const
|
|
242
|
-
let response = yield server.datastore.deleteInstances(
|
|
277
|
+
const criteria = yield getCriteria('provide instance criteria');
|
|
278
|
+
let response = yield server.datastore.deleteInstances(criteria);
|
|
243
279
|
console.log("Instances Deleted:", response['result']['deletedCount']);
|
|
244
280
|
});
|
|
245
281
|
}
|