@supatype/client 0.1.0-alpha.10

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 (71) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/.turbo/turbo-test.log +23 -0
  3. package/.turbo/turbo-typecheck.log +4 -0
  4. package/dist/auth.d.ts +279 -0
  5. package/dist/auth.d.ts.map +1 -0
  6. package/dist/auth.js +848 -0
  7. package/dist/auth.js.map +1 -0
  8. package/dist/error-codes-doc.d.ts +31 -0
  9. package/dist/error-codes-doc.d.ts.map +1 -0
  10. package/dist/error-codes-doc.js +294 -0
  11. package/dist/error-codes-doc.js.map +1 -0
  12. package/dist/errors.d.ts +197 -0
  13. package/dist/errors.d.ts.map +1 -0
  14. package/dist/errors.js +162 -0
  15. package/dist/errors.js.map +1 -0
  16. package/dist/fetch-with-retry.d.ts +49 -0
  17. package/dist/fetch-with-retry.d.ts.map +1 -0
  18. package/dist/fetch-with-retry.js +150 -0
  19. package/dist/fetch-with-retry.js.map +1 -0
  20. package/dist/index.d.ts +151 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +285 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/query.d.ts +55 -0
  25. package/dist/query.d.ts.map +1 -0
  26. package/dist/query.js +264 -0
  27. package/dist/query.js.map +1 -0
  28. package/dist/realtime.d.ts +69 -0
  29. package/dist/realtime.d.ts.map +1 -0
  30. package/dist/realtime.js +279 -0
  31. package/dist/realtime.js.map +1 -0
  32. package/dist/retry.d.ts +24 -0
  33. package/dist/retry.d.ts.map +1 -0
  34. package/dist/retry.js +25 -0
  35. package/dist/retry.js.map +1 -0
  36. package/dist/serverless-docs.d.ts +38 -0
  37. package/dist/serverless-docs.d.ts.map +1 -0
  38. package/dist/serverless-docs.js +83 -0
  39. package/dist/serverless-docs.js.map +1 -0
  40. package/dist/storage.d.ts +102 -0
  41. package/dist/storage.d.ts.map +1 -0
  42. package/dist/storage.js +169 -0
  43. package/dist/storage.js.map +1 -0
  44. package/dist/types.d.ts +212 -0
  45. package/dist/types.d.ts.map +1 -0
  46. package/dist/types.js +3 -0
  47. package/dist/types.js.map +1 -0
  48. package/package.json +26 -0
  49. package/src/auth.ts +1024 -0
  50. package/src/error-codes-doc.ts +315 -0
  51. package/src/errors.ts +201 -0
  52. package/src/fetch-with-retry.ts +200 -0
  53. package/src/index.ts +518 -0
  54. package/src/query.ts +331 -0
  55. package/src/realtime.ts +418 -0
  56. package/src/retry.ts +35 -0
  57. package/src/serverless-docs.ts +107 -0
  58. package/src/storage.ts +234 -0
  59. package/src/types.ts +264 -0
  60. package/tests/auth.test.ts +351 -0
  61. package/tests/mfa-totp-integration.test.ts +359 -0
  62. package/tests/query.test.ts +286 -0
  63. package/tests/rate-limit-integration.test.ts +185 -0
  64. package/tests/realtime-multi-tenant-integration.test.ts +372 -0
  65. package/tests/retry-integration.test.ts +212 -0
  66. package/tests/serverless.test.ts +115 -0
  67. package/tests/storage-quota-integration.test.ts +189 -0
  68. package/tests/storage-upload-limit-integration.test.ts +185 -0
  69. package/tests/types.test.ts +137 -0
  70. package/tsconfig.json +11 -0
  71. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,418 @@
1
+ export type RealtimeEvent = "INSERT" | "UPDATE" | "DELETE" | "*"
2
+
3
+ export interface RealtimePayload<TRow> {
4
+ eventType: RealtimeEvent
5
+ new: TRow | null
6
+ old: TRow | null
7
+ schema: string
8
+ table: string
9
+ commitTimestamp: string
10
+ }
11
+
12
+ type RealtimeCallback<TRow> = (payload: RealtimePayload<TRow>) => void
13
+
14
+ export type ChannelStatus = "SUBSCRIBED" | "SUBSCRIBING" | "CLOSED" | "CHANNEL_ERROR" | "TIMED_OUT"
15
+
16
+ interface ChannelSubscription<TRow> {
17
+ on(
18
+ event: "postgres_changes",
19
+ opts: {
20
+ event: RealtimeEvent
21
+ schema?: string | undefined
22
+ table?: string | undefined
23
+ filter?: string | undefined
24
+ },
25
+ callback: RealtimeCallback<TRow>,
26
+ ): ChannelSubscription<TRow>
27
+ /** Listen for presence changes. */
28
+ onPresence(
29
+ callback: (event: { joins: PresenceEntry[]; leaves: PresenceEntry[] }) => void,
30
+ ): ChannelSubscription<TRow>
31
+ /** Listen for broadcast events. */
32
+ onBroadcast(
33
+ event: string,
34
+ callback: (payload: Record<string, unknown>) => void,
35
+ ): ChannelSubscription<TRow>
36
+ /** Subscribe to the channel, opening the WebSocket if needed. */
37
+ subscribe(callback?: ((status: ChannelStatus) => void) | undefined): ChannelSubscription<TRow>
38
+ /** Unsubscribe and clean up. */
39
+ unsubscribe(): void
40
+ /** Send a broadcast event to the channel. */
41
+ broadcast(event: string, payload: Record<string, unknown>): void
42
+ /** Track presence in this channel. */
43
+ track(payload: Record<string, unknown>): void
44
+ /** Stop tracking presence. */
45
+ untrack(): void
46
+ }
47
+
48
+ export interface PresenceEntry {
49
+ user_id: string
50
+ [key: string]: unknown
51
+ }
52
+
53
+ // ─── Server message types (subset matching @supatype/realtime) ───────────────
54
+
55
+ interface ServerChangeMessage {
56
+ type: "change"
57
+ channel: string
58
+ event: "INSERT" | "UPDATE" | "DELETE"
59
+ payload: { old: Record<string, unknown> | null; new: Record<string, unknown> | null }
60
+ timestamp: string
61
+ }
62
+
63
+ interface ServerPresenceMessage {
64
+ type: "presence"
65
+ channel: string
66
+ joins: PresenceEntry[]
67
+ leaves: PresenceEntry[]
68
+ }
69
+
70
+ interface ServerBroadcastMessage {
71
+ type: "broadcast"
72
+ channel: string
73
+ event: string
74
+ payload: Record<string, unknown>
75
+ }
76
+
77
+ interface ServerSystemMessage {
78
+ type: "system"
79
+ status: "ok" | "error"
80
+ message: string
81
+ }
82
+
83
+ type ServerMessage = ServerChangeMessage | ServerPresenceMessage | ServerBroadcastMessage | ServerSystemMessage
84
+
85
+ // ─── Realtime client ─────────────────────────────────────────────────────────
86
+
87
+ export class RealtimeClient {
88
+ private readonly url: string
89
+ private readonly headers: Record<string, string>
90
+ private ws: WebSocket | null = null
91
+ private channels = new Map<string, ChannelState>()
92
+ private reconnectTimer: ReturnType<typeof setTimeout> | null = null
93
+ private reconnectAttempts = 0
94
+ private maxReconnectAttempts = 10
95
+ private baseReconnectDelay = 1000
96
+
97
+ constructor(url: string, headers: Record<string, string>) {
98
+ // Convert http(s) URL to ws(s) URL
99
+ this.url = url.replace(/^http/, "ws")
100
+ this.headers = headers
101
+ }
102
+
103
+ channel<TRow = Record<string, unknown>>(name: string): ChannelSubscription<TRow> {
104
+ const state = this.getOrCreateChannel(name)
105
+
106
+ const sub: ChannelSubscription<TRow> = {
107
+ on(_event, opts, callback) {
108
+ state.pgListeners.push({
109
+ event: opts.event,
110
+ schema: opts.schema ?? "public",
111
+ table: opts.table ?? name.split(":").pop() ?? name,
112
+ filter: opts.filter,
113
+ callback: callback as RealtimeCallback<Record<string, unknown>>,
114
+ })
115
+ return sub
116
+ },
117
+
118
+ onPresence(callback) {
119
+ state.presenceListeners.push(callback)
120
+ return sub
121
+ },
122
+
123
+ onBroadcast(event, callback) {
124
+ if (!state.broadcastListeners.has(event)) {
125
+ state.broadcastListeners.set(event, [])
126
+ }
127
+ state.broadcastListeners.get(event)!.push(callback)
128
+ return sub
129
+ },
130
+
131
+ subscribe: (callback) => {
132
+ state.statusCallback = callback ?? null
133
+ this.ensureConnection()
134
+ this.sendSubscribe(state)
135
+ return sub
136
+ },
137
+
138
+ unsubscribe: () => {
139
+ this.sendUnsubscribe(state)
140
+ this.channels.delete(name)
141
+ // Close WebSocket if no channels left
142
+ if (this.channels.size === 0) {
143
+ this.disconnect()
144
+ }
145
+ },
146
+
147
+ broadcast: (event, payload) => {
148
+ this.sendMessage({
149
+ type: "broadcast",
150
+ channel: name,
151
+ event,
152
+ payload,
153
+ })
154
+ },
155
+
156
+ track: (payload) => {
157
+ this.sendMessage({
158
+ type: "presence_track",
159
+ channel: name,
160
+ payload,
161
+ })
162
+ },
163
+
164
+ untrack: () => {
165
+ this.sendMessage({
166
+ type: "presence_untrack",
167
+ channel: name,
168
+ })
169
+ },
170
+ }
171
+
172
+ return sub
173
+ }
174
+
175
+ /** Remove a channel by name. */
176
+ removeChannel(name: string): void {
177
+ const state = this.channels.get(name)
178
+ if (state) {
179
+ this.sendUnsubscribe(state)
180
+ this.channels.delete(name)
181
+ }
182
+ if (this.channels.size === 0) {
183
+ this.disconnect()
184
+ }
185
+ }
186
+
187
+ /** Disconnect the WebSocket entirely. */
188
+ disconnect(): void {
189
+ if (this.reconnectTimer) {
190
+ clearTimeout(this.reconnectTimer)
191
+ this.reconnectTimer = null
192
+ }
193
+ if (this.ws) {
194
+ this.ws.close(1000, "client disconnect")
195
+ this.ws = null
196
+ }
197
+ this.reconnectAttempts = 0
198
+ }
199
+
200
+ // ─── Internal ──────────────────────────────────────────────────────────
201
+
202
+ private getOrCreateChannel(name: string): ChannelState {
203
+ let state = this.channels.get(name)
204
+ if (!state) {
205
+ state = {
206
+ name,
207
+ pgListeners: [],
208
+ presenceListeners: [],
209
+ broadcastListeners: new Map(),
210
+ statusCallback: null,
211
+ subscribed: false,
212
+ }
213
+ this.channels.set(name, state)
214
+ }
215
+ return state
216
+ }
217
+
218
+ private ensureConnection(): void {
219
+ if (this.ws && (this.ws.readyState === WebSocket.OPEN || this.ws.readyState === WebSocket.CONNECTING)) {
220
+ return
221
+ }
222
+
223
+ // Build URL with token from apikey header
224
+ const token = this.headers["apikey"] ?? this.headers["Authorization"]?.replace("Bearer ", "")
225
+ const wsUrl = token ? `${this.url}?token=${encodeURIComponent(token)}` : this.url
226
+
227
+ this.ws = new WebSocket(wsUrl)
228
+
229
+ this.ws.onopen = () => {
230
+ this.reconnectAttempts = 0
231
+ // Re-subscribe all channels
232
+ for (const state of this.channels.values()) {
233
+ if (!state.subscribed) {
234
+ this.sendSubscribe(state)
235
+ }
236
+ }
237
+ }
238
+
239
+ this.ws.onmessage = (event) => {
240
+ try {
241
+ const msg = JSON.parse(String(event.data)) as ServerMessage
242
+ this.handleServerMessage(msg)
243
+ } catch {
244
+ // Ignore unparseable messages
245
+ }
246
+ }
247
+
248
+ this.ws.onclose = () => {
249
+ this.ws = null
250
+ // Mark all channels as unsubscribed
251
+ for (const state of this.channels.values()) {
252
+ state.subscribed = false
253
+ }
254
+ // Attempt reconnection with exponential backoff
255
+ if (this.channels.size > 0) {
256
+ this.scheduleReconnect()
257
+ }
258
+ }
259
+
260
+ this.ws.onerror = () => {
261
+ // onclose will fire after onerror
262
+ }
263
+ }
264
+
265
+ private scheduleReconnect(): void {
266
+ if (this.reconnectAttempts >= this.maxReconnectAttempts) {
267
+ for (const state of this.channels.values()) {
268
+ state.statusCallback?.("TIMED_OUT")
269
+ }
270
+ return
271
+ }
272
+
273
+ const delay = this.baseReconnectDelay * Math.pow(2, this.reconnectAttempts)
274
+ this.reconnectAttempts++
275
+
276
+ for (const state of this.channels.values()) {
277
+ state.statusCallback?.("SUBSCRIBING")
278
+ }
279
+
280
+ this.reconnectTimer = setTimeout(() => {
281
+ this.ensureConnection()
282
+ }, delay)
283
+ }
284
+
285
+ private handleServerMessage(msg: ServerMessage): void {
286
+ switch (msg.type) {
287
+ case "system":
288
+ this.handleSystem(msg)
289
+ break
290
+ case "change":
291
+ this.handleChange(msg)
292
+ break
293
+ case "presence":
294
+ this.handlePresence(msg)
295
+ break
296
+ case "broadcast":
297
+ this.handleBroadcastMsg(msg)
298
+ break
299
+ }
300
+ }
301
+
302
+ private handleSystem(msg: ServerSystemMessage): void {
303
+ // When server confirms subscription
304
+ if (msg.status === "ok" && msg.message.startsWith("subscribed to ")) {
305
+ const channel = msg.message.replace("subscribed to ", "")
306
+ const state = this.channels.get(channel)
307
+ if (state) {
308
+ state.subscribed = true
309
+ state.statusCallback?.("SUBSCRIBED")
310
+ }
311
+ }
312
+
313
+ if (msg.status === "error") {
314
+ // Find which channel this error relates to — broadcast to all as fallback
315
+ for (const state of this.channels.values()) {
316
+ state.statusCallback?.("CHANNEL_ERROR")
317
+ }
318
+ }
319
+ }
320
+
321
+ private handleChange(msg: ServerChangeMessage): void {
322
+ const state = this.channels.get(msg.channel)
323
+ if (!state) return
324
+
325
+ // Parse channel to get schema/table
326
+ const parts = msg.channel.split(":")
327
+ const schema = parts.length >= 2 ? parts[0]! : "public"
328
+ const table = parts.length >= 2 ? parts[1]! : parts[0]!
329
+
330
+ const payload: RealtimePayload<Record<string, unknown>> = {
331
+ eventType: msg.event,
332
+ new: msg.payload.new,
333
+ old: msg.payload.old,
334
+ schema,
335
+ table,
336
+ commitTimestamp: msg.timestamp,
337
+ }
338
+
339
+ for (const listener of state.pgListeners) {
340
+ if (listener.event !== "*" && listener.event !== msg.event) continue
341
+ listener.callback(payload)
342
+ }
343
+ }
344
+
345
+ private handlePresence(msg: ServerPresenceMessage): void {
346
+ const state = this.channels.get(msg.channel)
347
+ if (!state) return
348
+
349
+ for (const listener of state.presenceListeners) {
350
+ listener({ joins: msg.joins, leaves: msg.leaves })
351
+ }
352
+ }
353
+
354
+ private handleBroadcastMsg(msg: ServerBroadcastMessage): void {
355
+ const state = this.channels.get(msg.channel)
356
+ if (!state) return
357
+
358
+ const listeners = state.broadcastListeners.get(msg.event)
359
+ if (listeners) {
360
+ for (const listener of listeners) {
361
+ listener(msg.payload)
362
+ }
363
+ }
364
+ }
365
+
366
+ private sendSubscribe(state: ChannelState): void {
367
+ if (!this.ws || this.ws.readyState !== WebSocket.OPEN) return
368
+
369
+ // Build filter from the first pg listener (if any)
370
+ const firstListener = state.pgListeners[0]
371
+ const filter: Record<string, string> = {}
372
+ if (firstListener?.filter) {
373
+ // Parse PostgREST filter format "column=eq.value" into { column: "eq.value" }
374
+ for (const part of firstListener.filter.split(",")) {
375
+ const eqIdx = part.indexOf("=")
376
+ if (eqIdx > 0) {
377
+ filter[part.slice(0, eqIdx)] = part.slice(eqIdx + 1)
378
+ }
379
+ }
380
+ }
381
+
382
+ this.sendMessage({
383
+ type: "subscribe",
384
+ channel: state.name,
385
+ event: firstListener?.event ?? "*",
386
+ filter: Object.keys(filter).length > 0 ? filter : undefined,
387
+ })
388
+ }
389
+
390
+ private sendUnsubscribe(state: ChannelState): void {
391
+ this.sendMessage({ type: "unsubscribe", channel: state.name })
392
+ }
393
+
394
+ private sendMessage(msg: Record<string, unknown>): void {
395
+ if (this.ws && this.ws.readyState === WebSocket.OPEN) {
396
+ this.ws.send(JSON.stringify(msg))
397
+ }
398
+ }
399
+ }
400
+
401
+ // ─── Internal types ──────────────────────────────────────────────────────────
402
+
403
+ interface PgListener {
404
+ event: RealtimeEvent
405
+ schema: string
406
+ table: string
407
+ filter: string | undefined
408
+ callback: RealtimeCallback<Record<string, unknown>>
409
+ }
410
+
411
+ interface ChannelState {
412
+ name: string
413
+ pgListeners: PgListener[]
414
+ presenceListeners: Array<(event: { joins: PresenceEntry[]; leaves: PresenceEntry[] }) => void>
415
+ broadcastListeners: Map<string, Array<(payload: Record<string, unknown>) => void>>
416
+ statusCallback: ((status: ChannelStatus) => void) | null
417
+ subscribed: boolean
418
+ }
package/src/retry.ts ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Retry configuration module.
3
+ *
4
+ * Re-exports the core fetchWithRetry and provides a factory that binds
5
+ * client-level retry/timeout options so callers don't repeat them.
6
+ */
7
+
8
+ import { fetchWithRetry, type FetchOptions } from "./fetch-with-retry.js"
9
+
10
+ export type { FetchOptions } from "./fetch-with-retry.js"
11
+
12
+ export interface RetryConfig {
13
+ /** Disable automatic retry. When false, no retries are attempted. */
14
+ retry?: boolean | undefined
15
+ /** Request timeout in milliseconds. Default: 30000. */
16
+ timeout?: number | undefined
17
+ }
18
+
19
+ /**
20
+ * Create a fetch function pre-configured with client-level retry/timeout.
21
+ *
22
+ * ```ts
23
+ * const doFetch = createRetryFetch({ retry: true, timeout: 10000 })
24
+ * const res = await doFetch('https://api.example.com/data', { method: 'GET' })
25
+ * ```
26
+ */
27
+ export function createRetryFetch(config: RetryConfig) {
28
+ return (url: string, init?: RequestInit & Partial<FetchOptions>): Promise<Response> => {
29
+ return fetchWithRetry(url, {
30
+ ...init,
31
+ retry: init?.retry ?? config.retry,
32
+ timeout: init?.timeout ?? config.timeout,
33
+ })
34
+ }
35
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Serverless connection documentation — Gap Appendices task 84
3
+ *
4
+ * Code-accessible documentation for connection modes.
5
+ * Rendered in Studio's getting-started view and available to CLI help output.
6
+ */
7
+
8
+ export interface ConnectionModeDoc {
9
+ /** Short label for this mode. */
10
+ label: string
11
+ /** When to use this mode (environment/context). */
12
+ recommended: string
13
+ /** Whether this mode is safe in serverless contexts. */
14
+ serverlessSafe: boolean
15
+ /** How it handles connection pooling. */
16
+ pooling: string
17
+ /** Brief description. */
18
+ description: string
19
+ /** Example code snippet (TypeScript). */
20
+ example: string
21
+ }
22
+
23
+ /**
24
+ * Documents the two primary ways to connect to a Supatype project,
25
+ * with clear guidance on serverless vs. long-lived server environments.
26
+ */
27
+ export const CONNECTION_MODES: readonly ConnectionModeDoc[] = [
28
+ {
29
+ label: "Supatype SDK (via PostgREST)",
30
+ recommended: "Serverless environments: Next.js API routes, Vercel Edge Functions, AWS Lambda, Cloudflare Workers, Deno Deploy",
31
+ serverlessSafe: true,
32
+ pooling: "PostgREST maintains a persistent connection pool to Postgres. Each SDK request is an HTTP call that reuses an existing database connection from the pool.",
33
+ description:
34
+ "Use the Supatype SDK in serverless environments. PostgREST handles connection pooling for you. " +
35
+ "Each serverless invocation makes an HTTP request to PostgREST, which maps it to a pre-established " +
36
+ "database connection. This avoids the connection-per-invocation problem entirely.",
37
+ example: [
38
+ 'import { createClient } from "@supatype/client"',
39
+ "",
40
+ "const client = createClient(process.env.SUPATYPE_URL!, process.env.SUPATYPE_ANON_KEY!)",
41
+ "",
42
+ "// Safe in serverless — each call is an HTTP request, not a new DB connection",
43
+ "const users = await client.from(\"users\").select()",
44
+ ].join("\n"),
45
+ },
46
+ {
47
+ label: "Direct database connection",
48
+ recommended: "Long-lived servers: Express/Fastify/Hono on a VM or container, background workers, migration scripts, CLI tools",
49
+ serverlessSafe: false,
50
+ pooling: "Each new connection opens a TCP socket to Postgres. In serverless, each invocation creates a new connection that is never reused, exhausting the connection pool within seconds under load.",
51
+ description:
52
+ "Do NOT use direct database connections from serverless environments. " +
53
+ "Each invocation opens a new connection, which will exhaust your connection pool " +
54
+ "within seconds under load. Direct connections are only appropriate for long-lived " +
55
+ "server processes that open a connection once and reuse it across many requests.",
56
+ example: [
57
+ '// ONLY for long-lived servers — NOT for serverless',
58
+ 'import pg from "pg"',
59
+ "",
60
+ "const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL })",
61
+ "",
62
+ "// Connection is reused across requests in a long-lived process",
63
+ "const result = await pool.query(\"SELECT * FROM users\")",
64
+ ].join("\n"),
65
+ },
66
+ ] as const
67
+
68
+ /**
69
+ * A short, actionable warning suitable for display in Studio banners,
70
+ * CLI output, and getting-started guides.
71
+ */
72
+ export const SERVERLESS_CONNECTION_WARNING =
73
+ "Use the Supatype SDK (via PostgREST) in serverless environments (Next.js API routes, " +
74
+ "Vercel Edge Functions, AWS Lambda). PostgREST handles connection pooling for you. " +
75
+ "Do NOT use direct database connections from serverless — each invocation opens a new " +
76
+ "connection, which will exhaust your connection pool within seconds under load."
77
+
78
+ /**
79
+ * Structured FAQ entries for the connection modes documentation.
80
+ */
81
+ export const CONNECTION_FAQ: ReadonlyArray<{ question: string; answer: string }> = [
82
+ {
83
+ question: "Can I use Prisma/Drizzle/Knex in serverless?",
84
+ answer:
85
+ "These ORMs require a direct database connection. In serverless, use the Supatype SDK instead. " +
86
+ "If you must use an ORM, deploy it on a long-lived server (container, VM) or use a connection " +
87
+ "pooler like PgBouncer in transaction mode.",
88
+ },
89
+ {
90
+ question: "What about Edge Functions?",
91
+ answer:
92
+ "Edge Functions (Vercel Edge, Cloudflare Workers) are serverless. Use the Supatype SDK. " +
93
+ "Direct TCP connections are not available in most edge runtimes anyway.",
94
+ },
95
+ {
96
+ question: "How many connections does PostgREST use?",
97
+ answer:
98
+ "PostgREST maintains a configurable pool (default: 10 connections). All incoming HTTP requests " +
99
+ "share this pool, so even thousands of concurrent SDK requests only use 10 database connections.",
100
+ },
101
+ {
102
+ question: "When should I use a direct connection?",
103
+ answer:
104
+ "Use direct connections for: migration scripts, long-lived API servers (Express, Fastify), " +
105
+ "background job processors, and CLI tooling. These processes start once and reuse connections.",
106
+ },
107
+ ]