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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (641) hide show
  1. package/CHANGELOG.md +2720 -0
  2. package/README.md +182 -115
  3. package/dist/.build-hash +1 -0
  4. package/dist/access/declared-dependencies.d.ts +102 -88
  5. package/dist/access/declared-dependencies.d.ts.map +1 -1
  6. package/dist/access/declared-dependencies.js +83 -71
  7. package/dist/access/declared-dependencies.js.map +1 -1
  8. package/dist/access/depth-limits.d.ts +4 -0
  9. package/dist/access/depth-limits.d.ts.map +1 -1
  10. package/dist/access/depth-limits.js +4 -0
  11. package/dist/access/depth-limits.js.map +1 -1
  12. package/dist/access/engine.d.ts +68 -20
  13. package/dist/access/engine.d.ts.map +1 -1
  14. package/dist/access/engine.js +151 -37
  15. package/dist/access/engine.js.map +1 -1
  16. package/dist/access/errors.d.ts +33 -48
  17. package/dist/access/errors.d.ts.map +1 -1
  18. package/dist/access/errors.js +73 -63
  19. package/dist/access/errors.js.map +1 -1
  20. package/dist/access/field-access.d.ts +76 -5
  21. package/dist/access/field-access.d.ts.map +1 -1
  22. package/dist/access/field-access.js +235 -61
  23. package/dist/access/field-access.js.map +1 -1
  24. package/dist/access/field-visibility.d.ts +50 -4
  25. package/dist/access/field-visibility.d.ts.map +1 -1
  26. package/dist/access/field-visibility.js +143 -160
  27. package/dist/access/field-visibility.js.map +1 -1
  28. package/dist/access/index.d.ts +5 -12
  29. package/dist/access/index.d.ts.map +1 -1
  30. package/dist/access/index.js +6 -19
  31. package/dist/access/index.js.map +1 -1
  32. package/dist/access/orm-client.d.ts +19 -0
  33. package/dist/access/orm-client.d.ts.map +1 -0
  34. package/dist/access/orm-client.js +37 -0
  35. package/dist/access/orm-client.js.map +1 -0
  36. package/dist/access/query-validation.d.ts +7 -129
  37. package/dist/access/query-validation.d.ts.map +1 -1
  38. package/dist/access/query-validation.js +12 -314
  39. package/dist/access/query-validation.js.map +1 -1
  40. package/dist/access/system-fields.d.ts +2 -0
  41. package/dist/access/system-fields.d.ts.map +1 -0
  42. package/dist/access/system-fields.js +7 -0
  43. package/dist/access/system-fields.js.map +1 -0
  44. package/dist/access/transaction-registry.d.ts +25 -2
  45. package/dist/access/transaction-registry.d.ts.map +1 -1
  46. package/dist/access/transaction-registry.js +34 -17
  47. package/dist/access/transaction-registry.js.map +1 -1
  48. package/dist/access/types.d.ts +217 -131
  49. package/dist/access/types.d.ts.map +1 -1
  50. package/dist/config/field-kind.d.ts +66 -0
  51. package/dist/config/field-kind.d.ts.map +1 -0
  52. package/dist/config/field-kind.js +63 -0
  53. package/dist/config/field-kind.js.map +1 -0
  54. package/dist/config/hook-only-fields.d.ts +3 -0
  55. package/dist/config/hook-only-fields.d.ts.map +1 -0
  56. package/dist/config/hook-only-fields.js +17 -0
  57. package/dist/config/hook-only-fields.js.map +1 -0
  58. package/dist/config/index.d.ts +3 -1
  59. package/dist/config/index.d.ts.map +1 -1
  60. package/dist/config/index.js +6 -3
  61. package/dist/config/index.js.map +1 -1
  62. package/dist/config/mcp-tool-names.d.ts +3 -0
  63. package/dist/config/mcp-tool-names.d.ts.map +1 -0
  64. package/dist/config/mcp-tool-names.js +25 -0
  65. package/dist/config/mcp-tool-names.js.map +1 -0
  66. package/dist/config/nav-count.d.ts.map +1 -1
  67. package/dist/config/nav-count.js +4 -4
  68. package/dist/config/nav-count.js.map +1 -1
  69. package/dist/config/plugin-engine.d.ts +8 -2
  70. package/dist/config/plugin-engine.d.ts.map +1 -1
  71. package/dist/config/plugin-engine.js +102 -38
  72. package/dist/config/plugin-engine.js.map +1 -1
  73. package/dist/config/types.d.ts +966 -614
  74. package/dist/config/types.d.ts.map +1 -1
  75. package/dist/context/apply-defaults.d.ts +18 -1
  76. package/dist/context/apply-defaults.d.ts.map +1 -1
  77. package/dist/context/apply-defaults.js +30 -4
  78. package/dist/context/apply-defaults.js.map +1 -1
  79. package/dist/context/engine-context.d.ts +73 -0
  80. package/dist/context/engine-context.d.ts.map +1 -0
  81. package/dist/context/engine-context.js +67 -0
  82. package/dist/context/engine-context.js.map +1 -0
  83. package/dist/context/hook-pipeline.d.ts +9 -2
  84. package/dist/context/hook-pipeline.d.ts.map +1 -1
  85. package/dist/context/hook-pipeline.js +5 -4
  86. package/dist/context/hook-pipeline.js.map +1 -1
  87. package/dist/context/index.d.ts +98 -89
  88. package/dist/context/index.d.ts.map +1 -1
  89. package/dist/context/index.js +917 -722
  90. package/dist/context/index.js.map +1 -1
  91. package/dist/context/junction.d.ts +59 -0
  92. package/dist/context/junction.d.ts.map +1 -0
  93. package/dist/context/junction.js +126 -0
  94. package/dist/context/junction.js.map +1 -0
  95. package/dist/context/plugin-field-read.d.ts +33 -0
  96. package/dist/context/plugin-field-read.d.ts.map +1 -0
  97. package/dist/context/plugin-field-read.js +41 -0
  98. package/dist/context/plugin-field-read.js.map +1 -0
  99. package/dist/context/plugin-field-write.d.ts +104 -0
  100. package/dist/context/plugin-field-write.d.ts.map +1 -0
  101. package/dist/context/plugin-field-write.js +184 -0
  102. package/dist/context/plugin-field-write.js.map +1 -0
  103. package/dist/context/relationship-input.d.ts +146 -0
  104. package/dist/context/relationship-input.d.ts.map +1 -0
  105. package/dist/context/relationship-input.js +453 -0
  106. package/dist/context/relationship-input.js.map +1 -0
  107. package/dist/context/transaction-boundary.d.ts +54 -28
  108. package/dist/context/transaction-boundary.d.ts.map +1 -1
  109. package/dist/context/transaction-boundary.js +87 -169
  110. package/dist/context/transaction-boundary.js.map +1 -1
  111. package/dist/context/write-pipeline.d.ts +33 -51
  112. package/dist/context/write-pipeline.d.ts.map +1 -1
  113. package/dist/context/write-pipeline.js +372 -185
  114. package/dist/context/write-pipeline.js.map +1 -1
  115. package/dist/contract/dependencies.d.ts +88 -0
  116. package/dist/contract/dependencies.d.ts.map +1 -0
  117. package/dist/contract/dependencies.js +237 -0
  118. package/dist/contract/dependencies.js.map +1 -0
  119. package/dist/contract/derive.d.ts +49 -0
  120. package/dist/contract/derive.d.ts.map +1 -0
  121. package/dist/contract/derive.js +540 -0
  122. package/dist/contract/derive.js.map +1 -0
  123. package/dist/contract/fixtures/contract-configs.d.ts +64 -0
  124. package/dist/contract/fixtures/contract-configs.d.ts.map +1 -0
  125. package/dist/contract/fixtures/contract-configs.js +345 -0
  126. package/dist/contract/fixtures/contract-configs.js.map +1 -0
  127. package/dist/contract/id-boundary.d.ts +53 -0
  128. package/dist/contract/id-boundary.d.ts.map +1 -0
  129. package/dist/contract/id-boundary.js +76 -0
  130. package/dist/contract/id-boundary.js.map +1 -0
  131. package/dist/contract/index.d.ts +8 -0
  132. package/dist/contract/index.d.ts.map +1 -0
  133. package/dist/contract/index.js +11 -0
  134. package/dist/contract/index.js.map +1 -0
  135. package/dist/contract/prisma.d.ts +58 -0
  136. package/dist/contract/prisma.d.ts.map +1 -0
  137. package/dist/contract/prisma.js +282 -0
  138. package/dist/contract/prisma.js.map +1 -0
  139. package/dist/contract/relation-graph.d.ts +70 -0
  140. package/dist/contract/relation-graph.d.ts.map +1 -0
  141. package/dist/contract/relation-graph.js +113 -0
  142. package/dist/contract/relation-graph.js.map +1 -0
  143. package/dist/contract/types.d.ts +135 -0
  144. package/dist/contract/types.d.ts.map +1 -0
  145. package/dist/contract/types.js +2 -0
  146. package/dist/contract/types.js.map +1 -0
  147. package/dist/db/client.d.ts +55 -0
  148. package/dist/db/client.d.ts.map +1 -0
  149. package/dist/db/client.js +73 -0
  150. package/dist/db/client.js.map +1 -0
  151. package/dist/db/dev-database.d.ts +124 -0
  152. package/dist/db/dev-database.d.ts.map +1 -0
  153. package/dist/db/dev-database.js +291 -0
  154. package/dist/db/dev-database.js.map +1 -0
  155. package/dist/db/password-front.d.ts +10 -0
  156. package/dist/db/password-front.d.ts.map +1 -0
  157. package/dist/db/password-front.js +147 -0
  158. package/dist/db/password-front.js.map +1 -0
  159. package/dist/db/process-identity.d.ts +36 -0
  160. package/dist/db/process-identity.d.ts.map +1 -0
  161. package/dist/db/process-identity.js +114 -0
  162. package/dist/db/process-identity.js.map +1 -0
  163. package/dist/db/state-file.d.ts +54 -0
  164. package/dist/db/state-file.d.ts.map +1 -0
  165. package/dist/db/state-file.js +91 -0
  166. package/dist/db/state-file.js.map +1 -0
  167. package/dist/db/url.d.ts +89 -0
  168. package/dist/db/url.d.ts.map +1 -0
  169. package/dist/db/url.js +118 -0
  170. package/dist/db/url.js.map +1 -0
  171. package/dist/extend.d.ts +13 -2
  172. package/dist/extend.d.ts.map +1 -1
  173. package/dist/extend.js +24 -1
  174. package/dist/extend.js.map +1 -1
  175. package/dist/fields/index.d.ts +87 -42
  176. package/dist/fields/index.d.ts.map +1 -1
  177. package/dist/fields/index.js +457 -677
  178. package/dist/fields/index.js.map +1 -1
  179. package/dist/filter/collect.d.ts +3 -4
  180. package/dist/filter/collect.d.ts.map +1 -1
  181. package/dist/filter/collect.js +2 -2
  182. package/dist/filter/collect.js.map +1 -1
  183. package/dist/filter/index.d.ts +1 -2
  184. package/dist/filter/index.d.ts.map +1 -1
  185. package/dist/filter/index.js +0 -1
  186. package/dist/filter/index.js.map +1 -1
  187. package/dist/filter/map.d.ts +12 -5
  188. package/dist/filter/map.d.ts.map +1 -1
  189. package/dist/filter/map.js +47 -19
  190. package/dist/filter/map.js.map +1 -1
  191. package/dist/filter/types.d.ts +10 -24
  192. package/dist/filter/types.d.ts.map +1 -1
  193. package/dist/filter/types.js +2 -11
  194. package/dist/filter/types.js.map +1 -1
  195. package/dist/hooks/index.d.ts +22 -31
  196. package/dist/hooks/index.d.ts.map +1 -1
  197. package/dist/hooks/index.js +33 -37
  198. package/dist/hooks/index.js.map +1 -1
  199. package/dist/hooks/transition-guard.d.ts +61 -0
  200. package/dist/hooks/transition-guard.d.ts.map +1 -0
  201. package/dist/hooks/transition-guard.js +93 -0
  202. package/dist/hooks/transition-guard.js.map +1 -0
  203. package/dist/index.d.ts +52 -16
  204. package/dist/index.d.ts.map +1 -1
  205. package/dist/index.js +105 -51
  206. package/dist/index.js.map +1 -1
  207. package/dist/internal.d.ts +4 -2
  208. package/dist/internal.d.ts.map +1 -1
  209. package/dist/internal.js +16 -0
  210. package/dist/internal.js.map +1 -1
  211. package/dist/lib/case-utils.d.ts +0 -1
  212. package/dist/lib/case-utils.d.ts.map +1 -1
  213. package/dist/lib/case-utils.js +0 -3
  214. package/dist/lib/case-utils.js.map +1 -1
  215. package/dist/lib/client-safe-error.d.ts +9 -0
  216. package/dist/lib/client-safe-error.d.ts.map +1 -0
  217. package/dist/lib/client-safe-error.js +23 -0
  218. package/dist/lib/client-safe-error.js.map +1 -0
  219. package/dist/lib/database-errors.d.ts +78 -0
  220. package/dist/lib/database-errors.d.ts.map +1 -0
  221. package/dist/lib/database-errors.js +148 -0
  222. package/dist/lib/database-errors.js.map +1 -0
  223. package/dist/lib/null-prototype-registry.d.ts +9 -0
  224. package/dist/lib/null-prototype-registry.d.ts.map +1 -0
  225. package/dist/lib/null-prototype-registry.js +11 -0
  226. package/dist/lib/null-prototype-registry.js.map +1 -0
  227. package/dist/lib/prisma-errors.d.ts +30 -32
  228. package/dist/lib/prisma-errors.d.ts.map +1 -1
  229. package/dist/lib/prisma-errors.js +86 -46
  230. package/dist/lib/prisma-errors.js.map +1 -1
  231. package/dist/lib/process-global.d.ts +23 -0
  232. package/dist/lib/process-global.d.ts.map +1 -0
  233. package/dist/lib/process-global.js +33 -0
  234. package/dist/lib/process-global.js.map +1 -0
  235. package/dist/lib/warn-once.d.ts +7 -0
  236. package/dist/lib/warn-once.d.ts.map +1 -0
  237. package/dist/lib/warn-once.js +13 -0
  238. package/dist/lib/warn-once.js.map +1 -0
  239. package/dist/mcp/advertise.d.ts +16 -0
  240. package/dist/mcp/advertise.d.ts.map +1 -0
  241. package/dist/mcp/advertise.js +25 -0
  242. package/dist/mcp/advertise.js.map +1 -0
  243. package/dist/mcp/arguments.d.ts +10 -0
  244. package/dist/mcp/arguments.d.ts.map +1 -0
  245. package/dist/mcp/arguments.js +143 -0
  246. package/dist/mcp/arguments.js.map +1 -0
  247. package/dist/mcp/field-schema.d.ts +50 -5
  248. package/dist/mcp/field-schema.d.ts.map +1 -1
  249. package/dist/mcp/field-schema.js +137 -14
  250. package/dist/mcp/field-schema.js.map +1 -1
  251. package/dist/mcp/handler.d.ts +16 -5
  252. package/dist/mcp/handler.d.ts.map +1 -1
  253. package/dist/mcp/handler.js +404 -126
  254. package/dist/mcp/handler.js.map +1 -1
  255. package/dist/mcp/index.d.ts +1 -0
  256. package/dist/mcp/index.d.ts.map +1 -1
  257. package/dist/mcp/index.js +1 -0
  258. package/dist/mcp/index.js.map +1 -1
  259. package/dist/mcp/projection.d.ts +42 -34
  260. package/dist/mcp/projection.d.ts.map +1 -1
  261. package/dist/mcp/projection.js +246 -200
  262. package/dist/mcp/projection.js.map +1 -1
  263. package/dist/mcp/tool-error.d.ts +8 -0
  264. package/dist/mcp/tool-error.d.ts.map +1 -0
  265. package/dist/mcp/tool-error.js +11 -0
  266. package/dist/mcp/tool-error.js.map +1 -0
  267. package/dist/mcp/types.d.ts +3 -2
  268. package/dist/mcp/types.d.ts.map +1 -1
  269. package/dist/mcp/where-id-boundary.d.ts +28 -0
  270. package/dist/mcp/where-id-boundary.d.ts.map +1 -0
  271. package/dist/mcp/where-id-boundary.js +187 -0
  272. package/dist/mcp/where-id-boundary.js.map +1 -0
  273. package/dist/origin.d.ts +147 -0
  274. package/dist/origin.d.ts.map +1 -0
  275. package/dist/origin.js +191 -0
  276. package/dist/origin.js.map +1 -0
  277. package/dist/query/relationship-options.d.ts +35 -6
  278. package/dist/query/relationship-options.d.ts.map +1 -1
  279. package/dist/query/relationship-options.js +33 -23
  280. package/dist/query/relationship-options.js.map +1 -1
  281. package/dist/secured/aggregate.d.ts +32 -0
  282. package/dist/secured/aggregate.d.ts.map +1 -0
  283. package/dist/secured/aggregate.js +31 -0
  284. package/dist/secured/aggregate.js.map +1 -0
  285. package/dist/secured/include.d.ts +320 -0
  286. package/dist/secured/include.d.ts.map +1 -0
  287. package/dist/secured/include.js +650 -0
  288. package/dist/secured/include.js.map +1 -0
  289. package/dist/secured/lock.d.ts +127 -0
  290. package/dist/secured/lock.d.ts.map +1 -0
  291. package/dist/secured/lock.js +275 -0
  292. package/dist/secured/lock.js.map +1 -0
  293. package/dist/secured/lower.d.ts +82 -0
  294. package/dist/secured/lower.d.ts.map +1 -0
  295. package/dist/secured/lower.js +162 -0
  296. package/dist/secured/lower.js.map +1 -0
  297. package/dist/secured/operators.d.ts +7 -0
  298. package/dist/secured/operators.d.ts.map +1 -0
  299. package/dist/secured/operators.js +18 -0
  300. package/dist/secured/operators.js.map +1 -0
  301. package/dist/secured/read.d.ts +208 -0
  302. package/dist/secured/read.d.ts.map +1 -0
  303. package/dist/secured/read.js +1245 -0
  304. package/dist/secured/read.js.map +1 -0
  305. package/dist/secured/select.d.ts +87 -0
  306. package/dist/secured/select.d.ts.map +1 -0
  307. package/dist/secured/select.js +250 -0
  308. package/dist/secured/select.js.map +1 -0
  309. package/dist/secured/vector.d.ts +58 -0
  310. package/dist/secured/vector.d.ts.map +1 -0
  311. package/dist/secured/vector.js +113 -0
  312. package/dist/secured/vector.js.map +1 -0
  313. package/dist/secured/vocabulary.d.ts +227 -0
  314. package/dist/secured/vocabulary.d.ts.map +1 -0
  315. package/dist/secured/vocabulary.js +578 -0
  316. package/dist/secured/vocabulary.js.map +1 -0
  317. package/dist/secured/write.d.ts +58 -0
  318. package/dist/secured/write.d.ts.map +1 -0
  319. package/dist/secured/write.js +87 -0
  320. package/dist/secured/write.js.map +1 -0
  321. package/dist/testing/context.d.ts +236 -0
  322. package/dist/testing/context.d.ts.map +1 -0
  323. package/dist/testing/context.js +457 -0
  324. package/dist/testing/context.js.map +1 -0
  325. package/dist/testing/escape.d.ts +83 -0
  326. package/dist/testing/escape.d.ts.map +1 -0
  327. package/dist/testing/escape.js +148 -0
  328. package/dist/testing/escape.js.map +1 -0
  329. package/dist/testing/extensions.d.ts +48 -0
  330. package/dist/testing/extensions.d.ts.map +1 -0
  331. package/dist/testing/extensions.js +107 -0
  332. package/dist/testing/extensions.js.map +1 -0
  333. package/dist/testing/index.d.ts +5 -0
  334. package/dist/testing/index.d.ts.map +1 -0
  335. package/dist/testing/index.js +11 -0
  336. package/dist/testing/index.js.map +1 -0
  337. package/dist/testing/plans.d.ts +64 -0
  338. package/dist/testing/plans.d.ts.map +1 -0
  339. package/dist/testing/plans.js +47 -0
  340. package/dist/testing/plans.js.map +1 -0
  341. package/dist/types/context.d.ts +110 -0
  342. package/dist/types/context.d.ts.map +1 -0
  343. package/dist/types/context.js +2 -0
  344. package/dist/types/context.js.map +1 -0
  345. package/dist/types/contract.d.ts +198 -0
  346. package/dist/types/contract.d.ts.map +1 -0
  347. package/dist/types/contract.js +2 -0
  348. package/dist/types/contract.js.map +1 -0
  349. package/dist/types/index.d.ts +6 -0
  350. package/dist/types/index.d.ts.map +1 -0
  351. package/dist/types/index.js +11 -0
  352. package/dist/types/index.js.map +1 -0
  353. package/dist/types/inputs.d.ts +83 -0
  354. package/dist/types/inputs.d.ts.map +1 -0
  355. package/dist/types/inputs.js +2 -0
  356. package/dist/types/inputs.js.map +1 -0
  357. package/dist/types/rows.d.ts +76 -0
  358. package/dist/types/rows.d.ts.map +1 -0
  359. package/dist/types/rows.js +2 -0
  360. package/dist/types/rows.js.map +1 -0
  361. package/dist/types/secured-list.d.ts +396 -0
  362. package/dist/types/secured-list.d.ts.map +1 -0
  363. package/dist/types/secured-list.js +2 -0
  364. package/dist/types/secured-list.js.map +1 -0
  365. package/dist/unsafe.d.ts +162 -0
  366. package/dist/unsafe.d.ts.map +1 -0
  367. package/dist/unsafe.js +177 -0
  368. package/dist/unsafe.js.map +1 -0
  369. package/dist/validation/config-refusal.d.ts +16 -0
  370. package/dist/validation/config-refusal.d.ts.map +1 -0
  371. package/dist/validation/config-refusal.js +2 -0
  372. package/dist/validation/config-refusal.js.map +1 -0
  373. package/dist/validation/database-config.d.ts +19 -0
  374. package/dist/validation/database-config.d.ts.map +1 -0
  375. package/dist/validation/database-config.js +221 -0
  376. package/dist/validation/database-config.js.map +1 -0
  377. package/dist/validation/default-value.d.ts +21 -0
  378. package/dist/validation/default-value.d.ts.map +1 -0
  379. package/dist/validation/default-value.js +72 -0
  380. package/dist/validation/default-value.js.map +1 -0
  381. package/dist/validation/extension-packs.d.ts +11 -0
  382. package/dist/validation/extension-packs.d.ts.map +1 -0
  383. package/dist/validation/extension-packs.js +53 -0
  384. package/dist/validation/extension-packs.js.map +1 -0
  385. package/dist/validation/field-config.d.ts +35 -21
  386. package/dist/validation/field-config.d.ts.map +1 -1
  387. package/dist/validation/field-config.js +51 -41
  388. package/dist/validation/field-config.js.map +1 -1
  389. package/dist/validation/field-names.d.ts +15 -0
  390. package/dist/validation/field-names.d.ts.map +1 -0
  391. package/dist/validation/field-names.js +155 -0
  392. package/dist/validation/field-names.js.map +1 -0
  393. package/dist/validation/identifier-names.d.ts +4 -0
  394. package/dist/validation/identifier-names.d.ts.map +1 -0
  395. package/dist/validation/identifier-names.js +39 -0
  396. package/dist/validation/identifier-names.js.map +1 -0
  397. package/dist/validation/needs-closure.d.ts +20 -30
  398. package/dist/validation/needs-closure.d.ts.map +1 -1
  399. package/dist/validation/needs-closure.js +29 -105
  400. package/dist/validation/needs-closure.js.map +1 -1
  401. package/dist/validation/relations.d.ts +17 -0
  402. package/dist/validation/relations.d.ts.map +1 -0
  403. package/dist/validation/relations.js +268 -0
  404. package/dist/validation/relations.js.map +1 -0
  405. package/dist/validation/schema.d.ts.map +1 -1
  406. package/dist/validation/schema.js +1 -3
  407. package/dist/validation/schema.js.map +1 -1
  408. package/dist/where/like.d.ts +32 -0
  409. package/dist/where/like.d.ts.map +1 -0
  410. package/dist/where/like.js +42 -0
  411. package/dist/where/like.js.map +1 -0
  412. package/package.json +70 -8
  413. package/.turbo/turbo-build.log +0 -4
  414. package/CLAUDE.md +0 -609
  415. package/dist/access/access-filter.d.ts +0 -241
  416. package/dist/access/access-filter.d.ts.map +0 -1
  417. package/dist/access/access-filter.js +0 -692
  418. package/dist/access/access-filter.js.map +0 -1
  419. package/dist/access/access-filter.test.d.ts +0 -2
  420. package/dist/access/access-filter.test.d.ts.map +0 -1
  421. package/dist/access/access-filter.test.js +0 -1256
  422. package/dist/access/access-filter.test.js.map +0 -1
  423. package/dist/access/declared-dependencies.test.d.ts +0 -2
  424. package/dist/access/declared-dependencies.test.d.ts.map +0 -1
  425. package/dist/access/declared-dependencies.test.js +0 -226
  426. package/dist/access/declared-dependencies.test.js.map +0 -1
  427. package/dist/access/denied-relation-visibility.test.d.ts +0 -2
  428. package/dist/access/denied-relation-visibility.test.d.ts.map +0 -1
  429. package/dist/access/denied-relation-visibility.test.js +0 -114
  430. package/dist/access/denied-relation-visibility.test.js.map +0 -1
  431. package/dist/access/engine.test.d.ts +0 -2
  432. package/dist/access/engine.test.d.ts.map +0 -1
  433. package/dist/access/engine.test.js +0 -56
  434. package/dist/access/engine.test.js.map +0 -1
  435. package/dist/access/field-access.test.d.ts +0 -2
  436. package/dist/access/field-access.test.d.ts.map +0 -1
  437. package/dist/access/field-access.test.js +0 -635
  438. package/dist/access/field-access.test.js.map +0 -1
  439. package/dist/access/multi-column-read-write.test.d.ts +0 -2
  440. package/dist/access/multi-column-read-write.test.d.ts.map +0 -1
  441. package/dist/access/multi-column-read-write.test.js +0 -183
  442. package/dist/access/multi-column-read-write.test.js.map +0 -1
  443. package/dist/access/relationship-count.d.ts +0 -98
  444. package/dist/access/relationship-count.d.ts.map +0 -1
  445. package/dist/access/relationship-count.js +0 -262
  446. package/dist/access/relationship-count.js.map +0 -1
  447. package/dist/access/relationship-count.test.d.ts +0 -2
  448. package/dist/access/relationship-count.test.d.ts.map +0 -1
  449. package/dist/access/relationship-count.test.js +0 -247
  450. package/dist/access/relationship-count.test.js.map +0 -1
  451. package/dist/access/relationship-label-filter.d.ts +0 -45
  452. package/dist/access/relationship-label-filter.d.ts.map +0 -1
  453. package/dist/access/relationship-label-filter.js +0 -22
  454. package/dist/access/relationship-label-filter.js.map +0 -1
  455. package/dist/access/relationship-label-filter.test.d.ts +0 -2
  456. package/dist/access/relationship-label-filter.test.d.ts.map +0 -1
  457. package/dist/access/relationship-label-filter.test.js +0 -89
  458. package/dist/access/relationship-label-filter.test.js.map +0 -1
  459. package/dist/access/synthetic-include-read.test.d.ts +0 -2
  460. package/dist/access/synthetic-include-read.test.d.ts.map +0 -1
  461. package/dist/access/synthetic-include-read.test.js +0 -121
  462. package/dist/access/synthetic-include-read.test.js.map +0 -1
  463. package/dist/context/nested-operations.d.ts +0 -74
  464. package/dist/context/nested-operations.d.ts.map +0 -1
  465. package/dist/context/nested-operations.js +0 -847
  466. package/dist/context/nested-operations.js.map +0 -1
  467. package/dist/fields/calendar-day.test.d.ts +0 -2
  468. package/dist/fields/calendar-day.test.d.ts.map +0 -1
  469. package/dist/fields/calendar-day.test.js +0 -246
  470. package/dist/fields/calendar-day.test.js.map +0 -1
  471. package/dist/fields/format-prisma-default.d.ts +0 -35
  472. package/dist/fields/format-prisma-default.d.ts.map +0 -1
  473. package/dist/fields/format-prisma-default.js +0 -49
  474. package/dist/fields/format-prisma-default.js.map +0 -1
  475. package/dist/fields/format-prisma-default.test.d.ts +0 -2
  476. package/dist/fields/format-prisma-default.test.d.ts.map +0 -1
  477. package/dist/fields/format-prisma-default.test.js +0 -54
  478. package/dist/fields/format-prisma-default.test.js.map +0 -1
  479. package/dist/fields/relationship-foreign-key.test.d.ts +0 -2
  480. package/dist/fields/relationship-foreign-key.test.d.ts.map +0 -1
  481. package/dist/fields/relationship-foreign-key.test.js +0 -18
  482. package/dist/fields/relationship-foreign-key.test.js.map +0 -1
  483. package/dist/fields/select.test.d.ts +0 -2
  484. package/dist/fields/select.test.d.ts.map +0 -1
  485. package/dist/fields/select.test.js +0 -279
  486. package/dist/fields/select.test.js.map +0 -1
  487. package/dist/fields/text-keystone-compat.test.d.ts +0 -2
  488. package/dist/fields/text-keystone-compat.test.d.ts.map +0 -1
  489. package/dist/fields/text-keystone-compat.test.js +0 -93
  490. package/dist/fields/text-keystone-compat.test.js.map +0 -1
  491. package/dist/filter/filter.test.d.ts +0 -2
  492. package/dist/filter/filter.test.d.ts.map +0 -1
  493. package/dist/filter/filter.test.js +0 -431
  494. package/dist/filter/filter.test.js.map +0 -1
  495. package/dist/filter/serialize.test.d.ts +0 -2
  496. package/dist/filter/serialize.test.d.ts.map +0 -1
  497. package/dist/filter/serialize.test.js +0 -83
  498. package/dist/filter/serialize.test.js.map +0 -1
  499. package/dist/index.test.d.ts +0 -2
  500. package/dist/index.test.d.ts.map +0 -1
  501. package/dist/index.test.js +0 -33
  502. package/dist/index.test.js.map +0 -1
  503. package/dist/lib/case-utils.test.d.ts +0 -2
  504. package/dist/lib/case-utils.test.d.ts.map +0 -1
  505. package/dist/lib/case-utils.test.js +0 -123
  506. package/dist/lib/case-utils.test.js.map +0 -1
  507. package/dist/query/index.d.ts +0 -127
  508. package/dist/query/index.d.ts.map +0 -1
  509. package/dist/query/index.js +0 -179
  510. package/dist/query/index.js.map +0 -1
  511. package/dist/query/index.test.d.ts +0 -2
  512. package/dist/query/index.test.d.ts.map +0 -1
  513. package/dist/query/index.test.js +0 -632
  514. package/dist/query/index.test.js.map +0 -1
  515. package/dist/query/relationship-options.test.d.ts +0 -2
  516. package/dist/query/relationship-options.test.d.ts.map +0 -1
  517. package/dist/query/relationship-options.test.js +0 -150
  518. package/dist/query/relationship-options.test.js.map +0 -1
  519. package/dist/validation/field-config.test.d.ts +0 -2
  520. package/dist/validation/field-config.test.d.ts.map +0 -1
  521. package/dist/validation/field-config.test.js +0 -159
  522. package/dist/validation/field-config.test.js.map +0 -1
  523. package/dist/validation/schema.test.d.ts +0 -2
  524. package/dist/validation/schema.test.d.ts.map +0 -1
  525. package/dist/validation/schema.test.js +0 -409
  526. package/dist/validation/schema.test.js.map +0 -1
  527. package/docs/type-distribution-fix.md +0 -136
  528. package/src/access/access-filter.test.ts +0 -1919
  529. package/src/access/access-filter.ts +0 -1041
  530. package/src/access/declared-dependencies.test.ts +0 -277
  531. package/src/access/declared-dependencies.ts +0 -220
  532. package/src/access/denied-relation-visibility.test.ts +0 -173
  533. package/src/access/depth-limits.ts +0 -27
  534. package/src/access/engine.test.ts +0 -67
  535. package/src/access/engine.ts +0 -193
  536. package/src/access/errors.ts +0 -242
  537. package/src/access/field-access.test.ts +0 -792
  538. package/src/access/field-access.ts +0 -353
  539. package/src/access/field-transforms.ts +0 -68
  540. package/src/access/field-visibility.ts +0 -569
  541. package/src/access/index.ts +0 -82
  542. package/src/access/multi-column-read-write.test.ts +0 -305
  543. package/src/access/query-validation.ts +0 -486
  544. package/src/access/relationship-count.test.ts +0 -344
  545. package/src/access/relationship-count.ts +0 -346
  546. package/src/access/relationship-label-filter.test.ts +0 -128
  547. package/src/access/relationship-label-filter.ts +0 -63
  548. package/src/access/synthetic-include-read.test.ts +0 -179
  549. package/src/access/transaction-registry.ts +0 -58
  550. package/src/access/types.ts +0 -391
  551. package/src/config/index.ts +0 -177
  552. package/src/config/label.ts +0 -51
  553. package/src/config/nav-count.ts +0 -77
  554. package/src/config/plugin-engine.ts +0 -261
  555. package/src/config/types.ts +0 -3270
  556. package/src/context/apply-defaults.ts +0 -47
  557. package/src/context/hook-pipeline.ts +0 -137
  558. package/src/context/index.ts +0 -1737
  559. package/src/context/nested-operations.ts +0 -1470
  560. package/src/context/transaction-boundary.ts +0 -485
  561. package/src/context/write-pipeline.ts +0 -732
  562. package/src/extend.ts +0 -28
  563. package/src/fields/calendar-day.test.ts +0 -291
  564. package/src/fields/format-prisma-default.test.ts +0 -64
  565. package/src/fields/format-prisma-default.ts +0 -64
  566. package/src/fields/index.ts +0 -1901
  567. package/src/fields/relationship-foreign-key.test.ts +0 -29
  568. package/src/fields/select.test.ts +0 -336
  569. package/src/fields/text-keystone-compat.test.ts +0 -126
  570. package/src/filter/collect.ts +0 -108
  571. package/src/filter/filter.test.ts +0 -538
  572. package/src/filter/index.ts +0 -26
  573. package/src/filter/map.ts +0 -63
  574. package/src/filter/parse.ts +0 -99
  575. package/src/filter/serialize.test.ts +0 -115
  576. package/src/filter/serialize.ts +0 -73
  577. package/src/filter/types.ts +0 -120
  578. package/src/hooks/index.ts +0 -752
  579. package/src/index.test.ts +0 -50
  580. package/src/index.ts +0 -192
  581. package/src/internal.ts +0 -61
  582. package/src/lib/case-utils.test.ts +0 -159
  583. package/src/lib/case-utils.ts +0 -68
  584. package/src/lib/prisma-errors.ts +0 -86
  585. package/src/mcp/constants.ts +0 -24
  586. package/src/mcp/field-schema.ts +0 -84
  587. package/src/mcp/handler.ts +0 -633
  588. package/src/mcp/index.ts +0 -7
  589. package/src/mcp/projection.ts +0 -497
  590. package/src/mcp/types.ts +0 -18
  591. package/src/query/index.test.ts +0 -830
  592. package/src/query/index.ts +0 -352
  593. package/src/query/relationship-options.test.ts +0 -194
  594. package/src/query/relationship-options.ts +0 -78
  595. package/src/utils/password.ts +0 -80
  596. package/src/validation/field-config.test.ts +0 -199
  597. package/src/validation/field-config.ts +0 -139
  598. package/src/validation/needs-closure.ts +0 -188
  599. package/src/validation/schema.test.ts +0 -487
  600. package/src/validation/schema.ts +0 -51
  601. package/tests/access-relationships.test.ts +0 -646
  602. package/tests/access.test.ts +0 -590
  603. package/tests/apply-defaults.test.ts +0 -119
  604. package/tests/bare-read-scalars.test.ts +0 -147
  605. package/tests/computed-field-selective-evaluation.test.ts +0 -418
  606. package/tests/config.test.ts +0 -242
  607. package/tests/context.test.ts +0 -3146
  608. package/tests/default-value-create.test.ts +0 -299
  609. package/tests/field-hooks.test.ts +0 -410
  610. package/tests/field-types.test.ts +0 -1291
  611. package/tests/hook-context-secured.test.ts +0 -424
  612. package/tests/hook-pipeline.test.ts +0 -233
  613. package/tests/hooks.test.ts +0 -481
  614. package/tests/interactive-transaction.test.ts +0 -444
  615. package/tests/label.test.ts +0 -135
  616. package/tests/mcp-fields-projection-access.test.ts +0 -250
  617. package/tests/mcp-handler.test.ts +0 -1411
  618. package/tests/multi-column-validation-ordering.test.ts +0 -305
  619. package/tests/nav-count.test.ts +0 -189
  620. package/tests/needs-declared-dependencies.test.ts +0 -503
  621. package/tests/nested-access-and-hooks.test.ts +0 -2566
  622. package/tests/nested-operation-registry.test.ts +0 -317
  623. package/tests/nested-write-hooks.test.ts +0 -864
  624. package/tests/nested-write-synthetic-relation.test.ts +0 -437
  625. package/tests/password-type-distribution.test.ts +0 -154
  626. package/tests/password-types.test.ts +0 -174
  627. package/tests/password.test.ts +0 -263
  628. package/tests/plugin-engine.test.ts +0 -1155
  629. package/tests/prisma-errors.test.ts +0 -141
  630. package/tests/resolve-chain.test.ts +0 -411
  631. package/tests/singleton.test.ts +0 -421
  632. package/tests/sudo.test.ts +0 -676
  633. package/tests/to-one-include-access-filter.test.ts +0 -172
  634. package/tests/transaction-boundary-hooks.test.ts +0 -710
  635. package/tests/transaction-boundary-outermost.test.ts +0 -530
  636. package/tests/virtual-fields.test.ts +0 -421
  637. package/tests/with-session.test.ts +0 -243
  638. package/tests/write-pipeline.test.ts +0 -617
  639. package/tsconfig.json +0 -12
  640. package/tsconfig.tsbuildinfo +0 -1
  641. package/vitest.config.ts +0 -69
@@ -1,792 +0,0 @@
1
- import { describe, it, expect, expectTypeOf } from 'vitest'
2
- import {
3
- checkFieldAccess,
4
- filterWritableFields,
5
- isFieldReadableForPredicate,
6
- } from './field-access.js'
7
- import { InvalidFieldAccessResultError } from './errors.js'
8
- import { ValidationError } from '../hooks/index.js'
9
- import type { FieldAccess, FieldAccessControl } from './types.js'
10
-
11
- // A non-sudo access context. The cast is localized to test setup (mirrors the
12
- // existing sudo-context casts in this file): the runtime AccessContext carries
13
- // Prisma plumbing the unit under test never touches.
14
- function nonSudoContext() {
15
- return {
16
- session: null,
17
- _isSudo: false,
18
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
- } as any
20
- }
21
-
22
- function sudoContext() {
23
- return {
24
- session: null,
25
- _isSudo: true,
26
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
- } as any
28
- }
29
-
30
- // ── #914: `FieldAccess['read']`'s `item` must type as present, matching what
31
- // Field Visibility (field-visibility.ts) actually passes ──
32
-
33
- describe("FieldAccess['read'] item typing (issue #914)", () => {
34
- type Item = { ownerId: string }
35
-
36
- it('types item as present for a read rule that reads a property off it — no cast, no `any`', () => {
37
- const fieldAccess: FieldAccess<Item> = {
38
- read: ({ session, item }) => item.ownerId === session?.userId,
39
- }
40
- expect(typeof fieldAccess.read).toBe('function')
41
- })
42
-
43
- it('still compiles a read rule that ignores item entirely', () => {
44
- const fieldAccess: FieldAccess<Item> = {
45
- read: () => true,
46
- }
47
- expect(typeof fieldAccess.read).toBe('function')
48
- })
49
-
50
- it('leaves the create branch unchanged — item is still absent, there genuinely is no row yet', () => {
51
- // Pinned against `FieldAccessControl`'s discriminated union directly
52
- // (rather than `FieldAccess['create']`'s destructured callback), because
53
- // `create`/`update` — unlike `read` — are untouched by this fix and keep
54
- // accepting the full `FieldAccessControl` union in `FieldAccess`.
55
- type CreateArgs = Extract<Parameters<FieldAccessControl<Item>>[0], { operation: 'create' }>
56
- expectTypeOf<CreateArgs['item']>().toEqualTypeOf<undefined>()
57
- })
58
-
59
- // Type-level pin: `resolveReadableFieldValue` (field-visibility.ts) is the
60
- // sole caller of `checkFieldAccess` for `operation: 'read'`, and always
61
- // supplies `item: accessItem` — a full row, never `undefined`. This
62
- // assertion has no runtime effect (`expectTypeOf` is a no-op outside
63
- // `vitest --typecheck`); its value is that `pnpm build`/`tsc` fails on this
64
- // file the moment `FieldAccess['read']`'s `item` type drifts back to
65
- // optional/absent, so the declared type and the call site cannot silently
66
- // diverge again.
67
- it("pins FieldAccess['read']'s item type against the field-visibility.ts call site", () => {
68
- type ReadArgs = Parameters<NonNullable<FieldAccess<Item>['read']>>[0]
69
- expectTypeOf<ReadArgs['item']>().toEqualTypeOf<Item>()
70
- expectTypeOf<ReadArgs['operation']>().toEqualTypeOf<'read'>()
71
- })
72
- })
73
-
74
- // ── #913: a field rule returning a filter must not be granted blanket access ──
75
-
76
- describe('checkFieldAccess', () => {
77
- it('allows when the rule returns true', async () => {
78
- const allowed = await checkFieldAccess({ read: () => true }, 'read', {
79
- session: null,
80
- item: { ownerId: 'someone-else' },
81
- context: nonSudoContext(),
82
- })
83
- expect(allowed).toBe(true)
84
- })
85
-
86
- it('denies when the rule returns false', async () => {
87
- const allowed = await checkFieldAccess({ read: () => false }, 'read', {
88
- session: null,
89
- item: { ownerId: 'someone-else' },
90
- context: nonSudoContext(),
91
- })
92
- expect(allowed).toBe(false)
93
- })
94
-
95
- it('allows when no field access is configured', async () => {
96
- const allowed = await checkFieldAccess(undefined, 'read', {
97
- session: null,
98
- context: nonSudoContext(),
99
- })
100
- expect(allowed).toBe(true)
101
- })
102
-
103
- it('allows when no rule is configured for the operation', async () => {
104
- const allowed = await checkFieldAccess({ update: () => false }, 'read', {
105
- session: null,
106
- context: nonSudoContext(),
107
- })
108
- expect(allowed).toBe(true)
109
- })
110
-
111
- it('throws InvalidFieldAccessResultError, not allow, when a read rule returns a filter', async () => {
112
- // The exact reproduction from the issue: a rule written to scope a field
113
- // by row, which the previous fail-open default granted full access to.
114
- const fieldAccess = {
115
- read: () => ({ ownerId: { equals: 'someone-else' } }),
116
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
117
- } as any
118
-
119
- await expect(
120
- checkFieldAccess(fieldAccess, 'read', {
121
- session: null,
122
- item: { ownerId: 'the-owner' },
123
- context: nonSudoContext(),
124
- }),
125
- ).rejects.toThrow(InvalidFieldAccessResultError)
126
- })
127
-
128
- it('throws for a filter-returning rule on create, where there is no item to test it against', async () => {
129
- const fieldAccess = {
130
- create: () => ({ ownerId: { equals: 'someone-else' } }),
131
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
132
- } as any
133
-
134
- await expect(
135
- checkFieldAccess(fieldAccess, 'create', {
136
- session: null,
137
- context: nonSudoContext(),
138
- inputData: { ownerId: 'the-owner' },
139
- }),
140
- ).rejects.toThrow(InvalidFieldAccessResultError)
141
- })
142
-
143
- it('throws for a filter-returning rule on update', async () => {
144
- const fieldAccess = {
145
- update: () => ({ ownerId: { equals: 'someone-else' } }),
146
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
147
- } as any
148
-
149
- await expect(
150
- checkFieldAccess(fieldAccess, 'update', {
151
- session: null,
152
- item: { ownerId: 'the-owner' },
153
- context: nonSudoContext(),
154
- inputData: { ownerId: 'someone-else' },
155
- }),
156
- ).rejects.toThrow(InvalidFieldAccessResultError)
157
- })
158
-
159
- it('throws for a non-boolean, non-filter result too (e.g. undefined)', async () => {
160
- const fieldAccess = {
161
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
162
- read: () => undefined as any,
163
- }
164
-
165
- await expect(
166
- checkFieldAccess(fieldAccess, 'read', {
167
- session: null,
168
- item: {},
169
- context: nonSudoContext(),
170
- }),
171
- ).rejects.toThrow(InvalidFieldAccessResultError)
172
- })
173
-
174
- it('throws with a descriptive message for null, and for other primitive results', async () => {
175
- const nullAccess = {
176
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
177
- read: () => null as any,
178
- }
179
- await expect(
180
- checkFieldAccess(nullAccess, 'read', {
181
- session: null,
182
- item: {},
183
- context: nonSudoContext(),
184
- }),
185
- ).rejects.toThrow(/returned null, not a boolean/)
186
-
187
- const numberAccess = {
188
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
189
- read: () => 42 as any,
190
- }
191
- await expect(
192
- checkFieldAccess(numberAccess, 'read', {
193
- session: null,
194
- item: {},
195
- context: nonSudoContext(),
196
- }),
197
- ).rejects.toThrow(/returned a number, not a boolean/)
198
- })
199
-
200
- it('sudo bypasses the rule entirely, so a filter-returning rule never reaches the throw', async () => {
201
- const fieldAccess = {
202
- read: () => ({ ownerId: { equals: 'someone-else' } }),
203
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
204
- } as any
205
-
206
- const allowed = await checkFieldAccess(fieldAccess, 'read', {
207
- session: null,
208
- item: { ownerId: 'the-owner' },
209
- context: sudoContext(),
210
- })
211
- expect(allowed).toBe(true)
212
- })
213
- })
214
-
215
- describe('isFieldReadableForPredicate (#915)', () => {
216
- it('allows when there is no field access configured', async () => {
217
- const readable = await isFieldReadableForPredicate(undefined, {
218
- session: null,
219
- context: nonSudoContext(),
220
- })
221
- expect(readable).toBe(true)
222
- })
223
-
224
- it('allows when the rule only inspects session (never touches item)', async () => {
225
- const readable = await isFieldReadableForPredicate(
226
- { read: ({ session }) => session?.userId === 'admin' },
227
- { session: { userId: 'admin' }, context: nonSudoContext() },
228
- )
229
- expect(readable).toBe(true)
230
- })
231
-
232
- it('denies when the rule returns false', async () => {
233
- const readable = await isFieldReadableForPredicate(
234
- { read: () => false },
235
- { session: null, context: nonSudoContext() },
236
- )
237
- expect(readable).toBe(false)
238
- })
239
-
240
- it('denies a row-dependent rule that dereferences `item` directly', async () => {
241
- const readable = await isFieldReadableForPredicate(
242
- { read: ({ item, session }) => item.ownerId === session?.userId },
243
- { session: { userId: 'user-1' }, context: nonSudoContext() },
244
- )
245
- expect(readable).toBe(false)
246
- })
247
-
248
- it('denies a row-dependent rule even when it reads `item` via optional chaining', async () => {
249
- // This is the exact idiom `InvalidFieldAccessResultError`'s own message
250
- // recommends (`item?.ownerId === session?.userId`) — it must still deny,
251
- // not silently misevaluate `undefined === session?.userId` against a
252
- // poisoned `item`.
253
- const readable = await isFieldReadableForPredicate(
254
- { read: ({ item, session }) => item?.ownerId === session?.userId },
255
- { session: null, context: nonSudoContext() },
256
- )
257
- expect(readable).toBe(false)
258
- })
259
-
260
- it('denies a row-dependent rule that only enumerates `item`s keys', async () => {
261
- const readable = await isFieldReadableForPredicate(
262
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
263
- { read: ({ item }) => Object.keys(item as any).length > 0 },
264
- { session: null, context: nonSudoContext() },
265
- )
266
- expect(readable).toBe(false)
267
- })
268
-
269
- it('propagates InvalidFieldAccessResultError instead of folding it into a denial', async () => {
270
- const fieldAccess = {
271
- read: () => ({ ownerId: { equals: 'someone-else' } }),
272
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
273
- } as any
274
-
275
- await expect(
276
- isFieldReadableForPredicate(fieldAccess, { session: null, context: nonSudoContext() }),
277
- ).rejects.toThrow(InvalidFieldAccessResultError)
278
- })
279
-
280
- it('propagates a genuine error the rule throws for its own reasons, not just non-boolean results', async () => {
281
- // The rule never touches `item` — it throws for a reason of its own.
282
- // This must NOT be folded into an ordinary `false` denial (that would
283
- // mask a real bug in the rule as "field not readable"), matching how the
284
- // post-query path (`filterReadableFields`) already lets such a throw
285
- // propagate unchanged.
286
- const fieldAccess: FieldAccess = {
287
- read: ({ session }) => {
288
- if (session === null) throw new Error('unexpected anonymous access')
289
- return true
290
- },
291
- }
292
-
293
- await expect(
294
- isFieldReadableForPredicate(fieldAccess, { session: null, context: nonSudoContext() }),
295
- ).rejects.toThrow('unexpected anonymous access')
296
- })
297
-
298
- it('sudo bypasses the rule entirely, so a row-dependent rule never denies', async () => {
299
- const readable = await isFieldReadableForPredicate(
300
- { read: ({ item, session }) => item.ownerId === session?.userId },
301
- { session: null, context: sudoContext() },
302
- )
303
- expect(readable).toBe(true)
304
- })
305
- })
306
-
307
- describe('filterWritableFields', () => {
308
- it('should filter out foreign key fields when their corresponding relationship field exists', async () => {
309
- // Setup: Define field configs with a relationship field
310
- const fieldConfigs = {
311
- title: {
312
- type: 'text',
313
- },
314
- author: {
315
- type: 'relationship',
316
- many: false,
317
- },
318
- tags: {
319
- type: 'relationship',
320
- many: true, // Many-to-many relationships don't have foreign keys
321
- },
322
- }
323
-
324
- // Data that includes both the foreign key (authorId) and other fields
325
- const data = {
326
- title: 'Test Post',
327
- authorId: 'user-123', // This should be filtered out
328
- tagsId: 'tag-456', // This should NOT be filtered (tags is many:true)
329
- author: {
330
- connect: { id: 'user-123' },
331
- },
332
- }
333
-
334
- const filtered = await filterWritableFields(data, fieldConfigs, 'create', {
335
- session: null,
336
- context: {
337
- session: null,
338
- _isSudo: true, // Use sudo to bypass access control checks
339
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
340
- } as any,
341
- inputData: data,
342
- })
343
-
344
- // authorId should be filtered out
345
- expect(filtered).not.toHaveProperty('authorId')
346
-
347
- // title should remain
348
- expect(filtered).toHaveProperty('title', 'Test Post')
349
-
350
- // author relationship should remain
351
- expect(filtered).toHaveProperty('author')
352
- expect(filtered.author).toEqual({ connect: { id: 'user-123' } })
353
-
354
- // tagsId should remain (tags is many:true, so no foreign key is created)
355
- expect(filtered).toHaveProperty('tagsId', 'tag-456')
356
- })
357
-
358
- it('should filter out system fields', async () => {
359
- const fieldConfigs = {
360
- title: { type: 'text' },
361
- }
362
-
363
- const data = {
364
- id: 'post-123',
365
- title: 'Test',
366
- createdAt: new Date(),
367
- updatedAt: new Date(),
368
- }
369
-
370
- const filtered = await filterWritableFields(data, fieldConfigs, 'create', {
371
- session: null,
372
- context: {
373
- session: null,
374
- _isSudo: true,
375
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
376
- } as any,
377
- inputData: data,
378
- })
379
-
380
- // System fields should be filtered out
381
- expect(filtered).not.toHaveProperty('id')
382
- expect(filtered).not.toHaveProperty('createdAt')
383
- expect(filtered).not.toHaveProperty('updatedAt')
384
-
385
- // Regular fields should remain
386
- expect(filtered).toHaveProperty('title', 'Test')
387
- })
388
-
389
- it('should handle update operation', async () => {
390
- const fieldConfigs = {
391
- title: { type: 'text' },
392
- author: {
393
- type: 'relationship',
394
- many: false,
395
- },
396
- }
397
-
398
- const data = {
399
- title: 'Updated Title',
400
- authorId: 'user-456', // Should be filtered out
401
- author: {
402
- connect: { id: 'user-456' },
403
- },
404
- }
405
-
406
- const filtered = await filterWritableFields(data, fieldConfigs, 'update', {
407
- session: null,
408
- item: { id: 'post-123' },
409
- context: {
410
- session: null,
411
- _isSudo: true,
412
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
413
- } as any,
414
- inputData: data,
415
- })
416
-
417
- expect(filtered).not.toHaveProperty('authorId')
418
- expect(filtered).toHaveProperty('title', 'Updated Title')
419
- expect(filtered).toHaveProperty('author')
420
- })
421
-
422
- it('should not filter fields that happen to end with "Id" but are not foreign keys', async () => {
423
- const fieldConfigs = {
424
- trackingId: { type: 'text' }, // Regular field that happens to end with "Id"
425
- author: {
426
- type: 'relationship',
427
- many: false,
428
- },
429
- }
430
-
431
- const data = {
432
- trackingId: 'track-123', // Should NOT be filtered (it's a regular field)
433
- authorId: 'user-456', // SHOULD be filtered (it's a foreign key)
434
- }
435
-
436
- const filtered = await filterWritableFields(data, fieldConfigs, 'create', {
437
- session: null,
438
- context: {
439
- session: null,
440
- _isSudo: true,
441
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
442
- } as any,
443
- inputData: data,
444
- })
445
-
446
- // trackingId is a defined field, so it should remain
447
- expect(filtered).toHaveProperty('trackingId', 'track-123')
448
-
449
- // authorId is a foreign key for author relationship, so it should be filtered
450
- expect(filtered).not.toHaveProperty('authorId')
451
- })
452
-
453
- // ── #564: undeclared data keys must fail CLOSED (throw) for non-sudo writes ──
454
-
455
- it('throws on an undeclared data key for a non-sudo create', async () => {
456
- const fieldConfigs = { title: { type: 'text' } }
457
- const data = {
458
- title: 'Test',
459
- // Not a declared field — e.g. a Prisma back-relation the config never
460
- // exposed (`from_Enrolment_student`). Must be rejected, not passed through.
461
- from_Enrolment_student: { disconnect: [{ id: 'e1' }] },
462
- }
463
-
464
- await expect(
465
- filterWritableFields(data, fieldConfigs, 'create', {
466
- session: null,
467
- context: nonSudoContext(),
468
- inputData: data,
469
- }),
470
- ).rejects.toThrow(ValidationError)
471
- await expect(
472
- filterWritableFields(data, fieldConfigs, 'create', {
473
- session: null,
474
- context: nonSudoContext(),
475
- inputData: data,
476
- }),
477
- ).rejects.toThrow(/from_Enrolment_student/)
478
- })
479
-
480
- it('throws on an undeclared data key for a non-sudo update', async () => {
481
- const fieldConfigs = { title: { type: 'text' } }
482
- const data = {
483
- title: 'Updated',
484
- bogusKey: 'value',
485
- }
486
-
487
- await expect(
488
- filterWritableFields(data, fieldConfigs, 'update', {
489
- session: null,
490
- item: { id: 'post-1' },
491
- context: nonSudoContext(),
492
- inputData: data,
493
- }),
494
- ).rejects.toThrow(/bogusKey/)
495
- })
496
-
497
- it('passes undeclared data keys through under sudo (the single trusted bypass)', async () => {
498
- const fieldConfigs = { title: { type: 'text' } }
499
- const data = {
500
- title: 'Test',
501
- from_Enrolment_student: { disconnect: [{ id: 'e1' }] },
502
- }
503
-
504
- const filtered = await filterWritableFields(data, fieldConfigs, 'create', {
505
- session: null,
506
- context: sudoContext(),
507
- inputData: data,
508
- })
509
-
510
- expect(filtered).toHaveProperty('title', 'Test')
511
- expect(filtered).toHaveProperty('from_Enrolment_student')
512
- })
513
-
514
- it('still skips system fields and relationship FK fields cleanly for a non-sudo write', async () => {
515
- const fieldConfigs = {
516
- title: { type: 'text' },
517
- author: { type: 'relationship', many: false },
518
- }
519
- const data = {
520
- id: 'post-1',
521
- createdAt: new Date(),
522
- updatedAt: new Date(),
523
- title: 'Test',
524
- authorId: 'user-1', // FK skipped, not rejected
525
- }
526
-
527
- const filtered = await filterWritableFields(data, fieldConfigs, 'create', {
528
- session: null,
529
- context: nonSudoContext(),
530
- inputData: data,
531
- })
532
-
533
- expect(filtered).not.toHaveProperty('id')
534
- expect(filtered).not.toHaveProperty('createdAt')
535
- expect(filtered).not.toHaveProperty('updatedAt')
536
- expect(filtered).not.toHaveProperty('authorId')
537
- expect(filtered).toHaveProperty('title', 'Test')
538
- })
539
-
540
- it('passes through raw per-part columns from a multi-column field whose write access ALLOWS (non-sudo)', async () => {
541
- // Multi-column fields inject raw columns (e.g. m_url/m_size) that are not
542
- // declared in fieldConfigs; they must not trip the undeclared-key reject.
543
- // With no field-level access (allow), they pass through.
544
- const fieldConfigs = {
545
- media: {
546
- type: 'image',
547
- getColumnNames: (fieldName: string) => [`${fieldName}_url`, `${fieldName}_size`],
548
- },
549
- }
550
- const data = {
551
- media_url: 'https://x/y.jpg',
552
- media_size: 99,
553
- }
554
-
555
- const filtered = await filterWritableFields(data, fieldConfigs, 'create', {
556
- session: null,
557
- context: nonSudoContext(),
558
- inputData: data,
559
- })
560
-
561
- expect(filtered).toHaveProperty('media_url', 'https://x/y.jpg')
562
- expect(filtered).toHaveProperty('media_size', 99)
563
- })
564
-
565
- it('THROWS when raw split columns are supplied for a field whose write access is DENIED (non-sudo)', async () => {
566
- // Security (#568): a non-sudo caller who supplies the raw per-part columns
567
- // DIRECTLY must not bypass the owning field's write-access gate. The
568
- // logical-key gate in the hooks layer never fires here (no `media` key), so
569
- // this filter is the only enforcement point — it must throw.
570
- const fieldConfigs = {
571
- media: {
572
- type: 'image',
573
- access: { create: () => false, update: () => false },
574
- getColumnNames: (fieldName: string) => [`${fieldName}_url`, `${fieldName}_size`],
575
- },
576
- }
577
- const data = {
578
- media_url: 'https://evil/x.jpg',
579
- media_size: 1,
580
- }
581
-
582
- // Throws ValidationError, and the message names the owning field.
583
- await expect(
584
- filterWritableFields(data, fieldConfigs, 'create', {
585
- session: null,
586
- context: nonSudoContext(),
587
- inputData: data,
588
- }),
589
- ).rejects.toThrow(ValidationError)
590
- await expect(
591
- filterWritableFields(data, fieldConfigs, 'update', {
592
- session: null,
593
- item: { id: 'item-1' },
594
- context: nonSudoContext(),
595
- inputData: data,
596
- }),
597
- ).rejects.toThrow(/media/)
598
- })
599
-
600
- it('passes raw split columns through under sudo regardless of denied owning-field access', async () => {
601
- // sudo is the single trusted bypass; `checkFieldAccess` returns true under
602
- // sudo, so even a would-be-denied multi-column field passes through.
603
- const fieldConfigs = {
604
- media: {
605
- type: 'image',
606
- access: { create: () => false, update: () => false },
607
- getColumnNames: (fieldName: string) => [`${fieldName}_url`, `${fieldName}_size`],
608
- },
609
- }
610
- const data = {
611
- media_url: 'https://x/y.jpg',
612
- media_size: 99,
613
- }
614
-
615
- const filtered = await filterWritableFields(data, fieldConfigs, 'create', {
616
- session: null,
617
- context: sudoContext(),
618
- inputData: data,
619
- })
620
-
621
- expect(filtered).toHaveProperty('media_url', 'https://x/y.jpg')
622
- expect(filtered).toHaveProperty('media_size', 99)
623
- })
624
-
625
- // ── #568: field-access-denied keys must THROW, not be silently stripped ──────
626
-
627
- it('throws when a declared field is denied by field-level access (non-sudo)', async () => {
628
- const fieldConfigs = {
629
- title: { type: 'text' },
630
- status: {
631
- type: 'text',
632
- access: { update: () => false, create: () => false },
633
- },
634
- }
635
- const data = { title: 'Test', status: 'published' }
636
-
637
- await expect(
638
- filterWritableFields(data, fieldConfigs, 'update', {
639
- session: null,
640
- item: { id: 'post-1' },
641
- context: nonSudoContext(),
642
- inputData: data,
643
- }),
644
- ).rejects.toThrow(/status/)
645
- })
646
-
647
- // ── #913: a field rule returning a filter must not grant blanket write access ──
648
-
649
- it('throws InvalidFieldAccessResultError, not a blanket write, when field access returns a filter (non-sudo)', async () => {
650
- const fieldConfigs = {
651
- title: { type: 'text' },
652
- status: {
653
- type: 'text',
654
- access: {
655
- // Written as a row-scoping rule; field access does not honour filters.
656
- update: () => ({ status: { equals: 'draft' } }),
657
- create: () => ({ status: { equals: 'draft' } }),
658
- },
659
- },
660
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
661
- } as any
662
- const data = { title: 'Test', status: 'published' }
663
-
664
- await expect(
665
- filterWritableFields(data, fieldConfigs, 'update', {
666
- session: null,
667
- item: { id: 'post-1', status: 'draft' },
668
- context: nonSudoContext(),
669
- inputData: data,
670
- }),
671
- ).rejects.toThrow(InvalidFieldAccessResultError)
672
- })
673
-
674
- it('does NOT throw on a would-be-denied field under sudo', async () => {
675
- const fieldConfigs = {
676
- title: { type: 'text' },
677
- status: {
678
- type: 'text',
679
- access: { update: () => false, create: () => false },
680
- },
681
- }
682
- const data = { title: 'Test', status: 'published' }
683
-
684
- const filtered = await filterWritableFields(data, fieldConfigs, 'update', {
685
- session: null,
686
- item: { id: 'post-1' },
687
- context: sudoContext(),
688
- inputData: data,
689
- })
690
-
691
- expect(filtered).toHaveProperty('title', 'Test')
692
- expect(filtered).toHaveProperty('status', 'published')
693
- })
694
-
695
- it('passes a declared relationship field through to nested operations (non-sudo)', async () => {
696
- const fieldConfigs = {
697
- title: { type: 'text' },
698
- author: { type: 'relationship', many: false },
699
- }
700
- const data = {
701
- title: 'Test',
702
- author: { connect: { id: 'user-1' } },
703
- }
704
-
705
- const filtered = await filterWritableFields(data, fieldConfigs, 'create', {
706
- session: null,
707
- context: nonSudoContext(),
708
- inputData: data,
709
- })
710
-
711
- expect(filtered).toHaveProperty('author')
712
- expect(filtered.author).toEqual({ connect: { id: 'user-1' } })
713
- })
714
- })
715
-
716
- // ── #978: under sudo, only a synthetic reverse-relation key is a recognised
717
- // undeclared key — anything else is refused, even under sudo ──────────────
718
-
719
- describe('filterWritableFields — #978 tightened sudo undeclared-key guard', () => {
720
- // A minimal config: Account is the target of ChargeRequest's list-only ref
721
- // (`ref: 'Account'`, no field named on Account), so the generator
722
- // synthesizes `from_ChargeRequest_account` on Account.
723
- const config = {
724
- db: { provider: 'sqlite', url: 'file:./dev.db' },
725
- lists: {
726
- Account: { fields: { name: { type: 'text' } } },
727
- ChargeRequest: {
728
- fields: {
729
- kind: { type: 'text' },
730
- account: { type: 'relationship', ref: 'Account' },
731
- },
732
- },
733
- },
734
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
735
- } as any
736
-
737
- it('passes a synthetic reverse-relation key through under sudo, when config/listName are supplied', async () => {
738
- const fieldConfigs = { name: { type: 'text' } }
739
- const data = {
740
- name: 'Acme',
741
- from_ChargeRequest_account: { create: { kind: 'DEPOSIT' } },
742
- }
743
-
744
- const filtered = await filterWritableFields(data, fieldConfigs, 'update', {
745
- session: null,
746
- item: { id: 'a1' },
747
- context: sudoContext(),
748
- inputData: data,
749
- listName: 'Account',
750
- config,
751
- })
752
-
753
- expect(filtered).toHaveProperty('name', 'Acme')
754
- expect(filtered).toHaveProperty('from_ChargeRequest_account')
755
- })
756
-
757
- it('throws on a genuinely unknown key under sudo, when config/listName are supplied', async () => {
758
- const fieldConfigs = { name: { type: 'text' } }
759
- const data = {
760
- name: 'Acme',
761
- totallyBogusKey: 'value',
762
- }
763
-
764
- await expect(
765
- filterWritableFields(data, fieldConfigs, 'update', {
766
- session: null,
767
- item: { id: 'a1' },
768
- context: sudoContext(),
769
- inputData: data,
770
- listName: 'Account',
771
- config,
772
- }),
773
- ).rejects.toThrow(/totallyBogusKey/)
774
- })
775
-
776
- it('keeps the pre-#978 blanket sudo passthrough when config/listName are omitted', async () => {
777
- // Pins the fallback direct unit tests above (e.g. "passes undeclared data
778
- // keys through under sudo") rely on: with no config to resolve a synthetic
779
- // key against, any undeclared key still passes through under sudo.
780
- const fieldConfigs = { name: { type: 'text' } }
781
- const data = { name: 'Acme', totallyBogusKey: 'value' }
782
-
783
- const filtered = await filterWritableFields(data, fieldConfigs, 'update', {
784
- session: null,
785
- item: { id: 'a1' },
786
- context: sudoContext(),
787
- inputData: data,
788
- })
789
-
790
- expect(filtered).toHaveProperty('totallyBogusKey', 'value')
791
- })
792
- })