@voltro/plugin-broadcast 0.85.0 → 0.87.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/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { ChangeEvent } from '@voltro/database';
2
+ import { ConnectionPubSub } from '@voltro/kv/connection';
3
+ import { ConnectionRef } from '@voltro/kv/connection';
2
4
  import { Effect } from 'effect';
3
5
  import { Schema } from 'effect';
4
6
  import { VoltroPlugin } from '@voltro/protocol';
@@ -72,6 +74,12 @@ export declare interface BroadcastBusLogger {
72
74
  * `voltro start` WEB process rather than an api replica. */
73
75
  export declare type BroadcastChannelKind = 'changes' | 'events' | 'members' | 'presence' | 'revalidate';
74
76
 
77
+ export declare interface BroadcastConnectionSelection {
78
+ readonly role: string;
79
+ readonly kind: 'redis' | 'nats';
80
+ readonly reference?: BrokerReference;
81
+ }
82
+
75
83
  /**
76
84
  * What rides the wire on the `voltro:changes` channel. `origin` is the
77
85
  * publishing replica's id; subscribers skip their OWN origin (the writer
@@ -193,7 +201,6 @@ export declare interface BroadcastHealth {
193
201
  export declare interface BroadcastPlugin extends VoltroPlugin {
194
202
  readonly broadcast: {
195
203
  readonly provider: BroadcastProvider;
196
- readonly url: string | null;
197
204
  readonly crossReplica: boolean;
198
205
  /**
199
206
  * The namespace as DECLARED here, before the app name or env is consulted.
@@ -208,18 +215,14 @@ export declare const broadcastPlugin: (options?: BroadcastPluginOptions) => Broa
208
215
 
209
216
  export declare interface BroadcastPluginOptions {
210
217
  /** Provider name (`'redis' | 'nats' | 'memory'`) or a pre-built
211
- * `BroadcastProvider`. Default: inferred from `BROADCAST_URL` /
212
- * `BROADCAST_PROVIDER` / `REDIS_URL` env, else `'memory'`. */
218
+ * `BroadcastProvider`. Default: reference kind, provider Env or registry endpoint Env, else memory. */
213
219
  readonly provider?: BroadcastProviderName | BroadcastProvider;
214
- /** Broker URL — a broker-agnostic override (redis:// or nats://). Takes
215
- * precedence over the named-connection env. Default `BROADCAST_URL` env. */
216
- readonly url?: string;
217
- /** Named connection for the redis provider — resolves the broker URL via the
218
- * shared convention `<NAME>_REDIS_URL` → `REDIS_URL` (like cache / kv /
219
- * ratelimit). Default `'broadcast'` (→ `BROADCAST_REDIS_URL`, then
220
- * `REDIS_URL`). Point broadcast at its own server or the shared one purely
221
- * by which env var you set. */
222
- readonly connection?: string;
220
+ /** Default broker reference. Endpoints and credentials belong in app connections. */
221
+ readonly connection?: ConnectionRef<'redis' | 'nats'>;
222
+ readonly events?: ConnectionRef<'redis' | 'nats'>;
223
+ readonly members?: ConnectionRef<'redis' | 'nats'>;
224
+ readonly presence?: ConnectionRef<'redis' | 'nats'>;
225
+ readonly revalidate?: ConnectionRef<'redis' | 'nats'>;
223
226
  /**
224
227
  * Namespace for EVERY framework channel on this broker — changes, events,
225
228
  * membership and presence alike.
@@ -299,6 +302,8 @@ export declare interface BroadcastTransportEvent {
299
302
  readonly detail?: string;
300
303
  }
301
304
 
305
+ declare type BrokerReference = ConnectionRef<'redis' | 'nats'>;
306
+
302
307
  /**
303
308
  * One framework channel inside a namespace.
304
309
  *
@@ -362,63 +367,17 @@ export declare const getBroadcastPlugin: (plugins: ReadonlyArray<VoltroPlugin>)
362
367
  */
363
368
  export declare const memoryProvider: (bus?: string) => BroadcastProvider;
364
369
 
365
- declare interface NatsLike {
366
- publish: (subject: string, data: Uint8Array) => void;
367
- subscribe: (subject: string) => NatsSubscription;
368
- drain: () => Promise<void>;
369
- /** nats.js' connection events. Read for two reasons: to report a reconnect as
370
- * the hole it is, and to notice a connection that gave up. */
371
- status: () => AsyncIterable<{
372
- type: string;
373
- data?: unknown;
374
- }>;
375
- }
376
-
377
370
  export declare const natsProvider: (options: NatsProviderOptions) => BroadcastProvider;
378
371
 
379
- export declare interface NatsProviderOptions {
380
- /** `nats://host:port` (comma-separated for a cluster). Required. */
381
- readonly url: string;
382
- /** Bring your own connected NATS connection (e.g. for shared creds). */
383
- readonly connection?: NatsLike;
384
- }
385
-
386
- declare interface NatsSubscription extends AsyncIterable<{
387
- data: Uint8Array;
388
- }> {
389
- unsubscribe: () => void;
390
- }
391
-
392
- /** The slice of ioredis the provider touches — keeps the optional dep out
393
- * of the type surface. */
394
- declare interface RedisLike {
395
- publish: (channel: string, message: string) => Promise<number>;
396
- subscribe: (channel: string) => Promise<unknown>;
397
- unsubscribe: (channel: string) => Promise<unknown>;
398
- on(event: 'message', listener: (channel: string, message: string) => void): void;
399
- /** ioredis' connection lifecycle. The subscriber re-subscribes its channels
400
- * itself on `ready`; what it does NOT do is tell anyone that the messages
401
- * sent while it was away are gone. That is what these are read for. */
402
- on(event: 'ready' | 'reconnecting' | 'end' | 'close', listener: () => void): void;
403
- /** `error` is REQUIRED, not optional decoration: an `EventEmitter` with no
404
- * `error` listener turns the event into an uncaught exception. See the
405
- * registration below. */
406
- on(event: 'error', listener: (err: unknown) => void): void;
407
- off(event: 'message', listener: (channel: string, message: string) => void): void;
408
- off(event: 'ready' | 'reconnecting' | 'end' | 'close', listener: () => void): void;
409
- duplicate: () => RedisLike;
410
- quit: () => Promise<unknown>;
372
+ export declare interface NatsProviderOptions extends RedisProviderOptions {
411
373
  }
412
374
 
375
+ /** Both adapters borrow the same consumer contract; neither owns a broker. */
413
376
  export declare const redisProvider: (options: RedisProviderOptions) => BroadcastProvider;
414
377
 
415
378
  export declare interface RedisProviderOptions {
416
- /** `redis://[:pass@]host:port[/db]`. Required. */
417
- readonly url: string;
418
- /** Bring your own ioredis client (publisher). A `subscriber` is
419
- * `client.duplicate()`d internally — a RESP connection in subscribe
420
- * mode can't issue normal commands. */
421
- readonly client?: RedisLike;
379
+ /** Acquire a consumer from the app's ConnectionRegistry, never a raw socket. */
380
+ readonly pubsub: Effect.Effect<ConnectionPubSub, unknown>;
422
381
  }
423
382
 
424
383
  /* Excluded from this release type: resetMemoryBus */
@@ -435,31 +394,18 @@ export declare interface ResolveBroadcastNamespaceInput {
435
394
  }
436
395
 
437
396
  export declare interface ResolveBroadcastOptions {
438
- /** Explicit provider name or a pre-built `BroadcastProvider`. */
439
397
  readonly provider?: BroadcastProviderName | BroadcastProvider;
440
- /** Broker URL — a broker-agnostic override (redis:// or nats://). Takes
441
- * precedence over the named-connection env. Default `BROADCAST_URL` env. */
442
- readonly url?: string;
443
- /** Named connection for the redis provider. The broker URL resolves via the
444
- * shared convention `<NAME>_REDIS_URL` → `REDIS_URL` (like cache / kv /
445
- * ratelimit), so a deployment points broadcast at the same server or its own
446
- * purely by env. Default `'broadcast'` (→ `BROADCAST_REDIS_URL`). */
447
- readonly connection?: string;
398
+ readonly connection?: BrokerReference;
399
+ readonly events?: BrokerReference;
400
+ readonly members?: BrokerReference;
401
+ readonly presence?: BrokerReference;
402
+ readonly revalidate?: BrokerReference;
448
403
  }
449
404
 
450
- /**
451
- * Resolve the bus backend. Order: an object provider is used verbatim; a
452
- * named provider builds from `url`/env; absent → `BROADCAST_PROVIDER` env,
453
- * else inferred from a `redis://` / `nats://` URL, else `memory`.
454
- *
455
- * Returns the provider plus the URL it resolved (for the boot banner) and
456
- * whether the choice is a real cross-replica bus or the single-process
457
- * memory fallback.
458
- */
459
- export declare const resolveBroadcastProvider: (options: ResolveBroadcastOptions, env: NodeJS.ProcessEnv) => {
405
+ export declare const resolveBroadcastProvider: (options: ResolveBroadcastOptions, environment: NodeJS.ProcessEnv, pubsub?: (role: string) => Effect.Effect<ConnectionPubSub, unknown>) => {
460
406
  provider: BroadcastProvider;
461
- url: string | null;
462
407
  crossReplica: boolean;
408
+ selections: ReadonlyArray<BroadcastConnectionSelection>;
463
409
  };
464
410
 
465
411
  /** Retry cadence for a subscribe that could not land: 500ms doubling to a 10s