@epztickets/common 1.24.0 → 1.25.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.
@@ -28,6 +28,37 @@ exports.ensureStreams = ensureStreams;
28
28
  // max_age: 7 * 24 * 60 * 60 * 1000, // 7 days
29
29
  // });
30
30
  // }
31
+ const nats_1 = require("nats");
32
+ const subjects_1 = require("../events/subjects");
33
+ function ensureStreams(jsm) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ const existing = yield jsm.streams.list().next();
36
+ const has = (name) => existing.some(s => s.config.name === name);
37
+ /* ---------------- EVENTS STREAM ---------------- */
38
+ if (!has(subjects_1.Streams.Events)) {
39
+ yield jsm.streams.add({
40
+ name: subjects_1.Streams.Events,
41
+ subjects: ["events.>"],
42
+ retention: nats_1.RetentionPolicy.Limits, // FAN-OUT
43
+ storage: nats_1.StorageType.File,
44
+ discard: nats_1.DiscardPolicy.Old,
45
+ max_age: 7 * 24 * 60 * 60 * 1000000000,
46
+ });
47
+ console.log("Created stream:", subjects_1.Streams.Events);
48
+ }
49
+ /* ---------------- JOBS STREAM ---------------- */
50
+ if (!has(subjects_1.Streams.Jobs)) {
51
+ yield jsm.streams.add({
52
+ name: subjects_1.Streams.Jobs,
53
+ subjects: ["jobs.>"],
54
+ retention: nats_1.RetentionPolicy.Workqueue, // EXACTLY-ONCE
55
+ storage: nats_1.StorageType.File,
56
+ discard: nats_1.DiscardPolicy.Old,
57
+ });
58
+ console.log("Created stream:", subjects_1.Streams.Jobs);
59
+ }
60
+ });
61
+ }
31
62
  // import {
32
63
  // JetStreamManager,
33
64
  // RetentionPolicy,
@@ -36,57 +67,27 @@ exports.ensureStreams = ensureStreams;
36
67
  // } from "nats";
37
68
  // import { Streams } from "../events/subjects";
38
69
  // export async function ensureStreams(jsm: JetStreamManager) {
39
- // const existing = await jsm.streams.list().next();
40
- // const has = (name: string) =>
41
- // existing.some(s => s.config.name === name);
42
- // /* ---------------- EVENTS STREAM ---------------- */
43
- // if (!has(Streams.Events)) {
44
- // await jsm.streams.add({
45
- // name: Streams.Events,
46
- // subjects: ["events.>"],
47
- // retention: RetentionPolicy.Limits, // FAN-OUT
48
- // storage: StorageType.File,
49
- // discard: DiscardPolicy.Old,
50
- // max_age: 7 * 24 * 60 * 60 * 1000,
51
- // });
52
- // console.log("Created stream:", Streams.Events);
53
- // }
54
- // /* ---------------- JOBS STREAM ---------------- */
55
- // if (!has(Streams.Jobs)) {
56
- // await jsm.streams.add({
57
- // name: Streams.Jobs,
58
- // subjects: ["jobs.>"],
59
- // retention: RetentionPolicy.Workqueue, // EXACTLY-ONCE
60
- // storage: StorageType.File,
61
- // discard: DiscardPolicy.Old,
62
- // });
63
- // console.log("Created stream:", Streams.Jobs);
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;
64
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");
65
93
  // }
66
- const nats_1 = require("nats");
67
- const subjects_1 = require("../events/subjects");
68
- function ensureStreams(jsm) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- const streams = yield jsm.streams.list().next();
71
- const hasEvents = streams.some(s => s.config.name === subjects_1.Streams.Events);
72
- // 1️⃣ Stream already exists → validate config
73
- if (hasEvents) {
74
- const info = yield jsm.streams.info(subjects_1.Streams.Events);
75
- if (info.config.retention !== nats_1.RetentionPolicy.Limits) {
76
- throw new Error(`EVENTS stream has invalid retention: ${info.config.retention}`);
77
- }
78
- console.log("✅ EVENTS stream already exists with correct retention");
79
- return;
80
- }
81
- // 2️⃣ Stream does not exist → create it
82
- yield jsm.streams.add({
83
- name: subjects_1.Streams.Events,
84
- subjects: ["events.>"],
85
- retention: nats_1.RetentionPolicy.Limits, // FAN-OUT
86
- storage: nats_1.StorageType.File,
87
- discard: nats_1.DiscardPolicy.Old,
88
- max_age: 7 * 24 * 60 * 60 * 1000,
89
- });
90
- console.log("✅ Created EVENTS stream");
91
- });
92
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epztickets/common",
3
- "version": "1.24.0",
3
+ "version": "1.25.0",
4
4
  "main": "./build/index.js",
5
5
  "types": "./build/index.d.ts",
6
6
  "files": [