@supalive/core 1.1.0 → 1.2.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/README.md +28 -0
- package/dist/db-ClCicssQ.js +28 -0
- package/dist/db-ClCicssQ.js.map +1 -0
- package/dist/{index-DouKwYL6.d.ts → index-DJYvJYR4.d.ts} +214 -9
- package/dist/index-DJYvJYR4.d.ts.map +1 -0
- package/dist/{mysql-Bxurg_PH.d.ts → mysql-53W9lRh9.d.ts} +8 -3
- package/dist/mysql-53W9lRh9.d.ts.map +1 -0
- package/dist/{mysql-bvnjYWvZ.js → mysql-C0mysDQ_.js} +57 -25
- package/dist/mysql-C0mysDQ_.js.map +1 -0
- package/dist/{overlap-checker-Ct_HP_iB.js → overlap-checker-ClJC0nxW.js} +52 -4
- package/dist/overlap-checker-ClJC0nxW.js.map +1 -0
- package/dist/{postgres-Ck-xt72U.d.ts → postgres-7d6R9P7w.d.ts} +8 -3
- package/dist/postgres-7d6R9P7w.d.ts.map +1 -0
- package/dist/{postgres-B8u1YN8X.js → postgres-SvdXfb0w.js} +55 -22
- package/dist/postgres-SvdXfb0w.js.map +1 -0
- package/dist/{procedure-DX87tyef.js → procedure-Ze1GE-N9.js} +33 -2
- package/dist/procedure-Ze1GE-N9.js.map +1 -0
- package/dist/{query-Bh0RNxDz.js → query-CrbJ_W0W.js} +21 -1
- package/dist/query-CrbJ_W0W.js.map +1 -0
- package/dist/{realtime_db-DOCgqbwi.js → realtime_db-BtwBABDY.js} +76 -51
- package/dist/realtime_db-BtwBABDY.js.map +1 -0
- package/dist/{router-DlTYWpop.js → router-CiWYeWUR.js} +8 -2
- package/dist/router-CiWYeWUR.js.map +1 -0
- package/dist/src/client/index.d.ts +1 -1
- package/dist/src/client/index.js +44 -5
- package/dist/src/client/index.js.map +1 -1
- package/dist/src/exports/mysql.d.ts +1 -1
- package/dist/src/exports/mysql.js +1 -1
- package/dist/src/exports/postgres.d.ts +1 -1
- package/dist/src/exports/postgres.js +1 -1
- package/dist/src/exports/procedure.d.ts +2 -2
- package/dist/src/exports/procedure.js +4 -4
- package/dist/src/exports/schema-sql.d.ts +36 -2
- package/dist/src/exports/schema-sql.d.ts.map +1 -1
- package/dist/src/exports/schema-sql.js +74 -19
- package/dist/src/exports/schema-sql.js.map +1 -1
- package/dist/src/exports/server.d.ts +65 -17
- package/dist/src/exports/server.d.ts.map +1 -1
- package/dist/src/exports/server.js +724 -63
- package/dist/src/exports/server.js.map +1 -1
- package/dist/src/exports/subscription-manager-worker-entry.js +8 -5
- package/dist/src/exports/subscription-manager-worker-entry.js.map +1 -1
- package/dist/src/exports/types.d.ts +3 -3
- package/dist/src/exports/types.js +1 -1
- package/dist/{subscription-worker-CqoWp6zB.js → subscription-worker-B2XtjFWY.js} +307 -69
- package/dist/subscription-worker-B2XtjFWY.js.map +1 -0
- package/dist/{types_db-DXj_l9n-.js → types_db-CTRm_awX.js} +7 -2
- package/dist/types_db-CTRm_awX.js.map +1 -0
- package/dist/types_server-wW3ZgE7l.d.ts +420 -0
- package/dist/types_server-wW3ZgE7l.d.ts.map +1 -0
- package/package.json +5 -4
- package/dist/index-CaWMDqq0.d.ts +0 -1754
- package/dist/index-CaWMDqq0.d.ts.map +0 -1
- package/dist/index-DouKwYL6.d.ts.map +0 -1
- package/dist/mysql-Bxurg_PH.d.ts.map +0 -1
- package/dist/mysql-Cxd4Uq5p.d.ts +0 -104
- package/dist/mysql-Cxd4Uq5p.d.ts.map +0 -1
- package/dist/mysql-bvnjYWvZ.js.map +0 -1
- package/dist/overlap-checker-Ct_HP_iB.js.map +0 -1
- package/dist/postgres-B8u1YN8X.js.map +0 -1
- package/dist/postgres-CfT_aDx3.d.ts +0 -108
- package/dist/postgres-CfT_aDx3.d.ts.map +0 -1
- package/dist/postgres-Ck-xt72U.d.ts.map +0 -1
- package/dist/procedure-DX87tyef.js.map +0 -1
- package/dist/query-Bh0RNxDz.js.map +0 -1
- package/dist/realtime_db-DOCgqbwi.js.map +0 -1
- package/dist/router-DlTYWpop.js.map +0 -1
- package/dist/src/exports/codegen.d.ts +0 -38
- package/dist/src/exports/codegen.d.ts.map +0 -1
- package/dist/src/exports/codegen.js +0 -134
- package/dist/src/exports/codegen.js.map +0 -1
- package/dist/subscription-worker-CqoWp6zB.js.map +0 -1
- package/dist/subscription-worker-PtmJWEj1.js +0 -511
- package/dist/subscription-worker-PtmJWEj1.js.map +0 -1
- package/dist/subscription-worker-pahX0zxg.js +0 -511
- package/dist/subscription-worker-pahX0zxg.js.map +0 -1
- package/dist/types_db-DXj_l9n-.js.map +0 -1
- package/dist/types_server-BW1ys_SK.d.ts +0 -216
- package/dist/types_server-BW1ys_SK.d.ts.map +0 -1
- package/dist/types_server-Dpsi0wpG.d.ts +0 -216
- package/dist/types_server-Dpsi0wpG.d.ts.map +0 -1
- package/dist/types_server-DzrIccyO.d.ts +0 -216
- package/dist/types_server-DzrIccyO.d.ts.map +0 -1
- package/dist/types_server-TFo6SWDH.d.ts +0 -216
- package/dist/types_server-TFo6SWDH.d.ts.map +0 -1
|
@@ -1,216 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types_server-DzrIccyO.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,cAAsB,IAAA;EAAtB;;;;EAMlB,eAAA;AAAA;AAAA,UAGa,yBAAA;EACb,IAAA;EACA,OAAA;IAAW,GAAA;IAAa,KAAA;IAAe,QAAA;EAAA;EACvC,QAAA,EAAU,cAAc;EACxB,eAAA;EADA;;;;;;AAoBuB;;;;ACxI3B;;EDkII,OAAA;EClIkB;AAAA;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,216 +0,0 @@
|
|
|
1
|
-
import { An as CacheLayer, ar as MutationResult, tt as RegisteredProcedure, wt as SupaliveDb } from "./index-CaWMDqq0.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) => 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-TFo6SWDH.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types_server-TFo6SWDH.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,EAAW,QAAA;EACX,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"}
|