@hahnpro/flow-sdk 9.6.4 → 2025.2.0-beta.1

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 (81) hide show
  1. package/CHANGELOG.md +904 -0
  2. package/jest.config.ts +10 -0
  3. package/package.json +7 -20
  4. package/project.json +41 -0
  5. package/src/index.ts +15 -0
  6. package/src/lib/ContextManager.ts +111 -0
  7. package/src/lib/FlowApplication.ts +659 -0
  8. package/src/lib/FlowElement.ts +220 -0
  9. package/src/lib/FlowEvent.ts +73 -0
  10. package/src/lib/FlowLogger.ts +131 -0
  11. package/src/lib/FlowModule.ts +18 -0
  12. package/src/lib/RpcClient.ts +99 -0
  13. package/src/lib/TestModule.ts +14 -0
  14. package/src/lib/__pycache__/rpc_server.cpython-310.pyc +0 -0
  15. package/src/lib/amqp.ts +32 -0
  16. package/src/lib/extra-validators.ts +62 -0
  17. package/src/lib/flow.interface.ts +56 -0
  18. package/{dist/index.d.ts → src/lib/index.ts} +3 -0
  19. package/src/lib/nats.ts +140 -0
  20. package/src/lib/unit-decorators.ts +156 -0
  21. package/src/lib/unit-utils.ts +163 -0
  22. package/src/lib/units.ts +587 -0
  23. package/src/lib/utils.ts +176 -0
  24. package/test/context-manager-purpose.spec.ts +248 -0
  25. package/test/context-manager.spec.ts +55 -0
  26. package/test/context.spec.ts +180 -0
  27. package/test/event.spec.ts +155 -0
  28. package/test/extra-validators.spec.ts +84 -0
  29. package/test/flow-logger.spec.ts +104 -0
  30. package/test/flow.spec.ts +508 -0
  31. package/test/input-stream.decorator.spec.ts +379 -0
  32. package/test/long-rpc.test.py +14 -0
  33. package/test/long-running-rpc.spec.ts +60 -0
  34. package/test/message.spec.ts +57 -0
  35. package/test/mocks/logger.mock.ts +7 -0
  36. package/test/mocks/nats-connection.mock.ts +135 -0
  37. package/test/mocks/nats-prepare.reals-nats.ts +15 -0
  38. package/test/rpc.spec.ts +198 -0
  39. package/test/rpc.test.py +45 -0
  40. package/test/rx.spec.ts +92 -0
  41. package/test/unit-decorator.spec.ts +57 -0
  42. package/test/utils.spec.ts +210 -0
  43. package/test/validation.spec.ts +174 -0
  44. package/tsconfig.json +13 -0
  45. package/tsconfig.lib.json +22 -0
  46. package/tsconfig.spec.json +8 -0
  47. package/LICENSE +0 -21
  48. package/dist/ContextManager.d.ts +0 -40
  49. package/dist/ContextManager.js +0 -77
  50. package/dist/FlowApplication.d.ts +0 -85
  51. package/dist/FlowApplication.js +0 -500
  52. package/dist/FlowElement.d.ts +0 -67
  53. package/dist/FlowElement.js +0 -163
  54. package/dist/FlowEvent.d.ts +0 -25
  55. package/dist/FlowEvent.js +0 -71
  56. package/dist/FlowLogger.d.ts +0 -44
  57. package/dist/FlowLogger.js +0 -94
  58. package/dist/FlowModule.d.ts +0 -7
  59. package/dist/FlowModule.js +0 -13
  60. package/dist/RpcClient.d.ts +0 -13
  61. package/dist/RpcClient.js +0 -84
  62. package/dist/TestModule.d.ts +0 -2
  63. package/dist/TestModule.js +0 -27
  64. package/dist/amqp.d.ts +0 -14
  65. package/dist/amqp.js +0 -12
  66. package/dist/extra-validators.d.ts +0 -1
  67. package/dist/extra-validators.js +0 -51
  68. package/dist/flow.interface.d.ts +0 -48
  69. package/dist/flow.interface.js +0 -9
  70. package/dist/index.js +0 -18
  71. package/dist/nats.d.ts +0 -12
  72. package/dist/nats.js +0 -109
  73. package/dist/unit-decorators.d.ts +0 -39
  74. package/dist/unit-decorators.js +0 -156
  75. package/dist/unit-utils.d.ts +0 -8
  76. package/dist/unit-utils.js +0 -143
  77. package/dist/units.d.ts +0 -31
  78. package/dist/units.js +0 -570
  79. package/dist/utils.d.ts +0 -51
  80. package/dist/utils.js +0 -137
  81. /package/{dist → src/lib}/rpc_server.py +0 -0
package/jest.config.ts ADDED
@@ -0,0 +1,10 @@
1
+ export default {
2
+ displayName: 'flow-sdk',
3
+ preset: '../../jest.preset.js',
4
+ testEnvironment: 'node',
5
+ transform: {
6
+ '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
7
+ },
8
+ moduleFileExtensions: ['ts', 'js', 'html'],
9
+ coverageDirectory: '../../coverage/lib/flow-sdk',
10
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hahnpro/flow-sdk",
3
- "version": "9.6.4",
3
+ "version": "2025.2.0-beta.1",
4
4
  "description": "SDK for building Flow Modules",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -11,34 +11,27 @@
11
11
  "type": "git",
12
12
  "url": "git@github.com:hahnprojects/flow.git"
13
13
  },
14
- "directories": {
15
- "lib": "lib",
16
- "test": "test"
17
- },
18
- "files": [
19
- "dist"
20
- ],
21
- "main": "./dist/index.js",
22
- "types": "./dist/index.d.ts",
14
+ "main": "./src/index.js",
15
+ "types": "./src/index.d.ts",
23
16
  "publishConfig": {
24
17
  "access": "public"
25
18
  },
26
19
  "dependencies": {
27
- "@hahnpro/hpc-api": "2025.5.0",
28
20
  "@nats-io/jetstream": "3.2.0",
29
21
  "@nats-io/nats-core": "3.2.0",
30
22
  "@nats-io/transport-node": "3.2.0",
31
23
  "amqp-connection-manager": "4.1.15",
32
24
  "amqplib": "0.10.9",
33
25
  "class-transformer": "0.5.1",
34
- "class-validator": "~0.14.2",
26
+ "class-validator": "0.14.2",
35
27
  "cloudevents": "10.0.0",
36
28
  "lodash": "4.17.21",
37
- "object-sizeof": "~2.6.5",
29
+ "object-sizeof": "2.6.5",
38
30
  "python-shell": "5.0.0",
39
31
  "reflect-metadata": "0.2.2",
40
32
  "rxjs": "7.8.2",
41
- "string-interp": "0.3.6"
33
+ "string-interp": "0.3.6",
34
+ "@hahnpro/hpc-api": "2025.6.0"
42
35
  },
43
36
  "devDependencies": {
44
37
  "@types/amqplib": "0.10.7",
@@ -58,11 +51,5 @@
58
51
  },
59
52
  "engines": {
60
53
  "node": ">=v22"
61
- },
62
- "scripts": {
63
- "build": "../../node_modules/.bin/tsc -p tsconfig.lib.json",
64
- "build:nocomments": "../../node_modules/.bin/tsc -p tsconfig.nocomments.json",
65
- "postbuild": "../../node_modules/.bin/copyfiles -u 1 lib/*.py dist",
66
- "lint": "eslint '*/**/*.{js,ts}'"
67
54
  }
68
55
  }
package/project.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "flow-sdk",
3
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
+ "root": "lib/flow-sdk",
5
+ "sourceRoot": "lib/flow-sdk/src",
6
+ "projectType": "library",
7
+ "release": {
8
+ "version": {
9
+ "preserveLocalDependencyProtocols": false,
10
+ "manifestRootsToUpdate": ["dist/{projectRoot}"]
11
+ }
12
+ },
13
+ "targets": {
14
+ "build": {
15
+ "executor": "@nx/js:tsc",
16
+ "outputs": ["{options.outputPath}"],
17
+ "options": {
18
+ "outputPath": "dist/lib/flow-sdk",
19
+ "main": "lib/flow-sdk/src/index.ts",
20
+ "tsConfig": "lib/flow-sdk/tsconfig.lib.json",
21
+ "assets": ["lib/flow-sdk/*.md", "lib/flow-sdk/src/lib/*.py"]
22
+ }
23
+ },
24
+ "nx-release-publish": {
25
+ "options": {
26
+ "packageRoot": "dist/{projectRoot}"
27
+ }
28
+ },
29
+ "lint": {
30
+ "executor": "@nx/eslint:lint"
31
+ },
32
+ "test": {
33
+ "executor": "@nx/jest:jest",
34
+ "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
35
+ "options": {
36
+ "jestConfig": "lib/flow-sdk/jest.config.ts"
37
+ }
38
+ }
39
+ },
40
+ "tags": []
41
+ }
package/src/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ export * from '@hahnpro/hpc-api';
2
+
3
+ export * from './lib/flow.interface';
4
+ export * from './lib/utils';
5
+ export * from './lib/FlowApplication';
6
+ export * from './lib/FlowElement';
7
+ export * from './lib/FlowEvent';
8
+ export * from './lib/FlowLogger';
9
+ export { FlowModule } from './lib/FlowModule';
10
+ export * from './lib/TestModule';
11
+ export * from './lib/unit-decorators';
12
+
13
+ export * from './lib/ContextManager';
14
+
15
+ export { IncompatableWith } from './lib/extra-validators';
@@ -0,0 +1,111 @@
1
+ import { cloneDeep, get, isPlainObject, set } from 'lodash';
2
+ import interp from 'string-interp';
3
+
4
+ import { Logger } from './FlowLogger';
5
+
6
+ /**
7
+ * Class representing a context manager for handling properties.
8
+ */
9
+ export class ContextManager {
10
+ private properties: Record<string, any>;
11
+
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(
18
+ protected logger: Logger,
19
+ flowProperties: Record<string, any> = {},
20
+ ) {
21
+ this.properties = { flow: flowProperties };
22
+ }
23
+
24
+ /**
25
+ * Init or overwrite all properties.
26
+ * @param properties
27
+ */
28
+ public overwriteAllProperties(properties: Record<string, any> = {}): void {
29
+ this.properties = { flow: properties };
30
+ }
31
+
32
+ public updateFlowProperties(properties: Record<string, any> = {}): void {
33
+ this.properties.flow = properties;
34
+ }
35
+
36
+ /**
37
+ * Get a copy of the current properties.
38
+ * @returns {Record<string, any>} A copy of the properties.
39
+ */
40
+ public getProperties(): Record<string, any> {
41
+ return { ...this.properties };
42
+ }
43
+
44
+ /**
45
+ * Set a property.
46
+ * A property key starting with "flow." is reserved for the properties set by in UI and so it is not allowed to be set.
47
+ * @param {string} keyOrPath - The key or the path of the property.
48
+ * @param {any} value - The value of the property.
49
+ */
50
+ public set(keyOrPath: string, value: any): void {
51
+ if (keyOrPath.startsWith('flow.')) {
52
+ this.logger.error(
53
+ `Set property of "${keyOrPath}" is not allowed, because it starts with "flow.", so it is reserved for the properties set by in UI.`,
54
+ );
55
+ } else {
56
+ set(this.properties, keyOrPath, value);
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Get a property value by key.
62
+ * @param {string} keyOrPath - The key or the path of the property.
63
+ * @returns {any} The value of the property.
64
+ */
65
+ public get(keyOrPath: string): any {
66
+ return get(this.properties, keyOrPath, undefined);
67
+ }
68
+
69
+ public replaceAllPlaceholderProperties(properties: any) {
70
+ return flowInterpolate(cloneDeep(properties), this.properties);
71
+ }
72
+ }
73
+
74
+ export function flowInterpolate(value: any, properties: Record<string, any>): any {
75
+ if (!properties) {
76
+ return value;
77
+ }
78
+ if (isPlainObject(value)) {
79
+ for (const key of Object.keys(value)) {
80
+ value[key] = flowInterpolate(value[key], properties);
81
+ }
82
+ return value;
83
+ } else if (Array.isArray(value) && value.length > 0) {
84
+ value.forEach(function (v, index) {
85
+ this[index] = flowInterpolate(v, properties);
86
+ }, value);
87
+ return value;
88
+ } else if (value != null && typeof value === 'string' && value.startsWith('${')) {
89
+ // get ${...} blocks and replace the ones that start with flow. in a new string
90
+ const blockRegEx = /\$\{\s*(\S+)\s*}/g;
91
+ let newValue = value;
92
+ let m: RegExpExecArray;
93
+ do {
94
+ m = blockRegEx.exec(value);
95
+ if (m?.[1].startsWith('flow.')) {
96
+ newValue = newValue.replace(m[0], interpolate(m[0], { flow: properties.flow }));
97
+ }
98
+ } while (m);
99
+ return newValue;
100
+ } else {
101
+ return value;
102
+ }
103
+ }
104
+
105
+ function interpolate(text: string, templateVariables: Record<string, any>): string {
106
+ try {
107
+ return interp(text, templateVariables) ?? text;
108
+ } catch (err) {
109
+ return text;
110
+ }
111
+ }