better-supabase 0.15.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) hide show
  1. package/dist/{adapter-B0b6MXYS.js → adapter-Dyks1lX1.js} +1 -1
  2. package/dist/{agents-5n8DWRfP.d.ts → agents-CMIB3802.d.ts} +1 -1
  3. package/dist/{ai-cache-DyHohbFP.d.ts → ai-cache-2LGgaT7F.d.ts} +1 -1
  4. package/dist/{ai-chat-D1GuRnke.d.ts → ai-chat-BCaKsvLW.d.ts} +1 -1
  5. package/dist/{ai-schedules-CAquecT_.d.ts → ai-schedules-D_Hz-ik5.d.ts} +2 -2
  6. package/dist/ai-sdk/agents/index.d.ts +4 -4
  7. package/dist/ai-sdk/batches/index.d.ts +1 -1
  8. package/dist/ai-sdk/cache/index.d.ts +1 -1
  9. package/dist/ai-sdk/chat/index.d.ts +1 -1
  10. package/dist/ai-sdk/embeddings/index.d.ts +2 -2
  11. package/dist/ai-sdk/index.d.ts +4 -4
  12. package/dist/ai-sdk/memory/index.d.ts +3 -3
  13. package/dist/ai-sdk/workflow/index.d.ts +3 -3
  14. package/dist/{app-tables-CF2DD-Mu.d.ts → app-tables-CbCFSXLG.d.ts} +1 -1
  15. package/dist/{approvals-Crutd4-o.d.ts → approvals-Dh9dUXrN.d.ts} +1 -1
  16. package/dist/{assistant-CD_h8Vxx.d.ts → assistant-ndGdOBax.d.ts} +2 -2
  17. package/dist/astro/index.d.ts +2 -2
  18. package/dist/astro/index.js +2 -2
  19. package/dist/{authorization-hooks-Cs1vP_ej.d.ts → authorization-hooks-D_pwXlBs.d.ts} +4 -0
  20. package/dist/{bind-CrMBwrPN.d.ts → bind-h5jre2K0.d.ts} +3 -3
  21. package/dist/{block-env-B_uEM2xz.d.ts → block-env-BrfRvPrj.d.ts} +4 -4
  22. package/dist/blocks/access-requests/index.d.ts +1 -1
  23. package/dist/blocks/activities/index.d.ts +2 -2
  24. package/dist/blocks/agents/index.d.ts +2 -2
  25. package/dist/blocks/ai-cache/index.d.ts +2 -2
  26. package/dist/blocks/ai-chat/index.d.ts +5 -5
  27. package/dist/blocks/ai-files/index.d.ts +1 -1
  28. package/dist/blocks/ai-keys/index.d.ts +1 -1
  29. package/dist/blocks/ai-schedules/index.d.ts +2 -2
  30. package/dist/blocks/announcements/index.d.ts +4 -4
  31. package/dist/blocks/api-keys/index.d.ts +2 -2
  32. package/dist/blocks/approvals/index.d.ts +2 -2
  33. package/dist/blocks/assets/index.d.ts +1 -1
  34. package/dist/blocks/assignment/index.d.ts +1 -1
  35. package/dist/blocks/attachments/index.d.ts +2 -2
  36. package/dist/blocks/audit/index.d.ts +3 -3
  37. package/dist/blocks/automations/index.d.ts +4 -4
  38. package/dist/blocks/billable-time/index.d.ts +1 -1
  39. package/dist/blocks/billing/index.d.ts +2 -2
  40. package/dist/blocks/bookings/index.d.ts +3 -3
  41. package/dist/blocks/bulk/index.d.ts +1 -1
  42. package/dist/blocks/calendar/index.d.ts +2 -2
  43. package/dist/blocks/catalog/index.d.ts +1 -1
  44. package/dist/blocks/channels/index.d.ts +1 -1
  45. package/dist/blocks/collections/index.d.ts +1 -1
  46. package/dist/blocks/comments/index.d.ts +4 -4
  47. package/dist/blocks/compliance/index.d.ts +1 -1
  48. package/dist/blocks/connectors/index.d.ts +1 -1
  49. package/dist/blocks/contacts/index.d.ts +1 -1
  50. package/dist/blocks/content/index.d.ts +1 -1
  51. package/dist/blocks/contracts/index.d.ts +1 -1
  52. package/dist/blocks/courses/index.d.ts +1 -1
  53. package/dist/blocks/created-by/index.d.ts +1 -1
  54. package/dist/blocks/custom-fields/index.d.ts +1 -1
  55. package/dist/blocks/data-lifecycle/index.d.ts +2 -2
  56. package/dist/blocks/deals/index.d.ts +1 -1
  57. package/dist/blocks/dispatch/index.d.ts +1 -1
  58. package/dist/blocks/documents/index.d.ts +1 -1
  59. package/dist/blocks/domains/index.d.ts +1 -1
  60. package/dist/blocks/donations/index.d.ts +1 -1
  61. package/dist/blocks/drive/index.d.ts +2 -2
  62. package/dist/blocks/employees/index.d.ts +2 -2
  63. package/dist/blocks/enrichment/index.d.ts +1 -1
  64. package/dist/blocks/enrollments/index.d.ts +1 -1
  65. package/dist/blocks/entitlements/index.d.ts +3 -3
  66. package/dist/blocks/expenses/index.d.ts +1 -1
  67. package/dist/blocks/field-history/index.d.ts +1 -1
  68. package/dist/blocks/flags/index.d.ts +1 -1
  69. package/dist/blocks/forecasts/index.d.ts +1 -1
  70. package/dist/blocks/forms/index.d.ts +2 -2
  71. package/dist/blocks/goals/index.d.ts +1 -1
  72. package/dist/blocks/guests/index.d.ts +1 -1
  73. package/dist/blocks/hiring/index.d.ts +1 -1
  74. package/dist/blocks/identities/index.d.ts +2 -2
  75. package/dist/blocks/imports/index.d.ts +1 -1
  76. package/dist/blocks/inbox/index.d.ts +5 -5
  77. package/dist/blocks/incidents/index.d.ts +1 -1
  78. package/dist/blocks/index.d.ts +2 -2
  79. package/dist/blocks/inventory/index.d.ts +2 -2
  80. package/dist/blocks/invoices/index.d.ts +1 -1
  81. package/dist/blocks/knowledge/index.d.ts +2 -2
  82. package/dist/blocks/lead-scoring/index.d.ts +1 -1
  83. package/dist/blocks/leases/index.d.ts +1 -1
  84. package/dist/blocks/leave/index.d.ts +1 -1
  85. package/dist/blocks/ledger/index.d.ts +1 -1
  86. package/dist/blocks/mail-sync/index.d.ts +1 -1
  87. package/dist/blocks/memberships/index.d.ts +1 -1
  88. package/dist/blocks/memory/index.d.ts +3 -3
  89. package/dist/blocks/messaging/index.d.ts +4 -4
  90. package/dist/blocks/metrics/index.d.ts +2 -2
  91. package/dist/blocks/mfa/index.d.ts +2 -2
  92. package/dist/blocks/moderation/index.d.ts +1 -1
  93. package/dist/blocks/notifications/index.d.ts +5 -5
  94. package/dist/blocks/numbering/index.d.ts +1 -1
  95. package/dist/blocks/oauth-server/index.d.ts +1 -1
  96. package/dist/blocks/onboarding/index.d.ts +2 -2
  97. package/dist/blocks/orders/index.d.ts +3 -3
  98. package/dist/blocks/organizations/index.d.ts +2 -2
  99. package/dist/blocks/outbox/index.d.ts +2 -2
  100. package/dist/blocks/passes/index.d.ts +2 -2
  101. package/dist/blocks/permissions/index.d.ts +3 -3
  102. package/dist/blocks/pipelines/index.d.ts +1 -1
  103. package/dist/blocks/posts/index.d.ts +1 -1
  104. package/dist/blocks/profiles/index.d.ts +1 -1
  105. package/dist/blocks/promotions/index.d.ts +1 -1
  106. package/dist/blocks/push/index.d.ts +2 -2
  107. package/dist/blocks/queue/index.d.ts +2 -2
  108. package/dist/blocks/queue/index.js +1 -1
  109. package/dist/blocks/quotes/index.d.ts +1 -1
  110. package/dist/blocks/rank/index.d.ts +2 -2
  111. package/dist/blocks/reactions/index.d.ts +4 -4
  112. package/dist/blocks/relations/index.d.ts +1 -1
  113. package/dist/blocks/reminders/index.d.ts +3 -3
  114. package/dist/blocks/reviews/index.d.ts +1 -1
  115. package/dist/blocks/saved-views/index.d.ts +2 -2
  116. package/dist/blocks/scores/index.d.ts +1 -1
  117. package/dist/blocks/search/index.d.ts +3 -3
  118. package/dist/blocks/security-events/index.d.ts +1 -1
  119. package/dist/blocks/segments/index.d.ts +1 -1
  120. package/dist/blocks/sequences/index.d.ts +1 -1
  121. package/dist/blocks/service-accounts/index.d.ts +1 -1
  122. package/dist/blocks/sessions/index.d.ts +2 -2
  123. package/dist/blocks/settings/index.d.ts +2 -2
  124. package/dist/blocks/share-links/index.d.ts +1 -1
  125. package/dist/blocks/shipments/index.d.ts +1 -1
  126. package/dist/blocks/signatures/index.d.ts +1 -1
  127. package/dist/blocks/signing-keys/index.d.ts +1 -1
  128. package/dist/blocks/sla/index.d.ts +1 -1
  129. package/dist/blocks/sso/index.d.ts +1 -1
  130. package/dist/blocks/state-machine/index.d.ts +1 -1
  131. package/dist/blocks/subjects/index.d.ts +2 -2
  132. package/dist/blocks/tags/index.d.ts +2 -2
  133. package/dist/blocks/tasks/index.d.ts +2 -2
  134. package/dist/blocks/teams/index.d.ts +1 -1
  135. package/dist/blocks/templates/index.d.ts +3 -3
  136. package/dist/blocks/time-tracking/index.d.ts +1 -1
  137. package/dist/blocks/timeline/index.d.ts +1 -1
  138. package/dist/blocks/trash/index.d.ts +1 -1
  139. package/dist/blocks/undo/index.d.ts +2 -2
  140. package/dist/blocks/updated-at/index.d.ts +1 -1
  141. package/dist/blocks/usage/index.d.ts +3 -3
  142. package/dist/blocks/vercel-marketplace/index.d.ts +1 -1
  143. package/dist/blocks/versions/index.d.ts +1 -1
  144. package/dist/blocks/waitlist/index.d.ts +1 -1
  145. package/dist/blocks/webhooks/index.d.ts +3 -3
  146. package/dist/blocks/workflow-editor/index.d.ts +6 -6
  147. package/dist/blocks/workflow-editor/index.js +12 -1
  148. package/dist/blocks/workflows/index.d.ts +4 -4
  149. package/dist/{bookings-D4dvGXiR.d.ts → bookings-Dox2rced.d.ts} +1 -1
  150. package/dist/chat-sdk/index.d.ts +1 -1
  151. package/dist/cli/{add-DCI5JKjA.js → add-C04vkBk9.js} +2 -2
  152. package/dist/cli/add-CUH0rORo.js +1 -0
  153. package/dist/cli/{add-BgsUjCan.js → add-DNOL9PDu.js} +17 -12
  154. package/dist/cli/{backfill-nxPbcsns.js → backfill-VFzf-TJP.js} +1 -1
  155. package/dist/cli/bin.js +1 -1
  156. package/dist/cli/{blocks-Cr4HGePW.js → blocks-Bn7WUca5.js} +1 -1
  157. package/dist/cli/{blocks-BZHI8mRC.js → blocks-Cb7mILFU.js} +1 -1
  158. package/dist/cli/{cache-CXgR_Ahi.js → cache-DkplpIGe.js} +1 -1
  159. package/dist/cli/{codemod-DSN7iAdg.js → codemod-BbaE5dL_.js} +95 -3
  160. package/dist/cli/{content-mapper-DNs7lTu7.js → content-mapper-Cdx6arxu.js} +2 -2
  161. package/dist/cli/{doctor-DDrEM6S1.js → doctor-C-VO-QQ2.js} +29 -14
  162. package/dist/cli/{gen-MtijJQ9r.js → gen-yRHOHW1b.js} +10 -10
  163. package/dist/cli/index.d.ts +1 -1
  164. package/dist/cli/index.js +6 -6
  165. package/dist/cli/{init-D-aDv9r5.js → init-BOw0SX65.js} +5 -5
  166. package/dist/cli/legacy-prefix-DkTA3Rhx.js +141 -0
  167. package/dist/cli/{live-iEeH15ck.js → live-Lmg-hYyO.js} +2 -2
  168. package/dist/cli/{mcp-BAPyaQ62.js → mcp-DQ1zR2eA.js} +2 -2
  169. package/dist/cli/{metadata-DVx9Zgbj.js → metadata-CZaxkv21.js} +3 -3
  170. package/dist/cli/{migration-safety-D7PhzFxm.js → migration-safety-BbhLu2fo.js} +1 -1
  171. package/dist/cli/{module-migration-aPCckev6.js → module-migration-DOn6EmNz.js} +5 -216
  172. package/dist/cli/{print-BeWO7OJY.js → print-D_xf8PPj.js} +1 -1
  173. package/dist/cli/{remove-B46Dmd2M.js → remove-BY_TOTRj.js} +5 -4
  174. package/dist/cli/{render-ucJmUyuM.js → render-lJmHr0y9.js} +3 -3
  175. package/dist/cli/{run-CvYVAztY.js → run-BJ6IMs_H.js} +20 -7
  176. package/dist/cli/{run-DYhLBcFW.js → run-DkB0fhc9.js} +20 -20
  177. package/dist/cli/{shared-LZroULBe.js → shared-Bh-6IqJS.js} +1 -1
  178. package/dist/cli/{snapshot-C8MVPyO8.js → snapshot-Bzcigm7T.js} +2 -2
  179. package/dist/cli/{source-DANaJJVc.js → source-WoLdcQzN.js} +1 -1
  180. package/dist/cli/{spec-g8_G5K7o.js → spec-BF_dpwzW.js} +1 -1
  181. package/dist/cli/{spec-DGVNMSSB.js → spec-CZMiLhv_.js} +2 -2
  182. package/dist/cli/sql-layout-rFP0oq1N.js +247 -0
  183. package/dist/cli/{sync-btj01bcM.js → sync-mANmYYoL.js} +2 -1
  184. package/dist/cli/{upgrade-B596d4t8.js → upgrade-B0Q9wMs-.js} +4 -137
  185. package/dist/cli/{upgrade-Dw3TMQzn.js → upgrade-BrNLt92u.js} +2 -2
  186. package/dist/cli/{version-Du4CgONY.js → version-CyavsyGA.js} +1 -1
  187. package/dist/client/index.d.ts +5 -5
  188. package/dist/client/native/index.d.ts +4 -4
  189. package/dist/{composite-BARuBEDE.js → composite-B3TIjId4.js} +1 -1
  190. package/dist/{composite-Dsxj7T5K.d.ts → composite-BZYXlVBN.d.ts} +2 -2
  191. package/dist/config/index.d.ts +1 -1
  192. package/dist/{context-CEuTKrkz.d.ts → context-TGX2eDS5.d.ts} +24 -2
  193. package/dist/{controller-BrP0gn47.d.ts → controller-DyPPMFSw.d.ts} +1 -1
  194. package/dist/{conversion-BAbucuXq.d.ts → conversion-O-kyhXcC.d.ts} +1 -1
  195. package/dist/create/index.d.ts +2 -2
  196. package/dist/create/index.js +1 -1
  197. package/dist/{define-block-BVcLQ3DF.d.ts → define-block-DvvcM54N.d.ts} +1 -1
  198. package/dist/delegation-C7eWP2r8.d.ts +14 -0
  199. package/dist/{delegation--93jRsVO.js → delegation-DGOIiT8k.js} +12 -5
  200. package/dist/edge/index.d.ts +1 -1
  201. package/dist/edge/index.js +3 -3
  202. package/dist/{embeddings-kFbRvuic.d.ts → embeddings-D_RsS6ow.d.ts} +1 -1
  203. package/dist/{entitlements-CJpYQXeE.d.ts → entitlements-BnhDBxLW.d.ts} +1 -1
  204. package/dist/{envelope-Bzu0JnY2.js → envelope-DEI2iX-d.js} +1 -1
  205. package/dist/eve/index.d.ts +2 -2
  206. package/dist/{eve-BFSwTu1z.d.ts → eve-B7jxYPCw.d.ts} +2 -2
  207. package/dist/{executor-_2ekNofh.d.ts → executor-Bi056Cnj.d.ts} +1 -1
  208. package/dist/expo/index.d.ts +1 -1
  209. package/dist/expo/index.js +2 -2
  210. package/dist/{field-errors-fsbFktYF.d.ts → field-errors-DYtg1mwv.d.ts} +5 -5
  211. package/dist/{framework-DDdkR7FX.js → framework-BozTXRzt.js} +1 -1
  212. package/dist/{framework-BKyTeS-j.d.ts → framework-h5lP_5yj.d.ts} +3 -3
  213. package/dist/{gateway-TD1pRfTP.d.ts → gateway-DzI687yd.d.ts} +3 -3
  214. package/dist/hono/index.d.ts +1 -1
  215. package/dist/hono/index.js +2 -2
  216. package/dist/{index-BnH4Gomw.d.ts → index-Ab4UeEn_.d.ts} +8 -8
  217. package/dist/{index-BUuVq1co.d.ts → index-B4gcStOz.d.ts} +2 -2
  218. package/dist/{index-C-qpk8EQ.d.ts → index-BAHGLvGD.d.ts} +1 -1
  219. package/dist/{index-CguFm716.d.ts → index-BfK6olKm.d.ts} +31 -3
  220. package/dist/{index-DLq69k3F.d.ts → index-BfkltrGJ.d.ts} +1 -1
  221. package/dist/{index-B938YqY-.d.ts → index-DN9mfmhA.d.ts} +1 -1
  222. package/dist/{knowledge-CtL-Vfgy.d.ts → knowledge-F1IhRI4Q.d.ts} +1 -1
  223. package/dist/mapper/bin.js +5 -5
  224. package/dist/mcp/index.d.ts +1 -1
  225. package/dist/mcp/index.js +1 -1
  226. package/dist/mcp/sdk/index.d.ts +1 -1
  227. package/dist/mcp/sdk/index.js +1 -1
  228. package/dist/next/index.d.ts +8 -8
  229. package/dist/next/index.js +2 -2
  230. package/dist/orpc/index.d.ts +1 -1
  231. package/dist/orpc/index.js +1 -1
  232. package/dist/otel/index.js +4 -4
  233. package/dist/{outbox-HvGAJuBe.d.ts → outbox-HxjZTfF6.d.ts} +1 -1
  234. package/dist/{ports-sx226JUL.d.ts → ports-CpdiQv1D.d.ts} +1 -1
  235. package/dist/powersync/index.d.ts +1 -1
  236. package/dist/preset/index.d.ts +3 -3
  237. package/dist/{push-token-D3Vcf0Pf.d.ts → push-token-B3m3pWAv.d.ts} +1 -1
  238. package/dist/query/index.d.ts +1 -1
  239. package/dist/react/index.d.ts +5 -5
  240. package/dist/react/native/index.d.ts +1 -1
  241. package/dist/react/server.d.ts +5 -5
  242. package/dist/react-router/index.d.ts +2 -2
  243. package/dist/react-router/index.js +2 -2
  244. package/dist/realtime/index.d.ts +4 -4
  245. package/dist/{record-form-BYs9xv_N.d.ts → record-form-DB_5Ue_B.d.ts} +1 -1
  246. package/dist/records/index.d.ts +7 -7
  247. package/dist/server/index.d.ts +7 -6
  248. package/dist/server/index.js +5 -4
  249. package/dist/{server-types-CFtehAsr.d.ts → server-types-7QPzW2bF.d.ts} +1 -1
  250. package/dist/{session-CH0SKgIz.d.ts → session-CfBCJGgc.d.ts} +1 -1
  251. package/dist/{sign-in-DNCdrk05.js → sign-in-B64114O4.js} +1 -1
  252. package/dist/solid/index.d.ts +5 -5
  253. package/dist/solid-start/index.d.ts +2 -2
  254. package/dist/solid-start/index.js +2 -2
  255. package/dist/sql/index.d.ts +4 -4
  256. package/dist/sql/index.js +2 -2
  257. package/dist/{sql-ClHIdgKS.js → sql-OLVW4t08.js} +275 -13
  258. package/dist/ssr/index.d.ts +1 -1
  259. package/dist/{subject-readers-BNSzkqw_.d.ts → subject-readers-8GySC9Z8.d.ts} +1 -1
  260. package/dist/svelte/index.d.ts +5 -5
  261. package/dist/sveltekit/index.d.ts +2 -2
  262. package/dist/sveltekit/index.js +2 -2
  263. package/dist/tanstack-start/index.d.ts +2 -2
  264. package/dist/tanstack-start/index.js +2 -2
  265. package/dist/{tenant-yYg0E2-n.d.ts → tenant-DzFsg0Pc.d.ts} +1 -1
  266. package/dist/testing/index.d.ts +10 -10
  267. package/dist/{timeline-CtG0sehj.d.ts → timeline-WrFMgd3U.d.ts} +2 -2
  268. package/dist/{topic-CJrQZQaa.d.ts → topic-DNFEFGKI.d.ts} +1 -1
  269. package/dist/{types-CAQBmpDx.d.ts → types-A4yyKEsg.d.ts} +1 -1
  270. package/dist/{types-SFRomQF7.d.ts → types-Czq9Xtpa.d.ts} +1 -7
  271. package/dist/{types-BBQLbui9.d.ts → types-DsRfiQ0v.d.ts} +1 -1
  272. package/dist/{usage-D7QkrwzV.d.ts → usage-Dp45V42p.d.ts} +1 -1
  273. package/dist/vue/index.d.ts +5 -5
  274. package/dist/{watch-topic-BcGfvZOE.d.ts → watch-topic-Bo9S2R4P.d.ts} +1 -1
  275. package/dist/workflow-sdk/builder/index.d.ts +3 -3
  276. package/dist/workflow-sdk/builder/index.js +1 -1
  277. package/dist/workflow-sdk/index.d.ts +1 -1
  278. package/dist/workflow-sdk/index.js +1 -1
  279. package/dist/{workflow-sdk-BFHu4sci.d.ts → workflow-sdk-B3Ss55Fy.d.ts} +1 -1
  280. package/dist/{workflow-sdk-BVlFEB5Q.js → workflow-sdk-Cf0LAOFF.js} +2 -2
  281. package/dist/yjs/index.d.ts +1 -1
  282. package/package.json +1 -1
  283. package/schemas/doctor-report-v1.json +1 -0
  284. package/dist/cli/add-DWjlVwvP.js +0 -1
@@ -774,6 +774,108 @@ function declaredTables(files, schemas) {
774
774
  }
775
775
  return [...found];
776
776
  }
777
+ const VIEW = /* @__PURE__ */ new RegExp(String.raw`\bcreate\s+(?:or\s+replace\s+)?(?:(?:temp|temporary|recursive)\s+)?(materialized\s+)?view\s+(?:if\s+not\s+exists\s+)?(${TABLE_NAME$4})\s*(\()?`, "gi");
778
+ const DROP_VIEW = /* @__PURE__ */ new RegExp(String.raw`\bdrop\s+(?:materialized\s+)?view\s+(?:if\s+exists\s+)?(${TABLE_NAME$4}(?:\s*,\s*${TABLE_NAME$4})*)`, "gi");
779
+ const INSTEAD_OF_TRIGGER = /* @__PURE__ */ new RegExp(String.raw`\bcreate\s+(?:or\s+replace\s+)?trigger\s+${NAME$9}\s+instead\s+of\b[^;]*?\bon\s+(${TABLE_NAME$4})`, "gi");
780
+ /**
781
+ * What keeps Postgres from writing through a view to its table: a view that has
782
+ * one of these is not auto-updatable.
783
+ */
784
+ const NOT_UPDATABLE = /\b(?:(?:distinct|group\s+by|having|limit|offset|fetch\s+first|union|intersect|except|join|window)\b|over\s*\(|(?:count|sum|avg|min|max|array_agg|string_agg|jsonb_agg|json_agg|bool_and|bool_or)\s*\()/i;
785
+ /** The word that ends a view's select list, at the top level. */
786
+ const SELECT_END$1 = /\bfrom\b/i;
787
+ const ALIAS = /* @__PURE__ */ new RegExp(String.raw`\bas\s+(${NAME$9})\s*$`, "i");
788
+ const BARE_COLUMN = /* @__PURE__ */ new RegExp(String.raw`^(?:${NAME$9}\s*\.\s*)*(${NAME$9})$`);
789
+ /**
790
+ * The view's columns from its select list: each item's alias, or the column it
791
+ * names. `undefined` when an item is `*` or has no name to read.
792
+ */
793
+ function selectColumns(body) {
794
+ const select = /^\s*(?:\(\s*)?select\s+/i.exec(body);
795
+ if (select === null) return;
796
+ let rest = body.slice(select[0].length);
797
+ const distinct = /^distinct\s+on\s*\(/i.exec(rest);
798
+ if (distinct === null) rest = rest.replace(/^(?:distinct|all)\b/i, "");
799
+ else {
800
+ const close = closingParen(rest, distinct[0].length - 1);
801
+ if (close === -1) return;
802
+ rest = rest.slice(close + 1);
803
+ }
804
+ const end = topLevelIndex(rest, SELECT_END$1);
805
+ const items = splitTopLevel(end === -1 ? rest : rest.slice(0, end));
806
+ const columns = [];
807
+ for (const item of items) {
808
+ const alias = ALIAS.exec(item)?.[1] ?? BARE_COLUMN.exec(item.trim())?.[1];
809
+ if (alias === void 0 || item.trim().endsWith("*")) return;
810
+ columns.push(unquote$4(alias));
811
+ }
812
+ return columns;
813
+ }
814
+ /** The first match of `pattern` outside parentheses and quotes, or -1. */
815
+ function topLevelIndex(text, pattern) {
816
+ let depth = 0;
817
+ let quote;
818
+ for (let i = 0; i < text.length; i += 1) {
819
+ const char = text[i];
820
+ if (quote) {
821
+ if (char === quote) quote = void 0;
822
+ } else if (char === "'" || char === "\"") quote = char;
823
+ else if (char === "(") depth += 1;
824
+ else if (char === ")") depth -= 1;
825
+ else if (depth === 0 && /\w/.test(char) && !/\w/.test(text[i - 1] ?? "") && pattern.exec(text.slice(i))?.index === 0) return i;
826
+ }
827
+ return -1;
828
+ }
829
+ /**
830
+ * The views and materialized views `files` create, as `schema.view`, with their
831
+ * columns and whether they are auto-updatable. A later `drop view` removes one.
832
+ * Only views in `schemas` are kept.
833
+ */
834
+ function declaredViews(files, schemas) {
835
+ const found = /* @__PURE__ */ new Map();
836
+ const insteadOf = /* @__PURE__ */ new Set();
837
+ for (const file of files) {
838
+ const text = withoutComments$1(file.text);
839
+ for (const match of text.matchAll(INSTEAD_OF_TRIGGER)) insteadOf.add(qualified$8(match[1]));
840
+ inOrder([[...text.matchAll(VIEW)].map((match) => ({
841
+ index: match.index,
842
+ apply: () => {
843
+ const view = qualified$8(match[2]);
844
+ if (!schemas.includes(view.slice(0, view.indexOf(".")))) return;
845
+ let at = match.index + match[0].length;
846
+ let listed;
847
+ if (match[3] !== void 0) {
848
+ const close = closingParen(text, at - 1);
849
+ if (close === -1) return;
850
+ listed = splitTopLevel(text.slice(at, close)).map((column) => unquote$4(column.trim()));
851
+ at = close + 1;
852
+ }
853
+ const as = /\bas\b/i.exec(text.slice(at));
854
+ if (as === null) return;
855
+ const start = at + as.index + as[0].length;
856
+ const end = text.indexOf(";", start);
857
+ const body = text.slice(start, end === -1 ? text.length : end);
858
+ found.set(view, {
859
+ columns: listed ?? selectColumns(body),
860
+ updatable: match[1] === void 0 && !NOT_UPDATABLE.test(body)
861
+ });
862
+ }
863
+ })), [...text.matchAll(DROP_VIEW)].map((match) => ({
864
+ index: match.index,
865
+ apply: () => {
866
+ for (const view of droppedTables(match[1])) found.delete(view);
867
+ }
868
+ }))]);
869
+ }
870
+ for (const view of insteadOf) {
871
+ const entry = found.get(view);
872
+ if (entry !== void 0) found.set(view, {
873
+ ...entry,
874
+ updatable: true
875
+ });
876
+ }
877
+ return found;
878
+ }
777
879
  const RLS_TOGGLE = /* @__PURE__ */ new RegExp(String.raw`\balter\s+table\s+(?:if\s+exists\s+)?(?:only\s+)?(${NAME$9}(?:\s*\.\s*${NAME$9})?)\s+(enable|disable)\s+row\s+level\s+security\b`, "gi");
778
880
  /**
779
881
  * The tables in `schemas` that `files` leave with row level security on: `alter
@@ -983,6 +1085,7 @@ function declaredUpdatedAtTriggers(files, schemas) {
983
1085
  }
984
1086
  //#endregion
985
1087
  //#region src/sql/over-app-tables.ts
1088
+ const TABLE_NAME$3 = String.raw`${NAME$9}(?:\s*\.\s*${NAME$9})?`;
986
1089
  /** Comments replaced by spaces, so offsets into `text` stay the same. */
987
1090
  function maskComments(text) {
988
1091
  return text.replaceAll(/--[^\n]*/g, (comment) => " ".repeat(comment.length)).replaceAll(/\/\*[\s\S]*?\*\//g, (comment) => comment.replaceAll(/[^\n]/g, " "));
@@ -1068,7 +1171,6 @@ function withoutUnmappedTables(sql, instance) {
1068
1171
  if (use !== null) throw new TypeError(`Module "${instance}" needs table "${use[1]}", which blocks.${instance}.tables maps to null`);
1069
1172
  return out;
1070
1173
  }
1071
- const TABLE_NAME$3 = String.raw`${NAME$9}(?:\s*\.\s*${NAME$9})?`;
1072
1174
  const ALTER_CONSTRAINT = /* @__PURE__ */ new RegExp(String.raw`^[ \t]*alter\s+table\s+(?:only\s+)?(${TABLE_NAME$3})\s+(?:add\s+constraint|drop\s+constraint|validate\s+constraint|alter\s+column)\b[^;]*;[ \t]*\n?`, "gim");
1073
1175
  const REVOKE = /* @__PURE__ */ new RegExp(String.raw`^[ \t]*revoke\s[^;]*?\son\s+(?:table\s+)?(${TABLE_NAME$3})\s+from\b[^;]*;[ \t]*\n?`, "gim");
1074
1176
  const ENSURE_CHECK = /^do \$\$\nbegin\n {2}if coalesce\(obj_description\(\(\n\s+select c\.oid from pg_catalog\.pg_constraint c\n\s+where c\.conrelid = '([^']+)'::regclass[\s\S]*?\n\$\$;\n?/gm;
@@ -1082,6 +1184,42 @@ function withoutAppTableEdits(sql, appTables) {
1082
1184
  const drop = (statement, table) => appTables.has(qualified$8(table)) ? "" : statement;
1083
1185
  return sql.replaceAll(ALTER_CONSTRAINT, drop).replaceAll(REVOKE, drop).replaceAll(ENSURE_CHECK, drop);
1084
1186
  }
1187
+ /**
1188
+ * The relation a DDL statement builds or changes: its table, index, grant,
1189
+ * policy, trigger or comment target.
1190
+ */
1191
+ const DDL_TARGETS = [
1192
+ new RegExp(String.raw`^\s*create\s+(?:unlogged\s+)?table\s+(?:if\s+not\s+exists\s+)?(${TABLE_NAME$3})`, "i"),
1193
+ new RegExp(String.raw`^\s*alter\s+table\s+(?:if\s+exists\s+)?(?:only\s+)?(${TABLE_NAME$3})`, "i"),
1194
+ new RegExp(String.raw`^\s*create\s+(?:unique\s+)?index\s+(?:concurrently\s+)?(?:if\s+not\s+exists\s+)?(?:${NAME$9}\s+)?on\s+(?:only\s+)?(${TABLE_NAME$3})`, "i"),
1195
+ new RegExp(String.raw`^\s*(?:grant|revoke)\s[^;]*?\bon\s+(?:table\s+)?(${TABLE_NAME$3})\s+(?:to|from)\b`, "i"),
1196
+ new RegExp(String.raw`^\s*(?:create|alter|drop)\s+policy\s+(?:if\s+exists\s+)?${NAME$9}\s+on\s+(${TABLE_NAME$3})`, "i"),
1197
+ new RegExp(String.raw`^\s*create\s+(?:or\s+replace\s+)?(?:constraint\s+)?trigger\s+${NAME$9}\s[^;]*?\bon\s+(${TABLE_NAME$3})`, "i"),
1198
+ new RegExp(String.raw`^\s*drop\s+trigger\s+(?:if\s+exists\s+)?${NAME$9}\s+on\s+(${TABLE_NAME$3})`, "i"),
1199
+ new RegExp(String.raw`^\s*comment\s+on\s+table\s+(${TABLE_NAME$3})`, "i"),
1200
+ new RegExp(String.raw`^\s*comment\s+on\s+column\s+(${TABLE_NAME$3})\s*\.\s*${NAME$9}`, "i")
1201
+ ];
1202
+ /**
1203
+ * `sql` without the statements that build or change the app's views in `views`
1204
+ * (as `schema.view`): their `create table`, columns, constraints, indexes, row
1205
+ * level security, grants, revokes, policies, triggers and comments. The
1206
+ * functions that read the views stay.
1207
+ */
1208
+ function overAppViews(sql, views) {
1209
+ if (views.size === 0) return sql;
1210
+ const said = /* @__PURE__ */ new Set();
1211
+ return statementSpans(sql).map(([from, to]) => {
1212
+ const statement = sql.slice(from, to);
1213
+ const masked = maskComments(statement);
1214
+ const target = DDL_TARGETS.map((pattern) => pattern.exec(masked)?.[1]).find((match) => match !== void 0);
1215
+ const view = target === void 0 ? void 0 : qualified$8(target);
1216
+ if (view === void 0 || !views.has(view)) return statement;
1217
+ const lead = /^\s*/.exec(statement)[0];
1218
+ if (said.has(view)) return "";
1219
+ said.add(view);
1220
+ return `${lead}-- ${view} is the app's view: this block writes only the functions that read it.`;
1221
+ }).join("");
1222
+ }
1085
1223
  const COLUMN_NAME$1 = /^("(?:[^"]|"")+"|[a-z_][\w$]*)/i;
1086
1224
  const TABLE_CONSTRAINT$1 = /^(constraint|check|unique|primary|foreign|exclude|like)\b/i;
1087
1225
  function unquote$3(name) {
@@ -1157,8 +1295,13 @@ function appOwnedTables(input) {
1157
1295
  function tableOwnership(input, column, requiredColumn) {
1158
1296
  const appOwned = appOwnedTables(input);
1159
1297
  const overApp = appOwned.length > 0;
1298
+ const views = input.source.ownViews ?? {};
1160
1299
  return {
1161
1300
  appOwned,
1301
+ appViews: appOwned.filter((logical) => {
1302
+ const parts = input.tableName(logical);
1303
+ return Object.hasOwn(views, `${parts.schema}.${parts.name}`);
1304
+ }),
1162
1305
  owns: (logical) => {
1163
1306
  input.tableName(logical);
1164
1307
  return input.config.mode !== "custom" && !appOwned.includes(logical);
@@ -2255,6 +2398,83 @@ function guestOr(sql, checks) {
2255
2398
  return live.length === 0 ? sql : `(${sql}) or ${live.join(" or ")}`;
2256
2399
  }
2257
2400
  //#endregion
2401
+ //#region src/sql/view-columns.ts
2402
+ const cache = /* @__PURE__ */ new WeakMap();
2403
+ /**
2404
+ * The columns of the app's views that a block reads. A view can't take the
2405
+ * columns a block would add to a table, so each optional column (`optional` in
2406
+ * the table's spec) a view lacks counts as mapped to `null`, unless the config
2407
+ * maps it; any other column a view lacks is in `missing`. Views whose columns
2408
+ * aren't known are left alone.
2409
+ */
2410
+ function viewColumns(layout, modules, namesOf) {
2411
+ const views = layout.ownViews;
2412
+ if (modules === void 0 || views === void 0 || Object.keys(views).length === 0) return {
2413
+ modules,
2414
+ missing: []
2415
+ };
2416
+ const known = cache.get(layout)?.get(modules);
2417
+ if (known !== void 0) return known;
2418
+ const out = { ...modules };
2419
+ const missing = [];
2420
+ for (const [block, config] of Object.entries(modules)) {
2421
+ const names = namesOf(block);
2422
+ if (config === void 0 || names === void 0 || !Object.values(names.tables).some((spec) => spec.app !== void 0)) continue;
2423
+ const ctx = createModuleContext(block, namesOf, {
2424
+ modules,
2425
+ ...layout.ownTables ? { ownTables: layout.ownTables } : {},
2426
+ ownViews: views
2427
+ });
2428
+ const configured = config.columns ?? {};
2429
+ const columns = {};
2430
+ for (const logical of ctx.appViews) {
2431
+ const parts = ctx.tableName(logical);
2432
+ const view = `${parts.schema}.${parts.name}`;
2433
+ const has = layout.ownColumns?.[view];
2434
+ const spec = names.tables[logical];
2435
+ if (has === void 0 || spec.app === void 0) continue;
2436
+ const unused = new Set(spec.app.unused?.(ctx));
2437
+ for (const column of Object.keys(spec.columns)) {
2438
+ if (unused.has(column) || !ctx.has(logical, column)) continue;
2439
+ const physical = ctx.colName(logical, column);
2440
+ if (has.includes(physical)) continue;
2441
+ if (spec.optional?.includes(column) === true && configured[logical]?.[column] === void 0) columns[logical] = {
2442
+ ...columns[logical],
2443
+ [column]: null
2444
+ };
2445
+ else missing.push({
2446
+ block,
2447
+ view,
2448
+ column: physical
2449
+ });
2450
+ }
2451
+ }
2452
+ if (Object.keys(columns).length > 0) out[block] = {
2453
+ ...config,
2454
+ columns: Object.fromEntries([.../* @__PURE__ */ new Set([...Object.keys(configured), ...Object.keys(columns)])].map((logical) => [logical, {
2455
+ ...configured[logical],
2456
+ ...columns[logical]
2457
+ }]))
2458
+ };
2459
+ }
2460
+ const result = {
2461
+ modules: Object.keys(out).some((block) => out[block] !== modules[block]) ? out : modules,
2462
+ missing
2463
+ };
2464
+ const byModules = cache.get(layout) ?? /* @__PURE__ */ new WeakMap();
2465
+ byModules.set(modules, result);
2466
+ cache.set(layout, byModules);
2467
+ return result;
2468
+ }
2469
+ /**
2470
+ * Throws when a view of the app's at a block table's name lacks a column the
2471
+ * block needs, naming the view and the column.
2472
+ */
2473
+ function assertViewColumns(missing) {
2474
+ if (missing[0] === void 0) return;
2475
+ throw new TypeError([...missing.map((each) => `blocks.${each.block} reads ${each.view}.${each.column}, which the view doesn't have.`), "Add the column to the view, or map it in blocks.<name>.columns to one the view has."].join("\n"));
2476
+ }
2477
+ //#endregion
2258
2478
  //#region src/sql/module-context.ts
2259
2479
  let bound;
2260
2480
  /**
@@ -2282,6 +2502,7 @@ function moduleContext(name, layout = {}, installed, instance) {
2282
2502
  ...layout.subjects ? { subjects: layout.subjects } : {},
2283
2503
  ...layout.appTables ? { appTables: Object.keys(layout.appTables) } : {},
2284
2504
  ...layout.ownTables ? { ownTables: layout.ownTables } : {},
2505
+ ...layout.ownViews ? { ownViews: layout.ownViews } : {},
2285
2506
  ...installed ? { installed } : {},
2286
2507
  ...layout.instances ? { instances: layout.instances } : {},
2287
2508
  ...instance === void 0 || instance === name ? {} : { instance },
@@ -2311,7 +2532,14 @@ function moduleContext(name, layout = {}, installed, instance) {
2311
2532
  * a roles table, gets the same `roleThrough`, unless the config sets one.
2312
2533
  */
2313
2534
  function withProviderDefaults(layout) {
2314
- return withProviderRoles(layout, withProviderSuspension(layout));
2535
+ return viewColumnsOf(layout).modules;
2536
+ }
2537
+ /**
2538
+ * The provider defaults, then the optional columns the app's views lack mapped
2539
+ * to `null`, with the required columns they lack.
2540
+ */
2541
+ function viewColumnsOf(layout) {
2542
+ return viewColumns(layout, withProviderRoles(layout, withProviderSuspension(layout)), (module) => registry().modules[module]?.names);
2315
2543
  }
2316
2544
  /**
2317
2545
  * `blocks.permissions.disabled` from the provider's `suspension` under the
@@ -3057,7 +3285,7 @@ function tenantSql(ctx, layout) {
3057
3285
  )` : ` select has_organization_role.organization in (
3058
3286
  select ${ctx.fn("member_organization_ids")}(has_organization_role.roles)
3059
3287
  )`;
3060
- const memberRoleFilter = members.idsFor === void 0 ? "" : ` and m.${tenant} in (select p.id from ${members.idsFor("organization_member_role.member")} as p(id))`;
3288
+ const memberRoleFilter = `${active}${members.idsFor === void 0 ? "" : ` and m.${tenant} in (select p.id from ${members.idsFor("organization_member_role.member")} as p(id))`}`;
3061
3289
  const claimJson = ctx.text("claimFormat", "array") === "map" ? `coalesce(jsonb_object_agg(m.${tenant}::text, ${role}), '{}'::jsonb)` : `coalesce(jsonb_agg(jsonb_build_object(
3062
3290
  'scope', ${sqlString(ctx.claims.scope)},
3063
3291
  'id', m.${tenant},
@@ -7359,6 +7587,7 @@ const MAX_IDENTIFIER = 63;
7359
7587
  function lockModuleTable(ctx, logical, options = {}) {
7360
7588
  const table = ctx.table(logical);
7361
7589
  if (!ctx.appOwned.includes(logical)) return lockTable(table, options);
7590
+ if (ctx.appViews.includes(logical)) return "";
7362
7591
  return `alter table ${table} enable row level security;
7363
7592
  ${options.read ? `grant select on ${table} to authenticated;\n` : ""}grant all on ${table} to service_role;`;
7364
7593
  }
@@ -7377,7 +7606,7 @@ function asText(ctx, logical, expr) {
7377
7606
  * `where` clause.
7378
7607
  */
7379
7608
  function appUniqueIndex(ctx, logical, columns, where) {
7380
- if (!ctx.appOwned.includes(logical)) return "";
7609
+ if (!ctx.appOwned.includes(logical) || ctx.appViews.includes(logical)) return "";
7381
7610
  const physical = columns.map((column) => ctx.colName(logical, column));
7382
7611
  const name = `${ctx.tableName(logical).name}_${physical.join("_")}_key`;
7383
7612
  return `\ncreate unique index if not exists ${sqlIdent(name.slice(0, MAX_IDENTIFIER))} on ${ctx.table(logical)} (${physical.map((column) => sqlIdent(column)).join(", ")})${where === void 0 ? "" : ` where ${where}`};`;
@@ -68034,6 +68263,8 @@ $$;
68034
68263
  -- False when the token is narrower than the permission: a permission cap
68035
68264
  -- (bsb_permission_cap) without the key, or a delegated token whose scopes
68036
68265
  -- don't map to it. True for every other token, the service role included.
68266
+ -- 0.14 named the cap bs_permission_cap; 0.15 still reads it when the new
68267
+ -- claim is missing, so a cap from an older runAs keeps narrowing.
68037
68268
  create or replace function better_supabase.cap_allows(permission text)
68038
68269
  returns boolean
68039
68270
  language sql
@@ -68043,9 +68274,9 @@ set search_path = ''
68043
68274
  as $$
68044
68275
  select case
68045
68276
  when jwt is null then true
68046
- when jsonb_typeof(jwt -> 'bsb_permission_cap') = 'array'
68277
+ when jsonb_typeof(cap) = 'array'
68047
68278
  and not exists (
68048
- select 1 from jsonb_array_elements_text(jwt -> 'bsb_permission_cap') c(key)
68279
+ select 1 from jsonb_array_elements_text(cap) c(key)
68049
68280
  where better_supabase.permission_matches(c.key, cap_allows.permission)
68050
68281
  ) then false
68051
68282
  when coalesce(jwt ->> 'client_id', '') = ''
@@ -68065,6 +68296,9 @@ as $$
68065
68296
  )
68066
68297
  end
68067
68298
  from (select auth.jwt() as jwt) as token
68299
+ cross join lateral (
68300
+ select coalesce(jwt -> 'bsb_permission_cap', jwt -> 'bs_permission_cap') as cap
68301
+ ) as capped
68068
68302
  $$;`;
68069
68303
  }
68070
68304
  //#endregion
@@ -123684,7 +123918,7 @@ function applyTenantScope(sql, ctx) {
123684
123918
  const targets = [];
123685
123919
  for (const [logical, spec] of Object.entries(ctx.names.tables)) {
123686
123920
  const tenant = spec.lifecycle?.tenant;
123687
- if (tenant === void 0 || !ctx.hasTable(logical) || !ctx.has(logical, tenant)) continue;
123921
+ if (tenant === void 0 || ctx.appViews.includes(logical) || !ctx.hasTable(logical) || !ctx.has(logical, tenant)) continue;
123688
123922
  const name = ctx.tableName(logical);
123689
123923
  const key = tableKey(`${name.schema}.${name.name}`);
123690
123924
  const own = policies.filter((policy) => policy.target === key && !policy.restrictive && policy.authenticated);
@@ -125880,6 +126114,7 @@ function upgradePlan(installed, layout = {}, modules = SQL_MODULES) {
125880
126114
  ...entry.module === block ? {} : { instance: entry.module },
125881
126115
  installed: names,
125882
126116
  ...layout.ownTables ? { ownTables: layout.ownTables } : {},
126117
+ ...layout.ownViews ? { ownViews: layout.ownViews } : {},
125883
126118
  ...providerIdType(layout),
125884
126119
  ...providerGuests(layout)
125885
126120
  });
@@ -125928,6 +126163,7 @@ function moduleSql(module, ctx, layout) {
125928
126163
  function moduleBody(name, layout = {}) {
125929
126164
  checkModules(layout.modules);
125930
126165
  checkMigrationOptions(layout.modules, layout.ownTables);
126166
+ assertViewColumns(viewColumnsOf(layout).missing);
125931
126167
  const modules = resolveBlocks([name], layout);
125932
126168
  const module = modules.find((entry) => entry.name === name);
125933
126169
  const ctx = moduleContext(name, layout, modules.map((entry) => entry.name));
@@ -125939,11 +126175,11 @@ function moduleBody(name, layout = {}) {
125939
126175
  */
125940
126176
  function overApp(sql, ctx, layout) {
125941
126177
  const appTables = appTableSet(ctx);
125942
- return withoutUnmappedColumns(withoutUnmappedTables(blockNamesOnAppTables(withoutAppTableEdits(overAppTables(sql, appTables, layout.ownColumns), appTables), appTables, layout.ownUpdatedAtTriggers), ctx.instance), ctx.instance);
126178
+ return withoutUnmappedColumns(withoutUnmappedTables(blockNamesOnAppTables(withoutAppTableEdits(overAppTables(overAppViews(sql, appTableSet(ctx, ctx.appViews)), appTables, layout.ownColumns), appTables), appTables, layout.ownUpdatedAtTriggers), ctx.instance), ctx.instance);
125943
126179
  }
125944
126180
  /** The app's tables a module runs over, as `schema.table`. */
125945
- function appTableSet(ctx) {
125946
- return new Set(ctx.manages ? ctx.appOwned.map((table) => {
126181
+ function appTableSet(ctx, tables = ctx.appOwned) {
126182
+ return new Set(ctx.manages ? tables.map((table) => {
125947
126183
  const parts = ctx.tableName(table);
125948
126184
  return `${parts.schema}.${parts.name}`;
125949
126185
  }) : []);
@@ -125989,6 +126225,7 @@ on conflict (name) do update
125989
126225
  function renderBlocks(names, layout = {}) {
125990
126226
  checkModules(layout.modules);
125991
126227
  checkMigrationOptions(layout.modules, layout.ownTables);
126228
+ assertViewColumns(viewColumnsOf(layout).missing);
125992
126229
  const modules = resolveBlocks(names, layout);
125993
126230
  checkTenantName(modules, layout);
125994
126231
  const installed = modules.map((module) => module.name);
@@ -126553,11 +126790,12 @@ function contextOf(name, layout) {
126553
126790
  * `ownTables` lists it or `blocks.<name>.on` names it, with the columns their
126554
126791
  * SQL names: mapped to `null` and unused optional columns are left out.
126555
126792
  */
126556
- function adoptedTables(modules, ownTables) {
126793
+ function adoptedTables(modules, ownTables, views = {}) {
126557
126794
  const tables = [];
126558
126795
  const layout = {
126559
126796
  modules,
126560
- ...ownTables === void 0 ? {} : { ownTables }
126797
+ ...ownTables === void 0 ? {} : { ownTables },
126798
+ ...views
126561
126799
  };
126562
126800
  const contexts = Object.keys(modules).flatMap((name) => {
126563
126801
  const mode = modules[name]?.mode ?? "managed";
@@ -126635,6 +126873,30 @@ function enumColumnProblems(modules, files, schemas, ownTables) {
126635
126873
  function enumColumnProblem(table, logical, column, type) {
126636
126874
  return `blocks.${table.module} writes text into ${table.schema}.${table.table}.${column} (${table.logical}.${logical}), which is the enum ${type}. Postgres does not cast text to an enum, so the module's functions fail. Change the column to text with a check constraint on its values.`;
126637
126875
  }
126876
+ /** The block tables in `modules` that run over the app's views. */
126877
+ function adoptedViews(modules, ownTables, views) {
126878
+ const layout = {
126879
+ modules,
126880
+ ownTables,
126881
+ ...views
126882
+ };
126883
+ return Object.keys(modules).flatMap((name) => {
126884
+ const spec = SQL_MODULES[name]?.names?.tables;
126885
+ const ctx = spec === void 0 ? void 0 : contextOf(name, layout);
126886
+ if (spec === void 0 || ctx === void 0) return [];
126887
+ return ctx.appViews.map((logical) => {
126888
+ const { schema, name: table } = ctx.tableName(logical);
126889
+ const view = `${schema}.${table}`;
126890
+ return {
126891
+ module: name,
126892
+ logical,
126893
+ view,
126894
+ updatable: views.ownViews[view]?.updatable === true,
126895
+ writes: spec[logical]?.app?.writes !== false
126896
+ };
126897
+ });
126898
+ });
126899
+ }
126638
126900
  //#endregion
126639
126901
  //#region src/sql/foreign-keys.ts
126640
126902
  const TABLE_NAME = String.raw`${NAME$9}(?:\s*\.\s*${NAME$9})?`;
@@ -126993,4 +127255,4 @@ async function compileReadSets(sets) {
126993
127255
  return Promise.all(names.map((name) => compileReadSet(byName.get(name))));
126994
127256
  }
126995
127257
  //#endregion
126996
- export { isBlockSqlIdType as $, sameBlockFile as A, SECRET_COLUMNS as B, APP_TABLES_MODULE as C, blockFileState as D, blockSqlVersion as E, SQL_MODULES as F, migrationOptionUses as G, subjectColumns$1 as H, resolveBlocks as I, formerBlockName as J, BLOCK_RENAMES as K, TENANT_SCOPE_POLICY as L, moduleHidingColumns as M, modulePermissionKeys as N, isModuleDataFile as O, moduleSchemaExtensions as P, contractSignature as Q, excludedColumns as R, APP_TABLES_MARKER as S, scopePolicyName as T, sameTenantColumn as U, dataExportPlan as V, sameTenantTrigger as W, AUDIT_CATEGORIES as X, renamedBlock as Y, MODULE_ID_TYPES as Z, upgradePlan as _, tenantsQuery as a, extensionSchema as at, moduleDataDir as b, adoptedColumnProblems as c, auditRegistrations as ct, entityRenamePlan as d, moduleIdType as et, customContracts as f, moduleDeprecations as g, renderBlocks as h, moduleLayout as i, declaredUpdatedAtTriggers as it, moduleEventTriggers as j, moduleFileVersion as k, adoptedTables as l, moduleTopics as m, compileReadSets as n, declaredTableColumns as nt, expiredFlagsQuery as o, policyGrants as ot, moduleBody as p, currentBlockName as q, sharedRolesProblems as r, declaredTables as rt, sameTenantLayout as s, rlsTables as st, compileReadSet as t, BLOCK_OPTION_SCHEMAS as tt, instanceFunctions as u, declaredPolicies as v, appTablesFiles as w, moduleFilePaths as x, widenedCommands as y, resolveExposeColumns as z };
127258
+ export { contractSignature as $, moduleFileVersion as A, resolveExposeColumns as B, APP_TABLES_MARKER as C, blockSqlVersion as D, scopePolicyName as E, moduleSchemaExtensions as F, sameTenantTrigger as G, dataExportPlan as H, SQL_MODULES as I, currentBlockName as J, migrationOptionUses as K, resolveBlocks as L, moduleEventTriggers as M, moduleHidingColumns as N, blockFileState as O, modulePermissionKeys as P, MODULE_ID_TYPES as Q, TENANT_SCOPE_POLICY as R, moduleFilePaths as S, appTablesFiles as T, subjectColumns$1 as U, SECRET_COLUMNS as V, sameTenantColumn as W, renamedBlock as X, formerBlockName as Y, AUDIT_CATEGORIES as Z, moduleDeprecations as _, tenantsQuery as a, declaredUpdatedAtTriggers as at, widenedCommands as b, adoptedColumnProblems as c, policyGrants as ct, instanceFunctions as d, isBlockSqlIdType as et, entityRenamePlan as f, renderBlocks as g, moduleTopics as h, moduleLayout as i, declaredTables as it, sameBlockFile as j, isModuleDataFile as k, adoptedTables as l, rlsTables as lt, moduleBody as m, compileReadSets as n, BLOCK_OPTION_SCHEMAS as nt, expiredFlagsQuery as o, declaredViews as ot, customContracts as p, BLOCK_RENAMES as q, sharedRolesProblems as r, declaredTableColumns as rt, sameTenantLayout as s, extensionSchema as st, compileReadSet as t, moduleIdType as tt, adoptedViews as u, auditRegistrations as ut, upgradePlan as v, APP_TABLES_MODULE as w, moduleDataDir as x, declaredPolicies as y, excludedColumns as z };
@@ -1,6 +1,6 @@
1
1
  import { C as readSession, D as writeSession, E as sessionEncoding, S as pruneSessionChunks, T as sessionCookieName, _ as StoredSession, a as ResolveAuthOptions, b as clearSessionAtScopes, d as CookieOptions, f as CookieRecord, g as SessionEncoding, h as DEFAULT_SESSION_ENCODING, l as resolveAuth, m as CookieWrite, n as AuthResolver, p as CookieScope, r as AuthState, t as AuthResolution, u as AUTH_CACHE_HEADERS, v as WriteSessionOptions, w as serializeCookie, x as parseCookies, y as applyCookieWrites } from "../resolve-CXX6DHv3.js";
2
2
  import { n as toSession, t as AuthSession } from "../view-DyFdMCqg.js";
3
- import { r as MembershipClaim } from "../entitlements-CJpYQXeE.js";
3
+ import { r as MembershipClaim } from "../entitlements-BnhDBxLW.js";
4
4
  import { n as RefreshOutcome, r as refreshSession, t as RefreshOptions } from "../refresh-DT_ICaK-.js";
5
5
  import { a as sessionStatus, i as clearSessionCookies, n as SessionStatus, o as authContext, r as SessionStatusOptions, t as ClearSessionCookiesOptions } from "../ended-gUsMZVNg.js";
6
6
  export { AUTH_CACHE_HEADERS, type AuthResolution, type AuthResolver, type AuthSession, type AuthState, type ClearSessionCookiesOptions, type CookieOptions, type CookieRecord, type CookieScope, type CookieWrite, DEFAULT_SESSION_ENCODING, type MembershipClaim, type RefreshOptions, type RefreshOutcome, type ResolveAuthOptions, type SessionEncoding, type SessionStatus, type SessionStatusOptions, type StoredSession, type WriteSessionOptions, applyCookieWrites, authContext, clearSessionAtScopes, clearSessionCookies, parseCookies, pruneSessionChunks, readSession, refreshSession, resolveAuth, serializeCookie, sessionCookieName, sessionEncoding, sessionStatus, toSession, writeSession };
@@ -1,5 +1,5 @@
1
1
  import { t as BlockTransport } from "./block-transport-DWZSJrwN.js";
2
- import { g as SubscriberPolicy } from "./authorization-hooks-Cs1vP_ej.js";
2
+ import { g as SubscriberPolicy } from "./authorization-hooks-D_pwXlBs.js";
3
3
  //#region src/core/subject-readers.d.ts
4
4
  interface SubjectReadersOptions {
5
5
  /** The schema of the `subjects` module. Default `better_supabase`. */
@@ -2,12 +2,12 @@ import { b as DbError } from "../result-DZeA5KS6.js";
2
2
  import { Ct as Events, D as BlockEventPattern, T as BlockEvent, bt as EventMap, k as BlockEventsMatching } from "../events-vcqenSYU.js";
3
3
  import { pt as QuerySpec } from "../define-DFBnQyYg.js";
4
4
  import { $ as TemplateValues } from "../bucket-CiNi8sIw.js";
5
- import { g as TopicHandlers, m as Topic, p as SubscriptionStatus, r as PresenceMember, t as EventSchemas } from "../topic-CJrQZQaa.js";
6
- import { t as AuthSnapshot } from "../bind-CrMBwrPN.js";
5
+ import { g as TopicHandlers, m as Topic, p as SubscriptionStatus, r as PresenceMember, t as EventSchemas } from "../topic-DNFEFGKI.js";
6
+ import { t as AuthSnapshot } from "../bind-h5jre2K0.js";
7
7
  import { t as AuthSession } from "../view-DyFdMCqg.js";
8
- import { n as Controller } from "../controller-BrP0gn47.js";
9
- import { C as LiveCountSource, D as ProfileOf, E as PresenceTopic, O as UseActionOptions, S as LiveCountHookOptions, T as PresenceHookOptions, _ as ActionResultOf, a as DataRows, b as ClaimsOf, c as DataWrites, d as BlockMutationState, f as BlockQueryActions, g as ActionInputOf, h as BlockRefetchOn, i as DataRow, l as BlockEventSource, m as BlockQueryState, n as DataId, o as DataSource, p as BlockQueryOptions, r as DataListArgs, s as DataState, t as fieldErrorsOf, u as BlockMutationActions, v as ActionState, w as LiveQueryHookOptions, x as ClientLike, y as BroadcastOptions } from "../field-errors-fsbFktYF.js";
10
- import { n as BlockOptions } from "../block-env-B_uEM2xz.js";
8
+ import { n as Controller } from "../controller-DyPPMFSw.js";
9
+ import { C as LiveCountSource, D as ProfileOf, E as PresenceTopic, O as UseActionOptions, S as LiveCountHookOptions, T as PresenceHookOptions, _ as ActionResultOf, a as DataRows, b as ClaimsOf, c as DataWrites, d as BlockMutationState, f as BlockQueryActions, g as ActionInputOf, h as BlockRefetchOn, i as DataRow, l as BlockEventSource, m as BlockQueryState, n as DataId, o as DataSource, p as BlockQueryOptions, r as DataListArgs, s as DataState, t as fieldErrorsOf, u as BlockMutationActions, v as ActionState, w as LiveQueryHookOptions, x as ClientLike, y as BroadcastOptions } from "../field-errors-DYtg1mwv.js";
10
+ import { n as BlockOptions } from "../block-env-BrfRvPrj.js";
11
11
  import { n as BlockDataOf, r as BlockMethodName, t as BlockArgsOf } from "../block-method-CiVa2G-J.js";
12
12
  import { SupabaseClient } from "@supabase/supabase-js";
13
13
  import { QueryClient } from "@tanstack/query-core";
@@ -1,10 +1,10 @@
1
1
  import { O as AnyFunctions, k as AnyModels } from "../types-DFdg_4yN.js";
2
2
  import { l as PermissionRef, t as AnyAuthorizer } from "../authorizer-B6X09otb.js";
3
3
  import { t as BetterSupabase } from "../define-DFBnQyYg.js";
4
- import { n as BetterServer } from "../server-types-CFtehAsr.js";
4
+ import { n as BetterServer } from "../server-types-7QPzW2bF.js";
5
5
  import { a as AuthorizedContext, c as ResourceLoaderContext, i as AuthorizeOptions, l as Unwrapped, n as ActionParsed, o as BlockActionOptions, r as ActionResult, s as BlockRequireOptions } from "../kit-DOwKpSkA.js";
6
6
  import { t as RefusalRedirects } from "../refusal-CSntB_x8.js";
7
- import { n as FrameworkOptions, r as LocalsResource, t as FrameworkLocals } from "../framework-BKyTeS-j.js";
7
+ import { n as FrameworkOptions, r as LocalsResource, t as FrameworkLocals } from "../framework-h5lP_5yj.js";
8
8
  import { t as Validated } from "../shared-CRRfQAKG.js";
9
9
  import { i as tagFor } from "../tags-BjHflcHF.js";
10
10
  import { AnyEntry, Contributions } from "@supabase/middleware";
@@ -1,12 +1,12 @@
1
1
  import { t as DbException } from "../db-exception-Lngc1W49.js";
2
2
  import { r as dbErrorOf } from "../errors-BVFgt8BZ.js";
3
3
  import { c as toProblem } from "../problem-Bf0cJ7tk.js";
4
- import { c as extendServer, o as withFlush, s as createServer } from "../adapter-B0b6MXYS.js";
4
+ import { c as extendServer, o as withFlush, s as createServer } from "../adapter-Dyks1lX1.js";
5
5
  import { t as defaultExpose } from "../respond-C3CcOZlA.js";
6
6
  import { r as tagFor } from "../tags-CIZTqtlY.js";
7
7
  import { i as requireCaller, o as runAction } from "../kit-5l-o8RxL.js";
8
8
  import { n as bufferInPlace, t as around } from "../shared-Bf-I13Ht.js";
9
- import { a as platformWaitUntil, i as localsOf, n as actionInput, r as frameworkEntry } from "../framework-DDdkR7FX.js";
9
+ import { a as platformWaitUntil, i as localsOf, n as actionInput, r as frameworkEntry } from "../framework-BozTXRzt.js";
10
10
  import { i as refusalTarget } from "../refusal-ByBZcm0V.js";
11
11
  //#region src/bridges/sveltekit.ts
12
12
  /**
@@ -1,10 +1,10 @@
1
1
  import { O as AnyFunctions, k as AnyModels } from "../types-DFdg_4yN.js";
2
2
  import { l as PermissionRef, t as AnyAuthorizer } from "../authorizer-B6X09otb.js";
3
3
  import { t as BetterSupabase } from "../define-DFBnQyYg.js";
4
- import { n as BetterServer } from "../server-types-CFtehAsr.js";
4
+ import { n as BetterServer } from "../server-types-7QPzW2bF.js";
5
5
  import { a as AuthorizedContext, c as ResourceLoaderContext, i as AuthorizeOptions, l as Unwrapped, n as ActionParsed, o as BlockActionOptions, r as ActionResult, s as BlockRequireOptions } from "../kit-DOwKpSkA.js";
6
6
  import { t as RefusalRedirects } from "../refusal-CSntB_x8.js";
7
- import { n as FrameworkOptions, r as LocalsResource, t as FrameworkLocals } from "../framework-BKyTeS-j.js";
7
+ import { n as FrameworkOptions, r as LocalsResource, t as FrameworkLocals } from "../framework-h5lP_5yj.js";
8
8
  import { t as Validated } from "../shared-CRRfQAKG.js";
9
9
  import { AnyEntry, Contributions } from "@supabase/middleware";
10
10
  import { StandardSchemaV1 } from "@standard-schema/spec";
@@ -1,8 +1,8 @@
1
- import { c as extendServer, o as withFlush, s as createServer } from "../adapter-B0b6MXYS.js";
1
+ import { c as extendServer, o as withFlush, s as createServer } from "../adapter-Dyks1lX1.js";
2
2
  import { t as defaultExpose } from "../respond-C3CcOZlA.js";
3
3
  import { i as requireCaller, o as runAction } from "../kit-5l-o8RxL.js";
4
4
  import { n as bufferInPlace, t as around } from "../shared-Bf-I13Ht.js";
5
- import { i as localsOf, r as frameworkEntry } from "../framework-DDdkR7FX.js";
5
+ import { i as localsOf, r as frameworkEntry } from "../framework-BozTXRzt.js";
6
6
  import { r as refusalResponse } from "../refusal-ByBZcm0V.js";
7
7
  //#region src/bridges/tanstack-start.ts
8
8
  /**
@@ -1,4 +1,4 @@
1
- import { t as AuthSnapshot } from "./bind-CrMBwrPN.js";
1
+ import { t as AuthSnapshot } from "./bind-h5jre2K0.js";
2
2
  import { t as AuthSession } from "./view-DyFdMCqg.js";
3
3
  //#region src/auth/tenant.d.ts
4
4
  /**
@@ -7,35 +7,35 @@ import { a as CredentialSubject, i as CredentialRef, r as CredentialProvider } f
7
7
  import { n as SqlClient } from "../executor-hGjrop3A.js";
8
8
  import { a as BlockTransportMiddleware } from "../block-hooks-DZN2w69m.js";
9
9
  import { a as SessionActor, o as SessionDelegation } from "../actor-CoveJgya.js";
10
- import { P as QueueProvider } from "../types-SFRomQF7.js";
11
- import { n as Embedder } from "../knowledge-CtL-Vfgy.js";
10
+ import { P as QueueProvider } from "../types-Czq9Xtpa.js";
11
+ import { n as Embedder } from "../knowledge-F1IhRI4Q.js";
12
12
  import { a as AuthorizationProvider } from "../authorization-HZdJCaVm.js";
13
13
  import { o as StreamStore } from "../store-CpheI-lN.js";
14
14
  import { o as Authorizer } from "../authorizer-B6X09otb.js";
15
15
  import { J as DbStats, Zt as CacheAdapter, t as BetterSupabase, v as Db } from "../define-DFBnQyYg.js";
16
16
  import { X as StoragePath } from "../bucket-CiNi8sIw.js";
17
- import { B as SupportSessionStore, a as ServerContext, c as ServerOptions } from "../server-types-CFtehAsr.js";
17
+ import { B as SupportSessionStore, a as ServerContext, c as ServerOptions } from "../server-types-7QPzW2bF.js";
18
18
  import { n as Impersonator } from "../impersonation-YTa9dZUv.js";
19
- import { tn as AnyRecordBinding } from "../define-block-BVcLQ3DF.js";
19
+ import { tn as AnyRecordBinding } from "../define-block-DvvcM54N.js";
20
20
  import { n as Money } from "../money-BNRdJQzA.js";
21
21
  import { i as EventSink, t as CloudEvent } from "../cloud-event-CzZTJkXv.js";
22
- import { i as AuthorizationHooks } from "../authorization-hooks-Cs1vP_ej.js";
22
+ import { i as AuthorizationHooks } from "../authorization-hooks-D_pwXlBs.js";
23
23
  import { s as SqlClaims, t as BetterPostgres } from "../pool-CrtT4dg-.js";
24
24
  import { r as GuardOptions } from "../respond-Dn1_YhC1.js";
25
25
  import { l as Transcriber, s as NoteTaker, u as TranscriberInput } from "../recordings-BBSJt_YV.js";
26
- import { n as Controller } from "../controller-BrP0gn47.js";
27
- import { c as AiTaskRunner, o as AiTaskRun, r as AiTask } from "../ai-schedules-CAquecT_.js";
28
- import { At as Generator, Rt as GeneratorInput, Vt as GeneratorModel, Zt as ResolvedConfig } from "../context-CEuTKrkz.js";
26
+ import { n as Controller } from "../controller-DyPPMFSw.js";
27
+ import { c as AiTaskRunner, o as AiTaskRun, r as AiTask } from "../ai-schedules-D_Hz-ik5.js";
28
+ import { Ht as GeneratorModel, Qt as ResolvedConfig, jt as Generator, zt as GeneratorInput } from "../context-TGX2eDS5.js";
29
29
  import { r as WebhookInput } from "../signatures-Dkx9OE8j.js";
30
30
  import { n as Payment, o as PaymentProvider } from "../payments-BYcN34Fp.js";
31
31
  import { t as NotificationChannel } from "../channel-BjvGO39m.js";
32
32
  import { a as DeliveryTransport } from "../delivery-n6lZGuGx.js";
33
33
  import { l as TaxProvider, r as TaxAddress } from "../tax-DPShHual.js";
34
34
  import { p as ShippingProvider, s as ShipmentAddress } from "../carrier-KzeYXVrW.js";
35
- import { L as WorkflowGraph, c as GraphCompiler, i as BuilderStarter, r as BuilderStartCall } from "../types-BBQLbui9.js";
35
+ import { L as WorkflowGraph, c as GraphCompiler, i as BuilderStarter, r as BuilderStartCall } from "../types-DsRfiQ0v.js";
36
36
  import { O as IncomingDestination, f as WebhookSecretStore, o as WebhookSigner, v as WebhookTransport } from "../signers-BAEzvTJ0.js";
37
37
  import { t as ApiModel } from "../model-hwpvole9.js";
38
- import { t as EveDocumentBackend } from "../eve-BFSwTu1z.js";
38
+ import { t as EveDocumentBackend } from "../eve-B7jxYPCw.js";
39
39
  import { l as VersionOf, t as AnyDocumentFormat } from "../format-u-65igKI.js";
40
40
  import { SupabaseClient } from "@supabase/supabase-js";
41
41
  import { Message, StateAdapter } from "chat";
@@ -1,8 +1,8 @@
1
1
  import { D as ValidationIssue, t as AsyncResult } from "./result-DZeA5KS6.js";
2
2
  import { $ as RecordRef } from "./types-DFdg_4yN.js";
3
3
  import { o as FilterField } from "./filter-query-BXLs72G9.js";
4
- import { cn as RecordBindingResult, hn as TimelineItem, in as RecordBindingData } from "./define-block-BVcLQ3DF.js";
5
- import { A as BindingBlocks, F as LoadBindingsOptions, M as BindingName, N as BindingOf, P as BindingSource, V as PermissionSet, _ as RecordTypeBlocks, g as RecordType, h as RecordCan } from "./index-DLq69k3F.js";
4
+ import { cn as RecordBindingResult, hn as TimelineItem, in as RecordBindingData } from "./define-block-DvvcM54N.js";
5
+ import { A as BindingBlocks, F as LoadBindingsOptions, M as BindingName, N as BindingOf, P as BindingSource, V as PermissionSet, _ as RecordTypeBlocks, g as RecordType, h as RecordCan } from "./index-BfkltrGJ.js";
6
6
  import { c as ListParseOptions, m as ListSearchParams } from "./list-query-BDVutLFr.js";
7
7
  //#region src/records/list.d.ts
8
8
  /**
@@ -3,7 +3,7 @@ import { D as AccessTopicPolicy, O as AnyFunctions, it as Row, k as AnyModels, u
3
3
  import { t as AuthorizationFunctions } from "./authorization-HZdJCaVm.js";
4
4
  import { t as BetterSupabase } from "./define-DFBnQyYg.js";
5
5
  import { $ as TemplateValues, Q as TemplateParams } from "./bucket-CiNi8sIw.js";
6
- import { g as SubscriberPolicy, h as SubscriberEvent, i as AuthorizationHooks, m as Subscriber } from "./authorization-hooks-Cs1vP_ej.js";
6
+ import { g as SubscriberPolicy, h as SubscriberEvent, i as AuthorizationHooks, m as Subscriber } from "./authorization-hooks-D_pwXlBs.js";
7
7
  import { t as RealtimeStatus } from "./realtime-status-BhNkb-Ow.js";
8
8
  import { RealtimeChannel, SupabaseClient } from "@supabase/supabase-js";
9
9
  import { StandardSchemaV1 } from "@standard-schema/spec";
@@ -4,7 +4,7 @@ import { n as Logger } from "./logger-DWVYUmwi.js";
4
4
  import { r as BlockTemporalOptions } from "./block-helpers-CRpAHrp_.js";
5
5
  import { t as BlockTransport } from "./block-transport-DWZSJrwN.js";
6
6
  import { n as BlockHooks } from "./block-hooks-DZN2w69m.js";
7
- import { n as Embedder } from "./knowledge-CtL-Vfgy.js";
7
+ import { n as Embedder } from "./knowledge-F1IhRI4Q.js";
8
8
  //#region src/blocks/memory/types.d.ts
9
9
  type MemoryScope = "user" | "agent" | "chat" | "project" | "organization";
10
10
  type MemoryKind = "core" | "archival";