@epztickets/common 1.25.0 → 1.26.0

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.
@@ -11,6 +11,6 @@ export declare abstract class JetStreamListener<T extends Event> {
11
11
  protected js: JetStreamClient;
12
12
  constructor(js: JetStreamClient);
13
13
  listen(): Promise<void>;
14
- abstract onMessage(data: T["data"], msg: JsMsg): void;
14
+ abstract onMessage(data: T["data"], msg: JsMsg): Promise<void>;
15
15
  }
16
16
  export {};
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ // import {
3
+ // JetStreamClient,
4
+ // consumerOpts,
5
+ // JsMsg,
6
+ // } from "nats";
7
+ // import { Subjects } from "./subjects";
2
8
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
9
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
10
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -17,7 +23,6 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
17
23
  };
18
24
  Object.defineProperty(exports, "__esModule", { value: true });
19
25
  exports.JetStreamListener = void 0;
20
- const nats_1 = require("nats");
21
26
  class JetStreamListener {
22
27
  constructor(js) {
23
28
  this.js = js;
@@ -25,24 +30,22 @@ class JetStreamListener {
25
30
  listen() {
26
31
  return __awaiter(this, void 0, void 0, function* () {
27
32
  var _a, e_1, _b, _c;
28
- const opts = (0, nats_1.consumerOpts)();
29
- opts.durable(this.durableName);
30
- opts.manualAck();
31
- opts.ackExplicit();
32
- opts.deliverAll();
33
- opts.maxDeliver(5);
34
- opts.filterSubject(this.subject);
35
- opts.deliverTo(`${this.queueGroup}.${this.durableName}`);
36
- const sub = yield this.js.subscribe(this.subject, opts);
33
+ // Get or bind to the durable consumer
34
+ const consumer = yield this.js.consumers.get("events", this.durableName);
37
35
  console.log(`Listening for ${this.subject} with durable ${this.durableName}`);
36
+ // Long-running pull-based consumption
37
+ const messages = yield consumer.consume({
38
+ max_messages: 1, // backpressure control
39
+ });
38
40
  try {
39
- for (var _d = true, sub_1 = __asyncValues(sub), sub_1_1; sub_1_1 = yield sub_1.next(), _a = sub_1_1.done, !_a; _d = true) {
40
- _c = sub_1_1.value;
41
+ for (var _d = true, messages_1 = __asyncValues(messages), messages_1_1; messages_1_1 = yield messages_1.next(), _a = messages_1_1.done, !_a; _d = true) {
42
+ _c = messages_1_1.value;
41
43
  _d = false;
42
44
  const msg = _c;
43
45
  try {
44
46
  const data = JSON.parse(msg.data.toString());
45
47
  yield this.onMessage(data, msg);
48
+ msg.ack();
46
49
  }
47
50
  catch (err) {
48
51
  console.error("Listener error", err);
@@ -52,7 +55,7 @@ class JetStreamListener {
52
55
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
53
56
  finally {
54
57
  try {
55
- if (!_d && !_a && (_b = sub_1.return)) yield _b.call(sub_1);
58
+ if (!_d && !_a && (_b = messages_1.return)) yield _b.call(messages_1);
56
59
  }
57
60
  finally { if (e_1) throw e_1.error; }
58
61
  }
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
- // import { JetStreamManager, RetentionPolicy, StorageType, DiscardPolicy } from "nats";
3
- // import { Streams } from "../events/subjects";
4
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -12,22 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
12
10
  };
13
11
  Object.defineProperty(exports, "__esModule", { value: true });
14
12
  exports.ensureStreams = ensureStreams;
15
- // export async function ensureEventStream(jsm: JetStreamManager) {
16
- // const streams = await jsm.streams.list().next();
17
- // const exists = streams.some(s => s.config.name === Streams.Events);
18
- // if (exists) {
19
- // console.log("Stream already exists:", Streams.Events);
20
- // return};
21
- // await jsm.streams.add({
22
- // name: Streams.Events,
23
- // subjects: ["events.>"],
24
- // // retention: RetentionPolicy.Workqueue, // consumer needs to be unique
25
- // retention: RetentionPolicy.Limits, // fan-out to multiple services
26
- // storage: StorageType.File,
27
- // discard: DiscardPolicy.Old,
28
- // max_age: 7 * 24 * 60 * 60 * 1000, // 7 days
29
- // });
30
- // }
31
13
  const nats_1 = require("nats");
32
14
  const subjects_1 = require("../events/subjects");
33
15
  function ensureStreams(jsm) {
@@ -59,35 +41,3 @@ function ensureStreams(jsm) {
59
41
  }
60
42
  });
61
43
  }
62
- // import {
63
- // JetStreamManager,
64
- // RetentionPolicy,
65
- // StorageType,
66
- // DiscardPolicy,
67
- // } from "nats";
68
- // import { Streams } from "../events/subjects";
69
- // export async function ensureStreams(jsm: JetStreamManager) {
70
- // const streams = await jsm.streams.list().next();
71
- // const hasEvents = streams.some(s => s.config.name === Streams.Events);
72
- // // 1️⃣ Stream already exists → validate config
73
- // if (hasEvents) {
74
- // const info = await jsm.streams.info(Streams.Events);
75
- // if (info.config.retention !== RetentionPolicy.Limits) {
76
- // throw new Error(
77
- // `EVENTS stream has invalid retention: ${info.config.retention}`
78
- // );
79
- // }
80
- // console.log("✅ EVENTS stream already exists with correct retention");
81
- // return;
82
- // }
83
- // // 2️⃣ Stream does not exist → create it
84
- // await jsm.streams.add({
85
- // name: Streams.Events,
86
- // subjects: ["events.>"],
87
- // retention: RetentionPolicy.Limits, // FAN-OUT
88
- // storage: StorageType.File,
89
- // discard: DiscardPolicy.Old,
90
- // max_age: 7 * 24 * 60 * 60 * 1_000_000_000 // ✅ nanoseconds
91
- // });
92
- // console.log("✅ Created EVENTS stream");
93
- // }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epztickets/common",
3
- "version": "1.25.0",
3
+ "version": "1.26.0",
4
4
  "main": "./build/index.js",
5
5
  "types": "./build/index.d.ts",
6
6
  "files": [