@opensaas/stack-core 0.44.0-alpha.5 → 0.44.0-alpha.7

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 (402) hide show
  1. package/CHANGELOG.md +1051 -0
  2. package/dist/.build-hash +1 -1
  3. package/dist/access/actor.d.ts +56 -0
  4. package/dist/access/actor.d.ts.map +1 -0
  5. package/dist/access/actor.js +66 -0
  6. package/dist/access/actor.js.map +1 -0
  7. package/dist/access/decide-advertisement.d.ts +55 -0
  8. package/dist/access/decide-advertisement.d.ts.map +1 -0
  9. package/dist/access/decide-advertisement.js +125 -0
  10. package/dist/access/decide-advertisement.js.map +1 -0
  11. package/dist/access/declared-dependencies.d.ts +4 -89
  12. package/dist/access/declared-dependencies.d.ts.map +1 -1
  13. package/dist/access/declared-dependencies.js +14 -84
  14. package/dist/access/declared-dependencies.js.map +1 -1
  15. package/dist/access/depth-limits.d.ts +2 -0
  16. package/dist/access/depth-limits.d.ts.map +1 -1
  17. package/dist/access/depth-limits.js +2 -0
  18. package/dist/access/depth-limits.js.map +1 -1
  19. package/dist/access/engine.d.ts +1 -24
  20. package/dist/access/engine.d.ts.map +1 -1
  21. package/dist/access/engine.js +0 -35
  22. package/dist/access/engine.js.map +1 -1
  23. package/dist/access/field-access.d.ts +43 -19
  24. package/dist/access/field-access.d.ts.map +1 -1
  25. package/dist/access/field-access.js +206 -185
  26. package/dist/access/field-access.js.map +1 -1
  27. package/dist/access/index.d.ts +5 -6
  28. package/dist/access/index.d.ts.map +1 -1
  29. package/dist/access/index.js +6 -7
  30. package/dist/access/index.js.map +1 -1
  31. package/dist/access/rule-item.d.ts +42 -0
  32. package/dist/access/rule-item.d.ts.map +1 -0
  33. package/dist/access/rule-item.js +215 -0
  34. package/dist/access/rule-item.js.map +1 -0
  35. package/dist/access/session-vocabulary.d.ts +124 -0
  36. package/dist/access/session-vocabulary.d.ts.map +1 -0
  37. package/dist/access/session-vocabulary.js +366 -0
  38. package/dist/access/session-vocabulary.js.map +1 -0
  39. package/dist/access/transaction-registry.d.ts +6 -0
  40. package/dist/access/transaction-registry.d.ts.map +1 -1
  41. package/dist/access/transaction-registry.js +19 -2
  42. package/dist/access/transaction-registry.js.map +1 -1
  43. package/dist/access/types.d.ts +66 -0
  44. package/dist/access/types.d.ts.map +1 -1
  45. package/dist/access/vocabulary-filter-specs.d.ts +17 -0
  46. package/dist/access/vocabulary-filter-specs.d.ts.map +1 -0
  47. package/dist/access/vocabulary-filter-specs.js +27 -0
  48. package/dist/access/vocabulary-filter-specs.js.map +1 -0
  49. package/dist/client-safe.d.ts +8 -0
  50. package/dist/client-safe.d.ts.map +1 -0
  51. package/dist/client-safe.js +8 -0
  52. package/dist/client-safe.js.map +1 -0
  53. package/dist/config/field-kind.d.ts +7 -21
  54. package/dist/config/field-kind.d.ts.map +1 -1
  55. package/dist/config/field-kind.js +8 -5
  56. package/dist/config/field-kind.js.map +1 -1
  57. package/dist/config/has-access-gate.d.ts +20 -0
  58. package/dist/config/has-access-gate.d.ts.map +1 -0
  59. package/dist/config/has-access-gate.js +26 -0
  60. package/dist/config/has-access-gate.js.map +1 -0
  61. package/dist/config/index.d.ts +1 -1
  62. package/dist/config/index.d.ts.map +1 -1
  63. package/dist/config/index.js +8 -2
  64. package/dist/config/index.js.map +1 -1
  65. package/dist/config/list-view-keys.d.ts +5 -0
  66. package/dist/config/list-view-keys.d.ts.map +1 -0
  67. package/dist/config/list-view-keys.js +18 -0
  68. package/dist/config/list-view-keys.js.map +1 -0
  69. package/dist/config/mcp-default-tools.d.ts +3 -0
  70. package/dist/config/mcp-default-tools.d.ts.map +1 -0
  71. package/dist/config/mcp-default-tools.js +14 -0
  72. package/dist/config/mcp-default-tools.js.map +1 -0
  73. package/dist/config/mcp-tool-names.d.ts +2 -0
  74. package/dist/config/mcp-tool-names.d.ts.map +1 -1
  75. package/dist/config/mcp-tool-names.js +17 -5
  76. package/dist/config/mcp-tool-names.js.map +1 -1
  77. package/dist/config/nav-count.d.ts +8 -16
  78. package/dist/config/nav-count.d.ts.map +1 -1
  79. package/dist/config/nav-count.js +20 -32
  80. package/dist/config/nav-count.js.map +1 -1
  81. package/dist/config/plugin-engine.d.ts.map +1 -1
  82. package/dist/config/plugin-engine.js +6 -0
  83. package/dist/config/plugin-engine.js.map +1 -1
  84. package/dist/config/preset-views.d.ts +22 -0
  85. package/dist/config/preset-views.d.ts.map +1 -0
  86. package/dist/config/preset-views.js +46 -0
  87. package/dist/config/preset-views.js.map +1 -0
  88. package/dist/config/row-action-availability.d.ts +4 -0
  89. package/dist/config/row-action-availability.d.ts.map +1 -0
  90. package/dist/config/row-action-availability.js +20 -0
  91. package/dist/config/row-action-availability.js.map +1 -0
  92. package/dist/config/types.d.ts +409 -34
  93. package/dist/config/types.d.ts.map +1 -1
  94. package/dist/context/engine-context.d.ts +2 -0
  95. package/dist/context/engine-context.d.ts.map +1 -1
  96. package/dist/context/engine-context.js +8 -0
  97. package/dist/context/engine-context.js.map +1 -1
  98. package/dist/context/hook-pipeline.d.ts +6 -1
  99. package/dist/context/hook-pipeline.d.ts.map +1 -1
  100. package/dist/context/hook-pipeline.js +6 -4
  101. package/dist/context/hook-pipeline.js.map +1 -1
  102. package/dist/context/index.d.ts +10 -1
  103. package/dist/context/index.d.ts.map +1 -1
  104. package/dist/context/index.js +217 -94
  105. package/dist/context/index.js.map +1 -1
  106. package/dist/context/junction.d.ts +28 -21
  107. package/dist/context/junction.d.ts.map +1 -1
  108. package/dist/context/junction.js +74 -69
  109. package/dist/context/junction.js.map +1 -1
  110. package/dist/context/plugin-field-write.d.ts.map +1 -1
  111. package/dist/context/plugin-field-write.js +19 -25
  112. package/dist/context/plugin-field-write.js.map +1 -1
  113. package/dist/context/process-lifetime.d.ts +8 -0
  114. package/dist/context/process-lifetime.d.ts.map +1 -0
  115. package/dist/context/process-lifetime.js +14 -0
  116. package/dist/context/process-lifetime.js.map +1 -0
  117. package/dist/context/relationship-input.d.ts +2 -15
  118. package/dist/context/relationship-input.d.ts.map +1 -1
  119. package/dist/context/relationship-input.js +44 -85
  120. package/dist/context/relationship-input.js.map +1 -1
  121. package/dist/context/transaction-boundary.d.ts +3 -2
  122. package/dist/context/transaction-boundary.d.ts.map +1 -1
  123. package/dist/context/transaction-boundary.js +17 -2
  124. package/dist/context/transaction-boundary.js.map +1 -1
  125. package/dist/context/write-pipeline.d.ts +5 -19
  126. package/dist/context/write-pipeline.d.ts.map +1 -1
  127. package/dist/context/write-pipeline.js +54 -92
  128. package/dist/context/write-pipeline.js.map +1 -1
  129. package/dist/context/write-target.d.ts +52 -0
  130. package/dist/context/write-target.d.ts.map +1 -0
  131. package/dist/context/write-target.js +118 -0
  132. package/dist/context/write-target.js.map +1 -0
  133. package/dist/contract/dependencies.d.ts +24 -10
  134. package/dist/contract/dependencies.d.ts.map +1 -1
  135. package/dist/contract/dependencies.js +120 -80
  136. package/dist/contract/dependencies.js.map +1 -1
  137. package/dist/contract/derive.d.ts +6 -11
  138. package/dist/contract/derive.d.ts.map +1 -1
  139. package/dist/contract/derive.js +256 -211
  140. package/dist/contract/derive.js.map +1 -1
  141. package/dist/contract/fixtures/contract-configs.d.ts +5 -0
  142. package/dist/contract/fixtures/contract-configs.d.ts.map +1 -1
  143. package/dist/contract/fixtures/contract-configs.js +21 -0
  144. package/dist/contract/fixtures/contract-configs.js.map +1 -1
  145. package/dist/contract/id-boundary.js +1 -1
  146. package/dist/contract/id-boundary.js.map +1 -1
  147. package/dist/contract/prisma.js +2 -2
  148. package/dist/contract/prisma.js.map +1 -1
  149. package/dist/contract/strategy.d.ts +13 -0
  150. package/dist/contract/strategy.d.ts.map +1 -0
  151. package/dist/contract/strategy.js +38 -0
  152. package/dist/contract/strategy.js.map +1 -0
  153. package/dist/db/client-alias.d.ts +12 -0
  154. package/dist/db/client-alias.d.ts.map +1 -0
  155. package/dist/db/client-alias.js +8 -0
  156. package/dist/db/client-alias.js.map +1 -0
  157. package/dist/extend.d.ts +2 -2
  158. package/dist/extend.d.ts.map +1 -1
  159. package/dist/extend.js.map +1 -1
  160. package/dist/fields/index.d.ts +12 -14
  161. package/dist/fields/index.d.ts.map +1 -1
  162. package/dist/fields/index.js +217 -67
  163. package/dist/fields/index.js.map +1 -1
  164. package/dist/filter/collect.d.ts +43 -25
  165. package/dist/filter/collect.d.ts.map +1 -1
  166. package/dist/filter/collect.js +107 -38
  167. package/dist/filter/collect.js.map +1 -1
  168. package/dist/filter/index.d.ts +7 -5
  169. package/dist/filter/index.d.ts.map +1 -1
  170. package/dist/filter/index.js +6 -14
  171. package/dist/filter/index.js.map +1 -1
  172. package/dist/filter/map.d.ts +112 -20
  173. package/dist/filter/map.d.ts.map +1 -1
  174. package/dist/filter/map.js +271 -52
  175. package/dist/filter/map.js.map +1 -1
  176. package/dist/filter/parse.d.ts +70 -26
  177. package/dist/filter/parse.d.ts.map +1 -1
  178. package/dist/filter/parse.js +212 -79
  179. package/dist/filter/parse.js.map +1 -1
  180. package/dist/filter/record-id.d.ts +19 -0
  181. package/dist/filter/record-id.d.ts.map +1 -0
  182. package/dist/filter/record-id.js +37 -0
  183. package/dist/filter/record-id.js.map +1 -0
  184. package/dist/filter/serialize.d.ts +45 -19
  185. package/dist/filter/serialize.d.ts.map +1 -1
  186. package/dist/filter/serialize.js +146 -50
  187. package/dist/filter/serialize.js.map +1 -1
  188. package/dist/filter/types.d.ts +132 -21
  189. package/dist/filter/types.d.ts.map +1 -1
  190. package/dist/filter/types.js +2 -11
  191. package/dist/filter/types.js.map +1 -1
  192. package/dist/hooks/index.d.ts +6 -3
  193. package/dist/hooks/index.d.ts.map +1 -1
  194. package/dist/hooks/index.js +38 -8
  195. package/dist/hooks/index.js.map +1 -1
  196. package/dist/index.d.ts +10 -9
  197. package/dist/index.d.ts.map +1 -1
  198. package/dist/index.js +5 -5
  199. package/dist/index.js.map +1 -1
  200. package/dist/internal.d.ts +11 -2
  201. package/dist/internal.d.ts.map +1 -1
  202. package/dist/internal.js +8 -8
  203. package/dist/internal.js.map +1 -1
  204. package/dist/lib/database-errors.d.ts +2 -1
  205. package/dist/lib/database-errors.d.ts.map +1 -1
  206. package/dist/lib/database-errors.js +5 -4
  207. package/dist/lib/database-errors.js.map +1 -1
  208. package/dist/mcp/advertise.d.ts +5 -13
  209. package/dist/mcp/advertise.d.ts.map +1 -1
  210. package/dist/mcp/advertise.js +7 -22
  211. package/dist/mcp/advertise.js.map +1 -1
  212. package/dist/mcp/arguments.d.ts.map +1 -1
  213. package/dist/mcp/arguments.js +8 -11
  214. package/dist/mcp/arguments.js.map +1 -1
  215. package/dist/mcp/field-schema.d.ts +4 -15
  216. package/dist/mcp/field-schema.d.ts.map +1 -1
  217. package/dist/mcp/field-schema.js +50 -69
  218. package/dist/mcp/field-schema.js.map +1 -1
  219. package/dist/mcp/handler.d.ts +111 -18
  220. package/dist/mcp/handler.d.ts.map +1 -1
  221. package/dist/mcp/handler.js +231 -87
  222. package/dist/mcp/handler.js.map +1 -1
  223. package/dist/mcp/index.d.ts +2 -1
  224. package/dist/mcp/index.d.ts.map +1 -1
  225. package/dist/mcp/index.js +1 -1
  226. package/dist/mcp/index.js.map +1 -1
  227. package/dist/mcp/procedure-tools.d.ts +63 -0
  228. package/dist/mcp/procedure-tools.d.ts.map +1 -0
  229. package/dist/mcp/procedure-tools.js +139 -0
  230. package/dist/mcp/procedure-tools.js.map +1 -0
  231. package/dist/mcp/projection.d.ts +6 -5
  232. package/dist/mcp/projection.d.ts.map +1 -1
  233. package/dist/mcp/projection.js +33 -38
  234. package/dist/mcp/projection.js.map +1 -1
  235. package/dist/mcp/reachability.d.ts +13 -0
  236. package/dist/mcp/reachability.d.ts.map +1 -0
  237. package/dist/mcp/reachability.js +51 -0
  238. package/dist/mcp/reachability.js.map +1 -0
  239. package/dist/mcp/relation-member.d.ts +15 -0
  240. package/dist/mcp/relation-member.d.ts.map +1 -0
  241. package/dist/mcp/relation-member.js +50 -0
  242. package/dist/mcp/relation-member.js.map +1 -0
  243. package/dist/mcp/types.d.ts +12 -0
  244. package/dist/mcp/types.d.ts.map +1 -1
  245. package/dist/mcp/where-id-boundary.d.ts.map +1 -1
  246. package/dist/mcp/where-id-boundary.js +12 -24
  247. package/dist/mcp/where-id-boundary.js.map +1 -1
  248. package/dist/mcp/where-reachability.d.ts +10 -0
  249. package/dist/mcp/where-reachability.d.ts.map +1 -0
  250. package/dist/mcp/where-reachability.js +88 -0
  251. package/dist/mcp/where-reachability.js.map +1 -0
  252. package/dist/members/claims.d.ts +71 -0
  253. package/dist/members/claims.d.ts.map +1 -0
  254. package/dist/members/claims.js +199 -0
  255. package/dist/members/claims.js.map +1 -0
  256. package/dist/members/list-members.d.ts +87 -0
  257. package/dist/members/list-members.d.ts.map +1 -0
  258. package/dist/members/list-members.js +250 -0
  259. package/dist/members/list-members.js.map +1 -0
  260. package/dist/procedures/client.d.ts +163 -0
  261. package/dist/procedures/client.d.ts.map +1 -0
  262. package/dist/procedures/client.js +152 -0
  263. package/dist/procedures/client.js.map +1 -0
  264. package/dist/procedures/codes.d.ts +23 -0
  265. package/dist/procedures/codes.d.ts.map +1 -0
  266. package/dist/procedures/codes.js +46 -0
  267. package/dist/procedures/codes.js.map +1 -0
  268. package/dist/procedures/context-face.d.ts +4 -0
  269. package/dist/procedures/context-face.d.ts.map +1 -0
  270. package/dist/procedures/context-face.js +31 -0
  271. package/dist/procedures/context-face.js.map +1 -0
  272. package/dist/procedures/failures.d.ts +31 -0
  273. package/dist/procedures/failures.d.ts.map +1 -0
  274. package/dist/procedures/failures.js +51 -0
  275. package/dist/procedures/failures.js.map +1 -0
  276. package/dist/procedures/http.d.ts +114 -0
  277. package/dist/procedures/http.d.ts.map +1 -0
  278. package/dist/procedures/http.js +224 -0
  279. package/dist/procedures/http.js.map +1 -0
  280. package/dist/procedures/index.d.ts +7 -0
  281. package/dist/procedures/index.d.ts.map +1 -0
  282. package/dist/procedures/index.js +11 -0
  283. package/dist/procedures/index.js.map +1 -0
  284. package/dist/procedures/procedure.d.ts +204 -0
  285. package/dist/procedures/procedure.d.ts.map +1 -0
  286. package/dist/procedures/procedure.js +123 -0
  287. package/dist/procedures/procedure.js.map +1 -0
  288. package/dist/procedures/result.d.ts +42 -0
  289. package/dist/procedures/result.d.ts.map +1 -0
  290. package/dist/procedures/result.js +51 -0
  291. package/dist/procedures/result.js.map +1 -0
  292. package/dist/procedures/run.d.ts +36 -0
  293. package/dist/procedures/run.d.ts.map +1 -0
  294. package/dist/procedures/run.js +76 -0
  295. package/dist/procedures/run.js.map +1 -0
  296. package/dist/procedures/server.d.ts +131 -0
  297. package/dist/procedures/server.d.ts.map +1 -0
  298. package/dist/procedures/server.js +115 -0
  299. package/dist/procedures/server.js.map +1 -0
  300. package/dist/procedures/validate.d.ts +60 -0
  301. package/dist/procedures/validate.d.ts.map +1 -0
  302. package/dist/procedures/validate.js +254 -0
  303. package/dist/procedures/validate.js.map +1 -0
  304. package/dist/procedures/web-session.d.ts +12 -0
  305. package/dist/procedures/web-session.d.ts.map +1 -0
  306. package/dist/procedures/web-session.js +35 -0
  307. package/dist/procedures/web-session.js.map +1 -0
  308. package/dist/query/relationship-options.d.ts +8 -0
  309. package/dist/query/relationship-options.d.ts.map +1 -1
  310. package/dist/query/relationship-options.js +18 -4
  311. package/dist/query/relationship-options.js.map +1 -1
  312. package/dist/secured/binding.d.ts +84 -0
  313. package/dist/secured/binding.d.ts.map +1 -0
  314. package/dist/secured/binding.js +52 -0
  315. package/dist/secured/binding.js.map +1 -0
  316. package/dist/secured/declared-branch.d.ts +11 -0
  317. package/dist/secured/declared-branch.d.ts.map +1 -0
  318. package/dist/secured/declared-branch.js +17 -0
  319. package/dist/secured/declared-branch.js.map +1 -0
  320. package/dist/secured/field-visibility.d.ts +56 -0
  321. package/dist/secured/field-visibility.d.ts.map +1 -0
  322. package/dist/secured/field-visibility.js +624 -0
  323. package/dist/secured/field-visibility.js.map +1 -0
  324. package/dist/secured/include.d.ts +77 -37
  325. package/dist/secured/include.d.ts.map +1 -1
  326. package/dist/secured/include.js +228 -122
  327. package/dist/secured/include.js.map +1 -1
  328. package/dist/secured/lock.d.ts +8 -2
  329. package/dist/secured/lock.d.ts.map +1 -1
  330. package/dist/secured/lock.js +44 -15
  331. package/dist/secured/lock.js.map +1 -1
  332. package/dist/secured/lower.d.ts.map +1 -1
  333. package/dist/secured/lower.js +15 -4
  334. package/dist/secured/lower.js.map +1 -1
  335. package/dist/secured/read.d.ts +13 -52
  336. package/dist/secured/read.d.ts.map +1 -1
  337. package/dist/secured/read.js +88 -614
  338. package/dist/secured/read.js.map +1 -1
  339. package/dist/secured/select.d.ts +0 -24
  340. package/dist/secured/select.d.ts.map +1 -1
  341. package/dist/secured/select.js +60 -153
  342. package/dist/secured/select.js.map +1 -1
  343. package/dist/secured/vocabulary.d.ts +13 -1
  344. package/dist/secured/vocabulary.d.ts.map +1 -1
  345. package/dist/secured/vocabulary.js +173 -83
  346. package/dist/secured/vocabulary.js.map +1 -1
  347. package/dist/testing/untyped-rule.d.ts +8 -0
  348. package/dist/testing/untyped-rule.d.ts.map +1 -0
  349. package/dist/testing/untyped-rule.js +4 -0
  350. package/dist/testing/untyped-rule.js.map +1 -0
  351. package/dist/types/index.d.ts +1 -1
  352. package/dist/types/index.d.ts.map +1 -1
  353. package/dist/types/rows.d.ts +18 -1
  354. package/dist/types/rows.d.ts.map +1 -1
  355. package/dist/validation/config-refusal.d.ts +3 -1
  356. package/dist/validation/config-refusal.d.ts.map +1 -1
  357. package/dist/validation/database-config.d.ts +1 -15
  358. package/dist/validation/database-config.d.ts.map +1 -1
  359. package/dist/validation/database-config.js +32 -1
  360. package/dist/validation/database-config.js.map +1 -1
  361. package/dist/validation/default-value.d.ts.map +1 -1
  362. package/dist/validation/default-value.js +3 -8
  363. package/dist/validation/default-value.js.map +1 -1
  364. package/dist/validation/extension-packs.d.ts.map +1 -1
  365. package/dist/validation/extension-packs.js +1 -0
  366. package/dist/validation/extension-packs.js.map +1 -1
  367. package/dist/validation/field-config.d.ts +3 -2
  368. package/dist/validation/field-config.d.ts.map +1 -1
  369. package/dist/validation/field-config.js +3 -1
  370. package/dist/validation/field-config.js.map +1 -1
  371. package/dist/validation/field-names.d.ts +2 -1
  372. package/dist/validation/field-names.d.ts.map +1 -1
  373. package/dist/validation/field-names.js +76 -63
  374. package/dist/validation/field-names.js.map +1 -1
  375. package/dist/validation/identifier-names.d.ts +1 -0
  376. package/dist/validation/identifier-names.d.ts.map +1 -1
  377. package/dist/validation/identifier-names.js +17 -9
  378. package/dist/validation/identifier-names.js.map +1 -1
  379. package/dist/validation/needs-closure.d.ts +30 -14
  380. package/dist/validation/needs-closure.d.ts.map +1 -1
  381. package/dist/validation/needs-closure.js +184 -31
  382. package/dist/validation/needs-closure.js.map +1 -1
  383. package/dist/validation/relations.d.ts.map +1 -1
  384. package/dist/validation/relations.js +11 -0
  385. package/dist/validation/relations.js.map +1 -1
  386. package/dist/validation/schema.d.ts +4 -3
  387. package/dist/validation/schema.d.ts.map +1 -1
  388. package/dist/validation/schema.js +8 -6
  389. package/dist/validation/schema.js.map +1 -1
  390. package/package.json +26 -10
  391. package/dist/access/field-visibility.d.ts +0 -58
  392. package/dist/access/field-visibility.d.ts.map +0 -1
  393. package/dist/access/field-visibility.js +0 -383
  394. package/dist/access/field-visibility.js.map +0 -1
  395. package/dist/access/query-validation.d.ts +0 -30
  396. package/dist/access/query-validation.d.ts.map +0 -1
  397. package/dist/access/query-validation.js +0 -49
  398. package/dist/access/query-validation.js.map +0 -1
  399. package/dist/access/system-fields.d.ts +0 -2
  400. package/dist/access/system-fields.d.ts.map +0 -1
  401. package/dist/access/system-fields.js +0 -7
  402. package/dist/access/system-fields.js.map +0 -1
@@ -1,23 +1,28 @@
1
1
  import { checkAccess } from '../access/index.js';
2
- import { resolveSyntheticReverseRelation } from '../access/engine.js';
3
- import { ValidationError, DatabaseError } from '../hooks/index.js';
2
+ import { bindSessionReadOnly, sealSession } from '../access/actor.js';
3
+ import { ValidationError, DatabaseError, isPlainObject } from '../hooks/index.js';
4
4
  import { databaseErrorMessage, normalizeDatabaseError } from '../lib/prisma-errors.js';
5
5
  import { isClientSafeError } from '../lib/client-safe-error.js';
6
6
  import { nullPrototypeRegistry } from '../lib/null-prototype-registry.js';
7
7
  import { warnOnce } from '../lib/warn-once.js';
8
8
  import { createSecuredRead } from '../secured/read.js';
9
- import { createLivenessProbe, createRowLockLane, RowLockUnavailableError, unusableRowLockLane, } from '../secured/lock.js';
9
+ import { invalidatesSessionVocabularyOf, withOwnSessionVocabulary, } from '../access/session-vocabulary.js';
10
+ import { withSingletonProbe } from './write-target.js';
11
+ import { createLivenessProbe, createRowLockLane, RowLockUnavailableError, RowLockLaneUnavailableError, unusableRowLockLane, } from '../secured/lock.js';
10
12
  import { createUnsafeSurface, createUnsafeTransactionSurface, unavailableUnsafeSurface, } from '../unsafe.js';
11
13
  import { ENGINE_FACE, engineContextOf } from './engine-context.js';
12
14
  import { withOrigin } from '../origin.js';
13
- import { getRelationshipOptions, isRelationshipLabelReadable, } from '../query/relationship-options.js';
15
+ import { getRelationshipOptions, isRelationshipLabelReadable, relationshipSearchWhere, } from '../query/relationship-options.js';
14
16
  import { runWritePipeline, createWriteStrategy, updateWriteStrategy, deleteWriteStrategy, } from './write-pipeline.js';
15
- import { resolveJunctionEdge, ownsForeignKey } from './junction.js';
16
- import { isRelationshipField } from '../fields/index.js';
17
+ import { resolveJunctionEdge, resolveLinkableScope } from './junction.js';
18
+ import { assertListMembersResolve, resolveListMember, resolveListMembers, } from '../members/list-members.js';
17
19
  import { parseListId } from '../contract/id-boundary.js';
18
20
  import { reportAfterTransactionFailures } from './transaction-boundary.js';
21
+ import { isRowActionAvailable } from '../config/row-action-availability.js';
22
+ import { checkHasAccess } from '../config/has-access-gate.js';
19
23
  import { TransactionRegistry, TransactionRolledBackError, } from '../access/transaction-registry.js';
20
24
  export { TransactionRolledBackError };
25
+ const LINKED_TARGET_LIMIT = 1000;
21
26
  /**
22
27
  * Warn once per (list, operation) when a caller passes `select` to a read op
23
28
  * that ignores it. See "Narrowing Reads" in packages/core/CLAUDE.md.
@@ -30,30 +35,30 @@ function warnIfSelectIgnored(args, listName, operation) {
30
35
  `Narrow a read with \`include\`, or with \`.select()\` on the secured surface, instead. ` +
31
36
  `See https://stack.opensaas.au/docs/concepts/queries`);
32
37
  }
33
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
34
- function isSingletonList(listConfig) {
35
- return !!listConfig.isSingleton;
36
- }
37
- /**
38
- * Whether `fieldName` on `listKey` owns a foreign-key column — the property
39
- * `removeRelated`/`createRelated`/`linkRelated` actually need, rather than
40
- * `many`, which is only a proxy for it: a non-owning to-one (the inverse half
41
- * of a one-to-one) has `many` falsy exactly like an owning one, and a
42
- * synthetic `from_<List>_<field>` back-relation is never declared, so it is
43
- * never itself in `listConfig.fields` (#1442).
44
- */
45
- function classifyBackReference(listKey, fieldName,
46
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
47
- listConfig, config) {
48
- const field = listConfig.fields[fieldName];
49
- if (isRelationshipField(field)) {
50
- return ownsForeignKey(config, listKey, fieldName, field)
51
- ? { kind: 'owning', field }
52
- : { kind: 'nonOwning' };
38
+ function classifyBackReference(listKey, fieldName, config) {
39
+ const member = resolveListMember(config, listKey, fieldName);
40
+ if (member === undefined)
41
+ return { kind: 'notRelationship' };
42
+ switch (member.kind) {
43
+ case 'field': {
44
+ const { storage } = member;
45
+ if (storage.kind !== 'relation')
46
+ return { kind: 'notRelationship' };
47
+ return storage.foreignKey === undefined
48
+ ? { kind: 'nonOwning' }
49
+ : { kind: 'owning', relatedList: storage.relatedList, foreignKey: storage.foreignKey.name };
50
+ }
51
+ case 'syntheticBackRelation':
52
+ return { kind: 'nonOwning' };
53
+ case 'foreignKey':
54
+ case 'partColumn':
55
+ case 'systemField':
56
+ return { kind: 'notRelationship' };
57
+ default: {
58
+ const unhandled = member;
59
+ return unhandled;
60
+ }
53
61
  }
54
- return resolveSyntheticReverseRelation(fieldName, listKey, config) !== null
55
- ? { kind: 'nonOwning' }
56
- : { kind: 'notRelationship' };
57
62
  }
58
63
  function isRawRowCollection(value) {
59
64
  return (typeof value === 'object' &&
@@ -90,12 +95,8 @@ function assertIdentityWhere(where, listName, terminal) {
90
95
  ], {});
91
96
  }
92
97
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
93
- function shouldAutoCreate(listConfig) {
94
- if (!listConfig.isSingleton)
95
- return false;
96
- if (typeof listConfig.isSingleton === 'boolean')
97
- return true;
98
- return listConfig.isSingleton.autoCreate !== false;
98
+ function autoCreates(listConfig) {
99
+ return typeof listConfig.isSingleton !== 'object' || listConfig.isSingleton.autoCreate !== false;
99
100
  }
100
101
  /**
101
102
  * Thrown when `context.transaction()` can neither open a transaction nor join
@@ -342,13 +343,19 @@ function transactionFace(base, lock, owner) {
342
343
  advisoryLock: async (key) => {
343
344
  if (lock === undefined)
344
345
  throw new RowLockUnavailableError('advisoryLock()');
345
- await lock.advisory(key);
346
+ try {
347
+ await lock.advisory(key);
348
+ }
349
+ catch (error) {
350
+ owner.poison(error);
351
+ throw error;
352
+ }
346
353
  },
347
354
  sudo: () => transactionFace(base.sudo(), lock, owner),
348
355
  withSession: (session) => transactionFace(base.withSession(session), lock, owner),
349
356
  transaction: (fn) => joinNested(fn, face, owner),
350
357
  };
351
- return face;
358
+ return bindSessionReadOnly(face);
352
359
  }
353
360
  // A database failure reaches the client as the stack's own message (ADR-0042),
354
361
  // so the driver's diagnostic text — carried on `cause` — reaches no channel at
@@ -359,6 +366,7 @@ function logDatabaseFailure(error, listKey, action) {
359
366
  return;
360
367
  console.error(`Database error on "${action}" for list "${listKey}":`, error.cause ?? error);
361
368
  }
369
+ const ROW_ACTION_NOT_RUN = 'This action was not run';
362
370
  function clientFailure(error, config, listKey, action, options = {}) {
363
371
  const classifier = config.ui?.classifyActionError;
364
372
  if (classifier) {
@@ -443,7 +451,7 @@ function assertValidSession(session) {
443
451
  if (undefinedKeys.length > 0)
444
452
  throw new InvalidSessionError(undefinedKeys);
445
453
  }
446
- export function getContext(config, ormHandle, session, storage, _isSudo = false,
454
+ export function getContext(config, ormHandle, givenSession, storage, _isSudo = false,
447
455
  // Internal: when rebuilding the context against a transaction client, reuse the
448
456
  // already-initialised plugin services rather than re-running plugin runtimes.
449
457
  _sharedPlugins,
@@ -471,7 +479,8 @@ _unsafeTransaction,
471
479
  // carried through by `sudo()`/`withSession()` unchanged; omitted for a
472
480
  // fresh, non-transactional context, which is its own base.
473
481
  _baseContext) {
474
- assertValidSession(session);
482
+ assertValidSession(givenSession);
483
+ const session = givenSession === null ? null : sealSession(givenSession);
475
484
  // Broad type to allow dynamic model access; populated by populateDbDelegate below.
476
485
  const db = {};
477
486
  const openTransaction = transactionOpenerFor(config, client, _unsafeTransaction);
@@ -514,6 +523,8 @@ _baseContext) {
514
523
  _config: config,
515
524
  _baseContext,
516
525
  };
526
+ withOwnSessionVocabulary(context, config);
527
+ withSingletonProbe(context);
517
528
  populateDbDelegate(db, config, ormHandle, context, lock);
518
529
  // Skipped when reusing shared plugins (transaction rebind) so runtimes — and
519
530
  // any side effects they carry — run exactly once per top-level context.
@@ -590,22 +601,15 @@ _baseContext) {
590
601
  error: `Bulk action "${props.key}" not found on list "${props.listKey}"`,
591
602
  };
592
603
  }
604
+ if (!(await checkHasAccess(action, context, props.listKey, 'Bulk action'))) {
605
+ return { bulkAction: false, error: 'Access denied' };
606
+ }
593
607
  try {
594
- if (action.hasAccess) {
595
- const allowed = await action.hasAccess({
596
- session: context.session,
597
- context,
598
- listKey: props.listKey,
599
- });
600
- if (!allowed) {
601
- return { bulkAction: false, error: 'Access denied' };
602
- }
603
- }
604
- const result = await action.handler({
608
+ const result = await transaction(async (tx) => action.handler({
605
609
  listKey: props.listKey,
606
610
  ids: props.ids,
607
- context,
608
- });
611
+ context: engineContextOf(tx),
612
+ }));
609
613
  return { bulkAction: true, message: result?.message };
610
614
  }
611
615
  catch (error) {
@@ -615,6 +619,56 @@ _baseContext) {
615
619
  return { bulkAction: false, error: failure.error, code: failure.code };
616
620
  }
617
621
  }
622
+ // A missing row, a denied row, a failed `hasAccess` and a row that is no
623
+ // longer eligible all answer with this one outcome, so a caller cannot tell
624
+ // them apart (Silent failure).
625
+ if (props.action === 'rowAction') {
626
+ const notRun = { rowAction: false, error: ROW_ACTION_NOT_RUN };
627
+ const rowActions = listConfig.ui?.listView?.rowActions ?? [];
628
+ const action = rowActions.find((a) => a.key === props.key);
629
+ if (!action) {
630
+ return {
631
+ rowAction: false,
632
+ error: `Row action "${props.key}" not found on list "${props.listKey}"`,
633
+ };
634
+ }
635
+ const id = parseId(props.listKey, props.id);
636
+ if (id === null)
637
+ return notRun;
638
+ if (!(await checkHasAccess(action, context, props.listKey, 'Row action')))
639
+ return notRun;
640
+ try {
641
+ return await transaction(async (tx) => {
642
+ const list = tx.db[props.listKey];
643
+ const locked = await list
644
+ .where({ id: { equals: id } })
645
+ .forUpdate()
646
+ .first();
647
+ if (locked === null)
648
+ return notRun;
649
+ const item = await list.where({ id: { equals: id } }).first();
650
+ if (item === null)
651
+ return notRun;
652
+ const txContext = engineContextOf(tx);
653
+ if (!isRowActionAvailable(action, props.listKey, item, txContext.session)) {
654
+ return notRun;
655
+ }
656
+ const result = await action.handler({
657
+ listKey: props.listKey,
658
+ id,
659
+ item,
660
+ context: txContext,
661
+ });
662
+ return { rowAction: true, message: result?.message };
663
+ });
664
+ }
665
+ catch (error) {
666
+ const failure = clientFailure(error, config, props.listKey, props.action, {
667
+ genericMessage: 'Action failed',
668
+ });
669
+ return { rowAction: false, error: failure.error, code: failure.code };
670
+ }
671
+ }
618
672
  // Runs on the RELATED row (ADR-0018 boundary — see ServerActionProps above).
619
673
  // Honours Silent failure: an access-denied operation returns `null`, which
620
674
  // becomes `{ removed: false }` with a generic reason — never leaking whether
@@ -639,7 +693,7 @@ _baseContext) {
639
693
  if (!props.field) {
640
694
  return { removed: false, error: 'Missing back-reference field for disconnect' };
641
695
  }
642
- const backRef = classifyBackReference(props.listKey, props.field, listConfig, config);
696
+ const backRef = classifyBackReference(props.listKey, props.field, config);
643
697
  if (backRef.kind === 'notRelationship') {
644
698
  return {
645
699
  removed: false,
@@ -665,9 +719,8 @@ _baseContext) {
665
719
  // owning foreign-key column `<field>Id` (relationship-input.ts),
666
720
  // which is the key a bare read (no `include`) returns it under.
667
721
  const fieldName = props.field;
668
- const foreignKeyColumn = `${fieldName}Id`;
669
- const parentListKey = backRef.field.ref.split('.')[0];
670
- const expectedParentId = parseId(parentListKey, props.parentId);
722
+ const foreignKeyColumn = backRef.foreignKey;
723
+ const expectedParentId = parseId(backRef.relatedList, props.parentId);
671
724
  if (expectedParentId === null) {
672
725
  return { removed: false, error: 'Access denied or operation failed' };
673
726
  }
@@ -764,7 +817,7 @@ _baseContext) {
764
817
  }
765
818
  const data = { ...props.data };
766
819
  if (props.field && props.parentId) {
767
- const backRef = classifyBackReference(props.listKey, props.field, listConfig, config);
820
+ const backRef = classifyBackReference(props.listKey, props.field, config);
768
821
  // The back-reference must name a relationship field on this list; a
769
822
  // non-relationship field would otherwise receive a nonsensical
770
823
  // { connect } value. Also hardening — the drawer only ever passes a
@@ -786,7 +839,7 @@ _baseContext) {
786
839
  `Link the parent from the side that holds the column.`,
787
840
  };
788
841
  }
789
- const parentId = parseId(backRef.field.ref.split('.')[0], props.parentId);
842
+ const parentId = parseId(backRef.relatedList, props.parentId);
790
843
  if (parentId === null) {
791
844
  return { created: false, error: 'Access denied or operation failed' };
792
845
  }
@@ -862,26 +915,26 @@ _baseContext) {
862
915
  // update returns `null`, surfaced as `{ linked: false }` with a generic
863
916
  // reason.
864
917
  if (props.action === 'linkRelated') {
865
- const backRef = classifyBackReference(props.listKey, props.field, listConfig, config);
866
- if (backRef.kind === 'notRelationship') {
867
- return {
868
- linked: false,
869
- error: `Field "${props.field}" on list "${props.listKey}" is not a relationship field`,
870
- };
871
- }
872
- if (backRef.kind === 'nonOwning') {
873
- return {
874
- linked: false,
875
- error: `Cannot link through "${props.field}": a non-owning back-reference owns no foreign key. ` +
876
- `Link the parent from the side that holds the column.`,
877
- };
878
- }
879
- const relatedId = parseId(props.listKey, props.id);
880
- const parentId = parseId(backRef.field.ref.split('.')[0], props.parentId);
881
- if (relatedId === null || parentId === null) {
882
- return { linked: false, error: 'Access denied or operation failed' };
883
- }
884
918
  try {
919
+ const backRef = classifyBackReference(props.listKey, props.field, config);
920
+ if (backRef.kind === 'notRelationship') {
921
+ return {
922
+ linked: false,
923
+ error: `Field "${props.field}" on list "${props.listKey}" is not a relationship field`,
924
+ };
925
+ }
926
+ if (backRef.kind === 'nonOwning') {
927
+ return {
928
+ linked: false,
929
+ error: `Cannot link through "${props.field}": a non-owning back-reference owns no foreign key. ` +
930
+ `Link the parent from the side that holds the column.`,
931
+ };
932
+ }
933
+ const relatedId = parseId(props.listKey, props.id);
934
+ const parentId = parseId(backRef.relatedList, props.parentId);
935
+ if (relatedId === null || parentId === null) {
936
+ return { linked: false, error: 'Access denied or operation failed' };
937
+ }
885
938
  const result = await model.update({
886
939
  where: { id: relatedId },
887
940
  data: { [props.field]: { connect: { id: parentId } } },
@@ -927,15 +980,44 @@ _baseContext) {
927
980
  error: `Field "${props.field}" on list "${props.listKey}" is not a relationship field`,
928
981
  };
929
982
  }
930
- const relatedListKey = fieldConfig.ref.split('.')[0];
983
+ const linkedTargetIds = async (linkable) => {
984
+ const rows = await context.db[linkable.junctionListKey]
985
+ .where(linkable.linkedRows)
986
+ .limit(LINKED_TARGET_LIMIT)
987
+ .all();
988
+ return rows.flatMap((row) => {
989
+ const id = row[linkable.targetForeignKey];
990
+ return typeof id === 'string' || typeof id === 'number' ? [id] : [];
991
+ });
992
+ };
993
+ let relatedListKey = fieldConfig.ref.split('.')[0];
994
+ let scope;
995
+ if (props.linkableFor !== undefined) {
996
+ const parentId = parseId(props.listKey, props.linkableFor);
997
+ if (parentId === null)
998
+ return { options: [], searched: false };
999
+ const linkable = resolveLinkableScope(config, props.listKey, props.field, parentId);
1000
+ if (linkable === null)
1001
+ return { options: [], searched: false };
1002
+ relatedListKey = linkable.listKey;
1003
+ scope =
1004
+ linkable.kind === 'where'
1005
+ ? linkable.where
1006
+ : { id: { notIn: await linkedTargetIds(linkable) } };
1007
+ }
931
1008
  const labelReadable = await isRelationshipLabelReadable(context, config, relatedListKey);
932
1009
  const options = await getRelationshipOptions(context, config, relatedListKey, {
933
1010
  labelReadable,
934
1011
  search: props.search,
935
1012
  take: props.take,
936
1013
  selectedIds: props.selectedIds,
1014
+ scope,
937
1015
  });
938
- return { options };
1016
+ const searched = relationshipSearchWhere(config, relatedListKey, {
1017
+ search: props.search,
1018
+ labelReadable,
1019
+ }) !== undefined;
1020
+ return { options, searched };
939
1021
  }
940
1022
  let result = null;
941
1023
  if (props.action === 'create') {
@@ -966,24 +1048,24 @@ _baseContext) {
966
1048
  }
967
1049
  // Bypasses access control; hooks and validation still run.
968
1050
  function sudo() {
969
- return getContext(config, ormHandle, session, context.storage, true, undefined,
1051
+ return vocabularyDerivedFrom(context, getContext(config, ormHandle, session, context.storage, true, undefined,
970
1052
  // ADR-0028: a sudo write issued from inside an owned transaction (e.g.
971
1053
  // `tx.sudo().db.x.create()`) must still defer to that owner.
972
1054
  context._transactionOwner, client, _unsafeTransaction,
973
1055
  // Carry the same base-client context forward (issue #1348) — sudo()
974
1056
  // derives a new context, not a new transaction boundary.
975
- context._baseContext);
1057
+ context._baseContext));
976
1058
  }
977
1059
  // Substitutes the session; access control and hooks still run against it
978
1060
  // (orthogonal to `sudo`, so the receiver's sudo state is preserved).
979
1061
  function withSession(newSession) {
980
- return getContext(config, ormHandle, newSession, context.storage, _isSudo, undefined,
1062
+ return vocabularyDerivedFrom(context, getContext(config, ormHandle, newSession, context.storage, _isSudo, undefined,
981
1063
  // ADR-0028: a write issued from inside an owned transaction (e.g.
982
1064
  // `tx.withSession(s).db.x.create()`) must still defer to that owner.
983
1065
  context._transactionOwner, client, _unsafeTransaction,
984
1066
  // Carry the same base-client context forward (issue #1348) — withSession()
985
1067
  // derives a new context, not a new transaction boundary.
986
- context._baseContext);
1068
+ context._baseContext));
987
1069
  }
988
1070
  // Interactive, hook-firing transaction (#614). See the `transaction` doc on
989
1071
  // `StackContext` above for the atomicity/isolation/retry contract.
@@ -1002,7 +1084,11 @@ _baseContext) {
1002
1084
  }
1003
1085
  const registry = new TransactionRegistry();
1004
1086
  const ormClient = ormHandle;
1005
- const settled = runTransactionBody(fn, registry, ormClient);
1087
+ const settled = runTransactionBody(fn, registry, ormClient).then((result) => {
1088
+ if (registry.hasWritten)
1089
+ context._invalidateSessionVocabulary?.();
1090
+ return result;
1091
+ });
1006
1092
  return settleTransactionOwner(settled, registry, config);
1007
1093
  }
1008
1094
  function runTransactionBody(fn, registry, ormClient) {
@@ -1067,7 +1153,12 @@ _baseContext) {
1067
1153
  _isSudo,
1068
1154
  [ENGINE_FACE]: context,
1069
1155
  };
1070
- return returned;
1156
+ bindSessionReadOnly(context);
1157
+ return bindSessionReadOnly(returned);
1158
+ }
1159
+ function vocabularyDerivedFrom(receiver, derived) {
1160
+ invalidatesSessionVocabularyOf(engineContextOf(derived), receiver);
1161
+ return derived;
1071
1162
  }
1072
1163
  /**
1073
1164
  * Complete the normalisation the engine terminal started, for a write.
@@ -1105,6 +1196,7 @@ function resolvingConstraints(operation, config) {
1105
1196
  export function populateDbDelegate(target, config, ormHandle, context,
1106
1197
  /** The row-lock lane, on a transaction-bound context alone (ADR-0047). */
1107
1198
  lock) {
1199
+ const listMembers = assertListMembersResolve(config);
1108
1200
  for (const [listName, listConfig] of Object.entries(config.lists)) {
1109
1201
  const createOp = resolvingConstraints(createCreate(listName, listConfig, ormHandle, context, config), config);
1110
1202
  const updateOp = resolvingConstraints(createUpdate(listName, listConfig, ormHandle, context, config), config);
@@ -1113,9 +1205,17 @@ lock) {
1113
1205
  update: updateOp,
1114
1206
  delete: resolvingConstraints(createDelete(listName, listConfig, ormHandle, context, config), config),
1115
1207
  };
1116
- const read = createSecuredRead({ listName, listConfig, ormHandle, context, config, lock });
1117
- if (isSingletonList(listConfig)) {
1118
- operations.get = resolvingConstraints(createGet(listName, listConfig, read, context, createOp), config);
1208
+ const read = createSecuredRead({
1209
+ listName,
1210
+ listConfig,
1211
+ ormHandle,
1212
+ context,
1213
+ config,
1214
+ rebindDb: rebindDb(config),
1215
+ lock,
1216
+ });
1217
+ if (listMembers.get(listName)?.singleton === true) {
1218
+ operations.get = resolvingConstraints(createGet(listName, listConfig, read, context, createOp, lock), config);
1119
1219
  }
1120
1220
  else {
1121
1221
  operations.where = read.where;
@@ -1151,6 +1251,10 @@ export function buildDbDelegate(config, ormHandle, context) {
1151
1251
  populateDbDelegate(db, config, ormHandle, context, context._rowLock);
1152
1252
  return db;
1153
1253
  }
1254
+ /** The read binding's `rebindDb`: a hook's `context.db`, built against the hook's own context. */
1255
+ export function rebindDb(config) {
1256
+ return (derived) => buildDbDelegate(config, derived.ormHandle, derived);
1257
+ }
1154
1258
  const WRITE_ARG_KEYS = {
1155
1259
  create: ['data'],
1156
1260
  update: ['where', 'data'],
@@ -1161,6 +1265,9 @@ function assertWriteArgs(args, listName, operation, isSingleton) {
1161
1265
  if (args === null || typeof args !== 'object') {
1162
1266
  throw new ValidationError([`${operation}() on "${listName}" takes an argument object with ${allowed.join(', ')}.`], {});
1163
1267
  }
1268
+ if (operation !== 'delete' && !isPlainObject(Reflect.get(args, 'data'))) {
1269
+ throw new ValidationError([`${operation}() on "${listName}" takes \`data\` as an object of field values.`], {});
1270
+ }
1164
1271
  for (const [key, value] of Object.entries(args)) {
1165
1272
  if (allowed.includes(key) || value === undefined)
1166
1273
  continue;
@@ -1180,7 +1287,7 @@ listConfig, ormHandle, context, config) {
1180
1287
  // Thin adapter over the Write Pipeline: pick the create strategy, run the
1181
1288
  // canonical secured write sequence, return its result.
1182
1289
  return async (args) => {
1183
- assertWriteArgs(args, listName, 'create', isSingletonList(listConfig));
1290
+ assertWriteArgs(args, listName, 'create', resolveListMembers(config, listName).singleton);
1184
1291
  return runWritePipeline({
1185
1292
  listName,
1186
1293
  listConfig,
@@ -1188,7 +1295,7 @@ listConfig, ormHandle, context, config) {
1188
1295
  context,
1189
1296
  config,
1190
1297
  inputData: args.data,
1191
- strategy: createWriteStrategy(listName, listConfig),
1298
+ strategy: createWriteStrategy(listName, listConfig, config),
1192
1299
  });
1193
1300
  };
1194
1301
  }
@@ -1200,7 +1307,7 @@ listConfig, ormHandle, context, config) {
1200
1307
  return async (args) => {
1201
1308
  // Runs before the pipeline's access gate — a `where` the engine cannot
1202
1309
  // lower is the caller's own shape error, not a denial.
1203
- assertWriteArgs(args, listName, 'update', isSingletonList(listConfig));
1310
+ assertWriteArgs(args, listName, 'update', resolveListMembers(config, listName).singleton);
1204
1311
  assertIdentityWhere(args.where, listName, 'update');
1205
1312
  return runWritePipeline({
1206
1313
  listName,
@@ -1219,7 +1326,7 @@ listConfig, ormHandle, context, config) {
1219
1326
  // Thin adapter over the Write Pipeline: pick the delete strategy, run the
1220
1327
  // canonical secured write sequence, return its result.
1221
1328
  return async (args) => {
1222
- assertWriteArgs(args, listName, 'delete', isSingletonList(listConfig));
1329
+ assertWriteArgs(args, listName, 'delete', resolveListMembers(config, listName).singleton);
1223
1330
  assertIdentityWhere(args.where, listName, 'delete');
1224
1331
  return runWritePipeline({
1225
1332
  listName,
@@ -1271,9 +1378,20 @@ function assertBooleanInclude(include, listName) {
1271
1378
  * so the create is refused and `get()` answers `null` — the same `null` a
1272
1379
  * denied or an absent row answers with.
1273
1380
  */
1381
+ async function tookSingletonLock(lock, listName) {
1382
+ try {
1383
+ await lock.advisory(`opensaas:singleton-create:${listName}`);
1384
+ return true;
1385
+ }
1386
+ catch (error) {
1387
+ if (error instanceof RowLockLaneUnavailableError)
1388
+ return false;
1389
+ throw error;
1390
+ }
1391
+ }
1274
1392
  function createGet(listName,
1275
1393
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
1276
- listConfig, read, context, createFn) {
1394
+ listConfig, read, context, createFn, lock) {
1277
1395
  return async (args) => {
1278
1396
  warnIfSelectIgnored(args, listName, 'get');
1279
1397
  assertBooleanInclude(args?.include, listName);
@@ -1281,7 +1399,7 @@ listConfig, read, context, createFn) {
1281
1399
  const item = await scoped.first();
1282
1400
  if (item)
1283
1401
  return item;
1284
- if (!shouldAutoCreate(listConfig))
1402
+ if (!autoCreates(listConfig))
1285
1403
  return null;
1286
1404
  // `first()` conflates denied with absent, and auto-create must fire only on
1287
1405
  // absent — a denied session that provoked a create would both write a row it
@@ -1298,6 +1416,11 @@ listConfig, read, context, createFn) {
1298
1416
  if (readable !== true)
1299
1417
  return null;
1300
1418
  }
1419
+ if (lock !== undefined && (await tookSingletonLock(lock, listName))) {
1420
+ const settled = await scoped.first();
1421
+ if (settled)
1422
+ return settled;
1423
+ }
1301
1424
  try {
1302
1425
  await createFn({ data: {} });
1303
1426
  }