@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,1256 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import { buildAccessScopedInclude, resolveToOneAccessVisibility } from './access-filter.js';
3
- import { AccessScopeDepthExceededError, RelationFilterAccessDeniedError, UndeclaredCountKeyError, UndeclaredIncludeKeyError, } from './errors.js';
4
- import { READ_INCLUDE_MAX_DEPTH } from './depth-limits.js';
5
- import { ValidationError } from '../hooks/index.js';
6
- /**
7
- * Regression coverage for `buildAccessScopedInclude`, the caller-directed
8
- * access-scoping walk introduced by ADR-0026. It replaces the old two-step
9
- * "auto-walk every relationship of the list, then reconcile against whatever
10
- * the caller asked for" pipeline (`buildIncludeWithAccessControl` +
11
- * `mergeIncludeWithAccessControl`): the walk now recurses ONLY into the
12
- * branches a request (`requestedInclude`) itself names, and never evaluates
13
- * `query` access on a relation nobody asked for.
14
- *
15
- * The scenarios below carry forward the guarantees the old two-function
16
- * pipeline encoded — #566 (caller include augments, never replaces, the
17
- * access-controlled scope), #752 (a caller `take` survives the merge), #830
18
- * (fail-closed past the read-include depth cap) — expressed against the new,
19
- * single-function API. New coverage (the point of ADR-0026 itself): a
20
- * relation the request doesn't name never has its list's `query` access
21
- * invoked, and naming a relation fetches its own columns and stops (the "One
22
- * hop" rule) at every level, not just the root.
23
- *
24
- * The scenarios in this file build every chain relation as to-MANY
25
- * (`rel(ref, true)`), so `where`-in-`include` keeps meaning what it always
26
- * has here — the walk-depth/caller-directed logic under test is arity-
27
- * agnostic. The to-one-specific behavior this function grew for issue #974
28
- * (a `where` on a to-one include is not something Prisma accepts, so it's
29
- * recorded in `toOneAccessFilters` instead and resolved post-query by
30
- * `resolveToOneAccessVisibility`) has its own dedicated describe blocks below.
31
- */
32
- // A relationship field pointing at another list.
33
- function rel(ref, many = false) {
34
- return { type: 'relationship', ref, many };
35
- }
36
- function makeContext() {
37
- return {
38
- session: null,
39
- _isSudo: false,
40
- _resolveOutputChain: [],
41
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal context for unit test
42
- };
43
- }
44
- // Measure the maximum nesting depth of an include tree.
45
- function includeDepth(include) {
46
- if (!include || typeof include !== 'object')
47
- return 0;
48
- let max = 0;
49
- for (const value of Object.values(include)) {
50
- if (value && typeof value === 'object') {
51
- const nested = value.include;
52
- if (nested)
53
- max = Math.max(max, 1 + includeDepth(nested));
54
- else
55
- max = Math.max(max, 1);
56
- }
57
- else {
58
- max = Math.max(max, 1);
59
- }
60
- }
61
- return max;
62
- }
63
- // A straight-line chain of `count` lists, each with a scalar field and a
64
- // single relationship to the next list: L0 → L1 → … → L(count-1). Every list
65
- // past the root is query-scoped with a filter unique to it, so a test can
66
- // assert the scoped tree actually carries the right `where` at a given hop
67
- // (not just that it happens not to throw). `access.operation.query` is a
68
- // `vi.fn()` on every list so tests can additionally assert which lists' access
69
- // functions were (or were not) invoked.
70
- function chainConfig(count) {
71
- const lists = {};
72
- const queryFns = {};
73
- for (let i = 0; i < count; i++) {
74
- const listName = `L${i}`;
75
- const fields = { name: { type: 'text' } };
76
- if (i < count - 1) {
77
- fields.next = rel(`L${i + 1}.prev`, true);
78
- }
79
- if (i > 0) {
80
- fields.prev = rel(`L${i - 1}.next`, true);
81
- }
82
- const filter = { ownerId: { equals: listName } };
83
- const queryFn = vi.fn(i === 0 ? () => true : () => filter);
84
- queryFns[listName] = queryFn;
85
- lists[listName] = { fields, access: { operation: { query: queryFn } } };
86
- }
87
- return {
88
- config: {
89
- db: { provider: 'sqlite', url: 'file:./dev.db' },
90
- lists,
91
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
92
- },
93
- queryFns,
94
- };
95
- }
96
- // A requested `include` value selecting `next` `hops` more times beyond the
97
- // point at which this value is attached, ending in a bare `true` leaf. E.g.
98
- // `nestedInclude(0) === true` (stop here); `{ include: { next: nestedInclude(2) } }`
99
- // at the top level names 3 hops total (the outer `next` plus 2 more).
100
- function nestedInclude(hops) {
101
- if (hops <= 0)
102
- return true;
103
- return { include: { next: nestedInclude(hops - 1) } };
104
- }
105
- // Read the `where` at the end of a chain of nested `next` includes (used to
106
- // assert row-scoping survived down to a specific hop).
107
- function whereAtHop(scoped, hops) {
108
- let current = scoped;
109
- for (let i = 0; i < hops; i++) {
110
- const entry = current?.next;
111
- if (i === hops - 1)
112
- return entry?.where;
113
- current = entry?.include;
114
- }
115
- return undefined;
116
- }
117
- describe('buildAccessScopedInclude — caller-directed walk (ADR-0026)', () => {
118
- it('does not invoke query access on a relation the request never named', async () => {
119
- // A → B, A → C (siblings). Requesting only `b` must never touch C's
120
- // access function — the core guarantee #852 introduces: a request
121
- // naming one relation no longer walks (and access-checks) every other
122
- // relationship of the list.
123
- const queryB = vi.fn(() => true);
124
- const queryC = vi.fn(() => true);
125
- const config = {
126
- db: { provider: 'sqlite' },
127
- lists: {
128
- A: {
129
- fields: { b: rel('B.a'), c: rel('C.a') },
130
- access: { operation: { query: () => true } },
131
- },
132
- B: {
133
- fields: { name: { type: 'text' } },
134
- access: { operation: { query: queryB } },
135
- },
136
- C: {
137
- fields: { name: { type: 'text' } },
138
- access: { operation: { query: queryC } },
139
- },
140
- },
141
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
142
- };
143
- const { include } = await buildAccessScopedInclude({ b: true }, config.lists.A.fields, { session: null, context: makeContext() }, config, 'A');
144
- expect(include).toEqual({ b: true });
145
- expect(queryB).toHaveBeenCalledTimes(1);
146
- expect(queryC).not.toHaveBeenCalled();
147
- });
148
- it("fetches a named relation's own columns and stops — does not auto-expand its subtree (One hop)", async () => {
149
- const { config, queryFns } = chainConfig(4); // L0 → L1 → L2 → L3
150
- const { include } = await buildAccessScopedInclude({ next: true }, config.lists.L0.fields, { session: null, context: makeContext() }, config, 'L0');
151
- // L1 is fetched and where-scoped; L2/L3 are never reached because the
152
- // request named `next` bare, with no nested `include` beneath it.
153
- expect(include).toEqual({ next: { where: { ownerId: { equals: 'L1' } } } });
154
- expect(includeDepth(include)).toBe(1);
155
- expect(queryFns.L1).toHaveBeenCalledTimes(1);
156
- expect(queryFns.L2).not.toHaveBeenCalled();
157
- expect(queryFns.L3).not.toHaveBeenCalled();
158
- });
159
- it('scopes a nested path at every level the request names it', async () => {
160
- const { config, queryFns } = chainConfig(4); // L0 → L1 → L2 → L3
161
- const { include } = await buildAccessScopedInclude({ next: { include: { next: { include: { next: true } } } } }, config.lists.L0.fields, { session: null, context: makeContext() }, config, 'L0');
162
- expect(include).toEqual({
163
- next: {
164
- where: { ownerId: { equals: 'L1' } },
165
- include: {
166
- next: {
167
- where: { ownerId: { equals: 'L2' } },
168
- include: { next: { where: { ownerId: { equals: 'L3' } } } },
169
- },
170
- },
171
- },
172
- });
173
- expect(queryFns.L1).toHaveBeenCalledTimes(1);
174
- expect(queryFns.L2).toHaveBeenCalledTimes(1);
175
- expect(queryFns.L3).toHaveBeenCalledTimes(1);
176
- });
177
- it('scopes a full cyclic path exactly as requested, one hop stopping the cycle', async () => {
178
- // A → B → C → A. The caller explicitly names the whole cyclic path; the
179
- // walk simply follows the finite literal it was given (no cycle guard
180
- // needed here — that only matters for the declared-dependency fold, see
181
- // declared-dependencies.ts).
182
- const allowQuery = () => true;
183
- const config = {
184
- db: { provider: 'sqlite' },
185
- lists: {
186
- A: { fields: { b: rel('B.a') }, access: { operation: { query: allowQuery } } },
187
- B: { fields: { c: rel('C.b') }, access: { operation: { query: allowQuery } } },
188
- C: { fields: { a: rel('A.c') }, access: { operation: { query: allowQuery } } },
189
- },
190
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
191
- };
192
- const { include } = await buildAccessScopedInclude({ b: { include: { c: { include: { a: true } } } } }, config.lists.A.fields, { session: null, context: makeContext() }, config, 'A');
193
- expect(include).toEqual({ b: { include: { c: { include: { a: true } } } } });
194
- });
195
- });
196
- /**
197
- * A caller-supplied `take` on a to-many relation include must survive
198
- * scoping (issue #752). It only narrows the fetched rows and can never widen
199
- * past the access `where`, so it rides on top of the access filter unchanged.
200
- */
201
- describe('buildAccessScopedInclude — caller take on a to-many relation (issue #752)', () => {
202
- function scopedConfig() {
203
- return {
204
- db: { provider: 'sqlite' },
205
- lists: {
206
- User: {
207
- fields: { name: { type: 'text' }, posts: rel('Post.author', true) },
208
- access: { operation: { query: () => true } },
209
- },
210
- Post: {
211
- fields: { title: { type: 'text' }, author: rel('User.posts') },
212
- access: { operation: { query: () => ({ published: { equals: true } }) } },
213
- },
214
- },
215
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
216
- };
217
- }
218
- it('preserves the take and AND-combines it with the access where', async () => {
219
- const config = scopedConfig();
220
- const { include } = await buildAccessScopedInclude({ posts: { take: 10 } }, config.lists.User.fields, { session: null, context: makeContext() }, config, 'User');
221
- // The bound rides on top of the access filter — neither is dropped. The
222
- // Post→author back-relation is NOT auto-nested (One hop, ADR-0026) since
223
- // the request didn't name it.
224
- expect(include).toEqual({
225
- posts: {
226
- where: { published: { equals: true } },
227
- take: 10,
228
- },
229
- });
230
- });
231
- it('drops a take for a relation whose query access is denied', async () => {
232
- const config = scopedConfig();
233
- config.lists.Post.access = { operation: { query: () => false } };
234
- const { include } = await buildAccessScopedInclude({ posts: { take: 10 } }, config.lists.User.fields, { session: null, context: makeContext() }, config, 'User');
235
- // A denied relation is dropped wholesale — the take cannot resurrect it.
236
- expect(include).toEqual({});
237
- });
238
- });
239
- /**
240
- * Regression coverage for issue #830: the read pipeline used to FAIL OPEN past
241
- * `READ_INCLUDE_MAX_DEPTH` — a caller-supplied `include` nested deeper than the
242
- * engine could scope was passed through unscoped rather than denied. These
243
- * tests pin the exact boundary ADR-0022 introduced and ADR-0026 preserves: a
244
- * request one level past the cap throws, the same request one level
245
- * shallower still works, and a request that never reaches the cap is
246
- * unaffected.
247
- */
248
- describe('buildAccessScopedInclude — fail-closed at the read-include depth cap (#830)', () => {
249
- const HOPS_AT_CAP = READ_INCLUDE_MAX_DEPTH;
250
- it('throws AccessScopeDepthExceededError when the request reaches past the cap', async () => {
251
- const chainLength = HOPS_AT_CAP + 2;
252
- const { config } = chainConfig(chainLength);
253
- // Outer `next` (hop 1) + nestedInclude(HOPS_AT_CAP) (HOPS_AT_CAP more) = HOPS_AT_CAP + 1 hops.
254
- const requested = { next: nestedInclude(HOPS_AT_CAP) };
255
- await expect(buildAccessScopedInclude(requested, config.lists.L0.fields, { session: null, context: makeContext() }, config, 'L0')).rejects.toThrow(AccessScopeDepthExceededError);
256
- });
257
- it('describes a cost refusal, not an inability to scope', async () => {
258
- const chainLength = HOPS_AT_CAP + 2;
259
- const { config } = chainConfig(chainLength);
260
- const requested = { next: nestedInclude(HOPS_AT_CAP) };
261
- await expect(buildAccessScopedInclude(requested, config.lists.L0.fields, { session: null, context: makeContext() }, config, 'L0')).rejects.toThrow(/cost limit/);
262
- });
263
- it('still row-scopes a request one level shallower than the cap', async () => {
264
- const chainLength = HOPS_AT_CAP + 1;
265
- const { config } = chainConfig(chainLength);
266
- // Outer `next` (hop 1) + nestedInclude(HOPS_AT_CAP - 1) = HOPS_AT_CAP hops total — right at the boundary.
267
- const requested = { next: nestedInclude(HOPS_AT_CAP - 1) };
268
- const { include } = await buildAccessScopedInclude(requested, config.lists.L0.fields, { session: null, context: makeContext() }, config, 'L0');
269
- expect(includeDepth(include)).toBe(HOPS_AT_CAP);
270
- expect(whereAtHop(include, HOPS_AT_CAP)).toEqual({ ownerId: { equals: `L${HOPS_AT_CAP}` } });
271
- });
272
- it('does not throw for a request that never reaches the cap', async () => {
273
- const chainLength = HOPS_AT_CAP + 3;
274
- const { config } = chainConfig(chainLength);
275
- await expect(buildAccessScopedInclude({ next: true }, config.lists.L0.fields, { session: null, context: makeContext() }, config, 'L0')).resolves.not.toThrow();
276
- });
277
- it('an empty request never throws, even on a deep schema', async () => {
278
- const chainLength = HOPS_AT_CAP + 3;
279
- const { config } = chainConfig(chainLength);
280
- const { include } = await buildAccessScopedInclude({}, config.lists.L0.fields, { session: null, context: makeContext() }, config, 'L0');
281
- expect(include).toEqual({});
282
- });
283
- it('a declared non-relationship key on a list with no relationships passes through unchanged', async () => {
284
- const config = {
285
- db: { provider: 'sqlite' },
286
- lists: {
287
- Leaf: {
288
- fields: { name: { type: 'text' } },
289
- access: { operation: { query: () => true } },
290
- },
291
- },
292
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
293
- };
294
- // A declared field that isn't a relationship — access control does not
295
- // govern it (e.g. a virtual field named in `include`, stripped later by
296
- // `stripVirtualFieldsFromInclude`).
297
- const { include } = await buildAccessScopedInclude({ name: true }, config.lists.Leaf.fields, { session: null, context: makeContext() }, config, 'Leaf');
298
- expect(include).toEqual({ name: true });
299
- });
300
- it('rejects a key that is neither declared nor a synthetic back-relation (#1082)', async () => {
301
- const config = {
302
- db: { provider: 'sqlite' },
303
- lists: {
304
- Leaf: {
305
- fields: { name: { type: 'text' } },
306
- access: { operation: { query: () => true } },
307
- },
308
- },
309
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
310
- };
311
- await expect(buildAccessScopedInclude({ someUnrelatedKey: true }, config.lists.Leaf.fields, { session: null, context: makeContext() }, config, 'Leaf')).rejects.toThrow(UndeclaredIncludeKeyError);
312
- });
313
- it('a bare `_count: true` on a list with no to-many relations yields no `_count` key at all (#1087)', async () => {
314
- const config = {
315
- db: { provider: 'sqlite' },
316
- lists: {
317
- Leaf: {
318
- fields: { name: { type: 'text' } },
319
- access: { operation: { query: () => true } },
320
- },
321
- },
322
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
323
- };
324
- const { include } = await buildAccessScopedInclude({ _count: true }, config.lists.Leaf.fields, { session: null, context: makeContext() }, config, 'Leaf');
325
- expect(include).toEqual({});
326
- });
327
- });
328
- /**
329
- * Regression coverage for issue #1087: a caller-supplied `_count` in
330
- * `include` used to reach Prisma unscoped (#1082's "Out of scope" — the one
331
- * key `buildAccessScopedInclude`'s own denial rule allowlisted through rather
332
- * than rejecting or scoping). These tests pin the fix: each named relation's
333
- * `_count.select` entry is scoped by that relation's own `query` access,
334
- * exactly like the rest of this module scopes `include`, and a denied
335
- * relation is recorded in `countDenials` for `filterReadableFields` to inject
336
- * `0` for post-query (Prisma cannot be asked for a guaranteed `0`).
337
- */
338
- describe('buildAccessScopedInclude — `_count` is scoped like any other relation (issue #1087)', () => {
339
- function countConfig(postQuery) {
340
- return {
341
- db: { provider: 'sqlite' },
342
- lists: {
343
- User: {
344
- fields: {
345
- name: { type: 'text' },
346
- posts: rel('Post.author', true),
347
- secrets: rel('Secret.owner', true),
348
- },
349
- access: { operation: { query: () => true } },
350
- },
351
- Post: {
352
- fields: { title: { type: 'text' }, author: rel('User.posts') },
353
- access: { operation: { query: postQuery } },
354
- },
355
- Secret: {
356
- fields: { body: { type: 'text' }, owner: rel('User.secrets') },
357
- access: { operation: { query: () => false } },
358
- },
359
- },
360
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
361
- };
362
- }
363
- it('a fully-readable relation counts unchanged', async () => {
364
- const config = countConfig(() => true);
365
- const { include, countDenials } = await buildAccessScopedInclude({ _count: { select: { posts: true } } }, config.lists.User.fields, { session: null, context: makeContext() }, config, 'User');
366
- expect(include).toEqual({ _count: { select: { posts: true } } });
367
- expect(countDenials.keys.size).toBe(0);
368
- });
369
- it('folds the related list row filter into the count select', async () => {
370
- const config = countConfig(() => ({ published: { equals: true } }));
371
- const { include } = await buildAccessScopedInclude({ _count: { select: { posts: true } } }, config.lists.User.fields, { session: null, context: makeContext() }, config, 'User');
372
- expect(include).toEqual({
373
- _count: { select: { posts: { where: { published: { equals: true } } } } },
374
- });
375
- });
376
- it('AND-combines a caller-supplied nested `where` with the access filter, never replacing it', async () => {
377
- const config = countConfig(() => ({ published: { equals: true } }));
378
- const { include } = await buildAccessScopedInclude({ _count: { select: { posts: { where: { title: { contains: 'foo' } } } } } }, config.lists.User.fields, { session: null, context: makeContext() }, config, 'User');
379
- expect(include).toEqual({
380
- _count: {
381
- select: {
382
- posts: {
383
- where: {
384
- AND: [{ published: { equals: true } }, { title: { contains: 'foo' } }],
385
- },
386
- },
387
- },
388
- },
389
- });
390
- });
391
- it('omits a fully-denied relation from the select and records it in `countDenials`', async () => {
392
- const config = countConfig(() => true);
393
- const { include, countDenials } = await buildAccessScopedInclude({ _count: { select: { posts: true, secrets: true } } }, config.lists.User.fields, { session: null, context: makeContext() }, config, 'User');
394
- expect(include).toEqual({ _count: { select: { posts: true } } });
395
- expect(countDenials.keys).toEqual(new Set(['secrets']));
396
- });
397
- it('a wholly-denied `_count.select` omits the `_count` key entirely, still recording the denial', async () => {
398
- const config = countConfig(() => true);
399
- const { include, countDenials } = await buildAccessScopedInclude({ _count: { select: { secrets: true } } }, config.lists.User.fields, { session: null, context: makeContext() }, config, 'User');
400
- expect(include).toEqual({});
401
- expect(countDenials.keys).toEqual(new Set(['secrets']));
402
- });
403
- it('a denied relation resolves to 0 without validating its caller `where` — no field-name/read-access oracle', async () => {
404
- // A caller who cannot read a single `Secret` row supplies a nonsense
405
- // `where` naming a field that doesn't exist. If denial were checked
406
- // AFTER `where` validation, this would throw a `ValidationError` naming
407
- // "Secret"'s fields — letting a caller probe a fully denied list's
408
- // schema. Denial must win first: the count is 0 regardless of `where`.
409
- const config = countConfig(() => true);
410
- const { include, countDenials } = await buildAccessScopedInclude({ _count: { select: { secrets: { where: { bogusField: { equals: 1 } } } } } }, config.lists.User.fields, { session: null, context: makeContext() }, config, 'User');
411
- expect(include).toEqual({});
412
- expect(countDenials.keys).toEqual(new Set(['secrets']));
413
- });
414
- it('rejects a `_count.select` key that is not a countable to-many (undeclared)', async () => {
415
- const config = countConfig(() => true);
416
- await expect(buildAccessScopedInclude({ _count: { select: { nonsense: true } } }, config.lists.User.fields, { session: null, context: makeContext() }, config, 'User')).rejects.toThrow(UndeclaredCountKeyError);
417
- });
418
- it('rejects a `_count.select` key naming a scalar field', async () => {
419
- const config = countConfig(() => true);
420
- await expect(buildAccessScopedInclude({ _count: { select: { name: true } } }, config.lists.User.fields, { session: null, context: makeContext() }, config, 'User')).rejects.toThrow(UndeclaredCountKeyError);
421
- });
422
- it('rejects a `_count.select` key naming a to-one relationship', async () => {
423
- const config = countConfig(() => true);
424
- await expect(buildAccessScopedInclude({ _count: { select: { author: true } } }, config.lists.Post.fields, { session: null, context: makeContext() }, config, 'Post')).rejects.toThrow(UndeclaredCountKeyError);
425
- });
426
- // Issue #1111: a relationship hidden via field-level `read` access must not
427
- // leak its true count through `_count`, even though the related list's rows
428
- // are otherwise fully readable — the same denial an ordinary `include` of
429
- // that field already gets from `filterReadableFields`'s `checkFieldAccess`
430
- // call.
431
- it('omits a relation whose field-level `read` access denies it, even though the related list is fully readable', async () => {
432
- const config = {
433
- db: { provider: 'sqlite' },
434
- lists: {
435
- User: {
436
- fields: {
437
- name: { type: 'text' },
438
- posts: {
439
- type: 'relationship',
440
- ref: 'Post.author',
441
- many: true,
442
- access: { read: () => false },
443
- },
444
- },
445
- access: { operation: { query: () => true } },
446
- },
447
- Post: {
448
- fields: { title: { type: 'text' }, author: rel('User.posts') },
449
- access: { operation: { query: () => true } },
450
- },
451
- },
452
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
453
- };
454
- const { include, countDenials } = await buildAccessScopedInclude({ _count: { select: { posts: true } } }, config.lists.User.fields, { session: null, context: makeContext() }, config, 'User');
455
- expect(include).toEqual({});
456
- expect(countDenials.keys).toEqual(new Set(['posts']));
457
- });
458
- it('does not reject a `_count.select` key naming a synthetic back-relation (#1082)', async () => {
459
- const config = {
460
- db: { provider: 'sqlite' },
461
- lists: {
462
- Category: {
463
- fields: { name: { type: 'text' } },
464
- access: { operation: { query: () => true } },
465
- },
466
- Post: {
467
- fields: {
468
- title: { type: 'text' },
469
- // A list-only ref: no `Category` field names it back, so schema
470
- // generation synthesizes `from_Post_category` on Category.
471
- category: rel('Category'),
472
- },
473
- access: { operation: { query: () => true } },
474
- },
475
- },
476
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
477
- };
478
- const { include } = await buildAccessScopedInclude({ _count: { select: { from_Post_category: true } } }, config.lists.Category.fields, { session: null, context: makeContext() }, config, 'Category');
479
- expect(include).toEqual({ _count: { select: { from_Post_category: true } } });
480
- });
481
- it('`_count: true` also expands to a synthetic back-relation, scoped (#1082/#1087)', async () => {
482
- const config = {
483
- db: { provider: 'sqlite' },
484
- lists: {
485
- Category: {
486
- fields: { name: { type: 'text' } },
487
- access: { operation: { query: () => true } },
488
- },
489
- Post: {
490
- fields: {
491
- title: { type: 'text' },
492
- category: rel('Category'),
493
- },
494
- // A row filter — proves the synthetic relation's count is scoped
495
- // exactly like an explicitly-named one, not merely included.
496
- access: { operation: { query: () => ({ published: { equals: true } }) } },
497
- },
498
- },
499
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
500
- };
501
- const { include } = await buildAccessScopedInclude({ _count: true }, config.lists.Category.fields, { session: null, context: makeContext() }, config, 'Category');
502
- expect(include).toEqual({
503
- _count: { select: { from_Post_category: { where: { published: { equals: true } } } } },
504
- });
505
- });
506
- it('scopes a relation filter nested inside a caller-supplied count `where` (e.g. `_count.select.posts.where.comments.some`)', async () => {
507
- const config = {
508
- db: { provider: 'sqlite' },
509
- lists: {
510
- User: {
511
- fields: { name: { type: 'text' }, posts: rel('Post.author', true) },
512
- access: { operation: { query: () => true } },
513
- },
514
- Post: {
515
- fields: {
516
- title: { type: 'text' },
517
- author: rel('User.posts'),
518
- comments: rel('Comment.post', true),
519
- },
520
- access: { operation: { query: () => true } },
521
- },
522
- Comment: {
523
- fields: { body: { type: 'text' }, post: rel('Post.comments') },
524
- // A row filter one hop past the counted relation — must still be
525
- // folded in, or the resulting post count would reveal whether
526
- // inaccessible comments matching the caller's filter exist.
527
- access: { operation: { query: () => ({ approved: { equals: true } }) } },
528
- },
529
- },
530
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
531
- };
532
- const { include } = await buildAccessScopedInclude({
533
- _count: {
534
- select: {
535
- posts: { where: { comments: { some: { body: { contains: 'hi' } } } } },
536
- },
537
- },
538
- }, config.lists.User.fields, { session: null, context: makeContext() }, config, 'User');
539
- expect(include).toEqual({
540
- _count: {
541
- select: {
542
- posts: {
543
- where: {
544
- comments: {
545
- some: {
546
- AND: [{ approved: { equals: true } }, { body: { contains: 'hi' } }],
547
- },
548
- },
549
- },
550
- },
551
- },
552
- },
553
- });
554
- });
555
- it('resolves a synthetic back-relation named inside a caller-supplied count `where` (#1082/#1092)', async () => {
556
- const config = {
557
- db: { provider: 'sqlite' },
558
- lists: {
559
- User: {
560
- fields: { name: { type: 'text' }, posts: rel('Post.author', true) },
561
- access: { operation: { query: () => true } },
562
- },
563
- Post: {
564
- fields: {
565
- title: { type: 'text' },
566
- author: rel('User.posts'),
567
- // A list-only ref: no `Post` field names it back, so schema
568
- // generation synthesizes `from_Category_posts` on Post.
569
- category: rel('Category'),
570
- },
571
- access: { operation: { query: () => true } },
572
- },
573
- Category: {
574
- fields: {
575
- name: { type: 'text' },
576
- posts: rel('Post', true),
577
- },
578
- // A row filter one hop past the counted relation, reached only
579
- // through the synthetic back-relation — must still be folded in.
580
- access: { operation: { query: () => ({ published: { equals: true } }) } },
581
- },
582
- },
583
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
584
- };
585
- const { include } = await buildAccessScopedInclude({
586
- _count: {
587
- select: {
588
- posts: { where: { from_Category_posts: { some: { name: { contains: 'news' } } } } },
589
- },
590
- },
591
- }, config.lists.User.fields, { session: null, context: makeContext() }, config, 'User');
592
- expect(include).toEqual({
593
- _count: {
594
- select: {
595
- posts: {
596
- where: {
597
- from_Category_posts: {
598
- some: {
599
- AND: [{ published: { equals: true } }, { name: { contains: 'news' } }],
600
- },
601
- },
602
- },
603
- },
604
- },
605
- },
606
- });
607
- });
608
- it('`_count: true` expands to every declared to-many relation, scoped', async () => {
609
- const config = countConfig(() => true);
610
- const { include, countDenials } = await buildAccessScopedInclude({ _count: true }, config.lists.User.fields, { session: null, context: makeContext() }, config, 'User');
611
- expect(include).toEqual({ _count: { select: { posts: true } } });
612
- expect(countDenials.keys).toEqual(new Set(['secrets']));
613
- });
614
- it('scopes `_count` nested inside an ordinary relation include, at that level', async () => {
615
- const config = {
616
- db: { provider: 'sqlite' },
617
- lists: {
618
- Org: {
619
- fields: { name: { type: 'text' }, users: rel('User.org', true) },
620
- access: { operation: { query: () => true } },
621
- },
622
- User: {
623
- fields: {
624
- name: { type: 'text' },
625
- org: rel('Org.users'),
626
- posts: rel('Post.author', true),
627
- },
628
- access: { operation: { query: () => true } },
629
- },
630
- Post: {
631
- fields: { title: { type: 'text' }, author: rel('User.posts') },
632
- access: { operation: { query: () => ({ published: { equals: true } }) } },
633
- },
634
- },
635
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
636
- };
637
- const { include } = await buildAccessScopedInclude({ users: { include: { _count: { select: { posts: true } } } } }, config.lists.Org.fields, { session: null, context: makeContext() }, config, 'Org');
638
- expect(include).toEqual({
639
- users: {
640
- include: { _count: { select: { posts: { where: { published: { equals: true } } } } } },
641
- },
642
- });
643
- });
644
- });
645
- /**
646
- * Regression coverage for issue #974: Prisma accepts a nested `where` on an
647
- * `include` entry only for a to-many relation — the same shape on a to-one
648
- * relation raises `PrismaClientValidationError`. `buildAccessScopedInclude`
649
- * must never attach one for a to-one relation, whatever its related list's
650
- * `query` access resolves to; the scoping information goes into
651
- * `toOneAccessFilters` instead.
652
- */
653
- describe('buildAccessScopedInclude — to-one relations record a post-query filter, not `where` (issue #974)', () => {
654
- function ownerConfig(queryAccess) {
655
- return {
656
- db: { provider: 'sqlite' },
657
- lists: {
658
- Child: {
659
- fields: { name: { type: 'text' }, owner: rel('Owner') },
660
- access: { operation: { query: () => true } },
661
- },
662
- Owner: {
663
- fields: { name: { type: 'text' } },
664
- access: { operation: { query: queryAccess } },
665
- },
666
- },
667
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
668
- };
669
- }
670
- it('records the access filter instead of attaching `where` when the related list scopes by a filter', async () => {
671
- const config = ownerConfig(() => ({ id: { equals: 'u1' } }));
672
- const { include, toOneAccessFilters } = await buildAccessScopedInclude({ owner: true }, config.lists.Child.fields, { session: null, context: makeContext() }, config, 'Child');
673
- // The Prisma-bound include never carries a `where` on this to-one key —
674
- // Prisma would reject it.
675
- expect(include).toEqual({ owner: true });
676
- expect(toOneAccessFilters).toEqual({
677
- filters: {
678
- owner: { kind: 'scoped', relatedListName: 'Owner', accessWhere: { id: { equals: 'u1' } } },
679
- },
680
- nested: {},
681
- });
682
- });
683
- it('leaves a to-one relation whose related list is fully open untouched — no filter recorded, no extra query later', async () => {
684
- const config = ownerConfig(() => true);
685
- const { include, toOneAccessFilters } = await buildAccessScopedInclude({ owner: true }, config.lists.Child.fields, { session: null, context: makeContext() }, config, 'Child');
686
- expect(include).toEqual({ owner: true });
687
- expect(toOneAccessFilters).toEqual({ filters: {}, nested: {} });
688
- });
689
- it('drops a to-one relation whose related list denies query access outright, and records the denial', async () => {
690
- const config = ownerConfig(() => false);
691
- const { include, toOneAccessFilters } = await buildAccessScopedInclude({ owner: true }, config.lists.Child.fields, { session: null, context: makeContext() }, config, 'Child');
692
- // Never asked of Prisma at all — same as before this fix.
693
- expect(include).toEqual({});
694
- expect(toOneAccessFilters).toEqual({ filters: { owner: { kind: 'denied' } }, nested: {} });
695
- });
696
- it('records a to-one filter nested inside another relation the caller explicitly included', async () => {
697
- const config = {
698
- db: { provider: 'sqlite' },
699
- lists: {
700
- GrandChild: {
701
- fields: { name: { type: 'text' }, child: rel('Child') },
702
- access: { operation: { query: () => true } },
703
- },
704
- Child: {
705
- fields: { name: { type: 'text' }, owner: rel('Owner') },
706
- access: { operation: { query: () => true } },
707
- },
708
- Owner: {
709
- fields: { name: { type: 'text' } },
710
- access: { operation: { query: () => ({ id: { equals: 'u1' } }) } },
711
- },
712
- },
713
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
714
- };
715
- const { include, toOneAccessFilters } = await buildAccessScopedInclude({ child: { include: { owner: true } } }, config.lists.GrandChild.fields, { session: null, context: makeContext() }, config, 'GrandChild');
716
- expect(include).toEqual({ child: { include: { owner: true } } });
717
- expect(toOneAccessFilters).toEqual({
718
- filters: {},
719
- nested: {
720
- child: {
721
- filters: {
722
- owner: {
723
- kind: 'scoped',
724
- relatedListName: 'Owner',
725
- accessWhere: { id: { equals: 'u1' } },
726
- },
727
- },
728
- nested: {},
729
- },
730
- },
731
- });
732
- });
733
- });
734
- /**
735
- * Regression coverage for issue #1103: a denied to-MANY relation used to be
736
- * dropped from `include` with nothing recorded, unlike its to-one sibling
737
- * (issue #974, covered above). `filterReadableFields`'s main loop only ever
738
- * visits keys present in the raw row, so an unrecorded denial left the key
739
- * silently absent from the result — `undefined`, not `[]` — breaking the
740
- * fragment API's typed contract (`ResultOf` types a to-many relation as an
741
- * array). These tests pin that a to-many denial is now recorded exactly like
742
- * a to-one one, sharing the same `toOneAccessFilters` tree and `kind:
743
- * 'denied'` entry.
744
- */
745
- describe('buildAccessScopedInclude — to-many relations record a denial too, like to-one (issue #1103)', () => {
746
- function secretsConfig() {
747
- return {
748
- db: { provider: 'sqlite' },
749
- lists: {
750
- Author: {
751
- fields: { name: { type: 'text' }, secrets: rel('Secret.author', true) },
752
- access: { operation: { query: () => true } },
753
- },
754
- Secret: {
755
- fields: { value: { type: 'text' } },
756
- access: { operation: { query: () => false } },
757
- },
758
- },
759
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
760
- };
761
- }
762
- it('drops a to-many relation whose related list denies query access outright, and records the denial', async () => {
763
- const config = secretsConfig();
764
- const { include, toOneAccessFilters } = await buildAccessScopedInclude({ secrets: true }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author');
765
- // Never asked of Prisma at all — same treatment as a denied to-one.
766
- expect(include).toEqual({});
767
- expect(toOneAccessFilters).toEqual({ filters: { secrets: { kind: 'denied' } }, nested: {} });
768
- });
769
- it('records the denial even when the caller also asked for a `take`/`where` — a denied relation has no shape to preserve', async () => {
770
- const config = secretsConfig();
771
- const { include, toOneAccessFilters } = await buildAccessScopedInclude({ secrets: { take: 5, where: { value: { equals: 'x' } } } }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author');
772
- expect(include).toEqual({});
773
- expect(toOneAccessFilters).toEqual({ filters: { secrets: { kind: 'denied' } }, nested: {} });
774
- });
775
- // Code-review finding on #1103's own PR: a caller's `Include` type allows a
776
- // bare `boolean` for a relation, so `{ secrets: false }` (or a conditional
777
- // `{ secrets: cond ? true : undefined }` that resolved to `undefined`)
778
- // explicitly opts the relation OUT — no different from the key being
779
- // absent altogether. Before this guard, the loop evaluated (and, once
780
- // denied, recorded) the key regardless of its value, so a denied relation
781
- // the caller explicitly disabled still ended up forced to `[]` downstream
782
- // by `field-visibility.ts` — surfacing a value for a key nobody asked for.
783
- it('treats an explicit `false` include value as not requested, even when the related list denies query access', async () => {
784
- const config = secretsConfig();
785
- const { include, toOneAccessFilters } = await buildAccessScopedInclude({ secrets: false }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author');
786
- expect(include).toEqual({});
787
- expect(toOneAccessFilters).toEqual({ filters: {}, nested: {} });
788
- });
789
- it('treats an explicit `undefined` include value as not requested, even when the related list denies query access', async () => {
790
- const config = secretsConfig();
791
- const { include, toOneAccessFilters } = await buildAccessScopedInclude({ secrets: undefined }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author');
792
- expect(include).toEqual({});
793
- expect(toOneAccessFilters).toEqual({ filters: {}, nested: {} });
794
- });
795
- it('treats an explicit `false` include value as not requested even when the related list is fully open — never flips it to `true`', async () => {
796
- const config = secretsConfig();
797
- config.lists.Secret.access = { operation: { query: () => true } };
798
- const { include, toOneAccessFilters } = await buildAccessScopedInclude({ secrets: false }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author');
799
- expect(include).toEqual({});
800
- expect(toOneAccessFilters).toEqual({ filters: {}, nested: {} });
801
- });
802
- });
803
- describe('resolveToOneAccessVisibility (issue #974)', () => {
804
- function makeVisibilityContext(findMany) {
805
- return {
806
- session: null,
807
- _isSudo: false,
808
- _resolveOutputChain: [],
809
- prisma: { owner: { findMany } },
810
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal context for unit test
811
- };
812
- }
813
- it('passes a denied filter straight through with no query', async () => {
814
- const findMany = vi.fn();
815
- const context = makeVisibilityContext(findMany);
816
- const resolved = await resolveToOneAccessVisibility([{ id: 'c1' }], { filters: { owner: { kind: 'denied' } }, nested: {} }, { session: null, context });
817
- expect(resolved).toEqual({ filters: { owner: { kind: 'denied' } }, nested: {} });
818
- expect(findMany).not.toHaveBeenCalled();
819
- });
820
- it('skips the query when no row carries a value at the scoped key', async () => {
821
- const findMany = vi.fn();
822
- const context = makeVisibilityContext(findMany);
823
- const tree = {
824
- filters: {
825
- owner: {
826
- kind: 'scoped',
827
- relatedListName: 'Owner',
828
- accessWhere: { id: { equals: 'u1' } },
829
- },
830
- },
831
- nested: {},
832
- };
833
- const resolved = await resolveToOneAccessVisibility([{ id: 'c1', owner: null }], tree, {
834
- session: null,
835
- context,
836
- });
837
- expect(resolved).toEqual({
838
- filters: { owner: { kind: 'visible', ids: new Set() } },
839
- nested: {},
840
- });
841
- expect(findMany).not.toHaveBeenCalled();
842
- });
843
- it('batches every row into ONE existence check, through the raw Prisma client, using the exact access filter', async () => {
844
- const findMany = vi.fn().mockResolvedValue([{ id: 'u1' }, { id: 'u2' }]);
845
- const context = makeVisibilityContext(findMany);
846
- const tree = {
847
- filters: {
848
- owner: {
849
- kind: 'scoped',
850
- relatedListName: 'Owner',
851
- accessWhere: { studioId: { equals: 's1' } },
852
- },
853
- },
854
- nested: {},
855
- };
856
- const items = [
857
- { id: 'c1', owner: { id: 'u1' } },
858
- { id: 'c2', owner: { id: 'u2' } },
859
- { id: 'c3', owner: { id: 'u3' } }, // excluded by the mocked response below
860
- { id: 'c4', owner: null }, // contributes no id
861
- ];
862
- const resolved = await resolveToOneAccessVisibility(items, tree, { session: null, context });
863
- // One call, not one per row.
864
- expect(findMany).toHaveBeenCalledTimes(1);
865
- expect(findMany).toHaveBeenCalledWith({
866
- where: { AND: [{ studioId: { equals: 's1' } }, { id: { in: ['u1', 'u2', 'u3'] } }] },
867
- select: { id: true },
868
- });
869
- expect(resolved.filters.owner).toEqual({ kind: 'visible', ids: new Set(['u1', 'u2']) });
870
- });
871
- it('recurses into nested trees, flattening rows reached through a to-many hop into one batch', async () => {
872
- const ownerFindMany = vi.fn().mockResolvedValue([{ id: 'u1' }]);
873
- const context = {
874
- session: null,
875
- _isSudo: false,
876
- _resolveOutputChain: [],
877
- prisma: { owner: { findMany: ownerFindMany } },
878
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal context for unit test
879
- };
880
- const tree = {
881
- filters: {},
882
- nested: {
883
- children: {
884
- filters: {
885
- owner: {
886
- kind: 'scoped',
887
- relatedListName: 'Owner',
888
- accessWhere: { id: { equals: 'u1' } },
889
- },
890
- },
891
- nested: {},
892
- },
893
- },
894
- };
895
- const items = [
896
- {
897
- id: 'p1',
898
- children: [
899
- { id: 'c1', owner: { id: 'u1' } },
900
- { id: 'c2', owner: { id: 'u9' } },
901
- ],
902
- },
903
- { id: 'p2', children: [{ id: 'c3', owner: { id: 'u1' } }] },
904
- ];
905
- const resolved = await resolveToOneAccessVisibility(items, tree, { session: null, context });
906
- // Every child across BOTH parents resolved in one batched call.
907
- expect(ownerFindMany).toHaveBeenCalledTimes(1);
908
- expect(ownerFindMany).toHaveBeenCalledWith({
909
- where: { AND: [{ id: { equals: 'u1' } }, { id: { in: ['u1', 'u9'] } }] },
910
- select: { id: true },
911
- });
912
- expect(resolved.nested.children.filters.owner).toEqual({
913
- kind: 'visible',
914
- ids: new Set(['u1']),
915
- });
916
- });
917
- });
918
- /**
919
- * Regression coverage for issue #1082: a list-only `ref` (`ref: 'Term'`, no
920
- * target field) makes schema generation synthesize a back-relation on `Term`
921
- * (`from_Bill_term`) that no list config declares. Before this fix,
922
- * `buildAccessScopedInclude` treated any key it couldn't resolve to a
923
- * DECLARED relationship as "not governed by access control" and passed it
924
- * through unchanged — so a caller naming `from_Bill_term` in `include`
925
- * bypassed `Bill`'s own `query` access entirely. These tests pin the fix: a
926
- * synthetic key is scoped exactly like the declared relationship field it
927
- * stands for.
928
- */
929
- describe('buildAccessScopedInclude — synthetic back-relation (#1082)', () => {
930
- // Term ← Bill.term (list-only ref) ← Bill.lineItems (declared, to-many).
931
- // `from_Bill_term` is the back-relation schema generation synthesizes on
932
- // Term; nothing in `Term.fields` declares it.
933
- function syntheticConfig(billQuery) {
934
- const config = {
935
- db: { provider: 'sqlite' },
936
- lists: {
937
- Term: {
938
- fields: { name: { type: 'text' } },
939
- access: { operation: { query: () => true } },
940
- },
941
- Bill: {
942
- fields: {
943
- amount: { type: 'integer' },
944
- term: rel('Term'), // list-only ref — synthesizes `from_Bill_term` on Term
945
- lineItems: rel('LineItem.bill', true),
946
- },
947
- access: { operation: { query: billQuery } },
948
- },
949
- LineItem: {
950
- fields: { sku: { type: 'text' }, bill: rel('Bill.lineItems') },
951
- access: { operation: { query: () => true } },
952
- },
953
- },
954
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
955
- };
956
- return config;
957
- }
958
- it('drops the relation entirely when the owning list denies query access', async () => {
959
- const config = syntheticConfig(() => false);
960
- const { include } = await buildAccessScopedInclude({ from_Bill_term: true }, config.lists.Term.fields, { session: null, context: makeContext() }, config, 'Term');
961
- expect(include).toEqual({});
962
- });
963
- it('AND-folds the owning list access filter with the caller-supplied where', async () => {
964
- const config = syntheticConfig(() => ({ paid: { equals: true } }));
965
- const { include } = await buildAccessScopedInclude({ from_Bill_term: { where: { amount: { gt: 10 } } } }, config.lists.Term.fields, { session: null, context: makeContext() }, config, 'Term');
966
- expect(include).toEqual({
967
- from_Bill_term: {
968
- where: { AND: [{ paid: { equals: true } }, { amount: { gt: 10 } }] },
969
- },
970
- });
971
- });
972
- it('scopes a nested include against the OWNING list fields and consumes depth', async () => {
973
- const config = syntheticConfig(() => true);
974
- const lineItemQuery = vi.fn(() => true);
975
- config.lists.LineItem.access = { operation: { query: lineItemQuery } };
976
- const { include } = await buildAccessScopedInclude({ from_Bill_term: { include: { lineItems: true } } }, config.lists.Term.fields, { session: null, context: makeContext() }, config, 'Term');
977
- // The nested `lineItems` key was resolved against Bill's own fields (not
978
- // Term's, which has no `lineItems` field at all) — proof the recursion
979
- // used the owning list, not the synthetic key's declaring list.
980
- expect(lineItemQuery).toHaveBeenCalledTimes(1);
981
- expect(include).toEqual({ from_Bill_term: { include: { lineItems: true } } });
982
- });
983
- it('a synthetic hop counts toward the read-include depth cap the same as a declared one', async () => {
984
- // A chain like `chainConfig` builds (L0 ↔ L1 ↔ … via declared `next`/`prev`),
985
- // except the FIRST hop is synthetic: L1's `prev` is a list-only ref, so L0
986
- // never declares `next` at all — it only gets `from_L1_prev` synthesized
987
- // onto it. Every hop past that first one is declared, exactly matching the
988
- // mixed synthetic-then-declared case the depth cap must bound identically.
989
- const chainLength = READ_INCLUDE_MAX_DEPTH + 2;
990
- const { config } = chainConfig(chainLength);
991
- delete config.lists.L0.fields.next;
992
- config.lists.L1.fields.prev = rel('L0');
993
- // Outer `from_L1_prev` (hop 1) + nestedInclude(HOPS_AT_CAP) (HOPS_AT_CAP
994
- // more, via the declared `next` chain from L1 onward) = HOPS_AT_CAP + 1.
995
- const requested = { from_L1_prev: nestedInclude(READ_INCLUDE_MAX_DEPTH) };
996
- await expect(buildAccessScopedInclude(requested, config.lists.L0.fields, { session: null, context: makeContext() }, config, 'L0')).rejects.toThrow(AccessScopeDepthExceededError);
997
- });
998
- it('still resolves a synthetic hop one level shallower than the cap', async () => {
999
- const chainLength = READ_INCLUDE_MAX_DEPTH + 1;
1000
- const { config } = chainConfig(chainLength);
1001
- delete config.lists.L0.fields.next;
1002
- config.lists.L1.fields.prev = rel('L0');
1003
- const requested = { from_L1_prev: nestedInclude(READ_INCLUDE_MAX_DEPTH - 1) };
1004
- const { include } = await buildAccessScopedInclude(requested, config.lists.L0.fields, { session: null, context: makeContext() }, config, 'L0');
1005
- expect(includeDepth(include)).toBe(READ_INCLUDE_MAX_DEPTH);
1006
- });
1007
- it('rejects a key that resolves to neither a declared relationship nor a synthetic one', async () => {
1008
- const config = syntheticConfig(() => true);
1009
- await expect(buildAccessScopedInclude({ from_Nonexistent_field: true }, config.lists.Term.fields, { session: null, context: makeContext() }, config, 'Term')).rejects.toThrow(UndeclaredIncludeKeyError);
1010
- });
1011
- });
1012
- /**
1013
- * Regression coverage for issue #1092: a `where`/`orderBy` a caller nests
1014
- * inside an `include` entry reached Prisma with neither #912's key-existence
1015
- * check nor #915's field-read check — a probing oracle over exactly the
1016
- * fields those two tickets close one level up. `secret`/`secretNote` below
1017
- * deny field-level `read` outright; every other field is a normal declared
1018
- * field, so a throw in these tests can only come from the new validation.
1019
- */
1020
- describe('buildAccessScopedInclude — nested where/orderBy validation (#1092)', () => {
1021
- function blogConfig() {
1022
- return {
1023
- db: { provider: 'sqlite' },
1024
- lists: {
1025
- Author: {
1026
- fields: {
1027
- name: { type: 'text' },
1028
- posts: rel('Post.author', true),
1029
- },
1030
- access: { operation: { query: () => true } },
1031
- },
1032
- Post: {
1033
- fields: {
1034
- title: { type: 'text' },
1035
- secret: { type: 'text', access: { read: () => false } },
1036
- author: rel('Author.posts'),
1037
- comments: rel('Comment.post', true),
1038
- },
1039
- access: { operation: { query: () => true } },
1040
- },
1041
- Comment: {
1042
- fields: {
1043
- body: { type: 'text' },
1044
- secretNote: { type: 'text', access: { read: () => false } },
1045
- post: rel('Post.comments'),
1046
- },
1047
- access: { operation: { query: () => true } },
1048
- },
1049
- },
1050
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
1051
- };
1052
- }
1053
- it('throws when a nested `where` names a field the session cannot read', async () => {
1054
- const config = blogConfig();
1055
- await expect(buildAccessScopedInclude({ posts: { where: { secret: { equals: 'x' } } } }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author')).rejects.toThrow(ValidationError);
1056
- await expect(buildAccessScopedInclude({ posts: { where: { secret: { equals: 'x' } } } }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author')).rejects.toThrow(/"secret" is denied by field-level read access/);
1057
- });
1058
- it('throws when a nested `where` names a key the related list does not declare, naming the related list and key', async () => {
1059
- const config = blogConfig();
1060
- await expect(buildAccessScopedInclude({ posts: { where: { bogusField: { equals: 'x' } } } }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author')).rejects.toThrow(/Cannot query "Post" — "bogusField" is not a field of this list/);
1061
- });
1062
- it('applies the same two checks to a nested `orderBy`', async () => {
1063
- const config = blogConfig();
1064
- await expect(buildAccessScopedInclude({ posts: { orderBy: { secret: 'asc' } } }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author')).rejects.toThrow(ValidationError);
1065
- await expect(buildAccessScopedInclude({ posts: { orderBy: { bogusField: 'asc' } } }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author')).rejects.toThrow(/Cannot query "Post"/);
1066
- });
1067
- it('resolves against the RELATED list, not the current one — a key valid on the parent but not the related list is rejected', async () => {
1068
- const config = blogConfig();
1069
- // `name` is declared on Author, not on Post — validating against the
1070
- // wrong list would let this through.
1071
- await expect(buildAccessScopedInclude({ posts: { where: { name: { equals: 'x' } } } }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author')).rejects.toThrow(/Cannot query "Post" — "name"/);
1072
- });
1073
- it('recurses through AND/OR/NOT', async () => {
1074
- const config = blogConfig();
1075
- await expect(buildAccessScopedInclude({
1076
- posts: {
1077
- where: { AND: [{ title: { contains: 'x' } }, { OR: [{ secret: { equals: 'x' } }] }] },
1078
- },
1079
- }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author')).rejects.toThrow(ValidationError);
1080
- });
1081
- it("the key-existence check recurses through a relation quantifier nested inside the entry's own where", async () => {
1082
- // #912's existence check (`validateQueryKeys`) is the reused #912/#915
1083
- // top-level walker, which already recurses through a relation quantifier
1084
- // regardless of caller position — an undeclared key nested that deep
1085
- // still rejects, naming the list it actually resolved against (Comment,
1086
- // not Post).
1087
- const config = blogConfig();
1088
- await expect(buildAccessScopedInclude({ posts: { where: { comments: { some: { bogusField: { equals: 'x' } } } } } }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author')).rejects.toThrow(/Cannot query "Comment" — "bogusField"/);
1089
- });
1090
- it("scopes a relation quantifier nested inside the entry's own where against the DEEPER related list — a read-denied field one hop further out still throws (#916)", async () => {
1091
- // Without this, #1092's fix would only move the oracle one hop further
1092
- // out instead of closing it: `posts: { where: { comments: { some: {...} } } }`
1093
- // names Comment, a list the entry's own #912/#915 checks never reach —
1094
- // only `buildAccessScopedWhere` (#916), reused here, does.
1095
- const config = blogConfig();
1096
- await expect(buildAccessScopedInclude({ posts: { where: { comments: { some: { secretNote: { equals: 'x' } } } } } }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author')).rejects.toThrow(/Cannot query "Comment" — "secretNote"/);
1097
- });
1098
- it("folds the deeper related list's own query access into a relation quantifier nested inside the entry's own where", async () => {
1099
- const config = blogConfig();
1100
- config.lists.Comment.access = {
1101
- operation: { query: () => ({ approved: { equals: true } }) },
1102
- };
1103
- const { include } = await buildAccessScopedInclude({ posts: { where: { comments: { some: { body: { contains: 'hi' } } } } } }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author');
1104
- expect(include).toEqual({
1105
- posts: {
1106
- where: {
1107
- comments: {
1108
- some: { AND: [{ approved: { equals: true } }, { body: { contains: 'hi' } }] },
1109
- },
1110
- },
1111
- },
1112
- });
1113
- });
1114
- it("throws when the deeper related list denies query access outright, matching #916's loud failure", async () => {
1115
- const config = blogConfig();
1116
- config.lists.Comment.access = { operation: { query: () => false } };
1117
- await expect(buildAccessScopedInclude({ posts: { where: { comments: { some: { body: { contains: 'hi' } } } } } }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author')).rejects.toThrow(RelationFilterAccessDeniedError);
1118
- });
1119
- it('recurses through a further nested include, at every level the walk reaches', async () => {
1120
- const config = blogConfig();
1121
- await expect(buildAccessScopedInclude({ posts: { include: { comments: { where: { secretNote: { equals: 'x' } } } } } }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author')).rejects.toThrow(/Cannot query "Comment" — "secretNote"/);
1122
- });
1123
- it('accepts a foreign-key scalar a to-one relationship implies, matching the top-level resolver', async () => {
1124
- const config = blogConfig();
1125
- await expect(buildAccessScopedInclude({ posts: { where: { authorId: { equals: 'a1' } } } }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author')).resolves.not.toThrow();
1126
- });
1127
- it('leaves a legitimate nested where over readable, declared fields unchanged, still AND-combined with the access filter', async () => {
1128
- const config = blogConfig();
1129
- config.lists.Post.access = { operation: { query: () => ({ published: { equals: true } }) } };
1130
- const { include } = await buildAccessScopedInclude({ posts: { where: { title: { contains: 'hello' } } } }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author');
1131
- expect(include).toEqual({
1132
- posts: {
1133
- where: { AND: [{ published: { equals: true } }, { title: { contains: 'hello' } }] },
1134
- },
1135
- });
1136
- });
1137
- it('equivalence: the same read-denied predicate throws whether it names the current list, a relation quantifier, or an include-nested where', async () => {
1138
- // Mirrors the triage comment's three-position table for #1092 — the
1139
- // include-nested position (the one gap) now matches the other two.
1140
- const config = blogConfig();
1141
- await expect(buildAccessScopedInclude({ posts: { where: { secret: { equals: 'x' } } } }, config.lists.Author.fields, { session: null, context: makeContext() }, config, 'Author')).rejects.toThrow(ValidationError);
1142
- });
1143
- describe('synthetic back-relation nested in a where (#1082 interaction)', () => {
1144
- function syntheticNestedConfig() {
1145
- const config = {
1146
- db: { provider: 'sqlite' },
1147
- lists: {
1148
- Company: {
1149
- fields: {
1150
- name: { type: 'text' },
1151
- terms: rel('Term', true),
1152
- },
1153
- access: { operation: { query: () => true } },
1154
- },
1155
- Term: {
1156
- fields: { name: { type: 'text' } },
1157
- access: { operation: { query: () => true } },
1158
- },
1159
- Bill: {
1160
- fields: {
1161
- amount: { type: 'integer' },
1162
- term: rel('Term'), // list-only ref — synthesizes `from_Bill_term` on Term
1163
- },
1164
- access: { operation: { query: () => true } },
1165
- },
1166
- },
1167
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
1168
- };
1169
- return config;
1170
- }
1171
- it('does not throw for a nested predicate naming a synthetic back-relation', async () => {
1172
- const config = syntheticNestedConfig();
1173
- await expect(buildAccessScopedInclude({ terms: { where: { from_Bill_term: { some: { amount: { gt: 5 } } } } } }, config.lists.Company.fields, { session: null, context: makeContext() }, config, 'Company')).resolves.not.toThrow();
1174
- });
1175
- it("recurses into the synthetic's own SOURCE list — an invalid key nested under it still throws, naming that list", async () => {
1176
- const config = syntheticNestedConfig();
1177
- await expect(buildAccessScopedInclude({ terms: { where: { from_Bill_term: { some: { bogusField: { equals: 'x' } } } } } }, config.lists.Company.fields, { session: null, context: makeContext() }, config, 'Company')).rejects.toThrow(/Cannot query "Bill" — "bogusField"/);
1178
- });
1179
- it("folds the synthetic's own SOURCE list's query access into the nested quantifier clause", async () => {
1180
- // Regression coverage for a Codex review finding on #1108: the deeper
1181
- // #916-style scoping originally only recognised a DECLARED
1182
- // relationship — a synthetic key's nested quantifier passed through
1183
- // with neither the source list's `query` access folded in nor its
1184
- // fields' read access checked, even though the shallow #912/#915
1185
- // checks (validateQueryKeys/validateQueryFieldReadAccess) already
1186
- // correctly tolerated and resolved the synthetic key itself.
1187
- const config = syntheticNestedConfig();
1188
- config.lists.Bill.access = { operation: { query: () => ({ paid: { equals: true } }) } };
1189
- const { include } = await buildAccessScopedInclude({ terms: { where: { from_Bill_term: { some: { amount: { gt: 5 } } } } } }, config.lists.Company.fields, { session: null, context: makeContext() }, config, 'Company');
1190
- expect(include).toEqual({
1191
- terms: {
1192
- where: {
1193
- from_Bill_term: {
1194
- some: { AND: [{ paid: { equals: true } }, { amount: { gt: 5 } }] },
1195
- },
1196
- },
1197
- },
1198
- });
1199
- });
1200
- it('throws when a field nested under a synthetic quantifier is denied by field-level read access', async () => {
1201
- const config = syntheticNestedConfig();
1202
- config.lists.Bill.fields.secretAmount = {
1203
- type: 'integer',
1204
- access: { read: () => false },
1205
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal field config for unit test
1206
- };
1207
- await expect(buildAccessScopedInclude({ terms: { where: { from_Bill_term: { some: { secretAmount: { gt: 5 } } } } } }, config.lists.Company.fields, { session: null, context: makeContext() }, config, 'Company')).rejects.toThrow(/"secretAmount" is denied by field-level read access/);
1208
- });
1209
- it("throws when the synthetic's own SOURCE list denies query access outright, matching #916's loud failure", async () => {
1210
- const config = syntheticNestedConfig();
1211
- config.lists.Bill.access = { operation: { query: () => false } };
1212
- await expect(buildAccessScopedInclude({ terms: { where: { from_Bill_term: { some: { amount: { gt: 5 } } } } } }, config.lists.Company.fields, { session: null, context: makeContext() }, config, 'Company')).rejects.toThrow(RelationFilterAccessDeniedError);
1213
- });
1214
- });
1215
- describe("a to-one relation's `is: null`/`isNot: null` inside a nested quantifier (Codex review finding on #1108)", () => {
1216
- // Root -> Parent (to-many, unscoped) -> Owner (to-one, query-scoped by a
1217
- // filter). Parent's own access is `true` (no filter), so the outer
1218
- // AND-fold is a no-op and cannot mask what this test is isolating: the
1219
- // fold that happens INSIDE the quantifier's own value.
1220
- function nullQuantifierConfig() {
1221
- return {
1222
- db: { provider: 'sqlite' },
1223
- lists: {
1224
- Root: {
1225
- fields: { name: { type: 'text' }, parent: rel('Parent', true) },
1226
- access: { operation: { query: () => true } },
1227
- },
1228
- Parent: {
1229
- fields: { name: { type: 'text' }, owner: rel('Owner') },
1230
- access: { operation: { query: () => true } },
1231
- },
1232
- Owner: {
1233
- fields: { name: { type: 'text' } },
1234
- access: { operation: { query: () => ({ secret: { equals: true } }) } },
1235
- },
1236
- },
1237
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- minimal config for unit test
1238
- };
1239
- }
1240
- it('preserves `is: null` rather than inverting it into an access-filter match', async () => {
1241
- // Before this fix, folding the access filter into a quantifier's
1242
- // value unconditionally turned `is: null` ("has no related row") into
1243
- // `is: <accessWhere>` ("has a related row matching the filter") —
1244
- // the opposite of the caller's own predicate.
1245
- const config = nullQuantifierConfig();
1246
- const { include } = await buildAccessScopedInclude({ parent: { where: { owner: { is: null } } } }, config.lists.Root.fields, { session: null, context: makeContext() }, config, 'Root');
1247
- expect(include).toEqual({ parent: { where: { owner: { is: null } } } });
1248
- });
1249
- it('preserves `isNot: null` the same way', async () => {
1250
- const config = nullQuantifierConfig();
1251
- const { include } = await buildAccessScopedInclude({ parent: { where: { owner: { isNot: null } } } }, config.lists.Root.fields, { session: null, context: makeContext() }, config, 'Root');
1252
- expect(include).toEqual({ parent: { where: { owner: { isNot: null } } } });
1253
- });
1254
- });
1255
- });
1256
- //# sourceMappingURL=access-filter.test.js.map