12345678910111213141516 |
- "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1807],{16384:function(e,t,n){function l(e){var t;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"-",{displayName:l,display_name:o,fullName:i,full_name:r,familyName:s,family_name:a,givenName:c,given_name:d,surname:u,lastName:h,last_name:m,firstName:x,first_name:f}=null!==(t=e.raw_user_meta_data)&&void 0!==t?t:{},p=s||a||u||h||m,v=c||d||x||f;return l||o||i||r||v&&p&&"".concat(v," ").concat(p)||n}function o(e){var t;let{avatarUrl:n,avatarURL:l,avatar_url:o,profileUrl:i,profileURL:r,profile_url:s,profileImage:a,profile_image:c,profileImageUrl:d,profileImageURL:u,profile_image_url:h}=null!==(t=e.raw_user_meta_data)&&void 0!==t?t:{};return n||l||o||a||c||i||r||s||d||u||h}n.d(t,{E:function(){return o},G:function(){return l}})},3696:function(e,t,n){n.d(t,{Q:function(){return z},G:function(){return T}});var l=n(52322),o=n(2784),i=n(61786),r=n(32079),s=n(54383),a=n(78232),c=n(24334),d=n(83537),u=n(16384),h=n(34503),m=n(6659);let x=e=>{let{isSelected:t=!1}=e,{resolvedTheme:n}=(0,m.F)();return(0,l.jsx)("svg",{width:"53",height:"17",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,l.jsxs)("g",{opacity:t?"1":".5",children:[(0,l.jsx)("rect",{x:"37.161",y:".53",width:"15",height:"15",rx:"5.5",stroke:"light"===n?"#11181C":"#EDEDED"}),(0,l.jsx)("path",{d:"M1 10.53h32.214",stroke:"#33A7E9",strokeLinecap:"round",strokeDasharray:"2 2"}),(0,l.jsx)("rect",{x:"15.964",y:".53",width:"9",height:"15",rx:"4.5",stroke:"light"===n?"#7E868C":"#7E7E7E"}),(0,l.jsx)("path",{d:"M1 5.53h32.214",stroke:"#33A7E9",strokeLinecap:"round",strokeDasharray:"2 2"})]})})},f=e=>{let{isSelected:t=!1}=e,{resolvedTheme:n}=(0,m.F)();return(0,l.jsx)("svg",{width:"53",height:"17",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,l.jsxs)("g",{opacity:t?"1":".5",children:[(0,l.jsx)("path",{d:"M1 4.994a.5.5 0 0 0 0 1v-1Zm16.218 1h.5v-1h-.5v1ZM1 5.994h1.014v-1H1v1Zm3.04 0h2.028v-1H4.041v1Zm4.056 0h2.027v-1H8.096v1Zm4.054 0h2.027v-1H12.15v1Zm4.055 0h1.013v-1h-1.013v1Z",fill:"light"===n?"#7E868C":"#7E7E7E"}),(0,l.jsx)("path",{d:"m15.92 12.56 9.04-9.04",stroke:"light"===n?"#11181C":"#EDEDED"}),(0,l.jsx)("rect",{x:"15.964",y:".494",width:"9",height:"15",rx:"4.5",stroke:"light"===n?"#11181C":"#EDEDED"}),(0,l.jsx)("rect",{x:"37.161",y:".744",width:"15",height:"15",rx:"5.5",stroke:"light"===n?"#11181C":"#EDEDED"}),(0,l.jsx)("path",{d:"M1 10.494h32.214",stroke:"#33A7E9",strokeLinecap:"round",strokeDasharray:"2 2"}),(0,l.jsx)("path",{d:"M15.96 7.562 22.568.956M19.049 14.885l5.957-5.958",stroke:"light"===n?"#11181C":"#EDEDED"})]})})},p=e=>{let{isSelected:t=!1}=e,{resolvedTheme:n}=(0,m.F)();return(0,l.jsx)("svg",{width:"68",height:"17",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,l.jsxs)("g",{opacity:t?"1":".5",children:[(0,l.jsx)("path",{d:"M15.63 5.156a.5.5 0 1 0 0 1v-1Zm16.218 1h.5v-1h-.5v1Zm-16.218 0h1.013v-1H15.63v1Zm3.04 0h2.028v-1h-2.027v1Zm4.055 0h2.028v-1h-2.028v1Zm4.055 0h2.027v-1H26.78v1Zm4.055 0h1.013v-1h-1.013v1Z",fill:"light"===n?"#7E868C":"#7E7E7E"}),(0,l.jsx)("path",{d:"m30.55 12.722 9.04-9.04",stroke:"light"===n?"#11181C":"#EDEDED"}),(0,l.jsx)("rect",{x:"30.594",y:".656",width:"9",height:"15",rx:"4.5",stroke:"light"===n?"#11181C":"#EDEDED"}),(0,l.jsx)("rect",{x:"51.791",y:".906",width:"15",height:"15",rx:"5.5",stroke:"light"===n?"#11181C":"#EDEDED"}),(0,l.jsx)("path",{d:"M15.63 10.656h32.214",stroke:"#33A7E9",strokeLinecap:"round",strokeDasharray:"2 2"}),(0,l.jsx)("path",{d:"m30.59 7.724 6.607-6.606M33.679 15.047l5.957-5.958",stroke:"light"===n?"#11181C":"#EDEDED"}),(0,l.jsx)("path",{d:"M12.666 14.281v-1.333A2.667 2.667 0 0 0 10 10.28H6a2.667 2.667 0 0 0-2.667 2.667v1.333M8 7.615A2.667 2.667 0 1 0 8 2.28a2.667 2.667 0 0 0 0 5.334Z",stroke:"light"===n?"#11181C":"#EDEDED",strokeLinecap:"round",strokeLinejoin:"round"})]})})};var v=n(76141),g=n(17747),j=function(e){let{label:t,value:n,isSelected:o,onSelectedChange:i,icon:r}=e;return(0,l.jsxs)("label",{className:(0,s.cn)("border border-default rounded-md bg-surface-200 hover:bg-overlay-hover hover:border-control px-4 py-3 w-44 cursor-pointer transition-colors",o&&"border-foreground-muted hover:border-foreground-muted bg-surface-300"),tabIndex:0,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&i(n)},htmlFor:"role-".concat(n),children:[(0,l.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[r&&(0,l.jsx)("div",{children:r}),o&&(0,l.jsxs)("div",{className:"flex items-center justify-center p-0.5 bg-foreground text-background rounded-full",children:["boolean"==typeof o&&(0,l.jsx)(v.Z,{size:12,strokeWidth:"4",className:"text-background"}),"partially"===o&&(0,l.jsx)(g.Z,{size:12,strokeWidth:"4",className:"text-background"})]})]}),(0,l.jsx)("input",{id:"role-".concat(n),type:"radio",name:"role",value:n,checked:!!o,onChange:e=>{i(e.target.value)},className:"invisible h-0 w-0 border-0"}),(0,l.jsxs)("span",{className:(0,s.cn)("text-sm text-foreground-light whitespace-nowrap select-none transition-colors",o&&"text-foreground"),children:[null!=t?t:n," role"]})]})},y=n(53111),b=n(45010),w=n(68806),N=n(8609),E=n(17172),S=n(27570),C=n(56006),k=n(38530),D=n(750),A=n(55283),R=n(93705),L=n(69548),_=()=>{var e,t,n,i;let[s,c]=(0,o.useState)(""),[h,m]=(0,o.useState)("aal1"),x=(0,y.Nr)(s,300),{project:f}=(0,S.d2)(),{data:p,isSuccess:v,isLoading:g,isError:j,error:_,isFetching:T,isPreviousData:z}=(0,k.xY)({projectRef:null==f?void 0:f.ref,connectionString:null==f?void 0:f.connectionString,keywords:x||void 0},{keepPreviousData:!0}),P=(0,d.fN)(),W=(null===(e=P.role)||void 0===e?void 0:e.type)==="postgrest"&&"authenticated"===P.role.role&&P.role.user;function F(e){P.setRole({type:"postgrest",role:"authenticated",user:e,aal:h})}return(0,l.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,l.jsx)("h2",{className:"text-foreground text-base",children:W?"Impersonating ".concat((0,u.G)(W,null!==(i=null!==(n=null!==(t=W.email)&&void 0!==t?t:W.phone)&&void 0!==n?n:W.id)&&void 0!==i?i:"Unknown")):"Impersonate a User"}),(0,l.jsx)("p",{className:"text-sm text-foreground-light max-w-md",children:W?"Results will respect your database's Row-Level Security policies for this user.":"Select a user to respect your database's Row-Level Security policies for that particular user."}),W?(0,l.jsx)(Z,{user:W,onClick:function(){P.setRole(void 0)},isImpersonating:!0,aal:h}):(0,l.jsxs)("div",{className:"flex flex-col gap-2 mt-4",children:[(0,l.jsx)(D.Z,{className:"table-editor-search border-none",icon:z&&T?(0,l.jsx)(b.Z,{className:"animate-spin text-foreground-lighter",size:16,strokeWidth:1.5}):(0,l.jsx)(w.Z,{className:"text-foreground-lighter",size:16,strokeWidth:1.5}),placeholder:"Search for a user..",onChange:e=>c(e.target.value.trim()),value:s,size:"small",actions:s&&(0,l.jsx)(r.z,{size:"tiny",type:"text",className:"px-1",onClick:()=>c(""),children:(0,l.jsx)(N.Z,{size:12,strokeWidth:2})})}),(0,l.jsxs)(A.zF,{children:[(0,l.jsx)(A.wy,{className:"group font-normal p-0 [&[data-state=open]>div>svg]:!-rotate-180",children:(0,l.jsxs)("div",{className:"flex items-center gap-x-1 w-full",children:[(0,l.jsx)("p",{className:"text-xs text-foreground-light group-hover:text-foreground transition",children:"Advanced options"}),(0,l.jsx)(a.Z,{className:"transition-transform duration-200",strokeWidth:1.5,size:14})]})}),(0,l.jsxs)(A.Fw,{className:"mt-1 flex flex-row items-center gap-x-4 text-sm text-foreground-light",children:[(0,l.jsxs)("div",{className:"flex items-center gap-x-1",children:[(0,l.jsx)("h3",{children:"MFA assurance level"}),(0,l.jsxs)(L.b,{side:"top",className:"flex flex-col gap-1 max-w-96",children:[(0,l.jsxs)("p",{children:["AAL1 verifies users via standard login methods, while AAL2 adds a second authentication factor.",(0,l.jsx)("br",{}),"If you're not using MFA, you can leave this on AAL1."]}),(0,l.jsxs)("a",{href:"/docs/guides/auth/auth-mfa",target:"_blank",rel:"noreferrer",className:"flex items-center gap-x-1 opacity-50 hover:opacity-100 transition",children:["Learn more about MFA ",(0,l.jsx)(E.Z,{size:14,strokeWidth:2})]})]})]}),(0,l.jsxs)("div",{className:"flex flex-row items-center gap-x-2 text-xs font-bold",children:[(0,l.jsx)("p",{className:"aal1"===h?void 0:"text-foreground-lighter",children:"AAL1"}),(0,l.jsx)(R.r,{checked:"aal2"===h,onCheckedChange:function(){m(e=>"aal2"===e?"aal1":"aal2")}}),(0,l.jsx)("p",{className:"aal2"===h?void 0:"text-foreground-lighter",children:"AAL2"})]})]})]}),g&&(0,l.jsxs)("div",{className:"flex flex-col gap-2 items-center justify-center h-24",children:[(0,l.jsx)(b.Z,{className:"animate-spin",size:24}),(0,l.jsx)("span",{children:"Loading users..."})]}),j&&(0,l.jsx)(C.Z,{error:_,subject:"Failed to retrieve users"}),v&&(p.users.length>0?(0,l.jsx)("ul",{className:"divide-y max-h-[192px] overflow-y-scroll",role:"list",children:p.users.map(e=>(0,l.jsx)("li",{role:"listitem",children:(0,l.jsx)(I,{user:e,onClick:F})},e.id))}):(0,l.jsx)("div",{className:"flex flex-col gap-2 items-center justify-center h-24",children:(0,l.jsx)("p",{className:"text-foreground-light text-xs",role:"status",children:"No users found"})}))]})]})};let Z=e=>{var t,n,o;let{user:i,onClick:s,isImpersonating:a=!1,aal:d}=e,h=(0,u.E)(i),m=(0,u.G)(i,null!==(o=null!==(n=null!==(t=i.email)&&void 0!==t?t:i.phone)&&void 0!==n?n:i.id)&&void 0!==o?o:"Unknown")+(i.is_anonymous?" (anonymous)":"");return(0,l.jsxs)("div",{className:"flex items-center gap-3 py-2 text-foreground",children:[(0,l.jsxs)("div",{className:"flex items-center gap-4 bg-surface-200 pr-4 pl-0.5 py-0.5 border rounded-full max-w-l",children:[h?(0,l.jsx)("img",{className:"rounded-full w-5 h-5",src:h,alt:m}):(0,l.jsx)("div",{className:"rounded-full w-[21px] h-[21px] bg-surface-300 border border-strong flex items-center justify-center",children:(0,l.jsx)(c.Z,{size:12,strokeWidth:2})}),(0,l.jsxs)("span",{className:"text-sm truncate",children:[m," ",(0,l.jsx)("span",{className:"ml-2 text-foreground-lighter text-xs font-light",children:"aal2"===d?"AAL2":"AAL1"})]})]}),(0,l.jsx)(r.z,{type:"secondary",onClick:()=>{s(i)},children:a?"Stop Impersonating":"Impersonate"})]})},I=e=>{var t,n,o;let{user:i,onClick:s,isImpersonating:a=!1}=e,d=(0,u.E)(i),h=(0,u.G)(i,null!==(o=null!==(n=null!==(t=i.email)&&void 0!==t?t:i.phone)&&void 0!==n?n:i.id)&&void 0!==o?o:"Unknown")+(i.is_anonymous?" (anonymous)":"");return(0,l.jsxs)("div",{className:"flex items-center justify-between py-2 text-foreground",children:[(0,l.jsxs)("div",{className:"flex items-center gap-4",children:[d?(0,l.jsx)("img",{className:"rounded-full w-5 h-5",src:d,alt:h}):(0,l.jsx)("div",{className:"rounded-full w-[21px] h-[21px] bg-surface-300 border text-muted flex items-center justify-center text-background",children:(0,l.jsx)(c.Z,{size:12,strokeWidth:2})}),(0,l.jsx)("span",{className:"text-sm",children:h})]}),(0,l.jsx)(r.z,{type:"secondary",onClick:()=>{s(i)},children:a?"Stop Impersonating":"Impersonate"})]})};var T=e=>{var t;let{serviceRoleLabel:n,padded:i=!0}=e,r=(0,d.fN)(),[a,c]=(0,o.useState)(()=>{var e;return(null===(e=r.role)||void 0===e?void 0:e.type)==="postgrest"&&("anon"===r.role.role||"authenticated"===r.role.role)?r.role.role:"service_role"}),u=!!("authenticated"===a&&(null===(t=r.role)||void 0===t?void 0:t.type)==="postgrest"&&"authenticated"===r.role.role&&r.role.user);function m(e){"service_role"===e&&r.setRole(void 0),"anon"===e&&r.setRole({type:"postgrest",role:e}),c(e)}return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:(0,s.cn)("flex flex-col gap-3",i?"p-5":"pb-5"),children:[(0,l.jsx)("h2",{className:"text-foreground text-base",children:"Database role settings"}),(0,l.jsx)("form",{onSubmit:e=>{e.preventDefault()},children:(0,l.jsxs)("fieldset",{className:"flex gap-3",children:[(0,l.jsx)(j,{value:"service_role",isSelected:"service_role"===a,onSelectedChange:m,label:n,icon:(0,l.jsx)(x,{isSelected:"service_role"===a})}),(0,l.jsx)(j,{value:"anon",isSelected:"anon"===a,onSelectedChange:m,icon:(0,l.jsx)(f,{isSelected:"anon"===a})}),(0,l.jsx)(j,{value:"authenticated",isSelected:"authenticated"===a&&(u||"partially"),onSelectedChange:m,icon:(0,l.jsx)(p,{isSelected:"authenticated"===a})})]})}),"service_role"===a&&(0,l.jsxs)("p",{className:"text-foreground-light text-sm",children:["The default Postgres/superuser role. This has admin privileges.",(0,l.jsx)("br",{}),"It will bypass Row Level Security (RLS) policies."]}),"anon"===a&&(0,l.jsxs)("p",{className:"text-foreground-light text-sm",children:['For "anonymous access". This is the role which the API (PostgREST) will use when a user',(0,l.jsx)("br",{}),"is not logged in. It will respect Row Level Security (RLS) policies."]}),"authenticated"===a&&(0,l.jsxs)("p",{className:"text-foreground-light text-sm",children:['For "authenticated access". This is the role which the API (PostgREST) will use when',(0,l.jsx)("br",{})," a user is logged in. It will respect Row Level Security (RLS) policies."]})]}),"authenticated"===a&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(h.VD,{}),(0,l.jsx)("div",{className:(0,s.cn)("py-5",i&&"px-5"),children:(0,l.jsx)(_,{})})]})]})},z=e=>{var t,n,c,u;let{serviceRoleLabel:h,variant:m="regular",align:x="end"}=e,f=(0,d.fN)(),[p,v]=(0,o.useState)(!1),g=null!==(u=null!==(c=null===(t=f.role)||void 0===t?void 0:t.role)&&void 0!==c?c:h)&&void 0!==u?u:"service role";return(0,l.jsxs)(i.J2,{open:p,onOpenChange:v,modal:!1,children:[(0,l.jsx)(i.xo,{asChild:!0,children:(0,l.jsx)(r.z,{size:"tiny",type:"default",className:(0,s.cn)("h-[26px] pr-3 gap-0","connected-on-right"===m&&"rounded-r-none border-r-0","connected-on-left"===m&&"rounded-l-none border-l-0","connected-on-both"===m&&"rounded-none border-x-0"),children:(0,l.jsxs)("div",{className:"flex items-center gap-1",children:[(0,l.jsx)("span",{className:"text-foreground-muted",children:"role"}),(0,l.jsx)("span",{children:g}),(null===(n=f.role)||void 0===n?void 0:n.type)==="postgrest"&&"authenticated"===f.role.role&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(P,{user:f.role.user}),(0,l.jsx)("span",{className:"text-xs text-foreground-lighter font-light",children:"aal2"===f.role.aal?"AAL2":"AAL1"})]}),(0,l.jsx)(a.Z,{className:"text-muted",strokeWidth:1,size:12})]})})}),(0,l.jsx)(i.yk,{className:"p-0 w-full overflow-hidden",side:"bottom",align:x,children:(0,l.jsx)(T,{serviceRoleLabel:h})})]})};let P=e=>{var t,n,o;let{user:i}=e,r=(0,u.E)(i),s=(0,u.G)(i,null!==(o=null!==(n=null!==(t=i.email)&&void 0!==t?t:i.phone)&&void 0!==n?n:i.id)&&void 0!==o?o:"Unknown");return(0,l.jsxs)("div",{className:"flex gap-1 items-center pl-0.5 pr-1.5 h-[21px] bg-surface-200 rounded-full overflow-hidden",children:[r?(0,l.jsx)("img",{className:"rounded-full w-[18px] h-[18px]",src:r,alt:s}):(0,l.jsx)("div",{className:"rounded-full w-[18px] h-[18px] bg-surface-100 border flex items-center justify-center text-light",children:(0,l.jsx)(c.Z,{size:12,strokeWidth:2})}),(0,l.jsx)("span",{className:"truncate max-w-[84px]",children:s})]})}},16879:function(e,t,n){n.d(t,{Z:function(){return z}});var l=n(52322),o=n(17172),i=n(39097),r=n.n(i),s=n(56958),a=n(48998),c=n(27570),d=n(56742),u=n(85945),h=n(48228),m=n(7820),x=n(18592),f=n(18545),p=n(35432),v=n(83537),g=n(22320);async function j(e){let{projectRef:t,connectionString:n,table:l,filters:o,impersonatedRole:i}=e,r=(0,p.Jh)(function(e){var t;let{table:n,filters:l}=e,o=new m.A().from(n.name,null!==(t=n.schema)&&void 0!==t?t:void 0).delete();return l.filter(e=>e.value&&""!==e.value).forEach(e=>{let t=(0,g.q)(n,e);o=o.filter(e.column,e.operator,t)}),o.toSql()}({table:l,filters:o}),{projectRef:t,role:i}),{result:s}=await (0,x.Rj)({projectRef:t,connectionString:n,sql:r,isRoleImpersonationEnabled:(0,v.Gm)(i)});return s}let y=function(){let{onSuccess:e,onError:t,...n}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},l=(0,u.NL)();return(0,h.D)(e=>j(e),{async onSuccess(t,n,o){let{projectRef:i,table:r}=n;await l.invalidateQueries(f.M.query(i,[r.schema,r.name])),await (null==e?void 0:e(t,n,o))},async onError(e,n,l){void 0===t?s.Am.error("Failed to delete all table rows: ".concat(e.message)):t(e,n,l)},...n})};var b=n(32079),w=n(80435);async function N(e){let{projectRef:t,connectionString:n,table:l,rows:o,impersonatedRole:i}=e,r=(0,p.Jh)(function(e){var t;let{table:n,rows:l}=e,{primaryKeys:o,error:i}=(0,g.h)({table:n});if(i)throw i;let r=new m.A().from(n.name,null!==(t=n.schema)&&void 0!==t?t:void 0).delete();return o.forEach(e=>{let t=l.map(t=>t[e]);r=r.filter(e,"in",t)}),r.toSql()}({table:l,rows:o}),{projectRef:t,role:i}),{result:s}=await (0,x.Rj)({projectRef:t,connectionString:n,sql:r,isRoleImpersonationEnabled:(0,v.Gm)(i)});return s}let E=function(){let{onSuccess:e,onError:t,...n}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=(0,u.NL)();return(0,h.D)(e=>N(e),{async onSuccess(t,n,l){let{projectRef:o,table:r}=n;await i.invalidateQueries(f.M.query(o,[r.schema,r.name])),await (null==e?void 0:e(t,n,l))},async onError(e,n,i){if(void 0===t){let{table:t,rows:i}=n,r=e.message.includes("Please add a primary key column"),a=e.message.includes("violates foreign key constraint"),c=i.length>1;if(a){let n=t.name,i=e.message.split("on table ")[2].replaceAll('"',""),r=e.message.split("foreign key constraint")[1].split("on table")[0].replaceAll('"',""),a=c?"Unable to delete rows as one of them is currently referenced by a foreign key constraint from the table `".concat(i,"`."):"Unable to delete row as it is currently referenced by a foreign key constraint from the table `".concat(i,"`."),d="Set an on delete behavior on the foreign key relation `".concat(r,"` in the `").concat(i,"` table to automatically respond when row(s) are being deleted in the `").concat(n,"` table.");(0,s.Am)(a,{description:(0,l.jsx)(w.U,{content:d,className:"[&>p]:m-0"}),action:(0,l.jsx)("div",{className:"w-full flex gap-x-2 !mx-0 mt-3",children:(0,l.jsx)(b.z,{asChild:!0,type:"outline",icon:(0,l.jsx)(o.Z,{}),children:(0,l.jsx)("a",{target:"_blank",rel:"noreferrer",href:"https://supabase.com/docs/guides/database/postgres/cascade-deletes",children:"Documentation"})})})})}else r?(0,s.Am)("Unable to delete row(s) as table has no primary keys",{description:(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"text-sm text-foreground-light",children:"Add a primary key column to your table first to serve as a unique identifier for each row before updating or deleting the row."}),(0,l.jsx)("div",{className:"mt-3",children:(0,l.jsx)(b.z,{asChild:!0,type:"outline",icon:(0,l.jsx)(o.Z,{}),children:(0,l.jsx)("a",{target:"_blank",rel:"noreferrer",href:"https://supabase.com/docs/guides/database/tables#primary-keys",children:"Documentation"})})})]})}):s.Am.error("Failed to delete table row: ".concat(e.message))}else t(e,n,i)},...n})};async function S(e){let{projectRef:t,connectionString:n,table:l}=e,o=function(e){var t;let{table:n}=e;return new m.A().from(n.name,null!==(t=n.schema)&&void 0!==t?t:void 0).truncate().toSql()}({table:l}),{result:i}=await (0,x.Rj)({projectRef:t,connectionString:n,sql:o});return i}let C=function(){let{onSuccess:e,onError:t,...n}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},l=(0,u.NL)();return(0,h.D)(e=>S(e),{async onSuccess(t,n,o){let{projectRef:i,table:r}=n;await l.invalidateQueries(f.M.query(i,[r.schema,r.name])),await (null==e?void 0:e(t,n,o))},async onError(e,n,l){void 0===t?s.Am.error("Failed to truncate table row: ".concat(e.message)):t(e,n,l)},...n})};var k=n(85768),D=n(57924),A=n(90130),R=n(58870),L=n(45077),_=n(53475),Z=n(12934),I=n(95492),T=n(74138),z=e=>{var t,n,i,u,h,m,x,f,p;let{selectedTable:g,onAfterDeleteTable:j=L.ZT}=e,{project:w}=(0,c.d2)(),N=(0,_._2)(),{selectedSchema:S}=(0,A.B)(),[{filter:z},P]=(0,R.x)({arrayKeys:["filter","sort"]}),W=(0,a.Yb)(z),F=(0,D.AF)({projectRef:null==w?void 0:w.ref,connectionString:null==w?void 0:w.connectionString}),O=e=>{P(t=>{var n,l;let o=null!==(n=null==t?void 0:t.filter)&&void 0!==n?n:[],i=null!==(l=null==t?void 0:t.sort)&&void 0!==l?l:[];return{...t,filter:o.filter(t=>{let[n]=t.split(":");if(n!==e)return t}),sort:i.filter(t=>{let[n]=t.split(":");if(n!==e)return t})}})},{mutate:M}=(0,d.v)({onSuccess:()=>{var e;if((null===(e=N.confirmationDialog)||void 0===e?void 0:e.type)!=="column")return;let t=N.confirmationDialog.column;O(t.name),s.Am.success('Successfully deleted column "'.concat(t.name,'"'))},onError:e=>{var t;if((null===(t=N.confirmationDialog)||void 0===t?void 0:t.type)!=="column")return;let n=N.confirmationDialog.column;s.Am.error("Failed to delete ".concat(n.name,": ").concat(e.message))},onSettled:()=>{N.closeConfirmationDialog()}}),{mutate:q}=(0,k.H)({onSuccess:async()=>{j(await F(S)),s.Am.success('Successfully deleted table "'.concat(null==g?void 0:g.name,'"'))},onError:e=>{s.Am.error("Failed to delete ".concat(null==g?void 0:g.name,": ").concat(e.message))},onSettled:()=>{N.closeConfirmationDialog()}}),{mutate:U}=E({onSuccess:()=>{var e,t,n;(null===(e=N.confirmationDialog)||void 0===e?void 0:e.type)==="row"&&(null===(t=(n=N.confirmationDialog).callback)||void 0===t||t.call(n)),s.Am.success("Successfully deleted selected row(s)")},onSettled:()=>{N.closeConfirmationDialog()}}),{mutate:K}=y({onSuccess:()=>{var e,t,n;(null===(e=N.confirmationDialog)||void 0===e?void 0:e.type)==="row"&&(null===(t=(n=N.confirmationDialog).callback)||void 0===t||t.call(n)),s.Am.success("Successfully deleted selected rows")},onError:e=>{s.Am.error("Failed to delete rows: ".concat(e.message))},onSettled:()=>{N.closeConfirmationDialog()}}),{mutate:V}=C({onSuccess:()=>{var e,t,n;(null===(e=N.confirmationDialog)||void 0===e?void 0:e.type)==="row"&&(null===(t=(n=N.confirmationDialog).callback)||void 0===t||t.call(n)),s.Am.success("Successfully deleted all rows from table")},onError:e=>{s.Am.error("Failed to delete rows: ".concat(e.message))},onSettled:()=>{N.closeConfirmationDialog()}}),Q=(null===(t=N.confirmationDialog)||void 0===t?void 0:t.type)==="row"&&N.confirmationDialog.allRowsSelected,J=(null===(n=N.confirmationDialog)||void 0===n?void 0:n.type)==="row"?N.confirmationDialog.allRowsSelected?null!==(p=N.confirmationDialog.numRows)&&void 0!==p?p:0:N.confirmationDialog.rows.length:0,G=((null===(i=N.confirmationDialog)||void 0===i?void 0:i.type)==="column"||(null===(u=N.confirmationDialog)||void 0===u?void 0:u.type)==="table")&&N.confirmationDialog.isDeleteWithCascade,H=async()=>{var e;if((null===(e=N.confirmationDialog)||void 0===e?void 0:e.type)!=="column"||void 0===w)return;let t=N.confirmationDialog.column;void 0!==t&&M({id:t.id,cascade:G,projectRef:w.ref,connectionString:null==w?void 0:w.connectionString,table:g})},B=async()=>{var e;(null===(e=N.confirmationDialog)||void 0===e?void 0:e.type)==="table"&&void 0!==g&&q({projectRef:null==w?void 0:w.ref,connectionString:null==w?void 0:w.connectionString,schema:g.schema,id:g.id,cascade:G})},X=(0,v.z6)(),Y=async()=>{var e;if(!w)return console.error("Project ref is required");if(!g)return console.error("Selected table required");if((null===(e=N.confirmationDialog)||void 0===e?void 0:e.type)!=="row")return;let t=N.confirmationDialog.rows;if(N.confirmationDialog.allRowsSelected){if(0===W.length){if(void 0!==X())return N.closeConfirmationDialog(),s.Am.error("Table truncation is not supported when impersonating a role");V({projectRef:w.ref,connectionString:w.connectionString,table:g})}else K({projectRef:w.ref,connectionString:w.connectionString,table:g,filters:W,impersonatedRole:X()})}else U({projectRef:w.ref,connectionString:w.connectionString,table:g,rows:t,impersonatedRole:X()})};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(T.Z,{variant:"destructive",size:"small",visible:(null===(h=N.confirmationDialog)||void 0===h?void 0:h.type)==="column",title:'Confirm deletion of column "'.concat((null===(m=N.confirmationDialog)||void 0===m?void 0:m.type)==="column"&&N.confirmationDialog.column.name,'"'),confirmLabel:"Delete",confirmLabelLoading:"Deleting",onCancel:()=>{N.closeConfirmationDialog()},onConfirm:H,children:(0,l.jsxs)("div",{className:"space-y-4",children:[(0,l.jsx)("p",{className:"text-sm text-foreground-light",children:"Are you sure you want to delete the selected column? This action cannot be undone."}),(0,l.jsx)(Z.Z,{label:"Drop column with cascade?",description:"Deletes the column and its dependent objects",checked:G,onChange:()=>N.toggleConfirmationIsWithCascade()}),G&&(0,l.jsxs)(I.bZ,{variant:"warning",title:"Warning: Dropping with cascade may result in unintended consequences",children:[(0,l.jsx)(I.Cd,{children:"All dependent objects will be removed, as will any objects that depend on them, recursively."}),(0,l.jsx)(I.X,{children:(0,l.jsx)(b.z,{asChild:!0,size:"tiny",type:"default",icon:(0,l.jsx)(o.Z,{}),children:(0,l.jsx)(r(),{href:"https://www.postgresql.org/docs/current/ddl-depend.html",target:"_blank",rel:"noreferrer",children:"About dependency tracking"})})})]})]})}),(0,l.jsx)(T.Z,{variant:"destructive",size:"small",visible:(null===(x=N.confirmationDialog)||void 0===x?void 0:x.type)==="table",title:(0,l.jsx)("span",{className:"break-words",children:'Confirm deletion of table "'.concat(null==g?void 0:g.name,'"')}),confirmLabel:"Delete",confirmLabelLoading:"Deleting",onCancel:()=>{N.closeConfirmationDialog()},onConfirm:B,children:(0,l.jsxs)("div",{className:"space-y-4",children:[(0,l.jsx)("p",{className:"text-sm text-foreground-light",children:"Are you sure you want to delete the selected table? This action cannot be undone."}),(0,l.jsx)(Z.Z,{label:"Drop table with cascade?",description:"Deletes the table and its dependent objects",checked:G,onChange:()=>N.toggleConfirmationIsWithCascade(!G)}),G&&(0,l.jsxs)(I.bZ,{variant:"warning",children:[(0,l.jsx)(I.Cd,{children:"Warning: Dropping with cascade may result in unintended consequences"}),(0,l.jsx)(I.X,{children:"All dependent objects will be removed, as will any objects that depend on them, recursively."}),(0,l.jsx)(I.X,{className:"mt-4",children:(0,l.jsx)(b.z,{asChild:!0,size:"tiny",type:"default",icon:(0,l.jsx)(o.Z,{}),children:(0,l.jsx)(r(),{href:"https://www.postgresql.org/docs/current/ddl-depend.html",target:"_blank",rel:"noreferrer",children:"About dependency tracking"})})})]})]})}),(0,l.jsx)(T.Z,{variant:"destructive",size:"small",visible:(null===(f=N.confirmationDialog)||void 0===f?void 0:f.type)==="row",title:(0,l.jsxs)("p",{className:"break-words",children:[(0,l.jsx)("span",{children:"Confirm to delete the selected row"}),(0,l.jsx)("span",{children:J>1&&"s"})]}),confirmLabel:"Delete",confirmLabelLoading:"Deleting",onCancel:()=>N.closeConfirmationDialog(),onConfirm:()=>Y(),children:(0,l.jsx)("div",{className:"space-y-4",children:(0,l.jsxs)("p",{className:"text-sm text-foreground-light",children:[(0,l.jsx)("span",{children:"Are you sure you want to delete "}),(0,l.jsxs)("span",{children:[Q?"all":"the selected"," "]}),(0,l.jsx)("span",{children:J>1&&"".concat(J," ")}),(0,l.jsx)("span",{children:"row"}),(0,l.jsx)("span",{children:J>1&&"s"}),(0,l.jsx)("span",{children:"? This action cannot be undone."})]})})})]})}},46611:function(e,t,n){n.d(t,{l5:function(){return eV.Z},mM:function(){return e2}});var l=n(52322),o=n(59491),i=n(85945),r=n(55281),s=n.n(r),a=n(84336),c=n.n(a),d=n(17172),u=n(5632),h=n(56958),m=n(99959),x=n(2784),f=n(28846),p=n(52797),v=n(28316),g=n(27570),j=n(57142),y=n(58870),b=n(83537),w=n(53475),N=n(48998),E=n(71878),S=n(64568);function C(e,t){return e.indexOf(t)>=0}function k(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],[l,o]=x.useState(),i=l=>{if(!e||C(t,l.target.nodeName)||C(n,l.target.className))return;let i=l.metaKey&&l.shiftKey?"Command+Shift+".concat(l.key):l.metaKey?"Command+".concat(l.key):l.shiftKey&&"Enter"===l.key?"Shift+".concat(l.key):l.ctrlKey&&l.key?"Control+".concat(l.key):l.key;e[i]&&(i.includes("+")?(l.preventDefault(),e[i](l),o(null)):(o(l.key),l.preventDefault()))},r=t=>{e&&e[t.key]&&l===t.key&&(t.preventDefault(),e[t.key](t),o(null))};x.useEffect(()=>(window.addEventListener("keydown",i),window.addEventListener("keyup",r),()=>{window.removeEventListener("keydown",i),window.removeEventListener("keyup",r)}))}function D(e){let{gridRef:t}=e,{rows:n,gridColumns:l,selectedCellPosition:o}=(0,E.Qq)(),[i,r]=x.useState("Command");return x.useEffect(()=>{var e,t;r("windows"==((null===(e=navigator)||void 0===e?void 0:e.appVersion.indexOf("Win"))!==-1?"windows":(null===(t=navigator)||void 0===t?void 0:t.appVersion.indexOf("Mac"))!==-1?"macos":"unknown")?"Control":"Command")},[]),k({["".concat(i,"+ArrowUp")]:e=>{if(e.stopPropagation(),o){var n;let e={idx:null!==(n=null==o?void 0:o.idx)&&void 0!==n?n:0,rowIdx:0};t.current.selectCell(e)}else t.current.scrollToCell({rowIdx:Number(0)})},["".concat(i,"+ArrowDown")]:e=>{if(e.stopPropagation(),o){var l;let e={idx:null!==(l=null==o?void 0:o.idx)&&void 0!==l?l:0,rowIdx:n.length>1?n.length-1:0};t.current.selectCell(e)}else t.current.scrollToCell({rowIdx:Number(n.length)})},["".concat(i,"+ArrowLeft")]:e=>{var n;e.stopPropagation();let i={idx:l.filter(e=>e.frozen).length,rowIdx:null!==(n=null==o?void 0:o.rowIdx)&&void 0!==n?n:0};t.current.selectCell(i)},["".concat(i,"+ArrowRight")]:e=>{var n,i;e.stopPropagation(),null===(n=t.current)||void 0===n||n.selectCell({idx:l.length-1,rowIdx:null!==(i=null==o?void 0:o.rowIdx)&&void 0!==i?i:0})},["".concat(i,"+c")]:e=>{if(e.stopPropagation(),o){let{idx:e,rowIdx:r}=o;if(e>0){var t,i;let o=l[e].key,s=null!==(i=null===(t=n[r])||void 0===t?void 0:t[o])&&void 0!==i?i:"",a=(0,S.Lw)(s);(0,S.vQ)(a)}}}},["INPUT","TEXTAREA","SELECT"]),null}var A=n(55600),R=n(38264),L=n(37603),_=n(65802),Z=n(42991),I=n(30557),T=n(19278),z=n(63480),P=n(78976),W=n(86305),F=n(32079),O=n(4419),M=n(2322),q=n(74138),U=n(62591);let K=e=>{if(0===e)return"0";let t=Math.floor(Math.log(e)/Math.log(1e3)),n=t>4?"T":["","K","M","B","T"][t];return"".concat((e/Math.pow(1e3,t>4?4:t)).toFixed(1)).concat(n)},V=[{value:100,label:"100 rows"},{value:500,label:"500 rows"},{value:1e3,label:"1000 rows"}];var Q=()=>{var e,t,n,o;let{id:i}=(0,m.UO)(),r=i?Number(i):void 0,s=(0,E.Qq)(),a=(0,E.I0)(),{project:c}=(0,g.d2)(),d=(0,w._2)(),{data:u}=(0,Z.Z)(r),h=null!==(e=null==u?void 0:u.live_rows_estimate)&&void 0!==e?e:null,[{filter:f}]=(0,y.x)({arrayKeys:["filter"]}),p=(0,N.Yb)(f),v=d.page,j=null!==(t=s.table)&&void 0!==t?t:void 0,S=(0,b.fN)(),[C,k]=(0,x.useState)(!1),[D,A]=(0,x.useState)(!1),[R,L]=(0,x.useState)(!1),{data:_,isLoading:I,isSuccess:Q,isError:J,isFetching:G}=(0,W.HS)({queryKey:[null==j?void 0:j.schema,null==j?void 0:j.name,"count-estimate"],projectRef:null==c?void 0:c.ref,connectionString:null==c?void 0:c.connectionString,table:j,filters:p,enforceExactCount:d.enforceExactCount,impersonatedRole:S.role},{keepPreviousData:!0,onSuccess(e){a({type:"SET_ROWS_COUNT",payload:e.count})}}),H=(null==_?void 0:_.is_estimate)?K(_.count):null==_?void 0:_.count.toLocaleString(),B=Math.ceil((null!==(n=null==_?void 0:_.count)&&void 0!==n?n:0)/d.rowsPerPage),X=(null!==(o=null==_?void 0:_.count)&&void 0!==o?o:0)>0?B:1,Y=()=>{ee(),a({type:"SELECTED_ROWS_CHANGE",payload:{selectedRows:new Set}})},$=()=>{et(),a({type:"SELECTED_ROWS_CHANGE",payload:{selectedRows:new Set}})},ee=()=>{let e=v-1;d.setPage(e)},et=()=>{let e=v+1;d.setPage(e)};return(0,x.useEffect)(()=>{v&&v>X&&d.setPage(X)},[v,X]),(0,x.useEffect)(()=>{void 0!==r&&d.setEnforceExactCount(null!==h&&h<=W.Fi)},[r]),(0,l.jsxs)("div",{className:"flex items-center gap-x-4",children:[I&&(0,l.jsx)("p",{className:"text-sm text-foreground-light",children:"Loading records count..."}),Q&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,l.jsx)(F.z,{icon:(0,l.jsx)(T.Z,{}),type:"outline",className:"px-1.5",disabled:v<=1||I,onClick:()=>{v>1&&(s.selectedRows.size>=1?A(!0):ee())}}),(0,l.jsx)("p",{className:"text-xs text-foreground-light",children:"Page"}),(0,l.jsx)("div",{className:"w-12",children:(0,l.jsx)(O.Z,{size:"tiny",value:v,onChange:e=>{let t=e.target.value,n=Number(t)>B?B:Number(t);d.setPage(n||1)},style:{width:"3rem"},min:1,max:B})}),(0,l.jsxs)("p",{className:"text-xs text-foreground-light",children:["of ",X.toLocaleString()]}),(0,l.jsx)(F.z,{icon:(0,l.jsx)(z.Z,{}),type:"outline",className:"px-1.5",disabled:v>=B||I,onClick:()=>{v<B&&(s.selectedRows.size>=1?k(!0):et())}}),(0,l.jsx)(U.F,{options:V,onSelect:e=>{let t=Number(e);d.setRowsPerPage(isNaN(t)?100:t)},side:"top",align:"start",children:(0,l.jsx)(F.z,{asChild:!0,type:"outline",style:{padding:"3px 10px"},children:(0,l.jsx)("span",{children:"".concat(d.rowsPerPage," rows")})})})]}),(0,l.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,l.jsxs)("p",{className:"text-xs text-foreground-light",children:["".concat(H," ").concat(0===_.count||_.count>1?"records":"record")," ",_.is_estimate?"(estimated)":""]}),_.is_estimate&&(0,l.jsxs)(M.u,{children:[(0,l.jsx)(M.aJ,{asChild:!0,children:(0,l.jsx)(F.z,{size:"tiny",type:"text",className:"px-1.5",loading:G,icon:(0,l.jsx)(P.Z,{}),onClick:()=>{null===h||_.count>W.Fi?L(!0):d.setEnforceExactCount(!0)}})}),(0,l.jsxs)(M._v,{side:"top",className:"w-72",children:["This is an estimated value as your table has more than"," ",W.Fi.toLocaleString()," rows. ",(0,l.jsx)("br",{}),(0,l.jsx)("span",{className:"text-brand",children:"Click to retrieve the exact count of the table."})]})]})]})]}),J&&(0,l.jsx)("p",{className:"text-sm text-foreground-light",children:"Error fetching records count. Please refresh the page."}),(0,l.jsx)(q.Z,{visible:D,title:"Confirm moving to previous page",confirmLabel:"Confirm",onCancel:()=>A(!1),onConfirm:()=>{Y()},children:(0,l.jsx)("p",{className:"text-sm text-foreground-light",children:"The currently selected lines will be deselected, do you want to proceed?"})}),(0,l.jsx)(q.Z,{visible:C,title:"Confirm moving to next page",confirmLabel:"Confirm",onCancel:()=>k(!1),onConfirm:()=>{$()},children:(0,l.jsx)("p",{className:"text-sm text-foreground-light",children:"The currently selected lines will be deselected, do you want to proceed?"})}),(0,l.jsx)(q.Z,{variant:"warning",visible:R,title:"Confirm to fetch exact count for table",confirmLabel:"Retrieve exact count",onCancel:()=>L(!1),onConfirm:()=>{d.setEnforceExactCount(!0),L(!1)},children:(0,l.jsx)("p",{className:"text-sm text-foreground-light",children:null===h?"If your table has a row count of greater than ".concat(W.Fi.toLocaleString()," rows,\n retrieving the exact count of the table may cause performance issues on your database."):"Your table has a row count of greater than ".concat(W.Fi.toLocaleString()," rows, and\n retrieving the exact count of the table may cause performance issues on your database.")})})]})},J=e=>{let{isRefetching:t}=e,{id:n}=(0,m.UO)(),o=n?Number(n):void 0,{data:i}=(0,Z.Z)(o),r=(0,_.Z)(null==i?void 0:i.id),[{view:s="data"},a]=(0,y.x)(),c=(null==r?void 0:r.type)===L.l.VIEW||(null==r?void 0:r.type)===L.l.MATERIALIZED_VIEW,d=(null==r?void 0:r.type)===L.l.TABLE;return(0,l.jsxs)(A.x,{children:["data"===s&&(0,l.jsx)(Q,{}),(0,l.jsxs)("div",{className:"ml-auto flex items-center gap-x-2",children:[i&&"data"===s&&(0,l.jsx)(I.Z,{table:i,isRefetching:t}),(c||d)&&(0,l.jsx)(R.Z,{width:75,options:["definition","data"],activeOption:s,borderOverride:"border",onClickOption:e=>{"data"===e?a({view:void 0}):a({view:e})}})]})]})},G=n(79147),H=n(47370),B=n(64018),X=n(56006),Y=n(41679),$=n(75153),ee=n(82955),et=n(54383),en=n(71623),el=n(88264);function eo(e,t){let{show:n}=(0,en.av)();return(0,l.jsx)(H.X2,{...t,onContextMenu:function(e){n(e,{id:el.ep,props:{rowIdx:t.rowIdx}})}},e)}var ei=n(66864);let er=e=>{var t;return null!==(t=null==e?void 0:e.idx)&&void 0!==t?t:-1},es=(0,G.Z)((e,t,n)=>{n({type:"UPDATE_COLUMN_SIZE",payload:{index:e,width:Math.round(t)}})},500),ea=(0,B.X$)((0,x.forwardRef)((e,t)=>{var n;let{width:o,height:i,containerClass:r,gridClass:s,rowClass:a,rows:c,error:d,isLoading:u,isSuccess:h,isError:m,filters:f,setParams:p,updateRow:v,onAddRow:j,onImportData:y,onEditForeignKeyColumnValue:b}=e,w=(0,E.I0)(),N=(0,E.Qq)();async function C(e,t){let n=e[t.indexes[0]],l=c.find(e=>e.idx==n.idx),o=Object.keys(n).find(e=>n[e]!==l[e]);o&&v(l,{[o]:n[o]})}let D=(0,x.useRef)(null);function A(){var e,t,n,l;let o=null===(l=D.current)||void 0===l?void 0:null===(n=l.row)||void 0===n?void 0:n[null===(t=D.current)||void 0===t?void 0:null===(e=t.column)||void 0===e?void 0:e.key],i=(0,S.Lw)(o);i&&(0,ee.vQ)(i)}k({"Command+c":e=>{e.stopPropagation(),A()},"Control+c":e=>{e.stopPropagation(),A()}},["INPUT","TEXTAREA"]);let R=N.table,{project:L}=(0,g.d2)(),{data:_}=(0,$.X)({projectRef:null==L?void 0:L.ref,connectionString:null==L?void 0:L.connectionString,schema:null!==(n=null==R?void 0:R.schema)&&void 0!==n?n:void 0}),Z=()=>{p(e=>({...e,filter:[]}))};return(0,l.jsx)("div",{className:(0,et.cn)("flex flex-col",r),style:{width:o||"100%",height:i||"50vh"},children:(0,l.jsx)(H.ZP,{ref:t,className:"".concat(s," flex-grow"),rowClass:a,columns:N.gridColumns,rows:null!=c?c:[],renderers:{renderRow:eo,noRowsFallback:(0,l.jsxs)("div",{style:{width:"calc(100vw - 255px - 55px)"},children:[u&&(0,l.jsx)("div",{className:"p-2 col-span-full",children:(0,l.jsx)(Y.A,{})}),m&&(0,l.jsx)("div",{className:"p-2 col-span-full",children:(0,l.jsx)(X.Z,{error:d,subject:"Failed to retrieve rows from table"})}),h&&(0,l.jsx)(l.Fragment,{children:0===(null!=f?f:[]).length?(0,l.jsxs)("div",{style:{height:"calc(100% - 35px)"},className:"flex flex-col items-center justify-center col-span-full",children:[(0,l.jsx)("p",{className:"text-sm text-light",children:"This table is empty"}),void 0!==j&&void 0!==y&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("p",{className:"text-sm text-light mt-1",children:"Add rows to your table to get started."}),(0,l.jsx)("div",{className:"flex items-center space-x-2 mt-4",children:void 0!==j&&void 0!==y&&(0,l.jsx)(F.z,{type:"default",onClick:y,children:"Import data via CSV"})})]})]}):(0,l.jsxs)("div",{style:{height:"calc(100% - 35px)"},className:"flex flex-col items-center justify-center col-span-full",children:[(0,l.jsx)("p",{className:"text-sm text-light",children:"The filters applied has returned no results from this table"}),(0,l.jsx)("div",{className:"flex items-center space-x-2 mt-4",children:(0,l.jsx)(F.z,{type:"default",onClick:()=>Z(),children:"Remove all filters"})})]})})]})},rowKeyGetter:er,selectedRows:N.selectedRows,onColumnResize:function(e,t){es(e,t,w)},onRowsChange:C,onSelectedCellChange:function(e){D.current=e,w({type:"SELECTED_CELL_CHANGE",payload:{position:{idx:e.column.idx,rowIdx:e.rowIdx}}})},onSelectedRowsChange:function(e){w({type:"SELECTED_ROWS_CHANGE",payload:{selectedRows:e}})},onCellDoubleClick:e=>(function(e,t){let n=function(e){var t,n;let{targetTableSchema:l,targetTableName:o,targetColumnName:i}=null!==(n=null==R?void 0:null===(t=R.columns.find(t=>t.name==e))||void 0===t?void 0:t.foreignKey)&&void 0!==n?n:{},r=null==_?void 0:_.find(t=>t.source_schema===(null==R?void 0:R.schema)&&t.source_table===(null==R?void 0:R.name)&&t.source_columns.includes(e)&&t.target_schema===l&&t.target_table===o&&t.target_columns.includes(i));return void 0!==r?(0,ei.S)([r])[0]:void 0}(t.name);n&&b({foreignKey:n,row:e,column:t})})(e.row,e.column)})})}));var ec=n(96048),ed=n(87115),eu=n(52993);async function eh(e,t,n,l,o){var i,r;let s=e.projectRef?function(e,t,n){let l=(0,N.x4)(ed.E_,e),o=localStorage.getItem(l);if(o)return JSON.parse(o)[n&&"public"!=n?"".concat(n,".").concat(t):t]}(e.projectRef,e.table.name,e.table.schema):void 0;if(!t.isInitialComplete&&void 0===l&&void 0===o&&((null==s?void 0:s.sorts)||(null==s?void 0:s.filters)))return{savedState:{sorts:s.sorts,filters:s.filters}};let a=(0,eu.cv)(e.table,{projectRef:e.projectRef,tableId:e.tableId,editable:e.editable,defaultWidth:null===(i=e.gridProps)||void 0===i?void 0:i.defaultColumnWidth,onAddColumn:e.editable?e.onAddColumn:void 0,onExpandJSONEditor:e.onExpandJSONEditor,onExpandTextEditor:e.onExpandTextEditor});return n({type:"INIT_TABLE",payload:{table:e.table,gridProps:e.gridProps,gridColumns:a,savedState:s,editable:e.editable,onError:null!==(r=e.onError)&&void 0!==r?r:e=>{console.error("Supabase grid error: ",e)}}}),{savedState:{}}}let em=e=>{let t=(0,N.cc)(e);return(0,l.jsx)(E.g3,{children:(0,l.jsx)(f.W,{backend:p.PD,context:window,children:(0,l.jsx)(ex,{...t})})})},ex=e=>{var t,n;let{editable:o,projectRef:i,gridProps:r,headerActions:s,showCustomChildren:a,customHeader:c,children:d,onAddRow:u,onAddColumn:h,updateTableRow:f,onEditForeignKeyColumnValue:p,onImportData:S}=e,{id:C}=(0,m.UO)(),k=(0,E.I0)(),A=(0,E.Qq)(),R=(0,w._2)(),L=(0,x.useRef)(null),[_,Z]=(0,x.useState)(!1),[{sort:I,filter:T},z]=(0,y.x)({arrayKeys:["sort","filter"]}),P=(0,N.rg)(e.table.name,I),W=(0,N.Yb)(T),F=(0,b.fN)(),{project:O}=(0,g.d2)(),{data:M,error:q,isSuccess:U,isError:K,isLoading:V,isRefetching:Q}=(0,j.KK)({queryKey:[e.table.schema,e.table.name],projectRef:null==O?void 0:O.ref,connectionString:null==O?void 0:O.connectionString,table:e.table,sorts:P,filters:W,page:R.page,limit:R.rowsPerPage,impersonatedRole:F.role},{keepPreviousData:!0,retryDelay:(e,t)=>{var n;return(t&&(null===(n=t.message)||void 0===n?void 0:n.includes("does not exist"))&&z(e=>({...e,sort:void 0})),e>3)?1/0:5e3},onSuccess(e){k({type:"SET_ROWS_COUNT",payload:e.rows.length})}});return(0,x.useEffect)(()=>{_||Z(!0)},[]),(0,x.useEffect)(()=>{_&&k({type:"UPDATE_FILTERS",payload:{}})},[JSON.stringify(W)]),(0,x.useEffect)(()=>{_&&k({type:"UPDATE_SORTS",payload:{}})},[JSON.stringify(P)]),(0,x.useEffect)(()=>{A.isInitialComplete&&i&&A.table&&(0,N.Tf)(A,i,I,T)},[A.table,A.isInitialComplete,A.gridColumns,JSON.stringify(P),JSON.stringify(W),i]),(0,x.useEffect)(()=>{k({type:"INIT_CALLBACK",payload:{...e}})},[]),(0,x.useEffect)(()=>{let t=async()=>{let{savedState:t}=await eh({...e,tableId:C},A,k,I,T);(t.sorts||t.filters)&&z(e=>({...e,...t.sorts&&{sort:t.sorts},...t.filters&&{filter:t.filters}}))},n=JSON.stringify(e.table)!==JSON.stringify(A.table);(!A.table||n)&&t()},[A.table,e.table,e.schema]),(0,l.jsxs)("div",{className:"sb-grid",children:[(0,l.jsx)(ec.ZP,{table:e.table,sorts:P,filters:W,onAddRow:o?u:void 0,onAddColumn:o?h:void 0,onImportData:o?S:void 0,headerActions:s,customHeader:c}),a&&void 0!==d?(0,l.jsx)(l.Fragment,{children:d}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(ea,{ref:L,...r,rows:null!==(t=null==M?void 0:M.rows)&&void 0!==t?t:[],error:q,isLoading:V,isSuccess:U,isError:K,filters:W,setParams:z,updateRow:f,onAddRow:u,onImportData:S,onEditForeignKeyColumnValue:p}),(0,l.jsx)(J,{isRefetching:Q}),(0,l.jsx)(D,{gridRef:L})]}),_&&(0,v.createPortal)((0,l.jsx)(el.q4,{rows:null!==(n=null==M?void 0:M.rows)&&void 0!==n?n:[]}),document.body)]})};var ef=n(25733),ep=n(68871),ev=n(18545),eg=n(61371),ej=n(87175),ey=n(38591),eb=n(11354),ew=n(45077),eN=n(24990),eE=n(34548),eS=n(16826),eC=n(64273);/**
- * @license lucide-react v0.436.0 - ISC
- *
- * This source code is licensed under the ISC license.
- * See the LICENSE file in the root directory of this source tree.
- */let ek=(0,n(46145).Z)("MousePointer2",[["path",{d:"M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z",key:"edeuup"}]]);var eD=n(39097),eA=n.n(eD),eR=n(34420),eL=n(53449),e_=n(49521),eZ=n(60028),eI=n(26764),eT=n(52903),ez=n(92270),eP=n(40654),eW=n(61786),eF=n(73831),eO=n(3696),eM=e=>{var t;let{table:n}=e,i=(0,_.Z)(null==n?void 0:n.id),{ref:r}=(0,m.UO)(),{project:s}=(0,g.d2)(),{data:a=[]}=(0,eT.U)({projectRef:null==s?void 0:s.ref}),c=(null==i?void 0:i.type)===L.l.TABLE,d=(null==i?void 0:i.type)===L.l.MATERIALIZED_VIEW,u=(null==i?void 0:i.type)===L.l.VIEW,f=(null==i?void 0:i.type)===L.l.FOREIGN_TABLE,p=(0,eP.N)("realtime:all"),v=eb.F.includes(n.schema),{mutate:j}=(0,ez.V)({onError:e=>{h.Am.error("Failed to toggle RLS: ".concat(e.message))},onSettled:()=>{J()}}),[y,b]=(0,x.useState)(!1),[w,N]=(0,x.useState)(!1),[E,S]=(0,x.useState)(!1),C=null==s?void 0:s.ref,{data:k}=(0,e_.r)({projectRef:null==s?void 0:s.ref,connectionString:null==s?void 0:s.connectionString}),D=(null!=k?k:[]).filter(e=>e.schema===n.schema&&e.table===n.name),{data:A}=(0,eZ.z)({projectRef:null==s?void 0:s.ref,connectionString:null==s?void 0:s.connectionString}),R=(null!=A?A:[]).find(e=>"supabase_realtime"===e.name),Z=null!==(t=null==R?void 0:R.tables)&&void 0!==t?t:[],I=Z.some(e=>e.id===(null==n?void 0:n.id)),{mutate:T,isLoading:z}=(0,eI.u)({onSuccess:()=>{b(!1)},onError:e=>{h.Am.error("Failed to toggle realtime for ".concat(n.name,": ").concat(e.message))}}),P=(0,ej.Xo)(o.KA.TENANT_SQL_ADMIN_WRITE,"tables"),W=(0,ej.Xo)(o.KA.TENANT_SQL_ADMIN_WRITE,"columns"),O="public"===n.schema,{hasLint:M,matchingLint:U}=(0,eR.R)(n.name,"security_definer_view",["ERROR","WARN"],a,n.schema),{hasLint:K,matchingLint:V}=(0,eR.R)(n.name,"materialized_view_in_api",["ERROR","WARN"],a,n.schema),Q=async()=>{if(!s)return console.error("Project is required");if(!R)return console.error("Unable to find realtime publication");let e=Z.some(e=>e.id==n.id)?Z.filter(e=>e.id!=n.id).map(e=>"".concat(e.schema,".").concat(e.name)):["".concat(n.schema,".").concat(n.name)].concat(Z.map(e=>"".concat(e.schema,".").concat(e.name)));T({projectRef:null==s?void 0:s.ref,connectionString:null==s?void 0:s.connectionString,id:R.id,tables:e})},J=()=>{S(!1)},G=async()=>{let e={id:n.id,rls_enabled:!n.rls_enabled};j({projectRef:null==s?void 0:s.ref,connectionString:null==s?void 0:s.connectionString,id:e.id,schema:n.schema,payload:e})};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[!P&&!W&&(0,l.jsxs)(eN.fC,{delayDuration:0,children:[(0,l.jsx)(eN.xz,{className:"w-full",children:(0,l.jsx)("div",{className:"border border-strong rounded bg-overlay-hover px-3 py-1 text-xs",children:"Viewing as read-only"})}),(0,l.jsx)(eN.h_,{children:(0,l.jsxs)(eN.VY,{side:"bottom",children:[(0,l.jsx)(eN.Eh,{className:"radix-tooltip-arrow"}),(0,l.jsx)("div",{className:"rounded bg-alternative py-1 px-2 leading-none shadow border border-background",children:(0,l.jsx)("span",{className:"text-xs text-foreground",children:"You need additional permissions to manage your project's data"})})]})})]}),c?n.rls_enabled?(0,l.jsx)(l.Fragment,{children:D.length<1&&!v?(0,l.jsxs)(eN.fC,{delayDuration:0,children:[(0,l.jsx)(eN.xz,{asChild:!0,className:"w-full",children:(0,l.jsx)(F.z,{asChild:!0,type:"default",className:"group",icon:(0,l.jsx)(eE.Z,{strokeWidth:1.5,className:"text-foreground-muted"}),children:(0,l.jsx)(eA(),{passHref:!0,href:"/project/".concat(C,"/auth/policies?search=").concat(n.id,"&schema=").concat(n.schema),children:"Add RLS policy"})})}),(0,l.jsx)(eN.h_,{children:(0,l.jsxs)(eN.VY,{side:"bottom",children:[(0,l.jsx)(eN.Eh,{className:"radix-tooltip-arrow"}),(0,l.jsx)("div",{className:"rounded bg-alternative py-1 px-2 leading-none shadow border border-background",children:(0,l.jsxs)("div",{className:"text-xs text-foreground p-1 leading-relaxed",children:[(0,l.jsx)("p",{children:"RLS is enabled for this table, but no policies are set. "}),(0,l.jsx)("p",{children:"Select queries may return 0 results."})]})})]})})]}):(0,l.jsx)(F.z,{asChild:!0,type:D.length<1&&!v?"warning":"default",className:"group",icon:v||D.length>0?(0,l.jsx)("div",{className:(0,et.cn)("flex items-center justify-center rounded-full bg-border-stronger h-[16px]",D.length>9?" px-1":"w-[16px]",""),children:(0,l.jsx)("span",{className:"text-[11px] text-foreground font-mono text-center",children:D.length})}):(0,l.jsx)(eE.Z,{strokeWidth:1.5}),children:(0,l.jsxs)(eA(),{passHref:!0,href:"/project/".concat(C,"/auth/policies?search=").concat(n.id,"&schema=").concat(n.schema),children:["Auth ",D.length>1?"policies":"policy"]})})}):(0,l.jsxs)(eW.J2,{open:w,onOpenChange:()=>N(!w),modal:!1,children:[(0,l.jsx)(eW.xo,{asChild:!0,children:(0,l.jsx)(F.z,{type:"warning",icon:(0,l.jsx)(eS.Z,{strokeWidth:1.5}),children:"RLS disabled"})}),(0,l.jsxs)(eW.yk,{className:"min-w-[395px] text-sm",align:"end",children:[(0,l.jsxs)("h3",{className:"flex items-center gap-2",children:[(0,l.jsx)(eS.Z,{size:16})," Row Level Security (RLS)"]}),(0,l.jsxs)("div",{className:"grid gap-2 mt-4 text-foreground-light text-sm",children:[(0,l.jsx)("p",{children:"You can restrict and control who can read, write and update data in this table using Row Level Security."}),(0,l.jsx)("p",{children:"With RLS enabled, anonymous users will not be able to read/write data in the table."}),!v&&(0,l.jsx)("div",{className:"mt-2",children:(0,l.jsx)(F.z,{type:"default",onClick:()=>S(!E),children:"Enable RLS for this table"})})]})]})]}):null,u&&M&&(0,l.jsxs)(eW.J2,{open:w,onOpenChange:()=>N(!w),modal:!1,children:[(0,l.jsx)(eW.xo,{asChild:!0,children:(0,l.jsx)(F.z,{type:"warning",icon:(0,l.jsx)(eC.Z,{strokeWidth:1.5}),children:"Security Definer view"})}),(0,l.jsxs)(eW.yk,{className:"min-w-[395px] text-sm",align:"end",children:[(0,l.jsxs)("h3",{className:"flex items-center gap-2",children:[(0,l.jsx)(eC.Z,{size:16})," Secure your View"]}),(0,l.jsxs)("div",{className:"grid gap-2 mt-4 text-foreground-light text-sm",children:[(0,l.jsx)("p",{children:"This view is defined with the Security Definer property, giving it permissions of the view's creator (Postgres), rather than the permissions of the querying user."}),(0,l.jsx)("p",{children:"Since this view is in the public schema, it is accessible via your project's APIs."}),(0,l.jsx)("div",{className:"mt-2",children:(0,l.jsx)(F.z,{type:"default",asChild:!0,children:(0,l.jsx)(eA(),{target:"_blank",href:"/project/".concat(r,"/advisors/security?preset=").concat(null==U?void 0:U.level,"&id=").concat(null==U?void 0:U.cache_key),children:"Learn more"})})})]})]})]}),d&&K&&(0,l.jsxs)(eW.J2,{open:w,onOpenChange:()=>N(!w),modal:!1,children:[(0,l.jsx)(eW.xo,{asChild:!0,children:(0,l.jsx)(F.z,{type:"warning",icon:(0,l.jsx)(eC.Z,{strokeWidth:1.5}),children:"Security Definer view"})}),(0,l.jsxs)(eW.yk,{className:"min-w-[395px] text-sm",align:"end",children:[(0,l.jsxs)("h3",{className:"flex items-center gap-2",children:[(0,l.jsx)(eC.Z,{size:16})," Secure your View"]}),(0,l.jsxs)("div",{className:"grid gap-2 mt-4 text-foreground-light text-sm",children:[(0,l.jsx)("p",{children:"This view is defined with the Security Definer property, giving it permissions of the view's creator (Postgres), rather than the permissions of the querying user."}),(0,l.jsx)("p",{children:"Since this view is in the public schema, it is accessible via your project's APIs."}),(0,l.jsx)("div",{className:"mt-2",children:(0,l.jsx)(F.z,{type:"default",asChild:!0,children:(0,l.jsx)(eA(),{target:"_blank",href:"/project/".concat(r,"/advisors/security?preset=").concat(null==V?void 0:V.level,"&id=").concat(null==V?void 0:V.cache_key),children:"Learn more"})})})]})]})]}),f&&"public"===i.schema&&(0,l.jsxs)(eW.J2,{open:w,onOpenChange:()=>N(!w),modal:!1,children:[(0,l.jsx)(eW.xo,{asChild:!0,children:(0,l.jsx)(F.z,{type:"warning",icon:(0,l.jsx)(eC.Z,{strokeWidth:1.5}),children:"Foreign table is accessible via your project's APIs"})}),(0,l.jsxs)(eW.yk,{className:"min-w-[395px] text-sm",align:"end",children:[(0,l.jsxs)("h3",{className:"flex items-center gap-2",children:[(0,l.jsx)(eC.Z,{size:16})," Secure Foreign table"]}),(0,l.jsxs)("div",{className:"grid gap-2 mt-4 text-foreground-light text-sm",children:[(0,l.jsx)("p",{children:"Foreign tables do not enforce RLS. Move them to a private schema not exposed to Postgrest or disable Postgrest."}),(0,l.jsx)("div",{className:"mt-2",children:(0,l.jsx)(F.z,{type:"default",asChild:!0,children:(0,l.jsx)(eA(),{target:"_blank",href:"https://github.com/orgs/supabase/discussions/21647",children:"Learn more"})})})]})]})]}),(0,l.jsx)(eO.Q,{serviceRoleLabel:"postgres"}),c&&p&&(0,l.jsxs)(F.z,{type:"default",icon:(0,l.jsx)(ek,{strokeWidth:1.5,className:I?"text-brand":"text-foreground-muted"}),onClick:()=>b(!0),children:["Realtime ",I?"on":"off"]}),O&&(0,l.jsx)(eL.Z,{section:["entities",n.name]})]}),(0,l.jsx)(q.Z,{visible:y,loading:z,title:"".concat(I?"Disable":"Enable"," realtime for ").concat(n.name),confirmLabel:"".concat(I?"Disable":"Enable"," realtime"),confirmLabelLoading:"".concat(I?"Disabling":"Enabling"," realtime"),onCancel:()=>b(!1),onConfirm:()=>Q(),children:(0,l.jsxs)("div",{className:"space-y-2",children:[(0,l.jsxs)("p",{className:"text-sm",children:["Once realtime has been ",I?"disabled":"enabled",", the table will"," ",I?"no longer ":"","broadcast any changes to authorized subscribers."]}),!I&&(0,l.jsxs)("p",{className:"text-sm",children:["You may also select which events to broadcast to subscribers on the"," ",(0,l.jsx)(eA(),{href:"/project/".concat(r,"/database/publications"),className:"text-brand",children:"database publications"})," ","settings."]})]})}),(null==i?void 0:i.type)===L.l.TABLE&&(0,l.jsx)(eF.Z,{danger:n.rls_enabled,visible:E,title:"Confirm to enable Row Level Security",description:"Are you sure you want to enable Row Level Security for this table?",buttonLabel:"Enable RLS",buttonLoadingLabel:"Updating",onSelectCancel:J,onSelectConfirm:G})]})},eq=n(61531),eU=n(52006),eK=e=>{let{id:t}=e;return(0,l.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,l.jsx)("div",{className:"w-[400px]",children:(0,l.jsx)(eq.Z,{icon:(0,l.jsx)(eU.Z,{strokeWidth:2}),title:"Unable to find your table with ID ".concat(t)})})})},eV=n(63899),eQ=n(49793),eJ=n(79534),eG=n(6659),eH=n(82784),eB=n(18592);let eX=e=>{let{schema:t="public",name:n}=e;return"\n ".concat(ep.k,"\n\n select pg_temp.pg_get_tabledef (\n '").concat(t,"',\n '").concat(n,"',\n false,\n 'FKEYS_INTERNAL',\n 'INCLUDE_TRIGGERS'\n ) as definition\n ").trim()},eY=function(e){let{projectRef:t,connectionString:n,schema:l,name:o}=e,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return(0,eB.cp)({projectRef:t,connectionString:n,sql:eX({schema:l,name:o}),queryKey:["table-definition",l,o]},{select:e=>e.result[0].definition.trim(),...i})},e$=e=>{let{schema:t,name:n}=e;return"\n select pg_get_viewdef(to_regclass('\"".concat(t,'"."').concat(n,"\"'), true) as definition\n ").trim()},e0=function(e){let{projectRef:t,connectionString:n,schema:l,name:o}=e,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return(0,eB.cp)({projectRef:t,connectionString:n,sql:e$({schema:l,name:o}),queryKey:["view-definition",l,o]},{select:e=>e.result[0].definition.trim(),enabled:void 0!==l&&void 0!==o,...i})};var e1=e=>{let{id:t}=e,{ref:n}=(0,m.UO)(),o=(0,x.useRef)(null),i=(0,x.useRef)(null),{resolvedTheme:r}=(0,eG.F)(),s=(0,_.Z)(t),{project:a}=(0,g.d2)(),c=e0({schema:null==s?void 0:s.schema,name:null==s?void 0:s.name,projectRef:null==a?void 0:a.ref,connectionString:null==a?void 0:a.connectionString},{enabled:(null==s?void 0:s.type)===L.l.VIEW||(null==s?void 0:s.type)===L.l.MATERIALIZED_VIEW}),d=eY({schema:null==s?void 0:s.schema,name:null==s?void 0:s.name,projectRef:null==a?void 0:a.ref,connectionString:null==a?void 0:a.connectionString},{enabled:(null==s?void 0:s.type)===L.l.TABLE}),{data:u,isLoading:h}=(null==s?void 0:s.type)===L.l.VIEW||(null==s?void 0:s.type)===L.l.MATERIALIZED_VIEW?c:d,f=(null==s?void 0:s.type)===L.l.VIEW?"create view ".concat(s.schema,".").concat(s.name," as\n"):(null==s?void 0:s.type)===L.l.MATERIALIZED_VIEW?"create materialized view ".concat(s.schema,".").concat(s.name," as\n"):"",p=e=>{try{return(0,eH.WU)(e,{language:"postgresql",keywordCase:"lower"})}catch(t){return e}},v=(0,x.useMemo)(()=>u?p(f+u):void 0,[u]),j=async(e,t)=>{o.current=e,i.current=t,e.changeViewZones(e=>{e.addZone({afterLineNumber:0,heightInPx:4,domNode:document.createElement("div")})}),await (0,ee.Vs)(500),null==e||e.focus()};return h?(0,l.jsxs)("div",{className:"h-full grid",children:[(0,l.jsx)("div",{className:"p-4",children:(0,l.jsx)(Y.A,{})}),(0,l.jsx)("div",{className:"mt-auto",children:(0,l.jsx)(J,{})})]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"flex-grow overflow-y-auto border-t border-muted relative",children:[(0,l.jsx)(F.z,{asChild:!0,type:"default",className:"absolute top-2 right-5 z-10",children:(0,l.jsx)(eA(),{href:"/project/".concat(n,"/sql/new?content=").concat(encodeURIComponent(null!=v?v:"")),children:"Open in SQL Editor"})}),(0,l.jsx)(eJ.default,{className:"monaco-editor",theme:(null==r?void 0:r.includes("dark"))?"vs-dark":"vs",onMount:j,defaultLanguage:"pgsql",value:v,path:"",options:{domReadOnly:!0,readOnly:!0,tabSize:2,fontSize:13,minimap:{enabled:!1},wordWrap:"on",fixedOverflowWidgets:!0}})]}),(0,l.jsx)(J,{})]})},e2=e=>{var t,n,r,a,x;let{theme:f="dark",isLoadingSelectedTable:p=!1,selectedTable:v}=e,j=(0,u.useRouter)(),{ref:E,id:S}=(0,m.UO)(),{project:C}=(0,g.d2)(),k=(0,w._2)(),D=(0,b.z6)(),[{view:A="data"}]=(0,y.x)(),R=(0,ej.Xo)(o.KA.TENANT_SQL_ADMIN_WRITE,"tables"),Z=(0,ej.Xo)(o.KA.TENANT_SQL_ADMIN_WRITE,"columns"),I=!R&&!Z,T=(0,eQ.Ei)({schemaName:null==v?void 0:v.schema,tableName:null==v?void 0:v.name}),z=(0,i.NL)(),{mutate:P}=(0,eg.Gz)({async onMutate(e){let{projectRef:t,table:n,configuration:l,payload:o}=e,i=new Set(Object.keys(l.identifiers)),r=ev.M.query(t,[n.schema,n.name,{table:{name:n.name,schema:n.schema}}]);await z.cancelQueries(r);let s=z.getQueriesData(r);return z.setQueriesData(r,e=>{var t;return{result:null!==(t=null==e?void 0:e.result.map(e=>Object.entries(e).filter(e=>{let[t]=e;return i.has(t)}).every(e=>{let[t,n]=e;return n===l.identifiers[t]})?{...e,...o}:e))&&void 0!==t?t:[]}}),{previousRowsQueries:s}},onError(e,t,n){let{previousRowsQueries:l}=n;l.forEach(e=>{let[t,n]=e;n&&z.setQueriesData(t,n),z.invalidateQueries(t)}),X(e)}}),{data:W}=(0,$.X)({projectRef:null==C?void 0:C.ref,connectionString:null==C?void 0:C.connectionString,schema:null==v?void 0:v.schema}),O=W||[],M=(0,_.Z)(null==v?void 0:v.id),q=(0,ey.Z)(null!==(t=null==v?void 0:v.columns)&&void 0!==t?t:ew.Z6);if(p)return(0,l.jsx)(ef.Z,{});if(c()(v))return(0,l.jsx)(eK,{id:Number(S)});let U=(null==M?void 0:M.type)===L.l.VIEW||(null==M?void 0:M.type)===L.l.MATERIALIZED_VIEW,K=(null==M?void 0:M.type)===L.l.TABLE,V=(null==M?void 0:M.type)===L.l.FOREIGN_TABLE,Q=eb.F.includes(null!==(n=null==M?void 0:M.schema)&&void 0!==n?n:""),J=K&&!Q,G=("relationships"in v&&v.relationships||[]).map(e=>{var t;let n=O.find(t=>t.id===e.id);return{...e,deletion_action:null!==(t=null==n?void 0:n.deletion_action)&&void 0!==t?t:ep.N.NO_ACTION}}),H=U||V?(0,N.NK)({table:v,columns:null!==(x=v.columns)&&void 0!==x?x:[],primaryKeys:[],relationships:[]}):(0,N.NK)({table:v,columns:null!==(r=v.columns)&&void 0!==r?r:[],primaryKeys:null!==(a=v.primary_keys)&&void 0!==a?a:[],relationships:G},T),B="".concat(v.schema,"_").concat(v.name),X=e=>{var t,n;h.Am.error(null!==(n=null!==(t=null==e?void 0:e.details)&&void 0!==t?t:null==e?void 0:e.message)&&void 0!==n?n:e)};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(em,{theme:f,gridProps:{height:"100%"},projectRef:E,editable:!I&&J,schema:v.schema,table:H,headerActions:(0,l.jsx)(eM,{table:v,canEditViaTableEditor:J}),onAddColumn:k.onAddColumn,onEditColumn:e=>{let t=s()(q.current,{name:e});t?k.onEditColumn(t):h.Am.error("Unable to find column ".concat(e," in ").concat(null==v?void 0:v.name))},onDeleteColumn:e=>{var t;let n=s()(null!==(t=q.current)&&void 0!==t?t:[],{name:e});n?k.onDeleteColumn(n):h.Am.error("Unable to find column ".concat(e," in ").concat(null==v?void 0:v.name))},onAddRow:k.onAddRow,updateTableRow:(e,t)=>{var n;if(!C)return;let o="columns"in v&&(null===(n=v.columns)||void 0===n?void 0:n.filter(e=>{var t;return(null!==(t=null==e?void 0:e.enums)&&void 0!==t?t:[]).length>0&&"array"===e.data_type.toLowerCase()}).map(e=>e.name))||[],i={};if(v.primary_keys.forEach(t=>i[t.name]=e[t.name]),0===Object.keys(i).length)return(0,h.Am)("Unable to update row as table has no primary keys",{description:(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"text-sm text-foreground-light",children:"Add a primary key column to your table first to serve as a unique identifier for each row before updating or deleting the row."}),(0,l.jsx)("div",{className:"mt-3",children:(0,l.jsx)(F.z,{asChild:!0,type:"outline",icon:(0,l.jsx)(d.Z,{}),children:(0,l.jsx)("a",{target:"_blank",rel:"noreferrer",href:"https://supabase.com/docs/guides/database/tables#primary-keys",children:"Documentation"})})})]})});P({projectRef:C.ref,connectionString:C.connectionString,table:H,configuration:{identifiers:i},payload:t,enumArrayColumns:o,impersonatedRole:D()})},onEditRow:k.onEditRow,onImportData:k.onImportData,onError:X,onExpandJSONEditor:(e,t)=>{k.onExpandJSONEditor({column:e,row:t,value:JSON.stringify(t[e])||""})},onExpandTextEditor:(e,t)=>{k.onExpandTextEditor(e,t)},onEditForeignKeyColumnValue:k.onEditForeignKeyColumnValue,showCustomChildren:(U||K)&&"definition"===A,customHeader:(U||K)&&"definition"===A?(0,l.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,l.jsxs)("p",{children:["SQL Definition of ",(0,l.jsx)("code",{className:"text-sm",children:v.name})," "]}),(0,l.jsx)("p",{className:"text-foreground-light text-sm",children:"(Read only)"})]}):null,children:(U||K)&&(0,l.jsx)(e1,{id:null==v?void 0:v.id})},B),(0,l.jsx)(eV.Z,{editable:!I&&J,selectedTable:v,onTableCreated:e=>{j.push("/project/".concat(E,"/editor/").concat(e.id))}})]})};n(62456)},53449:function(e,t,n){var l=n(52322),o=n(30339),i=n(16289),r=n(32079);t.Z=e=>{let{section:t}=e,n=(0,i.WZ)();return(0,l.jsx)(r.z,{size:"tiny",type:"default",onClick:()=>{t&&n.setActiveDocsSection(t),n.setShowProjectApiDocs(!0)},icon:(0,l.jsx)(o.Z,{strokeWidth:1.5,className:"text-foreground-muted"}),children:"API Docs"})}},55600:function(e,t,n){n.d(t,{x:function(){return i}});var l=n(52322),o=n(54383);let i=e=>{let{children:t,className:n}=e;return(0,l.jsx)("div",{className:(0,o.cn)("flex min-h-9 h-9 overflow-hidden items-center px-2 w-full border-t",n),children:t})}},7161:function(e,t,n){n.d(t,{o:function(){return l}});let l={users:(e,t)=>["auth",e,"users",...t?[t]:[]],authConfig:e=>["auth",e,"config"],accessToken:()=>["access-token"]}},38530:function(e,t,n){n.d(t,{RT:function(){return r},xY:function(){return a}});var l=n(36492),o=n(31696),i=n(7161);let r=10;async function s(e,t){let{projectRef:n,page:l=1,keywords:i="",filter:s}=e;if(!n)throw Error("Project ref is required");let a={limit:r.toString(),offset:((l-1)*10).toString(),keywords:i};s&&(a.verified=s);let{data:c,error:d}=await (0,o.U2)("/platform/auth/{ref}/users",{params:{path:{ref:n},query:a},signal:t});return d&&(0,o.S3)(d),c}let a=function(e){let{projectRef:t,page:n,keywords:o,filter:r,connectionString:a}=e,{enabled:c=!0,...d}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return(0,l.a)(i.o.users(t,{page:n,keywords:o,filter:r}),e=>{let{signal:l}=e;return s({projectRef:t,page:n,keywords:o,filter:r,connectionString:a},l)},{enabled:c&&void 0!==t,...d})}},49521:function(e,t,n){n.d(t,{r:function(){return s}});var l=n(36492),o=n(31696),i=n(11596);async function r(e,t){let{projectRef:n,connectionString:l,schema:i}=e;if(!n)throw Error("projectRef is required");let r=new Headers;l&&r.set("x-connection-encrypted",l);let{data:s,error:a}=await (0,o.U2)("/platform/pg-meta/{ref}/policies",{params:{header:{"x-connection-encrypted":l},path:{ref:n},query:{included_schemas:i||"",excluded_schemas:""}},headers:r,signal:t});return a&&(0,o.S3)(a),s}let s=function(e){let{projectRef:t,connectionString:n,schema:o}=e,{enabled:s=!0,...a}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return(0,l.a)(i.R.list(t,o),e=>{let{signal:l}=e;return r({projectRef:t,connectionString:n,schema:o},l)},{enabled:s&&void 0!==t,...a})}},11596:function(e,t,n){n.d(t,{R:function(){return l}});let l={list:(e,t)=>["projects",e,"database-policies",t].filter(Boolean)}},34548:function(e,t,n){n.d(t,{Z:function(){return l}});/**
- * @license lucide-react v0.436.0 - ISC
- *
- * This source code is licensed under the ISC license.
- * See the LICENSE file in the root directory of this source tree.
- */let l=(0,n(46145).Z)("CirclePlus",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 12h8",key:"1wcyev"}],["path",{d:"M12 8v8",key:"napkw2"}]])},17747:function(e,t,n){n.d(t,{Z:function(){return l}});/**
- * @license lucide-react v0.436.0 - ISC
- *
- * This source code is licensed under the ISC license.
- * See the LICENSE file in the root directory of this source tree.
- */let l=(0,n(46145).Z)("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]])},69548:function(e,t,n){n.d(t,{b:function(){return s}});var l=n(52322),o=n(2784),i=n(2322);let r=(0,o.forwardRef)((e,t)=>(0,l.jsx)("svg",{ref:t,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 16 16",fill:"currentColor",...e,children:(0,l.jsx)("path",{"fill-rule":"evenodd",d:"M15 8A7 7 0 1 1 1 8a7 7 0 0 1 14 0ZM9 5a1 1 0 1 1-2 0 1 1 0 0 1 2 0ZM6.75 8a.75.75 0 0 0 0 1.5h.75v1.75a.75.75 0 0 0 1.5 0v-2.5A.75.75 0 0 0 8.25 8h-1.5Z","clip-rule":"evenodd"})})),s=(0,o.forwardRef)((e,t)=>{let{...n}=e;return(0,l.jsxs)(i.u,{children:[(0,l.jsx)(i.aJ,{type:"button",role:"button",className:"flex [&_svg]:data-[state=delayed-open]:fill-foreground-lighter [&_svg]:data-[state=instant-open]:fill-foreground-lighter",children:(0,l.jsx)(r,{strokeWidth:2,className:"transition-colors fill-foreground-muted w-4 h-4"})}),(0,l.jsx)(i._v,{...n})]})})},4419:function(e,t,n){var l=n(52322),o=n(2784),i=n(25001),r=n(71653),s=n(67440),a=n(46318),c=n(70780);t.Z=function(e){let{defaultValue:t,descriptionText:n,error:d,icon:u,inputRef:h,label:m,afterLabel:x,beforeLabel:f,labelOptional:p,layout:v,value:g,actions:j,size:y="medium",validation:b,id:w="",name:N="",...E}=e,S=(0,a.Z)("inputNumber"),{formContextOnChange:C,values:k,errors:D,handleBlur:A,touched:R,fieldLevelValidation:L}=(0,c.G)();k&&!g&&(g=k[w||N]),d||(D&&!d&&(d=D[w||N]),d=R&&R[w||N]?d:void 0),(0,o.useEffect)(()=>{b&&L(w,b(g))},[]);let _=[S.base];return d&&_.push(S.variants.error),d||_.push(S.variants.standard),u&&_.push(S.with_icon),y&&_.push(S.size[y]),E.disabled&&_.push(S.disabled),(0,l.jsx)("div",{className:E.className,children:(0,l.jsx)(i.l,{label:m,afterLabel:x,beforeLabel:f,labelOptional:p,layout:v,id:w,error:d,descriptionText:n,style:E.style,size:y,children:(0,l.jsxs)("div",{className:S.container,children:[(0,l.jsx)("input",{"data-size":y,id:w,name:N,onChange:function(e){E.onChange&&E.onChange(e),C&&C(e),b&&L(w,b(e.target.value))},onBlur:function(e){A&&A(e),E.onBlur&&E.onBlur(e)},type:"number",ref:h,value:g,className:_.join(" "),...E}),u&&(0,l.jsx)(s.Z,{size:y,icon:u}),d||j?(0,l.jsxs)("div",{className:S.actions_container,children:[d&&(0,l.jsx)(r.Z,{size:y}),j&&j]}):null]})})})}}}]);
|