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

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 +2753 -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 +1035 -611
  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 +629 -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 +294 -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 +153 -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 +462 -678
  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 +237 -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
@@ -0,0 +1,629 @@
1
+ import { isOneToOneRelationship, isRelationshipField } from '../fields/index.js';
2
+ const DEFAULT_NAMESPACE = 'public';
3
+ function pgType(type, args) {
4
+ return args && args.length > 0 ? { pack: 'pg', type, args } : { pack: 'pg', type };
5
+ }
6
+ export function idColumn(strategy) {
7
+ switch (strategy) {
8
+ case 'uuid7':
9
+ return { strategy, type: pgType('uuid') };
10
+ case 'cuid2':
11
+ return { strategy, type: pgType('char', [24]) };
12
+ case 'cuid':
13
+ return { strategy, type: pgType('text') };
14
+ case 'int autoincrement':
15
+ case 'singleton':
16
+ return { strategy, type: pgType('int') };
17
+ }
18
+ }
19
+ export function resolveIdStrategy(listConfig, config) {
20
+ if (listConfig.isSingleton)
21
+ return 'singleton';
22
+ return listConfig.db?.idField ?? config.db.idField ?? 'uuid7';
23
+ }
24
+ /**
25
+ * Which auto-timestamp columns a list carries: `db.timestamps` per list over
26
+ * the config default, off by default (ADR-0004). A declared `createdAt`/
27
+ * `updatedAt` field replaces the auto-timestamp column, as the generator has
28
+ * always allowed.
29
+ */
30
+ export function resolveListTimestamps(listConfig, dbConfig) {
31
+ const enabled = listConfig.db?.timestamps ?? dbConfig.timestamps ?? false;
32
+ if (!enabled)
33
+ return { createdAt: false, updatedAt: false };
34
+ return {
35
+ createdAt: !Object.prototype.hasOwnProperty.call(listConfig.fields, 'createdAt'),
36
+ updatedAt: !Object.prototype.hasOwnProperty.call(listConfig.fields, 'updatedAt'),
37
+ };
38
+ }
39
+ /**
40
+ * The Postgres constructors `db.nativeType` may name, keyed by their
41
+ * lower-cased spelling, and the pack type each folds to. Every entry is one
42
+ * the builder feed lowers to its own column descriptor.
43
+ */
44
+ const NATIVE_TYPES = {
45
+ text: { type: 'text', arity: [0, 0] },
46
+ varchar: { type: 'varchar', arity: [1, 1] },
47
+ char: { type: 'char', arity: [1, 1] },
48
+ uuid: { type: 'uuid', arity: [0, 0] },
49
+ integer: { type: 'int', arity: [0, 0] },
50
+ int: { type: 'int', arity: [0, 0] },
51
+ smallint: { type: 'smallint', arity: [0, 0] },
52
+ bigint: { type: 'bigint', arity: [0, 0] },
53
+ decimal: { type: 'decimal', arity: [0, 2] },
54
+ numeric: { type: 'decimal', arity: [0, 2] },
55
+ doubleprecision: { type: 'float', arity: [0, 0] },
56
+ real: { type: 'real', arity: [0, 0] },
57
+ boolean: { type: 'boolean', arity: [0, 0] },
58
+ date: { type: 'date', arity: [0, 0] },
59
+ timestamp: { type: 'timestamp', arity: [0, 1], precision: true },
60
+ timestamptz: { type: 'timestamptz', arity: [0, 1], precision: true },
61
+ time: { type: 'time', arity: [0, 1], precision: true },
62
+ json: { type: 'json', arity: [0, 0] },
63
+ jsonb: { type: 'jsonb', arity: [0, 0] },
64
+ bytea: { type: 'bytes', arity: [0, 0] },
65
+ };
66
+ function nativeTypeError(listKey, fieldKey, nativeType, detail) {
67
+ return new Error(`List "${listKey}": fields.${fieldKey} sets db.nativeType "${nativeType}", ${detail}`);
68
+ }
69
+ /**
70
+ * Fold a `db.nativeType` override (`VarChar(255)`, `Date`, `Decimal(10, 2)`,
71
+ * `Timestamptz(3)`) into the column's type descriptor. Only the constructors
72
+ * in {@link NATIVE_TYPES} are recognised, each with its own argument count;
73
+ * anything else is a generate-time error naming the field.
74
+ */
75
+ function foldNativeType(listKey, fieldKey, type, nativeType) {
76
+ if (nativeType === undefined)
77
+ return type;
78
+ const match = /^\s*([A-Za-z]+)\s*(?:\(\s*([^)]*)\))?\s*$/.exec(nativeType);
79
+ const native = match ? NATIVE_TYPES[match[1].toLowerCase()] : undefined;
80
+ if (!match || native === undefined) {
81
+ throw nativeTypeError(listKey, fieldKey, nativeType, `which is not a Postgres type the contract can carry. Supported: ${Object.keys(NATIVE_TYPES).join(', ')} (with their arguments).`);
82
+ }
83
+ const args = (match[2] ?? '')
84
+ .split(',')
85
+ .map((part) => part.trim())
86
+ .filter((part) => part.length > 0)
87
+ .map((part) => {
88
+ const n = Number(part);
89
+ if (!Number.isInteger(n)) {
90
+ throw nativeTypeError(listKey, fieldKey, nativeType, `whose argument "${part}" is not an integer.`);
91
+ }
92
+ return n;
93
+ });
94
+ const [min, max] = native.arity;
95
+ if (args.length < min || args.length > max) {
96
+ const expected = min === max ? `${min} argument${min === 1 ? '' : 's'}` : `between ${min} and ${max} arguments`;
97
+ throw nativeTypeError(listKey, fieldKey, nativeType, `but ${match[1]} takes ${expected}${min > 0 && args.length === 0 ? ` — write ${match[1]}(n)` : ''}.`);
98
+ }
99
+ if (native.precision && args.length === 1 && (args[0] < 0 || args[0] > 6)) {
100
+ throw nativeTypeError(listKey, fieldKey, nativeType, `but a fractional-seconds precision must be between 0 and 6.`);
101
+ }
102
+ return pgType(native.type, args);
103
+ }
104
+ function toContractColumn(listKey, fieldKey, descriptor) {
105
+ const { nativeType, ...rest } = descriptor;
106
+ return { ...rest, type: foldNativeType(listKey, fieldKey, descriptor.type, nativeType) };
107
+ }
108
+ const TIMESTAMP_DEFAULT_TYPES = new Set(['timestamp', 'timestamptz']);
109
+ function resolveTimestampDefault(config) {
110
+ const nativeType = config.db.defaults?.timestamp?.nativeType;
111
+ if (nativeType === undefined)
112
+ return undefined;
113
+ let type;
114
+ try {
115
+ type = foldNativeType('', '', pgType('dateTime'), nativeType);
116
+ }
117
+ catch (error) {
118
+ const detail = error instanceof Error ? error.message.replace(/^.*?sets db\.nativeType "[^"]*", /, '') : '';
119
+ throw new Error(`db.defaults.timestamp.nativeType "${nativeType}" is invalid: ${detail}`);
120
+ }
121
+ if (!TIMESTAMP_DEFAULT_TYPES.has(type.type)) {
122
+ throw new Error(`db.defaults.timestamp.nativeType "${nativeType}" is not a timestamp type. Use Timestamp or Timestamptz, with an optional precision (Timestamp(3)).`);
123
+ }
124
+ return type;
125
+ }
126
+ function foreignKeyColumnName(fieldKey) {
127
+ return `${fieldKey}Id`;
128
+ }
129
+ function claimMember(listKey, draft, name, origin) {
130
+ const existing = draft.members.get(name);
131
+ if (existing !== undefined) {
132
+ throw new Error(`List "${listKey}": ${origin} derives the contract member "${name}", which ${existing} already claims on the same model`);
133
+ }
134
+ draft.members.set(name, origin);
135
+ }
136
+ function refuseColumnsAliasingRelations(model) {
137
+ const relationNames = new Set(model.relations.map((relation) => relation.name));
138
+ for (const column of model.columns) {
139
+ const physical = column.map ?? column.name;
140
+ if (relationNames.has(physical)) {
141
+ throw new Error(`List "${model.name}": column "${column.name}" is stored as "${physical}", which is also the ` +
142
+ `name of the relation "${physical}" on the same list. An include is aliased by relation ` +
143
+ `name and a scalar by physical column name, so the two would collide (#1236, ADR-0069). ` +
144
+ `Pick a different db.map or db.foreignKey.map.`);
145
+ }
146
+ }
147
+ }
148
+ function readIsIndexed(field) {
149
+ const value = 'isIndexed' in field ? field.isIndexed : undefined;
150
+ return value === true || value === 'unique' ? value : undefined;
151
+ }
152
+ function requireList(config, listKey, from) {
153
+ if (!config.lists[listKey]) {
154
+ throw new Error(`${from} references list "${listKey}", which is not in the config`);
155
+ }
156
+ }
157
+ function deriveRelation(listKey, fieldKey, field, descriptor, config, draft, syntheticByTarget) {
158
+ const from = `List "${listKey}": fields.${fieldKey}`;
159
+ requireList(config, descriptor.target, from);
160
+ const targetList = config.lists[descriptor.target];
161
+ const inverseKey = `${descriptor.target}.${descriptor.inverse.field}`;
162
+ if (descriptor.many && descriptor.inverse.synthetic) {
163
+ throw new Error(`${from} is many: true with the list-only ref "${field.ref}" — an implicit many-to-many, which the ` +
164
+ `contract cannot carry (ADR-0048). Author the junction as its own list.`);
165
+ }
166
+ if (!descriptor.inverse.synthetic) {
167
+ const inverseField = targetList.fields[descriptor.inverse.field];
168
+ if (!isRelationshipField(inverseField)) {
169
+ throw new Error(`${from} refs "${field.ref}", but "${inverseKey}" is not a relationship field`);
170
+ }
171
+ if (inverseField.ref !== `${listKey}.${fieldKey}`) {
172
+ throw new Error(`${from} refs "${field.ref}", but "${inverseKey}" refs "${inverseField.ref}" rather than ` +
173
+ `"${listKey}.${fieldKey}" — the two ends of a relationship must name each other`);
174
+ }
175
+ if (descriptor.many && inverseField.many) {
176
+ throw new Error(`${from} and list "${descriptor.target}": fields.${descriptor.inverse.field} are both many: true — ` +
177
+ `an implicit many-to-many, which the contract cannot carry (ADR-0048).`);
178
+ }
179
+ }
180
+ claimMember(listKey, draft, fieldKey, `fields.${fieldKey}`);
181
+ const { foreignKey } = descriptor;
182
+ if (foreignKey) {
183
+ const targetStrategy = resolveIdStrategy(targetList, config);
184
+ const oneToOne = isOneToOneRelationship(fieldKey, field, config);
185
+ claimMember(listKey, draft, foreignKey.name, `the foreign-key column of fields.${fieldKey}`);
186
+ draft.model.columns.push({
187
+ name: foreignKey.name,
188
+ type: idColumn(targetStrategy).type,
189
+ nullable: foreignKey.nullable,
190
+ ...(foreignKey.map !== undefined && foreignKey.map !== foreignKey.name
191
+ ? { map: foreignKey.map }
192
+ : {}),
193
+ ...(foreignKey.unique ? { unique: true } : {}),
194
+ ...(foreignKey.index && !foreignKey.unique ? { index: true } : {}),
195
+ });
196
+ draft.model.foreignKeys.push({
197
+ column: foreignKey.name,
198
+ references: { model: descriptor.target, column: 'id' },
199
+ ...(field.db?.onDelete !== undefined ? { onDelete: field.db.onDelete } : {}),
200
+ ...(field.db?.onUpdate !== undefined ? { onUpdate: field.db.onUpdate } : {}),
201
+ });
202
+ draft.ownedForeignKeys.set(fieldKey, foreignKey.name);
203
+ if (foreignKey.unique || foreignKey.index) {
204
+ const explicit = field.isIndexed === 'unique' || (field.isIndexed === true && !oneToOne);
205
+ draft.fieldLevelIndexes.set(foreignKey.name, {
206
+ fieldKey,
207
+ isIndexed: foreignKey.unique ? 'unique' : true,
208
+ implicit: !explicit,
209
+ ...(oneToOne ? { oneToOneWith: inverseKey } : {}),
210
+ });
211
+ }
212
+ draft.model.relations.push({
213
+ name: fieldKey,
214
+ target: descriptor.target,
215
+ kind: 'belongsTo',
216
+ column: foreignKey.name,
217
+ oneToOne,
218
+ synthetic: false,
219
+ });
220
+ if (descriptor.inverse.synthetic) {
221
+ const existing = syntheticByTarget.get(descriptor.target) ?? [];
222
+ existing.push({
223
+ from: `${listKey}.${fieldKey}`,
224
+ relation: {
225
+ name: descriptor.inverse.field,
226
+ target: listKey,
227
+ kind: 'hasMany',
228
+ column: foreignKey.name,
229
+ oneToOne: false,
230
+ synthetic: true,
231
+ },
232
+ });
233
+ syntheticByTarget.set(descriptor.target, existing);
234
+ }
235
+ return;
236
+ }
237
+ draft.model.relations.push({
238
+ name: fieldKey,
239
+ target: descriptor.target,
240
+ kind: descriptor.many ? 'hasMany' : 'hasOne',
241
+ column: foreignKeyColumnName(descriptor.inverse.field),
242
+ oneToOne: !descriptor.many,
243
+ synthetic: false,
244
+ });
245
+ }
246
+ function resolveIndexColumn(listKey, listConfig, draft, entry, fieldRef) {
247
+ const fieldKey = typeof fieldRef === 'string' ? fieldRef : fieldRef.field;
248
+ const field = listConfig.fields[fieldKey];
249
+ if (!field) {
250
+ if (fieldKey === 'id')
251
+ return 'id';
252
+ if ((fieldKey === 'createdAt' && draft.model.timestamps.createdAt) ||
253
+ (fieldKey === 'updatedAt' && draft.model.timestamps.updatedAt)) {
254
+ return fieldKey;
255
+ }
256
+ throw new Error(`${entry} on list "${listKey}" references unknown field "${fieldKey}"`);
257
+ }
258
+ if (field.virtual) {
259
+ throw new Error(`${entry} on list "${listKey}" references virtual field "${fieldKey}", which has no database column`);
260
+ }
261
+ if (isRelationshipField(field)) {
262
+ if (field.many) {
263
+ throw new Error(`${entry} on list "${listKey}" references to-many relationship field "${fieldKey}", which has no single database column`);
264
+ }
265
+ const column = draft.ownedForeignKeys.get(fieldKey);
266
+ if (!column) {
267
+ throw new Error(`${entry} on list "${listKey}" references relationship field "${fieldKey}", which does not own a foreign key column on this model (the other side of the relationship owns it)`);
268
+ }
269
+ return column;
270
+ }
271
+ if (draft.multiColumnFields.has(fieldKey)) {
272
+ throw new Error(`${entry} on list "${listKey}" references field "${fieldKey}", which maps to more than one database column and cannot be used in a model-level index`);
273
+ }
274
+ return fieldKey;
275
+ }
276
+ /**
277
+ * A single-field entry on a column a field-level constraint already covers:
278
+ * a spelled-out `isIndexed` is a genuine duplicate and is refused; a
279
+ * relationship's default index, or the one-to-one's implicit unique, yields
280
+ * to the entry — which then names the constraint — except that a plain
281
+ * index cannot stand in for the unique that makes a one-to-one.
282
+ */
283
+ function adoptFieldLevelIndex(listKey, draft, entry, column, collision, unique) {
284
+ if (!collision.implicit) {
285
+ const value = collision.isIndexed === 'unique' ? `'unique'` : 'true';
286
+ throw new Error(`${entry} on list "${listKey}" duplicates the constraint already produced by field "${collision.fieldKey}"'s isIndexed: ${value} — both would emit an index on "${column}"; remove one of them`);
287
+ }
288
+ if (collision.isIndexed === 'unique' && !unique) {
289
+ throw new Error(`${entry} on list "${listKey}" names field "${collision.fieldKey}", the owning side of the one-to-one with ` +
290
+ `"${collision.oneToOneWith}", whose column "${column}" already carries the unique constraint that makes ` +
291
+ `it one-to-one (ADR-0064); a further index on it is redundant. Set unique: true on the entry to name ` +
292
+ `that constraint, or remove the entry`);
293
+ }
294
+ const owned = draft.model.columns.find((candidate) => candidate.name === column);
295
+ if (owned) {
296
+ delete owned.unique;
297
+ delete owned.index;
298
+ }
299
+ draft.fieldLevelIndexes.delete(column);
300
+ }
301
+ function deriveIndexes(listKey, listConfig, draft) {
302
+ const indexes = listConfig.db?.indexes ?? [];
303
+ return indexes.map((index, i) => {
304
+ const entry = `Model-level index db.indexes[${i}]`;
305
+ if (index.fields.length === 0) {
306
+ throw new Error(`${entry} on list "${listKey}" has an empty "fields" array — an index/constraint must name at least one field`);
307
+ }
308
+ const columns = index.fields.map((fieldRef) => resolveIndexColumn(listKey, listConfig, draft, entry, fieldRef));
309
+ const unique = index.unique === true;
310
+ if (index.where !== undefined) {
311
+ if (typeof index.where !== 'string' || index.where.trim() === '') {
312
+ throw new Error(`${entry} on list "${listKey}" has an empty "where" — a partial index needs a SQL predicate`);
313
+ }
314
+ if (index.name === undefined) {
315
+ throw new Error(`${entry} on list "${listKey}" has a "where" but no "name" — a partial index must be named so the database object can be adopted and its violations mapped`);
316
+ }
317
+ }
318
+ else if (columns.length === 1) {
319
+ const collision = draft.fieldLevelIndexes.get(columns[0]);
320
+ if (collision)
321
+ adoptFieldLevelIndex(listKey, draft, entry, columns[0], collision, unique);
322
+ }
323
+ return {
324
+ columns,
325
+ unique,
326
+ ...(index.name !== undefined ? { name: index.name } : {}),
327
+ ...(index.where !== undefined ? { where: index.where } : {}),
328
+ };
329
+ });
330
+ }
331
+ function sameColumnSet(a, b) {
332
+ return a.length === b.length && [...a].sort().join('\0') === [...b].sort().join('\0');
333
+ }
334
+ function declaresUnique(draft, columns) {
335
+ if (columns.length === 1 && columns[0] === 'id')
336
+ return true;
337
+ if (draft.model.indexes.some((index) => index.unique && sameColumnSet(index.columns, columns))) {
338
+ return true;
339
+ }
340
+ if (columns.length !== 1)
341
+ return false;
342
+ const column = draft.model.columns.find((candidate) => candidate.name === columns[0]);
343
+ return column?.unique === true;
344
+ }
345
+ function deriveCompositeForeignKeys(listKey, config, drafts) {
346
+ const draft = drafts.get(listKey);
347
+ const listConfig = config.lists[listKey];
348
+ if (!draft || !listConfig)
349
+ return [];
350
+ return (listConfig.db?.foreignKeys ?? []).map((foreignKey, i) => {
351
+ const entry = `Foreign key db.foreignKeys[${i}]`;
352
+ const { fields, references } = foreignKey;
353
+ if (fields.length === 0) {
354
+ throw new Error(`${entry} on list "${listKey}" has an empty "fields" array — a foreign key must name at least one field`);
355
+ }
356
+ if (fields.length !== references.fields.length) {
357
+ throw new Error(`${entry} on list "${listKey}" names ${fields.length} field(s) but references ${references.fields.length} field(s) on "${references.list}" — the two lists must have the same arity`);
358
+ }
359
+ if (new Set(fields.map((f) => (typeof f === 'string' ? f : f.field))).size !== fields.length) {
360
+ throw new Error(`${entry} on list "${listKey}" names the same field more than once`);
361
+ }
362
+ const targetConfig = config.lists[references.list];
363
+ const targetDraft = drafts.get(references.list);
364
+ if (!targetConfig || !targetDraft) {
365
+ throw new Error(`${entry} on list "${listKey}" references list "${references.list}", which is not in the config`);
366
+ }
367
+ const columns = fields.map((fieldRef) => resolveIndexColumn(listKey, listConfig, draft, entry, fieldRef));
368
+ const targetColumns = references.fields.map((fieldKey) => resolveIndexColumn(references.list, targetConfig, targetDraft, entry, fieldKey));
369
+ if (columns.length === 1 &&
370
+ draft.model.foreignKeys.some((existing) => existing.column === columns[0])) {
371
+ throw new Error(`${entry} on list "${listKey}" constrains "${columns[0]}", which a relationship field already references with its own foreign key — remove the entry`);
372
+ }
373
+ if (!declaresUnique(targetDraft, targetColumns)) {
374
+ throw new Error(`${entry} on list "${listKey}" references (${references.fields.join(', ')}) on "${references.list}", which is not a declared unique there. ` +
375
+ `Add db.indexes: [{ fields: [${references.fields.map((f) => `'${f}'`).join(', ')}], unique: true }] to "${references.list}", or reference its id`);
376
+ }
377
+ return {
378
+ columns,
379
+ references: { model: references.list, columns: targetColumns },
380
+ ...(foreignKey.onDelete !== undefined ? { onDelete: foreignKey.onDelete } : {}),
381
+ ...(foreignKey.onUpdate !== undefined ? { onUpdate: foreignKey.onUpdate } : {}),
382
+ ...(foreignKey.name !== undefined ? { name: foreignKey.name } : {}),
383
+ };
384
+ });
385
+ }
386
+ function collectEnums(models) {
387
+ const byName = new Map();
388
+ for (const model of models) {
389
+ for (const column of model.columns) {
390
+ if (!column.enum)
391
+ continue;
392
+ const existing = byName.get(column.enum.name);
393
+ if (!existing) {
394
+ byName.set(column.enum.name, { name: column.enum.name, values: [...column.enum.values] });
395
+ continue;
396
+ }
397
+ if (existing.values.length !== column.enum.values.length ||
398
+ existing.values.some((value, i) => value !== column.enum?.values[i])) {
399
+ throw new Error(`Enum "${column.enum.name}" is declared with different values by more than one field (model "${model.name}", column "${column.name}"). ` +
400
+ `Give each distinct value set its own db.enumName.`);
401
+ }
402
+ }
403
+ }
404
+ return [...byName.values()];
405
+ }
406
+ const POSTGRES_IDENTIFIER_BYTES = 63;
407
+ function prisma7Name(table, columns, suffix) {
408
+ const base = `${table}_${columns.join('_')}`;
409
+ const room = POSTGRES_IDENTIFIER_BYTES - suffix.length - 1;
410
+ const bytes = Buffer.from(base, 'utf8');
411
+ let trimmed = bytes.length > room ? bytes.subarray(0, room).toString('utf8') : base;
412
+ while (Buffer.byteLength(trimmed, 'utf8') > room)
413
+ trimmed = trimmed.slice(0, -1);
414
+ return `${trimmed}_${suffix}`;
415
+ }
416
+ function applyPrisma7Names(model) {
417
+ const table = model.table ?? model.name;
418
+ const physical = (column) => model.columns.find((candidate) => candidate.name === column)?.map ?? column;
419
+ const hoisted = [];
420
+ for (const column of model.columns) {
421
+ if (column.unique) {
422
+ delete column.unique;
423
+ hoisted.push({
424
+ columns: [column.name],
425
+ unique: true,
426
+ name: prisma7Name(table, [physical(column.name)], 'key'),
427
+ });
428
+ }
429
+ if (column.index) {
430
+ delete column.index;
431
+ hoisted.push({
432
+ columns: [column.name],
433
+ unique: false,
434
+ name: prisma7Name(table, [physical(column.name)], 'idx'),
435
+ });
436
+ }
437
+ }
438
+ model.indexes = [
439
+ ...model.indexes.map((index) => index.name !== undefined
440
+ ? index
441
+ : {
442
+ ...index,
443
+ name: prisma7Name(table, index.columns.map(physical), index.unique ? 'key' : 'idx'),
444
+ }),
445
+ ...hoisted,
446
+ ];
447
+ for (const foreignKey of model.foreignKeys) {
448
+ foreignKey.name = prisma7Name(table, [physical(foreignKey.column)], 'fkey');
449
+ }
450
+ const seen = new Set();
451
+ const names = [
452
+ ...model.indexes.flatMap((index) => (index.name !== undefined ? [index.name] : [])),
453
+ ...model.foreignKeys.flatMap((foreignKey) => foreignKey.name !== undefined ? [foreignKey.name] : []),
454
+ ];
455
+ for (const name of names) {
456
+ if (seen.has(name)) {
457
+ throw new Error(`List "${model.name}": db.indexNaming 'prisma7' derives the constraint name "${name}" more than once (a long name truncated to 63 bytes, or two constraints on the same columns). Give one of them an explicit db.indexes name.`);
458
+ }
459
+ seen.add(name);
460
+ }
461
+ }
462
+ function dedupeExtensions(extensions) {
463
+ const seen = new Map();
464
+ for (const extension of extensions) {
465
+ if (!seen.has(extension.name))
466
+ seen.set(extension.name, { ...extension });
467
+ }
468
+ return [...seen.values()];
469
+ }
470
+ function collectNamespaces(config, models) {
471
+ const namespaces = new Set(config.db.schemas ?? []);
472
+ for (const model of models) {
473
+ if (model.namespace !== undefined)
474
+ namespaces.add(model.namespace);
475
+ }
476
+ namespaces.delete(DEFAULT_NAMESPACE);
477
+ return [...namespaces];
478
+ }
479
+ /**
480
+ * Derive the contract data a config describes (ADR-0057): one model per list
481
+ * with its id by strategy, stored columns from each field builder's structured
482
+ * descriptor, `temporal` auto-timestamps, foreign keys with the relationship's
483
+ * referential actions, `db.indexes` resolved to columns, the relation graph
484
+ * with foreign-key ownership (ADR-0064), synthetic back-relations for
485
+ * list-only refs, the native enums, the namespaces beyond `public`, and the
486
+ * declared extension packs.
487
+ *
488
+ * Expects a config that passed `validateDatabaseConfig` and
489
+ * `validateRelations`; what it still throws on — naming the list and field —
490
+ * is a backstop for a config that skipped them, plus the `db.nativeType` and
491
+ * `db.indexes` resolution errors that are only decidable here.
492
+ *
493
+ * @example
494
+ * ```typescript
495
+ * import { deriveContract } from '@opensaas/stack-core'
496
+ * const data = deriveContract(config)
497
+ * data.models.find((m) => m.name === 'Post')?.relations
498
+ * // [{ name: 'author', target: 'User', kind: 'belongsTo', column: 'authorId', oneToOne: false, synthetic: false }]
499
+ * ```
500
+ *
501
+ * Known limits:
502
+ * - Composite primary keys and a relationship at a composite-keyed list are
503
+ * out of scope (ADR-0048) and refused before derivation.
504
+ * - `db.nativeType` is folded only for the Postgres pack's own constructors;
505
+ * an extension type's native-type override is not supported.
506
+ * - `keystoneCompat`'s implicit `""` text default is carried only where the
507
+ * field's own create validator accepts both an omission and `""`. A
508
+ * `validation.isRequired` text column therefore keeps no default — carrying
509
+ * one would drop the column from the required half of the generated create
510
+ * input while the validator still refused the omission — and neither does a
511
+ * `validation.length.min` above zero, whose validator refuses the `""` the
512
+ * default would insert. That leaves the flag inert for Keystone's commonest
513
+ * text column.
514
+ */
515
+ export function deriveContract(config) {
516
+ const extensions = dedupeExtensions(config.db.extensions ?? []);
517
+ const timestampDefault = resolveTimestampDefault(config);
518
+ const drafts = new Map();
519
+ const syntheticByTarget = new Map();
520
+ for (const [listKey, listConfig] of Object.entries(config.lists)) {
521
+ const timestamps = resolveListTimestamps(listConfig, config.db);
522
+ const draft = {
523
+ model: {
524
+ name: listKey,
525
+ ...(listConfig.db?.map !== undefined ? { table: listConfig.db.map } : {}),
526
+ ...(listConfig.db?.schema !== undefined && listConfig.db.schema !== DEFAULT_NAMESPACE
527
+ ? { namespace: listConfig.db.schema }
528
+ : {}),
529
+ singleton: listConfig.isSingleton !== undefined && listConfig.isSingleton !== false,
530
+ id: idColumn(resolveIdStrategy(listConfig, config)),
531
+ columns: [],
532
+ foreignKeys: [],
533
+ indexes: [],
534
+ relations: [],
535
+ timestamps,
536
+ ...(timestampDefault !== undefined && timestamps.createdAt
537
+ ? { timestampType: timestampDefault }
538
+ : {}),
539
+ },
540
+ fieldLevelIndexes: new Map(),
541
+ ownedForeignKeys: new Map(),
542
+ multiColumnFields: new Set(),
543
+ members: new Map([['id', 'the id column']]),
544
+ };
545
+ if (timestamps.createdAt)
546
+ draft.members.set('createdAt', 'the createdAt auto-timestamp');
547
+ if (timestamps.updatedAt)
548
+ draft.members.set('updatedAt', 'the updatedAt auto-timestamp');
549
+ for (const [fieldKey, field] of Object.entries(listConfig.fields)) {
550
+ if (field.virtual)
551
+ continue;
552
+ if (!field.getContractField) {
553
+ throw new Error(`Field "${listKey}.${fieldKey}" (type "${field.type}") does not implement getContractField, so its contract contribution is unknown`);
554
+ }
555
+ const descriptor = field.getContractField(fieldKey, listKey, config);
556
+ switch (descriptor.kind) {
557
+ case 'computed':
558
+ break;
559
+ case 'column': {
560
+ const { kind: _kind, ...column } = descriptor;
561
+ claimMember(listKey, draft, column.name, `fields.${fieldKey}`);
562
+ const resolved = toContractColumn(listKey, fieldKey, column);
563
+ draft.model.columns.push(timestampDefault !== undefined &&
564
+ field.type === 'timestamp' &&
565
+ column.nativeType === undefined
566
+ ? { ...resolved, type: timestampDefault }
567
+ : resolved);
568
+ const isIndexed = readIsIndexed(field);
569
+ if (isIndexed !== undefined) {
570
+ draft.fieldLevelIndexes.set(column.name, { fieldKey, isIndexed, implicit: false });
571
+ }
572
+ break;
573
+ }
574
+ case 'columns':
575
+ draft.multiColumnFields.add(fieldKey);
576
+ for (const column of descriptor.columns) {
577
+ if (column.nullable === false) {
578
+ throw new Error(`Field "${listKey}.${fieldKey}" (type "${field.type}") declares its multi-column ` +
579
+ `part "${column.name}" as non-nullable. The secured surface always types a ` +
580
+ `multi-column field's assembled logical key as optional on create — there is no ` +
581
+ `all-parts-required case for it to satisfy a NOT NULL part with — so every part ` +
582
+ `column must stay nullable. Remove nullable: false from this column.`);
583
+ }
584
+ claimMember(listKey, draft, column.name, `fields.${fieldKey}`);
585
+ draft.model.columns.push(toContractColumn(listKey, fieldKey, column));
586
+ }
587
+ break;
588
+ case 'relation':
589
+ if (!isRelationshipField(field)) {
590
+ throw new Error(`Field "${listKey}.${fieldKey}" (type "${field.type}") describes a relation but is not a relationship field`);
591
+ }
592
+ deriveRelation(listKey, fieldKey, field, descriptor, config, draft, syntheticByTarget);
593
+ break;
594
+ }
595
+ }
596
+ draft.model.indexes = deriveIndexes(listKey, listConfig, draft);
597
+ if (config.db.indexNaming !== undefined && config.db.indexNaming !== 'prisma7') {
598
+ throw new Error(`db.indexNaming must be 'prisma7', received ${JSON.stringify(config.db.indexNaming)}`);
599
+ }
600
+ if (config.db.indexNaming === 'prisma7')
601
+ applyPrisma7Names(draft.model);
602
+ drafts.set(listKey, draft);
603
+ }
604
+ for (const [target, relations] of syntheticByTarget) {
605
+ const draft = drafts.get(target);
606
+ if (!draft) {
607
+ throw new Error(`Synthetic back-relation targets list "${target}", which is not in the config`);
608
+ }
609
+ for (const { from, relation } of relations) {
610
+ claimMember(target, draft, relation.name, `the back-relation synthesised for the list-only ref on "${from}"`);
611
+ draft.model.relations.push(relation);
612
+ }
613
+ }
614
+ for (const draft of drafts.values())
615
+ refuseColumnsAliasingRelations(draft.model);
616
+ for (const [listKey, draft] of drafts) {
617
+ const composite = deriveCompositeForeignKeys(listKey, config, drafts);
618
+ if (composite.length > 0)
619
+ draft.model.compositeForeignKeys = composite;
620
+ }
621
+ const models = [...drafts.values()].map((draft) => draft.model);
622
+ return {
623
+ models,
624
+ namespaces: collectNamespaces(config, models),
625
+ enums: collectEnums(models),
626
+ extensions,
627
+ };
628
+ }
629
+ //# sourceMappingURL=derive.js.map