@lpdjs/firestore-repo-service 2.6.19 → 2.6.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{create-servers-O2stZ-yF.d.ts → create-servers-DWvDFvHz.d.ts} +2 -2
- package/dist/{create-servers-C3CIViuc.d.cts → create-servers-DmX0SDwc.d.cts} +2 -2
- package/dist/index.cjs +19 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +19 -19
- package/dist/index.js.map +1 -1
- package/dist/llms-full.txt +1 -1
- package/dist/llms.txt +1 -1
- package/dist/servers/admin/index.cjs +34 -34
- package/dist/servers/admin/index.cjs.map +1 -1
- package/dist/servers/admin/index.js +34 -34
- package/dist/servers/admin/index.js.map +1 -1
- package/dist/servers/index.cjs +28 -28
- package/dist/servers/index.cjs.map +1 -1
- package/dist/servers/index.d.cts +1 -1
- package/dist/servers/index.d.ts +1 -1
- package/dist/servers/index.js +28 -28
- package/dist/servers/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {jsx,jsxs,Fragment}from'hono/jsx/jsx-runtime';import {randomBytes}from'crypto';import {z}from'zod';import {renderToString}from'hono/jsx/dom/server';var Ht=Object.defineProperty;var Ee=(e,t)=>()=>(e&&(t=e(e=0)),t);var Ut=(e,t)=>{for(var n in t)Ht(e,n,{get:t[n],enumerable:true});};function j(e){let t=e,n=t._zod?.def?.type;if(n)return Jt[n]??`Zod${n.charAt(0).toUpperCase()}${n.slice(1)}`;let r=t._def?.typeName;return r||""}function G(e){let t=e;if(t._zod?.def?.innerType)return t._zod.def.innerType;if(t._def?.innerType)return t._def.innerType}function st(e){let t=e,n=t._zod?.def?.in;if(n)return n;if(t._def?.schema)return t._def.schema}function it(e){let t=e;if(t._zod?.def?.element)return t._zod.def.element;if(t._def?.type)return t._def.type}function lt(e){let t=e;if(t._zod?.def?.defaultValue!==void 0)return t._zod.def.defaultValue;let n=t._def?.defaultValue;return typeof n=="function"?n():n}function Y(e){let t=e;return t.shape&&typeof t.shape=="object"?t.shape:t._zod?.def?.shape&&typeof t._zod.def.shape=="object"?t._zod.def.shape:t._def?.shape?typeof t._def.shape=="function"?t._def.shape():t._def.shape:{}}function we(e){let t=e;return Array.isArray(t.options)?t.options:t._zod?.def?.entries?Object.values(t._zod.def.entries):Array.isArray(t._def?.values)?t._def.values:[]}function ke(e){let t=e;return t._zod?.def?.entries?t._zod.def.entries:t.enum&&typeof t.enum=="object"?t.enum:t._def?.values&&typeof t._def.values=="object"?t._def.values:{}}function Se(e){let t=e;return Array.isArray(t._zod?.def?.values)?t._zod.def.values[0]:t._def?.value}function dt(e){let t=e;return Array.isArray(t.options)?t.options:Array.isArray(t._zod?.def?.options)?t._zod.def.options:Array.isArray(t._def?.options)?t._def.options:[]}function ct(e){let t=e,n=[],r=t._zod?.def?.checks;if(Array.isArray(r)){for(let o of r)o.format&&n.push(o.format);if(n.length>0)return n}let a=t._def?.checks;if(Array.isArray(a))for(let o of a)o.kind&&n.push(o.kind);return n}var Jt,Te=Ee(()=>{Jt={string:"ZodString",number:"ZodNumber",bigint:"ZodBigInt",boolean:"ZodBoolean",date:"ZodDate",enum:"ZodEnum",nativeEnum:"ZodNativeEnum",literal:"ZodLiteral",object:"ZodObject",array:"ZodArray",optional:"ZodOptional",nullable:"ZodNullable",default:"ZodDefault",coerce:"ZodCoerce",union:"ZodUnion",undefined:"ZodUndefined",unknown:"ZodUnknown",any:"ZodAny",record:"ZodRecord"};});function vt({val:e}){return jsx("span",{class:"text-sm text-base-content/80 font-mono tabular-nums whitespace-nowrap",children:e.toLocaleString()})}function an({message:e}){return jsx("span",{class:"tooltip tooltip-warning tooltip-right inline-flex align-middle ml-1 text-warning","data-tip":e,role:"img","aria-label":e,children:jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",class:"size-3.5",children:jsx("path",{d:"M12 2 1 22h22L12 2zm0 6 7.5 13h-15L12 8zm-1 4v4h2v-4h-2zm0 5v2h2v-2h-2z"})})})}function ye({val:e,mismatch:t}){let n=on(e);return t?jsxs("span",{class:"inline-flex items-start gap-0.5",children:[n,jsx(an,{message:t})]}):n}function on(e){if(e==null)return jsx("span",{class:"opacity-30 italic text-xs",children:"\u2014"});if(typeof e=="boolean")return e?jsx("span",{class:"badge badge-success badge-sm",children:"true"}):jsx("span",{class:"badge badge-error badge-sm",children:"false"});if(e instanceof Date)return jsx(vt,{val:e});if(typeof e=="object"&&e!==null&&typeof e.toDate=="function")return jsx(vt,{val:e.toDate()});if(typeof e=="number")return jsx("span",{class:"text-sm font-mono tabular-nums",children:String(e)});if(Array.isArray(e))return e.length===0?jsx("span",{class:"text-xs text-base-content/30",children:"[]"}):jsxs("ul",{class:"list-none p-0 m-0 space-y-0.5 text-xs",children:[e.slice(0,8).map((n,r)=>jsx("li",{class:"break-all",children:typeof n=="object"?JSON.stringify(n):String(n)},r)),e.length>8&&jsxs("li",{class:"text-base-content/40 italic",children:["+",e.length-8," more\u2026"]})]});if(typeof e=="object"&&e!==null){let n=Object.entries(e);return n.length===0?jsx("span",{class:"text-xs text-base-content/30",children:"{}"}):jsxs("dl",{class:"grid grid-cols-[auto_1fr] gap-x-2 gap-y-0.5 text-xs m-0",children:[n.slice(0,8).map(([r,a])=>jsxs(Fragment,{children:[jsx("dt",{class:"text-base-content/50 font-semibold whitespace-nowrap",children:r}),jsx("dd",{class:"break-all",children:String(a??"")})]})),n.length>8&&jsxs("dt",{class:"col-span-2 text-base-content/40 italic",children:["+",n.length-8," more\u2026"]})]})}let t=String(e);return jsx("span",{class:"text-sm break-all",children:t})}var _e=Ee(()=>{});function he(e){if(!e)return "unknown";let t=He(e);switch(j(t)){case "ZodString":return "string";case "ZodNumber":return "number";case "ZodBigInt":return "bigint";case "ZodBoolean":return "boolean";case "ZodDate":return "date";case "ZodArray":return "array";case "ZodObject":case "ZodRecord":return "object";case "ZodEnum":case "ZodNativeEnum":return "enum";case "ZodLiteral":return "literal";default:return "unknown"}}function He(e){let t=j(e);if(t==="ZodOptional"||t==="ZodNullable"||t==="ZodDefault"){let n=G(e);return n?He(n):e}return e}function ge(e,t){if(!e)return;let n=t.split("."),r=e;for(let a of n){if(!r)return;let o=He(r);if(j(o)!=="ZodObject")return;r=Y(o)[a];}return r}function cn(e){return e==null?"null":e instanceof Date?"date":Array.isArray(e)?"array":typeof e=="string"?"string":typeof e=="boolean"?"boolean":typeof e=="bigint"?"bigint":typeof e=="number"?"number":typeof e=="object"?typeof e.toDate=="function"?"date":"object":"unknown"}function Ae(e,t){if(e==="unknown")return null;let n=cn(t);return n==="null"?null:e==="enum"||e==="literal"?n==="string"||n==="number"?null:`Expected ${e} (string/number), got ${n}`:e===n||e==="number"&&n==="bigint"||e==="bigint"&&n==="number"?null:`Expected ${e}, got ${n}`}var Ue=Ee(()=>{Te();});var kt={};Ut(kt,{PanelMany:()=>pn,PanelOne:()=>un,RightPanel:()=>qe});function un({doc:e,repoName:t,basePath:n,schema:r,columns:a}){if(!e)return jsx("div",{class:"text-center py-12 text-base-content/50",children:"Document not found."});let o=String(e.docId??e.id??""),s=`${n}/${t}/${encodeURIComponent(o)}/edit`,c=wt(r,a);return jsxs("div",{class:"space-y-4",children:[jsxs("div",{class:"flex items-center justify-between gap-2",children:[jsxs("div",{class:"text-xs text-base-content/60",children:[jsx("span",{class:"font-mono",children:t}),jsx("span",{class:"opacity-50",children:" \xB7 "}),jsx("span",{class:"font-mono break-all",children:o})]}),jsx("a",{href:s,class:"btn btn-sm btn-primary",children:"Edit \u2192"})]}),jsx("dl",{class:"grid grid-cols-[max-content_1fr] gap-x-4 gap-y-2 border border-base-300 rounded-box p-4 bg-base-100",children:a.map(l=>{let p=e[l],b=c[l],g=b?Ae(b,p):null;return jsxs(Fragment,{children:[jsx("dt",{class:"text-xs font-semibold text-base-content/60 uppercase tracking-wide pt-0.5",children:l}),jsx("dd",{class:"min-w-0",children:jsx(ye,{val:p,mismatch:g})})]})})})]})}function pn({docs:e,repoName:t,basePath:n,fk:r,fv:a,columns:o,schema:s,pagination:c}){let l=`${n}/${t}?fv_${r}=${encodeURIComponent(a)}`,p=wt(s,o);return jsxs("div",{class:"space-y-4",children:[jsxs("div",{class:"flex items-center justify-between gap-2",children:[jsxs("div",{class:"text-xs text-base-content/60",children:[jsx("span",{class:"font-mono",children:t}),jsx("span",{class:"opacity-50",children:" where "}),jsx("span",{class:"font-mono",children:r}),jsx("span",{class:"opacity-50",children:" = "}),jsx("span",{class:"font-mono break-all",children:a}),jsx("span",{class:"opacity-50",children:" \xB7 "}),jsxs("span",{children:[e.length," doc",e.length!==1?"s":""]})]}),jsx("a",{href:l,class:"btn btn-sm btn-outline",children:"Full view \u2192"})]}),jsx("div",{class:"overflow-x-auto rounded-box border border-base-300 bg-base-100",children:jsxs("table",{class:"table table-xs w-full",children:[jsx("thead",{children:jsxs("tr",{class:"bg-base-200/50",children:[o.map((b,g)=>jsx("th",{class:"text-xs font-semibold text-base-content/60 uppercase tracking-wide",children:b},g)),jsx("th",{})]})}),jsx("tbody",{children:e.length===0?jsx("tr",{children:jsx("td",{colspan:o.length+1,class:"text-center py-10 text-base-content/40",children:"No related documents"})}):e.map((b,g)=>{let C=String(b.docId??b.id??""),S=`${n}/${t}/${encodeURIComponent(C)}/edit`;return jsxs("tr",{class:"hover",children:[o.map((y,U)=>{let D=b[y],B=p[y],m=B?Ae(B,D):null;return jsx("td",{class:"align-top py-1.5",children:jsx(ye,{val:D,mismatch:m})},U)}),jsx("td",{class:"text-right py-1.5",children:jsx("a",{href:S,class:"btn btn-xs btn-ghost",children:"Edit"})})]},g)})})]})}),(c.hasPrev||c.hasNext)&&jsxs("div",{class:"flex justify-center items-center gap-2",children:[c.hasPrev?jsx("button",{type:"button",class:"btn btn-xs btn-outline","data-frs-panel-page":"prev","data-cursor":c.prevCursor,children:"\u2190 Previous"}):jsx("button",{class:"btn btn-xs btn-outline",disabled:true,children:"\u2190 Previous"}),c.hasNext?jsx("button",{type:"button",class:"btn btn-xs btn-outline","data-frs-panel-page":"next","data-cursor":c.nextCursor,children:"Next \u2192"}):jsx("button",{class:"btn btn-xs btn-outline",disabled:true,children:"Next \u2192"})]})]})}function wt(e,t){if(!e)return {};let n={};for(let r of t)n[r]=he(ge(e,r));return n}var qe,Ve=Ee(()=>{_e();Ue();qe=({basePath:e=""})=>jsxs("div",{class:"fixed inset-0 z-[100] hidden pointer-events-none","data-frs-panel-root":true,"data-frs-base-path":e,"aria-hidden":"true",children:[jsx("div",{class:"absolute inset-0 bg-black/30 opacity-0 transition-opacity duration-200 pointer-events-auto","data-frs-panel-backdrop":true}),jsxs("aside",{class:"absolute top-0 right-0 h-full w-full md:w-1/2 bg-base-100 shadow-2xl border-l border-base-300 translate-x-full transition-transform duration-200 pointer-events-auto flex flex-col","data-frs-panel":true,role:"dialog","aria-label":"Relation preview",children:[jsxs("header",{class:"flex items-center justify-between px-5 py-3 border-b border-base-300 bg-base-200/40 shrink-0",children:[jsx("h2",{class:"font-semibold text-base truncate","data-frs-panel-title":true,children:"Relation"}),jsx("button",{type:"button",class:"btn btn-sm btn-ghost btn-circle","data-frs-panel-close":true,"aria-label":"Close panel",children:"\u2715"})]}),jsx("div",{class:"flex-1 overflow-auto p-5 text-sm","data-frs-panel-body":true,children:jsx("div",{class:"flex items-center justify-center py-12 text-base-content/40",children:jsx("span",{class:"loading loading-spinner loading-md"})})})]})]});});function ze(e,t,n){let r=t==="/"?"":t.replace(/\/$/,"");if(process.env.FUNCTIONS_EMULATOR==="true"){let s=process.env.GCLOUD_PROJECT??process.env.GOOGLE_CLOUD_PROJECT??"demo-project",c=n??process.env.FUNCTION_REGION??"us-central1",l=(process.env.FUNCTION_TARGET??"").replace(/\./g,"-");return `/${s}/${c}/${l}${r}`}let a=process.env.K_SERVICE,o=e?.hostname??e?.headers?.host??"";return a&&typeof o=="string"&&o.includes("cloudfunctions.net")?`/${a.toLowerCase()}${r}`:r}function ot(e){if(typeof e=="string")return e;if(Array.isArray(e)){let t=e[0];return typeof t=="string"?t:void 0}}function Fe(e){return !!e&&typeof e=="object"&&e.__authExtension===true}Te();Te();function Kt(e){return e.replace(/([A-Z])/g," $1").replace(/_/g," ").replace(/^\s/,"").replace(/^./,t=>t.toUpperCase())}function ut(e){let t=e,n=true,r=false,a;for(;;){let o=j(t);if(o==="ZodOptional")n=false,t=G(t);else if(o==="ZodNullable")n=false,r=true,t=G(t);else if(o==="ZodDefault")n=false,a=lt(t),t=G(t);else if(o==="ZodEffects"||o==="ZodPipe"||o==="ZodTransform"){let s=st(t);if(!s)break;t=s;}else break}return {inner:t,required:n,nullable:r,defaultValue:a}}function ee(e,t=""){if(j(e)==="ZodObject"){let r=Y(e);return Object.entries(r).map(([a,o])=>pt(t?`${t}.${a}`:a,a,o))}return [pt(t||"value",t||"value",e)]}function pt(e,t,n){let{inner:r,required:a,nullable:o,defaultValue:s}=ut(n),c=j(r),l=Kt(t.split(".").pop()??t);switch(c){case "ZodString":{let p=ct(r),b=p.includes("email"),g=p.includes("url");return {name:e,label:l,type:"text",required:a,nullable:o,defaultValue:s,hint:b?"email":g?"url":void 0}}case "ZodNumber":case "ZodBigInt":return {name:e,label:l,type:"number",required:a,nullable:o,defaultValue:s};case "ZodBoolean":return {name:e,label:l,type:"checkbox",required:a,nullable:o,defaultValue:s};case "ZodDate":case "ZodCoerce":return {name:e,label:l,type:"datetime-local",required:a,nullable:o,defaultValue:s};case "ZodEnum":{let p=we(r);return {name:e,label:l,type:"select",required:a,nullable:o,defaultValue:s,options:p}}case "ZodNativeEnum":{let p=ke(r),b=Object.values(p).filter(g=>typeof g=="string");return {name:e,label:l,type:"select",required:a,nullable:o,defaultValue:s,options:b}}case "ZodLiteral":{let p=String(Se(r)??"");return {name:e,label:l,type:"select",required:a,nullable:o,defaultValue:s,options:[p]}}case "ZodUnion":{let p=dt(r);if(p.length>0&&p.every(S=>j(S)==="ZodLiteral")){let S=p.map(y=>String(Se(y)??""));return {name:e,label:l,type:"select",required:a,nullable:o,defaultValue:s,options:S}}if(p.some(S=>j(S)==="ZodDate"))return {name:e,label:l,type:"datetime-local",required:a,nullable:o,defaultValue:s};let C=p.find(S=>{if(j(S)==="ZodObject"){let y=Y(S);return "_latitude"in y&&"_longitude"in y||"latitude"in y&&"longitude"in y}return false});return C?{name:e,label:l,type:"textarea",required:a,nullable:o,defaultValue:s,nested:ee(C,e),hint:"GeoPoint"}:{name:e,label:l,type:"textarea",required:a,nullable:o,defaultValue:s,hint:"JSON"}}case "ZodObject":{let p=ee(r,e);return {name:e,label:l,type:"textarea",required:a,nullable:o,defaultValue:s,nested:p,hint:"JSON object"}}case "ZodArray":{let p=it(r);if(!p)return {name:e,label:l,type:"textarea",required:a,nullable:o,defaultValue:s,hint:"JSON array"};let{inner:b}=ut(p),g=j(b),C,S,y;switch(g){case "ZodString":C="text";break;case "ZodNumber":case "ZodBigInt":C="number";break;case "ZodBoolean":C="checkbox";break;case "ZodDate":C="datetime-local";break;case "ZodEnum":C="select",S=we(b);break;case "ZodNativeEnum":C="select",S=Object.values(ke(b)).filter(U=>typeof U=="string");break;case "ZodObject":C="object",y=ee(b);break;default:return {name:e,label:l,type:"textarea",required:a,nullable:o,defaultValue:s,hint:"JSON array"}}return {name:e,label:l,type:"textarea",required:a,nullable:o,defaultValue:s,arrayElementType:C,arrayElementOptions:S,arrayElementFields:y}}default:return {name:e,label:l,type:"textarea",required:a,nullable:o,defaultValue:s,hint:"JSON"}}}function bt(e,t=0){let n=t>0?`ml-${t*4}`:"",r=`field_${e.name.replace(/\./g,"__")}`,a=e.name,o=e.required?" required":"",s=e.defaultValue==="__null__",c=!s&&e.defaultValue!=null?String(e.defaultValue):"",l=e.nullable&&e.type!=="checkbox"?`<span class="flex items-center gap-1 shrink-0">
|
|
1
|
+
import {jsx,jsxs,Fragment}from'hono/jsx/jsx-runtime';import {randomBytes}from'crypto';import {z}from'zod';import {renderToString}from'hono/jsx/dom/server';var qt=Object.defineProperty;var Ee=(e,t)=>()=>(e&&(t=e(e=0)),t);var Vt=(e,t)=>{for(var n in t)qt(e,n,{get:t[n],enumerable:true});};function L(e){let t=e,n=t._zod?.def?.type;if(n)return Gt[n]??`Zod${n.charAt(0).toUpperCase()}${n.slice(1)}`;let r=t._def?.typeName;return r||""}function W(e){let t=e;if(t._zod?.def?.innerType)return t._zod.def.innerType;if(t._def?.innerType)return t._def.innerType}function it(e){let t=e,n=t._zod?.def?.in;if(n)return n;if(t._def?.schema)return t._def.schema}function lt(e){let t=e;if(t._zod?.def?.element)return t._zod.def.element;if(t._def?.type)return t._def.type}function dt(e){let t=e;if(t._zod?.def?.defaultValue!==void 0)return t._zod.def.defaultValue;let n=t._def?.defaultValue;return typeof n=="function"?n():n}function X(e){let t=e;return t.shape&&typeof t.shape=="object"?t.shape:t._zod?.def?.shape&&typeof t._zod.def.shape=="object"?t._zod.def.shape:t._def?.shape?typeof t._def.shape=="function"?t._def.shape():t._def.shape:{}}function we(e){let t=e;return Array.isArray(t.options)?t.options:t._zod?.def?.entries?Object.values(t._zod.def.entries):Array.isArray(t._def?.values)?t._def.values:[]}function ke(e){let t=e;return t._zod?.def?.entries?t._zod.def.entries:t.enum&&typeof t.enum=="object"?t.enum:t._def?.values&&typeof t._def.values=="object"?t._def.values:{}}function Se(e){let t=e;return Array.isArray(t._zod?.def?.values)?t._zod.def.values[0]:t._def?.value}function Te(e){let t=e;return Array.isArray(t.options)?t.options:Array.isArray(t._zod?.def?.options)?t._zod.def.options:Array.isArray(t._def?.options)?t._def.options:[]}function ct(e){let t=e,n=[],r=t._zod?.def?.checks;if(Array.isArray(r)){for(let o of r)o.format&&n.push(o.format);if(n.length>0)return n}let a=t._def?.checks;if(Array.isArray(a))for(let o of a)o.kind&&n.push(o.kind);return n}var Gt,Oe=Ee(()=>{Gt={string:"ZodString",number:"ZodNumber",bigint:"ZodBigInt",boolean:"ZodBoolean",date:"ZodDate",enum:"ZodEnum",nativeEnum:"ZodNativeEnum",literal:"ZodLiteral",object:"ZodObject",array:"ZodArray",optional:"ZodOptional",nullable:"ZodNullable",default:"ZodDefault",coerce:"ZodCoerce",union:"ZodUnion",undefined:"ZodUndefined",unknown:"ZodUnknown",any:"ZodAny",record:"ZodRecord"};});function vt({val:e}){return jsx("span",{class:"text-sm text-base-content/80 font-mono tabular-nums whitespace-nowrap",children:e.toLocaleString()})}function sn({message:e}){return jsx("span",{class:"tooltip tooltip-warning tooltip-right inline-flex align-middle ml-1 text-warning","data-tip":e,role:"img","aria-label":e,children:jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",class:"size-3.5",children:jsx("path",{d:"M12 2 1 22h22L12 2zm0 6 7.5 13h-15L12 8zm-1 4v4h2v-4h-2zm0 5v2h2v-2h-2z"})})})}function ye({val:e,mismatch:t}){let n=He(e);return t?jsxs("span",{class:"inline-flex items-start gap-0.5",children:[n,jsx(sn,{message:t})]}):n}function He(e){if(e==null)return jsx("span",{class:"opacity-30 italic text-xs",children:"\u2014"});if(typeof e=="boolean")return e?jsx("span",{class:"badge badge-success badge-sm",children:"true"}):jsx("span",{class:"badge badge-error badge-sm",children:"false"});if(e instanceof Date)return jsx(vt,{val:e});if(typeof e=="object"&&e!==null&&typeof e.toDate=="function")return jsx(vt,{val:e.toDate()});if(typeof e=="number")return jsx("span",{class:"text-sm font-mono tabular-nums",children:String(e)});if(Array.isArray(e))return e.length===0?jsx("span",{class:"text-xs text-base-content/30",children:"[]"}):jsxs("ul",{class:"list-none p-0 m-0 space-y-0.5 text-xs",children:[e.slice(0,8).map((n,r)=>jsx("li",{class:"break-all",children:He(n)},r)),e.length>8&&jsxs("li",{class:"text-base-content/40 italic",children:["+",e.length-8," more\u2026"]})]});if(typeof e=="object"&&e!==null){let n=Object.entries(e);return n.length===0?jsx("span",{class:"text-xs text-base-content/30",children:"{}"}):jsxs("dl",{class:"grid grid-cols-[auto_1fr] gap-x-2 gap-y-0.5 text-xs m-0",children:[n.slice(0,8).map(([r,a])=>jsxs(Fragment,{children:[jsx("dt",{class:"text-base-content/50 font-semibold whitespace-nowrap",children:r}),jsx("dd",{class:"break-all",children:He(a)})]})),n.length>8&&jsxs("dt",{class:"col-span-2 text-base-content/40 italic",children:["+",n.length-8," more\u2026"]})]})}let t=String(e);return jsx("span",{class:"text-sm break-all",children:t})}var Ne=Ee(()=>{});function he(e){if(!e)return "unknown";let t=qe(e);switch(L(t)){case "ZodString":return "string";case "ZodNumber":return "number";case "ZodBigInt":return "bigint";case "ZodBoolean":return "boolean";case "ZodDate":return "date";case "ZodArray":return "array";case "ZodObject":case "ZodRecord":return "object";case "ZodEnum":case "ZodNativeEnum":return "enum";case "ZodLiteral":return "literal";default:return "unknown"}}function qe(e){let t=L(e);if(t==="ZodOptional"||t==="ZodNullable"||t==="ZodDefault"){let n=W(e);return n?qe(n):e}return e}function ge(e,t){if(!e)return;let n=t.split("."),r=e;for(let a of n){if(!r)return;let o=qe(r);if(L(o)!=="ZodObject")return;r=X(o)[a];}return r}function un(e){return e==null?"null":e instanceof Date?"date":Array.isArray(e)?"array":typeof e=="string"?"string":typeof e=="boolean"?"boolean":typeof e=="bigint"?"bigint":typeof e=="number"?"number":typeof e=="object"?typeof e.toDate=="function"?"date":"object":"unknown"}function Ae(e,t){if(e==="unknown")return null;let n=un(t);return n==="null"?null:e==="enum"||e==="literal"?n==="string"||n==="number"?null:`Expected ${e} (string/number), got ${n}`:e===n||e==="number"&&n==="bigint"||e==="bigint"&&n==="number"?null:`Expected ${e}, got ${n}`}var Ve=Ee(()=>{Oe();});var kt={};Vt(kt,{PanelMany:()=>fn,PanelOne:()=>pn,RightPanel:()=>Je});function pn({doc:e,repoName:t,basePath:n,schema:r,columns:a}){if(!e)return jsx("div",{class:"text-center py-12 text-base-content/50",children:"Document not found."});let o=String(e.docId??e.id??""),s=`${n}/${t}/${encodeURIComponent(o)}/edit`,c=wt(r,a);return jsxs("div",{class:"space-y-4",children:[jsxs("div",{class:"flex items-center justify-between gap-2",children:[jsxs("div",{class:"text-xs text-base-content/60",children:[jsx("span",{class:"font-mono",children:t}),jsx("span",{class:"opacity-50",children:" \xB7 "}),jsx("span",{class:"font-mono break-all",children:o})]}),jsx("a",{href:s,class:"btn btn-sm btn-primary",children:"Edit \u2192"})]}),jsx("dl",{class:"grid grid-cols-[max-content_1fr] gap-x-4 gap-y-2 border border-base-300 rounded-box p-4 bg-base-100",children:a.map(l=>{let p=e[l],b=c[l],g=b?Ae(b,p):null;return jsxs(Fragment,{children:[jsx("dt",{class:"text-xs font-semibold text-base-content/60 uppercase tracking-wide pt-0.5",children:l}),jsx("dd",{class:"min-w-0",children:jsx(ye,{val:p,mismatch:g})})]})})})]})}function fn({docs:e,repoName:t,basePath:n,fk:r,fv:a,columns:o,schema:s,pagination:c}){let l=`${n}/${t}?fv_${r}=${encodeURIComponent(a)}`,p=wt(s,o);return jsxs("div",{class:"space-y-4",children:[jsxs("div",{class:"flex items-center justify-between gap-2",children:[jsxs("div",{class:"text-xs text-base-content/60",children:[jsx("span",{class:"font-mono",children:t}),jsx("span",{class:"opacity-50",children:" where "}),jsx("span",{class:"font-mono",children:r}),jsx("span",{class:"opacity-50",children:" = "}),jsx("span",{class:"font-mono break-all",children:a}),jsx("span",{class:"opacity-50",children:" \xB7 "}),jsxs("span",{children:[e.length," doc",e.length!==1?"s":""]})]}),jsx("a",{href:l,class:"btn btn-sm btn-outline",children:"Full view \u2192"})]}),jsx("div",{class:"overflow-x-auto rounded-box border border-base-300 bg-base-100",children:jsxs("table",{class:"table table-xs w-full",children:[jsx("thead",{children:jsxs("tr",{class:"bg-base-200/50",children:[o.map((b,g)=>jsx("th",{class:"text-xs font-semibold text-base-content/60 uppercase tracking-wide",children:b},g)),jsx("th",{})]})}),jsx("tbody",{children:e.length===0?jsx("tr",{children:jsx("td",{colspan:o.length+1,class:"text-center py-10 text-base-content/40",children:"No related documents"})}):e.map((b,g)=>{let k=String(b.docId??b.id??""),A=`${n}/${t}/${encodeURIComponent(k)}/edit`;return jsxs("tr",{class:"hover",children:[o.map((y,F)=>{let z=b[y],M=p[y],m=M?Ae(M,z):null;return jsx("td",{class:"align-top py-1.5",children:jsx(ye,{val:z,mismatch:m})},F)}),jsx("td",{class:"text-right py-1.5",children:jsx("a",{href:A,class:"btn btn-xs btn-ghost",children:"Edit"})})]},g)})})]})}),(c.hasPrev||c.hasNext)&&jsxs("div",{class:"flex justify-center items-center gap-2",children:[c.hasPrev?jsx("button",{type:"button",class:"btn btn-xs btn-outline","data-frs-panel-page":"prev","data-cursor":c.prevCursor,children:"\u2190 Previous"}):jsx("button",{class:"btn btn-xs btn-outline",disabled:true,children:"\u2190 Previous"}),c.hasNext?jsx("button",{type:"button",class:"btn btn-xs btn-outline","data-frs-panel-page":"next","data-cursor":c.nextCursor,children:"Next \u2192"}):jsx("button",{class:"btn btn-xs btn-outline",disabled:true,children:"Next \u2192"})]})]})}function wt(e,t){if(!e)return {};let n={};for(let r of t)n[r]=he(ge(e,r));return n}var Je,Ke=Ee(()=>{Ne();Ve();Je=({basePath:e=""})=>jsxs("div",{class:"fixed inset-0 z-[100] hidden pointer-events-none","data-frs-panel-root":true,"data-frs-base-path":e,"aria-hidden":"true",children:[jsx("div",{class:"absolute inset-0 bg-black/30 opacity-0 transition-opacity duration-200 pointer-events-auto","data-frs-panel-backdrop":true}),jsxs("aside",{class:"absolute top-0 right-0 h-full w-full md:w-1/2 bg-base-100 shadow-2xl border-l border-base-300 translate-x-full transition-transform duration-200 pointer-events-auto flex flex-col","data-frs-panel":true,role:"dialog","aria-label":"Relation preview",children:[jsxs("header",{class:"flex items-center justify-between px-5 py-3 border-b border-base-300 bg-base-200/40 shrink-0",children:[jsx("h2",{class:"font-semibold text-base truncate","data-frs-panel-title":true,children:"Relation"}),jsx("button",{type:"button",class:"btn btn-sm btn-ghost btn-circle","data-frs-panel-close":true,"aria-label":"Close panel",children:"\u2715"})]}),jsx("div",{class:"flex-1 overflow-auto p-5 text-sm","data-frs-panel-body":true,children:jsx("div",{class:"flex items-center justify-center py-12 text-base-content/40",children:jsx("span",{class:"loading loading-spinner loading-md"})})})]})]});});function De(e,t,n){let r=t==="/"?"":t.replace(/\/$/,"");if(process.env.FUNCTIONS_EMULATOR==="true"){let s=process.env.GCLOUD_PROJECT??process.env.GOOGLE_CLOUD_PROJECT??"demo-project",c=n??process.env.FUNCTION_REGION??"us-central1",l=(process.env.FUNCTION_TARGET??"").replace(/\./g,"-");return `/${s}/${c}/${l}${r}`}let a=process.env.K_SERVICE,o=e?.hostname??e?.headers?.host??"";return a&&typeof o=="string"&&o.includes("cloudfunctions.net")?`/${a.toLowerCase()}${r}`:r}function st(e){if(typeof e=="string")return e;if(Array.isArray(e)){let t=e[0];return typeof t=="string"?t:void 0}}function Fe(e){return !!e&&typeof e=="object"&&e.__authExtension===true}Oe();Oe();function Wt(e){return e.replace(/([A-Z])/g," $1").replace(/_/g," ").replace(/^\s/,"").replace(/^./,t=>t.toUpperCase())}function ut(e){let t=e,n=true,r=false,a;for(;;){let o=L(t);if(o==="ZodOptional")n=false,t=W(t);else if(o==="ZodNullable")n=false,r=true,t=W(t);else if(o==="ZodDefault")n=false,a=dt(t),t=W(t);else if(o==="ZodEffects"||o==="ZodPipe"||o==="ZodTransform"){let s=it(t);if(!s)break;t=s;}else break}return {inner:t,required:n,nullable:r,defaultValue:a}}function ee(e,t=""){if(L(e)==="ZodObject"){let r=X(e);return Object.entries(r).map(([a,o])=>pt(t?`${t}.${a}`:a,a,o))}return [pt(t||"value",t||"value",e)]}function pt(e,t,n){let{inner:r,required:a,nullable:o,defaultValue:s}=ut(n),c=L(r),l=Wt(t.split(".").pop()??t);switch(c){case "ZodString":{let p=ct(r),b=p.includes("email"),g=p.includes("url");return {name:e,label:l,type:"text",required:a,nullable:o,defaultValue:s,hint:b?"email":g?"url":void 0}}case "ZodNumber":case "ZodBigInt":return {name:e,label:l,type:"number",required:a,nullable:o,defaultValue:s};case "ZodBoolean":return {name:e,label:l,type:"checkbox",required:a,nullable:o,defaultValue:s};case "ZodDate":case "ZodCoerce":return {name:e,label:l,type:"datetime-local",required:a,nullable:o,defaultValue:s};case "ZodEnum":{let p=we(r);return {name:e,label:l,type:"select",required:a,nullable:o,defaultValue:s,options:p}}case "ZodNativeEnum":{let p=ke(r),b=Object.values(p).filter(g=>typeof g=="string");return {name:e,label:l,type:"select",required:a,nullable:o,defaultValue:s,options:b}}case "ZodLiteral":{let p=String(Se(r)??"");return {name:e,label:l,type:"select",required:a,nullable:o,defaultValue:s,options:[p]}}case "ZodUnion":{let p=Te(r);if(p.length>0&&p.every(A=>L(A)==="ZodLiteral")){let A=p.map(y=>String(Se(y)??""));return {name:e,label:l,type:"select",required:a,nullable:o,defaultValue:s,options:A}}if(p.some(A=>L(A)==="ZodDate"))return {name:e,label:l,type:"datetime-local",required:a,nullable:o,defaultValue:s};let k=p.find(A=>{if(L(A)==="ZodObject"){let y=X(A);return "_latitude"in y&&"_longitude"in y||"latitude"in y&&"longitude"in y}return false});return k?{name:e,label:l,type:"textarea",required:a,nullable:o,defaultValue:s,nested:ee(k,e),hint:"GeoPoint"}:{name:e,label:l,type:"textarea",required:a,nullable:o,defaultValue:s,hint:"JSON"}}case "ZodObject":{let p=ee(r,e);return {name:e,label:l,type:"textarea",required:a,nullable:o,defaultValue:s,nested:p,hint:"JSON object"}}case "ZodArray":{let p=lt(r);if(!p)return {name:e,label:l,type:"textarea",required:a,nullable:o,defaultValue:s,hint:"JSON array"};let{inner:b}=ut(p),g=L(b),k,A,y;switch(g){case "ZodString":k="text";break;case "ZodNumber":case "ZodBigInt":k="number";break;case "ZodBoolean":k="checkbox";break;case "ZodDate":k="datetime-local";break;case "ZodEnum":k="select",A=we(b);break;case "ZodNativeEnum":k="select",A=Object.values(ke(b)).filter(F=>typeof F=="string");break;case "ZodObject":k="object",y=ee(b);break;default:return {name:e,label:l,type:"textarea",required:a,nullable:o,defaultValue:s,hint:"JSON array"}}return {name:e,label:l,type:"textarea",required:a,nullable:o,defaultValue:s,arrayElementType:k,arrayElementOptions:A,arrayElementFields:y}}default:return {name:e,label:l,type:"textarea",required:a,nullable:o,defaultValue:s,hint:"JSON"}}}function bt(e,t=0){let n=t>0?`ml-${t*4}`:"",r=`field_${e.name.replace(/\./g,"__")}`,a=e.name,o=e.required?" required":"",s=e.defaultValue==="__null__",c=!s&&e.defaultValue!=null?String(e.defaultValue):"",l=e.nullable&&e.type!=="checkbox"?`<span class="flex items-center gap-1 shrink-0">
|
|
2
2
|
<input type="hidden" id="${r}__isnull" name="${a}__isnull" value="${s?"1":""}">
|
|
3
3
|
<label class="flex items-center gap-1 cursor-pointer select-none text-xs text-base-content/40 hover:text-base-content/70 border border-base-300 rounded px-2 py-1">
|
|
4
4
|
<input type="checkbox" class="checkbox checkbox-xs" ${s?"checked":""}
|
|
@@ -14,7 +14,7 @@ import {jsx,jsxs,Fragment}from'hono/jsx/jsx-runtime';import {randomBytes}from'cr
|
|
|
14
14
|
<div class="form-control mb-3 ${n}">
|
|
15
15
|
<label for="${r}" class="label pb-1">
|
|
16
16
|
<span class="label-text font-medium">
|
|
17
|
-
${
|
|
17
|
+
${C(e.label)}
|
|
18
18
|
<span class="text-base-content/40 text-xs ml-1">(nullable)</span>
|
|
19
19
|
</span>
|
|
20
20
|
</label>
|
|
@@ -28,41 +28,41 @@ import {jsx,jsxs,Fragment}from'hono/jsx/jsx-runtime';import {randomBytes}from'cr
|
|
|
28
28
|
<label class="label cursor-pointer justify-start gap-3">
|
|
29
29
|
<input type="checkbox" id="${r}" name="${a}" value="true"${c==="true"?" checked":""} class="checkbox checkbox-primary checkbox-sm">
|
|
30
30
|
<span class="label-text font-medium">
|
|
31
|
-
${
|
|
31
|
+
${C(e.label)}${e.required?' <span class="text-error">*</span>':""}
|
|
32
32
|
</span>
|
|
33
33
|
</label>
|
|
34
34
|
</div>`;case "select":p=`<select id="${r}" name="${a}"${o}${s?' disabled style="opacity:0.35"':""} class="select select-bordered select-sm w-full">
|
|
35
35
|
${e.required&&!e.nullable?"":'<option value="">\u2014 optional \u2014</option>'}
|
|
36
|
-
${(e.options??[]).map(b=>`<option value="${
|
|
36
|
+
${(e.options??[]).map(b=>`<option value="${C(b)}"${c===b?" selected":""}>${C(b)}</option>`).join(`
|
|
37
37
|
`)}
|
|
38
|
-
</select>`;break;case "textarea":if(e.arrayElementType)return
|
|
38
|
+
</select>`;break;case "textarea":if(e.arrayElementType)return Qt(e,t);if(e.nested&&e.nested.length>0){let b=e.nested.map(g=>bt(g,t+1)).join(`
|
|
39
39
|
`);return `
|
|
40
40
|
<fieldset class="fieldset border border-base-300 rounded-box p-3 mb-3 ${n}">
|
|
41
41
|
<legend class="fieldset-legend text-xs font-semibold text-base-content/60 px-1">
|
|
42
|
-
${
|
|
42
|
+
${C(e.label)}${e.required?' <span class="text-error">*</span>':""}
|
|
43
43
|
</legend>
|
|
44
44
|
${b}
|
|
45
45
|
</fieldset>`}p=`<textarea id="${r}" name="${a}"${o} rows="3"${s?' disabled style="opacity:0.35"':""}
|
|
46
46
|
data-json
|
|
47
47
|
class="textarea textarea-bordered textarea-sm w-full font-mono text-xs"
|
|
48
|
-
placeholder="${
|
|
49
|
-
value="${
|
|
48
|
+
placeholder="${C(e.hint??"JSON")}">${C(c)}</textarea>`;break;default:p=`<input type="${e.type}" id="${r}" name="${a}"${o}${s?' disabled style="opacity:0.35"':""}
|
|
49
|
+
value="${C(c)}"
|
|
50
50
|
class="input input-bordered input-sm w-full"${e.hint==="email"?' autocomplete="email"':e.hint==="url"?' autocomplete="url"':""}>`;}return `
|
|
51
51
|
<div class="form-control mb-3 ${n}">
|
|
52
52
|
<label for="${r}" class="label pb-1">
|
|
53
53
|
<span class="label-text font-medium">
|
|
54
|
-
${
|
|
55
|
-
${e.hint?`<span class="text-base-content/40 text-xs ml-1">(${
|
|
54
|
+
${C(e.label)}${e.required?' <span class="text-error">*</span>':""}
|
|
55
|
+
${e.hint?`<span class="text-base-content/40 text-xs ml-1">(${C(e.hint)})</span>`:""}
|
|
56
56
|
</span>
|
|
57
57
|
</label>
|
|
58
58
|
<div class="flex items-center gap-2">
|
|
59
59
|
<div class="flex-1 min-w-0">${p}</div>
|
|
60
60
|
${l}
|
|
61
61
|
</div>
|
|
62
|
-
</div>`}function
|
|
62
|
+
</div>`}function C(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Qt(e,t){let n=t>0?`ml-${t*4}`:"",r=`field_${e.name.replace(/\./g,"__")}`,a=e.defaultValue==="__null__",o=e.arrayElementType==="object",s=[];if(e.defaultValue!=null&&e.defaultValue!==""&&e.defaultValue!=="__null__")try{s=JSON.parse(String(e.defaultValue));}catch{}Array.isArray(s)||(s=[]);let c=o?s.map(b=>mt(e,b??{})).join(`
|
|
63
63
|
`):s.map(b=>ft(e,b)).join(`
|
|
64
64
|
`),l=o?mt(e,{}):ft(e,""),p=e.nullable?`<span class="flex items-center gap-1 mt-2">
|
|
65
|
-
<input type="hidden" id="${r}__isnull" name="${
|
|
65
|
+
<input type="hidden" id="${r}__isnull" name="${C(e.name)}__isnull" value="${a?"1":""}">
|
|
66
66
|
<label class="flex items-center gap-1 cursor-pointer select-none text-xs text-base-content/40 hover:text-base-content/70 border border-base-300 rounded px-2 py-1">
|
|
67
67
|
<input type="checkbox" class="checkbox checkbox-xs" ${a?"checked":""}
|
|
68
68
|
onchange="(function(cb){
|
|
@@ -76,11 +76,11 @@ import {jsx,jsxs,Fragment}from'hono/jsx/jsx-runtime';import {randomBytes}from'cr
|
|
|
76
76
|
</label>
|
|
77
77
|
</span>`:"";return `
|
|
78
78
|
<fieldset class="fieldset border border-base-300 rounded-box p-3 mb-3 ${n}"
|
|
79
|
-
data-frs-array="${
|
|
79
|
+
data-frs-array="${C(e.name)}" data-frs-array-type="${C(e.arrayElementType??"text")}">
|
|
80
80
|
<legend class="fieldset-legend text-xs font-semibold text-base-content/60 px-1">
|
|
81
|
-
${
|
|
81
|
+
${C(e.label)}${e.required?' <span class="text-error">*</span>':""}
|
|
82
82
|
</legend>
|
|
83
|
-
<input type="hidden" id="${r}" name="${
|
|
83
|
+
<input type="hidden" id="${r}" name="${C(e.name)}" value="${C(JSON.stringify(s))}"${a?" disabled":""}>
|
|
84
84
|
<div data-frs-array-items${a?' style="opacity:0.35"':""}>
|
|
85
85
|
${c}
|
|
86
86
|
</div>
|
|
@@ -89,11 +89,11 @@ import {jsx,jsxs,Fragment}from'hono/jsx/jsx-runtime';import {randomBytes}from'cr
|
|
|
89
89
|
${p}
|
|
90
90
|
</fieldset>`}function ft(e,t){let n=t!=null?String(t):"",r;switch(e.arrayElementType){case "select":r=`<select data-frs-val class="select select-bordered select-sm flex-1">
|
|
91
91
|
<option value="">\u2014</option>
|
|
92
|
-
${(e.arrayElementOptions??[]).map(a=>`<option value="${
|
|
92
|
+
${(e.arrayElementOptions??[]).map(a=>`<option value="${C(a)}"${n===a?" selected":""}>${C(a)}</option>`).join("")}
|
|
93
93
|
</select>`;break;case "checkbox":r=`<label class="flex items-center gap-2 flex-1 cursor-pointer">
|
|
94
94
|
<input type="checkbox" data-frs-val class="checkbox checkbox-sm checkbox-primary"${n==="true"?" checked":""}>
|
|
95
95
|
<span class="text-sm">true</span>
|
|
96
|
-
</label>`;break;case "number":r=`<input type="number" data-frs-val value="${
|
|
96
|
+
</label>`;break;case "number":r=`<input type="number" data-frs-val value="${C(n)}" class="input input-bordered input-sm flex-1">`;break;case "datetime-local":r=`<input type="datetime-local" data-frs-val value="${C(n)}" class="input input-bordered input-sm flex-1">`;break;default:r=`<input type="text" data-frs-val value="${C(n)}" class="input input-bordered input-sm flex-1">`;}return `<div class="flex items-center gap-2 mb-2" data-frs-array-item>
|
|
97
97
|
${r}
|
|
98
98
|
<button type="button" class="btn btn-xs btn-ghost text-error" data-frs-array-rm>×</button>
|
|
99
99
|
</div>`}function mt(e,t){return `<div class="border border-base-200 rounded p-3 mb-2" data-frs-array-item>
|
|
@@ -102,38 +102,38 @@ import {jsx,jsxs,Fragment}from'hono/jsx/jsx-runtime';import {randomBytes}from'cr
|
|
|
102
102
|
</div>
|
|
103
103
|
${(e.arrayElementFields??[]).map(a=>{let o=t[a.name],s=o==null?"":typeof o=="object"?JSON.stringify(o):String(o);switch(a.type){case "checkbox":return `<div class="form-control mb-2">
|
|
104
104
|
<label class="label cursor-pointer justify-start gap-3">
|
|
105
|
-
<input type="checkbox" data-frs-key="${
|
|
106
|
-
<span class="label-text text-sm">${
|
|
105
|
+
<input type="checkbox" data-frs-key="${C(a.name)}" class="checkbox checkbox-sm checkbox-primary"${s==="true"?" checked":""}>
|
|
106
|
+
<span class="label-text text-sm">${C(a.label)}</span>
|
|
107
107
|
</label>
|
|
108
108
|
</div>`;case "select":return `<div class="form-control mb-2">
|
|
109
|
-
<label class="label pb-1"><span class="label-text text-sm">${
|
|
110
|
-
<select data-frs-key="${
|
|
109
|
+
<label class="label pb-1"><span class="label-text text-sm">${C(a.label)}</span></label>
|
|
110
|
+
<select data-frs-key="${C(a.name)}" class="select select-bordered select-sm w-full">
|
|
111
111
|
${a.required?"":'<option value="">\u2014</option>'}
|
|
112
|
-
${(a.options??[]).map(c=>`<option value="${
|
|
112
|
+
${(a.options??[]).map(c=>`<option value="${C(c)}"${s===c?" selected":""}>${C(c)}</option>`).join("")}
|
|
113
113
|
</select>
|
|
114
114
|
</div>`;case "number":return `<div class="form-control mb-2">
|
|
115
|
-
<label class="label pb-1"><span class="label-text text-sm">${
|
|
116
|
-
<input type="number" data-frs-key="${
|
|
115
|
+
<label class="label pb-1"><span class="label-text text-sm">${C(a.label)}</span></label>
|
|
116
|
+
<input type="number" data-frs-key="${C(a.name)}" value="${C(s)}" class="input input-bordered input-sm w-full">
|
|
117
117
|
</div>`;case "datetime-local":return `<div class="form-control mb-2">
|
|
118
|
-
<label class="label pb-1"><span class="label-text text-sm">${
|
|
119
|
-
<input type="datetime-local" data-frs-key="${
|
|
118
|
+
<label class="label pb-1"><span class="label-text text-sm">${C(a.label)}</span></label>
|
|
119
|
+
<input type="datetime-local" data-frs-key="${C(a.name)}" value="${C(s)}" class="input input-bordered input-sm w-full">
|
|
120
120
|
</div>`;case "textarea":return `<div class="form-control mb-2">
|
|
121
|
-
<label class="label pb-1"><span class="label-text text-sm">${
|
|
122
|
-
<textarea data-frs-key="${
|
|
121
|
+
<label class="label pb-1"><span class="label-text text-sm">${C(a.label)}</span></label>
|
|
122
|
+
<textarea data-frs-key="${C(a.name)}" rows="2" class="textarea textarea-bordered textarea-sm w-full font-mono text-xs" placeholder="JSON">${C(s)}</textarea>
|
|
123
123
|
</div>`;default:return `<div class="form-control mb-2">
|
|
124
|
-
<label class="label pb-1"><span class="label-text text-sm">${
|
|
125
|
-
<input type="text" data-frs-key="${
|
|
124
|
+
<label class="label pb-1"><span class="label-text text-sm">${C(a.label)}</span></label>
|
|
125
|
+
<input type="text" data-frs-key="${C(a.name)}" value="${C(s)}" class="input input-bordered input-sm w-full">
|
|
126
126
|
</div>`}}).join(`
|
|
127
127
|
`)}
|
|
128
128
|
</div>`}function le(e,t,n,r="Save"){let a=e.map(o=>bt(o)).join(`
|
|
129
129
|
`);return `
|
|
130
|
-
<form action="${
|
|
130
|
+
<form action="${C(t)}" method="${n}" novalidate data-frs-form>
|
|
131
131
|
${a}
|
|
132
132
|
<div class="flex gap-2 mt-4 pt-4 border-t border-base-200">
|
|
133
|
-
<button type="submit" class="btn btn-primary btn-sm">${
|
|
133
|
+
<button type="submit" class="btn btn-primary btn-sm">${C(r)}</button>
|
|
134
134
|
<button type="button" class="btn btn-ghost btn-sm" onclick="history.back()">Cancel</button>
|
|
135
135
|
</div>
|
|
136
|
-
</form>`}var
|
|
136
|
+
</form>`}var Xt=new Set(["<","<=",">",">=","!="]),Yt=new Set(["array-contains","array-contains-any"]);function je(e){return e==="desc"?"DESCENDING":"ASCENDING"}function en(e){let t=e.split("/").filter(Boolean);return t[t.length-1]??e}function tn(e,t,n,r,a){let o=[],s=new Set;for(let l of r)if(l.op==="=="||l.op==="in"||l.op==="not-in"){if(s.has(l.field))continue;s.add(l.field),o.push({fieldPath:l.field,order:"ASCENDING"});}for(let l of r)if(Yt.has(l.op)){if(s.has(l.field))continue;s.add(l.field),o.push({fieldPath:l.field,arrayConfig:"CONTAINS"});}for(let l of r)if(Xt.has(l.op)){if(s.has(l.field))continue;s.add(l.field);let p=a?.field===l.field?je(a.dir):"ASCENDING";o.push({fieldPath:l.field,order:p});}if(a&&!s.has(a.field)&&o.push({fieldPath:a.field,order:je(a.dir)}),o.length===1&&n)return an(e,t,o[0]);let c=a&&o.some(l=>l.fieldPath===a.field)?je(a.dir):"ASCENDING";return o.push({fieldPath:"__name__",order:c}),nn(e,t,n,o)}function nn(e,t,n,r,a="(default)"){let o=`projects/${e}/databases/${a}/collectionGroups/${t}/indexes/_`,s=[...Me(1,o),..._e(2,n?2:1)];for(let p of r)s.push(...yt(3,ht(p)));let c=a==="(default)"?"-default-":a,l=encodeURIComponent(gt(s));return `https://console.firebase.google.com/project/${e}/firestore/databases/${c}/indexes?create_composite=${l}`}function rn(e){return e.match(/https:\/\/console\.firebase\.google\.com[^\s)"]*/)?.[0]}function Le(e){let t=[],n=e>>>0;for(;n>=128;)t.push(n&127|128),n>>>=7;return t.push(n&127),t}function Be(e,t){return e<<3|t}function Me(e,t){let n=Array.from(new TextEncoder().encode(t));return [Be(e,2),...Le(n.length),...n]}function _e(e,t){return [Be(e,0),...Le(t)]}function yt(e,t){return [Be(e,2),...Le(t.length),...t]}function ht(e){let t=[...Me(1,e.fieldPath)];return e.arrayConfig==="CONTAINS"?t.push(..._e(3,1)):t.push(..._e(2,e.order==="DESCENDING"?2:1)),t}function gt(e){let t=String.fromCharCode(...e),n;if(typeof Buffer<"u")n=Buffer.from(e).toString("base64");else if(typeof btoa<"u")n=btoa(t);else throw new Error("No base64 encoder available");return n.replace(/=+$/,"")}function an(e,t,n,r="(default)"){let a=`projects/${e}/databases/${r}/collectionGroups/${t}/fields/${n.fieldPath}`,o=[...Me(1,a),..._e(2,2),...yt(3,ht(n))],s=r==="(default)"?"-default-":r,c=encodeURIComponent(gt(o));return `https://console.firebase.google.com/project/${e}/firestore/databases/${s}/indexes/automatic?create_exemption=${c}`}function on(e){let t=e,n=[t?.firestore?.projectId,t?.firestore?.app?.options?.projectId,t?.firestore?._settings?.projectId,t?.firestore?.databaseId?.projectId,t?._firestore?.projectId];for(let a of n)if(typeof a=="string"&&a.length>0)return a;return process.env.GCLOUD_PROJECT||process.env.GOOGLE_CLOUD_PROJECT||process.env.FIREBASE_PROJECT_ID||void 0}function de(e){let t=e;return t?t.code===9?true:typeof t.message=="string"?t.message.includes("requires an index"):false:false}function Ue(e,t){let n=e??{},r=de(e),a;if(r&&(a=n.message?rn(n.message):void 0,!a)){let o=on(t.ref);if(o){let s=en(t.path);a=tn(o,s,t.isGroup,t.filters,t.sort);}}return {type:r?"index":"error",message:r?"This query requires a composite index that does not exist yet.":n.message??"Query failed",indexUrl:a}}Ne();var xt=`// \u2500\u2500 Shared helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
137
137
|
function frsGetBasePath() {
|
|
138
138
|
var root = document.querySelector("[data-frs-panel-root]");
|
|
139
139
|
var bp = root && root.getAttribute("data-frs-base-path");
|
|
@@ -1060,6 +1060,6 @@ function initColumnReorder(table) {
|
|
|
1060
1060
|
});
|
|
1061
1061
|
});
|
|
1062
1062
|
}
|
|
1063
|
-
`;function Ne(){return jsx("script",{dangerouslySetInnerHTML:{__html:xt}})}Ve();function ae(e){return "<!DOCTYPE html>"+renderToString(e)}var bn=["corporate","silk","dark"],yn=()=>jsxs("div",{class:"dropdown dropdown-end","data-frs-theme-switcher":true,children:[jsxs("button",{type:"button",tabIndex:0,class:"btn btn-sm btn-ghost text-neutral-content gap-1.5","aria-label":"Switch theme",children:[jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",class:"size-4",children:[jsx("circle",{cx:"12",cy:"12",r:"4"}),jsx("path",{d:"M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41"})]}),jsx("span",{class:"text-xs hidden sm:inline","data-frs-theme-current":true,children:"Theme"})]}),jsx("ul",{tabIndex:0,class:"dropdown-content menu menu-sm bg-base-100 text-base-content rounded-box z-50 mt-2 w-40 p-1 shadow-lg border border-base-300",children:bn.map(e=>jsx("li",{children:jsxs("button",{type:"button","data-frs-theme":e,class:"capitalize justify-between",children:[jsx("span",{children:e}),jsx("span",{class:"hidden text-primary","data-frs-theme-check":e,children:"\u2713"})]})},e))})]}),oe=({opts:e,children:t})=>{let{title:n,breadcrumb:r,flash:a,basePath:o="/"}=e;return jsxs("html",{lang:"en","data-theme":"corporate",children:[jsxs("head",{children:[jsx("meta",{charset:"UTF-8"}),jsx("meta",{name:"viewport",content:"width=device-width, initial-scale=1"}),jsxs("title",{children:[n," \u2014 FRS Admin"]}),jsx("script",{dangerouslySetInnerHTML:{__html:"(function(){try{var t=localStorage.getItem('frs-admin-theme');if(t){document.documentElement.setAttribute('data-theme',t);}}catch(_){}})();"}}),jsx("link",{href:"https://cdn.jsdelivr.net/npm/daisyui@5/themes.css",rel:"stylesheet",type:"text/css"}),jsx("link",{href:"https://cdn.jsdelivr.net/npm/daisyui@5/daisyui.css",rel:"stylesheet",type:"text/css"}),jsx("script",{src:"https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"})]}),jsxs("body",{class:"bg-base-200/50 min-h-screen flex flex-col",children:[jsxs("div",{class:"navbar bg-neutral text-neutral-content shadow-sm sticky top-0 z-50 px-6",children:[jsx("div",{class:"flex-1",children:jsx("a",{href:o,class:"font-bold text-lg tracking-tight hover:opacity-80 transition-opacity",children:"FRS Admin"})}),jsx("div",{class:"flex-none",children:jsx(yn,{})})]}),jsxs("main",{class:"px-6 py-8 w-full flex-1",children:[r&&r.length>0&&jsx("div",{class:"text-sm breadcrumbs mb-4",children:jsx("ul",{children:r.map((s,c)=>s.href?jsx("li",{children:jsx("a",{href:s.href,children:s.label})},c):jsx("li",{class:"text-base-content/60",children:s.label},c))})}),jsx("h1",{class:"text-2xl font-bold mb-6",children:n}),a&&jsxs("div",{role:"alert",class:`alert ${a.type==="success"?"alert-success":a.type==="warning"?"alert-warning":"alert-error"} mb-6`,children:[jsx("span",{class:"flex-1",children:a.message}),a.action&&jsx("a",{href:a.action.href,...a.action.external?{target:"_blank",rel:"noopener noreferrer"}:{},class:"btn btn-sm btn-outline",children:a.action.label})]}),t]}),jsx(qe,{basePath:o}),jsx(Ne,{})]})]})};function Je(e,t){return ae(jsx(oe,{opts:t,children:jsx("div",{dangerouslySetInnerHTML:{__html:e}})}))}function Ke(e,t){return ae(jsx(oe,{opts:{title:"Repositories",basePath:t},children:e.length===0?jsxs("div",{class:"text-center py-20 text-base-content/50",children:[jsx("p",{class:"text-lg font-medium mb-1",children:"No repositories configured"}),jsx("p",{class:"text-sm",children:"Add a repository to your FRS config to get started."})]}):jsx("div",{class:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:e.map(n=>jsx("a",{href:`${t}/${n.name}`,class:"card bg-base-100 border border-base-300 hover:shadow-md no-underline transition-shadow",children:jsxs("div",{class:"card-body p-5",children:[jsx("h2",{class:"card-title text-sm font-semibold",children:n.name}),jsx("p",{class:"text-xs text-base-content/50 font-mono",children:n.path})]})},n.name))})}))}var At=[{value:"==",label:"="},{value:"!=",label:"\u2260"},{value:"in",label:"in"},{value:"not-in",label:"not in"}],hn=[{value:"==",label:"="},{value:"!=",label:"\u2260"},{value:"<",label:"<"},{value:"<=",label:"\u2264"},{value:">",label:">"},{value:">=",label:"\u2265"},{value:"in",label:"in"},{value:"not-in",label:"not in"}],gn=[{value:"array-contains",label:"contains"},{value:"array-contains-any",label:"contains any"}];function vn(e){switch(e){case "ZodNumber":case "ZodBigInt":case "ZodDate":return hn;case "ZodBoolean":return At;case "ZodArray":return gn;default:return At}}var se="__null__";function xn(e){return `(function(cb){var i=document.getElementById('${e}');if(!i)return;if(cb.checked){i.dataset._prev=i.value;if(i.tagName==='SELECT'){var o=i.querySelector('option[value="${se}"]');if(!o){o=document.createElement('option');o.value='${se}';o.textContent='\u2205 null';o.dataset._auto='1';i.appendChild(o);}o.selected=true;}else{if(i.type==='number'||i.type==='datetime-local'){i.dataset._type=i.type;i.type='text';}i.value='${se}';i.readOnly=true;}i.style.opacity='0.55';}else{i.style.opacity='';if(i.tagName==='SELECT'){var o2=i.querySelector('option[value="${se}"][data-_auto="1"]');if(o2)o2.remove();var prev=i.dataset._prev||'';for(var k=0;k<i.options.length;k++)i.options[k].selected=(i.options[k].value===prev);}else{if(i.dataset._type){i.type=i.dataset._type;delete i.dataset._type;}i.readOnly=false;i.value=(i.dataset._prev&&i.dataset._prev!=='${se}')?i.dataset._prev:'';}}})(this)`}function wn(e,t){return `(function(){var h=document.getElementById('${e}');var boxes=document.querySelectorAll('input[data-enum-group="${t}"]');h.value=Array.from(boxes).filter(function(b){return b.checked;}).map(function(b){return b.value;}).join(',');})()`}function Re({inputId:e,active:t}){return jsxs("label",{class:"flex items-center gap-1 cursor-pointer select-none text-xs text-base-content/60 hover:text-base-content border border-base-300 rounded-md px-1.5 py-1 shrink-0 leading-none h-8",title:"Filter where field IS NULL",children:[jsx("input",{type:"checkbox",class:"checkbox checkbox-xs",checked:t,onchange:xn(e)}),jsx("span",{children:"\u2205"})]})}function kn({col:e,active:t}){let n=t?.value??"",r=n===se,a=`fv_input_${e.name.replace(/\./g,"__")}`,o=t?.op,s=o==="in"||o==="not-in";if(e.enumValues&&e.enumValues.length>0){if(s){let c=new Set(n.split(",").map(p=>p.trim()).filter(Boolean)),l=`eg_${e.name.replace(/\./g,"__")}`;return jsxs("div",{class:"flex flex-wrap items-center gap-1 w-full",children:[jsx("input",{type:"hidden",id:a,name:`fv_${e.name}`,value:n}),e.enumValues.map(p=>jsxs("label",{class:"flex items-center gap-1 text-xs border border-base-300 rounded px-2 cursor-pointer hover:bg-base-200",children:[jsx("input",{type:"checkbox",class:"checkbox checkbox-xs",value:p,checked:c.has(p),"data-enum-group":l,onchange:wn(a,l)}),jsx("span",{children:p})]},p))]})}return jsxs("div",{class:"flex items-center gap-1 w-full",children:[jsxs("select",{id:a,name:`fv_${e.name}`,class:"select select-sm select-bordered w-full",style:r?"opacity:0.55":void 0,children:[jsx("option",{value:"",selected:n===""&&!r,children:"\u2014"}),e.enumValues.map(c=>jsx("option",{value:c,selected:n===c,children:c},c)),e.nullable&&jsx("option",{value:se,"data-_auto":"1",selected:r,children:"\u2205 null"})]}),e.nullable&&jsx(Re,{inputId:a,active:r})]})}if(e.zodType==="ZodBoolean")return jsxs("div",{class:"flex items-center gap-1 w-full",children:[jsxs("select",{id:a,name:`fv_${e.name}`,class:"select select-sm select-bordered w-full",style:r?"opacity:0.55":void 0,children:[jsx("option",{value:"",selected:n===""&&!r,children:"\u2014"}),jsx("option",{value:"true",selected:n==="true",children:"true"}),jsx("option",{value:"false",selected:n==="false",children:"false"}),e.nullable&&jsx("option",{value:se,"data-_auto":"1",selected:r,children:"\u2205 null"})]}),e.nullable&&jsx(Re,{inputId:a,active:r})]});if(e.zodType==="ZodArray"){let c=t?.op==="array-contains-any";return jsx("input",{id:a,type:"text",name:`fv_${e.name}`,value:n,placeholder:c?"val1, val2, \u2026":"value",class:"input input-sm input-bordered w-full"})}return e.zodType==="ZodNumber"||e.zodType==="ZodBigInt"?jsxs("div",{class:"flex items-center gap-1 w-full",children:[jsx("input",{id:a,type:r?"text":"number",name:`fv_${e.name}`,value:n,placeholder:"value",class:"input input-sm input-bordered w-full",readOnly:r||void 0,style:r?"opacity:0.55":void 0,"data-_type":r?"number":void 0}),e.nullable&&jsx(Re,{inputId:a,active:r})]}):e.zodType==="ZodDate"?jsxs("div",{class:"flex items-center gap-1 w-full",children:[jsx("input",{id:a,type:r?"text":"datetime-local",name:`fv_${e.name}`,value:n,class:"input input-sm input-bordered w-full",readOnly:r||void 0,style:r?"opacity:0.55":void 0,"data-_type":r?"datetime-local":void 0}),e.nullable&&jsx(Re,{inputId:a,active:r})]}):jsxs("div",{class:"flex items-center gap-1 w-full",children:[jsx("input",{id:a,type:"text",name:`fv_${e.name}`,value:n,placeholder:"value",class:"input input-sm input-bordered w-full",readOnly:r||void 0,style:r?"opacity:0.55":void 0}),e.nullable&&jsx(Re,{inputId:a,active:r})]})}function Ge({action:e,columnMeta:t,activeFilters:n,isGroup:r}){let a=Object.fromEntries(n.map(l=>[l.field,l])),o=n.length>0,s=n.length>=2||r&&o,c=t.filter(l=>l.zodType!=="ZodObject"&&l.zodType!=="ZodRecord");return jsxs("details",{class:"collapse collapse-arrow bg-base-100 border border-base-300 rounded-box mb-6 shadow-sm",open:o?true:void 0,children:[jsxs("summary",{class:"collapse-title text-sm font-medium py-2 min-h-0",children:["Filters",o&&jsxs("span",{class:"badge badge-primary badge-sm ml-2",children:[n.length," active"]})]}),jsx("div",{class:"collapse-content pb-4 pt-2",children:jsxs("form",{method:"get",action:e,children:[jsx("div",{class:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:c.map(l=>{let p=vn(l.zodType),b=a[l.name],g=b?.op??p[0].value;return jsxs("div",{class:"flex flex-col gap-1.5",children:[jsx("label",{class:"text-xs font-semibold text-base-content/60 uppercase tracking-wide",children:l.name}),jsxs("div",{class:"flex gap-1.5",children:[p.length>1?jsx("select",{name:`fo_${l.name}`,class:"select select-sm select-bordered w-20 shrink-0",children:p.map(C=>jsx("option",{value:C.value,selected:C.value===g,children:C.label},C.value))}):jsx("input",{type:"hidden",name:`fo_${l.name}`,value:p[0].value}),jsx(kn,{col:l,active:b})]})]},l.name)})}),jsxs("div",{class:"flex flex-wrap gap-2 mt-4 pt-3 border-t border-base-200 items-center",children:[jsx("button",{type:"submit",class:"btn btn-sm btn-primary",children:"Apply"}),o&&jsx("a",{href:e,class:"btn btn-sm btn-ghost",children:"Clear"}),s&&jsxs("span",{class:"text-xs text-warning ml-auto flex items-center gap-1",children:[jsx("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:jsx("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),r?"Collection group queries require a composite index":"Multiple filters may require a composite index"]})]})]})})]})}function We(e,t,n,r,a,o){let s=n==="create"?`Create ${e}`:`Edit ${e} / ${r??""}`,c=n==="create"?[{label:"Repositories",href:a},{label:e,href:`${a}/${e}`},{label:"New document"}]:[{label:"Repositories",href:a},{label:e,href:`${a}/${e}`},{label:`Edit ${r??""}`}];return ae(jsx(oe,{opts:{title:s,breadcrumb:c,basePath:a,flash:o},children:jsx("div",{class:"card bg-base-100 border border-base-300",children:jsx("div",{class:"card-body p-6",children:jsx("div",{dangerouslySetInnerHTML:{__html:t}})})})}))}_e();Ue();function Qe(e,t,n){let r=new URLSearchParams;for(let a of e)r.set(`fv_${a.field}`,a.value),r.set(`fo_${a.field}`,a.op);return t&&(r.set("ob",t.field),r.set("od",t.dir)),n&&r.set("ps",String(n)),r}function Rt(e,t,n,r,a){let o=Qe(e,r,a);return o.set("cursor",t),o.set("dir",n),`?${o.toString()}`}function Sn(e,t,n,r){let a=Qe(n,void 0,r);return t?.field===e?t.dir==="asc"&&(a.set("ob",e),a.set("od","desc")):(a.set("ob",e),a.set("od","asc")),`?${a.toString()}`}function An(e,t,n){return `?${Qe(t,n,e).toString()}`}function Xe(e,t,n,r,a,o,s=[],c=[],l=false,p=[],b,g,C,S,y,U,D,B=false){let m=`${r}/${e}`,f=`${m}/create`,k={};if(D)for(let h of n)k[h]=he(ge(D,h));let i=(U??[]).filter(h=>{let N=k[h]??he(ge(D,h));return N==="string"||N==="number"||N==="bigint"||N==="boolean"||N==="enum"||N==="literal"}),d=i.length>0,u=l,w=u||d,I=i.map(h=>{let N=ge(D,h),A=he(N),R=s.find(T=>T.name===h);return {name:h,type:A,enumValues:R?.enumValues??null,nullable:R?.nullable??false}});return ae(jsxs(oe,{opts:{title:e,breadcrumb:[{label:"Repositories",href:r},{label:e}],basePath:r,flash:o},children:[s.length>0&&jsx(Ge,{action:m,columnMeta:s,activeFilters:c,isGroup:S}),C&&jsxs("div",{role:"alert",class:`alert ${C.type==="index"?"alert-warning":"alert-error"} mb-6 shadow-sm`,children:[jsx("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-6 w-6 shrink-0 stroke-current",fill:"none",viewBox:"0 0 24 24",children:C.type==="index"?jsx("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"}):jsx("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"})}),jsxs("div",{class:"flex-1",children:[jsx("h3",{class:"font-bold",children:C.type==="index"?"Composite index required":"Query failed"}),jsx("div",{class:"text-sm",children:C.message})]}),C.indexUrl&&jsx("a",{href:C.indexUrl,target:"_blank",rel:"noopener noreferrer",class:"btn btn-sm btn-outline",children:"Create Index \u2192"})]}),jsxs("div",{class:"flex flex-wrap justify-between items-center mb-4 gap-3","data-frs-toolbar":true,children:[jsxs("div",{class:"flex items-center gap-3",children:[jsxs("span",{class:"text-sm text-base-content/60",children:[t.length,typeof y=="number"&&jsxs(Fragment,{children:[" ","of"," ",jsx("span",{class:"font-semibold text-base-content/80",children:y})]})," ","document",(typeof y=="number"?y:t.length)!==1&&"s"]}),jsxs("div",{class:"flex items-center gap-1.5 text-sm text-base-content/60",children:[jsx("span",{children:"Rows"}),jsx("div",{class:"join",children:[10,25,50,100].map(h=>jsx("a",{href:An(h,c,b),class:`join-item btn btn-xs ${g===h?"btn-active btn-primary":"btn-outline"}`,children:h},h))})]})]}),jsx("a",{href:f,class:"btn btn-primary btn-sm",children:"+ New"})]}),w&&jsxs("div",{class:"hidden mb-3 alert alert-info py-2 px-3","data-frs-bulk-bar":true,"data-frs-repo":e,"data-frs-total":typeof y=="number"?String(y):"","data-frs-page-size":String(g??t.length),"data-frs-allow-delete":u?"1":"0","data-frs-allow-update":d?"1":"0","data-frs-fields":JSON.stringify(I),"data-frs-filters":JSON.stringify(c),children:[jsxs("div",{class:"flex-1 text-sm",children:[jsx("span",{"data-frs-bulk-summary":true,children:"0 selected"}),typeof y=="number"&&y>t.length&&jsxs("button",{type:"button",class:"ml-3 link text-sm hidden","data-frs-bulk-select-all":true,children:["Select all ",y," matching documents"]}),jsxs("span",{class:"hidden ml-3 italic","data-frs-bulk-all-active":true,children:["All ",y??"?"," matching documents are selected."," ",jsx("button",{type:"button",class:"link","data-frs-bulk-clear":true,children:"Clear selection"})]})]}),jsxs("div",{class:"flex gap-2",children:[d&&jsx("button",{type:"button",class:"btn btn-sm btn-outline","data-frs-bulk-action":"update",children:"Update field\u2026"}),u&&jsx("button",{type:"button",class:"btn btn-sm btn-error btn-outline","data-frs-bulk-action":"delete",children:"Delete"})]})]}),jsx("div",{class:"overflow-x-auto rounded-box border border-base-300 bg-base-100","data-frs-table-wrap":true,children:jsxs("table",{class:"table table-sm w-full","data-frs-table":true,"data-frs-repo":e,"data-frs-colcount":n.length,children:[jsx("thead",{children:jsxs("tr",{class:"bg-base-200/50",children:[w&&jsx("th",{class:"w-8",children:jsx("input",{type:"checkbox",class:"checkbox checkbox-xs checkbox-primary","data-frs-select-page":true,"aria-label":"Select all on this page"})}),[...n].map((h,N)=>{let A=b?.field===h,R=A?b.dir==="asc"?" \u25B2":" \u25BC":"";return jsx("th",{class:"text-xs font-semibold text-base-content/60 uppercase tracking-wide",children:jsxs("a",{href:Sn(h,b,c,g),class:`hover:text-base-content inline-flex items-center gap-0.5${A?" text-primary font-bold":""}`,children:[h,R]})},N)}),p.map((h,N)=>jsx("th",{class:"text-xs font-semibold text-base-content/60 uppercase tracking-wide",children:h.column},`rel-${N}`)),jsx("th",{class:"text-xs font-semibold text-base-content/60 uppercase tracking-wide text-right",children:"Actions"})]})}),jsx("tbody",{children:t.length===0?jsx("tr",{children:jsx("td",{colspan:n.length+p.length+1+(w?1:0),class:"text-center py-16 text-base-content/40",children:"No documents found"})}):t.map((h,N)=>{let A=String(h.docId??h.id??""),R=`${r}/${e}/${encodeURIComponent(A)}/edit`,T=`${r}/${e}/${encodeURIComponent(A)}/delete`;return jsxs("tr",{class:"hover","data-frs-row-id":A,children:[w&&jsx("td",{class:"align-middle py-2",children:jsx("input",{type:"checkbox",class:"checkbox checkbox-xs checkbox-primary","data-frs-select-row":true,value:A,"aria-label":`Select ${A}`})}),n.map((E,L)=>{let M=h[E],P=k[E],v=P?Ae(P,M):null;return jsx("td",{class:"align-top py-2",children:jsx(ye,{val:M,mismatch:v})},L)}),p.map((E,L)=>{let M=h[E.key];if(M==null||M==="")return jsx("td",{class:"py-2"},`rel-${L}`);let P=E.type==="one"?`${r}/${E.targetRepo}/${encodeURIComponent(String(M))}/edit`:`${r}/${E.targetRepo}?fv_${E.targetKey}=${encodeURIComponent(String(M))}`;return jsx("td",{class:"align-middle py-2",children:jsx("a",{href:P,class:"btn btn-xs btn-ghost btn-outline","data-frs-relation":true,"data-frs-rel-type":E.type,"data-frs-rel-repo":E.targetRepo,"data-frs-rel-fk":E.targetKey,"data-frs-rel-val":String(M),"data-frs-rel-label":E.column,children:E.column})},`rel-${L}`)}),jsx("td",{class:"align-middle text-right whitespace-nowrap py-2",children:jsxs("div",{class:"flex gap-1 justify-end",children:[jsx("a",{href:R,class:"btn btn-xs btn-outline",children:"Edit"}),B&&jsx("a",{href:`${r}/${e}/${encodeURIComponent(A)}/history`,class:"btn btn-xs btn-outline",title:"View change history",children:"History"}),l&&jsx("form",{method:"post",action:T,onsubmit:"return confirm('Delete this document?')",children:jsx("button",{type:"submit",class:"btn btn-xs btn-error btn-outline",children:"Delete"})})]})})]},N)})})]})}),(a.hasPrev||a.hasNext)&&jsxs("div",{class:"flex flex-col items-center mt-6 gap-2",children:[jsxs("div",{class:"flex justify-center items-center gap-2",children:[a.hasPrev?jsx("a",{href:Rt(c,a.prevCursor,"prev",b,g),class:"btn btn-sm btn-outline",children:"\u2190 Previous"}):jsx("button",{class:"btn btn-sm btn-outline",disabled:true,children:"\u2190 Previous"}),a.hasNext?jsx("a",{href:Rt(c,a.nextCursor,"next",b,g),class:"btn btn-sm btn-outline",children:"Next \u2192"}):jsx("button",{class:"btn btn-sm btn-outline",disabled:true,children:"Next \u2192"})]}),typeof y=="number"&&jsxs("div",{class:"text-xs text-base-content/50",children:[y," total document",y!==1?"s":"",c.length>0?" matching filters":""]})]}),w&&d&&jsxs("dialog",{id:"frs-bulk-update-modal",class:"modal",children:[jsxs("div",{class:"modal-box",children:[jsx("h3",{class:"font-bold text-lg mb-3",children:"Bulk update field"}),jsx("p",{class:"text-sm text-base-content/60 mb-4","data-frs-bulk-update-summary":true,children:"Update one field on the selected documents."}),jsxs("form",{method:"dialog","data-frs-bulk-update-form":true,children:[jsxs("label",{class:"form-control w-full mb-3",children:[jsx("div",{class:"label",children:jsx("span",{class:"label-text text-xs uppercase tracking-wide",children:"Field"})}),jsxs("select",{class:"select select-bordered select-sm w-full",name:"field",required:true,"data-frs-bulk-field-select":true,children:[jsx("option",{value:"",children:"\u2014 Select a field \u2014"}),i.map(h=>jsx("option",{value:h,children:h},h))]})]}),jsx("div",{class:"mb-4","data-frs-bulk-value-container":true}),jsxs("div",{class:"modal-action",children:[jsx("button",{type:"button",class:"btn btn-sm btn-ghost","data-frs-bulk-update-cancel":true,children:"Cancel"}),jsx("button",{type:"submit",class:"btn btn-sm btn-primary","data-frs-bulk-update-submit":true,children:"Apply"})]})]})]}),jsx("form",{method:"dialog",class:"modal-backdrop",children:jsx("button",{children:"close"})})]})]}))}function Ie(e,t){return Je(e,t)}function $t(e,t){return Ke(e,t)}function Ct(e,t,n,r,a,o,s,c,l,p,b,g,C,S,y,U,D,B){return Xe(e,t,n,r,a,o,s,c,l,p,b,g,C,S,y,U,D,B)}function ue(e,t,n,r,a,o){return We(e,t,n,r,a,o)}var Ye="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";function En(){let e="";for(;e.length<20;){let t=randomBytes(20);for(let n=0;n<t.length&&e.length<20;n++){let r=t[n];r>=Ye.length*4||(e+=Ye.charAt(r%Ye.length));}}return e}function Ze(e,t){if(!t)return;let n=e[t];if(typeof n!="string"||!n)return;let r=n.split("/").filter(Boolean),a=[];for(let o=1;o<r.length;o+=2)a.push(r[o]);return a.length>0?a:void 0}async function ve(e,t){let n=e.documentKey??"docId",r=`by${n.charAt(0).toUpperCase()}${n.slice(1)}`;if(typeof e.repo.get[r]=="function")try{let o=await e.repo.get[r](t);if(o)return o}catch{}return (await e.repo.query.by({where:[[n,"==",t]],limit:1}))[0]??null}function et(e,t,n){let r=e.documentKey??"docId",a=Me(n,{ref:e.repo.ref,path:e.path,isGroup:!!e.isGroup,filters:[{field:r,op:"==",value:t}]});return a.type==="index"?{type:"warning",message:"Loading this document requires a composite index that does not exist yet.",...a.indexUrl?{action:{href:a.indexUrl,label:"Create Index \u2192",external:true}}:{}}:{type:"error",message:a.message}}function _(e,t,n=200){e.status(n).set("Content-Type","text/html; charset=utf-8").send(t);}function tt(e,t){e.status(302).set("Location",t).send("");}function nt(e,t){let n=t.shape,r={};for(let[a,o]of Object.entries(n)){let s=at(o);if(s==="ZodObject"){if(e[a+"__isnull"]==="1"){r[a]=null;continue}let p={},b=false;for(let[S,y]of Object.entries(e))S.startsWith(`${a}.`)&&(p[S.slice(a.length+1)]=y,b=true);if(b){let S=o;for(;;){let y=j(S);if(y==="ZodOptional"||y==="ZodNullable"||y==="ZodDefault")S=G(S);else break}r[a]=nt(p,S);continue}let g=e[a],C=Array.isArray(g)?g[g.length-1]:g;if(C)try{r[a]=JSON.parse(C);}catch{r[a]=C;}continue}let c=e[a],l=Array.isArray(c)?c[c.length-1]:c;if(e[a+"__isnull"]==="1"){r[a]=null;continue}if(l===void 0||l===""){s==="ZodBoolean"&&(r[a]=false);continue}switch(s){case "ZodBoolean":l==="__null__"?r[a]=null:r[a]=l==="true"||l==="on"||l==="1";break;case "ZodNumber":case "ZodBigInt":r[a]=Number(l);break;case "ZodDate":r[a]=new Date(l);break;case "ZodArray":try{r[a]=JSON.parse(l);}catch{r[a]=l;}break;default:if(l.startsWith("{")||l.startsWith("["))try{r[a]=JSON.parse(l);break}catch{}r[a]=l;}}return r}function Et(e){let t=null;if(e instanceof Date)t=e;else if(typeof e=="object"&&e!==null&&typeof e.toDate=="function")t=e.toDate();else if(typeof e=="object"&&e!==null&&"_seconds"in e&&"_nanoseconds"in e)t=new Date(e._seconds*1e3+Math.floor(e._nanoseconds/1e6));else if(typeof e=="string"||typeof e=="number"){let r=new Date(e);isNaN(r.getTime())||(t=r);}if(!t||isNaN(t.getTime()))return null;let n=r=>String(r).padStart(2,"0");return `${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function at(e){let t=e;for(;;){let n=j(t);if(n==="ZodOptional"||n==="ZodNullable"||n==="ZodDefault")t=G(t);else return n}}function Tn(e){let t=e;for(;;){let n=j(t);if(n==="ZodOptional"||n==="ZodNullable"||n==="ZodDefault")t=G(t);else return t}}function Ot(e){let t=e;for(;;){let n=j(t);if(n==="ZodOptional"||n==="ZodNullable")return true;if(n==="ZodDefault"){t=G(t);continue}return false}}function _t(e){let t=Tn(e),n=j(t);if(n==="ZodEnum"){let r=we(t);return r.length>0?r:void 0}if(n==="ZodNativeEnum"){let r=ke(t),a=Object.values(r).filter(o=>typeof o=="string");return a.length>0?a:void 0}if(n==="ZodLiteral"){let r=Se(t);return typeof r=="string"?[r]:void 0}}function Nt(e,t,n=""){let r={};for(let a of Object.keys(t.shape)){let o=n?`${n}.${a}`:a,s=e[a];if(s===null){r[o]="__null__";continue}if(s===void 0)continue;let c=t.shape[a];for(;;){let p=j(c);if(p==="ZodOptional"||p==="ZodNullable"||p==="ZodDefault")c=G(c);else break}let l=j(c);if(l==="ZodObject"&&typeof s=="object"&&s!==null&&!Array.isArray(s)){let p=Nt(s,c,o);Object.assign(r,p);}else if(l==="ZodDate"){let p=Et(s);p!==null&&(r[o]=p);}else if(typeof s=="object"&&s!==null&&!Array.isArray(s)&&("_seconds"in s||typeof s.toDate=="function")){let p=Et(s);r[o]=p??JSON.stringify(s,null,2);}else typeof s=="object"?r[o]=JSON.stringify(s,null,2):r[o]=String(s);}return r}function rt(e,t){return e.map(n=>({...n,defaultValue:t[n.name]??n.defaultValue,nested:n.nested?rt(n.nested,t):void 0}))}function On(e,t){let n=new Set(["==","!=","<","<=",">",">=","in","not-in","array-contains","array-contains-any"]),r=[];for(let[a,o]of Object.entries(e)){if(!a.startsWith("fv_"))continue;let s=a.slice(3);if(!t.has(s))continue;let c=(o??"").trim();if(!c)continue;let l=e[`fo_${s}`]??"==",p=n.has(l)?l:"==";r.push({field:s,op:p,value:c});}return r}function Tt(e){let t="__null__",n=r=>r===t?null:r==="true"?true:r==="false"?false:r!==""&&!isNaN(Number(r))?Number(r):r;return e.map(r=>{if(r.op==="array-contains-any"||r.op==="in"||r.op==="not-in"){let a=r.value.split(",").map(o=>o.trim()).filter(o=>o!==""&&o!==t).map(o=>n(o));return [r.field,r.op,a]}return [r.field,r.op,n(r.value)]})}function Pt(e,t,n=""){let r=[];for(let a of e){let o=n?`${n}.${a}`:a,s=t.shape[a];if(!s){r.push({name:o,zodType:"ZodString"});continue}let c=at(s);if(c==="ZodObject"){let l=s;for(;;){let b=j(l);if(b==="ZodOptional"||b==="ZodNullable"||b==="ZodDefault")l=G(l);else break}let p=Y(l);r.push(...Pt(Object.keys(p),l,o));}else r.push({name:o,zodType:c,nullable:Ot(s),enumValues:_t(s)});}return r}function _n(e,t){let n=t.split("."),r=e;for(let a of n){for(;;){let s=j(r);if(s==="ZodOptional"||s==="ZodNullable"||s==="ZodDefault")r=G(r);else break}let o=Y(r);if(!(a in o))return null;r=o[a];}return r}function pe(e,t){if(!t||t.length===0)return e;let n=[],r=new Map;for(let o of t){let s=o.indexOf(".");if(s===-1)n.push(o);else {let c=o.slice(0,s),l=o.slice(s+1);r.has(c)||r.set(c,[]),r.get(c).push(l);}}let a={};for(let o of n)o in e.shape&&(a[o]=e.shape[o]);for(let[o,s]of r){if(!(o in e.shape))continue;let c=e.shape[o];for(;;){let l=j(c);if(l==="ZodOptional"||l==="ZodNullable"||l==="ZodDefault")c=G(c);else break}if(j(c)!=="ZodObject"){a[o]=e.shape[o];continue}a[o]=pe(c,s);}return z.object(a)}function ne(e,t,n){return ze(e,t,n)}function It(e,t,n){let r=(m,f)=>{let k=ne(m,t,n),i=Object.values(e).map(d=>({name:d.name,path:d.path}));_(f,$t(i,k));},a=async(m,f)=>{let k=m.params.repoName;if(!k){_(f,"Bad request",400);return}let i=e[k];if(!i){_(f,"Repository not found",404);return}let d=i.pageSize??25,u=m.query??{},w=u.cursor,I=u.dir==="prev"?"prev":"next",h=u.ob??"",N=u.od==="desc"?"desc":"asc",A=h?{field:h,dir:N}:void 0,R=parseInt(u.ps??""),T=Number.isFinite(R)&&R>0?Math.min(R,200):d,E=i.listColumns??Object.keys(i.schema.shape),L=i.documentKey??"docId",M=[L,...E.filter(V=>V!==L)];A&&(new Set([L,...E]).has(A.field)||(A=void 0));let P=i.filterableFields?(()=>{let V=[];for(let te of i.filterableFields)(te.includes(".")||E.includes(te))&&V.push(te);return V})():E,v=(()=>{let V=[];for(let te of P)if(te.includes(".")){let me=_n(i.schema,te);V.push({name:te,zodType:me?at(me):"ZodString",nullable:me?Ot(me):false,enumValues:me?_t(me):void 0});}else V.push(...Pt([te],i.schema));return V})(),q=new Set(v.map(V=>V.name)),ie=On(u,q),re=Tt(ie),xe;if(w)try{let V=i.repo.ref;typeof V.doc=="function"&&(xe=await V.doc(w).get());}catch{}let[K,Ce]=await Promise.all([i.repo.query.paginate({pageSize:T,cursor:xe,direction:I,...re.length>0?{where:re}:{},...A?{orderBy:[{field:A.field,direction:A.dir}]}:{}}).catch(V=>({queryError:Me(V,{ref:i.repo.ref,path:i.path,isGroup:!!i.isGroup,filters:ie,sort:A})})),i.repo.aggregate.count(re.length>0?{where:re}:{}).catch(()=>{})]),fe="queryError"in K,Dt=fe?[]:K.data,jt=fe?"":K.nextCursor?.id??"",Lt=fe?"":K.prevCursor?.id??"",Bt=fe?K.queryError:void 0,Mt=ne(m,t,n);_(f,Ct(i.name,Dt,M,Mt,{hasPrev:fe?false:K.hasPrevPage,hasNext:fe?false:K.hasNextPage,prevCursor:Lt,nextCursor:jt},void 0,v,ie,i.allowDelete??false,i.relationalMeta,A,T,Bt,i.isGroup,Ce,i.mutableFields,i.schema,i.historyEnabled));},o=(m,f)=>{let k=m.params.repoName;if(!k){_(f,"Bad request",400);return}let i=e[k];if(!i){_(f,"Repository not found",404);return}let d=ne(m,t,n),u=pe(i.schema,i.createFields),w=ee(u),I=`${d}/${i.name}/create`,h=le(w,I,"POST","Create document");_(f,ue(i.name,h,"create",null,d));},s=async(m,f)=>{let k=m.params.repoName;if(!k){_(f,"Bad request",400);return}let i=e[k];if(!i){_(f,"Repository not found",404);return}let d=ne(m,t,n),u=m.body??{},w=nt(u,i.schema),I=pe(i.schema,i.createFields),h=I.safeParse(w);if(!h.success){let N=ee(I),A=`${d}/${i.name}/create`,R=le(N,A,"POST","Create document"),T=h.error.issues.map(E=>`${E.path.join(".")}: ${E.message}`).join(", ");_(f,ue(i.name,R,"create",null,d,{type:"error",message:`Validation error: ${T}`}),422);return}try{if(i.isGroup&&i.parentKeys&&i.parentKeys.length>0){let N={...h.data};i.createdKey&&(N[i.createdKey]=new Date);let A=i.parentKeys.filter(L=>!N[L]);if(A.length>0)throw new Error(`Missing parent key(s) for subcollection create: ${A.join(", ")}`);let R=i.parentKeys.map(L=>N[L]),T=i.documentKey??"docId",E=N[T]||En();await i.repo.set(...R,E,N);}else await i.repo.create(h.data);tt(f,`${d}/${i.name}?flash=created`);}catch(N){let A=pe(i.schema,i.createFields),R=ee(A),T=`${d}/${i.name}/create`,E=le(R,T,"POST","Create document");_(f,ue(i.name,E,"create",null,d,{type:"error",message:`Save error: ${N.message}`}),500);}},c=async(m,f)=>{let k=m.params.repoName,i=m.params.id;if(!k||!i){_(f,"Bad request",400);return}let d=e[k];if(!d){_(f,"Repository not found",404);return}let u=ne(m,t,n),w=null;try{w=await ve(d,i);}catch(T){let E=et(d,i,T),L=de(T)?424:500;_(f,Ie("",{title:`Edit ${d.name} / ${i}`,basePath:u,breadcrumb:[{label:"Repositories",href:u},{label:d.name,href:`${u}/${d.name}`},{label:`Edit ${i}`}],flash:E}),L);return}if(!w){_(f,"Document not found",404);return}let I=Nt(w,d.schema),h=pe(d.schema,d.mutableFields),N=rt(ee(h),I),A=`${u}/${d.name}/${encodeURIComponent(i)}/edit`,R=le(N,A,"POST","Save changes");_(f,ue(d.name,R,"edit",i,u));},l=async(m,f)=>{let k=m.params.repoName,i=m.params.id;if(!k||!i){_(f,"Bad request",400);return}let d=e[k];if(!d){_(f,"Repository not found",404);return}let u=ne(m,t,n),w=m.body??{},I=nt(w,d.schema),h=pe(d.schema,d.mutableFields),A=h.partial().safeParse(I);if(!A.success){let R=Object.fromEntries(Object.entries(w).map(([P,v])=>[P,Array.isArray(v)?v.join(","):v??""])),T=rt(ee(h),R),E=`${u}/${d.name}/${encodeURIComponent(i)}/edit`,L=le(T,E,"POST","Save changes"),M=A.error.issues.map(P=>`${P.path.join(".")}: ${P.message}`).join(", ");_(f,ue(d.name,L,"edit",i,u,{type:"error",message:`Validation error: ${M}`}),422);return}try{let R=await ve(d,i),T=(R&&Ze(R,d.pathKey))??[i];await d.repo.update(...T,A.data),tt(f,`${u}/${d.name}?flash=updated`);}catch(R){let T=pe(d.schema,d.mutableFields),E=ee(T),L=`${u}/${d.name}/${encodeURIComponent(i)}/edit`,M=le(E,L,"POST","Save changes"),P=de(R)?et(d,i,R):{type:"error",message:`Save error: ${R.message}`},v=de(R)?424:500;_(f,ue(d.name,M,"edit",i,u,P),v);}},p=async(m,f)=>{let k=m.params.repoName,i=m.params.id;if(!k||!i){_(f,"Bad request",400);return}let d=e[k];if(!d){_(f,"Repository not found",404);return}if(!d.allowDelete){_(f,"Delete is not allowed for this repository",403);return}let u=ne(m,t,n);try{let w=await ve(d,i),I=(w&&Ze(w,d.pathKey))??[i];await d.repo.delete(...I),tt(f,`${u}/${d.name}?flash=deleted`);}catch(w){let I=de(w)?et(d,i,w):{type:"error",message:`Delete error: ${w.message}`},h=de(w)?424:500;_(f,Ie("",{title:`Delete ${d.name} / ${i}`,basePath:u,breadcrumb:[{label:"Repositories",href:u},{label:d.name,href:`${u}/${d.name}`},{label:`Delete ${i}`}],flash:I}),h);}},b=async(m,f)=>{let k=m.params.repoName;if(!k){_(f,"Bad request",400);return}let i=e[k];if(!i){_(f,"Repository not found",404);return}let d=ne(m,t,n),u=m.query,w=u?.type==="many"?"many":"one",I=Math.max(1,Math.min(100,Number(u?.ps??25)||25)),h=i.listColumns??Object.keys(Y(i.schema)),{PanelOne:N,PanelMany:A}=await Promise.resolve().then(()=>(Ve(),kt)),{renderToString:R}=await import('hono/jsx/dom/server');if(w==="one"){let v=String(u?.id??"");if(!v){_(f,"<div class='p-6 text-error'>Missing id parameter.</div>",400);return}try{let q=await ve(i,v),ie=R(N({doc:q,repoName:i.name,basePath:d,schema:i.schema,columns:h}));_(f,ie);}catch(q){_(f,`<div class='p-6 text-error text-sm'>Error: ${q.message}</div>`,500);}return}let T=String(u?.fk??""),E=String(u?.fv??"");if(!T||!E){_(f,"<div class='p-6 text-error'>Missing fk/fv parameters.</div>",400);return}let L=u?.cursor??"",M=u?.dir==="prev"?"prev":"next",P;if(L)try{let v=i.repo.ref;typeof v.doc=="function"&&(P=await v.doc(L).get());}catch{}try{let v=await i.repo.query.paginate({pageSize:I,cursor:P,direction:M,where:[[T,"==",Nn(E)]]}),q=R(A({docs:v.data,repoName:i.name,basePath:d,fk:T,fv:E,columns:h,schema:i.schema,pagination:{hasPrev:v.hasPrevPage,hasNext:v.hasNextPage,prevCursor:v.prevCursor?.id??"",nextCursor:v.nextCursor?.id??"",pageSize:I}}));_(f,q);}catch(v){_(f,`<div class='p-6 text-error text-sm'>Error: ${v.message}</div>`,500);}},g=async(m,f)=>{let k=[];for(let i of f){let d;if(m.isGroup||m.parentKeys?.length){let u=await ve(m,i);d=u?Ze(u,m.pathKey):void 0;}d||(d=[i]);try{let u=m.repo.documentRef(...d);u&&k.push(u);}catch{}}return k},C=async(m,f)=>{let k=Tt(f),i=m.documentKey??"docId",d=[],u;for(;;){let w=await m.repo.query.paginate({pageSize:500,cursor:u,direction:"next",...k.length>0?{where:k}:{}});for(let I of w.data){let h=String(I[i]??I.id??"");h&&d.push(h);}if(!w.hasNextPage||!w.nextCursor)break;u=w.nextCursor;}return d},S=async(m,f)=>{let k=m.params.repoName;if(!k){Q(f,{error:"Bad request"},400);return}let i=e[k];if(!i){Q(f,{error:"Repository not found"},404);return}if(!i.allowDelete){Q(f,{error:"Delete is not allowed for this repository"},403);return}let d=m.body??{};try{let u=await U(i,d);if(u.length===0){Q(f,{deleted:0});return}let w=await g(i,u);for(let I=0;I<w.length;I+=500)await i.repo.bulk.delete(w.slice(I,I+500));Q(f,{deleted:w.length});}catch(u){Q(f,{error:u.message},500);}},y=async(m,f)=>{let k=m.params.repoName;if(!k){Q(f,{error:"Bad request"},400);return}let i=e[k];if(!i){Q(f,{error:"Repository not found"},404);return}let d=m.body??{},u=String(d.field??"");if(!u){Q(f,{error:"Missing 'field'"},400);return}if(!i.mutableFields||!i.mutableFields.includes(u)){Q(f,{error:`Field '${u}' is not bulk-updatable`},403);return}let w=i.schema.shape?.[u],I=d.value;if(w){let h=w.safeParse(d.value);if(!h.success){Q(f,{error:`Invalid value for '${u}': ${h.error.message}`},400);return}I=h.data;}try{let h=await U(i,d);if(h.length===0){Q(f,{updated:0});return}let A=(await g(i,h)).map(R=>({docRef:R,data:{[u]:I}}));for(let R=0;R<A.length;R+=500)await i.repo.bulk.update(A.slice(R,R+500));Q(f,{updated:A.length});}catch(h){Q(f,{error:h.message},500);}};async function U(m,f){if(f.selectAll){let k=D(f.filters,m);return await C(m,k)}return Array.isArray(f.ids)?f.ids.filter(k=>typeof k=="string"&&!!k):[]}function D(m,f){if(!Array.isArray(m))return [];let k=new Set((f.filterableFields??Object.keys(Y(f.schema))).map(u=>String(u))),i=new Set(["==","!=","<","<=",">",">=","in","not-in","array-contains","array-contains-any"]),d=[];for(let u of m)u&&typeof u=="object"&&typeof u.field=="string"&&k.has(u.field)&&typeof u.value=="string"&&i.has(String(u.op))&&d.push({field:u.field,op:u.op,value:u.value});return d}return {handleDashboard:r,handleList:a,handleCreateForm:o,handleCreateSubmit:s,handleEditForm:c,handleEditSubmit:l,handleDelete:p,handlePanel:b,handleBulkDelete:S,handleBulkUpdate:y,handleHistory:async(m,f)=>{let k=m.params.repoName,i=m.params.id;if(!k||!i){_(f,"Bad request",400);return}let d=e[k];if(!d){_(f,"Repository not found",404);return}if(!d.historyEnabled||!d.repo.history){_(f,"History not enabled for this repository",404);return}let u=ne(m,t,n),w=d.historySubcollection??"history",I=[i];try{let v=await ve(d,i),q=v?Ze(v,d.pathKey):void 0;q&&q.length>0&&(I=q);}catch{}let h=parseInt(String(m.query?.limit??"")),N=Number.isFinite(h)&&h>0?Math.min(h,500):100,A=[],R;try{A=await d.repo.history.list(...I,{limit:N});}catch(v){R=v.message;}let T=v=>String(v??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),E=v=>{if(v===void 0)return '<span class="opacity-40">undefined</span>';if(v===null)return '<span class="opacity-40">null</span>';if(typeof v=="object")try{return `<code class="text-xs">${T(JSON.stringify(v))}</code>`}catch{return T(String(v))}return T(String(v))},L=v=>v?typeof v.toDate=="function"?v.toDate().toISOString():v instanceof Date?v.toISOString():T(String(v)):"",M=v=>`<span class="badge badge-sm ${v==="create"?"badge-success":v==="delete"?"badge-error":"badge-info"}">${T(v)}</span>`,P="";if(P+='<div class="flex items-center justify-between mb-4">',P+=`<a href="${u}/${d.name}/${encodeURIComponent(i)}/edit" class="btn btn-sm btn-outline">\u2190 Back to edit</a>`,P+=`<a href="${u}/${d.name}" class="btn btn-sm btn-outline">\u2190 Back to list</a>`,P+="</div>",P+=`<p class="text-sm text-base-content/60 mb-4">Subcollection: <code>${T(w)}</code> \xB7 Showing up to ${N} entries.</p>`,R)P+=`<div class="alert alert-error mb-4">${T(R)}</div>`;else if(A.length===0)P+='<div class="alert">No history entries found.</div>';else {P+='<div class="overflow-x-auto"><table class="table table-zebra table-sm">',P+="<thead><tr><th>When</th><th>Op</th><th>User</th><th>Reason / Comment</th><th>Changes</th></tr></thead><tbody>";for(let v of A){let q=v.meta??{},ie=[q.reason,q.comment].filter(K=>K!=null&&K!=="").map(K=>T(String(K))).join(" \u2014 "),re="",xe=Object.keys(v.changes??{});xe.length===0?re='<span class="opacity-40">\u2014</span>':re='<ul class="space-y-1">'+xe.map(K=>{let Ce=v.changes[K];return `<li><strong>${T(K)}</strong>: ${E(Ce.oldValue)} \u2192 ${E(Ce.newValue)}</li>`}).join("")+"</ul>",P+="<tr>",P+=`<td class="whitespace-nowrap text-xs font-mono">${T(L(v.historySetAt))}</td>`,P+=`<td>${M(v.operation??"update")}</td>`,P+=`<td class="text-xs">${T(q.userEmail??q.userId??"")}</td>`,P+=`<td class="text-xs">${ie}</td>`,P+=`<td>${re}</td>`,P+="</tr>";}P+="</tbody></table></div>";}_(f,Ie(P,{title:`History \u2014 ${d.name} / ${i}`,basePath:u,breadcrumb:[{label:"Repositories",href:u},{label:d.name,href:`${u}/${d.name}`},{label:`History ${i}`}]}));}}}function Q(e,t,n=200){e.status(n).set("Content-Type","application/json; charset=utf-8").send(JSON.stringify(t));}function Nn(e){return e==="true"?true:e==="false"?false:e!==""&&!isNaN(Number(e))?Number(e):e}function Pn(e){let t=[],n=e.replace(/[.*+?^${}()|[\]\\]/g,r=>r===":"?r:`\\${r}`).replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,(r,a)=>(t.push(a),"([^/]+)"));return {pattern:new RegExp(`^${n}$`),paramNames:t}}function In(e){let t=e.path??e.url??"/",n=t.indexOf("?");return n===-1?t:t.slice(0,n)}var $e=class{constructor(){this.routes=[];this.middlewares=[];this.notFoundHandler=(t,n)=>{n.status(404).send("Not Found");};this.errorHandler=(t,n,r)=>{console.error("[MiniRouter]",t),r.status(500).send("Internal Server Error");};}use(t){return this.middlewares.push(t),this}get(t,n){return this.addRoute("GET",t,n)}post(t,n){return this.addRoute("POST",t,n)}put(t,n){return this.addRoute("PUT",t,n)}patch(t,n){return this.addRoute("PATCH",t,n)}delete(t,n){return this.addRoute("DELETE",t,n)}onNotFound(t){return this.notFoundHandler=t,this}onError(t){return this.errorHandler=t,this}addRoute(t,n,r){let{pattern:a,paramNames:o}=Pn(n);return this.routes.push({method:t.toUpperCase(),pattern:a,paramNames:o,handler:r}),this}async handle(t,n){let r=(t.method??"GET").toUpperCase(),a=In(t),o=null,s={};for(let p of this.routes){if(p.method!==r)continue;let b=a.match(p.pattern);if(b){o=p,s={},p.paramNames.forEach((g,C)=>{s[g]=decodeURIComponent(b[C+1]??"");});break}}let c=Object.assign(t,{params:s}),l=o?o.handler:this.notFoundHandler;try{await this.runMiddlewareChain(c,n,l);}catch(p){this.errorHandler(p,t,n);}}async runMiddlewareChain(t,n,r){let a=0,o=async()=>{if(a<this.middlewares.length){let s=this.middlewares[a++];await s(t,n,o);}else await r(t,n);};await o();}};var Zt="https://cdn.jsdelivr.net",zt="https://www.gstatic.com",Zn=["default-src 'self'",`script-src 'self' 'unsafe-inline' 'unsafe-eval' ${Zt} ${zt}`,`style-src 'self' 'unsafe-inline' ${Zt}`,`connect-src 'self' ${zt} https://*.googleapis.com https://*.firebaseio.com https://identitytoolkit.googleapis.com`,"img-src 'self' data:","font-src 'self' data:","frame-ancestors 'none'","base-uri 'self'","form-action 'self'"].join("; ");function Ft(e={}){let t=e.csp===void 0?Zn:e.csp,n=e.frameOptions===void 0?"DENY":e.frameOptions,r=e.referrerPolicy===void 0?"no-referrer":e.referrerPolicy,a=e.cacheControl===void 0?"private, no-store":e.cacheControl;return async(o,s,c)=>{typeof s?.setHeader=="function"&&(s.setHeader("X-Content-Type-Options","nosniff"),n&&s.setHeader("X-Frame-Options",n),r&&s.setHeader("Referrer-Policy",r),a&&s.setHeader("Cache-Control",a),t&&s.setHeader("Content-Security-Policy",t)),await c();}}async function zn(e){return typeof e.rawBody=="string"?e.rawBody:Buffer.isBuffer(e.rawBody)?e.rawBody.toString("utf8"):""}function Fn(e){let t={};if(!e)return t;for(let n of e.split("&")){let r=n.indexOf("=");if(r===-1)continue;let a=decodeURIComponent(n.slice(0,r).replace(/\+/g," ")),o=decodeURIComponent(n.slice(r+1).replace(/\+/g," ")),s=t[a];s===void 0?t[a]=o:Array.isArray(s)?s.push(o):t[a]=[s,o];}return t}function sa(e){let{basePath:t="/",repos:n,parseBody:r=true,securityHeaders:a,auth:o,middleware:s=[],httpsOptions:c}=e,l=t==="/"?"":t.replace(/\/$/,""),p={};for(let[S,y]of Object.entries(n)){let U=y.schema??y.repo.schema??null;if(!U)throw new Error(`[createAdminServer] Repository "${S}" has no Zod schema. Either use createRepositoryConfig(schema)(config) or pass schema: explicitly.`);let D,B,m;if(y.fieldsConfig){let i=y.fieldsConfig;D=[],B=[],m=[];for(let[d,u]of Object.entries(i))for(let w of u)w==="filterable"?D.push(d):w==="mutable"?B.push(d):w==="create"&&m.push(d);D.length===0&&(D=void 0),B.length===0&&(B=void 0),m.length===0&&(m=void 0);}let f=(()=>{let i=y.repo._parentKeys;return i&&i.length>0?i:void 0})();if(f&&m)for(let i of f)m.includes(i)||m.push(i);let k={name:S,path:y.path,repo:y.repo,schema:U,documentKey:y.documentKey??"docId",pathKey:y.repo._pathKey??void 0,isGroup:!!y.repo._isGroup,parentKeys:f,createdKey:y.repo._createdKey??void 0,listColumns:y.listColumns,pageSize:y.pageSize,filterableFields:D,mutableFields:B,createFields:m,allowDelete:y.allowDelete??false,historyEnabled:!!y.repo._historyConfig?.enabled,historySubcollection:(y.repo._historyConfig?.enabled&&y.repo._historySubcollection)??void 0,relationalMeta:(()=>{if(!y.relationalFields||y.relationalFields.length===0)return;let i=y.repo.relationalKeys??{},d=[];for(let u of y.relationalFields){let w=i[u.key];w&&d.push({key:u.key,column:u.column,targetRepo:String(w.repo),targetKey:String(w.key),type:w.type});}return d.length>0?d:void 0})()};p[S]=k;}let b=It(p,l,ot(c?.region)),g=new $e;if(a!==false&&g.use(Ft(a===void 0?{}:a)),r&&g.use(async(S,y,U)=>{let D=S,B=String(D.headers?.["content-type"]??"");if(B.includes("application/x-www-form-urlencoded")){let m=await zn(D);S.body=Fn(m);}else if(B.includes("application/json")&&typeof D.body=="string")try{S.body=JSON.parse(D.body);}catch{}await U();}),o)if(Fe(o)){for(let S of o.routes){let y=`${l}${S.path}`;S.method==="GET"?g.get(y,S.handler):g.post(y,S.handler);}g.use(o.middleware);}else if(typeof o=="function")g.use(o);else {let S=o.realm??"Admin",y="Basic "+Buffer.from(`${o.username}:${o.password}`).toString("base64");g.use((U,D,B)=>{if((U.headers?.authorization??"")!==y){D.status(401).set("WWW-Authenticate",`Basic realm="${S}"`).set("Content-Type","text/plain").send("Unauthorized");return}B();});}for(let S of s)g.use(S);g.get(`${l}/`,b.handleDashboard),g.get(`${l}`,b.handleDashboard),g.get(`${l}/:repoName/_panel`,b.handlePanel),g.post(`${l}/:repoName/_bulk/delete`,b.handleBulkDelete),g.post(`${l}/:repoName/_bulk/update`,b.handleBulkUpdate),g.get(`${l}/:repoName`,b.handleList),g.get(`${l}/:repoName/create`,b.handleCreateForm),g.post(`${l}/:repoName/create`,b.handleCreateSubmit),g.get(`${l}/:repoName/:id/edit`,b.handleEditForm),g.post(`${l}/:repoName/:id/edit`,b.handleEditSubmit),g.get(`${l}/:repoName/:id/history`,b.handleHistory),g.post(`${l}/:repoName/:id/delete`,b.handleDelete);let C=async(S,y)=>{await g.handle(S,y);};return c&&(C.httpsOptions=c),C}
|
|
1063
|
+
`;function Pe(){return jsx("script",{dangerouslySetInnerHTML:{__html:xt}})}Ke();function ae(e){return "<!DOCTYPE html>"+renderToString(e)}var yn=["corporate","silk","dark"],hn=()=>jsxs("div",{class:"dropdown dropdown-end","data-frs-theme-switcher":true,children:[jsxs("button",{type:"button",tabIndex:0,class:"btn btn-sm btn-ghost text-neutral-content gap-1.5","aria-label":"Switch theme",children:[jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",class:"size-4",children:[jsx("circle",{cx:"12",cy:"12",r:"4"}),jsx("path",{d:"M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41"})]}),jsx("span",{class:"text-xs hidden sm:inline","data-frs-theme-current":true,children:"Theme"})]}),jsx("ul",{tabIndex:0,class:"dropdown-content menu menu-sm bg-base-100 text-base-content rounded-box z-50 mt-2 w-40 p-1 shadow-lg border border-base-300",children:yn.map(e=>jsx("li",{children:jsxs("button",{type:"button","data-frs-theme":e,class:"capitalize justify-between",children:[jsx("span",{children:e}),jsx("span",{class:"hidden text-primary","data-frs-theme-check":e,children:"\u2713"})]})},e))})]}),oe=({opts:e,children:t})=>{let{title:n,breadcrumb:r,flash:a,basePath:o="/"}=e;return jsxs("html",{lang:"en","data-theme":"corporate",children:[jsxs("head",{children:[jsx("meta",{charset:"UTF-8"}),jsx("meta",{name:"viewport",content:"width=device-width, initial-scale=1"}),jsxs("title",{children:[n," \u2014 FRS Admin"]}),jsx("script",{dangerouslySetInnerHTML:{__html:"(function(){try{var t=localStorage.getItem('frs-admin-theme');if(t){document.documentElement.setAttribute('data-theme',t);}}catch(_){}})();"}}),jsx("link",{href:"https://cdn.jsdelivr.net/npm/daisyui@5/themes.css",rel:"stylesheet",type:"text/css"}),jsx("link",{href:"https://cdn.jsdelivr.net/npm/daisyui@5/daisyui.css",rel:"stylesheet",type:"text/css"}),jsx("script",{src:"https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"})]}),jsxs("body",{class:"bg-base-200/50 min-h-screen flex flex-col",children:[jsxs("div",{class:"navbar bg-neutral text-neutral-content shadow-sm sticky top-0 z-50 px-6",children:[jsx("div",{class:"flex-1",children:jsx("a",{href:o,class:"font-bold text-lg tracking-tight hover:opacity-80 transition-opacity",children:"FRS Admin"})}),jsx("div",{class:"flex-none",children:jsx(hn,{})})]}),jsxs("main",{class:"px-6 py-8 w-full flex-1",children:[r&&r.length>0&&jsx("div",{class:"text-sm breadcrumbs mb-4",children:jsx("ul",{children:r.map((s,c)=>s.href?jsx("li",{children:jsx("a",{href:s.href,children:s.label})},c):jsx("li",{class:"text-base-content/60",children:s.label},c))})}),jsx("h1",{class:"text-2xl font-bold mb-6",children:n}),a&&jsxs("div",{role:"alert",class:`alert ${a.type==="success"?"alert-success":a.type==="warning"?"alert-warning":"alert-error"} mb-6`,children:[jsx("span",{class:"flex-1",children:a.message}),a.action&&jsx("a",{href:a.action.href,...a.action.external?{target:"_blank",rel:"noopener noreferrer"}:{},class:"btn btn-sm btn-outline",children:a.action.label})]}),t]}),jsx(Je,{basePath:o}),jsx(Pe,{})]})]})};function Ge(e,t){return ae(jsx(oe,{opts:t,children:jsx("div",{dangerouslySetInnerHTML:{__html:e}})}))}function We(e,t){return ae(jsx(oe,{opts:{title:"Repositories",basePath:t},children:e.length===0?jsxs("div",{class:"text-center py-20 text-base-content/50",children:[jsx("p",{class:"text-lg font-medium mb-1",children:"No repositories configured"}),jsx("p",{class:"text-sm",children:"Add a repository to your FRS config to get started."})]}):jsx("div",{class:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:e.map(n=>jsx("a",{href:`${t}/${n.name}`,class:"card bg-base-100 border border-base-300 hover:shadow-md no-underline transition-shadow",children:jsxs("div",{class:"card-body p-5",children:[jsx("h2",{class:"card-title text-sm font-semibold",children:n.name}),jsx("p",{class:"text-xs text-base-content/50 font-mono",children:n.path})]})},n.name))})}))}var At=[{value:"==",label:"="},{value:"!=",label:"\u2260"},{value:"in",label:"in"},{value:"not-in",label:"not in"}],gn=[{value:"==",label:"="},{value:"!=",label:"\u2260"},{value:"<",label:"<"},{value:"<=",label:"\u2264"},{value:">",label:">"},{value:">=",label:"\u2265"},{value:"in",label:"in"},{value:"not-in",label:"not in"}],vn=[{value:"array-contains",label:"contains"},{value:"array-contains-any",label:"contains any"}];function xn(e){switch(e){case "ZodNumber":case "ZodBigInt":case "ZodDate":return gn;case "ZodBoolean":return At;case "ZodArray":return vn;default:return At}}var se="__null__";function wn(e){return `(function(cb){var i=document.getElementById('${e}');if(!i)return;if(cb.checked){i.dataset._prev=i.value;if(i.tagName==='SELECT'){var o=i.querySelector('option[value="${se}"]');if(!o){o=document.createElement('option');o.value='${se}';o.textContent='\u2205 null';o.dataset._auto='1';i.appendChild(o);}o.selected=true;}else{if(i.type==='number'||i.type==='datetime-local'){i.dataset._type=i.type;i.type='text';}i.value='${se}';i.readOnly=true;}i.style.opacity='0.55';}else{i.style.opacity='';if(i.tagName==='SELECT'){var o2=i.querySelector('option[value="${se}"][data-_auto="1"]');if(o2)o2.remove();var prev=i.dataset._prev||'';for(var k=0;k<i.options.length;k++)i.options[k].selected=(i.options[k].value===prev);}else{if(i.dataset._type){i.type=i.dataset._type;delete i.dataset._type;}i.readOnly=false;i.value=(i.dataset._prev&&i.dataset._prev!=='${se}')?i.dataset._prev:'';}}})(this)`}function kn(e,t){return `(function(){var h=document.getElementById('${e}');var boxes=document.querySelectorAll('input[data-enum-group="${t}"]');h.value=Array.from(boxes).filter(function(b){return b.checked;}).map(function(b){return b.value;}).join(',');})()`}function Re({inputId:e,active:t}){return jsxs("label",{class:"flex items-center gap-1 cursor-pointer select-none text-xs text-base-content/60 hover:text-base-content border border-base-300 rounded-md px-1.5 py-1 shrink-0 leading-none h-8",title:"Filter where field IS NULL",children:[jsx("input",{type:"checkbox",class:"checkbox checkbox-xs",checked:t,onchange:wn(e)}),jsx("span",{children:"\u2205"})]})}function Sn({col:e,active:t}){let n=t?.value??"",r=n===se,a=`fv_input_${e.name.replace(/\./g,"__")}`,o=t?.op,s=o==="in"||o==="not-in";if(e.enumValues&&e.enumValues.length>0){if(s){let c=new Set(n.split(",").map(p=>p.trim()).filter(Boolean)),l=`eg_${e.name.replace(/\./g,"__")}`;return jsxs("div",{class:"flex flex-wrap items-center gap-1 w-full",children:[jsx("input",{type:"hidden",id:a,name:`fv_${e.name}`,value:n}),e.enumValues.map(p=>jsxs("label",{class:"flex items-center gap-1 text-xs border border-base-300 rounded px-2 cursor-pointer hover:bg-base-200",children:[jsx("input",{type:"checkbox",class:"checkbox checkbox-xs",value:p,checked:c.has(p),"data-enum-group":l,onchange:kn(a,l)}),jsx("span",{children:p})]},p))]})}return jsxs("div",{class:"flex items-center gap-1 w-full",children:[jsxs("select",{id:a,name:`fv_${e.name}`,class:"select select-sm select-bordered w-full",style:r?"opacity:0.55":void 0,children:[jsx("option",{value:"",selected:n===""&&!r,children:"\u2014"}),e.enumValues.map(c=>jsx("option",{value:c,selected:n===c,children:c},c)),e.nullable&&jsx("option",{value:se,"data-_auto":"1",selected:r,children:"\u2205 null"})]}),e.nullable&&jsx(Re,{inputId:a,active:r})]})}if(e.zodType==="ZodBoolean")return jsxs("div",{class:"flex items-center gap-1 w-full",children:[jsxs("select",{id:a,name:`fv_${e.name}`,class:"select select-sm select-bordered w-full",style:r?"opacity:0.55":void 0,children:[jsx("option",{value:"",selected:n===""&&!r,children:"\u2014"}),jsx("option",{value:"true",selected:n==="true",children:"true"}),jsx("option",{value:"false",selected:n==="false",children:"false"}),e.nullable&&jsx("option",{value:se,"data-_auto":"1",selected:r,children:"\u2205 null"})]}),e.nullable&&jsx(Re,{inputId:a,active:r})]});if(e.zodType==="ZodArray"){let c=t?.op==="array-contains-any";return jsx("input",{id:a,type:"text",name:`fv_${e.name}`,value:n,placeholder:c?"val1, val2, \u2026":"value",class:"input input-sm input-bordered w-full"})}return e.zodType==="ZodNumber"||e.zodType==="ZodBigInt"?jsxs("div",{class:"flex items-center gap-1 w-full",children:[jsx("input",{id:a,type:r?"text":"number",name:`fv_${e.name}`,value:n,placeholder:"value",class:"input input-sm input-bordered w-full",readOnly:r||void 0,style:r?"opacity:0.55":void 0,"data-_type":r?"number":void 0}),e.nullable&&jsx(Re,{inputId:a,active:r})]}):e.zodType==="ZodDate"?jsxs("div",{class:"flex items-center gap-1 w-full",children:[jsx("input",{id:a,type:r?"text":"datetime-local",name:`fv_${e.name}`,value:n,class:"input input-sm input-bordered w-full",readOnly:r||void 0,style:r?"opacity:0.55":void 0,"data-_type":r?"datetime-local":void 0}),e.nullable&&jsx(Re,{inputId:a,active:r})]}):jsxs("div",{class:"flex items-center gap-1 w-full",children:[jsx("input",{id:a,type:"text",name:`fv_${e.name}`,value:n,placeholder:"value",class:"input input-sm input-bordered w-full",readOnly:r||void 0,style:r?"opacity:0.55":void 0}),e.nullable&&jsx(Re,{inputId:a,active:r})]})}function Qe({action:e,columnMeta:t,activeFilters:n,isGroup:r}){let a=Object.fromEntries(n.map(l=>[l.field,l])),o=n.length>0,s=n.length>=2||r&&o,c=t.filter(l=>l.zodType!=="ZodObject"&&l.zodType!=="ZodRecord");return jsxs("details",{class:"collapse collapse-arrow bg-base-100 border border-base-300 rounded-box mb-6 shadow-sm",open:o?true:void 0,children:[jsxs("summary",{class:"collapse-title text-sm font-medium py-2 min-h-0",children:["Filters",o&&jsxs("span",{class:"badge badge-primary badge-sm ml-2",children:[n.length," active"]})]}),jsx("div",{class:"collapse-content pb-4 pt-2",children:jsxs("form",{method:"get",action:e,children:[jsx("div",{class:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:c.map(l=>{let p=xn(l.zodType),b=a[l.name],g=b?.op??p[0].value;return jsxs("div",{class:"flex flex-col gap-1.5",children:[jsx("label",{class:"text-xs font-semibold text-base-content/60 uppercase tracking-wide",children:l.name}),jsxs("div",{class:"flex gap-1.5",children:[p.length>1?jsx("select",{name:`fo_${l.name}`,class:"select select-sm select-bordered w-20 shrink-0",children:p.map(k=>jsx("option",{value:k.value,selected:k.value===g,children:k.label},k.value))}):jsx("input",{type:"hidden",name:`fo_${l.name}`,value:p[0].value}),jsx(Sn,{col:l,active:b})]})]},l.name)})}),jsxs("div",{class:"flex flex-wrap gap-2 mt-4 pt-3 border-t border-base-200 items-center",children:[jsx("button",{type:"submit",class:"btn btn-sm btn-primary",children:"Apply"}),o&&jsx("a",{href:e,class:"btn btn-sm btn-ghost",children:"Clear"}),s&&jsxs("span",{class:"text-xs text-warning ml-auto flex items-center gap-1",children:[jsx("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:jsx("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),r?"Collection group queries require a composite index":"Multiple filters may require a composite index"]})]})]})})]})}function Xe(e,t,n,r,a,o){let s=n==="create"?`Create ${e}`:`Edit ${e} / ${r??""}`,c=n==="create"?[{label:"Repositories",href:a},{label:e,href:`${a}/${e}`},{label:"New document"}]:[{label:"Repositories",href:a},{label:e,href:`${a}/${e}`},{label:`Edit ${r??""}`}];return ae(jsx(oe,{opts:{title:s,breadcrumb:c,basePath:a,flash:o},children:jsx("div",{class:"card bg-base-100 border border-base-300",children:jsx("div",{class:"card-body p-6",children:jsx("div",{dangerouslySetInnerHTML:{__html:t}})})})}))}Ne();Ve();function Ye(e,t,n){let r=new URLSearchParams;for(let a of e)r.set(`fv_${a.field}`,a.value),r.set(`fo_${a.field}`,a.op);return t&&(r.set("ob",t.field),r.set("od",t.dir)),n&&r.set("ps",String(n)),r}function Rt(e,t,n,r,a){let o=Ye(e,r,a);return o.set("cursor",t),o.set("dir",n),`?${o.toString()}`}function An(e,t,n,r){let a=Ye(n,void 0,r);return t?.field===e?t.dir==="asc"&&(a.set("ob",e),a.set("od","desc")):(a.set("ob",e),a.set("od","asc")),`?${a.toString()}`}function Rn(e,t,n){return `?${Ye(t,n,e).toString()}`}function et(e,t,n,r,a,o,s=[],c=[],l=false,p=[],b,g,k,A,y,F,z,M=false){let m=`${r}/${e}`,f=`${m}/create`,S={};if(z)for(let h of n)S[h]=he(ge(z,h));let i=(F??[]).filter(h=>{let N=S[h]??he(ge(z,h));return N==="string"||N==="number"||N==="bigint"||N==="boolean"||N==="enum"||N==="literal"}),d=i.length>0,u=l,w=u||d,I=i.map(h=>{let N=ge(z,h),R=he(N),$=s.find(T=>T.name===h);return {name:h,type:R,enumValues:$?.enumValues??null,nullable:$?.nullable??false}});return ae(jsxs(oe,{opts:{title:e,breadcrumb:[{label:"Repositories",href:r},{label:e}],basePath:r,flash:o},children:[s.length>0&&jsx(Qe,{action:m,columnMeta:s,activeFilters:c,isGroup:A}),k&&jsxs("div",{role:"alert",class:`alert ${k.type==="index"?"alert-warning":"alert-error"} mb-6 shadow-sm`,children:[jsx("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-6 w-6 shrink-0 stroke-current",fill:"none",viewBox:"0 0 24 24",children:k.type==="index"?jsx("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"}):jsx("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"})}),jsxs("div",{class:"flex-1",children:[jsx("h3",{class:"font-bold",children:k.type==="index"?"Composite index required":"Query failed"}),jsx("div",{class:"text-sm",children:k.message})]}),k.indexUrl&&jsx("a",{href:k.indexUrl,target:"_blank",rel:"noopener noreferrer",class:"btn btn-sm btn-outline",children:"Create Index \u2192"})]}),jsxs("div",{class:"flex flex-wrap justify-between items-center mb-4 gap-3","data-frs-toolbar":true,children:[jsxs("div",{class:"flex items-center gap-3",children:[jsxs("span",{class:"text-sm text-base-content/60",children:[t.length,typeof y=="number"&&jsxs(Fragment,{children:[" ","of"," ",jsx("span",{class:"font-semibold text-base-content/80",children:y})]})," ","document",(typeof y=="number"?y:t.length)!==1&&"s"]}),jsxs("div",{class:"flex items-center gap-1.5 text-sm text-base-content/60",children:[jsx("span",{children:"Rows"}),jsx("div",{class:"join",children:[10,25,50,100].map(h=>jsx("a",{href:Rn(h,c,b),class:`join-item btn btn-xs ${g===h?"btn-active btn-primary":"btn-outline"}`,children:h},h))})]})]}),jsx("a",{href:f,class:"btn btn-primary btn-sm",children:"+ New"})]}),w&&jsxs("div",{class:"hidden mb-3 alert alert-info py-2 px-3","data-frs-bulk-bar":true,"data-frs-repo":e,"data-frs-total":typeof y=="number"?String(y):"","data-frs-page-size":String(g??t.length),"data-frs-allow-delete":u?"1":"0","data-frs-allow-update":d?"1":"0","data-frs-fields":JSON.stringify(I),"data-frs-filters":JSON.stringify(c),children:[jsxs("div",{class:"flex-1 text-sm",children:[jsx("span",{"data-frs-bulk-summary":true,children:"0 selected"}),typeof y=="number"&&y>t.length&&jsxs("button",{type:"button",class:"ml-3 link text-sm hidden","data-frs-bulk-select-all":true,children:["Select all ",y," matching documents"]}),jsxs("span",{class:"hidden ml-3 italic","data-frs-bulk-all-active":true,children:["All ",y??"?"," matching documents are selected."," ",jsx("button",{type:"button",class:"link","data-frs-bulk-clear":true,children:"Clear selection"})]})]}),jsxs("div",{class:"flex gap-2",children:[d&&jsx("button",{type:"button",class:"btn btn-sm btn-outline","data-frs-bulk-action":"update",children:"Update field\u2026"}),u&&jsx("button",{type:"button",class:"btn btn-sm btn-error btn-outline","data-frs-bulk-action":"delete",children:"Delete"})]})]}),jsx("div",{class:"overflow-x-auto rounded-box border border-base-300 bg-base-100","data-frs-table-wrap":true,children:jsxs("table",{class:"table table-sm w-full","data-frs-table":true,"data-frs-repo":e,"data-frs-colcount":n.length,children:[jsx("thead",{children:jsxs("tr",{class:"bg-base-200/50",children:[w&&jsx("th",{class:"w-8",children:jsx("input",{type:"checkbox",class:"checkbox checkbox-xs checkbox-primary","data-frs-select-page":true,"aria-label":"Select all on this page"})}),[...n].map((h,N)=>{let R=b?.field===h,$=R?b.dir==="asc"?" \u25B2":" \u25BC":"";return jsx("th",{class:"text-xs font-semibold text-base-content/60 uppercase tracking-wide",children:jsxs("a",{href:An(h,b,c,g),class:`hover:text-base-content inline-flex items-center gap-0.5${R?" text-primary font-bold":""}`,children:[h,$]})},N)}),p.map((h,N)=>jsx("th",{class:"text-xs font-semibold text-base-content/60 uppercase tracking-wide",children:h.column},`rel-${N}`)),jsx("th",{class:"text-xs font-semibold text-base-content/60 uppercase tracking-wide text-right",children:"Actions"})]})}),jsx("tbody",{children:t.length===0?jsx("tr",{children:jsx("td",{colspan:n.length+p.length+1+(w?1:0),class:"text-center py-16 text-base-content/40",children:"No documents found"})}):t.map((h,N)=>{let R=String(h.docId??h.id??""),$=`${r}/${e}/${encodeURIComponent(R)}/edit`,T=`${r}/${e}/${encodeURIComponent(R)}/delete`;return jsxs("tr",{class:"hover","data-frs-row-id":R,children:[w&&jsx("td",{class:"align-middle py-2",children:jsx("input",{type:"checkbox",class:"checkbox checkbox-xs checkbox-primary","data-frs-select-row":true,value:R,"aria-label":`Select ${R}`})}),n.map((E,B)=>{let U=h[E],P=S[E],v=P?Ae(P,U):null;return jsx("td",{class:"align-top py-2",children:jsx(ye,{val:U,mismatch:v})},B)}),p.map((E,B)=>{let U=h[E.key];if(U==null||U==="")return jsx("td",{class:"py-2"},`rel-${B}`);let P=E.type==="one"?`${r}/${E.targetRepo}/${encodeURIComponent(String(U))}/edit`:`${r}/${E.targetRepo}?fv_${E.targetKey}=${encodeURIComponent(String(U))}`;return jsx("td",{class:"align-middle py-2",children:jsx("a",{href:P,class:"btn btn-xs btn-ghost btn-outline","data-frs-relation":true,"data-frs-rel-type":E.type,"data-frs-rel-repo":E.targetRepo,"data-frs-rel-fk":E.targetKey,"data-frs-rel-val":String(U),"data-frs-rel-label":E.column,children:E.column})},`rel-${B}`)}),jsx("td",{class:"align-middle text-right whitespace-nowrap py-2",children:jsxs("div",{class:"flex gap-1 justify-end",children:[jsx("a",{href:$,class:"btn btn-xs btn-outline",children:"Edit"}),M&&jsx("a",{href:`${r}/${e}/${encodeURIComponent(R)}/history`,class:"btn btn-xs btn-outline",title:"View change history",children:"History"}),l&&jsx("form",{method:"post",action:T,onsubmit:"return confirm('Delete this document?')",children:jsx("button",{type:"submit",class:"btn btn-xs btn-error btn-outline",children:"Delete"})})]})})]},N)})})]})}),(a.hasPrev||a.hasNext)&&jsxs("div",{class:"flex flex-col items-center mt-6 gap-2",children:[jsxs("div",{class:"flex justify-center items-center gap-2",children:[a.hasPrev?jsx("a",{href:Rt(c,a.prevCursor,"prev",b,g),class:"btn btn-sm btn-outline",children:"\u2190 Previous"}):jsx("button",{class:"btn btn-sm btn-outline",disabled:true,children:"\u2190 Previous"}),a.hasNext?jsx("a",{href:Rt(c,a.nextCursor,"next",b,g),class:"btn btn-sm btn-outline",children:"Next \u2192"}):jsx("button",{class:"btn btn-sm btn-outline",disabled:true,children:"Next \u2192"})]}),typeof y=="number"&&jsxs("div",{class:"text-xs text-base-content/50",children:[y," total document",y!==1?"s":"",c.length>0?" matching filters":""]})]}),w&&d&&jsxs("dialog",{id:"frs-bulk-update-modal",class:"modal",children:[jsxs("div",{class:"modal-box",children:[jsx("h3",{class:"font-bold text-lg mb-3",children:"Bulk update field"}),jsx("p",{class:"text-sm text-base-content/60 mb-4","data-frs-bulk-update-summary":true,children:"Update one field on the selected documents."}),jsxs("form",{method:"dialog","data-frs-bulk-update-form":true,children:[jsxs("label",{class:"form-control w-full mb-3",children:[jsx("div",{class:"label",children:jsx("span",{class:"label-text text-xs uppercase tracking-wide",children:"Field"})}),jsxs("select",{class:"select select-bordered select-sm w-full",name:"field",required:true,"data-frs-bulk-field-select":true,children:[jsx("option",{value:"",children:"\u2014 Select a field \u2014"}),i.map(h=>jsx("option",{value:h,children:h},h))]})]}),jsx("div",{class:"mb-4","data-frs-bulk-value-container":true}),jsxs("div",{class:"modal-action",children:[jsx("button",{type:"button",class:"btn btn-sm btn-ghost","data-frs-bulk-update-cancel":true,children:"Cancel"}),jsx("button",{type:"submit",class:"btn btn-sm btn-primary","data-frs-bulk-update-submit":true,children:"Apply"})]})]})]}),jsx("form",{method:"dialog",class:"modal-backdrop",children:jsx("button",{children:"close"})})]})]}))}function Ze(e,t){return Ge(e,t)}function $t(e,t){return We(e,t)}function Ct(e,t,n,r,a,o,s,c,l,p,b,g,k,A,y,F,z,M){return et(e,t,n,r,a,o,s,c,l,p,b,g,k,A,y,F,z,M)}function ue(e,t,n,r,a,o){return Xe(e,t,n,r,a,o)}var tt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";function Tn(){let e="";for(;e.length<20;){let t=randomBytes(20);for(let n=0;n<t.length&&e.length<20;n++){let r=t[n];r>=tt.length*4||(e+=tt.charAt(r%tt.length));}}return e}function ze(e,t){if(!t)return;let n=e[t];if(typeof n!="string"||!n)return;let r=n.split("/").filter(Boolean),a=[];for(let o=1;o<r.length;o+=2)a.push(r[o]);return a.length>0?a:void 0}async function ve(e,t){let n=e.documentKey??"docId",r=`by${n.charAt(0).toUpperCase()}${n.slice(1)}`;if(typeof e.repo.get[r]=="function")try{let o=await e.repo.get[r](t);if(o)return o}catch{}return (await e.repo.query.by({where:[[n,"==",t]],limit:1}))[0]??null}function nt(e,t,n){let r=e.documentKey??"docId",a=Ue(n,{ref:e.repo.ref,path:e.path,isGroup:!!e.isGroup,filters:[{field:r,op:"==",value:t}]});return a.type==="index"?{type:"warning",message:"Loading this document requires a composite index that does not exist yet.",...a.indexUrl?{action:{href:a.indexUrl,label:"Create Index \u2192",external:true}}:{}}:{type:"error",message:a.message}}function _(e,t,n=200){e.status(n).set("Content-Type","text/html; charset=utf-8").send(t);}function rt(e,t){e.status(302).set("Location",t).send("");}function at(e,t){let n=t.shape,r={};for(let[a,o]of Object.entries(n)){let s=_t(o),c=L(s),l=c==="ZodObject",p=s,b=false;if(c==="ZodUnion"){let A=Te(s);A.some(F=>L(F)==="ZodDate")&&(b=true);let y=A.find(F=>{if(L(F)==="ZodObject"){let z=X(F);return "latitude"in z&&"longitude"in z}return false});y&&(l=true,p=y);}if(e[a+"__isnull"]==="1"){r[a]=null;continue}if(l){let A={},y=false;for(let[M,m]of Object.entries(e))M.startsWith(`${a}.`)&&(A[M.slice(a.length+1)]=m,y=true);if(y){r[a]=at(A,p);continue}let F=e[a],z=Array.isArray(F)?F[F.length-1]:F;if(z)try{r[a]=JSON.parse(z);}catch{r[a]=z;}continue}let g=e[a],k=Array.isArray(g)?g[g.length-1]:g;if(k===void 0||k===""){c==="ZodBoolean"&&(r[a]=false);continue}if(b){r[a]=new Date(k);continue}switch(c){case "ZodBoolean":k==="__null__"?r[a]=null:r[a]=k==="true"||k==="on"||k==="1";break;case "ZodNumber":case "ZodBigInt":r[a]=Number(k);break;case "ZodDate":r[a]=new Date(k);break;case "ZodArray":try{r[a]=JSON.parse(k);}catch{r[a]=k;}break;default:if(k.startsWith("{")||k.startsWith("["))try{r[a]=JSON.parse(k);break}catch{}r[a]=k;}}return r}function Et(e){let t=null;if(e instanceof Date)t=e;else if(typeof e=="object"&&e!==null&&typeof e.toDate=="function")t=e.toDate();else if(typeof e=="object"&&e!==null&&"_seconds"in e&&"_nanoseconds"in e)t=new Date(e._seconds*1e3+Math.floor(e._nanoseconds/1e6));else if(typeof e=="string"||typeof e=="number"){let r=new Date(e);isNaN(r.getTime())||(t=r);}if(!t||isNaN(t.getTime()))return null;let n=r=>String(r).padStart(2,"0");return `${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function Ot(e){let t=e;for(;;){let n=L(t);if(n==="ZodOptional"||n==="ZodNullable"||n==="ZodDefault")t=W(t);else return n}}function _t(e){let t=e;for(;;){let n=L(t);if(n==="ZodOptional"||n==="ZodNullable"||n==="ZodDefault")t=W(t);else return t}}function Nt(e){let t=e;for(;;){let n=L(t);if(n==="ZodOptional"||n==="ZodNullable")return true;if(n==="ZodDefault"){t=W(t);continue}return false}}function Pt(e){let t=_t(e),n=L(t);if(n==="ZodEnum"){let r=we(t);return r.length>0?r:void 0}if(n==="ZodNativeEnum"){let r=ke(t),a=Object.values(r).filter(o=>typeof o=="string");return a.length>0?a:void 0}if(n==="ZodLiteral"){let r=Se(t);return typeof r=="string"?[r]:void 0}}function It(e,t,n=""){let r={};for(let a of Object.keys(t.shape)){let o=n?`${n}.${a}`:a,s=e[a];if(s===null){r[o]="__null__";continue}if(s===void 0)continue;let c=t.shape[a];for(;;){let p=L(c);if(p==="ZodOptional"||p==="ZodNullable"||p==="ZodDefault")c=W(c);else break}let l=L(c);if(l==="ZodObject"&&typeof s=="object"&&s!==null&&!Array.isArray(s)){let p=It(s,c,o);Object.assign(r,p);}else if(l==="ZodDate"){let p=Et(s);p!==null&&(r[o]=p);}else if(typeof s=="object"&&s!==null&&!Array.isArray(s)&&("_seconds"in s||typeof s.toDate=="function")){let p=Et(s);r[o]=p??JSON.stringify(s,null,2);}else typeof s=="object"?r[o]=JSON.stringify(s,null,2):r[o]=String(s);}return r}function ot(e,t){return e.map(n=>({...n,defaultValue:t[n.name]??n.defaultValue,nested:n.nested?ot(n.nested,t):void 0}))}function On(e,t){let n=new Set(["==","!=","<","<=",">",">=","in","not-in","array-contains","array-contains-any"]),r=[];for(let[a,o]of Object.entries(e)){if(!a.startsWith("fv_"))continue;let s=a.slice(3);if(!t.has(s))continue;let c=(o??"").trim();if(!c)continue;let l=e[`fo_${s}`]??"==",p=n.has(l)?l:"==";r.push({field:s,op:p,value:c});}return r}function Tt(e){let t="__null__",n=r=>r===t?null:r==="true"?true:r==="false"?false:r!==""&&!isNaN(Number(r))?Number(r):r;return e.map(r=>{if(r.op==="array-contains-any"||r.op==="in"||r.op==="not-in"){let a=r.value.split(",").map(o=>o.trim()).filter(o=>o!==""&&o!==t).map(o=>n(o));return [r.field,r.op,a]}return [r.field,r.op,n(r.value)]})}function Zt(e,t,n=""){let r=[];for(let a of e){let o=n?`${n}.${a}`:a,s=t.shape[a];if(!s){r.push({name:o,zodType:"ZodString"});continue}let c=Ot(s);if(c==="ZodObject"){let l=s;for(;;){let b=L(l);if(b==="ZodOptional"||b==="ZodNullable"||b==="ZodDefault")l=W(l);else break}let p=X(l);r.push(...Zt(Object.keys(p),l,o));}else r.push({name:o,zodType:c,nullable:Nt(s),enumValues:Pt(s)});}return r}function _n(e,t){let n=t.split("."),r=e;for(let a of n){for(;;){let s=L(r);if(s==="ZodOptional"||s==="ZodNullable"||s==="ZodDefault")r=W(r);else break}let o=X(r);if(!(a in o))return null;r=o[a];}return r}function pe(e,t){if(!t||t.length===0)return e;let n=[],r=new Map;for(let o of t){let s=o.indexOf(".");if(s===-1)n.push(o);else {let c=o.slice(0,s),l=o.slice(s+1);r.has(c)||r.set(c,[]),r.get(c).push(l);}}let a={};for(let o of n)o in e.shape&&(a[o]=e.shape[o]);for(let[o,s]of r){if(!(o in e.shape))continue;let c=e.shape[o];for(;;){let l=L(c);if(l==="ZodOptional"||l==="ZodNullable"||l==="ZodDefault")c=W(c);else break}if(L(c)!=="ZodObject"){a[o]=e.shape[o];continue}a[o]=pe(c,s);}return z.object(a)}function ne(e,t,n){return De(e,t,n)}function zt(e,t,n){let r=(m,f)=>{let S=ne(m,t,n),i=Object.values(e).map(d=>({name:d.name,path:d.path}));_(f,$t(i,S));},a=async(m,f)=>{let S=m.params.repoName;if(!S){_(f,"Bad request",400);return}let i=e[S];if(!i){_(f,"Repository not found",404);return}let d=i.pageSize??25,u=m.query??{},w=u.cursor,I=u.dir==="prev"?"prev":"next",h=u.ob??"",N=u.od==="desc"?"desc":"asc",R=h?{field:h,dir:N}:void 0,$=parseInt(u.ps??""),T=Number.isFinite($)&&$>0?Math.min($,200):d,E=i.listColumns??Object.keys(i.schema.shape),B=i.documentKey??"docId",U=[B,...E.filter(V=>V!==B)];R&&(new Set([B,...E]).has(R.field)||(R=void 0));let P=i.filterableFields?(()=>{let V=[];for(let te of i.filterableFields)(te.includes(".")||E.includes(te))&&V.push(te);return V})():E,v=(()=>{let V=[];for(let te of P)if(te.includes(".")){let me=_n(i.schema,te);V.push({name:te,zodType:me?Ot(me):"ZodString",nullable:me?Nt(me):false,enumValues:me?Pt(me):void 0});}else V.push(...Zt([te],i.schema));return V})(),q=new Set(v.map(V=>V.name)),ie=On(u,q),re=Tt(ie),xe;if(w)try{let V=i.repo.ref;typeof V.doc=="function"&&(xe=await V.doc(w).get());}catch{}let[K,Ce]=await Promise.all([i.repo.query.paginate({pageSize:T,cursor:xe,direction:I,...re.length>0?{where:re}:{},...R?{orderBy:[{field:R.field,direction:R.dir}]}:{}}).catch(V=>({queryError:Ue(V,{ref:i.repo.ref,path:i.path,isGroup:!!i.isGroup,filters:ie,sort:R})})),i.repo.aggregate.count(re.length>0?{where:re}:{}).catch(()=>{})]),fe="queryError"in K,Lt=fe?[]:K.data,Bt=fe?"":K.nextCursor?.id??"",Mt=fe?"":K.prevCursor?.id??"",Ut=fe?K.queryError:void 0,Ht=ne(m,t,n);_(f,Ct(i.name,Lt,U,Ht,{hasPrev:fe?false:K.hasPrevPage,hasNext:fe?false:K.hasNextPage,prevCursor:Mt,nextCursor:Bt},void 0,v,ie,i.allowDelete??false,i.relationalMeta,R,T,Ut,i.isGroup,Ce,i.mutableFields,i.schema,i.historyEnabled));},o=(m,f)=>{let S=m.params.repoName;if(!S){_(f,"Bad request",400);return}let i=e[S];if(!i){_(f,"Repository not found",404);return}let d=ne(m,t,n),u=pe(i.schema,i.createFields),w=ee(u),I=`${d}/${i.name}/create`,h=le(w,I,"POST","Create document");_(f,ue(i.name,h,"create",null,d));},s=async(m,f)=>{let S=m.params.repoName;if(!S){_(f,"Bad request",400);return}let i=e[S];if(!i){_(f,"Repository not found",404);return}let d=ne(m,t,n),u=m.body??{},w=at(u,i.schema),I=pe(i.schema,i.createFields),h=I.safeParse(w);if(!h.success){let N=ee(I),R=`${d}/${i.name}/create`,$=le(N,R,"POST","Create document"),T=h.error.issues.map(E=>`${E.path.join(".")}: ${E.message}`).join(", ");_(f,ue(i.name,$,"create",null,d,{type:"error",message:`Validation error: ${T}`}),422);return}try{if(i.isGroup&&i.parentKeys&&i.parentKeys.length>0){let N={...h.data};i.createdKey&&(N[i.createdKey]=new Date);let R=i.parentKeys.filter(B=>!N[B]);if(R.length>0)throw new Error(`Missing parent key(s) for subcollection create: ${R.join(", ")}`);let $=i.parentKeys.map(B=>N[B]),T=i.documentKey??"docId",E=N[T]||Tn();await i.repo.set(...$,E,N);}else await i.repo.create(h.data);rt(f,`${d}/${i.name}?flash=created`);}catch(N){let R=pe(i.schema,i.createFields),$=ee(R),T=`${d}/${i.name}/create`,E=le($,T,"POST","Create document");_(f,ue(i.name,E,"create",null,d,{type:"error",message:`Save error: ${N.message}`}),500);}},c=async(m,f)=>{let S=m.params.repoName,i=m.params.id;if(!S||!i){_(f,"Bad request",400);return}let d=e[S];if(!d){_(f,"Repository not found",404);return}let u=ne(m,t,n),w=null;try{w=await ve(d,i);}catch(T){let E=nt(d,i,T),B=de(T)?424:500;_(f,Ze("",{title:`Edit ${d.name} / ${i}`,basePath:u,breadcrumb:[{label:"Repositories",href:u},{label:d.name,href:`${u}/${d.name}`},{label:`Edit ${i}`}],flash:E}),B);return}if(!w){_(f,"Document not found",404);return}let I=It(w,d.schema),h=pe(d.schema,d.mutableFields),N=ot(ee(h),I),R=`${u}/${d.name}/${encodeURIComponent(i)}/edit`,$=le(N,R,"POST","Save changes");_(f,ue(d.name,$,"edit",i,u));},l=async(m,f)=>{let S=m.params.repoName,i=m.params.id;if(!S||!i){_(f,"Bad request",400);return}let d=e[S];if(!d){_(f,"Repository not found",404);return}let u=ne(m,t,n),w=m.body??{},I=at(w,d.schema),h=pe(d.schema,d.mutableFields),R=h.partial().safeParse(I);if(!R.success){let $=Object.fromEntries(Object.entries(w).map(([P,v])=>[P,Array.isArray(v)?v.join(","):v??""])),T=ot(ee(h),$),E=`${u}/${d.name}/${encodeURIComponent(i)}/edit`,B=le(T,E,"POST","Save changes"),U=R.error.issues.map(P=>`${P.path.join(".")}: ${P.message}`).join(", ");_(f,ue(d.name,B,"edit",i,u,{type:"error",message:`Validation error: ${U}`}),422);return}try{let $=await ve(d,i),T=($&&ze($,d.pathKey))??[i];await d.repo.update(...T,R.data),rt(f,`${u}/${d.name}?flash=updated`);}catch($){let T=pe(d.schema,d.mutableFields),E=ee(T),B=`${u}/${d.name}/${encodeURIComponent(i)}/edit`,U=le(E,B,"POST","Save changes"),P=de($)?nt(d,i,$):{type:"error",message:`Save error: ${$.message}`},v=de($)?424:500;_(f,ue(d.name,U,"edit",i,u,P),v);}},p=async(m,f)=>{let S=m.params.repoName,i=m.params.id;if(!S||!i){_(f,"Bad request",400);return}let d=e[S];if(!d){_(f,"Repository not found",404);return}if(!d.allowDelete){_(f,"Delete is not allowed for this repository",403);return}let u=ne(m,t,n);try{let w=await ve(d,i),I=(w&&ze(w,d.pathKey))??[i];await d.repo.delete(...I),rt(f,`${u}/${d.name}?flash=deleted`);}catch(w){let I=de(w)?nt(d,i,w):{type:"error",message:`Delete error: ${w.message}`},h=de(w)?424:500;_(f,Ze("",{title:`Delete ${d.name} / ${i}`,basePath:u,breadcrumb:[{label:"Repositories",href:u},{label:d.name,href:`${u}/${d.name}`},{label:`Delete ${i}`}],flash:I}),h);}},b=async(m,f)=>{let S=m.params.repoName;if(!S){_(f,"Bad request",400);return}let i=e[S];if(!i){_(f,"Repository not found",404);return}let d=ne(m,t,n),u=m.query,w=u?.type==="many"?"many":"one",I=Math.max(1,Math.min(100,Number(u?.ps??25)||25)),h=i.listColumns??Object.keys(X(i.schema)),{PanelOne:N,PanelMany:R}=await Promise.resolve().then(()=>(Ke(),kt)),{renderToString:$}=await import('hono/jsx/dom/server');if(w==="one"){let v=String(u?.id??"");if(!v){_(f,"<div class='p-6 text-error'>Missing id parameter.</div>",400);return}try{let q=await ve(i,v),ie=$(N({doc:q,repoName:i.name,basePath:d,schema:i.schema,columns:h}));_(f,ie);}catch(q){_(f,`<div class='p-6 text-error text-sm'>Error: ${q.message}</div>`,500);}return}let T=String(u?.fk??""),E=String(u?.fv??"");if(!T||!E){_(f,"<div class='p-6 text-error'>Missing fk/fv parameters.</div>",400);return}let B=u?.cursor??"",U=u?.dir==="prev"?"prev":"next",P;if(B)try{let v=i.repo.ref;typeof v.doc=="function"&&(P=await v.doc(B).get());}catch{}try{let v=await i.repo.query.paginate({pageSize:I,cursor:P,direction:U,where:[[T,"==",Nn(E)]]}),q=$(R({docs:v.data,repoName:i.name,basePath:d,fk:T,fv:E,columns:h,schema:i.schema,pagination:{hasPrev:v.hasPrevPage,hasNext:v.hasNextPage,prevCursor:v.prevCursor?.id??"",nextCursor:v.nextCursor?.id??"",pageSize:I}}));_(f,q);}catch(v){_(f,`<div class='p-6 text-error text-sm'>Error: ${v.message}</div>`,500);}},g=async(m,f)=>{let S=[];for(let i of f){let d;if(m.isGroup||m.parentKeys?.length){let u=await ve(m,i);d=u?ze(u,m.pathKey):void 0;}d||(d=[i]);try{let u=m.repo.documentRef(...d);u&&S.push(u);}catch{}}return S},k=async(m,f)=>{let S=Tt(f),i=m.documentKey??"docId",d=[],u;for(;;){let w=await m.repo.query.paginate({pageSize:500,cursor:u,direction:"next",...S.length>0?{where:S}:{}});for(let I of w.data){let h=String(I[i]??I.id??"");h&&d.push(h);}if(!w.hasNextPage||!w.nextCursor)break;u=w.nextCursor;}return d},A=async(m,f)=>{let S=m.params.repoName;if(!S){Q(f,{error:"Bad request"},400);return}let i=e[S];if(!i){Q(f,{error:"Repository not found"},404);return}if(!i.allowDelete){Q(f,{error:"Delete is not allowed for this repository"},403);return}let d=m.body??{};try{let u=await F(i,d);if(u.length===0){Q(f,{deleted:0});return}let w=await g(i,u);for(let I=0;I<w.length;I+=500)await i.repo.bulk.delete(w.slice(I,I+500));Q(f,{deleted:w.length});}catch(u){Q(f,{error:u.message},500);}},y=async(m,f)=>{let S=m.params.repoName;if(!S){Q(f,{error:"Bad request"},400);return}let i=e[S];if(!i){Q(f,{error:"Repository not found"},404);return}let d=m.body??{},u=String(d.field??"");if(!u){Q(f,{error:"Missing 'field'"},400);return}if(!i.mutableFields||!i.mutableFields.includes(u)){Q(f,{error:`Field '${u}' is not bulk-updatable`},403);return}let w=i.schema.shape?.[u],I=d.value;if(w){let h=w.safeParse(d.value);if(!h.success){Q(f,{error:`Invalid value for '${u}': ${h.error.message}`},400);return}I=h.data;}try{let h=await F(i,d);if(h.length===0){Q(f,{updated:0});return}let R=(await g(i,h)).map($=>({docRef:$,data:{[u]:I}}));for(let $=0;$<R.length;$+=500)await i.repo.bulk.update(R.slice($,$+500));Q(f,{updated:R.length});}catch(h){Q(f,{error:h.message},500);}};async function F(m,f){if(f.selectAll){let S=z(f.filters,m);return await k(m,S)}return Array.isArray(f.ids)?f.ids.filter(S=>typeof S=="string"&&!!S):[]}function z(m,f){if(!Array.isArray(m))return [];let S=new Set((f.filterableFields??Object.keys(X(f.schema))).map(u=>String(u))),i=new Set(["==","!=","<","<=",">",">=","in","not-in","array-contains","array-contains-any"]),d=[];for(let u of m)u&&typeof u=="object"&&typeof u.field=="string"&&S.has(u.field)&&typeof u.value=="string"&&i.has(String(u.op))&&d.push({field:u.field,op:u.op,value:u.value});return d}return {handleDashboard:r,handleList:a,handleCreateForm:o,handleCreateSubmit:s,handleEditForm:c,handleEditSubmit:l,handleDelete:p,handlePanel:b,handleBulkDelete:A,handleBulkUpdate:y,handleHistory:async(m,f)=>{let S=m.params.repoName,i=m.params.id;if(!S||!i){_(f,"Bad request",400);return}let d=e[S];if(!d){_(f,"Repository not found",404);return}if(!d.historyEnabled||!d.repo.history){_(f,"History not enabled for this repository",404);return}let u=ne(m,t,n),w=d.historySubcollection??"history",I=[i];try{let v=await ve(d,i),q=v?ze(v,d.pathKey):void 0;q&&q.length>0&&(I=q);}catch{}let h=parseInt(String(m.query?.limit??"")),N=Number.isFinite(h)&&h>0?Math.min(h,500):100,R=[],$;try{R=await d.repo.history.list(...I,{limit:N});}catch(v){$=v.message;}let T=v=>String(v??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),E=v=>{if(v===void 0)return '<span class="opacity-40">undefined</span>';if(v===null)return '<span class="opacity-40">null</span>';if(typeof v=="object")try{return `<code class="text-xs">${T(JSON.stringify(v))}</code>`}catch{return T(String(v))}return T(String(v))},B=v=>v?typeof v.toDate=="function"?v.toDate().toISOString():v instanceof Date?v.toISOString():T(String(v)):"",U=v=>`<span class="badge badge-sm ${v==="create"?"badge-success":v==="delete"?"badge-error":"badge-info"}">${T(v)}</span>`,P="";if(P+='<div class="flex items-center justify-between mb-4">',P+=`<a href="${u}/${d.name}/${encodeURIComponent(i)}/edit" class="btn btn-sm btn-outline">\u2190 Back to edit</a>`,P+=`<a href="${u}/${d.name}" class="btn btn-sm btn-outline">\u2190 Back to list</a>`,P+="</div>",P+=`<p class="text-sm text-base-content/60 mb-4">Subcollection: <code>${T(w)}</code> \xB7 Showing up to ${N} entries.</p>`,$)P+=`<div class="alert alert-error mb-4">${T($)}</div>`;else if(R.length===0)P+='<div class="alert">No history entries found.</div>';else {P+='<div class="overflow-x-auto"><table class="table table-zebra table-sm">',P+="<thead><tr><th>When</th><th>Op</th><th>User</th><th>Reason / Comment</th><th>Changes</th></tr></thead><tbody>";for(let v of R){let q=v.meta??{},ie=[q.reason,q.comment].filter(K=>K!=null&&K!=="").map(K=>T(String(K))).join(" \u2014 "),re="",xe=Object.keys(v.changes??{});xe.length===0?re='<span class="opacity-40">\u2014</span>':re='<ul class="space-y-1">'+xe.map(K=>{let Ce=v.changes[K];return `<li><strong>${T(K)}</strong>: ${E(Ce.oldValue)} \u2192 ${E(Ce.newValue)}</li>`}).join("")+"</ul>",P+="<tr>",P+=`<td class="whitespace-nowrap text-xs font-mono">${T(B(v.historySetAt))}</td>`,P+=`<td>${U(v.operation??"update")}</td>`,P+=`<td class="text-xs">${T(q.userEmail??q.userId??"")}</td>`,P+=`<td class="text-xs">${ie}</td>`,P+=`<td>${re}</td>`,P+="</tr>";}P+="</tbody></table></div>";}_(f,Ze(P,{title:`History \u2014 ${d.name} / ${i}`,basePath:u,breadcrumb:[{label:"Repositories",href:u},{label:d.name,href:`${u}/${d.name}`},{label:`History ${i}`}]}));}}}function Q(e,t,n=200){e.status(n).set("Content-Type","application/json; charset=utf-8").send(JSON.stringify(t));}function Nn(e){return e==="true"?true:e==="false"?false:e!==""&&!isNaN(Number(e))?Number(e):e}function Pn(e){let t=[],n=e.replace(/[.*+?^${}()|[\]\\]/g,r=>r===":"?r:`\\${r}`).replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,(r,a)=>(t.push(a),"([^/]+)"));return {pattern:new RegExp(`^${n}$`),paramNames:t}}function In(e){let t=e.path??e.url??"/",n=t.indexOf("?");return n===-1?t:t.slice(0,n)}var $e=class{constructor(){this.routes=[];this.middlewares=[];this.notFoundHandler=(t,n)=>{n.status(404).send("Not Found");};this.errorHandler=(t,n,r)=>{console.error("[MiniRouter]",t),r.status(500).send("Internal Server Error");};}use(t){return this.middlewares.push(t),this}get(t,n){return this.addRoute("GET",t,n)}post(t,n){return this.addRoute("POST",t,n)}put(t,n){return this.addRoute("PUT",t,n)}patch(t,n){return this.addRoute("PATCH",t,n)}delete(t,n){return this.addRoute("DELETE",t,n)}onNotFound(t){return this.notFoundHandler=t,this}onError(t){return this.errorHandler=t,this}addRoute(t,n,r){let{pattern:a,paramNames:o}=Pn(n);return this.routes.push({method:t.toUpperCase(),pattern:a,paramNames:o,handler:r}),this}async handle(t,n){let r=(t.method??"GET").toUpperCase(),a=In(t),o=null,s={};for(let p of this.routes){if(p.method!==r)continue;let b=a.match(p.pattern);if(b){o=p,s={},p.paramNames.forEach((g,k)=>{s[g]=decodeURIComponent(b[k+1]??"");});break}}let c=Object.assign(t,{params:s}),l=o?o.handler:this.notFoundHandler;try{await this.runMiddlewareChain(c,n,l);}catch(p){this.errorHandler(p,t,n);}}async runMiddlewareChain(t,n,r){let a=0,o=async()=>{if(a<this.middlewares.length){let s=this.middlewares[a++];await s(t,n,o);}else await r(t,n);};await o();}};var Dt="https://cdn.jsdelivr.net",Ft="https://www.gstatic.com",Zn=["default-src 'self'",`script-src 'self' 'unsafe-inline' 'unsafe-eval' ${Dt} ${Ft}`,`style-src 'self' 'unsafe-inline' ${Dt}`,`connect-src 'self' ${Ft} https://*.googleapis.com https://*.firebaseio.com https://identitytoolkit.googleapis.com`,"img-src 'self' data:","font-src 'self' data:","frame-ancestors 'none'","base-uri 'self'","form-action 'self'"].join("; ");function jt(e={}){let t=e.csp===void 0?Zn:e.csp,n=e.frameOptions===void 0?"DENY":e.frameOptions,r=e.referrerPolicy===void 0?"no-referrer":e.referrerPolicy,a=e.cacheControl===void 0?"private, no-store":e.cacheControl;return async(o,s,c)=>{typeof s?.setHeader=="function"&&(s.setHeader("X-Content-Type-Options","nosniff"),n&&s.setHeader("X-Frame-Options",n),r&&s.setHeader("Referrer-Policy",r),a&&s.setHeader("Cache-Control",a),t&&s.setHeader("Content-Security-Policy",t)),await c();}}async function zn(e){return typeof e.rawBody=="string"?e.rawBody:Buffer.isBuffer(e.rawBody)?e.rawBody.toString("utf8"):""}function Dn(e){let t={};if(!e)return t;for(let n of e.split("&")){let r=n.indexOf("=");if(r===-1)continue;let a=decodeURIComponent(n.slice(0,r).replace(/\+/g," ")),o=decodeURIComponent(n.slice(r+1).replace(/\+/g," ")),s=t[a];s===void 0?t[a]=o:Array.isArray(s)?s.push(o):t[a]=[s,o];}return t}function sa(e){let{basePath:t="/",repos:n,parseBody:r=true,securityHeaders:a,auth:o,middleware:s=[],httpsOptions:c}=e,l=t==="/"?"":t.replace(/\/$/,""),p={};for(let[A,y]of Object.entries(n)){let F=y.schema??y.repo.schema??null;if(!F)throw new Error(`[createAdminServer] Repository "${A}" has no Zod schema. Either use createRepositoryConfig(schema)(config) or pass schema: explicitly.`);let z,M,m;if(y.fieldsConfig){let i=y.fieldsConfig;z=[],M=[],m=[];for(let[d,u]of Object.entries(i))for(let w of u)w==="filterable"?z.push(d):w==="mutable"?M.push(d):w==="create"&&m.push(d);z.length===0&&(z=void 0),M.length===0&&(M=void 0),m.length===0&&(m=void 0);}let f=(()=>{let i=y.repo._parentKeys;return i&&i.length>0?i:void 0})();if(f&&m)for(let i of f)m.includes(i)||m.push(i);let S={name:A,path:y.path,repo:y.repo,schema:F,documentKey:y.documentKey??"docId",pathKey:y.repo._pathKey??void 0,isGroup:!!y.repo._isGroup,parentKeys:f,createdKey:y.repo._createdKey??void 0,listColumns:y.listColumns,pageSize:y.pageSize,filterableFields:z,mutableFields:M,createFields:m,allowDelete:y.allowDelete??false,historyEnabled:!!y.repo._historyConfig?.enabled,historySubcollection:(y.repo._historyConfig?.enabled&&y.repo._historySubcollection)??void 0,relationalMeta:(()=>{if(!y.relationalFields||y.relationalFields.length===0)return;let i=y.repo.relationalKeys??{},d=[];for(let u of y.relationalFields){let w=i[u.key];w&&d.push({key:u.key,column:u.column,targetRepo:String(w.repo),targetKey:String(w.key),type:w.type});}return d.length>0?d:void 0})()};p[A]=S;}let b=zt(p,l,st(c?.region)),g=new $e;if(a!==false&&g.use(jt(a===void 0?{}:a)),r&&g.use(async(A,y,F)=>{let z=A,M=String(z.headers?.["content-type"]??"");if(M.includes("application/x-www-form-urlencoded")){let m=await zn(z);A.body=Dn(m);}else if(M.includes("application/json")&&typeof z.body=="string")try{A.body=JSON.parse(z.body);}catch{}await F();}),o)if(Fe(o)){for(let A of o.routes){let y=`${l}${A.path}`;A.method==="GET"?g.get(y,A.handler):g.post(y,A.handler);}g.use(o.middleware);}else if(typeof o=="function")g.use(o);else {let A=o.realm??"Admin",y="Basic "+Buffer.from(`${o.username}:${o.password}`).toString("base64");g.use((F,z,M)=>{if((F.headers?.authorization??"")!==y){z.status(401).set("WWW-Authenticate",`Basic realm="${A}"`).set("Content-Type","text/plain").send("Unauthorized");return}M();});}for(let A of s)g.use(A);g.get(`${l}/`,b.handleDashboard),g.get(`${l}`,b.handleDashboard),g.get(`${l}/:repoName/_panel`,b.handlePanel),g.post(`${l}/:repoName/_bulk/delete`,b.handleBulkDelete),g.post(`${l}/:repoName/_bulk/update`,b.handleBulkUpdate),g.get(`${l}/:repoName`,b.handleList),g.get(`${l}/:repoName/create`,b.handleCreateForm),g.post(`${l}/:repoName/create`,b.handleCreateSubmit),g.get(`${l}/:repoName/:id/edit`,b.handleEditForm),g.post(`${l}/:repoName/:id/edit`,b.handleEditSubmit),g.get(`${l}/:repoName/:id/history`,b.handleHistory),g.post(`${l}/:repoName/:id/delete`,b.handleDelete);let k=async(A,y)=>{await g.handle(A,y);};return c&&(k.httpsOptions=c),k}
|
|
1064
1064
|
export{$e as MiniRouter,sa as createAdminServer};//# sourceMappingURL=index.js.map
|
|
1065
1065
|
//# sourceMappingURL=index.js.map
|