@zintrust/queue-redis 0.4.94 → 0.4.96

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.
@@ -0,0 +1,10 @@
1
+ import type { QueueMessage } from '@zintrust/core';
2
+ interface IQueueDriver {
3
+ enqueue<T = unknown>(queue: string, payload: T): Promise<string>;
4
+ dequeue<T = unknown>(queue: string): Promise<QueueMessage<T> | undefined>;
5
+ ack(queue: string, id: string): Promise<void>;
6
+ length(queue: string): Promise<number>;
7
+ drain(queue: string): Promise<void>;
8
+ }
9
+ export declare const RedisQueue: IQueueDriver;
10
+ export default RedisQueue;
@@ -0,0 +1,92 @@
1
+ import { ErrorFactory, generateUuid, getRedisUrl, Logger } from '@zintrust/core';
2
+ export const RedisQueue = (() => {
3
+ let client = null;
4
+ let connected = false;
5
+ const ensureClient = async () => {
6
+ if (connected && client !== null)
7
+ return client;
8
+ const url = getRedisUrl();
9
+ if (url === null)
10
+ throw ErrorFactory.createConfigError('Redis queue driver requires REDIS_URL');
11
+ // Import lazily so package is optional for environments that don't use Redis
12
+ try {
13
+ // Prefer the redis package when available
14
+ try {
15
+ const mod = (await import('redis'));
16
+ const createClient = mod.createClient;
17
+ client = createClient({ url });
18
+ if (typeof client.connect === 'function') {
19
+ try {
20
+ await client.connect();
21
+ connected = true;
22
+ }
23
+ catch (connectionError) {
24
+ connected = false;
25
+ Logger.warn('Redis client connect failed:', String(connectionError));
26
+ }
27
+ }
28
+ else {
29
+ connected = true;
30
+ }
31
+ }
32
+ catch {
33
+ // Fallback to ioredis when available (used by queue-monitor)
34
+ const mod = (await import('ioredis'));
35
+ const redis = mod.default(url);
36
+ client = {
37
+ rPush: (queue, value) => redis.rpush(queue, value),
38
+ lPop: (queue) => redis.lpop(queue),
39
+ lLen: (queue) => redis.llen(queue),
40
+ del: (queue) => redis.del(queue),
41
+ };
42
+ connected = true;
43
+ }
44
+ }
45
+ catch (error) {
46
+ const globalFake = globalThis
47
+ .__fakeRedisClient;
48
+ if (globalFake === undefined) {
49
+ throw ErrorFactory.createConfigError("Redis queue driver requires the 'redis' or 'ioredis' package (run `zin add queue:redis` / `zin plugin install queue:redis`, or `npm install redis` / `npm install ioredis`) or a test fake client set in globalThis.__fakeRedisClient", error);
50
+ }
51
+ client = globalFake;
52
+ connected = true;
53
+ }
54
+ if (client === null)
55
+ throw ErrorFactory.createConfigError('Redis client could not be initialized');
56
+ return client;
57
+ };
58
+ return {
59
+ async enqueue(queue, payload) {
60
+ const cli = await ensureClient();
61
+ const id = generateUuid();
62
+ const msg = JSON.stringify({ id, payload, attempts: 0 });
63
+ await cli.rPush(queue, msg);
64
+ return id;
65
+ },
66
+ async dequeue(queue) {
67
+ const cli = await ensureClient();
68
+ const raw = await cli.lPop(queue);
69
+ if (raw === null)
70
+ return undefined;
71
+ try {
72
+ const parsed = JSON.parse(raw);
73
+ return parsed;
74
+ }
75
+ catch (err) {
76
+ throw ErrorFactory.createTryCatchError('Failed to parse queue message', err);
77
+ }
78
+ },
79
+ async ack(_queue, _id) {
80
+ return Promise.resolve(); // NOSONAR
81
+ },
82
+ async length(queue) {
83
+ const cli = await ensureClient();
84
+ return cli.lLen(queue);
85
+ },
86
+ async drain(queue) {
87
+ const cli = await ensureClient();
88
+ await cli.del(queue);
89
+ },
90
+ };
91
+ })();
92
+ export default RedisQueue;
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@zintrust/queue-redis",
3
- "version": "0.4.94",
4
- "buildDate": "2026-04-11T09:22:51.168Z",
3
+ "version": "0.4.96",
4
+ "buildDate": "2026-04-11T20:48:09.060Z",
5
5
  "buildEnvironment": {
6
- "node": "v20.20.2",
7
- "platform": "linux",
8
- "arch": "x64"
6
+ "node": "v22.22.1",
7
+ "platform": "darwin",
8
+ "arch": "arm64"
9
9
  },
10
10
  "git": {
11
- "commit": "785d0351",
12
- "branch": "master"
11
+ "commit": "ddf9b233",
12
+ "branch": "release"
13
13
  },
14
14
  "package": {
15
15
  "engines": {
@@ -56,13 +56,25 @@
56
56
  "size": 5464,
57
57
  "sha256": "18b785c47b4df689f9969625880d1b559e6cf8c95bb8c3cd3a4112fa75e0d870"
58
58
  },
59
+ "RedisQueue.d.ts": {
60
+ "size": 438,
61
+ "sha256": "eefad366ae71d63044b23038265bf3eb60a0277e41ac70f57c5973d79f2af5ce"
62
+ },
63
+ "RedisQueue.js": {
64
+ "size": 3593,
65
+ "sha256": "dc8b2c28b2e288e048423067f90ffbe0389ac813086246a1c8fafeeeab5c142d"
66
+ },
67
+ "build-manifest.json": {
68
+ "size": 2513,
69
+ "sha256": "cabad763255ab97b931790c84336c8d3f08f5cf7590a0832bb01508a637cf037"
70
+ },
59
71
  "index.d.ts": {
60
72
  "size": 565,
61
73
  "sha256": "7bc063419989a39530b3a4213627e0aea33fbaacac8c307d9e7e654c99bd5b8d"
62
74
  },
63
75
  "index.js": {
64
76
  "size": 677,
65
- "sha256": "8fa34ed1b1c0aa9b3b7402caca7d262e6b009c8433d8612674495dc2854ca369"
77
+ "sha256": "ff7e4e8e41a23c94a07812632185fb6c89fc81518c5ff8337a4927b31e1384f3"
66
78
  },
67
79
  "register.d.ts": {
68
80
  "size": 170,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zintrust/queue-redis",
3
- "version": "0.4.94",
3
+ "version": "0.4.96",
4
4
  "description": "Redis queue driver for ZinTrust.",
5
5
  "private": false,
6
6
  "type": "module",
@@ -23,7 +23,7 @@
23
23
  "node": ">=20.0.0"
24
24
  },
25
25
  "peerDependencies": {
26
- "@zintrust/core": "^0.4.93"
26
+ "@zintrust/core": "^0.4.95"
27
27
  },
28
28
  "publishConfig": {
29
29
  "access": "public"