@opensaas/stack-core 0.42.3 → 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 +2745 -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 -15
  204. package/dist/index.d.ts.map +1 -1
  205. package/dist/index.js +105 -44
  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 -47
  464. package/dist/context/nested-operations.d.ts.map +0 -1
  465. package/dist/context/nested-operations.js +0 -731
  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 -1325
  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 -184
  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 -3141
  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 -231
  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,864 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest'
2
- import { getContext } from '../src/context/index.js'
3
- import { config, list } from '../src/config/index.js'
4
- import { text, relationship } from '../src/fields/index.js'
5
-
6
- /**
7
- * #569 / ADR-0010: nested create/update/delete must run the SAME full hook
8
- * pipeline (list + field `beforeOperation`/`afterOperation`) as the equivalent
9
- * top-level write, with the documented arguments, inside ONE transaction that
10
- * rolls back if any hook throws.
11
- *
12
- * These tests use a transaction-aware in-memory Prisma mock so they can assert:
13
- * - nested before/afterOperation fire with correct args;
14
- * - side effects are identical nested vs top-level;
15
- * - a throwing nested afterOperation rolls back the parent write (atomicity);
16
- * - sudo still bypasses access while running hooks.
17
- */
18
-
19
- /**
20
- * A tiny in-memory Prisma mock supporting interactive transactions.
21
- *
22
- * `$transaction(fn)` snapshots every table, runs `fn` against a tx client whose
23
- * writes mutate the live tables, and on throw restores the snapshot (rollback).
24
- * Nested writes are supported for to-one/to-many `create`/`update`/`delete`.
25
- */
26
- function createTxPrisma() {
27
- const tables: Record<string, Map<string, Record<string, unknown>>> = {
28
- post: new Map(),
29
- user: new Map(),
30
- comment: new Map(),
31
- }
32
- let idCounter = 0
33
- const nextId = () => `id-${++idCounter}`
34
-
35
- function applyNested(
36
- table: string,
37
- record: Record<string, unknown>,
38
- data: Record<string, unknown>,
39
- ): Record<string, unknown> {
40
- const result = { ...record }
41
- for (const [key, value] of Object.entries(data)) {
42
- if (value && typeof value === 'object' && !Array.isArray(value)) {
43
- const nested = value as Record<string, unknown>
44
- // Heuristic: a relationship op object has create/update/delete keys.
45
- if (nested.create || nested.update || nested.delete || nested.connect) {
46
- const relTable = key === 'author' ? 'user' : key === 'comments' ? 'comment' : key
47
- const linkField = `${key}Link`
48
- if (nested.create) {
49
- const created = doCreate(relTable, nested.create as Record<string, unknown>)
50
- result[linkField] = created.id
51
- result[key] = created
52
- }
53
- if (nested.update) {
54
- const upd = nested.update as { where: { id: string }; data: Record<string, unknown> }
55
- const updated = doUpdate(relTable, upd.where, upd.data)
56
- result[key] = updated
57
- }
58
- if (nested.delete) {
59
- const del = nested.delete as { id: string }
60
- doDelete(relTable, del)
61
- result[key] = null
62
- }
63
- continue
64
- }
65
- }
66
- result[key] = value
67
- }
68
- return result
69
- }
70
-
71
- function doCreate(table: string, data: Record<string, unknown>): Record<string, unknown> {
72
- const id = (data.id as string) ?? nextId()
73
- let record: Record<string, unknown> = { id }
74
- record = applyNested(table, record, data)
75
- tables[table].set(id, record)
76
- return record
77
- }
78
-
79
- function doUpdate(
80
- table: string,
81
- where: { id: string },
82
- data: Record<string, unknown>,
83
- ): Record<string, unknown> {
84
- const existing = tables[table].get(where.id) ?? { id: where.id }
85
- const updated = applyNested(table, existing, data)
86
- tables[table].set(where.id, updated)
87
- return updated
88
- }
89
-
90
- function doDelete(table: string, where: { id: string }): Record<string, unknown> {
91
- const existing = tables[table].get(where.id) ?? { id: where.id }
92
- tables[table].delete(where.id)
93
- return existing
94
- }
95
-
96
- function makeModel(table: string) {
97
- return {
98
- findUnique: vi.fn(
99
- async ({ where }: { where: { id: string } }) => tables[table].get(where.id) ?? null,
100
- ),
101
- findFirst: vi.fn(async ({ where }: { where?: { id?: string } }) => {
102
- if (where?.id) return tables[table].get(where.id) ?? null
103
- return tables[table].values().next().value ?? null
104
- }),
105
- findMany: vi.fn(async () => Array.from(tables[table].values())),
106
- count: vi.fn(async () => tables[table].size),
107
- create: vi.fn(async ({ data }: { data: Record<string, unknown> }) => doCreate(table, data)),
108
- update: vi.fn(
109
- async ({ where, data }: { where: { id: string }; data: Record<string, unknown> }) =>
110
- doUpdate(table, where, data),
111
- ),
112
- delete: vi.fn(async ({ where }: { where: { id: string } }) => doDelete(table, where)),
113
- }
114
- }
115
-
116
- const client: Record<string, unknown> = {
117
- post: makeModel('post'),
118
- user: makeModel('user'),
119
- comment: makeModel('comment'),
120
- }
121
-
122
- client.$transaction = async (fn: (tx: unknown) => Promise<unknown>) => {
123
- const snapshot: Record<string, Map<string, Record<string, unknown>>> = {}
124
- for (const [name, map] of Object.entries(tables)) {
125
- snapshot[name] = new Map(map)
126
- }
127
- try {
128
- return await fn(client)
129
- } catch (err) {
130
- // Roll back: restore every table from the snapshot.
131
- for (const [name, map] of Object.entries(snapshot)) {
132
- tables[name] = map
133
- }
134
- throw err
135
- }
136
- }
137
-
138
- return { client, tables }
139
- }
140
-
141
- describe('#569 nested writes — full hook pipeline + transaction', () => {
142
- let mock: ReturnType<typeof createTxPrisma>
143
-
144
- beforeEach(() => {
145
- mock = createTxPrisma()
146
- vi.clearAllMocks()
147
- })
148
-
149
- it('nested create fires list + field before/afterOperation with correct args', async () => {
150
- const events: string[] = []
151
- const listBefore = vi.fn(({ operation }) => {
152
- events.push(`list:before:${operation}`)
153
- })
154
- const listAfter = vi.fn(({ operation, item }) => {
155
- events.push(`list:after:${operation}`)
156
- expect(item).toBeDefined()
157
- expect(item.id).toBeDefined()
158
- })
159
- const fieldBefore = vi.fn(({ operation }) => {
160
- events.push(`field:before:${operation}`)
161
- })
162
- const fieldAfter = vi.fn(({ operation, item }) => {
163
- events.push(`field:after:${operation}`)
164
- expect(item.id).toBeDefined()
165
- })
166
-
167
- const testConfig = config({
168
- db: { provider: 'postgresql', url: 'postgresql://localhost:5432/test' },
169
- lists: {
170
- User: list({
171
- fields: {
172
- name: text({ hooks: { beforeOperation: fieldBefore, afterOperation: fieldAfter } }),
173
- },
174
- access: { operation: { query: () => true, create: () => true, update: () => true } },
175
- hooks: { beforeOperation: listBefore, afterOperation: listAfter },
176
- }),
177
- Post: list({
178
- fields: {
179
- title: text(),
180
- author: relationship({ ref: 'User.posts' }),
181
- },
182
- access: { operation: { query: () => true, update: () => true } },
183
- }),
184
- },
185
- })
186
-
187
- mock.tables.post.set('p1', { id: 'p1', title: 'Original' })
188
-
189
- const context = getContext(await testConfig, mock.client, { userId: '1' })
190
-
191
- await context.db.post.update({
192
- where: { id: 'p1' },
193
- data: {
194
- title: 'Updated',
195
- author: { create: { name: 'john' } },
196
- },
197
- })
198
-
199
- // All four hooks fired, create operation, before strictly precedes after.
200
- expect(listBefore).toHaveBeenCalledWith(
201
- expect.objectContaining({ operation: 'create', listKey: 'User' }),
202
- )
203
- expect(fieldBefore).toHaveBeenCalledWith(
204
- expect.objectContaining({ operation: 'create', fieldKey: 'name' }),
205
- )
206
- expect(listAfter).toHaveBeenCalledWith(
207
- expect.objectContaining({ operation: 'create', listKey: 'User' }),
208
- )
209
- expect(fieldAfter).toHaveBeenCalledWith(
210
- expect.objectContaining({ operation: 'create', fieldKey: 'name' }),
211
- )
212
- expect(events.indexOf('list:before:create')).toBeLessThan(events.indexOf('list:after:create'))
213
- })
214
-
215
- it('nested update fires afterOperation with originalItem + updated item', async () => {
216
- const listAfter = vi.fn()
217
-
218
- const testConfig = config({
219
- db: { provider: 'postgresql', url: 'postgresql://localhost:5432/test' },
220
- lists: {
221
- User: list({
222
- fields: { name: text() },
223
- access: { operation: { query: () => true, update: () => true } },
224
- hooks: { afterOperation: listAfter },
225
- }),
226
- Post: list({
227
- fields: { title: text(), author: relationship({ ref: 'User.posts' }) },
228
- access: { operation: { query: () => true, update: () => true } },
229
- }),
230
- },
231
- })
232
-
233
- mock.tables.post.set('p1', { id: 'p1', title: 'P', authorLink: 'u1' })
234
- mock.tables.user.set('u1', { id: 'u1', name: 'old name' })
235
-
236
- const context = getContext(await testConfig, mock.client, { userId: '1' })
237
-
238
- await context.db.post.update({
239
- where: { id: 'p1' },
240
- data: {
241
- author: { update: { where: { id: 'u1' }, data: { name: 'new name' } } },
242
- },
243
- })
244
-
245
- expect(listAfter).toHaveBeenCalledWith(
246
- expect.objectContaining({
247
- operation: 'update',
248
- originalItem: expect.objectContaining({ id: 'u1', name: 'old name' }),
249
- item: expect.objectContaining({ id: 'u1', name: 'new name' }),
250
- }),
251
- )
252
- })
253
-
254
- it('nested delete fires before/afterOperation with originalItem', async () => {
255
- const listBefore = vi.fn()
256
- const listAfter = vi.fn()
257
-
258
- const testConfig = config({
259
- db: { provider: 'postgresql', url: 'postgresql://localhost:5432/test' },
260
- lists: {
261
- Comment: list({
262
- fields: { body: text() },
263
- access: {
264
- operation: { query: () => true, update: () => true, delete: () => true },
265
- },
266
- hooks: { beforeOperation: listBefore, afterOperation: listAfter },
267
- }),
268
- Post: list({
269
- fields: {
270
- title: text(),
271
- comments: relationship({ ref: 'Comment', many: true }),
272
- },
273
- access: { operation: { query: () => true, update: () => true } },
274
- }),
275
- },
276
- })
277
-
278
- mock.tables.post.set('p1', { id: 'p1', title: 'P' })
279
- mock.tables.comment.set('c1', { id: 'c1', body: 'doomed' })
280
-
281
- const context = getContext(await testConfig, mock.client, { userId: '1' })
282
-
283
- await context.db.post.update({
284
- where: { id: 'p1' },
285
- data: { comments: { delete: { id: 'c1' } } },
286
- })
287
-
288
- expect(listBefore).toHaveBeenCalledWith(
289
- expect.objectContaining({
290
- operation: 'delete',
291
- item: expect.objectContaining({ id: 'c1', body: 'doomed' }),
292
- }),
293
- )
294
- expect(listAfter).toHaveBeenCalledWith(
295
- expect.objectContaining({
296
- operation: 'delete',
297
- originalItem: expect.objectContaining({ id: 'c1', body: 'doomed' }),
298
- }),
299
- )
300
- })
301
-
302
- it('side effect fires identically for nested vs top-level create', async () => {
303
- const sideEffects: string[] = []
304
- const afterOp = vi.fn(({ operation, item }) => {
305
- if (operation === 'create') sideEffects.push(`created:${item.name}`)
306
- })
307
-
308
- const makeConfig = () =>
309
- config({
310
- db: { provider: 'postgresql', url: 'postgresql://localhost:5432/test' },
311
- lists: {
312
- User: list({
313
- fields: { name: text() },
314
- access: { operation: { query: () => true, create: () => true, update: () => true } },
315
- hooks: { afterOperation: afterOp },
316
- }),
317
- Post: list({
318
- fields: { title: text(), author: relationship({ ref: 'User.posts' }) },
319
- access: { operation: { query: () => true, create: () => true, update: () => true } },
320
- }),
321
- },
322
- })
323
-
324
- // Top-level create.
325
- const ctx1 = getContext(await makeConfig(), mock.client, { userId: '1' })
326
- await ctx1.db.user.create({ data: { name: 'top-level' } })
327
-
328
- // Nested create (same logical operation).
329
- mock.tables.post.set('p1', { id: 'p1', title: 'P' })
330
- const ctx2 = getContext(await makeConfig(), mock.client, { userId: '1' })
331
- await ctx2.db.post.update({
332
- where: { id: 'p1' },
333
- data: { author: { create: { name: 'nested' } } },
334
- })
335
-
336
- expect(sideEffects).toContain('created:top-level')
337
- expect(sideEffects).toContain('created:nested')
338
- })
339
-
340
- it('a throwing nested afterOperation rolls back the parent write (atomicity)', async () => {
341
- const testConfig = config({
342
- db: { provider: 'postgresql', url: 'postgresql://localhost:5432/test' },
343
- lists: {
344
- User: list({
345
- fields: { name: text() },
346
- access: { operation: { query: () => true, create: () => true, update: () => true } },
347
- hooks: {
348
- afterOperation: ({ operation }) => {
349
- if (operation === 'create') {
350
- throw new Error('nested afterOperation boom')
351
- }
352
- },
353
- },
354
- }),
355
- Post: list({
356
- fields: { title: text(), author: relationship({ ref: 'User.posts' }) },
357
- access: { operation: { query: () => true, update: () => true } },
358
- }),
359
- },
360
- })
361
-
362
- mock.tables.post.set('p1', { id: 'p1', title: 'Original' })
363
-
364
- const context = getContext(await testConfig, mock.client, { userId: '1' })
365
-
366
- await expect(
367
- context.db.post.update({
368
- where: { id: 'p1' },
369
- data: {
370
- title: 'Should NOT persist',
371
- author: { create: { name: 'doomed' } },
372
- },
373
- }),
374
- ).rejects.toThrow('nested afterOperation boom')
375
-
376
- // Rollback: the parent title is unchanged and the nested user is gone.
377
- expect(mock.tables.post.get('p1')?.title).toBe('Original')
378
- expect(mock.tables.user.size).toBe(0)
379
- })
380
-
381
- it('a throwing nested beforeOperation rolls back and never persists', async () => {
382
- const testConfig = config({
383
- db: { provider: 'postgresql', url: 'postgresql://localhost:5432/test' },
384
- lists: {
385
- User: list({
386
- fields: { name: text() },
387
- access: { operation: { query: () => true, create: () => true, update: () => true } },
388
- hooks: {
389
- beforeOperation: ({ operation }) => {
390
- if (operation === 'create') throw new Error('nested beforeOperation boom')
391
- },
392
- },
393
- }),
394
- Post: list({
395
- fields: { title: text(), author: relationship({ ref: 'User.posts' }) },
396
- access: { operation: { query: () => true, update: () => true } },
397
- }),
398
- },
399
- })
400
-
401
- mock.tables.post.set('p1', { id: 'p1', title: 'Original' })
402
- const context = getContext(await testConfig, mock.client, { userId: '1' })
403
-
404
- await expect(
405
- context.db.post.update({
406
- where: { id: 'p1' },
407
- data: { title: 'nope', author: { create: { name: 'doomed' } } },
408
- }),
409
- ).rejects.toThrow('nested beforeOperation boom')
410
-
411
- expect(mock.tables.post.get('p1')?.title).toBe('Original')
412
- expect(mock.tables.user.size).toBe(0)
413
- })
414
-
415
- it('sudo bypasses access on nested create but still runs hooks', async () => {
416
- const createAccess = vi.fn(() => false as const)
417
- const afterOp = vi.fn()
418
-
419
- const testConfig = config({
420
- db: { provider: 'postgresql', url: 'postgresql://localhost:5432/test' },
421
- lists: {
422
- User: list({
423
- fields: { name: text() },
424
- access: { operation: { query: () => true, create: createAccess, update: () => true } },
425
- hooks: { afterOperation: afterOp },
426
- }),
427
- Post: list({
428
- fields: { title: text(), author: relationship({ ref: 'User.posts' }) },
429
- access: { operation: { query: () => true, update: () => true } },
430
- }),
431
- },
432
- })
433
-
434
- mock.tables.post.set('p1', { id: 'p1', title: 'P' })
435
- const context = getContext(await testConfig, mock.client, { userId: '1' }).sudo()
436
-
437
- await context.db.post.update({
438
- where: { id: 'p1' },
439
- data: { author: { create: { name: 'sudo-made' } } },
440
- })
441
-
442
- // Access denied normally; sudo bypasses the access fn, but hooks still run.
443
- expect(createAccess).not.toHaveBeenCalled()
444
- expect(afterOp).toHaveBeenCalledWith(expect.objectContaining({ operation: 'create' }))
445
- expect(mock.tables.user.size).toBe(1)
446
- })
447
-
448
- it('non-sudo nested create denied by access throws and rolls back', async () => {
449
- const testConfig = config({
450
- db: { provider: 'postgresql', url: 'postgresql://localhost:5432/test' },
451
- lists: {
452
- User: list({
453
- fields: { name: text() },
454
- access: { operation: { query: () => true, create: () => false, update: () => true } },
455
- }),
456
- Post: list({
457
- fields: { title: text(), author: relationship({ ref: 'User.posts' }) },
458
- access: { operation: { query: () => true, update: () => true } },
459
- }),
460
- },
461
- })
462
-
463
- mock.tables.post.set('p1', { id: 'p1', title: 'Original' })
464
- const context = getContext(await testConfig, mock.client, { userId: '1' })
465
-
466
- await expect(
467
- context.db.post.update({
468
- where: { id: 'p1' },
469
- data: { title: 'nope', author: { create: { name: 'denied' } } },
470
- }),
471
- ).rejects.toThrow('Access denied: Cannot create related item')
472
-
473
- // The whole write rolled back — parent title unchanged.
474
- expect(mock.tables.post.get('p1')?.title).toBe('Original')
475
- })
476
-
477
- it('every write is transactional — top-level create uses $transaction', async () => {
478
- const txSpy = vi.spyOn(
479
- mock.client as { $transaction: unknown } & Record<string, unknown>,
480
- '$transaction',
481
- )
482
-
483
- const testConfig = config({
484
- db: { provider: 'postgresql', url: 'postgresql://localhost:5432/test' },
485
- lists: {
486
- User: list({
487
- fields: { name: text() },
488
- access: { operation: { query: () => true, create: () => true } },
489
- }),
490
- },
491
- })
492
-
493
- const context = getContext(await testConfig, mock.client, { userId: '1' })
494
- await context.db.user.create({ data: { name: 'solo' } })
495
-
496
- expect(txSpy).toHaveBeenCalledTimes(1)
497
- })
498
- })
499
-
500
- /**
501
- * A richer transaction-aware mock that models a to-many relation
502
- * (`Post.comments`) with real link tracking and `include`-echoing, so the
503
- * created-row recovery (#569 finding 1+2) can be exercised against the actual
504
- * id-diff: each created comment gets a fresh id, the parent `update`/`create`
505
- * result echoes `include: { comments: true }` with the linked rows, and
506
- * pre-existing comments are preserved.
507
- */
508
- function createToManyPrisma() {
509
- const tables: Record<string, Map<string, Record<string, unknown>>> = {
510
- post: new Map(),
511
- comment: new Map(),
512
- }
513
- // commentId -> postId link.
514
- const commentToPost = new Map<string, string>()
515
- let idCounter = 0
516
- const nextId = () => `c-${++idCounter}`
517
-
518
- function linkedComments(postId: string): Array<Record<string, unknown>> {
519
- const rows: Array<Record<string, unknown>> = []
520
- for (const [commentId, owner] of commentToPost.entries()) {
521
- if (owner === postId) {
522
- const row = tables.comment.get(commentId)
523
- if (row) rows.push(row)
524
- }
525
- }
526
- return rows
527
- }
528
-
529
- function applyCommentOps(postId: string, ops: Record<string, unknown>) {
530
- if (ops.create) {
531
- const creates = Array.isArray(ops.create) ? ops.create : [ops.create]
532
- for (const data of creates as Array<Record<string, unknown>>) {
533
- const id = (data.id as string) ?? nextId()
534
- const row: Record<string, unknown> = { id, ...data }
535
- tables.comment.set(id, row)
536
- commentToPost.set(id, postId)
537
- }
538
- }
539
- if (ops.update) {
540
- const updates = Array.isArray(ops.update) ? ops.update : [ops.update]
541
- for (const u of updates as Array<{ where: { id: string }; data: Record<string, unknown> }>) {
542
- const existing = tables.comment.get(u.where.id) ?? { id: u.where.id }
543
- tables.comment.set(u.where.id, { ...existing, ...u.data })
544
- }
545
- }
546
- if (ops.delete) {
547
- const deletes = Array.isArray(ops.delete) ? ops.delete : [ops.delete]
548
- for (const d of deletes as Array<{ id: string }>) {
549
- tables.comment.delete(d.id)
550
- commentToPost.delete(d.id)
551
- }
552
- }
553
- }
554
-
555
- function buildPostResult(
556
- postId: string,
557
- include: Record<string, unknown> | undefined,
558
- ): Record<string, unknown> {
559
- const base = tables.post.get(postId) ?? { id: postId }
560
- if (include?.comments) {
561
- return { ...base, comments: linkedComments(postId) }
562
- }
563
- return { ...base }
564
- }
565
-
566
- const postModel = {
567
- findUnique: vi.fn(
568
- async ({ where, include }: { where: { id: string }; include?: Record<string, unknown> }) => {
569
- if (!tables.post.has(where.id)) return null
570
- return buildPostResult(where.id, include)
571
- },
572
- ),
573
- findFirst: vi.fn(async ({ where }: { where?: { id?: string } }) => {
574
- if (where?.id) return tables.post.get(where.id) ?? null
575
- return tables.post.values().next().value ?? null
576
- }),
577
- findMany: vi.fn(async () => Array.from(tables.post.values())),
578
- count: vi.fn(async () => tables.post.size),
579
- create: vi.fn(
580
- async ({
581
- data,
582
- include,
583
- }: {
584
- data: Record<string, unknown>
585
- include?: Record<string, unknown>
586
- }) => {
587
- const id = (data.id as string) ?? `p-${++idCounter}`
588
- const { comments, ...scalars } = data
589
- tables.post.set(id, { id, ...scalars })
590
- if (comments) applyCommentOps(id, comments as Record<string, unknown>)
591
- return buildPostResult(id, include)
592
- },
593
- ),
594
- update: vi.fn(
595
- async ({
596
- where,
597
- data,
598
- include,
599
- }: {
600
- where: { id: string }
601
- data: Record<string, unknown>
602
- include?: Record<string, unknown>
603
- }) => {
604
- const existing = tables.post.get(where.id) ?? { id: where.id }
605
- const { comments, ...scalars } = data
606
- tables.post.set(where.id, { ...existing, ...scalars })
607
- if (comments) applyCommentOps(where.id, comments as Record<string, unknown>)
608
- return buildPostResult(where.id, include)
609
- },
610
- ),
611
- delete: vi.fn(async ({ where }: { where: { id: string } }) => {
612
- const existing = tables.post.get(where.id) ?? { id: where.id }
613
- tables.post.delete(where.id)
614
- return existing
615
- }),
616
- }
617
-
618
- function makeCommentModel() {
619
- return {
620
- findUnique: vi.fn(
621
- async ({ where }: { where: { id: string } }) => tables.comment.get(where.id) ?? null,
622
- ),
623
- findFirst: vi.fn(async () => tables.comment.values().next().value ?? null),
624
- findMany: vi.fn(async () => Array.from(tables.comment.values())),
625
- count: vi.fn(async () => tables.comment.size),
626
- create: vi.fn(async ({ data }: { data: Record<string, unknown> }) => {
627
- const id = (data.id as string) ?? nextId()
628
- const row = { id, ...data }
629
- tables.comment.set(id, row)
630
- return row
631
- }),
632
- update: vi.fn(
633
- async ({ where, data }: { where: { id: string }; data: Record<string, unknown> }) => {
634
- const existing = tables.comment.get(where.id) ?? { id: where.id }
635
- const updated = { ...existing, ...data }
636
- tables.comment.set(where.id, updated)
637
- return updated
638
- },
639
- ),
640
- delete: vi.fn(async ({ where }: { where: { id: string } }) => {
641
- const existing = tables.comment.get(where.id) ?? { id: where.id }
642
- tables.comment.delete(where.id)
643
- commentToPost.delete(where.id)
644
- return existing
645
- }),
646
- }
647
- }
648
-
649
- const client: Record<string, unknown> = {
650
- post: postModel,
651
- comment: makeCommentModel(),
652
- }
653
-
654
- client.$transaction = async (fn: (tx: unknown) => Promise<unknown>) => {
655
- const snapshot = {
656
- post: new Map(tables.post),
657
- comment: new Map(tables.comment),
658
- links: new Map(commentToPost),
659
- }
660
- try {
661
- return await fn(client)
662
- } catch (err) {
663
- tables.post = snapshot.post
664
- tables.comment = snapshot.comment
665
- commentToPost.clear()
666
- for (const [k, v] of snapshot.links) commentToPost.set(k, v)
667
- throw err
668
- }
669
- }
670
-
671
- /** Link a pre-existing comment to a post (test setup helper). */
672
- function seedComment(postId: string, comment: Record<string, unknown>) {
673
- tables.comment.set(comment.id as string, comment)
674
- commentToPost.set(comment.id as string, postId)
675
- }
676
-
677
- return { client, tables, seedComment, linkedComments }
678
- }
679
-
680
- describe('#569 nested writes — created-row recovery by id-diff (findings 1 + 2)', () => {
681
- function makeConfig(afterOp: ReturnType<typeof vi.fn>) {
682
- return config({
683
- db: { provider: 'postgresql', url: 'postgresql://localhost:5432/test' },
684
- lists: {
685
- Comment: list({
686
- fields: { body: text() },
687
- access: { operation: { query: () => true, create: () => true, update: () => true } },
688
- hooks: { afterOperation: afterOp },
689
- }),
690
- Post: list({
691
- fields: {
692
- title: text(),
693
- comments: relationship({ ref: 'Comment', many: true }),
694
- },
695
- access: { operation: { query: () => true, create: () => true, update: () => true } },
696
- }),
697
- },
698
- })
699
- }
700
-
701
- it('multiple nested creates on a to-many relation each fire afterOperation once with their OWN distinct row', async () => {
702
- const mock = createToManyPrisma()
703
- const created: Array<{ id: unknown; body: unknown }> = []
704
- const afterOp = vi.fn(({ operation, item }) => {
705
- if (operation === 'create') created.push({ id: item.id, body: item.body })
706
- })
707
-
708
- mock.tables.post.set('p1', { id: 'p1', title: 'P' })
709
- const context = getContext(await makeConfig(afterOp), mock.client, { userId: '1' })
710
-
711
- await context.db.post.update({
712
- where: { id: 'p1' },
713
- data: {
714
- comments: { create: [{ body: 'A' }, { body: 'B' }] },
715
- },
716
- })
717
-
718
- // afterOperation fired exactly once per created comment.
719
- const createEvents = afterOp.mock.calls.filter((c) => c[0].operation === 'create')
720
- expect(createEvents).toHaveLength(2)
721
-
722
- // Each fired against its OWN distinct, persisted row — distinct ids, the two
723
- // bodies, never the same row twice (the original bug recovered fresh[last]
724
- // for every create).
725
- expect(created).toHaveLength(2)
726
- const ids = created.map((c) => c.id)
727
- expect(new Set(ids).size).toBe(2)
728
- for (const id of ids) expect(typeof id).toBe('string')
729
- expect(created.map((c) => c.body).sort()).toEqual(['A', 'B'])
730
- })
731
-
732
- it('nested create on a to-many relation with pre-existing rows fires afterOperation ONLY for the newly-created row', async () => {
733
- const mock = createToManyPrisma()
734
- const createdItems: Array<Record<string, unknown>> = []
735
- const afterOp = vi.fn(({ operation, item }) => {
736
- if (operation === 'create') createdItems.push(item)
737
- })
738
-
739
- // A post that already has a pre-existing comment.
740
- mock.tables.post.set('p1', { id: 'p1', title: 'P' })
741
- mock.seedComment('p1', { id: 'pre-1', body: 'pre-existing' })
742
-
743
- const context = getContext(await makeConfig(afterOp), mock.client, { userId: '1' })
744
-
745
- await context.db.post.update({
746
- where: { id: 'p1' },
747
- data: { comments: { create: { body: 'brand-new' } } },
748
- })
749
-
750
- // Exactly one create afterOperation — for the new row, NOT the pre-existing one.
751
- const createEvents = afterOp.mock.calls.filter((c) => c[0].operation === 'create')
752
- expect(createEvents).toHaveLength(1)
753
- expect(createdItems).toHaveLength(1)
754
- expect(createdItems[0].id).not.toBe('pre-1')
755
- expect(createdItems[0].body).toBe('brand-new')
756
-
757
- // Both comments now exist in the DB (pre-existing preserved).
758
- expect(
759
- mock
760
- .linkedComments('p1')
761
- .map((c) => c.body)
762
- .sort(),
763
- ).toEqual(['brand-new', 'pre-existing'])
764
- })
765
- })
766
-
767
- describe('#569 nested writes — context.db inside hooks is transactional (finding 3)', () => {
768
- it('a hook writing via context.db rolls back when the transaction later throws', async () => {
769
- const mock = createToManyPrisma()
770
-
771
- // The Comment afterOperation writes a SECOND comment via context.db, then a
772
- // later (post) afterOperation throws — the whole transaction must roll back,
773
- // including the context.db write, leaving NO comments persisted.
774
- const testConfig = config({
775
- db: { provider: 'postgresql', url: 'postgresql://localhost:5432/test' },
776
- lists: {
777
- Comment: list({
778
- fields: { body: text() },
779
- access: { operation: { query: () => true, create: () => true, update: () => true } },
780
- hooks: {
781
- afterOperation: async ({ operation, item, context }) => {
782
- // Only the originally-created comment triggers the side-write, and
783
- // guard against recursion (the side-write is body 'audit').
784
- if (operation === 'create' && item.body === 'main') {
785
- await context.db.comment.create({ data: { body: 'audit' } })
786
- }
787
- },
788
- },
789
- }),
790
- Post: list({
791
- fields: {
792
- title: text(),
793
- comments: relationship({ ref: 'Comment', many: true }),
794
- },
795
- access: { operation: { query: () => true, create: () => true, update: () => true } },
796
- hooks: {
797
- afterOperation: ({ operation }) => {
798
- if (operation === 'update') throw new Error('post afterOperation boom')
799
- },
800
- },
801
- }),
802
- },
803
- })
804
-
805
- mock.tables.post.set('p1', { id: 'p1', title: 'P' })
806
- const context = getContext(await testConfig, mock.client, { userId: '1' })
807
-
808
- await expect(
809
- context.db.post.update({
810
- where: { id: 'p1' },
811
- data: { comments: { create: { body: 'main' } } },
812
- }),
813
- ).rejects.toThrow('post afterOperation boom')
814
-
815
- // Rollback: neither the nested 'main' comment nor the hook's 'audit'
816
- // context.db write survived — proving the hook's context.db participated in
817
- // the same transaction.
818
- expect(mock.tables.comment.size).toBe(0)
819
- })
820
-
821
- it('a hook writing via context.db persists when the transaction commits', async () => {
822
- const mock = createToManyPrisma()
823
-
824
- const testConfig = config({
825
- db: { provider: 'postgresql', url: 'postgresql://localhost:5432/test' },
826
- lists: {
827
- Comment: list({
828
- fields: { body: text() },
829
- access: { operation: { query: () => true, create: () => true, update: () => true } },
830
- hooks: {
831
- afterOperation: async ({ operation, item, context }) => {
832
- if (operation === 'create' && item.body === 'main') {
833
- await context.db.comment.create({ data: { body: 'audit' } })
834
- }
835
- },
836
- },
837
- }),
838
- Post: list({
839
- fields: {
840
- title: text(),
841
- comments: relationship({ ref: 'Comment', many: true }),
842
- },
843
- access: { operation: { query: () => true, create: () => true, update: () => true } },
844
- }),
845
- },
846
- })
847
-
848
- mock.tables.post.set('p1', { id: 'p1', title: 'P' })
849
- const context = getContext(await testConfig, mock.client, { userId: '1' })
850
-
851
- await context.db.post.update({
852
- where: { id: 'p1' },
853
- data: { comments: { create: { body: 'main' } } },
854
- })
855
-
856
- // Commit: both the nested 'main' comment and the hook's 'audit' write
857
- // persisted.
858
- expect(
859
- Array.from(mock.tables.comment.values())
860
- .map((c) => c.body)
861
- .sort(),
862
- ).toEqual(['audit', 'main'])
863
- })
864
- })