pipework 0.8.2 → 0.8.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 (355) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/async/jobs/execute.d.ts +2 -0
  3. package/dist/async/jobs/execute.d.ts.map +1 -1
  4. package/dist/async/jobs/execute.js +17 -2
  5. package/dist/async/jobs/execute.js.map +1 -1
  6. package/dist/audit/query/cursor.d.ts +7 -0
  7. package/dist/audit/query/cursor.d.ts.map +1 -0
  8. package/dist/audit/query/cursor.js +25 -0
  9. package/dist/audit/query/cursor.js.map +1 -0
  10. package/dist/audit/query/index.d.ts +5 -0
  11. package/dist/audit/query/index.d.ts.map +1 -0
  12. package/dist/audit/query/index.js +3 -0
  13. package/dist/audit/query/index.js.map +1 -0
  14. package/dist/audit/query/query.d.ts +49 -0
  15. package/dist/audit/query/query.d.ts.map +1 -0
  16. package/dist/audit/query/query.js +119 -0
  17. package/dist/audit/query/query.js.map +1 -0
  18. package/dist/audit/schema/audit-record-fields.d.ts +15 -0
  19. package/dist/audit/schema/audit-record-fields.d.ts.map +1 -0
  20. package/dist/audit/schema/audit-record-fields.js +50 -0
  21. package/dist/audit/schema/audit-record-fields.js.map +1 -0
  22. package/dist/audit/schema/audit-record.d.ts +15 -0
  23. package/dist/audit/schema/audit-record.d.ts.map +1 -0
  24. package/dist/audit/schema/audit-record.js +12 -0
  25. package/dist/audit/schema/audit-record.js.map +1 -0
  26. package/dist/auth/tenant/scope.js +1 -1
  27. package/dist/auth/tenant/scope.js.map +1 -1
  28. package/dist/auth/tenant/scoped-db.d.ts.map +1 -1
  29. package/dist/auth/tenant/scoped-db.js +1 -2
  30. package/dist/auth/tenant/scoped-db.js.map +1 -1
  31. package/dist/cli/commands/check.d.ts +4 -0
  32. package/dist/cli/commands/check.d.ts.map +1 -1
  33. package/dist/cli/commands/check.js +181 -14
  34. package/dist/cli/commands/check.js.map +1 -1
  35. package/dist/cli/commands/codemod.d.ts +6 -0
  36. package/dist/cli/commands/codemod.d.ts.map +1 -0
  37. package/dist/cli/commands/codemod.js +63 -0
  38. package/dist/cli/commands/codemod.js.map +1 -0
  39. package/dist/cli/index.d.ts.map +1 -1
  40. package/dist/cli/index.js +9 -0
  41. package/dist/cli/index.js.map +1 -1
  42. package/dist/core/config/load.d.ts +23 -0
  43. package/dist/core/config/load.d.ts.map +1 -1
  44. package/dist/core/config/load.js +8 -0
  45. package/dist/core/config/load.js.map +1 -1
  46. package/dist/core/config/namespace.d.ts +19 -0
  47. package/dist/core/config/namespace.d.ts.map +1 -1
  48. package/dist/core/config/schema.d.ts +41 -0
  49. package/dist/core/config/schema.d.ts.map +1 -1
  50. package/dist/core/config/schema.js +27 -0
  51. package/dist/core/config/schema.js.map +1 -1
  52. package/dist/core/logging/logger.d.ts +3 -1
  53. package/dist/core/logging/logger.d.ts.map +1 -1
  54. package/dist/core/logging/logger.js +2 -2
  55. package/dist/core/logging/logger.js.map +1 -1
  56. package/dist/core/pipework.d.ts +2 -2
  57. package/dist/core/pipework.d.ts.map +1 -1
  58. package/dist/data/db/bulk-set.js +1 -1
  59. package/dist/data/db/bulk-set.js.map +1 -1
  60. package/dist/data/db/composed.js +1 -1
  61. package/dist/data/db/composed.js.map +1 -1
  62. package/dist/data/db/db.d.ts +10 -0
  63. package/dist/data/db/db.d.ts.map +1 -1
  64. package/dist/data/db/db.js +12 -0
  65. package/dist/data/db/db.js.map +1 -1
  66. package/dist/data/db/filter.d.ts +42 -43
  67. package/dist/data/db/filter.d.ts.map +1 -1
  68. package/dist/data/db/filter.js +7 -6
  69. package/dist/data/db/filter.js.map +1 -1
  70. package/dist/data/db/namespace.d.ts +90 -82
  71. package/dist/data/db/namespace.d.ts.map +1 -1
  72. package/dist/data/db/namespace.js +21 -5
  73. package/dist/data/db/namespace.js.map +1 -1
  74. package/dist/data/migrate/post-process.d.ts +2 -1
  75. package/dist/data/migrate/post-process.d.ts.map +1 -1
  76. package/dist/data/migrate/post-process.js +2 -1
  77. package/dist/data/migrate/post-process.js.map +1 -1
  78. package/dist/data/temporal/definition-queries.js +1 -1
  79. package/dist/data/temporal/definition-queries.js.map +1 -1
  80. package/dist/data/temporal/query.js +1 -1
  81. package/dist/data/temporal/query.js.map +1 -1
  82. package/dist/data/temporal/resolve.js +1 -1
  83. package/dist/data/temporal/resolve.js.map +1 -1
  84. package/dist/data/write/audit/actor.d.ts +3 -0
  85. package/dist/data/write/audit/actor.d.ts.map +1 -0
  86. package/dist/data/write/audit/actor.js +15 -0
  87. package/dist/data/write/audit/actor.js.map +1 -0
  88. package/dist/data/write/audit/audit-columns.d.ts +6 -0
  89. package/dist/data/write/audit/audit-columns.d.ts.map +1 -0
  90. package/dist/data/write/audit/audit-columns.js +15 -0
  91. package/dist/data/write/audit/audit-columns.js.map +1 -0
  92. package/dist/data/write/audit/audit-select.d.ts +28 -0
  93. package/dist/data/write/audit/audit-select.d.ts.map +1 -0
  94. package/dist/data/write/audit/audit-select.js +49 -0
  95. package/dist/data/write/audit/audit-select.js.map +1 -0
  96. package/dist/data/write/audit/cte-compile.d.ts +7 -0
  97. package/dist/data/write/audit/cte-compile.d.ts.map +1 -0
  98. package/dist/data/write/audit/cte-compile.js +23 -0
  99. package/dist/data/write/audit/cte-compile.js.map +1 -0
  100. package/dist/data/write/audit/final-select.d.ts +4 -0
  101. package/dist/data/write/audit/final-select.d.ts.map +1 -0
  102. package/dist/data/write/audit/final-select.js +28 -0
  103. package/dist/data/write/audit/final-select.js.map +1 -0
  104. package/dist/data/write/audit/primary-key.d.ts +7 -0
  105. package/dist/data/write/audit/primary-key.d.ts.map +1 -0
  106. package/dist/data/write/audit/primary-key.js +32 -0
  107. package/dist/data/write/audit/primary-key.js.map +1 -0
  108. package/dist/data/write/audit/projection.d.ts +11 -0
  109. package/dist/data/write/audit/projection.d.ts.map +1 -0
  110. package/dist/data/write/audit/projection.js +37 -0
  111. package/dist/data/write/audit/projection.js.map +1 -0
  112. package/dist/data/write/audit/read-touches.d.ts +10 -0
  113. package/dist/data/write/audit/read-touches.d.ts.map +1 -0
  114. package/dist/data/write/audit/read-touches.js +63 -0
  115. package/dist/data/write/audit/read-touches.js.map +1 -0
  116. package/dist/data/write/audit/verb-delete.d.ts +7 -0
  117. package/dist/data/write/audit/verb-delete.d.ts.map +1 -0
  118. package/dist/data/write/audit/verb-delete.js +53 -0
  119. package/dist/data/write/audit/verb-delete.js.map +1 -0
  120. package/dist/data/write/audit/verb-insert.d.ts +7 -0
  121. package/dist/data/write/audit/verb-insert.d.ts.map +1 -0
  122. package/dist/data/write/audit/verb-insert.js +28 -0
  123. package/dist/data/write/audit/verb-insert.js.map +1 -0
  124. package/dist/data/write/audit/verb-update.d.ts +7 -0
  125. package/dist/data/write/audit/verb-update.d.ts.map +1 -0
  126. package/dist/data/write/audit/verb-update.js +52 -0
  127. package/dist/data/write/audit/verb-update.js.map +1 -0
  128. package/dist/data/write/audit/verb-upsert.d.ts +7 -0
  129. package/dist/data/write/audit/verb-upsert.d.ts.map +1 -0
  130. package/dist/data/write/audit/verb-upsert.js +81 -0
  131. package/dist/data/write/audit/verb-upsert.js.map +1 -0
  132. package/dist/data/write/delete.d.ts +15 -0
  133. package/dist/data/write/delete.d.ts.map +1 -0
  134. package/dist/data/write/delete.js +25 -0
  135. package/dist/data/write/delete.js.map +1 -0
  136. package/dist/data/write/execute.d.ts +3 -0
  137. package/dist/data/write/execute.d.ts.map +1 -0
  138. package/dist/data/write/execute.js +162 -0
  139. package/dist/data/write/execute.js.map +1 -0
  140. package/dist/data/write/index.d.ts +6 -0
  141. package/dist/data/write/index.d.ts.map +1 -0
  142. package/dist/data/write/index.js +10 -0
  143. package/dist/data/write/index.js.map +1 -0
  144. package/dist/data/write/insert.d.ts +18 -0
  145. package/dist/data/write/insert.d.ts.map +1 -0
  146. package/dist/data/write/insert.js +29 -0
  147. package/dist/data/write/insert.js.map +1 -0
  148. package/dist/data/write/state.d.ts +29 -0
  149. package/dist/data/write/state.d.ts.map +1 -0
  150. package/dist/data/write/state.js +9 -0
  151. package/dist/data/write/state.js.map +1 -0
  152. package/dist/data/write/update.d.ts +17 -0
  153. package/dist/data/write/update.d.ts.map +1 -0
  154. package/dist/data/write/update.js +39 -0
  155. package/dist/data/write/update.js.map +1 -0
  156. package/dist/data/write/upsert.d.ts +21 -0
  157. package/dist/data/write/upsert.d.ts.map +1 -0
  158. package/dist/data/write/upsert.js +42 -0
  159. package/dist/data/write/upsert.js.map +1 -0
  160. package/dist/index.d.ts +3 -0
  161. package/dist/index.d.ts.map +1 -1
  162. package/dist/index.js +1 -0
  163. package/dist/index.js.map +1 -1
  164. package/dist/infra/audit/namespace.d.ts +3 -0
  165. package/dist/infra/audit/namespace.d.ts.map +1 -1
  166. package/dist/infra/audit/namespace.js +3 -0
  167. package/dist/infra/audit/namespace.js.map +1 -1
  168. package/dist/lint/config.d.ts +4 -2
  169. package/dist/lint/config.d.ts.map +1 -1
  170. package/dist/lint/config.js +9 -5
  171. package/dist/lint/config.js.map +1 -1
  172. package/dist/lint/index.d.ts +2 -1
  173. package/dist/lint/index.d.ts.map +1 -1
  174. package/dist/lint/index.js +1 -0
  175. package/dist/lint/index.js.map +1 -1
  176. package/dist/lint/resolver.d.ts +16 -0
  177. package/dist/lint/resolver.d.ts.map +1 -0
  178. package/dist/lint/resolver.js +61 -0
  179. package/dist/lint/resolver.js.map +1 -0
  180. package/dist/request/context/create.d.ts +4 -0
  181. package/dist/request/context/create.d.ts.map +1 -1
  182. package/dist/request/context/create.js +3 -0
  183. package/dist/request/context/create.js.map +1 -1
  184. package/dist/request/context/types.d.ts +3 -0
  185. package/dist/request/context/types.d.ts.map +1 -1
  186. package/dist/request/http/middleware.d.ts.map +1 -1
  187. package/dist/request/http/middleware.js +30 -0
  188. package/dist/request/http/middleware.js.map +1 -1
  189. package/dist/request/http/server.d.ts.map +1 -1
  190. package/dist/request/http/server.js +6 -1
  191. package/dist/request/http/server.js.map +1 -1
  192. package/dist/test/context.d.ts.map +1 -1
  193. package/dist/test/context.js +43 -2
  194. package/dist/test/context.js.map +1 -1
  195. package/dist/test/index.d.ts +1 -1
  196. package/dist/test/index.d.ts.map +1 -1
  197. package/dist/test/index.js +1 -1
  198. package/dist/test/index.js.map +1 -1
  199. package/dist/test/vitest-workspace.d.ts +15 -2
  200. package/dist/test/vitest-workspace.d.ts.map +1 -1
  201. package/dist/test/vitest-workspace.js +60 -7
  202. package/dist/test/vitest-workspace.js.map +1 -1
  203. package/dist/trace/cardinality/analyze.d.ts +26 -0
  204. package/dist/trace/cardinality/analyze.d.ts.map +1 -0
  205. package/dist/trace/cardinality/analyze.js +129 -0
  206. package/dist/trace/cardinality/analyze.js.map +1 -0
  207. package/dist/trace/cardinality/branch-context.d.ts +13 -0
  208. package/dist/trace/cardinality/branch-context.d.ts.map +1 -0
  209. package/dist/trace/cardinality/branch-context.js +182 -0
  210. package/dist/trace/cardinality/branch-context.js.map +1 -0
  211. package/dist/trace/cardinality/check.d.ts +4 -0
  212. package/dist/trace/cardinality/check.d.ts.map +1 -0
  213. package/dist/trace/cardinality/check.js +29 -0
  214. package/dist/trace/cardinality/check.js.map +1 -0
  215. package/dist/trace/cardinality/classify-edge.d.ts +31 -0
  216. package/dist/trace/cardinality/classify-edge.d.ts.map +1 -0
  217. package/dist/trace/cardinality/classify-edge.js +27 -0
  218. package/dist/trace/cardinality/classify-edge.js.map +1 -0
  219. package/dist/trace/cardinality/structural-max.d.ts +14 -0
  220. package/dist/trace/cardinality/structural-max.d.ts.map +1 -0
  221. package/dist/trace/cardinality/structural-max.js +83 -0
  222. package/dist/trace/cardinality/structural-max.js.map +1 -0
  223. package/dist/trace/check/coverage-check.d.ts +20 -0
  224. package/dist/trace/check/coverage-check.d.ts.map +1 -0
  225. package/dist/trace/check/coverage-check.js +146 -0
  226. package/dist/trace/check/coverage-check.js.map +1 -0
  227. package/dist/trace/check/flow-check.d.ts +13 -0
  228. package/dist/trace/check/flow-check.d.ts.map +1 -0
  229. package/dist/trace/check/flow-check.js +82 -0
  230. package/dist/trace/check/flow-check.js.map +1 -0
  231. package/dist/trace/check/flow-step-site.d.ts +62 -0
  232. package/dist/trace/check/flow-step-site.d.ts.map +1 -0
  233. package/dist/trace/check/flow-step-site.js +142 -0
  234. package/dist/trace/check/flow-step-site.js.map +1 -0
  235. package/dist/trace/check/io-pattern.d.ts +14 -0
  236. package/dist/trace/check/io-pattern.d.ts.map +1 -0
  237. package/dist/trace/check/io-pattern.js +113 -0
  238. package/dist/trace/check/io-pattern.js.map +1 -0
  239. package/dist/trace/codemod/add-cardinality.d.ts +38 -0
  240. package/dist/trace/codemod/add-cardinality.d.ts.map +1 -0
  241. package/dist/trace/codemod/add-cardinality.js +106 -0
  242. package/dist/trace/codemod/add-cardinality.js.map +1 -0
  243. package/dist/trace/codemod/run.d.ts +25 -0
  244. package/dist/trace/codemod/run.d.ts.map +1 -0
  245. package/dist/trace/codemod/run.js +47 -0
  246. package/dist/trace/codemod/run.js.map +1 -0
  247. package/dist/trace/entry/close-trace.d.ts +7 -0
  248. package/dist/trace/entry/close-trace.d.ts.map +1 -0
  249. package/dist/trace/entry/close-trace.js +54 -0
  250. package/dist/trace/entry/close-trace.js.map +1 -0
  251. package/dist/trace/entry/finalize-trace.d.ts +5 -0
  252. package/dist/trace/entry/finalize-trace.d.ts.map +1 -0
  253. package/dist/trace/entry/finalize-trace.js +23 -0
  254. package/dist/trace/entry/finalize-trace.js.map +1 -0
  255. package/dist/trace/entry/open-trace.d.ts +26 -0
  256. package/dist/trace/entry/open-trace.d.ts.map +1 -0
  257. package/dist/trace/entry/open-trace.js +75 -0
  258. package/dist/trace/entry/open-trace.js.map +1 -0
  259. package/dist/trace/entry/parent-trace.d.ts +4 -0
  260. package/dist/trace/entry/parent-trace.d.ts.map +1 -0
  261. package/dist/trace/entry/parent-trace.js +10 -0
  262. package/dist/trace/entry/parent-trace.js.map +1 -0
  263. package/dist/trace/entry/parse-traceparent.d.ts +8 -0
  264. package/dist/trace/entry/parse-traceparent.d.ts.map +1 -0
  265. package/dist/trace/entry/parse-traceparent.js +37 -0
  266. package/dist/trace/entry/parse-traceparent.js.map +1 -0
  267. package/dist/trace/entry/trace-context.d.ts +19 -0
  268. package/dist/trace/entry/trace-context.d.ts.map +1 -0
  269. package/dist/trace/entry/trace-context.js +5 -0
  270. package/dist/trace/entry/trace-context.js.map +1 -0
  271. package/dist/trace/entry/tracing-enabled.d.ts +4 -0
  272. package/dist/trace/entry/tracing-enabled.d.ts.map +1 -0
  273. package/dist/trace/entry/tracing-enabled.js +8 -0
  274. package/dist/trace/entry/tracing-enabled.js.map +1 -0
  275. package/dist/trace/partition/plan.d.ts +2 -0
  276. package/dist/trace/partition/plan.d.ts.map +1 -1
  277. package/dist/trace/partition/plan.js +8 -1
  278. package/dist/trace/partition/plan.js.map +1 -1
  279. package/dist/trace/partition/schedule.d.ts.map +1 -1
  280. package/dist/trace/partition/schedule.js +6 -4
  281. package/dist/trace/partition/schedule.js.map +1 -1
  282. package/dist/trace/partition/startup-hook.d.ts.map +1 -1
  283. package/dist/trace/partition/startup-hook.js +6 -2
  284. package/dist/trace/partition/startup-hook.js.map +1 -1
  285. package/dist/trace/partition/tables.d.ts +1 -1
  286. package/dist/trace/partition/tables.d.ts.map +1 -1
  287. package/dist/trace/partition/tables.js +13 -5
  288. package/dist/trace/partition/tables.js.map +1 -1
  289. package/dist/trace/runtime/expire-stale-traces.d.ts +10 -0
  290. package/dist/trace/runtime/expire-stale-traces.d.ts.map +1 -0
  291. package/dist/trace/runtime/expire-stale-traces.js +36 -0
  292. package/dist/trace/runtime/expire-stale-traces.js.map +1 -0
  293. package/dist/trace/runtime/flow-step.d.ts +6 -0
  294. package/dist/trace/runtime/flow-step.d.ts.map +1 -0
  295. package/dist/trace/runtime/flow-step.js +122 -0
  296. package/dist/trace/runtime/flow-step.js.map +1 -0
  297. package/dist/trace/runtime/flush-steps.d.ts +5 -0
  298. package/dist/trace/runtime/flush-steps.d.ts.map +1 -0
  299. package/dist/trace/runtime/flush-steps.js +23 -0
  300. package/dist/trace/runtime/flush-steps.js.map +1 -0
  301. package/dist/trace/runtime/step-buffer.d.ts +139 -0
  302. package/dist/trace/runtime/step-buffer.d.ts.map +1 -0
  303. package/dist/trace/runtime/step-buffer.js +140 -0
  304. package/dist/trace/runtime/step-buffer.js.map +1 -0
  305. package/dist/trace/runtime/step-error.d.ts +8 -0
  306. package/dist/trace/runtime/step-error.d.ts.map +1 -0
  307. package/dist/trace/runtime/step-error.js +13 -0
  308. package/dist/trace/runtime/step-error.js.map +1 -0
  309. package/dist/trace/runtime/step-meta.d.ts +48 -0
  310. package/dist/trace/runtime/step-meta.d.ts.map +1 -0
  311. package/dist/trace/runtime/step-meta.js +6 -0
  312. package/dist/trace/runtime/step-meta.js.map +1 -0
  313. package/dist/trace/runtime/thenable.d.ts +3 -0
  314. package/dist/trace/runtime/thenable.d.ts.map +1 -0
  315. package/dist/trace/runtime/thenable.js +12 -0
  316. package/dist/trace/runtime/thenable.js.map +1 -0
  317. package/dist/trace/runtime/truncate-trace.d.ts +5 -0
  318. package/dist/trace/runtime/truncate-trace.d.ts.map +1 -0
  319. package/dist/trace/runtime/truncate-trace.js +44 -0
  320. package/dist/trace/runtime/truncate-trace.js.map +1 -0
  321. package/dist/trace/schema/trace-fields.d.ts +1 -1
  322. package/dist/trace/schema/trace-retained.d.ts +1 -1
  323. package/dist/trace/schema/trace.d.ts +1 -1
  324. package/dist/trace/transformer/build-meta-literal.d.ts +3 -0
  325. package/dist/trace/transformer/build-meta-literal.d.ts.map +1 -0
  326. package/dist/trace/transformer/build-meta-literal.js +8 -0
  327. package/dist/trace/transformer/build-meta-literal.js.map +1 -0
  328. package/dist/trace/transformer/find-flow-step-sites.d.ts +24 -0
  329. package/dist/trace/transformer/find-flow-step-sites.d.ts.map +1 -0
  330. package/dist/trace/transformer/find-flow-step-sites.js +69 -0
  331. package/dist/trace/transformer/find-flow-step-sites.js.map +1 -0
  332. package/dist/trace/transformer/inject-flow-step-import.d.ts +3 -0
  333. package/dist/trace/transformer/inject-flow-step-import.d.ts.map +1 -0
  334. package/dist/trace/transformer/inject-flow-step-import.js +28 -0
  335. package/dist/trace/transformer/inject-flow-step-import.js.map +1 -0
  336. package/dist/trace/transformer/transform-error.d.ts +8 -0
  337. package/dist/trace/transformer/transform-error.d.ts.map +1 -0
  338. package/dist/trace/transformer/transform-error.js +5 -0
  339. package/dist/trace/transformer/transform-error.js.map +1 -0
  340. package/dist/trace/transformer/transform-flow-steps.d.ts +12 -0
  341. package/dist/trace/transformer/transform-flow-steps.d.ts.map +1 -0
  342. package/dist/trace/transformer/transform-flow-steps.js +85 -0
  343. package/dist/trace/transformer/transform-flow-steps.js.map +1 -0
  344. package/dist/trace/transformer/wrap-function-declaration.d.ts +3 -0
  345. package/dist/trace/transformer/wrap-function-declaration.d.ts.map +1 -0
  346. package/dist/trace/transformer/wrap-function-declaration.js +28 -0
  347. package/dist/trace/transformer/wrap-function-declaration.js.map +1 -0
  348. package/dist/trace/transformer/wrap-variable-declaration.d.ts +3 -0
  349. package/dist/trace/transformer/wrap-variable-declaration.d.ts.map +1 -0
  350. package/dist/trace/transformer/wrap-variable-declaration.js +30 -0
  351. package/dist/trace/transformer/wrap-variable-declaration.js.map +1 -0
  352. package/dist/workspace/generate.d.ts.map +1 -1
  353. package/dist/workspace/generate.js +5 -8
  354. package/dist/workspace/generate.js.map +1 -1
  355. package/package.json +21 -6
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parent-trace.js","sourceRoot":"","sources":["../../../src/trace/entry/parent-trace.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,2EAA2E;AAC3E,+EAA+E;AAC/E,kDAAkD;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AAG3D,2FAA2F;AAC3F,MAAM,UAAU,WAAW;IACzB,OAAO,UAAU,EAAE,EAAE,KAAK,IAAI,IAAI,CAAA;AACpC,CAAC"}
@@ -0,0 +1,8 @@
1
+ /** A parsed traceparent — only the fields pipework actually wires through. */
2
+ export interface ParsedTraceparent {
3
+ /** The W3C trace-id, formatted as a UUID for direct use in `trace.parent_id`. */
4
+ readonly traceId: string;
5
+ }
6
+ /** Parses a `traceparent` header value; returns `null` for missing or malformed input. */
7
+ export declare function parseTraceparent(header: string | string[] | undefined): ParsedTraceparent | null;
8
+ //# sourceMappingURL=parse-traceparent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-traceparent.d.ts","sourceRoot":"","sources":["../../../src/trace/entry/parse-traceparent.ts"],"names":[],"mappings":"AAiBA,8EAA8E;AAC9E,MAAM,WAAW,iBAAiB;IAChC,iFAAiF;IACjF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB;AAED,0FAA0F;AAC1F,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,GAAG,iBAAiB,GAAG,IAAI,CAUhG"}
@@ -0,0 +1,37 @@
1
+ // Parses the W3C `traceparent` HTTP header (Q10 — cross-team contract with
2
+ // plumb). Format: `version-trace-id-parent-id-trace-flags`, version-00 only.
3
+ // The spec is strict: any deviation from the format means the header is
4
+ // invalid and the receiver MUST start a new trace as if it weren't there.
5
+ // We return the trace-id formatted as a UUID so it can land in
6
+ // `trace.parent_id` directly; the parent-id and trace-flags fields are
7
+ // validated but not surfaced — pipework's parent_id wiring uses the
8
+ // distributed trace-id, not the W3C parent-span-id.
9
+ //
10
+ // Spec: https://www.w3.org/TR/trace-context/#traceparent-header
11
+ const TRACE_ID_RE = /^[0-9a-f]{32}$/;
12
+ const PARENT_ID_RE = /^[0-9a-f]{16}$/;
13
+ const FLAGS_RE = /^[0-9a-f]{2}$/;
14
+ const TRACE_ID_ZERO = '0'.repeat(32);
15
+ const PARENT_ID_ZERO = '0'.repeat(16);
16
+ /** Parses a `traceparent` header value; returns `null` for missing or malformed input. */
17
+ export function parseTraceparent(header) {
18
+ if (typeof header !== 'string')
19
+ return null;
20
+ const parts = header.split('-');
21
+ if (parts.length !== 4)
22
+ return null;
23
+ const [version, traceId, parentId, flags] = parts;
24
+ if (version !== '00')
25
+ return null;
26
+ if (!TRACE_ID_RE.test(traceId) || traceId === TRACE_ID_ZERO)
27
+ return null;
28
+ if (!PARENT_ID_RE.test(parentId) || parentId === PARENT_ID_ZERO)
29
+ return null;
30
+ if (!FLAGS_RE.test(flags))
31
+ return null;
32
+ return { traceId: formatAsUuid(traceId) };
33
+ }
34
+ function formatAsUuid(hex32) {
35
+ return `${hex32.slice(0, 8)}-${hex32.slice(8, 12)}-${hex32.slice(12, 16)}-${hex32.slice(16, 20)}-${hex32.slice(20, 32)}`;
36
+ }
37
+ //# sourceMappingURL=parse-traceparent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-traceparent.js","sourceRoot":"","sources":["../../../src/trace/entry/parse-traceparent.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,6EAA6E;AAC7E,wEAAwE;AACxE,0EAA0E;AAC1E,+DAA+D;AAC/D,uEAAuE;AACvE,oEAAoE;AACpE,oDAAoD;AACpD,EAAE;AACF,gEAAgE;AAEhE,MAAM,WAAW,GAAG,gBAAgB,CAAA;AACpC,MAAM,YAAY,GAAG,gBAAgB,CAAA;AACrC,MAAM,QAAQ,GAAG,eAAe,CAAA;AAChC,MAAM,aAAa,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AACpC,MAAM,cAAc,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AAQrC,0FAA0F;AAC1F,MAAM,UAAU,gBAAgB,CAAC,MAAqC;IACpE,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IAC3C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC/B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IACnC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,KAAyC,CAAA;IACrF,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IACjC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,OAAO,KAAK,aAAa;QAAE,OAAO,IAAI,CAAA;IACxE,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,QAAQ,KAAK,cAAc;QAAE,OAAO,IAAI,CAAA;IAC5E,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IACtC,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE,CAAA;AAC3C,CAAC;AAED,SAAS,YAAY,CAAC,KAAa;IACjC,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAA;AAC1H,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { StepBuffer } from '../runtime/step-buffer.js';
2
+ /** The ingress point a trace was opened at. Mirrors `traceFields.entryKind`. */
3
+ export type TraceEntryKind = 'http' | 'job' | 'cron' | 'test';
4
+ export interface TraceContext {
5
+ /** This trace's id — the `trace.id` of the row opened at the entry. */
6
+ readonly id: string;
7
+ /** The root of the trace tree. Equals `id` for a root trace. */
8
+ readonly rootId: string;
9
+ /** The UTC calendar day the trace opened — the partition its row lives in. */
10
+ readonly openedDay: string;
11
+ /**
12
+ * Resolves once the opening `INSERT` has settled. The closing `UPDATE` waits
13
+ * on this so it can never race ahead of the row it means to close.
14
+ */
15
+ readonly persisted: Promise<void>;
16
+ /** The in-memory `trace_step` buffer flow steps record into — drained at close. */
17
+ readonly buffer: StepBuffer;
18
+ }
19
+ //# sourceMappingURL=trace-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace-context.d.ts","sourceRoot":"","sources":["../../../src/trace/entry/trace-context.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAE3D,gFAAgF;AAChF,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAA;AAE7D,MAAM,WAAW,YAAY;IAC3B,uEAAuE;IACvE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,gEAAgE;IAChE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,8EAA8E;IAC9E,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACjC,mFAAmF;IACnF,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;CAC5B"}
@@ -0,0 +1,5 @@
1
+ // The trace's runtime handle on the Flow. Every Flow that runs under tracing
2
+ // carries one; flow steps record `trace_step` rows into `buffer`, and a child
3
+ // entry reads `id` / `rootId` to wire itself into the trace tree.
4
+ export {};
5
+ //# sourceMappingURL=trace-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace-context.js","sourceRoot":"","sources":["../../../src/trace/entry/trace-context.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,8EAA8E;AAC9E,kEAAkE"}
@@ -0,0 +1,4 @@
1
+ import type { Manifold } from '../../core/pipework.js';
2
+ /** Whether trace rows should be opened for this manifold's entries. */
3
+ export declare function isTracingEnabled(instance: Manifold): boolean;
4
+ //# sourceMappingURL=tracing-enabled.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracing-enabled.d.ts","sourceRoot":"","sources":["../../../src/trace/entry/tracing-enabled.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AAEtD,uEAAuE;AACvE,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAE5D"}
@@ -0,0 +1,8 @@
1
+ // Tracing is opt-in: a Blueprint with no `trace` block runs untraced and pays
2
+ // zero overhead at the ingress points. Configuring `trace` — even as `{}`, which
3
+ // resolves entirely to defaults — turns it on.
4
+ /** Whether trace rows should be opened for this manifold's entries. */
5
+ export function isTracingEnabled(instance) {
6
+ return instance.config.raw.trace !== undefined;
7
+ }
8
+ //# sourceMappingURL=tracing-enabled.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracing-enabled.js","sourceRoot":"","sources":["../../../src/trace/entry/tracing-enabled.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,iFAAiF;AACjF,+CAA+C;AAI/C,uEAAuE;AACvE,MAAM,UAAU,gBAAgB,CAAC,QAAkB;IACjD,OAAO,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,KAAK,SAAS,CAAA;AAChD,CAAC"}
@@ -3,6 +3,8 @@ export interface TracePartitionConfig {
3
3
  readonly hotRetentionDays: number;
4
4
  /** Days of cold partitions kept for `trace_retained` / `trace_step_retained`. */
5
5
  readonly errorRetentionDays: number;
6
+ /** Days of audit partitions kept for `audit_record` — independent of trace storage. */
7
+ readonly auditRetentionDays: number;
6
8
  /** Days of partitions pre-created ahead of today so writes never race creation. */
7
9
  readonly partitionLeadDays: number;
8
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../../../src/trace/partition/plan.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,oBAAoB;IACnC,8DAA8D;IAC9D,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAA;IACjC,iFAAiF;IACjF,QAAQ,CAAC,kBAAkB,EAAE,MAAM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ED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,CAAA;IACxC,QAAQ,CAAC,IAAI,EAAE,SAAS,YAAY,EAAE,CAAA;CACvC;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAA;IAClB,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAA;IACrC,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAA;CAC5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,kBAAkB,GAAG,aAAa,CAuBvE"}
@@ -20,7 +20,7 @@ export function planPartitions(input) {
20
20
  const create = [];
21
21
  const drop = [];
22
22
  for (const { parent, retention } of PARTITIONED_TRACE_TABLES) {
23
- const retentionDays = retention === 'hot' ? config.hotRetentionDays : config.errorRetentionDays;
23
+ const retentionDays = retentionDaysFor(retention, config);
24
24
  const cutoff = addDays(today, -retentionDays);
25
25
  const existing = input.existing.get(parent) ?? new Set();
26
26
  for (const day of dayRange(cutoff, addDays(today, config.partitionLeadDays))) {
@@ -36,4 +36,11 @@ export function planPartitions(input) {
36
36
  }
37
37
  return { create, drop };
38
38
  }
39
+ function retentionDaysFor(retention, config) {
40
+ switch (retention) {
41
+ case 'hot': return config.hotRetentionDays;
42
+ case 'cold': return config.errorRetentionDays;
43
+ case 'audit': return config.auditRetentionDays;
44
+ }
45
+ }
39
46
  //# sourceMappingURL=plan.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plan.js","sourceRoot":"","sources":["../../../src/trace/partition/plan.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,qEAAqE;AACrE,8EAA8E;AAC9E,0EAA0E;AAE1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,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AM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACxF;AAED,wBAAsB,iCAAiC,CACrD,SAAS,EAAE,aAAa,EACxB,EAAE,EAAE,EAAE,EACN,IAAI,GAAE,MAAyC,GAC9C,OAAO,CAAC,IAAI,CAAC,CAEf"}
1
+ {"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../../src/trace/partition/schedule.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAA;AAEhD,eAAO,MAAM,+BAA+B,yCAAyC,CAAA;AAErF,kFAAkF;AAClF,eAAO,MAAM,gCAAgC,eAAe,CAAA;AAE5D,kGAAkG;AAClG,UAAU,aAAa;IACrB,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACxF;AAED,wBAAsB,iCAAiC,CACrD,SAAS,EAAE,aAAa,EACxB,EAAE,EAAE,EAAE,EACN,IAAI,GAAE,MAAyC,GAC9C,OAAO,CAAC,IAAI,CAAC,CAEf"}
@@ -1,7 +1,9 @@
1
- // Registers partition maintenance as a recurring job on the cron scheduler.
2
- // The startup hook covers the boot moment; this keeps partitions rolling
3
- // forward for a long-lived process. The job body is `syncTracePartitions` —
4
- // the consumer's worker dispatch routes `TRACE_PARTITION_MAINTENANCE_JOB` to it.
1
+ // Registers trace maintenance as a recurring job on the cron scheduler. The
2
+ // startup hook covers the boot moment; this keeps things rolling forward for a
3
+ // long-lived process. The consumer's worker dispatch routes
4
+ // `TRACE_PARTITION_MAINTENANCE_JOB` to a body that runs both `syncTracePartitions`
5
+ // (rolls day partitions forward, drops retired ones) and `expireStaleTraces`
6
+ // (force-closes orphan traces past their hot retention window — Q7).
5
7
  export const TRACE_PARTITION_MAINTENANCE_JOB = 'pipework.trace.partition-maintenance';
6
8
  /** Daily at 01:10 UTC — past the midnight day rollover, before business hours. */
7
9
  export const TRACE_PARTITION_MAINTENANCE_CRON = '10 1 * * *';
@@ -1 +1 @@
1
- {"version":3,"file":"schedule.js","sourceRoot":"","sources":["../../../src/trace/partition/schedule.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,yEAAyE;AACzE,4EAA4E;AAC5E,iFAAiF;AAIjF,MAAM,CAAC,MAAM,+BAA+B,GAAG,sCAAsC,CAAA;AAErF,kFAAkF;AAClF,MAAM,CAAC,MAAM,gCAAgC,GAAG,YAAY,CAAA;AAO5D,MAAM,CAAC,KAAK,UAAU,iCAAiC,CACrD,SAAwB,EACxB,EAAM,EACN,OAAe,gCAAgC;IAE/C,MAAM,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,+BAA+B,EAAE,IAAI,EAAE,CAAC,CAAA;AAC/E,CAAC"}
1
+ {"version":3,"file":"schedule.js","sourceRoot":"","sources":["../../../src/trace/partition/schedule.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,+EAA+E;AAC/E,4DAA4D;AAC5D,mFAAmF;AACnF,6EAA6E;AAC7E,qEAAqE;AAIrE,MAAM,CAAC,MAAM,+BAA+B,GAAG,sCAAsC,CAAA;AAErF,kFAAkF;AAClF,MAAM,CAAC,MAAM,gCAAgC,GAAG,YAAY,CAAA;AAO5D,MAAM,CAAC,KAAK,UAAU,iCAAiC,CACrD,SAAwB,EACxB,EAAM,EACN,OAAe,gCAAgC;IAE/C,MAAM,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,+BAA+B,EAAE,IAAI,EAAE,CAAC,CAAA;AAC/E,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"startup-hook.d.ts","sourceRoot":"","sources":["../../../src/trace/partition/startup-hook.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAA;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAEhE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAErD,eAAO,MAAM,yBAAyB,gCAAgC,CAAA;AAEtE,wBAAgB,+BAA+B,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,oBAAoB,GAAG,WAAW,CAOjG"}
1
+ {"version":3,"file":"startup-hook.d.ts","sourceRoot":"","sources":["../../../src/trace/partition/startup-hook.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAA;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAGhE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAErD,eAAO,MAAM,yBAAyB,gCAAgC,CAAA;AAEtE,wBAAgB,+BAA+B,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,oBAAoB,GAAG,WAAW,CAQjG"}
@@ -1,14 +1,18 @@
1
- // Partition maintenance as a startup hook. Running it at boot guarantees the
1
+ // Trace maintenance as a startup hook. Running it at boot guarantees the
2
2
  // near-term partitions exist before the app takes its first request — a fresh
3
3
  // deploy on a new day must not write a trace into a partition that doesn't
4
- // exist yet. The cron schedule keeps it current after that.
4
+ // exist yet and clears any orphan traces left open by a process that died
5
+ // without closing them (Q7 expiry). The cron schedule keeps both current after
6
+ // that.
5
7
  import { syncTracePartitions } from './sync.js';
8
+ import { expireStaleTraces } from '../runtime/expire-stale-traces.js';
6
9
  export const TRACE_PARTITION_HOOK_NAME = 'trace-partition-maintenance';
7
10
  export function createTracePartitionStartupHook(db, config) {
8
11
  return {
9
12
  name: TRACE_PARTITION_HOOK_NAME,
10
13
  async execute() {
11
14
  await syncTracePartitions(db, config);
15
+ await expireStaleTraces(db);
12
16
  },
13
17
  };
14
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"startup-hook.js","sourceRoot":"","sources":["../../../src/trace/partition/startup-hook.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,8EAA8E;AAC9E,2EAA2E;AAC3E,4DAA4D;AAI5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAG/C,MAAM,CAAC,MAAM,yBAAyB,GAAG,6BAA6B,CAAA;AAEtE,MAAM,UAAU,+BAA+B,CAAC,EAAM,EAAE,MAA4B;IAClF,OAAO;QACL,IAAI,EAAE,yBAAyB;QAC/B,KAAK,CAAC,OAAO;YACX,MAAM,mBAAmB,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;QACvC,CAAC;KACF,CAAA;AACH,CAAC"}
1
+ {"version":3,"file":"startup-hook.js","sourceRoot":"","sources":["../../../src/trace/partition/startup-hook.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,8EAA8E;AAC9E,2EAA2E;AAC3E,4EAA4E;AAC5E,+EAA+E;AAC/E,QAAQ;AAIR,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AAGrE,MAAM,CAAC,MAAM,yBAAyB,GAAG,6BAA6B,CAAA;AAEtE,MAAM,UAAU,+BAA+B,CAAC,EAAM,EAAE,MAA4B;IAClF,OAAO;QACL,IAAI,EAAE,yBAAyB;QAC/B,KAAK,CAAC,OAAO;YACX,MAAM,mBAAmB,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;YACrC,MAAM,iBAAiB,CAAC,EAAE,CAAC,CAAA;QAC7B,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -1,4 +1,4 @@
1
- export type RetentionClass = 'hot' | 'cold';
1
+ export type RetentionClass = 'hot' | 'cold' | 'audit';
2
2
  export interface PartitionedTraceTable {
3
3
  /** The parent table's wire name — partitions are children of this. */
4
4
  readonly parent: string;
@@ -1 +1 @@
1
- {"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../../../src/trace/partition/tables.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,MAAM,CAAA;AAE3C,MAAM,WAAW,qBAAqB;IACpC,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,SAAS,EAAE,cAAc,CAAA;CACnC;AAED,eAAO,MAAM,wBAAwB,EAAE,SAAS,qBAAqB,EAKpE,CAAA"}
1
+ {"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../../../src/trace/partition/tables.ts"],"names":[],"mappings":"AAkBA,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,CAAA;AAErD,MAAM,WAAW,qBAAqB;IACpC,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,SAAS,EAAE,cAAc,CAAA;CACnC;AAED,eAAO,MAAM,wBAAwB,EAAE,SAAS,qBAAqB,EAMpE,CAAA"}
@@ -1,16 +1,24 @@
1
- // The four partitioned trace tables and the retention window each one obeys.
2
- // Hot tables (`trace`, `trace_step`) keep `hotRetentionDays` of partitions;
3
- // cold tables (`trace_retained`, `trace_step_retained`) keep
4
- // `errorRetentionDays`. Partition creation uses the same lead window for all
5
- // four — copy-on-error can land a cold row on any day a hot row exists.
1
+ // The partitioned tables the substrate manages, plus the retention window each
2
+ // one obeys. Three retention classes share one partition lifecycle:
3
+ //
4
+ // - **hot** (`trace`, `trace_step`) `hotRetentionDays`, short-lived.
5
+ // - **cold** (`trace_retained`, `trace_step_retained`) `errorRetentionDays`,
6
+ // copy-on-error survives past hot retention.
7
+ // - **audit** (`audit_record`) — `auditRetentionDays`, long / indefinite; the
8
+ // audit projection lives independently of trace storage.
9
+ //
10
+ // Partition creation uses the same `partitionLeadDays` for all three classes —
11
+ // inserts on any class must never race partition creation.
6
12
  import { trace } from '../schema/trace.js';
7
13
  import { traceStep } from '../schema/trace-step.js';
8
14
  import { traceRetained } from '../schema/trace-retained.js';
9
15
  import { traceStepRetained } from '../schema/trace-step-retained.js';
16
+ import { auditRecord } from '../../audit/schema/audit-record.js';
10
17
  export const PARTITIONED_TRACE_TABLES = [
11
18
  { parent: trace.$name, retention: 'hot' },
12
19
  { parent: traceStep.$name, retention: 'hot' },
13
20
  { parent: traceRetained.$name, retention: 'cold' },
14
21
  { parent: traceStepRetained.$name, retention: 'cold' },
22
+ { parent: auditRecord.$name, retention: 'audit' },
15
23
  ];
16
24
  //# sourceMappingURL=tables.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tables.js","sourceRoot":"","sources":["../../../src/trace/partition/tables.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,4EAA4E;AAC5E,6DAA6D;AAC7D,6EAA6E;AAC7E,wEAAwE;AAExE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AAUpE,MAAM,CAAC,MAAM,wBAAwB,GAAqC;IACxE,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE;IACzC,EAAE,MAAM,EAAE,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE;IAC7C,EAAE,MAAM,EAAE,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE;IAClD,EAAE,MAAM,EAAE,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE;CACvD,CAAA"}
1
+ {"version":3,"file":"tables.js","sourceRoot":"","sources":["../../../src/trace/partition/tables.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,oEAAoE;AACpE,EAAE;AACF,yEAAyE;AACzE,iFAAiF;AACjF,iDAAiD;AACjD,gFAAgF;AAChF,6DAA6D;AAC7D,EAAE;AACF,+EAA+E;AAC/E,2DAA2D;AAE3D,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAA;AAUhE,MAAM,CAAC,MAAM,wBAAwB,GAAqC;IACxE,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE;IACzC,EAAE,MAAM,EAAE,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE;IAC7C,EAAE,MAAM,EAAE,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE;IAClD,EAAE,MAAM,EAAE,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE;IACtD,EAAE,MAAM,EAAE,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE;CAClD,CAAA"}
@@ -0,0 +1,10 @@
1
+ import type { DB } from '../../data/db/index.js';
2
+ export interface ExpireStaleTracesResult {
3
+ /** Trace rows force-closed by this sweep (`open` past `expires_at`). */
4
+ readonly expired: number;
5
+ /** Rows newly inserted into `trace_retained` across all expired traces. */
6
+ readonly retained: number;
7
+ }
8
+ /** Force-closes every trace whose `expires_at` has passed; copies each to the cold set. */
9
+ export declare function expireStaleTraces(db: DB, now?: Date): Promise<ExpireStaleTracesResult>;
10
+ //# sourceMappingURL=expire-stale-traces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expire-stale-traces.d.ts","sourceRoot":"","sources":["../../../src/trace/runtime/expire-stale-traces.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAA;AAIhD,MAAM,WAAW,uBAAuB;IACtC,wEAAwE;IACxE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,2EAA2E;IAC3E,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAC1B;AAED,2FAA2F;AAC3F,wBAAsB,iBAAiB,CACrC,EAAE,EAAE,EAAE,EACN,GAAG,GAAE,IAAiB,GACrB,OAAO,CAAC,uBAAuB,CAAC,CAuBlC"}
@@ -0,0 +1,36 @@
1
+ // Q7 expiry sweep. A trace must not outlive its own oldest day-partition: if
2
+ // a trace is still `open` past `expires_at` (stamped as `opened_at +
3
+ // hotRetentionDays` at entry), the entry leaked or the job hung — the process
4
+ // that opened the trace may be long dead, so there is no in-memory buffer to
5
+ // flush. The sweep force-closes those orphans at the database level: stamps
6
+ // `status = 'expired'` and `closed_at`, then copies the trace to the cold set
7
+ // (treated as an error for Q4) before the next partition retirement drops the
8
+ // hot row.
9
+ //
10
+ // `force_now` is injectable so the sweep is testable without mocking the
11
+ // clock — production calls pass nothing and use `NOW()`.
12
+ import { sql } from '../../data/db/sql.js';
13
+ import { getBaseLogger } from '../../core/logging/index.js';
14
+ import { copyTraceOnError } from '../retain/copy-on-error.js';
15
+ /** Force-closes every trace whose `expires_at` has passed; copies each to the cold set. */
16
+ export async function expireStaleTraces(db, now = new Date()) {
17
+ // postgres.js's raw `sql` parameters carry no column-type hint, so a Date
18
+ // binds as an unsupported type for `timestamptz`. The boundary cast to an
19
+ // ISO string keeps the production signature on `Date` without losing
20
+ // precision (compared as a literal, Postgres parses it back to `timestamptz`).
21
+ const nowIso = now.toISOString();
22
+ const rows = await db.execute(sql `
23
+ UPDATE "trace"
24
+ SET "status" = 'expired', "closed_at" = ${nowIso}
25
+ WHERE "status" = 'open' AND "expires_at" <= ${nowIso}
26
+ RETURNING "id"
27
+ `);
28
+ const ids = rows.map(r => r['id']);
29
+ if (ids.length === 0)
30
+ return { expired: 0, retained: 0 };
31
+ getBaseLogger().error({ count: ids.length, traceIds: ids }, 'Force-closed expired traces — entries leaked or hung past their hot retention window');
32
+ const copyResults = await Promise.all(ids.map(id => copyTraceOnError(db, id)));
33
+ const retained = copyResults.reduce((sum, r) => sum + r.traces, 0);
34
+ return { expired: ids.length, retained };
35
+ }
36
+ //# sourceMappingURL=expire-stale-traces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expire-stale-traces.js","sourceRoot":"","sources":["../../../src/trace/runtime/expire-stale-traces.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,qEAAqE;AACrE,8EAA8E;AAC9E,6EAA6E;AAC7E,4EAA4E;AAC5E,8EAA8E;AAC9E,8EAA8E;AAC9E,WAAW;AACX,EAAE;AACF,yEAAyE;AACzE,yDAAyD;AAEzD,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAA;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAS7D,2FAA2F;AAC3F,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,EAAM,EACN,MAAY,IAAI,IAAI,EAAE;IAEtB,0EAA0E;IAC1E,0EAA0E;IAC1E,qEAAqE;IACrE,+EAA+E;IAC/E,MAAM,MAAM,GAAG,GAAG,CAAC,WAAW,EAAE,CAAA;IAChC,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,CAAA;;8CAEW,MAAM;kDACF,MAAM;;GAErD,CAAC,CAAA;IACF,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAW,CAAC,CAAA;IAC5C,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAA;IAExD,aAAa,EAAE,CAAC,KAAK,CACnB,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,EACpC,sFAAsF,CACvF,CAAA;IAED,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,gBAAgB,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA;IAC9E,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;IAClE,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAA;AAC1C,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { FlowStepMeta } from './step-meta.js';
2
+ type AnyFunction = (...args: any[]) => any;
3
+ /** Wraps `impl` so that, under an active traced Flow, each call records a `trace_step`. */
4
+ export declare function __flowStep<F extends AnyFunction>(meta: FlowStepMeta, impl: F): F;
5
+ export {};
6
+ //# sourceMappingURL=flow-step.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-step.d.ts","sourceRoot":"","sources":["../../../src/trace/runtime/flow-step.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAqB,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAKrE,KAAK,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAA;AAE1C,2FAA2F;AAC3F,wBAAgB,UAAU,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CA2DhF"}
@@ -0,0 +1,122 @@
1
+ // `__flowStep` — the value-wrapping runtime for a flow step. The build
2
+ // transformer (component 5) renames each documented function and rebinds its
3
+ // public name through this wrapper: `export const runJob = __flowStep(meta,
4
+ // runJobImpl)`. No body is rewritten; the wrapper is the whole instrumentation.
5
+ //
6
+ // Off the traced path it is a pass-through with one `getContext()` lookup and a
7
+ // branch — there is no active Flow, or the Flow opened no trace, so there is
8
+ // nothing to record. On the traced path it brackets the implementation with a
9
+ // `trace_step`: a `seq`, a parent link, start/end timing, and the outcome.
10
+ // Once a trace truncates (Q7), every later step takes the pass-through path
11
+ // too, so a truncated trace costs exactly what an untraced one does.
12
+ //
13
+ // Tier-2 input capture (Q5) runs at `begin` time, before the implementation
14
+ // gets a chance to mutate the arguments. Each parameter's projection — baked
15
+ // into `meta.capture` by the transformer — turns its argument into a
16
+ // trace-safe payload, which the bounded serializer caps for depth, fan-out,
17
+ // string length, and redaction before staging onto `trace_step.captured_inputs`.
18
+ // The trace's `captureInputs` kill-switch (resolved at trace open from
19
+ // `config.trace.captureInputs`) suppresses the whole capture path while
20
+ // leaving Tier-1 (timing, status, error) untouched.
21
+ //
22
+ // `meta` is a literal baked in at transform time — the wrapper never computes
23
+ // the step's identity.
24
+ import { getContext } from '../../request/context/store.js';
25
+ import { serializeForTrace } from '../capture/bounded-serializer.js';
26
+ import { isThenable } from './thenable.js';
27
+ import { truncateTrace } from './truncate-trace.js';
28
+ import { emitReadTouches } from '../../data/write/audit/read-touches.js';
29
+ /** Wraps `impl` so that, under an active traced Flow, each call records a `trace_step`. */
30
+ export function __flowStep(meta, impl) {
31
+ function traced(...args) {
32
+ const flow = getContext();
33
+ if (flow === undefined || flow.trace === null) {
34
+ return impl.apply(this, args);
35
+ }
36
+ const ctx = flow.trace;
37
+ const buffer = ctx.buffer;
38
+ if (buffer.truncated) {
39
+ return impl.apply(this, args);
40
+ }
41
+ const capturedInputs = buffer.captureInputs && meta.capture !== undefined
42
+ ? captureArgs(args, meta.capture)
43
+ : null;
44
+ const begun = buffer.begin(meta.ref, capturedInputs, meta.touches ?? []);
45
+ // `begin` returns null for the call that blows the step cap — that call,
46
+ // and every step after it, runs untraced. The transition fires `truncateTrace`
47
+ // exactly once: the `buffer.truncated` short-circuit above catches every
48
+ // subsequent call before it reaches `begin`.
49
+ if (begun === null) {
50
+ void truncateTrace(flow.instance, ctx);
51
+ return impl.apply(this, args);
52
+ }
53
+ let result;
54
+ try {
55
+ result = impl.apply(this, args);
56
+ }
57
+ catch (err) {
58
+ buffer.complete(begun, 'error', err);
59
+ throw err;
60
+ }
61
+ if (isThenable(result)) {
62
+ return result.then(async (value) => {
63
+ buffer.complete(begun, 'ok', null);
64
+ await emitReadTouchesIfNeeded(flow, begun);
65
+ return value;
66
+ }, (err) => {
67
+ buffer.complete(begun, 'error', err);
68
+ throw err;
69
+ });
70
+ }
71
+ buffer.complete(begun, 'ok', null);
72
+ // Sync impl: can't change the wrapper's return type to Promise, so fire-and-
73
+ // forget. The audit emitter swallows its own errors, so this won't yield an
74
+ // unhandled rejection; the trade-off is that a sync `@touches` step's audit
75
+ // row may land after control has returned to the caller. Sync impls under
76
+ // `@touches` are rare anyway (pipe.* writes are all async).
77
+ void emitReadTouchesIfNeeded(flow, begun);
78
+ return result;
79
+ }
80
+ return traced;
81
+ }
82
+ /* eslint-enable @typescript-eslint/no-explicit-any */
83
+ /**
84
+ * Read-touches gate. The CTE-form write path already covered the write case
85
+ * (flips `wroteForAudit` via `markWrote()`); this fires the complement —
86
+ * a step that declared `@touches` but performed no `pipe.*` write. Empty
87
+ * `touches` means no audit projection at all and short-circuits earlier in
88
+ * the emitter.
89
+ */
90
+ function emitReadTouchesIfNeeded(flow, begun) {
91
+ if (begun.touches.length === 0 || begun.wroteForAudit)
92
+ return Promise.resolve();
93
+ return emitReadTouches(flow, begun);
94
+ }
95
+ /**
96
+ * Projects + bounded-serializes one captured payload per parameter, in
97
+ * declaration order. A `null` projection slot means the parameter has no
98
+ * registry-derived projection (primitive, `any`, or no `.traceSafe()` entry)
99
+ * and the raw arg is handed straight to the serializer. A projection that
100
+ * returns `undefined` is preserved as a `null` slot — fail-closed: an unsafe
101
+ * structured type with no marked-safe fields contributes no payload.
102
+ */
103
+ function captureArgs(args, projections) {
104
+ const out = [];
105
+ // Pair by parameter index. Extra args (a variadic tail without a matching
106
+ // projection) fall through to the raw-serializer path; extra projections
107
+ // (impl invoked with fewer than declared args) project `undefined` — both
108
+ // paths converge on the bounded serializer's `undefined` handling.
109
+ const count = Math.max(args.length, projections.length);
110
+ for (let i = 0; i < count; i++) {
111
+ const projection = projections[i] ?? null;
112
+ const raw = args[i];
113
+ const projected = projection === null ? raw : projection(raw);
114
+ if (projected === undefined) {
115
+ out.push(null);
116
+ continue;
117
+ }
118
+ out.push(serializeForTrace(projected));
119
+ }
120
+ return out;
121
+ }
122
+ //# sourceMappingURL=flow-step.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-step.js","sourceRoot":"","sources":["../../../src/trace/runtime/flow-step.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,6EAA6E;AAC7E,4EAA4E;AAC5E,gFAAgF;AAChF,EAAE;AACF,gFAAgF;AAChF,6EAA6E;AAC7E,8EAA8E;AAC9E,2EAA2E;AAC3E,4EAA4E;AAC5E,qEAAqE;AACrE,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,qEAAqE;AACrE,4EAA4E;AAC5E,iFAAiF;AACjF,uEAAuE;AACvE,wEAAwE;AACxE,oDAAoD;AACpD,EAAE;AACF,8EAA8E;AAC9E,uBAAuB;AAEvB,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAA;AAQxE,2FAA2F;AAC3F,MAAM,UAAU,UAAU,CAAwB,IAAkB,EAAE,IAAO;IAC3E,SAAS,MAAM,CAAgB,GAAG,IAAmB;QACnD,MAAM,IAAI,GAAG,UAAU,EAAE,CAAA;QACzB,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,KAA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E,CAAC;QAC/B,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,IAAI,CAAA;QACzC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;QACnB,MAAM,SAAS,GAAG,UAAU,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;QAC7D,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACd,SAAQ;QACV,CAAC;QACD,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAA;IACxC,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Manifold } from '../../core/pipework.js';
2
+ import type { PendingStep } from './step-buffer.js';
3
+ /** Inserts `steps` into `trace_step` in a single batch. Resolves once the write settles. */
4
+ export declare function flushSteps(instance: Manifold, steps: readonly PendingStep[]): Promise<void>;
5
+ //# sourceMappingURL=flush-steps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flush-steps.d.ts","sourceRoot":"","sources":["../../../src/trace/runtime/flush-steps.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AAGtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEnD,4FAA4F;AAC5F,wBAAgB,UAAU,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAY3F"}
@@ -0,0 +1,23 @@
1
+ // Batch-writes a buffered set of `trace_step` rows. The write is fire-and-
2
+ // forget — the close path doesn't block on it, and a failure must not break
3
+ // the request: a missing step row is a degraded trace, not a degraded user
4
+ // flow. Errors land in the base logger so an operator can see what was lost.
5
+ //
6
+ // The write goes through `instance.pool` directly, never the request
7
+ // transaction — an errored request rolls back, but its trace steps must
8
+ // survive to be inspected.
9
+ import { getBaseLogger } from '../../core/logging/index.js';
10
+ import { traceStep } from '../schema/trace-step.js';
11
+ /** Inserts `steps` into `trace_step` in a single batch. Resolves once the write settles. */
12
+ export function flushSteps(instance, steps) {
13
+ if (steps.length === 0)
14
+ return Promise.resolve();
15
+ const db = instance.pool.getOrCreate(instance.config.database()).drizzle;
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Drizzle's insert needs the concrete runtime table type
17
+ return db.insert(traceStep.table()).values([...steps])
18
+ .then(() => undefined)
19
+ .catch((err) => {
20
+ getBaseLogger().error({ err, traceId: steps[0].traceId, steps: steps.length }, 'Failed to persist trace steps — the trace is missing step rows');
21
+ });
22
+ }
23
+ //# sourceMappingURL=flush-steps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flush-steps.js","sourceRoot":"","sources":["../../../src/trace/runtime/flush-steps.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,4EAA4E;AAC5E,2EAA2E;AAC3E,6EAA6E;AAC7E,EAAE;AACF,qEAAqE;AACrE,wEAAwE;AACxE,2BAA2B;AAG3B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAGnD,4FAA4F;AAC5F,MAAM,UAAU,UAAU,CAAC,QAAkB,EAAE,KAA6B;IAC1E,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;IAChD,MAAM,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAA;IACxE,wHAAwH;IACxH,OAAQ,EAAU,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;SAC5D,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC;SACrB,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;QACtB,aAAa,EAAE,CAAC,KAAK,CACnB,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAE,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,EACxD,gEAAgE,CACjE,CAAA;IACH,CAAC,CAAC,CAAA;AACN,CAAC"}