@objectstack/service-cluster-redis 16.1.0 → 17.0.0-rc.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,338 @@
1
1
  # @objectstack/service-cluster-redis
2
2
 
3
+ ## 17.0.0-rc.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 2e836de: chore(packaging): CHANGELOG.md ships in every npm tarball (#4261)
8
+
9
+ The AGENTS.md post-task checklist requires breaking changesets to carry their
10
+ FROM → TO migration because "this text ships to consumers as `CHANGELOG.md`
11
+ inside the npm package and is what an upgrading agent greps after the tombstone
12
+ error." That delivery path was severed for 68 of the 69 publishable packages:
13
+ npm packs `package.json` / `README*` / `LICENSE*` unconditionally but — unlike
14
+ older npm versions — not `CHANGELOG.md`, and the canonical
15
+ `"files": ["dist", "README.md"]` whitelist never named it. Measured on npm
16
+ 10.9.7: `npm pack --dry-run` on `@objectstack/types` shipped 3 files while its
17
+ 70KB `CHANGELOG.md` stayed behind. Only `@objectstack/spec` listed it
18
+ explicitly.
19
+
20
+ The tombstone-error scenario is precisely the one where the repo is out of
21
+ reach — the upgrading agent has `node_modules` and nothing else — so the
22
+ migration text has to ride in the tarball. Every publishable package now
23
+ declares `CHANGELOG.md` in `files`, and the canonical whitelist is
24
+ `["dist", "README.md", "CHANGELOG.md"]`.
25
+
26
+ The other half is the gate: `check:published-files` gains a fifth invariant,
27
+ COMPLETE — a whitelist that fails to cover `CHANGELOG.md` fails the
28
+ always-required lint job, so the next package cannot silently sever the path
29
+ again. `@objectstack/spec`'s per-package EXTRA_ENTRIES exemption dissolves
30
+ into the canonical set.
31
+
32
+ Consumer-visible change: one more file per install (the package's changelog,
33
+ e.g. 70.8KB for `@objectstack/types`), and `grep -r "removed key"
34
+ node_modules/@objectstack/*/CHANGELOG.md` now finds the migration it was
35
+ promised.
36
+
37
+ - cc2de0e: chore(packaging): 20 packages stop publishing their sources, tests and build tooling (#4248)
38
+
39
+ These 20 packages declared no `files` field, so npm fell back to packing the
40
+ whole package directory. `npm pack --dry-run` on `@objectstack/plugin-webhooks`
41
+ listed **21 files** — 15 under `src/`, three of them unit tests
42
+ (`auto-enqueuer.test.ts`, `bootstrap-declared-webhooks.test.ts`, …), plus the
43
+ build-time `scripts/i18n-extract.config.ts`. `dist/` lands on top of that at
44
+ publish time rather than instead of it, so consumers were installing the
45
+ TypeScript sources and the test suite alongside the artifact they asked for.
46
+
47
+ Each now declares `"files": ["dist", "README.md"]`, matching the 29 packages
48
+ that already did. Nothing a consumer imports moves: every `main` / `types` /
49
+ `exports` target in all 20 already resolved inside `dist/`, which the new
50
+ `check:published-files` guard verifies rather than assumes. The visible change
51
+ is a smaller install and a smaller dependency-scanning surface — `npm pack` on
52
+ `@objectstack/plugin-webhooks` now yields 2 files plus `dist/`.
53
+
54
+ The other half of the fix is the gate. Half the packages declaring `files` and
55
+ half not was the #3786 shape — a hand-copied convention with nothing enforcing
56
+ it, where whoever forgets the line gets no signal at all. `check:published-files`
57
+ (new, wired into the always-required `lint` job) holds every non-private
58
+ workspace package to four invariants: `files` is **declared**; it is
59
+ **sufficient** (covers every entry point, so tightening a whitelist cannot ship
60
+ a package that fails to resolve); it is **minimal** (admits no test, test-harness
61
+ config or build script); and anything beyond `dist` + `README.md` is
62
+ **registered** with a reason, reconciled in both directions so a stale exemption
63
+ is an error rather than dead text. `@objectstack/spec` is the one package with
64
+ registered extras — its `.zod.ts` sources, JSON Schemas, liveness ledgers and
65
+ `CHANGELOG.md` are product, not build input.
66
+
67
+ This also closes an assumption #4206 was resting on. Excluding `<pkg>/scripts/**`
68
+ from the docs-drift implementation test is sound only while no package publishes
69
+ `scripts/` as runtime code; that held, but it held because someone read all three
70
+ offenders by hand. It is now checked on every PR.
71
+
72
+ - Updated dependencies [6a67d7a]
73
+ - Updated dependencies [0ecc656]
74
+ - Updated dependencies [06772eb]
75
+ - Updated dependencies [270650f]
76
+ - Updated dependencies [3aef718]
77
+ - Updated dependencies [1ea6bce]
78
+ - Updated dependencies [c1dcacd]
79
+ - Updated dependencies [ad303ed]
80
+ - Updated dependencies [32ccb23]
81
+ - Updated dependencies [f5a4ef0]
82
+ - Updated dependencies [2d3e255]
83
+ - Updated dependencies [7d7521f]
84
+ - Updated dependencies [5dc4d02]
85
+ - Updated dependencies [05154a1]
86
+ - Updated dependencies [9b6fe7c]
87
+ - Updated dependencies [8c711fb]
88
+ - Updated dependencies [09e4547]
89
+ - Updated dependencies [91f4c78]
90
+ - Updated dependencies [820eff9]
91
+ - Updated dependencies [8d895ff]
92
+ - Updated dependencies [f6472d7]
93
+ - Updated dependencies [78caf51]
94
+ - Updated dependencies [62a789b]
95
+ - Updated dependencies [789ad63]
96
+ - Updated dependencies [2af1988]
97
+ - Updated dependencies [2e836de]
98
+ - Updated dependencies [12a19a8]
99
+ - Updated dependencies [41dcda3]
100
+ - Updated dependencies [c8124e5]
101
+ - Updated dependencies [a1a4140]
102
+ - Updated dependencies [217e2e6]
103
+ - Updated dependencies [86a71d1]
104
+ - Updated dependencies [d5c75e2]
105
+ - Updated dependencies [03d26f7]
106
+ - Updated dependencies [4384921]
107
+ - Updated dependencies [3c628ce]
108
+ - Updated dependencies [7cb922e]
109
+ - Updated dependencies [1d22114]
110
+ - Updated dependencies [b5f9397]
111
+ - Updated dependencies [ed77493]
112
+ - Updated dependencies [58a03d2]
113
+ - Updated dependencies [dc530b4]
114
+ - Updated dependencies [e59786e]
115
+ - Updated dependencies [bcf1112]
116
+ - Updated dependencies [9774b78]
117
+ - Updated dependencies [b07d829]
118
+ - Updated dependencies [a648e96]
119
+ - Updated dependencies [a47ac06]
120
+ - Updated dependencies [e4c61a7]
121
+ - Updated dependencies [cc60165]
122
+ - Updated dependencies [081aa6f]
123
+ - Updated dependencies [91f4c78]
124
+ - Updated dependencies [e8d0c21]
125
+ - Updated dependencies [c1d44f7]
126
+ - Updated dependencies [ab9fb5c]
127
+ - Updated dependencies [f985b3f]
128
+ - Updated dependencies [9a4932a]
129
+ - Updated dependencies [f9fc874]
130
+ - Updated dependencies [011b386]
131
+ - Updated dependencies [7777e8f]
132
+ - Updated dependencies [507b92a]
133
+ - Updated dependencies [7309c81]
134
+ - Updated dependencies [20bc1ec]
135
+ - Updated dependencies [90c2b15]
136
+ - Updated dependencies [42eeb7d]
137
+ - Updated dependencies [01e124d]
138
+ - Updated dependencies [7ce02eb]
139
+ - Updated dependencies [a13827e]
140
+ - Updated dependencies [7733604]
141
+ - Updated dependencies [40e420f]
142
+ - Updated dependencies [d13004a]
143
+ - Updated dependencies [be7360c]
144
+ - Updated dependencies [cc2de0e]
145
+ - Updated dependencies [5b47ab5]
146
+ - Updated dependencies [b09d8d9]
147
+ - Updated dependencies [b09d8d9]
148
+ - Updated dependencies [8675db6]
149
+ - Updated dependencies [b09d8d9]
150
+ - Updated dependencies [3eb1b2b]
151
+ - Updated dependencies [59b85c0]
152
+ - Updated dependencies [6e357ed]
153
+ - Updated dependencies [d6938bf]
154
+ - Updated dependencies [31e0be9]
155
+ - Updated dependencies [4bfd455]
156
+ - Updated dependencies [ffd2ce2]
157
+ - Updated dependencies [62f8017]
158
+ - Updated dependencies [a831df1]
159
+ - Updated dependencies [f752ee3]
160
+ - Updated dependencies [a1b61e0]
161
+ - Updated dependencies [cd6b9f2]
162
+ - Updated dependencies [2cb6d3c]
163
+ - Updated dependencies [af2a095]
164
+ - Updated dependencies [ec796d5]
165
+ - Updated dependencies [e87fea1]
166
+ - Updated dependencies [c65e529]
167
+ - Updated dependencies [3ca34c1]
168
+ - Updated dependencies [239c3a3]
169
+ - Updated dependencies [94a0bbc]
170
+ - Updated dependencies [d6bfb3d]
171
+ - Updated dependencies [a2266a6]
172
+ - Updated dependencies [d25a0ec]
173
+ - Updated dependencies [667b83e]
174
+ - Updated dependencies [627b188]
175
+ - Updated dependencies [8d4eae7]
176
+ - Updated dependencies [65a3a84]
177
+ - Updated dependencies [ccd9397]
178
+ - Updated dependencies [bca935b]
179
+ - Updated dependencies [c54c822]
180
+ - Updated dependencies [8dcc0f5]
181
+ - Updated dependencies [75b9e51]
182
+ - Updated dependencies [0a2f233]
183
+ - Updated dependencies [8621cdd]
184
+ - Updated dependencies [6f23667]
185
+ - Updated dependencies [5d21a48]
186
+ - Updated dependencies [19365b7]
187
+ - Updated dependencies [b7ed26d]
188
+ - Updated dependencies [b3a3d83]
189
+ - Updated dependencies [7a55913]
190
+ - Updated dependencies [35accbf]
191
+ - Updated dependencies [6038de7]
192
+ - Updated dependencies [eb95d97]
193
+ - Updated dependencies [e4c2dc8]
194
+ - Updated dependencies [1bd2795]
195
+ - Updated dependencies [8186a70]
196
+ - Updated dependencies [a329cca]
197
+ - Updated dependencies [6eec18c]
198
+ - Updated dependencies [4d7bebf]
199
+ - Updated dependencies [821ac7a]
200
+ - Updated dependencies [8f81731]
201
+ - Updated dependencies [8b50cb3]
202
+ - Updated dependencies [8c2db68]
203
+ - Updated dependencies [22b5e54]
204
+ - Updated dependencies [0166bd5]
205
+ - Updated dependencies [9b702dc]
206
+ - Updated dependencies [ab16331]
207
+ - @objectstack/spec@17.0.0-rc.1
208
+ - @objectstack/service-cluster@17.0.0-rc.1
209
+
210
+ ## 17.0.0-rc.0
211
+
212
+ ### Patch Changes
213
+
214
+ - Updated dependencies [50616d9]
215
+ - Updated dependencies [08b5a3d]
216
+ - Updated dependencies [d99aeb3]
217
+ - Updated dependencies [4727eb8]
218
+ - Updated dependencies [f63cd09]
219
+ - Updated dependencies [fa3d0cf]
220
+ - Updated dependencies [af5a224]
221
+ - Updated dependencies [71f76e1]
222
+ - Updated dependencies [37b1346]
223
+ - Updated dependencies [99736a0]
224
+ - Updated dependencies [fe67e34]
225
+ - Updated dependencies [fdb4f50]
226
+ - Updated dependencies [1bd5652]
227
+ - Updated dependencies [14252d3]
228
+ - Updated dependencies [7fb436c]
229
+ - Updated dependencies [879ea13]
230
+ - Updated dependencies [201b31f]
231
+ - Updated dependencies [e2616e0]
232
+ - Updated dependencies [6fdc5c6]
233
+ - Updated dependencies [8b9d71e]
234
+ - Updated dependencies [33f5e23]
235
+ - Updated dependencies [259af21]
236
+ - Updated dependencies [587fc91]
237
+ - Updated dependencies [1986594]
238
+ - Updated dependencies [ad4af62]
239
+ - Updated dependencies [d44dbfa]
240
+ - Updated dependencies [474fe39]
241
+ - Updated dependencies [0bc685a]
242
+ - Updated dependencies [b949059]
243
+ - Updated dependencies [be1c52c]
244
+ - Updated dependencies [c5ff96d]
245
+ - Updated dependencies [84e7be9]
246
+ - Updated dependencies [a6c3f38]
247
+ - Updated dependencies [debc23a]
248
+ - Updated dependencies [0f8ad09]
249
+ - Updated dependencies [8f9689f]
250
+ - Updated dependencies [57a3bb3]
251
+ - Updated dependencies [5f9a987]
252
+ - Updated dependencies [db02d47]
253
+ - Updated dependencies [0bfdf46]
254
+ - Updated dependencies [376a061]
255
+ - Updated dependencies [7c7e246]
256
+ - Updated dependencies [f35cdc5]
257
+ - Updated dependencies [9ea2bc5]
258
+ - Updated dependencies [c2d9098]
259
+ - Updated dependencies [a227ed7]
260
+ - Updated dependencies [9613396]
261
+ - Updated dependencies [e47b342]
262
+ - Updated dependencies [4ed7ed4]
263
+ - Updated dependencies [2fa4ca1]
264
+ - Updated dependencies [f5a2320]
265
+ - Updated dependencies [deb538f]
266
+ - Updated dependencies [5b89711]
267
+ - Updated dependencies [0c8a22f]
268
+ - Updated dependencies [763931e]
269
+ - Updated dependencies [de9af8a]
270
+ - Updated dependencies [c4df271]
271
+ - Updated dependencies [a41ba5c]
272
+ - Updated dependencies [189854c]
273
+ - Updated dependencies [0e3a226]
274
+ - Updated dependencies [1d4756e]
275
+ - Updated dependencies [720c5ad]
276
+ - Updated dependencies [a8d1e24]
277
+ - Updated dependencies [41642b0]
278
+ - Updated dependencies [4cca74c]
279
+ - Updated dependencies [88ef03e]
280
+ - Updated dependencies [9e2caf3]
281
+ - Updated dependencies [81ce41a]
282
+ - Updated dependencies [85e1e4e]
283
+ - Updated dependencies [dac6a08]
284
+ - Updated dependencies [394b7a1]
285
+ - Updated dependencies [677b591]
286
+ - Updated dependencies [d77d1b7]
287
+ - Updated dependencies [5b79a34]
288
+ - Updated dependencies [c757854]
289
+ - Updated dependencies [0045682]
290
+ - Updated dependencies [2a5f04a]
291
+ - Updated dependencies [4f740b0]
292
+ - Updated dependencies [67452d1]
293
+ - Updated dependencies [0fc6219]
294
+ - Updated dependencies [605e190]
295
+ - Updated dependencies [c6c59f1]
296
+ - Updated dependencies [b0e78a8]
297
+ - Updated dependencies [f31cc8d]
298
+ - Updated dependencies [f343dc4]
299
+ - Updated dependencies [8269e32]
300
+ - Updated dependencies [74f7339]
301
+ - Updated dependencies [a6c35a2]
302
+ - Updated dependencies [c2f1002]
303
+ - Updated dependencies [f163028]
304
+ - Updated dependencies [f07808c]
305
+ - Updated dependencies [7ffc3d3]
306
+ - Updated dependencies [88346ba]
307
+ - Updated dependencies [4631592]
308
+ - Updated dependencies [32ff033]
309
+ - Updated dependencies [5ac93d4]
310
+ - Updated dependencies [93f267f]
311
+ - Updated dependencies [0024abf]
312
+ - Updated dependencies [acbf364]
313
+ - Updated dependencies [7687f7b]
314
+ - Updated dependencies [1659072]
315
+ - Updated dependencies [abceb0d]
316
+ - Updated dependencies [0c302a7]
317
+ - Updated dependencies [6633337]
318
+ - Updated dependencies [f00d8d4]
319
+ - Updated dependencies [503be86]
320
+ - Updated dependencies [cde1975]
321
+ - Updated dependencies [0bc685a]
322
+ - Updated dependencies [11949fc]
323
+ - Updated dependencies [b098b0e]
324
+ - Updated dependencies [4d00b13]
325
+ - Updated dependencies [57bab76]
326
+ - Updated dependencies [b90086a]
327
+ - Updated dependencies [b95577a]
328
+ - Updated dependencies [83c161f]
329
+ - Updated dependencies [d8c4957]
330
+ - Updated dependencies [f24cb83]
331
+ - Updated dependencies [5dbbb92]
332
+ - Updated dependencies [69f1dfd]
333
+ - @objectstack/spec@17.0.0-rc.0
334
+ - @objectstack/service-cluster@17.0.0-rc.0
335
+
3
336
  ## 16.1.0
4
337
 
5
338
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@objectstack/service-cluster-redis",
3
- "version": "16.1.0",
3
+ "version": "17.0.0-rc.1",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Redis cluster driver for ObjectStack — implements IPubSub/ILock/IKV/ICounter against Redis using ioredis.",
6
6
  "type": "module",
@@ -15,8 +15,8 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "ioredis": "^5.11.1",
18
- "@objectstack/service-cluster": "16.1.0",
19
- "@objectstack/spec": "16.1.0"
18
+ "@objectstack/service-cluster": "17.0.0-rc.1",
19
+ "@objectstack/spec": "17.0.0-rc.1"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "^26.1.1",
@@ -38,8 +38,14 @@
38
38
  "url": "https://github.com/objectstack-ai/objectstack.git",
39
39
  "directory": "packages/services/service-cluster-redis"
40
40
  },
41
+ "files": [
42
+ "dist",
43
+ "README.md",
44
+ "CHANGELOG.md"
45
+ ],
41
46
  "scripts": {
42
47
  "build": "tsup",
43
- "test": "vitest run"
48
+ "test": "vitest run",
49
+ "typecheck": "tsc --noEmit"
44
50
  }
45
51
  }
@@ -1,22 +0,0 @@
1
-
2
- > @objectstack/service-cluster-redis@16.1.0 build /home/runner/work/objectstack/objectstack/packages/services/service-cluster-redis
3
- > tsup
4
-
5
- CLI Building entry: src/index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v8.5.1
8
- CLI Using tsup config: /home/runner/work/objectstack/objectstack/packages/services/service-cluster-redis/tsup.config.ts
9
- CLI Target: es2020
10
- CLI Cleaning output folder
11
- ESM Build start
12
- CJS Build start
13
- ESM dist/index.js 13.20 KB
14
- ESM dist/index.js.map 37.77 KB
15
- ESM ⚡️ Build success in 892ms
16
- CJS dist/index.cjs 14.57 KB
17
- CJS dist/index.cjs.map 35.25 KB
18
- CJS ⚡️ Build success in 898ms
19
- DTS Build start
20
- DTS ⚡️ Build success in 13185ms
21
- DTS dist/index.d.ts 9.99 KB
22
- DTS dist/index.d.cts 9.99 KB
package/src/client.ts DELETED
@@ -1,75 +0,0 @@
1
- // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2
-
3
- import { Redis, type RedisOptions } from 'ioredis';
4
-
5
- /**
6
- * Options accepted by {@link createRedisClient}.
7
- *
8
- * Either pass `url` (e.g. `redis://user:pass@host:6379/0`) or a full
9
- * ioredis `options` bag. The two are merged with `options` taking
10
- * precedence so callers can override individual fields parsed from the
11
- * URL.
12
- *
13
- * This factory is intended to be the single Redis-client construction
14
- * point across ObjectStack — `service-cluster-redis` uses it for the
15
- * driver, and `service-cache` will eventually share the same connection
16
- * pool via {@link CreateRedisOptions.existing}.
17
- */
18
- export interface CreateRedisOptions {
19
- /** Connection URL. Ignored when `existing` is provided. */
20
- url?: string;
21
- /** Extra ioredis options merged on top of `url`. */
22
- options?: RedisOptions;
23
- /**
24
- * Bring-your-own client. When provided, this exact instance is
25
- * returned and `url`/`options` are ignored — useful for sharing one
26
- * pool across cluster + cache.
27
- */
28
- existing?: Redis;
29
- /**
30
- * If true, the returned client is created in lazyConnect mode so the
31
- * TCP connection happens on first command rather than at construction.
32
- * Default: true (matches ObjectStack's "fail at usage, not boot" stance).
33
- */
34
- lazyConnect?: boolean;
35
- }
36
-
37
- /**
38
- * Construct (or reuse) an ioredis client with ObjectStack defaults.
39
- *
40
- * Defaults applied when `existing` is absent:
41
- * - `lazyConnect: true` — don't crash boot if Redis is briefly down
42
- * - `maxRetriesPerRequest: 3` — bound the failure window before surfacing
43
- * - `enableAutoPipelining: true` — modest throughput boost for batch workloads
44
- *
45
- * @example
46
- * const client = createRedisClient({ url: 'redis://localhost:6379' });
47
- *
48
- * @example reuse one pool across services
49
- * const shared = createRedisClient({ url });
50
- * const clusterClient = createRedisClient({ existing: shared });
51
- * const cacheClient = createRedisClient({ existing: shared });
52
- */
53
- export function createRedisClient(opts: CreateRedisOptions = {}): Redis {
54
- if (opts.existing) return opts.existing;
55
-
56
- const base: RedisOptions = {
57
- lazyConnect: opts.lazyConnect ?? true,
58
- maxRetriesPerRequest: 3,
59
- enableAutoPipelining: true,
60
- };
61
-
62
- if (opts.url) {
63
- return new Redis(opts.url, { ...base, ...opts.options });
64
- }
65
- return new Redis({ ...base, ...opts.options });
66
- }
67
-
68
- /**
69
- * Duplicate a Redis client so that pub/sub commands (which monopolize
70
- * the connection) don't block regular commands. Mirrors the standard
71
- * ioredis "two clients" pattern.
72
- */
73
- export function duplicateForPubSub(client: Redis): Redis {
74
- return client.duplicate();
75
- }
package/src/counter.ts DELETED
@@ -1,63 +0,0 @@
1
- // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2
-
3
- import type { Redis } from 'ioredis';
4
- import type { ICounter, CounterIncrOptions } from '@objectstack/spec/contracts';
5
-
6
- export interface RedisCounterOptions {
7
- client: Redis;
8
- keyPrefix?: string;
9
- }
10
-
11
- /**
12
- * Redis-backed monotonic counter using INCRBY. Each counter key lives at
13
- * `{prefix}ctr:{key}` so the same Redis instance can host multiple
14
- * tenants without collision.
15
- *
16
- * Values are stored as ASCII decimals (Redis convention). We surface
17
- * them as `bigint` to match the contract — INCRBY accepts up to a
18
- * signed 64-bit range, well beyond Number.MAX_SAFE_INTEGER.
19
- */
20
- export class RedisCounter implements ICounter {
21
- private readonly client: Redis;
22
- private readonly keyPrefix: string;
23
- private closed = false;
24
-
25
- constructor(opts: RedisCounterOptions) {
26
- this.client = opts.client;
27
- this.keyPrefix = opts.keyPrefix ?? 'os:';
28
- }
29
-
30
- async incr(key: string, opts: CounterIncrOptions = {}): Promise<bigint> {
31
- if (this.closed) throw new Error('RedisCounter is closed');
32
- const by = opts.by ?? 1;
33
- const next = await this.client.incrby(this.ctrKey(key), by);
34
- return BigInt(next);
35
- }
36
-
37
- async peek(key: string): Promise<bigint> {
38
- const raw = await this.client.get(this.ctrKey(key));
39
- if (raw === null) return 0n;
40
- try {
41
- return BigInt(raw);
42
- } catch {
43
- return 0n;
44
- }
45
- }
46
-
47
- async reset(key: string, value: bigint = 0n): Promise<void> {
48
- if (this.closed) throw new Error('RedisCounter is closed');
49
- if (value === 0n) {
50
- await this.client.del(this.ctrKey(key));
51
- return;
52
- }
53
- await this.client.set(this.ctrKey(key), value.toString());
54
- }
55
-
56
- async close(): Promise<void> {
57
- this.closed = true;
58
- }
59
-
60
- private ctrKey(key: string): string {
61
- return `${this.keyPrefix}ctr:${key}`;
62
- }
63
- }
package/src/index.ts DELETED
@@ -1,111 +0,0 @@
1
- // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2
-
3
- /**
4
- * @objectstack/service-cluster-redis
5
- *
6
- * Redis driver for `@objectstack/service-cluster`. Import this package
7
- * once at process start to register the `'redis'` driver:
8
- *
9
- * ```ts
10
- * import '@objectstack/service-cluster-redis';
11
- * import { defineCluster } from '@objectstack/service-cluster';
12
- *
13
- * const cluster = defineCluster({
14
- * driver: 'redis',
15
- * url: 'redis://localhost:6379',
16
- * nodeId: 'web-1',
17
- * });
18
- * ```
19
- *
20
- * The driver also exports raw constructors so callers who already own
21
- * an ioredis client can compose primitives by hand.
22
- */
23
-
24
- import type { Redis } from 'ioredis';
25
- import {
26
- ComposedClusterService,
27
- registerClusterDriver,
28
- type DriverFactoryConfig,
29
- } from '@objectstack/service-cluster';
30
- import { createRedisClient } from './client.js';
31
- import { RedisPubSub } from './pubsub.js';
32
- import { RedisLock } from './lock.js';
33
- import { RedisKV } from './kv.js';
34
- import { RedisCounter } from './counter.js';
35
-
36
- // Re-exports for advanced composition.
37
- export { createRedisClient, duplicateForPubSub, type CreateRedisOptions } from './client.js';
38
- export { RedisPubSub, type RedisPubSubOptions } from './pubsub.js';
39
- export { RedisLock, type RedisLockOptions } from './lock.js';
40
- export { RedisKV, VersionMismatchError, type RedisKVOptions } from './kv.js';
41
- export { RedisCounter, type RedisCounterOptions } from './counter.js';
42
-
43
- /**
44
- * Driver-specific options accepted under `driverOptions` in
45
- * `ClusterCapabilityConfig`. All are optional — supply a `client` to
46
- * share a Redis pool with other services (e.g. `service-cache`).
47
- */
48
- export interface RedisDriverOptions {
49
- /** Pre-built ioredis client. When provided, `url` is ignored. */
50
- client?: Redis;
51
- /** Key prefix applied to every Redis key (default: 'os:'). */
52
- keyPrefix?: string;
53
- /** Default lock TTL in ms. Overridden by `LockAcquireOptions.ttlMs`. */
54
- lockTtlMs?: number;
55
- /** Pub/sub subscriber error sink. */
56
- onError?: (err: unknown, channel: string) => void;
57
- }
58
-
59
- /**
60
- * Factory consumed by `defineCluster({ driver: 'redis' })`. Builds an
61
- * `IClusterService` backed by Redis. Owns the underlying ioredis client
62
- * iff it created it (i.e. when caller didn't pass `driverOptions.client`).
63
- */
64
- function redisDriverFactory(config: DriverFactoryConfig) {
65
- const driverOpts = (config.driverOptions ?? {}) as RedisDriverOptions;
66
- const ownsClient = !driverOpts.client;
67
- const client =
68
- driverOpts.client ??
69
- createRedisClient({ url: config.url });
70
-
71
- const keyPrefix = driverOpts.keyPrefix ?? 'os:';
72
- const ttlMs = config.lockTtlMs ?? driverOpts.lockTtlMs;
73
-
74
- const pubsub = new RedisPubSub({
75
- client,
76
- nodeId: config.nodeId,
77
- keyPrefix,
78
- onError: driverOpts.onError,
79
- });
80
- const lock = new RedisLock({
81
- client,
82
- keyPrefix,
83
- defaultTtlMs: ttlMs,
84
- nodeId: config.nodeId,
85
- });
86
- const kv = new RedisKV({ client, keyPrefix });
87
- const counter = new RedisCounter({ client, keyPrefix });
88
-
89
- const facade = new ComposedClusterService(
90
- config.nodeId,
91
- 'redis',
92
- pubsub,
93
- lock,
94
- kv,
95
- counter,
96
- );
97
-
98
- // Wrap close() so we also tear down the publisher client if we own it.
99
- const originalClose = facade.close.bind(facade);
100
- facade.close = async () => {
101
- await originalClose();
102
- if (ownsClient) {
103
- try { await client.quit(); } catch { /* swallow */ }
104
- }
105
- };
106
-
107
- return facade;
108
- }
109
-
110
- // Module-load registration — importing this package is enough.
111
- registerClusterDriver('redis', redisDriverFactory);