@onify/flow-extensions 0.0.2 → 1.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ Changelog
2
+ =========
3
+
4
+ # 1.0.1
5
+
6
+ - allow ISO8601 repeating interval and duration in timeCycle
7
+
8
+ # 1.0.0
9
+
10
+ - proper routing keys for end formatting
11
+
12
+ # 0.1.0
13
+
14
+ - catch errors when resolving service expression
15
+ - test with bpmn-engine@14
16
+
17
+ # 0.0.2
18
+
19
+ - allow expressions in timeCycle
20
+ - test with bpmn-engine@13
21
+ - error message changed in node 16
package/dist/index.js CHANGED
@@ -20,6 +20,8 @@ var _IO = require("./src/IO");
20
20
 
21
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
22
 
23
+ const iso8601cycle = /^\s*(R\d+\/)?P\w+/i;
24
+
23
25
  class FormatError extends Error {
24
26
  constructor(elementId, err) {
25
27
  super(`<${elementId}> ${err.message}`);
@@ -130,7 +132,7 @@ class OnifyElementExtensions {
130
132
  activity.on('activity.execution.completed', async elementApi => {
131
133
  if (elementApi.fields.redelivered) return;
132
134
  formatQ.queueMessage({
133
- routingKey: 'run.end.error'
135
+ routingKey: 'run.end.format'
134
136
  }, {
135
137
  endRoutingKey: 'run.end.complete'
136
138
  }, {
@@ -140,7 +142,7 @@ class OnifyElementExtensions {
140
142
  try {
141
143
  var format = await this._onExecuted(elementApi);
142
144
  } catch (err) {
143
- return broker.publish('format', 'run.enter.error', {
145
+ return broker.publish('format', 'run.end.error', {
144
146
  error: err
145
147
  }, {
146
148
  persistent: false
@@ -330,7 +332,7 @@ class FormatActivity {
330
332
  if (timeCycles) {
331
333
  for (const cycle of timeCycles) {
332
334
  const cron = elementApi.resolveExpression(cycle);
333
- if (!cron) continue;
335
+ if (!cron || iso8601cycle.test(cron)) continue;
334
336
 
335
337
  const expireAtDt = _cronParser.default.parseExpression(cron).next().toDate();
336
338
 
@@ -340,9 +342,9 @@ class FormatActivity {
340
342
 
341
343
  return {
342
344
  resultVariable: this.resultVariable,
343
- ...(scheduledStart && activity.parent.type === 'bpmn:Process' ? {
345
+ ...(scheduledStart && activity.parent.type === 'bpmn:Process' && {
344
346
  scheduledStart
345
- } : undefined),
347
+ }),
346
348
  ...(((_user = user) === null || _user === void 0 ? void 0 : _user.length) && {
347
349
  candidateUsers: user
348
350
  }),
@@ -444,12 +446,12 @@ function registerIOScripts(parentId, context, type, ioBehaviour) {
444
446
  context.addScript(filename, {
445
447
  id: filename,
446
448
  scriptFormat: definition.scriptFormat,
447
- ...(definition.value ? {
449
+ ...(definition.value && {
448
450
  body: definition.value
449
- } : undefined),
450
- ...(definition.resource ? {
451
+ }),
452
+ ...(definition.resource && {
451
453
  resource: definition.resource
452
- } : undefined)
454
+ })
453
455
  });
454
456
  }
455
457
  }
@@ -5,16 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = Connector;
7
7
 
8
- class NotImplemented extends Error {
9
- constructor(serviceId) {
10
- super(`${serviceId} service function not found`);
11
- this.code = 'EFLOW_NOT_IMPLEMENTED';
12
- this.output = {
13
- statusCode: 501
14
- };
15
- }
16
-
17
- }
8
+ var _Errors = require("./Errors");
18
9
 
19
10
  function Connector(connectorId, io, activity, executionMessage) {
20
11
  if (!(this instanceof Connector)) return new Connector(connectorId, io, activity, executionMessage);
@@ -33,7 +24,7 @@ Connector.prototype.execute = async function execute(...args) {
33
24
  const connectorId = this.connectorId;
34
25
  const executionMessage = this.executionMessage;
35
26
  const serviceFunction = environment.services[connectorId];
36
- if (!serviceFunction) return callback(new NotImplemented(connectorId));
27
+ if (!serviceFunction) return callback(new _Errors.NotImplemented(connectorId));
37
28
 
38
29
  try {
39
30
  const input = io && (await io.getInput(activity, executionMessage));
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NotImplemented = void 0;
7
+
8
+ class NotImplemented extends Error {
9
+ constructor(serviceId) {
10
+ super(`${serviceId} service function not found`);
11
+ this.code = 'EFLOW_NOT_IMPLEMENTED';
12
+ this.output = {
13
+ statusCode: 501
14
+ };
15
+ }
16
+
17
+ }
18
+
19
+ exports.NotImplemented = NotImplemented;
package/dist/src/IO.js CHANGED
@@ -64,12 +64,12 @@ class InputOutput {
64
64
  type: parm.$type,
65
65
  behaviour: {
66
66
  scriptFormat,
67
- ...(value ? {
67
+ ...(value && {
68
68
  script: value
69
- } : undefined),
70
- ...(resource ? {
69
+ }),
70
+ ...(resource && {
71
71
  resource
72
- } : undefined)
72
+ })
73
73
  }
74
74
  });
75
75
  mapped.push(new IOScript(parm, id));
@@ -159,10 +159,8 @@ class IOList extends IOBase {
159
159
  }
160
160
 
161
161
  getValue(activity, executionMessage) {
162
- var _this$behaviour$defin;
163
-
164
162
  const name = this.name;
165
- const items = (_this$behaviour$defin = this.behaviour.definition) === null || _this$behaviour$defin === void 0 ? void 0 : _this$behaviour$defin.items;
163
+ const items = this.behaviour.definition.items;
166
164
  const result = [];
167
165
  if (!Array.isArray(items)) return {
168
166
  [name]: result
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = ServiceExpression;
7
7
 
8
+ var _Errors = require("./Errors");
9
+
8
10
  function ServiceExpression(activity) {
9
11
  if (!(this instanceof ServiceExpression)) return new ServiceExpression(activity);
10
12
  this.activity = activity;
@@ -13,7 +15,14 @@ function ServiceExpression(activity) {
13
15
  }
14
16
 
15
17
  ServiceExpression.prototype.execute = function execute(executionMessage, callback) {
16
- const serviceFn = this.activity.environment.resolveExpression(this.expression, executionMessage);
18
+ try {
19
+ const expression = this.expression;
20
+ var serviceFn = this.activity.environment.resolveExpression(expression, executionMessage);
21
+ if (typeof serviceFn !== 'function') throw new _Errors.NotImplemented(`expression "${expression}"`);
22
+ } catch (err) {
23
+ return callback(err);
24
+ }
25
+
17
26
  serviceFn.call(this.activity, executionMessage, (err, result) => {
18
27
  callback(err, result);
19
28
  });
package/index.js CHANGED
@@ -5,6 +5,8 @@ import Connector from './src/Connector';
5
5
  import ServiceExpression from './src/ServiceExpression';
6
6
  import {InputOutput} from './src/IO';
7
7
 
8
+ const iso8601cycle = /^\s*(R\d+\/)?P\w+/i;
9
+
8
10
  class FormatError extends Error {
9
11
  constructor(elementId, err) {
10
12
  super(`<${elementId}> ${err.message}`);
@@ -90,12 +92,12 @@ class OnifyElementExtensions {
90
92
  activity.on('activity.execution.completed', async (elementApi) => {
91
93
  if (elementApi.fields.redelivered) return;
92
94
 
93
- formatQ.queueMessage({routingKey: 'run.end.error'}, {endRoutingKey: 'run.end.complete'}, {persistent: false});
95
+ formatQ.queueMessage({routingKey: 'run.end.format'}, {endRoutingKey: 'run.end.complete'}, {persistent: false});
94
96
 
95
97
  try {
96
98
  var format = await this._onExecuted(elementApi);
97
99
  } catch (err) {
98
- return broker.publish('format', 'run.enter.error', {error: err}, {persistent: false});
100
+ return broker.publish('format', 'run.end.error', {error: err}, {persistent: false});
99
101
  }
100
102
 
101
103
  broker.publish('format', 'run.end.complete', {...format}, {persistent: false});
@@ -236,7 +238,8 @@ class FormatActivity {
236
238
  if (timeCycles) {
237
239
  for (const cycle of timeCycles) {
238
240
  const cron = elementApi.resolveExpression(cycle);
239
- if (!cron) continue;
241
+ if (!cron || iso8601cycle.test(cron)) continue;
242
+
240
243
  const expireAtDt = cronParser.parseExpression(cron).next().toDate();
241
244
  if (!expireAt || expireAtDt < expireAt) expireAt = expireAtDt;
242
245
  }
@@ -244,7 +247,7 @@ class FormatActivity {
244
247
 
245
248
  return {
246
249
  resultVariable: this.resultVariable,
247
- ...(scheduledStart && activity.parent.type === 'bpmn:Process' ? {scheduledStart} : undefined),
250
+ ...(scheduledStart && activity.parent.type === 'bpmn:Process' && {scheduledStart}),
248
251
  ...(user?.length && {candidateUsers: user}),
249
252
  ...(groups?.length && {candidateGroups: groups}),
250
253
  ...(!elementApi.content.description && description && {description: elementApi.resolveExpression(description)}),
@@ -323,8 +326,8 @@ function registerIOScripts(parentId, context, type, ioBehaviour) {
323
326
  context.addScript(filename, {
324
327
  id: filename,
325
328
  scriptFormat: definition.scriptFormat,
326
- ...(definition.value ? {body: definition.value}: undefined),
327
- ...(definition.resource ? {resource: definition.resource}: undefined),
329
+ ...(definition.value && {body: definition.value}),
330
+ ...(definition.resource && {resource: definition.resource}),
328
331
  });
329
332
  }
330
333
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onify/flow-extensions",
3
- "version": "0.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Onify Flow extensions",
5
5
  "module": "index.js",
6
6
  "main": "dist/index.js",
@@ -35,26 +35,26 @@
35
35
  "license": "MIT",
36
36
  "devDependencies": {
37
37
  "@aircall/expression-parser": "^1.0.4",
38
- "@babel/cli": "^7.17.6",
39
- "@babel/core": "^7.17.8",
40
- "@babel/preset-env": "^7.16.11",
41
- "@babel/register": "^7.17.7",
42
- "bpmn-elements": "^7.0.0",
43
- "bpmn-engine": "^13.0.1",
38
+ "@babel/cli": "^7.18.6",
39
+ "@babel/core": "^7.18.6",
40
+ "@babel/preset-env": "^7.18.6",
41
+ "@babel/register": "^7.18.6",
42
+ "bpmn-elements": "^8.1.0",
43
+ "bpmn-engine": "^14.1.0",
44
44
  "bpmn-moddle": "^7.1.2",
45
- "c8": "^7.11.0",
45
+ "c8": "^7.11.3",
46
46
  "camunda-bpmn-moddle": "^6.1.2",
47
47
  "chai": "^4.3.6",
48
48
  "chronokinesis": "^3.1.2",
49
49
  "debug": "^4.3.4",
50
- "eslint": "^8.11.0",
51
- "mocha": "^9.2.2",
50
+ "eslint": "^7.32.0",
51
+ "mocha": "^10.0.0",
52
52
  "mocha-cakes-2": "^3.3.0",
53
53
  "moddle-context-serializer": "^2.1.0",
54
- "nock": "^13.2.4"
54
+ "nock": "^13.2.8"
55
55
  },
56
56
  "dependencies": {
57
- "cron-parser": "^4.2.1"
57
+ "cron-parser": "^4.5.0"
58
58
  },
59
59
  "files": [
60
60
  "src",
package/src/Connector.js CHANGED
@@ -1,10 +1,4 @@
1
- class NotImplemented extends Error {
2
- constructor(serviceId) {
3
- super(`${serviceId} service function not found`);
4
- this.code = 'EFLOW_NOT_IMPLEMENTED';
5
- this.output = {statusCode: 501};
6
- }
7
- }
1
+ import {NotImplemented} from './Errors';
8
2
 
9
3
  export default function Connector(connectorId, io, activity, executionMessage) {
10
4
  if (!(this instanceof Connector)) return new Connector(connectorId, io, activity, executionMessage);
package/src/Errors.js ADDED
@@ -0,0 +1,11 @@
1
+ class NotImplemented extends Error {
2
+ constructor(serviceId) {
3
+ super(`${serviceId} service function not found`);
4
+ this.code = 'EFLOW_NOT_IMPLEMENTED';
5
+ this.output = {statusCode: 501};
6
+ }
7
+ }
8
+
9
+ export {
10
+ NotImplemented,
11
+ };
package/src/IO.js CHANGED
@@ -51,8 +51,8 @@ class InputOutput {
51
51
  type: parm.$type,
52
52
  behaviour: {
53
53
  scriptFormat,
54
- ...(value ? {script: value} : undefined),
55
- ...(resource ? {resource} : undefined),
54
+ ...(value && {script: value}),
55
+ ...(resource && {resource}),
56
56
  },
57
57
  });
58
58
 
@@ -123,7 +123,7 @@ class IOList extends IOBase {
123
123
  }
124
124
  getValue(activity, executionMessage) {
125
125
  const name = this.name;
126
- const items = this.behaviour.definition?.items;
126
+ const items = this.behaviour.definition.items;
127
127
 
128
128
  const result = [];
129
129
  if (!Array.isArray(items)) return {[name]: result};
@@ -1,3 +1,5 @@
1
+ import {NotImplemented} from './Errors';
2
+
1
3
  export default function ServiceExpression(activity) {
2
4
  if (!(this instanceof ServiceExpression)) return new ServiceExpression(activity);
3
5
  this.activity = activity;
@@ -6,7 +8,14 @@ export default function ServiceExpression(activity) {
6
8
  }
7
9
 
8
10
  ServiceExpression.prototype.execute = function execute(executionMessage, callback) {
9
- const serviceFn = this.activity.environment.resolveExpression(this.expression, executionMessage);
11
+ try {
12
+ const expression = this.expression;
13
+ var serviceFn = this.activity.environment.resolveExpression(expression, executionMessage);
14
+ if (typeof serviceFn !== 'function') throw new NotImplemented(`expression "${expression}"`);
15
+ } catch (err) {
16
+ return callback(err);
17
+ }
18
+
10
19
  serviceFn.call(this.activity, executionMessage, (err, result) => {
11
20
  callback(err, result);
12
21
  });