better-supabase 0.7.0 → 0.8.0

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 (500) hide show
  1. package/README.md +6 -2
  2. package/dist/{access-sql-B0dF-SoF.js → access-sql-CrSbK1q-.js} +1 -1
  3. package/dist/{adapter-B-tL8hqg.js → adapter-CN45ibbV.js} +663 -157
  4. package/dist/{agents-CVHGd7It.d.ts → agents-BY_LQXtQ.d.ts} +4 -4
  5. package/dist/{ai-cache-CBWs1W0k.js → ai-cache-Dfgk8nBT.js} +2 -1
  6. package/dist/{ai-cache-DaDu_G5L.d.ts → ai-cache-DrUMMgp6.d.ts} +4 -4
  7. package/dist/{ai-chat-B24UI962.js → ai-chat-CVLRWbtS.js} +4 -3
  8. package/dist/{ai-chat-7amvXjmQ.d.ts → ai-chat-DXkMy74O.d.ts} +5 -5
  9. package/dist/{ai-files-CSPNswUY.js → ai-files-CioLu5du.js} +5 -4
  10. package/dist/ai-message-DfaP8sis.js +14 -0
  11. package/dist/ai-sdk/agents/index.d.ts +4 -4
  12. package/dist/ai-sdk/batches/index.d.ts +4 -4
  13. package/dist/ai-sdk/batches/index.js +4 -4
  14. package/dist/ai-sdk/cache/index.d.ts +2 -2
  15. package/dist/ai-sdk/cache/index.js +2 -2
  16. package/dist/ai-sdk/chat/index.d.ts +1 -1
  17. package/dist/ai-sdk/chat/index.js +8 -20
  18. package/dist/ai-sdk/embeddings/index.d.ts +2 -2
  19. package/dist/ai-sdk/files/index.d.ts +3 -3
  20. package/dist/ai-sdk/files/index.js +4 -4
  21. package/dist/ai-sdk/index.d.ts +37 -9
  22. package/dist/ai-sdk/index.js +3 -2
  23. package/dist/ai-sdk/mcp/index.d.ts +43 -6
  24. package/dist/ai-sdk/mcp/index.js +36 -7
  25. package/dist/ai-sdk/memory/index.d.ts +2 -2
  26. package/dist/ai-sdk/memory/index.js +1 -1
  27. package/dist/ai-sdk/workflow/index.d.ts +6 -6
  28. package/dist/ai-sdk/workflow/index.js +13 -24
  29. package/dist/{ai-tasks-Cd1HMFvB.d.ts → ai-tasks-BRQ6iQLc.d.ts} +4 -4
  30. package/dist/{announcements-ZRGnScWI.d.ts → announcements-Bouy0Ski.d.ts} +3 -3
  31. package/dist/{announcements-CiyOs-xP.js → announcements-p_BFofiR.js} +1 -1
  32. package/dist/api-Dnf2q-Ht.d.ts +370 -0
  33. package/dist/api-DtHFC037.js +676 -0
  34. package/dist/{api-keys-CIjghYjV.d.ts → api-keys-C8BlF3L2.d.ts} +4 -4
  35. package/dist/arazzo/index.d.ts +255 -0
  36. package/dist/arazzo/index.js +622 -0
  37. package/dist/{assistant-DwdpDH1q.d.ts → assistant-DBlFDZsi.d.ts} +5 -5
  38. package/dist/astro/index.d.ts +7 -7
  39. package/dist/astro/index.js +7 -7
  40. package/dist/asyncapi/index.d.ts +103 -0
  41. package/dist/asyncapi/index.js +569 -0
  42. package/dist/authorizer-ayxUDXXP.js +126 -0
  43. package/dist/authorizer-eiOjo-3l.d.ts +73 -0
  44. package/dist/better-result/index.d.ts +118 -0
  45. package/dist/better-result/index.js +64 -0
  46. package/dist/{bind-l4kAvYSv.js → bind-ButSzrHe.js} +1 -1
  47. package/dist/{bind-Bu_ZNa3W.d.ts → bind-CQ5mPyX1.d.ts} +3 -3
  48. package/dist/{block-events-CrT8r7Fe.js → block-events-DTxU5tfr.js} +18 -3
  49. package/dist/{block-fields-GFkxl4dP.js → block-fields-CroxUuF2.js} +3 -3
  50. package/dist/{block-fields-SJ6fEf3o.d.ts → block-fields-D1pfrcIY.d.ts} +2 -2
  51. package/dist/{block-helpers-CKtbFcRv.d.ts → block-helpers-C0Xj8War.d.ts} +2 -2
  52. package/dist/{block-helpers-DWHxHsEQ.js → block-helpers-Cy3pB96I.js} +41 -9
  53. package/dist/{block-hooks-BmjMyXTa.js → block-hooks-BPNMIlLl.js} +3 -3
  54. package/dist/{block-hooks-plbZ0AbJ.d.ts → block-hooks-DaOVC7SC.d.ts} +3 -3
  55. package/dist/{block-transport-BLr-ZgLc.js → block-transport-bAKh-dGc.js} +28 -2
  56. package/dist/{block-transport-DvaoPuZ9.d.ts → block-transport-inD4fFq-.d.ts} +24 -2
  57. package/dist/blocks/agents/index.d.ts +3 -3
  58. package/dist/blocks/agents/index.js +5 -4
  59. package/dist/blocks/ai-cache/index.d.ts +3 -3
  60. package/dist/blocks/ai-cache/index.js +3 -3
  61. package/dist/blocks/ai-chat/index.d.ts +9 -4
  62. package/dist/blocks/ai-chat/index.js +5 -5
  63. package/dist/blocks/ai-chat/react/index.d.ts +3 -3
  64. package/dist/blocks/ai-chat/react/index.js +5 -5
  65. package/dist/blocks/ai-files/index.d.ts +3 -3
  66. package/dist/blocks/ai-files/index.js +3 -3
  67. package/dist/blocks/ai-providers/index.d.ts +3 -3
  68. package/dist/blocks/ai-providers/index.js +8 -7
  69. package/dist/blocks/ai-tasks/index.d.ts +3 -3
  70. package/dist/blocks/ai-tasks/index.js +7 -6
  71. package/dist/blocks/announcements/index.d.ts +3 -3
  72. package/dist/blocks/announcements/index.js +3 -3
  73. package/dist/blocks/announcements/react/index.d.ts +3 -3
  74. package/dist/blocks/announcements/react/index.js +3 -3
  75. package/dist/blocks/api-keys/index.d.ts +5 -5
  76. package/dist/blocks/api-keys/index.js +8 -8
  77. package/dist/blocks/attachments/index.d.ts +12 -8
  78. package/dist/blocks/attachments/index.js +22 -13
  79. package/dist/blocks/audit/index.d.ts +21 -10
  80. package/dist/blocks/audit/index.js +30 -11
  81. package/dist/blocks/billing/index.d.ts +11 -9
  82. package/dist/blocks/billing/index.js +15 -15
  83. package/dist/blocks/comments/index.d.ts +8 -8
  84. package/dist/blocks/comments/index.js +8 -7
  85. package/dist/blocks/connectors/index.d.ts +3 -3
  86. package/dist/blocks/connectors/index.js +7 -6
  87. package/dist/blocks/data-lifecycle/index.d.ts +12 -8
  88. package/dist/blocks/data-lifecycle/index.js +13 -8
  89. package/dist/blocks/entitlements/index.d.ts +3 -3
  90. package/dist/blocks/entitlements/index.js +1 -1
  91. package/dist/blocks/flags/index.d.ts +4 -4
  92. package/dist/blocks/flags/index.js +4 -3
  93. package/dist/blocks/inbox/index.d.ts +3 -3
  94. package/dist/blocks/inbox/index.js +4 -5
  95. package/dist/blocks/inbox/react/index.d.ts +1 -1
  96. package/dist/blocks/inbox/react/index.js +1 -1
  97. package/dist/blocks/inbox/react/server.d.ts +1 -1
  98. package/dist/blocks/index.d.ts +10 -10
  99. package/dist/blocks/index.js +6 -6
  100. package/dist/blocks/jobs/index.d.ts +48 -32
  101. package/dist/blocks/jobs/index.js +44 -287
  102. package/dist/blocks/knowledge/index.d.ts +3 -3
  103. package/dist/blocks/knowledge/index.js +3 -3
  104. package/dist/blocks/memory/index.d.ts +4 -4
  105. package/dist/blocks/memory/index.js +7 -6
  106. package/dist/blocks/notifications/index.d.ts +11 -9
  107. package/dist/blocks/notifications/index.js +20 -25
  108. package/dist/blocks/notifications/react/index.d.ts +1 -1
  109. package/dist/blocks/notifications/react/index.js +1 -1
  110. package/dist/blocks/onboarding/index.d.ts +3 -3
  111. package/dist/blocks/onboarding/index.js +3 -3
  112. package/dist/blocks/onboarding/react/index.d.ts +2 -2
  113. package/dist/blocks/onboarding/react/index.js +2 -2
  114. package/dist/blocks/onboarding/react/server.d.ts +1 -1
  115. package/dist/blocks/organizations/index.d.ts +9 -9
  116. package/dist/blocks/organizations/index.js +11 -18
  117. package/dist/blocks/outbox/index.d.ts +2 -2
  118. package/dist/blocks/outbox/index.js +16 -25
  119. package/dist/blocks/profiles/index.d.ts +7 -7
  120. package/dist/blocks/profiles/index.js +7 -6
  121. package/dist/blocks/push/index.d.ts +4 -4
  122. package/dist/blocks/push/index.js +3 -3
  123. package/dist/blocks/settings/index.d.ts +4 -4
  124. package/dist/blocks/settings/index.js +7 -6
  125. package/dist/blocks/sso/index.d.ts +5 -5
  126. package/dist/blocks/sso/index.js +6 -5
  127. package/dist/blocks/usage/index.d.ts +3 -3
  128. package/dist/blocks/usage/index.js +5 -4
  129. package/dist/blocks/waitlist/index.d.ts +5 -5
  130. package/dist/blocks/waitlist/index.js +5 -4
  131. package/dist/blocks/webhooks/index.d.ts +22 -13
  132. package/dist/blocks/webhooks/index.js +41 -70
  133. package/dist/blocks/workflow-builder/index.d.ts +4 -4
  134. package/dist/blocks/workflow-builder/index.js +3 -3
  135. package/dist/blocks/workflow-builder/react/index.d.ts +4 -4
  136. package/dist/blocks/workflow-builder/react/index.js +4 -4
  137. package/dist/blocks/workflows/index.d.ts +3 -3
  138. package/dist/blocks/workflows/index.js +3 -3
  139. package/dist/blocks/workflows/react/index.d.ts +3 -3
  140. package/dist/blocks/workflows/react/index.js +3 -3
  141. package/dist/build-hPwk3_X5.js +1296 -0
  142. package/dist/{build-BXIzE6Xv.js → build-meLuYGri.js} +3 -3
  143. package/dist/casing-DdFWEtqr.js +16 -0
  144. package/dist/chat-sdk/index.d.ts +6 -6
  145. package/dist/chat-sdk/index.js +5 -4
  146. package/dist/chat-sdk/react/index.d.ts +1 -1
  147. package/dist/chat-sdk/react/server.d.ts +1 -1
  148. package/dist/{claims-DDBQT6BK.js → claims-0KZVT804.js} +1 -1
  149. package/dist/cli/add-1dc5wM5k.js +69 -0
  150. package/dist/cli/arazzo-1.0-BalU61-_.js +532 -0
  151. package/dist/cli/arazzo-1.1-Bnfasbun.js +705 -0
  152. package/dist/cli/asyncapi-3.0.0-C78dBjR6.js +5593 -0
  153. package/dist/cli/asyncapi-3.1.0-g-7aIfV1.js +5833 -0
  154. package/dist/cli/bin.js +4 -4
  155. package/dist/cli/cache-CIfA-jBV.js +483 -0
  156. package/dist/cli/{codemod-Bl_tQpHn.js → codemod-JVlTQQG2.js} +4 -4
  157. package/dist/cli/{command-CK14fP91.js → command-DV-StG1x.js} +5 -0
  158. package/dist/cli/{config-DU7EJImt.js → config-C2Pz2_4A.js} +7 -4
  159. package/dist/cli/config-DpbF8ML3.js +2 -0
  160. package/dist/cli/{config-NiPxAmUF.js → config-M-WzL9O2.js} +116 -18
  161. package/dist/cli/{db-DOBPt660.js → db-BkcfOlyB.js} +2 -1
  162. package/dist/cli/{diff-SjkO5rNr.js → diff-D1jGdb3Y.js} +1 -1
  163. package/dist/cli/{doctor-CVdnLahA.js → doctor-VcDtuusV.js} +317 -222
  164. package/dist/cli/emit-BHHfwUoT.js +1136 -0
  165. package/dist/cli/{env-qXgyMV6r.js → env-B--LMhEe.js} +13 -10
  166. package/dist/cli/env-vzBG90Um.js +2 -0
  167. package/dist/cli/{env-CJLbUVPB.js → env-zHJtMIBo.js} +11 -3
  168. package/dist/cli/{errors-4v4DTtda.js → errors-CqTLXe2M.js} +18 -2
  169. package/dist/cli/{fastest-levenshtein-CFN-lNDv.js → fastest-levenshtein-CF7BCi9l.js} +1 -1
  170. package/dist/cli/files-BVupXPIC.js +34 -0
  171. package/dist/cli/gen-DmVj3u4L.js +322 -0
  172. package/dist/cli/{init-Cr6arjXU.js → glue-C1UE8gQN.js} +16 -313
  173. package/dist/cli/index.d.ts +59 -31
  174. package/dist/cli/index.js +8 -6
  175. package/dist/cli/init-CVZ3s5kl.js +258 -0
  176. package/dist/cli/{introspect-Bzuv1HHj.js → introspect-BToGNfm-.js} +14 -14
  177. package/dist/cli/{io-DI1mTdSA.js → io-CFzJVJ68.js} +5 -1
  178. package/dist/cli/{keys-BGCnnb-s.js → keys-CJhtIxJ3.js} +4 -4
  179. package/dist/cli/metadata-DSRKCaf-.js +133 -0
  180. package/dist/cli/names-D6LrQnOv.js +6 -0
  181. package/dist/cli/openapi-3.0-t7xwkuRH.js +928 -0
  182. package/dist/cli/openapi-3.1-CVze7tBS.js +870 -0
  183. package/dist/cli/openapi-3.2-CFoMYM01.js +1031 -0
  184. package/dist/cli/{openapi-BlRJ18s3.js → openapi-DWa4Ir1q.js} +8 -14
  185. package/dist/cli/prompts-BdeVmVpg.js +2 -0
  186. package/dist/cli/{prompts-BNcNfAve.js → prompts-DZJB1nTw.js} +6 -6
  187. package/dist/cli/{rolldown-runtime-BPOCksWG.js → rolldown-runtime-CMFfr-1z.js} +3 -1
  188. package/dist/cli/run-DA6_lg3w.js +389 -0
  189. package/dist/cli/run-DuN1MX-7.js +705 -0
  190. package/dist/cli/scaffold-5DenHSxF.js +292 -0
  191. package/dist/cli/scaffold-CwQUMFRb.js +2 -0
  192. package/dist/cli/{seed-DQzqT7LP.js → seed-CzBmrGON.js} +14 -18
  193. package/dist/cli/seed-DOmit9Hq.js +2 -0
  194. package/dist/cli/{skills-QQs4q68J.js → skills-CnO8QFS7.js} +7 -6
  195. package/dist/cli/snapshot-Bstk6ulj.js +287 -0
  196. package/dist/cli/source-args-BYfq6imV.js +31 -0
  197. package/dist/cli/spec-CzosTYm3.js +7438 -0
  198. package/dist/cli/spec-T_0Bcyw7.js +2 -0
  199. package/dist/cli/{sql-B8csQPyn.js → sql-BKOOQAX3.js} +240 -218
  200. package/dist/cli/sql-DJrNDxQm.js +3 -0
  201. package/dist/cli/{style-C0NFdJRL.js → style-CB3vxgh0.js} +3 -3
  202. package/dist/cli/typegen-Demi5-VQ.js +486 -0
  203. package/dist/cli/validate-Ca13ktgz.js +7522 -0
  204. package/dist/cli/{version-Bp4fyubI.js → version-B4k0aUxS.js} +1 -1
  205. package/dist/client/index.d.ts +4 -3
  206. package/dist/client/index.js +60 -3
  207. package/dist/client/native/index.d.ts +3 -3
  208. package/dist/client/native/index.js +3 -3
  209. package/dist/{client-CI0Z2zWX.js → client-wxeTQFtB.js} +36 -3
  210. package/dist/{clone-BfgmLU90.js → clone-dN9XOL1K.js} +9 -1
  211. package/dist/{cloud-event-BnmD5fb9.js → cloud-event-CTh9Sr5w.js} +16 -2
  212. package/dist/{cloud-event-C1JCc1bH.d.ts → cloud-event-Dune0KI7.d.ts} +16 -2
  213. package/dist/{compiler-DY_wkj4R.d.ts → compiler-V1qvcST1.d.ts} +2 -2
  214. package/dist/{compose-BIBNgAnq.js → compose-BHej1acw.js} +3 -3
  215. package/dist/{composite-CpHLEo-G.d.ts → composite-CWAJTRBF.d.ts} +6 -6
  216. package/dist/{composite-C6I8ZyaF.js → composite-zTe0TCqj.js} +4 -4
  217. package/dist/config/index.d.ts +3 -4
  218. package/dist/config/index.js +4 -4
  219. package/dist/config-DlKvtt95.js +540 -0
  220. package/dist/{connector-Dv8kK0MO.d.ts → connector-CySQEFcW.d.ts} +1 -1
  221. package/dist/{connectors-CrpknU0P.d.ts → connectors--PGhmiu0.d.ts} +4 -4
  222. package/dist/{context-BCrWe7ow.d.ts → context-DsV2SueA.d.ts} +11 -2
  223. package/dist/context-nPDvQ-Zl.js +41 -0
  224. package/dist/credentials/index.d.ts +5 -5
  225. package/dist/credentials/index.js +9 -17
  226. package/dist/{cron-DVPUg5k3.js → cron-D25Ukpxy.js} +1 -1
  227. package/dist/cron-route-D2AN9SA1.js +24 -0
  228. package/dist/{csv-DCK-PT1n.js → csv-BZnHA1Py.js} +1 -1
  229. package/dist/{define-B-TVjC25.js → define-CFQcvM20.js} +263 -229
  230. package/dist/{define-CJJkkr1-.d.ts → define-DmcfoNXB.d.ts} +136 -111
  231. package/dist/edge/index.d.ts +66 -13
  232. package/dist/edge/index.js +65 -39
  233. package/dist/elysia/index.d.ts +1 -1
  234. package/dist/elysia/index.js +1 -1
  235. package/dist/{embeddings-C9KGQnXt.d.ts → embeddings-B4vhS-dY.d.ts} +1 -1
  236. package/dist/{ended-XjeGQ5XW.d.ts → ended-CcvcRqEd.d.ts} +7 -1
  237. package/dist/{entitlements-DRl6ZJUm.js → entitlements-BYFf0Cdh.js} +2 -2
  238. package/dist/{entitlements-BKSVGtrG.d.ts → entitlements-Ds8qoYZ-.d.ts} +1 -1
  239. package/dist/env/index.d.ts +1 -1
  240. package/dist/env/index.js +9 -2
  241. package/dist/{errors-B11Duf73.js → errors-2M6CKMP4.js} +5 -0
  242. package/dist/{errors-DLjJHPLK.js → errors-rZ7VIqp6.js} +2 -2
  243. package/dist/{escape-like-ImTK0ps_.d.ts → escape-like-DDWoHzh_.d.ts} +1 -1
  244. package/dist/eve/index.d.ts +5 -5
  245. package/dist/eve/index.js +5 -11
  246. package/dist/{eve-gT2Fpjut.d.ts → eve-CoAIcCkq.d.ts} +2 -2
  247. package/dist/events/index.d.ts +4 -4
  248. package/dist/events/index.js +7 -2
  249. package/dist/{events-DWDhx77e.d.ts → events-D1BOCll8.d.ts} +6 -4
  250. package/dist/{executor-Bq28caBo.js → executor-B-fD7DLt.js} +52 -35
  251. package/dist/executor-B_Hfobee.js +162 -0
  252. package/dist/{executor-BVBFM86G.d.ts → executor-CpxLPCiz.d.ts} +1 -1
  253. package/dist/{executor-CaWigTyR.d.ts → executor-DfEtf0cq.d.ts} +43 -27
  254. package/dist/{executor-DvsBbNBS.d.ts → executor-Drzu3dBK.d.ts} +2 -2
  255. package/dist/{executor-DbvExCFC.d.ts → executor-ngjKL_Pe.d.ts} +2 -2
  256. package/dist/expo/index.d.ts +4 -4
  257. package/dist/expo/index.js +6 -6
  258. package/dist/expo-sqlite/index.d.ts +3 -3
  259. package/dist/expo-sqlite/index.js +2 -2
  260. package/dist/extra-CGQ2_q3S.js +10 -0
  261. package/dist/{field-errors-BFOa7WhB.d.ts → field-errors-DIe9XYWL.d.ts} +17 -7
  262. package/dist/{field-errors-VF1yb8yI.js → field-errors-DZVRWRkf.js} +1 -1
  263. package/dist/format-DTXdu8ya.d.ts +70 -0
  264. package/dist/{framework-KIPvRQJU.d.ts → framework-148t1m3C.d.ts} +5 -5
  265. package/dist/{framework-BDCpJI7o.js → framework-3ey3QmrO.js} +2 -2
  266. package/dist/function-contract-BcZenXMO.d.ts +8 -0
  267. package/dist/{gateway-C1ssRHnf.d.ts → gateway-S9vicgeo.d.ts} +4 -4
  268. package/dist/{guards-BnzDvFrz.js → guards-6F2bCtQR.js} +3 -1
  269. package/dist/h3/index.d.ts +1 -1
  270. package/dist/h3/index.js +1 -1
  271. package/dist/h3/v1/index.d.ts +1 -1
  272. package/dist/h3/v1/index.js +1 -1
  273. package/dist/{message-CaKlqdsX.js → history-GH1HJWQV.js} +65 -13
  274. package/dist/hmac-DCud0myt.js +22 -0
  275. package/dist/hono/index.d.ts +19 -14
  276. package/dist/hono/index.js +21 -16
  277. package/dist/{hooks-1BTCJsiw.js → hooks-Bhza9Hnr.js} +68 -100
  278. package/dist/http-sbmBe5d2.js +25 -0
  279. package/dist/{inbox-i7E1ppo6.d.ts → inbox-Cd1KCEBL.d.ts} +3 -3
  280. package/dist/index-B72Rvv_j.d.ts +89 -0
  281. package/dist/{index-DunNRdnT.d.ts → index-BCHR4Ucl.d.ts} +4 -4
  282. package/dist/{index-CLg87OBW.d.ts → index-BUK7jUzR.d.ts} +6 -0
  283. package/dist/{config-D44Y7PAv.d.ts → index-Ba1SI-uO.d.ts} +625 -278
  284. package/dist/{index-D48jVS-N.d.ts → index-BfxOaOYs.d.ts} +4 -5
  285. package/dist/{index-ClmjK_o-.d.ts → index-CicIyqOe.d.ts} +4 -4
  286. package/dist/{index-ACiNPN4Z.d.ts → index-D69h4QqD.d.ts} +1 -1
  287. package/dist/index-DG2SUXDQ.d.ts +58 -0
  288. package/dist/{index-Bepi-Hgg.d.ts → index-DoNVLHOU.d.ts} +3 -3
  289. package/dist/{index-CdZKQF98.d.ts → index-R274XFlg.d.ts} +1 -1
  290. package/dist/{index-CewnYSpv.d.ts → index-_4R4b01v.d.ts} +8 -18
  291. package/dist/index.d.ts +89 -14
  292. package/dist/index.js +12 -11
  293. package/dist/{json-schema-CvER4kgT.js → json-schema-CT4tvrkA.js} +148 -102
  294. package/dist/{kit-Fm-Fv7q5.js → kit-BhHr9T9v.js} +36 -10
  295. package/dist/{kit-CkNzZUqv.d.ts → kit-W99LCPBS.d.ts} +13 -7
  296. package/dist/{knowledge-BXBbT0Tr.d.ts → knowledge-CAReFpRA.d.ts} +5 -5
  297. package/dist/{knowledge-CDmiMLew.js → knowledge-DnHtb64A.js} +4 -3
  298. package/dist/list/index.d.ts +1 -2
  299. package/dist/{list-query-BRt-zDF7.d.ts → list-query-D3JQeEL7.d.ts} +4 -4
  300. package/dist/mcp/index.d.ts +49 -19
  301. package/dist/mcp/index.js +158 -94
  302. package/dist/mcp/sdk/index.d.ts +38 -6
  303. package/dist/mcp/sdk/index.js +88 -6
  304. package/dist/{message-CfDoR0Y6.d.ts → message-B0fNJgq8.d.ts} +1 -2
  305. package/dist/{messages-B9-5887d.js → messages-CJoHHCWT.js} +4 -205
  306. package/dist/{mfa-Daak8ukG.d.ts → mfa-SZc9YYyb.d.ts} +1 -1
  307. package/dist/model-OgBxvk3N.d.ts +300 -0
  308. package/dist/model-messages-Cxw_Up4f.js +206 -0
  309. package/dist/model-messages-D4GZllOD.d.ts +34 -0
  310. package/dist/modules-DksjZyMW.js +77 -0
  311. package/dist/nestjs/index.d.ts +2 -2
  312. package/dist/nestjs/index.js +1 -1
  313. package/dist/next/index.d.ts +105 -55
  314. package/dist/next/index.js +204 -170
  315. package/dist/node/index.d.ts +2 -2
  316. package/dist/node/index.js +1 -1
  317. package/dist/{onboarding-BZGHYJks.d.ts → onboarding-LZvlK1P4.d.ts} +3 -3
  318. package/dist/openapi/index.d.ts +4 -2
  319. package/dist/openapi/index.js +21 -343
  320. package/dist/optional-peer-D1pi-skw.js +24 -0
  321. package/dist/orpc/index.d.ts +8 -8
  322. package/dist/orpc/index.js +21 -20
  323. package/dist/otel/index.d.ts +3 -3
  324. package/dist/otel/index.js +7 -7
  325. package/dist/{outbox-Cq7pPYvl.d.ts → outbox-DZfAvfzC.d.ts} +6 -6
  326. package/dist/overlay/index.d.ts +233 -0
  327. package/dist/overlay/index.js +554 -0
  328. package/dist/{plugin-FGY8UhYm.d.ts → plugin-CPK2HsbY.d.ts} +42 -3
  329. package/dist/plugins/actor/index.d.ts +1 -1
  330. package/dist/plugins/actor/index.js +1 -1
  331. package/dist/plugins/rules/index.d.ts +2 -2
  332. package/dist/plugins/rules/index.js +1 -1
  333. package/dist/plugins/soft-delete/index.d.ts +3 -3
  334. package/dist/plugins/soft-delete/index.js +9 -2
  335. package/dist/plugins/tenant/index.d.ts +7 -2
  336. package/dist/plugins/tenant/index.js +16 -2
  337. package/dist/plugins/timestamps/index.d.ts +1 -1
  338. package/dist/plugins/timestamps/index.js +8 -1
  339. package/dist/plugins/validation/index.d.ts +2 -2
  340. package/dist/plugins/validation/index.js +4 -4
  341. package/dist/{pool-CAu2nLrL.d.ts → pool-gkhbGp2E.d.ts} +2 -2
  342. package/dist/postgres/index.d.ts +4 -4
  343. package/dist/postgres/index.js +2 -1
  344. package/dist/{postgrest-BLVdEnfe.d.ts → postgrest-BUqLag2Q.d.ts} +1 -1
  345. package/dist/powersync/index.d.ts +5 -5
  346. package/dist/powersync/index.js +4 -4
  347. package/dist/powersync/react/index.d.ts +3 -3
  348. package/dist/powersync/react/index.js +1 -1
  349. package/dist/{problem-BreOl8b8.js → problem-CJvFeGu7.js} +13 -2
  350. package/dist/{problem-DD8LZFjc.d.ts → problem-TvGdxO1t.d.ts} +7 -1
  351. package/dist/{provider-Di3sRutW.js → provider-DxRTex4x.js} +1 -1
  352. package/dist/{provider-D-UEMvSD.d.ts → provider-ib9wzUDz.d.ts} +2 -2
  353. package/dist/query/index.d.ts +2 -2
  354. package/dist/query/index.js +1 -1
  355. package/dist/{query-BQ-NaZon.js → query-Ctz-qKRx.js} +1 -1
  356. package/dist/rate-limit-Bw7HgmFj.js +260 -0
  357. package/dist/react/index.d.ts +9 -9
  358. package/dist/react/index.js +4 -4
  359. package/dist/react/native/index.d.ts +1 -1
  360. package/dist/react/native/index.js +2 -2
  361. package/dist/react/server.d.ts +10 -10
  362. package/dist/react/server.js +3 -3
  363. package/dist/react/session.d.ts +2 -2
  364. package/dist/{react-F80mF4-t.js → react-Bmpo59D7.js} +4 -4
  365. package/dist/react-router/index.d.ts +6 -6
  366. package/dist/react-router/index.js +9 -11
  367. package/dist/{read-set-DuKWC9Mj.js → read-set-DAeWhqPf.js} +2 -2
  368. package/dist/realtime/index.d.ts +3 -3
  369. package/dist/realtime/index.js +30 -36
  370. package/dist/{refusal-DhSU2Vvr.d.ts → refusal-CFI8-5nf.d.ts} +4 -1
  371. package/dist/{refusal-CeJWxmkH.js → refusal-K78A1Vmq.js} +5 -5
  372. package/dist/{resolve-tJZY3FEa.js → resolve-Bvgf3ut_.js} +131 -42
  373. package/dist/{resolve-ChTYeTEl.d.ts → resolve-MxXVWyhd.d.ts} +12 -8
  374. package/dist/resource--vTrBe6I.d.ts +103 -0
  375. package/dist/resource-BqNqlYg9.js +91 -0
  376. package/dist/resource-DA811u_4.js +463 -0
  377. package/dist/resource-execute-rbKvuCsY.d.ts +12 -0
  378. package/dist/resource-schemas-BJ518zFH.js +79 -0
  379. package/dist/resource-types-CqB6GWGT.d.ts +141 -0
  380. package/dist/resources-BVYPnuLo.js +56 -0
  381. package/dist/resources-DZSk8tXJ.d.ts +7 -0
  382. package/dist/{respond-DprrgyXX.d.ts → respond-Cw-zanCm.d.ts} +3 -3
  383. package/dist/{respond-BUgsXNgk.js → respond-volM3ByS.js} +4 -4
  384. package/dist/{result-D7y2fT87.d.ts → result-BchM1XZn.d.ts} +7 -1
  385. package/dist/{result-DzUbqgdW.js → result-DEqHCMKP.js} +1 -1
  386. package/dist/server/index.d.ts +81 -19
  387. package/dist/server/index.js +16 -14
  388. package/dist/{server-ZSJ9rCcV.d.ts → server-types-CrAmZ8jv.d.ts} +110 -36
  389. package/dist/{shared-CxWmcyqB.js → shared-DHjhfRdV.js} +2 -15
  390. package/dist/shared-DTneRoxi.js +14 -0
  391. package/dist/{sign-in-Cb1mwv6X.js → sign-in-D_yoP0PF.js} +1 -1
  392. package/dist/signatures-BRS_p3WD.d.ts +34 -0
  393. package/dist/signatures-DsWv_bYR.js +103 -0
  394. package/dist/{signers-4y62_VIi.d.ts → signers-cpdmZYrv.d.ts} +1 -1
  395. package/dist/solid/index.d.ts +9 -18
  396. package/dist/solid/index.js +2 -2
  397. package/dist/solid-start/index.d.ts +6 -6
  398. package/dist/solid-start/index.js +7 -7
  399. package/dist/spec/index.d.ts +134 -0
  400. package/dist/spec/index.js +353 -0
  401. package/dist/{spec-pins-C89s6DyW.d.ts → spec-pins-CwzDY25w.d.ts} +18 -1
  402. package/dist/{spec-pins--j6mTok4.js → spec-pins-DsLfUH7l.js} +14 -1
  403. package/dist/sql/index.d.ts +145 -119
  404. package/dist/sql/index.js +19921 -19798
  405. package/dist/{executor-De1Of3m3.js → sql-CwuqaQ4Y.js} +34 -169
  406. package/dist/ssr/index.d.ts +4 -4
  407. package/dist/ssr/index.js +3 -2
  408. package/dist/{standard-BK0cqJ7y.js → standard-DkzZUneg.js} +2 -2
  409. package/dist/{standard-CYsm7xpT.d.ts → standard-lmkbOtPB.d.ts} +1 -1
  410. package/dist/{stats-D_AD9GGu.js → stats-DhU78Ctf.js} +8 -4
  411. package/dist/storage/index.d.ts +4 -6
  412. package/dist/storage/index.js +16 -17
  413. package/dist/{bucket-Cl46E3jS.d.ts → storage-api-CB7Zl1Ci.d.ts} +243 -8
  414. package/dist/{store-CGjgWu5n.d.ts → store-DsIYEBnv.d.ts} +1 -1
  415. package/dist/streams/index.d.ts +4 -4
  416. package/dist/streams/index.js +5 -4
  417. package/dist/streams/redis/index.d.ts +1 -1
  418. package/dist/streams/redis/index.js +5 -11
  419. package/dist/{stripe-BMj5LtsT.js → stripe-v-Y2lmop.js} +2 -8
  420. package/dist/supabase-mcp-C6tMoEjn.d.ts +43 -0
  421. package/dist/supabase-mcp-Cpn5A4i-.js +28 -0
  422. package/dist/{support-DWwzVf-O.js → support-D1pFFouF.js} +71 -35
  423. package/dist/{support-view-CVOJJLpc.d.ts → support-view-scqMgtOo.d.ts} +1 -1
  424. package/dist/svelte/index.d.ts +8 -17
  425. package/dist/svelte/index.js +2 -2
  426. package/dist/sveltekit/index.d.ts +7 -7
  427. package/dist/sveltekit/index.js +10 -12
  428. package/dist/table-schema-htM_SbCW.js +286 -0
  429. package/dist/{tags-Cx-LnIQP.d.ts → tags-BO9LjtWG.d.ts} +1 -1
  430. package/dist/tanstack-db/index.d.ts +2 -2
  431. package/dist/tanstack-db/supabase/index.d.ts +52 -0
  432. package/dist/tanstack-db/supabase/index.js +97 -0
  433. package/dist/tanstack-start/index.d.ts +6 -6
  434. package/dist/tanstack-start/index.js +8 -12
  435. package/dist/{tee-CoEppCER.js → tee-Cb98Vn3b.js} +1 -1
  436. package/dist/{template--jDkl3UP.js → template-lPVh-EwW.js} +11 -2
  437. package/dist/{temporal-required-BVvW7SYJ.js → temporal-required-BtynQtM-.js} +1 -1
  438. package/dist/{tenant-BxNFk9bx.d.ts → tenant-CM368LXb.d.ts} +2 -2
  439. package/dist/testing/index.d.ts +249 -118
  440. package/dist/testing/index.js +1418 -870
  441. package/dist/ttl-cache-XzZ-Q2eX.js +29 -0
  442. package/dist/types-BRTSpOIh.js +5 -0
  443. package/dist/{types-C05bxW-W.d.ts → types-Bb_4-vdW.d.ts} +4 -4
  444. package/dist/{types-AYOvcyep.d.ts → types-CD6yCDx3.d.ts} +5 -5
  445. package/dist/{types-6rocye-y.d.ts → types-CbOUc5IH.d.ts} +4 -4
  446. package/dist/{types-6BdhkmZe.d.ts → types-CoE5Zwy4.d.ts} +8 -0
  447. package/dist/{types-DGs5L0VN.d.ts → types-DSJ3-m9X.d.ts} +4 -4
  448. package/dist/{queue-CLJurhdy.d.ts → types-D__3EN0q.d.ts} +17 -19
  449. package/dist/{usage-CrvrL2vw.d.ts → usage-D0NNUFfr.d.ts} +3 -3
  450. package/dist/{vault-wlbBhqm7.d.ts → vault-BpmApxxW.d.ts} +3 -3
  451. package/dist/vercel-connect/index.d.ts +1 -1
  452. package/dist/vercel-connect/index.js +5 -11
  453. package/dist/{verify-DPuWngD4.d.ts → verify-C91Wyp40.d.ts} +5 -35
  454. package/dist/verify-CJbYfADA.js +124 -0
  455. package/dist/{version--AolB5ej.js → version-Cq8gfDbd.js} +1 -1
  456. package/dist/{view-BeFcRV6G.js → view-D5ryq3gz.js} +1 -1
  457. package/dist/{view-CF7ihnkg.d.ts → view-TpXEUcVN.d.ts} +3 -3
  458. package/dist/vue/index.d.ts +9 -18
  459. package/dist/vue/index.js +2 -2
  460. package/dist/{watch-Xuxrvxq-.js → watch-BcvtAHOd.js} +2 -2
  461. package/dist/{watch-DI34G86j.d.ts → watch-COzRWvVN.d.ts} +23 -9
  462. package/dist/{wire-DtZQ4sdE.js → wire-Df3EWkG8.js} +2 -2
  463. package/dist/{workflow-builder-DJ1oHn8g.js → workflow-builder-CHqHpAVt.js} +6 -5
  464. package/dist/workflow-sdk/builder/index.d.ts +3 -3
  465. package/dist/workflow-sdk/index.d.ts +1 -1
  466. package/dist/workflow-sdk/world/index.d.ts +23 -17
  467. package/dist/workflow-sdk/world/index.js +59 -76
  468. package/dist/{workflow-sdk-B3yLD6Br.d.ts → workflow-sdk-DTZyrvNo.d.ts} +3 -3
  469. package/dist/{workflow-sdk-world-D-prir6O.js → workflow-sdk-world-CMV1ahFW.js} +528 -526
  470. package/dist/{workflows-B0j9WKPu.d.ts → workflows-CcpCBfIe.d.ts} +3 -3
  471. package/dist/{workflows-wu1WWBn7.js → workflows-IvxzG2cl.js} +5 -4
  472. package/package.json +54 -3
  473. package/schemas/config-v1.json +243 -0
  474. package/schemas/doctor-report-v1.json +4 -1
  475. package/schemas/spec-manifest-v1.json +95 -0
  476. package/skills/better-supabase/SKILL.md +8 -4
  477. package/skills/better-supabase/references/troubleshooting.md +20 -20
  478. package/skills/better-supabase-api/references/expo.md +6 -3
  479. package/skills/better-supabase-api/references/powersync.md +2 -1
  480. package/skills/better-supabase-auth/SKILL.md +8 -4
  481. package/dist/cli/config-B9HkL8nF.js +0 -2
  482. package/dist/cli/gen-AIf4MREI.js +0 -3100
  483. package/dist/cli/gen-DSrahEdX.js +0 -2
  484. package/dist/cli/prompts-BTYQGunc.js +0 -2
  485. package/dist/cli/run-BO052mki.js +0 -361
  486. package/dist/config-Dn7F5k9A.js +0 -202
  487. package/dist/history-BZih6SFP.js +0 -64
  488. package/dist/index-BkWT_uBO.d.ts +0 -51
  489. package/dist/index-Bxih3l0u.d.ts +0 -81
  490. package/dist/index-CaxrMD1A.d.ts +0 -1
  491. package/dist/index-DQh4VCc9.d.ts +0 -98
  492. package/dist/keys-4MnkWTTh.js +0 -35
  493. package/dist/messages-DYP0sUTe.d.ts +0 -59
  494. package/dist/modules-dxrVK3ID.js +0 -228
  495. package/dist/path-Cv__-OTj.d.ts +0 -17
  496. package/dist/resource-BsvzCMlX.js +0 -212
  497. package/dist/resource-IPS5xi9q.d.ts +0 -74
  498. package/dist/template-CwO38Do8.d.ts +0 -6
  499. package/dist/verify-DL41hbvY.js +0 -232
  500. package/dist/cli/{read-sets-CETOSFx4.js → read-sets-DjJrm8Wj.js} +1 -1
@@ -1,529 +1,243 @@
1
- import { i as sqlString, r as sqlIdent } from "./template--jDkl3UP.js";
2
- //#region src/sql/modules/workflow-sdk-world-ddl.generated.ts
3
- /** The `@workflow/world-postgres` version the DDL below was generated from. */
4
- const WORLD_POSTGRES_VERSION = "5.0.2";
5
- /** The `workflow` schema after every migration above, as idempotent DDL. */
6
- const WORLD_POSTGRES_DDL = `create schema if not exists workflow;
7
-
8
- do $$ begin
9
- create type workflow.status as enum ('pending', 'running', 'completed', 'failed', 'cancelled');
10
- exception when duplicate_object then null;
11
- end $$;
1
+ import { a as sqlString, i as sqlIdent } from "./template-lPVh-EwW.js";
2
+ //#region src/sql/shared.ts
3
+ /** What `record` and the other statement helpers return when there is nothing to do. */
4
+ const NOTHING = "null;";
5
+ /** `alter table ... add column if not exists` for each extra column of a managed table. */
6
+ const addExtraColumns = (table, columns) => columns.map((column) => `\nalter table ${table} add column if not exists ${column.ident} ${column.type};`).join("");
7
+ /**
8
+ * A `jsonb` object of `columns` of row `alias`, keyed by column name, so
9
+ * reads return extra columns without exposing the rest of the row.
10
+ */
11
+ const columnsObject = (alias, columns) => `jsonb_build_object(${columns.map((name) => `${sqlString(name)}, ${alias}.${sqlIdent(name)}`).join(", ")})`;
12
+ const SCHEMA = `create schema if not exists better_supabase;
13
+ grant usage on schema better_supabase to anon, authenticated, service_role;`;
14
+ /**
15
+ * A SQL condition true for the service role and for a direct admin
16
+ * connection (no JWT, a privileged session user), which may act for others.
17
+ */
18
+ const SERVICE_CALLER = "coalesce(nullif((select auth.jwt()) ->> 'role', ''), session_user::text) in ('service_role', 'postgres', 'supabase_admin')";
19
+ /**
20
+ * The `organization.member_added` record for a module that adds a member, so
21
+ * every module writes the same payload. Each value is a SQL expression.
22
+ */
23
+ function memberAddedRecord(ctx, member) {
24
+ return ctx.record({
25
+ type: "organization.member_added",
26
+ payload: `jsonb_build_object('organizationId', ${member.tenant}::text, 'userId', ${member.user}, 'role', ${member.role})`,
27
+ subject: `'organizations/' || ${member.tenant}::text`,
28
+ tenant: member.tenant,
29
+ audit: {
30
+ category: "membership",
31
+ targetType: "user",
32
+ recordId: `${member.user}::text`
33
+ }
34
+ });
35
+ }
36
+ /** Creates the module's schema when it isn't `better_supabase`, then the module schema. */
37
+ function schemaPreamble(ctx) {
38
+ if (ctx.schemaName === "better_supabase") return SCHEMA;
39
+ return `${SCHEMA}
40
+ create schema if not exists ${ctx.schema};
41
+ grant usage on schema ${ctx.schema} to anon, authenticated, service_role;`;
42
+ }
43
+ /**
44
+ * A policy condition for "the caller holds `permission` in this row's
45
+ * tenant". Postgres never inlines `can()` (it is `security definer`), so a
46
+ * `can('tenant', column, ...)` in `using` runs once per row and can't use the
47
+ * tenant index; the `tenant_ids_with` set runs once per statement.
48
+ */
49
+ function tenantIn(tenant, permission) {
50
+ return `${tenant} in (select better_supabase.tenant_ids_with(${permission}))`;
51
+ }
52
+ /** A claim from the top level of the token, then `app_metadata`. */
53
+ function jwtClaim(name) {
54
+ return `coalesce(auth.jwt() ->> ${sqlString(name)}, auth.jwt() -> 'app_metadata' ->> ${sqlString(name)})`;
55
+ }
56
+ /** `table` or `schema.table` as `[schema, table]`, in `public` without a schema. */
57
+ function splitTable(name) {
58
+ const parts = name.split(".");
59
+ if (parts.length > 2 || parts.some((part) => part.length === 0)) throw new TypeError(`"${name}" must be "table" or "schema.table"`);
60
+ return parts.length === 2 ? [parts[0], parts[1]] : ["public", parts[0]];
61
+ }
62
+ /** `table` or `schema.table`, quoted. */
63
+ function quotedTable(name) {
64
+ const [schema, table] = splitTable(name);
65
+ return `${sqlIdent(schema)}.${sqlIdent(table)}`;
66
+ }
67
+ /** `schema.table.column` split into its quoted table and column. */
68
+ function columnRef(where, value) {
69
+ const parts = value.split(".");
70
+ if (parts.length !== 3 || parts.some((part) => part.length === 0)) throw new TypeError(`${where} must be "schema.table.column", got "${value}"`);
71
+ const [schema, table, column] = parts;
72
+ return {
73
+ table: `${sqlIdent(schema)}.${sqlIdent(table)}`,
74
+ column: sqlIdent(column)
75
+ };
76
+ }
77
+ const QUOTED_IDENT = /^"(.*)"$/s;
78
+ /**
79
+ * Replaces the check constraints on one column of a table a module created
80
+ * earlier: `create table if not exists` never changes an inline check, and
81
+ * its generated name follows the table's configured name. For upgrade steps.
82
+ * `column` is a quoted identifier; the catalog stores the bare name.
83
+ */
84
+ function replaceColumnCheck(check) {
85
+ const column = QUOTED_IDENT.exec(check.column)?.[1]?.replaceAll("\"\"", "\"") ?? check.column;
86
+ return `do $$
87
+ declare
88
+ v_name name;
89
+ begin
90
+ for v_name in
91
+ select c.conname from pg_catalog.pg_constraint c
92
+ join pg_catalog.pg_attribute a on a.attrelid = c.conrelid and a.attnum = c.conkey[1]
93
+ where c.conrelid = ${sqlString(check.table)}::regclass and c.contype = 'c'
94
+ and cardinality(c.conkey) = 1 and a.attname = ${sqlString(column)}
95
+ loop
96
+ execute format('alter table %s drop constraint %I', ${sqlString(check.table)}, v_name);
97
+ end loop;
98
+ end;
99
+ $$;
100
+ alter table ${check.table} add constraint ${sqlIdent(check.name)} check (${check.expression});`;
101
+ }
102
+ /**
103
+ * Adds a foreign key to a table a module created earlier, once: `create
104
+ * table if not exists` can't add it to a table that already exists, and the
105
+ * referenced table can come from a module that renders later. Existing rows
106
+ * without a match leave the key unvalidated, with a warning.
107
+ */
108
+ function addForeignKey(fk) {
109
+ return `do $$
110
+ begin
111
+ if not exists (
112
+ select 1 from pg_constraint
113
+ where conrelid = ${sqlString(fk.table)}::regclass and conname = ${sqlString(fk.name)}
114
+ ) then
115
+ alter table ${fk.table} add constraint ${sqlIdent(fk.name)}
116
+ foreign key (${fk.column}) references ${fk.references} on delete ${fk.onDelete} not valid;
117
+ begin
118
+ alter table ${fk.table} validate constraint ${sqlIdent(fk.name)};
119
+ exception when foreign_key_violation then
120
+ raise warning '% has rows without a match, so only new rows are checked. Delete them, then run: alter table % validate constraint %',
121
+ ${sqlString(fk.table)}, ${sqlString(fk.table)}, ${sqlString(fk.name)};
122
+ end;
123
+ end if;
124
+ end;
125
+ $$;`;
126
+ }
127
+ /**
128
+ * An `updated_at` column on a managed table, kept current by the
129
+ * `updated-at` module's `set_updated_at()` (the module must require it).
130
+ */
131
+ function updatedAt(table, column) {
132
+ return `alter table ${table} add column if not exists ${column} timestamptz not null default now();
133
+ drop trigger if exists bs_updated_at on ${table};
134
+ create trigger bs_updated_at before update on ${table}
135
+ for each row execute function better_supabase.set_updated_at(${sqlString(column.replaceAll("\"", ""))});`;
136
+ }
137
+ function renameSql(renames) {
138
+ const schema = sqlString(renames.schema);
139
+ const q = (name) => `${sqlIdent(renames.schema)}.${sqlIdent(name)}`;
140
+ const lines = [];
141
+ let table = renames.table;
142
+ for (const [from, to] of renames.tables ?? []) {
143
+ lines.push(` if to_regclass(${sqlString(`${renames.schema}.${from}`)}) is not null
144
+ and (select c.relkind from pg_class c where c.oid = to_regclass(${sqlString(`${renames.schema}.${from}`)})) in ('r', 'p')
145
+ and to_regclass(${sqlString(`${renames.schema}.${to}`)}) is null then
146
+ alter table ${q(from)} rename to ${sqlIdent(to)};
147
+ end if;`);
148
+ if (from === table) table = to;
149
+ }
150
+ for (const [from, to] of renames.columns ?? []) lines.push(` if exists (select 1 from information_schema.columns c
151
+ where c.table_schema = ${schema} and c.table_name = ${sqlString(table)} and c.column_name = ${sqlString(from)})
152
+ and not exists (select 1 from information_schema.columns c
153
+ where c.table_schema = ${schema} and c.table_name = ${sqlString(table)} and c.column_name = ${sqlString(to)}) then
154
+ alter table ${q(table)} rename column ${sqlIdent(from)} to ${sqlIdent(to)};
155
+ end if;`);
156
+ for (const [from, to] of renames.indexes ?? []) lines.push(` if to_regclass(${sqlString(`${renames.schema}.${from}`)}) is not null
157
+ and to_regclass(${sqlString(`${renames.schema}.${to}`)}) is null then
158
+ alter index ${q(from)} rename to ${sqlIdent(to)};
159
+ end if;`);
160
+ for (const [from, to, args] of renames.functions ?? []) lines.push(` if to_regprocedure(${sqlString(`${renames.schema}.${from}(${args})`)}) is not null
161
+ and to_regprocedure(${sqlString(`${renames.schema}.${to}(${args})`)}) is null then
162
+ alter function ${q(from)}(${args}) rename to ${sqlIdent(to)};
163
+ end if;`);
164
+ if (lines.length === 0) return "";
165
+ return `do $$
166
+ begin
167
+ ${lines.join("\n")}
168
+ end;
169
+ $$;`;
170
+ }
171
+ /**
172
+ * A SQL condition true when `organization` names no row of the installed
173
+ * organizations table. False without the organizations module.
174
+ */
175
+ function organizationMissing(ctx, organization) {
176
+ if (!ctx.installed("organizations")) return "false";
177
+ const organizations = ctx.of("organizations");
178
+ return `not exists (select 1 from ${organizations.table("organizations")} o where o.${organizations.col("organizations", "id")} = ${organization})`;
179
+ }
180
+ function membershipDisabledAt(ctx) {
181
+ if (ctx.module !== "tenant" && !ctx.installed("tenant")) return void 0;
182
+ const tenant = ctx.module === "tenant" ? ctx : ctx.of("tenant");
183
+ if (!tenant.has("memberships", "disabledAt")) return void 0;
184
+ if (!tenant.manages && typeof tenant.config.columns["memberships"]?.["disabledAt"] !== "string") return void 0;
185
+ return tenant.col("memberships", "disabledAt");
186
+ }
187
+ function activeMembership(ctx, alias) {
188
+ const column = membershipDisabledAt(ctx);
189
+ return column === void 0 ? "" : ` and ${alias}.${column} is null`;
190
+ }
191
+ function membershipSuspended(ctx, tenant, user) {
192
+ const column = membershipDisabledAt(ctx);
193
+ if (column === void 0) return void 0;
194
+ const t = ctx.module === "tenant" ? ctx : ctx.of("tenant");
195
+ return `exists (select 1 from ${t.table("memberships")} sm where sm.${t.col("memberships", "tenant")} = ${tenant} and sm.${t.col("memberships", "user")} = ${user} and sm.${column} is not null)`;
196
+ }
197
+ /**
198
+ * `tenant_disabled(id)` and `user_disabled(uuid)` from
199
+ * `sql.modules.access.disabled`. Without a column they return false, so callers
200
+ * don't need to know whether it is configured.
201
+ */
202
+ function disabledHelpers(ctx) {
203
+ const disabled = ctx.modules.access?.disabled ?? {};
204
+ const id = ctx.idType;
205
+ const organizations = managedOrganizations(ctx);
206
+ let tenantCheck = "false";
207
+ if (disabled.tenant !== void 0) tenantCheck = disabledCheck("sql.modules.access.disabled.tenant", disabled.tenant, {
208
+ key: "\"id\"",
209
+ alias: "t",
210
+ value: "tenant_disabled.tenant"
211
+ });
212
+ else if (organizations) tenantCheck = `exists (select 1 from ${organizations.table} t where t.${organizations.id} = tenant_disabled.tenant and (${organizations.flags.map((column) => `t.${column} is not null`).join(" or ")}))`;
213
+ const userCheck = disabled.user === void 0 ? "false" : disabledCheck("sql.modules.access.disabled.user", disabled.user, {
214
+ key: sqlIdent(disabled.userKey ?? "id"),
215
+ alias: "u",
216
+ value: "user_disabled.user_id"
217
+ });
218
+ return `
219
+ -- Disabled tenants and users get no permissions and no membership claims
220
+ -- (modules.access.disabled; with the managed organizations module, its
221
+ -- disabled_at and deleted_at columns).
222
+ create or replace function better_supabase.tenant_disabled(tenant ${id})
223
+ returns boolean
224
+ language sql
225
+ stable
226
+ security definer
227
+ set search_path = ''
228
+ as $$
229
+ select ${tenantCheck}
230
+ $$;
12
231
 
13
- do $$ begin
14
- create type workflow.step_status as enum ('pending', 'running', 'completed', 'failed', 'cancelled');
15
- exception when duplicate_object then null;
16
- end $$;
17
-
18
- do $$ begin
19
- create type workflow.wait_status as enum ('waiting', 'completed');
20
- exception when duplicate_object then null;
21
- end $$;
22
-
23
- create table if not exists workflow.workflow_event_slots (
24
- "run_id" character varying not null,
25
- constraint "workflow_event_slots_pkey" PRIMARY KEY (run_id)
26
- );
27
-
28
- alter table workflow.workflow_event_slots
29
- add column if not exists "run_id" character varying not null;
30
-
31
- create table if not exists workflow.workflow_events (
32
- "id" character varying not null,
33
- "type" character varying not null,
34
- "correlation_id" character varying,
35
- "created_at" timestamp without time zone not null default now(),
36
- "run_id" character varying not null,
37
- "payload" jsonb,
38
- "payload_cbor" bytea,
39
- "spec_version" integer,
40
- "resume_id" character varying,
41
- "resume_payload_digest" character varying,
42
- constraint "workflow_events_run_id_id_pk" PRIMARY KEY (run_id, id)
43
- );
44
-
45
- alter table workflow.workflow_events
46
- add column if not exists "id" character varying not null,
47
- add column if not exists "type" character varying not null,
48
- add column if not exists "correlation_id" character varying,
49
- add column if not exists "created_at" timestamp without time zone not null default now(),
50
- add column if not exists "run_id" character varying not null,
51
- add column if not exists "payload" jsonb,
52
- add column if not exists "payload_cbor" bytea,
53
- add column if not exists "spec_version" integer,
54
- add column if not exists "resume_id" character varying,
55
- add column if not exists "resume_payload_digest" character varying;
56
-
57
- create index if not exists workflow_events_correlation_id_index ON workflow.workflow_events USING btree (correlation_id);
58
-
59
- create unique index if not exists workflow_events_entity_creation_unique ON workflow.workflow_events USING btree (run_id, correlation_id, type) WHERE ((type)::text = ANY ((ARRAY['step_created'::character varying, 'hook_created'::character varying, 'wait_created'::character varying, 'attr_set'::character varying])::text[]));
60
-
61
- create unique index if not exists workflow_events_hook_resume_unique ON workflow.workflow_events USING btree (run_id, resume_id) WHERE (((type)::text = 'hook_received'::text) AND (resume_id IS NOT NULL));
62
-
63
- create table if not exists workflow.workflow_hooks (
64
- "run_id" character varying not null,
65
- "hook_id" character varying not null,
66
- "token" character varying not null,
67
- "owner_id" character varying not null,
68
- "project_id" character varying not null,
69
- "environment" character varying not null,
70
- "created_at" timestamp without time zone not null default now(),
71
- "metadata" jsonb,
72
- "metadata_cbor" bytea,
73
- "spec_version" integer,
74
- "is_webhook" boolean default true,
75
- "is_system" boolean default false,
76
- "resume_context" bytea,
77
- "token_retention_until" timestamp with time zone,
78
- "claimed_from" bytea,
79
- constraint "workflow_hooks_pkey" PRIMARY KEY (hook_id)
80
- );
81
-
82
- alter table workflow.workflow_hooks
83
- add column if not exists "run_id" character varying not null,
84
- add column if not exists "hook_id" character varying not null,
85
- add column if not exists "token" character varying not null,
86
- add column if not exists "owner_id" character varying not null,
87
- add column if not exists "project_id" character varying not null,
88
- add column if not exists "environment" character varying not null,
89
- add column if not exists "created_at" timestamp without time zone not null default now(),
90
- add column if not exists "metadata" jsonb,
91
- add column if not exists "metadata_cbor" bytea,
92
- add column if not exists "spec_version" integer,
93
- add column if not exists "is_webhook" boolean default true,
94
- add column if not exists "is_system" boolean default false,
95
- add column if not exists "resume_context" bytea,
96
- add column if not exists "token_retention_until" timestamp with time zone,
97
- add column if not exists "claimed_from" bytea;
98
-
99
- create index if not exists workflow_hooks_run_id_index ON workflow.workflow_hooks USING btree (run_id);
100
-
101
- create index if not exists workflow_hooks_token_index ON workflow.workflow_hooks USING btree (token);
102
-
103
- create table if not exists workflow.workflow_invocations (
104
- "sequence" bigserial,
105
- "run_id" character varying not null,
106
- "request_id" character varying not null,
107
- "payload" bytea,
108
- "fingerprint" character varying,
109
- "result" bytea,
110
- "created_at" timestamp without time zone not null default now(),
111
- "responded_at" timestamp without time zone,
112
- "expired_at" timestamp without time zone,
113
- "result_version" integer not null default 0,
114
- constraint "workflow_invocations_pkey" PRIMARY KEY (run_id, request_id)
115
- );
116
-
117
- alter table workflow.workflow_invocations
118
- add column if not exists "sequence" bigserial,
119
- add column if not exists "run_id" character varying not null,
120
- add column if not exists "request_id" character varying not null,
121
- add column if not exists "payload" bytea,
122
- add column if not exists "fingerprint" character varying,
123
- add column if not exists "result" bytea,
124
- add column if not exists "created_at" timestamp without time zone not null default now(),
125
- add column if not exists "responded_at" timestamp without time zone,
126
- add column if not exists "expired_at" timestamp without time zone,
127
- add column if not exists "result_version" integer not null default 0;
128
-
129
- create index if not exists workflow_invocations_pending ON workflow.workflow_invocations USING btree (run_id, sequence) WHERE (responded_at IS NULL);
130
-
131
- create table if not exists workflow.workflow_runs (
132
- "id" character varying not null,
133
- "output" jsonb,
134
- "deployment_id" character varying not null,
135
- "status" workflow.status not null,
136
- "name" character varying not null,
137
- "execution_context" jsonb,
138
- "input" jsonb,
139
- "error" text,
140
- "created_at" timestamp without time zone not null default now(),
141
- "updated_at" timestamp without time zone not null default now(),
142
- "completed_at" timestamp without time zone,
143
- "started_at" timestamp without time zone,
144
- "output_cbor" bytea,
145
- "execution_context_cbor" bytea,
146
- "input_cbor" bytea,
147
- "expired_at" timestamp without time zone,
148
- "spec_version" character varying,
149
- "error_cbor" bytea,
150
- "error_code" character varying,
151
- "attributes" jsonb not null default '{}'::jsonb,
152
- "encryption_public_key" character varying,
153
- "dynamic_workflow_code_cbor" bytea,
154
- constraint "workflow_runs_pkey" PRIMARY KEY (id)
155
- );
156
-
157
- alter table workflow.workflow_runs
158
- add column if not exists "id" character varying not null,
159
- add column if not exists "output" jsonb,
160
- add column if not exists "deployment_id" character varying not null,
161
- add column if not exists "status" workflow.status not null,
162
- add column if not exists "name" character varying not null,
163
- add column if not exists "execution_context" jsonb,
164
- add column if not exists "input" jsonb,
165
- add column if not exists "error" text,
166
- add column if not exists "created_at" timestamp without time zone not null default now(),
167
- add column if not exists "updated_at" timestamp without time zone not null default now(),
168
- add column if not exists "completed_at" timestamp without time zone,
169
- add column if not exists "started_at" timestamp without time zone,
170
- add column if not exists "output_cbor" bytea,
171
- add column if not exists "execution_context_cbor" bytea,
172
- add column if not exists "input_cbor" bytea,
173
- add column if not exists "expired_at" timestamp without time zone,
174
- add column if not exists "spec_version" character varying,
175
- add column if not exists "error_cbor" bytea,
176
- add column if not exists "error_code" character varying,
177
- add column if not exists "attributes" jsonb not null default '{}'::jsonb,
178
- add column if not exists "encryption_public_key" character varying,
179
- add column if not exists "dynamic_workflow_code_cbor" bytea;
180
-
181
- create index if not exists workflow_runs_name_index ON workflow.workflow_runs USING btree (name);
182
-
183
- create index if not exists workflow_runs_status_index ON workflow.workflow_runs USING btree (status);
184
-
185
- create table if not exists workflow.workflow_snapshots (
186
- "run_id" character varying not null,
187
- "data" bytea not null,
188
- "events_cursor" character varying,
189
- "created_at" timestamp without time zone not null default now(),
190
- constraint "workflow_snapshots_pkey" PRIMARY KEY (run_id)
191
- );
192
-
193
- alter table workflow.workflow_snapshots
194
- add column if not exists "run_id" character varying not null,
195
- add column if not exists "data" bytea not null,
196
- add column if not exists "events_cursor" character varying,
197
- add column if not exists "created_at" timestamp without time zone not null default now();
198
-
199
- create table if not exists workflow.workflow_steps (
200
- "run_id" character varying not null,
201
- "step_id" character varying not null,
202
- "step_name" character varying not null,
203
- "status" workflow.step_status not null,
204
- "input" jsonb,
205
- "output" jsonb,
206
- "error" text,
207
- "attempt" integer not null,
208
- "started_at" timestamp without time zone,
209
- "completed_at" timestamp without time zone,
210
- "created_at" timestamp without time zone not null default now(),
211
- "updated_at" timestamp without time zone not null default now(),
212
- "retry_after" timestamp without time zone,
213
- "input_cbor" bytea,
214
- "output_cbor" bytea,
215
- "error_cbor" bytea,
216
- "spec_version" integer,
217
- constraint "workflow_steps_pkey" PRIMARY KEY (step_id)
218
- );
219
-
220
- alter table workflow.workflow_steps
221
- add column if not exists "run_id" character varying not null,
222
- add column if not exists "step_id" character varying not null,
223
- add column if not exists "step_name" character varying not null,
224
- add column if not exists "status" workflow.step_status not null,
225
- add column if not exists "input" jsonb,
226
- add column if not exists "output" jsonb,
227
- add column if not exists "error" text,
228
- add column if not exists "attempt" integer not null,
229
- add column if not exists "started_at" timestamp without time zone,
230
- add column if not exists "completed_at" timestamp without time zone,
231
- add column if not exists "created_at" timestamp without time zone not null default now(),
232
- add column if not exists "updated_at" timestamp without time zone not null default now(),
233
- add column if not exists "retry_after" timestamp without time zone,
234
- add column if not exists "input_cbor" bytea,
235
- add column if not exists "output_cbor" bytea,
236
- add column if not exists "error_cbor" bytea,
237
- add column if not exists "spec_version" integer;
238
-
239
- create index if not exists workflow_steps_run_id_index ON workflow.workflow_steps USING btree (run_id);
240
-
241
- create index if not exists workflow_steps_status_index ON workflow.workflow_steps USING btree (status);
242
-
243
- create table if not exists workflow.workflow_stream_chunks (
244
- "id" character varying not null,
245
- "stream_id" character varying not null,
246
- "data" bytea not null,
247
- "created_at" timestamp without time zone not null default now(),
248
- "eof" boolean not null,
249
- "run_id" character varying,
250
- constraint "workflow_stream_chunks_stream_id_id_pk" PRIMARY KEY (stream_id, id)
251
- );
252
-
253
- alter table workflow.workflow_stream_chunks
254
- add column if not exists "id" character varying not null,
255
- add column if not exists "stream_id" character varying not null,
256
- add column if not exists "data" bytea not null,
257
- add column if not exists "created_at" timestamp without time zone not null default now(),
258
- add column if not exists "eof" boolean not null,
259
- add column if not exists "run_id" character varying;
260
-
261
- create index if not exists workflow_stream_chunks_run_id_index ON workflow.workflow_stream_chunks USING btree (run_id);
262
-
263
- create table if not exists workflow.workflow_waits (
264
- "wait_id" character varying not null,
265
- "run_id" character varying not null,
266
- "status" workflow.wait_status not null,
267
- "resume_at" timestamp without time zone,
268
- "completed_at" timestamp without time zone,
269
- "created_at" timestamp without time zone not null default now(),
270
- "updated_at" timestamp without time zone not null default now(),
271
- "spec_version" integer,
272
- constraint "workflow_waits_pkey" PRIMARY KEY (wait_id)
273
- );
274
-
275
- alter table workflow.workflow_waits
276
- add column if not exists "wait_id" character varying not null,
277
- add column if not exists "run_id" character varying not null,
278
- add column if not exists "status" workflow.wait_status not null,
279
- add column if not exists "resume_at" timestamp without time zone,
280
- add column if not exists "completed_at" timestamp without time zone,
281
- add column if not exists "created_at" timestamp without time zone not null default now(),
282
- add column if not exists "updated_at" timestamp without time zone not null default now(),
283
- add column if not exists "spec_version" integer;
284
-
285
- create index if not exists workflow_waits_run_id_index ON workflow.workflow_waits USING btree (run_id);
286
- `;
287
- //#endregion
288
- //#region src/sql/shared.ts
289
- /** What `record` and the other statement helpers return when there is nothing to do. */
290
- const NOTHING = "null;";
291
- /** `alter table ... add column if not exists` for each extra column of a managed table. */
292
- const addExtraColumns = (table, columns) => columns.map((column) => `\nalter table ${table} add column if not exists ${column.ident} ${column.type};`).join("");
293
- /**
294
- * A `jsonb` object of `columns` of row `alias`, keyed by column name, so
295
- * reads return extra columns without exposing the rest of the row.
296
- */
297
- const columnsObject = (alias, columns) => `jsonb_build_object(${columns.map((name) => `${sqlString(name)}, ${alias}.${sqlIdent(name)}`).join(", ")})`;
298
- const SCHEMA = `create schema if not exists better_supabase;
299
- grant usage on schema better_supabase to anon, authenticated, service_role;`;
300
- /**
301
- * A SQL condition true for the service role and for a direct admin
302
- * connection (no JWT, a privileged session user), which may act for others.
303
- */
304
- const SERVICE_CALLER = "coalesce(nullif((select auth.jwt()) ->> 'role', ''), session_user::text) in ('service_role', 'postgres', 'supabase_admin')";
305
- /**
306
- * The `organization.member_added` record for a module that adds a member, so
307
- * every module writes the same payload. Each value is a SQL expression.
308
- */
309
- function memberAddedRecord(ctx, member) {
310
- return ctx.record({
311
- type: "organization.member_added",
312
- payload: `jsonb_build_object('organizationId', ${member.tenant}::text, 'userId', ${member.user}, 'role', ${member.role})`,
313
- subject: `'organizations/' || ${member.tenant}::text`,
314
- tenant: member.tenant,
315
- audit: {
316
- category: "membership",
317
- targetType: "user",
318
- recordId: `${member.user}::text`
319
- }
320
- });
321
- }
322
- /** Creates the module's schema when it isn't `better_supabase`, then the module schema. */
323
- function schemaPreamble(ctx) {
324
- if (ctx.schemaName === "better_supabase") return SCHEMA;
325
- return `${SCHEMA}
326
- create schema if not exists ${ctx.schema};
327
- grant usage on schema ${ctx.schema} to anon, authenticated, service_role;`;
328
- }
329
- /**
330
- * A policy condition for "the caller holds `permission` in this row's
331
- * tenant". Postgres never inlines `can()` (it is `security definer`), so a
332
- * `can('tenant', column, ...)` in `using` runs once per row and can't use the
333
- * tenant index; the `tenant_ids_with` set runs once per statement.
334
- */
335
- function tenantIn(tenant, permission) {
336
- return `${tenant} in (select better_supabase.tenant_ids_with(${permission}))`;
337
- }
338
- /** A claim from the top level of the token, then `app_metadata`. */
339
- function jwtClaim(name) {
340
- return `coalesce(auth.jwt() ->> ${sqlString(name)}, auth.jwt() -> 'app_metadata' ->> ${sqlString(name)})`;
341
- }
342
- /** `table` or `schema.table` as `[schema, table]`, in `public` without a schema. */
343
- function splitTable(name) {
344
- const parts = name.split(".");
345
- if (parts.length > 2 || parts.some((part) => part.length === 0)) throw new TypeError(`"${name}" must be "table" or "schema.table"`);
346
- return parts.length === 2 ? [parts[0], parts[1]] : ["public", parts[0]];
347
- }
348
- /** `table` or `schema.table`, quoted. */
349
- function quotedTable(name) {
350
- const [schema, table] = splitTable(name);
351
- return `${sqlIdent(schema)}.${sqlIdent(table)}`;
352
- }
353
- /** `schema.table.column` split into its quoted table and column. */
354
- function columnRef(where, value) {
355
- const parts = value.split(".");
356
- if (parts.length !== 3 || parts.some((part) => part.length === 0)) throw new TypeError(`${where} must be "schema.table.column", got "${value}"`);
357
- const [schema, table, column] = parts;
358
- return {
359
- table: `${sqlIdent(schema)}.${sqlIdent(table)}`,
360
- column: sqlIdent(column)
361
- };
362
- }
363
- const QUOTED_IDENT = /^"(.*)"$/s;
364
- /**
365
- * Replaces the check constraints on one column of a table a module created
366
- * earlier: `create table if not exists` never changes an inline check, and
367
- * its generated name follows the table's configured name. For upgrade steps.
368
- * `column` is a quoted identifier; the catalog stores the bare name.
369
- */
370
- function replaceColumnCheck(check) {
371
- const column = QUOTED_IDENT.exec(check.column)?.[1]?.replaceAll("\"\"", "\"") ?? check.column;
372
- return `do $$
373
- declare
374
- v_name name;
375
- begin
376
- for v_name in
377
- select c.conname from pg_catalog.pg_constraint c
378
- join pg_catalog.pg_attribute a on a.attrelid = c.conrelid and a.attnum = c.conkey[1]
379
- where c.conrelid = ${sqlString(check.table)}::regclass and c.contype = 'c'
380
- and cardinality(c.conkey) = 1 and a.attname = ${sqlString(column)}
381
- loop
382
- execute format('alter table %s drop constraint %I', ${sqlString(check.table)}, v_name);
383
- end loop;
384
- end;
385
- $$;
386
- alter table ${check.table} add constraint ${sqlIdent(check.name)} check (${check.expression});`;
387
- }
388
- /**
389
- * Adds a foreign key to a table a module created earlier, once: `create
390
- * table if not exists` can't add it to a table that already exists, and the
391
- * referenced table can come from a module that renders later. Existing rows
392
- * without a match leave the key unvalidated, with a warning.
393
- */
394
- function addForeignKey(fk) {
395
- return `do $$
396
- begin
397
- if not exists (
398
- select 1 from pg_constraint
399
- where conrelid = ${sqlString(fk.table)}::regclass and conname = ${sqlString(fk.name)}
400
- ) then
401
- alter table ${fk.table} add constraint ${sqlIdent(fk.name)}
402
- foreign key (${fk.column}) references ${fk.references} on delete ${fk.onDelete} not valid;
403
- begin
404
- alter table ${fk.table} validate constraint ${sqlIdent(fk.name)};
405
- exception when foreign_key_violation then
406
- raise warning '% has rows without a match, so only new rows are checked. Delete them, then run: alter table % validate constraint %',
407
- ${sqlString(fk.table)}, ${sqlString(fk.table)}, ${sqlString(fk.name)};
408
- end;
409
- end if;
410
- end;
411
- $$;`;
412
- }
413
- /**
414
- * An `updated_at` column on a managed table, kept current by the
415
- * `updated-at` module's `set_updated_at()` (the module must require it).
416
- */
417
- function updatedAt(table, column) {
418
- return `alter table ${table} add column if not exists ${column} timestamptz not null default now();
419
- drop trigger if exists bs_updated_at on ${table};
420
- create trigger bs_updated_at before update on ${table}
421
- for each row execute function better_supabase.set_updated_at(${sqlString(column.replaceAll("\"", ""))});`;
422
- }
423
- function renameSql(renames) {
424
- const schema = sqlString(renames.schema);
425
- const q = (name) => `${sqlIdent(renames.schema)}.${sqlIdent(name)}`;
426
- const lines = [];
427
- let table = renames.table;
428
- for (const [from, to] of renames.tables ?? []) {
429
- lines.push(` if to_regclass(${sqlString(`${renames.schema}.${from}`)}) is not null
430
- and (select c.relkind from pg_class c where c.oid = to_regclass(${sqlString(`${renames.schema}.${from}`)})) in ('r', 'p')
431
- and to_regclass(${sqlString(`${renames.schema}.${to}`)}) is null then
432
- alter table ${q(from)} rename to ${sqlIdent(to)};
433
- end if;`);
434
- if (from === table) table = to;
435
- }
436
- for (const [from, to] of renames.columns ?? []) lines.push(` if exists (select 1 from information_schema.columns c
437
- where c.table_schema = ${schema} and c.table_name = ${sqlString(table)} and c.column_name = ${sqlString(from)})
438
- and not exists (select 1 from information_schema.columns c
439
- where c.table_schema = ${schema} and c.table_name = ${sqlString(table)} and c.column_name = ${sqlString(to)}) then
440
- alter table ${q(table)} rename column ${sqlIdent(from)} to ${sqlIdent(to)};
441
- end if;`);
442
- for (const [from, to] of renames.indexes ?? []) lines.push(` if to_regclass(${sqlString(`${renames.schema}.${from}`)}) is not null
443
- and to_regclass(${sqlString(`${renames.schema}.${to}`)}) is null then
444
- alter index ${q(from)} rename to ${sqlIdent(to)};
445
- end if;`);
446
- for (const [from, to, args] of renames.functions ?? []) lines.push(` if to_regprocedure(${sqlString(`${renames.schema}.${from}(${args})`)}) is not null
447
- and to_regprocedure(${sqlString(`${renames.schema}.${to}(${args})`)}) is null then
448
- alter function ${q(from)}(${args}) rename to ${sqlIdent(to)};
449
- end if;`);
450
- if (lines.length === 0) return "";
451
- return `do $$
452
- begin
453
- ${lines.join("\n")}
454
- end;
455
- $$;`;
456
- }
457
- /**
458
- * A SQL condition true when `organization` names no row of the installed
459
- * organizations table. False without the organizations module.
460
- */
461
- function organizationMissing(ctx, organization) {
462
- if (!ctx.installed("organizations")) return "false";
463
- const organizations = ctx.of("organizations");
464
- return `not exists (select 1 from ${organizations.table("organizations")} o where o.${organizations.col("organizations", "id")} = ${organization})`;
465
- }
466
- function membershipDisabledAt(ctx) {
467
- if (ctx.module !== "tenant" && !ctx.installed("tenant")) return void 0;
468
- const tenant = ctx.module === "tenant" ? ctx : ctx.of("tenant");
469
- if (!tenant.has("memberships", "disabledAt")) return void 0;
470
- if (!tenant.manages && typeof tenant.config.columns["memberships"]?.["disabledAt"] !== "string") return void 0;
471
- return tenant.col("memberships", "disabledAt");
472
- }
473
- function activeMembership(ctx, alias) {
474
- const column = membershipDisabledAt(ctx);
475
- return column === void 0 ? "" : ` and ${alias}.${column} is null`;
476
- }
477
- function membershipSuspended(ctx, tenant, user) {
478
- const column = membershipDisabledAt(ctx);
479
- if (column === void 0) return void 0;
480
- const t = ctx.module === "tenant" ? ctx : ctx.of("tenant");
481
- return `exists (select 1 from ${t.table("memberships")} sm where sm.${t.col("memberships", "tenant")} = ${tenant} and sm.${t.col("memberships", "user")} = ${user} and sm.${column} is not null)`;
482
- }
483
- /**
484
- * `tenant_disabled(id)` and `user_disabled(uuid)` from
485
- * `sql.modules.access.disabled`. Without a column they return false, so callers
486
- * don't need to know whether it is configured.
487
- */
488
- function disabledHelpers(ctx) {
489
- const disabled = ctx.modules.access?.disabled ?? {};
490
- const id = ctx.idType;
491
- const organizations = managedOrganizations(ctx);
492
- let tenantCheck = "false";
493
- if (disabled.tenant !== void 0) tenantCheck = disabledCheck("sql.modules.access.disabled.tenant", disabled.tenant, {
494
- key: "\"id\"",
495
- alias: "t",
496
- value: "tenant_disabled.tenant"
497
- });
498
- else if (organizations) tenantCheck = `exists (select 1 from ${organizations.table} t where t.${organizations.id} = tenant_disabled.tenant and (${organizations.flags.map((column) => `t.${column} is not null`).join(" or ")}))`;
499
- const userCheck = disabled.user === void 0 ? "false" : disabledCheck("sql.modules.access.disabled.user", disabled.user, {
500
- key: sqlIdent(disabled.userKey ?? "id"),
501
- alias: "u",
502
- value: "user_disabled.user_id"
503
- });
504
- return `
505
- -- Disabled tenants and users get no permissions and no membership claims
506
- -- (modules.access.disabled; with the managed organizations module, its
507
- -- disabled_at and deleted_at columns).
508
- create or replace function better_supabase.tenant_disabled(tenant ${id})
509
- returns boolean
510
- language sql
511
- stable
512
- security definer
513
- set search_path = ''
514
- as $$
515
- select ${tenantCheck}
516
- $$;
517
-
518
- create or replace function better_supabase.user_disabled(user_id uuid)
519
- returns boolean
520
- language sql
521
- stable
522
- security definer
523
- set search_path = ''
524
- as $$
525
- select ${userCheck}
526
- $$;
232
+ create or replace function better_supabase.user_disabled(user_id uuid)
233
+ returns boolean
234
+ language sql
235
+ stable
236
+ security definer
237
+ set search_path = ''
238
+ as $$
239
+ select ${userCheck}
240
+ $$;
527
241
 
528
242
  revoke execute on function better_supabase.tenant_disabled(${id}) from public, anon, authenticated;
529
243
  revoke execute on function better_supabase.user_disabled(uuid) from public, anon, authenticated;
@@ -712,6 +426,8 @@ function serviceOnly(signatures, schema = "better_supabase") {
712
426
  }
713
427
  /** `raise exception` with an errcode and a hint the TypeScript side maps. */
714
428
  const raise = (message, errcode, hint, ...args) => `raise exception ${sqlString(message)}${args.map((arg) => `, ${arg}`).join("")} using errcode = '${errcode}', hint = '${hint}';`;
429
+ /** `raise` for a module function: the hint first, the errcode defaulting to insufficient privilege. */
430
+ const fail = (code, message, errcode = "42501") => raise(message, errcode, code);
715
431
  /** `coalesce(can('tenant', tenant, permission), false)`. */
716
432
  const canIn = (tenant, permission) => `coalesce(better_supabase.can('tenant', ${tenant}, ${permission}), false)`;
717
433
  /** The hex SHA-256 of a `text` expression, as tokens and codes are stored. */
@@ -1192,6 +908,292 @@ function modulePermissionKey(ctx, action, fallback) {
1192
908
  }
1193
909
  const modulePermission = (ctx, action, fallback) => sqlString(modulePermissionKey(ctx, action, fallback));
1194
910
  //#endregion
911
+ //#region src/sql/modules/workflow-sdk-world-ddl.generated.ts
912
+ /** The `@workflow/world-postgres` version the DDL below was generated from. */
913
+ const WORLD_POSTGRES_VERSION = "5.0.2";
914
+ /** The `workflow` schema after every migration above, as idempotent DDL. */
915
+ const WORLD_POSTGRES_DDL = `create schema if not exists workflow;
916
+
917
+ do $$ begin
918
+ create type workflow.status as enum ('pending', 'running', 'completed', 'failed', 'cancelled');
919
+ exception when duplicate_object then null;
920
+ end $$;
921
+
922
+ do $$ begin
923
+ create type workflow.step_status as enum ('pending', 'running', 'completed', 'failed', 'cancelled');
924
+ exception when duplicate_object then null;
925
+ end $$;
926
+
927
+ do $$ begin
928
+ create type workflow.wait_status as enum ('waiting', 'completed');
929
+ exception when duplicate_object then null;
930
+ end $$;
931
+
932
+ create table if not exists workflow.workflow_event_slots (
933
+ "run_id" character varying not null,
934
+ constraint "workflow_event_slots_pkey" PRIMARY KEY (run_id)
935
+ );
936
+
937
+ alter table workflow.workflow_event_slots
938
+ add column if not exists "run_id" character varying not null;
939
+
940
+ create table if not exists workflow.workflow_events (
941
+ "id" character varying not null,
942
+ "type" character varying not null,
943
+ "correlation_id" character varying,
944
+ "created_at" timestamp without time zone not null default now(),
945
+ "run_id" character varying not null,
946
+ "payload" jsonb,
947
+ "payload_cbor" bytea,
948
+ "spec_version" integer,
949
+ "resume_id" character varying,
950
+ "resume_payload_digest" character varying,
951
+ constraint "workflow_events_run_id_id_pk" PRIMARY KEY (run_id, id)
952
+ );
953
+
954
+ alter table workflow.workflow_events
955
+ add column if not exists "id" character varying not null,
956
+ add column if not exists "type" character varying not null,
957
+ add column if not exists "correlation_id" character varying,
958
+ add column if not exists "created_at" timestamp without time zone not null default now(),
959
+ add column if not exists "run_id" character varying not null,
960
+ add column if not exists "payload" jsonb,
961
+ add column if not exists "payload_cbor" bytea,
962
+ add column if not exists "spec_version" integer,
963
+ add column if not exists "resume_id" character varying,
964
+ add column if not exists "resume_payload_digest" character varying;
965
+
966
+ create index if not exists workflow_events_correlation_id_index ON workflow.workflow_events USING btree (correlation_id);
967
+
968
+ create unique index if not exists workflow_events_entity_creation_unique ON workflow.workflow_events USING btree (run_id, correlation_id, type) WHERE ((type)::text = ANY ((ARRAY['step_created'::character varying, 'hook_created'::character varying, 'wait_created'::character varying, 'attr_set'::character varying])::text[]));
969
+
970
+ create unique index if not exists workflow_events_hook_resume_unique ON workflow.workflow_events USING btree (run_id, resume_id) WHERE (((type)::text = 'hook_received'::text) AND (resume_id IS NOT NULL));
971
+
972
+ create table if not exists workflow.workflow_hooks (
973
+ "run_id" character varying not null,
974
+ "hook_id" character varying not null,
975
+ "token" character varying not null,
976
+ "owner_id" character varying not null,
977
+ "project_id" character varying not null,
978
+ "environment" character varying not null,
979
+ "created_at" timestamp without time zone not null default now(),
980
+ "metadata" jsonb,
981
+ "metadata_cbor" bytea,
982
+ "spec_version" integer,
983
+ "is_webhook" boolean default true,
984
+ "is_system" boolean default false,
985
+ "resume_context" bytea,
986
+ "token_retention_until" timestamp with time zone,
987
+ "claimed_from" bytea,
988
+ constraint "workflow_hooks_pkey" PRIMARY KEY (hook_id)
989
+ );
990
+
991
+ alter table workflow.workflow_hooks
992
+ add column if not exists "run_id" character varying not null,
993
+ add column if not exists "hook_id" character varying not null,
994
+ add column if not exists "token" character varying not null,
995
+ add column if not exists "owner_id" character varying not null,
996
+ add column if not exists "project_id" character varying not null,
997
+ add column if not exists "environment" character varying not null,
998
+ add column if not exists "created_at" timestamp without time zone not null default now(),
999
+ add column if not exists "metadata" jsonb,
1000
+ add column if not exists "metadata_cbor" bytea,
1001
+ add column if not exists "spec_version" integer,
1002
+ add column if not exists "is_webhook" boolean default true,
1003
+ add column if not exists "is_system" boolean default false,
1004
+ add column if not exists "resume_context" bytea,
1005
+ add column if not exists "token_retention_until" timestamp with time zone,
1006
+ add column if not exists "claimed_from" bytea;
1007
+
1008
+ create index if not exists workflow_hooks_run_id_index ON workflow.workflow_hooks USING btree (run_id);
1009
+
1010
+ create index if not exists workflow_hooks_token_index ON workflow.workflow_hooks USING btree (token);
1011
+
1012
+ create table if not exists workflow.workflow_invocations (
1013
+ "sequence" bigserial,
1014
+ "run_id" character varying not null,
1015
+ "request_id" character varying not null,
1016
+ "payload" bytea,
1017
+ "fingerprint" character varying,
1018
+ "result" bytea,
1019
+ "created_at" timestamp without time zone not null default now(),
1020
+ "responded_at" timestamp without time zone,
1021
+ "expired_at" timestamp without time zone,
1022
+ "result_version" integer not null default 0,
1023
+ constraint "workflow_invocations_pkey" PRIMARY KEY (run_id, request_id)
1024
+ );
1025
+
1026
+ alter table workflow.workflow_invocations
1027
+ add column if not exists "sequence" bigserial,
1028
+ add column if not exists "run_id" character varying not null,
1029
+ add column if not exists "request_id" character varying not null,
1030
+ add column if not exists "payload" bytea,
1031
+ add column if not exists "fingerprint" character varying,
1032
+ add column if not exists "result" bytea,
1033
+ add column if not exists "created_at" timestamp without time zone not null default now(),
1034
+ add column if not exists "responded_at" timestamp without time zone,
1035
+ add column if not exists "expired_at" timestamp without time zone,
1036
+ add column if not exists "result_version" integer not null default 0;
1037
+
1038
+ create index if not exists workflow_invocations_pending ON workflow.workflow_invocations USING btree (run_id, sequence) WHERE (responded_at IS NULL);
1039
+
1040
+ create table if not exists workflow.workflow_runs (
1041
+ "id" character varying not null,
1042
+ "output" jsonb,
1043
+ "deployment_id" character varying not null,
1044
+ "status" workflow.status not null,
1045
+ "name" character varying not null,
1046
+ "execution_context" jsonb,
1047
+ "input" jsonb,
1048
+ "error" text,
1049
+ "created_at" timestamp without time zone not null default now(),
1050
+ "updated_at" timestamp without time zone not null default now(),
1051
+ "completed_at" timestamp without time zone,
1052
+ "started_at" timestamp without time zone,
1053
+ "output_cbor" bytea,
1054
+ "execution_context_cbor" bytea,
1055
+ "input_cbor" bytea,
1056
+ "expired_at" timestamp without time zone,
1057
+ "spec_version" character varying,
1058
+ "error_cbor" bytea,
1059
+ "error_code" character varying,
1060
+ "attributes" jsonb not null default '{}'::jsonb,
1061
+ "encryption_public_key" character varying,
1062
+ "dynamic_workflow_code_cbor" bytea,
1063
+ constraint "workflow_runs_pkey" PRIMARY KEY (id)
1064
+ );
1065
+
1066
+ alter table workflow.workflow_runs
1067
+ add column if not exists "id" character varying not null,
1068
+ add column if not exists "output" jsonb,
1069
+ add column if not exists "deployment_id" character varying not null,
1070
+ add column if not exists "status" workflow.status not null,
1071
+ add column if not exists "name" character varying not null,
1072
+ add column if not exists "execution_context" jsonb,
1073
+ add column if not exists "input" jsonb,
1074
+ add column if not exists "error" text,
1075
+ add column if not exists "created_at" timestamp without time zone not null default now(),
1076
+ add column if not exists "updated_at" timestamp without time zone not null default now(),
1077
+ add column if not exists "completed_at" timestamp without time zone,
1078
+ add column if not exists "started_at" timestamp without time zone,
1079
+ add column if not exists "output_cbor" bytea,
1080
+ add column if not exists "execution_context_cbor" bytea,
1081
+ add column if not exists "input_cbor" bytea,
1082
+ add column if not exists "expired_at" timestamp without time zone,
1083
+ add column if not exists "spec_version" character varying,
1084
+ add column if not exists "error_cbor" bytea,
1085
+ add column if not exists "error_code" character varying,
1086
+ add column if not exists "attributes" jsonb not null default '{}'::jsonb,
1087
+ add column if not exists "encryption_public_key" character varying,
1088
+ add column if not exists "dynamic_workflow_code_cbor" bytea;
1089
+
1090
+ create index if not exists workflow_runs_name_index ON workflow.workflow_runs USING btree (name);
1091
+
1092
+ create index if not exists workflow_runs_status_index ON workflow.workflow_runs USING btree (status);
1093
+
1094
+ create table if not exists workflow.workflow_snapshots (
1095
+ "run_id" character varying not null,
1096
+ "data" bytea not null,
1097
+ "events_cursor" character varying,
1098
+ "created_at" timestamp without time zone not null default now(),
1099
+ constraint "workflow_snapshots_pkey" PRIMARY KEY (run_id)
1100
+ );
1101
+
1102
+ alter table workflow.workflow_snapshots
1103
+ add column if not exists "run_id" character varying not null,
1104
+ add column if not exists "data" bytea not null,
1105
+ add column if not exists "events_cursor" character varying,
1106
+ add column if not exists "created_at" timestamp without time zone not null default now();
1107
+
1108
+ create table if not exists workflow.workflow_steps (
1109
+ "run_id" character varying not null,
1110
+ "step_id" character varying not null,
1111
+ "step_name" character varying not null,
1112
+ "status" workflow.step_status not null,
1113
+ "input" jsonb,
1114
+ "output" jsonb,
1115
+ "error" text,
1116
+ "attempt" integer not null,
1117
+ "started_at" timestamp without time zone,
1118
+ "completed_at" timestamp without time zone,
1119
+ "created_at" timestamp without time zone not null default now(),
1120
+ "updated_at" timestamp without time zone not null default now(),
1121
+ "retry_after" timestamp without time zone,
1122
+ "input_cbor" bytea,
1123
+ "output_cbor" bytea,
1124
+ "error_cbor" bytea,
1125
+ "spec_version" integer,
1126
+ constraint "workflow_steps_pkey" PRIMARY KEY (step_id)
1127
+ );
1128
+
1129
+ alter table workflow.workflow_steps
1130
+ add column if not exists "run_id" character varying not null,
1131
+ add column if not exists "step_id" character varying not null,
1132
+ add column if not exists "step_name" character varying not null,
1133
+ add column if not exists "status" workflow.step_status not null,
1134
+ add column if not exists "input" jsonb,
1135
+ add column if not exists "output" jsonb,
1136
+ add column if not exists "error" text,
1137
+ add column if not exists "attempt" integer not null,
1138
+ add column if not exists "started_at" timestamp without time zone,
1139
+ add column if not exists "completed_at" timestamp without time zone,
1140
+ add column if not exists "created_at" timestamp without time zone not null default now(),
1141
+ add column if not exists "updated_at" timestamp without time zone not null default now(),
1142
+ add column if not exists "retry_after" timestamp without time zone,
1143
+ add column if not exists "input_cbor" bytea,
1144
+ add column if not exists "output_cbor" bytea,
1145
+ add column if not exists "error_cbor" bytea,
1146
+ add column if not exists "spec_version" integer;
1147
+
1148
+ create index if not exists workflow_steps_run_id_index ON workflow.workflow_steps USING btree (run_id);
1149
+
1150
+ create index if not exists workflow_steps_status_index ON workflow.workflow_steps USING btree (status);
1151
+
1152
+ create table if not exists workflow.workflow_stream_chunks (
1153
+ "id" character varying not null,
1154
+ "stream_id" character varying not null,
1155
+ "data" bytea not null,
1156
+ "created_at" timestamp without time zone not null default now(),
1157
+ "eof" boolean not null,
1158
+ "run_id" character varying,
1159
+ constraint "workflow_stream_chunks_stream_id_id_pk" PRIMARY KEY (stream_id, id)
1160
+ );
1161
+
1162
+ alter table workflow.workflow_stream_chunks
1163
+ add column if not exists "id" character varying not null,
1164
+ add column if not exists "stream_id" character varying not null,
1165
+ add column if not exists "data" bytea not null,
1166
+ add column if not exists "created_at" timestamp without time zone not null default now(),
1167
+ add column if not exists "eof" boolean not null,
1168
+ add column if not exists "run_id" character varying;
1169
+
1170
+ create index if not exists workflow_stream_chunks_run_id_index ON workflow.workflow_stream_chunks USING btree (run_id);
1171
+
1172
+ create table if not exists workflow.workflow_waits (
1173
+ "wait_id" character varying not null,
1174
+ "run_id" character varying not null,
1175
+ "status" workflow.wait_status not null,
1176
+ "resume_at" timestamp without time zone,
1177
+ "completed_at" timestamp without time zone,
1178
+ "created_at" timestamp without time zone not null default now(),
1179
+ "updated_at" timestamp without time zone not null default now(),
1180
+ "spec_version" integer,
1181
+ constraint "workflow_waits_pkey" PRIMARY KEY (wait_id)
1182
+ );
1183
+
1184
+ alter table workflow.workflow_waits
1185
+ add column if not exists "wait_id" character varying not null,
1186
+ add column if not exists "run_id" character varying not null,
1187
+ add column if not exists "status" workflow.wait_status not null,
1188
+ add column if not exists "resume_at" timestamp without time zone,
1189
+ add column if not exists "completed_at" timestamp without time zone,
1190
+ add column if not exists "created_at" timestamp without time zone not null default now(),
1191
+ add column if not exists "updated_at" timestamp without time zone not null default now(),
1192
+ add column if not exists "spec_version" integer;
1193
+
1194
+ create index if not exists workflow_waits_run_id_index ON workflow.workflow_waits USING btree (run_id);
1195
+ `;
1196
+ //#endregion
1195
1197
  //#region src/sql/modules/workflow-sdk-world.ts
1196
1198
  /** The Vault secret names the pg_net dispatcher reads. */
1197
1199
  const WORKFLOW_VAULT_SECRETS = {
@@ -1394,4 +1396,4 @@ const WORKFLOW_SDK_WORLD = {
1394
1396
  data
1395
1397
  };
1396
1398
  //#endregion
1397
- export { jwtClaim as A, replaceColumnCheck as B, canIn as C, disabledHelpersNeedLaterTables as D, disabledHelpers as E, pageSize as F, splitTable as G, serviceGrant as H, quotedTable as I, userGrant as J, tenantIn as K, raise as L, membershipDisabledAt as M, membershipSuspended as N, ensureCheck as O, organizationMissing as P, recordTrigger as R, addForeignKey as S, columnsObject as T, serviceOnly as U, schemaPreamble as V, sha256Hex as W, WORLD_POSTGRES_VERSION as Y, SCHEMA as _, MODULE_PERMISSION_SCOPES as a, activeMembership as b, modulePermission as c, roleNames as d, roleScopeIs as f, NOTHING as g, EQUIVALENT_TRIGGERS as h, MODULE_PERMISSIONS as i, memberAddedRecord as j, jsonSchemaChecks as k, modulePermissionKey as l, tenantScope as m, WORKFLOW_SDK_WORLD as n, accessModel as o, rolesOf as p, updatedAt as q, WORKFLOW_VAULT_SECRETS as r, hasPlatformRoles as s, WORKFLOW_DELIVERY_QUEUE as t, providerPlatformRoles as u, SERVICE_CALLER as v, columnRef as w, addExtraColumns as x, accessDefinesDisabledHelpers as y, renameSql as z };
1399
+ export { fail as A, recordTrigger as B, addForeignKey as C, disabledHelpers as D, columnsObject as E, membershipSuspended as F, serviceOnly as G, replaceColumnCheck as H, organizationMissing as I, tenantIn as J, sha256Hex as K, pageSize as L, jwtClaim as M, memberAddedRecord as N, disabledHelpersNeedLaterTables as O, membershipDisabledAt as P, quotedTable as R, addExtraColumns as S, columnRef as T, schemaPreamble as U, renameSql as V, serviceGrant as W, userGrant as X, updatedAt as Y, NOTHING as _, MODULE_PERMISSIONS as a, accessDefinesDisabledHelpers as b, hasPlatformRoles as c, providerPlatformRoles as d, roleNames as f, EQUIVALENT_TRIGGERS as g, tenantScope as h, WORLD_POSTGRES_VERSION as i, jsonSchemaChecks as j, ensureCheck as k, modulePermission as l, rolesOf as m, WORKFLOW_SDK_WORLD as n, MODULE_PERMISSION_SCOPES as o, roleScopeIs as p, splitTable as q, WORKFLOW_VAULT_SECRETS as r, accessModel as s, WORKFLOW_DELIVERY_QUEUE as t, modulePermissionKey as u, SCHEMA as v, canIn as w, activeMembership as x, SERVICE_CALLER as y, raise as z };