"use strict";(()=>{var a={};a.id=51756,a.ids=[51756],a.modules={51455:a=>{a.exports=require("node:fs/promises")},176760:a=>{a.exports=require("node:path")},200261:a=>{a.exports=require("next/dist/shared/lib/router/utils/app-paths")},257975:a=>{a.exports=require("node:util")},529294:a=>{a.exports=require("next/dist/server/app-render/work-async-storage.external.js")},644185:(a,b,c)=>{c.r(b),c.d(b,{handler:()=>O,patchFetch:()=>N,routeModule:()=>J,serverHooks:()=>M,workAsyncStorage:()=>K,workUnitAsyncStorage:()=>L});var d={};c.r(d),c.d(d,{GET:()=>I,dynamic:()=>x,runtime:()=>y});var e=c(940527),f=c(41752),g=c(633335),h=c(573615),i=c(301769),j=c(200261),k=c(405563),l=c(439285),m=c(443399),n=c(295860),o=c(161730),p=c(728392),q=c(976618),r=c(406527),s=c(986439),t=c(975973),u=c(693349),v=c(544388),w=c(556881);let x="force-dynamic",y="nodejs",z=new Map;async function A(a){let b=z.get(a);if(b)return b;let c=(0,u.eI)(a,"ALTER TABLE objects ADD COLUMN IF NOT EXISTS display_field VARCHAR").then(()=>void 0);return z.set(a,c),c}async function B(a,b){return(0,u.LM)(a,b)}function C(a){if("string"!=typeof a)return a;try{return JSON.parse(a)}catch{return a}}function D(a){return a.replace(/'/g,"''")}async function E(a){let b=await (0,u.Bk)();if(0===b.length)return null;let c=`SELECT * FROM objects WHERE name = '${D(a)}' LIMIT 1`;for(let a=0;a<2;a+=1){for(let a of b){let b=await B(a,c);if(b.length>0)return{dbFile:a,object:b[0]}}0===a&&await new Promise(a=>setTimeout(a,100))}return null}function F(a,b){if(a.display_field)return a.display_field;let c=b.find(a=>/\bname\b/i.test(a.name)||/\btitle\b/i.test(a.name));if(c)return c.name;let d=b.find(a=>"text"===a.type);return d?d.name:b[0]?.name??"id"}async function G(a,b,c){let d={},e={},f={};for(let g of b.filter(a=>"relation"===a.type&&a.related_object_id)){let b=await B(a,`SELECT * FROM objects WHERE id = '${D(g.related_object_id)}' LIMIT 1`);if(0===b.length)continue;let h=b[0];f[g.name]=h.name;let i=await B(a,`SELECT * FROM fields WHERE object_id = '${D(h.id)}' ORDER BY sort_order`),j=F(h,i),k=new Set;for(let a of c){let b=a[g.name];if(null==b||""===b)continue;let c="object"==typeof b&&null!==b?JSON.stringify(b):"string"==typeof b?b:"number"==typeof b||"boolean"==typeof b?String(b):"";for(let a of(0,u.Dv)(c))k.add(a)}if(0===k.size){d[g.name]={},e[g.name]={};continue}let l=Array.from(k).map(a=>`'${D(a)}'`).join(","),m=await B(a,`SELECT e.id as entry_id, ef.value
       FROM entries e
       JOIN entry_fields ef ON ef.entry_id = e.id
       JOIN fields f ON f.id = ef.field_id
       WHERE e.id IN (${l})
       AND f.object_id = '${D(h.id)}'
       AND f.name = '${D(j)}'`),n={};for(let a of m)n[a.entry_id]=a.value||a.entry_id;for(let a of k)n[a]||(n[a]=a);d[g.name]=n;let o=await B(a,`SELECT e.id as entry_id, ef.value, COALESCE(f.sort_order, 999999) as sort_order
       FROM entries e
       JOIN entry_fields ef ON ef.entry_id = e.id
       JOIN fields f ON f.id = ef.field_id
       WHERE e.id IN (${l})
       AND f.object_id = '${D(h.id)}'
       AND f.type = 'url'
       ORDER BY f.sort_order`),p={};for(let a of o){if(p[a.entry_id])continue;let b=(a.value??"").trim();if(!b)continue;let c=/^https?:\/\//i.test(b)?b:`https://${b}`,d=(0,w.jv)(c);d&&(p[a.entry_id]=d)}e[g.name]=p}return{labels:d,faviconUrls:e,relatedObjectNames:f}}async function H(a){let b=await (0,u.Bk)(),c=[];for(let d of b)for(let b of(await B(d,`SELECT f.*, f.object_id as source_object_id, o.name as source_object_name
       FROM fields f
       JOIN objects o ON o.id = f.object_id
       WHERE f.type = 'relation'
       AND f.related_object_id = '${D(a)}'`))){let a=await B(d,`SELECT * FROM objects WHERE id = '${D(b.source_object_id)}' LIMIT 1`);if(0===a.length)continue;let e=await B(d,`SELECT * FROM fields WHERE object_id = '${D(b.source_object_id)}' ORDER BY sort_order`),f=F(a[0],e),g=await B(d,`SELECT ef.entry_id as source_entry_id, ef.value as target_value
         FROM entry_fields ef
         WHERE ef.field_id = '${D(b.id)}'
         AND ef.value IS NOT NULL
         AND ef.value != ''`);if(0===g.length)continue;let h=[...new Set(g.map(a=>a.source_entry_id))].map(a=>`'${D(a)}'`).join(","),i=await B(d,`SELECT ef.entry_id, ef.value
         FROM entry_fields ef
         JOIN fields f ON f.id = ef.field_id
         WHERE ef.entry_id IN (${h})
         AND f.name = '${D(f)}'
         AND f.object_id = '${D(b.source_object_id)}'`),j={};for(let a of i)j[a.entry_id]=a.value||a.entry_id;let k={};for(let a of g)for(let b of(0,u.Dv)(a.target_value))k[b]||(k[b]=[]),k[b].push({id:a.source_entry_id,label:j[a.source_entry_id]||a.source_entry_id});c.push({fieldName:b.name,sourceObjectName:b.source_object_name,sourceObjectId:b.source_object_id,displayField:f,entries:k})}return c}async function I(a,{params:b}){let{name:c}=await b;if(!(0,u.XL)())return Response.json({error:"DuckDB CLI is not installed",code:"DUCKDB_NOT_INSTALLED"},{status:503});if(!/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(c))return Response.json({error:"Invalid object name"},{status:400});let d=await E(c);if(!d)return await (0,u.Jv)()?Response.json({error:`Object '${c}' not found`},{status:404}):Response.json({error:"DuckDB database not found"},{status:404});let{dbFile:e,object:f}=d;await A(e);let g=await B(e,`SELECT * FROM fields WHERE object_id = '${f.id}' ORDER BY sort_order`);0===g.length&&(await new Promise(a=>setTimeout(a,100)),g=await B(e,`SELECT * FROM fields WHERE object_id = '${f.id}' ORDER BY sort_order`));let h=await B(e,`SELECT * FROM statuses WHERE object_id = '${f.id}' ORDER BY sort_order`);0===h.length&&g.length>0&&(await new Promise(a=>setTimeout(a,50)),h=await B(e,`SELECT * FROM statuses WHERE object_id = '${f.id}' ORDER BY sort_order`));let i=new URL(a.url),j=i.searchParams.get("filters"),k=i.searchParams.get("sort"),l=i.searchParams.get("search"),m=i.searchParams.get("page"),n=i.searchParams.get("pageSize"),o=j?(0,v.Dc)(j):void 0,p=g.map(a=>({name:a.name,type:a.type})),q="";if(o){let a=(0,v.hv)(o,p);a&&(q=` WHERE ${a}`)}let r=" ORDER BY created_at DESC, entry_id DESC";if(k)try{let a=JSON.parse(k),b=(0,v.XF)(a);b&&(r=` ORDER BY ${b}, entry_id DESC`)}catch{}let s=Math.max(1,Number(m)||1),t=Math.min(5e3,Math.max(1,Number(n)||100)),w=(s-1)*t,x=` LIMIT ${t} OFFSET ${w}`;if(l&&l.trim()){let a=g.filter(a=>["text","richtext","email"].includes(a.type));if(a.length>0){let b=a.map(a=>`LOWER(CAST("${a.name.replace(/"/g,'""')}" AS VARCHAR)) LIKE '%${D(l.toLowerCase())}%'`).join(" OR ");q=q?`${q} AND (${b})`:` WHERE (${b})`}}let y=(0,u.Bu)(c),z=[],I=0,J=!1;try{let a=await (0,u.mT)(e,`SELECT COUNT(*) as cnt FROM ${y}${q}`);I=Number(a[0]?.cnt??0);let b=await (0,u.mT)(e,`SELECT * FROM ${y}${q}${r}${x}`);0===b.length&&I>0&&(await new Promise(a=>setTimeout(a,120)),b=await (0,u.mT)(e,`SELECT * FROM ${y}${q}${r}${x}`)),z=b}catch{J=!0,z=function(a){let b=new Map;for(let c of a){let a=b.get(c.entry_id);a||(a={entry_id:c.entry_id,created_at:c.created_at,updated_at:c.updated_at},b.set(c.entry_id,a)),c.field_name&&(a[c.field_name]=c.value)}return Array.from(b.values())}(await B(e,`SELECT e.id as entry_id, e.created_at, e.updated_at,
              f.name as field_name, ef.value
       FROM entries e
       JOIN entry_fields ef ON ef.entry_id = e.id
       JOIN fields f ON f.id = ef.field_id
       WHERE e.object_id = '${f.id}'
       ORDER BY e.created_at DESC, e.id DESC
       LIMIT 5000`))}if(J){let a=await B(e,`SELECT COUNT(*) as cnt FROM entries WHERE object_id = '${f.id}'`);I=Number(a[0]?.cnt??z.length)}let K=g.map(a=>({...a,enum_values:a.enum_values?C(a.enum_values):void 0,enum_colors:a.enum_colors?C(a.enum_colors):void 0})),{labels:L,faviconUrls:M,relatedObjectNames:N}=await G(e,g,z),O=K.map(a=>({...a,related_object_name:"relation"===a.type?N[a.name]:void 0})),P=await H(f.id),Q=F(f,g),{views:R,activeView:S,viewSettings:T}=(0,u.up)(c),U=(0,u.yw)(c),V={...f,icon:U};return Response.json({object:V,fields:O,statuses:h,entries:z,relationLabels:L,relationFaviconUrls:M,reverseRelations:P,effectiveDisplayField:Q,savedViews:R,activeView:S,viewSettings:T,totalCount:I,page:s,pageSize:t})}let J=new e.AppRouteRouteModule({definition:{kind:f.RouteKind.APP_ROUTE,page:"/api/workspace/objects/[name]/route",pathname:"/api/workspace/objects/[name]",filename:"route",bundlePath:"app/api/workspace/objects/[name]/route"},distDir:".next",relativeProjectDir:"",resolvedPagePath:"/home/runner/work/DenchClaw/DenchClaw/apps/web/app/api/workspace/objects/[name]/route.ts",nextConfigOutput:"standalone",userland:d}),{workAsyncStorage:K,workUnitAsyncStorage:L,serverHooks:M}=J;function N(){return(0,g.patchFetch)({workAsyncStorage:K,workUnitAsyncStorage:L})}async function O(a,b,c){var d;let e="/api/workspace/objects/[name]/route";"/index"===e&&(e="/");let g=await J.prepare(a,b,{srcPage:e,multiZoneDraftMode:!1});if(!g)return b.statusCode=400,b.end("Bad Request"),null==c.waitUntil||c.waitUntil.call(c,Promise.resolve()),null;let{buildId:u,params:v,nextConfig:w,isDraftMode:x,prerenderManifest:y,routerServerContext:z,isOnDemandRevalidate:A,revalidateOnlyGenerated:B,resolvedPathname:C}=g,D=(0,j.normalizeAppPath)(e),E=!!(y.dynamicRoutes[D]||y.routes[C]);if(E&&!x){let a=!!y.routes[C],b=y.dynamicRoutes[D];if(b&&!1===b.fallback&&!a)throw new s.NoFallbackError}let F=null;!E||J.isDev||x||(F="/index"===(F=C)?"/":F);let G=!0===J.isDev||!E,H=E&&!G,I=a.method||"GET",K=(0,i.getTracer)(),L=K.getActiveScopeSpan(),M={params:v,prerenderManifest:y,renderOpts:{experimental:{cacheComponents:!!w.experimental.cacheComponents,authInterrupts:!!w.experimental.authInterrupts},supportsDynamicResponse:G,incrementalCache:(0,h.getRequestMeta)(a,"incrementalCache"),cacheLifeProfiles:null==(d=w.experimental)?void 0:d.cacheLife,isRevalidate:H,waitUntil:c.waitUntil,onClose:a=>{b.on("close",a)},onAfterTaskError:void 0,onInstrumentationRequestError:(b,c,d)=>J.onRequestError(a,b,d,z)},sharedContext:{buildId:u}},N=new k.NodeNextRequest(a),O=new k.NodeNextResponse(b),P=l.NextRequestAdapter.fromNodeNextRequest(N,(0,l.signalFromNodeResponse)(b));try{let d=async c=>J.handle(P,M).finally(()=>{if(!c)return;c.setAttributes({"http.status_code":b.statusCode,"next.rsc":!1});let d=K.getRootSpanAttributes();if(!d)return;if(d.get("next.span_type")!==m.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${d.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let e=d.get("next.route");if(e){let a=`${I} ${e}`;c.setAttributes({"next.route":e,"http.route":e,"next.span_name":a}),c.updateName(a)}else c.updateName(`${I} ${a.url}`)}),g=async g=>{var i,j;let k=async({previousCacheEntry:f})=>{try{if(!(0,h.getRequestMeta)(a,"minimalMode")&&A&&B&&!f)return b.statusCode=404,b.setHeader("x-nextjs-cache","REVALIDATED"),b.end("This page could not be found"),null;let e=await d(g);a.fetchMetrics=M.renderOpts.fetchMetrics;let i=M.renderOpts.pendingWaitUntil;i&&c.waitUntil&&(c.waitUntil(i),i=void 0);let j=M.renderOpts.collectedTags;if(!E)return await (0,o.I)(N,O,e,M.renderOpts.pendingWaitUntil),null;{let a=await e.blob(),b=(0,p.toNodeOutgoingHttpHeaders)(e.headers);j&&(b[r.NEXT_CACHE_TAGS_HEADER]=j),!b["content-type"]&&a.type&&(b["content-type"]=a.type);let c=void 0!==M.renderOpts.collectedRevalidate&&!(M.renderOpts.collectedRevalidate>=r.INFINITE_CACHE)&&M.renderOpts.collectedRevalidate,d=void 0===M.renderOpts.collectedExpire||M.renderOpts.collectedExpire>=r.INFINITE_CACHE?void 0:M.renderOpts.collectedExpire;return{value:{kind:t.CachedRouteKind.APP_ROUTE,status:e.status,body:Buffer.from(await a.arrayBuffer()),headers:b},cacheControl:{revalidate:c,expire:d}}}}catch(b){throw(null==f?void 0:f.isStale)&&await J.onRequestError(a,b,{routerKind:"App Router",routePath:e,routeType:"route",revalidateReason:(0,n.c)({isRevalidate:H,isOnDemandRevalidate:A})},z),b}},l=await J.handleResponse({req:a,nextConfig:w,cacheKey:F,routeKind:f.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:y,isRoutePPREnabled:!1,isOnDemandRevalidate:A,revalidateOnlyGenerated:B,responseGenerator:k,waitUntil:c.waitUntil});if(!E)return null;if((null==l||null==(i=l.value)?void 0:i.kind)!==t.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==l||null==(j=l.value)?void 0:j.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});(0,h.getRequestMeta)(a,"minimalMode")||b.setHeader("x-nextjs-cache",A?"REVALIDATED":l.isMiss?"MISS":l.isStale?"STALE":"HIT"),x&&b.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let m=(0,p.fromNodeOutgoingHttpHeaders)(l.value.headers);return(0,h.getRequestMeta)(a,"minimalMode")&&E||m.delete(r.NEXT_CACHE_TAGS_HEADER),!l.cacheControl||b.getHeader("Cache-Control")||m.get("Cache-Control")||m.set("Cache-Control",(0,q.getCacheControlHeader)(l.cacheControl)),await (0,o.I)(N,O,new Response(l.value.body,{headers:m,status:l.value.status||200})),null};L?await g(L):await K.withPropagatedContext(a.headers,()=>K.trace(m.BaseServerSpan.handleRequest,{spanName:`${I} ${a.url}`,kind:i.SpanKind.SERVER,attributes:{"http.method":I,"http.target":a.url}},g))}catch(b){if(b instanceof s.NoFallbackError||await J.onRequestError(a,b,{routerKind:"App Router",routePath:D,routeType:"route",revalidateReason:(0,n.c)({isRevalidate:H,isOnDemandRevalidate:A})}),E)throw b;return await (0,o.I)(N,O,new Response(null,{status:500})),null}}},663033:a=>{a.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},710846:a=>{a.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},719771:a=>{a.exports=require("process")},731421:a=>{a.exports=require("node:child_process")},744870:a=>{a.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},848161:a=>{a.exports=require("node:os")},973024:a=>{a.exports=require("node:fs")},979428:a=>{a.exports=require("buffer")},986439:a=>{a.exports=require("next/dist/shared/lib/no-fallback-error.external")}};var b=require("../../../../../webpack-runtime.js");b.C(a);var c=b.X(0,[76973,22137,93349,94856],()=>b(b.s=644185));module.exports=c})();