"use strict";(()=>{var a={};a.id=86045,a.ids=[86045],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")},279048:(a,b,c)=>{c.r(b),c.d(b,{handler:()=>K,patchFetch:()=>J,routeModule:()=>F,serverHooks:()=>I,workAsyncStorage:()=>G,workUnitAsyncStorage:()=>H});var d={};c.r(d),c.d(d,{DELETE:()=>E,GET:()=>C,PATCH:()=>D,dynamic:()=>w,runtime:()=>x});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(556881);let w="force-dynamic",x="nodejs";function y(a){return a.replace(/'/g,"''")}function z(a){if("string"!=typeof a)return a;try{return JSON.parse(a)}catch{return a}}function A(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"}function B(a,b){return(0,u.hM)(a,b)}async function C(a,{params:b}){let{name:c,id:d}=await b;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c))return Response.json({error:"Invalid object name"},{status:400});if(!d||d.length>64)return Response.json({error:"Invalid entry ID"},{status:400});let e=(0,u.fO)(c);if(!e)return Response.json({error:"DuckDB not found"},{status:404});let f=B(e,`SELECT * FROM objects WHERE name = '${y(c)}' LIMIT 1`);if(0===f.length)return Response.json({error:`Object '${c}' not found`},{status:404});let g=f[0],h=B(e,`SELECT * FROM fields WHERE object_id = '${y(g.id)}' ORDER BY sort_order`),i=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.id = '${y(d)}'
     AND e.object_id = '${y(g.id)}'`);if(0===i.length){let a=B(e,`SELECT COUNT(*) as cnt FROM entries WHERE id = '${y(d)}' AND object_id = '${y(g.id)}'`);if(!a[0]||0===a[0].cnt)return Response.json({error:"Entry not found"},{status:404})}let j={entry_id:d};for(let a of i)j.created_at??=a.created_at,j.updated_at??=a.updated_at,a.field_name&&(j[a.field_name]=a.value);let k=h.map(a=>({...a,enum_values:a.enum_values?z(a.enum_values):void 0,enum_colors:a.enum_colors?z(a.enum_colors):void 0})),l={},m={},n={};for(let a of h.filter(a=>"relation"===a.type&&a.related_object_id)){let b=B(e,`SELECT * FROM objects WHERE id = '${y(a.related_object_id)}' LIMIT 1`);if(0===b.length)continue;let c=b[0];n[a.name]=c.name;let d=j[a.name];if(null==d||""===d){l[a.name]={},m[a.name]={};continue}let f="object"==typeof d&&null!==d?JSON.stringify(d):"string"==typeof d?d:"number"==typeof d||"boolean"==typeof d?String(d):"",g=(0,u.Dv)(f);if(0===g.length){l[a.name]={},m[a.name]={};continue}let h=B(e,`SELECT * FROM fields WHERE object_id = '${y(c.id)}' ORDER BY sort_order`),i=A(c,h),k=g.map(a=>`'${y(a)}'`).join(","),o=B(e,`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 (${k})
       AND f.object_id = '${y(c.id)}'
       AND f.name = '${y(i)}'`),p={};for(let a of o)p[a.entry_id]=a.value||a.entry_id;for(let a of g)p[a]||(p[a]=a);l[a.name]=p;let q=B(e,`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 (${k})
       AND f.object_id = '${y(c.id)}'
       AND f.type = 'url'
       ORDER BY f.sort_order`),r={};for(let a of q){if(r[a.entry_id])continue;let b=(a.value??"").trim();if(!b)continue;let c=/^https?:\/\//i.test(b)?b:`https://${b}`,d=(0,v.jv)(c);d&&(r[a.entry_id]=d)}m[a.name]=r}let o=k.map(a=>({...a,related_object_name:"relation"===a.type?n[a.name]:void 0})),p=function(a,b){let c=(0,u.b)(),d=[];for(let e of c)for(let c of B(e,`SELECT f.id, f.name, f.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 = '${y(a)}'`)){let a=B(e,`SELECT ef.entry_id as source_entry_id, ef.value as target_value
         FROM entry_fields ef
         WHERE ef.field_id = '${y(c.id)}'
         AND ef.value IS NOT NULL
         AND ef.value != ''`),f=[];for(let c of a)(0,u.Dv)(c.target_value).includes(b)&&f.push(c.source_entry_id);if(0===f.length)continue;let g=B(e,`SELECT * FROM objects WHERE id = '${y(c.object_id)}' LIMIT 1`);if(0===g.length)continue;let h=B(e,`SELECT * FROM fields WHERE object_id = '${y(c.object_id)}' ORDER BY sort_order`),i=A(g[0],h),j=f.map(a=>`'${y(a)}'`).join(","),k=B(e,`SELECT ef.entry_id, ef.value
         FROM entry_fields ef
         JOIN fields f ON f.id = ef.field_id
         WHERE ef.entry_id IN (${j})
         AND f.name = '${y(i)}'
         AND f.object_id = '${y(c.object_id)}'`),l={};for(let a of k)l[a.entry_id]=a.value||a.entry_id;let m=f.map(a=>({id:a,label:l[a]||a}));d.push({fieldName:c.name,sourceObjectName:c.source_object_name,sourceObjectId:c.object_id,displayField:i,links:m})}return d}(g.id,d),q=A(g,h);return Response.json({object:g,fields:o,entry:j,relationLabels:l,relationFaviconUrls:m,reverseRelations:p,effectiveDisplayField:q})}async function D(a,{params:b}){let{name:c,id:d}=await b;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c))return Response.json({error:"Invalid object name"},{status:400});let e=(0,u.fO)(c);if(!e)return Response.json({error:"DuckDB not found"},{status:404});let f=B(e,`SELECT id FROM objects WHERE name = '${y(c)}' LIMIT 1`);if(0===f.length)return Response.json({error:`Object '${c}' not found`},{status:404});let g=f[0].id,h=B(e,`SELECT COUNT(*) as cnt FROM entries WHERE id = '${y(d)}' AND object_id = '${y(g)}'`);if(!h[0]||0===h[0].cnt)return Response.json({error:"Entry not found"},{status:404});let i=(await a.json()).fields??{},j=new Map(B(e,`SELECT id, name FROM fields WHERE object_id = '${y(g)}'`).map(a=>[a.name,a.id])),k=0;for(let[a,b]of Object.entries(i)){let c=j.get(a);if(!c)continue;let f=null==b?"NULL":`'${y(String(b))}'`,g=B(e,`SELECT COUNT(*) as cnt FROM entry_fields WHERE entry_id = '${y(d)}' AND field_id = '${y(c)}'`);g[0]?.cnt>0?(0,u.u4)(e,`UPDATE entry_fields SET value = ${f} WHERE entry_id = '${y(d)}' AND field_id = '${y(c)}'`):(0,u.u4)(e,`INSERT INTO entry_fields (entry_id, field_id, value) VALUES ('${y(d)}', '${y(c)}', ${f})`),k++}let l=new Date().toISOString();return(0,u.u4)(e,`UPDATE entries SET updated_at = '${l}' WHERE id = '${y(d)}'`),Response.json({ok:!0,updatedCount:k})}async function E(a,{params:b}){let{name:c,id:d}=await b;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c))return Response.json({error:"Invalid object name"},{status:400});let e=(0,u.fO)(c);if(!e)return Response.json({error:"DuckDB not found"},{status:404});let f=B(e,`SELECT id FROM objects WHERE name = '${y(c)}' LIMIT 1`);if(0===f.length)return Response.json({error:`Object '${c}' not found`},{status:404});let g=f[0].id;return(0,u.u4)(e,`DELETE FROM entry_fields WHERE entry_id = '${y(d)}'`),(0,u.u4)(e,`DELETE FROM entries WHERE id = '${y(d)}' AND object_id = '${y(g)}'`),Response.json({ok:!0})}let F=new e.AppRouteRouteModule({definition:{kind:f.RouteKind.APP_ROUTE,page:"/api/workspace/objects/[name]/entries/[id]/route",pathname:"/api/workspace/objects/[name]/entries/[id]",filename:"route",bundlePath:"app/api/workspace/objects/[name]/entries/[id]/route"},distDir:".next",relativeProjectDir:"",resolvedPagePath:"/home/runner/work/DenchClaw/DenchClaw/apps/web/app/api/workspace/objects/[name]/entries/[id]/route.ts",nextConfigOutput:"standalone",userland:d}),{workAsyncStorage:G,workUnitAsyncStorage:H,serverHooks:I}=F;function J(){return(0,g.patchFetch)({workAsyncStorage:G,workUnitAsyncStorage:H})}async function K(a,b,c){var d;let e="/api/workspace/objects/[name]/entries/[id]/route";"/index"===e&&(e="/");let g=await F.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 G=null;!E||F.isDev||x||(G="/index"===(G=C)?"/":G);let H=!0===F.isDev||!E,I=E&&!H,J=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:H,incrementalCache:(0,h.getRequestMeta)(a,"incrementalCache"),cacheLifeProfiles:null==(d=w.experimental)?void 0:d.cacheLife,isRevalidate:I,waitUntil:c.waitUntil,onClose:a=>{b.on("close",a)},onAfterTaskError:void 0,onInstrumentationRequestError:(b,c,d)=>F.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=>F.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=`${J} ${e}`;c.setAttributes({"next.route":e,"http.route":e,"next.span_name":a}),c.updateName(a)}else c.updateName(`${J} ${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 F.onRequestError(a,b,{routerKind:"App Router",routePath:e,routeType:"route",revalidateReason:(0,n.c)({isRevalidate:I,isOnDemandRevalidate:A})},z),b}},l=await F.handleResponse({req:a,nextConfig:w,cacheKey:G,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:`${J} ${a.url}`,kind:i.SpanKind.SERVER,attributes:{"http.method":J,"http.target":a.url}},g))}catch(b){if(b instanceof s.NoFallbackError||await F.onRequestError(a,b,{routerKind:"App Router",routePath:D,routeType:"route",revalidateReason:(0,n.c)({isRevalidate:I,isOnDemandRevalidate:A})}),E)throw b;return await (0,o.I)(N,O,new Response(null,{status:500})),null}}},529294:a=>{a.exports=require("next/dist/server/app-render/work-async-storage.external.js")},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=279048));module.exports=c})();