@opensaas/stack-core 0.43.0 → 0.44.0-alpha.1

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 (641) hide show
  1. package/CHANGELOG.md +2720 -0
  2. package/README.md +182 -115
  3. package/dist/.build-hash +1 -0
  4. package/dist/access/declared-dependencies.d.ts +102 -88
  5. package/dist/access/declared-dependencies.d.ts.map +1 -1
  6. package/dist/access/declared-dependencies.js +83 -71
  7. package/dist/access/declared-dependencies.js.map +1 -1
  8. package/dist/access/depth-limits.d.ts +4 -0
  9. package/dist/access/depth-limits.d.ts.map +1 -1
  10. package/dist/access/depth-limits.js +4 -0
  11. package/dist/access/depth-limits.js.map +1 -1
  12. package/dist/access/engine.d.ts +68 -20
  13. package/dist/access/engine.d.ts.map +1 -1
  14. package/dist/access/engine.js +151 -37
  15. package/dist/access/engine.js.map +1 -1
  16. package/dist/access/errors.d.ts +33 -48
  17. package/dist/access/errors.d.ts.map +1 -1
  18. package/dist/access/errors.js +73 -63
  19. package/dist/access/errors.js.map +1 -1
  20. package/dist/access/field-access.d.ts +76 -5
  21. package/dist/access/field-access.d.ts.map +1 -1
  22. package/dist/access/field-access.js +235 -61
  23. package/dist/access/field-access.js.map +1 -1
  24. package/dist/access/field-visibility.d.ts +50 -4
  25. package/dist/access/field-visibility.d.ts.map +1 -1
  26. package/dist/access/field-visibility.js +143 -160
  27. package/dist/access/field-visibility.js.map +1 -1
  28. package/dist/access/index.d.ts +5 -12
  29. package/dist/access/index.d.ts.map +1 -1
  30. package/dist/access/index.js +6 -19
  31. package/dist/access/index.js.map +1 -1
  32. package/dist/access/orm-client.d.ts +19 -0
  33. package/dist/access/orm-client.d.ts.map +1 -0
  34. package/dist/access/orm-client.js +37 -0
  35. package/dist/access/orm-client.js.map +1 -0
  36. package/dist/access/query-validation.d.ts +7 -129
  37. package/dist/access/query-validation.d.ts.map +1 -1
  38. package/dist/access/query-validation.js +12 -314
  39. package/dist/access/query-validation.js.map +1 -1
  40. package/dist/access/system-fields.d.ts +2 -0
  41. package/dist/access/system-fields.d.ts.map +1 -0
  42. package/dist/access/system-fields.js +7 -0
  43. package/dist/access/system-fields.js.map +1 -0
  44. package/dist/access/transaction-registry.d.ts +25 -2
  45. package/dist/access/transaction-registry.d.ts.map +1 -1
  46. package/dist/access/transaction-registry.js +34 -17
  47. package/dist/access/transaction-registry.js.map +1 -1
  48. package/dist/access/types.d.ts +217 -131
  49. package/dist/access/types.d.ts.map +1 -1
  50. package/dist/config/field-kind.d.ts +66 -0
  51. package/dist/config/field-kind.d.ts.map +1 -0
  52. package/dist/config/field-kind.js +63 -0
  53. package/dist/config/field-kind.js.map +1 -0
  54. package/dist/config/hook-only-fields.d.ts +3 -0
  55. package/dist/config/hook-only-fields.d.ts.map +1 -0
  56. package/dist/config/hook-only-fields.js +17 -0
  57. package/dist/config/hook-only-fields.js.map +1 -0
  58. package/dist/config/index.d.ts +3 -1
  59. package/dist/config/index.d.ts.map +1 -1
  60. package/dist/config/index.js +6 -3
  61. package/dist/config/index.js.map +1 -1
  62. package/dist/config/mcp-tool-names.d.ts +3 -0
  63. package/dist/config/mcp-tool-names.d.ts.map +1 -0
  64. package/dist/config/mcp-tool-names.js +25 -0
  65. package/dist/config/mcp-tool-names.js.map +1 -0
  66. package/dist/config/nav-count.d.ts.map +1 -1
  67. package/dist/config/nav-count.js +4 -4
  68. package/dist/config/nav-count.js.map +1 -1
  69. package/dist/config/plugin-engine.d.ts +8 -2
  70. package/dist/config/plugin-engine.d.ts.map +1 -1
  71. package/dist/config/plugin-engine.js +102 -38
  72. package/dist/config/plugin-engine.js.map +1 -1
  73. package/dist/config/types.d.ts +966 -614
  74. package/dist/config/types.d.ts.map +1 -1
  75. package/dist/context/apply-defaults.d.ts +18 -1
  76. package/dist/context/apply-defaults.d.ts.map +1 -1
  77. package/dist/context/apply-defaults.js +30 -4
  78. package/dist/context/apply-defaults.js.map +1 -1
  79. package/dist/context/engine-context.d.ts +73 -0
  80. package/dist/context/engine-context.d.ts.map +1 -0
  81. package/dist/context/engine-context.js +67 -0
  82. package/dist/context/engine-context.js.map +1 -0
  83. package/dist/context/hook-pipeline.d.ts +9 -2
  84. package/dist/context/hook-pipeline.d.ts.map +1 -1
  85. package/dist/context/hook-pipeline.js +5 -4
  86. package/dist/context/hook-pipeline.js.map +1 -1
  87. package/dist/context/index.d.ts +98 -89
  88. package/dist/context/index.d.ts.map +1 -1
  89. package/dist/context/index.js +917 -722
  90. package/dist/context/index.js.map +1 -1
  91. package/dist/context/junction.d.ts +59 -0
  92. package/dist/context/junction.d.ts.map +1 -0
  93. package/dist/context/junction.js +126 -0
  94. package/dist/context/junction.js.map +1 -0
  95. package/dist/context/plugin-field-read.d.ts +33 -0
  96. package/dist/context/plugin-field-read.d.ts.map +1 -0
  97. package/dist/context/plugin-field-read.js +41 -0
  98. package/dist/context/plugin-field-read.js.map +1 -0
  99. package/dist/context/plugin-field-write.d.ts +104 -0
  100. package/dist/context/plugin-field-write.d.ts.map +1 -0
  101. package/dist/context/plugin-field-write.js +184 -0
  102. package/dist/context/plugin-field-write.js.map +1 -0
  103. package/dist/context/relationship-input.d.ts +146 -0
  104. package/dist/context/relationship-input.d.ts.map +1 -0
  105. package/dist/context/relationship-input.js +453 -0
  106. package/dist/context/relationship-input.js.map +1 -0
  107. package/dist/context/transaction-boundary.d.ts +54 -28
  108. package/dist/context/transaction-boundary.d.ts.map +1 -1
  109. package/dist/context/transaction-boundary.js +87 -169
  110. package/dist/context/transaction-boundary.js.map +1 -1
  111. package/dist/context/write-pipeline.d.ts +33 -51
  112. package/dist/context/write-pipeline.d.ts.map +1 -1
  113. package/dist/context/write-pipeline.js +372 -185
  114. package/dist/context/write-pipeline.js.map +1 -1
  115. package/dist/contract/dependencies.d.ts +88 -0
  116. package/dist/contract/dependencies.d.ts.map +1 -0
  117. package/dist/contract/dependencies.js +237 -0
  118. package/dist/contract/dependencies.js.map +1 -0
  119. package/dist/contract/derive.d.ts +49 -0
  120. package/dist/contract/derive.d.ts.map +1 -0
  121. package/dist/contract/derive.js +540 -0
  122. package/dist/contract/derive.js.map +1 -0
  123. package/dist/contract/fixtures/contract-configs.d.ts +64 -0
  124. package/dist/contract/fixtures/contract-configs.d.ts.map +1 -0
  125. package/dist/contract/fixtures/contract-configs.js +345 -0
  126. package/dist/contract/fixtures/contract-configs.js.map +1 -0
  127. package/dist/contract/id-boundary.d.ts +53 -0
  128. package/dist/contract/id-boundary.d.ts.map +1 -0
  129. package/dist/contract/id-boundary.js +76 -0
  130. package/dist/contract/id-boundary.js.map +1 -0
  131. package/dist/contract/index.d.ts +8 -0
  132. package/dist/contract/index.d.ts.map +1 -0
  133. package/dist/contract/index.js +11 -0
  134. package/dist/contract/index.js.map +1 -0
  135. package/dist/contract/prisma.d.ts +58 -0
  136. package/dist/contract/prisma.d.ts.map +1 -0
  137. package/dist/contract/prisma.js +282 -0
  138. package/dist/contract/prisma.js.map +1 -0
  139. package/dist/contract/relation-graph.d.ts +70 -0
  140. package/dist/contract/relation-graph.d.ts.map +1 -0
  141. package/dist/contract/relation-graph.js +113 -0
  142. package/dist/contract/relation-graph.js.map +1 -0
  143. package/dist/contract/types.d.ts +135 -0
  144. package/dist/contract/types.d.ts.map +1 -0
  145. package/dist/contract/types.js +2 -0
  146. package/dist/contract/types.js.map +1 -0
  147. package/dist/db/client.d.ts +55 -0
  148. package/dist/db/client.d.ts.map +1 -0
  149. package/dist/db/client.js +73 -0
  150. package/dist/db/client.js.map +1 -0
  151. package/dist/db/dev-database.d.ts +124 -0
  152. package/dist/db/dev-database.d.ts.map +1 -0
  153. package/dist/db/dev-database.js +291 -0
  154. package/dist/db/dev-database.js.map +1 -0
  155. package/dist/db/password-front.d.ts +10 -0
  156. package/dist/db/password-front.d.ts.map +1 -0
  157. package/dist/db/password-front.js +147 -0
  158. package/dist/db/password-front.js.map +1 -0
  159. package/dist/db/process-identity.d.ts +36 -0
  160. package/dist/db/process-identity.d.ts.map +1 -0
  161. package/dist/db/process-identity.js +114 -0
  162. package/dist/db/process-identity.js.map +1 -0
  163. package/dist/db/state-file.d.ts +54 -0
  164. package/dist/db/state-file.d.ts.map +1 -0
  165. package/dist/db/state-file.js +91 -0
  166. package/dist/db/state-file.js.map +1 -0
  167. package/dist/db/url.d.ts +89 -0
  168. package/dist/db/url.d.ts.map +1 -0
  169. package/dist/db/url.js +118 -0
  170. package/dist/db/url.js.map +1 -0
  171. package/dist/extend.d.ts +13 -2
  172. package/dist/extend.d.ts.map +1 -1
  173. package/dist/extend.js +24 -1
  174. package/dist/extend.js.map +1 -1
  175. package/dist/fields/index.d.ts +87 -42
  176. package/dist/fields/index.d.ts.map +1 -1
  177. package/dist/fields/index.js +457 -677
  178. package/dist/fields/index.js.map +1 -1
  179. package/dist/filter/collect.d.ts +3 -4
  180. package/dist/filter/collect.d.ts.map +1 -1
  181. package/dist/filter/collect.js +2 -2
  182. package/dist/filter/collect.js.map +1 -1
  183. package/dist/filter/index.d.ts +1 -2
  184. package/dist/filter/index.d.ts.map +1 -1
  185. package/dist/filter/index.js +0 -1
  186. package/dist/filter/index.js.map +1 -1
  187. package/dist/filter/map.d.ts +12 -5
  188. package/dist/filter/map.d.ts.map +1 -1
  189. package/dist/filter/map.js +47 -19
  190. package/dist/filter/map.js.map +1 -1
  191. package/dist/filter/types.d.ts +10 -24
  192. package/dist/filter/types.d.ts.map +1 -1
  193. package/dist/filter/types.js +2 -11
  194. package/dist/filter/types.js.map +1 -1
  195. package/dist/hooks/index.d.ts +22 -31
  196. package/dist/hooks/index.d.ts.map +1 -1
  197. package/dist/hooks/index.js +33 -37
  198. package/dist/hooks/index.js.map +1 -1
  199. package/dist/hooks/transition-guard.d.ts +61 -0
  200. package/dist/hooks/transition-guard.d.ts.map +1 -0
  201. package/dist/hooks/transition-guard.js +93 -0
  202. package/dist/hooks/transition-guard.js.map +1 -0
  203. package/dist/index.d.ts +52 -16
  204. package/dist/index.d.ts.map +1 -1
  205. package/dist/index.js +105 -51
  206. package/dist/index.js.map +1 -1
  207. package/dist/internal.d.ts +4 -2
  208. package/dist/internal.d.ts.map +1 -1
  209. package/dist/internal.js +16 -0
  210. package/dist/internal.js.map +1 -1
  211. package/dist/lib/case-utils.d.ts +0 -1
  212. package/dist/lib/case-utils.d.ts.map +1 -1
  213. package/dist/lib/case-utils.js +0 -3
  214. package/dist/lib/case-utils.js.map +1 -1
  215. package/dist/lib/client-safe-error.d.ts +9 -0
  216. package/dist/lib/client-safe-error.d.ts.map +1 -0
  217. package/dist/lib/client-safe-error.js +23 -0
  218. package/dist/lib/client-safe-error.js.map +1 -0
  219. package/dist/lib/database-errors.d.ts +78 -0
  220. package/dist/lib/database-errors.d.ts.map +1 -0
  221. package/dist/lib/database-errors.js +148 -0
  222. package/dist/lib/database-errors.js.map +1 -0
  223. package/dist/lib/null-prototype-registry.d.ts +9 -0
  224. package/dist/lib/null-prototype-registry.d.ts.map +1 -0
  225. package/dist/lib/null-prototype-registry.js +11 -0
  226. package/dist/lib/null-prototype-registry.js.map +1 -0
  227. package/dist/lib/prisma-errors.d.ts +30 -32
  228. package/dist/lib/prisma-errors.d.ts.map +1 -1
  229. package/dist/lib/prisma-errors.js +86 -46
  230. package/dist/lib/prisma-errors.js.map +1 -1
  231. package/dist/lib/process-global.d.ts +23 -0
  232. package/dist/lib/process-global.d.ts.map +1 -0
  233. package/dist/lib/process-global.js +33 -0
  234. package/dist/lib/process-global.js.map +1 -0
  235. package/dist/lib/warn-once.d.ts +7 -0
  236. package/dist/lib/warn-once.d.ts.map +1 -0
  237. package/dist/lib/warn-once.js +13 -0
  238. package/dist/lib/warn-once.js.map +1 -0
  239. package/dist/mcp/advertise.d.ts +16 -0
  240. package/dist/mcp/advertise.d.ts.map +1 -0
  241. package/dist/mcp/advertise.js +25 -0
  242. package/dist/mcp/advertise.js.map +1 -0
  243. package/dist/mcp/arguments.d.ts +10 -0
  244. package/dist/mcp/arguments.d.ts.map +1 -0
  245. package/dist/mcp/arguments.js +143 -0
  246. package/dist/mcp/arguments.js.map +1 -0
  247. package/dist/mcp/field-schema.d.ts +50 -5
  248. package/dist/mcp/field-schema.d.ts.map +1 -1
  249. package/dist/mcp/field-schema.js +137 -14
  250. package/dist/mcp/field-schema.js.map +1 -1
  251. package/dist/mcp/handler.d.ts +16 -5
  252. package/dist/mcp/handler.d.ts.map +1 -1
  253. package/dist/mcp/handler.js +404 -126
  254. package/dist/mcp/handler.js.map +1 -1
  255. package/dist/mcp/index.d.ts +1 -0
  256. package/dist/mcp/index.d.ts.map +1 -1
  257. package/dist/mcp/index.js +1 -0
  258. package/dist/mcp/index.js.map +1 -1
  259. package/dist/mcp/projection.d.ts +42 -34
  260. package/dist/mcp/projection.d.ts.map +1 -1
  261. package/dist/mcp/projection.js +246 -200
  262. package/dist/mcp/projection.js.map +1 -1
  263. package/dist/mcp/tool-error.d.ts +8 -0
  264. package/dist/mcp/tool-error.d.ts.map +1 -0
  265. package/dist/mcp/tool-error.js +11 -0
  266. package/dist/mcp/tool-error.js.map +1 -0
  267. package/dist/mcp/types.d.ts +3 -2
  268. package/dist/mcp/types.d.ts.map +1 -1
  269. package/dist/mcp/where-id-boundary.d.ts +28 -0
  270. package/dist/mcp/where-id-boundary.d.ts.map +1 -0
  271. package/dist/mcp/where-id-boundary.js +187 -0
  272. package/dist/mcp/where-id-boundary.js.map +1 -0
  273. package/dist/origin.d.ts +147 -0
  274. package/dist/origin.d.ts.map +1 -0
  275. package/dist/origin.js +191 -0
  276. package/dist/origin.js.map +1 -0
  277. package/dist/query/relationship-options.d.ts +35 -6
  278. package/dist/query/relationship-options.d.ts.map +1 -1
  279. package/dist/query/relationship-options.js +33 -23
  280. package/dist/query/relationship-options.js.map +1 -1
  281. package/dist/secured/aggregate.d.ts +32 -0
  282. package/dist/secured/aggregate.d.ts.map +1 -0
  283. package/dist/secured/aggregate.js +31 -0
  284. package/dist/secured/aggregate.js.map +1 -0
  285. package/dist/secured/include.d.ts +320 -0
  286. package/dist/secured/include.d.ts.map +1 -0
  287. package/dist/secured/include.js +650 -0
  288. package/dist/secured/include.js.map +1 -0
  289. package/dist/secured/lock.d.ts +127 -0
  290. package/dist/secured/lock.d.ts.map +1 -0
  291. package/dist/secured/lock.js +275 -0
  292. package/dist/secured/lock.js.map +1 -0
  293. package/dist/secured/lower.d.ts +82 -0
  294. package/dist/secured/lower.d.ts.map +1 -0
  295. package/dist/secured/lower.js +162 -0
  296. package/dist/secured/lower.js.map +1 -0
  297. package/dist/secured/operators.d.ts +7 -0
  298. package/dist/secured/operators.d.ts.map +1 -0
  299. package/dist/secured/operators.js +18 -0
  300. package/dist/secured/operators.js.map +1 -0
  301. package/dist/secured/read.d.ts +208 -0
  302. package/dist/secured/read.d.ts.map +1 -0
  303. package/dist/secured/read.js +1245 -0
  304. package/dist/secured/read.js.map +1 -0
  305. package/dist/secured/select.d.ts +87 -0
  306. package/dist/secured/select.d.ts.map +1 -0
  307. package/dist/secured/select.js +250 -0
  308. package/dist/secured/select.js.map +1 -0
  309. package/dist/secured/vector.d.ts +58 -0
  310. package/dist/secured/vector.d.ts.map +1 -0
  311. package/dist/secured/vector.js +113 -0
  312. package/dist/secured/vector.js.map +1 -0
  313. package/dist/secured/vocabulary.d.ts +227 -0
  314. package/dist/secured/vocabulary.d.ts.map +1 -0
  315. package/dist/secured/vocabulary.js +578 -0
  316. package/dist/secured/vocabulary.js.map +1 -0
  317. package/dist/secured/write.d.ts +58 -0
  318. package/dist/secured/write.d.ts.map +1 -0
  319. package/dist/secured/write.js +87 -0
  320. package/dist/secured/write.js.map +1 -0
  321. package/dist/testing/context.d.ts +236 -0
  322. package/dist/testing/context.d.ts.map +1 -0
  323. package/dist/testing/context.js +457 -0
  324. package/dist/testing/context.js.map +1 -0
  325. package/dist/testing/escape.d.ts +83 -0
  326. package/dist/testing/escape.d.ts.map +1 -0
  327. package/dist/testing/escape.js +148 -0
  328. package/dist/testing/escape.js.map +1 -0
  329. package/dist/testing/extensions.d.ts +48 -0
  330. package/dist/testing/extensions.d.ts.map +1 -0
  331. package/dist/testing/extensions.js +107 -0
  332. package/dist/testing/extensions.js.map +1 -0
  333. package/dist/testing/index.d.ts +5 -0
  334. package/dist/testing/index.d.ts.map +1 -0
  335. package/dist/testing/index.js +11 -0
  336. package/dist/testing/index.js.map +1 -0
  337. package/dist/testing/plans.d.ts +64 -0
  338. package/dist/testing/plans.d.ts.map +1 -0
  339. package/dist/testing/plans.js +47 -0
  340. package/dist/testing/plans.js.map +1 -0
  341. package/dist/types/context.d.ts +110 -0
  342. package/dist/types/context.d.ts.map +1 -0
  343. package/dist/types/context.js +2 -0
  344. package/dist/types/context.js.map +1 -0
  345. package/dist/types/contract.d.ts +198 -0
  346. package/dist/types/contract.d.ts.map +1 -0
  347. package/dist/types/contract.js +2 -0
  348. package/dist/types/contract.js.map +1 -0
  349. package/dist/types/index.d.ts +6 -0
  350. package/dist/types/index.d.ts.map +1 -0
  351. package/dist/types/index.js +11 -0
  352. package/dist/types/index.js.map +1 -0
  353. package/dist/types/inputs.d.ts +83 -0
  354. package/dist/types/inputs.d.ts.map +1 -0
  355. package/dist/types/inputs.js +2 -0
  356. package/dist/types/inputs.js.map +1 -0
  357. package/dist/types/rows.d.ts +76 -0
  358. package/dist/types/rows.d.ts.map +1 -0
  359. package/dist/types/rows.js +2 -0
  360. package/dist/types/rows.js.map +1 -0
  361. package/dist/types/secured-list.d.ts +396 -0
  362. package/dist/types/secured-list.d.ts.map +1 -0
  363. package/dist/types/secured-list.js +2 -0
  364. package/dist/types/secured-list.js.map +1 -0
  365. package/dist/unsafe.d.ts +162 -0
  366. package/dist/unsafe.d.ts.map +1 -0
  367. package/dist/unsafe.js +177 -0
  368. package/dist/unsafe.js.map +1 -0
  369. package/dist/validation/config-refusal.d.ts +16 -0
  370. package/dist/validation/config-refusal.d.ts.map +1 -0
  371. package/dist/validation/config-refusal.js +2 -0
  372. package/dist/validation/config-refusal.js.map +1 -0
  373. package/dist/validation/database-config.d.ts +19 -0
  374. package/dist/validation/database-config.d.ts.map +1 -0
  375. package/dist/validation/database-config.js +221 -0
  376. package/dist/validation/database-config.js.map +1 -0
  377. package/dist/validation/default-value.d.ts +21 -0
  378. package/dist/validation/default-value.d.ts.map +1 -0
  379. package/dist/validation/default-value.js +72 -0
  380. package/dist/validation/default-value.js.map +1 -0
  381. package/dist/validation/extension-packs.d.ts +11 -0
  382. package/dist/validation/extension-packs.d.ts.map +1 -0
  383. package/dist/validation/extension-packs.js +53 -0
  384. package/dist/validation/extension-packs.js.map +1 -0
  385. package/dist/validation/field-config.d.ts +35 -21
  386. package/dist/validation/field-config.d.ts.map +1 -1
  387. package/dist/validation/field-config.js +51 -41
  388. package/dist/validation/field-config.js.map +1 -1
  389. package/dist/validation/field-names.d.ts +15 -0
  390. package/dist/validation/field-names.d.ts.map +1 -0
  391. package/dist/validation/field-names.js +155 -0
  392. package/dist/validation/field-names.js.map +1 -0
  393. package/dist/validation/identifier-names.d.ts +4 -0
  394. package/dist/validation/identifier-names.d.ts.map +1 -0
  395. package/dist/validation/identifier-names.js +39 -0
  396. package/dist/validation/identifier-names.js.map +1 -0
  397. package/dist/validation/needs-closure.d.ts +20 -30
  398. package/dist/validation/needs-closure.d.ts.map +1 -1
  399. package/dist/validation/needs-closure.js +29 -105
  400. package/dist/validation/needs-closure.js.map +1 -1
  401. package/dist/validation/relations.d.ts +17 -0
  402. package/dist/validation/relations.d.ts.map +1 -0
  403. package/dist/validation/relations.js +268 -0
  404. package/dist/validation/relations.js.map +1 -0
  405. package/dist/validation/schema.d.ts.map +1 -1
  406. package/dist/validation/schema.js +1 -3
  407. package/dist/validation/schema.js.map +1 -1
  408. package/dist/where/like.d.ts +32 -0
  409. package/dist/where/like.d.ts.map +1 -0
  410. package/dist/where/like.js +42 -0
  411. package/dist/where/like.js.map +1 -0
  412. package/package.json +70 -8
  413. package/.turbo/turbo-build.log +0 -4
  414. package/CLAUDE.md +0 -609
  415. package/dist/access/access-filter.d.ts +0 -241
  416. package/dist/access/access-filter.d.ts.map +0 -1
  417. package/dist/access/access-filter.js +0 -692
  418. package/dist/access/access-filter.js.map +0 -1
  419. package/dist/access/access-filter.test.d.ts +0 -2
  420. package/dist/access/access-filter.test.d.ts.map +0 -1
  421. package/dist/access/access-filter.test.js +0 -1256
  422. package/dist/access/access-filter.test.js.map +0 -1
  423. package/dist/access/declared-dependencies.test.d.ts +0 -2
  424. package/dist/access/declared-dependencies.test.d.ts.map +0 -1
  425. package/dist/access/declared-dependencies.test.js +0 -226
  426. package/dist/access/declared-dependencies.test.js.map +0 -1
  427. package/dist/access/denied-relation-visibility.test.d.ts +0 -2
  428. package/dist/access/denied-relation-visibility.test.d.ts.map +0 -1
  429. package/dist/access/denied-relation-visibility.test.js +0 -114
  430. package/dist/access/denied-relation-visibility.test.js.map +0 -1
  431. package/dist/access/engine.test.d.ts +0 -2
  432. package/dist/access/engine.test.d.ts.map +0 -1
  433. package/dist/access/engine.test.js +0 -56
  434. package/dist/access/engine.test.js.map +0 -1
  435. package/dist/access/field-access.test.d.ts +0 -2
  436. package/dist/access/field-access.test.d.ts.map +0 -1
  437. package/dist/access/field-access.test.js +0 -635
  438. package/dist/access/field-access.test.js.map +0 -1
  439. package/dist/access/multi-column-read-write.test.d.ts +0 -2
  440. package/dist/access/multi-column-read-write.test.d.ts.map +0 -1
  441. package/dist/access/multi-column-read-write.test.js +0 -183
  442. package/dist/access/multi-column-read-write.test.js.map +0 -1
  443. package/dist/access/relationship-count.d.ts +0 -98
  444. package/dist/access/relationship-count.d.ts.map +0 -1
  445. package/dist/access/relationship-count.js +0 -262
  446. package/dist/access/relationship-count.js.map +0 -1
  447. package/dist/access/relationship-count.test.d.ts +0 -2
  448. package/dist/access/relationship-count.test.d.ts.map +0 -1
  449. package/dist/access/relationship-count.test.js +0 -247
  450. package/dist/access/relationship-count.test.js.map +0 -1
  451. package/dist/access/relationship-label-filter.d.ts +0 -45
  452. package/dist/access/relationship-label-filter.d.ts.map +0 -1
  453. package/dist/access/relationship-label-filter.js +0 -22
  454. package/dist/access/relationship-label-filter.js.map +0 -1
  455. package/dist/access/relationship-label-filter.test.d.ts +0 -2
  456. package/dist/access/relationship-label-filter.test.d.ts.map +0 -1
  457. package/dist/access/relationship-label-filter.test.js +0 -89
  458. package/dist/access/relationship-label-filter.test.js.map +0 -1
  459. package/dist/access/synthetic-include-read.test.d.ts +0 -2
  460. package/dist/access/synthetic-include-read.test.d.ts.map +0 -1
  461. package/dist/access/synthetic-include-read.test.js +0 -121
  462. package/dist/access/synthetic-include-read.test.js.map +0 -1
  463. package/dist/context/nested-operations.d.ts +0 -74
  464. package/dist/context/nested-operations.d.ts.map +0 -1
  465. package/dist/context/nested-operations.js +0 -847
  466. package/dist/context/nested-operations.js.map +0 -1
  467. package/dist/fields/calendar-day.test.d.ts +0 -2
  468. package/dist/fields/calendar-day.test.d.ts.map +0 -1
  469. package/dist/fields/calendar-day.test.js +0 -246
  470. package/dist/fields/calendar-day.test.js.map +0 -1
  471. package/dist/fields/format-prisma-default.d.ts +0 -35
  472. package/dist/fields/format-prisma-default.d.ts.map +0 -1
  473. package/dist/fields/format-prisma-default.js +0 -49
  474. package/dist/fields/format-prisma-default.js.map +0 -1
  475. package/dist/fields/format-prisma-default.test.d.ts +0 -2
  476. package/dist/fields/format-prisma-default.test.d.ts.map +0 -1
  477. package/dist/fields/format-prisma-default.test.js +0 -54
  478. package/dist/fields/format-prisma-default.test.js.map +0 -1
  479. package/dist/fields/relationship-foreign-key.test.d.ts +0 -2
  480. package/dist/fields/relationship-foreign-key.test.d.ts.map +0 -1
  481. package/dist/fields/relationship-foreign-key.test.js +0 -18
  482. package/dist/fields/relationship-foreign-key.test.js.map +0 -1
  483. package/dist/fields/select.test.d.ts +0 -2
  484. package/dist/fields/select.test.d.ts.map +0 -1
  485. package/dist/fields/select.test.js +0 -279
  486. package/dist/fields/select.test.js.map +0 -1
  487. package/dist/fields/text-keystone-compat.test.d.ts +0 -2
  488. package/dist/fields/text-keystone-compat.test.d.ts.map +0 -1
  489. package/dist/fields/text-keystone-compat.test.js +0 -93
  490. package/dist/fields/text-keystone-compat.test.js.map +0 -1
  491. package/dist/filter/filter.test.d.ts +0 -2
  492. package/dist/filter/filter.test.d.ts.map +0 -1
  493. package/dist/filter/filter.test.js +0 -431
  494. package/dist/filter/filter.test.js.map +0 -1
  495. package/dist/filter/serialize.test.d.ts +0 -2
  496. package/dist/filter/serialize.test.d.ts.map +0 -1
  497. package/dist/filter/serialize.test.js +0 -83
  498. package/dist/filter/serialize.test.js.map +0 -1
  499. package/dist/index.test.d.ts +0 -2
  500. package/dist/index.test.d.ts.map +0 -1
  501. package/dist/index.test.js +0 -33
  502. package/dist/index.test.js.map +0 -1
  503. package/dist/lib/case-utils.test.d.ts +0 -2
  504. package/dist/lib/case-utils.test.d.ts.map +0 -1
  505. package/dist/lib/case-utils.test.js +0 -123
  506. package/dist/lib/case-utils.test.js.map +0 -1
  507. package/dist/query/index.d.ts +0 -127
  508. package/dist/query/index.d.ts.map +0 -1
  509. package/dist/query/index.js +0 -179
  510. package/dist/query/index.js.map +0 -1
  511. package/dist/query/index.test.d.ts +0 -2
  512. package/dist/query/index.test.d.ts.map +0 -1
  513. package/dist/query/index.test.js +0 -632
  514. package/dist/query/index.test.js.map +0 -1
  515. package/dist/query/relationship-options.test.d.ts +0 -2
  516. package/dist/query/relationship-options.test.d.ts.map +0 -1
  517. package/dist/query/relationship-options.test.js +0 -150
  518. package/dist/query/relationship-options.test.js.map +0 -1
  519. package/dist/validation/field-config.test.d.ts +0 -2
  520. package/dist/validation/field-config.test.d.ts.map +0 -1
  521. package/dist/validation/field-config.test.js +0 -159
  522. package/dist/validation/field-config.test.js.map +0 -1
  523. package/dist/validation/schema.test.d.ts +0 -2
  524. package/dist/validation/schema.test.d.ts.map +0 -1
  525. package/dist/validation/schema.test.js +0 -409
  526. package/dist/validation/schema.test.js.map +0 -1
  527. package/docs/type-distribution-fix.md +0 -136
  528. package/src/access/access-filter.test.ts +0 -1919
  529. package/src/access/access-filter.ts +0 -1041
  530. package/src/access/declared-dependencies.test.ts +0 -277
  531. package/src/access/declared-dependencies.ts +0 -220
  532. package/src/access/denied-relation-visibility.test.ts +0 -173
  533. package/src/access/depth-limits.ts +0 -27
  534. package/src/access/engine.test.ts +0 -67
  535. package/src/access/engine.ts +0 -193
  536. package/src/access/errors.ts +0 -242
  537. package/src/access/field-access.test.ts +0 -792
  538. package/src/access/field-access.ts +0 -353
  539. package/src/access/field-transforms.ts +0 -68
  540. package/src/access/field-visibility.ts +0 -569
  541. package/src/access/index.ts +0 -82
  542. package/src/access/multi-column-read-write.test.ts +0 -305
  543. package/src/access/query-validation.ts +0 -486
  544. package/src/access/relationship-count.test.ts +0 -344
  545. package/src/access/relationship-count.ts +0 -346
  546. package/src/access/relationship-label-filter.test.ts +0 -128
  547. package/src/access/relationship-label-filter.ts +0 -63
  548. package/src/access/synthetic-include-read.test.ts +0 -179
  549. package/src/access/transaction-registry.ts +0 -58
  550. package/src/access/types.ts +0 -391
  551. package/src/config/index.ts +0 -177
  552. package/src/config/label.ts +0 -51
  553. package/src/config/nav-count.ts +0 -77
  554. package/src/config/plugin-engine.ts +0 -261
  555. package/src/config/types.ts +0 -3270
  556. package/src/context/apply-defaults.ts +0 -47
  557. package/src/context/hook-pipeline.ts +0 -137
  558. package/src/context/index.ts +0 -1737
  559. package/src/context/nested-operations.ts +0 -1470
  560. package/src/context/transaction-boundary.ts +0 -485
  561. package/src/context/write-pipeline.ts +0 -732
  562. package/src/extend.ts +0 -28
  563. package/src/fields/calendar-day.test.ts +0 -291
  564. package/src/fields/format-prisma-default.test.ts +0 -64
  565. package/src/fields/format-prisma-default.ts +0 -64
  566. package/src/fields/index.ts +0 -1901
  567. package/src/fields/relationship-foreign-key.test.ts +0 -29
  568. package/src/fields/select.test.ts +0 -336
  569. package/src/fields/text-keystone-compat.test.ts +0 -126
  570. package/src/filter/collect.ts +0 -108
  571. package/src/filter/filter.test.ts +0 -538
  572. package/src/filter/index.ts +0 -26
  573. package/src/filter/map.ts +0 -63
  574. package/src/filter/parse.ts +0 -99
  575. package/src/filter/serialize.test.ts +0 -115
  576. package/src/filter/serialize.ts +0 -73
  577. package/src/filter/types.ts +0 -120
  578. package/src/hooks/index.ts +0 -752
  579. package/src/index.test.ts +0 -50
  580. package/src/index.ts +0 -192
  581. package/src/internal.ts +0 -61
  582. package/src/lib/case-utils.test.ts +0 -159
  583. package/src/lib/case-utils.ts +0 -68
  584. package/src/lib/prisma-errors.ts +0 -86
  585. package/src/mcp/constants.ts +0 -24
  586. package/src/mcp/field-schema.ts +0 -84
  587. package/src/mcp/handler.ts +0 -633
  588. package/src/mcp/index.ts +0 -7
  589. package/src/mcp/projection.ts +0 -497
  590. package/src/mcp/types.ts +0 -18
  591. package/src/query/index.test.ts +0 -830
  592. package/src/query/index.ts +0 -352
  593. package/src/query/relationship-options.test.ts +0 -194
  594. package/src/query/relationship-options.ts +0 -78
  595. package/src/utils/password.ts +0 -80
  596. package/src/validation/field-config.test.ts +0 -199
  597. package/src/validation/field-config.ts +0 -139
  598. package/src/validation/needs-closure.ts +0 -188
  599. package/src/validation/schema.test.ts +0 -487
  600. package/src/validation/schema.ts +0 -51
  601. package/tests/access-relationships.test.ts +0 -646
  602. package/tests/access.test.ts +0 -590
  603. package/tests/apply-defaults.test.ts +0 -119
  604. package/tests/bare-read-scalars.test.ts +0 -147
  605. package/tests/computed-field-selective-evaluation.test.ts +0 -418
  606. package/tests/config.test.ts +0 -242
  607. package/tests/context.test.ts +0 -3146
  608. package/tests/default-value-create.test.ts +0 -299
  609. package/tests/field-hooks.test.ts +0 -410
  610. package/tests/field-types.test.ts +0 -1291
  611. package/tests/hook-context-secured.test.ts +0 -424
  612. package/tests/hook-pipeline.test.ts +0 -233
  613. package/tests/hooks.test.ts +0 -481
  614. package/tests/interactive-transaction.test.ts +0 -444
  615. package/tests/label.test.ts +0 -135
  616. package/tests/mcp-fields-projection-access.test.ts +0 -250
  617. package/tests/mcp-handler.test.ts +0 -1411
  618. package/tests/multi-column-validation-ordering.test.ts +0 -305
  619. package/tests/nav-count.test.ts +0 -189
  620. package/tests/needs-declared-dependencies.test.ts +0 -503
  621. package/tests/nested-access-and-hooks.test.ts +0 -2566
  622. package/tests/nested-operation-registry.test.ts +0 -317
  623. package/tests/nested-write-hooks.test.ts +0 -864
  624. package/tests/nested-write-synthetic-relation.test.ts +0 -437
  625. package/tests/password-type-distribution.test.ts +0 -154
  626. package/tests/password-types.test.ts +0 -174
  627. package/tests/password.test.ts +0 -263
  628. package/tests/plugin-engine.test.ts +0 -1155
  629. package/tests/prisma-errors.test.ts +0 -141
  630. package/tests/resolve-chain.test.ts +0 -411
  631. package/tests/singleton.test.ts +0 -421
  632. package/tests/sudo.test.ts +0 -676
  633. package/tests/to-one-include-access-filter.test.ts +0 -172
  634. package/tests/transaction-boundary-hooks.test.ts +0 -710
  635. package/tests/transaction-boundary-outermost.test.ts +0 -530
  636. package/tests/virtual-fields.test.ts +0 -421
  637. package/tests/with-session.test.ts +0 -243
  638. package/tests/write-pipeline.test.ts +0 -617
  639. package/tsconfig.json +0 -12
  640. package/tsconfig.tsbuildinfo +0 -1
  641. package/vitest.config.ts +0 -69
@@ -1,38 +1,63 @@
1
- import { checkAccess, checkCreateAccess, mergeFilters, filterReadableFields, filterWritableFields, } from '../access/index.js';
1
+ import { assertAccessFilterConstrains, checkAccess, checkCreateAccess, filterWritableFields, } from '../access/index.js';
2
2
  import { executeValidate, executeBeforeOperation, executeAfterOperation, executeFieldValidateHooks, executeFieldBeforeOperationHooks, executeFieldAfterOperationHooks, ValidationError, } from '../hooks/index.js';
3
+ import { countRows, deleteFirst, firstMatching, identityPredicate, insertRow, updateFirst, whereCombinators, writeCollection, } from '../secured/write.js';
4
+ import { visibleWrittenRow, writtenRowQueryable } from '../secured/read.js';
5
+ import { resolveWhere } from '../secured/vocabulary.js';
3
6
  import { hookPipeline } from './hook-pipeline.js';
4
- import { processNestedOperations, runAfterTasks } from './nested-operations.js';
7
+ import { lowerRelationInput, refuseNestedRelationInput, snapshotCallerInput, } from './relationship-input.js';
5
8
  import { enumerateInvolvedLists, runWithTransactionBoundary } from './transaction-boundary.js';
6
- import { TransactionRegistry } from '../access/transaction-registry.js';
7
- import { getDbKey } from '../lib/case-utils.js';
9
+ import { TransactionRegistry, TransactionRolledBackError } from '../access/transaction-registry.js';
10
+ import { warnOnce } from '../lib/warn-once.js';
11
+ import { RowLockIdentityError, RowLockLaneUnavailableError, } from '../secured/lock.js';
8
12
  // NOTE: `index.ts` imports from this module too — this is an intentional cyclic
9
- // dependency. It is safe because `getContext` is only INVOKED at write time
10
- // (never during module evaluation), so by the time it runs the export is fully
11
- // initialised.
12
- import { getContext } from './index.js';
13
+ // dependency. It is safe because `buildDbDelegate` is only INVOKED at write
14
+ // time (never during module evaluation), so by the time it runs the export is
15
+ // fully initialised.
16
+ import { buildDbDelegate } from './index.js';
13
17
  /**
14
- * Resolve the dynamic Prisma model for a list. Model names are generated at
15
- * runtime, so the cast is unavoidable — kept localized here (mirrors
16
- * `context/index.ts`).
18
+ * Run `fn` inside ONE transaction (ADR-0010).
19
+ *
20
+ * With no `opener`, `fn` runs directly against the handle it was given. Hook
21
+ * ordering and arguments are identical either way, but only a real transaction
22
+ * carries the rollback guarantee.
23
+ *
24
+ * Known limits — the absent opener does not by itself mean an enclosing
25
+ * transaction is open. It covers two shapes and cannot tell them apart:
26
+ * a Joined write, the Unowned join of ADR-0028, whose context was rebound to a
27
+ * transaction someone else opened; and a context assembled without a Prisma 8
28
+ * client at all — a hand-built ORM double — where nothing is open around the
29
+ * write and it simply has no rollback guarantee. The signal that a write is
30
+ * joined is `existingOwner` in {@link runWritePipeline}, not this parameter.
17
31
  */
18
- function getModel(prisma, listName) {
19
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- model names are generated at runtime
20
- return prisma[getDbKey(listName)];
32
+ async function runInTransaction(opener, ormHandle, fn) {
33
+ if (opener === undefined)
34
+ return fn(ormHandle, undefined);
35
+ return opener((opened) => fn(opened.ormHandle, opened.rowLock));
21
36
  }
22
37
  /**
23
- * Run `fn` inside ONE interactive transaction, used as the persistence target
24
- * for the parent and all nested writes (ADR-0010).
25
- *
26
- * Without `$transaction` (e.g. a test mock), `fn` runs directly against the
27
- * client — hook ordering and arguments are identical, but only a real
28
- * transaction provides the rollback guarantee.
38
+ * Thrown inside the write's transaction when the write ends as `null` after its
39
+ * hooks already ran, so their writes roll back with it. Caught at the
40
+ * transaction boundary and answered as `null`; never reaches the caller.
29
41
  */
30
- async function runInTransaction(prisma, fn) {
31
- const client = prisma;
32
- if (typeof client.$transaction === 'function') {
33
- return (await client.$transaction(async (tx) => fn(tx)));
42
+ class WriteAbandonedSignal extends Error {
43
+ constructor() {
44
+ super('The write produced no row after its hooks ran.');
45
+ this.name = 'WriteAbandonedSignal';
34
46
  }
35
- return fn(prisma);
47
+ }
48
+ /**
49
+ * Warn once per (list, operation) when a write has neither an opener of its
50
+ * own nor an enclosing transaction to join — a context built without
51
+ * `getContext`'s `client` argument (#1273). `context.transaction()` refuses
52
+ * this shape outright (`TransactionUnavailableError`); a plain `context.db`
53
+ * write has no such terminal to refuse from, so it still runs — directly
54
+ * against the handle, with no rollback guarantee — but no longer silently.
55
+ */
56
+ function warnNoTransactionCapability(listName, operation) {
57
+ warnOnce(`no-transaction:${listName}.${operation}`, `[@opensaas/stack-core] context.db.${listName}.${operation}() is running with no ` +
58
+ `transaction and no rollback guarantee: this context was built without getContext's ` +
59
+ `\`client\` argument. Pass the Prisma 8 client through (the generated context and ` +
60
+ `requireOrmHandle(config, client.orm) both do) to restore it.`);
36
61
  }
37
62
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
38
63
  function isSingletonList(listConfig) {
@@ -49,10 +74,10 @@ function isSingletonList(listConfig) {
49
74
  * - sudo mode skips access checks and writable-field filtering.
50
75
  * - `afterOperation` receives `originalItem` for update/delete (undefined for
51
76
  * create).
52
- * - delete returns the deleted row as-is (no Field Visibility pass).
53
77
  */
54
78
  export async function runWritePipeline(args) {
55
- const { prisma, listName, listConfig, context, config, inputData, strategy } = args;
79
+ const { ormHandle, listName, listConfig, context, config, inputData, strategy } = args;
80
+ const ops = await whereCombinators();
56
81
  // ── Pre-transaction access gate (#590) ──────────────────────────────────────
57
82
  // Resolves the top-level target + access OUTSIDE the transaction so a denied
58
83
  // write short-circuits to `null` WITHOUT firing beforeTransaction/
@@ -60,107 +85,250 @@ export async function runWritePipeline(args) {
60
85
  // boundary hooks must not run. The result feeds `preResolvedTarget` and is
61
86
  // REUSED inside the transaction rather than re-resolved, keeping the target
62
87
  // read exactly once (#569).
63
- const gate = await strategy.resolveTarget(getModel(prisma, listName));
64
- if (gate.status === 'denied') {
65
- return null;
88
+ let gate;
89
+ try {
90
+ gate = await strategy.resolveTarget(writeCollection(ormHandle, listName), ops, context);
91
+ if (gate.status === 'denied') {
92
+ return null;
93
+ }
94
+ // A payload-shape refusal, after the access gate so a denied caller learns
95
+ // nothing about this list's fields from it (ADR-0031).
96
+ refuseNestedRelationInput(listName, listConfig, config, inputData);
97
+ }
98
+ catch (err) {
99
+ context._transactionOwner?.poison(err);
100
+ throw err;
66
101
  }
67
- // ── Enumerate involved lists from the input tree (no DB reads) ──────────────
68
102
  const involvedLists = enumerateInvolvedLists({
69
103
  listName,
70
104
  listConfig,
71
105
  operation: strategy.operation,
72
106
  inputData,
73
- topLevelOriginalItem: gate.originalItem,
74
- config,
107
+ originalItem: gate.originalItem,
75
108
  });
76
109
  // ── Transaction ownership for the transaction-boundary hooks (ADR-0028) ────
77
110
  // A context carrying `_transactionOwner` is JOINING an enclosing transaction
78
- // it did not open — defer to that owner even if `prisma` here still exposes
79
- // `$transaction`. Otherwise this write becomes the owner: the registry every
80
- // joined write below it enqueues into.
111
+ // it did not open — defer to that owner even if this context could open one.
112
+ // Otherwise this write becomes the owner: the registry every joined write
113
+ // below it enqueues into.
81
114
  const existingOwner = context._transactionOwner;
82
- const opensOwnTransaction = !existingOwner && typeof prisma.$transaction === 'function';
83
- const ownedRegistry = opensOwnTransaction ? new TransactionRegistry() : undefined;
115
+ const opener = existingOwner ? undefined : context._transactionOpener;
116
+ // Neither joining an enclosing transaction nor able to open one of its own —
117
+ // the silently non-transactional shape #1273 exists to flag (see
118
+ // `warnNoTransactionCapability`).
119
+ if (existingOwner === undefined && opener === undefined) {
120
+ warnNoTransactionCapability(listName, strategy.operation);
121
+ }
122
+ const ownedRegistry = opener ? new TransactionRegistry() : undefined;
84
123
  const transactionOwnerForBody = existingOwner ?? ownedRegistry;
85
124
  // ── Bracket the transaction with beforeTransaction/afterTransaction (#590) ──
86
125
  // afterTransaction fires when the transaction settles, deferred to the owner
87
- // for a joined write (ADR-0028, symmetric-bracket rule).
126
+ // for a joined write (ADR-0028, symmetric-bracket rule). Its context is
127
+ // rebound to the BASE client (ADR-0028, issue #1348): `context` itself is
128
+ // already transaction-bound on a joined write (it is the context the caller
129
+ // handed to `context.db.*`, rebound by an enclosing
130
+ // `bindContextToTransaction`/`context.transaction()`), and a compensating
131
+ // write must be reachable after that transaction closes. `beforeTransaction`
132
+ // keeps running through `context` as given — see `runWithTransactionBoundary`'s
133
+ // own param doc for why that one is deliberately left alone.
88
134
  return runWithTransactionBoundary({
135
+ config,
89
136
  involvedLists,
90
137
  context,
138
+ afterTransactionContext: resolveAfterTransactionContext(context, config),
91
139
  joinedOwner: existingOwner,
92
140
  ownedRegistry,
93
- runTransaction: () =>
94
- // ADR-0010: parent + nested writes share `tx` as their persistence target.
95
- runInTransaction(prisma, (tx) => runWriteInTransaction({
96
- ...args,
97
- prisma: tx,
98
- // Reuse the pre-transaction target resolution (#569 call-count semantics).
99
- preResolvedTarget: gate,
100
- // Rebind context.db/prisma to `tx` (ADR-0010 atomicity) and carry the
101
- // transaction owner (ADR-0028) — see bindContextToTransaction below.
102
- context: bindContextToTransaction(args, tx, transactionOwnerForBody),
103
- })),
141
+ runTransaction: async () => {
142
+ try {
143
+ return await runInTransaction(opener, ormHandle, async (tx, openedLock) => {
144
+ const written = await runWriteInTransaction({
145
+ ...args,
146
+ ormHandle: tx,
147
+ // Reuse the pre-transaction target resolution (#569 call-count semantics).
148
+ preResolvedTarget: gate,
149
+ onTargetLocked: (lockedItem) => {
150
+ for (const involved of involvedLists)
151
+ involved.originalItem = lockedItem;
152
+ },
153
+ // Rebind context.db/ormHandle to `tx` (ADR-0010 atomicity) and carry the
154
+ // transaction owner (ADR-0028) — see bindContextToTransaction below.
155
+ context: bindContextToTransaction(args, tx, transactionOwnerForBody, openedLock),
156
+ }, ops);
157
+ if (ownedRegistry?.isPoisoned) {
158
+ throw new TransactionRolledBackError({ cause: ownedRegistry.poisonCause });
159
+ }
160
+ return written;
161
+ });
162
+ }
163
+ catch (error) {
164
+ if (!(error instanceof WriteAbandonedSignal))
165
+ throw error;
166
+ (existingOwner ?? ownedRegistry)?.poison(error);
167
+ return null;
168
+ }
169
+ },
104
170
  });
105
171
  }
106
172
  /**
107
- * Build the full {@link StackContext} a hook's `context` is (issue #1176):
108
- * bound to the transaction client `tx`, so a `context.db` write a hook
109
- * performs runs inside — and rolls back with — this write's transaction
110
- * (ADR-0010), and carrying `sudo()`/`withSession()`/`transaction()` so a hook
111
- * can reach an elevated or substituted read/write that stays on the SAME
112
- * transaction client rather than escaping to the base one.
173
+ * Take the row lock on an update/delete target, then resolve the target again
174
+ * under it so `originalItem`, item-based access rules and the Access Filter all
175
+ * see the row as it is while no one else can change it (ADR-0078). A row that is
176
+ * gone, or no longer in scope, resolves to `denied`.
177
+ */
178
+ async function lockTarget(args, collection, ops, gated) {
179
+ const lane = args.context._rowLock;
180
+ if (args.strategy.operation === 'create' || lane === undefined || gated.status !== 'ok') {
181
+ return gated;
182
+ }
183
+ const { originalItem } = gated;
184
+ if (originalItem === undefined)
185
+ return gated;
186
+ let identity;
187
+ try {
188
+ identity = lane.identity(args.listName);
189
+ }
190
+ catch (error) {
191
+ if (error instanceof RowLockIdentityError || error instanceof RowLockLaneUnavailableError) {
192
+ return gated;
193
+ }
194
+ throw error;
195
+ }
196
+ const key = originalItem[identity.column];
197
+ if (typeof key !== 'string' && typeof key !== 'number')
198
+ return gated;
199
+ const held = await lane.lock(args.listName, identity, [key]);
200
+ if (held.length === 0)
201
+ return { status: 'denied' };
202
+ return args.strategy.resolveTarget(collection, ops, args.context);
203
+ }
204
+ /**
205
+ * Build an {@link AccessContext} whose `db`/`ormHandle` target the transaction
206
+ * client `tx`, so a `context.db` write a hook performs runs inside — and rolls
207
+ * back with — this write's transaction (ADR-0010).
208
+ *
209
+ * Spreads the request context and overrides only what a transaction rebind
210
+ * must change, so a member added to `AccessContext` later is carried by
211
+ * default instead of by remembering to list it here (#1345).
113
212
  *
114
- * Goes through the same {@link getContext} factory `context.transaction()`
115
- * already rebuilds through (ADR-0012), rather than hand-assembling a plain
116
- * object literal — reusing the request context's `session`, `storage`,
117
- * `_isSudo`, `plugins` (as `_sharedPlugins`, so plugin `runtime()` is NOT
118
- * re-executed on the rebind), and `_resolveOutputChain` (so a write issued
119
- * from inside a `resolveOutput` hook keeps that hook's cycle-guard chain,
120
- * ADR-0023) as-is.
213
+ * The access-controlled `db` delegates capture their Prisma client at
214
+ * construction, so swapping `context.ormHandle` alone would not rebind `db` —
215
+ * we rebuild the delegates against `tx` via {@link buildDbDelegate}. Plugin
216
+ * runtimes are NOT re-executed.
121
217
  *
122
218
  * `transactionOwner` (ADR-0028) is carried onto the rebuilt context so a hook's
123
- * own `context.db` write — and any write reached through its `sudo()`/
124
- * `withSession()` — defers its transaction-boundary bracket to that owner
125
- * instead of firing eagerly; `context.transaction()` called from a hook joins
126
- * this same owner rather than opening a nested transaction, for the same
127
- * reason.
219
+ * own `context.db` write defers its transaction-boundary bracket to that owner
220
+ * instead of firing eagerly.
221
+ *
222
+ * `_baseContext` (issue #1348) is set explicitly rather than left to the
223
+ * spread: `context` IS the base when it carries none of its own, so a
224
+ * transaction rebind one level deep must record `context` itself as the
225
+ * ancestor a further-nested joined write's `afterTransaction` resolves
226
+ * against (see {@link resolveAfterTransactionContext}) — the spread alone
227
+ * would just carry `undefined` forward.
228
+ *
229
+ * `_transactionOpener` is explicitly cleared: a context rebound to a
230
+ * transaction runs directly against the handle it was given, never opening a
231
+ * second one of its own.
232
+ *
233
+ * The lock lane (ADR-0047) is the one bound to `tx`: the lane of the transaction
234
+ * this write opened, or — on a joined write, where `tx` is the handle the
235
+ * context already had — the enclosing owner's.
128
236
  */
129
- function bindContextToTransaction(args, tx, transactionOwner) {
237
+ function bindContextToTransaction(args, tx, transactionOwner, openedLock) {
130
238
  const { context, config } = args;
131
- return getContext(config, tx, context.session, context.storage, context._isSudo, context.plugins, transactionOwner, context._resolveOutputChain);
239
+ const txContext = {
240
+ ...context,
241
+ ormHandle: tx,
242
+ _transactionOwner: transactionOwner,
243
+ _transactionOpener: undefined,
244
+ _rowLock: openedLock ?? (tx === context.ormHandle ? context._rowLock : undefined),
245
+ _config: config,
246
+ _baseContext: context._baseContext ?? context,
247
+ };
248
+ // Rebuild `db` against `tx`, referencing `txContext` itself so hooks reached
249
+ // through it see the transactional context.
250
+ txContext.db = buildDbDelegate(config, tx, txContext);
251
+ return txContext;
252
+ }
253
+ /**
254
+ * The context a write's `afterTransaction` bracket actually runs with
255
+ * (ADR-0028, issue #1348). `context` unchanged when it already IS the base
256
+ * (`_baseContext` unset — the top-level path, bit-for-bit as before). On a
257
+ * joined write, rebuilds `db`/`ormHandle` against the ancestor `_baseContext`
258
+ * names — never a transaction client, which may already be closed by flush
259
+ * time — while otherwise spreading `context` AS GIVEN, so this write's own
260
+ * `session`/`_isSudo`/`plugins` survive: a write issued through
261
+ * `tx.sudo()`/`tx.withSession()` must keep that elevation for its own
262
+ * `afterTransaction`, not fall back to the pre-elevation context the
263
+ * enclosing transaction was originally opened with.
264
+ *
265
+ * Deliberately NOT used for `beforeTransaction` — see
266
+ * {@link runWithTransactionBoundary}'s own param doc for why that one keeps
267
+ * running through `context` as given.
268
+ */
269
+ function resolveAfterTransactionContext(context, config) {
270
+ const base = context._baseContext;
271
+ if (base === undefined)
272
+ return context;
273
+ const afterTransactionContext = {
274
+ ...context,
275
+ ormHandle: base.ormHandle,
276
+ _transactionOwner: undefined,
277
+ _transactionOpener: base._transactionOpener,
278
+ _rowLock: undefined,
279
+ _baseContext: undefined,
280
+ _config: config,
281
+ };
282
+ afterTransactionContext.db = buildDbDelegate(config, base.ormHandle, afterTransactionContext);
283
+ return afterTransactionContext;
132
284
  }
133
285
  /**
134
286
  * The body of one secured write, executed against the transaction client `tx`
135
- * (passed in as `args.prisma`). Returns `null` for the silent-failure cases and
287
+ * (passed in as `args.ormHandle`). Returns `null` for the silent-failure cases and
136
288
  * the Field-Visibility-filtered row otherwise. Any throw here propagates out of
137
289
  * `runInTransaction` and rolls the transaction back.
138
290
  */
139
- async function runWriteInTransaction(args) {
140
- const { listName, listConfig, prisma: tx, context, config, inputData, strategy } = args;
291
+ async function runWriteInTransaction(args, ops) {
292
+ const { listName, listConfig, ormHandle: tx, context, config, inputData, strategy } = args;
141
293
  const { operation } = strategy;
142
- const model = getModel(tx, listName);
294
+ const collection = writeCollection(tx, listName);
143
295
  // ── Phase 1: resolve target + operation-level access ──────────────────────
144
296
  // Reuses `preResolvedTarget` from the pre-transaction gate rather than
145
297
  // reading the target twice; falls back to resolving here when invoked
146
298
  // directly (e.g. a unit test) without that bracket.
147
- const resolution = args.preResolvedTarget ?? (await strategy.resolveTarget(model));
299
+ const gated = args.preResolvedTarget ?? (await strategy.resolveTarget(collection, ops, context));
300
+ const resolution = await lockTarget(args, collection, ops, gated);
148
301
  if (resolution.status === 'denied') {
302
+ if (gated.status === 'ok')
303
+ args.onTargetLocked?.(undefined);
149
304
  return null;
150
305
  }
151
- const originalItem = resolution.originalItem;
306
+ const { originalItem, scope } = resolution;
307
+ args.onTargetLocked?.(originalItem);
152
308
  // ── Delete path: skip input phases, run only validate/field-validate ────────
153
309
  if (!strategy.runInputPhases) {
154
- return runDeletePath({ listName, listConfig, context, originalItem, model, strategy });
310
+ return runDeletePath({
311
+ ormHandle: tx,
312
+ listName,
313
+ listConfig,
314
+ context,
315
+ config,
316
+ originalItem,
317
+ collection,
318
+ ops,
319
+ scope,
320
+ strategy,
321
+ });
155
322
  }
156
323
  // Only create/update reach here (delete short-circuited above); narrow so
157
324
  // field-hook helpers receive a 'create' | 'update' value.
158
325
  const writeOp = operation === 'create' ? 'create' : 'update';
159
326
  // `inputData` is always present here; `?? {}` is only a defensive fallback.
160
327
  const input = inputData ?? {};
328
+ const callerInput = snapshotCallerInput(input);
161
329
  // ── Phases 2–4: transform + validate span (Hook Pipeline glossary, CONTEXT.md) ──
162
330
  // THROWS `ValidationError` on any validation failure (never silent).
163
- const { resolvedData } = await hookPipeline.run({
331
+ const { resolvedData, defaultedFields } = await hookPipeline.run({
164
332
  operation: writeOp,
165
333
  listName,
166
334
  listConfig,
@@ -168,25 +336,37 @@ async function runWriteInTransaction(args) {
168
336
  item: originalItem,
169
337
  context,
170
338
  });
339
+ // The same payload-shape refusal, over what the hooks produced: a
340
+ // `resolveInput` that assembles a relation payload writes it into
341
+ // `resolvedData`, which the pre-transaction check could not see.
342
+ refuseNestedRelationInput(listName, listConfig, config, resolvedData);
171
343
  // ── Phase 5: filter writable fields (field-level access, skip if sudo) ──────
172
- const filteredData = await filterWritableFields(resolvedData, listConfig.fields, writeOp, {
344
+ const data = await filterWritableFields(resolvedData, listConfig.fields, writeOp, {
173
345
  session: context.session,
174
346
  item: originalItem,
175
347
  context: { ...context, _isSudo: context._isSudo },
176
- inputData: input,
348
+ inputData: callerInput,
349
+ listName,
350
+ config,
351
+ defaultedFields,
352
+ });
353
+ // ── Phase 5.5: relationship resolution (ADR-0050) ──────────────────────────
354
+ // `connect` becomes a foreign key once the reachability query says the caller
355
+ // may see that row, and `null` clears the same column. An unreachable target
356
+ // is the silent `null` every other denial is, before `beforeOperation` runs.
357
+ const linked = await lowerRelationInput({
177
358
  listName,
359
+ listConfig,
178
360
  config,
361
+ context,
362
+ ormHandle: tx,
363
+ ops,
364
+ data,
365
+ inputData: callerInput,
179
366
  });
180
- // ── Phase 5.5: process nested relationship operations ───────────────────────
181
- // Runs each nested record's resolveInput/validate/field-rules AND its
182
- // `beforeOperation` inside this transaction, returning deferred
183
- // `afterOperation` tasks plus the relation fields to `include` so those tasks
184
- // can recover their persisted `item`.
185
- const { data, afterTasks, includeFields } = await processNestedOperations(filteredData, listConfig.fields, config, { ...context, prisma: tx }, writeOp, listName, originalItem,
186
- // Same `inputData` Phase 5's filterWritableFields used, so the connect-site
187
- // owning-field gate evaluates identically and can't diverge into a
188
- // spurious connect denial (#588).
189
- input);
367
+ if (linked.status === 'unreachable')
368
+ throw new WriteAbandonedSignal();
369
+ const writeData = linked.data;
190
370
  // ── Phase 6: field-level beforeOperation (side effects only) ────────────────
191
371
  await executeFieldBeforeOperationHooks(input, resolvedData, listConfig.fields, writeOp, context, listName, originalItem);
192
372
  // ── Phase 7: list-level beforeOperation ─────────────────────────────────────
@@ -207,10 +387,15 @@ async function runWriteInTransaction(args) {
207
387
  context,
208
388
  });
209
389
  // ── Phase 8: DB write ───────────────────────────────────────────────────────
210
- // `include` returns the nested relations with deferred `afterOperation`
211
- // tasks so they can recover their persisted `item`.
212
- const include = buildIncludeFromFields(includeFields);
213
- const item = await strategy.persist(model, data, include);
390
+ const item = await strategy.persist(collection, ops, scope, writeData);
391
+ // The scope matched nothing this time: the target was read under the same
392
+ // predicate moments earlier in this transaction, so the row is gone —
393
+ // dropped by a `beforeOperation` hook's own write, typically. `null` is
394
+ // denied-or-gone on every terminal. The hooks that already ran are rolled
395
+ // back with the write, and no after-hook fires for a write that did not
396
+ // happen.
397
+ if (item === null)
398
+ throw new WriteAbandonedSignal();
214
399
  // ── Phase 9: list-level afterOperation ──────────────────────────────────────
215
400
  await executeAfterOperation(listConfig.hooks, operation === 'create'
216
401
  ? {
@@ -233,49 +418,18 @@ async function runWriteInTransaction(args) {
233
418
  });
234
419
  // ── Phase 10: field-level afterOperation (side effects only) ────────────────
235
420
  await executeFieldAfterOperationHooks(item, input, resolvedData, listConfig.fields, writeOp, context, listName, originalItem);
236
- // ── Phase 10.5: nested afterOperation (deferred, in this transaction) ────────
237
- // Each nested create/update/delete's `afterOperation` fires now, with the
238
- // persisted nested row recovered from the parent's included relations. A throw
239
- // here rolls the whole transaction back (parent write included).
240
- await runNestedAfterTasks(afterTasks, item);
241
421
  // ── Phase 11: Field Visibility (filter readable fields + resolveOutput) ─────
242
- return filterReadableFields(item, listConfig.fields, {
243
- session: context.session,
244
- context: { ...context, _isSudo: context._isSudo },
245
- }, config, 0, listName);
246
- }
247
- /**
248
- * Build a Prisma `include` from the set of relation field names that have
249
- * deferred nested `afterOperation` tasks, so the parent write returns those
250
- * relations and the tasks can recover their persisted `item`.
251
- */
252
- function buildIncludeFromFields(includeFields) {
253
- if (includeFields.size === 0)
254
- return undefined;
255
- const include = {};
256
- for (const field of includeFields) {
257
- include[field] = true;
258
- }
259
- return include;
260
- }
261
- /**
262
- * Run the deferred nested `afterOperation` tasks against the persisted parent
263
- * row (`?? {}` is only a type-narrowing guard — parent is always a record
264
- * here). Each task recovers its own nested row by id-diff/known id and THROWS
265
- * if it can't, rather than firing with a fabricated item (ADR-0010).
266
- */
267
- async function runNestedAfterTasks(afterTasks, item) {
268
- if (afterTasks.length === 0)
269
- return;
270
- await runAfterTasks(afterTasks, item ?? {});
422
+ const binding = { listName, listConfig, ormHandle: tx, context, config };
423
+ const visible = await visibleWrittenRow(binding, item, await writtenRowQueryable(binding, item.id));
424
+ return { visible, raw: item };
271
425
  }
272
426
  /**
273
427
  * The delete tail of the pipeline: skips the input-shaping phases and runs
274
428
  * only validate/field-validate before the DB delete, then the after-hooks.
275
- * Returns the deleted row as-is (no Field Visibility pass).
429
+ * Returns the deleted row through the Field Visibility pass.
276
430
  */
277
431
  async function runDeletePath(args) {
278
- const { listName, listConfig, context, originalItem, model, strategy } = args;
432
+ const { ormHandle, listName, listConfig, context, config, originalItem, collection, ops, scope, strategy, } = args;
279
433
  const item = originalItem;
280
434
  // ── Phase 3: list-level validate (delete) ──────────────────────────────────
281
435
  await executeValidate(listConfig.hooks, {
@@ -295,8 +449,12 @@ async function runDeletePath(args) {
295
449
  item,
296
450
  context,
297
451
  });
452
+ const binding = { listName, listConfig, ormHandle, context, config };
453
+ const queryable = await writtenRowQueryable(binding, item.id);
298
454
  // ── Phase 8: DB delete ──────────────────────────────────────────────────────
299
- const deleted = await strategy.persist(model, {});
455
+ const deleted = await strategy.persist(collection, ops, scope, {});
456
+ if (deleted === null)
457
+ throw new WriteAbandonedSignal();
300
458
  // ── Phase 9: list-level afterOperation (delete) ─────────────────────────────
301
459
  await executeAfterOperation(listConfig.hooks, {
302
460
  listKey: listName,
@@ -306,7 +464,8 @@ async function runDeletePath(args) {
306
464
  });
307
465
  // ── Phase 10: field-level afterOperation (delete) ───────────────────────────
308
466
  await executeFieldAfterOperationHooks(deleted, undefined, undefined, listConfig.fields, 'delete', context, listName, item);
309
- return deleted;
467
+ const visible = await visibleWrittenRow(binding, deleted, queryable);
468
+ return { visible, raw: deleted };
310
469
  }
311
470
  // ── Per-operation strategies ──────────────────────────────────────────────────
312
471
  /**
@@ -317,20 +476,20 @@ async function runDeletePath(args) {
317
476
  * create has no row to re-check a filter against, unlike update/delete
318
477
  * (#1009). Enforces the singleton-create constraint even under sudo.
319
478
  * Axis 2: runs all input phases.
320
- * Axis 3: `model.create({ data })`, prepending `id: 1` for singleton lists.
479
+ * Axis 3: `collection.create(row)`, prepending `id: 1` for singleton lists.
321
480
  */
322
481
  export function createWriteStrategy(listName,
323
482
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
324
- listConfig, context) {
483
+ listConfig) {
325
484
  const singleton = isSingletonList(listConfig);
326
485
  return {
327
486
  operation: 'create',
328
487
  runInputPhases: true,
329
- async resolveTarget(model) {
488
+ async resolveTarget(collection, _ops, context) {
330
489
  // Singleton constraint is enforced even under sudo.
331
490
  if (singleton) {
332
- const existingCount = await model.count();
333
- if (existingCount > 0) {
491
+ const existing = await countRows(collection, listName);
492
+ if (existing > 0) {
334
493
  throw new ValidationError([`Cannot create: ${listName} is a singleton list with an existing record`], {});
335
494
  }
336
495
  }
@@ -343,94 +502,122 @@ listConfig, context) {
343
502
  return { status: 'denied' };
344
503
  }
345
504
  }
346
- return { status: 'ok', originalItem: undefined };
505
+ return { status: 'ok', originalItem: undefined, scope: [] };
347
506
  },
348
- async persist(model, data, include) {
349
- // Singleton lists use Int @id with value always 1 (matching Keystone 6).
350
- const createData = singleton ? { id: 1, ...data } : data;
351
- return model.create(include ? { data: createData, include } : { data: createData });
507
+ async persist(collection, _ops, _scope, data) {
508
+ // Singleton lists use an integer id, always 1 (matching Keystone 6).
509
+ return insertRow(collection, singleton ? { id: 1, ...data } : data);
352
510
  },
353
511
  };
354
512
  }
355
513
  /**
356
- * Build the shared target resolution for update/delete: fetch the row (missing
357
- * → denied), check operation-level access (false → denied), and if access
358
- * returns a filter, re-check via `findFirst(mergeFilters(where, filter))`
359
- * (no match → denied). An access result of `true` proceeds with no re-check.
514
+ * The Access Filter as a predicate to AND into the write's own, lowered
515
+ * through the same seam a read lowers it through: trusted config, so its keys
516
+ * are not read-gated, but total, so a rule that resolved to `undefined` is
517
+ * refused rather than dropped (ADR-0022, ADR-0055).
360
518
  */
361
- function resolveExistingTarget(
519
+ async function accessFilterPlan(listName,
362
520
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
363
- listConfig, context, where, access) {
364
- return async (model) => {
365
- const item = await model.findUnique({ where });
521
+ listConfig, config, context, filter) {
522
+ assertAccessFilterConstrains(filter);
523
+ return await resolveWhere(filter, {
524
+ listName,
525
+ listConfig,
526
+ config,
527
+ session: context.session,
528
+ context,
529
+ checkFieldRead: false,
530
+ applyRelationAccess: true,
531
+ accessFilterPath: [listName],
532
+ });
533
+ }
534
+ /**
535
+ * Build the shared target resolution for update/delete: read the row by
536
+ * identity (missing → denied), check operation-level access (false → denied),
537
+ * and if access returns a filter, re-read under the filter as well (no match →
538
+ * denied) and carry it forward as part of the write's own predicate.
539
+ *
540
+ * The second read is what gates the hooks: a filter non-match must short-
541
+ * circuit to `null` before `beforeOperation` runs, which a scope merged into
542
+ * the write alone could not do.
543
+ */
544
+ function resolveExistingTarget(listName,
545
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
546
+ listConfig, config, where, access) {
547
+ return async (collection, ops, context) => {
548
+ const identity = identityPredicate(listName, where.id);
549
+ const item = await firstMatching(collection, [identity], ops);
366
550
  if (!item) {
367
551
  return { status: 'denied' };
368
552
  }
369
- if (!context._isSudo) {
370
- const accessResult = await checkAccess(listConfig.access?.operation?.[access], {
371
- session: context.session,
372
- item,
373
- context,
374
- });
375
- if (accessResult === false) {
376
- return { status: 'denied' };
377
- }
378
- // A filter result must additionally match the target row.
379
- if (typeof accessResult === 'object') {
380
- const matchesFilter = await model.findFirst({
381
- where: mergeFilters(where, accessResult) ?? {},
382
- });
383
- if (!matchesFilter) {
384
- return { status: 'denied' };
385
- }
386
- }
553
+ if (context._isSudo) {
554
+ return { status: 'ok', originalItem: item, scope: [identity] };
555
+ }
556
+ const accessResult = await checkAccess(listConfig.access?.operation?.[access], {
557
+ session: context.session,
558
+ item,
559
+ context,
560
+ });
561
+ if (accessResult === false) {
562
+ return { status: 'denied' };
563
+ }
564
+ if (accessResult === true) {
565
+ return { status: 'ok', originalItem: item, scope: [identity] };
566
+ }
567
+ const filter = await accessFilterPlan(listName, listConfig, config, context, accessResult);
568
+ const scope = [identity, filter];
569
+ const scopedItem = await firstMatching(collection, scope, ops);
570
+ if (!scopedItem) {
571
+ return { status: 'denied' };
387
572
  }
388
- return { status: 'ok', originalItem: item };
573
+ return { status: 'ok', originalItem: item, scope };
389
574
  };
390
575
  }
391
576
  /**
392
577
  * Update strategy for {@link WriteStrategy}.
393
578
  *
394
- * Axis 1: fetch row, check `update` access, re-check filter results.
579
+ * Axis 1: read the row, check `update` access, re-read under a filter result.
395
580
  * Axis 2: runs all input phases.
396
- * Axis 3: `model.update({ where, data })`; afterOperation gets `originalItem`.
581
+ * Axis 3: `collection.where(scope).update(row)`; afterOperation gets `originalItem`.
397
582
  */
398
- export function updateWriteStrategy(
583
+ export function updateWriteStrategy(listName,
399
584
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
400
- listConfig, context, where) {
585
+ listConfig, config, where) {
401
586
  return {
402
587
  operation: 'update',
403
588
  runInputPhases: true,
404
- resolveTarget: resolveExistingTarget(listConfig, context, where, 'update'),
405
- async persist(model, data, include) {
406
- return model.update(include ? { where, data, include } : { where, data });
589
+ resolveTarget: resolveExistingTarget(listName, listConfig, config, where, 'update'),
590
+ async persist(collection, ops, scope, data) {
591
+ if (Object.values(data).every((value) => value === undefined))
592
+ return firstMatching(collection, scope, ops);
593
+ return updateFirst(collection, scope, ops, data);
407
594
  },
408
595
  };
409
596
  }
410
597
  /**
411
598
  * Delete strategy for {@link WriteStrategy}.
412
599
  *
413
- * Axis 1: enforce singleton constraint (even under sudo), fetch row, check
414
- * `delete` access, re-check filter results.
600
+ * Axis 1: enforce singleton constraint (even under sudo), read the row, check
601
+ * `delete` access, re-read under a filter result.
415
602
  * Axis 2: skips input phases (runs only validate/field-validate).
416
- * Axis 3: `model.delete({ where })`; afterOperation gets `originalItem`.
603
+ * Axis 3: `collection.where(scope).delete()`; afterOperation gets `originalItem`.
417
604
  */
418
605
  export function deleteWriteStrategy(listName,
419
606
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
420
- listConfig, context, where) {
421
- const resolveTarget = resolveExistingTarget(listConfig, context, where, 'delete');
607
+ listConfig, config, where) {
608
+ const resolveTarget = resolveExistingTarget(listName, listConfig, config, where, 'delete');
422
609
  return {
423
610
  operation: 'delete',
424
611
  runInputPhases: false,
425
- async resolveTarget(model) {
612
+ async resolveTarget(collection, ops, context) {
426
613
  // Singleton lists may not be deleted (enforced even under sudo).
427
614
  if (isSingletonList(listConfig)) {
428
615
  throw new ValidationError([`Cannot delete: ${listName} is a singleton list`], {});
429
616
  }
430
- return resolveTarget(model);
617
+ return resolveTarget(collection, ops, context);
431
618
  },
432
- async persist(model) {
433
- return model.delete({ where });
619
+ async persist(collection, ops, scope) {
620
+ return deleteFirst(collection, scope, ops);
434
621
  },
435
622
  };
436
623
  }