@hahnpro/flow-sdk 4.23.7 → 4.23.8

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.
@@ -30,6 +30,7 @@ export declare class FlowApplication {
30
30
  private setQueueMetrics;
31
31
  private updateMetrics;
32
32
  subscribe: (streamId: string, observer: PartialObserver<FlowEvent>) => import("rxjs").Subscription;
33
+ rpcClient: () => RpcClient;
33
34
  emit: (event: FlowEvent) => void;
34
35
  emitPartial: (completeEvent: FlowEvent, partialEvent: FlowEvent) => void;
35
36
  getProperties(): Record<string, any>;
@@ -39,7 +40,6 @@ export declare class FlowApplication {
39
40
  * If the event size exceeds the limit it will be truncated
40
41
  */
41
42
  publishEvent: (event: FlowEvent) => void;
42
- rpcClient(): Promise<RpcClient>;
43
43
  /**
44
44
  * Calls onDestroy lifecycle method on all flow elements,
45
45
  * closes amqp connection after allowing logs to be processed and published
@@ -76,6 +76,7 @@ class FlowApplication {
76
76
  }
77
77
  };
78
78
  this.subscribe = (streamId, observer) => this.getOutputStream(streamId).subscribe(observer);
79
+ this.rpcClient = () => this._rpcClient;
79
80
  this.emit = (event) => {
80
81
  if (event) {
81
82
  try {
@@ -252,6 +253,7 @@ class FlowApplication {
252
253
  await logErrorAndExit(`Could not subscribe to deployment exchange: ${err}`);
253
254
  return;
254
255
  }
256
+ this._rpcClient = new RpcClient_1.RpcClient(this.amqpConnection);
255
257
  }
256
258
  for (const module of this.modules) {
257
259
  const moduleName = Reflect.getMetadata('module:name', module);
@@ -341,16 +343,6 @@ class FlowApplication {
341
343
  getProperties() {
342
344
  return this.properties;
343
345
  }
344
- async rpcClient() {
345
- if (!this.amqpConnection) {
346
- throw new Error('No AMQP connection available');
347
- }
348
- if (!this._rpcClient) {
349
- this._rpcClient = new RpcClient_1.RpcClient(this.amqpConnection);
350
- await this._rpcClient.init();
351
- }
352
- return this._rpcClient;
353
- }
354
346
  async destroy(exitCode = 0) {
355
347
  var _a, _b, _c, _d;
356
348
  try {
@@ -370,7 +362,7 @@ class FlowApplication {
370
362
  console.error(err);
371
363
  }
372
364
  finally {
373
- if (process.env.JEST_WORKER_ID == undefined || process.env.NODE_ENV !== 'test') {
365
+ if (process.env.NODE_ENV !== 'test') {
374
366
  process.exit(exitCode);
375
367
  }
376
368
  }
@@ -92,13 +92,8 @@ class FlowElement {
92
92
  return this.validateProperties(classType, event.getData(), whitelist);
93
93
  }
94
94
  async callRpcFunction(functionName, ...args) {
95
- var _a, _b;
96
- try {
97
- return (_b = (await ((_a = this.app) === null || _a === void 0 ? void 0 : _a.rpcClient()))) === null || _b === void 0 ? void 0 : _b.callFunction(this.rpcRoutingKey, functionName, ...args);
98
- }
99
- catch (err) {
100
- this.logger.error(err);
101
- }
95
+ var _a;
96
+ return (_a = this.app) === null || _a === void 0 ? void 0 : _a.rpcClient().callFunction(this.rpcRoutingKey, functionName, ...args);
102
97
  }
103
98
  runPyRpcScript(scriptPath, ...args) {
104
99
  const options = {
@@ -4,7 +4,6 @@ export declare class RpcClient {
4
4
  private channel;
5
5
  private openRequests;
6
6
  constructor(amqpConnection: AmqpConnection);
7
- init(): Promise<void>;
8
7
  private onMessage;
9
8
  callFunction: (routingKey: string, functionName: string, ...args: any[]) => Promise<unknown>;
10
9
  declareFunction: (routingKey: string, name: string) => (...args: any[]) => Promise<unknown>;
package/dist/RpcClient.js CHANGED
@@ -53,12 +53,13 @@ class RpcClient {
53
53
  if (!amqpConnection) {
54
54
  throw new Error('currently no amqp connection available');
55
55
  }
56
- }
57
- async init() {
58
- this.channel = this.amqpConnection.managedConnection.createChannel({ json: true });
59
- await this.channel.waitForConnect();
60
- await this.channel.assertExchange('rpc_direct_exchange', 'direct', { durable: false });
61
- await this.channel.consume('amq.rabbitmq.reply-to', this.onMessage, { noAck: true });
56
+ this.channel = this.amqpConnection.managedConnection.createChannel({
57
+ json: true,
58
+ setup: async (channel) => {
59
+ await channel.assertExchange('rpc_direct_exchange', 'direct', { durable: false });
60
+ await channel.consume('amq.rabbitmq.reply-to', this.onMessage, { noAck: true });
61
+ },
62
+ });
62
63
  }
63
64
  close() {
64
65
  return this.channel.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hahnpro/flow-sdk",
3
- "version": "4.23.7",
3
+ "version": "4.23.8",
4
4
  "description": "SDK for building Flow Modules",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -42,11 +42,11 @@
42
42
  "@nestjs/common": "^9.3.9",
43
43
  "@types/amqp-connection-manager": "^2.0.12",
44
44
  "@types/amqplib": "^0.10.1",
45
- "@types/jest": "^29.4.0",
45
+ "@types/jest": "^29.4.2",
46
46
  "@types/lodash": "^4.14.191",
47
- "@types/node": "^18.14.4",
48
- "class-validator-jsonschema": "^4.0.0",
49
- "jest": "^29.4.3",
47
+ "@types/node": "^18.15.3",
48
+ "class-validator-jsonschema": "^5.0.0",
49
+ "jest": "^29.5.0",
50
50
  "typescript": "^4.9.5"
51
51
  },
52
52
  "engines": {