@voltro/sql-postgres 0.55.0 → 0.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
1
  import { PgClient as e, PgClient as t } from "@effect/sql-pg";
2
2
  import { Config as n, Duration as r, Effect as i, Fiber as a, Layer as o, ManagedRuntime as s, Metric as c, Option as l, Redacted as u, Schedule as d, Stream as f } from "effect";
3
3
  import p from "pg";
4
- import { DEFAULT_ACQUIRE_TIMEOUT_MS as m, EagerCardinalityError as h, attachEagerLoads as g, attributionFields as ee, attributionKey as te, beginLocalWrite as ne, bulkInsertLimitsFor as re, chunkRowsForInsert as ie, compileEagerJson as ae, compilePredicate as _, compileRawFragment as oe, compileSelect as se, encodeRowForSchema as v, endLocalWrite as ce, externalChangeEvent as le, hasEagerLoads as ue, isTableReactive as y, makeEagerFallbackReporter as de, observeDbOp as b, raiseChangeListenerCeiling as fe, recordsTable as x, registerPendingAttribution as S, requireTable as C, resolveEchoAttribution as w, runRetryingTransaction as pe, runStoreTransaction as T, runWriteRecorders as me, stampGeneratedId as E, stampGeneratedIds as he, withCapturedAttribution as D } from "@voltro/database";
5
- import { EventEmitter as ge } from "node:events";
6
- import { createLogger as _e } from "@voltro/logger";
7
- import { SqlClient as O, TransactionConnection as k } from "@effect/sql/SqlClient";
4
+ import { DEFAULT_ACQUIRE_TIMEOUT_MS as m, EagerCardinalityError as h, attachEagerLoads as g, attributionFields as ee, attributionKey as te, beginLocalWrite as ne, bulkInsertLimitsFor as re, chunkRowsForInsert as ie, compileEagerJson as ae, compilePredicate as _, compileRawFragment as oe, compileSelect as se, encodeRowForSchema as v, endLocalWrite as ce, externalChangeEvent as le, hasEagerLoads as ue, isTableReactive as y, makeEagerFallbackReporter as de, observeDbOp as b, raiseChangeListenerCeiling as fe, recordsTable as x, registerPendingAttribution as pe, requireTable as me, resolveEchoAttribution as he, runRetryingTransaction as ge, runStoreTransaction as S, runWriteRecorders as _e, stampGeneratedId as C, stampGeneratedIds as ve, withCapturedAttribution as w } from "@voltro/database";
5
+ import { EventEmitter as ye } from "node:events";
6
+ import { createLogger as be } from "@voltro/logger";
7
+ import { SqlClient as T, TransactionConnection as E } from "@effect/sql/SqlClient";
8
8
  //#region src/sqlLayer.ts
9
- var A = (e) => {
9
+ var D = (e) => {
10
10
  let t = e.acquireTimeoutMs ?? m;
11
11
  return t > 0 ? t : void 0;
12
- }, j = (e) => e ? { rejectUnauthorized: !1 } : !1, M = /^[A-Za-z_][A-Za-z0-9_]*$/, N = (e) => {
13
- let t = A(e);
12
+ }, O = (e) => e ? { rejectUnauthorized: !1 } : !1, k = /^[A-Za-z_][A-Za-z0-9_]*$/, xe = (e) => {
13
+ let t = D(e);
14
14
  return {
15
15
  host: n.succeed(e.host),
16
16
  port: n.succeed(e.port),
@@ -18,30 +18,30 @@ var A = (e) => {
18
18
  password: n.succeed(u.make(e.password)),
19
19
  database: n.succeed(e.database),
20
20
  ...e.maxConnections === void 0 ? {} : { maxConnections: n.succeed(e.maxConnections) },
21
- ...e.ssl === void 0 ? {} : { ssl: n.succeed(j(e.ssl)) },
21
+ ...e.ssl === void 0 ? {} : { ssl: n.succeed(O(e.ssl)) },
22
22
  ...t === void 0 ? {} : { connectTimeout: n.succeed(r.millis(t)) }
23
23
  };
24
- }, P = (t) => {
25
- if (t.schema === void 0 && t.statementTimeoutMs === void 0) return e.layerConfig(N(t));
24
+ }, A = (t) => {
25
+ if (t.schema === void 0 && t.statementTimeoutMs === void 0) return e.layerConfig(xe(t));
26
26
  let n = {};
27
27
  if (t.schema !== void 0) {
28
- if (!M.test(t.schema)) throw Error(`DB_SCHEMA '${t.schema}' is not a valid postgres identifier (expected ${M}).`);
28
+ if (!k.test(t.schema)) throw Error(`DB_SCHEMA '${t.schema}' is not a valid postgres identifier (expected ${k}).`);
29
29
  n = { options: `-c search_path="${t.schema}"` };
30
30
  }
31
- let r = A(t), a = i.acquireRelease(i.sync(() => new p.Pool({
31
+ let r = D(t), a = i.acquireRelease(i.sync(() => new p.Pool({
32
32
  host: t.host,
33
33
  port: t.port,
34
34
  user: t.username,
35
35
  password: t.password,
36
36
  database: t.database,
37
37
  ...t.maxConnections === void 0 ? {} : { max: t.maxConnections },
38
- ...t.ssl === void 0 ? {} : { ssl: j(t.ssl) },
38
+ ...t.ssl === void 0 ? {} : { ssl: O(t.ssl) },
39
39
  ...t.statementTimeoutMs === void 0 ? {} : { statement_timeout: t.statementTimeoutMs },
40
40
  ...r === void 0 ? {} : { connectionTimeoutMillis: r },
41
41
  ...n
42
42
  })), (e) => i.promise(() => e.end()));
43
43
  return e.layerFromPool({ acquire: a });
44
- }, F = (e) => {
44
+ }, Se = (e) => {
45
45
  let t = e.get("sslmode");
46
46
  if (t !== null) {
47
47
  if (t === "require") return !0;
@@ -54,10 +54,10 @@ var A = (e) => {
54
54
  if (n === "false" || n === "0") return !1;
55
55
  throw Error(`DB_URL '?ssl=${n}' is not supported by the postgres dialect — use 'true'/'1' or 'false'/'0'.`);
56
56
  }
57
- }, I = (e) => {
57
+ }, j = (e) => {
58
58
  let t = e.schema === void 0 ? {} : { schema: e.schema }, n = e.acquireTimeoutMs === void 0 ? {} : { acquireTimeoutMs: e.acquireTimeoutMs };
59
59
  if (e.url) {
60
- let r = new URL(e.url), i = e.ssl ?? F(r.searchParams);
60
+ let r = new URL(e.url), i = e.ssl ?? Se(r.searchParams);
61
61
  return {
62
62
  host: r.hostname || "localhost",
63
63
  port: r.port ? Number(r.port) : 5432,
@@ -83,7 +83,21 @@ var A = (e) => {
83
83
  ...n,
84
84
  ...t
85
85
  };
86
- }, L = (e) => P(I(e)), R = /* @__PURE__ */ new Set(["40001", "40P01"]), ve = (e) => {
86
+ }, M = (e) => A(j(e)), N = {
87
+ idleMs: 2e4,
88
+ timeoutMs: 1e4
89
+ }, P = (e, t, n = N) => e.probeSentAtMs === null ? t - e.lastHeardAtMs >= n.idleMs ? "probe" : "healthy" : e.lastHeardAtMs > e.probeSentAtMs ? "healthy" : t - e.probeSentAtMs >= n.timeoutMs ? "reconnect" : "healthy", F = "__voltro_cdc_heartbeat", I = (e) => JSON.stringify({ [F]: e }), Ce = (e) => typeof e == "object" && !!e && "__voltro_cdc_heartbeat" in e, L = (e) => Math.min(250 * 2 ** Math.min(e - 1, 6), 1e4), R = (e = process.env, t = {}) => {
90
+ let n = (t, n) => {
91
+ let r = e[t];
92
+ if (r === void 0) return n;
93
+ let i = Number(r);
94
+ return Number.isFinite(i) && i > 0 ? i : n;
95
+ };
96
+ return {
97
+ idleMs: t.idleMs ?? n("VOLTRO_CDC_HEARTBEAT_MS", N.idleMs),
98
+ timeoutMs: t.timeoutMs ?? n("VOLTRO_CDC_HEARTBEAT_TIMEOUT_MS", N.timeoutMs)
99
+ };
100
+ }, we = /* @__PURE__ */ new Set(["40001", "40P01"]), Te = (e) => {
87
101
  let t = e;
88
102
  for (let e = 0; e < 5 && typeof t == "object" && t; e++) {
89
103
  let e = t.code;
@@ -91,15 +105,15 @@ var A = (e) => {
91
105
  t = t.cause;
92
106
  }
93
107
  }, z = (e) => {
94
- let t = ve(e);
95
- return t !== void 0 && R.has(t);
96
- }, B = (e) => z(e) ? "retry" : "noRetry", V = c.counter("voltro_cdc_oversized_total", { description: "Change events whose row images exceeded the postgres NOTIFY payload cap, by what re-hydration recovered (rehydrated = row re-read · tombstone = delete, primary key only · unrecovered = content lost to taps)." }), ye = {
108
+ let t = Te(e);
109
+ return t !== void 0 && we.has(t);
110
+ }, B = (e) => z(e) ? "retry" : "noRetry", V = c.counter("voltro_cdc_oversized_total", { description: "Change events whose row images exceeded the postgres NOTIFY payload cap, by what re-hydration recovered (rehydrated = row re-read · tombstone = delete, primary key only · unrecovered = content lost to taps)." }), Ee = {
97
111
  rehydrated: c.tagged(V, "outcome", "rehydrated"),
98
112
  tombstone: c.tagged(V, "outcome", "tombstone"),
99
113
  unrecovered: c.tagged(V, "outcome", "unrecovered")
100
114
  }, H = (e) => {
101
- i.runSync(c.increment(ye[e]));
102
- }, be = {
115
+ i.runSync(c.increment(Ee[e]));
116
+ }, De = {
103
117
  rehydrateTimeoutMs: 5e3,
104
118
  rehydrateRetries: 2
105
119
  }, U = (e) => {
@@ -108,12 +122,12 @@ var A = (e) => {
108
122
  let n = Number(t);
109
123
  return Number.isFinite(n) && n >= 0 ? n : void 0;
110
124
  }, W = (e) => {
111
- let t = be, n = e ?? {};
125
+ let t = De, n = e ?? {};
112
126
  return {
113
127
  rehydrateTimeoutMs: Math.max(1, n.rehydrateTimeoutMs ?? U("VOLTRO_CDC_REHYDRATE_TIMEOUT_MS") ?? t.rehydrateTimeoutMs),
114
128
  rehydrateRetries: Math.max(0, n.rehydrateRetries ?? U("VOLTRO_CDC_REHYDRATE_RETRIES") ?? t.rehydrateRetries)
115
129
  };
116
- }, xe = (e) => i.suspend(() => {
130
+ }, Oe = (e) => i.suspend(() => {
117
131
  let t = e.notification, n = t.id, a = {
118
132
  table: t.table,
119
133
  op: t.op
@@ -155,7 +169,7 @@ var A = (e) => {
155
169
  },
156
170
  outcome: "rehydrated"
157
171
  })), i.catchAllCause(() => (H("unrecovered"), i.succeed(o("read-failed")))));
158
- }), Se = (e) => {
172
+ }), ke = (e) => {
159
173
  let t = /* @__PURE__ */ new Set();
160
174
  return (n, r) => {
161
175
  if (r.outcome === "unrecovered") {
@@ -173,25 +187,33 @@ var A = (e) => {
173
187
  note: r.outcome === "tombstone" ? "a delete of an oversized row delivers the primary key only — the pre-image is unrecoverable" : "the re-read returns the row as it is NOW, not the image at commit"
174
188
  }));
175
189
  };
176
- }, G = ["json"], K = _e({ scope: "voltro:postgres" }), q = async (e) => {
177
- let t = e.tracerLayer ? o.mergeAll(e.sqlLayer, e.tracerLayer) : e.sqlLayer, n = s.make(t), r = await n.runPromise(O), i = e.changeStrategy ?? "inline", a = new Ce(r, n, i, e.cdcChannel ?? "framework_changes", W({
190
+ }, G = ["json"], K = be({ scope: "voltro:postgres" }), q = async (e) => {
191
+ let t = e.tracerLayer ? o.mergeAll(e.sqlLayer, e.tracerLayer) : e.sqlLayer, n = s.make(t), r = await n.runPromise(T), i = e.changeStrategy ?? "inline", a = new Ae(r, n, i, e.cdcChannel ?? "framework_changes", W({
178
192
  ...e.cdcRehydrateTimeoutMs === void 0 ? {} : { rehydrateTimeoutMs: e.cdcRehydrateTimeoutMs },
179
193
  ...e.cdcRehydrateRetries === void 0 ? {} : { rehydrateRetries: e.cdcRehydrateRetries }
180
194
  }));
181
195
  return i === "cdc" && await a.startCdcConsumer(), a;
182
- }, Ce = class {
196
+ }, Ae = class {
183
197
  sql;
184
198
  runtime;
185
199
  changeStrategy;
186
200
  cdcChannel;
187
201
  cdcRehydrate;
188
- emitter = new ge();
202
+ cdcLiveness;
203
+ emitter = new ye();
189
204
  cdcFiber = null;
205
+ cdcWatchdog = null;
206
+ cdcLastHeardAt = 0;
207
+ cdcHeardCount = 0;
208
+ cdcProbeSentAt = null;
209
+ cdcReconnecting = !1;
210
+ cdcStopped = !1;
211
+ cdcGapListeners = /* @__PURE__ */ new Set();
190
212
  inflightTxns = 0;
191
- reportOversized = Se(K);
213
+ reportOversized = ke(K);
192
214
  reportEagerFallback = de(K);
193
- constructor(e, t, n, r, i = W()) {
194
- this.sql = e, this.runtime = t, this.changeStrategy = n, this.cdcChannel = r, this.cdcRehydrate = i, fe(this.emitter);
215
+ constructor(e, t, n, r, i = W(), a = R()) {
216
+ this.sql = e, this.runtime = t, this.changeStrategy = n, this.cdcChannel = r, this.cdcRehydrate = i, this.cdcLiveness = a, fe(this.emitter);
195
217
  }
196
218
  txnSpec(e, t, n) {
197
219
  return {
@@ -210,15 +232,15 @@ var A = (e) => {
210
232
  };
211
233
  }
212
234
  withNamespace(e) {
213
- return e === null ? this : new we(this, e);
235
+ return e === null ? this : new je(this, e);
214
236
  }
215
237
  async runInNamespace(e, t) {
216
238
  let n = this.sql;
217
239
  this.inflightTxns++;
218
240
  try {
219
- return await T({
241
+ return await S({
220
242
  ...this.txnSpec("PostgresDataStore.runInNamespace", "store.namespace", "namespace.transaction"),
221
- prepare: (t) => i.provideService(n`SET LOCAL search_path TO ${n(e)}`, k, t),
243
+ prepare: (t) => i.provideService(n`SET LOCAL search_path TO ${n(e)}`, E, t),
222
244
  work: t,
223
245
  makeView: (e, t) => new J(this, e, t)
224
246
  });
@@ -228,12 +250,12 @@ var A = (e) => {
228
250
  }
229
251
  __postgresReplicationFriend = { runEffect: (e) => this.runtime.runPromise(e) };
230
252
  async executeQuery(e, t, n = null) {
231
- let r = se(e, this.sql, n), a = t ? i.provideService(r, k, t) : r;
253
+ let r = se(e, this.sql, n), a = t ? i.provideService(r, E, t) : r;
232
254
  return b("postgres", "select", () => this.runtime.runPromise(a));
233
255
  }
234
256
  async executeInsert(e, t, n, r, a) {
235
- t = E(e, t);
236
- let o = this.sql, s = o`INSERT INTO ${o(e)} ${o.insert(v(t, e, G))} RETURNING *`, c = n ? i.provideService(s, k, n) : s, l = (await this.runtime.runPromise(c))[0];
257
+ t = C(e, t);
258
+ let o = this.sql, s = o`INSERT INTO ${o(e)} ${o.insert(v(t, e, G))} RETURNING *`, c = n ? i.provideService(s, E, n) : s, l = (await this.runtime.runPromise(c))[0];
237
259
  if (!l) throw Error(`PostgresDataStore.insert: no row returned for table '${e}'`);
238
260
  return await this.routeEvent({
239
261
  table: e,
@@ -243,7 +265,7 @@ var A = (e) => {
243
265
  }, r, n, a), l;
244
266
  }
245
267
  async executeUpdate(e, t, n, r, a, o) {
246
- let s = this.sql, c = s`UPDATE ${s(e)} SET ${s.update(v(n, e, G))} WHERE ${s("id")} = ${t} RETURNING *`, l = r ? i.provideService(c, k, r) : c, u = (await this.runtime.runPromise(l))[0];
268
+ let s = this.sql, c = s`UPDATE ${s(e)} SET ${s.update(v(n, e, G))} WHERE ${s("id")} = ${t} RETURNING *`, l = r ? i.provideService(c, E, r) : c, u = (await this.runtime.runPromise(l))[0];
247
269
  return u ? (await this.routeEvent({
248
270
  table: e,
249
271
  op: "update",
@@ -252,17 +274,17 @@ var A = (e) => {
252
274
  }, a, r, o), u) : null;
253
275
  }
254
276
  async executeUpsert(e, t, n, r, a, o) {
255
- t = E(e, t);
277
+ t = C(e, t);
256
278
  let s = this.sql;
257
279
  if (typeof n.update == "function") {
258
280
  let o = n.update, c = n.conflictColumns.map((e) => s`${s(e)} = ${t[e]}`), l = (n) => {
259
281
  let r = s`SELECT * FROM ${s(e)} WHERE ${s.and(c)} LIMIT 1 FOR UPDATE`;
260
- return this.runtime.runPromise(i.flatMap(i.provideService(r, k, n), (r) => i.promise(() => r[0] ? this.executeUpdate(e, r[0].id, o(r[0]), n, a).then((e) => e) : this.executeInsert(e, t, n, a))));
282
+ return this.runtime.runPromise(i.flatMap(i.provideService(r, E, n), (r) => i.promise(() => r[0] ? this.executeUpdate(e, r[0].id, o(r[0]), n, a).then((e) => e) : this.executeInsert(e, t, n, a))));
261
283
  };
262
284
  if (r) return l(r);
263
285
  this.inflightTxns++;
264
286
  try {
265
- return await pe({
287
+ return await ge({
266
288
  ...this.txnSpec("PostgresDataStore.upsert", "store.upsert", "upsert.transaction"),
267
289
  body: (e) => l(e)
268
290
  });
@@ -270,7 +292,7 @@ var A = (e) => {
270
292
  this.inflightTxns--;
271
293
  }
272
294
  }
273
- let c = n.conflictColumns.map((e) => s`${s(e)}`), l = Object.keys(t).filter((e) => t[e] !== void 0), u = n.update === void 0 ? l.filter((e) => e !== "id" && !n.conflictColumns.includes(e)) : n.update, d = u.length > 0 ? s.csv(u.map((e) => s`${s(e)} = EXCLUDED.${s(e)}`)) : s`${s(n.conflictColumns[0])} = EXCLUDED.${s(n.conflictColumns[0])}`, f = s`INSERT INTO ${s(e)} ${s.insert(v(t, e, G))} ON CONFLICT (${s.csv(c)}) DO UPDATE SET ${d} RETURNING *`, p = r ? i.provideService(f, k, r) : f, m = (await this.runtime.runPromise(p))[0];
295
+ let c = n.conflictColumns.map((e) => s`${s(e)}`), l = Object.keys(t).filter((e) => t[e] !== void 0), u = n.update === void 0 ? l.filter((e) => e !== "id" && !n.conflictColumns.includes(e)) : n.update, d = u.length > 0 ? s.csv(u.map((e) => s`${s(e)} = EXCLUDED.${s(e)}`)) : s`${s(n.conflictColumns[0])} = EXCLUDED.${s(n.conflictColumns[0])}`, f = s`INSERT INTO ${s(e)} ${s.insert(v(t, e, G))} ON CONFLICT (${s.csv(c)}) DO UPDATE SET ${d} RETURNING *`, p = r ? i.provideService(f, E, r) : f, m = (await this.runtime.runPromise(p))[0];
274
296
  if (!m) throw Error(`PostgresDataStore.upsert: no row returned for table '${e}'`);
275
297
  {
276
298
  let n = t.id !== void 0 && t.id === m.id ? "insert" : "update";
@@ -284,27 +306,27 @@ var A = (e) => {
284
306
  return m;
285
307
  }
286
308
  async executeInsertIgnore(e, t, n, r, a, o) {
287
- t = E(e, t);
288
- let s = this.sql, c = n.conflictColumns.map((e) => s`${s(e)}`), l = s`INSERT INTO ${s(e)} ${s.insert(v(t, e, G))} ON CONFLICT (${s.csv(c)}) DO NOTHING RETURNING *`, u = r ? i.provideService(l, k, r) : l, d = (await this.runtime.runPromise(u))[0];
309
+ t = C(e, t);
310
+ let s = this.sql, c = n.conflictColumns.map((e) => s`${s(e)}`), l = s`INSERT INTO ${s(e)} ${s.insert(v(t, e, G))} ON CONFLICT (${s.csv(c)}) DO NOTHING RETURNING *`, u = r ? i.provideService(l, E, r) : l, d = (await this.runtime.runPromise(u))[0];
289
311
  if (d) return await this.routeEvent({
290
312
  table: e,
291
313
  op: "insert",
292
314
  old: null,
293
315
  new: d
294
316
  }, a, r, o), d;
295
- let f = n.conflictColumns.map((e) => s`${s(e)} = ${t[e]}`), p = s`SELECT * FROM ${s(e)} WHERE ${s.and(f)} LIMIT 1`, m = r ? i.provideService(p, k, r) : p, h = await this.runtime.runPromise(m);
317
+ let f = n.conflictColumns.map((e) => s`${s(e)} = ${t[e]}`), p = s`SELECT * FROM ${s(e)} WHERE ${s.and(f)} LIMIT 1`, m = r ? i.provideService(p, E, r) : p, h = await this.runtime.runPromise(m);
296
318
  if (!h[0]) throw Error(`PostgresDataStore.insertIgnore: the insert was skipped as a conflict, but no existing row matches conflictColumns [${n.conflictColumns.join(", ")}] on '${e}'. A DIFFERENT unique constraint fired — a second unique index, or the primary key when you named something else. insertIgnore models ONE conflict target: name the columns of the constraint that actually collides, or handle the unique violation yourself.`);
297
319
  return h[0];
298
320
  }
299
321
  async executeInsertMany(e, t, n, r, a) {
300
- if (t = he(e, t), t.length === 0) return [];
322
+ if (t = ve(e, t), t.length === 0) return [];
301
323
  let o = this.sql, s = t.map((t) => v(t, e, G)), c = ie(s, re("postgres")), l = (t) => o`INSERT INTO ${o(e)} ${o.insert(t)} RETURNING *`, u;
302
324
  if (c.length === 1) {
303
- let e = l(c[0]), t = n ? i.provideService(e, k, n) : e;
325
+ let e = l(c[0]), t = n ? i.provideService(e, E, n) : e;
304
326
  u = await this.runtime.runPromise(t);
305
327
  } else if (n) {
306
328
  let e = [];
307
- for (let t of c) e.push(...await this.runtime.runPromise(i.provideService(l(t), k, n)));
329
+ for (let t of c) e.push(...await this.runtime.runPromise(i.provideService(l(t), E, n)));
308
330
  u = e;
309
331
  } else u = await this.runtime.runPromise(o.withTransaction(i.map(i.forEach(c, l, { concurrency: 1 }), (e) => e.flat())));
310
332
  for (let t of u) await this.routeEvent({
@@ -316,7 +338,7 @@ var A = (e) => {
316
338
  return u;
317
339
  }
318
340
  async executePatchJson(e, t, n, r, a, o, s) {
319
- let c = this.sql, l = n.split("."), u = l[0], d = l.slice(1), f = JSON.stringify(r ?? null), p = d.length === 0 ? c`${c(u)} = COALESCE(${c(u)}, '{}'::jsonb) || ${f}::jsonb` : c`${c(u)} = jsonb_set(COALESCE(${c(u)}, '{}'::jsonb), ${`{${d.join(",")}}`}, ${f}::jsonb, true)`, m = c`UPDATE ${c(e)} SET ${p} WHERE ${c("id")} = ${t} RETURNING *`, h = a ? i.provideService(m, k, a) : m, g = (await this.runtime.runPromise(h))[0];
341
+ let c = this.sql, l = n.split("."), u = l[0], d = l.slice(1), f = JSON.stringify(r ?? null), p = d.length === 0 ? c`${c(u)} = COALESCE(${c(u)}, '{}'::jsonb) || ${f}::jsonb` : c`${c(u)} = jsonb_set(COALESCE(${c(u)}, '{}'::jsonb), ${`{${d.join(",")}}`}, ${f}::jsonb, true)`, m = c`UPDATE ${c(e)} SET ${p} WHERE ${c("id")} = ${t} RETURNING *`, h = a ? i.provideService(m, E, a) : m, g = (await this.runtime.runPromise(h))[0];
320
342
  return g ? (await this.routeEvent({
321
343
  table: e,
322
344
  op: "update",
@@ -325,7 +347,7 @@ var A = (e) => {
325
347
  }, o, a, s), g) : null;
326
348
  }
327
349
  async executeDelete(e, t, n, r, a) {
328
- let o = this.sql, s = o`DELETE FROM ${o(e)} WHERE ${o("id")} = ${t} RETURNING *`, c = n ? i.provideService(s, k, n) : s, l = (await this.runtime.runPromise(c))[0];
350
+ let o = this.sql, s = o`DELETE FROM ${o(e)} WHERE ${o("id")} = ${t} RETURNING *`, c = n ? i.provideService(s, E, n) : s, l = (await this.runtime.runPromise(c))[0];
329
351
  return l ? (await this.routeEvent({
330
352
  table: e,
331
353
  op: "delete",
@@ -335,17 +357,17 @@ var A = (e) => {
335
357
  }
336
358
  async appendInTxn(e, t, n) {
337
359
  let r = this.sql, a = r`INSERT INTO ${r(e)} ${r.insert(v(t, e, G))}`;
338
- await this.runtime.runPromise(n ? i.provideService(a, k, n) : a);
360
+ await this.runtime.runPromise(n ? i.provideService(a, E, n) : a);
339
361
  }
340
362
  async maxInTxn(e, t, n, r) {
341
- let a = this.sql, o = Object.entries(n).map(([e, t]) => a`${a(e)} = ${t}`), s = a`SELECT MAX(${a(t)}) AS ${a("m")} FROM ${a(e)} WHERE ${a.and(o)}`, c = (await this.runtime.runPromise(r ? i.provideService(s, k, r) : s))[0]?.m;
363
+ let a = this.sql, o = Object.entries(n).map(([e, t]) => a`${a(e)} = ${t}`), s = a`SELECT MAX(${a(t)}) AS ${a("m")} FROM ${a(e)} WHERE ${a.and(o)}`, c = (await this.runtime.runPromise(r ? i.provideService(s, E, r) : s))[0]?.m;
342
364
  return c == null ? null : Number(c);
343
365
  }
344
366
  async routeEvent(e, t, n = null, r) {
345
367
  if (e = {
346
368
  ...ee(r),
347
369
  ...e
348
- }, x(e.table) && await me({
370
+ }, x(e.table) && await _e({
349
371
  append: (e, t) => this.appendInTxn(e, t, n),
350
372
  maxOf: (e, t, r) => this.maxInTxn(e, t, r, n)
351
373
  }, {
@@ -358,7 +380,7 @@ var A = (e) => {
358
380
  }), y(e.table)) {
359
381
  if (this.changeStrategy === "cdc") {
360
382
  let t = (e.op === "delete" ? e.old : e.new)?.id;
361
- t != null && S(te(e.table, e.op, t), {
383
+ t != null && pe(te(e.table, e.op, t), {
362
384
  ...e.traceId === void 0 ? {} : { traceId: e.traceId },
363
385
  ...e.subjectId === void 0 ? {} : { subjectId: e.subjectId }
364
386
  });
@@ -378,7 +400,7 @@ var A = (e) => {
378
400
  if (!ue(e)) return this.executeQuery(e, t, n);
379
401
  let r = n === null ? ae(e, this.sql, "postgres") : null;
380
402
  if (r !== null) try {
381
- let e = t ? i.provideService(r.fragment, k, t) : r.fragment, n = await b("postgres", "select", () => this.runtime.runPromise(e));
403
+ let e = t ? i.provideService(r.fragment, E, t) : r.fragment, n = await b("postgres", "select", () => this.runtime.runPromise(e));
382
404
  return r.decode(n);
383
405
  } catch (t) {
384
406
  if (t instanceof h) throw t;
@@ -395,7 +417,7 @@ var A = (e) => {
395
417
  reason: "not-compilable"
396
418
  });
397
419
  let a = await this.executeQuery(e, t, n);
398
- return g(a, e.eager, e.sourceTable ?? C(e.table), (e) => this.executeQuery(e, t, n));
420
+ return g(a, e.eager, e.sourceTable ?? me(e.table), (e) => this.executeQuery(e, t, n));
399
421
  }
400
422
  getInternalRunWithEager() {
401
423
  return (e, t) => this.runWithEager(e, t);
@@ -404,7 +426,7 @@ var A = (e) => {
404
426
  return this.runWithEager(t, null, e);
405
427
  }
406
428
  async writeWithRecorders(e, t) {
407
- let n = [], r = this.sql, a = await this.runtime.runPromise(r.withTransaction(i.flatMap(i.serviceOption(k), (r) => l.isNone(r) ? i.fail(/* @__PURE__ */ Error("PostgresDataStore.write: TransactionConnection missing.")) : i.tryPromise({
429
+ let n = [], r = this.sql, a = await this.runtime.runPromise(r.withTransaction(i.flatMap(i.serviceOption(E), (r) => l.isNone(r) ? i.fail(/* @__PURE__ */ Error("PostgresDataStore.write: TransactionConnection missing.")) : i.tryPromise({
408
430
  try: () => e(t, r.value, n),
409
431
  catch: (e) => e
410
432
  }))));
@@ -414,10 +436,10 @@ var A = (e) => {
414
436
  async localWrite(e, t, n) {
415
437
  let r = (e) => x(t) ? this.writeWithRecorders(n, e) : n(e, null, null);
416
438
  return b("postgres", e, async () => {
417
- if (this.changeStrategy !== "cdc") return D(r);
439
+ if (this.changeStrategy !== "cdc") return w(r);
418
440
  ne(t);
419
441
  try {
420
- return await D(r);
442
+ return await w(r);
421
443
  } finally {
422
444
  ce(t);
423
445
  }
@@ -445,7 +467,7 @@ var A = (e) => {
445
467
  return this.localWrite("delete", e, (n, r, i) => this.executeDeleteMany(e, t, r, i, n));
446
468
  }
447
469
  async executeUpdateMany(e, t, n, r, a, o) {
448
- let s = this.sql, c = _(n.where, s), l = s`UPDATE ${s(e)} SET ${s.update(v(t, e, G))} WHERE ${c} RETURNING *`, u = r ? i.provideService(l, k, r) : l, d = await this.runtime.runPromise(u);
470
+ let s = this.sql, c = _(n.where, s), l = s`UPDATE ${s(e)} SET ${s.update(v(t, e, G))} WHERE ${c} RETURNING *`, u = r ? i.provideService(l, E, r) : l, d = await this.runtime.runPromise(u);
449
471
  for (let t of d) await this.routeEvent({
450
472
  table: e,
451
473
  op: "update",
@@ -455,7 +477,7 @@ var A = (e) => {
455
477
  return d.length;
456
478
  }
457
479
  async executeDeleteMany(e, t, n, r, a) {
458
- let o = this.sql, s = _(t.where, o), c = o`DELETE FROM ${o(e)} WHERE ${s} RETURNING *`, l = n ? i.provideService(c, k, n) : c, u = await this.runtime.runPromise(l);
480
+ let o = this.sql, s = _(t.where, o), c = o`DELETE FROM ${o(e)} WHERE ${s} RETURNING *`, l = n ? i.provideService(c, E, n) : c, u = await this.runtime.runPromise(l);
459
481
  for (let t of u) await this.routeEvent({
460
482
  table: e,
461
483
  op: "delete",
@@ -525,17 +547,17 @@ var A = (e) => {
525
547
  }));
526
548
  }
527
549
  runStatementOnTransaction(e, t) {
528
- return this.runtime.runPromise(i.provideService(this.sql.unsafe(e), k, t));
550
+ return this.runtime.runPromise(i.provideService(this.sql.unsafe(e), E, t));
529
551
  }
530
552
  async emptyTablesOn(e, t) {
531
553
  if (e.length === 0) return;
532
- let n = this.sql, r = i.forEach(e, (e) => n`DELETE FROM ${n(e)}`, { discard: !0 }), a = t === null ? n.withTransaction(r) : i.provideService(r, k, t);
554
+ let n = this.sql, r = i.forEach(e, (e) => n`DELETE FROM ${n(e)}`, { discard: !0 }), a = t === null ? n.withTransaction(r) : i.provideService(r, E, t);
533
555
  await this.runtime.runPromise(a);
534
556
  }
535
557
  async transactional(e) {
536
558
  this.inflightTxns++;
537
559
  try {
538
- return await T({
560
+ return await S({
539
561
  ...this.txnSpec("PostgresDataStore.transactional", "store.transactional", "transaction"),
540
562
  work: e,
541
563
  makeView: (e, t) => new J(this, e, t)
@@ -555,7 +577,7 @@ var A = (e) => {
555
577
  injectExternalChange(e) {
556
578
  if (!y(e.table)) return;
557
579
  let t = (e.op === "delete" ? e.old : e.new)?.id;
558
- w(e.table, e.op, t, (t) => {
580
+ he(e.table, e.op, t, (t) => {
559
581
  this.emitter.emit("change", le(e, t));
560
582
  });
561
583
  }
@@ -571,7 +593,7 @@ var A = (e) => {
571
593
  inflight: this.inflightTxns
572
594
  });
573
595
  }
574
- this.cdcFiber &&= (await this.runtime.runPromise(a.interrupt(this.cdcFiber)), null), await this.runtime.dispose();
596
+ this.cdcStopped = !0, this.cdcWatchdog !== null && (clearInterval(this.cdcWatchdog), this.cdcWatchdog = null), this.cdcFiber &&= (await this.runtime.runPromise(a.interrupt(this.cdcFiber)), null), await this.runtime.dispose();
575
597
  }
576
598
  async ping() {
577
599
  await this.runtime.runPromise(this.sql`SELECT 1`);
@@ -586,13 +608,43 @@ var A = (e) => {
586
608
  }));
587
609
  }
588
610
  async startCdcConsumer() {
611
+ await this.attachCdcStream(), await this.proveCdcListening(1e4) || K.warn("cdc: the consumer could not prove it is listening yet — the watchdog will keep trying. Changes written on other replicas may not arrive until it does.", { channel: this.cdcChannel }), this.startCdcWatchdog();
612
+ }
613
+ async proveCdcListening(e) {
614
+ let t = Date.now() + e;
615
+ for (; Date.now() < t && !this.cdcStopped;) {
616
+ let e = this.cdcHeardCount;
617
+ try {
618
+ await this.runtime.runPromise(this.sql`SELECT pg_notify(${this.cdcChannel}, ${I(String(process.pid))})`);
619
+ } catch {}
620
+ let t = Date.now() + 500;
621
+ for (; this.cdcHeardCount === e && Date.now() < t;) await new Promise((e) => setTimeout(e, 10));
622
+ if (this.cdcHeardCount > e) return !0;
623
+ }
624
+ return !1;
625
+ }
626
+ onChangeStreamGap(e) {
627
+ return this.cdcGapListeners.add(e), () => {
628
+ this.cdcGapListeners.delete(e);
629
+ };
630
+ }
631
+ emitCdcGap(e) {
632
+ for (let t of this.cdcGapListeners) try {
633
+ t(e);
634
+ } catch (e) {
635
+ K.warn("cdc: gap listener threw", {}, e instanceof Error ? e : void 0);
636
+ }
637
+ }
638
+ async attachCdcStream() {
589
639
  let e = (await this.runtime.runPromise(t.PgClient)).listen(this.cdcChannel), n = (e) => i.suspend(() => {
640
+ this.cdcLastHeardAt = Date.now(), this.cdcHeardCount += 1;
590
641
  let t;
591
642
  try {
592
643
  t = JSON.parse(e);
593
644
  } catch (e) {
594
645
  return K.warn("cdc: bad payload", { channel: this.cdcChannel }, e), i.void;
595
646
  }
647
+ if (Ce(t)) return i.void;
596
648
  if (t.oversized !== !0) {
597
649
  let e = {
598
650
  table: t.table,
@@ -604,7 +656,7 @@ var A = (e) => {
604
656
  this.injectExternalChange(e);
605
657
  });
606
658
  }
607
- return y(t.table) ? xe({
659
+ return y(t.table) ? Oe({
608
660
  notification: t,
609
661
  fetchRow: ({ schema: e, table: t, key: n }) => this.readRowAsCdcJson(e, t, n),
610
662
  tunables: this.cdcRehydrate
@@ -612,7 +664,66 @@ var A = (e) => {
612
664
  this.reportOversized(t, e), this.injectExternalChange(e.event);
613
665
  })) : i.void;
614
666
  });
615
- this.cdcFiber = this.runtime.runFork(e.pipe(f.runForEach(n)));
667
+ this.cdcLastHeardAt = Date.now(), this.cdcProbeSentAt = null, this.cdcFiber = this.runtime.runFork(e.pipe(f.runForEach(n)));
668
+ }
669
+ startCdcWatchdog() {
670
+ if (this.cdcWatchdog !== null) return;
671
+ let e = this.cdcLiveness, t = Math.max(1e3, Math.floor(e.idleMs / 4)), n = setInterval(() => {
672
+ this.cdcWatchdogTick(e);
673
+ }, t);
674
+ n.unref?.(), this.cdcWatchdog = n;
675
+ }
676
+ async cdcWatchdogTick(e) {
677
+ if (this.cdcStopped || this.cdcReconnecting) return;
678
+ let t = P({
679
+ lastHeardAtMs: this.cdcLastHeardAt,
680
+ probeSentAtMs: this.cdcProbeSentAt
681
+ }, Date.now(), e);
682
+ if (t === "healthy") {
683
+ this.cdcProbeSentAt !== null && this.cdcLastHeardAt > this.cdcProbeSentAt && (this.cdcProbeSentAt = null);
684
+ return;
685
+ }
686
+ if (t === "probe") {
687
+ let e = Date.now();
688
+ try {
689
+ await this.runtime.runPromise(this.sql`SELECT pg_notify(${this.cdcChannel}, ${I(String(process.pid))})`), this.cdcProbeSentAt = e;
690
+ } catch (e) {
691
+ K.debug("cdc: heartbeat could not be sent — treating the database as unreachable, not the consumer as dead", {
692
+ channel: this.cdcChannel,
693
+ error: e instanceof Error ? e.message : String(e)
694
+ }), this.cdcProbeSentAt = null;
695
+ }
696
+ return;
697
+ }
698
+ await this.reconnectCdc(`no notification on '${this.cdcChannel}' for ${Math.round((Date.now() - this.cdcLastHeardAt) / 1e3)}s and a heartbeat went unanswered — the LISTEN connection is dead`);
699
+ }
700
+ async reconnectCdc(e) {
701
+ if (this.cdcReconnecting || this.cdcStopped) return;
702
+ this.cdcReconnecting = !0;
703
+ let t = this.cdcLastHeardAt;
704
+ K.warn(`cdc: reconnecting — ${e}`, { channel: this.cdcChannel });
705
+ try {
706
+ for (let n = 1; !this.cdcStopped; n++) try {
707
+ if (this.cdcFiber &&= (await this.runtime.runPromise(a.interrupt(this.cdcFiber)), null), await this.attachCdcStream(), !await this.proveCdcListening(5e3)) throw Error("the re-opened consumer never echoed its own heartbeat");
708
+ let r = Date.now() - t;
709
+ K.info("cdc: reconnected — refreshing live state, which is safe because a query is idempotent", {
710
+ channel: this.cdcChannel,
711
+ attempt: n,
712
+ downForMs: r
713
+ }), this.emitCdcGap({
714
+ reason: e,
715
+ downForMs: r
716
+ });
717
+ return;
718
+ } catch (e) {
719
+ K.warn("cdc: reconnect attempt failed", {
720
+ channel: this.cdcChannel,
721
+ attempt: n
722
+ }, e instanceof Error ? e : void 0), await new Promise((e) => setTimeout(e, L(n)));
723
+ }
724
+ } finally {
725
+ this.cdcReconnecting = !1;
726
+ }
616
727
  }
617
728
  }, J = class {
618
729
  parent;
@@ -683,7 +794,7 @@ var A = (e) => {
683
794
  this.events.length = 0;
684
795
  }
685
796
  }
686
- }, we = class {
797
+ }, je = class {
687
798
  parent;
688
799
  namespace;
689
800
  constructor(e, t) {
@@ -737,17 +848,17 @@ var A = (e) => {
737
848
  return r === void 0 ? Promise.reject(/* @__PURE__ */ Error("PostgresNamespaceView.raw: underlying store has no raw()")) : r(e, t);
738
849
  });
739
850
  }
740
- }, Y = (e) => e.__postgresReplicationFriend ?? null, Te = (e, t) => {
851
+ }, Y = (e) => e.__postgresReplicationFriend ?? null, Me = (e, t) => {
741
852
  let [n, r] = e.split("/"), [i, a] = t.split("/");
742
853
  if (!n || !r || !i || !a) throw Error(`postgres LSN compare: invalid format (${e} vs ${t})`);
743
854
  let o = parseInt(n, 16), s = parseInt(r, 16), c = parseInt(i, 16);
744
855
  return o === c ? s - parseInt(a, 16) : o - c;
745
- }, Ee = () => ({
856
+ }, Ne = () => ({
746
857
  async capturePrimaryPosition(e) {
747
858
  let t = Y(e);
748
859
  if (t === null) throw Error("postgresReplicationAdapter: primary is not a PostgresDataStore (missing __postgresReplicationFriend). Pass the postgres store directly.");
749
860
  return t.runEffect(i.gen(function* () {
750
- let e = (yield* (yield* O)`SELECT pg_current_wal_lsn()::text AS lsn`)[0]?.lsn;
861
+ let e = (yield* (yield* T)`SELECT pg_current_wal_lsn()::text AS lsn`)[0]?.lsn;
751
862
  return typeof e == "string" ? e : yield* i.die("postgres did not return a WAL LSN");
752
863
  }));
753
864
  },
@@ -755,23 +866,23 @@ var A = (e) => {
755
866
  let t = Y(e);
756
867
  if (t === null) throw Error("postgresReplicationAdapter: replica is not a PostgresDataStore.");
757
868
  return t.runEffect(i.gen(function* () {
758
- let e = (yield* (yield* O)`
869
+ let e = (yield* (yield* T)`
759
870
  SELECT COALESCE(pg_last_wal_replay_lsn()::text, pg_current_wal_lsn()::text) AS lsn
760
871
  `)[0]?.lsn;
761
872
  return typeof e == "string" ? e : yield* i.die("postgres did not return a replay LSN");
762
873
  }));
763
874
  },
764
875
  compare(e, t) {
765
- return Te(t, e) >= 0 ? "caught-up" : "behind";
876
+ return Me(t, e) >= 0 ? "caught-up" : "behind";
766
877
  }
767
- }), X = (e) => `"${e.replace(/"/g, "\"\"")}"`, De = (e) => e.replace(/\\/g, "\\\\").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\v/g, "\\v").replace(/\f/g, "\\f").replace(/[\b]/g, "\\b"), Oe = (e) => {
878
+ }), X = (e) => `"${e.replace(/"/g, "\"\"")}"`, Pe = (e) => e.replace(/\\/g, "\\\\").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\v/g, "\\v").replace(/\f/g, "\\f").replace(/[\b]/g, "\\b"), Fe = (e) => {
768
879
  let t = "";
769
880
  for (let n of e) t += n.toString(16).padStart(2, "0");
770
881
  return t;
771
- }, Z = (e) => `{${e.map((e) => e == null ? "NULL" : Array.isArray(e) ? Z(e) : typeof e == "number" || typeof e == "bigint" ? String(e) : typeof e == "boolean" ? e ? "t" : "f" : `"${(e instanceof Date ? e.toISOString() : String(e)).replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`).join(",")}}`, Q = (e, t) => e == null ? null : typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : typeof e == "boolean" ? e ? "t" : "f" : e instanceof Date ? e.toISOString() : e instanceof Uint8Array ? `\\x${Oe(e)}` : Array.isArray(e) && t === "array" ? Z(e) : JSON.stringify(e), $ = (e, t, n = {}) => t.map((t) => {
882
+ }, Z = (e) => `{${e.map((e) => e == null ? "NULL" : Array.isArray(e) ? Z(e) : typeof e == "number" || typeof e == "bigint" ? String(e) : typeof e == "boolean" ? e ? "t" : "f" : `"${(e instanceof Date ? e.toISOString() : String(e)).replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`).join(",")}}`, Q = (e, t) => e == null ? null : typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : typeof e == "boolean" ? e ? "t" : "f" : e instanceof Date ? e.toISOString() : e instanceof Uint8Array ? `\\x${Fe(e)}` : Array.isArray(e) && t === "array" ? Z(e) : JSON.stringify(e), $ = (e, t, n = {}) => t.map((t) => {
772
883
  let r = Q(e[t], n[t]);
773
- return r === null ? "\\N" : De(r);
774
- }).join(" "), ke = class {
884
+ return r === null ? "\\N" : Pe(r);
885
+ }).join(" "), Ie = class {
775
886
  text;
776
887
  chunks;
777
888
  done;
@@ -802,7 +913,7 @@ var A = (e) => {
802
913
  handleReadyForQuery() {
803
914
  this.settle(void 0);
804
915
  }
805
- }, Ae = (e) => ({
916
+ }, Le = (e) => ({
806
917
  ...e.url ? { connectionString: e.url } : {
807
918
  host: e.host ?? "localhost",
808
919
  port: e.port ?? 5432,
@@ -811,9 +922,9 @@ var A = (e) => {
811
922
  database: e.database ?? "postgres"
812
923
  },
813
924
  ...e.ssl === !0 ? { ssl: { rejectUnauthorized: !1 } } : {}
814
- }), je = 65536, Me = (e) => {
925
+ }), Re = 65536, ze = (e) => {
815
926
  let t, n, r = () => t ? Promise.resolve(t) : (n ??= (async () => {
816
- let n = new p.Client(Ae(e));
927
+ let n = new p.Client(Le(e));
817
928
  return await n.connect(), t = n, n;
818
929
  })(), n);
819
930
  return {
@@ -821,9 +932,9 @@ var A = (e) => {
821
932
  copyInto: async ({ table: e, columns: t, columnTypes: n, rows: i }) => {
822
933
  if (i.length === 0) return 0;
823
934
  let a = await r(), o = `COPY ${X(e)} (${t.map(X).join(", ")}) FROM STDIN`, s = [], c = "";
824
- for (let e of i) c += $(e, t, n ?? {}), c += "\n", c.length >= je && (s.push(Buffer.from(c, "utf8")), c = "");
935
+ for (let e of i) c += $(e, t, n ?? {}), c += "\n", c.length >= Re && (s.push(Buffer.from(c, "utf8")), c = "");
825
936
  return c.length > 0 && s.push(Buffer.from(c, "utf8")), await new Promise((e, t) => {
826
- let n = new ke(o, s, (n, r) => {
937
+ let n = new Ie(o, s, (n, r) => {
827
938
  n ? t(n) : e(r);
828
939
  });
829
940
  a.query(n);
@@ -834,12 +945,12 @@ var A = (e) => {
834
945
  t = void 0, n = void 0, e && await e.end().catch(() => void 0);
835
946
  }
836
947
  };
837
- }, Ne = {
948
+ }, Be = {
838
949
  id: "postgres",
839
- makeSqlLayer: (e) => L(e),
950
+ makeSqlLayer: (e) => M(e),
840
951
  makeStore: (e) => q(e),
841
952
  compileContains: (e, t, n) => n`${e} ILIKE ${`%${t.replace(/[\\%_]/g, (e) => `\\${e}`)}%`} ESCAPE '\\'`,
842
953
  retryFilter: B
843
954
  };
844
955
  //#endregion
845
- export { e as PgClient, I as connectionFromConfig, $ as encodeCopyRow, Q as encodeCopyValue, Me as makePgCopySession, q as makePostgresDataStore, P as makePostgresSqlLayer, L as makePostgresSqlLayerFromConfig, Ne as postgresDialect, Ee as postgresReplicationAdapter, B as postgresRetryFilter };
956
+ export { F as CDC_HEARTBEAT_MARKER, N as DEFAULT_CDC_LIVENESS, e as PgClient, P as cdcLivenessVerdict, L as cdcReconnectDelayMs, j as connectionFromConfig, $ as encodeCopyRow, Q as encodeCopyValue, ze as makePgCopySession, q as makePostgresDataStore, A as makePostgresSqlLayer, M as makePostgresSqlLayerFromConfig, Be as postgresDialect, Ne as postgresReplicationAdapter, B as postgresRetryFilter, R as resolveCdcLiveness };