ioredis-toolkit 0.0.10 → 0.0.12

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.
Files changed (256) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/LICENSE +1 -1
  3. package/README.md +68 -1613
  4. package/dist/cache/cache.d.ts +30 -0
  5. package/dist/cache/cache.d.ts.map +1 -0
  6. package/dist/cache/cache.js +59 -0
  7. package/dist/cache/cache.js.map +1 -0
  8. package/dist/cache/config.d.ts +12 -0
  9. package/dist/cache/config.d.ts.map +1 -0
  10. package/dist/cache/config.js +13 -0
  11. package/dist/cache/config.js.map +1 -0
  12. package/dist/cache/types.d.ts +32 -0
  13. package/dist/cache/types.d.ts.map +1 -0
  14. package/dist/cache/types.js +5 -0
  15. package/dist/cache/types.js.map +1 -0
  16. package/dist/index.d.ts +43 -51
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +32 -44
  19. package/dist/index.js.map +1 -0
  20. package/dist/lock/config.d.ts +12 -0
  21. package/dist/lock/config.d.ts.map +1 -0
  22. package/dist/lock/config.js +8 -0
  23. package/dist/lock/config.js.map +1 -0
  24. package/dist/lock/lock.d.ts +20 -0
  25. package/dist/lock/lock.d.ts.map +1 -0
  26. package/dist/lock/lock.js +44 -0
  27. package/dist/lock/lock.js.map +1 -0
  28. package/dist/lock/types.d.ts +19 -0
  29. package/dist/lock/types.d.ts.map +1 -0
  30. package/dist/lock/types.js +2 -0
  31. package/dist/lock/types.js.map +1 -0
  32. package/dist/modules-config.d.ts +3 -0
  33. package/dist/modules-config.d.ts.map +1 -0
  34. package/dist/modules-config.js +2 -0
  35. package/dist/modules-config.js.map +1 -0
  36. package/dist/pubsub/config.d.ts +11 -0
  37. package/dist/pubsub/config.d.ts.map +1 -0
  38. package/dist/pubsub/config.js +6 -0
  39. package/dist/pubsub/config.js.map +1 -0
  40. package/dist/pubsub/pubsub.d.ts +20 -0
  41. package/dist/pubsub/pubsub.d.ts.map +1 -0
  42. package/dist/pubsub/pubsub.js +54 -0
  43. package/dist/pubsub/pubsub.js.map +1 -0
  44. package/dist/pubsub/types.d.ts +24 -0
  45. package/dist/pubsub/types.d.ts.map +1 -0
  46. package/dist/pubsub/types.js +2 -0
  47. package/dist/pubsub/types.js.map +1 -0
  48. package/dist/rate-limit/config.d.ts +12 -0
  49. package/dist/rate-limit/config.d.ts.map +1 -0
  50. package/dist/rate-limit/config.js +6 -0
  51. package/dist/rate-limit/config.js.map +1 -0
  52. package/dist/rate-limit/rate-limiter.d.ts +18 -0
  53. package/dist/rate-limit/rate-limiter.d.ts.map +1 -0
  54. package/dist/rate-limit/rate-limiter.js +37 -0
  55. package/dist/rate-limit/rate-limiter.js.map +1 -0
  56. package/dist/rate-limit/types.d.ts +27 -0
  57. package/dist/rate-limit/types.d.ts.map +1 -0
  58. package/dist/rate-limit/types.js +2 -0
  59. package/dist/rate-limit/types.js.map +1 -0
  60. package/dist/redis/client-facade.d.ts +77 -0
  61. package/dist/redis/client-facade.d.ts.map +1 -0
  62. package/dist/redis/client-facade.js +102 -0
  63. package/dist/redis/client-facade.js.map +1 -0
  64. package/dist/redis/client.d.ts +10 -0
  65. package/dist/redis/client.d.ts.map +1 -0
  66. package/dist/redis/client.js +29 -0
  67. package/dist/redis/client.js.map +1 -0
  68. package/dist/redis/cluster.d.ts +7 -0
  69. package/dist/redis/cluster.d.ts.map +1 -0
  70. package/dist/redis/cluster.js +47 -0
  71. package/dist/redis/cluster.js.map +1 -0
  72. package/dist/redis/config.d.ts +39 -0
  73. package/dist/redis/config.d.ts.map +1 -0
  74. package/dist/redis/config.js +52 -0
  75. package/dist/redis/config.js.map +1 -0
  76. package/dist/redis/errors.d.ts +5 -0
  77. package/dist/redis/errors.d.ts.map +1 -0
  78. package/dist/redis/errors.js +5 -0
  79. package/dist/redis/errors.js.map +1 -0
  80. package/dist/redis/types.d.ts +135 -0
  81. package/dist/redis/types.d.ts.map +1 -0
  82. package/dist/redis/types.js +2 -0
  83. package/dist/redis/types.js.map +1 -0
  84. package/dist/redis/wrapper.d.ts +88 -0
  85. package/dist/redis/wrapper.d.ts.map +1 -0
  86. package/dist/redis/wrapper.js +206 -0
  87. package/dist/redis/wrapper.js.map +1 -0
  88. package/dist/session/config.d.ts +47 -0
  89. package/dist/session/config.d.ts.map +1 -0
  90. package/dist/session/config.js +101 -0
  91. package/dist/session/config.js.map +1 -0
  92. package/dist/session/cookie.d.ts +16 -0
  93. package/dist/session/cookie.d.ts.map +1 -0
  94. package/dist/session/cookie.js +28 -0
  95. package/dist/session/cookie.js.map +1 -0
  96. package/dist/session/errors.d.ts +56 -0
  97. package/dist/session/errors.d.ts.map +1 -0
  98. package/dist/session/errors.js +58 -0
  99. package/dist/session/errors.js.map +1 -0
  100. package/dist/session/factory.d.ts +21 -0
  101. package/dist/session/factory.d.ts.map +1 -0
  102. package/dist/session/factory.js +30 -0
  103. package/dist/session/factory.js.map +1 -0
  104. package/dist/session/health.d.ts +12 -0
  105. package/dist/session/health.d.ts.map +1 -0
  106. package/dist/session/health.js +23 -0
  107. package/dist/session/health.js.map +1 -0
  108. package/dist/session/keys.d.ts +23 -0
  109. package/dist/session/keys.d.ts.map +1 -0
  110. package/dist/session/keys.js +27 -0
  111. package/dist/session/keys.js.map +1 -0
  112. package/dist/session/manager.d.ts +34 -0
  113. package/dist/session/manager.d.ts.map +1 -0
  114. package/dist/session/manager.js +31 -0
  115. package/dist/session/manager.js.map +1 -0
  116. package/dist/session/metrics.d.ts +11 -0
  117. package/dist/session/metrics.d.ts.map +1 -0
  118. package/dist/session/metrics.js +10 -0
  119. package/dist/session/metrics.js.map +1 -0
  120. package/dist/session/repository.d.ts +49 -0
  121. package/dist/session/repository.d.ts.map +1 -0
  122. package/dist/session/repository.js +203 -0
  123. package/dist/session/repository.js.map +1 -0
  124. package/dist/session/revocation.d.ts +22 -0
  125. package/dist/session/revocation.d.ts.map +1 -0
  126. package/dist/session/revocation.js +41 -0
  127. package/dist/session/revocation.js.map +1 -0
  128. package/dist/session/script-sources.d.ts +11 -0
  129. package/dist/session/script-sources.d.ts.map +1 -0
  130. package/dist/session/script-sources.js +140 -0
  131. package/dist/session/script-sources.js.map +1 -0
  132. package/dist/session/scripts.d.ts +15 -0
  133. package/dist/session/scripts.d.ts.map +1 -0
  134. package/dist/session/scripts.js +41 -0
  135. package/dist/session/scripts.js.map +1 -0
  136. package/dist/session/serializer.d.ts +12 -0
  137. package/dist/session/serializer.d.ts.map +1 -0
  138. package/dist/session/serializer.js +77 -0
  139. package/dist/session/serializer.js.map +1 -0
  140. package/dist/session/service.d.ts +48 -0
  141. package/dist/session/service.d.ts.map +1 -0
  142. package/dist/session/service.js +235 -0
  143. package/dist/session/service.js.map +1 -0
  144. package/dist/session/token.d.ts +16 -0
  145. package/dist/session/token.d.ts.map +1 -0
  146. package/dist/session/token.js +32 -0
  147. package/dist/session/token.js.map +1 -0
  148. package/dist/session/types.d.ts +134 -0
  149. package/dist/session/types.d.ts.map +1 -0
  150. package/dist/session/types.js +2 -0
  151. package/dist/session/types.js.map +1 -0
  152. package/dist/streams/config.d.ts +12 -0
  153. package/dist/streams/config.d.ts.map +1 -0
  154. package/dist/streams/config.js +6 -0
  155. package/dist/streams/config.js.map +1 -0
  156. package/dist/streams/streams.d.ts +24 -0
  157. package/dist/streams/streams.d.ts.map +1 -0
  158. package/dist/streams/streams.js +55 -0
  159. package/dist/streams/streams.js.map +1 -0
  160. package/dist/streams/types.d.ts +32 -0
  161. package/dist/streams/types.d.ts.map +1 -0
  162. package/dist/streams/types.js +2 -0
  163. package/dist/streams/types.js.map +1 -0
  164. package/docs/ACCEPTANCE-REPORT.md +70 -0
  165. package/docs/ARCHITECTURE.md +61 -0
  166. package/docs/CAPACITY.md +33 -0
  167. package/docs/DEPLOYMENT.md +22 -0
  168. package/docs/README-API.md +15 -0
  169. package/docs/STATE-MACHINE.md +38 -0
  170. package/docs/TESTING.md +37 -0
  171. package/docs/THREAT-MODEL.md +23 -0
  172. package/docs/TYPE-SAFETY.md +34 -0
  173. package/docs/modules/cache/README.md +7 -0
  174. package/docs/modules/cache/usage.md +156 -0
  175. package/docs/modules/lock/README.md +7 -0
  176. package/docs/modules/lock/usage.md +105 -0
  177. package/docs/modules/pubsub/README.md +7 -0
  178. package/docs/modules/pubsub/usage.md +106 -0
  179. package/docs/modules/rate-limit/README.md +7 -0
  180. package/docs/modules/rate-limit/usage.md +100 -0
  181. package/docs/modules/sessions/README.md +7 -0
  182. package/docs/modules/sessions/usage.md +262 -0
  183. package/docs/modules/streams/README.md +7 -0
  184. package/docs/modules/streams/usage.md +141 -0
  185. package/package.json +50 -60
  186. package/dist/cache.d.ts +0 -797
  187. package/dist/cache.js +0 -1115
  188. package/dist/client.d.ts +0 -287
  189. package/dist/client.js +0 -1113
  190. package/dist/cluster-slot.d.ts +0 -4
  191. package/dist/cluster-slot.js +0 -31
  192. package/dist/cluster.d.ts +0 -79
  193. package/dist/cluster.js +0 -156
  194. package/dist/errors.d.ts +0 -30
  195. package/dist/errors.js +0 -63
  196. package/dist/health.d.ts +0 -180
  197. package/dist/health.js +0 -239
  198. package/dist/lock.d.ts +0 -233
  199. package/dist/lock.js +0 -440
  200. package/dist/logger.d.ts +0 -12
  201. package/dist/logger.js +0 -40
  202. package/dist/pubsub.d.ts +0 -423
  203. package/dist/pubsub.js +0 -537
  204. package/dist/ratelimiter.d.ts +0 -441
  205. package/dist/ratelimiter.js +0 -539
  206. package/dist/session/index.d.ts +0 -23
  207. package/dist/session/index.js +0 -16
  208. package/dist/session/revocation-store.d.ts +0 -176
  209. package/dist/session/revocation-store.js +0 -318
  210. package/dist/session/scripts/cleanup-index.lua +0 -21
  211. package/dist/session/scripts/conditional-update-encrypted.lua +0 -60
  212. package/dist/session/scripts/conditional-update.lua +0 -63
  213. package/dist/session/scripts/create.lua +0 -83
  214. package/dist/session/scripts/delete-by-user.lua +0 -29
  215. package/dist/session/scripts/delete.lua +0 -15
  216. package/dist/session/scripts/enforce-limit.lua +0 -38
  217. package/dist/session/scripts/revoke.lua +0 -61
  218. package/dist/session/scripts/rotate-encrypted.lua +0 -149
  219. package/dist/session/scripts/rotate.lua +0 -167
  220. package/dist/session/scripts/touch-encrypted.lua +0 -89
  221. package/dist/session/scripts/touch.lua +0 -72
  222. package/dist/session/scripts/validate.lua +0 -90
  223. package/dist/session/session-circuit-breaker.d.ts +0 -42
  224. package/dist/session/session-circuit-breaker.js +0 -129
  225. package/dist/session/session-config.d.ts +0 -355
  226. package/dist/session/session-config.js +0 -171
  227. package/dist/session/session-cookie.d.ts +0 -72
  228. package/dist/session/session-cookie.js +0 -101
  229. package/dist/session/session-encryption.d.ts +0 -87
  230. package/dist/session/session-encryption.js +0 -139
  231. package/dist/session/session-errors.d.ts +0 -85
  232. package/dist/session/session-errors.js +0 -145
  233. package/dist/session/session-health.d.ts +0 -38
  234. package/dist/session/session-health.js +0 -60
  235. package/dist/session/session-keys.d.ts +0 -64
  236. package/dist/session/session-keys.js +0 -128
  237. package/dist/session/session-manager.d.ts +0 -73
  238. package/dist/session/session-manager.js +0 -94
  239. package/dist/session/session-metrics.d.ts +0 -41
  240. package/dist/session/session-metrics.js +0 -135
  241. package/dist/session/session-repository.d.ts +0 -184
  242. package/dist/session/session-repository.js +0 -763
  243. package/dist/session/session-scripts.d.ts +0 -36
  244. package/dist/session/session-scripts.js +0 -130
  245. package/dist/session/session-serializer.d.ts +0 -42
  246. package/dist/session/session-serializer.js +0 -267
  247. package/dist/session/session-service.d.ts +0 -123
  248. package/dist/session/session-service.js +0 -670
  249. package/dist/session/session-token.d.ts +0 -38
  250. package/dist/session/session-token.js +0 -86
  251. package/dist/session/session-types.d.ts +0 -281
  252. package/dist/session/session-types.js +0 -16
  253. package/dist/types.d.ts +0 -924
  254. package/dist/types.js +0 -151
  255. package/dist/utils/deepmerge.d.ts +0 -9
  256. package/dist/utils/deepmerge.js +0 -61
package/dist/pubsub.d.ts DELETED
@@ -1,423 +0,0 @@
1
- import { RedisClientWrapper } from './client.js';
2
- import { EventEmitter } from 'node:events';
3
- import { RedisConfig } from './types.js';
4
- import { LoggerLike } from './logger.js';
5
- /**
6
- * Redis Pub/Sub with a dedicated publisher and subscriber connection.
7
- *
8
- * **Description:**
9
- * Provides a higher-level interface over native Redis Pub/Sub with the following features:
10
- * - Dedicated publisher connection (configured at construction)
11
- * - Dedicated subscriber connection (opened via {@link connectSubscriber})
12
- * - JSON serialization on publish, auto-parsing on delivery
13
- * - Pattern subscription support (`psubscribe`, `punsubscribe`)
14
- * - Extends Node.js `EventEmitter` for event-based handling
15
- * - Emits `'error'` events on subscriber failures
16
- *
17
- * **Type Parameters:**
18
- * - `T` - The type of message payload. When publishing non-string values, they are
19
- * JSON-serialized. When subscribing, messages are auto-parsed from JSON when possible.
20
- *
21
- * **Mode Support:**
22
- * - Standalone, Sentinel, and Cluster modes are all supported.
23
- * - The subscriber connection is created per the configured mode.
24
- *
25
- * **Example:**
26
- * ```ts
27
- * const pubsub = new PubSub(client);
28
- * await pubsub.connectSubscriber({ mode: 'standalone', host: 'localhost', port: 6379 });
29
- *
30
- * // Subscribe to a channel
31
- * await pubsub.subscribe('orders:created', (message) => {
32
- * console.log(message); // { id: 1 } - JSON-parsed
33
- * });
34
- *
35
- * // Publish a message
36
- * const receivers = await pubsub.publish('orders:created', { id: 1 });
37
- * // receivers === number of subscribers that received the message
38
- *
39
- * // Pattern subscription
40
- * await pubsub.psubscribe('orders:*', ({ channel, message }) => {
41
- * console.log(channel, message);
42
- * });
43
- * ```
44
- *
45
- * **Event Emissions:**
46
- * - `message`: Emitted when a message is received on a subscribed channel.
47
- * Payload: `{ channel: string, message: string }`
48
- * - `pmessage`: Emitted when a pattern message is received.
49
- * Payload: `{ pattern: string, channel: string, message: string }`
50
- * - `error`: Emitted on subscriber errors.
51
- * Payload: `Error`
52
- */
53
- export declare class PubSub extends EventEmitter {
54
- private publisher;
55
- private subscriber;
56
- private logger;
57
- private subscriptions;
58
- private patternSubscriptions;
59
- /**
60
- * Creates a pub/sub instance. Publishing works immediately; subscribing
61
- * requires calling {@link connectSubscriber} first.
62
- *
63
- * @param publisher - A {@link RedisClientWrapper} used for publishing.
64
- * @param logger - Optional pino-compatible logger; defaults to `console`.
65
- *
66
- * @example
67
- * ```ts
68
- * const pubsub = new PubSub(client);
69
- * ```
70
- */
71
- /**
72
- * Creates a pub/sub instance. Publishing works immediately; subscribing
73
- * requires calling {@link connectSubscriber} first.
74
- *
75
- * @param publisher - A {@link RedisClientWrapper} used for publishing.
76
- * @param logger - Optional pino-compatible logger; defaults to `console`.
77
- *
78
- * @example
79
- * ```ts
80
- * const pubsub = new PubSub(client);
81
- * ```
82
- */
83
- constructor(publisher: RedisClientWrapper, logger?: LoggerLike);
84
- /**
85
- * Opens a dedicated subscriber connection.
86
- *
87
- * Idempotent: a second call is a no-op while a subscriber is connected.
88
- * Subscriber errors are emitted as `'error'` events on the instance.
89
- *
90
- * @param config - Redis config for the subscriber connection (any mode).
91
- *
92
- * @example
93
- * ```ts
94
- * await pubsub.connectSubscriber({ mode: 'standalone', host: 'localhost', port: 6379 });
95
- * ```
96
- */
97
- /**
98
- * Opens a dedicated subscriber connection.
99
- *
100
- * **Behavior:**
101
- * - Idempotent: a second call is a no-op while a subscriber is connected.
102
- * - Subscriber errors are emitted as `'error'` events on the instance.
103
- *
104
- * **Parameters:**
105
- * - `config` - Redis config for the subscriber connection (any mode: standalone, sentinel, or cluster).
106
- *
107
- * **Example:**
108
- * ```ts
109
- * // Connect with standalone configuration
110
- * await pubsub.connectSubscriber({ mode: 'standalone', host: 'localhost', port: 6379 });
111
- *
112
- * // Connect with cluster configuration
113
- * await pubsub.connectSubscriber({
114
- * mode: 'cluster',
115
- * clusterNodes: [{ host: 'redis1', port: 7000 }, { host: 'redis2', port: 7001 }],
116
- * });
117
- * ```
118
- *
119
- * @returns `Promise<void>` that resolves when the subscriber connection is established.
120
- */
121
- connectSubscriber(config: RedisConfig): Promise<void>;
122
- /**
123
- * Sets up event listeners on the subscriber connection.
124
- *
125
- * **Behavior:**
126
- * - Listens for `message` events and dispatches to {@link handleMessage}.
127
- * - Listens for `pmessage` events (pattern subscriptions) and dispatches to {@link handlePatternMessage}.
128
- * - Listens for `error` events and emits them on the instance.
129
- *
130
- * @internal
131
- */
132
- private setupSubscriber;
133
- /**
134
- * Handles a standard message event from the subscriber.
135
- *
136
- * **Behavior:**
137
- * - Parses the message payload as JSON when possible.
138
- * - Invokes all registered handlers for the channel.
139
- * - Catches and logs handler errors without crashing.
140
- *
141
- * **Parameters:**
142
- * - `channel` - The Redis channel name.
143
- * - `message` - The raw message string from Redis (JSON-encoded).
144
- *
145
- * @internal
146
- */
147
- private handleMessage;
148
- /**
149
- * Handles a pattern message event from the subscriber.
150
- *
151
- * **Behavior:**
152
- * - Parses the message payload as JSON when possible.
153
- * - Invokes all registered handlers for the pattern.
154
- * - Each handler receives an object with `channel` and `message` properties.
155
- * - Catches and logs handler errors without crashing.
156
- *
157
- * **Parameters:**
158
- * - `pattern` - The pattern that matched.
159
- * - `channel` - The specific channel that was matched.
160
- * - `message` - The raw message string from Redis (JSON-encoded).
161
- *
162
- * @internal
163
- */
164
- private handlePatternMessage;
165
- /**
166
- * Publishes a message to a channel.
167
- *
168
- * Non-string values are JSON-serialized.
169
- *
170
- * @param channel - The channel name.
171
- * @param message - The message payload (string or any JSON-serializable value).
172
- * @returns The number of subscribers that received the message.
173
- *
174
- * @example
175
- * ```ts
176
- * const receivers = await pubsub.publish('orders:created', { id: 1, total: 99 });
177
- * ```
178
- */
179
- /**
180
- * Publishes a message to a channel.
181
- *
182
- * **Behavior:**
183
- * - Non-string values are JSON-serialized automatically.
184
- * - The raw message is published to the Redis channel.
185
- * - Returns the number of subscribers that received the message.
186
- *
187
- * **Type Parameters:**
188
- * - `T` - The type of the message payload. Non-string values are JSON-serialized.
189
- *
190
- * **Returns:**
191
- * - The number of subscribers that received the message.
192
- *
193
- * **Example:**
194
- * ```ts
195
- * const receivers = await pubsub.publish('orders:created', { id: 1, total: 99 });
196
- * // receivers === number of subscribed clients
197
- * ```
198
- *
199
- * **Parameters:**
200
- * - `channel` - The channel name.
201
- * - `message` - The message payload (string or any JSON-serializable value).
202
- *
203
- * @returns The number of subscribers that received the message.
204
- */
205
- publish<T = any>(channel: string, message: T): Promise<number>;
206
- /**
207
- * Subscribes a handler to a channel.
208
- *
209
- * Multiple handlers per channel are supported; the channel is subscribed on
210
- * Redis only once. Delivered payloads are JSON-parsed when possible.
211
- *
212
- * @param channel - The channel name.
213
- * @param handler - Callback receiving the (parsed) message.
214
- * @throws `Error` if the subscriber connection is not open.
215
- *
216
- * @example
217
- * ```ts
218
- * await pubsub.subscribe('orders:created', (order) => {
219
- * console.log(order.id);
220
- * });
221
- * ```
222
- */
223
- /**
224
- * Subscribes a handler to a channel.
225
- *
226
- * **Behavior:**
227
- * - Multiple handlers per channel are supported; the channel is subscribed on
228
- * Redis only once.
229
- * - Delivered payloads are JSON-parsed when possible.
230
- * - Throws an error if the subscriber connection is not open.
231
- *
232
- * **Type Parameters:**
233
- * - `T` - The type of the message data received in the handler.
234
- *
235
- * **Returns:**
236
- * - `Promise<void>` that resolves when the subscription is established.
237
- *
238
- * **Example:**
239
- * ```ts
240
- * await pubsub.subscribe('orders:created', (order) => {
241
- * console.log(order.id);
242
- * });
243
- * ```
244
- *
245
- * **Parameters:**
246
- * - `channel` - The channel name.
247
- * - `handler` - Callback receiving the (parsed) message.
248
- *
249
- * @throws `Error` if the subscriber connection is not open.
250
- */
251
- subscribe<T = any>(channel: string, handler: (data: T) => void): Promise<void>;
252
- /**
253
- * Removes a handler (or all handlers) from a channel.
254
- *
255
- * The Redis subscription is dropped once the last handler for the channel is
256
- * removed. Without a handler, the whole channel is unsubscribed.
257
- *
258
- * @param channel - The channel name.
259
- * @param handler - Optional specific handler to remove; when omitted all
260
- * handlers for the channel are removed.
261
- *
262
- * @example
263
- * ```ts
264
- * await pubsub.unsubscribe('orders:created', myHandler);
265
- * await pubsub.unsubscribe('orders:created'); // remove everything
266
- * ```
267
- */
268
- /**
269
- * Removes a handler (or all handlers) from a channel.
270
- *
271
- * **Behavior:**
272
- * - The Redis subscription is dropped once the last handler for the channel is
273
- * removed.
274
- * - Without a handler, the whole channel is unsubscribed.
275
- *
276
- * **Returns:**
277
- * - `Promise<void>` that resolves when the unsubscription is complete.
278
- *
279
- * **Example:**
280
- * ```ts
281
- * await pubsub.unsubscribe('orders:created', myHandler);
282
- * await pubsub.unsubscribe('orders:created'); // remove everything
283
- * ```
284
- *
285
- * **Parameters:**
286
- * - `channel` - The channel name.
287
- * - `handler` - Optional specific handler to remove; when omitted all
288
- * handlers for the channel are removed.
289
- */
290
- unsubscribe<T = any>(channel: string, handler?: (data: T) => void): Promise<void>;
291
- /**
292
- * Subscribes a handler to all channels matching a glob pattern.
293
- *
294
- * Pattern handlers receive `{ channel, message }` (message JSON-parsed).
295
- *
296
- * @param pattern - Glob pattern, e.g. `'orders:*'`.
297
- * @param handler - Callback receiving `{ channel, message }`.
298
- * @throws `Error` if the subscriber connection is not open.
299
- *
300
- * @example
301
- * ```ts
302
- * await pubsub.psubscribe('orders:*', ({ channel, message }) => {
303
- * console.log(channel, message);
304
- * });
305
- * ```
306
- */
307
- /**
308
- * Subscribes a handler to all channels matching a glob pattern.
309
- *
310
- * **Behavior:**
311
- * - Pattern handlers receive `{ channel, message }` (message JSON-parsed).
312
- * - The Redis subscription is set up once per pattern.
313
- *
314
- * **Type Parameters:**
315
- * - `T` - The type of the message data received in the handler.
316
- *
317
- * **Returns:**
318
- * - `Promise<void>` that resolves when the pattern subscription is established.
319
- *
320
- * **Example:**
321
- * ```ts
322
- * await pubsub.psubscribe('orders:*', ({ channel, message }) => {
323
- * console.log(channel, message);
324
- * });
325
- * ```
326
- *
327
- * **Parameters:**
328
- * - `pattern` - Glob pattern, e.g. `'orders:*'`.
329
- * - `handler` - Callback receiving `{ channel, message }`.
330
- *
331
- * @throws `Error` if the subscriber connection is not open.
332
- */
333
- psubscribe<T = any>(pattern: string, handler: (data: {
334
- channel: string;
335
- message: T;
336
- }) => void): Promise<void>;
337
- /**
338
- * Removes a handler (or all handlers) from a pattern subscription.
339
- *
340
- * @param pattern - The glob pattern.
341
- * @param handler - Optional specific handler to remove; when omitted all
342
- * handlers for the pattern are removed.
343
- *
344
- * @example
345
- * ```ts
346
- * await pubsub.punsubscribe('orders:*', myHandler);
347
- * await pubsub.punsubscribe('orders:*');
348
- * ```
349
- */
350
- /**
351
- * Removes a handler (or all handlers) from a pattern subscription.
352
- *
353
- * **Returns:**
354
- * - `Promise<void>` that resolves when the punsubscription is complete.
355
- *
356
- * **Example:**
357
- * ```ts
358
- * await pubsub.punsubscribe('orders:*', myHandler);
359
- * await pubsub.punsubscribe('orders:*');
360
- * ```
361
- *
362
- * **Parameters:**
363
- * - `pattern` - The glob pattern.
364
- * - `handler` - Optional specific handler to remove; when omitted all
365
- * handlers for the pattern are removed.
366
- */
367
- punsubscribe(pattern: string, handler?: (data: any) => void): Promise<void>;
368
- /**
369
- * Closes the subscriber connection and clears all subscriptions.
370
- *
371
- * The publisher client is not closed (it is owned by the caller).
372
- *
373
- * @example
374
- * ```ts
375
- * await pubsub.close();
376
- * ```
377
- */
378
- /**
379
- * Closes the subscriber connection and clears all subscriptions.
380
- *
381
- * **Behavior:**
382
- * - The publisher client is not closed (it is owned by the caller).
383
- * - All subscriptions are cleared from memory.
384
- *
385
- * **Example:**
386
- * ```ts
387
- * await pubsub.close();
388
- * ```
389
- *
390
- * @returns `Promise<void>` that resolves when the subscriber is closed.
391
- */
392
- close(): Promise<void>;
393
- /**
394
- * Returns subscription statistics.
395
- *
396
- * @returns `{ subscriptions, patternSubscriptions, connected }`.
397
- *
398
- * @example
399
- * ```ts
400
- * const stats = pubsub.getStats();
401
- * // { subscriptions: 2, patternSubscriptions: 1, connected: true }
402
- * ```
403
- */
404
- /**
405
- * Returns subscription statistics.
406
- *
407
- * **Returns:**
408
- * - A {@link PubSubStats} object with the current subscription state.
409
- *
410
- * **Example:**
411
- * ```ts
412
- * const stats = pubsub.getStats();
413
- * // { subscriptions: 2, patternSubscriptions: 1, connected: true }
414
- * ```
415
- *
416
- * @returns `{ subscriptions, patternSubscriptions, connected }`.
417
- */
418
- getStats(): {
419
- subscriptions: number;
420
- patternSubscriptions: number;
421
- connected: boolean;
422
- };
423
- }