@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.
- package/dist/FlowApplication.js +22 -22
- package/dist/FlowElement.js +13 -21
- package/dist/FlowLogger.js +5 -5
- package/dist/RpcClient.js +1 -2
- package/dist/TestModule.js +2 -3
- package/dist/flow.interface.js +1 -1
- package/dist/unit-utils.js +1 -1
- package/package.json +7 -7
package/dist/FlowApplication.js
CHANGED
|
@@ -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:
|
|
40
|
+
data: {
|
|
41
|
+
flowEventId,
|
|
41
42
|
functionFqn,
|
|
42
|
-
inputStreamId
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
133
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
174
|
+
const elementId = data?.elementId;
|
|
173
175
|
if (elementId) {
|
|
174
|
-
|
|
176
|
+
this.elements?.[elementId]?.onMessage?.(data);
|
|
175
177
|
}
|
|
176
178
|
else {
|
|
177
179
|
for (const element of Object.values(this.elements)) {
|
|
178
|
-
|
|
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
|
|
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(
|
|
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 =
|
|
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(
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
380
|
+
element?.onDestroy?.();
|
|
381
381
|
}
|
|
382
382
|
this._rpcClient && (await this._rpcClient.close());
|
|
383
383
|
}
|
package/dist/FlowElement.js
CHANGED
|
@@ -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(
|
|
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 =
|
|
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 =
|
|
38
|
-
this.metadata =
|
|
39
|
-
this.logger = new FlowLogger_1.FlowLogger(this.metadata, logger || undefined,
|
|
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
|
-
|
|
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,
|
|
56
|
-
const streamID =
|
|
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
|
-
|
|
52
|
+
this.app?.emit(partialEvent);
|
|
59
53
|
return partialEvent;
|
|
60
54
|
}
|
|
61
55
|
else {
|
|
62
|
-
|
|
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
|
-
|
|
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,
|
|
115
|
+
this.stopPropagateStream.set(id, options?.stopPropagation ?? false);
|
|
124
116
|
}
|
|
125
|
-
return method.call(this, new FlowEvent_1.FlowEvent(
|
|
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
|
}
|
package/dist/FlowLogger.js
CHANGED
|
@@ -41,15 +41,15 @@ class FlowLogger {
|
|
|
41
41
|
}
|
|
42
42
|
switch (level) {
|
|
43
43
|
case 'debug':
|
|
44
|
-
return this.logger.debug(message,
|
|
44
|
+
return this.logger.debug(message, { ...this.metadata, ...options });
|
|
45
45
|
case 'error':
|
|
46
|
-
return this.logger.error(message,
|
|
46
|
+
return this.logger.error(message, { ...this.metadata, ...options });
|
|
47
47
|
case 'warn':
|
|
48
|
-
return this.logger.warn(message,
|
|
48
|
+
return this.logger.warn(message, { ...this.metadata, ...options });
|
|
49
49
|
case 'verbose':
|
|
50
|
-
return this.logger.verbose(message,
|
|
50
|
+
return this.logger.verbose(message, { ...this.metadata, ...options });
|
|
51
51
|
default:
|
|
52
|
-
this.logger.log(message,
|
|
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
|
-
|
|
52
|
+
this.logger?.warn(`Large RPC message size detected: ${messageSize} bytes`);
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
const call = { functionName, arguments: args };
|
package/dist/TestModule.js
CHANGED
|
@@ -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;
|
package/dist/flow.interface.js
CHANGED
|
@@ -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
|
|
9
|
+
})(LifecycleEvent || (exports.LifecycleEvent = LifecycleEvent = {}));
|
package/dist/unit-utils.js
CHANGED
|
@@ -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) =>
|
|
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.
|
|
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.
|
|
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.
|
|
38
|
+
"@hahnpro/hpc-api": "4.0.2"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/amqplib": "^0.10.1",
|
|
42
|
-
"@types/jest": "^29.5.
|
|
42
|
+
"@types/jest": "^29.5.2",
|
|
43
43
|
"@types/lodash": "^4.14.195",
|
|
44
|
-
"@types/node": "^18.16.
|
|
44
|
+
"@types/node": "^18.16.19",
|
|
45
45
|
"class-validator-jsonschema": "^5.0.0",
|
|
46
|
-
"jest": "^29.
|
|
47
|
-
"typescript": "^5.
|
|
46
|
+
"jest": "^29.6.0",
|
|
47
|
+
"typescript": "^5.1.6"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"axios": "1.x",
|