@similie/hyphen-command-server-types 1.0.4 → 1.0.5

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.
@@ -4,4 +4,5 @@ export * from "./jwt.js";
4
4
  export * from "./sql.js";
5
5
  export * from "./objectq.js";
6
6
  export * from "./secrets.js";
7
+ export * from "./queue.js";
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
@@ -4,4 +4,5 @@ export * from "./jwt.js";
4
4
  export * from "./sql.js";
5
5
  export * from "./objectq.js";
6
6
  export * from "./secrets.js";
7
+ export * from "./queue.js";
7
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { Queue, Worker, QueueEvents, type ConnectionOptions, type QueueOptions, type WorkerOptions, type Job, type QueueEventsOptions, type JobsOptions } from "bullmq";
2
+ export type JobValue = Job;
3
+ export type qOptions = QueueOptions;
4
+ export type wOptions = WorkerOptions;
5
+ export type qEOptions = QueueEventsOptions;
6
+ export type JOpt = JobsOptions;
7
+ export type jQueue = Queue;
8
+ export type jWorker = Worker;
9
+ export declare class QueueManager {
10
+ private readonly _connection;
11
+ private static _instance;
12
+ private readonly _qMap;
13
+ private readonly _wMap;
14
+ private constructor();
15
+ get connection(): ConnectionOptions;
16
+ get queueOpt(): {
17
+ connection: ConnectionOptions;
18
+ };
19
+ concurrentOpt(value?: number): {
20
+ connection: ConnectionOptions;
21
+ concurrency: number;
22
+ };
23
+ delayMsOpt(ttlMs: number): QueueOptions;
24
+ delaySecondsOpt(seconds: number): QueueOptions;
25
+ delayMinutesOpt(minutes: number): QueueOptions;
26
+ delayDaysOpt(days: number): QueueOptions;
27
+ get workerOption(): WorkerOptions;
28
+ static get get(): QueueManager;
29
+ add(name: string, JOpt?: {}): Promise<JobValue>;
30
+ queue(name: string, opt?: qOptions): Queue;
31
+ qEvents(name: string, opt?: qEOptions): QueueEvents;
32
+ worker(name: string, cb: (job: JobValue) => Promise<any>, opt?: wOptions): Worker;
33
+ }
34
+ //# sourceMappingURL=queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../src/services/queue.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,MAAM,EACN,WAAW,EACX,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,GAAG,EACR,KAAK,kBAAkB,EACvB,KAAK,WAAW,EACjB,MAAM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 @@
1
+ import { Queue, Worker, QueueEvents, } from "bullmq";
2
+ const getRedisConfig = () => {
3
+ return process.env.REDIS_CONFIG_URL || "redis://localhost:6379/1";
4
+ };
5
+ export class QueueManager {
6
+ _connection;
7
+ static _instance;
8
+ _qMap;
9
+ _wMap;
10
+ constructor() {
11
+ this._connection = { url: getRedisConfig() };
12
+ this._qMap = new Map();
13
+ this._wMap = new Map();
14
+ }
15
+ get connection() {
16
+ return this._connection;
17
+ }
18
+ get queueOpt() {
19
+ return { connection: this.connection };
20
+ }
21
+ concurrentOpt(value = 5) {
22
+ return { connection: this.connection, concurrency: value };
23
+ }
24
+ delayMsOpt(ttlMs) {
25
+ const opt = {
26
+ connection: this.connection,
27
+ defaultJobOptions: {
28
+ delay: ttlMs, // e.g. 7 days = 7 * 24 * 60 * 60 * 1000
29
+ removeOnComplete: true,
30
+ removeOnFail: true,
31
+ },
32
+ };
33
+ return opt;
34
+ }
35
+ delaySecondsOpt(seconds) {
36
+ const ttlMs = seconds * 1000;
37
+ const opt = {
38
+ connection: this.connection,
39
+ defaultJobOptions: {
40
+ delay: ttlMs, // e.g. 7 days = 7 * 24 * 60 * 60 * 1000
41
+ removeOnComplete: true,
42
+ removeOnFail: true,
43
+ },
44
+ };
45
+ return opt;
46
+ }
47
+ delayMinutesOpt(minutes) {
48
+ const ttlMs = minutes * 60 * 1000;
49
+ const opt = {
50
+ connection: this.connection,
51
+ defaultJobOptions: {
52
+ delay: ttlMs, // e.g. 7 days = 7 * 24 * 60 * 60 * 1000
53
+ removeOnComplete: true,
54
+ removeOnFail: true,
55
+ },
56
+ };
57
+ return opt;
58
+ }
59
+ delayDaysOpt(days) {
60
+ const ttlMs = days * 24 * 60 * 60 * 1000;
61
+ const opt = {
62
+ connection: this.connection,
63
+ defaultJobOptions: {
64
+ delay: ttlMs, // e.g. 7 days = 7 * 24 * 60 * 60 * 1000
65
+ removeOnComplete: true,
66
+ removeOnFail: true,
67
+ },
68
+ };
69
+ return opt;
70
+ }
71
+ get workerOption() {
72
+ const opt = {
73
+ connection: this._connection,
74
+ removeOnFail: { count: 500, age: 3600 },
75
+ removeOnComplete: { count: 500, age: 3600 },
76
+ };
77
+ return opt;
78
+ }
79
+ static get get() {
80
+ if (!this._instance) {
81
+ this._instance = new QueueManager();
82
+ }
83
+ return this._instance;
84
+ }
85
+ add(name, JOpt = {}) {
86
+ if (!this._qMap.has(name)) {
87
+ throw new Error("This queue hasn't been initialize");
88
+ }
89
+ return this._qMap.get(name).add(name, JOpt);
90
+ }
91
+ queue(name, opt = { connection: this._connection }) {
92
+ if (!opt.connection) {
93
+ opt.connection = this._connection;
94
+ }
95
+ const q = new Queue(name, opt);
96
+ this._qMap.set(name, q);
97
+ return q;
98
+ }
99
+ qEvents(name, opt = { connection: this._connection }) {
100
+ if (!opt.connection) {
101
+ opt.connection = this._connection;
102
+ }
103
+ if (!this._qMap.has(name)) {
104
+ this.queue(name);
105
+ }
106
+ return new QueueEvents(name, opt);
107
+ }
108
+ worker(name, cb, opt = this.workerOption) {
109
+ if (!opt.connection) {
110
+ opt.connection = this._connection;
111
+ }
112
+ if (!this._qMap.has(name)) {
113
+ this.queue(name);
114
+ }
115
+ const w = new Worker(name, cb, opt);
116
+ this._wMap.set(name, w);
117
+ return w;
118
+ }
119
+ }
120
+ //# sourceMappingURL=queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.js","sourceRoot":"","sources":["../../src/services/queue.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,MAAM,EACN,WAAW,GAOZ,MAAM,QAAQ,CAAC;AAChB,MAAM,cAAc,GAAG,GAAG,EAAE;IAC1B,OAAO,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,0BAA0B,CAAC;AACpE,CAAC,CAAC;AASF,MAAM,OAAO,YAAY;IACN,WAAW,CAAoB;IACxC,MAAM,CAAC,SAAS,CAA2B;IAClC,KAAK,CAAqB;IAC1B,KAAK,CAAsB;IAC5C;QACE,IAAI,CAAC,W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C;IACX,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@similie/hyphen-command-server-types",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Adds common types for Hyphen Command Center modules.",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -19,6 +19,7 @@
19
19
  "@similie/ellipsies": "^1.0.16",
20
20
  "@similie/http-connector": "^0.0.17",
21
21
  "@similie/model-connect-entities": "^1.1.4",
22
+ "bullmq": "^5.66.3",
22
23
  "crypto-js": "^4.2.0",
23
24
  "ioredis": "^5.8.2",
24
25
  "jsonwebtoken": "^9.0.3",