@brickkit/redis-world 0.11.0 → 0.12.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.
package/NOTICE CHANGED
@@ -8,10 +8,11 @@ Changes: ported the queue to Workflow SDK v5's single-queue contract; added
8
8
  atomic reservation and persisted attempt/delivery counters, heartbeat lease
9
9
  fencing, owner-checked dedup release, capped retries without message loss,
10
10
  v5 routing and binary transport, and new recovery and runtime chaos tests.
11
- Storage, streaming, retention, and utilities are copied from the independent
12
- @brickkit/bullmq-world v5 implementation in this repository.
11
+ Storage, streaming, retention, and utilities came from the
12
+ @brickkit/bullmq-world v5 implementation in this repository, which now uses
13
+ them from this package.
13
14
 
14
- The copied v5 implementation is derived from @fantasticfour/world-redis-bullmq
15
+ That v5 implementation is derived from @fantasticfour/world-redis-bullmq
15
16
  (https://github.com/vinnymac/worlds, packages/world-redis-bullmq), Apache-2.0.
16
17
  Its v5 changes include position-based event IDs, atomic writes, restart
17
18
  recovery, independent utilities, and concurrency and chaos tests.
package/README.md CHANGED
@@ -90,7 +90,7 @@ The optional in-band writer fence, `$retention: '0'` purging, hook token retenti
90
90
 
91
91
  ## Choosing a World
92
92
 
93
- Choose `@brickkit/redis-world` when you want fewer dependencies and a hand-built list queue with durable delays, retries, and worker recovery. Choose `@brickkit/bullmq-world` when you want BullMQ's queue tooling and delivery records. Both use independent copies of the same v5 storage, streaming, and run-retention implementation. This package has no BullMQ dependency and no Bull Board integration.
93
+ Choose `@brickkit/redis-world` when you want fewer dependencies and a hand-built list queue with durable delays, retries, and worker recovery. Choose `@brickkit/bullmq-world` when you want BullMQ's queue tooling and delivery records. Both use the same v5 storage, streaming, and run-retention implementation, which lives in this package; `@brickkit/bullmq-world` depends on it. This package has no BullMQ dependency and no Bull Board integration.
94
94
 
95
95
  BullMQ-only options `jobPrefix`, `stalledInterval`, `maxStalledCount`, `lockDuration`, and `jobRetention` are absent. `keyPrefix` isolates the queue; `heartbeatTtlMs` controls crash recovery. Promotion and orphan checks run about every 100 ms while workers are alive.
96
96
 
package/dist/cli.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- //#region src/cli.d.ts
2
1
  declare function setupRedis(): Promise<void>;
3
- //#endregion
4
2
  export { setupRedis };
5
3
  //# sourceMappingURL=cli.d.ts.map
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","names":[],"sources":["../src/cli.ts"],"mappings":";iBAGe,cAAU"}
1
+ {"version":3,"file":"cli.d.ts","names":[],"sources":["../src/cli.ts"],"mappings":"A,iBAGe,cAAU"}
package/dist/cli.js CHANGED
@@ -1,21 +1,6 @@
1
+ import { t as loadOptionalEnvFile } from "./env-DMwDVTiZ.js";
1
2
  import { Redis } from "ioredis";
2
- //#region src/internal/env.ts
3
- /**
4
- * Load an env file when present without making a `.env` file mandatory.
5
- *
6
- * Node 24 provides the parser natively, so published worlds do not need a
7
- * runtime dependency solely to load local development configuration.
8
- */
9
- function loadOptionalEnvFile(path) {
10
- try {
11
- if (path === void 0) process.loadEnvFile();
12
- else process.loadEnvFile(path);
13
- } catch (error) {
14
- if (error.code !== "ENOENT") throw error;
15
- }
16
- }
17
- //#endregion
18
- //#region src/cli.ts
3
+ // src/cli.ts
19
4
  async function setupRedis() {
20
5
  loadOptionalEnvFile();
21
6
  const connectionString = process.env.WORKFLOW_REDIS_URL || process.env.REDIS_URL || "redis://localhost:6379";
@@ -59,7 +44,6 @@ async function setupRedis() {
59
44
  process.exit(exitCode);
60
45
  }
61
46
  if (import.meta.url === `file://${process.argv[1]}`) setupRedis();
62
- //#endregion
63
47
  export { setupRedis };
64
48
 
65
49
  //# sourceMappingURL=cli.js.map
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","names":[],"sources":["../src/internal/env.ts","../src/cli.ts"],"sourcesContent":["/**\n * Load an env file when present without making a `.env` file mandatory.\n *\n * Node 24 provides the parser natively, so published worlds do not need a\n * runtime dependency solely to load local development configuration.\n */\nexport function loadOptionalEnvFile(path?: string): void {\n try {\n if (path === undefined) {\n process.loadEnvFile();\n } else {\n process.loadEnvFile(path);\n }\n } catch (error: unknown) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw error;\n }\n }\n}\n","import { loadOptionalEnvFile } from \"./internal/env.js\";\nimport { Redis } from \"ioredis\";\n\nasync function setupRedis() {\n // Load .env file if it exists.\n loadOptionalEnvFile();\n\n const connectionString =\n process.env.WORKFLOW_REDIS_URL ||\n process.env.REDIS_URL ||\n \"redis://localhost:6379\";\n\n const keyPrefix = process.env.WORKFLOW_REDIS_KEY_PREFIX || \"workflow:\";\n\n console.log(\"Setting up Redis for Workflow...\");\n console.log(\n `Connection: ${connectionString.replace(/^(\\w+:\\/\\/)([^@]+)@/, \"$1[redacted]@\")}`,\n );\n console.log(`Key Prefix: ${keyPrefix}`);\n\n let redis: Redis | undefined;\n let exitCode = 0;\n\n try {\n redis = new Redis(connectionString);\n\n // Test connection\n await redis.ping();\n console.log(\"Successfully connected to Redis!\");\n\n // Get Redis info\n const info = await redis.info(\"server\");\n const version = info.match(/redis_version:([^\\r\\n]+)/)?.[1];\n if (version) {\n console.log(`Redis version: ${version}`);\n }\n\n // Check if any workflow keys exist\n const existingKeys = await redis.keys(`${keyPrefix}*`);\n if (existingKeys.length > 0) {\n console.log(\n `\\nWarning: found ${existingKeys.length} existing workflow keys with prefix \"${keyPrefix}\"`,\n );\n console.log(\n \"\\nTo flush existing workflow data, run with FLUSH=true environment variable:\",\n );\n console.log(\" FLUSH=true npx brickkit-redis-world-setup\");\n\n if (process.env.FLUSH === \"true\") {\n console.log(\"\\nFlushing existing workflow data...\");\n const pipeline = redis.pipeline();\n for (const key of existingKeys) {\n pipeline.del(key);\n }\n await pipeline.exec();\n console.log(`Deleted ${existingKeys.length} keys`);\n }\n } else {\n console.log(`\\nNo existing workflow data found (clean slate)`);\n }\n\n console.log(\"\\nRedis is ready for Workflow DevKit!\");\n console.log(\"\\nThe following Redis data structures will be used:\");\n console.log(\n ` - Hashes: ${keyPrefix}run:*, ${keyPrefix}step:*, ${keyPrefix}event:*, ${keyPrefix}hook:*`,\n );\n console.log(\n ` - Sorted Sets: ${keyPrefix}runs:*, ${keyPrefix}steps:*, ${keyPrefix}events:*`,\n );\n console.log(` - Streams: ${keyPrefix}stream:*`);\n console.log(\n ` - Redis queue: ${keyPrefix}queue:flows, processing lists and delayed set`,\n );\n } catch (error) {\n exitCode = 1;\n console.error(\"Failed to setup Redis:\", error);\n } finally {\n await redis?.quit().catch(() => {});\n }\n\n process.exit(exitCode);\n}\n\n// Check if running as main module\nif (import.meta.url === `file://${process.argv[1]}`) {\n setupRedis();\n}\n\nexport { setupRedis };\n"],"mappings":";;;;;;;;AAMA,SAAgB,oBAAoB,MAAqB;CACvD,IAAI;EACF,IAAI,SAAS,KAAA,GACX,QAAQ,YAAY;OAEpB,QAAQ,YAAY,IAAI;CAE5B,SAAS,OAAgB;EACvB,IAAK,MAAgC,SAAS,UAC5C,MAAM;CAEV;AACF;;;ACfA,eAAe,aAAa;CAE1B,oBAAoB;CAEpB,MAAM,mBACJ,QAAQ,IAAI,sBACZ,QAAQ,IAAI,aACZ;CAEF,MAAM,YAAY,QAAQ,IAAI,6BAA6B;CAE3D,QAAQ,IAAI,kCAAkC;CAC9C,QAAQ,IACN,eAAe,iBAAiB,QAAQ,uBAAuB,eAAe,GAChF;CACA,QAAQ,IAAI,eAAe,WAAW;CAEtC,IAAI;CACJ,IAAI,WAAW;CAEf,IAAI;EACF,QAAQ,IAAI,MAAM,gBAAgB;EAGlC,MAAM,MAAM,KAAK;EACjB,QAAQ,IAAI,kCAAkC;EAI9C,MAAM,WAAU,MADG,MAAM,KAAK,QAAQ,EAAA,CACjB,MAAM,0BAA0B,CAAC,GAAG;EACzD,IAAI,SACF,QAAQ,IAAI,kBAAkB,SAAS;EAIzC,MAAM,eAAe,MAAM,MAAM,KAAK,GAAG,UAAU,EAAE;EACrD,IAAI,aAAa,SAAS,GAAG;GAC3B,QAAQ,IACN,oBAAoB,aAAa,OAAO,uCAAuC,UAAU,EAC3F;GACA,QAAQ,IACN,8EACF;GACA,QAAQ,IAAI,6CAA6C;GAEzD,IAAI,QAAQ,IAAI,UAAU,QAAQ;IAChC,QAAQ,IAAI,sCAAsC;IAClD,MAAM,WAAW,MAAM,SAAS;IAChC,KAAK,MAAM,OAAO,cAChB,SAAS,IAAI,GAAG;IAElB,MAAM,SAAS,KAAK;IACpB,QAAQ,IAAI,WAAW,aAAa,OAAO,MAAM;GACnD;EACF,OACE,QAAQ,IAAI,iDAAiD;EAG/D,QAAQ,IAAI,uCAAuC;EACnD,QAAQ,IAAI,qDAAqD;EACjE,QAAQ,IACN,eAAe,UAAU,SAAS,UAAU,UAAU,UAAU,WAAW,UAAU,OACvF;EACA,QAAQ,IACN,oBAAoB,UAAU,UAAU,UAAU,WAAW,UAAU,SACzE;EACA,QAAQ,IAAI,gBAAgB,UAAU,SAAS;EAC/C,QAAQ,IACN,oBAAoB,UAAU,8CAChC;CACF,SAAS,OAAO;EACd,WAAW;EACX,QAAQ,MAAM,0BAA0B,KAAK;CAC/C,UAAU;EACR,MAAM,OAAO,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC;CACpC;CAEA,QAAQ,KAAK,QAAQ;AACvB;AAGA,IAAI,YAAY,QAAQ,UAAU,QAAQ,KAAK,MAC7C,WAAW"}
1
+ {"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["import { loadOptionalEnvFile } from \"./internal/env.js\";\nimport { Redis } from \"ioredis\";\n\nasync function setupRedis() {\n // Load .env file if it exists.\n loadOptionalEnvFile();\n\n const connectionString =\n process.env.WORKFLOW_REDIS_URL ||\n process.env.REDIS_URL ||\n \"redis://localhost:6379\";\n\n const keyPrefix = process.env.WORKFLOW_REDIS_KEY_PREFIX || \"workflow:\";\n\n console.log(\"Setting up Redis for Workflow...\");\n console.log(\n `Connection: ${connectionString.replace(/^(\\w+:\\/\\/)([^@]+)@/, \"$1[redacted]@\")}`,\n );\n console.log(`Key Prefix: ${keyPrefix}`);\n\n let redis: Redis | undefined;\n let exitCode = 0;\n\n try {\n redis = new Redis(connectionString);\n\n // Test connection\n await redis.ping();\n console.log(\"Successfully connected to Redis!\");\n\n // Get Redis info\n const info = await redis.info(\"server\");\n const version = info.match(/redis_version:([^\\r\\n]+)/)?.[1];\n if (version) {\n console.log(`Redis version: ${version}`);\n }\n\n // Check if any workflow keys exist\n const existingKeys = await redis.keys(`${keyPrefix}*`);\n if (existingKeys.length > 0) {\n console.log(\n `\\nWarning: found ${existingKeys.length} existing workflow keys with prefix \"${keyPrefix}\"`,\n );\n console.log(\n \"\\nTo flush existing workflow data, run with FLUSH=true environment variable:\",\n );\n console.log(\" FLUSH=true npx brickkit-redis-world-setup\");\n\n if (process.env.FLUSH === \"true\") {\n console.log(\"\\nFlushing existing workflow data...\");\n const pipeline = redis.pipeline();\n for (const key of existingKeys) {\n pipeline.del(key);\n }\n await pipeline.exec();\n console.log(`Deleted ${existingKeys.length} keys`);\n }\n } else {\n console.log(`\\nNo existing workflow data found (clean slate)`);\n }\n\n console.log(\"\\nRedis is ready for Workflow DevKit!\");\n console.log(\"\\nThe following Redis data structures will be used:\");\n console.log(\n ` - Hashes: ${keyPrefix}run:*, ${keyPrefix}step:*, ${keyPrefix}event:*, ${keyPrefix}hook:*`,\n );\n console.log(\n ` - Sorted Sets: ${keyPrefix}runs:*, ${keyPrefix}steps:*, ${keyPrefix}events:*`,\n );\n console.log(` - Streams: ${keyPrefix}stream:*`);\n console.log(\n ` - Redis queue: ${keyPrefix}queue:flows, processing lists and delayed set`,\n );\n } catch (error) {\n exitCode = 1;\n console.error(\"Failed to setup Redis:\", error);\n } finally {\n await redis?.quit().catch(() => {});\n }\n\n process.exit(exitCode);\n}\n\n// Check if running as main module\nif (import.meta.url === `file://${process.argv[1]}`) {\n setupRedis();\n}\n\nexport { setupRedis };\n"],"mappings":";;;AAGA,eAAe,aAAa;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W;EACX,QAAQ,MAAM,0BAA0B,KAAK;CAC/C,UAAU;EACR,MAAM,OAAO,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC;CACpC;CAEA,QAAQ,KAAK,QAAQ;AACvB;AAGA,IAAI,YAAY,QAAQ,UAAU,QAAQ,KAAK,MAC7C,WAAW"}
@@ -0,0 +1,18 @@
1
+ // src/internal/env.ts
2
+ /**
3
+ * Load an env file when present without making a `.env` file mandatory.
4
+ *
5
+ * Node 24 provides the parser natively, so published worlds do not need a
6
+ * runtime dependency solely to load local development configuration.
7
+ */
8
+ function loadOptionalEnvFile(path) {
9
+ try {
10
+ if (path === void 0) process.loadEnvFile();
11
+ else process.loadEnvFile(path);
12
+ } catch (error) {
13
+ if (error.code !== "ENOENT") throw error;
14
+ }
15
+ }
16
+ export { loadOptionalEnvFile as t };
17
+
18
+ //# sourceMappingURL=env-DMwDVTiZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-DMwDVTiZ.js","names":[],"sources":["../src/internal/env.ts"],"sourcesContent":["/**\n * Load an env file when present without making a `.env` file mandatory.\n *\n * Node 24 provides the parser natively, so published worlds do not need a\n * runtime dependency solely to load local development configuration.\n */\nexport function loadOptionalEnvFile(path?: string): void {\n try {\n if (path === undefined) {\n process.loadEnvFile();\n } else {\n process.loadEnvFile(path);\n }\n } catch (error: unknown) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw error;\n }\n }\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,oBAAoB,MAAqB;CACvD,IAAI;EACF,IAAI,SAAS,KAAA,GACX,QAAQ,YAAY;OAEpB,QAAQ,YAAY,IAAI;CAE5B,SAAS,OAAgB;EACvB,IAAK,MAAgC,SAAS,UAC5C,MAAM;CAEV;AACF"}
package/dist/index.d.ts CHANGED
@@ -1,28 +1,6 @@
1
+ import { n as RunRetention, t as KeepRuns } from "./reaper-SOJDwnBw.js";
1
2
  import { World } from "@workflow/world";
2
3
  import { Redis, RedisOptions } from "ioredis";
3
- //#region src/reaper.d.ts
4
- /** How long finished runs are kept, using `age` and `count` limits. */
5
- interface KeepRuns {
6
- /** Delete runs that finished more than this many seconds ago. */
7
- age?: number;
8
- /** Keep at most this many of the newest runs; delete the rest. */
9
- count?: number;
10
- }
11
- /**
12
- * Retention for run data (the run, its event log, steps, hooks, and streams),
13
- * per terminal status. A status without a policy is kept forever.
14
- */
15
- interface RunRetention {
16
- completed?: KeepRuns;
17
- failed?: KeepRuns;
18
- cancelled?: KeepRuns;
19
- /** How often each worker looks for expired runs (ms). Default: 60000 */
20
- sweepIntervalMs?: number;
21
- /** Runs deleted per status per sweep. Default: 200 */
22
- batchSize?: number;
23
- }
24
- //#endregion
25
- //#region src/config.d.ts
26
4
  interface RedisWorldConfig {
27
5
  /**
28
6
  * Redis connection URL or connection options
@@ -125,8 +103,6 @@ interface RedisWorldConfig {
125
103
  */
126
104
  retention?: RunRetention;
127
105
  }
128
- //#endregion
129
- //#region src/queue.d.ts
130
106
  interface QueueStats {
131
107
  waiting: number;
132
108
  active: number;
@@ -135,14 +111,11 @@ interface QueueStats {
135
111
  completed: number;
136
112
  failed: number;
137
113
  }
138
- //#endregion
139
- //#region src/index.d.ts
140
114
  export declare function createWorld(config?: RedisWorldConfig): World & {
141
115
  start(): Promise<void>;
142
116
  getQueueStats(): Promise<QueueStats>;
143
117
  /** Run one retention sweep now; returns the runs deleted. 0 without `retention`. */
144
118
  sweepRetention(): Promise<number>;
145
119
  };
146
- //#endregion
147
120
  export type { KeepRuns, QueueStats, RedisWorldConfig, RunRetention };
148
121
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/reaper.ts","../src/config.ts","../src/queue.ts","../src/index.ts"],"mappings":";;;;UAIiB;;EAEf;;EAEA;;;;;;UAOe;EACf,YAAY;EACZ,SAAS;EACT,YAAY;;EAEZ;;EAEA;;;;UCnBe;;;;;;;;EAQf,gBAAgB;;;;;EAMhB;;;EAIA;;;;;;EAOA;;;;;;;;;;EAWA;;;;;;EAOA;;;;;;EAOA;;;;;;EAOA;;;;;;;;;EAUA;;;;;;EAOA;;;;;;;;;;;;EAaA;;;EAIA;;;;;;;EAQA;;;;;;;;;;;;;EAcA,YAAY;;;;UC/FG;EACf;EACA;EACA;;EAEA;EACA;;;;wBCOc,YACd,SAAQ,mBAaP;EACD,SAAS;EACT,iBAAiB,QAAQ;;EAEzB,kBAAkB"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/config.ts","../src/queue.ts","../src/index.ts"],"mappings":";;;UAGiB;;;;;;;;EAQf,gBAAgB;;;;;EAMhB;;;EAIA;;;;;;EAOA;;;;;;;;;;EAWA;;;;;;EAOA;;;;;;EAOA;;;;;;EAOA;;;;;;;;;EAUA;;;;;;EAOA;;;;;;;;;;;;EAaA;;;EAIA;;;;;;;EAQA;;;;;;;;;;;;;EAcA,YAAY;;UC/FG;EACf;EACA;EACA;;EAEA;EACA;;wBCbc,YACd,SAAQ,mBAaP;EACD,SAAS;EACT,iBAAiB,QAAQ;;EAEzB,kBAAkB"}