1import{d5 as R,d6 as ae,d7 as S,p as q,d8 as N,d9 as re,da as J,a8 as se,a$ as V,O as ce,c as ie,db as ue,dc as de,dd as le,aJ as pe,de as fe,ba as me,df as ye,dg as ge,dh as T,aL as he}from"./Icon-Ime4wSjK.js";import{a as u}from"./index-Dhy1axWM.js";import"./with-selector-Ce4EAgKw.js";import{r as be,v as we,w as Ee,c as P,d as Q,u as $e,x as Te,h as Ce,y as De,z as Ie,A as ke}from"./useAuthWrapper-CWXjgmIl.js";import{g as D}from"./project-wd5IloI0.js";import{f as U}from"./react-redux-Bz8azxLH.js";import"./_commonjsHelpers-CxYHiaSM.js";import"./index-CJZQOLKR.js";import"./index-AmsYr5ik.js";import"./jsx-runtime-esm-DgZK9P7c.js";import"./isEqual-BiqEbpPg.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};e.SENTRY_RELEASE={id:"967abcd"},e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=(function(n){for(var o=1;o<arguments.length;o++){var a=arguments[o];if(a!=null)for(var r in a)a.hasOwnProperty(r)&&(n[r]=a[r])}return n})({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:noloco-ui":!0});var t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="8a5a1274-1626-4034-92a8-2fd496b69b38",e._sentryDebugIdIdentifier="sentry-dbid-8a5a1274-1626-4034-92a8-2fd496b69b38")}catch{}})();const j=e=>e.type===se,x=e=>e.type===ce,B=e=>{const t=ie(e);return!!t&&!!ue[t]},F=e=>(de(e)||le(e))&&!j(e),Me=e=>V(e.relationship)?{...N,edges:{node:R}}:R,G=(e,t)=>{if(j(e))return Me(e);if(x(e)){if(!B(e))throw new Error(`[@noloco/data-sdk] OBJECT field "${e.name}" on DataType "${t}" has an unsupported format and cannot be selected.`);return re(e)}if(F(e))throw new Error(`[@noloco/data-sdk] Field "${e.name}" on DataType "${t}" is a relation; use a dotted path like "${e.name}.<field>" to select related fields.`);return!0},ve=new Set(Object.keys(R)),K=(e,t)=>{const n={...e};return Object.entries(t).forEach(([o,a])=>{const r=n[o];n[o]=r&&typeof r=="object"&&a&&typeof a=="object"?K(r,a):a}),n},je=(e,t,n)=>{if(j(e)){if(!ve.has(t))throw new Error(`[@noloco/data-sdk] Unknown property "${t}" on FILE field "${e.name}" of DataType "${n}".`);const o={[t]:!0};return V(e.relationship)?{...N,edges:{node:o}}:o}if(x(e)){if(!B(e))throw new Error(`[@noloco/data-sdk] OBJECT field "${e.name}" on DataType "${n}" has an unsupported format and cannot be selected.`);const o=J(e,{includeRoot:!0}).find(a=>a.name===t);if(!o)throw new Error(`[@noloco/data-sdk] Unknown sub-field "${t}" on OBJECT field "${e.name}" of DataType "${n}".`);return{[o.name]:!0}}throw new Error(`[@noloco/data-sdk] Field "${e.name}" on DataType "${n}" is not a file or object and cannot be traversed into "${t}".`)},_e=(e,t,n,o,a)=>{if(j(e))throw new Error(`[@noloco/data-sdk] Field "${e.name}" on DataType "${a}" is a file field; select it directly (e.g. "${e.name}") to get the full file shape.`);if(x(e)){if(n!==void 0)throw new Error(`[@noloco/data-sdk] select path on OBJECT field "${e.name}" of DataType "${a}" supports only a single sub-field (e.g. "${e.name}.${t}").`);if(!B(e))throw new Error(`[@noloco/data-sdk] OBJECT field "${e.name}" on DataType "${a}" has an unsupported format and cannot be selected.`);const d=J(e,{includeRoot:!0}).find(c=>c.name===t);if(!d)throw new Error(`[@noloco/data-sdk] Unknown sub-field "${t}" on OBJECT field "${e.name}" of DataType "${a}".`);return{selection:{[d.name]:!0}}}if(!F(e))throw new Error(`[@noloco/data-sdk] Field "${e.name}" on DataType "${a}" is not a relation and cannot be traversed.`);const r=o.getByName(e.type);if(!r)throw new Error(`[@noloco/data-sdk] Could not resolve related DataType "${e.type}" for field "${e.name}" on "${a}".`);const s=r.fields.getByName(t);if(!s)throw new Error(`[@noloco/data-sdk] Unknown field "${t}" on related DataType "${r.name}" (via "${e.name}").`);if(F(s))throw new Error(`[@noloco/data-sdk] select path traverses relation "${t}" on related DataType "${r.name}" (via "${e.name}"), exceeding the supported one-level relation depth.`);return{selection:n!==void 0?{...S,[s.name]:je(s,n,r.name)}:{...S,[s.name]:G(s,r.name)},relatedTypeName:r.name}},Oe=(e,t)=>
1{if(!e||typeof e!="object")return{};if(!t)return e;const n=e.edges;if(!n||typeof n!="object")return{};const o=n.node;return o&&typeof o=="object"?o:{}},_=(e,t,n)=>{const o=new Set([e.name]);if(n===void 0)return{selection:ae(e.fields),dataTypeNames:o};const a={...S};return n.forEach(r=>{const s=r.split(".");if(s.length>3)throw new Error(`[@noloco/data-sdk] select path "${r}" is too deep on DataType "${e.name}"; at most one relation hop plus a composite property (e.g. "relation.file.url") is supported.`);const[i,l,d]=s,c=e.fields.getByName(i);if(!c)throw new Error(`[@noloco/data-sdk] Unknown field "${i}" on DataType "${e.name}".`);if(l===void 0){a[c.name]=G(c,e.name);return}const{selection:m,relatedTypeName:p}=_e(c,l,d,t,e.name);p&&o.add(p);const y=q(c),f=Oe(a[c.name],y),b=K(f,m);a[c.name]=y?{...N,edges:{node:b}}:b}),{selection:a,dataTypeNames:o}},Y=e=>e.length===0?e:e.charAt(0).toUpperCase()+e.slice(1),Re=(e,t)=>{e.modify({fields:{[`${t}Collection`]:(n,{INVALIDATE:o})=>o}})},Se=(e,t,n)=>{const o=e.identify({__typename:Y(t),id:n});o&&(e.evict({id:o}),e.gc())};let Fe=0;const v=new Map,Ne=e=>be(e).join(` 2`)||e.message,W=(e,t)=>t?`${e}::${t.join(".")}`:e,z=e=>{const t=e.graphQLErrors;if(t&&t.length>0)return t.map(({message:o,path:a})=>({message:o,path:a}));const n=Ne(e);return n?[{message:n}]:[]},Pe=()=>`graphql-${++Fe}`,Qe=e=>{z(e).forEach(({message:t,path:n})=>{const o=W(t,n),a=v.get(o);if(a){a.count+=1;return}v.set(o,{captureId:Pe(),count:1,error:e,message:t,path:n})})},xe=e=>{z(e).forEach(({message:t,path:n})=>{const o=W(t,n),a=v.get(o);a&&(a.count-=1,a.count===0&&v.delete(o))})},I=e=>{u.useEffect(()=>{if(e)return Qe(e),()=>{xe(e)}},[e])},Be=()=>{const e=U(pe),t=U(fe);return{name:e,dataTypes:t}},k=({dataTypeId:e,dataTypeName:t})=>{const{name:n,dataTypes:o}=Be(),a=we();let r;if(t!==void 0)r=o.getByNameOrThrow(t,`[@noloco/data-sdk] No DataType found for name "${t}". Make sure the name matches a DataType in the current project.`);else if(e!==void 0)r=o.getByIdOrThrow(e,`[@noloco/data-sdk] No DataType found for id ${e}. Make sure the id matches a DataType in the current project.`);else throw new Error("[@noloco/data-sdk] One of dataTypeId or dataTypeName is required.");return{client:a,dataType:r,dataTypes:o,projectName:n}},et=({dataTypeId:e,dataTypeName:t,select:n})=>{const{dataType:o,dataTypes:a,projectName:r}=k({dataTypeId:e,dataTypeName:t}),s=o.name,i=Ee(s),{selection:l}=u.useMemo(()=>_(o,a,n),[o,a,n]),d=u.useMemo(()=>D` 3 ${P(me,s,o.fields,l)} 4 `,[s,o.fields,l]),[c,{data:m,error:p,loading:y}]=Q(d,{context:{projectQuery:!0,projectName:r},update:g=>Re(g,s)});I(p);const f=u.useCallback(async({input:g})=>(await c({variables:g})).data?.[i],[c,i]),w=m?.[i];return[f,{data:w,error:p,loading:y}]},tt=()=>{const{user:e,loading:t,error:n}=$e();return I(n),{user:e,loading:t,error:n}},ot=({dataTypeId:e,dataTypeName:t})=>{const{dataType:n,projectName:o}=k({dataTypeId:e,dataTypeName:t}),a=n.name,r=Te(a),s=u.useMemo(()=>D` 5 ${P(ye,a)} 6 `,[a]),[i,{data:l,error:d,loading:c}]=Q(s,{context:{projectQuery:!0,projectName:o}});I(d);const m=u.useCallback(async({id:f})=>(await i({variables:{id:f},update:g=>Se(g,n.name,f)})).data?.[r],[n.name,i,r]),y=l?.[r];return[m,{data:y,error:d,loading:c}]},Ae="en-US",Ue=()=>Intl.DateTimeFormat().resolvedOptions().locale||Ae,nt=()=>{const e=Ue();return u.useCallback((t,n)=>ge(t,n,void 0,e),[e])},L=new Set,H=e=>(L.add(e),()=>{L.delete(e)}),Le=e=>typeof e=="object"&&e!==null&&Array.isArray(e.edges),X=(e,t)=>{const n={...e};return t.fields.forEach(o=>{const a=n[o.name];a==null||!q(o)||Le(a)&&(n[o.name]=a.edges.map(r=>r.node))}),n},Z=(e,t={})=>{const n=Ce(e,t);return I(n.error),n},at=e=>{const{dataTypeId:t,dataTypeName:n,id:o,select:a,skip:r,uuid:s}=e,{dataType:i,dataTypes:l,projectName:d}=k({dataTypeId:t,dataTypeName:n}),c=o!==void 0,{selection:m,dataTypeNames:p}=u.useMemo(()=>_(i,l,a),[i,l,a]),y=u.useMemo(()=>D` 7 ${De(i.name,{__args:c?{id:new T.VariableType("id")}:{uuid:new T.VariableType("uuid")},__variables:c?{id:"ID"}:{uuid:"String"},...m})} 8 `,[i.name,c,m]),f=u.useMemo(()=>c?{id:o}:{uuid:s},[c,o,s]),{data:b,error:w,loading:g,refetch:$}=Z(y,{context:{projectQuery:!0,projectName:d},errorPolicy:"all",skip:r??!1,variables:f}),E=b?.[i.name],M=u.useMemo(()=>E!=null?X(E,i):E,[E,i]),C=u.useCallback(async()=>{await $()},[$]);return u.useEffect(()=>{if(!r)return H({dataTypeNames:p,onInvalidate:()=>{C().catch(()=>{})}})},[r,p,C]),{data:M,error:w,loading:g,refetch:C}},rt=({dataTypeId:e,dataTypeName:t,after:n,before:o,first:a,select:r,skip:s,sort:i,where:l})=>{const{dataType:d,dataTypes:c,projectName:m}=k({dataTypeId:e,dataTypeName:t}),p=d.name,y=`${p}Collection`,f=`${Y(p)}WhereInput`,{selection:b,dataTypeNames:w}=u.useMemo(()=>_(d,c,r),[d,c,r]),g=u.useMemo(()=>D` 9 ${Ie(p,{__args:{after:new T.VariableType("after"),before:new T.VariableType("before"),first:new T.VariableType("first"),sort:new T.VariableType("sort"),where:new T.VariableType("where")},__variables:{after:"String",before:"String",first:"Int",sort:"[SortClauseInput!]",where:f},edges:{node:b},pageInfo:{endCursor:!0,hasNextPage:!0,hasPreviousPage:!0,startCursor:!0},totalCount:!0})} 10 `,[p,b,f]),$=u.useMemo(()=>({after:n,before:o,first:a,sort:i,where:l}),[n,o,a,i,l]),{data:E,error:M,loading:C,refetch:A}=Z(g,{context:{projectQuery:!0,projectName:m},errorPolicy:"all",skip:s??!1,variables:$}),h=E?.[y],ee=u.useMemo(()=>({endCursor:h?.pageInfo?.endCursor??null,hasNextPage:h?.pageInfo?.hasNextPage??!1,hasPreviousPage:h?.pageInfo?.hasPreviousPage??!1,startCursor:h?.pageInfo?.startCursor??null}),[h?.pageInfo?.endCursor,h?.pageInfo?.hasNextPage,h?.pageInfo?.hasPreviousPage,h?.pageInfo?.startCursor]),te=h?.totalCount??null,oe=u.useMemo(()=>(h?.edges??[]).map(ne=>X(ne.node,d)),[h?.edges,d]),O=u.useCallback(async()=>{await A()},[A]);return u.useEffect(()=>{if(!s)return H({dataTypeNames:w,onInvalidate:()=>{O().catch(()=>{})}})},[s,w,O]),{data:oe,error:M,loading:C,pageInfo:ee,refetch:O,totalCount:te}},st=({dataTypeId:e,dataTypeName:t,select:n})=>{const{dataType:o,dataTypes:a,projectName:r}=k({dataTypeId:e,dataTypeName:t}),s=o.name,i=ke(s),{selection:l}=u.useMemo(()=>_(o,a,n),[o,a,n]),d=u.useMemo(()=>D` 11 ${P(he,s,o.fields,l)} 12 `,[s,o.fields,l]),[c,{data:m,error:p,loading:y}]=Q(d,{context:{projectQuery:!0,projectName:r}});I(p);const f=u.useCallback(async({id:g,input:$})=>(await c({variables:{...$,id:g}})).data?.[i],[c,i]),w=m?.[i];return[f,{data:w,error:p,loading:y}]};export{et as useCreateRecord,tt as useCurrentUser,ot as useDeleteRecord,nt as useFormatFieldValue,Be as useProject,at as useRecord,rt as useRecords,st as useUpdateRecord};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.