@supalive/core 0.1.6 → 1.1.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.
Files changed (36) hide show
  1. package/dist/index-DouKwYL6.d.ts +1754 -0
  2. package/dist/index-DouKwYL6.d.ts.map +1 -0
  3. package/dist/mysql-Bxurg_PH.d.ts +104 -0
  4. package/dist/mysql-Bxurg_PH.d.ts.map +1 -0
  5. package/dist/postgres-CfT_aDx3.d.ts +108 -0
  6. package/dist/postgres-CfT_aDx3.d.ts.map +1 -0
  7. package/dist/procedure-DX87tyef.js.map +1 -1
  8. package/dist/router-DlTYWpop.js.map +1 -1
  9. package/dist/src/client/index.d.ts +1 -1
  10. package/dist/src/exports/codegen.d.ts +38 -0
  11. package/dist/src/exports/codegen.d.ts.map +1 -0
  12. package/dist/src/exports/codegen.js +134 -0
  13. package/dist/src/exports/codegen.js.map +1 -0
  14. package/dist/src/exports/mysql.d.ts +1 -1
  15. package/dist/src/exports/postgres.d.ts +1 -1
  16. package/dist/src/exports/procedure.d.ts +1 -1
  17. package/dist/src/exports/schema-sql.d.ts +1 -1
  18. package/dist/src/exports/server.d.ts +4 -4
  19. package/dist/src/exports/server.d.ts.map +1 -1
  20. package/dist/src/exports/server.js +4 -8
  21. package/dist/src/exports/server.js.map +1 -1
  22. package/dist/src/exports/subscription-manager-worker-entry.js +1 -2
  23. package/dist/src/exports/subscription-manager-worker-entry.js.map +1 -1
  24. package/dist/src/exports/types.d.ts +2 -2
  25. package/dist/subscription-worker-CqoWp6zB.js +511 -0
  26. package/dist/subscription-worker-CqoWp6zB.js.map +1 -0
  27. package/dist/subscription-worker-PtmJWEj1.js +511 -0
  28. package/dist/subscription-worker-PtmJWEj1.js.map +1 -0
  29. package/dist/types_server-BW1ys_SK.d.ts +216 -0
  30. package/dist/types_server-BW1ys_SK.d.ts.map +1 -0
  31. package/dist/types_server-Dk6o_B7N.js.map +1 -1
  32. package/dist/types_server-Dpsi0wpG.d.ts +216 -0
  33. package/dist/types_server-Dpsi0wpG.d.ts.map +1 -0
  34. package/dist/types_server-DzrIccyO.d.ts +216 -0
  35. package/dist/types_server-DzrIccyO.d.ts.map +1 -0
  36. package/package.json +3 -2
@@ -0,0 +1,216 @@
1
+ import { An as CacheLayer, ar as MutationResult, tt as RegisteredProcedure, wt as SupaliveDb } from "./index-DouKwYL6.js";
2
+ import z from "zod";
3
+ import { WebSocket } from "ws";
4
+ import { Level } from "pino";
5
+ import { Redis } from "ioredis";
6
+
7
+ //#region src/config.d.ts
8
+ interface UpstashConfig {
9
+ url: string;
10
+ token: string;
11
+ redisUrl: string;
12
+ }
13
+ /** Database configuration for PostgreSQL */
14
+ interface PostgresConfig {
15
+ type: "postgres";
16
+ connectionString: string;
17
+ /** Optional max connections for the Postgres connection pool. Defaults to 10.*/
18
+ maxConnections?: number;
19
+ /** Optional min connections for the Postgres connection pool. Defaults to 1.*/
20
+ minConnections?: number;
21
+ /** Optional idle timeout for Postgres connections in milliseconds. Defaults to 30000 (30 seconds). */
22
+ idleTimeoutMillis?: number;
23
+ /** Optional connection timeout for acquiring Postgres connections in milliseconds. Defaults to 7000 (7 seconds). */
24
+ connectionTimeoutMillis?: number;
25
+ }
26
+ /** Database configuration for MySQL */
27
+ interface MySQLConfig {
28
+ type: "mysql";
29
+ connectionString: string;
30
+ /** Optional max connections for the MySQL connection pool. Defaults to 20.*/
31
+ maxConnections?: number;
32
+ /** Optional min connections for the MySQL connection pool. Defaults to 1.*/
33
+ minConnections?: number;
34
+ /** Optional idle timeout for MySQL connections in milliseconds. Defaults to 30000 (30 seconds). */
35
+ idleTimeoutMillis?: number;
36
+ /** Optional connection timeout for acquiring MySQL connections in milliseconds. Defaults to 7000 (7 seconds). */
37
+ connectionTimeoutMillis?: number;
38
+ /** Optional flag to queue connection requests when pool is exhausted. Defaults to true (queue requests). */
39
+ queueLimit?: number;
40
+ }
41
+ type DatabaseConfig = PostgresConfig | MySQLConfig;
42
+ /**
43
+ * Configuration for the Supalive WebSocket server.
44
+ */
45
+ interface SupaliveServerConfig<TContext = Record<string, unknown>> {
46
+ /** Server port (default: 3000) */
47
+ port?: number;
48
+ /** Server host (default: "0.0.0.0") */
49
+ host?: string;
50
+ cacheLayer: CacheLayer;
51
+ redisSubClient: Redis;
52
+ /**
53
+ * Subscription Manager WebSocket URL for RPC communication.
54
+ * A single sub-manager process owns all subscription state for this
55
+ * deployment. Internally it spawns N logical workers (configured on the
56
+ * sub-manager side) and routes by hash(subId) to spread CPU across them.
57
+ */
58
+ subManagerUrl: string;
59
+ /** Database instance */
60
+ database: SupaliveDb;
61
+ /**
62
+ * Optional authentication callback.
63
+ * Called when client sends auth message.
64
+ * Return null to reject authentication.
65
+ */
66
+ verifyAuth?: (data: Record<string, unknown>, sessionId: string) => Promise<TContext | null>;
67
+ /**
68
+ * Server context name for procedure routing.
69
+ * Must match the router's contextName.
70
+ */
71
+ contextName?: string;
72
+ /**
73
+ * Session TTL in seconds (default: 3600 = 1 hour).
74
+ * Sessions are kept alive while connected and expire after disconnect.
75
+ */
76
+ sessionTtlSeconds?: number;
77
+ /**
78
+ * Enable detailed logging.
79
+ */
80
+ logLevel?: Level;
81
+ /**
82
+ * Extract user ID from context for cache key generation.
83
+ * If not provided, caching is disabled (each sub recomputes independently).
84
+ */
85
+ getUserId?: (ctx: TContext | undefined) => string | null;
86
+ /**
87
+ * Cache TTL in seconds (default: 3600).
88
+ * How long query results are cached in Redis.
89
+ */
90
+ cacheTtlSeconds?: number;
91
+ }
92
+ interface SubscriptionManagerConfig {
93
+ port: number;
94
+ upstash: {
95
+ url: string;
96
+ token: string;
97
+ redisUrl: string;
98
+ };
99
+ database: DatabaseConfig;
100
+ cacheTTLSeconds: number;
101
+ /**
102
+ * Number of logical workers inside the sub-manager process.
103
+ *
104
+ * Subscriptions are routed by FNV-1a(subId) % workers so that all operations
105
+ * for a given subId always land on the same worker (preserving the existing
106
+ * `instances: Set<string>` dedup). Each worker owns an independent
107
+ * subscriptions Map; on invalidate, all workers scan their own slice in
108
+ * parallel (logically — JS still runs one at a time inside one event loop,
109
+ * but per-worker scans are smaller so total work is split N ways).
110
+ *
111
+ * Defaults to `SUPALIVE_SUB_MANAGER_WORKERS` env var if set, else 1.
112
+ */
113
+ workers?: number;
114
+ /**
115
+ * Connection pool size *per worker*. If omitted, falls back to
116
+ * `floor(database.maxConnections / workers)` (min 1) so the total pool
117
+ * size stays close to the legacy single-worker configuration.
118
+ */
119
+ maxConnectionsPerWorker?: number;
120
+ }
121
+ //#endregion
122
+ //#region src/server/types_server.d.ts
123
+ type InstanceId = string;
124
+ type SubId = string;
125
+ /** Local tracking of an active subscription (per-session) */
126
+ interface SubscriptionEntry {
127
+ subId: SubId;
128
+ cacheKey: string;
129
+ subscribedTimes: number;
130
+ }
131
+ /**
132
+ * A mutation that has been validated and parked on the per-session FIFO
133
+ * queue, waiting for the in-flight mutation on this socket to finish. Each
134
+ * `handleCall` for a mutation owns one of these and awaits its own
135
+ * resolve/reject so it can send the response.
136
+ */
137
+ interface PendingMutation<TContext = Record<string, unknown>> {
138
+ procedure: RegisteredProcedure<TContext>;
139
+ validatedInput: unknown;
140
+ resolve: (result: MutationResult<unknown>) => void;
141
+ reject: (err: unknown) => void;
142
+ }
143
+ /** WebSocket session (runtime, with WebSocket) */
144
+ interface Session<TContext = Record<string, unknown>> {
145
+ id: string;
146
+ ws: WebSocket;
147
+ /** Auth context from verifyAuth callback */
148
+ serverCtx?: TContext;
149
+ subIds: Set<string>;
150
+ /**
151
+ * Per-socket FIFO mutation queue. at most one mutation
152
+ * drains at a time so a single client cannot saturate the OCC retry
153
+ * loop or fan out concurrent commits that race the same rows.
154
+ */
155
+ mutationQueue: PendingMutation<TContext>[];
156
+ mutationInFlight: boolean;
157
+ /** Per-socket count of currently executing actions. */
158
+ actionInFlight: number;
159
+ /**
160
+ * Wall-clock of the last inbound frame (text message, ws-ping, or ws-pong).
161
+ * Used by the per-session heartbeat to terminate sockets that have gone
162
+ * silent past `CLIENT_TIMEOUT_MS`.
163
+ */
164
+ lastReceivedAt: number;
165
+ /**
166
+ * Wall-clock of the last outbound frame. Gates the idle-only app-level
167
+ * ping so a busy session (frequent sub:updates etc.) doesn't emit a
168
+ * redundant `{type:"ping"}` on every heartbeat tick.
169
+ */
170
+ lastSentAt: number;
171
+ /**
172
+ * Per-session combined heartbeat. Single `setInterval` that handles
173
+ * both dead-TCP detection (ws-ping or terminate) and client-watchdog
174
+ * refresh (idle-only app-level ping) on each tick.
175
+ */
176
+ heartbeatTimer: ReturnType<typeof setInterval> | null;
177
+ }
178
+ declare const RemoteSubscriptionUpdateSchema: z.ZodObject<{
179
+ type: z.ZodLiteral<"update">;
180
+ subId: z.ZodString;
181
+ data: z.ZodUnknown;
182
+ dataHash: z.ZodString;
183
+ originInstance: z.ZodString;
184
+ }, z.core.$strip>;
185
+ type RemoteSubscriptionUpdate = z.infer<typeof RemoteSubscriptionUpdateSchema>;
186
+ declare const RemoteRecomputeRaceSchema: z.ZodObject<{
187
+ type: z.ZodLiteral<"recompute-race">;
188
+ subId: z.ZodString;
189
+ cacheKey: z.ZodString;
190
+ queryName: z.ZodString;
191
+ args: z.ZodUnknown;
192
+ notifyInstances: z.ZodArray<z.ZodString>;
193
+ commitTs: z.ZodString;
194
+ originInstance: z.ZodString;
195
+ }, z.core.$strip>;
196
+ type RemoteRecomputeRace = z.infer<typeof RemoteRecomputeRaceSchema>;
197
+ declare const RemoteSubscriptionMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
198
+ type: z.ZodLiteral<"update">;
199
+ subId: z.ZodString;
200
+ data: z.ZodUnknown;
201
+ dataHash: z.ZodString;
202
+ originInstance: z.ZodString;
203
+ }, z.core.$strip>, z.ZodObject<{
204
+ type: z.ZodLiteral<"recompute-race">;
205
+ subId: z.ZodString;
206
+ cacheKey: z.ZodString;
207
+ queryName: z.ZodString;
208
+ args: z.ZodUnknown;
209
+ notifyInstances: z.ZodArray<z.ZodString>;
210
+ commitTs: z.ZodString;
211
+ originInstance: z.ZodString;
212
+ }, z.core.$strip>], "type">;
213
+ type RemoteSubscriptionMessage = z.infer<typeof RemoteSubscriptionMessageSchema>;
214
+ //#endregion
215
+ export { UpstashConfig as _, RemoteSubscriptionMessage as a, RemoteSubscriptionUpdateSchema as c, SubscriptionEntry as d, DatabaseConfig as f, SupaliveServerConfig as g, SubscriptionManagerConfig as h, RemoteRecomputeRaceSchema as i, Session as l, PostgresConfig as m, PendingMutation as n, RemoteSubscriptionMessageSchema as o, MySQLConfig as p, RemoteRecomputeRace as r, RemoteSubscriptionUpdate as s, InstanceId as t, SubId as u };
216
+ //# sourceMappingURL=types_server-BW1ys_SK.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types_server-BW1ys_SK.d.ts","names":[],"sources":["../src/config.ts","../src/server/types_server.ts"],"mappings":";;;;;;;UAKiB,aAAA;EACb,GAAA;EACA,KAAA;EACA,QAAA;AAAA;;UAIa,cAAA;EACb,IAAA;EACA,gBAAA;EANA;EAQA,cAAA;EARQ;EAWR,cAAA;EAP2B;EAU3B,iBAAA;EAV2B;EAa3B,uBAAA;AAAA;;UAIa,WAAA;EACb,IAAA;EACA,gBAAA;EANuB;EAQvB,cAAA;EAJa;EAOb,cAAA;;EAGA,iBAAA;EATA;EAYA,uBAAA;EATA;EAYA,UAAA;AAAA;AAAA,KAGQ,cAAA,GAAiB,cAAA,GAAiB,WAAW;;;AAH3C;UAQG,oBAAA,YAAgC,MAAA;EALvB;EAOtB,IAAA;EAPyB;EAUzB,IAAA;EAKA,UAAA,EAAY,UAAA;EAIZ,cAAA,EAAgB,KAAA;EAdiB;;;;;;EAsBjC,aAAA;EAaK;EAVL,QAAA,EAAU,UAAA;EAiCQ;;;;;EA1BlB,UAAA,IACI,IAAA,EAAM,MAAA,mBACN,SAAA,aACC,OAAA,CAAQ,QAAA;EA9Bb;;;;EAoCA,WAAA;EAnBA;;;;EAyBA,iBAAA;EAdI;;;EAmBJ,QAAA,GAAW,KAAA;EAXX;;;;EAiBA,SAAA,IAAa,GAAA,EAAK,QAAA;EAAA;;;;EAMlB,eAAA;AAAA;AAAA,UAGa,yBAAA;EACb,IAAA;EACA,OAAA;IAAW,GAAA;IAAa,KAAA;IAAe,QAAA;EAAA;EACvC,QAAA,EAAU,cAAc;EACxB,eAAA;EADU;;;;;AAoBa;;;;ACxI3B;;;EDkII,OAAA;EClIkB;AAEtB;;;;EDsII,uBAAA;AAAA;;;KCxIQ,UAAA;AAAA,KAEA,KAAA;;UAGK,iBAAA;EACf,KAAA,EAAO,KAAK;EACZ,QAAA;EACA,eAAA;AAAA;;;;ADPU;AAIZ;;UCYiB,eAAA,YAA2B,MAAA;EAC1C,SAAA,EAAW,mBAAA,CAAoB,QAAA;EAC/B,cAAA;EACA,OAAA,GAAU,MAAA,EAAQ,cAAA;EAClB,MAAA,GAAS,GAAA;AAAA;;UAIM,OAAA,YAAmB,MAAA;EAClC,EAAA;EACA,EAAA,EAAI,SAAA;EDLW;ECOf,SAAA,GAAY,QAAA;EACZ,MAAA,EAAQ,GAAA;EDRkB;;;;;ECc1B,aAAA,EAAe,eAAA,CAAgB,QAAA;EAC/B,gBAAA;EDCE;ECCF,cAAA;EDDY;AAGd;;;;ECIE,cAAA;EDCe;;;;;ECKf,UAAA;EDoBY;;;;;ECdZ,cAAA,EAAgB,UAAA,QAAkB,WAAA;AAAA;AAAA,cAgBvB,8BAAA,EAA8B,CAAA,CAAA,SAAA;;;;;;;KAO/B,wBAAA,GAA2B,CAAA,CAAE,KAAK,QAAQ,8BAAA;AAAA,cAEzC,yBAAA,EAAyB,CAAA,CAAA,SAAA;;;;;;;;;;KAU1B,mBAAA,GAAsB,CAAA,CAAE,KAAK,QAAQ,yBAAA;AAAA,cAEpC,+BAAA,EAA+B,CAAA,CAAA,qBAAA,EAAA,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;KAIhC,yBAAA,GAA4B,CAAA,CAAE,KAAK,QAAQ,+BAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"types_server-Dk6o_B7N.js","names":[],"sources":["../src/server/types_server.ts"],"sourcesContent":["import type { WebSocket } from \"ws\";\nimport type { ReadEntry, MutationResult } from \"../db/types_db\";\nimport type { RegisteredProcedure } from \"../router/router\";\nimport z from \"zod\";\n\n// ─── Core Types ───────────────────────────────────────────────────────────────\n\nexport type InstanceId = string;\n\nexport type SubId = string;\n\n/** Local tracking of an active subscription (per-session) */\nexport interface SubscriptionEntry {\n subId: SubId;\n cacheKey: string;\n subscribedTimes: number;\n}\n\n/**\n * A mutation that has been validated and parked on the per-session FIFO\n * queue, waiting for the in-flight mutation on this socket to finish. Each\n * `handleCall` for a mutation owns one of these and awaits its own\n * resolve/reject so it can send the response.\n */\nexport interface PendingMutation<TContext = Record<string, unknown>> {\n procedure: RegisteredProcedure<TContext>;\n validatedInput: unknown;\n resolve: (result: MutationResult<unknown>) => void;\n reject: (err: unknown) => void;\n}\n\n/** WebSocket session (runtime, with WebSocket) */\nexport interface Session<TContext = Record<string, unknown>> {\n id: string;\n ws: WebSocket;\n /** Auth context from verifyAuth callback */\n serverCtx: TContext;\n subIds: Set<string>;\n /**\n * Per-socket FIFO mutation queue. at most one mutation\n * drains at a time so a single client cannot saturate the OCC retry\n * loop or fan out concurrent commits that race the same rows.\n */\n mutationQueue: PendingMutation<TContext>[];\n mutationInFlight: boolean;\n /** Per-socket count of currently executing actions. */\n actionInFlight: number;\n /**\n * Wall-clock of the last inbound frame (text message, ws-ping, or ws-pong).\n * Used by the per-session heartbeat to terminate sockets that have gone\n * silent past `CLIENT_TIMEOUT_MS`.\n */\n lastReceivedAt: number;\n /**\n * Wall-clock of the last outbound frame. Gates the idle-only app-level\n * ping so a busy session (frequent sub:updates etc.) doesn't emit a\n * redundant `{type:\"ping\"}` on every heartbeat tick.\n */\n lastSentAt: number;\n /**\n * Per-session combined heartbeat. Single `setInterval` that handles\n * both dead-TCP detection (ws-ping or terminate) and client-watchdog\n * refresh (idle-only app-level ping) on each tick.\n */\n heartbeatTimer: ReturnType<typeof setInterval> | null;\n}\n\n// Messages published on `sub:instance:<instanceId>` for cross-instance fan-out.\n//\n// Two variants:\n// • update — the writer (or race winner) recomputed and is pushing\n// the result; receivers forward `data` to their local\n// sessions.\n// • recompute-race — the writer does not hold the affected sub locally, so\n// it broadcasts a race hint to every instance that does\n// (`notifyInstances`). Receivers try to acquire a Redis\n// lock keyed by (subId, commitTs); the winner runs the\n// query against one of its own sessions' serverCtx and\n// publishes the resulting `update` back out. Losers\n// no-op and pick up the winner's `update` over Redis.\nexport const RemoteSubscriptionUpdateSchema = z.object({\n type: z.literal(\"update\"),\n subId: z.string(),\n data: z.unknown(),\n dataHash: z.string(),\n originInstance: z.string(),\n});\nexport type RemoteSubscriptionUpdate = z.infer<typeof RemoteSubscriptionUpdateSchema>;\n\nexport const RemoteRecomputeRaceSchema = z.object({\n type: z.literal(\"recompute-race\"),\n subId: z.string(),\n cacheKey: z.string(),\n queryName: z.string(),\n args: z.unknown(),\n notifyInstances: z.array(z.string()),\n commitTs: z.string(),\n originInstance: z.string(),\n});\nexport type RemoteRecomputeRace = z.infer<typeof RemoteRecomputeRaceSchema>;\n\nexport const RemoteSubscriptionMessageSchema = z.discriminatedUnion(\"type\", [\n RemoteSubscriptionUpdateSchema,\n RemoteRecomputeRaceSchema,\n]);\nexport type RemoteSubscriptionMessage = z.infer<typeof RemoteSubscriptionMessageSchema>;\n"],"mappings":";;AAgFA,MAAa,iCAAiC,EAAE,OAAO;CACrD,MAAM,EAAE,QAAQ,QAAQ;CACxB,OAAO,EAAE,OAAO;CAChB,MAAM,EAAE,QAAQ;CAChB,UAAU,EAAE,OAAO;CACnB,gBAAgB,EAAE,OAAO;AAC3B,CAAC;AAGD,MAAa,4BAA4B,EAAE,OAAO;CAChD,MAAM,EAAE,QAAQ,gBAAgB;CAChC,OAAO,EAAE,OAAO;CAChB,UAAU,EAAE,OAAO;CACnB,WAAW,EAAE,OAAO;CACpB,MAAM,EAAE,QAAQ;CAChB,iBAAiB,EAAE,MAAM,EAAE,OAAO,CAAC;CACnC,UAAU,EAAE,OAAO;CACnB,gBAAgB,EAAE,OAAO;AAC3B,CAAC;AAGD,MAAa,kCAAkC,EAAE,mBAAmB,QAAQ,CAC1E,gCACA,yBACF,CAAC"}
1
+ {"version":3,"file":"types_server-Dk6o_B7N.js","names":[],"sources":["../src/server/types_server.ts"],"sourcesContent":["import type { WebSocket } from \"ws\";\nimport type { ReadEntry, MutationResult } from \"../db/types_db\";\nimport type { RegisteredProcedure } from \"../router/router\";\nimport z from \"zod\";\n\n// ─── Core Types ───────────────────────────────────────────────────────────────\n\nexport type InstanceId = string;\n\nexport type SubId = string;\n\n/** Local tracking of an active subscription (per-session) */\nexport interface SubscriptionEntry {\n subId: SubId;\n cacheKey: string;\n subscribedTimes: number;\n}\n\n/**\n * A mutation that has been validated and parked on the per-session FIFO\n * queue, waiting for the in-flight mutation on this socket to finish. Each\n * `handleCall` for a mutation owns one of these and awaits its own\n * resolve/reject so it can send the response.\n */\nexport interface PendingMutation<TContext = Record<string, unknown>> {\n procedure: RegisteredProcedure<TContext>;\n validatedInput: unknown;\n resolve: (result: MutationResult<unknown>) => void;\n reject: (err: unknown) => void;\n}\n\n/** WebSocket session (runtime, with WebSocket) */\nexport interface Session<TContext = Record<string, unknown>> {\n id: string;\n ws: WebSocket;\n /** Auth context from verifyAuth callback */\n serverCtx?: TContext;\n subIds: Set<string>;\n /**\n * Per-socket FIFO mutation queue. at most one mutation\n * drains at a time so a single client cannot saturate the OCC retry\n * loop or fan out concurrent commits that race the same rows.\n */\n mutationQueue: PendingMutation<TContext>[];\n mutationInFlight: boolean;\n /** Per-socket count of currently executing actions. */\n actionInFlight: number;\n /**\n * Wall-clock of the last inbound frame (text message, ws-ping, or ws-pong).\n * Used by the per-session heartbeat to terminate sockets that have gone\n * silent past `CLIENT_TIMEOUT_MS`.\n */\n lastReceivedAt: number;\n /**\n * Wall-clock of the last outbound frame. Gates the idle-only app-level\n * ping so a busy session (frequent sub:updates etc.) doesn't emit a\n * redundant `{type:\"ping\"}` on every heartbeat tick.\n */\n lastSentAt: number;\n /**\n * Per-session combined heartbeat. Single `setInterval` that handles\n * both dead-TCP detection (ws-ping or terminate) and client-watchdog\n * refresh (idle-only app-level ping) on each tick.\n */\n heartbeatTimer: ReturnType<typeof setInterval> | null;\n}\n\n// Messages published on `sub:instance:<instanceId>` for cross-instance fan-out.\n//\n// Two variants:\n// • update — the writer (or race winner) recomputed and is pushing\n// the result; receivers forward `data` to their local\n// sessions.\n// • recompute-race — the writer does not hold the affected sub locally, so\n// it broadcasts a race hint to every instance that does\n// (`notifyInstances`). Receivers try to acquire a Redis\n// lock keyed by (subId, commitTs); the winner runs the\n// query against one of its own sessions' serverCtx and\n// publishes the resulting `update` back out. Losers\n// no-op and pick up the winner's `update` over Redis.\nexport const RemoteSubscriptionUpdateSchema = z.object({\n type: z.literal(\"update\"),\n subId: z.string(),\n data: z.unknown(),\n dataHash: z.string(),\n originInstance: z.string(),\n});\nexport type RemoteSubscriptionUpdate = z.infer<typeof RemoteSubscriptionUpdateSchema>;\n\nexport const RemoteRecomputeRaceSchema = z.object({\n type: z.literal(\"recompute-race\"),\n subId: z.string(),\n cacheKey: z.string(),\n queryName: z.string(),\n args: z.unknown(),\n notifyInstances: z.array(z.string()),\n commitTs: z.string(),\n originInstance: z.string(),\n});\nexport type RemoteRecomputeRace = z.infer<typeof RemoteRecomputeRaceSchema>;\n\nexport const RemoteSubscriptionMessageSchema = z.discriminatedUnion(\"type\", [\n RemoteSubscriptionUpdateSchema,\n RemoteRecomputeRaceSchema,\n]);\nexport type RemoteSubscriptionMessage = z.infer<typeof RemoteSubscriptionMessageSchema>;\n"],"mappings":";;AAgFA,MAAa,iCAAiC,EAAE,OAAO;CACrD,MAAM,EAAE,QAAQ,QAAQ;CACxB,OAAO,EAAE,OAAO;CAChB,MAAM,EAAE,QAAQ;CAChB,UAAU,EAAE,OAAO;CACnB,gBAAgB,EAAE,OAAO;AAC3B,CAAC;AAGD,MAAa,4BAA4B,EAAE,OAAO;CAChD,MAAM,EAAE,QAAQ,gBAAgB;CAChC,OAAO,EAAE,OAAO;CAChB,UAAU,EAAE,OAAO;CACnB,WAAW,EAAE,OAAO;CACpB,MAAM,EAAE,QAAQ;CAChB,iBAAiB,EAAE,MAAM,EAAE,OAAO,CAAC;CACnC,UAAU,EAAE,OAAO;CACnB,gBAAgB,EAAE,OAAO;AAC3B,CAAC;AAGD,MAAa,kCAAkC,EAAE,mBAAmB,QAAQ,CAC1E,gCACA,yBACF,CAAC"}
@@ -0,0 +1,216 @@
1
+ import { An as CacheLayer, ar as MutationResult, tt as RegisteredProcedure, wt as SupaliveDb } from "./index-DouKwYL6.js";
2
+ import z from "zod";
3
+ import { WebSocket } from "ws";
4
+ import { Level } from "pino";
5
+ import { Redis } from "ioredis";
6
+
7
+ //#region src/config.d.ts
8
+ interface UpstashConfig {
9
+ url: string;
10
+ token: string;
11
+ redisUrl: string;
12
+ }
13
+ /** Database configuration for PostgreSQL */
14
+ interface PostgresConfig {
15
+ type: "postgres";
16
+ connectionString: string;
17
+ /** Optional max connections for the Postgres connection pool. Defaults to 10.*/
18
+ maxConnections?: number;
19
+ /** Optional min connections for the Postgres connection pool. Defaults to 1.*/
20
+ minConnections?: number;
21
+ /** Optional idle timeout for Postgres connections in milliseconds. Defaults to 30000 (30 seconds). */
22
+ idleTimeoutMillis?: number;
23
+ /** Optional connection timeout for acquiring Postgres connections in milliseconds. Defaults to 7000 (7 seconds). */
24
+ connectionTimeoutMillis?: number;
25
+ }
26
+ /** Database configuration for MySQL */
27
+ interface MySQLConfig {
28
+ type: "mysql";
29
+ connectionString: string;
30
+ /** Optional max connections for the MySQL connection pool. Defaults to 20.*/
31
+ maxConnections?: number;
32
+ /** Optional min connections for the MySQL connection pool. Defaults to 1.*/
33
+ minConnections?: number;
34
+ /** Optional idle timeout for MySQL connections in milliseconds. Defaults to 30000 (30 seconds). */
35
+ idleTimeoutMillis?: number;
36
+ /** Optional connection timeout for acquiring MySQL connections in milliseconds. Defaults to 7000 (7 seconds). */
37
+ connectionTimeoutMillis?: number;
38
+ /** Optional flag to queue connection requests when pool is exhausted. Defaults to true (queue requests). */
39
+ queueLimit?: number;
40
+ }
41
+ type DatabaseConfig = PostgresConfig | MySQLConfig;
42
+ /**
43
+ * Configuration for the Supalive WebSocket server.
44
+ */
45
+ interface SupaliveServerConfig<TContext = Record<string, unknown>> {
46
+ /** Server port (default: 3000) */
47
+ port?: number;
48
+ /** Server host (default: "0.0.0.0") */
49
+ host?: string;
50
+ cacheLayer: CacheLayer;
51
+ redisSubClient: Redis;
52
+ /**
53
+ * Subscription Manager WebSocket URL for RPC communication.
54
+ * A single sub-manager process owns all subscription state for this
55
+ * deployment. Internally it spawns N logical workers (configured on the
56
+ * sub-manager side) and routes by hash(subId) to spread CPU across them.
57
+ */
58
+ subManagerUrl: string;
59
+ /** Database instance */
60
+ database: SupaliveDb;
61
+ /**
62
+ * Optional authentication callback.
63
+ * Called when client sends auth message.
64
+ * Return null to reject authentication.
65
+ */
66
+ verifyAuth?: (data: Record<string, unknown>, sessionId: string) => Promise<TContext | null>;
67
+ /**
68
+ * Server context name for procedure routing.
69
+ * Must match the router's contextName.
70
+ */
71
+ contextName?: string;
72
+ /**
73
+ * Session TTL in seconds (default: 3600 = 1 hour).
74
+ * Sessions are kept alive while connected and expire after disconnect.
75
+ */
76
+ sessionTtlSeconds?: number;
77
+ /**
78
+ * Enable detailed logging.
79
+ */
80
+ logLevel?: Level;
81
+ /**
82
+ * Extract user ID from context for cache key generation.
83
+ * If not provided, caching is disabled (each sub recomputes independently).
84
+ */
85
+ getUserId?: (ctx: TContext | undefined) => string;
86
+ /**
87
+ * Cache TTL in seconds (default: 3600).
88
+ * How long query results are cached in Redis.
89
+ */
90
+ cacheTtlSeconds?: number;
91
+ }
92
+ interface SubscriptionManagerConfig {
93
+ port: number;
94
+ upstash: {
95
+ url: string;
96
+ token: string;
97
+ redisUrl: string;
98
+ };
99
+ database: DatabaseConfig;
100
+ cacheTTLSeconds: number;
101
+ /**
102
+ * Number of logical workers inside the sub-manager process.
103
+ *
104
+ * Subscriptions are routed by FNV-1a(subId) % workers so that all operations
105
+ * for a given subId always land on the same worker (preserving the existing
106
+ * `instances: Set<string>` dedup). Each worker owns an independent
107
+ * subscriptions Map; on invalidate, all workers scan their own slice in
108
+ * parallel (logically — JS still runs one at a time inside one event loop,
109
+ * but per-worker scans are smaller so total work is split N ways).
110
+ *
111
+ * Defaults to `SUPALIVE_SUB_MANAGER_WORKERS` env var if set, else 1.
112
+ */
113
+ workers?: number;
114
+ /**
115
+ * Connection pool size *per worker*. If omitted, falls back to
116
+ * `floor(database.maxConnections / workers)` (min 1) so the total pool
117
+ * size stays close to the legacy single-worker configuration.
118
+ */
119
+ maxConnectionsPerWorker?: number;
120
+ }
121
+ //#endregion
122
+ //#region src/server/types_server.d.ts
123
+ type InstanceId = string;
124
+ type SubId = string;
125
+ /** Local tracking of an active subscription (per-session) */
126
+ interface SubscriptionEntry {
127
+ subId: SubId;
128
+ cacheKey: string;
129
+ subscribedTimes: number;
130
+ }
131
+ /**
132
+ * A mutation that has been validated and parked on the per-session FIFO
133
+ * queue, waiting for the in-flight mutation on this socket to finish. Each
134
+ * `handleCall` for a mutation owns one of these and awaits its own
135
+ * resolve/reject so it can send the response.
136
+ */
137
+ interface PendingMutation<TContext = Record<string, unknown>> {
138
+ procedure: RegisteredProcedure<TContext>;
139
+ validatedInput: unknown;
140
+ resolve: (result: MutationResult<unknown>) => void;
141
+ reject: (err: unknown) => void;
142
+ }
143
+ /** WebSocket session (runtime, with WebSocket) */
144
+ interface Session<TContext = Record<string, unknown>> {
145
+ id: string;
146
+ ws: WebSocket;
147
+ /** Auth context from verifyAuth callback */
148
+ serverCtx?: TContext;
149
+ subIds: Set<string>;
150
+ /**
151
+ * Per-socket FIFO mutation queue. at most one mutation
152
+ * drains at a time so a single client cannot saturate the OCC retry
153
+ * loop or fan out concurrent commits that race the same rows.
154
+ */
155
+ mutationQueue: PendingMutation<TContext>[];
156
+ mutationInFlight: boolean;
157
+ /** Per-socket count of currently executing actions. */
158
+ actionInFlight: number;
159
+ /**
160
+ * Wall-clock of the last inbound frame (text message, ws-ping, or ws-pong).
161
+ * Used by the per-session heartbeat to terminate sockets that have gone
162
+ * silent past `CLIENT_TIMEOUT_MS`.
163
+ */
164
+ lastReceivedAt: number;
165
+ /**
166
+ * Wall-clock of the last outbound frame. Gates the idle-only app-level
167
+ * ping so a busy session (frequent sub:updates etc.) doesn't emit a
168
+ * redundant `{type:"ping"}` on every heartbeat tick.
169
+ */
170
+ lastSentAt: number;
171
+ /**
172
+ * Per-session combined heartbeat. Single `setInterval` that handles
173
+ * both dead-TCP detection (ws-ping or terminate) and client-watchdog
174
+ * refresh (idle-only app-level ping) on each tick.
175
+ */
176
+ heartbeatTimer: ReturnType<typeof setInterval> | null;
177
+ }
178
+ declare const RemoteSubscriptionUpdateSchema: z.ZodObject<{
179
+ type: z.ZodLiteral<"update">;
180
+ subId: z.ZodString;
181
+ data: z.ZodUnknown;
182
+ dataHash: z.ZodString;
183
+ originInstance: z.ZodString;
184
+ }, z.core.$strip>;
185
+ type RemoteSubscriptionUpdate = z.infer<typeof RemoteSubscriptionUpdateSchema>;
186
+ declare const RemoteRecomputeRaceSchema: z.ZodObject<{
187
+ type: z.ZodLiteral<"recompute-race">;
188
+ subId: z.ZodString;
189
+ cacheKey: z.ZodString;
190
+ queryName: z.ZodString;
191
+ args: z.ZodUnknown;
192
+ notifyInstances: z.ZodArray<z.ZodString>;
193
+ commitTs: z.ZodString;
194
+ originInstance: z.ZodString;
195
+ }, z.core.$strip>;
196
+ type RemoteRecomputeRace = z.infer<typeof RemoteRecomputeRaceSchema>;
197
+ declare const RemoteSubscriptionMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
198
+ type: z.ZodLiteral<"update">;
199
+ subId: z.ZodString;
200
+ data: z.ZodUnknown;
201
+ dataHash: z.ZodString;
202
+ originInstance: z.ZodString;
203
+ }, z.core.$strip>, z.ZodObject<{
204
+ type: z.ZodLiteral<"recompute-race">;
205
+ subId: z.ZodString;
206
+ cacheKey: z.ZodString;
207
+ queryName: z.ZodString;
208
+ args: z.ZodUnknown;
209
+ notifyInstances: z.ZodArray<z.ZodString>;
210
+ commitTs: z.ZodString;
211
+ originInstance: z.ZodString;
212
+ }, z.core.$strip>], "type">;
213
+ type RemoteSubscriptionMessage = z.infer<typeof RemoteSubscriptionMessageSchema>;
214
+ //#endregion
215
+ export { UpstashConfig as _, RemoteSubscriptionMessage as a, RemoteSubscriptionUpdateSchema as c, SubscriptionEntry as d, DatabaseConfig as f, SupaliveServerConfig as g, SubscriptionManagerConfig as h, RemoteRecomputeRaceSchema as i, Session as l, PostgresConfig as m, PendingMutation as n, RemoteSubscriptionMessageSchema as o, MySQLConfig as p, RemoteRecomputeRace as r, RemoteSubscriptionUpdate as s, InstanceId as t, SubId as u };
216
+ //# sourceMappingURL=types_server-Dpsi0wpG.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types_server-Dpsi0wpG.d.ts","names":[],"sources":["../src/config.ts","../src/server/types_server.ts"],"mappings":";;;;;;;UAKiB,aAAA;EACb,GAAA;EACA,KAAA;EACA,QAAA;AAAA;;UAIa,cAAA;EACb,IAAA;EACA,gBAAA;EANA;EAQA,cAAA;EARQ;EAWR,cAAA;EAP2B;EAU3B,iBAAA;EAV2B;EAa3B,uBAAA;AAAA;;UAIa,WAAA;EACb,IAAA;EACA,gBAAA;EANuB;EAQvB,cAAA;EAJa;EAOb,cAAA;;EAGA,iBAAA;EATA;EAYA,uBAAA;EATA;EAYA,UAAA;AAAA;AAAA,KAGQ,cAAA,GAAiB,cAAA,GAAiB,WAAW;;;AAH3C;UAQG,oBAAA,YAAgC,MAAA;EALvB;EAOtB,IAAA;EAPyB;EAUzB,IAAA;EAKA,UAAA,EAAY,UAAA;EAIZ,cAAA,EAAgB,KAAA;EAdiB;;;;;;EAsBjC,aAAA;EAaK;EAVL,QAAA,EAAU,UAAA;EAiCQ;;;;;EA1BlB,UAAA,IACI,IAAA,EAAM,MAAA,mBACN,SAAA,aACC,OAAA,CAAQ,QAAA;EA9Bb;;;;EAoCA,WAAA;EAnBA;;;;EAyBA,iBAAA;EAdI;;;EAmBJ,QAAA,GAAW,KAAA;EAXX;;;;EAiBA,SAAA,IAAa,GAAA,EAAK,QAAA;EAAA;;;;EAMlB,eAAA;AAAA;AAAA,UAGa,yBAAA;EACb,IAAA;EACA,OAAA;IAAW,GAAA;IAAa,KAAA;IAAe,QAAA;EAAA;EACvC,QAAA,EAAU,cAAc;EACxB,eAAA;EADU;;;;;AAoBa;;;;ACxI3B;;;EDkII,OAAA;EClIkB;AAEtB;;;;EDsII,uBAAA;AAAA;;;KCxIQ,UAAA;AAAA,KAEA,KAAA;;UAGK,iBAAA;EACf,KAAA,EAAO,KAAK;EACZ,QAAA;EACA,eAAA;AAAA;;;;ADPU;AAIZ;;UCYiB,eAAA,YAA2B,MAAA;EAC1C,SAAA,EAAW,mBAAA,CAAoB,QAAA;EAC/B,cAAA;EACA,OAAA,GAAU,MAAA,EAAQ,cAAA;EAClB,MAAA,GAAS,GAAA;AAAA;;UAIM,OAAA,YAAmB,MAAA;EAClC,EAAA;EACA,EAAA,EAAI,SAAA;EDLW;ECOf,SAAA,GAAY,QAAA;EACZ,MAAA,EAAQ,GAAA;EDRkB;;;;;ECc1B,aAAA,EAAe,eAAA,CAAgB,QAAA;EAC/B,gBAAA;EDCE;ECCF,cAAA;EDDY;AAGd;;;;ECIE,cAAA;EDCe;;;;;ECKf,UAAA;EDoBY;;;;;ECdZ,cAAA,EAAgB,UAAA,QAAkB,WAAA;AAAA;AAAA,cAgBvB,8BAAA,EAA8B,CAAA,CAAA,SAAA;;;;;;;KAO/B,wBAAA,GAA2B,CAAA,CAAE,KAAK,QAAQ,8BAAA;AAAA,cAEzC,yBAAA,EAAyB,CAAA,CAAA,SAAA;;;;;;;;;;KAU1B,mBAAA,GAAsB,CAAA,CAAE,KAAK,QAAQ,yBAAA;AAAA,cAEpC,+BAAA,EAA+B,CAAA,CAAA,qBAAA,EAAA,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;KAIhC,yBAAA,GAA4B,CAAA,CAAE,KAAK,QAAQ,+BAAA"}
@@ -0,0 +1,216 @@
1
+ import { An as CacheLayer, ar as MutationResult, tt as RegisteredProcedure, wt as SupaliveDb } from "./index-DouKwYL6.js";
2
+ import z from "zod";
3
+ import { WebSocket } from "ws";
4
+ import { Level } from "pino";
5
+ import { Redis } from "ioredis";
6
+
7
+ //#region src/config.d.ts
8
+ interface UpstashConfig {
9
+ url: string;
10
+ token: string;
11
+ redisUrl: string;
12
+ }
13
+ /** Database configuration for PostgreSQL */
14
+ interface PostgresConfig {
15
+ type: "postgres";
16
+ connectionString: string;
17
+ /** Optional max connections for the Postgres connection pool. Defaults to 10.*/
18
+ maxConnections?: number;
19
+ /** Optional min connections for the Postgres connection pool. Defaults to 1.*/
20
+ minConnections?: number;
21
+ /** Optional idle timeout for Postgres connections in milliseconds. Defaults to 30000 (30 seconds). */
22
+ idleTimeoutMillis?: number;
23
+ /** Optional connection timeout for acquiring Postgres connections in milliseconds. Defaults to 7000 (7 seconds). */
24
+ connectionTimeoutMillis?: number;
25
+ }
26
+ /** Database configuration for MySQL */
27
+ interface MySQLConfig {
28
+ type: "mysql";
29
+ connectionString: string;
30
+ /** Optional max connections for the MySQL connection pool. Defaults to 20.*/
31
+ maxConnections?: number;
32
+ /** Optional min connections for the MySQL connection pool. Defaults to 1.*/
33
+ minConnections?: number;
34
+ /** Optional idle timeout for MySQL connections in milliseconds. Defaults to 30000 (30 seconds). */
35
+ idleTimeoutMillis?: number;
36
+ /** Optional connection timeout for acquiring MySQL connections in milliseconds. Defaults to 7000 (7 seconds). */
37
+ connectionTimeoutMillis?: number;
38
+ /** Optional flag to queue connection requests when pool is exhausted. Defaults to true (queue requests). */
39
+ queueLimit?: number;
40
+ }
41
+ type DatabaseConfig = PostgresConfig | MySQLConfig;
42
+ /**
43
+ * Configuration for the Supalive WebSocket server.
44
+ */
45
+ interface SupaliveServerConfig<TContext = Record<string, unknown>> {
46
+ /** Server port (default: 3000) */
47
+ port?: number;
48
+ /** Server host (default: "0.0.0.0") */
49
+ host?: string;
50
+ cacheLayer: CacheLayer;
51
+ redisSubClient: Redis;
52
+ /**
53
+ * Subscription Manager WebSocket URL for RPC communication.
54
+ * A single sub-manager process owns all subscription state for this
55
+ * deployment. Internally it spawns N logical workers (configured on the
56
+ * sub-manager side) and routes by hash(subId) to spread CPU across them.
57
+ */
58
+ subManagerUrl: string;
59
+ /** Database instance */
60
+ database: SupaliveDb;
61
+ /**
62
+ * Optional authentication callback.
63
+ * Called when client sends auth message.
64
+ * Return null to reject authentication.
65
+ */
66
+ verifyAuth?: (data: Record<string, unknown>, sessionId: string) => Promise<TContext | null>;
67
+ /**
68
+ * Server context name for procedure routing.
69
+ * Must match the router's contextName.
70
+ */
71
+ contextName?: string;
72
+ /**
73
+ * Session TTL in seconds (default: 3600 = 1 hour).
74
+ * Sessions are kept alive while connected and expire after disconnect.
75
+ */
76
+ sessionTtlSeconds?: number;
77
+ /**
78
+ * Enable detailed logging.
79
+ */
80
+ logLevel?: Level;
81
+ /**
82
+ * Extract user ID from context for cache key generation.
83
+ * If not provided, caching is disabled (each sub recomputes independently).
84
+ */
85
+ getUserId?: (ctx: TContext | undefined, bool: boolean) => string | null;
86
+ /**
87
+ * Cache TTL in seconds (default: 3600).
88
+ * How long query results are cached in Redis.
89
+ */
90
+ cacheTtlSeconds?: number;
91
+ }
92
+ interface SubscriptionManagerConfig {
93
+ port: number;
94
+ upstash: {
95
+ url: string;
96
+ token: string;
97
+ redisUrl: string;
98
+ };
99
+ database: DatabaseConfig;
100
+ cacheTTLSeconds: number;
101
+ /**
102
+ * Number of logical workers inside the sub-manager process.
103
+ *
104
+ * Subscriptions are routed by FNV-1a(subId) % workers so that all operations
105
+ * for a given subId always land on the same worker (preserving the existing
106
+ * `instances: Set<string>` dedup). Each worker owns an independent
107
+ * subscriptions Map; on invalidate, all workers scan their own slice in
108
+ * parallel (logically — JS still runs one at a time inside one event loop,
109
+ * but per-worker scans are smaller so total work is split N ways).
110
+ *
111
+ * Defaults to `SUPALIVE_SUB_MANAGER_WORKERS` env var if set, else 1.
112
+ */
113
+ workers?: number;
114
+ /**
115
+ * Connection pool size *per worker*. If omitted, falls back to
116
+ * `floor(database.maxConnections / workers)` (min 1) so the total pool
117
+ * size stays close to the legacy single-worker configuration.
118
+ */
119
+ maxConnectionsPerWorker?: number;
120
+ }
121
+ //#endregion
122
+ //#region src/server/types_server.d.ts
123
+ type InstanceId = string;
124
+ type SubId = string;
125
+ /** Local tracking of an active subscription (per-session) */
126
+ interface SubscriptionEntry {
127
+ subId: SubId;
128
+ cacheKey: string;
129
+ subscribedTimes: number;
130
+ }
131
+ /**
132
+ * A mutation that has been validated and parked on the per-session FIFO
133
+ * queue, waiting for the in-flight mutation on this socket to finish. Each
134
+ * `handleCall` for a mutation owns one of these and awaits its own
135
+ * resolve/reject so it can send the response.
136
+ */
137
+ interface PendingMutation<TContext = Record<string, unknown>> {
138
+ procedure: RegisteredProcedure<TContext>;
139
+ validatedInput: unknown;
140
+ resolve: (result: MutationResult<unknown>) => void;
141
+ reject: (err: unknown) => void;
142
+ }
143
+ /** WebSocket session (runtime, with WebSocket) */
144
+ interface Session<TContext = Record<string, unknown>> {
145
+ id: string;
146
+ ws: WebSocket;
147
+ /** Auth context from verifyAuth callback */
148
+ serverCtx?: TContext;
149
+ subIds: Set<string>;
150
+ /**
151
+ * Per-socket FIFO mutation queue. at most one mutation
152
+ * drains at a time so a single client cannot saturate the OCC retry
153
+ * loop or fan out concurrent commits that race the same rows.
154
+ */
155
+ mutationQueue: PendingMutation<TContext>[];
156
+ mutationInFlight: boolean;
157
+ /** Per-socket count of currently executing actions. */
158
+ actionInFlight: number;
159
+ /**
160
+ * Wall-clock of the last inbound frame (text message, ws-ping, or ws-pong).
161
+ * Used by the per-session heartbeat to terminate sockets that have gone
162
+ * silent past `CLIENT_TIMEOUT_MS`.
163
+ */
164
+ lastReceivedAt: number;
165
+ /**
166
+ * Wall-clock of the last outbound frame. Gates the idle-only app-level
167
+ * ping so a busy session (frequent sub:updates etc.) doesn't emit a
168
+ * redundant `{type:"ping"}` on every heartbeat tick.
169
+ */
170
+ lastSentAt: number;
171
+ /**
172
+ * Per-session combined heartbeat. Single `setInterval` that handles
173
+ * both dead-TCP detection (ws-ping or terminate) and client-watchdog
174
+ * refresh (idle-only app-level ping) on each tick.
175
+ */
176
+ heartbeatTimer: ReturnType<typeof setInterval> | null;
177
+ }
178
+ declare const RemoteSubscriptionUpdateSchema: z.ZodObject<{
179
+ type: z.ZodLiteral<"update">;
180
+ subId: z.ZodString;
181
+ data: z.ZodUnknown;
182
+ dataHash: z.ZodString;
183
+ originInstance: z.ZodString;
184
+ }, z.core.$strip>;
185
+ type RemoteSubscriptionUpdate = z.infer<typeof RemoteSubscriptionUpdateSchema>;
186
+ declare const RemoteRecomputeRaceSchema: z.ZodObject<{
187
+ type: z.ZodLiteral<"recompute-race">;
188
+ subId: z.ZodString;
189
+ cacheKey: z.ZodString;
190
+ queryName: z.ZodString;
191
+ args: z.ZodUnknown;
192
+ notifyInstances: z.ZodArray<z.ZodString>;
193
+ commitTs: z.ZodString;
194
+ originInstance: z.ZodString;
195
+ }, z.core.$strip>;
196
+ type RemoteRecomputeRace = z.infer<typeof RemoteRecomputeRaceSchema>;
197
+ declare const RemoteSubscriptionMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
198
+ type: z.ZodLiteral<"update">;
199
+ subId: z.ZodString;
200
+ data: z.ZodUnknown;
201
+ dataHash: z.ZodString;
202
+ originInstance: z.ZodString;
203
+ }, z.core.$strip>, z.ZodObject<{
204
+ type: z.ZodLiteral<"recompute-race">;
205
+ subId: z.ZodString;
206
+ cacheKey: z.ZodString;
207
+ queryName: z.ZodString;
208
+ args: z.ZodUnknown;
209
+ notifyInstances: z.ZodArray<z.ZodString>;
210
+ commitTs: z.ZodString;
211
+ originInstance: z.ZodString;
212
+ }, z.core.$strip>], "type">;
213
+ type RemoteSubscriptionMessage = z.infer<typeof RemoteSubscriptionMessageSchema>;
214
+ //#endregion
215
+ export { UpstashConfig as _, RemoteSubscriptionMessage as a, RemoteSubscriptionUpdateSchema as c, SubscriptionEntry as d, DatabaseConfig as f, SupaliveServerConfig as g, SubscriptionManagerConfig as h, RemoteRecomputeRaceSchema as i, Session as l, PostgresConfig as m, PendingMutation as n, RemoteSubscriptionMessageSchema as o, MySQLConfig as p, RemoteRecomputeRace as r, RemoteSubscriptionUpdate as s, InstanceId as t, SubId as u };
216
+ //# sourceMappingURL=types_server-DzrIccyO.d.ts.map