@hahnpro/flow-sdk 2025.2.0-beta.1 → 2025.2.0-beta.3
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/package.json +4 -4
- package/src/{index.ts → index.d.ts} +0 -3
- package/src/index.js +18 -0
- package/src/lib/ContextManager.d.ts +40 -0
- package/src/lib/ContextManager.js +105 -0
- package/src/lib/FlowApplication.d.ts +85 -0
- package/src/lib/FlowApplication.js +528 -0
- package/src/lib/FlowElement.d.ts +67 -0
- package/src/lib/FlowElement.js +178 -0
- package/src/lib/FlowEvent.d.ts +25 -0
- package/src/lib/FlowEvent.js +72 -0
- package/src/lib/FlowLogger.d.ts +44 -0
- package/src/lib/FlowLogger.js +110 -0
- package/src/lib/FlowModule.d.ts +7 -0
- package/src/lib/FlowModule.js +14 -0
- package/src/lib/RpcClient.d.ts +13 -0
- package/src/lib/RpcClient.js +88 -0
- package/src/lib/TestModule.d.ts +2 -0
- package/src/lib/TestModule.js +27 -0
- package/src/lib/amqp.d.ts +14 -0
- package/src/lib/amqp.js +12 -0
- package/src/lib/extra-validators.d.ts +1 -0
- package/src/lib/extra-validators.js +53 -0
- package/src/lib/flow.interface.d.ts +48 -0
- package/src/lib/flow.interface.js +9 -0
- package/src/lib/{index.ts → index.d.ts} +0 -3
- package/src/lib/index.js +18 -0
- package/src/lib/nats.d.ts +12 -0
- package/src/lib/nats.js +115 -0
- package/src/lib/unit-decorators.d.ts +39 -0
- package/src/lib/unit-decorators.js +156 -0
- package/src/lib/unit-utils.d.ts +8 -0
- package/src/lib/unit-utils.js +144 -0
- package/src/lib/units.d.ts +31 -0
- package/src/lib/units.js +572 -0
- package/src/lib/utils.d.ts +51 -0
- package/src/lib/utils.js +178 -0
- package/jest.config.ts +0 -10
- package/project.json +0 -41
- package/src/lib/ContextManager.ts +0 -111
- package/src/lib/FlowApplication.ts +0 -659
- package/src/lib/FlowElement.ts +0 -220
- package/src/lib/FlowEvent.ts +0 -73
- package/src/lib/FlowLogger.ts +0 -131
- package/src/lib/FlowModule.ts +0 -18
- package/src/lib/RpcClient.ts +0 -99
- package/src/lib/TestModule.ts +0 -14
- package/src/lib/__pycache__/rpc_server.cpython-310.pyc +0 -0
- package/src/lib/amqp.ts +0 -32
- package/src/lib/extra-validators.ts +0 -62
- package/src/lib/flow.interface.ts +0 -56
- package/src/lib/nats.ts +0 -140
- package/src/lib/unit-decorators.ts +0 -156
- package/src/lib/unit-utils.ts +0 -163
- package/src/lib/units.ts +0 -587
- package/src/lib/utils.ts +0 -176
- package/test/context-manager-purpose.spec.ts +0 -248
- package/test/context-manager.spec.ts +0 -55
- package/test/context.spec.ts +0 -180
- package/test/event.spec.ts +0 -155
- package/test/extra-validators.spec.ts +0 -84
- package/test/flow-logger.spec.ts +0 -104
- package/test/flow.spec.ts +0 -508
- package/test/input-stream.decorator.spec.ts +0 -379
- package/test/long-rpc.test.py +0 -14
- package/test/long-running-rpc.spec.ts +0 -60
- package/test/message.spec.ts +0 -57
- package/test/mocks/logger.mock.ts +0 -7
- package/test/mocks/nats-connection.mock.ts +0 -135
- package/test/mocks/nats-prepare.reals-nats.ts +0 -15
- package/test/rpc.spec.ts +0 -198
- package/test/rpc.test.py +0 -45
- package/test/rx.spec.ts +0 -92
- package/test/unit-decorator.spec.ts +0 -57
- package/test/utils.spec.ts +0 -210
- package/test/validation.spec.ts +0 -174
- package/tsconfig.json +0 -13
- package/tsconfig.lib.json +0 -22
- package/tsconfig.spec.json +0 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hahnpro/flow-sdk",
|
|
3
|
-
"version": "2025.2.0-beta.
|
|
3
|
+
"version": "2025.2.0-beta.3",
|
|
4
4
|
"description": "SDK for building Flow Modules",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -30,8 +30,7 @@
|
|
|
30
30
|
"python-shell": "5.0.0",
|
|
31
31
|
"reflect-metadata": "0.2.2",
|
|
32
32
|
"rxjs": "7.8.2",
|
|
33
|
-
"string-interp": "0.3.6"
|
|
34
|
-
"@hahnpro/hpc-api": "2025.6.0"
|
|
33
|
+
"string-interp": "0.3.6"
|
|
35
34
|
},
|
|
36
35
|
"devDependencies": {
|
|
37
36
|
"@types/amqplib": "0.10.7",
|
|
@@ -51,5 +50,6 @@
|
|
|
51
50
|
},
|
|
52
51
|
"engines": {
|
|
53
52
|
"node": ">=v22"
|
|
54
|
-
}
|
|
53
|
+
},
|
|
54
|
+
"type": "commonjs"
|
|
55
55
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export * from '@hahnpro/hpc-api';
|
|
2
|
-
|
|
3
2
|
export * from './lib/flow.interface';
|
|
4
3
|
export * from './lib/utils';
|
|
5
4
|
export * from './lib/FlowApplication';
|
|
@@ -9,7 +8,5 @@ export * from './lib/FlowLogger';
|
|
|
9
8
|
export { FlowModule } from './lib/FlowModule';
|
|
10
9
|
export * from './lib/TestModule';
|
|
11
10
|
export * from './lib/unit-decorators';
|
|
12
|
-
|
|
13
11
|
export * from './lib/ContextManager';
|
|
14
|
-
|
|
15
12
|
export { IncompatableWith } from './lib/extra-validators';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IncompatableWith = exports.FlowModule = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
tslib_1.__exportStar(require("@hahnpro/hpc-api"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lib/flow.interface"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./lib/utils"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./lib/FlowApplication"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./lib/FlowElement"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./lib/FlowEvent"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./lib/FlowLogger"), exports);
|
|
12
|
+
var FlowModule_1 = require("./lib/FlowModule");
|
|
13
|
+
Object.defineProperty(exports, "FlowModule", { enumerable: true, get: function () { return FlowModule_1.FlowModule; } });
|
|
14
|
+
tslib_1.__exportStar(require("./lib/TestModule"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./lib/unit-decorators"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./lib/ContextManager"), exports);
|
|
17
|
+
var extra_validators_1 = require("./lib/extra-validators");
|
|
18
|
+
Object.defineProperty(exports, "IncompatableWith", { enumerable: true, get: function () { return extra_validators_1.IncompatableWith; } });
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Logger } from './FlowLogger';
|
|
2
|
+
/**
|
|
3
|
+
* Class representing a context manager for handling properties.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ContextManager {
|
|
6
|
+
protected logger: Logger;
|
|
7
|
+
private properties;
|
|
8
|
+
/**
|
|
9
|
+
* Constructor of the ContextManager.
|
|
10
|
+
* @param {Logger} logger - The logger instance for logging messages.
|
|
11
|
+
* @param {Record<string, any>} [flowProperties={}] - Initial properties to set.
|
|
12
|
+
*/
|
|
13
|
+
constructor(logger: Logger, flowProperties?: Record<string, any>);
|
|
14
|
+
/**
|
|
15
|
+
* Init or overwrite all properties.
|
|
16
|
+
* @param properties
|
|
17
|
+
*/
|
|
18
|
+
overwriteAllProperties(properties?: Record<string, any>): void;
|
|
19
|
+
updateFlowProperties(properties?: Record<string, any>): void;
|
|
20
|
+
/**
|
|
21
|
+
* Get a copy of the current properties.
|
|
22
|
+
* @returns {Record<string, any>} A copy of the properties.
|
|
23
|
+
*/
|
|
24
|
+
getProperties(): Record<string, any>;
|
|
25
|
+
/**
|
|
26
|
+
* Set a property.
|
|
27
|
+
* A property key starting with "flow." is reserved for the properties set by in UI and so it is not allowed to be set.
|
|
28
|
+
* @param {string} keyOrPath - The key or the path of the property.
|
|
29
|
+
* @param {any} value - The value of the property.
|
|
30
|
+
*/
|
|
31
|
+
set(keyOrPath: string, value: any): void;
|
|
32
|
+
/**
|
|
33
|
+
* Get a property value by key.
|
|
34
|
+
* @param {string} keyOrPath - The key or the path of the property.
|
|
35
|
+
* @returns {any} The value of the property.
|
|
36
|
+
*/
|
|
37
|
+
get(keyOrPath: string): any;
|
|
38
|
+
replaceAllPlaceholderProperties(properties: any): any;
|
|
39
|
+
}
|
|
40
|
+
export declare function flowInterpolate(value: any, properties: Record<string, any>): any;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContextManager = void 0;
|
|
4
|
+
exports.flowInterpolate = flowInterpolate;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
const string_interp_1 = tslib_1.__importDefault(require("string-interp"));
|
|
8
|
+
/**
|
|
9
|
+
* Class representing a context manager for handling properties.
|
|
10
|
+
*/
|
|
11
|
+
class ContextManager {
|
|
12
|
+
/**
|
|
13
|
+
* Constructor of the ContextManager.
|
|
14
|
+
* @param {Logger} logger - The logger instance for logging messages.
|
|
15
|
+
* @param {Record<string, any>} [flowProperties={}] - Initial properties to set.
|
|
16
|
+
*/
|
|
17
|
+
constructor(logger, flowProperties = {}) {
|
|
18
|
+
this.logger = logger;
|
|
19
|
+
this.properties = { flow: flowProperties };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Init or overwrite all properties.
|
|
23
|
+
* @param properties
|
|
24
|
+
*/
|
|
25
|
+
overwriteAllProperties(properties = {}) {
|
|
26
|
+
this.properties = { flow: properties };
|
|
27
|
+
}
|
|
28
|
+
updateFlowProperties(properties = {}) {
|
|
29
|
+
this.properties.flow = properties;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get a copy of the current properties.
|
|
33
|
+
* @returns {Record<string, any>} A copy of the properties.
|
|
34
|
+
*/
|
|
35
|
+
getProperties() {
|
|
36
|
+
return { ...this.properties };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Set a property.
|
|
40
|
+
* A property key starting with "flow." is reserved for the properties set by in UI and so it is not allowed to be set.
|
|
41
|
+
* @param {string} keyOrPath - The key or the path of the property.
|
|
42
|
+
* @param {any} value - The value of the property.
|
|
43
|
+
*/
|
|
44
|
+
set(keyOrPath, value) {
|
|
45
|
+
if (keyOrPath.startsWith('flow.')) {
|
|
46
|
+
this.logger.error(`Set property of "${keyOrPath}" is not allowed, because it starts with "flow.", so it is reserved for the properties set by in UI.`);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
(0, lodash_1.set)(this.properties, keyOrPath, value);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get a property value by key.
|
|
54
|
+
* @param {string} keyOrPath - The key or the path of the property.
|
|
55
|
+
* @returns {any} The value of the property.
|
|
56
|
+
*/
|
|
57
|
+
get(keyOrPath) {
|
|
58
|
+
return (0, lodash_1.get)(this.properties, keyOrPath, undefined);
|
|
59
|
+
}
|
|
60
|
+
replaceAllPlaceholderProperties(properties) {
|
|
61
|
+
return flowInterpolate((0, lodash_1.cloneDeep)(properties), this.properties);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.ContextManager = ContextManager;
|
|
65
|
+
function flowInterpolate(value, properties) {
|
|
66
|
+
if (!properties) {
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
if ((0, lodash_1.isPlainObject)(value)) {
|
|
70
|
+
for (const key of Object.keys(value)) {
|
|
71
|
+
value[key] = flowInterpolate(value[key], properties);
|
|
72
|
+
}
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
else if (Array.isArray(value) && value.length > 0) {
|
|
76
|
+
value.forEach(function (v, index) {
|
|
77
|
+
this[index] = flowInterpolate(v, properties);
|
|
78
|
+
}, value);
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
else if (value != null && typeof value === 'string' && value.startsWith('${')) {
|
|
82
|
+
// get ${...} blocks and replace the ones that start with flow. in a new string
|
|
83
|
+
const blockRegEx = /\$\{\s*(\S+)\s*}/g;
|
|
84
|
+
let newValue = value;
|
|
85
|
+
let m;
|
|
86
|
+
do {
|
|
87
|
+
m = blockRegEx.exec(value);
|
|
88
|
+
if (m?.[1].startsWith('flow.')) {
|
|
89
|
+
newValue = newValue.replace(m[0], interpolate(m[0], { flow: properties.flow }));
|
|
90
|
+
}
|
|
91
|
+
} while (m);
|
|
92
|
+
return newValue;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function interpolate(text, templateVariables) {
|
|
99
|
+
try {
|
|
100
|
+
return (0, string_interp_1.default)(text, templateVariables) ?? text;
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
return text;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { API, HttpClientService, MockAPI } from '@hahnpro/hpc-api';
|
|
3
|
+
import { NatsConnection, ConnectionOptions as NatsConnectionOptions } from '@nats-io/nats-core';
|
|
4
|
+
import { AmqpConnectionManager } from 'amqp-connection-manager';
|
|
5
|
+
import { CloudEvent } from 'cloudevents';
|
|
6
|
+
import { PartialObserver } from 'rxjs';
|
|
7
|
+
import { AmqpConnection, AmqpConnectionConfig } from './amqp';
|
|
8
|
+
import { ContextManager } from './ContextManager';
|
|
9
|
+
import { ClassType, Flow, FlowElementContext } from './flow.interface';
|
|
10
|
+
import { FlowEvent } from './FlowEvent';
|
|
11
|
+
import { Logger } from './FlowLogger';
|
|
12
|
+
import { RpcClient } from './RpcClient';
|
|
13
|
+
interface FlowAppConfig {
|
|
14
|
+
logger?: Logger;
|
|
15
|
+
amqpConfig?: AmqpConnectionConfig;
|
|
16
|
+
amqpConnection?: AmqpConnectionManager;
|
|
17
|
+
natsConfig?: NatsConnectionOptions;
|
|
18
|
+
natsConnection?: NatsConnection;
|
|
19
|
+
apiClient?: HttpClientService;
|
|
20
|
+
skipApi?: boolean;
|
|
21
|
+
explicitInit?: boolean;
|
|
22
|
+
mockApi?: MockAPI;
|
|
23
|
+
}
|
|
24
|
+
export declare class FlowApplication {
|
|
25
|
+
private modules;
|
|
26
|
+
private flow;
|
|
27
|
+
private _api;
|
|
28
|
+
private _rpcClient;
|
|
29
|
+
private amqpChannel;
|
|
30
|
+
private readonly amqpConnection;
|
|
31
|
+
private readonly natsConnectionConfig?;
|
|
32
|
+
private _natsConnection?;
|
|
33
|
+
private readonly baseLogger;
|
|
34
|
+
private context;
|
|
35
|
+
private declarations;
|
|
36
|
+
private elements;
|
|
37
|
+
private initialized;
|
|
38
|
+
private readonly logger;
|
|
39
|
+
private outputStreamMap;
|
|
40
|
+
private outputQueueMetrics;
|
|
41
|
+
private performanceMap;
|
|
42
|
+
private readonly skipApi;
|
|
43
|
+
private readonly apiClient?;
|
|
44
|
+
private readonly contextManager;
|
|
45
|
+
private natsMessageIterator;
|
|
46
|
+
constructor(modules: ClassType<any>[], flow: Flow, config?: FlowAppConfig);
|
|
47
|
+
constructor(modules: ClassType<any>[], flow: Flow, baseLogger?: Logger, amqpConnection?: AmqpConnection, natsConnection?: NatsConnection, skipApi?: boolean, explicitInit?: boolean);
|
|
48
|
+
get rpcClient(): RpcClient;
|
|
49
|
+
get api(): API;
|
|
50
|
+
get natsConnection(): NatsConnection;
|
|
51
|
+
getContextManager(): ContextManager;
|
|
52
|
+
getProperties(): Record<string, any>;
|
|
53
|
+
private consumeNatsMessagesOfConsumer;
|
|
54
|
+
init(): Promise<void>;
|
|
55
|
+
private publishLifecycleEvent;
|
|
56
|
+
private setQueueMetrics;
|
|
57
|
+
private updateMetrics;
|
|
58
|
+
subscribe: (streamId: string, observer: PartialObserver<FlowEvent>) => import("rxjs").Subscription;
|
|
59
|
+
emit: (event: FlowEvent) => void;
|
|
60
|
+
emitPartial: (completeEvent: FlowEvent, partialEvent: FlowEvent) => void;
|
|
61
|
+
onMessage: (cloudEvent: CloudEvent) => Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Publish a flow event to the amqp flowlogs exchange.
|
|
64
|
+
* If the event size exceeds the limit it will be truncated
|
|
65
|
+
*
|
|
66
|
+
* TODO warum darf hier nicht false zurückgegeben werden? -> erzeugt loop
|
|
67
|
+
*/
|
|
68
|
+
publishNatsEventFlowlogs: (event: FlowEvent) => Promise<boolean>;
|
|
69
|
+
/**
|
|
70
|
+
* Calls onDestroy lifecycle method on all flow elements,
|
|
71
|
+
* closes amqp connection after allowing logs to be processed and published
|
|
72
|
+
* then exits process
|
|
73
|
+
*/
|
|
74
|
+
destroy(exitCode?: number): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Returns rxjs subject for the specified stream id.
|
|
77
|
+
* A new subject will be created if one doesn't exist yet.
|
|
78
|
+
*/
|
|
79
|
+
private getOutputStream;
|
|
80
|
+
}
|
|
81
|
+
export interface Context extends FlowElementContext {
|
|
82
|
+
app?: FlowApplication;
|
|
83
|
+
logger?: Logger;
|
|
84
|
+
}
|
|
85
|
+
export {};
|