@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.
Files changed (79) hide show
  1. package/package.json +4 -4
  2. package/src/{index.ts → index.d.ts} +0 -3
  3. package/src/index.js +18 -0
  4. package/src/lib/ContextManager.d.ts +40 -0
  5. package/src/lib/ContextManager.js +105 -0
  6. package/src/lib/FlowApplication.d.ts +85 -0
  7. package/src/lib/FlowApplication.js +528 -0
  8. package/src/lib/FlowElement.d.ts +67 -0
  9. package/src/lib/FlowElement.js +178 -0
  10. package/src/lib/FlowEvent.d.ts +25 -0
  11. package/src/lib/FlowEvent.js +72 -0
  12. package/src/lib/FlowLogger.d.ts +44 -0
  13. package/src/lib/FlowLogger.js +110 -0
  14. package/src/lib/FlowModule.d.ts +7 -0
  15. package/src/lib/FlowModule.js +14 -0
  16. package/src/lib/RpcClient.d.ts +13 -0
  17. package/src/lib/RpcClient.js +88 -0
  18. package/src/lib/TestModule.d.ts +2 -0
  19. package/src/lib/TestModule.js +27 -0
  20. package/src/lib/amqp.d.ts +14 -0
  21. package/src/lib/amqp.js +12 -0
  22. package/src/lib/extra-validators.d.ts +1 -0
  23. package/src/lib/extra-validators.js +53 -0
  24. package/src/lib/flow.interface.d.ts +48 -0
  25. package/src/lib/flow.interface.js +9 -0
  26. package/src/lib/{index.ts → index.d.ts} +0 -3
  27. package/src/lib/index.js +18 -0
  28. package/src/lib/nats.d.ts +12 -0
  29. package/src/lib/nats.js +115 -0
  30. package/src/lib/unit-decorators.d.ts +39 -0
  31. package/src/lib/unit-decorators.js +156 -0
  32. package/src/lib/unit-utils.d.ts +8 -0
  33. package/src/lib/unit-utils.js +144 -0
  34. package/src/lib/units.d.ts +31 -0
  35. package/src/lib/units.js +572 -0
  36. package/src/lib/utils.d.ts +51 -0
  37. package/src/lib/utils.js +178 -0
  38. package/jest.config.ts +0 -10
  39. package/project.json +0 -41
  40. package/src/lib/ContextManager.ts +0 -111
  41. package/src/lib/FlowApplication.ts +0 -659
  42. package/src/lib/FlowElement.ts +0 -220
  43. package/src/lib/FlowEvent.ts +0 -73
  44. package/src/lib/FlowLogger.ts +0 -131
  45. package/src/lib/FlowModule.ts +0 -18
  46. package/src/lib/RpcClient.ts +0 -99
  47. package/src/lib/TestModule.ts +0 -14
  48. package/src/lib/__pycache__/rpc_server.cpython-310.pyc +0 -0
  49. package/src/lib/amqp.ts +0 -32
  50. package/src/lib/extra-validators.ts +0 -62
  51. package/src/lib/flow.interface.ts +0 -56
  52. package/src/lib/nats.ts +0 -140
  53. package/src/lib/unit-decorators.ts +0 -156
  54. package/src/lib/unit-utils.ts +0 -163
  55. package/src/lib/units.ts +0 -587
  56. package/src/lib/utils.ts +0 -176
  57. package/test/context-manager-purpose.spec.ts +0 -248
  58. package/test/context-manager.spec.ts +0 -55
  59. package/test/context.spec.ts +0 -180
  60. package/test/event.spec.ts +0 -155
  61. package/test/extra-validators.spec.ts +0 -84
  62. package/test/flow-logger.spec.ts +0 -104
  63. package/test/flow.spec.ts +0 -508
  64. package/test/input-stream.decorator.spec.ts +0 -379
  65. package/test/long-rpc.test.py +0 -14
  66. package/test/long-running-rpc.spec.ts +0 -60
  67. package/test/message.spec.ts +0 -57
  68. package/test/mocks/logger.mock.ts +0 -7
  69. package/test/mocks/nats-connection.mock.ts +0 -135
  70. package/test/mocks/nats-prepare.reals-nats.ts +0 -15
  71. package/test/rpc.spec.ts +0 -198
  72. package/test/rpc.test.py +0 -45
  73. package/test/rx.spec.ts +0 -92
  74. package/test/unit-decorator.spec.ts +0 -57
  75. package/test/utils.spec.ts +0 -210
  76. package/test/validation.spec.ts +0 -174
  77. package/tsconfig.json +0 -13
  78. package/tsconfig.lib.json +0 -22
  79. 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.1",
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 {};