@zintrust/workers 0.4.88 → 0.4.90

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,13 +4,13 @@
4
4
  * Sealed namespace for immutability
5
5
  */
6
6
  import { ErrorFactory, Logger, createRedisConnection } from '@zintrust/core';
7
- import { keyPrefix } from './config/workerConfig.js';
7
+ import { keyPrefixFor } from './config/workerConfig.js';
8
8
  // Redis key prefixes - using workers package prefix system
9
9
  const getDLQPrefix = () => {
10
- return keyPrefix() + ':dlq:';
10
+ return keyPrefixFor('dlq');
11
11
  };
12
12
  const getAuditPrefix = () => {
13
- return keyPrefix() + ':dlq:audit:';
13
+ return keyPrefixFor('dlq', 'audit');
14
14
  };
15
15
  // Internal state
16
16
  let redisClient = null;
@@ -22,7 +22,7 @@ import { ResourceMonitor } from './ResourceMonitor.js';
22
22
  import { WorkerMetrics } from './WorkerMetrics.js';
23
23
  import { WorkerRegistry } from './WorkerRegistry.js';
24
24
  import { WorkerVersioning } from './WorkerVersioning.js';
25
- import { keyPrefix } from './config/workerConfig.js';
25
+ import { resolveWorkerKeyPrefix } from './config/workerConfig.js';
26
26
  import { recordQueueMonitorJob } from './queueMonitorHistory.js';
27
27
  import { DbWorkerStore, InMemoryWorkerStore, RedisWorkerStore, } from './storage/WorkerStore.js';
28
28
  const path = NodeSingletons.path;
@@ -1496,7 +1496,7 @@ const normalizeExplicitPersistence = (persistence) => {
1496
1496
  return {
1497
1497
  driver: 'redis',
1498
1498
  redis: persistence.redis,
1499
- keyPrefix: keyPrefix(),
1499
+ keyPrefix: resolveWorkerKeyPrefix(persistence.keyPrefix),
1500
1500
  };
1501
1501
  }
1502
1502
  const clientIsConnection = typeof persistence.client === 'string';
@@ -1532,7 +1532,7 @@ const resolvePersistenceConfig = (config) => {
1532
1532
  env: true,
1533
1533
  db: persistenceDbOverride ? 'WORKER_PERSISTENCE_REDIS_DB' : 'REDIS_QUEUE_DB',
1534
1534
  },
1535
- keyPrefix: keyPrefix(),
1535
+ keyPrefix: resolveWorkerKeyPrefix(),
1536
1536
  };
1537
1537
  }
1538
1538
  if (driver === 'db' || driver === 'database') {
@@ -1577,7 +1577,7 @@ const resolveWorkerStore = async (config) => {
1577
1577
  }
1578
1578
  else if (persistence.driver === 'redis') {
1579
1579
  const redisConfig = resolveRedisConfigWithFallback(persistence.redis, config.infrastructure?.redis, 'Worker persistence requires redis config (persistence.redis or infrastructure.redis)', 'infrastructure.persistence.redis');
1580
- const key_prefix = persistence.keyPrefix ?? keyPrefix();
1580
+ const key_prefix = resolveWorkerKeyPrefix(persistence.keyPrefix);
1581
1581
  logRedisPersistenceConfig(redisConfig, key_prefix, 'resolveWorkerStore');
1582
1582
  const client = createRedisConnection(redisConfig, 3, { subsystem: 'worker-persistence' });
1583
1583
  next = RedisWorkerStore.create(client, key_prefix);
@@ -1621,7 +1621,7 @@ const createWorkerStore = async (persistence) => {
1621
1621
  }
1622
1622
  if (persistence.driver === 'redis') {
1623
1623
  const redisConfig = resolveRedisConfigWithFallback(persistence.redis ?? { env: true }, undefined, 'Worker persistence requires redis config (persistence.redis or REDIS_* env values)', 'persistence.redis');
1624
- const key_prefix = persistence.keyPrefix ?? keyPrefix();
1624
+ const key_prefix = resolveWorkerKeyPrefix(persistence.keyPrefix);
1625
1625
  logRedisPersistenceConfig(redisConfig, key_prefix, 'createWorkerStore');
1626
1626
  const client = createRedisConnection(redisConfig, 3, { subsystem: 'worker-persistence' });
1627
1627
  return RedisWorkerStore.create(client, key_prefix);
@@ -11,7 +11,7 @@ import { Env, Logger } from '@zintrust/core';
11
11
  import { ResourceMonitor } from './ResourceMonitor.js';
12
12
  import { WorkerFactory } from './WorkerFactory.js';
13
13
  import { WorkerShutdown } from './WorkerShutdown.js';
14
- import { keyPrefix } from './config/workerConfig.js';
14
+ import { resolveWorkerKeyPrefix } from './config/workerConfig.js';
15
15
  // ============================================================================
16
16
  // State
17
17
  // ============================================================================
@@ -53,7 +53,7 @@ function initializeResourceMonitoring(enableResourceMonitoring, resourceMonitori
53
53
  }
54
54
  const getPersistenceOverride = (driver) => {
55
55
  if (driver === 'redis') {
56
- return { driver: 'redis', keyPrefix: keyPrefix() };
56
+ return { driver: 'redis', keyPrefix: resolveWorkerKeyPrefix() };
57
57
  }
58
58
  if (driver === 'memory') {
59
59
  return { driver: 'memory' };
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@zintrust/workers",
3
- "version": "0.4.88",
4
- "buildDate": "2026-04-09T19:25:15.743Z",
3
+ "version": "0.4.90",
4
+ "buildDate": "2026-04-09T20:07:51.346Z",
5
5
  "buildEnvironment": {
6
6
  "node": "v22.22.1",
7
7
  "platform": "darwin",
8
8
  "arch": "arm64"
9
9
  },
10
10
  "git": {
11
- "commit": "2c76f668",
11
+ "commit": "507173d8",
12
12
  "branch": "release"
13
13
  },
14
14
  "package": {
@@ -106,8 +106,8 @@
106
106
  "sha256": "dd82e7e2c23a2fcaefc0cb87a1a7931594d6a5f76b758f608c77063f5e8533cd"
107
107
  },
108
108
  "DeadLetterQueue.js": {
109
- "size": 19476,
110
- "sha256": "de0ac7ee53a71e375536041a3ce65be22bc29f1901af8564f1e60307007c061e"
109
+ "size": 19478,
110
+ "sha256": "d99676dc1750f740ed31c0df40e4ee3ad1c7e1ea2c9ac54d43885d4f88a07888"
111
111
  },
112
112
  "HealthMonitor.d.ts": {
113
113
  "size": 1485,
@@ -178,16 +178,16 @@
178
178
  "sha256": "3869f960c87260588e40941ff91bffcfa0757be7a04815fd28b57dd4840c51df"
179
179
  },
180
180
  "WorkerFactory.js": {
181
- "size": 105839,
182
- "sha256": "b26135593d6e3849f5540d74d097082d8186b50c72a456722f83d624141c42c8"
181
+ "size": 105917,
182
+ "sha256": "11412e2889073bed28b16dbb2f7103c593181f364e47211bdc2beaf8a05985a5"
183
183
  },
184
184
  "WorkerInit.d.ts": {
185
185
  "size": 3284,
186
186
  "sha256": "f902550cda7fca36f2db6297d39a4339ed6b5ff1c738da867233309cf0ca8fe1"
187
187
  },
188
188
  "WorkerInit.js": {
189
- "size": 14031,
190
- "sha256": "51f44ca085a1682130aa36fed3acfd575108e974bf4c21eaa772001719c18853"
189
+ "size": 14057,
190
+ "sha256": "29c4d961d14b9d78ee638b8ed3e0be55afc7edc3a6b7418a2c783339a4f7797a"
191
191
  },
192
192
  "WorkerMetrics.d.ts": {
193
193
  "size": 3304,
@@ -230,16 +230,16 @@
230
230
  "sha256": "8af20d462270e7044c6ea983821f5b6e6ce8a5caf39b6e8fefff07c9a0bf071e"
231
231
  },
232
232
  "build-manifest.json": {
233
- "size": 19881,
234
- "sha256": "4cafd6bbb9c9f15439c7cde2edc4d27dde3d70cd9213b04ddec7510c983ef4e8"
233
+ "size": 19882,
234
+ "sha256": "e08c29c9f1674eb9a543b4623a3f8693cce1c91d824c0d4b8ee2ebcbbc152c95"
235
235
  },
236
236
  "config/workerConfig.d.ts": {
237
- "size": 132,
238
- "sha256": "577486dd9e0ef5b5c27d070e0f6a383337d9d68725fae0f0bad258254b828a3b"
237
+ "size": 282,
238
+ "sha256": "4671566a0cba372852c049ba66f7671ec19f5db38b0eaed1815eb532e7d58109"
239
239
  },
240
240
  "config/workerConfig.js": {
241
- "size": 1775,
242
- "sha256": "ce9e871099ead4f565b2af8aa8f7a6798fe5eb274ca43a442cdf1e255c3c8b1e"
241
+ "size": 3285,
242
+ "sha256": "c59a1d86d249c9841d83f5fe6ea3a0f0f79c82c4b986a2ecbbd2d5860b1847cd"
243
243
  },
244
244
  "createQueueWorker.d.ts": {
245
245
  "size": 1031,
@@ -415,7 +415,7 @@
415
415
  },
416
416
  "index.js": {
417
417
  "size": 2337,
418
- "sha256": "a04c542b9162b9514c8670a8374b0c7fbf5d98aae5f6eb8fdf5a64ae20501a52"
418
+ "sha256": "288271dc3495eea71f83ed1db31008aa6dd94cf6a5613ab30d87e8f493326237"
419
419
  },
420
420
  "queueMonitorHistory.d.ts": {
421
421
  "size": 433,
@@ -1,4 +1,6 @@
1
1
  export declare const WorkerConfig: Readonly<{
2
2
  getWorkerBaseUrl: () => string;
3
3
  }>;
4
+ export declare const resolveWorkerKeyPrefix: (value?: string | null) => string;
4
5
  export declare const keyPrefix: () => string;
6
+ export declare const keyPrefixFor: (...segments: string[]) => string;
@@ -17,6 +17,7 @@ const resolveWorkerApiUrl = () => {
17
17
  export const WorkerConfig = Object.freeze({
18
18
  getWorkerBaseUrl: resolveWorkerApiUrl,
19
19
  });
20
+ const LEGACY_REDIS_WORKER_PREFIX = 'zintrust:workers:';
20
21
  const trimBoundaryUnderscores = (value) => {
21
22
  let start = 0;
22
23
  let end = value.length;
@@ -36,13 +37,59 @@ const normalizeAppName = (value) => {
36
37
  const normalized = trimBoundaryUnderscores(collapsedUnderscores);
37
38
  return normalized === '' ? 'zintrust' : normalized;
38
39
  };
39
- export const keyPrefix = () => {
40
- const redisKeyPrefix = (Env.get('WORKER_PERSISTENCE_REDIS_KEY_PREFIX', '') ?? '').trim();
41
- if (redisKeyPrefix !== '') {
42
- return redisKeyPrefix;
40
+ const trimBoundaryColons = (value) => {
41
+ let start = 0;
42
+ let end = value.length;
43
+ while (start < end && value.charAt(start) === ':') {
44
+ start += 1;
43
45
  }
46
+ while (end > start && value.charAt(end - 1) === ':') {
47
+ end -= 1;
48
+ }
49
+ return value.slice(start, end);
50
+ };
51
+ const defaultKeyPrefix = () => {
44
52
  const appName = typeof appConfig.name === 'string' && appConfig.name.trim() !== ''
45
53
  ? appConfig.name
46
54
  : Env.get('APP_NAME', 'zintrust');
47
55
  return `${normalizeAppName(appName)}_zintrust:workers:`;
48
56
  };
57
+ const isLegacyWorkerPrefix = (value) => {
58
+ if (value === LEGACY_REDIS_WORKER_PREFIX)
59
+ return true;
60
+ if (value.startsWith('worker_'))
61
+ return true;
62
+ return value.includes(':workers:_worker_');
63
+ };
64
+ const normalizeConfiguredKeyPrefix = (value) => {
65
+ if (typeof value !== 'string')
66
+ return undefined;
67
+ const trimmed = value.trim();
68
+ if (trimmed === '')
69
+ return undefined;
70
+ if (isLegacyWorkerPrefix(trimmed)) {
71
+ return defaultKeyPrefix();
72
+ }
73
+ return trimmed;
74
+ };
75
+ const appendPrefixSegment = (base, segment) => {
76
+ const normalizedSegment = trimBoundaryColons(segment.trim());
77
+ if (normalizedSegment === '')
78
+ return base;
79
+ const normalizedBase = trimBoundaryColons(base);
80
+ if (normalizedBase === '') {
81
+ return `${normalizedSegment}:`;
82
+ }
83
+ return `${normalizedBase}:${normalizedSegment}:`;
84
+ };
85
+ export const resolveWorkerKeyPrefix = (value) => {
86
+ return (normalizeConfiguredKeyPrefix(value) ??
87
+ normalizeConfiguredKeyPrefix(Env.get('WORKER_PERSISTENCE_REDIS_KEY_PREFIX', '')) ??
88
+ defaultKeyPrefix());
89
+ };
90
+ export const keyPrefix = () => {
91
+ return resolveWorkerKeyPrefix();
92
+ };
93
+ export const keyPrefixFor = (...segments) => {
94
+ return segments.reduce((prefix, segment) => appendPrefixSegment(prefix, segment), keyPrefix());
95
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zintrust/workers",
3
- "version": "0.4.88",
3
+ "version": "0.4.90",
4
4
  "description": "Worker orchestration and background job management for ZinTrust.",
5
5
  "private": false,
6
6
  "type": "module",
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import { ErrorFactory, Logger, createRedisConnection, type RedisConfig } from '@zintrust/core';
8
- import { keyPrefix } from './config/workerConfig';
8
+ import { keyPrefixFor } from './config/workerConfig';
9
9
 
10
10
  type RedisConnection = ReturnType<typeof createRedisConnection>;
11
11
 
@@ -74,11 +74,11 @@ export type DLQStats = {
74
74
 
75
75
  // Redis key prefixes - using workers package prefix system
76
76
  const getDLQPrefix = (): string => {
77
- return keyPrefix() + ':dlq:';
77
+ return keyPrefixFor('dlq');
78
78
  };
79
79
 
80
80
  const getAuditPrefix = (): string => {
81
- return keyPrefix() + ':dlq:audit:';
81
+ return keyPrefixFor('dlq', 'audit');
82
82
  };
83
83
 
84
84
  // Internal state
@@ -46,7 +46,7 @@ import { ResourceMonitor } from './ResourceMonitor';
46
46
  import { WorkerMetrics } from './WorkerMetrics';
47
47
  import { WorkerRegistry, type WorkerInstance as RegistryWorkerInstance } from './WorkerRegistry';
48
48
  import { WorkerVersioning } from './WorkerVersioning';
49
- import { keyPrefix } from './config/workerConfig';
49
+ import { resolveWorkerKeyPrefix } from './config/workerConfig';
50
50
  import { recordQueueMonitorJob } from './queueMonitorHistory';
51
51
  import {
52
52
  DbWorkerStore,
@@ -2166,7 +2166,7 @@ const normalizeExplicitPersistence = (
2166
2166
  return {
2167
2167
  driver: 'redis',
2168
2168
  redis: persistence.redis,
2169
- keyPrefix: keyPrefix(),
2169
+ keyPrefix: resolveWorkerKeyPrefix(persistence.keyPrefix),
2170
2170
  };
2171
2171
  }
2172
2172
 
@@ -2210,7 +2210,7 @@ const resolvePersistenceConfig = (
2210
2210
  env: true,
2211
2211
  db: persistenceDbOverride ? 'WORKER_PERSISTENCE_REDIS_DB' : 'REDIS_QUEUE_DB',
2212
2212
  },
2213
- keyPrefix: keyPrefix(),
2213
+ keyPrefix: resolveWorkerKeyPrefix(),
2214
2214
  };
2215
2215
  }
2216
2216
 
@@ -2270,7 +2270,7 @@ const resolveWorkerStore = async (config: WorkerFactoryConfig): Promise<WorkerSt
2270
2270
  'Worker persistence requires redis config (persistence.redis or infrastructure.redis)',
2271
2271
  'infrastructure.persistence.redis'
2272
2272
  );
2273
- const key_prefix = persistence.keyPrefix ?? keyPrefix();
2273
+ const key_prefix = resolveWorkerKeyPrefix(persistence.keyPrefix);
2274
2274
  logRedisPersistenceConfig(redisConfig, key_prefix, 'resolveWorkerStore');
2275
2275
  const client = createRedisConnection(redisConfig, 3, { subsystem: 'worker-persistence' });
2276
2276
  next = RedisWorkerStore.create(client, key_prefix);
@@ -2324,7 +2324,7 @@ const createWorkerStore = async (persistence: WorkerPersistenceConfig): Promise<
2324
2324
  'Worker persistence requires redis config (persistence.redis or REDIS_* env values)',
2325
2325
  'persistence.redis'
2326
2326
  );
2327
- const key_prefix = persistence.keyPrefix ?? keyPrefix();
2327
+ const key_prefix = resolveWorkerKeyPrefix(persistence.keyPrefix);
2328
2328
  logRedisPersistenceConfig(redisConfig, key_prefix, 'createWorkerStore');
2329
2329
  const client = createRedisConnection(redisConfig, 3, { subsystem: 'worker-persistence' });
2330
2330
  return RedisWorkerStore.create(client, key_prefix);
package/src/WorkerInit.ts CHANGED
@@ -13,7 +13,7 @@ import { ResourceMonitor } from './ResourceMonitor';
13
13
  import type { WorkerPersistenceConfig } from './WorkerFactory';
14
14
  import { WorkerFactory } from './WorkerFactory';
15
15
  import { WorkerShutdown } from './WorkerShutdown';
16
- import { keyPrefix } from './config/workerConfig';
16
+ import { resolveWorkerKeyPrefix } from './config/workerConfig';
17
17
 
18
18
  // ============================================================================
19
19
  // Types
@@ -109,7 +109,7 @@ function initializeResourceMonitoring(
109
109
 
110
110
  const getPersistenceOverride = (driver: string): WorkerPersistenceConfig => {
111
111
  if (driver === 'redis') {
112
- return { driver: 'redis', keyPrefix: keyPrefix() };
112
+ return { driver: 'redis', keyPrefix: resolveWorkerKeyPrefix() };
113
113
  }
114
114
 
115
115
  if (driver === 'memory') {
@@ -24,6 +24,8 @@ export const WorkerConfig = Object.freeze({
24
24
  getWorkerBaseUrl: resolveWorkerApiUrl,
25
25
  });
26
26
 
27
+ const LEGACY_REDIS_WORKER_PREFIX = 'zintrust:workers:';
28
+
27
29
  const trimBoundaryUnderscores = (value: string): string => {
28
30
  let start = 0;
29
31
  let end = value.length;
@@ -48,13 +50,22 @@ const normalizeAppName = (value: string): string => {
48
50
  return normalized === '' ? 'zintrust' : normalized;
49
51
  };
50
52
 
51
- export const keyPrefix = (): string => {
52
- const redisKeyPrefix = (Env.get('WORKER_PERSISTENCE_REDIS_KEY_PREFIX', '') ?? '').trim();
53
+ const trimBoundaryColons = (value: string): string => {
54
+ let start = 0;
55
+ let end = value.length;
53
56
 
54
- if (redisKeyPrefix !== '') {
55
- return redisKeyPrefix;
57
+ while (start < end && value.charAt(start) === ':') {
58
+ start += 1;
59
+ }
60
+
61
+ while (end > start && value.charAt(end - 1) === ':') {
62
+ end -= 1;
56
63
  }
57
64
 
65
+ return value.slice(start, end);
66
+ };
67
+
68
+ const defaultKeyPrefix = (): string => {
58
69
  const appName =
59
70
  typeof appConfig.name === 'string' && appConfig.name.trim() !== ''
60
71
  ? appConfig.name
@@ -62,3 +73,50 @@ export const keyPrefix = (): string => {
62
73
 
63
74
  return `${normalizeAppName(appName)}_zintrust:workers:`;
64
75
  };
76
+
77
+ const isLegacyWorkerPrefix = (value: string): boolean => {
78
+ if (value === LEGACY_REDIS_WORKER_PREFIX) return true;
79
+ if (value.startsWith('worker_')) return true;
80
+ return value.includes(':workers:_worker_');
81
+ };
82
+
83
+ const normalizeConfiguredKeyPrefix = (value: string | undefined | null): string | undefined => {
84
+ if (typeof value !== 'string') return undefined;
85
+
86
+ const trimmed = value.trim();
87
+ if (trimmed === '') return undefined;
88
+
89
+ if (isLegacyWorkerPrefix(trimmed)) {
90
+ return defaultKeyPrefix();
91
+ }
92
+
93
+ return trimmed;
94
+ };
95
+
96
+ const appendPrefixSegment = (base: string, segment: string): string => {
97
+ const normalizedSegment = trimBoundaryColons(segment.trim());
98
+ if (normalizedSegment === '') return base;
99
+
100
+ const normalizedBase = trimBoundaryColons(base);
101
+ if (normalizedBase === '') {
102
+ return `${normalizedSegment}:`;
103
+ }
104
+
105
+ return `${normalizedBase}:${normalizedSegment}:`;
106
+ };
107
+
108
+ export const resolveWorkerKeyPrefix = (value?: string | null): string => {
109
+ return (
110
+ normalizeConfiguredKeyPrefix(value) ??
111
+ normalizeConfiguredKeyPrefix(Env.get('WORKER_PERSISTENCE_REDIS_KEY_PREFIX', '')) ??
112
+ defaultKeyPrefix()
113
+ );
114
+ };
115
+
116
+ export const keyPrefix = (): string => {
117
+ return resolveWorkerKeyPrefix();
118
+ };
119
+
120
+ export const keyPrefixFor = (...segments: string[]): string => {
121
+ return segments.reduce((prefix, segment) => appendPrefixSegment(prefix, segment), keyPrefix());
122
+ };