turbine-orm 0.60.1 → 0.62.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 (84) hide show
  1. package/README.md +71 -27
  2. package/dist/cjs/cli/config.d.ts +40 -0
  3. package/dist/cjs/cli/config.js +74 -2
  4. package/dist/cjs/cli/index.d.ts +85 -1
  5. package/dist/cjs/cli/index.js +374 -24
  6. package/dist/cjs/cli/mcp.d.ts +8 -0
  7. package/dist/cjs/cli/mcp.js +448 -29
  8. package/dist/cjs/cli/pii-tags.d.ts +64 -9
  9. package/dist/cjs/cli/pii-tags.js +218 -39
  10. package/dist/cjs/cli/studio-ui.generated.js +1 -1
  11. package/dist/cjs/cli/studio.d.ts +23 -0
  12. package/dist/cjs/cli/studio.js +126 -53
  13. package/dist/cjs/cli/ui.d.ts +15 -1
  14. package/dist/cjs/cli/ui.js +19 -5
  15. package/dist/cjs/client.js +248 -11
  16. package/dist/cjs/errors.d.ts +38 -1
  17. package/dist/cjs/errors.js +235 -24
  18. package/dist/cjs/index.d.ts +2 -2
  19. package/dist/cjs/index.js +7 -2
  20. package/dist/cjs/pipeline-submittable.js +26 -3
  21. package/dist/cjs/pipeline.js +15 -2
  22. package/dist/cjs/powql.d.ts +12 -0
  23. package/dist/cjs/powql.js +46 -21
  24. package/dist/cjs/prisma-compat.d.ts +15 -5
  25. package/dist/cjs/prisma-compat.js +273 -78
  26. package/dist/cjs/query/aggregates.d.ts +1 -1
  27. package/dist/cjs/query/aggregates.js +24 -10
  28. package/dist/cjs/query/batched-loader.d.ts +9 -4
  29. package/dist/cjs/query/batched-loader.js +4 -1
  30. package/dist/cjs/query/builder.d.ts +47 -0
  31. package/dist/cjs/query/builder.js +149 -21
  32. package/dist/cjs/query/index.d.ts +3 -1
  33. package/dist/cjs/query/index.js +7 -1
  34. package/dist/cjs/query/option-surface.d.ts +11 -0
  35. package/dist/cjs/query/option-surface.js +13 -0
  36. package/dist/cjs/query/relations.d.ts +8 -0
  37. package/dist/cjs/query/relations.js +21 -1
  38. package/dist/cjs/query/types.d.ts +152 -18
  39. package/dist/cjs/query/types.js +212 -1
  40. package/dist/cjs/query/where.d.ts +3 -3
  41. package/dist/cjs/query/where.js +8 -2
  42. package/dist/cjs/query/writes.js +10 -9
  43. package/dist/cli/config.d.ts +40 -0
  44. package/dist/cli/config.js +73 -2
  45. package/dist/cli/index.d.ts +85 -1
  46. package/dist/cli/index.js +373 -27
  47. package/dist/cli/mcp.d.ts +8 -0
  48. package/dist/cli/mcp.js +448 -29
  49. package/dist/cli/pii-tags.d.ts +64 -9
  50. package/dist/cli/pii-tags.js +217 -39
  51. package/dist/cli/studio-ui.generated.js +1 -1
  52. package/dist/cli/studio.d.ts +23 -0
  53. package/dist/cli/studio.js +125 -53
  54. package/dist/cli/ui.d.ts +15 -1
  55. package/dist/cli/ui.js +18 -4
  56. package/dist/client.js +250 -13
  57. package/dist/errors.d.ts +38 -1
  58. package/dist/errors.js +234 -23
  59. package/dist/index.d.ts +2 -2
  60. package/dist/index.js +5 -2
  61. package/dist/pipeline-submittable.js +26 -3
  62. package/dist/pipeline.js +15 -2
  63. package/dist/powql.d.ts +12 -0
  64. package/dist/powql.js +46 -21
  65. package/dist/prisma-compat.d.ts +15 -5
  66. package/dist/prisma-compat.js +274 -79
  67. package/dist/query/aggregates.d.ts +1 -1
  68. package/dist/query/aggregates.js +24 -10
  69. package/dist/query/batched-loader.d.ts +9 -4
  70. package/dist/query/batched-loader.js +4 -1
  71. package/dist/query/builder.d.ts +47 -0
  72. package/dist/query/builder.js +148 -21
  73. package/dist/query/index.d.ts +3 -1
  74. package/dist/query/index.js +2 -0
  75. package/dist/query/option-surface.d.ts +11 -0
  76. package/dist/query/option-surface.js +13 -0
  77. package/dist/query/relations.d.ts +8 -0
  78. package/dist/query/relations.js +21 -1
  79. package/dist/query/types.d.ts +152 -18
  80. package/dist/query/types.js +207 -2
  81. package/dist/query/where.d.ts +3 -3
  82. package/dist/query/where.js +8 -2
  83. package/dist/query/writes.js +10 -9
  84. package/package.json +13 -3
@@ -193,13 +193,215 @@ function warnUnknownConfigKeys(config) {
193
193
  // must never be the reason a client fails to construct.
194
194
  }
195
195
  }
196
- /** Maps isolation level names to SQL */
197
- const ISOLATION_LEVELS = {
196
+ /**
197
+ * Two bases that differ ONLY in host, used to detect whether the host pg ends
198
+ * up with came from the connection string or from pg's own placeholder base.
199
+ *
200
+ * pg-connection-string resolves a connection string as `new URL(str,
201
+ * 'postgres://base')`. A string with no scheme is therefore a RELATIVE url, and
202
+ * silently inherits the literal host `base`, which is where
203
+ * `getaddrinfo ENOTFOUND base` comes from. Parsing against two different bases
204
+ * and comparing the resulting hostnames identifies that case exactly, and
205
+ * cannot be fooled by a string that genuinely names a host called `base`.
206
+ */
207
+ const CONNECTION_STRING_PROBE_BASES = ['postgres://turbine-probe-a', 'postgres://turbine-probe-b'];
208
+ /**
209
+ * Classify a connection string by replaying the parse pg itself performs.
210
+ *
211
+ * This is a deliberate mirror of `pg-connection-string`'s `parse()`, in the
212
+ * same order, because that function IS the oracle: anything it resolves to a
213
+ * real host/socket is a string pg will connect with, and a validator that
214
+ * refuses one of those breaks a working deployment. In particular all of these
215
+ * are usable and must pass:
216
+ * - `/var/run/postgresql app` and `/cloudsql/proj:region:instance`, the
217
+ * leading-slash unix-socket form (peer auth, Cloud SQL),
218
+ * - `socket:/var/run/postgresql?db=app`, the explicit socket scheme,
219
+ * - `postgresql:///db`, `postgres:/db`, `postgres://`, all empty-host forms
220
+ * that fall back to pg's localhost default,
221
+ * - `postgres://user:pw@/db` (the `@/` dummy-host retry) and
222
+ * `?host=/var/run/postgresql` (host as a query parameter),
223
+ * - anything else that parses as an absolute URL, `localhost:5432` included.
224
+ *
225
+ * Only two shapes are not usable: a string with no scheme (pg substitutes its
226
+ * placeholder host) and a string neither parse attempt can turn into a URL (pg
227
+ * throws `Invalid URL` from its own constructor).
228
+ */
229
+ function classifyConnectionString(value) {
230
+ // Leading slash: pg short-circuits to `{ host: <path>, database: <word 2> }`
231
+ // before any URL parsing. Unix-domain socket directory or Cloud SQL path.
232
+ if (value.charAt(0) === '/')
233
+ return { kind: 'usable' };
234
+ // pg percent-encodes before parsing, so a string with spaces (or a stray
235
+ // half-written escape) reaches the URL constructor already encoded.
236
+ const encoded = / |%[^a-f0-9]|%[a-f0-9][^a-f0-9]/i.test(value)
237
+ ? encodeURI(value).replace(/%25(\d\d)/g, '%$1')
238
+ : value;
239
+ const parseAgainst = (base) => {
240
+ try {
241
+ return { url: new URL(encoded, base), dummyHost: false };
242
+ }
243
+ catch {
244
+ // pg's own second attempt: `postgres://user:pw@/db` is not a valid URL,
245
+ // so it retries with a placeholder authority and treats the host as empty.
246
+ try {
247
+ return { url: new URL(encoded.replace('@/', '@___DUMMY___/'), base), dummyHost: true };
248
+ }
249
+ catch {
250
+ return null;
251
+ }
252
+ }
253
+ };
254
+ const a = parseAgainst(CONNECTION_STRING_PROBE_BASES[0]);
255
+ const b = parseAgainst(CONNECTION_STRING_PROBE_BASES[1]);
256
+ if (!a || !b)
257
+ return { kind: 'unparseable' };
258
+ // `socket:` is handled by its own branch in pg's parse: the pathname is the
259
+ // socket directory and the base never contributes.
260
+ if (a.url.protocol === 'socket:')
261
+ return { kind: 'usable' };
262
+ // The dummy-host retry only happens for an absolute URL, so the host is
263
+ // empty by construction and pg falls back to its localhost default.
264
+ if (a.dummyHost)
265
+ return { kind: 'usable' };
266
+ // A `host=` query parameter wins over the URL authority in pg's parse.
267
+ if (a.url.searchParams.get('host'))
268
+ return { kind: 'usable' };
269
+ return a.url.hostname === b.url.hostname ? { kind: 'usable' } : { kind: 'phantom-host' };
270
+ }
271
+ /**
272
+ * Reject a connection string pg cannot connect with, at construction, naming
273
+ * the string as the problem.
274
+ *
275
+ * Without this, a typo'd or truncated string is handed to pg, which resolves it
276
+ * as a URL relative to its own `postgres://base`, so the string silently
277
+ * becomes a request for a host named `base`. The failure surfaces one query
278
+ * later as `[TURBINE_E004] Database connection error: getaddrinfo ENOTFOUND
279
+ * base`, and sends the reader looking for a DNS problem with a host they never
280
+ * configured.
281
+ *
282
+ * The oracle is pg itself (see {@link classifyConnectionString}), not a scheme
283
+ * pattern. An earlier scheme-matching version of this check refused
284
+ * `/var/run/postgresql app` and `/cloudsql/project:region:instance`, which are
285
+ * documented, working unix-socket connection strings, i.e. it broke peer-auth
286
+ * and Cloud SQL deployments at `new TurbineClient(...)`.
287
+ *
288
+ * The empty string never reaches here: the call sites skip a falsy value, which
289
+ * is exactly what the pool-building branch does with it, so
290
+ * `connectionString: process.env.DATABASE_URL ?? ''` keeps constructing.
291
+ */
292
+ function assertUsableConnectionString(value, source) {
293
+ // Whitespace-only is not empty: it is truthy, so pg WOULD take it, encode it
294
+ // to `%20%20%20`, and resolve it against its placeholder host. Naming it as
295
+ // empty is more useful than reporting the phantom host.
296
+ if (value.trim().length === 0) {
297
+ throw new errors_js_1.ConnectionError(`[turbine] The ${source} is empty. Expected a Postgres connection string such as ` +
298
+ '"postgresql://user:password@host:5432/database".');
299
+ }
300
+ const verdict = classifyConnectionString(value);
301
+ if (verdict.kind === 'usable')
302
+ return;
303
+ // Never echo the value: it may carry a password, and it is malformed, so no
304
+ // redaction written against the URL grammar can be trusted on it.
305
+ const tail = '(Check for a missing "//", a stray quote copied out of a .env file, or a shell-truncated value.) ' +
306
+ 'The value is not included here because it may contain a password.';
307
+ if (verdict.kind === 'unparseable') {
308
+ throw new errors_js_1.ConnectionError(`[turbine] The ${source} cannot be parsed as a connection string, pg rejects it with "Invalid URL" ` +
309
+ '(most often a non-numeric port). Expected something like ' +
310
+ `"postgresql://user:password@host:5432/database". ${tail}`);
311
+ }
312
+ // libpq keyword/value strings land here, and deserve their own sentence:
313
+ // node-postgres does NOT implement that form, it feeds the whole string to
314
+ // the URL parser, so `host=localhost dbname=app` becomes a request for the
315
+ // host `base` with the database `host=localhost dbname=app`.
316
+ const keywordForm = /^[A-Za-z_][A-Za-z0-9_]*\s*=/.test(value.trimStart())
317
+ ? 'It looks like a libpq "host=… dbname=…" keyword/value string, which node-postgres does not support. '
318
+ : '';
319
+ throw new errors_js_1.ConnectionError(`[turbine] The ${source} names no host: it has no "postgres://" or "postgresql://" scheme, so pg would ` +
320
+ `resolve it as a relative URL and try to connect to its internal placeholder host. ${keywordForm}` +
321
+ `Expected something like "postgresql://user:password@host:5432/database". ${tail}`);
322
+ }
323
+ /**
324
+ * Maps isolation level names to SQL. Null-prototype and read through
325
+ * {@link resolveIsolationLevel}, never indexed directly: an inherited key
326
+ * (`constructor`, `toString`) would otherwise resolve to a function and be
327
+ * interpolated verbatim into `BEGIN ISOLATION LEVEL …`.
328
+ */
329
+ const ISOLATION_LEVELS = Object.assign(Object.create(null), {
198
330
  ReadUncommitted: 'READ UNCOMMITTED',
199
331
  ReadCommitted: 'READ COMMITTED',
200
332
  RepeatableRead: 'REPEATABLE READ',
201
333
  Serializable: 'SERIALIZABLE',
202
- };
334
+ });
335
+ /**
336
+ * Resolve a requested isolation level, REFUSING anything not in the map.
337
+ *
338
+ * A miss used to yield `undefined`, which `beginStatement` renders as a plain
339
+ * `BEGIN`. So `isolationLevel: 'serializable'` (wrong case) asked for
340
+ * SERIALIZABLE and silently got READ COMMITTED, which is the worst available
341
+ * outcome for this option: the caller believes it has a guarantee it does not
342
+ * have, and the workload that depended on it produces wrong data with no error.
343
+ *
344
+ * The TypeScript union on `TransactionOptions.isolationLevel` does not prevent
345
+ * this. It is not enforced for a JavaScript consumer of a published package, for
346
+ * a value read from config or an environment variable, or across any `as`.
347
+ * Throwing costs a caller who was already broken one clear error.
348
+ */
349
+ /**
350
+ * Run a transaction-control statement (BEGIN / COMMIT / ROLLBACK) with the same
351
+ * error translation every other query boundary gets.
352
+ *
353
+ * These four statements were the only ones issued raw, and COMMIT is the one
354
+ * that matters: Postgres reports DEFERRABLE constraint violations and a good
355
+ * share of SERIALIZABLE conflicts at COMMIT rather than at the statement that
356
+ * caused them. Unwrapped, those surfaced as a raw `DatabaseError` carrying a
357
+ * SQLSTATE in `.code`, which is the SAME property Turbine puts `TURBINE_E0NN`
358
+ * in, so `err.code === 'TURBINE_E008'` silently missed them and a `switch` on
359
+ * `.code` received a value from a foreign namespace. Worse for the retry case:
360
+ * `SerializationFailureError.isRetryable` exists so callers can build retry
361
+ * loops, and a loop keyed on it would never fire for the commit-time conflicts
362
+ * that are the main reason to run SERIALIZABLE at all.
363
+ */
364
+ /**
365
+ * Check out a pooled connection, translating a driver failure into a typed
366
+ * Turbine error.
367
+ *
368
+ * `pool.connect()` is where the first-run failures actually land: wrong
369
+ * password (SQLSTATE 28P01), no such database (3D000), nothing listening
370
+ * (ECONNREFUSED), an unverifiable TLS certificate. Unwrapped, every one of
371
+ * those left `$transaction`, `transaction()` and `connect()` as a raw pg
372
+ * `DatabaseError` carrying a SQLSTATE in `.code`, the same property Turbine
373
+ * puts `TURBINE_E0NN` in, so the single error a new user is most likely to see
374
+ * was the one error the typed-error contract did not cover.
375
+ *
376
+ * Query paths need no equivalent: `pool.query()` opens the connection itself
377
+ * and rejects with the connect error, which the query boundary already wraps.
378
+ */
379
+ async function acquireConnection(pool) {
380
+ try {
381
+ return await pool.connect();
382
+ }
383
+ catch (err) {
384
+ throw (0, errors_js_1.wrapPgError)(err);
385
+ }
386
+ }
387
+ async function runTxControl(client, sql) {
388
+ try {
389
+ await client.query(sql);
390
+ }
391
+ catch (err) {
392
+ throw (0, errors_js_1.wrapPgError)(err);
393
+ }
394
+ }
395
+ function resolveIsolationLevel(level) {
396
+ if (level === undefined)
397
+ return undefined;
398
+ const sql = (0, utils_js_1.ownLookup)(ISOLATION_LEVELS, level);
399
+ if (sql === undefined) {
400
+ throw new errors_js_1.ValidationError(`[turbine] $transaction: unknown isolationLevel ${JSON.stringify(level)}. ` +
401
+ `Expected one of: ${Object.keys(ISOLATION_LEVELS).join(', ')} (case-sensitive).`);
402
+ }
403
+ return sql;
404
+ }
203
405
  /**
204
406
  * Strict GUC (session variable) name: an optionally namespaced identifier such
205
407
  * as `app.current_tenant` or `search_path`. Even though the name is passed as a
@@ -539,6 +741,39 @@ class TurbineClient {
539
741
  // would poison the next, valid, TurbineClient with a phantom conflict.
540
742
  const dialect = config.dialect ?? dialect_js_1.postgresDialect;
541
743
  const planCacheMode = TurbineClient.resolvePlanCacheMode(config.planCacheMode, dialect);
744
+ // Refuse a connection string that cannot address a database, before it
745
+ // reaches pg's permissive parser and comes back one query later as a DNS
746
+ // error about a fragment of itself. Only the strings this client will
747
+ // actually USE are checked: with an external pool the connection target is
748
+ // the caller's, and an explicit host/port/user config makes DATABASE_URL
749
+ // irrelevant (the same precedence the pool-building branch below applies).
750
+ // The truthiness checks here mirror the pool-building branch below EXACTLY.
751
+ // An empty `connectionString` is ignored there (pg ignores it too), so
752
+ // `connectionString: process.env.DATABASE_URL ?? ''` must keep constructing,
753
+ // and it still suppresses the DATABASE_URL fallback because
754
+ // `hasExplicitConnection` tests `!= null`, not truthiness.
755
+ if (!config.pool) {
756
+ if (config.connectionString) {
757
+ assertUsableConnectionString(config.connectionString, 'connectionString');
758
+ }
759
+ else if (config.connectionString == null &&
760
+ config.host == null &&
761
+ config.port == null &&
762
+ config.database == null &&
763
+ config.user == null &&
764
+ config.password == null &&
765
+ process.env.DATABASE_URL) {
766
+ assertUsableConnectionString(process.env.DATABASE_URL, 'DATABASE_URL environment variable');
767
+ }
768
+ }
769
+ for (const [i, replica] of (config.replicas ?? []).entries()) {
770
+ // Only string replicas are ours to open; a PgCompatPool entry is already
771
+ // connected by its owner. An empty string is skipped for the same reason
772
+ // as above: pg ignores a falsy connectionString and uses its defaults.
773
+ if (typeof replica === 'string' && replica) {
774
+ assertUsableConnectionString(replica, `replicas[${i}] connection string`);
775
+ }
776
+ }
542
777
  /**
543
778
  * Parse int8 (bigint, OID 20) as JavaScript number instead of string.
544
779
  * Safe for values up to Number.MAX_SAFE_INTEGER (9,007,199,254,740,991).
@@ -1259,7 +1494,7 @@ class TurbineClient {
1259
1494
  * ```
1260
1495
  */
1261
1496
  async transaction(fn) {
1262
- const client = await this.pool.connect();
1497
+ const client = await acquireConnection(this.pool);
1263
1498
  /**
1264
1499
  * Only true once BEGIN has actually succeeded. If BEGIN itself throws
1265
1500
  * (e.g. a single-writer engine's transaction gate times out or rejects a
@@ -1270,7 +1505,7 @@ class TurbineClient {
1270
1505
  */
1271
1506
  let began = false;
1272
1507
  try {
1273
- await client.query(this.dialect.beginStatement());
1508
+ await runTxControl(client, this.dialect.beginStatement());
1274
1509
  began = true;
1275
1510
  // Engine seam: single-writer engines scope their transaction re-entrancy
1276
1511
  // marker to the callback's async subtree (see
@@ -1278,7 +1513,7 @@ class TurbineClient {
1278
1513
  const wrap = client.wrapTransactionCallback;
1279
1514
  // `.call` erases the generic, so the callback's Promise<T> is re-asserted.
1280
1515
  const result = wrap ? (await wrap.call(client, () => fn(client))) : await fn(client);
1281
- await client.query(this.dialect.commitStatement());
1516
+ await runTxControl(client, this.dialect.commitStatement());
1282
1517
  return result;
1283
1518
  }
1284
1519
  catch (err) {
@@ -1303,7 +1538,10 @@ class TurbineClient {
1303
1538
  return this.transactionBatch(fnOrQueries);
1304
1539
  }
1305
1540
  const fn = fnOrQueries;
1306
- const client = await this.pool.connect();
1541
+ // Resolve the isolation level BEFORE taking a pool slot: a bad argument is
1542
+ // the caller's bug and should not cost a connection to discover.
1543
+ const isolationSql = resolveIsolationLevel(options?.isolationLevel);
1544
+ const client = await acquireConnection(this.pool);
1307
1545
  const timeout = options?.timeout;
1308
1546
  /**
1309
1547
  * Track whether the connection has already been released so the finally
@@ -1335,8 +1573,7 @@ class TurbineClient {
1335
1573
  try {
1336
1574
  // BEGIN with optional isolation level, the dialect owns the keyword and
1337
1575
  // BEGIN+isolation composition (Postgres appends ` ISOLATION LEVEL …`).
1338
- const isolationSql = options?.isolationLevel ? ISOLATION_LEVELS[options.isolationLevel] : undefined;
1339
- await client.query(this.dialect.beginStatement(isolationSql));
1576
+ await runTxControl(client, this.dialect.beginStatement(isolationSql));
1340
1577
  began = true;
1341
1578
  // Apply transaction-local session context (RLS / multi-tenant GUCs).
1342
1579
  // Order matters: BEGIN -> isolation level (above) -> set_config loop ->
@@ -1408,7 +1645,7 @@ class TurbineClient {
1408
1645
  else {
1409
1646
  result = await runCallback();
1410
1647
  }
1411
- await client.query(this.dialect.commitStatement());
1648
+ await runTxControl(client, this.dialect.commitStatement());
1412
1649
  if (this.logging) {
1413
1650
  console.log('[turbine] Transaction committed');
1414
1651
  }
@@ -1628,7 +1865,7 @@ class TurbineClient {
1628
1865
  * Throws if the connection fails.
1629
1866
  */
1630
1867
  async connect() {
1631
- const client = await this.pool.connect();
1868
+ const client = await acquireConnection(this.pool);
1632
1869
  try {
1633
1870
  await client.query('SELECT 1');
1634
1871
  if (this.logging) {
@@ -53,10 +53,29 @@ export type ErrorMessageMode = 'safe' | 'verbose';
53
53
  * clause (e.g. `where: { id, email }`). Values are redacted.
54
54
  * - `'verbose'`: the message includes the full JSON-serialized where
55
55
  * clause (e.g. `where: {"id":1,"email":"alice@x.com"}`).
56
+ *
57
+ * SCOPE, stated precisely because the useful version of this contract is the
58
+ * one that is true. 'safe' mode redacts row values from the surfaces Turbine
59
+ * OWNS: its own error messages, and the `detail` field of a driver error it
60
+ * wraps and attaches as `.cause` (see redactCauseForMode).
61
+ *
62
+ * It is NOT a blanket guarantee that no row value can be reached from a thrown
63
+ * error. A driver error whose SQLSTATE {@link wrapPgError} does not classify is
64
+ * returned UNCHANGED, and some of those carry a value in the `message` field
65
+ * itself, where nothing can be removed without destroying the diagnosis:
66
+ * `22P02 invalid input syntax for type integer: "alice@example.com"` is the
67
+ * common one. Treat 'safe' mode as removing Turbine's own contribution to the
68
+ * leak, not as a log-scrubbing boundary.
56
69
  */
57
70
  export declare function setErrorMessageMode(mode: ErrorMessageMode): void;
58
71
  /** Returns the current NotFoundError message mode. Exported for tests. */
59
72
  export declare function getErrorMessageMode(): ErrorMessageMode;
73
+ /**
74
+ * The marker left where a driver `detail` string was removed in 'safe' mode.
75
+ * Re-exported from the package root so tests and callers writing log
76
+ * assertions can match on it without hardcoding the wording.
77
+ */
78
+ export declare const REDACTED_DETAIL = "[redacted by turbine errorMessages:\"safe\"]";
60
79
  /**
61
80
  * Render a user-supplied `where` / `connect` target for a "no row found" error
62
81
  * message, honoring the global {@link ErrorMessageMode}. In 'safe' mode (the
@@ -122,13 +141,29 @@ export declare class ValidationError extends TurbineError {
122
141
  }
123
142
  /** Thrown when a database connection fails */
124
143
  export declare class ConnectionError extends TurbineError {
144
+ /**
145
+ * The driver code that produced this error: a Postgres SQLSTATE (`28P01`
146
+ * wrong password, `3D000` no such database, `08006` connection failure, ...)
147
+ * or a Node socket/TLS code (`ECONNREFUSED`, `CERT_HAS_EXPIRED`, ...).
148
+ *
149
+ * Exposed because E004 covers causes with very different remedies, and the
150
+ * alternative for a caller who needs to tell "wrong password" from "server
151
+ * down" is matching on `.message` text or reaching into `.cause`, both of
152
+ * which are exactly the untyped handling this error class exists to remove.
153
+ * Undefined when Turbine raised the error itself rather than wrapping a
154
+ * driver error (a malformed connection string, a subscription on an HTTP
155
+ * pool).
156
+ */
157
+ readonly sqlstate?: string;
125
158
  /**
126
159
  * @param message human-readable connection failure description.
127
160
  * @param options optional pg/driver `cause` to preserve, used when wrapping a
128
- * connection-class driver error via `wrapPgError`.
161
+ * connection-class driver error via `wrapPgError`, plus the driver `code`
162
+ * that classified it.
129
163
  */
130
164
  constructor(message: string, options?: {
131
165
  cause?: unknown;
166
+ sqlstate?: string;
132
167
  });
133
168
  }
134
169
  /** Thrown when a relation reference is invalid */
@@ -363,6 +398,8 @@ export declare class ReadOnlyError extends TurbineError {
363
398
  * 40P01 (deadlock_detected) -> DeadlockError (retryable)
364
399
  * 40001 (serialization_failure) -> SerializationFailureError (retryable)
365
400
  * 57014 (query_canceled) -> TimeoutError (server-side statement_timeout)
401
+ * 28P01 / 28000 (auth refused) -> ConnectionError, with a remediation hint
402
+ * 3D000 (no such database) -> ConnectionError, with a remediation hint
366
403
  * connection-class codes -> ConnectionError (see CONNECTION_ERROR_CODES)
367
404
  *
368
405
  * The original pg error is preserved as `.cause` on the wrapped error.