@axxel/event-bus 1.1.8 → 1.1.9

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,7 +1,4 @@
1
1
  import type { TokenPriceEvent } from '../types/TokenPriceEvent';
2
2
  export declare function produceTokenPrice(event: TokenPriceEvent): Promise<void>;
3
- /**
4
- * Batch produce multiple token prices in a single Kafka send for optimal performance
5
- */
6
3
  export declare function produceTokenPriceBatch(events: TokenPriceEvent[]): Promise<void>;
7
4
  //# sourceMappingURL=tokenPriceProducer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tokenPriceProducer.d.ts","sourceRoot":"","sources":["../../src/producers/tokenPriceProducer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAa,eAAe,EAAE,MAAM,0BAA0B,CAAC;AA+B3E,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,eAAe,iBAwB7D;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAAC,MAAM,EAAE,eAAe,EAAE,iBAiCrE"}
1
+ {"version":3,"file":"tokenPriceProducer.d.ts","sourceRoot":"","sources":["../../src/producers/tokenPriceProducer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAa,eAAe,EAAE,MAAM,0BAA0B,CAAC;AA+B3E,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,eAAe,iBAwB7D;AAED,wBAAsB,sBAAsB,CAAC,MAAM,EAAE,eAAe,EAAE,iBAiCrE"}
@@ -44,33 +44,31 @@ async function produceTokenPrice(event) {
44
44
  });
45
45
  console.log(`✅ Sent token price update for ${event.symbol ?? event.tokenAddress} (chain ${event.chainId})`);
46
46
  }
47
- /**
48
- * Batch produce multiple token prices in a single Kafka send for optimal performance
49
- */
50
47
  async function produceTokenPriceBatch(events) {
51
48
  if (events.length === 0)
52
49
  return;
53
50
  const producer = await getProducer();
54
- const messages = events.map((event) => {
55
- const key = `${event.chainId}:${event.tokenAddress}`;
56
- const serializedEvent = {
57
- ...event,
58
- price: normalizePriceMap(event.price),
59
- };
60
- return {
51
+ // group by (chainId + tokenAddress)
52
+ const byToken = new Map();
53
+ for (const e of events) {
54
+ const key = `${e.chainId}:${e.tokenAddress}`;
55
+ if (!byToken.has(key))
56
+ byToken.set(key, []);
57
+ byToken.get(key).push(e);
58
+ }
59
+ // send one ordered stream per token
60
+ for (const [key, tokenEvents] of byToken.entries()) {
61
+ const messages = tokenEvents.map((event) => ({
61
62
  key,
62
- value: JSON.stringify(serializedEvent),
63
- };
64
- });
65
- // Print only chainId, symbol, and tokenAddress for each event in the batch
66
- console.log('🔎 Token price batch:', events.map((event) => ({
67
- chainId: event.chainId,
68
- symbol: event.symbol,
69
- tokenAddress: event.tokenAddress,
70
- })));
71
- await producer.send({
72
- topic: topics_1.TOPICS.TOKEN_PRICES,
73
- messages,
74
- });
75
- console.log(`✅ Sent ${events.length} token price updates in batch`);
63
+ value: JSON.stringify({
64
+ ...event,
65
+ price: normalizePriceMap(event.price),
66
+ }),
67
+ }));
68
+ await producer.send({
69
+ topic: topics_1.TOPICS.TOKEN_PRICES,
70
+ messages,
71
+ });
72
+ }
73
+ console.log(`✅ Sent ${events.length} token price updates across ${byToken.size} token streams`);
76
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axxel/event-bus",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "Axxel Kafka Event Bus SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",