bulltrackers-module 1.0.318 → 1.0.319

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.
@@ -1,14 +1,8 @@
1
1
  /**
2
2
  * @fileoverview Core Pub/Sub utility functions.
3
- * REFACTORED: Hybrid module supporting both Stateless functions and Stateful Class.
4
- * Fixes "PubSubUtils is not a constructor" error.
3
+ * UPDATED: Added single-message publish method to the PubSubUtils class.
5
4
  */
6
5
 
7
- /**
8
- * Stateless Function: Publishes tasks in batches.
9
- * @param {object} dependencies - { pubsub, logger }
10
- * @param {object} config - { topicName, tasks, taskType, maxPubsubBatchSize }
11
- */
12
6
  async function batchPublishTasks(dependencies, config) {
13
7
  const { pubsub, logger } = dependencies;
14
8
  const { topicName, tasks, taskType, maxPubsubBatchSize = 500 } = config;
@@ -33,7 +27,6 @@ async function batchPublishTasks(dependencies, config) {
33
27
 
34
28
  await Promise.all(batchPromises);
35
29
  messagesPublished += batchTasks.length;
36
- logger.log('TRACE', `[Core Utils] Published batch ${Math.ceil((i + 1) / maxPubsubBatchSize)} for ${taskType} (${batchTasks.length} messages)`);
37
30
  }
38
31
  logger.log('SUCCESS', `[Core Utils] Finished publishing ${messagesPublished} ${taskType} tasks to ${topicName}.`);
39
32
  } catch (error) {
@@ -42,39 +35,35 @@ async function batchPublishTasks(dependencies, config) {
42
35
  }
43
36
  }
44
37
 
45
- /**
46
- * Stateful Class Wrapper
47
- * Allows usage like: const utils = new PubSubUtils(deps); utils.batchPublishTasks(...)
48
- */
49
38
  class PubSubUtils {
50
39
  constructor(dependencies) {
51
40
  this.dependencies = dependencies;
52
41
  }
53
42
 
54
43
  /**
55
- * Hybrid method: Supports both (config) and (dependencies, config) signatures.
44
+ * [NEW] Publishes a single JSON message to a topic.
56
45
  */
57
- async batchPublishTasks(arg1, arg2) {
58
- // If called as (dependencies, config), use passed dependencies (Stateless/Legacy style)
59
- if (arg2) {
60
- return batchPublishTasks(arg1, arg2);
46
+ async publish(topicName, message) {
47
+ const { pubsub, logger } = this.dependencies;
48
+ const topic = pubsub.topic(topicName);
49
+ const dataBuffer = Buffer.from(JSON.stringify(message));
50
+
51
+ try {
52
+ await topic.publishMessage({ data: dataBuffer });
53
+ } catch (error) {
54
+ logger.log('ERROR', `[Core Utils] Failed to publish message to ${topicName}`, { error: error.message });
55
+ throw error;
61
56
  }
62
- // If called as (config), use this.dependencies (Stateful style)
57
+ }
58
+
59
+ async batchPublishTasks(arg1, arg2) {
60
+ if (arg2) return batchPublishTasks(arg1, arg2);
63
61
  return batchPublishTasks(this.dependencies, arg1);
64
62
  }
65
63
 
66
- /**
67
- * Helper for Computation System (Dispatcher)
68
- * Maps (topic, messages) -> batchPublishTasks
69
- */
70
64
  async publishMessageBatch(topicName, messages) {
71
- // Unpack {json: ...} structure if present
72
65
  const tasks = messages.map(m => m.json || m);
73
- const config = {
74
- topicName,
75
- tasks,
76
- taskType: 'computation-batch'
77
- };
66
+ const config = { topicName, tasks, taskType: 'computation-batch' };
78
67
  return batchPublishTasks(this.dependencies, config);
79
68
  }
80
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.318",
3
+ "version": "1.0.319",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [