graphile-realtime-subscriptions 0.2.0 → 0.4.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/types.d.ts CHANGED
@@ -1,9 +1,146 @@
1
1
  /**
2
2
  * Configuration options for the Realtime Subscriptions Plugin.
3
- *
4
- * Phase 3a supports single-record and full-collection subscription modes
5
- * with no additional configuration required. Future phases will add
6
- * options for poll intervals, batch sizes, and throttling.
7
3
  */
8
4
  export interface RealtimeSubscriptionsPluginOptions {
5
+ /**
6
+ * Maximum number of events per table per second before switching to
7
+ * overflow (INVALIDATE) mode. When exceeded, the subscription sends
8
+ * a single { event: 'INVALIDATE', overflow: true } instead of
9
+ * individual row events, signaling the client to refetch.
10
+ *
11
+ * Default: 50
12
+ */
13
+ overflowThreshold?: number;
14
+ }
15
+ /**
16
+ * A minimal PostgreSQL client interface used by CursorTracker.
17
+ * Compatible with node-postgres (pg) Client or PoolClient.
18
+ */
19
+ export interface PgClient {
20
+ query<R = Record<string, unknown>>(text: string, values?: unknown[]): Promise<{
21
+ rows: R[];
22
+ }>;
23
+ }
24
+ /**
25
+ * Callback that provides a PgClient for executing queries.
26
+ * The client is released after the callback returns.
27
+ */
28
+ export type WithPgClient = <T>(callback: (client: PgClient) => Promise<T>) => Promise<T>;
29
+ /**
30
+ * A single entry from drain_changes(), representing a change_log row
31
+ * matched against subscriber tables.
32
+ */
33
+ export interface ChangeLogEntry {
34
+ id: string;
35
+ occurred_at: string;
36
+ source_schema: string;
37
+ source_table: string;
38
+ operation: string;
39
+ payload_after: Record<string, unknown> | null;
40
+ payload_before: Record<string, unknown> | null;
41
+ payload_diff: Record<string, unknown> | null;
42
+ subscriber_ids: string[];
43
+ }
44
+ /**
45
+ * Configuration for the CursorTracker background poller.
46
+ */
47
+ export interface CursorTrackerOptions {
48
+ /**
49
+ * Unique identifier for this listener node.
50
+ * Should be stable across restarts if you want cursor continuity.
51
+ * If not provided, a random ID is generated (ephemeral mode).
52
+ */
53
+ nodeId?: string;
54
+ /**
55
+ * The realtime_public schema name where drain_changes(),
56
+ * touch_listener(), and cleanup_ephemeral() live.
57
+ *
58
+ * Default: 'realtime_public'
59
+ */
60
+ schema?: string;
61
+ /**
62
+ * How often to poll drain_changes() for new events (milliseconds).
63
+ *
64
+ * Default: 5000 (5 seconds)
65
+ */
66
+ pollIntervalMs?: number;
67
+ /**
68
+ * How often to send a heartbeat via touch_listener() (milliseconds).
69
+ *
70
+ * Default: 30000 (30 seconds)
71
+ */
72
+ heartbeatIntervalMs?: number;
73
+ /**
74
+ * Maximum number of change_log rows to fetch per drain_changes() call.
75
+ *
76
+ * Default: 500
77
+ */
78
+ batchLimit?: number;
79
+ /**
80
+ * Function to acquire a PgClient for executing queries.
81
+ * The cursor tracker calls this for every poll and heartbeat cycle.
82
+ */
83
+ withPgClient: WithPgClient;
84
+ /**
85
+ * Called when drain_changes() returns new change_log entries.
86
+ * The entries include subscriber_ids for fan-out routing.
87
+ */
88
+ onChanges?: (entries: ChangeLogEntry[]) => void;
89
+ /**
90
+ * Called when an error occurs during polling, heartbeat, or cleanup.
91
+ * If not provided, errors are logged to the console.
92
+ */
93
+ onError?: (error: Error) => void;
94
+ }
95
+ /**
96
+ * Configuration for the RealtimeManager, which bridges CursorTracker
97
+ * events into PostGraphile's PgSubscriber for at-least-once delivery.
98
+ */
99
+ export interface RealtimeManagerOptions {
100
+ /**
101
+ * The PgSubscriber instance from PostGraphile's context.
102
+ * RealtimeManager emits cursor-tracked events on its internal EventEmitter
103
+ * so they flow through existing subscription plans.
104
+ */
105
+ pgSubscriber: unknown;
106
+ /**
107
+ * Function to acquire a PgClient for executing cursor tracking queries.
108
+ */
109
+ withPgClient: WithPgClient;
110
+ /**
111
+ * Unique identifier for this listener node.
112
+ * Should be stable across restarts if you want cursor continuity.
113
+ * If not provided, a random ID is generated (ephemeral mode).
114
+ */
115
+ nodeId?: string;
116
+ /**
117
+ * The realtime_public schema name where drain_changes(),
118
+ * touch_listener(), and cleanup_ephemeral() live.
119
+ *
120
+ * Default: 'realtime_public'
121
+ */
122
+ schema?: string;
123
+ /**
124
+ * How often to poll drain_changes() for new events (milliseconds).
125
+ *
126
+ * Default: 5000 (5 seconds)
127
+ */
128
+ pollIntervalMs?: number;
129
+ /**
130
+ * How often to send a heartbeat via touch_listener() (milliseconds).
131
+ *
132
+ * Default: 30000 (30 seconds)
133
+ */
134
+ heartbeatIntervalMs?: number;
135
+ /**
136
+ * Maximum number of change_log rows to fetch per drain_changes() call.
137
+ *
138
+ * Default: 500
139
+ */
140
+ batchLimit?: number;
141
+ /**
142
+ * Called when an error occurs during polling, heartbeat, or cleanup.
143
+ * If not provided, errors are logged via @pgpmjs/logger.
144
+ */
145
+ onError?: (error: Error) => void;
9
146
  }