@bastani/atomic 0.10.11-alpha.3 → 0.10.11-alpha.4

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 (288) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/dist/_shared/dist-KOELCESV.js +2 -2
  3. package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
  4. package/dist/_shared/lib-4PES5P4V.js +2 -2
  5. package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +4 -4
  6. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +4 -4
  7. package/dist/_shared/mode-shared-2QJSCUM6.js +4 -4
  8. package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
  9. package/dist/_shared/p1b-elig-TVB5CBLL.js +22 -6
  10. package/dist/_shared/p1b-elig-TVB5CBLL.js.map +1 -1
  11. package/dist/_shared/p2-shell-main-B2WIALFD.js +6 -3
  12. package/dist/_shared/p2-shell-main-B2WIALFD.js.map +1 -1
  13. package/dist/_shared/runtime-O4KCSG4C.js +2 -2
  14. package/dist/_shared/sdk-B5LEWGGI.js +899 -515
  15. package/dist/_shared/sdk-B5LEWGGI.js.map +1 -1
  16. package/dist/_shared/session-data-AHTU7IS6.js +2 -2
  17. package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
  18. package/dist/_shared/{startup-0-0-EZUKEP4Q.js → startup-0-0-XJJDOIEC.js} +6 -12
  19. package/dist/_shared/{startup-0-0-EZUKEP4Q.js.map → startup-0-0-XJJDOIEC.js.map} +1 -1
  20. package/dist/_shared/{startup-0-1-RTOHJFDJ.js → startup-0-1-M6OWAYHH.js} +354 -103
  21. package/dist/_shared/startup-0-1-M6OWAYHH.js.map +1 -0
  22. package/dist/_shared/startup-0-2-5QHPCEON.js +18 -9
  23. package/dist/_shared/startup-0-2-5QHPCEON.js.map +1 -1
  24. package/dist/_shared/startup-0-3-4ZYBYQNM.js +4 -4
  25. package/dist/_shared/startup-0-4-ZMJV547D.js +4 -4
  26. package/dist/_shared/startup-0-5-YDW47QX6.js +4 -4
  27. package/dist/_shared/startup-10-0-TDQNBDDL.js +4 -4
  28. package/dist/_shared/startup-12-0-55AAXBJZ.js +1 -1
  29. package/dist/_shared/startup-14-0-MLX36RBG.js +2 -2
  30. package/dist/_shared/startup-15-0-YUKGAC63.js +2 -2
  31. package/dist/_shared/startup-15-1-4S7FLMNG.js +4 -4
  32. package/dist/_shared/startup-8-0-34CBHPZH.js +2114 -235
  33. package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
  34. package/dist/_shared/startup-8-1-LZFXSD3Z.js +12 -12
  35. package/dist/_shared/storage-command-7MGXLJGZ.js +6 -6
  36. package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
  37. package/dist/_shared/storage-status-K7PX2RXA.js +2 -2
  38. package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
  39. package/dist/_shared/team-DOQKICG2.js +1 -1
  40. package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
  41. package/dist/builtin/intercom/CHANGELOG.md +19 -0
  42. package/dist/builtin/intercom/broker/broker.bundle.mjs +1020 -108
  43. package/dist/builtin/intercom/broker/client.ts +8 -0
  44. package/dist/builtin/intercom/broker/database-wake-up-bus.ts +91 -14
  45. package/dist/builtin/intercom/broker/multinode-router.ts +102 -17
  46. package/dist/builtin/intercom/broker/multinode-state-store.ts +41 -2
  47. package/dist/builtin/intercom/broker/send-order-gate.ts +5 -2
  48. package/dist/builtin/intercom/broker/sql-add-column.ts +22 -1
  49. package/dist/builtin/intercom/broker/sql-lease-store.ts +304 -48
  50. package/dist/builtin/intercom/broker/sql-outbox-store.ts +541 -50
  51. package/dist/builtin/intercom/broker/sql-restoring-reservation-store.ts +239 -8
  52. package/dist/builtin/intercom/broker/sql-retention.ts +11 -2
  53. package/dist/builtin/intercom/broker/sql-schema.ts +42 -8
  54. package/dist/builtin/intercom/index.bundle.mjs +13 -2
  55. package/dist/builtin/intercom/package.json +1 -1
  56. package/dist/builtin/mcp/index.bundle.mjs +1 -1
  57. package/dist/builtin/mcp/package.json +1 -1
  58. package/dist/builtin/subagents/CHANGELOG.md +6 -0
  59. package/dist/builtin/subagents/package.json +1 -1
  60. package/dist/builtin/subagents/skills/skill-creator/eval-viewer/generate_review.py +8 -1
  61. package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
  62. package/dist/builtin/web-access/index.bundle.mjs +1 -1
  63. package/dist/builtin/web-access/package.json +1 -1
  64. package/dist/cli/args.js +2 -2
  65. package/dist/cli/auth-cli.code.js +2 -2
  66. package/dist/cli/auth-cli.impl.js +3 -3
  67. package/dist/cli/auth-cli.js +3 -3
  68. package/dist/cli/blueprint-command.code.js +1 -1
  69. package/dist/cli/blueprint-command.impl.js +3 -3
  70. package/dist/cli/blueprint-command.js +3 -3
  71. package/dist/cli/intercom-command.code.js +2 -2
  72. package/dist/cli/intercom-command.impl.js +3 -3
  73. package/dist/cli/intercom-command.js +3 -3
  74. package/dist/cli/list-models.code.js +2 -2
  75. package/dist/cli/list-models.impl.js +3 -3
  76. package/dist/cli/list-models.js +3 -3
  77. package/dist/cli/session-picker.code.js +1 -1
  78. package/dist/cli/session-picker.impl.js +3 -3
  79. package/dist/cli/session-picker.js +3 -3
  80. package/dist/cli/startup-ui.code.js +1 -1
  81. package/dist/cli/startup-ui.impl.js +3 -3
  82. package/dist/cli/startup-ui.js +3 -3
  83. package/dist/cli/storage-command.impl.js +3 -3
  84. package/dist/cli/storage-command.js +3 -3
  85. package/dist/cli/storage-search-session.code.js +1 -1
  86. package/dist/cli/storage-search-session.impl.js +3 -3
  87. package/dist/cli/storage-search-session.js +3 -3
  88. package/dist/cli/team-command.code.js +1 -1
  89. package/dist/cli/team-command.impl.js +3 -3
  90. package/dist/cli/team-command.js +3 -3
  91. package/dist/cli.js +2 -2
  92. package/dist/core/debug.impl.js +3 -3
  93. package/dist/core/debug.js +3 -3
  94. package/dist/core/export-html/card-projection.impl.js +3 -3
  95. package/dist/core/export-html/card-projection.js +3 -3
  96. package/dist/core/export-html/index.code.js +4 -4
  97. package/dist/core/export-html/index.code.js.map +1 -1
  98. package/dist/core/export-html/index.impl.js +3 -3
  99. package/dist/core/export-html/index.js +3 -3
  100. package/dist/core/export-html/json-spans.impl.js +3 -3
  101. package/dist/core/export-html/json-spans.js +3 -3
  102. package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
  103. package/dist/core/export-html/oversized-render-inputs.js +3 -3
  104. package/dist/core/export-html/tool-renderer.impl.js +3 -3
  105. package/dist/core/export-html/tool-renderer.js +3 -3
  106. package/dist/core/extensions/jiti-loader.impl.js +3 -3
  107. package/dist/core/extensions/jiti-loader.js +3 -3
  108. package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
  109. package/dist/core/extensions/jiti-static-loader.js +3 -3
  110. package/dist/core/extensions/loader-host-modules.code.js +1 -1
  111. package/dist/core/extensions/loader-host-modules.impl.js +3 -3
  112. package/dist/core/extensions/loader-host-modules.js +3 -3
  113. package/dist/core/extensions/loader-virtual-modules.js +1 -1
  114. package/dist/core/extensions/runner-context.js +1 -1
  115. package/dist/core/intercom-broker-control-host.impl.js +3 -3
  116. package/dist/core/intercom-broker-control-host.js +3 -3
  117. package/dist/core/intercom-broker-control.code.js +3 -3
  118. package/dist/core/intercom-broker-control.impl.js +3 -3
  119. package/dist/core/intercom-broker-control.js +3 -3
  120. package/dist/core/package-manager-storage-adapters.impl.js +3 -3
  121. package/dist/core/package-manager-storage-adapters.js +3 -3
  122. package/dist/core/process-start-token.d.ts +5 -4
  123. package/dist/core/sdk.code.js +2 -2
  124. package/dist/core/sdk.impl.js +3 -3
  125. package/dist/core/sdk.js +3 -3
  126. package/dist/core/session-manager-core.js +4 -4
  127. package/dist/core/session-manager-list.impl.js +3 -3
  128. package/dist/core/session-manager-list.js +3 -3
  129. package/dist/core/session-manager.code.js +1 -1
  130. package/dist/core/session-manager.impl.js +3 -3
  131. package/dist/core/session-manager.js +3 -3
  132. package/dist/core/session-storage.impl.js +3 -3
  133. package/dist/core/session-storage.js +3 -3
  134. package/dist/core/storage/database.d.ts +6 -0
  135. package/dist/core/storage/database.js.map +1 -1
  136. package/dist/core/storage/fenced-paths.d.ts +7 -6
  137. package/dist/core/storage/fenced-paths.js +7 -6
  138. package/dist/core/storage/fenced-paths.js.map +1 -1
  139. package/dist/core/storage/index.js +2 -2
  140. package/dist/core/storage/node-sqlite-thread.js +209 -19
  141. package/dist/core/storage/node-sqlite-thread.js.map +1 -1
  142. package/dist/core/storage/node-sqlite.js +435 -71
  143. package/dist/core/storage/node-sqlite.js.map +1 -1
  144. package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
  145. package/dist/core/storage/offline-snapshot-file.js +3 -3
  146. package/dist/core/storage/provider.js +2 -2
  147. package/dist/core/storage/schema-catalog.d.ts +69 -7
  148. package/dist/core/storage/schema-catalog.js +352 -61
  149. package/dist/core/storage/schema-catalog.js.map +1 -1
  150. package/dist/core/storage/selection.js +2 -2
  151. package/dist/core/storage/session/branch-fork-source.code.js +2 -2
  152. package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
  153. package/dist/core/storage/session/branch-fork-source.js +3 -3
  154. package/dist/core/storage/session/card-view.impl.js +3 -3
  155. package/dist/core/storage/session/card-view.js +3 -3
  156. package/dist/core/storage/session/child-reader.code.js +3 -3
  157. package/dist/core/storage/session/child-reader.impl.js +3 -3
  158. package/dist/core/storage/session/child-reader.js +3 -3
  159. package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
  160. package/dist/core/storage/session/chunked-resume-projection.js +3 -3
  161. package/dist/core/storage/session/expanded-child-details.code.js +2 -2
  162. package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
  163. package/dist/core/storage/session/expanded-child-details.js +3 -3
  164. package/dist/core/storage/session/fork-detach.d.ts +11 -1
  165. package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
  166. package/dist/core/storage/session/fork-row-bytes.js +3 -3
  167. package/dist/core/storage/session/fork-row-index.impl.js +3 -3
  168. package/dist/core/storage/session/fork-row-index.js +3 -3
  169. package/dist/core/storage/session/fork-staging.code.js +1 -1
  170. package/dist/core/storage/session/fork-staging.impl.js +3 -3
  171. package/dist/core/storage/session/fork-staging.js +3 -3
  172. package/dist/core/storage/session/fork-sweep.js +31 -7
  173. package/dist/core/storage/session/fork-sweep.js.map +1 -1
  174. package/dist/core/storage/session/fork-window.code.js +3 -3
  175. package/dist/core/storage/session/fork-window.impl.js +3 -3
  176. package/dist/core/storage/session/fork-window.js +3 -3
  177. package/dist/core/storage/session/history-pages.impl.js +3 -3
  178. package/dist/core/storage/session/history-pages.js +3 -3
  179. package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
  180. package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
  181. package/dist/core/storage/session/jsonl-session-lock.d.ts +100 -0
  182. package/dist/core/storage/session/jsonl-session-store.d.ts +41 -23
  183. package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
  184. package/dist/core/storage/session/jsonl-session-store.js +3 -3
  185. package/dist/core/storage/session/memory-session-store.impl.js +3 -3
  186. package/dist/core/storage/session/memory-session-store.js +3 -3
  187. package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
  188. package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
  189. package/dist/core/storage/session/pinned-branch-resume.js +3 -3
  190. package/dist/core/storage/session/released-history-files.code.js +8 -8
  191. package/dist/core/storage/session/released-history-files.code.js.map +1 -1
  192. package/dist/core/storage/session/released-history-files.impl.js +3 -3
  193. package/dist/core/storage/session/released-history-files.js +3 -3
  194. package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
  195. package/dist/core/storage/session/resident-fork-rows.js +3 -3
  196. package/dist/core/storage/session/session-resume.impl.js +3 -3
  197. package/dist/core/storage/session/session-resume.js +3 -3
  198. package/dist/core/storage/session/session-search-index.d.ts +9 -1
  199. package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
  200. package/dist/core/storage/session/snapshot-cut.js +3 -3
  201. package/dist/core/storage/session/snapshot-history.code.js +3 -3
  202. package/dist/core/storage/session/snapshot-history.impl.js +3 -3
  203. package/dist/core/storage/session/snapshot-history.js +3 -3
  204. package/dist/core/storage/session/sql-session-store.d.ts +51 -7
  205. package/dist/core/storage/session/sql-session-store.impl.js +3 -3
  206. package/dist/core/storage/session/sql-session-store.js +3 -3
  207. package/dist/core/storage/session/tree-outline.impl.js +3 -3
  208. package/dist/core/storage/session/tree-outline.js +3 -3
  209. package/dist/core/storage/session/tree-presentation.impl.js +3 -3
  210. package/dist/core/storage/session/tree-presentation.js +3 -3
  211. package/dist/core/storage/sqlite-facade.d.ts +6 -0
  212. package/dist/core/storage/sqlite-facade.js +309 -33
  213. package/dist/core/storage/sqlite-facade.js.map +1 -1
  214. package/dist/core/storage/sqlite-open-batch.js +10 -0
  215. package/dist/core/storage/sqlite-open-batch.js.map +1 -0
  216. package/dist/core/storage/storage-status.impl.js +3 -3
  217. package/dist/core/storage/storage-status.js +3 -3
  218. package/dist/core/storage/team.impl.js +3 -3
  219. package/dist/core/storage/team.js +3 -3
  220. package/dist/core/structured-output/index.impl.js +3 -3
  221. package/dist/core/structured-output/index.js +3 -3
  222. package/dist/core/tasks/task-completion-entry.impl.js +3 -3
  223. package/dist/core/tasks/task-completion-entry.js +3 -3
  224. package/dist/core/tasks/task-file-history.code.js +3 -3
  225. package/dist/core/tasks/task-file-history.impl.js +3 -3
  226. package/dist/core/tasks/task-file-history.js +3 -3
  227. package/dist/core/tasks/task-reference-archive.code.js +3 -3
  228. package/dist/core/tasks/task-reference-archive.js +3 -3
  229. package/dist/core/tasks/task-reference-identity.js +3 -3
  230. package/dist/core/tasks/task-reference-stream.impl.js +3 -3
  231. package/dist/core/tasks/task-reference-stream.js +3 -3
  232. package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
  233. package/dist/core/tasks/task-unsaved-answer.js +3 -3
  234. package/dist/core/tasks/task-view-source.impl.js +3 -3
  235. package/dist/core/tasks/task-view-source.js +3 -3
  236. package/dist/core/tools/read-url.code.js +2 -2
  237. package/dist/core/tools/read-url.impl.js +3 -3
  238. package/dist/core/tools/read-url.js +3 -3
  239. package/dist/core/worktree-snapshot/blob-store.d.ts +5 -3
  240. package/dist/core/worktree-snapshot/blob-store.js +151 -21
  241. package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
  242. package/dist/core/worktree-snapshot/errors.code.js +2 -2
  243. package/dist/core/worktree-snapshot/errors.impl.js +3 -3
  244. package/dist/core/worktree-snapshot/errors.js +3 -3
  245. package/dist/core/worktree-snapshot/fork-snapshot-index.js +158 -41
  246. package/dist/core/worktree-snapshot/fork-snapshot-index.js.map +1 -1
  247. package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
  248. package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
  249. package/dist/extensions/codemode/execute.code.js +1 -1
  250. package/dist/extensions/codemode/execute.impl.js +3 -3
  251. package/dist/extensions/codemode/execute.js +3 -3
  252. package/dist/extensions/codemode/renderer.code.js +1 -1
  253. package/dist/extensions/codemode/renderer.impl.js +3 -3
  254. package/dist/extensions/codemode/renderer.js +3 -3
  255. package/dist/extensions/mcp/cli.code.js +1 -1
  256. package/dist/extensions/mcp/cli.impl.js +3 -3
  257. package/dist/extensions/mcp/cli.js +3 -3
  258. package/dist/extensions/mcp/cli.lazy.code.js +2 -2
  259. package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
  260. package/dist/extensions/mcp/cli.lazy.js +3 -3
  261. package/dist/extensions/mcp/runtime.impl.js +3 -3
  262. package/dist/extensions/mcp/runtime.js +3 -3
  263. package/dist/index.js +2 -2
  264. package/dist/main-first-time-setup.code.js +1 -1
  265. package/dist/main-first-time-setup.impl.js +3 -3
  266. package/dist/main-first-time-setup.js +3 -3
  267. package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
  268. package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
  269. package/dist/modes/interactive/components/stored-tree-view.js +3 -3
  270. package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
  271. package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
  272. package/dist/package-manager-cli.code.js +4 -4
  273. package/dist/package-manager-cli.impl.js +3 -3
  274. package/dist/package-manager-cli.js +3 -3
  275. package/dist/rpc-entry.js +1 -1
  276. package/dist/startup-files.json +1 -1
  277. package/dist/startup-stages/3.js +1 -1
  278. package/dist/startup-stages/5.js +1 -1
  279. package/dist/utils/startup-database-spare.code.js +2 -2
  280. package/dist/utils/startup-database-spare.impl.js +3 -3
  281. package/dist/utils/startup-database-spare.js +3 -3
  282. package/dist/utils/tools-manager.code.js +1 -1
  283. package/dist/utils/tools-manager.impl.js +3 -3
  284. package/dist/utils/tools-manager.js +3 -3
  285. package/docs/changelog.mdx +49 -0
  286. package/docs/storage/jsonl.md +3 -3
  287. package/package.json +8 -8
  288. package/dist/_shared/startup-0-1-RTOHJFDJ.js.map +0 -1
@@ -6,7 +6,7 @@ try {
6
6
  } catch (error) {
7
7
  const root = new URL("../../../", import.meta.url);
8
8
  const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
9
- const key = `${root.href}#0.10.11-alpha.3`;
9
+ const key = `${root.href}#0.10.11-alpha.4`;
10
10
  let release = releases.get(key);
11
11
  if (release === undefined) {
12
12
  const current = (async () => {
@@ -27,8 +27,8 @@ try {
27
27
  release = current;
28
28
  }
29
29
  const running = await release;
30
- if (running === undefined || running.version === "0.10.11-alpha.3") throw error;
31
- throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.11-alpha.3 while this session was running; restart it to keep using /tree.", {
30
+ if (running === undefined || running.version === "0.10.11-alpha.4") throw error;
31
+ throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.11-alpha.4 while this session was running; restart it to keep using /tree.", {
32
32
  cause: error,
33
33
  });
34
34
  }
@@ -6,7 +6,7 @@ try {
6
6
  } catch (error) {
7
7
  const root = new URL("../../../", import.meta.url);
8
8
  const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
9
- const key = `${root.href}#0.10.11-alpha.3`;
9
+ const key = `${root.href}#0.10.11-alpha.4`;
10
10
  let release = releases.get(key);
11
11
  if (release === undefined) {
12
12
  const current = (async () => {
@@ -27,8 +27,8 @@ try {
27
27
  release = current;
28
28
  }
29
29
  const running = await release;
30
- if (running === undefined || running.version === "0.10.11-alpha.3") throw error;
31
- throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.11-alpha.3 while this session was running; restart it to keep using /tree.", {
30
+ if (running === undefined || running.version === "0.10.11-alpha.4") throw error;
31
+ throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.11-alpha.4 while this session was running; restart it to keep using /tree.", {
32
32
  cause: error,
33
33
  });
34
34
  }
@@ -55,8 +55,14 @@ export interface SqliteDriverTransactionOptions {
55
55
  /**
56
56
  * Optional. `SqliteTransactionOptions.leadingOnly`, set only with every statement of `leading`: a driver with
57
57
  * `pipelinedTransactions` may send the commit right behind them, and then fails any other call without sending it.
58
+ * A driver that writes `COMMIT` before `commit()` must invoke `onCommit?.()` immediately before writing it.
58
59
  */
59
60
  readonly leadingOnly?: boolean;
61
+ /**
62
+ * Optional. Invoked by a driver right before writing `COMMIT` ahead of `commit()`, as with `leadingOnly`, so any
63
+ * connection loss from that point on keeps its ambiguous outcome and is never retried.
64
+ */
65
+ readonly onCommit?: () => void;
60
66
  /**
61
67
  * Optional. `SqliteTransactionOptions.lockIfLeadingFinds`, set only with `leading` whose first statement is the
62
68
  * transaction's: a driver with `pipelinedTransactions` may take a `serial` domain's locks in that statement, for the
@@ -207,34 +207,292 @@ function transactionConcurrency(options) {
207
207
  function concurrencyConfigError() {
208
208
  return new StorageConfigError("sdk", "concurrency", "kind-required", 'Pass { kind: "serial" }, { kind: "serial", domain }, or { kind: "fenced", audit: fencedPath(name) }, or omit it');
209
209
  }
210
+ const SAVEPOINT_KEYWORDS = /\b(?:SAVEPOINT|ROLLBACK|RELEASE)\b/i;
211
+ function classifySavepointStatement(tokens) {
212
+ const keyword = (at) => {
213
+ const token = tokens[at];
214
+ return token === undefined || token.quoted ? undefined : token.text.toUpperCase();
215
+ };
216
+ const identifier = (at) => {
217
+ const token = tokens[at];
218
+ if (token === undefined || token.text.length === 0)
219
+ return undefined;
220
+ return token.quoted ? token.text : token.text.toLowerCase();
221
+ };
222
+ const first = keyword(0);
223
+ if (first === "SAVEPOINT" && tokens.length === 2) {
224
+ const name = identifier(1);
225
+ if (name !== undefined)
226
+ return { kind: "savepoint", name };
227
+ }
228
+ if (first === "RELEASE") {
229
+ const nameIndex = keyword(1) === "SAVEPOINT" ? 2 : 1;
230
+ if (tokens.length === nameIndex + 1) {
231
+ const name = identifier(nameIndex);
232
+ if (name !== undefined)
233
+ return { kind: "release", name };
234
+ }
235
+ }
236
+ if (first === "ROLLBACK") {
237
+ let at = 1;
238
+ if (keyword(at) === "WORK" || keyword(at) === "TRANSACTION")
239
+ at++;
240
+ if (keyword(at) === "TO") {
241
+ at++;
242
+ if (keyword(at) === "SAVEPOINT")
243
+ at++;
244
+ if (tokens.length === at + 1) {
245
+ const name = identifier(at);
246
+ if (name !== undefined)
247
+ return { kind: "rollback-to", name };
248
+ }
249
+ }
250
+ }
251
+ return { kind: "other" };
252
+ }
253
+ /**
254
+ * Extracts `SAVEPOINT`, `ROLLBACK TO [SAVEPOINT]`, and `RELEASE [SAVEPOINT]` actions from `sql` in statement order,
255
+ * ignoring comments, string literals, and dollar-quoted strings. Returns undefined when `sql` contains none.
256
+ */
257
+ function parseSavepointActions(sql) {
258
+ if (!SAVEPOINT_KEYWORDS.test(sql))
259
+ return undefined;
260
+ const actions = [];
261
+ let index = 0;
262
+ const length = sql.length;
263
+ while (index < length) {
264
+ const tokens = [];
265
+ let extra = false;
266
+ while (index < length) {
267
+ const ch = sql[index];
268
+ if (/\s/.test(ch)) {
269
+ index++;
270
+ continue;
271
+ }
272
+ if (ch === "-" && sql[index + 1] === "-") {
273
+ const end = sql.indexOf("\n", index + 2);
274
+ index = end === -1 ? length : end + 1;
275
+ continue;
276
+ }
277
+ if (ch === "/" && sql[index + 1] === "*") {
278
+ let depth = 1;
279
+ index += 2;
280
+ while (index < length && depth > 0) {
281
+ if (sql.startsWith("/*", index)) {
282
+ depth++;
283
+ index += 2;
284
+ }
285
+ else if (sql.startsWith("*/", index)) {
286
+ depth--;
287
+ index += 2;
288
+ }
289
+ else
290
+ index++;
291
+ }
292
+ continue;
293
+ }
294
+ if (ch === ";") {
295
+ index++;
296
+ break;
297
+ }
298
+ if (ch === "'") {
299
+ const escapes = (sql[index - 1] === "e" || sql[index - 1] === "E") &&
300
+ !/[A-Za-z0-9_$\u0080-\uffff]/.test(sql[index - 2] ?? "");
301
+ index++;
302
+ while (index < length) {
303
+ if (escapes && sql[index] === "\\")
304
+ index += 2;
305
+ else if (sql[index] !== "'")
306
+ index++;
307
+ else if (sql[index + 1] === "'")
308
+ index += 2;
309
+ else
310
+ break;
311
+ }
312
+ index++;
313
+ extra = true;
314
+ continue;
315
+ }
316
+ if (ch === '"') {
317
+ let value = "";
318
+ index++;
319
+ while (index < length) {
320
+ if (sql[index] === '"') {
321
+ if (sql[index + 1] === '"') {
322
+ value += '"';
323
+ index += 2;
324
+ }
325
+ else {
326
+ index++;
327
+ break;
328
+ }
329
+ }
330
+ else {
331
+ value += sql[index++];
332
+ }
333
+ }
334
+ if (tokens.length < 5)
335
+ tokens.push({ text: value, quoted: true });
336
+ else
337
+ extra = true;
338
+ continue;
339
+ }
340
+ if (ch === "$") {
341
+ const tag = /^\$(?:[A-Za-z_\u0080-\uffff][A-Za-z0-9_\u0080-\uffff]*)?\$/.exec(sql.slice(index))?.[0];
342
+ if (tag !== undefined) {
343
+ const close = sql.indexOf(tag, index + tag.length);
344
+ index = close === -1 ? length : close + tag.length;
345
+ extra = true;
346
+ continue;
347
+ }
348
+ }
349
+ if (/[A-Za-z_\u0080-\uffff]/.test(ch)) {
350
+ let end = index + 1;
351
+ while (end < length && /[A-Za-z0-9_$\u0080-\uffff]/.test(sql[end]))
352
+ end++;
353
+ const word = sql.slice(index, end);
354
+ index = end;
355
+ if (tokens.length < 5)
356
+ tokens.push({ text: word, quoted: false });
357
+ else
358
+ extra = true;
359
+ continue;
360
+ }
361
+ extra = true;
362
+ index++;
363
+ }
364
+ if (tokens.length === 0 && !extra)
365
+ continue;
366
+ actions.push(extra ? { kind: "other" } : classifySavepointStatement(tokens));
367
+ }
368
+ return actions.some((action) => action.kind !== "other") ? actions : undefined;
369
+ }
370
+ /**
371
+ * Tracks unrecovered failures of a transaction's calls in push order, dropping failures recovered by a fulfilled
372
+ * `ROLLBACK TO [SAVEPOINT] <name>`. Settled prefixes fold incrementally so long transactions stay bounded in memory.
373
+ */
374
+ class SavepointFailureLog {
375
+ savepoints = [];
376
+ activeFailures = [];
377
+ pending = [];
378
+ head = 0;
379
+ track(sql, result) {
380
+ const entry = {
381
+ actions: sql === undefined ? undefined : parseSavepointActions(sql),
382
+ settled: false,
383
+ };
384
+ this.pending.push(entry);
385
+ return result.then(() => {
386
+ entry.settled = true;
387
+ this.compact();
388
+ }, (reason) => {
389
+ entry.failure = { reason };
390
+ entry.settled = true;
391
+ this.compact();
392
+ });
393
+ }
394
+ compact() {
395
+ while (this.head < this.pending.length && this.pending[this.head].settled) {
396
+ const entry = this.pending[this.head++];
397
+ this.apply(entry);
398
+ }
399
+ if (this.head > 0 && this.head === this.pending.length) {
400
+ this.pending.length = 0;
401
+ this.head = 0;
402
+ }
403
+ }
404
+ findLastSavepoint(name) {
405
+ for (let index = this.savepoints.length - 1; index >= 0; index--)
406
+ if (this.savepoints[index].name === name)
407
+ return index;
408
+ return -1;
409
+ }
410
+ apply(entry) {
411
+ if (entry.failure === undefined) {
412
+ for (const action of entry.actions ?? []) {
413
+ if (action.kind === "savepoint") {
414
+ this.savepoints.push({ name: action.name, failureCount: this.activeFailures.length });
415
+ }
416
+ else if (action.kind === "rollback-to") {
417
+ const index = this.findLastSavepoint(action.name);
418
+ if (index !== -1) {
419
+ this.activeFailures.length = this.savepoints[index].failureCount;
420
+ this.savepoints.length = index + 1;
421
+ }
422
+ }
423
+ else if (action.kind === "release") {
424
+ const index = this.findLastSavepoint(action.name);
425
+ if (index !== -1)
426
+ this.savepoints.length = index;
427
+ }
428
+ }
429
+ return;
430
+ }
431
+ const actions = entry.actions;
432
+ if (actions !== undefined &&
433
+ actions.length > 1 &&
434
+ actions[0]?.kind === "savepoint" &&
435
+ this.activeFailures.length === (this.savepoints.at(-1)?.failureCount ?? 0)) {
436
+ this.savepoints.push({ name: actions[0].name, failureCount: this.activeFailures.length });
437
+ }
438
+ this.activeFailures.push(entry.failure.reason);
439
+ }
440
+ firstFailure() {
441
+ this.compact();
442
+ return this.activeFailures[0];
443
+ }
444
+ firstTransientFailure() {
445
+ this.compact();
446
+ let chosen;
447
+ for (const reason of this.activeFailures) {
448
+ if (!(reason instanceof StorageTransientError))
449
+ continue;
450
+ if (reason.outcome !== "not-applied")
451
+ return reason;
452
+ chosen ??= reason;
453
+ }
454
+ return chosen;
455
+ }
456
+ }
210
457
  /** Serializes operations in call order; a failed operation does not stop the ones queued after it. */
211
458
  class CallQueue {
212
459
  tail = Promise.resolve();
213
- push(operation) {
460
+ log = new SavepointFailureLog();
461
+ push(operation, sql) {
214
462
  const result = this.tail.then(operation);
215
- this.tail = result.then(() => { }, () => { });
463
+ this.tail = this.log.track(sql, result);
216
464
  return result;
217
465
  }
218
466
  drained() {
219
467
  return this.tail;
220
468
  }
469
+ async firstTransientFailure() {
470
+ await this.drained();
471
+ return this.log.firstTransientFailure();
472
+ }
221
473
  }
222
474
  /** Starts each operation as it is pushed, so a pipelined connection receives them in push order without waiting. */
223
475
  class PipelineQueue {
224
- started = [];
225
- push(operation) {
476
+ inFlight = new Set();
477
+ log = new SavepointFailureLog();
478
+ push(operation, sql) {
226
479
  const result = operation();
227
- result.catch(() => { });
228
- // A queue lasts one transaction, so it keeps every call it started.
229
- this.started.push(result);
480
+ const tracked = this.log.track(sql, result);
481
+ this.inFlight.add(tracked);
482
+ void tracked.then(() => this.inFlight.delete(tracked));
230
483
  return result;
231
484
  }
232
485
  drained() {
233
- return Promise.allSettled(this.started).then(() => { });
486
+ return Promise.all(this.inFlight).then(() => { });
234
487
  }
235
- /** The failure of the first call, in the order they were sent, that failed; undefined when none did. */
236
- firstFailure() {
237
- return firstFailure(this.started);
488
+ /** The failure of the first unrecovered call, in the order they were sent, that failed; undefined when none did. */
489
+ async firstFailure() {
490
+ await this.drained();
491
+ return this.log.firstFailure();
492
+ }
493
+ async firstTransientFailure() {
494
+ await this.drained();
495
+ return this.log.firstTransientFailure();
238
496
  }
239
497
  }
240
498
  /**
@@ -505,13 +763,6 @@ function transactionScope(concurrency, readOnly, concurrentWrites) {
505
763
  function hasInvalidText(statement) {
506
764
  return statement.params.some((value) => typeof value === "string" && value.includes("\0"));
507
765
  }
508
- /** The failure of the first of `calls` that failed, in their order, once all settled; undefined when none did. */
509
- async function firstFailure(calls) {
510
- for (const outcome of await Promise.allSettled(calls))
511
- if (outcome.status === "rejected")
512
- return outcome.reason;
513
- return undefined;
514
- }
515
766
  /** `leading` with parameters snapshotted, up to the first statement that holds NUL, which the facade refuses to send. */
516
767
  function leadingStatements(leading) {
517
768
  const sent = [];
@@ -613,10 +864,10 @@ class DriverDatabase {
613
864
  const scopeOf = readsOnly !== undefined && (driver.concurrentTransactions === true || maxReads !== undefined)
614
865
  ? (sql) => (readsOnly(sql) ? READ_SCOPE : PLAIN_SCOPE)
615
866
  : () => PLAIN_SCOPE;
616
- this.executor = this.createExecutor(driver, (operation, sql) => {
867
+ this.executor = this.createExecutor(driver, (operation, sql, script) => {
617
868
  if (this.closePromise)
618
869
  return Promise.reject(new StoreClosedError(this.descriptor));
619
- return this.queue.push(() => this.retrying(operation, true), false, sql === undefined ? PLAIN_SCOPE : scopeOf(sql));
870
+ return this.queue.push(() => this.retrying(operation, true), false, sql === undefined || script === true ? PLAIN_SCOPE : scopeOf(sql));
620
871
  }, true);
621
872
  const batch = driver.batch?.bind(driver);
622
873
  if (batch)
@@ -763,7 +1014,10 @@ class DriverDatabase {
763
1014
  },
764
1015
  }),
765
1016
  }, safe);
766
- attempt.transient ??= failure;
1017
+ if (attempt.transient === undefined ||
1018
+ (attempt.transient.outcome === "not-applied" && failure.outcome !== "not-applied")) {
1019
+ attempt.transient = failure;
1020
+ }
767
1021
  throw failure;
768
1022
  }
769
1023
  }
@@ -778,10 +1032,10 @@ class DriverDatabase {
778
1032
  if (invalidIndex !== -1)
779
1033
  throw new StorageInvalidTextError(invalidIndex);
780
1034
  return this.call(() => connection.execute(sql, bound), attempt, applies, bound);
781
- }, sql);
1035
+ }, sql, false);
782
1036
  };
783
1037
  return {
784
- exec: (sql) => admit((attempt) => this.call(() => connection.executeMultiple(sql), attempt, applies)),
1038
+ exec: (sql) => admit((attempt) => this.call(() => connection.executeMultiple(sql), attempt, applies), sql, true),
785
1039
  run: async (sql, ...params) => ({ changes: (await statement(sql, params)).changes }),
786
1040
  get: async (sql, ...params) => {
787
1041
  const result = await statement(sql, params);
@@ -843,15 +1097,23 @@ class DriverDatabase {
843
1097
  return result;
844
1098
  }
845
1099
  async runTransaction(callback, attempt, begin) {
846
- const connection = await this.call(() => this.driver.beginTransaction(begin), attempt);
847
1100
  const pipelined = this.driver.pipelinedTransactions === true;
1101
+ const driverBegin = pipelined && begin.leadingOnly === true
1102
+ ? {
1103
+ ...begin,
1104
+ onCommit: () => {
1105
+ attempt.committing = true;
1106
+ },
1107
+ }
1108
+ : begin;
1109
+ const connection = await this.call(() => this.driver.beginTransaction(driverBegin), attempt);
848
1110
  const handleQueue = pipelined ? new PipelineQueue() : new CallQueue();
849
1111
  let active = true;
850
1112
  let result;
851
1113
  /** Set once `finish` sent the callback's last calls: the transaction takes no more. */
852
1114
  let finished = false;
853
- const handle = this.createExecutor(connection, (operation) => active && !finished
854
- ? handleQueue.push(() => operation(attempt))
1115
+ const handle = this.createExecutor(connection, (operation, sql) => active && !finished
1116
+ ? handleQueue.push(() => operation(attempt), sql)
855
1117
  : Promise.reject(new StorageTransactionClosedError()), false);
856
1118
  if (pipelined) {
857
1119
  offerSequences(handle, (sequence) => pipelineSequence(handle, sequence));
@@ -910,13 +1172,27 @@ class DriverDatabase {
910
1172
  }
911
1173
  catch (cause) {
912
1174
  let failure = cause;
913
- // A commit that came back as a rollback names no reason: the statement that failed is the transaction's failure,
914
- // and whether it may run again is that failure's, as when the callback awaited it.
915
- const unanswered = returned && handleQueue instanceof PipelineQueue ? await handleQueue.firstFailure() : undefined;
916
- if (unanswered !== undefined) {
917
- failure = unanswered;
918
- if (unanswered instanceof StorageTransientError)
919
- attempt.transient = unanswered;
1175
+ if (returned) {
1176
+ if (cause instanceof StorageTransientError) {
1177
+ // Keep the commit's own failure whenever the driver recognized it (especially an ambiguous outcome).
1178
+ attempt.transient = cause;
1179
+ }
1180
+ else {
1181
+ // A commit that came back as a rollback names no reason: the first unrecovered statement failure is
1182
+ // the transaction's failure, and whether it may run again is that failure's.
1183
+ const unanswered = handleQueue instanceof PipelineQueue ? await handleQueue.firstFailure() : undefined;
1184
+ if (unanswered !== undefined) {
1185
+ failure = unanswered;
1186
+ attempt.transient = unanswered instanceof StorageTransientError ? unanswered : undefined;
1187
+ }
1188
+ else {
1189
+ attempt.transient = undefined;
1190
+ }
1191
+ }
1192
+ }
1193
+ else if (!(cause instanceof StorageTransientError)) {
1194
+ // Recovered savepoint transient failures must not trigger retries for an unrelated callback failure.
1195
+ attempt.transient = await handleQueue.firstTransientFailure();
920
1196
  }
921
1197
  try {
922
1198
  await this.call(() => connection.rollback());