@hahnpro/flow-sdk 4.27.1 → 4.27.2

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.
@@ -37,9 +37,12 @@ class FlowApplication {
37
37
  const event = new cloudevents_1.CloudEvent({
38
38
  source: `flows/${flowId}/deployments/${deploymentId}/elements/${elementId}`,
39
39
  type: eventType,
40
- data: Object.assign({ flowEventId,
40
+ data: {
41
+ flowEventId,
41
42
  functionFqn,
42
- inputStreamId }, data),
43
+ inputStreamId,
44
+ ...data,
45
+ },
43
46
  time: new Date().toISOString(),
44
47
  });
45
48
  const message = event.toJSON();
@@ -100,7 +103,6 @@ class FlowApplication {
100
103
  }
101
104
  };
102
105
  this.onMessage = async (msg) => {
103
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
104
106
  let event;
105
107
  try {
106
108
  event = JSON.parse(msg.content.toString());
@@ -118,23 +120,23 @@ class FlowApplication {
118
120
  }
119
121
  let context = {};
120
122
  if (flow.context) {
121
- this.context = Object.assign(Object.assign({}, this.context), flow.context);
123
+ this.context = { ...this.context, ...flow.context };
122
124
  context = this.context;
123
125
  }
124
126
  if (flow.properties) {
125
127
  this.properties = flow.properties;
126
128
  for (const element of Object.values(this.elements)) {
127
- (_a = element.onFlowPropertiesChanged) === null || _a === void 0 ? void 0 : _a.call(element, flow.properties);
129
+ element.onFlowPropertiesChanged?.(flow.properties);
128
130
  }
129
131
  }
130
132
  if (Object.keys(context).length > 0) {
131
133
  for (const element of flow.elements || []) {
132
- context = Object.assign(Object.assign({}, context), { name: element.name });
133
- (_c = (_b = this.elements) === null || _b === void 0 ? void 0 : _b[element.id]) === null || _c === void 0 ? void 0 : _c.onContextChanged(context);
134
+ context = { ...context, name: element.name };
135
+ this.elements?.[element.id]?.onContextChanged(context);
134
136
  }
135
137
  }
136
138
  for (const element of flow.elements || []) {
137
- (_e = (_d = this.elements) === null || _d === void 0 ? void 0 : _d[element.id]) === null || _e === void 0 ? void 0 : _e.onPropertiesChanged(element.properties);
139
+ this.elements?.[element.id]?.onPropertiesChanged(element.properties);
138
140
  }
139
141
  const statusEvent = {
140
142
  eventId: (0, crypto_1.randomUUID)(),
@@ -144,7 +146,7 @@ class FlowApplication {
144
146
  data: { deploymentId: this.context.deploymentId, status: 'updated' },
145
147
  };
146
148
  try {
147
- (_f = this.amqpChannel) === null || _f === void 0 ? void 0 : _f.publish('deployment', 'health', statusEvent);
149
+ this.amqpChannel?.publish('deployment', 'health', statusEvent);
148
150
  }
149
151
  catch (err) {
150
152
  this.logger.error(err);
@@ -160,7 +162,7 @@ class FlowApplication {
160
162
  data: { deploymentId: this.context.deploymentId, status: 'updating failed' },
161
163
  };
162
164
  try {
163
- (_g = this.amqpChannel) === null || _g === void 0 ? void 0 : _g.publish('deployment', 'health', statusEvent);
165
+ this.amqpChannel?.publish('deployment', 'health', statusEvent);
164
166
  }
165
167
  catch (e) {
166
168
  this.logger.error(e);
@@ -169,13 +171,13 @@ class FlowApplication {
169
171
  }
170
172
  else if (event.type === 'com.flowstudio.deployment.message') {
171
173
  const data = event.data;
172
- const elementId = data === null || data === void 0 ? void 0 : data.elementId;
174
+ const elementId = data?.elementId;
173
175
  if (elementId) {
174
- (_k = (_j = (_h = this.elements) === null || _h === void 0 ? void 0 : _h[elementId]) === null || _j === void 0 ? void 0 : _j.onMessage) === null || _k === void 0 ? void 0 : _k.call(_j, data);
176
+ this.elements?.[elementId]?.onMessage?.(data);
175
177
  }
176
178
  else {
177
179
  for (const element of Object.values(this.elements)) {
178
- (_l = element === null || element === void 0 ? void 0 : element.onMessage) === null || _l === void 0 ? void 0 : _l.call(element, data);
180
+ element?.onMessage?.(data);
179
181
  }
180
182
  }
181
183
  }
@@ -212,12 +214,12 @@ class FlowApplication {
212
214
  }
213
215
  else {
214
216
  this.baseLogger = baseLoggerOrConfig;
215
- this.amqpConnection = amqpConnection === null || amqpConnection === void 0 ? void 0 : amqpConnection.managedConnection;
217
+ this.amqpConnection = amqpConnection?.managedConnection;
216
218
  this.skipApi = skipApi || false;
217
219
  explicitInit = explicitInit || false;
218
220
  this._api = mockApi || null;
219
221
  }
220
- this.logger = new FlowLogger_1.FlowLogger(Object.assign({ id: 'none', functionFqn: 'FlowApplication' }, flow === null || flow === void 0 ? void 0 : flow.context), this.baseLogger || undefined, this.publishEvent);
222
+ this.logger = new FlowLogger_1.FlowLogger({ id: 'none', functionFqn: 'FlowApplication', ...flow?.context }, this.baseLogger || undefined, this.publishEvent);
221
223
  process.once('uncaughtException', (err) => {
222
224
  this.logger.error('Uncaught exception!');
223
225
  this.logger.error(err);
@@ -245,10 +247,9 @@ class FlowApplication {
245
247
  return this._api;
246
248
  }
247
249
  async init() {
248
- var _a;
249
250
  if (this.initialized)
250
251
  return;
251
- this.context = Object.assign({}, this.flow.context);
252
+ this.context = { ...this.flow.context };
252
253
  this.properties = this.flow.properties || {};
253
254
  try {
254
255
  if (!this.skipApi && !(this._api instanceof hpc_api_1.MockAPI)) {
@@ -256,13 +257,13 @@ class FlowApplication {
256
257
  }
257
258
  }
258
259
  catch (err) {
259
- this.logger.error((err === null || err === void 0 ? void 0 : err.message) || err);
260
+ this.logger.error(err?.message || err);
260
261
  }
261
262
  const logErrorAndExit = async (err) => {
262
263
  this.logger.error(new Error(err));
263
264
  await this.destroy(1);
264
265
  };
265
- this.amqpChannel = (_a = this.amqpConnection) === null || _a === void 0 ? void 0 : _a.createChannel({
266
+ this.amqpChannel = this.amqpConnection?.createChannel({
266
267
  json: true,
267
268
  setup: async (channel) => {
268
269
  try {
@@ -303,7 +304,7 @@ class FlowApplication {
303
304
  for (const element of this.flow.elements) {
304
305
  const { id, name, properties, module, functionFqn } = element;
305
306
  try {
306
- const context = Object.assign(Object.assign({}, this.context), { id, name, logger: this.baseLogger, app: this });
307
+ const context = { ...this.context, id, name, logger: this.baseLogger, app: this };
307
308
  this.elements[id] = new this.declarations[`${module}.${functionFqn}`](context, properties);
308
309
  }
309
310
  catch (err) {
@@ -373,11 +374,10 @@ class FlowApplication {
373
374
  return this.properties;
374
375
  }
375
376
  async destroy(exitCode = 0) {
376
- var _a;
377
377
  try {
378
378
  try {
379
379
  for (const element of Object.values(this.elements)) {
380
- (_a = element === null || element === void 0 ? void 0 : element.onDestroy) === null || _a === void 0 ? void 0 : _a.call(element);
380
+ element?.onDestroy?.();
381
381
  }
382
382
  this._rpcClient && (await this._rpcClient.close());
383
383
  }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FlowDashboard = exports.FlowTrigger = exports.FlowTask = exports.FlowResource = exports.FlowFunction = exports.InputStream = exports.FlowElement = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const class_transformer_1 = require("class-transformer");
6
5
  const class_validator_1 = require("class-validator");
7
6
  const python_shell_1 = require("python-shell");
@@ -9,15 +8,12 @@ const FlowEvent_1 = require("./FlowEvent");
9
8
  const FlowLogger_1 = require("./FlowLogger");
10
9
  const utils_1 = require("./utils");
11
10
  class FlowElement {
12
- constructor(_a, properties, propertiesClassType, whitelist) {
13
- var _b, _c;
14
- var { app, logger } = _a, metadata = tslib_1.__rest(_a, ["app", "logger"]);
15
- if (whitelist === void 0) { whitelist = false; }
11
+ constructor({ app, logger, ...metadata }, properties, propertiesClassType, whitelist = false) {
16
12
  this.propertiesClassType = propertiesClassType;
17
13
  this.whitelist = whitelist;
18
14
  this.stopPropagateStream = new Map();
19
15
  this.onContextChanged = (context) => {
20
- this.metadata = Object.assign(Object.assign({}, this.metadata), context);
16
+ this.metadata = { ...this.metadata, ...context };
21
17
  };
22
18
  this.onPropertiesChanged = (properties) => {
23
19
  this.setProperties(properties);
@@ -34,32 +30,30 @@ class FlowElement {
34
30
  this.handleApiError = (error) => (0, utils_1.handleApiError)(error, this.logger);
35
31
  this.interpolate = (value, ...templateVariables) => (0, utils_1.fillTemplate)(value, ...templateVariables);
36
32
  this.app = app;
37
- this.api = (_b = this.app) === null || _b === void 0 ? void 0 : _b.api;
38
- this.metadata = Object.assign(Object.assign({}, metadata), { functionFqn: this.functionFqn });
39
- this.logger = new FlowLogger_1.FlowLogger(this.metadata, logger || undefined, (_c = this.app) === null || _c === void 0 ? void 0 : _c.publishEvent);
33
+ this.api = this.app?.api;
34
+ this.metadata = { ...metadata, functionFqn: this.functionFqn };
35
+ this.logger = new FlowLogger_1.FlowLogger(this.metadata, logger || undefined, this.app?.publishEvent);
40
36
  this.rpcRoutingKey = (this.metadata.flowId || '') + (this.metadata.deploymentId || '') + this.metadata.id;
41
37
  if (properties) {
42
38
  this.setProperties(properties);
43
39
  }
44
40
  }
45
41
  get flowProperties() {
46
- var _a, _b;
47
- return ((_b = (_a = this.app) === null || _a === void 0 ? void 0 : _a.getProperties) === null || _b === void 0 ? void 0 : _b.call(_a)) || {};
42
+ return this.app?.getProperties?.() || {};
48
43
  }
49
44
  emitOutput(data = {}, outputId = 'default', time = new Date()) {
50
45
  return this.emitEvent(data, null, outputId, time);
51
46
  }
52
47
  emitEvent(data, inputEvent, outputId = 'default', time = new Date()) {
53
- var _a, _b, _c;
54
48
  const partialEvent = new FlowEvent_1.FlowEvent(this.metadata, data, outputId, time);
55
- const completeEvent = new FlowEvent_1.FlowEvent(this.metadata, Object.assign(Object.assign({}, ((inputEvent === null || inputEvent === void 0 ? void 0 : inputEvent.getData()) || {})), data), outputId, time);
56
- const streamID = ((_a = inputEvent === null || inputEvent === void 0 ? void 0 : inputEvent.getMetadata()) === null || _a === void 0 ? void 0 : _a.inputStreamId) || '';
49
+ const completeEvent = new FlowEvent_1.FlowEvent(this.metadata, { ...(inputEvent?.getData() || {}), ...data }, outputId, time);
50
+ const streamID = inputEvent?.getMetadata()?.inputStreamId || '';
57
51
  if ((this.stopPropagateStream.has(streamID) && this.stopPropagateStream.get(streamID)) || !this.stopPropagateStream.has(streamID)) {
58
- (_b = this.app) === null || _b === void 0 ? void 0 : _b.emit(partialEvent);
52
+ this.app?.emit(partialEvent);
59
53
  return partialEvent;
60
54
  }
61
55
  else {
62
- (_c = this.app) === null || _c === void 0 ? void 0 : _c.emitPartial(completeEvent, partialEvent);
56
+ this.app?.emitPartial(completeEvent, partialEvent);
63
57
  return completeEvent;
64
58
  }
65
59
  }
@@ -92,8 +86,7 @@ class FlowElement {
92
86
  return this.validateProperties(classType, event.getData(), whitelist);
93
87
  }
94
88
  async callRpcFunction(functionName, ...args) {
95
- var _a;
96
- return (_a = this.app) === null || _a === void 0 ? void 0 : _a.rpcClient.callFunction(this.rpcRoutingKey, functionName, ...args);
89
+ return this.app?.rpcClient.callFunction(this.rpcRoutingKey, functionName, ...args);
97
90
  }
98
91
  runPyRpcScript(scriptPath, ...args) {
99
92
  const options = {
@@ -118,11 +111,10 @@ function InputStream(id = 'default', options) {
118
111
  }
119
112
  const method = propertyDescriptor.value;
120
113
  propertyDescriptor.value = function (event) {
121
- var _a;
122
114
  if (!this.stopPropagateStream.has(id)) {
123
- this.stopPropagateStream.set(id, (_a = options === null || options === void 0 ? void 0 : options.stopPropagation) !== null && _a !== void 0 ? _a : false);
115
+ this.stopPropagateStream.set(id, options?.stopPropagation ?? false);
124
116
  }
125
- return method.call(this, new FlowEvent_1.FlowEvent(Object.assign(Object.assign({ id: event.getMetadata().elementId }, event.getMetadata()), { inputStreamId: id }), event.getData(), event.getType(), new Date(event.getTime())));
117
+ return method.call(this, new FlowEvent_1.FlowEvent({ id: event.getMetadata().elementId, ...event.getMetadata(), inputStreamId: id }, event.getData(), event.getType(), new Date(event.getTime())));
126
118
  };
127
119
  };
128
120
  }
@@ -41,15 +41,15 @@ class FlowLogger {
41
41
  }
42
42
  switch (level) {
43
43
  case 'debug':
44
- return this.logger.debug(message, Object.assign(Object.assign({}, this.metadata), options));
44
+ return this.logger.debug(message, { ...this.metadata, ...options });
45
45
  case 'error':
46
- return this.logger.error(message, Object.assign(Object.assign({}, this.metadata), options));
46
+ return this.logger.error(message, { ...this.metadata, ...options });
47
47
  case 'warn':
48
- return this.logger.warn(message, Object.assign(Object.assign({}, this.metadata), options));
48
+ return this.logger.warn(message, { ...this.metadata, ...options });
49
49
  case 'verbose':
50
- return this.logger.verbose(message, Object.assign(Object.assign({}, this.metadata), options));
50
+ return this.logger.verbose(message, { ...this.metadata, ...options });
51
51
  default:
52
- this.logger.log(message, Object.assign(Object.assign({}, this.metadata), options));
52
+ this.logger.log(message, { ...this.metadata, ...options });
53
53
  }
54
54
  }
55
55
  }
package/dist/RpcClient.js CHANGED
@@ -43,14 +43,13 @@ class RpcClient {
43
43
  this.callFunction = (routingKey, functionName, ...args) => {
44
44
  const stack = new Error('test').stack;
45
45
  return new Promise((resolve, reject) => {
46
- var _a;
47
46
  if (MAX_MSG_SIZE || WARN_MSG_SIZE) {
48
47
  const messageSize = (0, object_sizeof_1.default)(args);
49
48
  if (messageSize > MAX_MSG_SIZE) {
50
49
  throw new Error(`Max RPC message size exceeded: ${messageSize} bytes / ${MAX_MSG_SIZE} bytes`);
51
50
  }
52
51
  if (messageSize > WARN_MSG_SIZE) {
53
- (_a = this.logger) === null || _a === void 0 ? void 0 : _a.warn(`Large RPC message size detected: ${messageSize} bytes`);
52
+ this.logger?.warn(`Large RPC message size detected: ${messageSize} bytes`);
54
53
  }
55
54
  }
56
55
  const call = { functionName, arguments: args };
@@ -19,9 +19,8 @@ tslib_1.__decorate([
19
19
  TestTrigger = tslib_1.__decorate([
20
20
  (0, FlowElement_1.FlowFunction)('test.task.Trigger')
21
21
  ], TestTrigger);
22
- let TestModule = class TestModule {
22
+ let TestModule = exports.TestModule = class TestModule {
23
23
  };
24
- TestModule = tslib_1.__decorate([
24
+ exports.TestModule = TestModule = tslib_1.__decorate([
25
25
  (0, FlowModule_1.FlowModule)({ name: 'test', declarations: [TestTrigger] })
26
26
  ], TestModule);
27
- exports.TestModule = TestModule;
@@ -6,4 +6,4 @@ var LifecycleEvent;
6
6
  LifecycleEvent["ACTIVATED"] = "com.hahnpro.flow_function.activated";
7
7
  LifecycleEvent["COMPLETED"] = "com.hahnpro.flow_function.completed";
8
8
  LifecycleEvent["TERMINATED"] = "com.hahnpro.flow_function.terminated";
9
- })(LifecycleEvent = exports.LifecycleEvent || (exports.LifecycleEvent = {}));
9
+ })(LifecycleEvent || (exports.LifecycleEvent = LifecycleEvent = {}));
@@ -95,7 +95,7 @@ function verifyIndices(indices, unit) {
95
95
  let index = 0;
96
96
  let convfactor = 1;
97
97
  while (index != unit.length) {
98
- const find = filteredElement.find((obj) => (obj === null || obj === void 0 ? void 0 : obj.index) === index);
98
+ const find = filteredElement.find((obj) => obj?.index === index);
99
99
  if (!find)
100
100
  continue outer;
101
101
  index += find.length;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hahnpro/flow-sdk",
3
- "version": "4.27.1",
3
+ "version": "4.27.2",
4
4
  "description": "SDK for building Flow Modules",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -28,23 +28,23 @@
28
28
  "amqplib": "^0.10.3",
29
29
  "class-transformer": "0.5.1",
30
30
  "class-validator": "~0.14.0",
31
- "cloudevents": "^7.0.0",
31
+ "cloudevents": "^7.0.1",
32
32
  "lodash": "^4.17.21",
33
33
  "object-sizeof": "~2.4.2",
34
34
  "python-shell": "^3.0.1",
35
35
  "reflect-metadata": "^0.1.13",
36
36
  "rxjs": "^7.8.1",
37
37
  "string-interp": "^0.3.6",
38
- "@hahnpro/hpc-api": "4.0.1"
38
+ "@hahnpro/hpc-api": "4.0.2"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/amqplib": "^0.10.1",
42
- "@types/jest": "^29.5.1",
42
+ "@types/jest": "^29.5.2",
43
43
  "@types/lodash": "^4.14.195",
44
- "@types/node": "^18.16.16",
44
+ "@types/node": "^18.16.19",
45
45
  "class-validator-jsonschema": "^5.0.0",
46
- "jest": "^29.5.0",
47
- "typescript": "^5.0.4"
46
+ "jest": "^29.6.0",
47
+ "typescript": "^5.1.6"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "axios": "1.x",