tanstack_start_ts 1.0.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 (336) hide show
  1. package/.wrangler/deploy/config.json +1 -0
  2. package/bunfig.toml +6 -0
  3. package/components.json +22 -0
  4. package/config.json +0 -0
  5. package/dist/client/.assetsignore +2 -0
  6. package/dist/client/assets/ProductCard-DbIkJAE-.js +1 -0
  7. package/dist/client/assets/about-AskxOruL.js +1 -0
  8. package/dist/client/assets/admin-BZVcAQM3.js +1 -0
  9. package/dist/client/assets/admin.functions--RdVcuBx.js +1 -0
  10. package/dist/client/assets/admin.login-QgrF_9Fp.js +1 -0
  11. package/dist/client/assets/affiliate-disclosure-BIAsA-HO.js +1 -0
  12. package/dist/client/assets/categories-D0N418mK.js +1 -0
  13. package/dist/client/assets/category._slug-aCaQm14E.js +1 -0
  14. package/dist/client/assets/contact-PhvO-V15.js +1 -0
  15. package/dist/client/assets/faq-BsiHWPM8.js +1 -0
  16. package/dist/client/assets/hero-bg-BP2eVUIX.jpg +0 -0
  17. package/dist/client/assets/index-BU9rnkF3.js +1 -0
  18. package/dist/client/assets/index-BpJWZkva.js +1 -0
  19. package/dist/client/assets/index-vRX-zAyq.js +1 -0
  20. package/dist/client/assets/login-DteE0ZGp.js +1 -0
  21. package/dist/client/assets/logo-pSNfLJQk.png +0 -0
  22. package/dist/client/assets/privacy-B_Pu7040.js +1 -0
  23. package/dist/client/assets/product-links-BkZ41Gv3.js +1 -0
  24. package/dist/client/assets/product._id-BVUysCW-.js +1 -0
  25. package/dist/client/assets/products.functions-cGzRziKO.js +1 -0
  26. package/dist/client/assets/profile-CveRcKq2.js +1 -0
  27. package/dist/client/assets/reset-password-ySEjItX_.js +1 -0
  28. package/dist/client/assets/saved-CHtdQDJF.js +1 -0
  29. package/dist/client/assets/search-CXWfET1y.js +1 -0
  30. package/dist/client/assets/signup-CEx90iuV.js +1 -0
  31. package/dist/client/assets/styles-DrNJG0BO.css +1 -0
  32. package/dist/client/assets/terms-VqJ9kX9b.js +1 -0
  33. package/dist/client/assets/update-password-C-d0ix5e.js +1 -0
  34. package/dist/client/assets/vendor-aria-hidden-DvXkyWUv.js +1 -0
  35. package/dist/client/assets/vendor-class-variance-authority-5VPnzWs2.js +1 -0
  36. package/dist/client/assets/vendor-clsx-B-dksMZM.js +1 -0
  37. package/dist/client/assets/vendor-cookie-es-CS0aJGDi.js +1 -0
  38. package/dist/client/assets/vendor-detect-node-es-l0sNRNKZ.js +1 -0
  39. package/dist/client/assets/vendor-floating-ui-core-BlUy28sp.js +1 -0
  40. package/dist/client/assets/vendor-floating-ui-dom-BxK0hn2R.js +1 -0
  41. package/dist/client/assets/vendor-floating-ui-react-dom-Bas3975S.js +1 -0
  42. package/dist/client/assets/vendor-floating-ui-utils-BfYUAVcw.js +1 -0
  43. package/dist/client/assets/vendor-framer-motion-BMdL-cuX.js +9 -0
  44. package/dist/client/assets/vendor-get-nonce-C-Z93AgS.js +1 -0
  45. package/dist/client/assets/vendor-iceberg-js-tWD4K6Lg.js +1 -0
  46. package/dist/client/assets/vendor-lovable.dev-cloud-auth-js-VuzqtJVg.js +1 -0
  47. package/dist/client/assets/vendor-lucide-react-b5K2fehp.js +1 -0
  48. package/dist/client/assets/vendor-motion-dom-BETJamZt.js +1 -0
  49. package/dist/client/assets/vendor-motion-utils-BuWewJbj.js +1 -0
  50. package/dist/client/assets/vendor-radix-ui-primitive-Dc_FVRD7.js +1 -0
  51. package/dist/client/assets/vendor-radix-ui-react-accordion-C22Rgxe9.js +1 -0
  52. package/dist/client/assets/vendor-radix-ui-react-arrow-DMHj2mKI.js +1 -0
  53. package/dist/client/assets/vendor-radix-ui-react-avatar-CVPBkFXg.js +1 -0
  54. package/dist/client/assets/vendor-radix-ui-react-collapsible-BvM-4sKX.js +1 -0
  55. package/dist/client/assets/vendor-radix-ui-react-collection-D9KtqmHm.js +1 -0
  56. package/dist/client/assets/vendor-radix-ui-react-compose-refs-Cvq0AS8Z.js +1 -0
  57. package/dist/client/assets/vendor-radix-ui-react-context-CAqqn5Nx.js +1 -0
  58. package/dist/client/assets/vendor-radix-ui-react-dialog-DZ01vOLq.js +5 -0
  59. package/dist/client/assets/vendor-radix-ui-react-direction-DxZwNuei.js +1 -0
  60. package/dist/client/assets/vendor-radix-ui-react-dismissable-layer-Dqgrs55Y.js +1 -0
  61. package/dist/client/assets/vendor-radix-ui-react-dropdown-menu-0uzvrqkn.js +1 -0
  62. package/dist/client/assets/vendor-radix-ui-react-focus-guards-DgWoZ-fP.js +1 -0
  63. package/dist/client/assets/vendor-radix-ui-react-focus-scope-BLIu5QaL.js +1 -0
  64. package/dist/client/assets/vendor-radix-ui-react-id-bpga_rLa.js +1 -0
  65. package/dist/client/assets/vendor-radix-ui-react-menu-D0qf2r6_.js +1 -0
  66. package/dist/client/assets/vendor-radix-ui-react-popper-BafIylxU.js +1 -0
  67. package/dist/client/assets/vendor-radix-ui-react-portal-BnAsfNCS.js +1 -0
  68. package/dist/client/assets/vendor-radix-ui-react-presence-C-f3UKQ2.js +1 -0
  69. package/dist/client/assets/vendor-radix-ui-react-primitive-zTHwXNoz.js +1 -0
  70. package/dist/client/assets/vendor-radix-ui-react-roving-focus-jyJB8K2E.js +1 -0
  71. package/dist/client/assets/vendor-radix-ui-react-slot-6LXHJrHl.js +1 -0
  72. package/dist/client/assets/vendor-radix-ui-react-use-callback-ref-E91aPc6s.js +1 -0
  73. package/dist/client/assets/vendor-radix-ui-react-use-controllable-state-Ca3eMtxa.js +1 -0
  74. package/dist/client/assets/vendor-radix-ui-react-use-effect-event-CPeX4A3c.js +1 -0
  75. package/dist/client/assets/vendor-radix-ui-react-use-escape-keydown-7n3YsXFo.js +1 -0
  76. package/dist/client/assets/vendor-radix-ui-react-use-is-hydrated-C1PY1qNv.js +1 -0
  77. package/dist/client/assets/vendor-radix-ui-react-use-layout-effect-B3AcGWPy.js +1 -0
  78. package/dist/client/assets/vendor-radix-ui-react-use-size-CXS04sct.js +1 -0
  79. package/dist/client/assets/vendor-react-dom-BnNs-kzm.js +9 -0
  80. package/dist/client/assets/vendor-react-gJPiVnX5.js +1 -0
  81. package/dist/client/assets/vendor-react-remove-scroll-DHKl-IMP.js +4 -0
  82. package/dist/client/assets/vendor-react-remove-scroll-bar-CSjdInc2.js +38 -0
  83. package/dist/client/assets/vendor-react-style-singleton-BqHpkgXn.js +1 -0
  84. package/dist/client/assets/vendor-scheduler-7OC5HNn7.js +1 -0
  85. package/dist/client/assets/vendor-seroval-B_Fur-nl.js +3 -0
  86. package/dist/client/assets/vendor-seroval-plugins-CBHnPkZJ.js +1 -0
  87. package/dist/client/assets/vendor-sonner-71-LdGG1.js +1 -0
  88. package/dist/client/assets/vendor-supabase-auth-js-DWrN-bIx.js +18 -0
  89. package/dist/client/assets/vendor-supabase-functions-js-uY_V-TxC.js +1 -0
  90. package/dist/client/assets/vendor-supabase-phoenix-BzEf37Ve.js +2 -0
  91. package/dist/client/assets/vendor-supabase-postgrest-js-C4rBWbCx.js +4 -0
  92. package/dist/client/assets/vendor-supabase-realtime-js-D6BlOYKE.js +23 -0
  93. package/dist/client/assets/vendor-supabase-storage-js-BG98L3Zz.js +1 -0
  94. package/dist/client/assets/vendor-supabase-supabase-js-DCCzdwBJ.js +1 -0
  95. package/dist/client/assets/vendor-tailwind-merge-Ct12j0u0.js +1 -0
  96. package/dist/client/assets/vendor-tanstack-history-C617CaxG.js +1 -0
  97. package/dist/client/assets/vendor-tanstack-query-core-7wuJJ5ZL.js +1 -0
  98. package/dist/client/assets/vendor-tanstack-react-query-HImzo8sX.js +1 -0
  99. package/dist/client/assets/vendor-tanstack-react-router-sIZLK-LU.js +1 -0
  100. package/dist/client/assets/vendor-tanstack-react-start-client-GiYCfWmf.js +1 -0
  101. package/dist/client/assets/vendor-tanstack-react-store-EvTi3ahh.js +1 -0
  102. package/dist/client/assets/vendor-tanstack-router-core-Cr7bYUZv.js +1 -0
  103. package/dist/client/assets/vendor-tanstack-start-client-core-C-00BBOu.js +2 -0
  104. package/dist/client/assets/vendor-tanstack-start-fn-stubs-l0sNRNKZ.js +1 -0
  105. package/dist/client/assets/vendor-tanstack-store-BC7mA7pq.js +1 -0
  106. package/dist/client/assets/vendor-tslib-Du-meQkk.js +1 -0
  107. package/dist/client/assets/vendor-use-callback-ref-C_fIAtot.js +1 -0
  108. package/dist/client/assets/vendor-use-sidecar-Bh0DDN6h.js +1 -0
  109. package/dist/client/assets/vendor-use-sync-external-store-ZvKHXaIn.js +1 -0
  110. package/dist/client/assets/vendor-vercel-analytics-DwPM5BWs.js +1 -0
  111. package/dist/client/assets/vendor-zod-By9teAtI.js +1 -0
  112. package/dist/client/robots.txt +2 -0
  113. package/dist/server/.dev.vars +5 -0
  114. package/dist/server/.vite/manifest.json +2528 -0
  115. package/dist/server/assets/ProductCard-CUPXy5Eo.js +149 -0
  116. package/dist/server/assets/_tanstack-start-manifest_v-do7vTWFD.js +4 -0
  117. package/dist/server/assets/about-TfKQw0Ga.js +28 -0
  118. package/dist/server/assets/admin-DspfJOJk.js +578 -0
  119. package/dist/server/assets/admin.functions-B78ppWLR.js +645 -0
  120. package/dist/server/assets/admin.functions-BWlKBoTL.js +93 -0
  121. package/dist/server/assets/admin.login-CV7QfeA6.js +139 -0
  122. package/dist/server/assets/affiliate-disclosure-B1wI1cDb.js +86 -0
  123. package/dist/server/assets/auth-middleware-Cn49MidW.js +62 -0
  124. package/dist/server/assets/categories-Z7jnAYZP.js +108 -0
  125. package/dist/server/assets/category._slug-D0XY3FGK.js +112 -0
  126. package/dist/server/assets/contact-IzyONsXs.js +104 -0
  127. package/dist/server/assets/faq-aRhB_CR3.js +133 -0
  128. package/dist/server/assets/hero-bg-BP2eVUIX.jpg +0 -0
  129. package/dist/server/assets/index-BTPHbXw9.js +221 -0
  130. package/dist/server/assets/index-ByJkHkrU.js +30 -0
  131. package/dist/server/assets/login-Dvy5Dm0f.js +175 -0
  132. package/dist/server/assets/logo-pSNfLJQk.png +0 -0
  133. package/dist/server/assets/privacy-B6Wiez1P.js +93 -0
  134. package/dist/server/assets/product-links-CGYEPP56.js +16 -0
  135. package/dist/server/assets/product._id-BpRa-1z0.js +231 -0
  136. package/dist/server/assets/products.functions-DSlmibYN.js +209 -0
  137. package/dist/server/assets/products.functions-DlHkRiqi.js +24 -0
  138. package/dist/server/assets/profile-B0NWzVAZ.js +314 -0
  139. package/dist/server/assets/reset-password-CY-rmqMr.js +115 -0
  140. package/dist/server/assets/saved-7FA6Dbom.js +126 -0
  141. package/dist/server/assets/search-Yw5c_fZa.js +329 -0
  142. package/dist/server/assets/signup-UPzgZo4i.js +143 -0
  143. package/dist/server/assets/styles-DrNJG0BO.css +1 -0
  144. package/dist/server/assets/terms-CMnX95bP.js +89 -0
  145. package/dist/server/assets/update-password-Cr94ea8n.js +131 -0
  146. package/dist/server/assets/vendor-aria-hidden-DPa16MWu.js +122 -0
  147. package/dist/server/assets/vendor-class-variance-authority-0YxJPB9Y.js +44 -0
  148. package/dist/server/assets/vendor-cloudflare-unenv-preset-ya0VEFBz.js +250 -0
  149. package/dist/server/assets/vendor-clsx-DgYk2OaC.js +16 -0
  150. package/dist/server/assets/vendor-cookie-es-DAoofYiI.js +44 -0
  151. package/dist/server/assets/vendor-detect-node-es-l0sNRNKZ.js +1 -0
  152. package/dist/server/assets/vendor-floating-ui-core-3tkK0THV.js +726 -0
  153. package/dist/server/assets/vendor-floating-ui-dom-C-cPtgJv.js +626 -0
  154. package/dist/server/assets/vendor-floating-ui-react-dom-CRG6gBpH.js +319 -0
  155. package/dist/server/assets/vendor-floating-ui-utils-DmXANH-E.js +320 -0
  156. package/dist/server/assets/vendor-framer-motion-X4zAkX3J.js +1979 -0
  157. package/dist/server/assets/vendor-get-nonce-DiSj3EHl.js +9 -0
  158. package/dist/server/assets/vendor-h3-v2-CCobnLY5.js +287 -0
  159. package/dist/server/assets/vendor-iceberg-js-bHCkXyJn.js +534 -0
  160. package/dist/server/assets/vendor-isbot-CZ7WjwVs.js +21 -0
  161. package/dist/server/assets/vendor-lovable.dev-cloud-auth-js-BE03njZw.js +180 -0
  162. package/dist/server/assets/vendor-lucide-react-Ddew6HYb.js +458 -0
  163. package/dist/server/assets/vendor-motion-dom-D2MTwGIG.js +5983 -0
  164. package/dist/server/assets/vendor-motion-utils-LJlIFN6m.js +161 -0
  165. package/dist/server/assets/vendor-radix-ui-primitive-B-mNdDrH.js +11 -0
  166. package/dist/server/assets/vendor-radix-ui-react-accordion-1Izf6x00.js +308 -0
  167. package/dist/server/assets/vendor-radix-ui-react-arrow-B882lnFK.js +23 -0
  168. package/dist/server/assets/vendor-radix-ui-react-avatar-BVgZt2Ab.js +209 -0
  169. package/dist/server/assets/vendor-radix-ui-react-collapsible-DCBbMZiS.js +147 -0
  170. package/dist/server/assets/vendor-radix-ui-react-collection-BZ2srfgU.js +150 -0
  171. package/dist/server/assets/vendor-radix-ui-react-compose-refs-D3qsKVk1.js +39 -0
  172. package/dist/server/assets/vendor-radix-ui-react-context-BVoNDLue.js +78 -0
  173. package/dist/server/assets/vendor-radix-ui-react-dialog-DlxMaNYK.js +406 -0
  174. package/dist/server/assets/vendor-radix-ui-react-direction-Dt_WDL1t.js +9 -0
  175. package/dist/server/assets/vendor-radix-ui-react-dismissable-layer-CjsuPohV.js +210 -0
  176. package/dist/server/assets/vendor-radix-ui-react-dropdown-menu-DVxKumY8.js +263 -0
  177. package/dist/server/assets/vendor-radix-ui-react-focus-guards-D_6NoePE.js +29 -0
  178. package/dist/server/assets/vendor-radix-ui-react-focus-scope-DEIhTJJH.js +206 -0
  179. package/dist/server/assets/vendor-radix-ui-react-id-DFFpgh6m.js +14 -0
  180. package/dist/server/assets/vendor-radix-ui-react-menu-CiTMLwjT.js +893 -0
  181. package/dist/server/assets/vendor-radix-ui-react-popper-23Ye2Vyc.js +286 -0
  182. package/dist/server/assets/vendor-radix-ui-react-portal-CZCH5uPk.js +16 -0
  183. package/dist/server/assets/vendor-radix-ui-react-presence-CaAULlDU.js +128 -0
  184. package/dist/server/assets/vendor-radix-ui-react-primitive-BeOk3UYa.js +124 -0
  185. package/dist/server/assets/vendor-radix-ui-react-roving-focus-DES9GR8l.js +224 -0
  186. package/dist/server/assets/vendor-radix-ui-react-slot-DUhZbzoH.js +103 -0
  187. package/dist/server/assets/vendor-radix-ui-react-use-callback-ref-BynBgohw.js +11 -0
  188. package/dist/server/assets/vendor-radix-ui-react-use-controllable-state-C9KpT6DG.js +69 -0
  189. package/dist/server/assets/vendor-radix-ui-react-use-effect-event-gpNY2xjS.js +1 -0
  190. package/dist/server/assets/vendor-radix-ui-react-use-escape-keydown-CcYRQ2pp.js +17 -0
  191. package/dist/server/assets/vendor-radix-ui-react-use-is-hydrated-D_LcBPXY.js +15 -0
  192. package/dist/server/assets/vendor-radix-ui-react-use-layout-effect-1LNLXAjr.js +6 -0
  193. package/dist/server/assets/vendor-radix-ui-react-use-size-D6fiKJQo.js +39 -0
  194. package/dist/server/assets/vendor-react-DvBrY0qp.js +511 -0
  195. package/dist/server/assets/vendor-react-dom-yvMLPM0j.js +10484 -0
  196. package/dist/server/assets/vendor-react-remove-scroll-BNtiEvVN.js +328 -0
  197. package/dist/server/assets/vendor-react-remove-scroll-bar-hLqRASRk.js +82 -0
  198. package/dist/server/assets/vendor-react-style-singleton-BXjcXskB.js +69 -0
  199. package/dist/server/assets/vendor-rou3-3NaGPdI8.js +8 -0
  200. package/dist/server/assets/vendor-seroval-dJyC-Zhz.js +1775 -0
  201. package/dist/server/assets/vendor-seroval-plugins-Pq_U2meB.js +58 -0
  202. package/dist/server/assets/vendor-sonner-CqbjhsRh.js +1086 -0
  203. package/dist/server/assets/vendor-srvx-BA-baEX9.js +6 -0
  204. package/dist/server/assets/vendor-supabase-auth-js-D4xjVprw.js +7602 -0
  205. package/dist/server/assets/vendor-supabase-functions-js-sWy4UYn1.js +322 -0
  206. package/dist/server/assets/vendor-supabase-phoenix-Bw3Uh2Nn.js +1777 -0
  207. package/dist/server/assets/vendor-supabase-postgrest-js-AO-BXa7I.js +4938 -0
  208. package/dist/server/assets/vendor-supabase-realtime-js-BtdNgJbm.js +2111 -0
  209. package/dist/server/assets/vendor-supabase-storage-js-Dk_MrPYO.js +2679 -0
  210. package/dist/server/assets/vendor-supabase-supabase-js-D1EEtG3j.js +697 -0
  211. package/dist/server/assets/vendor-tailwind-merge-BHb_obmC.js +3255 -0
  212. package/dist/server/assets/vendor-tanstack-history-C4pKJmkt.js +204 -0
  213. package/dist/server/assets/vendor-tanstack-query-core-PwwTR5ld.js +2552 -0
  214. package/dist/server/assets/vendor-tanstack-react-query-hhHzXAK1.js +190 -0
  215. package/dist/server/assets/vendor-tanstack-react-router-XzqpA65A.js +1120 -0
  216. package/dist/server/assets/vendor-tanstack-react-start-RvWUpvat.js +37 -0
  217. package/dist/server/assets/vendor-tanstack-react-start-client-gpNY2xjS.js +1 -0
  218. package/dist/server/assets/vendor-tanstack-react-start-server-uj_Y9pEN.js +15 -0
  219. package/dist/server/assets/vendor-tanstack-react-store-gpNY2xjS.js +1 -0
  220. package/dist/server/assets/vendor-tanstack-router-core-6wywV3KN.js +4252 -0
  221. package/dist/server/assets/vendor-tanstack-start-client-core-DoOKV2pA.js +1741 -0
  222. package/dist/server/assets/vendor-tanstack-start-fn-stubs-l0sNRNKZ.js +1 -0
  223. package/dist/server/assets/vendor-tanstack-start-server-core-CsAstXv7.js +1421 -0
  224. package/dist/server/assets/vendor-tanstack-start-storage-context-DgH9hIJT.js +17 -0
  225. package/dist/server/assets/vendor-tanstack-store-l0sNRNKZ.js +1 -0
  226. package/dist/server/assets/vendor-tslib-_8ICaZ64.js +67 -0
  227. package/dist/server/assets/vendor-unenv-DUvF4YIF.js +544 -0
  228. package/dist/server/assets/vendor-use-callback-ref-DMFDRvmi.js +66 -0
  229. package/dist/server/assets/vendor-use-sidecar-DG1tHua4.js +106 -0
  230. package/dist/server/assets/vendor-use-sync-external-store-rZ8vi0It.js +64 -0
  231. package/dist/server/assets/vendor-vercel-analytics-oP8BDp0L.js +168 -0
  232. package/dist/server/assets/vendor-zod-BRyQdbC-.js +3580 -0
  233. package/dist/server/index.js +158 -0
  234. package/dist/server/wrangler.json +1 -0
  235. package/enable-powershell.ps1 +7 -0
  236. package/eslint.config.js +41 -0
  237. package/lint.bat +4 -0
  238. package/package.json +95 -0
  239. package/public/robots.txt +2 -0
  240. package/run-npm-build.cjs +20 -0
  241. package/run-npm-build.js +20 -0
  242. package/src/assets/hero-bg.jpg +0 -0
  243. package/src/assets/logo.png +0 -0
  244. package/src/components/scrollsy/Footer.tsx +68 -0
  245. package/src/components/scrollsy/LiveTicker.tsx +31 -0
  246. package/src/components/scrollsy/Logo.tsx +28 -0
  247. package/src/components/scrollsy/Nav.tsx +255 -0
  248. package/src/components/scrollsy/ProductCard.tsx +190 -0
  249. package/src/components/scrollsy/ProductFilters.tsx +226 -0
  250. package/src/components/scrollsy/SupportWidget.tsx +197 -0
  251. package/src/components/ui/accordion.tsx +51 -0
  252. package/src/components/ui/alert-dialog.tsx +115 -0
  253. package/src/components/ui/alert.tsx +49 -0
  254. package/src/components/ui/aspect-ratio.tsx +5 -0
  255. package/src/components/ui/avatar.tsx +47 -0
  256. package/src/components/ui/badge.tsx +32 -0
  257. package/src/components/ui/breadcrumb.tsx +101 -0
  258. package/src/components/ui/button.tsx +49 -0
  259. package/src/components/ui/calendar.tsx +177 -0
  260. package/src/components/ui/card.tsx +55 -0
  261. package/src/components/ui/carousel.tsx +240 -0
  262. package/src/components/ui/chart.tsx +331 -0
  263. package/src/components/ui/checkbox.tsx +26 -0
  264. package/src/components/ui/collapsible.tsx +11 -0
  265. package/src/components/ui/command.tsx +143 -0
  266. package/src/components/ui/context-menu.tsx +187 -0
  267. package/src/components/ui/dialog.tsx +104 -0
  268. package/src/components/ui/drawer.tsx +98 -0
  269. package/src/components/ui/dropdown-menu.tsx +188 -0
  270. package/src/components/ui/form.tsx +171 -0
  271. package/src/components/ui/hover-card.tsx +27 -0
  272. package/src/components/ui/input-otp.tsx +69 -0
  273. package/src/components/ui/input.tsx +22 -0
  274. package/src/components/ui/label.tsx +21 -0
  275. package/src/components/ui/menubar.tsx +229 -0
  276. package/src/components/ui/navigation-menu.tsx +120 -0
  277. package/src/components/ui/pagination.tsx +98 -0
  278. package/src/components/ui/popover.tsx +31 -0
  279. package/src/components/ui/progress.tsx +25 -0
  280. package/src/components/ui/radio-group.tsx +36 -0
  281. package/src/components/ui/resizable.tsx +37 -0
  282. package/src/components/ui/scroll-area.tsx +44 -0
  283. package/src/components/ui/select.tsx +152 -0
  284. package/src/components/ui/separator.tsx +24 -0
  285. package/src/components/ui/sheet.tsx +122 -0
  286. package/src/components/ui/sidebar.tsx +744 -0
  287. package/src/components/ui/skeleton.tsx +7 -0
  288. package/src/components/ui/slider.tsx +23 -0
  289. package/src/components/ui/sonner.tsx +23 -0
  290. package/src/components/ui/switch.tsx +27 -0
  291. package/src/components/ui/table.tsx +94 -0
  292. package/src/components/ui/tabs.tsx +53 -0
  293. package/src/components/ui/textarea.tsx +21 -0
  294. package/src/components/ui/toggle-group.tsx +57 -0
  295. package/src/components/ui/toggle.tsx +42 -0
  296. package/src/components/ui/tooltip.tsx +32 -0
  297. package/src/hooks/use-auth.ts +26 -0
  298. package/src/hooks/use-mobile.tsx +19 -0
  299. package/src/integrations/lovable/index.ts +41 -0
  300. package/src/lib/admin.functions.ts +564 -0
  301. package/src/lib/error-capture.ts +27 -0
  302. package/src/lib/error-page.ts +30 -0
  303. package/src/lib/product-links.ts +39 -0
  304. package/src/lib/products.functions.ts +101 -0
  305. package/src/lib/utils.ts +6 -0
  306. package/src/routeTree.gen.ts +480 -0
  307. package/src/router.tsx +16 -0
  308. package/src/routes/__root.tsx +177 -0
  309. package/src/routes/about.tsx +66 -0
  310. package/src/routes/admin.login.tsx +95 -0
  311. package/src/routes/admin.tsx +811 -0
  312. package/src/routes/affiliate-disclosure.tsx +35 -0
  313. package/src/routes/categories.tsx +57 -0
  314. package/src/routes/category.$slug.tsx +51 -0
  315. package/src/routes/contact.tsx +69 -0
  316. package/src/routes/faq.tsx +63 -0
  317. package/src/routes/index.tsx +269 -0
  318. package/src/routes/login.tsx +160 -0
  319. package/src/routes/privacy.tsx +39 -0
  320. package/src/routes/product.$id.tsx +212 -0
  321. package/src/routes/profile.tsx +393 -0
  322. package/src/routes/reset-password.tsx +71 -0
  323. package/src/routes/saved.tsx +83 -0
  324. package/src/routes/search.tsx +136 -0
  325. package/src/routes/signup.tsx +108 -0
  326. package/src/routes/sitemap[.]xml.ts +34 -0
  327. package/src/routes/terms.tsx +40 -0
  328. package/src/routes/update-password.tsx +91 -0
  329. package/src/server.ts +80 -0
  330. package/src/start.ts +24 -0
  331. package/src/styles.css +333 -0
  332. package/terminal-test-output.txt +1 -0
  333. package/tsconfig.json +27 -0
  334. package/vercel.json +26 -0
  335. package/vite.config.ts +38 -0
  336. package/wrangler.jsonc +7 -0
@@ -0,0 +1,4938 @@
1
+ const DEFAULT_MAX_RETRIES = 3;
2
+ const getRetryDelay = (attemptIndex) => Math.min(1e3 * 2 ** attemptIndex, 3e4);
3
+ const RETRYABLE_STATUS_CODES = [520, 503];
4
+ const RETRYABLE_METHODS = [
5
+ "GET",
6
+ "HEAD",
7
+ "OPTIONS"
8
+ ];
9
+ var PostgrestError = class extends Error {
10
+ /**
11
+ * @example
12
+ * ```ts
13
+ * import PostgrestError from '@supabase/postgrest-js'
14
+ *
15
+ * throw new PostgrestError({
16
+ * message: 'Row level security prevented the request',
17
+ * details: 'RLS denied the insert',
18
+ * hint: 'Check your policies',
19
+ * code: 'PGRST301',
20
+ * })
21
+ * ```
22
+ */
23
+ constructor(context) {
24
+ super(context.message);
25
+ this.name = "PostgrestError";
26
+ this.details = context.details;
27
+ this.hint = context.hint;
28
+ this.code = context.code;
29
+ }
30
+ toJSON() {
31
+ return {
32
+ name: this.name,
33
+ message: this.message,
34
+ details: this.details,
35
+ hint: this.hint,
36
+ code: this.code
37
+ };
38
+ }
39
+ };
40
+ function sleep(ms, signal) {
41
+ return new Promise((resolve) => {
42
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
43
+ resolve();
44
+ return;
45
+ }
46
+ const id = setTimeout(() => {
47
+ signal === null || signal === void 0 || signal.removeEventListener("abort", onAbort);
48
+ resolve();
49
+ }, ms);
50
+ function onAbort() {
51
+ clearTimeout(id);
52
+ resolve();
53
+ }
54
+ signal === null || signal === void 0 || signal.addEventListener("abort", onAbort);
55
+ });
56
+ }
57
+ function shouldRetry(method, status, attemptCount, retryEnabled) {
58
+ if (!retryEnabled || attemptCount >= DEFAULT_MAX_RETRIES) return false;
59
+ if (!RETRYABLE_METHODS.includes(method)) return false;
60
+ if (!RETRYABLE_STATUS_CODES.includes(status)) return false;
61
+ return true;
62
+ }
63
+ var PostgrestBuilder = class {
64
+ /**
65
+ * Creates a builder configured for a specific PostgREST request.
66
+ *
67
+ * @example Using supabase-js (recommended)
68
+ * ```ts
69
+ * import { createClient } from '@supabase/supabase-js'
70
+ *
71
+ * const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
72
+ * const { data, error } = await supabase.from('users').select('*')
73
+ * ```
74
+ *
75
+ * @category Database
76
+ *
77
+ * @example Standalone import for bundle-sensitive environments
78
+ * ```ts
79
+ * import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
80
+ *
81
+ * const builder = new PostgrestQueryBuilder(
82
+ * new URL('https://xyzcompany.supabase.co/rest/v1/users'),
83
+ * { headers: new Headers({ apikey: 'your-publishable-key' }) }
84
+ * )
85
+ * ```
86
+ */
87
+ constructor(builder) {
88
+ var _builder$shouldThrowO, _builder$isMaybeSingl, _builder$shouldStripN, _builder$urlLengthLim, _builder$retry;
89
+ this.shouldThrowOnError = false;
90
+ this.retryEnabled = true;
91
+ this.method = builder.method;
92
+ this.url = builder.url;
93
+ this.headers = new Headers(builder.headers);
94
+ this.schema = builder.schema;
95
+ this.body = builder.body;
96
+ this.shouldThrowOnError = (_builder$shouldThrowO = builder.shouldThrowOnError) !== null && _builder$shouldThrowO !== void 0 ? _builder$shouldThrowO : false;
97
+ this.signal = builder.signal;
98
+ this.isMaybeSingle = (_builder$isMaybeSingl = builder.isMaybeSingle) !== null && _builder$isMaybeSingl !== void 0 ? _builder$isMaybeSingl : false;
99
+ this.shouldStripNulls = (_builder$shouldStripN = builder.shouldStripNulls) !== null && _builder$shouldStripN !== void 0 ? _builder$shouldStripN : false;
100
+ this.urlLengthLimit = (_builder$urlLengthLim = builder.urlLengthLimit) !== null && _builder$urlLengthLim !== void 0 ? _builder$urlLengthLim : 8e3;
101
+ this.retryEnabled = (_builder$retry = builder.retry) !== null && _builder$retry !== void 0 ? _builder$retry : true;
102
+ if (builder.fetch) this.fetch = builder.fetch;
103
+ else this.fetch = fetch;
104
+ }
105
+ /**
106
+ * If there's an error with the query, throwOnError will reject the promise by
107
+ * throwing the error instead of returning it as part of a successful response.
108
+ *
109
+ * {@link https://github.com/supabase/supabase-js/issues/92}
110
+ *
111
+ * @category Database
112
+ */
113
+ throwOnError() {
114
+ this.shouldThrowOnError = true;
115
+ return this;
116
+ }
117
+ /**
118
+ * Strip null values from the response data. Properties with `null` values
119
+ * will be omitted from the returned JSON objects.
120
+ *
121
+ * Requires PostgREST 11.2.0+.
122
+ *
123
+ * {@link https://docs.postgrest.org/en/stable/references/api/resource_representation.html#stripped-nulls}
124
+ *
125
+ * @category Database
126
+ * @subcategory Using modifiers
127
+ *
128
+ * @example With `select()`
129
+ * ```ts
130
+ * const { data, error } = await supabase
131
+ * .from('characters')
132
+ * .select()
133
+ * .stripNulls()
134
+ * ```
135
+ *
136
+ * @exampleSql With `select()`
137
+ * ```sql
138
+ * create table
139
+ * characters (id int8 primary key, name text, bio text);
140
+ *
141
+ * insert into
142
+ * characters (id, name, bio)
143
+ * values
144
+ * (1, 'Luke', null),
145
+ * (2, 'Leia', 'Princess of Alderaan');
146
+ * ```
147
+ *
148
+ * @exampleResponse With `select()`
149
+ * ```json
150
+ * {
151
+ * "data": [
152
+ * {
153
+ * "id": 1,
154
+ * "name": "Luke"
155
+ * },
156
+ * {
157
+ * "id": 2,
158
+ * "name": "Leia",
159
+ * "bio": "Princess of Alderaan"
160
+ * }
161
+ * ],
162
+ * "status": 200,
163
+ * "statusText": "OK"
164
+ * }
165
+ * ```
166
+ */
167
+ stripNulls() {
168
+ if (this.headers.get("Accept") === "text/csv") throw new Error("stripNulls() cannot be used with csv()");
169
+ this.shouldStripNulls = true;
170
+ return this;
171
+ }
172
+ /**
173
+ * Set an HTTP header for the request.
174
+ *
175
+ * @category Database
176
+ */
177
+ setHeader(name, value) {
178
+ this.headers = new Headers(this.headers);
179
+ this.headers.set(name, value);
180
+ return this;
181
+ }
182
+ /**
183
+ * @category Database
184
+ *
185
+ * Configure retry behavior for this request.
186
+ *
187
+ * By default, retries are enabled for idempotent requests (GET, HEAD, OPTIONS)
188
+ * that fail with network errors or specific HTTP status codes (503, 520).
189
+ * Retries use exponential backoff (1s, 2s, 4s) with a maximum of 3 attempts.
190
+ *
191
+ * @param enabled - Whether to enable retries for this request
192
+ *
193
+ * @example
194
+ * ```ts
195
+ * // Disable retries for a specific query
196
+ * const { data, error } = await supabase
197
+ * .from('users')
198
+ * .select()
199
+ * .retry(false)
200
+ * ```
201
+ */
202
+ retry(enabled) {
203
+ this.retryEnabled = enabled;
204
+ return this;
205
+ }
206
+ then(onfulfilled, onrejected) {
207
+ var _this = this;
208
+ if (this.schema === void 0) ;
209
+ else if (["GET", "HEAD"].includes(this.method)) this.headers.set("Accept-Profile", this.schema);
210
+ else this.headers.set("Content-Profile", this.schema);
211
+ if (this.method !== "GET" && this.method !== "HEAD") this.headers.set("Content-Type", "application/json");
212
+ if (this.shouldStripNulls) {
213
+ const currentAccept = this.headers.get("Accept");
214
+ if (currentAccept === "application/vnd.pgrst.object+json") this.headers.set("Accept", "application/vnd.pgrst.object+json;nulls=stripped");
215
+ else if (!currentAccept || currentAccept === "application/json") this.headers.set("Accept", "application/vnd.pgrst.array+json;nulls=stripped");
216
+ }
217
+ const _fetch = this.fetch;
218
+ const executeWithRetry = async () => {
219
+ let attemptCount = 0;
220
+ while (true) {
221
+ const requestHeaders = new Headers(_this.headers);
222
+ if (attemptCount > 0) requestHeaders.set("X-Retry-Count", String(attemptCount));
223
+ let res$1;
224
+ try {
225
+ res$1 = await _fetch(_this.url.toString(), {
226
+ method: _this.method,
227
+ headers: requestHeaders,
228
+ body: JSON.stringify(_this.body, (_, value) => typeof value === "bigint" ? value.toString() : value),
229
+ signal: _this.signal
230
+ });
231
+ } catch (fetchError) {
232
+ if ((fetchError === null || fetchError === void 0 ? void 0 : fetchError.name) === "AbortError" || (fetchError === null || fetchError === void 0 ? void 0 : fetchError.code) === "ABORT_ERR") throw fetchError;
233
+ if (!RETRYABLE_METHODS.includes(_this.method)) throw fetchError;
234
+ if (_this.retryEnabled && attemptCount < DEFAULT_MAX_RETRIES) {
235
+ const delay = getRetryDelay(attemptCount);
236
+ attemptCount++;
237
+ await sleep(delay, _this.signal);
238
+ continue;
239
+ }
240
+ throw fetchError;
241
+ }
242
+ if (shouldRetry(_this.method, res$1.status, attemptCount, _this.retryEnabled)) {
243
+ var _res$headers$get, _res$headers;
244
+ const retryAfterHeader = (_res$headers$get = (_res$headers = res$1.headers) === null || _res$headers === void 0 ? void 0 : _res$headers.get("Retry-After")) !== null && _res$headers$get !== void 0 ? _res$headers$get : null;
245
+ const delay = retryAfterHeader !== null ? Math.max(0, parseInt(retryAfterHeader, 10) || 0) * 1e3 : getRetryDelay(attemptCount);
246
+ await res$1.text();
247
+ attemptCount++;
248
+ await sleep(delay, _this.signal);
249
+ continue;
250
+ }
251
+ return await _this.processResponse(res$1);
252
+ }
253
+ };
254
+ let res = executeWithRetry();
255
+ if (!this.shouldThrowOnError) res = res.catch((fetchError) => {
256
+ var _fetchError$name2;
257
+ let errorDetails = "";
258
+ let hint = "";
259
+ let code = "";
260
+ const cause = fetchError === null || fetchError === void 0 ? void 0 : fetchError.cause;
261
+ if (cause) {
262
+ var _cause$message, _cause$code, _fetchError$name, _cause$name;
263
+ const causeMessage = (_cause$message = cause === null || cause === void 0 ? void 0 : cause.message) !== null && _cause$message !== void 0 ? _cause$message : "";
264
+ const causeCode = (_cause$code = cause === null || cause === void 0 ? void 0 : cause.code) !== null && _cause$code !== void 0 ? _cause$code : "";
265
+ errorDetails = `${(_fetchError$name = fetchError === null || fetchError === void 0 ? void 0 : fetchError.name) !== null && _fetchError$name !== void 0 ? _fetchError$name : "FetchError"}: ${fetchError === null || fetchError === void 0 ? void 0 : fetchError.message}`;
266
+ errorDetails += `
267
+
268
+ Caused by: ${(_cause$name = cause === null || cause === void 0 ? void 0 : cause.name) !== null && _cause$name !== void 0 ? _cause$name : "Error"}: ${causeMessage}`;
269
+ if (causeCode) errorDetails += ` (${causeCode})`;
270
+ if (cause === null || cause === void 0 ? void 0 : cause.stack) errorDetails += `
271
+ ${cause.stack}`;
272
+ } else {
273
+ var _fetchError$stack;
274
+ errorDetails = (_fetchError$stack = fetchError === null || fetchError === void 0 ? void 0 : fetchError.stack) !== null && _fetchError$stack !== void 0 ? _fetchError$stack : "";
275
+ }
276
+ const urlLength = this.url.toString().length;
277
+ if ((fetchError === null || fetchError === void 0 ? void 0 : fetchError.name) === "AbortError" || (fetchError === null || fetchError === void 0 ? void 0 : fetchError.code) === "ABORT_ERR") {
278
+ code = "";
279
+ hint = "Request was aborted (timeout or manual cancellation)";
280
+ if (urlLength > this.urlLengthLimit) hint += `. Note: Your request URL is ${urlLength} characters, which may exceed server limits. If selecting many fields, consider using views. If filtering with large arrays (e.g., .in('id', [many IDs])), consider using an RPC function to pass values server-side.`;
281
+ } else if ((cause === null || cause === void 0 ? void 0 : cause.name) === "HeadersOverflowError" || (cause === null || cause === void 0 ? void 0 : cause.code) === "UND_ERR_HEADERS_OVERFLOW") {
282
+ code = "";
283
+ hint = "HTTP headers exceeded server limits (typically 16KB)";
284
+ if (urlLength > this.urlLengthLimit) hint += `. Your request URL is ${urlLength} characters. If selecting many fields, consider using views. If filtering with large arrays (e.g., .in('id', [200+ IDs])), consider using an RPC function instead.`;
285
+ }
286
+ return {
287
+ success: false,
288
+ error: {
289
+ message: `${(_fetchError$name2 = fetchError === null || fetchError === void 0 ? void 0 : fetchError.name) !== null && _fetchError$name2 !== void 0 ? _fetchError$name2 : "FetchError"}: ${fetchError === null || fetchError === void 0 ? void 0 : fetchError.message}`,
290
+ details: errorDetails,
291
+ hint,
292
+ code
293
+ },
294
+ data: null,
295
+ count: null,
296
+ status: 0,
297
+ statusText: ""
298
+ };
299
+ });
300
+ return res.then(onfulfilled, onrejected);
301
+ }
302
+ /**
303
+ * Process a fetch response and return the standardized postgrest response.
304
+ */
305
+ async processResponse(res) {
306
+ var _this2 = this;
307
+ let error = null;
308
+ let data = null;
309
+ let count = null;
310
+ let status = res.status;
311
+ let statusText = res.statusText;
312
+ if (res.ok) {
313
+ var _this$headers$get2, _res$headers$get2;
314
+ if (_this2.method !== "HEAD") {
315
+ var _this$headers$get;
316
+ const body = await res.text();
317
+ if (body === "") ;
318
+ else if (_this2.headers.get("Accept") === "text/csv") data = body;
319
+ else if (_this2.headers.get("Accept") && ((_this$headers$get = _this2.headers.get("Accept")) === null || _this$headers$get === void 0 ? void 0 : _this$headers$get.includes("application/vnd.pgrst.plan+text"))) data = body;
320
+ else data = JSON.parse(body);
321
+ }
322
+ const countHeader = (_this$headers$get2 = _this2.headers.get("Prefer")) === null || _this$headers$get2 === void 0 ? void 0 : _this$headers$get2.match(/count=(exact|planned|estimated)/);
323
+ const contentRange = (_res$headers$get2 = res.headers.get("content-range")) === null || _res$headers$get2 === void 0 ? void 0 : _res$headers$get2.split("/");
324
+ if (countHeader && contentRange && contentRange.length > 1) count = parseInt(contentRange[1]);
325
+ if (_this2.isMaybeSingle && Array.isArray(data)) if (data.length > 1) {
326
+ error = {
327
+ code: "PGRST116",
328
+ details: `Results contain ${data.length} rows, application/vnd.pgrst.object+json requires 1 row`,
329
+ hint: null,
330
+ message: "JSON object requested, multiple (or no) rows returned"
331
+ };
332
+ data = null;
333
+ count = null;
334
+ status = 406;
335
+ statusText = "Not Acceptable";
336
+ } else if (data.length === 1) data = data[0];
337
+ else data = null;
338
+ } else {
339
+ const body = await res.text();
340
+ try {
341
+ error = JSON.parse(body);
342
+ if (Array.isArray(error) && res.status === 404) {
343
+ data = [];
344
+ error = null;
345
+ status = 200;
346
+ statusText = "OK";
347
+ }
348
+ } catch (_unused) {
349
+ if (res.status === 404 && body === "") {
350
+ status = 204;
351
+ statusText = "No Content";
352
+ } else error = { message: body };
353
+ }
354
+ if (error && _this2.shouldThrowOnError) throw new PostgrestError(error);
355
+ }
356
+ return {
357
+ success: error === null,
358
+ error,
359
+ data,
360
+ count,
361
+ status,
362
+ statusText
363
+ };
364
+ }
365
+ /**
366
+ * Override the type of the returned `data`.
367
+ *
368
+ * @typeParam NewResult - The new result type to override with
369
+ * @deprecated Use overrideTypes<yourType, { merge: false }>() method at the end of your call chain instead
370
+ *
371
+ * @category Database
372
+ */
373
+ returns() {
374
+ return this;
375
+ }
376
+ /**
377
+ * Override the type of the returned `data` field in the response.
378
+ *
379
+ * @typeParam NewResult - The new type to cast the response data to
380
+ * @typeParam Options - Optional type configuration (defaults to { merge: true })
381
+ * @typeParam Options.merge - When true, merges the new type with existing return type. When false, replaces the existing types entirely (defaults to true)
382
+ * @example
383
+ * ```typescript
384
+ * // Merge with existing types (default behavior)
385
+ * const query = supabase
386
+ * .from('users')
387
+ * .select()
388
+ * .overrideTypes<{ custom_field: string }>()
389
+ *
390
+ * // Replace existing types completely
391
+ * const replaceQuery = supabase
392
+ * .from('users')
393
+ * .select()
394
+ * .overrideTypes<{ id: number; name: string }, { merge: false }>()
395
+ * ```
396
+ * @returns A PostgrestBuilder instance with the new type
397
+ *
398
+ * @category Database
399
+ * @subcategory Using modifiers
400
+ *
401
+ * @example Complete Override type of successful response
402
+ * ```ts
403
+ * const { data } = await supabase
404
+ * .from('countries')
405
+ * .select()
406
+ * .overrideTypes<Array<MyType>, { merge: false }>()
407
+ * ```
408
+ *
409
+ * @exampleResponse Complete Override type of successful response
410
+ * ```ts
411
+ * let x: typeof data // MyType[]
412
+ * ```
413
+ *
414
+ * @example Complete Override type of object response
415
+ * ```ts
416
+ * const { data } = await supabase
417
+ * .from('countries')
418
+ * .select()
419
+ * .maybeSingle()
420
+ * .overrideTypes<MyType, { merge: false }>()
421
+ * ```
422
+ *
423
+ * @exampleResponse Complete Override type of object response
424
+ * ```ts
425
+ * let x: typeof data // MyType | null
426
+ * ```
427
+ *
428
+ * @example Partial Override type of successful response
429
+ * ```ts
430
+ * const { data } = await supabase
431
+ * .from('countries')
432
+ * .select()
433
+ * .overrideTypes<Array<{ status: "A" | "B" }>>()
434
+ * ```
435
+ *
436
+ * @exampleResponse Partial Override type of successful response
437
+ * ```ts
438
+ * let x: typeof data // Array<CountryRowProperties & { status: "A" | "B" }>
439
+ * ```
440
+ *
441
+ * @example Partial Override type of object response
442
+ * ```ts
443
+ * const { data } = await supabase
444
+ * .from('countries')
445
+ * .select()
446
+ * .maybeSingle()
447
+ * .overrideTypes<{ status: "A" | "B" }>()
448
+ * ```
449
+ *
450
+ * @exampleResponse Partial Override type of object response
451
+ * ```ts
452
+ * let x: typeof data // CountryRowProperties & { status: "A" | "B" } | null
453
+ * ```
454
+ *
455
+ * @example Merge vs replace existing types
456
+ * ```typescript
457
+ * // Merge with existing types (default behavior)
458
+ * const query = supabase
459
+ * .from('users')
460
+ * .select()
461
+ * .overrideTypes<{ custom_field: string }>()
462
+ *
463
+ * // Replace existing types completely
464
+ * const replaceQuery = supabase
465
+ * .from('users')
466
+ * .select()
467
+ * .overrideTypes<{ id: number; name: string }, { merge: false }>()
468
+ * ```
469
+ */
470
+ overrideTypes() {
471
+ return this;
472
+ }
473
+ };
474
+ var PostgrestTransformBuilder = class extends PostgrestBuilder {
475
+ /**
476
+ * Perform a SELECT on the query result.
477
+ *
478
+ * By default, `.insert()`, `.update()`, `.upsert()`, and `.delete()` do not
479
+ * return modified rows. By calling this method, modified rows are returned in
480
+ * `data`.
481
+ *
482
+ * @param columns - The columns to retrieve, separated by commas
483
+ *
484
+ * @category Database
485
+ * @subcategory Using modifiers
486
+ *
487
+ * @example With `upsert()`
488
+ * ```ts
489
+ * const { data, error } = await supabase
490
+ * .from('characters')
491
+ * .upsert({ id: 1, name: 'Han Solo' })
492
+ * .select()
493
+ * ```
494
+ *
495
+ * @exampleSql With `upsert()`
496
+ * ```sql
497
+ * create table
498
+ * characters (id int8 primary key, name text);
499
+ *
500
+ * insert into
501
+ * characters (id, name)
502
+ * values
503
+ * (1, 'Han');
504
+ * ```
505
+ *
506
+ * @exampleResponse With `upsert()`
507
+ * ```json
508
+ * {
509
+ * "data": [
510
+ * {
511
+ * "id": 1,
512
+ * "name": "Han Solo"
513
+ * }
514
+ * ],
515
+ * "status": 201,
516
+ * "statusText": "Created"
517
+ * }
518
+ * ```
519
+ */
520
+ select(columns) {
521
+ let quoted = false;
522
+ const cleanedColumns = (columns !== null && columns !== void 0 ? columns : "*").split("").map((c) => {
523
+ if (/\s/.test(c) && !quoted) return "";
524
+ if (c === '"') quoted = !quoted;
525
+ return c;
526
+ }).join("");
527
+ this.url.searchParams.set("select", cleanedColumns);
528
+ this.headers.append("Prefer", "return=representation");
529
+ return this;
530
+ }
531
+ /**
532
+ * Order the query result by `column`.
533
+ *
534
+ * You can call this method multiple times to order by multiple columns.
535
+ *
536
+ * You can order referenced tables, but it only affects the ordering of the
537
+ * parent table if you use `!inner` in the query.
538
+ *
539
+ * @param column - The column to order by
540
+ * @param options - Named parameters
541
+ * @param options.ascending - If `true`, the result will be in ascending order
542
+ * @param options.nullsFirst - If `true`, `null`s appear first. If `false`,
543
+ * `null`s appear last.
544
+ * @param options.referencedTable - Set this to order a referenced table by
545
+ * its columns
546
+ * @param options.foreignTable - Deprecated, use `options.referencedTable`
547
+ * instead
548
+ *
549
+ * @category Database
550
+ * @subcategory Using modifiers
551
+ *
552
+ * @example With `select()`
553
+ * ```ts
554
+ * const { data, error } = await supabase
555
+ * .from('characters')
556
+ * .select('id, name')
557
+ * .order('id', { ascending: false })
558
+ * ```
559
+ *
560
+ * @exampleSql With `select()`
561
+ * ```sql
562
+ * create table
563
+ * characters (id int8 primary key, name text);
564
+ *
565
+ * insert into
566
+ * characters (id, name)
567
+ * values
568
+ * (1, 'Luke'),
569
+ * (2, 'Leia'),
570
+ * (3, 'Han');
571
+ * ```
572
+ *
573
+ * @exampleResponse With `select()`
574
+ * ```json
575
+ * {
576
+ * "data": [
577
+ * {
578
+ * "id": 3,
579
+ * "name": "Han"
580
+ * },
581
+ * {
582
+ * "id": 2,
583
+ * "name": "Leia"
584
+ * },
585
+ * {
586
+ * "id": 1,
587
+ * "name": "Luke"
588
+ * }
589
+ * ],
590
+ * "status": 200,
591
+ * "statusText": "OK"
592
+ * }
593
+ * ```
594
+ *
595
+ * @exampleDescription On a referenced table
596
+ * Ordering with `referencedTable` doesn't affect the ordering of the
597
+ * parent table.
598
+ *
599
+ * @example On a referenced table
600
+ * ```ts
601
+ * const { data, error } = await supabase
602
+ * .from('orchestral_sections')
603
+ * .select(`
604
+ * name,
605
+ * instruments (
606
+ * name
607
+ * )
608
+ * `)
609
+ * .order('name', { referencedTable: 'instruments', ascending: false })
610
+ *
611
+ * ```
612
+ *
613
+ * @exampleSql On a referenced table
614
+ * ```sql
615
+ * create table
616
+ * orchestral_sections (id int8 primary key, name text);
617
+ * create table
618
+ * instruments (
619
+ * id int8 primary key,
620
+ * section_id int8 not null references orchestral_sections,
621
+ * name text
622
+ * );
623
+ *
624
+ * insert into
625
+ * orchestral_sections (id, name)
626
+ * values
627
+ * (1, 'strings'),
628
+ * (2, 'woodwinds');
629
+ * insert into
630
+ * instruments (id, section_id, name)
631
+ * values
632
+ * (1, 1, 'harp'),
633
+ * (2, 1, 'violin');
634
+ * ```
635
+ *
636
+ * @exampleResponse On a referenced table
637
+ * ```json
638
+ * {
639
+ * "data": [
640
+ * {
641
+ * "name": "strings",
642
+ * "instruments": [
643
+ * {
644
+ * "name": "violin"
645
+ * },
646
+ * {
647
+ * "name": "harp"
648
+ * }
649
+ * ]
650
+ * },
651
+ * {
652
+ * "name": "woodwinds",
653
+ * "instruments": []
654
+ * }
655
+ * ],
656
+ * "status": 200,
657
+ * "statusText": "OK"
658
+ * }
659
+ * ```
660
+ *
661
+ * @exampleDescription Order parent table by a referenced table
662
+ * Ordering with `referenced_table(col)` affects the ordering of the
663
+ * parent table.
664
+ *
665
+ * @example Order parent table by a referenced table
666
+ * ```ts
667
+ * const { data, error } = await supabase
668
+ * .from('instruments')
669
+ * .select(`
670
+ * name,
671
+ * section:orchestral_sections (
672
+ * name
673
+ * )
674
+ * `)
675
+ * .order('section(name)', { ascending: true })
676
+ *
677
+ * ```
678
+ *
679
+ * @exampleSql Order parent table by a referenced table
680
+ * ```sql
681
+ * create table
682
+ * orchestral_sections (id int8 primary key, name text);
683
+ * create table
684
+ * instruments (
685
+ * id int8 primary key,
686
+ * section_id int8 not null references orchestral_sections,
687
+ * name text
688
+ * );
689
+ *
690
+ * insert into
691
+ * orchestral_sections (id, name)
692
+ * values
693
+ * (1, 'strings'),
694
+ * (2, 'woodwinds');
695
+ * insert into
696
+ * instruments (id, section_id, name)
697
+ * values
698
+ * (1, 2, 'flute'),
699
+ * (2, 1, 'violin');
700
+ * ```
701
+ *
702
+ * @exampleResponse Order parent table by a referenced table
703
+ * ```json
704
+ * {
705
+ * "data": [
706
+ * {
707
+ * "name": "violin",
708
+ * "orchestral_sections": {"name": "strings"}
709
+ * },
710
+ * {
711
+ * "name": "flute",
712
+ * "orchestral_sections": {"name": "woodwinds"}
713
+ * }
714
+ * ],
715
+ * "status": 200,
716
+ * "statusText": "OK"
717
+ * }
718
+ * ```
719
+ */
720
+ order(column, { ascending = true, nullsFirst, foreignTable, referencedTable = foreignTable } = {}) {
721
+ const key = referencedTable ? `${referencedTable}.order` : "order";
722
+ const existingOrder = this.url.searchParams.get(key);
723
+ this.url.searchParams.set(key, `${existingOrder ? `${existingOrder},` : ""}${column}.${ascending ? "asc" : "desc"}${nullsFirst === void 0 ? "" : nullsFirst ? ".nullsfirst" : ".nullslast"}`);
724
+ return this;
725
+ }
726
+ /**
727
+ * Limit the query result by `count`.
728
+ *
729
+ * @param count - The maximum number of rows to return
730
+ * @param options - Named parameters
731
+ * @param options.referencedTable - Set this to limit rows of referenced
732
+ * tables instead of the parent table
733
+ * @param options.foreignTable - Deprecated, use `options.referencedTable`
734
+ * instead
735
+ *
736
+ * @category Database
737
+ * @subcategory Using modifiers
738
+ *
739
+ * @example With `select()`
740
+ * ```ts
741
+ * const { data, error } = await supabase
742
+ * .from('characters')
743
+ * .select('name')
744
+ * .limit(1)
745
+ * ```
746
+ *
747
+ * @exampleSql With `select()`
748
+ * ```sql
749
+ * create table
750
+ * characters (id int8 primary key, name text);
751
+ *
752
+ * insert into
753
+ * characters (id, name)
754
+ * values
755
+ * (1, 'Luke'),
756
+ * (2, 'Leia'),
757
+ * (3, 'Han');
758
+ * ```
759
+ *
760
+ * @exampleResponse With `select()`
761
+ * ```json
762
+ * {
763
+ * "data": [
764
+ * {
765
+ * "name": "Luke"
766
+ * }
767
+ * ],
768
+ * "status": 200,
769
+ * "statusText": "OK"
770
+ * }
771
+ * ```
772
+ *
773
+ * @example On a referenced table
774
+ * ```ts
775
+ * const { data, error } = await supabase
776
+ * .from('orchestral_sections')
777
+ * .select(`
778
+ * name,
779
+ * instruments (
780
+ * name
781
+ * )
782
+ * `)
783
+ * .limit(1, { referencedTable: 'instruments' })
784
+ * ```
785
+ *
786
+ * @exampleSql On a referenced table
787
+ * ```sql
788
+ * create table
789
+ * orchestral_sections (id int8 primary key, name text);
790
+ * create table
791
+ * instruments (
792
+ * id int8 primary key,
793
+ * section_id int8 not null references orchestral_sections,
794
+ * name text
795
+ * );
796
+ *
797
+ * insert into
798
+ * orchestral_sections (id, name)
799
+ * values
800
+ * (1, 'strings');
801
+ * insert into
802
+ * instruments (id, section_id, name)
803
+ * values
804
+ * (1, 1, 'harp'),
805
+ * (2, 1, 'violin');
806
+ * ```
807
+ *
808
+ * @exampleResponse On a referenced table
809
+ * ```json
810
+ * {
811
+ * "data": [
812
+ * {
813
+ * "name": "strings",
814
+ * "instruments": [
815
+ * {
816
+ * "name": "violin"
817
+ * }
818
+ * ]
819
+ * }
820
+ * ],
821
+ * "status": 200,
822
+ * "statusText": "OK"
823
+ * }
824
+ * ```
825
+ */
826
+ limit(count, { foreignTable, referencedTable = foreignTable } = {}) {
827
+ const key = typeof referencedTable === "undefined" ? "limit" : `${referencedTable}.limit`;
828
+ this.url.searchParams.set(key, `${count}`);
829
+ return this;
830
+ }
831
+ /**
832
+ * Limit the query result by starting at an offset `from` and ending at the offset `to`.
833
+ * Only records within this range are returned.
834
+ * This respects the query order and if there is no order clause the range could behave unexpectedly.
835
+ * The `from` and `to` values are 0-based and inclusive: `range(1, 3)` will include the second, third
836
+ * and fourth rows of the query.
837
+ *
838
+ * @param from - The starting index from which to limit the result
839
+ * @param to - The last index to which to limit the result
840
+ * @param options - Named parameters
841
+ * @param options.referencedTable - Set this to limit rows of referenced
842
+ * tables instead of the parent table
843
+ * @param options.foreignTable - Deprecated, use `options.referencedTable`
844
+ * instead
845
+ *
846
+ * @category Database
847
+ * @subcategory Using modifiers
848
+ *
849
+ * @example With `select()`
850
+ * ```ts
851
+ * const { data, error } = await supabase
852
+ * .from('characters')
853
+ * .select('name')
854
+ * .range(0, 1)
855
+ * ```
856
+ *
857
+ * @exampleSql With `select()`
858
+ * ```sql
859
+ * create table
860
+ * characters (id int8 primary key, name text);
861
+ *
862
+ * insert into
863
+ * characters (id, name)
864
+ * values
865
+ * (1, 'Luke'),
866
+ * (2, 'Leia'),
867
+ * (3, 'Han');
868
+ * ```
869
+ *
870
+ * @exampleResponse With `select()`
871
+ * ```json
872
+ * {
873
+ * "data": [
874
+ * {
875
+ * "name": "Luke"
876
+ * },
877
+ * {
878
+ * "name": "Leia"
879
+ * }
880
+ * ],
881
+ * "status": 200,
882
+ * "statusText": "OK"
883
+ * }
884
+ * ```
885
+ */
886
+ range(from, to, { foreignTable, referencedTable = foreignTable } = {}) {
887
+ const keyOffset = typeof referencedTable === "undefined" ? "offset" : `${referencedTable}.offset`;
888
+ const keyLimit = typeof referencedTable === "undefined" ? "limit" : `${referencedTable}.limit`;
889
+ this.url.searchParams.set(keyOffset, `${from}`);
890
+ this.url.searchParams.set(keyLimit, `${to - from + 1}`);
891
+ return this;
892
+ }
893
+ /**
894
+ * Set the AbortSignal for the fetch request.
895
+ *
896
+ * @param signal - The AbortSignal to use for the fetch request
897
+ *
898
+ * @category Database
899
+ * @subcategory Using modifiers
900
+ *
901
+ * @remarks
902
+ * You can use this to set a timeout for the request.
903
+ *
904
+ * @exampleDescription Aborting requests in-flight
905
+ * You can use an [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) to abort requests.
906
+ * Note that `status` and `statusText` don't mean anything for aborted requests as the request wasn't fulfilled.
907
+ *
908
+ * @example Aborting requests in-flight
909
+ * ```ts
910
+ * const ac = new AbortController()
911
+ *
912
+ * const { data, error } = await supabase
913
+ * .from('very_big_table')
914
+ * .select()
915
+ * .abortSignal(ac.signal)
916
+ *
917
+ * // Abort the request after 100 ms
918
+ * setTimeout(() => ac.abort(), 100)
919
+ * ```
920
+ *
921
+ * @exampleResponse Aborting requests in-flight
922
+ * ```json
923
+ * {
924
+ * "error": {
925
+ * "message": "AbortError: The user aborted a request.",
926
+ * "details": "",
927
+ * "hint": "The request was aborted locally via the provided AbortSignal.",
928
+ * "code": ""
929
+ * },
930
+ * "status": 0,
931
+ * "statusText": ""
932
+ * }
933
+ *
934
+ * ```
935
+ *
936
+ * @example Set a timeout
937
+ * ```ts
938
+ * const { data, error } = await supabase
939
+ * .from('very_big_table')
940
+ * .select()
941
+ * .abortSignal(AbortSignal.timeout(1000 /* ms *\/))
942
+ * ```
943
+ *
944
+ * @exampleResponse Set a timeout
945
+ * ```json
946
+ * {
947
+ * "error": {
948
+ * "message": "FetchError: The user aborted a request.",
949
+ * "details": "",
950
+ * "hint": "",
951
+ * "code": ""
952
+ * },
953
+ * "status": 400,
954
+ * "statusText": "Bad Request"
955
+ * }
956
+ *
957
+ * ```
958
+ */
959
+ abortSignal(signal) {
960
+ this.signal = signal;
961
+ return this;
962
+ }
963
+ /**
964
+ * Return `data` as a single object instead of an array of objects.
965
+ *
966
+ * Query result must be one row (e.g. using `.limit(1)`), otherwise this
967
+ * returns an error.
968
+ *
969
+ * @category Database
970
+ * @subcategory Using modifiers
971
+ *
972
+ * @example With `select()`
973
+ * ```ts
974
+ * const { data, error } = await supabase
975
+ * .from('characters')
976
+ * .select('name')
977
+ * .limit(1)
978
+ * .single()
979
+ * ```
980
+ *
981
+ * @exampleSql With `select()`
982
+ * ```sql
983
+ * create table
984
+ * characters (id int8 primary key, name text);
985
+ *
986
+ * insert into
987
+ * characters (id, name)
988
+ * values
989
+ * (1, 'Luke'),
990
+ * (2, 'Leia'),
991
+ * (3, 'Han');
992
+ * ```
993
+ *
994
+ * @exampleResponse With `select()`
995
+ * ```json
996
+ * {
997
+ * "data": {
998
+ * "name": "Luke"
999
+ * },
1000
+ * "status": 200,
1001
+ * "statusText": "OK"
1002
+ * }
1003
+ * ```
1004
+ */
1005
+ single() {
1006
+ this.headers.set("Accept", "application/vnd.pgrst.object+json");
1007
+ return this;
1008
+ }
1009
+ /**
1010
+ * Return `data` as a single object instead of an array of objects.
1011
+ *
1012
+ * Query result must be zero or one row (e.g. using `.limit(1)`), otherwise
1013
+ * this returns an error.
1014
+ *
1015
+ * @category Database
1016
+ * @subcategory Using modifiers
1017
+ *
1018
+ * @example With `select()`
1019
+ * ```ts
1020
+ * const { data, error } = await supabase
1021
+ * .from('characters')
1022
+ * .select()
1023
+ * .eq('name', 'Katniss')
1024
+ * .maybeSingle()
1025
+ * ```
1026
+ *
1027
+ * @exampleSql With `select()`
1028
+ * ```sql
1029
+ * create table
1030
+ * characters (id int8 primary key, name text);
1031
+ *
1032
+ * insert into
1033
+ * characters (id, name)
1034
+ * values
1035
+ * (1, 'Luke'),
1036
+ * (2, 'Leia'),
1037
+ * (3, 'Han');
1038
+ * ```
1039
+ *
1040
+ * @exampleResponse With `select()`
1041
+ * ```json
1042
+ * {
1043
+ * "status": 200,
1044
+ * "statusText": "OK"
1045
+ * }
1046
+ * ```
1047
+ */
1048
+ maybeSingle() {
1049
+ this.isMaybeSingle = true;
1050
+ return this;
1051
+ }
1052
+ /**
1053
+ * Return `data` as a string in CSV format.
1054
+ *
1055
+ * @category Database
1056
+ * @subcategory Using modifiers
1057
+ *
1058
+ * @exampleDescription Return data as CSV
1059
+ * By default, the data is returned in JSON format, but can also be returned as Comma Separated Values.
1060
+ *
1061
+ * @example Return data as CSV
1062
+ * ```ts
1063
+ * const { data, error } = await supabase
1064
+ * .from('characters')
1065
+ * .select()
1066
+ * .csv()
1067
+ * ```
1068
+ *
1069
+ * @exampleSql Return data as CSV
1070
+ * ```sql
1071
+ * create table
1072
+ * characters (id int8 primary key, name text);
1073
+ *
1074
+ * insert into
1075
+ * characters (id, name)
1076
+ * values
1077
+ * (1, 'Luke'),
1078
+ * (2, 'Leia'),
1079
+ * (3, 'Han');
1080
+ * ```
1081
+ *
1082
+ * @exampleResponse Return data as CSV
1083
+ * ```json
1084
+ * {
1085
+ * "data": "id,name\n1,Luke\n2,Leia\n3,Han",
1086
+ * "status": 200,
1087
+ * "statusText": "OK"
1088
+ * }
1089
+ * ```
1090
+ */
1091
+ csv() {
1092
+ this.headers.set("Accept", "text/csv");
1093
+ return this;
1094
+ }
1095
+ /**
1096
+ * Return `data` as an object in [GeoJSON](https://geojson.org) format.
1097
+ *
1098
+ * @category Database
1099
+ */
1100
+ geojson() {
1101
+ this.headers.set("Accept", "application/geo+json");
1102
+ return this;
1103
+ }
1104
+ /**
1105
+ * Return `data` as the EXPLAIN plan for the query.
1106
+ *
1107
+ * You need to enable the
1108
+ * [db_plan_enabled](https://supabase.com/docs/guides/database/debugging-performance#enabling-explain)
1109
+ * setting before using this method.
1110
+ *
1111
+ * @param options - Named parameters
1112
+ *
1113
+ * @param options.analyze - If `true`, the query will be executed and the
1114
+ * actual run time will be returned
1115
+ *
1116
+ * @param options.verbose - If `true`, the query identifier will be returned
1117
+ * and `data` will include the output columns of the query
1118
+ *
1119
+ * @param options.settings - If `true`, include information on configuration
1120
+ * parameters that affect query planning
1121
+ *
1122
+ * @param options.buffers - If `true`, include information on buffer usage
1123
+ *
1124
+ * @param options.wal - If `true`, include information on WAL record generation
1125
+ *
1126
+ * @param options.format - The format of the output, can be `"text"` (default)
1127
+ * or `"json"`
1128
+ *
1129
+ * @category Database
1130
+ * @subcategory Using modifiers
1131
+ *
1132
+ * @exampleDescription Get the execution plan
1133
+ * By default, the data is returned in TEXT format, but can also be returned as JSON by using the `format` parameter.
1134
+ *
1135
+ * @example Get the execution plan
1136
+ * ```ts
1137
+ * const { data, error } = await supabase
1138
+ * .from('characters')
1139
+ * .select()
1140
+ * .explain()
1141
+ * ```
1142
+ *
1143
+ * @exampleSql Get the execution plan
1144
+ * ```sql
1145
+ * create table
1146
+ * characters (id int8 primary key, name text);
1147
+ *
1148
+ * insert into
1149
+ * characters (id, name)
1150
+ * values
1151
+ * (1, 'Luke'),
1152
+ * (2, 'Leia'),
1153
+ * (3, 'Han');
1154
+ * ```
1155
+ *
1156
+ * @exampleResponse Get the execution plan
1157
+ * ```js
1158
+ * Aggregate (cost=33.34..33.36 rows=1 width=112)
1159
+ * -> Limit (cost=0.00..18.33 rows=1000 width=40)
1160
+ * -> Seq Scan on characters (cost=0.00..22.00 rows=1200 width=40)
1161
+ * ```
1162
+ *
1163
+ * @exampleDescription Get the execution plan with analyze and verbose
1164
+ * By default, the data is returned in TEXT format, but can also be returned as JSON by using the `format` parameter.
1165
+ *
1166
+ * @example Get the execution plan with analyze and verbose
1167
+ * ```ts
1168
+ * const { data, error } = await supabase
1169
+ * .from('characters')
1170
+ * .select()
1171
+ * .explain({analyze:true,verbose:true})
1172
+ * ```
1173
+ *
1174
+ * @exampleSql Get the execution plan with analyze and verbose
1175
+ * ```sql
1176
+ * create table
1177
+ * characters (id int8 primary key, name text);
1178
+ *
1179
+ * insert into
1180
+ * characters (id, name)
1181
+ * values
1182
+ * (1, 'Luke'),
1183
+ * (2, 'Leia'),
1184
+ * (3, 'Han');
1185
+ * ```
1186
+ *
1187
+ * @exampleResponse Get the execution plan with analyze and verbose
1188
+ * ```js
1189
+ * Aggregate (cost=33.34..33.36 rows=1 width=112) (actual time=0.041..0.041 rows=1 loops=1)
1190
+ * Output: NULL::bigint, count(ROW(characters.id, characters.name)), COALESCE(json_agg(ROW(characters.id, characters.name)), '[]'::json), NULLIF(current_setting('response.headers'::text, true), ''::text), NULLIF(current_setting('response.status'::text, true), ''::text)
1191
+ * -> Limit (cost=0.00..18.33 rows=1000 width=40) (actual time=0.005..0.006 rows=3 loops=1)
1192
+ * Output: characters.id, characters.name
1193
+ * -> Seq Scan on public.characters (cost=0.00..22.00 rows=1200 width=40) (actual time=0.004..0.005 rows=3 loops=1)
1194
+ * Output: characters.id, characters.name
1195
+ * Query Identifier: -4730654291623321173
1196
+ * Planning Time: 0.407 ms
1197
+ * Execution Time: 0.119 ms
1198
+ * ```
1199
+ */
1200
+ explain({ analyze = false, verbose = false, settings = false, buffers = false, wal = false, format = "text" } = {}) {
1201
+ var _this$headers$get;
1202
+ const options = [
1203
+ analyze ? "analyze" : null,
1204
+ verbose ? "verbose" : null,
1205
+ settings ? "settings" : null,
1206
+ buffers ? "buffers" : null,
1207
+ wal ? "wal" : null
1208
+ ].filter(Boolean).join("|");
1209
+ const forMediatype = (_this$headers$get = this.headers.get("Accept")) !== null && _this$headers$get !== void 0 ? _this$headers$get : "application/json";
1210
+ this.headers.set("Accept", `application/vnd.pgrst.plan+${format}; for="${forMediatype}"; options=${options};`);
1211
+ if (format === "json") return this;
1212
+ else return this;
1213
+ }
1214
+ /**
1215
+ * Rollback the query.
1216
+ *
1217
+ * `data` will still be returned, but the query is not committed.
1218
+ *
1219
+ * @category Database
1220
+ */
1221
+ rollback() {
1222
+ this.headers.append("Prefer", "tx=rollback");
1223
+ return this;
1224
+ }
1225
+ /**
1226
+ * Override the type of the returned `data`.
1227
+ *
1228
+ * @typeParam NewResult - The new result type to override with
1229
+ * @deprecated Use overrideTypes<yourType, { merge: false }>() method at the end of your call chain instead
1230
+ *
1231
+ * @category Database
1232
+ * @subcategory Using modifiers
1233
+ *
1234
+ * @remarks
1235
+ * - Deprecated: use overrideTypes method instead
1236
+ *
1237
+ * @example Override type of successful response
1238
+ * ```ts
1239
+ * const { data } = await supabase
1240
+ * .from('countries')
1241
+ * .select()
1242
+ * .returns<Array<MyType>>()
1243
+ * ```
1244
+ *
1245
+ * @exampleResponse Override type of successful response
1246
+ * ```js
1247
+ * let x: typeof data // MyType[]
1248
+ * ```
1249
+ *
1250
+ * @example Override type of object response
1251
+ * ```ts
1252
+ * const { data } = await supabase
1253
+ * .from('countries')
1254
+ * .select()
1255
+ * .maybeSingle()
1256
+ * .returns<MyType>()
1257
+ * ```
1258
+ *
1259
+ * @exampleResponse Override type of object response
1260
+ * ```js
1261
+ * let x: typeof data // MyType | null
1262
+ * ```
1263
+ */
1264
+ returns() {
1265
+ return this;
1266
+ }
1267
+ /**
1268
+ * Set the maximum number of rows that can be affected by the query.
1269
+ * Only available in PostgREST v13+ and only works with PATCH and DELETE methods.
1270
+ *
1271
+ * @param value - The maximum number of rows that can be affected
1272
+ *
1273
+ * @category Database
1274
+ */
1275
+ maxAffected(value) {
1276
+ this.headers.append("Prefer", "handling=strict");
1277
+ this.headers.append("Prefer", `max-affected=${value}`);
1278
+ return this;
1279
+ }
1280
+ };
1281
+ const PostgrestReservedCharsRegexp = /* @__PURE__ */ new RegExp("[,()]");
1282
+ var PostgrestFilterBuilder = class extends PostgrestTransformBuilder {
1283
+ /**
1284
+ * Match only rows where `column` is equal to `value`.
1285
+ *
1286
+ * To check if the value of `column` is NULL, you should use `.is()` instead.
1287
+ *
1288
+ * @param column - The column to filter on
1289
+ * @param value - The value to filter with
1290
+ *
1291
+ * @category Database
1292
+ * @subcategory Using filters
1293
+ *
1294
+ * @example With `select()`
1295
+ * ```ts
1296
+ * const { data, error } = await supabase
1297
+ * .from('characters')
1298
+ * .select()
1299
+ * .eq('name', 'Leia')
1300
+ * ```
1301
+ *
1302
+ * @exampleSql With `select()`
1303
+ * ```sql
1304
+ * create table
1305
+ * characters (id int8 primary key, name text);
1306
+ *
1307
+ * insert into
1308
+ * characters (id, name)
1309
+ * values
1310
+ * (1, 'Luke'),
1311
+ * (2, 'Leia'),
1312
+ * (3, 'Han');
1313
+ * ```
1314
+ *
1315
+ * @exampleResponse With `select()`
1316
+ * ```json
1317
+ * {
1318
+ * "data": [
1319
+ * {
1320
+ * "id": 2,
1321
+ * "name": "Leia"
1322
+ * }
1323
+ * ],
1324
+ * "status": 200,
1325
+ * "statusText": "OK"
1326
+ * }
1327
+ * ```
1328
+ */
1329
+ eq(column, value) {
1330
+ this.url.searchParams.append(column, `eq.${value}`);
1331
+ return this;
1332
+ }
1333
+ /**
1334
+ * Match only rows where `column` is not equal to `value`.
1335
+ *
1336
+ * This filter does not include rows where `column` is `NULL`. To match null
1337
+ * values, use `.is(column, null)` instead.
1338
+ *
1339
+ * @param column - The column to filter on
1340
+ * @param value - The value to filter with
1341
+ *
1342
+ * @category Database
1343
+ * @subcategory Using filters
1344
+ *
1345
+ * @example With `select()`
1346
+ * ```ts
1347
+ * const { data, error } = await supabase
1348
+ * .from('characters')
1349
+ * .select()
1350
+ * .neq('name', 'Leia')
1351
+ * ```
1352
+ *
1353
+ * @exampleSql With `select()`
1354
+ * ```sql
1355
+ * create table
1356
+ * characters (id int8 primary key, name text);
1357
+ *
1358
+ * insert into
1359
+ * characters (id, name)
1360
+ * values
1361
+ * (1, 'Luke'),
1362
+ * (2, 'Leia'),
1363
+ * (3, 'Han');
1364
+ * ```
1365
+ *
1366
+ * @exampleResponse With `select()`
1367
+ * ```json
1368
+ * {
1369
+ * "data": [
1370
+ * {
1371
+ * "id": 1,
1372
+ * "name": "Luke"
1373
+ * },
1374
+ * {
1375
+ * "id": 3,
1376
+ * "name": "Han"
1377
+ * }
1378
+ * ],
1379
+ * "status": 200,
1380
+ * "statusText": "OK"
1381
+ * }
1382
+ * ```
1383
+ */
1384
+ neq(column, value) {
1385
+ this.url.searchParams.append(column, `neq.${value}`);
1386
+ return this;
1387
+ }
1388
+ /**
1389
+ * Match only rows where `column` is greater than `value`.
1390
+ *
1391
+ * @param column - The column to filter on
1392
+ * @param value - The value to filter with
1393
+ *
1394
+ * @category Database
1395
+ * @subcategory Using filters
1396
+ *
1397
+ * @exampleDescription With `select()`
1398
+ * When using [reserved words](https://www.postgresql.org/docs/current/sql-keywords-appendix.html) for column names you need
1399
+ * to add double quotes e.g. `.gt('"order"', 2)`
1400
+ *
1401
+ * @example With `select()`
1402
+ * ```ts
1403
+ * const { data, error } = await supabase
1404
+ * .from('characters')
1405
+ * .select()
1406
+ * .gt('id', 2)
1407
+ * ```
1408
+ *
1409
+ * @exampleSql With `select()`
1410
+ * ```sql
1411
+ * create table
1412
+ * characters (id int8 primary key, name text);
1413
+ *
1414
+ * insert into
1415
+ * characters (id, name)
1416
+ * values
1417
+ * (1, 'Luke'),
1418
+ * (2, 'Leia'),
1419
+ * (3, 'Han');
1420
+ * ```
1421
+ *
1422
+ * @exampleResponse With `select()`
1423
+ * ```json
1424
+ * {
1425
+ * "data": [
1426
+ * {
1427
+ * "id": 3,
1428
+ * "name": "Han"
1429
+ * }
1430
+ * ],
1431
+ * "status": 200,
1432
+ * "statusText": "OK"
1433
+ * }
1434
+ * ```
1435
+ */
1436
+ gt(column, value) {
1437
+ this.url.searchParams.append(column, `gt.${value}`);
1438
+ return this;
1439
+ }
1440
+ /**
1441
+ * Match only rows where `column` is greater than or equal to `value`.
1442
+ *
1443
+ * @param column - The column to filter on
1444
+ * @param value - The value to filter with
1445
+ *
1446
+ * @category Database
1447
+ * @subcategory Using filters
1448
+ *
1449
+ * @example With `select()`
1450
+ * ```ts
1451
+ * const { data, error } = await supabase
1452
+ * .from('characters')
1453
+ * .select()
1454
+ * .gte('id', 2)
1455
+ * ```
1456
+ *
1457
+ * @exampleSql With `select()`
1458
+ * ```sql
1459
+ * create table
1460
+ * characters (id int8 primary key, name text);
1461
+ *
1462
+ * insert into
1463
+ * characters (id, name)
1464
+ * values
1465
+ * (1, 'Luke'),
1466
+ * (2, 'Leia'),
1467
+ * (3, 'Han');
1468
+ * ```
1469
+ *
1470
+ * @exampleResponse With `select()`
1471
+ * ```json
1472
+ * {
1473
+ * "data": [
1474
+ * {
1475
+ * "id": 2,
1476
+ * "name": "Leia"
1477
+ * },
1478
+ * {
1479
+ * "id": 3,
1480
+ * "name": "Han"
1481
+ * }
1482
+ * ],
1483
+ * "status": 200,
1484
+ * "statusText": "OK"
1485
+ * }
1486
+ * ```
1487
+ */
1488
+ gte(column, value) {
1489
+ this.url.searchParams.append(column, `gte.${value}`);
1490
+ return this;
1491
+ }
1492
+ /**
1493
+ * Match only rows where `column` is less than `value`.
1494
+ *
1495
+ * @param column - The column to filter on
1496
+ * @param value - The value to filter with
1497
+ *
1498
+ * @category Database
1499
+ * @subcategory Using filters
1500
+ *
1501
+ * @example With `select()`
1502
+ * ```ts
1503
+ * const { data, error } = await supabase
1504
+ * .from('characters')
1505
+ * .select()
1506
+ * .lt('id', 2)
1507
+ * ```
1508
+ *
1509
+ * @exampleSql With `select()`
1510
+ * ```sql
1511
+ * create table
1512
+ * characters (id int8 primary key, name text);
1513
+ *
1514
+ * insert into
1515
+ * characters (id, name)
1516
+ * values
1517
+ * (1, 'Luke'),
1518
+ * (2, 'Leia'),
1519
+ * (3, 'Han');
1520
+ * ```
1521
+ *
1522
+ * @exampleResponse With `select()`
1523
+ * ```json
1524
+ * {
1525
+ * "data": [
1526
+ * {
1527
+ * "id": 1,
1528
+ * "name": "Luke"
1529
+ * }
1530
+ * ],
1531
+ * "status": 200,
1532
+ * "statusText": "OK"
1533
+ * }
1534
+ * ```
1535
+ */
1536
+ lt(column, value) {
1537
+ this.url.searchParams.append(column, `lt.${value}`);
1538
+ return this;
1539
+ }
1540
+ /**
1541
+ * Match only rows where `column` is less than or equal to `value`.
1542
+ *
1543
+ * @param column - The column to filter on
1544
+ * @param value - The value to filter with
1545
+ *
1546
+ * @category Database
1547
+ * @subcategory Using filters
1548
+ *
1549
+ * @example With `select()`
1550
+ * ```ts
1551
+ * const { data, error } = await supabase
1552
+ * .from('characters')
1553
+ * .select()
1554
+ * .lte('id', 2)
1555
+ * ```
1556
+ *
1557
+ * @exampleSql With `select()`
1558
+ * ```sql
1559
+ * create table
1560
+ * characters (id int8 primary key, name text);
1561
+ *
1562
+ * insert into
1563
+ * characters (id, name)
1564
+ * values
1565
+ * (1, 'Luke'),
1566
+ * (2, 'Leia'),
1567
+ * (3, 'Han');
1568
+ * ```
1569
+ *
1570
+ * @exampleResponse With `select()`
1571
+ * ```json
1572
+ * {
1573
+ * "data": [
1574
+ * {
1575
+ * "id": 1,
1576
+ * "name": "Luke"
1577
+ * },
1578
+ * {
1579
+ * "id": 2,
1580
+ * "name": "Leia"
1581
+ * }
1582
+ * ],
1583
+ * "status": 200,
1584
+ * "statusText": "OK"
1585
+ * }
1586
+ * ```
1587
+ */
1588
+ lte(column, value) {
1589
+ this.url.searchParams.append(column, `lte.${value}`);
1590
+ return this;
1591
+ }
1592
+ /**
1593
+ * Match only rows where `column` matches `pattern` case-sensitively.
1594
+ *
1595
+ * @param column - The column to filter on
1596
+ * @param pattern - The pattern to match with
1597
+ *
1598
+ * @category Database
1599
+ * @subcategory Using filters
1600
+ *
1601
+ * @example With `select()`
1602
+ * ```ts
1603
+ * const { data, error } = await supabase
1604
+ * .from('characters')
1605
+ * .select()
1606
+ * .like('name', '%Lu%')
1607
+ * ```
1608
+ *
1609
+ * @exampleSql With `select()`
1610
+ * ```sql
1611
+ * create table
1612
+ * characters (id int8 primary key, name text);
1613
+ *
1614
+ * insert into
1615
+ * characters (id, name)
1616
+ * values
1617
+ * (1, 'Luke'),
1618
+ * (2, 'Leia'),
1619
+ * (3, 'Han');
1620
+ * ```
1621
+ *
1622
+ * @exampleResponse With `select()`
1623
+ * ```json
1624
+ * {
1625
+ * "data": [
1626
+ * {
1627
+ * "id": 1,
1628
+ * "name": "Luke"
1629
+ * }
1630
+ * ],
1631
+ * "status": 200,
1632
+ * "statusText": "OK"
1633
+ * }
1634
+ * ```
1635
+ */
1636
+ like(column, pattern) {
1637
+ this.url.searchParams.append(column, `like.${pattern}`);
1638
+ return this;
1639
+ }
1640
+ /**
1641
+ * Match only rows where `column` matches all of `patterns` case-sensitively.
1642
+ *
1643
+ * @param column - The column to filter on
1644
+ * @param patterns - The patterns to match with
1645
+ *
1646
+ * @category Database
1647
+ * @subcategory Using filters
1648
+ */
1649
+ likeAllOf(column, patterns) {
1650
+ this.url.searchParams.append(column, `like(all).{${patterns.join(",")}}`);
1651
+ return this;
1652
+ }
1653
+ /**
1654
+ * Match only rows where `column` matches any of `patterns` case-sensitively.
1655
+ *
1656
+ * @param column - The column to filter on
1657
+ * @param patterns - The patterns to match with
1658
+ *
1659
+ * @category Database
1660
+ * @subcategory Using filters
1661
+ */
1662
+ likeAnyOf(column, patterns) {
1663
+ this.url.searchParams.append(column, `like(any).{${patterns.join(",")}}`);
1664
+ return this;
1665
+ }
1666
+ /**
1667
+ * Match only rows where `column` matches `pattern` case-insensitively.
1668
+ *
1669
+ * @param column - The column to filter on
1670
+ * @param pattern - The pattern to match with
1671
+ *
1672
+ * @category Database
1673
+ * @subcategory Using filters
1674
+ *
1675
+ * @example With `select()`
1676
+ * ```ts
1677
+ * const { data, error } = await supabase
1678
+ * .from('characters')
1679
+ * .select()
1680
+ * .ilike('name', '%lu%')
1681
+ * ```
1682
+ *
1683
+ * @exampleSql With `select()`
1684
+ * ```sql
1685
+ * create table
1686
+ * characters (id int8 primary key, name text);
1687
+ *
1688
+ * insert into
1689
+ * characters (id, name)
1690
+ * values
1691
+ * (1, 'Luke'),
1692
+ * (2, 'Leia'),
1693
+ * (3, 'Han');
1694
+ * ```
1695
+ *
1696
+ * @exampleResponse With `select()`
1697
+ * ```json
1698
+ * {
1699
+ * "data": [
1700
+ * {
1701
+ * "id": 1,
1702
+ * "name": "Luke"
1703
+ * }
1704
+ * ],
1705
+ * "status": 200,
1706
+ * "statusText": "OK"
1707
+ * }
1708
+ * ```
1709
+ */
1710
+ ilike(column, pattern) {
1711
+ this.url.searchParams.append(column, `ilike.${pattern}`);
1712
+ return this;
1713
+ }
1714
+ /**
1715
+ * Match only rows where `column` matches all of `patterns` case-insensitively.
1716
+ *
1717
+ * @param column - The column to filter on
1718
+ * @param patterns - The patterns to match with
1719
+ *
1720
+ * @category Database
1721
+ * @subcategory Using filters
1722
+ */
1723
+ ilikeAllOf(column, patterns) {
1724
+ this.url.searchParams.append(column, `ilike(all).{${patterns.join(",")}}`);
1725
+ return this;
1726
+ }
1727
+ /**
1728
+ * Match only rows where `column` matches any of `patterns` case-insensitively.
1729
+ *
1730
+ * @param column - The column to filter on
1731
+ * @param patterns - The patterns to match with
1732
+ *
1733
+ * @category Database
1734
+ * @subcategory Using filters
1735
+ */
1736
+ ilikeAnyOf(column, patterns) {
1737
+ this.url.searchParams.append(column, `ilike(any).{${patterns.join(",")}}`);
1738
+ return this;
1739
+ }
1740
+ /**
1741
+ * Match only rows where `column` matches the PostgreSQL regex `pattern`
1742
+ * case-sensitively (using the `~` operator).
1743
+ *
1744
+ * @param column - The column to filter on
1745
+ * @param pattern - The PostgreSQL regular expression pattern to match with
1746
+ */
1747
+ regexMatch(column, pattern) {
1748
+ this.url.searchParams.append(column, `match.${pattern}`);
1749
+ return this;
1750
+ }
1751
+ /**
1752
+ * Match only rows where `column` matches the PostgreSQL regex `pattern`
1753
+ * case-insensitively (using the `~*` operator).
1754
+ *
1755
+ * @param column - The column to filter on
1756
+ * @param pattern - The PostgreSQL regular expression pattern to match with
1757
+ */
1758
+ regexIMatch(column, pattern) {
1759
+ this.url.searchParams.append(column, `imatch.${pattern}`);
1760
+ return this;
1761
+ }
1762
+ /**
1763
+ * Match only rows where `column` IS `value`.
1764
+ *
1765
+ * For non-boolean columns, this is only relevant for checking if the value of
1766
+ * `column` is NULL by setting `value` to `null`.
1767
+ *
1768
+ * For boolean columns, you can also set `value` to `true` or `false` and it
1769
+ * will behave the same way as `.eq()`.
1770
+ *
1771
+ * @param column - The column to filter on
1772
+ * @param value - The value to filter with
1773
+ *
1774
+ * @category Database
1775
+ * @subcategory Using filters
1776
+ *
1777
+ * @exampleDescription Checking for nullness, true or false
1778
+ * Using the `eq()` filter doesn't work when filtering for `null`.
1779
+ *
1780
+ * Instead, you need to use `is()`.
1781
+ *
1782
+ * @example Checking for nullness, true or false
1783
+ * ```ts
1784
+ * const { data, error } = await supabase
1785
+ * .from('countries')
1786
+ * .select()
1787
+ * .is('name', null)
1788
+ * ```
1789
+ *
1790
+ * @exampleSql Checking for nullness, true or false
1791
+ * ```sql
1792
+ * create table
1793
+ * countries (id int8 primary key, name text);
1794
+ *
1795
+ * insert into
1796
+ * countries (id, name)
1797
+ * values
1798
+ * (1, 'null'),
1799
+ * (2, null);
1800
+ * ```
1801
+ *
1802
+ * @exampleResponse Checking for nullness, true or false
1803
+ * ```json
1804
+ * {
1805
+ * "data": [
1806
+ * {
1807
+ * "id": 2,
1808
+ * "name": "null"
1809
+ * }
1810
+ * ],
1811
+ * "status": 200,
1812
+ * "statusText": "OK"
1813
+ * }
1814
+ * ```
1815
+ */
1816
+ is(column, value) {
1817
+ this.url.searchParams.append(column, `is.${value}`);
1818
+ return this;
1819
+ }
1820
+ /**
1821
+ * Match only rows where `column` IS DISTINCT FROM `value`.
1822
+ *
1823
+ * Unlike `.neq()`, this treats `NULL` as a comparable value. Two `NULL` values
1824
+ * are considered equal (not distinct), and comparing `NULL` with any non-NULL
1825
+ * value returns true (distinct).
1826
+ *
1827
+ * @param column - The column to filter on
1828
+ * @param value - The value to filter with
1829
+ */
1830
+ isDistinct(column, value) {
1831
+ this.url.searchParams.append(column, `isdistinct.${value}`);
1832
+ return this;
1833
+ }
1834
+ /**
1835
+ * Match only rows where `column` is included in the `values` array.
1836
+ *
1837
+ * @param column - The column to filter on
1838
+ * @param values - The values array to filter with
1839
+ *
1840
+ * @category Database
1841
+ * @subcategory Using filters
1842
+ *
1843
+ * @example With `select()`
1844
+ * ```ts
1845
+ * const { data, error } = await supabase
1846
+ * .from('characters')
1847
+ * .select()
1848
+ * .in('name', ['Leia', 'Han'])
1849
+ * ```
1850
+ *
1851
+ * @exampleSql With `select()`
1852
+ * ```sql
1853
+ * create table
1854
+ * characters (id int8 primary key, name text);
1855
+ *
1856
+ * insert into
1857
+ * characters (id, name)
1858
+ * values
1859
+ * (1, 'Luke'),
1860
+ * (2, 'Leia'),
1861
+ * (3, 'Han');
1862
+ * ```
1863
+ *
1864
+ * @exampleResponse With `select()`
1865
+ * ```json
1866
+ * {
1867
+ * "data": [
1868
+ * {
1869
+ * "id": 2,
1870
+ * "name": "Leia"
1871
+ * },
1872
+ * {
1873
+ * "id": 3,
1874
+ * "name": "Han"
1875
+ * }
1876
+ * ],
1877
+ * "status": 200,
1878
+ * "statusText": "OK"
1879
+ * }
1880
+ * ```
1881
+ */
1882
+ in(column, values) {
1883
+ const cleanedValues = Array.from(new Set(values)).map((s) => {
1884
+ if (typeof s === "string" && PostgrestReservedCharsRegexp.test(s)) return `"${s}"`;
1885
+ else return `${s}`;
1886
+ }).join(",");
1887
+ this.url.searchParams.append(column, `in.(${cleanedValues})`);
1888
+ return this;
1889
+ }
1890
+ /**
1891
+ * Match only rows where `column` is NOT included in the `values` array.
1892
+ *
1893
+ * @param column - The column to filter on
1894
+ * @param values - The values array to filter with
1895
+ */
1896
+ notIn(column, values) {
1897
+ const cleanedValues = Array.from(new Set(values)).map((s) => {
1898
+ if (typeof s === "string" && PostgrestReservedCharsRegexp.test(s)) return `"${s}"`;
1899
+ else return `${s}`;
1900
+ }).join(",");
1901
+ this.url.searchParams.append(column, `not.in.(${cleanedValues})`);
1902
+ return this;
1903
+ }
1904
+ /**
1905
+ * Only relevant for jsonb, array, and range columns. Match only rows where
1906
+ * `column` contains every element appearing in `value`.
1907
+ *
1908
+ * @param column - The jsonb, array, or range column to filter on
1909
+ * @param value - The jsonb, array, or range value to filter with
1910
+ *
1911
+ * @category Database
1912
+ * @subcategory Using filters
1913
+ *
1914
+ * @example On array columns
1915
+ * ```ts
1916
+ * const { data, error } = await supabase
1917
+ * .from('issues')
1918
+ * .select()
1919
+ * .contains('tags', ['is:open', 'priority:low'])
1920
+ * ```
1921
+ *
1922
+ * @exampleSql On array columns
1923
+ * ```sql
1924
+ * create table
1925
+ * issues (
1926
+ * id int8 primary key,
1927
+ * title text,
1928
+ * tags text[]
1929
+ * );
1930
+ *
1931
+ * insert into
1932
+ * issues (id, title, tags)
1933
+ * values
1934
+ * (1, 'Cache invalidation is not working', array['is:open', 'severity:high', 'priority:low']),
1935
+ * (2, 'Use better names', array['is:open', 'severity:low', 'priority:medium']);
1936
+ * ```
1937
+ *
1938
+ * @exampleResponse On array columns
1939
+ * ```json
1940
+ * {
1941
+ * "data": [
1942
+ * {
1943
+ * "title": "Cache invalidation is not working"
1944
+ * }
1945
+ * ],
1946
+ * "status": 200,
1947
+ * "statusText": "OK"
1948
+ * }
1949
+ * ```
1950
+ *
1951
+ * @exampleDescription On range columns
1952
+ * Postgres supports a number of [range
1953
+ * types](https://www.postgresql.org/docs/current/rangetypes.html). You
1954
+ * can filter on range columns using the string representation of range
1955
+ * values.
1956
+ *
1957
+ * @example On range columns
1958
+ * ```ts
1959
+ * const { data, error } = await supabase
1960
+ * .from('reservations')
1961
+ * .select()
1962
+ * .contains('during', '[2000-01-01 13:00, 2000-01-01 13:30)')
1963
+ * ```
1964
+ *
1965
+ * @exampleSql On range columns
1966
+ * ```sql
1967
+ * create table
1968
+ * reservations (
1969
+ * id int8 primary key,
1970
+ * room_name text,
1971
+ * during tsrange
1972
+ * );
1973
+ *
1974
+ * insert into
1975
+ * reservations (id, room_name, during)
1976
+ * values
1977
+ * (1, 'Emerald', '[2000-01-01 13:00, 2000-01-01 15:00)'),
1978
+ * (2, 'Topaz', '[2000-01-02 09:00, 2000-01-02 10:00)');
1979
+ * ```
1980
+ *
1981
+ * @exampleResponse On range columns
1982
+ * ```json
1983
+ * {
1984
+ * "data": [
1985
+ * {
1986
+ * "id": 1,
1987
+ * "room_name": "Emerald",
1988
+ * "during": "[\"2000-01-01 13:00:00\",\"2000-01-01 15:00:00\")"
1989
+ * }
1990
+ * ],
1991
+ * "status": 200,
1992
+ * "statusText": "OK"
1993
+ * }
1994
+ * ```
1995
+ *
1996
+ * @example On `jsonb` columns
1997
+ * ```ts
1998
+ * const { data, error } = await supabase
1999
+ * .from('users')
2000
+ * .select('name')
2001
+ * .contains('address', { postcode: 90210 })
2002
+ * ```
2003
+ *
2004
+ * @exampleSql On `jsonb` columns
2005
+ * ```sql
2006
+ * create table
2007
+ * users (
2008
+ * id int8 primary key,
2009
+ * name text,
2010
+ * address jsonb
2011
+ * );
2012
+ *
2013
+ * insert into
2014
+ * users (id, name, address)
2015
+ * values
2016
+ * (1, 'Michael', '{ "postcode": 90210, "street": "Melrose Place" }'),
2017
+ * (2, 'Jane', '{}');
2018
+ * ```
2019
+ *
2020
+ * @exampleResponse On `jsonb` columns
2021
+ * ```json
2022
+ * {
2023
+ * "data": [
2024
+ * {
2025
+ * "name": "Michael"
2026
+ * }
2027
+ * ],
2028
+ * "status": 200,
2029
+ * "statusText": "OK"
2030
+ * }
2031
+ * ```
2032
+ */
2033
+ contains(column, value) {
2034
+ if (typeof value === "string") this.url.searchParams.append(column, `cs.${value}`);
2035
+ else if (Array.isArray(value)) this.url.searchParams.append(column, `cs.{${value.join(",")}}`);
2036
+ else this.url.searchParams.append(column, `cs.${JSON.stringify(value)}`);
2037
+ return this;
2038
+ }
2039
+ /**
2040
+ * Only relevant for jsonb, array, and range columns. Match only rows where
2041
+ * every element appearing in `column` is contained by `value`.
2042
+ *
2043
+ * @param column - The jsonb, array, or range column to filter on
2044
+ * @param value - The jsonb, array, or range value to filter with
2045
+ *
2046
+ * @category Database
2047
+ * @subcategory Using filters
2048
+ *
2049
+ * @example On array columns
2050
+ * ```ts
2051
+ * const { data, error } = await supabase
2052
+ * .from('classes')
2053
+ * .select('name')
2054
+ * .containedBy('days', ['monday', 'tuesday', 'wednesday', 'friday'])
2055
+ * ```
2056
+ *
2057
+ * @exampleSql On array columns
2058
+ * ```sql
2059
+ * create table
2060
+ * classes (
2061
+ * id int8 primary key,
2062
+ * name text,
2063
+ * days text[]
2064
+ * );
2065
+ *
2066
+ * insert into
2067
+ * classes (id, name, days)
2068
+ * values
2069
+ * (1, 'Chemistry', array['monday', 'friday']),
2070
+ * (2, 'History', array['monday', 'wednesday', 'thursday']);
2071
+ * ```
2072
+ *
2073
+ * @exampleResponse On array columns
2074
+ * ```json
2075
+ * {
2076
+ * "data": [
2077
+ * {
2078
+ * "name": "Chemistry"
2079
+ * }
2080
+ * ],
2081
+ * "status": 200,
2082
+ * "statusText": "OK"
2083
+ * }
2084
+ * ```
2085
+ *
2086
+ * @exampleDescription On range columns
2087
+ * Postgres supports a number of [range
2088
+ * types](https://www.postgresql.org/docs/current/rangetypes.html). You
2089
+ * can filter on range columns using the string representation of range
2090
+ * values.
2091
+ *
2092
+ * @example On range columns
2093
+ * ```ts
2094
+ * const { data, error } = await supabase
2095
+ * .from('reservations')
2096
+ * .select()
2097
+ * .containedBy('during', '[2000-01-01 00:00, 2000-01-01 23:59)')
2098
+ * ```
2099
+ *
2100
+ * @exampleSql On range columns
2101
+ * ```sql
2102
+ * create table
2103
+ * reservations (
2104
+ * id int8 primary key,
2105
+ * room_name text,
2106
+ * during tsrange
2107
+ * );
2108
+ *
2109
+ * insert into
2110
+ * reservations (id, room_name, during)
2111
+ * values
2112
+ * (1, 'Emerald', '[2000-01-01 13:00, 2000-01-01 15:00)'),
2113
+ * (2, 'Topaz', '[2000-01-02 09:00, 2000-01-02 10:00)');
2114
+ * ```
2115
+ *
2116
+ * @exampleResponse On range columns
2117
+ * ```json
2118
+ * {
2119
+ * "data": [
2120
+ * {
2121
+ * "id": 1,
2122
+ * "room_name": "Emerald",
2123
+ * "during": "[\"2000-01-01 13:00:00\",\"2000-01-01 15:00:00\")"
2124
+ * }
2125
+ * ],
2126
+ * "status": 200,
2127
+ * "statusText": "OK"
2128
+ * }
2129
+ * ```
2130
+ *
2131
+ * @example On `jsonb` columns
2132
+ * ```ts
2133
+ * const { data, error } = await supabase
2134
+ * .from('users')
2135
+ * .select('name')
2136
+ * .containedBy('address', {})
2137
+ * ```
2138
+ *
2139
+ * @exampleSql On `jsonb` columns
2140
+ * ```sql
2141
+ * create table
2142
+ * users (
2143
+ * id int8 primary key,
2144
+ * name text,
2145
+ * address jsonb
2146
+ * );
2147
+ *
2148
+ * insert into
2149
+ * users (id, name, address)
2150
+ * values
2151
+ * (1, 'Michael', '{ "postcode": 90210, "street": "Melrose Place" }'),
2152
+ * (2, 'Jane', '{}');
2153
+ * ```
2154
+ *
2155
+ * @exampleResponse On `jsonb` columns
2156
+ * ```json
2157
+ * {
2158
+ * "data": [
2159
+ * {
2160
+ * "name": "Jane"
2161
+ * }
2162
+ * ],
2163
+ * "status": 200,
2164
+ * "statusText": "OK"
2165
+ * }
2166
+ *
2167
+ * ```
2168
+ */
2169
+ containedBy(column, value) {
2170
+ if (typeof value === "string") this.url.searchParams.append(column, `cd.${value}`);
2171
+ else if (Array.isArray(value)) this.url.searchParams.append(column, `cd.{${value.join(",")}}`);
2172
+ else this.url.searchParams.append(column, `cd.${JSON.stringify(value)}`);
2173
+ return this;
2174
+ }
2175
+ /**
2176
+ * Only relevant for range columns. Match only rows where every element in
2177
+ * `column` is greater than any element in `range`.
2178
+ *
2179
+ * @param column - The range column to filter on
2180
+ * @param range - The range to filter with
2181
+ *
2182
+ * @category Database
2183
+ * @subcategory Using filters
2184
+ *
2185
+ * @exampleDescription With `select()`
2186
+ * Postgres supports a number of [range
2187
+ * types](https://www.postgresql.org/docs/current/rangetypes.html). You
2188
+ * can filter on range columns using the string representation of range
2189
+ * values.
2190
+ *
2191
+ * @example With `select()`
2192
+ * ```ts
2193
+ * const { data, error } = await supabase
2194
+ * .from('reservations')
2195
+ * .select()
2196
+ * .rangeGt('during', '[2000-01-02 08:00, 2000-01-02 09:00)')
2197
+ * ```
2198
+ *
2199
+ * @exampleSql With `select()`
2200
+ * ```sql
2201
+ * create table
2202
+ * reservations (
2203
+ * id int8 primary key,
2204
+ * room_name text,
2205
+ * during tsrange
2206
+ * );
2207
+ *
2208
+ * insert into
2209
+ * reservations (id, room_name, during)
2210
+ * values
2211
+ * (1, 'Emerald', '[2000-01-01 13:00, 2000-01-01 15:00)'),
2212
+ * (2, 'Topaz', '[2000-01-02 09:00, 2000-01-02 10:00)');
2213
+ * ```
2214
+ *
2215
+ * @exampleResponse With `select()`
2216
+ * ```json
2217
+ * {
2218
+ * "data": [
2219
+ * {
2220
+ * "id": 2,
2221
+ * "room_name": "Topaz",
2222
+ * "during": "[\"2000-01-02 09:00:00\",\"2000-01-02 10:00:00\")"
2223
+ * }
2224
+ * ],
2225
+ * "status": 200,
2226
+ * "statusText": "OK"
2227
+ * }
2228
+ *
2229
+ * ```
2230
+ */
2231
+ rangeGt(column, range) {
2232
+ this.url.searchParams.append(column, `sr.${range}`);
2233
+ return this;
2234
+ }
2235
+ /**
2236
+ * Only relevant for range columns. Match only rows where every element in
2237
+ * `column` is either contained in `range` or greater than any element in
2238
+ * `range`.
2239
+ *
2240
+ * @param column - The range column to filter on
2241
+ * @param range - The range to filter with
2242
+ *
2243
+ * @category Database
2244
+ * @subcategory Using filters
2245
+ *
2246
+ * @exampleDescription With `select()`
2247
+ * Postgres supports a number of [range
2248
+ * types](https://www.postgresql.org/docs/current/rangetypes.html). You
2249
+ * can filter on range columns using the string representation of range
2250
+ * values.
2251
+ *
2252
+ * @example With `select()`
2253
+ * ```ts
2254
+ * const { data, error } = await supabase
2255
+ * .from('reservations')
2256
+ * .select()
2257
+ * .rangeGte('during', '[2000-01-02 08:30, 2000-01-02 09:30)')
2258
+ * ```
2259
+ *
2260
+ * @exampleSql With `select()`
2261
+ * ```sql
2262
+ * create table
2263
+ * reservations (
2264
+ * id int8 primary key,
2265
+ * room_name text,
2266
+ * during tsrange
2267
+ * );
2268
+ *
2269
+ * insert into
2270
+ * reservations (id, room_name, during)
2271
+ * values
2272
+ * (1, 'Emerald', '[2000-01-01 13:00, 2000-01-01 15:00)'),
2273
+ * (2, 'Topaz', '[2000-01-02 09:00, 2000-01-02 10:00)');
2274
+ * ```
2275
+ *
2276
+ * @exampleResponse With `select()`
2277
+ * ```json
2278
+ * {
2279
+ * "data": [
2280
+ * {
2281
+ * "id": 2,
2282
+ * "room_name": "Topaz",
2283
+ * "during": "[\"2000-01-02 09:00:00\",\"2000-01-02 10:00:00\")"
2284
+ * }
2285
+ * ],
2286
+ * "status": 200,
2287
+ * "statusText": "OK"
2288
+ * }
2289
+ *
2290
+ * ```
2291
+ */
2292
+ rangeGte(column, range) {
2293
+ this.url.searchParams.append(column, `nxl.${range}`);
2294
+ return this;
2295
+ }
2296
+ /**
2297
+ * Only relevant for range columns. Match only rows where every element in
2298
+ * `column` is less than any element in `range`.
2299
+ *
2300
+ * @param column - The range column to filter on
2301
+ * @param range - The range to filter with
2302
+ *
2303
+ * @category Database
2304
+ * @subcategory Using filters
2305
+ *
2306
+ * @exampleDescription With `select()`
2307
+ * Postgres supports a number of [range
2308
+ * types](https://www.postgresql.org/docs/current/rangetypes.html). You
2309
+ * can filter on range columns using the string representation of range
2310
+ * values.
2311
+ *
2312
+ * @example With `select()`
2313
+ * ```ts
2314
+ * const { data, error } = await supabase
2315
+ * .from('reservations')
2316
+ * .select()
2317
+ * .rangeLt('during', '[2000-01-01 15:00, 2000-01-01 16:00)')
2318
+ * ```
2319
+ *
2320
+ * @exampleSql With `select()`
2321
+ * ```sql
2322
+ * create table
2323
+ * reservations (
2324
+ * id int8 primary key,
2325
+ * room_name text,
2326
+ * during tsrange
2327
+ * );
2328
+ *
2329
+ * insert into
2330
+ * reservations (id, room_name, during)
2331
+ * values
2332
+ * (1, 'Emerald', '[2000-01-01 13:00, 2000-01-01 15:00)'),
2333
+ * (2, 'Topaz', '[2000-01-02 09:00, 2000-01-02 10:00)');
2334
+ * ```
2335
+ *
2336
+ * @exampleResponse With `select()`
2337
+ * ```json
2338
+ * {
2339
+ * "data": [
2340
+ * {
2341
+ * "id": 1,
2342
+ * "room_name": "Emerald",
2343
+ * "during": "[\"2000-01-01 13:00:00\",\"2000-01-01 15:00:00\")"
2344
+ * }
2345
+ * ],
2346
+ * "status": 200,
2347
+ * "statusText": "OK"
2348
+ * }
2349
+ * ```
2350
+ */
2351
+ rangeLt(column, range) {
2352
+ this.url.searchParams.append(column, `sl.${range}`);
2353
+ return this;
2354
+ }
2355
+ /**
2356
+ * Only relevant for range columns. Match only rows where every element in
2357
+ * `column` is either contained in `range` or less than any element in
2358
+ * `range`.
2359
+ *
2360
+ * @param column - The range column to filter on
2361
+ * @param range - The range to filter with
2362
+ *
2363
+ * @category Database
2364
+ * @subcategory Using filters
2365
+ *
2366
+ * @exampleDescription With `select()`
2367
+ * Postgres supports a number of [range
2368
+ * types](https://www.postgresql.org/docs/current/rangetypes.html). You
2369
+ * can filter on range columns using the string representation of range
2370
+ * values.
2371
+ *
2372
+ * @example With `select()`
2373
+ * ```ts
2374
+ * const { data, error } = await supabase
2375
+ * .from('reservations')
2376
+ * .select()
2377
+ * .rangeLte('during', '[2000-01-01 14:00, 2000-01-01 16:00)')
2378
+ * ```
2379
+ *
2380
+ * @exampleSql With `select()`
2381
+ * ```sql
2382
+ * create table
2383
+ * reservations (
2384
+ * id int8 primary key,
2385
+ * room_name text,
2386
+ * during tsrange
2387
+ * );
2388
+ *
2389
+ * insert into
2390
+ * reservations (id, room_name, during)
2391
+ * values
2392
+ * (1, 'Emerald', '[2000-01-01 13:00, 2000-01-01 15:00)'),
2393
+ * (2, 'Topaz', '[2000-01-02 09:00, 2000-01-02 10:00)');
2394
+ * ```
2395
+ *
2396
+ * @exampleResponse With `select()`
2397
+ * ```json
2398
+ * {
2399
+ * "data": [
2400
+ * {
2401
+ * "id": 1,
2402
+ * "room_name": "Emerald",
2403
+ * "during": "[\"2000-01-01 13:00:00\",\"2000-01-01 15:00:00\")"
2404
+ * }
2405
+ * ],
2406
+ * "status": 200,
2407
+ * "statusText": "OK"
2408
+ * }
2409
+ *
2410
+ * ```
2411
+ */
2412
+ rangeLte(column, range) {
2413
+ this.url.searchParams.append(column, `nxr.${range}`);
2414
+ return this;
2415
+ }
2416
+ /**
2417
+ * Only relevant for range columns. Match only rows where `column` is
2418
+ * mutually exclusive to `range` and there can be no element between the two
2419
+ * ranges.
2420
+ *
2421
+ * @param column - The range column to filter on
2422
+ * @param range - The range to filter with
2423
+ *
2424
+ * @category Database
2425
+ * @subcategory Using filters
2426
+ *
2427
+ * @exampleDescription With `select()`
2428
+ * Postgres supports a number of [range
2429
+ * types](https://www.postgresql.org/docs/current/rangetypes.html). You
2430
+ * can filter on range columns using the string representation of range
2431
+ * values.
2432
+ *
2433
+ * @example With `select()`
2434
+ * ```ts
2435
+ * const { data, error } = await supabase
2436
+ * .from('reservations')
2437
+ * .select()
2438
+ * .rangeAdjacent('during', '[2000-01-01 12:00, 2000-01-01 13:00)')
2439
+ * ```
2440
+ *
2441
+ * @exampleSql With `select()`
2442
+ * ```sql
2443
+ * create table
2444
+ * reservations (
2445
+ * id int8 primary key,
2446
+ * room_name text,
2447
+ * during tsrange
2448
+ * );
2449
+ *
2450
+ * insert into
2451
+ * reservations (id, room_name, during)
2452
+ * values
2453
+ * (1, 'Emerald', '[2000-01-01 13:00, 2000-01-01 15:00)'),
2454
+ * (2, 'Topaz', '[2000-01-02 09:00, 2000-01-02 10:00)');
2455
+ * ```
2456
+ *
2457
+ * @exampleResponse With `select()`
2458
+ * ```json
2459
+ * {
2460
+ * "data": [
2461
+ * {
2462
+ * "id": 1,
2463
+ * "room_name": "Emerald",
2464
+ * "during": "[\"2000-01-01 13:00:00\",\"2000-01-01 15:00:00\")"
2465
+ * }
2466
+ * ],
2467
+ * "status": 200,
2468
+ * "statusText": "OK"
2469
+ * }
2470
+ * ```
2471
+ */
2472
+ rangeAdjacent(column, range) {
2473
+ this.url.searchParams.append(column, `adj.${range}`);
2474
+ return this;
2475
+ }
2476
+ /**
2477
+ * Only relevant for array and range columns. Match only rows where
2478
+ * `column` and `value` have an element in common.
2479
+ *
2480
+ * @param column - The array or range column to filter on
2481
+ * @param value - The array or range value to filter with
2482
+ *
2483
+ * @category Database
2484
+ * @subcategory Using filters
2485
+ *
2486
+ * @example On array columns
2487
+ * ```ts
2488
+ * const { data, error } = await supabase
2489
+ * .from('issues')
2490
+ * .select('title')
2491
+ * .overlaps('tags', ['is:closed', 'severity:high'])
2492
+ * ```
2493
+ *
2494
+ * @exampleSql On array columns
2495
+ * ```sql
2496
+ * create table
2497
+ * issues (
2498
+ * id int8 primary key,
2499
+ * title text,
2500
+ * tags text[]
2501
+ * );
2502
+ *
2503
+ * insert into
2504
+ * issues (id, title, tags)
2505
+ * values
2506
+ * (1, 'Cache invalidation is not working', array['is:open', 'severity:high', 'priority:low']),
2507
+ * (2, 'Use better names', array['is:open', 'severity:low', 'priority:medium']);
2508
+ * ```
2509
+ *
2510
+ * @exampleResponse On array columns
2511
+ * ```json
2512
+ * {
2513
+ * "data": [
2514
+ * {
2515
+ * "title": "Cache invalidation is not working"
2516
+ * }
2517
+ * ],
2518
+ * "status": 200,
2519
+ * "statusText": "OK"
2520
+ * }
2521
+ * ```
2522
+ *
2523
+ * @exampleDescription On range columns
2524
+ * Postgres supports a number of [range
2525
+ * types](https://www.postgresql.org/docs/current/rangetypes.html). You
2526
+ * can filter on range columns using the string representation of range
2527
+ * values.
2528
+ *
2529
+ * @example On range columns
2530
+ * ```ts
2531
+ * const { data, error } = await supabase
2532
+ * .from('reservations')
2533
+ * .select()
2534
+ * .overlaps('during', '[2000-01-01 12:45, 2000-01-01 13:15)')
2535
+ * ```
2536
+ *
2537
+ * @exampleSql On range columns
2538
+ * ```sql
2539
+ * create table
2540
+ * reservations (
2541
+ * id int8 primary key,
2542
+ * room_name text,
2543
+ * during tsrange
2544
+ * );
2545
+ *
2546
+ * insert into
2547
+ * reservations (id, room_name, during)
2548
+ * values
2549
+ * (1, 'Emerald', '[2000-01-01 13:00, 2000-01-01 15:00)'),
2550
+ * (2, 'Topaz', '[2000-01-02 09:00, 2000-01-02 10:00)');
2551
+ * ```
2552
+ *
2553
+ * @exampleResponse On range columns
2554
+ * ```json
2555
+ * {
2556
+ * "data": [
2557
+ * {
2558
+ * "id": 1,
2559
+ * "room_name": "Emerald",
2560
+ * "during": "[\"2000-01-01 13:00:00\",\"2000-01-01 15:00:00\")"
2561
+ * }
2562
+ * ],
2563
+ * "status": 200,
2564
+ * "statusText": "OK"
2565
+ * }
2566
+ * ```
2567
+ */
2568
+ overlaps(column, value) {
2569
+ if (typeof value === "string") this.url.searchParams.append(column, `ov.${value}`);
2570
+ else this.url.searchParams.append(column, `ov.{${value.join(",")}}`);
2571
+ return this;
2572
+ }
2573
+ /**
2574
+ * Only relevant for text and tsvector columns. Match only rows where
2575
+ * `column` matches the query string in `query`.
2576
+ *
2577
+ * @param column - The text or tsvector column to filter on
2578
+ * @param query - The query text to match with
2579
+ * @param options - Named parameters
2580
+ * @param options.config - The text search configuration to use
2581
+ * @param options.type - Change how the `query` text is interpreted
2582
+ *
2583
+ * @category Database
2584
+ * @subcategory Using filters
2585
+ *
2586
+ * @remarks
2587
+ * - For more information, see [Postgres full text search](/docs/guides/database/full-text-search).
2588
+ *
2589
+ * @example Text search
2590
+ * ```ts
2591
+ * const result = await supabase
2592
+ * .from("texts")
2593
+ * .select("content")
2594
+ * .textSearch("content", `'eggs' & 'ham'`, {
2595
+ * config: "english",
2596
+ * });
2597
+ * ```
2598
+ *
2599
+ * @exampleSql Text search
2600
+ * ```sql
2601
+ * create table texts (
2602
+ * id bigint
2603
+ * primary key
2604
+ * generated always as identity,
2605
+ * content text
2606
+ * );
2607
+ *
2608
+ * insert into texts (content) values
2609
+ * ('Four score and seven years ago'),
2610
+ * ('The road goes ever on and on'),
2611
+ * ('Green eggs and ham')
2612
+ * ;
2613
+ * ```
2614
+ *
2615
+ * @exampleResponse Text search
2616
+ * ```json
2617
+ * {
2618
+ * "data": [
2619
+ * {
2620
+ * "content": "Green eggs and ham"
2621
+ * }
2622
+ * ],
2623
+ * "status": 200,
2624
+ * "statusText": "OK"
2625
+ * }
2626
+ * ```
2627
+ *
2628
+ * @exampleDescription Basic normalization
2629
+ * Uses PostgreSQL's `plainto_tsquery` function.
2630
+ *
2631
+ * @example Basic normalization
2632
+ * ```ts
2633
+ * const { data, error } = await supabase
2634
+ * .from('quotes')
2635
+ * .select('catchphrase')
2636
+ * .textSearch('catchphrase', `'fat' & 'cat'`, {
2637
+ * type: 'plain',
2638
+ * config: 'english'
2639
+ * })
2640
+ * ```
2641
+ *
2642
+ * @exampleDescription Full normalization
2643
+ * Uses PostgreSQL's `phraseto_tsquery` function.
2644
+ *
2645
+ * @example Full normalization
2646
+ * ```ts
2647
+ * const { data, error } = await supabase
2648
+ * .from('quotes')
2649
+ * .select('catchphrase')
2650
+ * .textSearch('catchphrase', `'fat' & 'cat'`, {
2651
+ * type: 'phrase',
2652
+ * config: 'english'
2653
+ * })
2654
+ * ```
2655
+ *
2656
+ * @exampleDescription Websearch
2657
+ * Uses PostgreSQL's `websearch_to_tsquery` function.
2658
+ * This function will never raise syntax errors, which makes it possible to use raw user-supplied input for search, and can be used
2659
+ * with advanced operators.
2660
+ *
2661
+ * - `unquoted text`: text not inside quote marks will be converted to terms separated by & operators, as if processed by plainto_tsquery.
2662
+ * - `"quoted text"`: text inside quote marks will be converted to terms separated by `<->` operators, as if processed by phraseto_tsquery.
2663
+ * - `OR`: the word “or” will be converted to the | operator.
2664
+ * - `-`: a dash will be converted to the ! operator.
2665
+ *
2666
+ * @example Websearch
2667
+ * ```ts
2668
+ * const { data, error } = await supabase
2669
+ * .from('quotes')
2670
+ * .select('catchphrase')
2671
+ * .textSearch('catchphrase', `'fat or cat'`, {
2672
+ * type: 'websearch',
2673
+ * config: 'english'
2674
+ * })
2675
+ * ```
2676
+ */
2677
+ textSearch(column, query, { config, type } = {}) {
2678
+ let typePart = "";
2679
+ if (type === "plain") typePart = "pl";
2680
+ else if (type === "phrase") typePart = "ph";
2681
+ else if (type === "websearch") typePart = "w";
2682
+ const configPart = config === void 0 ? "" : `(${config})`;
2683
+ this.url.searchParams.append(column, `${typePart}fts${configPart}.${query}`);
2684
+ return this;
2685
+ }
2686
+ /**
2687
+ * Match only rows where each column in `query` keys is equal to its
2688
+ * associated value. Shorthand for multiple `.eq()`s.
2689
+ *
2690
+ * @param query - The object to filter with, with column names as keys mapped
2691
+ * to their filter values
2692
+ *
2693
+ * @category Database
2694
+ * @subcategory Using filters
2695
+ *
2696
+ * @example With `select()`
2697
+ * ```ts
2698
+ * const { data, error } = await supabase
2699
+ * .from('characters')
2700
+ * .select('name')
2701
+ * .match({ id: 2, name: 'Leia' })
2702
+ * ```
2703
+ *
2704
+ * @exampleSql With `select()`
2705
+ * ```sql
2706
+ * create table
2707
+ * characters (id int8 primary key, name text);
2708
+ *
2709
+ * insert into
2710
+ * characters (id, name)
2711
+ * values
2712
+ * (1, 'Luke'),
2713
+ * (2, 'Leia'),
2714
+ * (3, 'Han');
2715
+ * ```
2716
+ *
2717
+ * @exampleResponse With `select()`
2718
+ * ```json
2719
+ * {
2720
+ * "data": [
2721
+ * {
2722
+ * "name": "Leia"
2723
+ * }
2724
+ * ],
2725
+ * "status": 200,
2726
+ * "statusText": "OK"
2727
+ * }
2728
+ * ```
2729
+ */
2730
+ match(query) {
2731
+ Object.entries(query).filter(([_, value]) => value !== void 0).forEach(([column, value]) => {
2732
+ this.url.searchParams.append(column, `eq.${value}`);
2733
+ });
2734
+ return this;
2735
+ }
2736
+ /**
2737
+ * Match only rows which doesn't satisfy the filter.
2738
+ *
2739
+ * Unlike most filters, `opearator` and `value` are used as-is and need to
2740
+ * follow [PostgREST
2741
+ * syntax](https://postgrest.org/en/stable/api.html#operators). You also need
2742
+ * to make sure they are properly sanitized.
2743
+ *
2744
+ * @param column - The column to filter on
2745
+ * @param operator - The operator to be negated to filter with, following
2746
+ * PostgREST syntax
2747
+ * @param value - The value to filter with, following PostgREST syntax
2748
+ *
2749
+ * @category Database
2750
+ * @subcategory Using filters
2751
+ *
2752
+ * @remarks
2753
+ * not() expects you to use the raw PostgREST syntax for the filter values.
2754
+ *
2755
+ * ```ts
2756
+ * .not('id', 'in', '(5,6,7)') // Use `()` for `in` filter
2757
+ * .not('arraycol', 'cs', '{"a","b"}') // Use `cs` for `contains()`, `{}` for array values
2758
+ * ```
2759
+ *
2760
+ * @example With `select()`
2761
+ * ```ts
2762
+ * const { data, error } = await supabase
2763
+ * .from('countries')
2764
+ * .select()
2765
+ * .not('name', 'is', null)
2766
+ * ```
2767
+ *
2768
+ * @exampleSql With `select()`
2769
+ * ```sql
2770
+ * create table
2771
+ * countries (id int8 primary key, name text);
2772
+ *
2773
+ * insert into
2774
+ * countries (id, name)
2775
+ * values
2776
+ * (1, 'null'),
2777
+ * (2, null);
2778
+ * ```
2779
+ *
2780
+ * @exampleResponse With `select()`
2781
+ * ```json
2782
+ * {
2783
+ * "data": [
2784
+ * {
2785
+ * "id": 1,
2786
+ * "name": "null"
2787
+ * }
2788
+ * ],
2789
+ * "status": 200,
2790
+ * "statusText": "OK"
2791
+ * }
2792
+ *
2793
+ * ```
2794
+ */
2795
+ not(column, operator, value) {
2796
+ this.url.searchParams.append(column, `not.${operator}.${value}`);
2797
+ return this;
2798
+ }
2799
+ /**
2800
+ * Match only rows which satisfy at least one of the filters.
2801
+ *
2802
+ * Unlike most filters, `filters` is used as-is and needs to follow [PostgREST
2803
+ * syntax](https://postgrest.org/en/stable/api.html#operators). You also need
2804
+ * to make sure it's properly sanitized.
2805
+ *
2806
+ * It's currently not possible to do an `.or()` filter across multiple tables.
2807
+ *
2808
+ * @param filters - The filters to use, following PostgREST syntax
2809
+ * @param options - Named parameters
2810
+ * @param options.referencedTable - Set this to filter on referenced tables
2811
+ * instead of the parent table
2812
+ * @param options.foreignTable - Deprecated, use `referencedTable` instead
2813
+ *
2814
+ * @category Database
2815
+ * @subcategory Using filters
2816
+ *
2817
+ * @remarks
2818
+ * or() expects you to use the raw PostgREST syntax for the filter names and values.
2819
+ *
2820
+ * ```ts
2821
+ * .or('id.in.(5,6,7), arraycol.cs.{"a","b"}') // Use `()` for `in` filter, `{}` for array values and `cs` for `contains()`.
2822
+ * .or('id.in.(5,6,7), arraycol.cd.{"a","b"}') // Use `cd` for `containedBy()`
2823
+ * ```
2824
+ *
2825
+ * @example With `select()`
2826
+ * ```ts
2827
+ * const { data, error } = await supabase
2828
+ * .from('characters')
2829
+ * .select('name')
2830
+ * .or('id.eq.2,name.eq.Han')
2831
+ * ```
2832
+ *
2833
+ * @exampleSql With `select()`
2834
+ * ```sql
2835
+ * create table
2836
+ * characters (id int8 primary key, name text);
2837
+ *
2838
+ * insert into
2839
+ * characters (id, name)
2840
+ * values
2841
+ * (1, 'Luke'),
2842
+ * (2, 'Leia'),
2843
+ * (3, 'Han');
2844
+ * ```
2845
+ *
2846
+ * @exampleResponse With `select()`
2847
+ * ```json
2848
+ * {
2849
+ * "data": [
2850
+ * {
2851
+ * "name": "Leia"
2852
+ * },
2853
+ * {
2854
+ * "name": "Han"
2855
+ * }
2856
+ * ],
2857
+ * "status": 200,
2858
+ * "statusText": "OK"
2859
+ * }
2860
+ * ```
2861
+ *
2862
+ * @example Use `or` with `and`
2863
+ * ```ts
2864
+ * const { data, error } = await supabase
2865
+ * .from('characters')
2866
+ * .select('name')
2867
+ * .or('id.gt.3,and(id.eq.1,name.eq.Luke)')
2868
+ * ```
2869
+ *
2870
+ * @exampleSql Use `or` with `and`
2871
+ * ```sql
2872
+ * create table
2873
+ * characters (id int8 primary key, name text);
2874
+ *
2875
+ * insert into
2876
+ * characters (id, name)
2877
+ * values
2878
+ * (1, 'Luke'),
2879
+ * (2, 'Leia'),
2880
+ * (3, 'Han');
2881
+ * ```
2882
+ *
2883
+ * @exampleResponse Use `or` with `and`
2884
+ * ```json
2885
+ * {
2886
+ * "data": [
2887
+ * {
2888
+ * "name": "Luke"
2889
+ * }
2890
+ * ],
2891
+ * "status": 200,
2892
+ * "statusText": "OK"
2893
+ * }
2894
+ * ```
2895
+ *
2896
+ * @example Use `or` on referenced tables
2897
+ * ```ts
2898
+ * const { data, error } = await supabase
2899
+ * .from('orchestral_sections')
2900
+ * .select(`
2901
+ * name,
2902
+ * instruments!inner (
2903
+ * name
2904
+ * )
2905
+ * `)
2906
+ * .or('section_id.eq.1,name.eq.guzheng', { referencedTable: 'instruments' })
2907
+ * ```
2908
+ *
2909
+ * @exampleSql Use `or` on referenced tables
2910
+ * ```sql
2911
+ * create table
2912
+ * orchestral_sections (id int8 primary key, name text);
2913
+ * create table
2914
+ * instruments (
2915
+ * id int8 primary key,
2916
+ * section_id int8 not null references orchestral_sections,
2917
+ * name text
2918
+ * );
2919
+ *
2920
+ * insert into
2921
+ * orchestral_sections (id, name)
2922
+ * values
2923
+ * (1, 'strings'),
2924
+ * (2, 'woodwinds');
2925
+ * insert into
2926
+ * instruments (id, section_id, name)
2927
+ * values
2928
+ * (1, 2, 'flute'),
2929
+ * (2, 1, 'violin');
2930
+ * ```
2931
+ *
2932
+ * @exampleResponse Use `or` on referenced tables
2933
+ * ```json
2934
+ * {
2935
+ * "data": [
2936
+ * {
2937
+ * "name": "strings",
2938
+ * "instruments": [
2939
+ * {
2940
+ * "name": "violin"
2941
+ * }
2942
+ * ]
2943
+ * }
2944
+ * ],
2945
+ * "status": 200,
2946
+ * "statusText": "OK"
2947
+ * }
2948
+ * ```
2949
+ */
2950
+ or(filters, { foreignTable, referencedTable = foreignTable } = {}) {
2951
+ const key = referencedTable ? `${referencedTable}.or` : "or";
2952
+ this.url.searchParams.append(key, `(${filters})`);
2953
+ return this;
2954
+ }
2955
+ /**
2956
+ * Match only rows which satisfy the filter. This is an escape hatch - you
2957
+ * should use the specific filter methods wherever possible.
2958
+ *
2959
+ * Unlike most filters, `opearator` and `value` are used as-is and need to
2960
+ * follow [PostgREST
2961
+ * syntax](https://postgrest.org/en/stable/api.html#operators). You also need
2962
+ * to make sure they are properly sanitized.
2963
+ *
2964
+ * @param column - The column to filter on
2965
+ * @param operator - The operator to filter with, following PostgREST syntax
2966
+ * @param value - The value to filter with, following PostgREST syntax
2967
+ *
2968
+ * @category Database
2969
+ * @subcategory Using filters
2970
+ *
2971
+ * @remarks
2972
+ * filter() expects you to use the raw PostgREST syntax for the filter values.
2973
+ *
2974
+ * ```ts
2975
+ * .filter('id', 'in', '(5,6,7)') // Use `()` for `in` filter
2976
+ * .filter('arraycol', 'cs', '{"a","b"}') // Use `cs` for `contains()`, `{}` for array values
2977
+ * ```
2978
+ *
2979
+ * @example With `select()`
2980
+ * ```ts
2981
+ * const { data, error } = await supabase
2982
+ * .from('characters')
2983
+ * .select()
2984
+ * .filter('name', 'in', '("Han","Yoda")')
2985
+ * ```
2986
+ *
2987
+ * @exampleSql With `select()`
2988
+ * ```sql
2989
+ * create table
2990
+ * characters (id int8 primary key, name text);
2991
+ *
2992
+ * insert into
2993
+ * characters (id, name)
2994
+ * values
2995
+ * (1, 'Luke'),
2996
+ * (2, 'Leia'),
2997
+ * (3, 'Han');
2998
+ * ```
2999
+ *
3000
+ * @exampleResponse With `select()`
3001
+ * ```json
3002
+ * {
3003
+ * "data": [
3004
+ * {
3005
+ * "id": 3,
3006
+ * "name": "Han"
3007
+ * }
3008
+ * ],
3009
+ * "status": 200,
3010
+ * "statusText": "OK"
3011
+ * }
3012
+ * ```
3013
+ *
3014
+ * @example On a referenced table
3015
+ * ```ts
3016
+ * const { data, error } = await supabase
3017
+ * .from('orchestral_sections')
3018
+ * .select(`
3019
+ * name,
3020
+ * instruments!inner (
3021
+ * name
3022
+ * )
3023
+ * `)
3024
+ * .filter('instruments.name', 'eq', 'flute')
3025
+ * ```
3026
+ *
3027
+ * @exampleSql On a referenced table
3028
+ * ```sql
3029
+ * create table
3030
+ * orchestral_sections (id int8 primary key, name text);
3031
+ * create table
3032
+ * instruments (
3033
+ * id int8 primary key,
3034
+ * section_id int8 not null references orchestral_sections,
3035
+ * name text
3036
+ * );
3037
+ *
3038
+ * insert into
3039
+ * orchestral_sections (id, name)
3040
+ * values
3041
+ * (1, 'strings'),
3042
+ * (2, 'woodwinds');
3043
+ * insert into
3044
+ * instruments (id, section_id, name)
3045
+ * values
3046
+ * (1, 2, 'flute'),
3047
+ * (2, 1, 'violin');
3048
+ * ```
3049
+ *
3050
+ * @exampleResponse On a referenced table
3051
+ * ```json
3052
+ * {
3053
+ * "data": [
3054
+ * {
3055
+ * "name": "woodwinds",
3056
+ * "instruments": [
3057
+ * {
3058
+ * "name": "flute"
3059
+ * }
3060
+ * ]
3061
+ * }
3062
+ * ],
3063
+ * "status": 200,
3064
+ * "statusText": "OK"
3065
+ * }
3066
+ * ```
3067
+ */
3068
+ filter(column, operator, value) {
3069
+ this.url.searchParams.append(column, `${operator}.${value}`);
3070
+ return this;
3071
+ }
3072
+ };
3073
+ var PostgrestQueryBuilder = class {
3074
+ /**
3075
+ * Creates a query builder scoped to a Postgres table or view.
3076
+ *
3077
+ * @category Database
3078
+ *
3079
+ * @param url - The URL for the query
3080
+ * @param options - Named parameters
3081
+ * @param options.headers - Custom headers
3082
+ * @param options.schema - Postgres schema to use
3083
+ * @param options.fetch - Custom fetch implementation
3084
+ * @param options.urlLengthLimit - Maximum URL length before warning
3085
+ * @param options.retry - Enable automatic retries for transient errors (default: true)
3086
+ *
3087
+ * @example Using supabase-js (recommended)
3088
+ * ```ts
3089
+ * import { createClient } from '@supabase/supabase-js'
3090
+ *
3091
+ * const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
3092
+ * const { data, error } = await supabase.from('users').select('*')
3093
+ * ```
3094
+ *
3095
+ * @example Standalone import for bundle-sensitive environments
3096
+ * ```ts
3097
+ * import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
3098
+ *
3099
+ * const query = new PostgrestQueryBuilder(
3100
+ * new URL('https://xyzcompany.supabase.co/rest/v1/users'),
3101
+ * { headers: { apikey: 'your-publishable-key' }, retry: true }
3102
+ * )
3103
+ * ```
3104
+ */
3105
+ constructor(url, { headers = {}, schema, fetch: fetch$1, urlLengthLimit = 8e3, retry }) {
3106
+ this.url = url;
3107
+ this.headers = new Headers(headers);
3108
+ this.schema = schema;
3109
+ this.fetch = fetch$1;
3110
+ this.urlLengthLimit = urlLengthLimit;
3111
+ this.retry = retry;
3112
+ }
3113
+ /**
3114
+ * Clone URL and headers to prevent shared state between operations.
3115
+ */
3116
+ cloneRequestState() {
3117
+ return {
3118
+ url: new URL(this.url.toString()),
3119
+ headers: new Headers(this.headers)
3120
+ };
3121
+ }
3122
+ /**
3123
+ * Perform a SELECT query on the table or view.
3124
+ *
3125
+ * @param columns - The columns to retrieve, separated by commas. Columns can be renamed when returned with `customName:columnName`
3126
+ *
3127
+ * @param options - Named parameters
3128
+ *
3129
+ * @param options.head - When set to `true`, `data` will not be returned.
3130
+ * Useful if you only need the count.
3131
+ *
3132
+ * @param options.count - Count algorithm to use to count rows in the table or view.
3133
+ *
3134
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
3135
+ * hood.
3136
+ *
3137
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
3138
+ * statistics under the hood.
3139
+ *
3140
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
3141
+ * numbers.
3142
+ *
3143
+ * @remarks
3144
+ * When using `count` with `.range()` or `.limit()`, the returned `count` is the total number of rows
3145
+ * that match your filters, not the number of rows in the current page. Use this to build pagination UI.
3146
+
3147
+ * - By default, Supabase projects return a maximum of 1,000 rows. This setting can be changed in your project's [API settings](/dashboard/project/_/settings/api). It's recommended that you keep it low to limit the payload size of accidental or malicious requests. You can use `range()` queries to paginate through your data.
3148
+ * - `select()` can be combined with [Filters](/docs/reference/javascript/using-filters)
3149
+ * - `select()` can be combined with [Modifiers](/docs/reference/javascript/using-modifiers)
3150
+ * - `apikey` is a reserved keyword if you're using the [Supabase Platform](/docs/guides/platform) and [should be avoided as a column name](https://github.com/supabase/supabase/issues/5465). *
3151
+ * @category Database
3152
+ *
3153
+ * @example Getting your data
3154
+ * ```js
3155
+ * const { data, error } = await supabase
3156
+ * .from('characters')
3157
+ * .select()
3158
+ * ```
3159
+ *
3160
+ * @exampleSql Getting your data
3161
+ * ```sql
3162
+ * create table
3163
+ * characters (id int8 primary key, name text);
3164
+ *
3165
+ * insert into
3166
+ * characters (id, name)
3167
+ * values
3168
+ * (1, 'Harry'),
3169
+ * (2, 'Frodo'),
3170
+ * (3, 'Katniss');
3171
+ * ```
3172
+ *
3173
+ * @exampleResponse Getting your data
3174
+ * ```json
3175
+ * {
3176
+ * "data": [
3177
+ * {
3178
+ * "id": 1,
3179
+ * "name": "Harry"
3180
+ * },
3181
+ * {
3182
+ * "id": 2,
3183
+ * "name": "Frodo"
3184
+ * },
3185
+ * {
3186
+ * "id": 3,
3187
+ * "name": "Katniss"
3188
+ * }
3189
+ * ],
3190
+ * "status": 200,
3191
+ * "statusText": "OK"
3192
+ * }
3193
+ * ```
3194
+ *
3195
+ * @example Selecting specific columns
3196
+ * ```js
3197
+ * const { data, error } = await supabase
3198
+ * .from('characters')
3199
+ * .select('name')
3200
+ * ```
3201
+ *
3202
+ * @exampleSql Selecting specific columns
3203
+ * ```sql
3204
+ * create table
3205
+ * characters (id int8 primary key, name text);
3206
+ *
3207
+ * insert into
3208
+ * characters (id, name)
3209
+ * values
3210
+ * (1, 'Frodo'),
3211
+ * (2, 'Harry'),
3212
+ * (3, 'Katniss');
3213
+ * ```
3214
+ *
3215
+ * @exampleResponse Selecting specific columns
3216
+ * ```json
3217
+ * {
3218
+ * "data": [
3219
+ * {
3220
+ * "name": "Frodo"
3221
+ * },
3222
+ * {
3223
+ * "name": "Harry"
3224
+ * },
3225
+ * {
3226
+ * "name": "Katniss"
3227
+ * }
3228
+ * ],
3229
+ * "status": 200,
3230
+ * "statusText": "OK"
3231
+ * }
3232
+ * ```
3233
+ *
3234
+ * @exampleDescription Query referenced tables
3235
+ * If your database has foreign key relationships, you can query related tables too.
3236
+ *
3237
+ * @example Query referenced tables
3238
+ * ```js
3239
+ * const { data, error } = await supabase
3240
+ * .from('orchestral_sections')
3241
+ * .select(`
3242
+ * name,
3243
+ * instruments (
3244
+ * name
3245
+ * )
3246
+ * `)
3247
+ * ```
3248
+ *
3249
+ * @exampleSql Query referenced tables
3250
+ * ```sql
3251
+ * create table
3252
+ * orchestral_sections (id int8 primary key, name text);
3253
+ * create table
3254
+ * instruments (
3255
+ * id int8 primary key,
3256
+ * section_id int8 not null references orchestral_sections,
3257
+ * name text
3258
+ * );
3259
+ *
3260
+ * insert into
3261
+ * orchestral_sections (id, name)
3262
+ * values
3263
+ * (1, 'strings'),
3264
+ * (2, 'woodwinds');
3265
+ * insert into
3266
+ * instruments (id, section_id, name)
3267
+ * values
3268
+ * (1, 2, 'flute'),
3269
+ * (2, 1, 'violin');
3270
+ * ```
3271
+ *
3272
+ * @exampleResponse Query referenced tables
3273
+ * ```json
3274
+ * {
3275
+ * "data": [
3276
+ * {
3277
+ * "name": "strings",
3278
+ * "instruments": [
3279
+ * {
3280
+ * "name": "violin"
3281
+ * }
3282
+ * ]
3283
+ * },
3284
+ * {
3285
+ * "name": "woodwinds",
3286
+ * "instruments": [
3287
+ * {
3288
+ * "name": "flute"
3289
+ * }
3290
+ * ]
3291
+ * }
3292
+ * ],
3293
+ * "status": 200,
3294
+ * "statusText": "OK"
3295
+ * }
3296
+ * ```
3297
+ *
3298
+ * @exampleDescription Query referenced tables with spaces in their names
3299
+ * If your table name contains spaces, you must use double quotes in the `select` statement to reference the table.
3300
+ *
3301
+ * @example Query referenced tables with spaces in their names
3302
+ * ```js
3303
+ * const { data, error } = await supabase
3304
+ * .from('orchestral sections')
3305
+ * .select(`
3306
+ * name,
3307
+ * "musical instruments" (
3308
+ * name
3309
+ * )
3310
+ * `)
3311
+ * ```
3312
+ *
3313
+ * @exampleSql Query referenced tables with spaces in their names
3314
+ * ```sql
3315
+ * create table
3316
+ * "orchestral sections" (id int8 primary key, name text);
3317
+ * create table
3318
+ * "musical instruments" (
3319
+ * id int8 primary key,
3320
+ * section_id int8 not null references "orchestral sections",
3321
+ * name text
3322
+ * );
3323
+ *
3324
+ * insert into
3325
+ * "orchestral sections" (id, name)
3326
+ * values
3327
+ * (1, 'strings'),
3328
+ * (2, 'woodwinds');
3329
+ * insert into
3330
+ * "musical instruments" (id, section_id, name)
3331
+ * values
3332
+ * (1, 2, 'flute'),
3333
+ * (2, 1, 'violin');
3334
+ * ```
3335
+ *
3336
+ * @exampleResponse Query referenced tables with spaces in their names
3337
+ * ```json
3338
+ * {
3339
+ * "data": [
3340
+ * {
3341
+ * "name": "strings",
3342
+ * "musical instruments": [
3343
+ * {
3344
+ * "name": "violin"
3345
+ * }
3346
+ * ]
3347
+ * },
3348
+ * {
3349
+ * "name": "woodwinds",
3350
+ * "musical instruments": [
3351
+ * {
3352
+ * "name": "flute"
3353
+ * }
3354
+ * ]
3355
+ * }
3356
+ * ],
3357
+ * "status": 200,
3358
+ * "statusText": "OK"
3359
+ * }
3360
+ * ```
3361
+ *
3362
+ * @exampleDescription Query referenced tables through a join table
3363
+ * If you're in a situation where your tables are **NOT** directly
3364
+ * related, but instead are joined by a _join table_, you can still use
3365
+ * the `select()` method to query the related data. The join table needs
3366
+ * to have the foreign keys as part of its composite primary key.
3367
+ *
3368
+ * @example Query referenced tables through a join table
3369
+ * ```ts
3370
+ * const { data, error } = await supabase
3371
+ * .from('users')
3372
+ * .select(`
3373
+ * name,
3374
+ * teams (
3375
+ * name
3376
+ * )
3377
+ * `)
3378
+ *
3379
+ * ```
3380
+ *
3381
+ * @exampleSql Query referenced tables through a join table
3382
+ * ```sql
3383
+ * create table
3384
+ * users (
3385
+ * id int8 primary key,
3386
+ * name text
3387
+ * );
3388
+ * create table
3389
+ * teams (
3390
+ * id int8 primary key,
3391
+ * name text
3392
+ * );
3393
+ * -- join table
3394
+ * create table
3395
+ * users_teams (
3396
+ * user_id int8 not null references users,
3397
+ * team_id int8 not null references teams,
3398
+ * -- both foreign keys must be part of a composite primary key
3399
+ * primary key (user_id, team_id)
3400
+ * );
3401
+ *
3402
+ * insert into
3403
+ * users (id, name)
3404
+ * values
3405
+ * (1, 'Kiran'),
3406
+ * (2, 'Evan');
3407
+ * insert into
3408
+ * teams (id, name)
3409
+ * values
3410
+ * (1, 'Green'),
3411
+ * (2, 'Blue');
3412
+ * insert into
3413
+ * users_teams (user_id, team_id)
3414
+ * values
3415
+ * (1, 1),
3416
+ * (1, 2),
3417
+ * (2, 2);
3418
+ * ```
3419
+ *
3420
+ * @exampleResponse Query referenced tables through a join table
3421
+ * ```json
3422
+ * {
3423
+ * "data": [
3424
+ * {
3425
+ * "name": "Kiran",
3426
+ * "teams": [
3427
+ * {
3428
+ * "name": "Green"
3429
+ * },
3430
+ * {
3431
+ * "name": "Blue"
3432
+ * }
3433
+ * ]
3434
+ * },
3435
+ * {
3436
+ * "name": "Evan",
3437
+ * "teams": [
3438
+ * {
3439
+ * "name": "Blue"
3440
+ * }
3441
+ * ]
3442
+ * }
3443
+ * ],
3444
+ * "status": 200,
3445
+ * "statusText": "OK"
3446
+ * }
3447
+ *
3448
+ * ```
3449
+ *
3450
+ * @exampleDescription Query the same referenced table multiple times
3451
+ * If you need to query the same referenced table twice, use the name of the
3452
+ * joined column to identify which join to use. You can also give each
3453
+ * column an alias.
3454
+ *
3455
+ * @example Query the same referenced table multiple times
3456
+ * ```ts
3457
+ * const { data, error } = await supabase
3458
+ * .from('messages')
3459
+ * .select(`
3460
+ * content,
3461
+ * from:sender_id(name),
3462
+ * to:receiver_id(name)
3463
+ * `)
3464
+ *
3465
+ * // To infer types, use the name of the table (in this case `users`) and
3466
+ * // the name of the foreign key constraint.
3467
+ * const { data, error } = await supabase
3468
+ * .from('messages')
3469
+ * .select(`
3470
+ * content,
3471
+ * from:users!messages_sender_id_fkey(name),
3472
+ * to:users!messages_receiver_id_fkey(name)
3473
+ * `)
3474
+ * ```
3475
+ *
3476
+ * @exampleSql Query the same referenced table multiple times
3477
+ * ```sql
3478
+ * create table
3479
+ * users (id int8 primary key, name text);
3480
+ *
3481
+ * create table
3482
+ * messages (
3483
+ * sender_id int8 not null references users,
3484
+ * receiver_id int8 not null references users,
3485
+ * content text
3486
+ * );
3487
+ *
3488
+ * insert into
3489
+ * users (id, name)
3490
+ * values
3491
+ * (1, 'Kiran'),
3492
+ * (2, 'Evan');
3493
+ *
3494
+ * insert into
3495
+ * messages (sender_id, receiver_id, content)
3496
+ * values
3497
+ * (1, 2, '👋');
3498
+ * ```
3499
+ * ```
3500
+ *
3501
+ * @exampleResponse Query the same referenced table multiple times
3502
+ * ```json
3503
+ * {
3504
+ * "data": [
3505
+ * {
3506
+ * "content": "👋",
3507
+ * "from": {
3508
+ * "name": "Kiran"
3509
+ * },
3510
+ * "to": {
3511
+ * "name": "Evan"
3512
+ * }
3513
+ * }
3514
+ * ],
3515
+ * "status": 200,
3516
+ * "statusText": "OK"
3517
+ * }
3518
+ * ```
3519
+ *
3520
+ * @exampleDescription Query nested foreign tables through a join table
3521
+ * You can use the result of a joined table to gather data in
3522
+ * another foreign table. With multiple references to the same foreign
3523
+ * table you must specify the column on which to conduct the join.
3524
+ *
3525
+ * @example Query nested foreign tables through a join table
3526
+ * ```ts
3527
+ * const { data, error } = await supabase
3528
+ * .from('games')
3529
+ * .select(`
3530
+ * game_id:id,
3531
+ * away_team:teams!games_away_team_fkey (
3532
+ * users (
3533
+ * id,
3534
+ * name
3535
+ * )
3536
+ * )
3537
+ * `)
3538
+ *
3539
+ * ```
3540
+ *
3541
+ * @exampleSql Query nested foreign tables through a join table
3542
+ * ```sql
3543
+ * ```sql
3544
+ * create table
3545
+ * users (
3546
+ * id int8 primary key,
3547
+ * name text
3548
+ * );
3549
+ * create table
3550
+ * teams (
3551
+ * id int8 primary key,
3552
+ * name text
3553
+ * );
3554
+ * -- join table
3555
+ * create table
3556
+ * users_teams (
3557
+ * user_id int8 not null references users,
3558
+ * team_id int8 not null references teams,
3559
+ *
3560
+ * primary key (user_id, team_id)
3561
+ * );
3562
+ * create table
3563
+ * games (
3564
+ * id int8 primary key,
3565
+ * home_team int8 not null references teams,
3566
+ * away_team int8 not null references teams,
3567
+ * name text
3568
+ * );
3569
+ *
3570
+ * insert into users (id, name)
3571
+ * values
3572
+ * (1, 'Kiran'),
3573
+ * (2, 'Evan');
3574
+ * insert into
3575
+ * teams (id, name)
3576
+ * values
3577
+ * (1, 'Green'),
3578
+ * (2, 'Blue');
3579
+ * insert into
3580
+ * users_teams (user_id, team_id)
3581
+ * values
3582
+ * (1, 1),
3583
+ * (1, 2),
3584
+ * (2, 2);
3585
+ * insert into
3586
+ * games (id, home_team, away_team, name)
3587
+ * values
3588
+ * (1, 1, 2, 'Green vs Blue'),
3589
+ * (2, 2, 1, 'Blue vs Green');
3590
+ * ```
3591
+ *
3592
+ * @exampleResponse Query nested foreign tables through a join table
3593
+ * ```json
3594
+ * {
3595
+ * "data": [
3596
+ * {
3597
+ * "game_id": 1,
3598
+ * "away_team": {
3599
+ * "users": [
3600
+ * {
3601
+ * "id": 1,
3602
+ * "name": "Kiran"
3603
+ * },
3604
+ * {
3605
+ * "id": 2,
3606
+ * "name": "Evan"
3607
+ * }
3608
+ * ]
3609
+ * }
3610
+ * },
3611
+ * {
3612
+ * "game_id": 2,
3613
+ * "away_team": {
3614
+ * "users": [
3615
+ * {
3616
+ * "id": 1,
3617
+ * "name": "Kiran"
3618
+ * }
3619
+ * ]
3620
+ * }
3621
+ * }
3622
+ * ],
3623
+ * "status": 200,
3624
+ * "statusText": "OK"
3625
+ * }
3626
+ *
3627
+ * ```
3628
+ *
3629
+ * @exampleDescription Filtering through referenced tables
3630
+ * If the filter on a referenced table's column is not satisfied, the referenced
3631
+ * table returns `[]` or `null` but the parent table is not filtered out.
3632
+ * If you want to filter out the parent table rows, use the `!inner` hint
3633
+ *
3634
+ * @example Filtering through referenced tables
3635
+ * ```ts
3636
+ * const { data, error } = await supabase
3637
+ * .from('instruments')
3638
+ * .select('name, orchestral_sections(*)')
3639
+ * .eq('orchestral_sections.name', 'percussion')
3640
+ * ```
3641
+ *
3642
+ * @exampleSql Filtering through referenced tables
3643
+ * ```sql
3644
+ * create table
3645
+ * orchestral_sections (id int8 primary key, name text);
3646
+ * create table
3647
+ * instruments (
3648
+ * id int8 primary key,
3649
+ * section_id int8 not null references orchestral_sections,
3650
+ * name text
3651
+ * );
3652
+ *
3653
+ * insert into
3654
+ * orchestral_sections (id, name)
3655
+ * values
3656
+ * (1, 'strings'),
3657
+ * (2, 'woodwinds');
3658
+ * insert into
3659
+ * instruments (id, section_id, name)
3660
+ * values
3661
+ * (1, 2, 'flute'),
3662
+ * (2, 1, 'violin');
3663
+ * ```
3664
+ *
3665
+ * @exampleResponse Filtering through referenced tables
3666
+ * ```json
3667
+ * {
3668
+ * "data": [
3669
+ * {
3670
+ * "name": "flute",
3671
+ * "orchestral_sections": null
3672
+ * },
3673
+ * {
3674
+ * "name": "violin",
3675
+ * "orchestral_sections": null
3676
+ * }
3677
+ * ],
3678
+ * "status": 200,
3679
+ * "statusText": "OK"
3680
+ * }
3681
+ * ```
3682
+ *
3683
+ * @exampleDescription Querying referenced table with count
3684
+ * You can get the number of rows in a related table by using the
3685
+ * **count** property.
3686
+ *
3687
+ * @example Querying referenced table with count
3688
+ * ```ts
3689
+ * const { data, error } = await supabase
3690
+ * .from('orchestral_sections')
3691
+ * .select(`*, instruments(count)`)
3692
+ * ```
3693
+ *
3694
+ * @exampleSql Querying referenced table with count
3695
+ * ```sql
3696
+ * create table orchestral_sections (
3697
+ * "id" "uuid" primary key default "extensions"."uuid_generate_v4"() not null,
3698
+ * "name" text
3699
+ * );
3700
+ *
3701
+ * create table characters (
3702
+ * "id" "uuid" primary key default "extensions"."uuid_generate_v4"() not null,
3703
+ * "name" text,
3704
+ * "section_id" "uuid" references public.orchestral_sections on delete cascade
3705
+ * );
3706
+ *
3707
+ * with section as (
3708
+ * insert into orchestral_sections (name)
3709
+ * values ('strings') returning id
3710
+ * )
3711
+ * insert into instruments (name, section_id) values
3712
+ * ('violin', (select id from section)),
3713
+ * ('viola', (select id from section)),
3714
+ * ('cello', (select id from section)),
3715
+ * ('double bass', (select id from section));
3716
+ * ```
3717
+ *
3718
+ * @exampleResponse Querying referenced table with count
3719
+ * ```json
3720
+ * [
3721
+ * {
3722
+ * "id": "693694e7-d993-4360-a6d7-6294e325d9b6",
3723
+ * "name": "strings",
3724
+ * "instruments": [
3725
+ * {
3726
+ * "count": 4
3727
+ * }
3728
+ * ]
3729
+ * }
3730
+ * ]
3731
+ * ```
3732
+ *
3733
+ * @exampleDescription Querying with count option
3734
+ * You can get the number of rows by using the
3735
+ * [count](/docs/reference/javascript/select#parameters) option.
3736
+ *
3737
+ * @example Querying with count option
3738
+ * ```ts
3739
+ * const { count, error } = await supabase
3740
+ * .from('characters')
3741
+ * .select('*', { count: 'exact', head: true })
3742
+ * ```
3743
+ *
3744
+ * @exampleSql Querying with count option
3745
+ * ```sql
3746
+ * create table
3747
+ * characters (id int8 primary key, name text);
3748
+ *
3749
+ * insert into
3750
+ * characters (id, name)
3751
+ * values
3752
+ * (1, 'Luke'),
3753
+ * (2, 'Leia'),
3754
+ * (3, 'Han');
3755
+ * ```
3756
+ *
3757
+ * @exampleResponse Querying with count option
3758
+ * ```json
3759
+ * {
3760
+ * "count": 3,
3761
+ * "status": 200,
3762
+ * "statusText": "OK"
3763
+ * }
3764
+ * ```
3765
+ *
3766
+ * @exampleDescription Querying JSON data
3767
+ * You can select and filter data inside of
3768
+ * [JSON](/docs/guides/database/json) columns. Postgres offers some
3769
+ * [operators](/docs/guides/database/json#query-the-jsonb-data) for
3770
+ * querying JSON data.
3771
+ *
3772
+ * @example Querying JSON data
3773
+ * ```ts
3774
+ * const { data, error } = await supabase
3775
+ * .from('users')
3776
+ * .select(`
3777
+ * id, name,
3778
+ * address->city
3779
+ * `)
3780
+ * ```
3781
+ *
3782
+ * @exampleSql Querying JSON data
3783
+ * ```sql
3784
+ * create table
3785
+ * users (
3786
+ * id int8 primary key,
3787
+ * name text,
3788
+ * address jsonb
3789
+ * );
3790
+ *
3791
+ * insert into
3792
+ * users (id, name, address)
3793
+ * values
3794
+ * (1, 'Frodo', '{"city":"Hobbiton"}');
3795
+ * ```
3796
+ *
3797
+ * @exampleResponse Querying JSON data
3798
+ * ```json
3799
+ * {
3800
+ * "data": [
3801
+ * {
3802
+ * "id": 1,
3803
+ * "name": "Frodo",
3804
+ * "city": "Hobbiton"
3805
+ * }
3806
+ * ],
3807
+ * "status": 200,
3808
+ * "statusText": "OK"
3809
+ * }
3810
+ * ```
3811
+ *
3812
+ * @exampleDescription Querying referenced table with inner join
3813
+ * If you don't want to return the referenced table contents, you can leave the parenthesis empty.
3814
+ * Like `.select('name, orchestral_sections!inner()')`.
3815
+ *
3816
+ * @example Querying referenced table with inner join
3817
+ * ```ts
3818
+ * const { data, error } = await supabase
3819
+ * .from('instruments')
3820
+ * .select('name, orchestral_sections!inner(name)')
3821
+ * .eq('orchestral_sections.name', 'woodwinds')
3822
+ * .limit(1)
3823
+ * ```
3824
+ *
3825
+ * @exampleSql Querying referenced table with inner join
3826
+ * ```sql
3827
+ * create table orchestral_sections (
3828
+ * "id" "uuid" primary key default "extensions"."uuid_generate_v4"() not null,
3829
+ * "name" text
3830
+ * );
3831
+ *
3832
+ * create table instruments (
3833
+ * "id" "uuid" primary key default "extensions"."uuid_generate_v4"() not null,
3834
+ * "name" text,
3835
+ * "section_id" "uuid" references public.orchestral_sections on delete cascade
3836
+ * );
3837
+ *
3838
+ * with section as (
3839
+ * insert into orchestral_sections (name)
3840
+ * values ('woodwinds') returning id
3841
+ * )
3842
+ * insert into instruments (name, section_id) values
3843
+ * ('flute', (select id from section)),
3844
+ * ('clarinet', (select id from section)),
3845
+ * ('bassoon', (select id from section)),
3846
+ * ('piccolo', (select id from section));
3847
+ * ```
3848
+ *
3849
+ * @exampleResponse Querying referenced table with inner join
3850
+ * ```json
3851
+ * {
3852
+ * "data": [
3853
+ * {
3854
+ * "name": "flute",
3855
+ * "orchestral_sections": {"name": "woodwinds"}
3856
+ * }
3857
+ * ],
3858
+ * "status": 200,
3859
+ * "statusText": "OK"
3860
+ * }
3861
+ * ```
3862
+ *
3863
+ * @exampleDescription Switching schemas per query
3864
+ * In addition to setting the schema during initialization, you can also switch schemas on a per-query basis.
3865
+ * Make sure you've set up your [database privileges and API settings](/docs/guides/api/using-custom-schemas).
3866
+ *
3867
+ * @example Switching schemas per query
3868
+ * ```ts
3869
+ * const { data, error } = await supabase
3870
+ * .schema('myschema')
3871
+ * .from('mytable')
3872
+ * .select()
3873
+ * ```
3874
+ *
3875
+ * @exampleSql Switching schemas per query
3876
+ * ```sql
3877
+ * create schema myschema;
3878
+ *
3879
+ * create table myschema.mytable (
3880
+ * id uuid primary key default gen_random_uuid(),
3881
+ * data text
3882
+ * );
3883
+ *
3884
+ * insert into myschema.mytable (data) values ('mydata');
3885
+ * ```
3886
+ *
3887
+ * @exampleResponse Switching schemas per query
3888
+ * ```json
3889
+ * {
3890
+ * "data": [
3891
+ * {
3892
+ * "id": "4162e008-27b0-4c0f-82dc-ccaeee9a624d",
3893
+ * "data": "mydata"
3894
+ * }
3895
+ * ],
3896
+ * "status": 200,
3897
+ * "statusText": "OK"
3898
+ * }
3899
+ * ```
3900
+ */
3901
+ select(columns, options) {
3902
+ const { head = false, count } = options !== null && options !== void 0 ? options : {};
3903
+ const method = head ? "HEAD" : "GET";
3904
+ let quoted = false;
3905
+ const cleanedColumns = (columns !== null && columns !== void 0 ? columns : "*").split("").map((c) => {
3906
+ if (/\s/.test(c) && !quoted) return "";
3907
+ if (c === '"') quoted = !quoted;
3908
+ return c;
3909
+ }).join("");
3910
+ const { url, headers } = this.cloneRequestState();
3911
+ url.searchParams.set("select", cleanedColumns);
3912
+ if (count) headers.append("Prefer", `count=${count}`);
3913
+ return new PostgrestFilterBuilder({
3914
+ method,
3915
+ url,
3916
+ headers,
3917
+ schema: this.schema,
3918
+ fetch: this.fetch,
3919
+ urlLengthLimit: this.urlLengthLimit,
3920
+ retry: this.retry
3921
+ });
3922
+ }
3923
+ /**
3924
+ * Perform an INSERT into the table or view.
3925
+ *
3926
+ * By default, inserted rows are not returned. To return it, chain the call
3927
+ * with `.select()`.
3928
+ *
3929
+ * @param values - The values to insert. Pass an object to insert a single row
3930
+ * or an array to insert multiple rows.
3931
+ *
3932
+ * @param options - Named parameters
3933
+ *
3934
+ * @param options.count - Count algorithm to use to count inserted rows.
3935
+ *
3936
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
3937
+ * hood.
3938
+ *
3939
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
3940
+ * statistics under the hood.
3941
+ *
3942
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
3943
+ * numbers.
3944
+ *
3945
+ * @param options.defaultToNull - Make missing fields default to `null`.
3946
+ * Otherwise, use the default value for the column. Only applies for bulk
3947
+ * inserts.
3948
+ *
3949
+ * @category Database
3950
+ *
3951
+ * @example Create a record
3952
+ * ```ts
3953
+ * const { error } = await supabase
3954
+ * .from('countries')
3955
+ * .insert({ id: 1, name: 'Mordor' })
3956
+ * ```
3957
+ *
3958
+ * @exampleSql Create a record
3959
+ * ```sql
3960
+ * create table
3961
+ * countries (id int8 primary key, name text);
3962
+ * ```
3963
+ *
3964
+ * @exampleResponse Create a record
3965
+ * ```json
3966
+ * {
3967
+ * "status": 201,
3968
+ * "statusText": "Created"
3969
+ * }
3970
+ * ```
3971
+ *
3972
+ * @example Create a record and return it
3973
+ * ```ts
3974
+ * const { data, error } = await supabase
3975
+ * .from('countries')
3976
+ * .insert({ id: 1, name: 'Mordor' })
3977
+ * .select()
3978
+ * ```
3979
+ *
3980
+ * @exampleSql Create a record and return it
3981
+ * ```sql
3982
+ * create table
3983
+ * countries (id int8 primary key, name text);
3984
+ * ```
3985
+ *
3986
+ * @exampleResponse Create a record and return it
3987
+ * ```json
3988
+ * {
3989
+ * "data": [
3990
+ * {
3991
+ * "id": 1,
3992
+ * "name": "Mordor"
3993
+ * }
3994
+ * ],
3995
+ * "status": 201,
3996
+ * "statusText": "Created"
3997
+ * }
3998
+ * ```
3999
+ *
4000
+ * @exampleDescription Bulk create
4001
+ * A bulk create operation is handled in a single transaction.
4002
+ * If any of the inserts fail, none of the rows are inserted.
4003
+ *
4004
+ * @example Bulk create
4005
+ * ```ts
4006
+ * const { error } = await supabase
4007
+ * .from('countries')
4008
+ * .insert([
4009
+ * { id: 1, name: 'Mordor' },
4010
+ * { id: 1, name: 'The Shire' },
4011
+ * ])
4012
+ * ```
4013
+ *
4014
+ * @exampleSql Bulk create
4015
+ * ```sql
4016
+ * create table
4017
+ * countries (id int8 primary key, name text);
4018
+ * ```
4019
+ *
4020
+ * @exampleResponse Bulk create
4021
+ * ```json
4022
+ * {
4023
+ * "error": {
4024
+ * "code": "23505",
4025
+ * "details": "Key (id)=(1) already exists.",
4026
+ * "hint": null,
4027
+ * "message": "duplicate key value violates unique constraint \"countries_pkey\""
4028
+ * },
4029
+ * "status": 409,
4030
+ * "statusText": "Conflict"
4031
+ * }
4032
+ * ```
4033
+ */
4034
+ insert(values, { count, defaultToNull = true } = {}) {
4035
+ var _this$fetch;
4036
+ const method = "POST";
4037
+ const { url, headers } = this.cloneRequestState();
4038
+ if (count) headers.append("Prefer", `count=${count}`);
4039
+ if (!defaultToNull) headers.append("Prefer", `missing=default`);
4040
+ if (Array.isArray(values)) {
4041
+ const columns = values.reduce((acc, x) => acc.concat(Object.keys(x)), []);
4042
+ if (columns.length > 0) {
4043
+ const uniqueColumns = [...new Set(columns)].map((column) => `"${column}"`);
4044
+ url.searchParams.set("columns", uniqueColumns.join(","));
4045
+ }
4046
+ }
4047
+ return new PostgrestFilterBuilder({
4048
+ method,
4049
+ url,
4050
+ headers,
4051
+ schema: this.schema,
4052
+ body: values,
4053
+ fetch: (_this$fetch = this.fetch) !== null && _this$fetch !== void 0 ? _this$fetch : fetch,
4054
+ urlLengthLimit: this.urlLengthLimit,
4055
+ retry: this.retry
4056
+ });
4057
+ }
4058
+ /**
4059
+ * Perform an UPSERT on the table or view. Depending on the column(s) passed
4060
+ * to `onConflict`, `.upsert()` allows you to perform the equivalent of
4061
+ * `.insert()` if a row with the corresponding `onConflict` columns doesn't
4062
+ * exist, or if it does exist, perform an alternative action depending on
4063
+ * `ignoreDuplicates`.
4064
+ *
4065
+ * By default, upserted rows are not returned. To return it, chain the call
4066
+ * with `.select()`.
4067
+ *
4068
+ * @param values - The values to upsert with. Pass an object to upsert a
4069
+ * single row or an array to upsert multiple rows.
4070
+ *
4071
+ * @param options - Named parameters
4072
+ *
4073
+ * @param options.onConflict - Comma-separated UNIQUE column(s) to specify how
4074
+ * duplicate rows are determined. Two rows are duplicates if all the
4075
+ * `onConflict` columns are equal.
4076
+ *
4077
+ * @param options.ignoreDuplicates - If `true`, duplicate rows are ignored. If
4078
+ * `false`, duplicate rows are merged with existing rows.
4079
+ *
4080
+ * @param options.count - Count algorithm to use to count upserted rows.
4081
+ *
4082
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
4083
+ * hood.
4084
+ *
4085
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
4086
+ * statistics under the hood.
4087
+ *
4088
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
4089
+ * numbers.
4090
+ *
4091
+ * @param options.defaultToNull - Make missing fields default to `null`.
4092
+ * Otherwise, use the default value for the column. This only applies when
4093
+ * inserting new rows, not when merging with existing rows under
4094
+ * `ignoreDuplicates: false`. This also only applies when doing bulk upserts.
4095
+ *
4096
+ * @example Upsert a single row using a unique key
4097
+ * ```ts
4098
+ * // Upserting a single row, overwriting based on the 'username' unique column
4099
+ * const { data, error } = await supabase
4100
+ * .from('users')
4101
+ * .upsert({ username: 'supabot' }, { onConflict: 'username' })
4102
+ *
4103
+ * // Example response:
4104
+ * // {
4105
+ * // data: [
4106
+ * // { id: 4, message: 'bar', username: 'supabot' }
4107
+ * // ],
4108
+ * // error: null
4109
+ * // }
4110
+ * ```
4111
+ *
4112
+ * @example Upsert with conflict resolution and exact row counting
4113
+ * ```ts
4114
+ * // Upserting and returning exact count
4115
+ * const { data, error, count } = await supabase
4116
+ * .from('users')
4117
+ * .upsert(
4118
+ * {
4119
+ * id: 3,
4120
+ * message: 'foo',
4121
+ * username: 'supabot'
4122
+ * },
4123
+ * {
4124
+ * onConflict: 'username',
4125
+ * count: 'exact'
4126
+ * }
4127
+ * )
4128
+ *
4129
+ * // Example response:
4130
+ * // {
4131
+ * // data: [
4132
+ * // {
4133
+ * // id: 42,
4134
+ * // handle: "saoirse",
4135
+ * // display_name: "Saoirse"
4136
+ * // }
4137
+ * // ],
4138
+ * // count: 1,
4139
+ * // error: null
4140
+ * // }
4141
+ * ```
4142
+ *
4143
+ * @category Database
4144
+ *
4145
+ * @remarks
4146
+ * - Primary keys must be included in `values` to use upsert.
4147
+ *
4148
+ * @example Upsert your data
4149
+ * ```ts
4150
+ * const { data, error } = await supabase
4151
+ * .from('instruments')
4152
+ * .upsert({ id: 1, name: 'piano' })
4153
+ * .select()
4154
+ * ```
4155
+ *
4156
+ * @exampleSql Upsert your data
4157
+ * ```sql
4158
+ * create table
4159
+ * instruments (id int8 primary key, name text);
4160
+ *
4161
+ * insert into
4162
+ * instruments (id, name)
4163
+ * values
4164
+ * (1, 'harpsichord');
4165
+ * ```
4166
+ *
4167
+ * @exampleResponse Upsert your data
4168
+ * ```json
4169
+ * {
4170
+ * "data": [
4171
+ * {
4172
+ * "id": 1,
4173
+ * "name": "piano"
4174
+ * }
4175
+ * ],
4176
+ * "status": 201,
4177
+ * "statusText": "Created"
4178
+ * }
4179
+ * ```
4180
+ *
4181
+ * @example Bulk Upsert your data
4182
+ * ```ts
4183
+ * const { data, error } = await supabase
4184
+ * .from('instruments')
4185
+ * .upsert([
4186
+ * { id: 1, name: 'piano' },
4187
+ * { id: 2, name: 'harp' },
4188
+ * ])
4189
+ * .select()
4190
+ * ```
4191
+ *
4192
+ * @exampleSql Bulk Upsert your data
4193
+ * ```sql
4194
+ * create table
4195
+ * instruments (id int8 primary key, name text);
4196
+ *
4197
+ * insert into
4198
+ * instruments (id, name)
4199
+ * values
4200
+ * (1, 'harpsichord');
4201
+ * ```
4202
+ *
4203
+ * @exampleResponse Bulk Upsert your data
4204
+ * ```json
4205
+ * {
4206
+ * "data": [
4207
+ * {
4208
+ * "id": 1,
4209
+ * "name": "piano"
4210
+ * },
4211
+ * {
4212
+ * "id": 2,
4213
+ * "name": "harp"
4214
+ * }
4215
+ * ],
4216
+ * "status": 201,
4217
+ * "statusText": "Created"
4218
+ * }
4219
+ * ```
4220
+ *
4221
+ * @exampleDescription Upserting into tables with constraints
4222
+ * In the following query, `upsert()` implicitly uses the `id`
4223
+ * (primary key) column to determine conflicts. If there is no existing
4224
+ * row with the same `id`, `upsert()` inserts a new row, which
4225
+ * will fail in this case as there is already a row with `handle` `"saoirse"`.
4226
+ * Using the `onConflict` option, you can instruct `upsert()` to use
4227
+ * another column with a unique constraint to determine conflicts.
4228
+ *
4229
+ * @example Upserting into tables with constraints
4230
+ * ```ts
4231
+ * const { data, error } = await supabase
4232
+ * .from('users')
4233
+ * .upsert({ id: 42, handle: 'saoirse', display_name: 'Saoirse' })
4234
+ * .select()
4235
+ * ```
4236
+ *
4237
+ * @exampleSql Upserting into tables with constraints
4238
+ * ```sql
4239
+ * create table
4240
+ * users (
4241
+ * id int8 generated by default as identity primary key,
4242
+ * handle text not null unique,
4243
+ * display_name text
4244
+ * );
4245
+ *
4246
+ * insert into
4247
+ * users (id, handle, display_name)
4248
+ * values
4249
+ * (1, 'saoirse', null);
4250
+ * ```
4251
+ *
4252
+ * @exampleResponse Upserting into tables with constraints
4253
+ * ```json
4254
+ * {
4255
+ * "error": {
4256
+ * "code": "23505",
4257
+ * "details": "Key (handle)=(saoirse) already exists.",
4258
+ * "hint": null,
4259
+ * "message": "duplicate key value violates unique constraint \"users_handle_key\""
4260
+ * },
4261
+ * "status": 409,
4262
+ * "statusText": "Conflict"
4263
+ * }
4264
+ * ```
4265
+ */
4266
+ upsert(values, { onConflict, ignoreDuplicates = false, count, defaultToNull = true } = {}) {
4267
+ var _this$fetch2;
4268
+ const method = "POST";
4269
+ const { url, headers } = this.cloneRequestState();
4270
+ headers.append("Prefer", `resolution=${ignoreDuplicates ? "ignore" : "merge"}-duplicates`);
4271
+ if (onConflict !== void 0) url.searchParams.set("on_conflict", onConflict);
4272
+ if (count) headers.append("Prefer", `count=${count}`);
4273
+ if (!defaultToNull) headers.append("Prefer", "missing=default");
4274
+ if (Array.isArray(values)) {
4275
+ const columns = values.reduce((acc, x) => acc.concat(Object.keys(x)), []);
4276
+ if (columns.length > 0) {
4277
+ const uniqueColumns = [...new Set(columns)].map((column) => `"${column}"`);
4278
+ url.searchParams.set("columns", uniqueColumns.join(","));
4279
+ }
4280
+ }
4281
+ return new PostgrestFilterBuilder({
4282
+ method,
4283
+ url,
4284
+ headers,
4285
+ schema: this.schema,
4286
+ body: values,
4287
+ fetch: (_this$fetch2 = this.fetch) !== null && _this$fetch2 !== void 0 ? _this$fetch2 : fetch,
4288
+ urlLengthLimit: this.urlLengthLimit,
4289
+ retry: this.retry
4290
+ });
4291
+ }
4292
+ /**
4293
+ * Perform an UPDATE on the table or view.
4294
+ *
4295
+ * By default, updated rows are not returned. To return it, chain the call
4296
+ * with `.select()` after filters.
4297
+ *
4298
+ * @param values - The values to update with
4299
+ *
4300
+ * @param options - Named parameters
4301
+ *
4302
+ * @param options.count - Count algorithm to use to count updated rows.
4303
+ *
4304
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
4305
+ * hood.
4306
+ *
4307
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
4308
+ * statistics under the hood.
4309
+ *
4310
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
4311
+ * numbers.
4312
+ *
4313
+ * @category Database
4314
+ *
4315
+ * @remarks
4316
+ * - `update()` should always be combined with [Filters](/docs/reference/javascript/using-filters) to target the item(s) you wish to update.
4317
+ *
4318
+ * @example Updating your data
4319
+ * ```ts
4320
+ * const { error } = await supabase
4321
+ * .from('instruments')
4322
+ * .update({ name: 'piano' })
4323
+ * .eq('id', 1)
4324
+ * ```
4325
+ *
4326
+ * @exampleSql Updating your data
4327
+ * ```sql
4328
+ * create table
4329
+ * instruments (id int8 primary key, name text);
4330
+ *
4331
+ * insert into
4332
+ * instruments (id, name)
4333
+ * values
4334
+ * (1, 'harpsichord');
4335
+ * ```
4336
+ *
4337
+ * @exampleResponse Updating your data
4338
+ * ```json
4339
+ * {
4340
+ * "status": 204,
4341
+ * "statusText": "No Content"
4342
+ * }
4343
+ * ```
4344
+ *
4345
+ * @example Update a record and return it
4346
+ * ```ts
4347
+ * const { data, error } = await supabase
4348
+ * .from('instruments')
4349
+ * .update({ name: 'piano' })
4350
+ * .eq('id', 1)
4351
+ * .select()
4352
+ * ```
4353
+ *
4354
+ * @exampleSql Update a record and return it
4355
+ * ```sql
4356
+ * create table
4357
+ * instruments (id int8 primary key, name text);
4358
+ *
4359
+ * insert into
4360
+ * instruments (id, name)
4361
+ * values
4362
+ * (1, 'harpsichord');
4363
+ * ```
4364
+ *
4365
+ * @exampleResponse Update a record and return it
4366
+ * ```json
4367
+ * {
4368
+ * "data": [
4369
+ * {
4370
+ * "id": 1,
4371
+ * "name": "piano"
4372
+ * }
4373
+ * ],
4374
+ * "status": 200,
4375
+ * "statusText": "OK"
4376
+ * }
4377
+ * ```
4378
+ *
4379
+ * @exampleDescription Updating JSON data
4380
+ * Postgres offers some
4381
+ * [operators](/docs/guides/database/json#query-the-jsonb-data) for
4382
+ * working with JSON data. Currently, it is only possible to update the entire JSON document.
4383
+ *
4384
+ * @example Updating JSON data
4385
+ * ```ts
4386
+ * const { data, error } = await supabase
4387
+ * .from('users')
4388
+ * .update({
4389
+ * address: {
4390
+ * street: 'Melrose Place',
4391
+ * postcode: 90210
4392
+ * }
4393
+ * })
4394
+ * .eq('address->postcode', 90210)
4395
+ * .select()
4396
+ * ```
4397
+ *
4398
+ * @exampleSql Updating JSON data
4399
+ * ```sql
4400
+ * create table
4401
+ * users (
4402
+ * id int8 primary key,
4403
+ * name text,
4404
+ * address jsonb
4405
+ * );
4406
+ *
4407
+ * insert into
4408
+ * users (id, name, address)
4409
+ * values
4410
+ * (1, 'Michael', '{ "postcode": 90210 }');
4411
+ * ```
4412
+ *
4413
+ * @exampleResponse Updating JSON data
4414
+ * ```json
4415
+ * {
4416
+ * "data": [
4417
+ * {
4418
+ * "id": 1,
4419
+ * "name": "Michael",
4420
+ * "address": {
4421
+ * "street": "Melrose Place",
4422
+ * "postcode": 90210
4423
+ * }
4424
+ * }
4425
+ * ],
4426
+ * "status": 200,
4427
+ * "statusText": "OK"
4428
+ * }
4429
+ * ```
4430
+ */
4431
+ update(values, { count } = {}) {
4432
+ var _this$fetch3;
4433
+ const method = "PATCH";
4434
+ const { url, headers } = this.cloneRequestState();
4435
+ if (count) headers.append("Prefer", `count=${count}`);
4436
+ return new PostgrestFilterBuilder({
4437
+ method,
4438
+ url,
4439
+ headers,
4440
+ schema: this.schema,
4441
+ body: values,
4442
+ fetch: (_this$fetch3 = this.fetch) !== null && _this$fetch3 !== void 0 ? _this$fetch3 : fetch,
4443
+ urlLengthLimit: this.urlLengthLimit,
4444
+ retry: this.retry
4445
+ });
4446
+ }
4447
+ /**
4448
+ * Perform a DELETE on the table or view.
4449
+ *
4450
+ * By default, deleted rows are not returned. To return it, chain the call
4451
+ * with `.select()` after filters.
4452
+ *
4453
+ * @param options - Named parameters
4454
+ *
4455
+ * @param options.count - Count algorithm to use to count deleted rows.
4456
+ *
4457
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
4458
+ * hood.
4459
+ *
4460
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
4461
+ * statistics under the hood.
4462
+ *
4463
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
4464
+ * numbers.
4465
+ *
4466
+ * @category Database
4467
+ *
4468
+ * @remarks
4469
+ * - `delete()` should always be combined with [filters](/docs/reference/javascript/using-filters) to target the item(s) you wish to delete.
4470
+ * - If you use `delete()` with filters and you have
4471
+ * [RLS](/docs/learn/auth-deep-dive/auth-row-level-security) enabled, only
4472
+ * rows visible through `SELECT` policies are deleted. Note that by default
4473
+ * no rows are visible, so you need at least one `SELECT`/`ALL` policy that
4474
+ * makes the rows visible.
4475
+ * - When using `delete().in()`, specify an array of values to target multiple rows with a single query. This is particularly useful for batch deleting entries that share common criteria, such as deleting users by their IDs. Ensure that the array you provide accurately represents all records you intend to delete to avoid unintended data removal.
4476
+ *
4477
+ * @example Delete a single record
4478
+ * ```ts
4479
+ * const response = await supabase
4480
+ * .from('countries')
4481
+ * .delete()
4482
+ * .eq('id', 1)
4483
+ * ```
4484
+ *
4485
+ * @exampleSql Delete a single record
4486
+ * ```sql
4487
+ * create table
4488
+ * countries (id int8 primary key, name text);
4489
+ *
4490
+ * insert into
4491
+ * countries (id, name)
4492
+ * values
4493
+ * (1, 'Mordor');
4494
+ * ```
4495
+ *
4496
+ * @exampleResponse Delete a single record
4497
+ * ```json
4498
+ * {
4499
+ * "status": 204,
4500
+ * "statusText": "No Content"
4501
+ * }
4502
+ * ```
4503
+ *
4504
+ * @example Delete a record and return it
4505
+ * ```ts
4506
+ * const { data, error } = await supabase
4507
+ * .from('countries')
4508
+ * .delete()
4509
+ * .eq('id', 1)
4510
+ * .select()
4511
+ * ```
4512
+ *
4513
+ * @exampleSql Delete a record and return it
4514
+ * ```sql
4515
+ * create table
4516
+ * countries (id int8 primary key, name text);
4517
+ *
4518
+ * insert into
4519
+ * countries (id, name)
4520
+ * values
4521
+ * (1, 'Mordor');
4522
+ * ```
4523
+ *
4524
+ * @exampleResponse Delete a record and return it
4525
+ * ```json
4526
+ * {
4527
+ * "data": [
4528
+ * {
4529
+ * "id": 1,
4530
+ * "name": "Mordor"
4531
+ * }
4532
+ * ],
4533
+ * "status": 200,
4534
+ * "statusText": "OK"
4535
+ * }
4536
+ * ```
4537
+ *
4538
+ * @example Delete multiple records
4539
+ * ```ts
4540
+ * const response = await supabase
4541
+ * .from('countries')
4542
+ * .delete()
4543
+ * .in('id', [1, 2, 3])
4544
+ * ```
4545
+ *
4546
+ * @exampleSql Delete multiple records
4547
+ * ```sql
4548
+ * create table
4549
+ * countries (id int8 primary key, name text);
4550
+ *
4551
+ * insert into
4552
+ * countries (id, name)
4553
+ * values
4554
+ * (1, 'Rohan'), (2, 'The Shire'), (3, 'Mordor');
4555
+ * ```
4556
+ *
4557
+ * @exampleResponse Delete multiple records
4558
+ * ```json
4559
+ * {
4560
+ * "status": 204,
4561
+ * "statusText": "No Content"
4562
+ * }
4563
+ * ```
4564
+ */
4565
+ delete({ count } = {}) {
4566
+ var _this$fetch4;
4567
+ const method = "DELETE";
4568
+ const { url, headers } = this.cloneRequestState();
4569
+ if (count) headers.append("Prefer", `count=${count}`);
4570
+ return new PostgrestFilterBuilder({
4571
+ method,
4572
+ url,
4573
+ headers,
4574
+ schema: this.schema,
4575
+ fetch: (_this$fetch4 = this.fetch) !== null && _this$fetch4 !== void 0 ? _this$fetch4 : fetch,
4576
+ urlLengthLimit: this.urlLengthLimit,
4577
+ retry: this.retry
4578
+ });
4579
+ }
4580
+ };
4581
+ function _typeof(o) {
4582
+ "@babel/helpers - typeof";
4583
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
4584
+ return typeof o$1;
4585
+ } : function(o$1) {
4586
+ return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
4587
+ }, _typeof(o);
4588
+ }
4589
+ function toPrimitive(t, r) {
4590
+ if ("object" != _typeof(t) || !t) return t;
4591
+ var e = t[Symbol.toPrimitive];
4592
+ if (void 0 !== e) {
4593
+ var i = e.call(t, r);
4594
+ if ("object" != _typeof(i)) return i;
4595
+ throw new TypeError("@@toPrimitive must return a primitive value.");
4596
+ }
4597
+ return ("string" === r ? String : Number)(t);
4598
+ }
4599
+ function toPropertyKey(t) {
4600
+ var i = toPrimitive(t, "string");
4601
+ return "symbol" == _typeof(i) ? i : i + "";
4602
+ }
4603
+ function _defineProperty(e, r, t) {
4604
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
4605
+ value: t,
4606
+ enumerable: true,
4607
+ configurable: true,
4608
+ writable: true
4609
+ }) : e[r] = t, e;
4610
+ }
4611
+ function ownKeys(e, r) {
4612
+ var t = Object.keys(e);
4613
+ if (Object.getOwnPropertySymbols) {
4614
+ var o = Object.getOwnPropertySymbols(e);
4615
+ r && (o = o.filter(function(r$1) {
4616
+ return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
4617
+ })), t.push.apply(t, o);
4618
+ }
4619
+ return t;
4620
+ }
4621
+ function _objectSpread2(e) {
4622
+ for (var r = 1; r < arguments.length; r++) {
4623
+ var t = null != arguments[r] ? arguments[r] : {};
4624
+ r % 2 ? ownKeys(Object(t), true).forEach(function(r$1) {
4625
+ _defineProperty(e, r$1, t[r$1]);
4626
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
4627
+ Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
4628
+ });
4629
+ }
4630
+ return e;
4631
+ }
4632
+ var PostgrestClient = class PostgrestClient2 {
4633
+ /**
4634
+ * Creates a PostgREST client.
4635
+ *
4636
+ * @param url - URL of the PostgREST endpoint
4637
+ * @param options - Named parameters
4638
+ * @param options.headers - Custom headers
4639
+ * @param options.schema - Postgres schema to switch to
4640
+ * @param options.fetch - Custom fetch
4641
+ * @param options.timeout - Optional timeout in milliseconds for all requests. When set, requests will automatically abort after this duration to prevent indefinite hangs.
4642
+ * @param options.urlLengthLimit - Maximum URL length in characters before warnings/errors are triggered. Defaults to 8000.
4643
+ * @param options.retry - Enable or disable automatic retries for transient errors.
4644
+ * When enabled, idempotent requests (GET, HEAD, OPTIONS) that fail with network
4645
+ * errors or HTTP 503/520 responses will be automatically retried up to 3 times
4646
+ * with exponential backoff (1s, 2s, 4s). Defaults to `true`.
4647
+ * @example Using supabase-js (recommended)
4648
+ * ```ts
4649
+ * import { createClient } from '@supabase/supabase-js'
4650
+ *
4651
+ * const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
4652
+ * const { data, error } = await supabase.from('profiles').select('*')
4653
+ * ```
4654
+ *
4655
+ * @category Database
4656
+ *
4657
+ * @remarks
4658
+ * - A `timeout` option (in milliseconds) can be set to automatically abort requests that take too long.
4659
+ * - A `urlLengthLimit` option (default: 8000) can be set to control when URL length warnings are included in error messages for aborted requests.
4660
+ *
4661
+ * @example Standalone import for bundle-sensitive environments
4662
+ * ```ts
4663
+ * import { PostgrestClient } from '@supabase/postgrest-js'
4664
+ *
4665
+ * const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', {
4666
+ * headers: { apikey: 'your-publishable-key' },
4667
+ * schema: 'public',
4668
+ * timeout: 30000, // 30 second timeout
4669
+ * })
4670
+ * ```
4671
+ */
4672
+ constructor(url, { headers = {}, schema, fetch: fetch$1, timeout, urlLengthLimit = 8e3, retry } = {}) {
4673
+ this.url = url;
4674
+ this.headers = new Headers(headers);
4675
+ this.schemaName = schema;
4676
+ this.urlLengthLimit = urlLengthLimit;
4677
+ const originalFetch = fetch$1 !== null && fetch$1 !== void 0 ? fetch$1 : globalThis.fetch;
4678
+ if (timeout !== void 0 && timeout > 0) this.fetch = (input, init) => {
4679
+ const controller = new AbortController();
4680
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
4681
+ const existingSignal = init === null || init === void 0 ? void 0 : init.signal;
4682
+ if (existingSignal) {
4683
+ if (existingSignal.aborted) {
4684
+ clearTimeout(timeoutId);
4685
+ return originalFetch(input, init);
4686
+ }
4687
+ const abortHandler = () => {
4688
+ clearTimeout(timeoutId);
4689
+ controller.abort();
4690
+ };
4691
+ existingSignal.addEventListener("abort", abortHandler, { once: true });
4692
+ return originalFetch(input, _objectSpread2(_objectSpread2({}, init), {}, { signal: controller.signal })).finally(() => {
4693
+ clearTimeout(timeoutId);
4694
+ existingSignal.removeEventListener("abort", abortHandler);
4695
+ });
4696
+ }
4697
+ return originalFetch(input, _objectSpread2(_objectSpread2({}, init), {}, { signal: controller.signal })).finally(() => clearTimeout(timeoutId));
4698
+ };
4699
+ else this.fetch = originalFetch;
4700
+ this.retry = retry;
4701
+ }
4702
+ /**
4703
+ * Perform a query on a table or a view.
4704
+ *
4705
+ * @param relation - The table or view name to query
4706
+ *
4707
+ * @category Database
4708
+ */
4709
+ from(relation) {
4710
+ if (!relation || typeof relation !== "string" || relation.trim() === "") throw new Error("Invalid relation name: relation must be a non-empty string.");
4711
+ return new PostgrestQueryBuilder(new URL(`${this.url}/${relation}`), {
4712
+ headers: new Headers(this.headers),
4713
+ schema: this.schemaName,
4714
+ fetch: this.fetch,
4715
+ urlLengthLimit: this.urlLengthLimit,
4716
+ retry: this.retry
4717
+ });
4718
+ }
4719
+ /**
4720
+ * Select a schema to query or perform an function (rpc) call.
4721
+ *
4722
+ * The schema needs to be on the list of exposed schemas inside Supabase.
4723
+ *
4724
+ * @param schema - The schema to query
4725
+ *
4726
+ * @category Database
4727
+ */
4728
+ schema(schema) {
4729
+ return new PostgrestClient2(this.url, {
4730
+ headers: this.headers,
4731
+ schema,
4732
+ fetch: this.fetch,
4733
+ urlLengthLimit: this.urlLengthLimit,
4734
+ retry: this.retry
4735
+ });
4736
+ }
4737
+ /**
4738
+ * Perform a function call.
4739
+ *
4740
+ * @param fn - The function name to call
4741
+ * @param args - The arguments to pass to the function call
4742
+ * @param options - Named parameters
4743
+ * @param options.head - When set to `true`, `data` will not be returned.
4744
+ * Useful if you only need the count.
4745
+ * @param options.get - When set to `true`, the function will be called with
4746
+ * read-only access mode.
4747
+ * @param options.count - Count algorithm to use to count rows returned by the
4748
+ * function. Only applicable for [set-returning
4749
+ * functions](https://www.postgresql.org/docs/current/functions-srf.html).
4750
+ *
4751
+ * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
4752
+ * hood.
4753
+ *
4754
+ * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
4755
+ * statistics under the hood.
4756
+ *
4757
+ * `"estimated"`: Uses exact count for low numbers and planned count for high
4758
+ * numbers.
4759
+ *
4760
+ * @example
4761
+ * ```ts
4762
+ * // For cross-schema functions where type inference fails, use overrideTypes:
4763
+ * const { data } = await supabase
4764
+ * .schema('schema_b')
4765
+ * .rpc('function_a', {})
4766
+ * .overrideTypes<{ id: string; user_id: string }[]>()
4767
+ * ```
4768
+ *
4769
+ * @category Database
4770
+ *
4771
+ * @example Call a Postgres function without arguments
4772
+ * ```ts
4773
+ * const { data, error } = await supabase.rpc('hello_world')
4774
+ * ```
4775
+ *
4776
+ * @exampleSql Call a Postgres function without arguments
4777
+ * ```sql
4778
+ * create function hello_world() returns text as $$
4779
+ * select 'Hello world';
4780
+ * $$ language sql;
4781
+ * ```
4782
+ *
4783
+ * @exampleResponse Call a Postgres function without arguments
4784
+ * ```json
4785
+ * {
4786
+ * "data": "Hello world",
4787
+ * "status": 200,
4788
+ * "statusText": "OK"
4789
+ * }
4790
+ * ```
4791
+ *
4792
+ * @example Call a Postgres function with arguments
4793
+ * ```ts
4794
+ * const { data, error } = await supabase.rpc('echo', { say: '👋' })
4795
+ * ```
4796
+ *
4797
+ * @exampleSql Call a Postgres function with arguments
4798
+ * ```sql
4799
+ * create function echo(say text) returns text as $$
4800
+ * select say;
4801
+ * $$ language sql;
4802
+ * ```
4803
+ *
4804
+ * @exampleResponse Call a Postgres function with arguments
4805
+ * ```json
4806
+ * {
4807
+ * "data": "👋",
4808
+ * "status": 200,
4809
+ * "statusText": "OK"
4810
+ * }
4811
+ *
4812
+ * ```
4813
+ *
4814
+ * @exampleDescription Bulk processing
4815
+ * You can process large payloads by passing in an array as an argument.
4816
+ *
4817
+ * @example Bulk processing
4818
+ * ```ts
4819
+ * const { data, error } = await supabase.rpc('add_one_each', { arr: [1, 2, 3] })
4820
+ * ```
4821
+ *
4822
+ * @exampleSql Bulk processing
4823
+ * ```sql
4824
+ * create function add_one_each(arr int[]) returns int[] as $$
4825
+ * select array_agg(n + 1) from unnest(arr) as n;
4826
+ * $$ language sql;
4827
+ * ```
4828
+ *
4829
+ * @exampleResponse Bulk processing
4830
+ * ```json
4831
+ * {
4832
+ * "data": [
4833
+ * 2,
4834
+ * 3,
4835
+ * 4
4836
+ * ],
4837
+ * "status": 200,
4838
+ * "statusText": "OK"
4839
+ * }
4840
+ * ```
4841
+ *
4842
+ * @exampleDescription Call a Postgres function with filters
4843
+ * Postgres functions that return tables can also be combined with [Filters](/docs/reference/javascript/using-filters) and [Modifiers](/docs/reference/javascript/using-modifiers).
4844
+ *
4845
+ * @example Call a Postgres function with filters
4846
+ * ```ts
4847
+ * const { data, error } = await supabase
4848
+ * .rpc('list_stored_countries')
4849
+ * .eq('id', 1)
4850
+ * .single()
4851
+ * ```
4852
+ *
4853
+ * @exampleSql Call a Postgres function with filters
4854
+ * ```sql
4855
+ * create table
4856
+ * countries (id int8 primary key, name text);
4857
+ *
4858
+ * insert into
4859
+ * countries (id, name)
4860
+ * values
4861
+ * (1, 'Rohan'),
4862
+ * (2, 'The Shire');
4863
+ *
4864
+ * create function list_stored_countries() returns setof countries as $$
4865
+ * select * from countries;
4866
+ * $$ language sql;
4867
+ * ```
4868
+ *
4869
+ * @exampleResponse Call a Postgres function with filters
4870
+ * ```json
4871
+ * {
4872
+ * "data": {
4873
+ * "id": 1,
4874
+ * "name": "Rohan"
4875
+ * },
4876
+ * "status": 200,
4877
+ * "statusText": "OK"
4878
+ * }
4879
+ * ```
4880
+ *
4881
+ * @example Call a read-only Postgres function
4882
+ * ```ts
4883
+ * const { data, error } = await supabase.rpc('hello_world', undefined, { get: true })
4884
+ * ```
4885
+ *
4886
+ * @exampleSql Call a read-only Postgres function
4887
+ * ```sql
4888
+ * create function hello_world() returns text as $$
4889
+ * select 'Hello world';
4890
+ * $$ language sql;
4891
+ * ```
4892
+ *
4893
+ * @exampleResponse Call a read-only Postgres function
4894
+ * ```json
4895
+ * {
4896
+ * "data": "Hello world",
4897
+ * "status": 200,
4898
+ * "statusText": "OK"
4899
+ * }
4900
+ * ```
4901
+ */
4902
+ rpc(fn, args = {}, { head = false, get = false, count } = {}) {
4903
+ var _this$fetch;
4904
+ let method;
4905
+ const url = new URL(`${this.url}/rpc/${fn}`);
4906
+ let body;
4907
+ const _isObject = (v) => v !== null && typeof v === "object" && (!Array.isArray(v) || v.some(_isObject));
4908
+ const _hasObjectArg = head && Object.values(args).some(_isObject);
4909
+ if (_hasObjectArg) {
4910
+ method = "POST";
4911
+ body = args;
4912
+ } else if (head || get) {
4913
+ method = head ? "HEAD" : "GET";
4914
+ Object.entries(args).filter(([_, value]) => value !== void 0).map(([name, value]) => [name, Array.isArray(value) ? `{${value.join(",")}}` : `${value}`]).forEach(([name, value]) => {
4915
+ url.searchParams.append(name, value);
4916
+ });
4917
+ } else {
4918
+ method = "POST";
4919
+ body = args;
4920
+ }
4921
+ const headers = new Headers(this.headers);
4922
+ if (_hasObjectArg) headers.set("Prefer", count ? `count=${count},return=minimal` : "return=minimal");
4923
+ else if (count) headers.set("Prefer", `count=${count}`);
4924
+ return new PostgrestFilterBuilder({
4925
+ method,
4926
+ url,
4927
+ headers,
4928
+ schema: this.schemaName,
4929
+ body,
4930
+ fetch: (_this$fetch = this.fetch) !== null && _this$fetch !== void 0 ? _this$fetch : fetch,
4931
+ urlLengthLimit: this.urlLengthLimit,
4932
+ retry: this.retry
4933
+ });
4934
+ }
4935
+ };
4936
+ export {
4937
+ PostgrestClient as P
4938
+ };