turbine-orm 0.81.0 → 0.90.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 (295) hide show
  1. package/README.md +26 -25
  2. package/dist/checkout.d.ts +27 -2
  3. package/dist/checkout.js +75 -4
  4. package/dist/cjs/checkout.d.ts +27 -2
  5. package/dist/cjs/checkout.js +76 -3
  6. package/dist/cjs/cli/code-first-tags.d.ts +62 -0
  7. package/dist/cjs/cli/code-first-tags.js +124 -0
  8. package/dist/cjs/cli/compile-query.js +9 -0
  9. package/dist/cjs/cli/config.d.ts +35 -6
  10. package/dist/cjs/cli/config.js +17 -1
  11. package/dist/cjs/cli/destructive.d.ts +7 -4
  12. package/dist/cjs/cli/destructive.js +224 -20
  13. package/dist/cjs/cli/error-catalog.js +36 -0
  14. package/dist/cjs/cli/error-text.d.ts +15 -0
  15. package/dist/cjs/cli/error-text.js +40 -0
  16. package/dist/cjs/cli/index.d.ts +62 -4
  17. package/dist/cjs/cli/index.js +568 -108
  18. package/dist/cjs/cli/local-server-guard.d.ts +53 -0
  19. package/dist/cjs/cli/local-server-guard.js +119 -0
  20. package/dist/cjs/cli/local-server-output.d.ts +41 -0
  21. package/dist/cjs/cli/local-server-output.js +103 -0
  22. package/dist/cjs/cli/mcp.d.ts +8 -0
  23. package/dist/cjs/cli/mcp.js +121 -32
  24. package/dist/cjs/cli/migrate.d.ts +113 -5
  25. package/dist/cjs/cli/migrate.js +270 -21
  26. package/dist/cjs/cli/observe.d.ts +6 -1
  27. package/dist/cjs/cli/observe.js +85 -55
  28. package/dist/cjs/cli/pii-predicate-guard.d.ts +43 -23
  29. package/dist/cjs/cli/pii-predicate-guard.js +98 -37
  30. package/dist/cjs/cli/prisma-resolve.js +17 -13
  31. package/dist/cjs/cli/prisma-schema.js +12 -4
  32. package/dist/cjs/cli/studio-ui.generated.js +1 -1
  33. package/dist/cjs/cli/studio.d.ts +14 -2
  34. package/dist/cjs/cli/studio.js +244 -69
  35. package/dist/cjs/cli/ui.d.ts +1 -1
  36. package/dist/cjs/client.d.ts +558 -85
  37. package/dist/cjs/client.js +1270 -395
  38. package/dist/cjs/connection-guard.d.ts +13 -0
  39. package/dist/cjs/connection-guard.js +28 -0
  40. package/dist/cjs/connection-url.d.ts +51 -16
  41. package/dist/cjs/connection-url.js +67 -34
  42. package/dist/cjs/diagnostics.d.ts +81 -0
  43. package/dist/cjs/diagnostics.js +147 -0
  44. package/dist/cjs/dialect.d.ts +449 -20
  45. package/dist/cjs/dialect.js +117 -76
  46. package/dist/cjs/engine-config.d.ts +7 -6
  47. package/dist/cjs/errors.d.ts +126 -6
  48. package/dist/cjs/errors.js +256 -13
  49. package/dist/cjs/generate.d.ts +57 -7
  50. package/dist/cjs/generate.js +635 -279
  51. package/dist/cjs/global-filters-config.d.ts +59 -0
  52. package/dist/cjs/global-filters-config.js +367 -0
  53. package/dist/cjs/index.d.ts +9 -4
  54. package/dist/cjs/index.js +10 -2
  55. package/dist/cjs/introspect.d.ts +31 -6
  56. package/dist/cjs/introspect.js +108 -50
  57. package/dist/cjs/log-codes.d.ts +12 -0
  58. package/dist/cjs/log-codes.js +77 -0
  59. package/dist/cjs/logger.d.ts +87 -0
  60. package/dist/cjs/logger.js +98 -0
  61. package/dist/cjs/mssql.d.ts +8 -5
  62. package/dist/cjs/mssql.js +352 -65
  63. package/dist/cjs/mysql.d.ts +3 -5
  64. package/dist/cjs/mysql.js +420 -70
  65. package/dist/cjs/nested-write.d.ts +3 -0
  66. package/dist/cjs/nested-write.js +179 -114
  67. package/dist/cjs/pipeline-submittable.d.ts +12 -0
  68. package/dist/cjs/pipeline-submittable.js +118 -44
  69. package/dist/cjs/pipeline.js +21 -26
  70. package/dist/cjs/powdb-introspect.d.ts +5 -2
  71. package/dist/cjs/powdb-introspect.js +20 -15
  72. package/dist/cjs/powdb-shared.d.ts +36 -5
  73. package/dist/cjs/powdb-shared.js +67 -8
  74. package/dist/cjs/powdb.d.ts +4 -0
  75. package/dist/cjs/powdb.js +183 -51
  76. package/dist/cjs/powql.d.ts +394 -51
  77. package/dist/cjs/powql.js +1829 -284
  78. package/dist/cjs/prisma-compat.d.ts +23 -15
  79. package/dist/cjs/prisma-compat.js +507 -372
  80. package/dist/cjs/query/aggregates.d.ts +17 -1
  81. package/dist/cjs/query/aggregates.js +261 -29
  82. package/dist/cjs/query/batched-loader.d.ts +25 -6
  83. package/dist/cjs/query/batched-loader.js +103 -20
  84. package/dist/cjs/query/builder.d.ts +325 -184
  85. package/dist/cjs/query/builder.js +1452 -490
  86. package/dist/cjs/query/column-ref.d.ts +61 -0
  87. package/dist/cjs/query/column-ref.js +73 -0
  88. package/dist/cjs/query/compound-unique.d.ts +21 -0
  89. package/dist/cjs/query/compound-unique.js +98 -18
  90. package/dist/cjs/query/deferred.d.ts +53 -16
  91. package/dist/cjs/query/expr.d.ts +217 -0
  92. package/dist/cjs/query/expr.js +859 -0
  93. package/dist/cjs/query/filters.d.ts +155 -53
  94. package/dist/cjs/query/filters.js +613 -76
  95. package/dist/cjs/query/index.d.ts +2 -0
  96. package/dist/cjs/query/index.js +7 -1
  97. package/dist/cjs/query/json-value.d.ts +43 -0
  98. package/dist/cjs/query/json-value.js +59 -0
  99. package/dist/cjs/query/normalize-args.d.ts +87 -0
  100. package/dist/cjs/query/normalize-args.js +527 -0
  101. package/dist/cjs/query/option-surface.d.ts +16 -4
  102. package/dist/cjs/query/option-surface.js +57 -14
  103. package/dist/cjs/query/relation-names.d.ts +14 -0
  104. package/dist/cjs/query/relation-names.js +77 -18
  105. package/dist/cjs/query/relations.d.ts +30 -3
  106. package/dist/cjs/query/relations.js +219 -63
  107. package/dist/cjs/query/row-lock.d.ts +49 -0
  108. package/dist/cjs/query/row-lock.js +138 -0
  109. package/dist/cjs/query/sql-comment.d.ts +161 -0
  110. package/dist/cjs/query/sql-comment.js +381 -0
  111. package/dist/cjs/query/stream-idle.d.ts +132 -0
  112. package/dist/cjs/query/stream-idle.js +212 -0
  113. package/dist/cjs/query/table-client.d.ts +101 -0
  114. package/dist/cjs/query/table-client.js +74 -0
  115. package/dist/cjs/query/types.d.ts +677 -298
  116. package/dist/cjs/query/utils.d.ts +105 -6
  117. package/dist/cjs/query/utils.js +426 -19
  118. package/dist/cjs/query/warn-registry.d.ts +18 -0
  119. package/dist/cjs/query/warn-registry.js +18 -0
  120. package/dist/cjs/query/where-compile.d.ts +138 -14
  121. package/dist/cjs/query/where-compile.js +513 -29
  122. package/dist/cjs/query/where.d.ts +159 -59
  123. package/dist/cjs/query/where.js +716 -246
  124. package/dist/cjs/query/writes.d.ts +112 -50
  125. package/dist/cjs/query/writes.js +1498 -200
  126. package/dist/cjs/query-events.d.ts +4 -2
  127. package/dist/cjs/query-events.js +3 -1
  128. package/dist/cjs/realtime.d.ts +7 -3
  129. package/dist/cjs/realtime.js +13 -2
  130. package/dist/cjs/schema-builder.d.ts +55 -4
  131. package/dist/cjs/schema-builder.js +382 -18
  132. package/dist/cjs/schema-metadata.d.ts +21 -1
  133. package/dist/cjs/schema-metadata.js +29 -7
  134. package/dist/cjs/schema-sql.d.ts +75 -5
  135. package/dist/cjs/schema-sql.js +497 -45
  136. package/dist/cjs/schema.d.ts +26 -5
  137. package/dist/cjs/schema.js +110 -13
  138. package/dist/cjs/sql-placeholders.d.ts +56 -0
  139. package/dist/cjs/sql-placeholders.js +204 -0
  140. package/dist/cjs/sqlite.d.ts +75 -20
  141. package/dist/cjs/sqlite.js +593 -95
  142. package/dist/cjs/supplied-pool-types.d.ts +48 -0
  143. package/dist/cjs/supplied-pool-types.js +256 -0
  144. package/dist/cjs/transaction-control.d.ts +51 -0
  145. package/dist/cjs/transaction-control.js +316 -0
  146. package/dist/cjs/transaction-state.d.ts +342 -0
  147. package/dist/cjs/transaction-state.js +707 -0
  148. package/dist/cjs/typed-sql.d.ts +37 -3
  149. package/dist/cjs/typed-sql.js +102 -8
  150. package/dist/cli/code-first-tags.d.ts +62 -0
  151. package/dist/cli/code-first-tags.js +120 -0
  152. package/dist/cli/compile-query.js +9 -0
  153. package/dist/cli/config.d.ts +35 -6
  154. package/dist/cli/config.js +16 -1
  155. package/dist/cli/destructive.d.ts +7 -4
  156. package/dist/cli/destructive.js +224 -20
  157. package/dist/cli/error-catalog.js +36 -0
  158. package/dist/cli/error-text.d.ts +15 -0
  159. package/dist/cli/error-text.js +37 -0
  160. package/dist/cli/index.d.ts +62 -4
  161. package/dist/cli/index.js +569 -112
  162. package/dist/cli/local-server-guard.d.ts +53 -0
  163. package/dist/cli/local-server-guard.js +113 -0
  164. package/dist/cli/local-server-output.d.ts +41 -0
  165. package/dist/cli/local-server-output.js +98 -0
  166. package/dist/cli/mcp.d.ts +8 -0
  167. package/dist/cli/mcp.js +121 -34
  168. package/dist/cli/migrate.d.ts +113 -5
  169. package/dist/cli/migrate.js +261 -21
  170. package/dist/cli/observe.d.ts +6 -1
  171. package/dist/cli/observe.js +84 -54
  172. package/dist/cli/pii-predicate-guard.d.ts +43 -23
  173. package/dist/cli/pii-predicate-guard.js +100 -35
  174. package/dist/cli/prisma-resolve.js +15 -11
  175. package/dist/cli/prisma-schema.js +12 -4
  176. package/dist/cli/studio-ui.generated.js +1 -1
  177. package/dist/cli/studio.d.ts +14 -2
  178. package/dist/cli/studio.js +246 -71
  179. package/dist/cli/ui.d.ts +1 -1
  180. package/dist/client.d.ts +558 -85
  181. package/dist/client.js +1275 -400
  182. package/dist/connection-guard.d.ts +13 -0
  183. package/dist/connection-guard.js +27 -0
  184. package/dist/connection-url.d.ts +51 -16
  185. package/dist/connection-url.js +63 -34
  186. package/dist/diagnostics.d.ts +81 -0
  187. package/dist/diagnostics.js +144 -0
  188. package/dist/dialect.d.ts +449 -20
  189. package/dist/dialect.js +115 -43
  190. package/dist/engine-config.d.ts +7 -6
  191. package/dist/errors.d.ts +126 -6
  192. package/dist/errors.js +252 -12
  193. package/dist/generate.d.ts +57 -7
  194. package/dist/generate.js +635 -281
  195. package/dist/global-filters-config.d.ts +59 -0
  196. package/dist/global-filters-config.js +361 -0
  197. package/dist/index.d.ts +9 -4
  198. package/dist/index.js +4 -2
  199. package/dist/introspect.d.ts +31 -6
  200. package/dist/introspect.js +106 -50
  201. package/dist/log-codes.d.ts +12 -0
  202. package/dist/log-codes.js +74 -0
  203. package/dist/logger.d.ts +87 -0
  204. package/dist/logger.js +93 -0
  205. package/dist/mssql.d.ts +8 -5
  206. package/dist/mssql.js +354 -67
  207. package/dist/mysql.d.ts +3 -5
  208. package/dist/mysql.js +423 -73
  209. package/dist/nested-write.d.ts +3 -0
  210. package/dist/nested-write.js +177 -112
  211. package/dist/pipeline-submittable.d.ts +12 -0
  212. package/dist/pipeline-submittable.js +117 -44
  213. package/dist/pipeline.js +21 -26
  214. package/dist/powdb-introspect.d.ts +5 -2
  215. package/dist/powdb-introspect.js +21 -16
  216. package/dist/powdb-shared.d.ts +36 -5
  217. package/dist/powdb-shared.js +65 -8
  218. package/dist/powdb.d.ts +4 -0
  219. package/dist/powdb.js +183 -51
  220. package/dist/powql.d.ts +394 -51
  221. package/dist/powql.js +1836 -291
  222. package/dist/prisma-compat.d.ts +23 -15
  223. package/dist/prisma-compat.js +508 -373
  224. package/dist/query/aggregates.d.ts +17 -1
  225. package/dist/query/aggregates.js +263 -32
  226. package/dist/query/batched-loader.d.ts +25 -6
  227. package/dist/query/batched-loader.js +101 -21
  228. package/dist/query/builder.d.ts +325 -184
  229. package/dist/query/builder.js +1458 -495
  230. package/dist/query/column-ref.d.ts +61 -0
  231. package/dist/query/column-ref.js +66 -0
  232. package/dist/query/compound-unique.d.ts +21 -0
  233. package/dist/query/compound-unique.js +97 -19
  234. package/dist/query/deferred.d.ts +53 -16
  235. package/dist/query/expr.d.ts +217 -0
  236. package/dist/query/expr.js +848 -0
  237. package/dist/query/filters.d.ts +155 -53
  238. package/dist/query/filters.js +597 -72
  239. package/dist/query/index.d.ts +2 -0
  240. package/dist/query/index.js +4 -0
  241. package/dist/query/json-value.d.ts +43 -0
  242. package/dist/query/json-value.js +54 -0
  243. package/dist/query/normalize-args.d.ts +87 -0
  244. package/dist/query/normalize-args.js +517 -0
  245. package/dist/query/option-surface.d.ts +16 -4
  246. package/dist/query/option-surface.js +56 -13
  247. package/dist/query/relation-names.d.ts +14 -0
  248. package/dist/query/relation-names.js +77 -19
  249. package/dist/query/relations.d.ts +30 -3
  250. package/dist/query/relations.js +220 -67
  251. package/dist/query/row-lock.d.ts +49 -0
  252. package/dist/query/row-lock.js +131 -0
  253. package/dist/query/sql-comment.d.ts +161 -0
  254. package/dist/query/sql-comment.js +374 -0
  255. package/dist/query/stream-idle.d.ts +132 -0
  256. package/dist/query/stream-idle.js +203 -0
  257. package/dist/query/table-client.d.ts +101 -0
  258. package/dist/query/table-client.js +70 -0
  259. package/dist/query/types.d.ts +677 -298
  260. package/dist/query/utils.d.ts +105 -6
  261. package/dist/query/utils.js +414 -18
  262. package/dist/query/warn-registry.d.ts +18 -0
  263. package/dist/query/warn-registry.js +18 -0
  264. package/dist/query/where-compile.d.ts +138 -14
  265. package/dist/query/where-compile.js +508 -31
  266. package/dist/query/where.d.ts +159 -59
  267. package/dist/query/where.js +711 -248
  268. package/dist/query/writes.d.ts +112 -50
  269. package/dist/query/writes.js +1496 -202
  270. package/dist/query-events.d.ts +4 -2
  271. package/dist/query-events.js +3 -1
  272. package/dist/realtime.d.ts +7 -3
  273. package/dist/realtime.js +13 -2
  274. package/dist/schema-builder.d.ts +55 -4
  275. package/dist/schema-builder.js +381 -18
  276. package/dist/schema-metadata.d.ts +21 -1
  277. package/dist/schema-metadata.js +28 -7
  278. package/dist/schema-sql.d.ts +75 -5
  279. package/dist/schema-sql.js +494 -44
  280. package/dist/schema.d.ts +26 -5
  281. package/dist/schema.js +109 -13
  282. package/dist/sql-placeholders.d.ts +56 -0
  283. package/dist/sql-placeholders.js +200 -0
  284. package/dist/sqlite.d.ts +75 -20
  285. package/dist/sqlite.js +597 -99
  286. package/dist/supplied-pool-types.d.ts +48 -0
  287. package/dist/supplied-pool-types.js +247 -0
  288. package/dist/transaction-control.d.ts +51 -0
  289. package/dist/transaction-control.js +311 -0
  290. package/dist/transaction-state.d.ts +342 -0
  291. package/dist/transaction-state.js +696 -0
  292. package/dist/typed-sql.d.ts +37 -3
  293. package/dist/typed-sql.js +100 -8
  294. package/package.json +7 -4
  295. package/skills/turbine-orm/SKILL.md +56 -6
@@ -0,0 +1,342 @@
1
+ /**
2
+ * turbine-orm, the state one open transaction shares
3
+ *
4
+ * Everything a `$transaction` hands out (table accessors, raw SQL, nested
5
+ * `$transaction` blocks, streams) runs on ONE pooled connection. This module
6
+ * owns what those share:
7
+ *
8
+ * - whether the transaction is still open. Once it settles, a `tx` that was
9
+ * captured somewhere (an un-awaited promise, an `async` `forEach`, a timer)
10
+ * must not send anything: its connection is back in the pool and may
11
+ * already be running another request's transaction.
12
+ * - the first statement failure. PostgreSQL aborts a transaction at its first
13
+ * error and answers the COMMIT that follows with `ROLLBACK`; that failure is
14
+ * what the caller needs to see as the cause.
15
+ * - savepoint blocks. Savepoints are a stack on the connection, so two blocks
16
+ * open at once would share it and a rollback in one would undo the other.
17
+ * Blocks that share a parent therefore run one at a time, and a statement
18
+ * at the parent's level waits for a block opened before it.
19
+ * - what is still running: statements on the wire (what a cancel request
20
+ * stops, and what a ROLLBACK must wait for) and work started but not
21
+ * settled (which, when the callback returns, means a missing `await`).
22
+ * - whether the server's transaction is already aborted. On PostgreSQL a
23
+ * failed statement leaves the transaction ignoring every statement until a
24
+ * rollback to a savepoint set before it, so a statement sent then is
25
+ * refused here, with the failure that caused it, instead of coming back as
26
+ * an untyped SQLSTATE 25P02 that no retry would recognise.
27
+ * - which `tx` a statement came through. A nested block's callback gets its
28
+ * own handle, and a statement through an OUTER handle from inside the
29
+ * block is refused: it would run in the block's savepoint and be undone
30
+ * with it.
31
+ * - transaction-control SQL on the raw paths, which is refused (see
32
+ * {@link TransactionState.runRaw}).
33
+ *
34
+ * A leaf (errors.ts, the zero-import transaction-control.ts, and type-only
35
+ * imports), so query/ can reach it without an import edge back to client.ts: a QueryInterface inside a transaction holds
36
+ * only its pool, and that pool carries this state under
37
+ * {@link TRANSACTION_STATE}.
38
+ */
39
+ import type { Dialect } from './dialect.js';
40
+ import { ValidationError } from './errors.js';
41
+ import type { PgCompatPoolClient, PgCompatQueryResult } from './pg-types.js';
42
+ /** The key a transaction-scoped pool carries its {@link TransactionState} under. */
43
+ export declare const TRANSACTION_STATE: unique symbol;
44
+ /** How a transaction ended, phrased to complete "This transaction ...". */
45
+ export type TransactionEnd = 'has ended' | 'committed' | 'was rolled back' | 'timed out';
46
+ /** The API that opened a transaction, which its error messages name. */
47
+ export type TransactionApi = '$transaction' | 'transaction';
48
+ type SavepointDialect = Pick<Dialect, 'capabilities' | 'savepointStatement' | 'releaseSavepointStatement' | 'rollbackToSavepointStatement'>;
49
+ /**
50
+ * One level of savepoint nesting: the transaction itself, or an open block.
51
+ * Also what a `tx` handle is bound to (see {@link TransactionState.run}), so it
52
+ * is exported as an opaque token: nothing outside this file reads its fields.
53
+ */
54
+ export interface TransactionScope {
55
+ readonly state: TransactionState;
56
+ /** The frame this one is nested in (undefined for the transaction). */
57
+ readonly parent: TransactionScope | undefined;
58
+ /**
59
+ * True for the transaction and for a block `tx.$transaction` handed its own
60
+ * `tx`; false for the savepoint one multi-statement write runs in, which has
61
+ * no handle of its own and is part of the handle that issued the write.
62
+ */
63
+ readonly handle: boolean;
64
+ /** Settles when every block registered on this frame's child slot is done. */
65
+ tail: Promise<void>;
66
+ /** Blocks registered on {@link tail} that have not finished. */
67
+ children: number;
68
+ /** The tick at which this frame's savepoint was set (0 for the transaction). */
69
+ readonly openedAt: number;
70
+ /** True from the moment the frame's savepoint is set until it is released or rolled back. */
71
+ open: boolean;
72
+ }
73
+ export interface TransactionStateOptions {
74
+ /** The API that opened the transaction (default `$transaction`). */
75
+ api?: TransactionApi;
76
+ /**
77
+ * True for a transaction the CALLER opened (`$transaction`, `$withSession`).
78
+ * Multi-statement writes inside one get a savepoint of their own, so a
79
+ * failure part way through cannot leave half of the write behind in a
80
+ * transaction that goes on to commit. An internal transaction (a nested
81
+ * write's own BEGIN/COMMIT) is atomic already and gets none.
82
+ */
83
+ userTransaction?: boolean;
84
+ }
85
+ export declare class TransactionState {
86
+ readonly client: PgCompatPoolClient;
87
+ private readonly dialect;
88
+ /** True when multi-statement writes run inside their own savepoint (see {@link withSavepoint}). */
89
+ readonly savepointWrites: boolean;
90
+ private endedAs;
91
+ private failure;
92
+ /** A statement cut short that may still have run: the transaction must roll back (see {@link abort}). */
93
+ private aborted;
94
+ /**
95
+ * The server's own error that left the PostgreSQL transaction in its aborted
96
+ * state, until a rollback to a savepoint set before it. Only recorded where
97
+ * a failed statement aborts the transaction (see {@link abortsOnError}) and
98
+ * only for a failure the SERVER reported: a client-side error (a value the
99
+ * driver could not serialize) never reached the transaction and changes
100
+ * nothing about what it will accept.
101
+ */
102
+ private dead;
103
+ /** True where one failed statement makes the server ignore the rest of the transaction (PostgreSQL). */
104
+ private readonly abortsOnError;
105
+ /** The lexical rules for finding transaction-control SQL in raw text, or undefined where none apply (PowDB). */
106
+ private readonly controlSyntax;
107
+ private tick;
108
+ private savepointCount;
109
+ private readonly root;
110
+ /** Frames whose SAVEPOINT is set and not yet released or rolled back, outermost first. */
111
+ private readonly openFrames;
112
+ /** Statements sent on the connection that have not answered yet. */
113
+ private onWire;
114
+ /** Statements and savepoint blocks started through the transaction that have not settled. */
115
+ private started;
116
+ private idleWaiters;
117
+ /** Settles at the first {@link end}, releasing anything still queued behind a block. */
118
+ private readonly endedSignal;
119
+ private signalEnded;
120
+ private readonly api;
121
+ constructor(client: PgCompatPoolClient, dialect: SavepointDialect, options?: TransactionStateOptions);
122
+ /** Whether the transaction has settled (see {@link end}). */
123
+ get ended(): boolean;
124
+ /**
125
+ * The first statement failure not undone by a savepoint rollback, if any.
126
+ * Where the server aborted the transaction, the failure that did it: that is
127
+ * the one a retry decision follows.
128
+ */
129
+ get firstFailure(): unknown;
130
+ /** The scope of the transaction itself: what the `tx` handed to the callback is bound to. */
131
+ get rootScope(): TransactionScope;
132
+ /** Why the transaction must roll back instead of committing (see {@link abort}), if it must. */
133
+ get abortedWith(): unknown;
134
+ /**
135
+ * Whether a statement or savepoint block started through the transaction is
136
+ * still running. True when the callback settles means work it started was
137
+ * not awaited.
138
+ */
139
+ get busy(): boolean;
140
+ /** Whether a statement is on the wire right now (what a cancel request would stop). */
141
+ get running(): boolean;
142
+ /**
143
+ * Run the transaction's callback. Statements and blocks it starts are then
144
+ * known to sit at the transaction's top level, which is what lets a block
145
+ * whose async context was lost be told apart from a sibling.
146
+ */
147
+ enter<R>(fn: () => R): R;
148
+ /**
149
+ * Resolve `true` once no statement is on the wire, or `false` after `ms`.
150
+ * Called after {@link end}, when nothing new can be sent.
151
+ */
152
+ whenIdle(ms: number): Promise<boolean>;
153
+ /**
154
+ * Mark the transaction settled. Called as soon as the callback settles,
155
+ * BEFORE the COMMIT or ROLLBACK, and again with the outcome; from the first
156
+ * call on every statement issued through the transaction is refused.
157
+ */
158
+ end(how: TransactionEnd): void;
159
+ /** Throw the closed-transaction error when the transaction has settled. */
160
+ assertOpen(): void;
161
+ /**
162
+ * Run a statement issued THROUGH the transaction (an accessor, raw SQL, a
163
+ * stream): refused once the transaction has settled, and its failure recorded
164
+ * as a candidate cause for a later ROLLBACK-at-COMMIT.
165
+ *
166
+ * `scope` is the handle the statement came through (the transaction's own
167
+ * `tx`, or the one a nested block's callback received). A statement through
168
+ * an OUTER handle from inside an open block is refused: it would run in the
169
+ * block's savepoint and be undone with it.
170
+ *
171
+ * A statement issued while a savepoint block started before it at the same
172
+ * level is still open waits for that block. Sent at once it would run inside
173
+ * the block's savepoint and be undone if the block rolled back, after it had
174
+ * already reported success.
175
+ *
176
+ * On PostgreSQL a statement sent after one failed is not sent at all: the
177
+ * server would ignore it (SQLSTATE 25P02) and the failure that caused that
178
+ * would be lost. `recovery` marks the one statement that is sent regardless,
179
+ * a rollback to a savepoint the caller set by hand (see {@link runRaw}).
180
+ */
181
+ run<T>(statement: () => Promise<T>, scope?: TransactionScope, recovery?: boolean): Promise<T>;
182
+ /**
183
+ * {@link run} for a statement the caller wrote (`tx.raw`, `tx.rawUnsafe`,
184
+ * `tx.sql`, the connection `$connection()` and `transaction()` hand out).
185
+ *
186
+ * Transaction-control SQL is refused with E003 before anything is sent.
187
+ * `COMMIT`, `ROLLBACK` or `BEGIN` ends or reshapes the transaction behind the
188
+ * state that tracks it, so later writes would autocommit and the callback's
189
+ * own throw would keep them. A savepoint of the caller's own sits on the
190
+ * connection's stack beside the ones Turbine sets, so those are refused too
191
+ * inside `$transaction`, where `tx.$transaction(...)` is the savepoint.
192
+ *
193
+ * The raw `transaction()` API has no such block, so `SAVEPOINT`, `RELEASE`
194
+ * and `ROLLBACK TO` stay available there: the only way to recover from a
195
+ * failed statement without losing the transaction. A `ROLLBACK TO` is also
196
+ * the one statement sent while the transaction is aborted, and when it
197
+ * succeeds the abort is over.
198
+ */
199
+ runRaw<T>(sql: unknown, statement: () => Promise<T>, scope?: TransactionScope): Promise<T>;
200
+ /**
201
+ * Check raw SQL for transaction control without sending it: throws E003 for
202
+ * a statement the caller may not send, and answers whether the text rolls
203
+ * back to a savepoint (the one control statement that is allowed to run in an
204
+ * aborted transaction).
205
+ */
206
+ screenRaw(sql: unknown): boolean;
207
+ /** Put one statement on the wire, counted for {@link whenIdle} and recorded on failure. */
208
+ private send;
209
+ /** Record `err` as the first failure, unless one is already recorded. */
210
+ noteFailure(err: unknown): void;
211
+ /** Record `err` as what aborted the server's transaction, unless something already did. */
212
+ private noteDead;
213
+ /**
214
+ * Mark the transaction as one that must not commit, because of `err`: a
215
+ * statement timed out and was cancelled, and whether it ran cannot be
216
+ * relied on. The server aborts the transaction when the cancel lands, but a
217
+ * cancel that arrives after the statement finished does nothing, and a
218
+ * COMMIT would then keep it. A rollback to a savepoint set before the
219
+ * statement clears the mark, as it clears the failure.
220
+ *
221
+ * Statements after it are refused like those after any failed statement: the
222
+ * transaction cannot commit, so there is nothing to send them for.
223
+ */
224
+ abort(err: unknown): void;
225
+ /**
226
+ * Refuse a statement the PostgreSQL transaction would ignore, with the
227
+ * failure that aborted it. The same error a COMMIT in this state gets
228
+ * ({@link rolledBackError}), so a deadlock, serialization conflict or lock
229
+ * wait that was caught and followed by one more statement is still the
230
+ * retryable class `$retry` looks for.
231
+ */
232
+ private assertNotAborted;
233
+ /** The caller rolled back to a savepoint of their own and the server accepted it: the abort is over. */
234
+ private clearAbort;
235
+ /**
236
+ * Refuse `what` issued through `scope` when the async context it was issued
237
+ * from is inside a block opened through a handle nested under `scope`.
238
+ *
239
+ * `tx.$transaction(async (inner) => { await tx.users.update(...) })` sends
240
+ * the update through the OUTER handle, but the connection is inside the
241
+ * block's savepoint, so a throw from the block would undo an update the
242
+ * caller placed outside it. The block's callback has its own handle for work
243
+ * inside it. A context this state cannot see (a timer created before the
244
+ * transaction, a callback API that drops the async context) is not refused:
245
+ * it cannot be told apart from a statement at the right level.
246
+ */
247
+ private assertNotFromInsideBlock;
248
+ /**
249
+ * Run `block` inside a savepoint: released when it resolves, rolled back to
250
+ * when it rejects, so the rest of the transaction is unaffected either way.
251
+ *
252
+ * Blocks that share a parent run one at a time. A savepoint is a position on
253
+ * the connection's one stack, so a block that opened second sits inside the
254
+ * first: rolling the first back would discard the second even after it had
255
+ * released and reported success. A block started from INSIDE another block's
256
+ * callback is nested under it and does not wait.
257
+ *
258
+ * A block whose callback swallowed a statement failure resolves normally,
259
+ * but PostgreSQL refuses to RELEASE a savepoint inside an aborted
260
+ * transaction. That case rolls the savepoint back and rejects with the same
261
+ * rolled-back error a COMMIT gets, carrying the failure as `cause`, so the
262
+ * outer transaction stays usable.
263
+ *
264
+ * This is the savepoint of ONE multi-statement write, which belongs to the
265
+ * handle that issued it. {@link withBlock} is a block the caller opened.
266
+ */
267
+ withSavepoint<R>(block: () => Promise<R>): Promise<R>;
268
+ /**
269
+ * Run `block` as a nested `tx.$transaction(...)`: a savepoint (see
270
+ * {@link withSavepoint}) whose callback receives a handle of its own, bound to
271
+ * the scope it is given. `caller` is the handle `$transaction` was called on.
272
+ */
273
+ withBlock<R>(block: (scope: TransactionScope) => Promise<R>, caller: TransactionScope): Promise<R>;
274
+ private openSavepoint;
275
+ /** The recorded failure, when it happened after `frame`'s savepoint was set. */
276
+ private failureSince;
277
+ /**
278
+ * What stops `frame` from being released: a statement cut short by its
279
+ * timeout, or (on PostgreSQL) a failure the server aborted the savepoint for,
280
+ * either one after the savepoint was set.
281
+ */
282
+ private doomedSince;
283
+ private rollbackTo;
284
+ /**
285
+ * A savepoint statement: refused once settled, failures recorded and typed.
286
+ * Typed INSIDE the statement, so the failure the state records is the Turbine
287
+ * error and not the driver's.
288
+ */
289
+ private control;
290
+ }
291
+ /** The state carried by a transaction-scoped pool, or undefined for any other pool. */
292
+ export declare function transactionStateOf(pool: unknown): TransactionState | undefined;
293
+ /**
294
+ * Run a multi-statement operation as one unit inside the caller's transaction.
295
+ *
296
+ * When `pool` belongs to a transaction the caller opened (`$transaction`,
297
+ * `$withSession`), `operation` runs inside its own savepoint: if it throws
298
+ * part way through, the statements it already ran are rolled back and the
299
+ * caller's transaction carries on as if the operation had never started. On
300
+ * any other pool (no transaction, or Turbine's own implicit transaction, which
301
+ * is atomic already) it simply runs `operation`.
302
+ *
303
+ * Every user-facing write that issues more than one statement inside a
304
+ * transaction already goes through this from `TransactionClient`'s accessors
305
+ * (nested creates and updates, lookup-first upserts); call it from any new
306
+ * multi-statement operation that can be reached some other way.
307
+ */
308
+ export declare function withSavepoint<R>(pool: unknown, operation: () => Promise<R>): Promise<R>;
309
+ /**
310
+ * Send COMMIT and refuse to report success when the server rolled back instead.
311
+ *
312
+ * PostgreSQL answers COMMIT in an aborted transaction with the command tag
313
+ * `ROLLBACK` and no error. Other engines never set `command` on a COMMIT
314
+ * result, so the check is inert for them.
315
+ */
316
+ export declare function commitTransaction(client: {
317
+ query(text: string): Promise<PgCompatQueryResult>;
318
+ }, commitSql: string, firstFailure?: unknown, api?: TransactionApi): Promise<void>;
319
+ /** Whether a COMMIT result reports that the server rolled the transaction back. */
320
+ export declare function commitWasRolledBack(result: {
321
+ command?: string;
322
+ } | null | undefined): boolean;
323
+ /**
324
+ * The error for work that was rolled back although the caller expected it to
325
+ * commit (a transaction) or be kept (a savepoint block).
326
+ *
327
+ * A retryable first failure (deadlock, serialization conflict, lock not
328
+ * available) keeps its class, so `$retry` and `isRetryable` checks retry the
329
+ * whole transaction, which is the documented response to all three. Anything
330
+ * else is a {@link TransactionRolledBackError} (E019) with the first failure as
331
+ * `cause`: nothing was committed, and the server did the rolling back.
332
+ */
333
+ export declare function rolledBackError(firstFailure: unknown, scope: 'transaction' | 'savepoint' | 'statement', api?: TransactionApi): Error;
334
+ /** The error for a statement sent through a transaction that has settled. */
335
+ export declare function closedTransactionError(how: TransactionEnd, api?: TransactionApi): ValidationError;
336
+ /**
337
+ * The error for a callback that returned while work it started through the
338
+ * transaction was still running. Committing then would save whatever part of
339
+ * that work had run, so the transaction is rolled back instead.
340
+ */
341
+ export declare function unawaitedWorkError(api: TransactionApi): ValidationError;
342
+ export {};