@shumai-one/shumai 0.2.2 → 0.3.0
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/bin/{chunk-e7ndw3hg.js → chunk-0p333kh7.js} +3 -3
- package/bin/chunk-1wz0dge4.js +3 -0
- package/bin/{chunk-gtrc5ka2.js → chunk-1yqar2gz.js} +1 -1
- package/bin/{chunk-fz88kkk1.js → chunk-1zpw2mbj.js} +2 -2
- package/bin/{chunk-46ar48f9.js → chunk-28egv700.js} +1 -1
- package/bin/{chunk-0xbf8bcg.js → chunk-2m2saan7.js} +2 -2
- package/bin/chunk-2p0rg6xs.js +1 -0
- package/bin/{chunk-w88219ex.js → chunk-2xmsa8wv.js} +1 -1
- package/bin/{chunk-mzg1h07d.js → chunk-36wf2dq0.js} +1 -1
- package/bin/{chunk-ta7bfdrn.js → chunk-3g54qkv5.js} +1 -1
- package/bin/chunk-3ge0s4k2.js +1 -0
- package/bin/{chunk-hr97a5j5.js → chunk-449feg7g.js} +1 -1
- package/bin/{chunk-hkbybhww.js → chunk-48ebezek.js} +1 -1
- package/bin/{chunk-8qg47kj6.js → chunk-4gbs9swm.js} +1 -1
- package/bin/{chunk-thsbcbay.js → chunk-4tt3jvm1.js} +1 -1
- package/bin/{chunk-15sefy5t.js → chunk-5jhrqbk2.js} +2 -2
- package/bin/{chunk-wg98cacx.js → chunk-5x1ppya9.js} +2 -2
- package/bin/{chunk-nrwna4ha.js → chunk-652x28v2.js} +1 -1
- package/bin/{chunk-0qkj838r.js → chunk-6f1twjf6.js} +1 -1
- package/bin/chunk-6ks4277t.js +2 -0
- package/bin/{chunk-0rxhc7ka.js → chunk-6wa075zh.js} +2 -2
- package/bin/{chunk-qksb0v3c.js → chunk-736tcjve.js} +2 -2
- package/bin/chunk-80d6p55n.js +1 -0
- package/bin/{chunk-gswbc6y9.js → chunk-8a9k4qj6.js} +2 -2
- package/bin/chunk-8g1s0pq1.js +2 -0
- package/bin/chunk-8gkm2ysh.js +1 -0
- package/bin/chunk-8nvybmyv.js +2 -0
- package/bin/{chunk-srn8t0v7.js → chunk-8rkp0fc5.js} +1 -1
- package/bin/{chunk-1wm57c6y.js → chunk-8sr8ff6a.js} +3 -3
- package/bin/{chunk-2aamsc5v.js → chunk-93jcw0pn.js} +1 -1
- package/bin/{chunk-3rmc8nz6.js → chunk-9bvwwj5y.js} +1 -1
- package/bin/{chunk-925q4paa.js → chunk-9fefn2st.js} +1 -1
- package/bin/{chunk-262hkppb.js → chunk-9h3c60vw.js} +2 -2
- package/bin/{chunk-xyjw8w3r.js → chunk-9jd3d3f3.js} +1 -1
- package/bin/chunk-9nwjhams.js +1 -0
- package/bin/{chunk-7b17fb36.js → chunk-9q32g9jd.js} +1 -1
- package/bin/{chunk-0aj303as.js → chunk-9zy0a8kt.js} +2 -2
- package/bin/{chunk-w7dn1m95.js → chunk-a06432s3.js} +1 -1
- package/bin/{chunk-de99643r.js → chunk-a1mtpcrd.js} +2 -2
- package/bin/{chunk-4e3jbp84.js → chunk-a2njf6av.js} +1 -1
- package/bin/{chunk-5d2q46mx.js → chunk-a6dvjjce.js} +1 -1
- package/bin/{chunk-s46zwr4p.js → chunk-aa2tkqg0.js} +1 -1
- package/bin/{chunk-fbte2rmd.js → chunk-ab45988z.js} +1 -1
- package/bin/chunk-af3nys0r.js +1 -0
- package/bin/{chunk-29tx9qe2.js → chunk-agd2jevj.js} +1 -1
- package/bin/{chunk-9h027f50.js → chunk-bf5a4yc8.js} +1 -1
- package/bin/{chunk-ybhgmvxa.js → chunk-bjfwz2m7.js} +2 -2
- package/bin/{chunk-e52nga6c.js → chunk-bnpw72vt.js} +2 -2
- package/bin/{chunk-c45rh4hk.js → chunk-c003q4v6.js} +1 -1
- package/bin/{chunk-5m9be8an.js → chunk-cfamv4b2.js} +2 -2
- package/bin/{chunk-922nnh39.js → chunk-cm25nm9t.js} +1 -1
- package/bin/{chunk-9h3ds7rn.js → chunk-cmcsxkh1.js} +2 -2
- package/bin/{chunk-zemrvz79.js → chunk-cspp4n1d.js} +2 -2
- package/bin/{chunk-kfhtk3eh.js → chunk-cwebycwv.js} +1 -1
- package/bin/chunk-cx1ebj9k.js +1 -0
- package/bin/chunk-d1p9qz3y.js +7 -0
- package/bin/{chunk-q24epdh8.js → chunk-d3cqp0tb.js} +2 -2
- package/bin/{chunk-97jzve52.js → chunk-d5fapvnp.js} +2 -2
- package/bin/{chunk-e3s3rz2e.js → chunk-ddag2ezv.js} +2 -2
- package/bin/{chunk-7hsgmjpa.js → chunk-dk45f6mp.js} +2 -2
- package/bin/{chunk-9ab6k4rq.js → chunk-e0kw3bst.js} +1 -1
- package/bin/{chunk-bd71dp4j.js → chunk-e56nza63.js} +1 -1
- package/bin/{chunk-re0b7sj7.js → chunk-e66j69wz.js} +1 -1
- package/bin/{chunk-pq18zenh.js → chunk-ea0fh29m.js} +1 -1
- package/bin/{chunk-s1n39qte.js → chunk-en4m76fw.js} +1 -1
- package/bin/{chunk-f14sqw1d.js → chunk-epsctccj.js} +1 -1
- package/bin/{chunk-92xxys10.js → chunk-evzxjqr3.js} +2 -2
- package/bin/{chunk-ymeycphq.js → chunk-f4x2dxe5.js} +3 -3
- package/bin/{chunk-pxw97qbq.js → chunk-fr3dg9aj.js} +1 -1
- package/bin/{chunk-fcvtgx1y.js → chunk-fvf7j1qj.js} +1 -1
- package/bin/{chunk-bs0fjz3w.js → chunk-fwcm78s9.js} +2 -2
- package/bin/{chunk-xcwbg4w9.js → chunk-fytbcgak.js} +2 -2
- package/bin/{chunk-wc8sc9r9.js → chunk-gc7b9j22.js} +1 -1
- package/bin/{chunk-b8js74jk.js → chunk-h1hj60fr.js} +2 -2
- package/bin/{chunk-9avkn3x1.js → chunk-h3y7szbm.js} +2 -2
- package/bin/{chunk-j8qtab70.js → chunk-hdqvbds8.js} +1 -1
- package/bin/{chunk-q09dfja5.js → chunk-he4h8e9e.js} +2 -2
- package/bin/{chunk-d2vxmn9v.js → chunk-hktggc90.js} +1 -1
- package/bin/{chunk-fepymbka.js → chunk-jh6pw37a.js} +1 -1
- package/bin/{chunk-ygz6pawn.js → chunk-jjgwrvdb.js} +1 -1
- package/bin/{chunk-2dsmsa6a.js → chunk-jmh934ca.js} +1 -1
- package/bin/{chunk-dghtwyq1.js → chunk-jtwvd0te.js} +2 -2
- package/bin/{chunk-4qpa7b5t.js → chunk-jxxq76at.js} +1 -1
- package/bin/chunk-jyr3g5m4.js +1 -0
- package/bin/{chunk-zzx99j8t.js → chunk-k0s6gfg6.js} +1 -1
- package/bin/chunk-ky3dx324.js +2 -0
- package/bin/{chunk-h0ytx8zc.js → chunk-mw0rc5m7.js} +1 -1
- package/bin/chunk-mzre12bp.js +1 -0
- package/bin/{chunk-s8t74q9m.js → chunk-n0cn0xfg.js} +1 -1
- package/bin/{chunk-88fg1sw7.js → chunk-nd6psyzq.js} +2 -2
- package/bin/{chunk-m4zpf9gg.js → chunk-nmzvxgd6.js} +2 -2
- package/bin/{chunk-891h8br6.js → chunk-nxhzchen.js} +1 -1
- package/bin/{chunk-8mkfgcvb.js → chunk-phc9efjf.js} +2 -2
- package/bin/{chunk-n4meg9wb.js → chunk-pna93n17.js} +1 -1
- package/bin/{chunk-d3wmdjze.js → chunk-pvx55h1v.js} +1 -1
- package/bin/{chunk-g8th86na.js → chunk-pzehf31g.js} +1 -1
- package/bin/{chunk-nyhqy6q2.js → chunk-q0dhm16d.js} +5 -5
- package/bin/chunk-q11m2cp3.js +2 -0
- package/bin/{chunk-31baz5n0.js → chunk-qjf561n2.js} +1 -1
- package/bin/chunk-qs5k9j8s.js +1 -0
- package/bin/{chunk-ztmj61z9.js → chunk-qt9efp9y.js} +1 -1
- package/bin/{chunk-1xpec5r8.js → chunk-qwxt1cha.js} +2 -2
- package/bin/{chunk-5t6c3038.js → chunk-r8vrfefa.js} +1 -1
- package/bin/{chunk-cxhmr356.js → chunk-rybbss5f.js} +1 -1
- package/bin/{chunk-t3t6021k.js → chunk-sa4gc1f5.js} +2 -2
- package/bin/{chunk-jf3vn5c3.js → chunk-sprpjp4t.js} +2 -2
- package/bin/chunk-swa43tzr.js +3 -0
- package/bin/{chunk-14fh4s1a.js → chunk-szs8dy1s.js} +2 -2
- package/bin/{chunk-ry33f2qk.js → chunk-t0detvbj.js} +2 -2
- package/bin/chunk-t0fq8b99.js +2 -0
- package/bin/{chunk-pmswtfe3.css → chunk-tm6z4hkd.css} +1 -1
- package/bin/{chunk-wsyg4rwg.js → chunk-vdn3jymh.js} +1 -1
- package/bin/{chunk-8wqfkm4c.js → chunk-vjxgv3r6.js} +1 -1
- package/bin/{chunk-dqgv5yy1.js → chunk-w3m9g3e9.js} +1 -1
- package/bin/{chunk-5r8858hx.js → chunk-wcfpdfgy.js} +2 -2
- package/bin/{chunk-rtngbgpk.js → chunk-wv8xk7n7.js} +1 -1
- package/bin/{chunk-7e06b2zb.js → chunk-wwsvnz4v.js} +1 -1
- package/bin/{chunk-qqk51620.js → chunk-y132jbf0.js} +1 -1
- package/bin/{chunk-2aascrtb.js → chunk-yaydmgcg.js} +1 -1
- package/bin/{chunk-7we7ex0m.js → chunk-yvgs4kmv.js} +1 -1
- package/bin/{chunk-fa2g2wge.js → chunk-z5p39kpk.js} +2 -2
- package/bin/{chunk-77r8w95d.js → chunk-zct68gc7.js} +2 -2
- package/bin/{chunk-mqjzmn0e.js → chunk-zy2sqtt9.js} +1 -1
- package/bin/shumai-app.html +1 -1
- package/bin/shumai-app.js +260 -208
- package/package.json +7 -7
- package/prisma/migrations/20260728024147_add_agent_session_entry_columns/migration.sql +14 -0
- package/prisma/migrations/20260728024205_migrate_agent_session_entry_data/migration.sql +12 -0
- package/prisma/migrations/20260728031230_remove_agent_session_entry_legacy_entry_column/migration.sql +8 -0
- package/prisma/schema.prisma +12 -6
- package/bin/chunk-23d3968z.js +0 -2
- package/bin/chunk-2g12s6mc.js +0 -2
- package/bin/chunk-4jk0y1w1.js +0 -1
- package/bin/chunk-54tr7y2x.js +0 -3
- package/bin/chunk-6z65xd0w.js +0 -3
- package/bin/chunk-8tf6kgdj.js +0 -2
- package/bin/chunk-av71yjaa.js +0 -1
- package/bin/chunk-byqc8tzq.js +0 -1
- package/bin/chunk-ccw7mjgq.js +0 -5
- package/bin/chunk-f7sbkfmk.js +0 -2
- package/bin/chunk-fd5a3pdd.js +0 -1
- package/bin/chunk-g6zzg6v2.js +0 -1
- package/bin/chunk-kr06nrbx.js +0 -2
- package/bin/chunk-r0w920zb.js +0 -1
- package/bin/chunk-sd86v1e6.js +0 -1
- package/bin/chunk-szzff7gd.js +0 -1
- package/bin/chunk-tspps87j.js +0 -1
- package/bin/chunk-y2qp11v9.js +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
async function q(j){if(typeof navigator<"u"&&navigator.clipboard&&typeof navigator.clipboard.writeText==="function")try{return await navigator.clipboard.writeText(j),!0}catch{}try{let h=document.createElement("textarea");h.value=j,h.style.position="fixed",h.style.top="0",h.style.left="0",h.style.width="2em",h.style.height="2em",h.style.padding="0",h.style.border="none",h.style.outline="none",h.style.boxShadow="none",h.style.background="transparent",h.style.opacity="0",document.body.appendChild(h),h.focus(),h.select();let p=document.execCommand("copy");return document.body.removeChild(h),p}catch(h){return console.error("Failed to copy text to clipboard:",h),!1}}
|
|
2
|
+
export{q as Za};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{Sb as V}from"./chunk-nxhzchen.js";import{Tb as M,Ub as k}from"./chunk-yvgs4kmv.js";import{Vb as b,Wb as H,Xb as E}from"./chunk-ddag2ezv.js";import"./chunk-hdqvbds8.js";import{Zb as _}from"./chunk-en4m76fw.js";import{_b as f}from"./chunk-h3y7szbm.js";import{fc as C,gc as N}from"./chunk-2xmsa8wv.js";import{ic as A}from"./chunk-jmh934ca.js";import"./chunk-bf5a4yc8.js";import{mc as U}from"./chunk-fr3dg9aj.js";import"./chunk-cspp4n1d.js";import{bf as L}from"./chunk-he4h8e9e.js";import{cf as B}from"./chunk-hktggc90.js";import{yk as q}from"./chunk-e0kw3bst.js";import"./chunk-fwcm78s9.js";import"./chunk-6f1twjf6.js";var I=new Set(["openai","openai-codex","opencode"]),v=16;function $(j,D){if(!j)return!1;let w=D.toLowerCase();for(let[F,z]of Object.entries(j))if(F.toLowerCase()===w&&z!==null&&z.trim().length>0)return!0;return!1}function S(j,D,w){if(D)return D;if($(w,"authorization")||$(w,"cf-aig-authorization"))return"unused";throw Error(`No API key for provider: ${j}`)}function x(j){return j.provider==="openrouter"||j.baseUrl.includes("openrouter.ai")?"openrouter":"openai"}function O(j,D){if(j)return j;if(f("PI_CACHE_RETENTION",D)==="long")return"long";return"short"}function y(j){return{supportsDeveloperRole:j.compat?.supportsDeveloperRole??!0,sessionAffinityFormat:j.compat?.sessionAffinityFormat??x(j),supportsLongCacheRetention:j.compat?.supportsLongCacheRetention??!0,supportsToolSearch:j.compat?.supportsToolSearch??!1}}function h(j,D){return D==="long"&&j.supportsLongCacheRetention?"24h":void 0}function g(j){return N(C(j),"OpenAI API error")}var u=(j,D,w)=>{let F=new B;return(async()=>{let z={role:"assistant",content:[],api:j.api,provider:j.provider,model:j.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"stop",timestamp:Date.now()};try{let Q=S(j.provider,w?.apiKey,w?.headers),J=O(w?.cacheRetention,w?.env)==="none"?void 0:w?.sessionId,W=c(j,D,Q,w?.headers,J),X=r(j,D,w),Y=await w?.onPayload?.(X,j);if(Y!==void 0)X=Y;let K={...w?.signal?{signal:w.signal}:{},...w?.timeoutMs!==void 0?{timeout:w.timeoutMs}:{},maxRetries:w?.maxRetries??0},{data:P,response:Z}=await W.responses.create(X,K).withResponse();if(await w?.onResponse?.({status:Z.status,headers:U(Z.headers)},j),F.push({type:"start",partial:z}),await E(P,z,F,j,{serviceTier:w?.serviceTier,applyServiceTierPricing:(T,R)=>d(T,R,j)}),w?.signal?.aborted)throw Error("Request was aborted");if(z.stopReason==="aborted"||z.stopReason==="error")throw Error("An unknown error occurred");F.push({type:"done",reason:z.stopReason,message:z}),F.end()}catch(Q){for(let G of z.content)delete G.index,delete G.partialJson;z.stopReason=w?.signal?.aborted?"aborted":"error",z.errorMessage=g(Q),F.push({type:"error",reason:z.stopReason,error:z}),F.end()}})(),F},zj=(j,D,w)=>{S(j.provider,w?.apiKey,w?.headers);let F=A(j,D,w,w?.apiKey),z=w?.reasoning?L(j,w.reasoning):void 0;return u(j,D,{...F,reasoningEffort:z==="off"?void 0:z})};function c(j,D,w,F,z){let Q=y(j),G={...j.headers};if(j.provider==="github-copilot"){let J=M(D.messages),W=k({messages:D.messages,hasImages:J});Object.assign(G,W)}if(z)if(Q.sessionAffinityFormat==="openrouter")G["x-session-id"]=z;else{if(Q.sessionAffinityFormat==="openai")G.session_id=z;G["x-client-request-id"]=z}if(F)Object.assign(G,F);return new q({apiKey:w,baseURL:j.baseUrl,dangerouslyAllowBrowser:!0,defaultHeaders:G})}function r(j,D,w){let F=y(j),z=V(D,F.supportsToolSearch),Q=b(j,D,I,{deferredTools:z.deferred}),G=O(w?.cacheRetention,w?.env),J={model:j.id,input:Q,stream:!0,prompt_cache_key:G==="none"?void 0:_(w?.sessionId),prompt_cache_retention:h(F,G),store:!1};if(w?.maxTokens)J.max_output_tokens=Math.max(w.maxTokens,v);if(w?.temperature!==void 0)J.temperature=w?.temperature;if(w?.serviceTier!==void 0)J.service_tier=w.serviceTier;if(z.immediate.length>0)J.tools=H(z.immediate);if(w?.toolChoice!==void 0)J.tool_choice=w.toolChoice;if(j.reasoning){if(w?.reasoningEffort||w?.reasoningSummary){let W=w?.reasoningEffort?j.thinkingLevelMap?.[w.reasoningEffort]??w.reasoningEffort:"medium";J.reasoning={effort:W,summary:w?.reasoningSummary||"auto"},J.include=["reasoning.encrypted_content"]}else if(j.provider!=="github-copilot"&&j.thinkingLevelMap?.off!==null)J.reasoning={effort:j.thinkingLevelMap?.off??"none"}}return J}function l(j,D){switch(D){case"flex":return 0.5;case"priority":return j.id==="gpt-5.5"?2.5:2;default:return 1}}function d(j,D,w){let F=l(w,D);if(F===1)return;j.cost.input*=F,j.cost.output*=F,j.cost.cacheRead*=F,j.cost.cacheWrite*=F,j.cost.total=j.cost.input+j.cost.output+j.cost.cacheRead+j.cost.cacheWrite}export{zj as streamSimple,u as stream};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{g as v}from"./chunk-y132jbf0.js";import"./chunk-mw0rc5m7.js";import"./chunk-9jd3d3f3.js";import"./chunk-d1p9qz3y.js";import"./chunk-ea0fh29m.js";import"./chunk-vdn3jymh.js";import"./chunk-wwsvnz4v.js";import"./chunk-8rkp0fc5.js";import"./chunk-cwebycwv.js";import"./chunk-ky3dx324.js";import"./chunk-q11m2cp3.js";import"./chunk-h1hj60fr.js";import"./chunk-2m2saan7.js";import"./chunk-5x1ppya9.js";import"./chunk-5jhrqbk2.js";import"./chunk-zct68gc7.js";import"./chunk-sa4gc1f5.js";import"./chunk-swa43tzr.js";import"./chunk-qwxt1cha.js";import"./chunk-6wa075zh.js";import"./chunk-z5p39kpk.js";import"./chunk-1zpw2mbj.js";import"./chunk-jtwvd0te.js";import"./chunk-8a9k4qj6.js";import{Hh as q,ph as k}from"./chunk-q0dhm16d.js";import"./chunk-6f1twjf6.js";function B(){let{shareId:w,folderId:A}=C.useParams();return k(v,{shareId:w,initialFolderId:A})}var C=q("/share/$shareId/folders/$folderId")({component:B});export{C as Route};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
var q=new Set;function F(b){return q.add(b),()=>{q.delete(b)}}function A(b){if(b instanceof Error)return b.message||b.name;if(typeof b==="string")return b;return String(b)}function B(b){if(!(b instanceof Error))return{name:"ThrownValue",message:A(b)};let k=b.code;return{name:b.name||void 0,message:b.message||b.name,stack:b.stack,code:typeof k==="string"||typeof k==="number"?k:void 0}}function H(b,k,z){return{type:b,timestamp:Date.now(),error:B(k),details:z}}function J(b,k){b.diagnostics=[...b.diagnostics??[],k]}
|
|
3
|
-
export{F as
|
|
3
|
+
export{F as Te,A as Ue,H as Ve,J as We};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
export{f as
|
|
1
|
+
import{Rj as t,Sj as a,hk as o,ph as r}from"./chunk-q0dhm16d.js";var c=t("inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3",{variants:{variant:{default:"bg-primary text-primary-foreground [a&]:hover:bg-primary/90",secondary:"bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",destructive:"bg-destructive text-white focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40 [a&]:hover:bg-destructive/90",outline:"border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",ghost:"[a&]:hover:bg-accent [a&]:hover:text-accent-foreground",link:"text-primary underline-offset-4 [a&]:hover:underline"}},defaultVariants:{variant:"default"}});function f({className:i,variant:e="default",asChild:n=!1,...s}){let d=n?a.Root:"span";return r(d,{"data-slot":"badge","data-variant":e,className:o(c({variant:e}),i),...s})}
|
|
2
|
+
export{f as kg};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{ud as Z,vd as v}from"./chunk-cmcsxkh1.js";import{ge as $,he as h}from"./chunk-pna93n17.js";import"./chunk-6f1twjf6.js";var F=class extends v{},G=class{#j;#z;constructor(j){this.#j={...j}}async init(){if(this.#z=new M(this.#j.database),this.#j.onCreateConnection)await this.#j.onCreateConnection(this.#z)}async acquireConnection(){return this.#z}async beginTransaction(){throw Error("D1 does not support interactive transactions. Use the D1 batch() API instead.")}async commitTransaction(){throw Error("D1 does not support interactive transactions. Use the D1 batch() API instead.")}async rollbackTransaction(){throw Error("D1 does not support interactive transactions. Use the D1 batch() API instead.")}async releaseConnection(){}async destroy(){}},M=class{#j;constructor(j){this.#j=j}async executeQuery(j){let z=await this.#j.prepare(j.sql).bind(...j.parameters).all(),J=z.meta.changes!=null?BigInt(z.meta.changes):void 0;return{insertId:z.meta.last_row_id===void 0||z.meta.last_row_id===null?void 0:BigInt(z.meta.last_row_id),rows:z?.results||[],numAffectedRows:J}}async*streamQuery(){throw Error("D1 does not support streaming queries.")}},N=class{#j;#z;constructor(j,z){this.#j=j,this.#z=z}async getSchemas(){return[]}async getTables(j={withInternalKyselyTables:!1}){let z=this.#j.selectFrom("sqlite_master").where("type","in",["table","view"]).where("name","not like","sqlite_%").where("name","not like","_cf_%").select(["name","type","sql"]).$castTo();if(!j.withInternalKyselyTables)z=z.where("name","!=",$).where("name","!=",h);let J=await z.execute();if(J.length===0)return[];let w=J.map((V)=>this.#z.prepare("SELECT * FROM pragma_table_info(?)").bind(V.name)),K=await this.#z.batch(w);return J.map((V,x)=>{let Y=K[x]?.results??[],W=V.sql?.split(/[(),]/)?.find((H)=>H.toLowerCase().includes("autoincrement"))?.split(/\s+/)?.filter(Boolean)?.[0]?.replace(/["`]/g,"");if(!W){let H=Y.filter((B)=>B.pk>0),X=H.length===1?H[0]:void 0;if(X&&X.type.toLowerCase()==="integer")W=X.name}return{name:V.name,isView:V.type==="view",columns:Y.map((H)=>({name:H.name,dataType:H.type,isNullable:!H.notnull,isAutoIncrementing:H.name===W,hasDefaultValue:H.dflt_value!=null}))}})}async getMetadata(j){return{tables:await this.getTables(j)}}},U=class extends Z{},P=class{#j;constructor(j){this.#j={...j}}createDriver(){return new G(this.#j)}createQueryCompiler(){return new U}createAdapter(){return new F}createIntrospector(j){return new N(j,this.#j.database)}};export{P as D1SqliteDialect};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
export{S as
|
|
1
|
+
import{Mh as Z,nh as W,ph as b,qh as Y}from"./chunk-q0dhm16d.js";import{Wk as R}from"./chunk-6f1twjf6.js";var r=Z((u)=>({uploading:0,tasks:{},fileProgress:{},increment:()=>u((d)=>({uploading:d.uploading+1})),decrement:()=>u((d)=>({uploading:d.uploading-1})),startTask:(d,k,F)=>u((o)=>{let l={},s=0;F.forEach((f)=>{l[f.fileId]={fileId:f.fileId,name:f.name,loaded:0,total:f.size,status:"uploading"},s+=f.size});let g={...o.tasks,[d]:{taskId:d,name:k,loaded:0,total:s,files:l}},P={...o.fileProgress};return F.forEach((f)=>{P[f.fileId]=l[f.fileId]}),{tasks:g,fileProgress:P}}),updateFileProgress:(d,k,F)=>u((o)=>{let l=o.tasks[d];if(!l)return{};let s=l.files[k];if(!s)return{};let g={...s,loaded:F},P={...l.files,[k]:g},f=Object.values(P).reduce((p,w)=>p+w.loaded,0);return{tasks:{...o.tasks,[d]:{...l,loaded:f,files:P}},fileProgress:{...o.fileProgress,[k]:g}}}),completeFile:(d,k)=>u((F)=>{let o=F.tasks[d];if(!o)return{};let l=o.files[k];if(!l)return{};let s={...l,status:"completed",loaded:l.total},g={...o.files,[k]:s},P=Object.values(g).reduce((f,p)=>f+p.loaded,0);return{tasks:{...F.tasks,[d]:{...o,loaded:P,files:g}},fileProgress:{...F.fileProgress,[k]:s}}}),failFile:(d,k)=>u((F)=>{let o=F.tasks[d];if(!o)return{};let l=o.files[k];if(!l)return{};let s={...l,status:"failed"},g={...o.files,[k]:s},P=Object.values(g).reduce((f,p)=>f+p.loaded,0);return{tasks:{...F.tasks,[d]:{...o,loaded:P,files:g}},fileProgress:{...F.fileProgress,[k]:s}}})}));var a=R(W(),1);var q=10,Q=10,$=q*Q,S=({spriteUrl:u,thumbnailUrl:d,videoWidth:k,videoHeight:F,className:o=""})=>{let l=a.useRef(null),[s,g]=a.useState({width:0,height:0}),[P,f]=a.useState({width:0,height:0}),[p,w]=a.useState(!1),[c,E]=a.useState(!1),[V,J]=a.useState(!1),[K,N]=a.useState(0),[j,n]=a.useState(0);a.useEffect(()=>{if(!l.current)return;let t=new ResizeObserver((m)=>{for(let B of m)g({width:B.contentRect.width,height:B.contentRect.height})});return t.observe(l.current),()=>t.disconnect()},[]);let X=a.useCallback(()=>{if(c||V)return;J(!0);let t=new Image;t.src=u,t.onload=()=>{f({width:t.naturalWidth,height:t.naturalHeight}),E(!0),J(!1)},t.onerror=()=>{console.error("Failed to load sprite image"),J(!1)}},[u,c,V]),M=()=>{w(!0),X()},A=()=>{w(!1)},D=(t)=>{if(!l.current)return;let m=l.current.getBoundingClientRect(),B=t.clientX-m.left,y=Math.max(0,Math.min(B,m.width));n(y);let T=y/m.width,U=Math.min(Math.floor(T*$),$-1);N(U)},G=a.useMemo(()=>{if(s.width===0||s.height===0)return{};let t=k/F;if(P.width>0&&P.height>0){let z=P.width/q,i=P.height/Q;t=z/i}let m=s.width/s.height,B,y;if(m>t)y=s.height,B=y*t;else B=s.width,y=B/t;let T=Math.ceil(B),U=Math.ceil(y),I=T*q,O=U*Q,v=K%q,x=Math.floor(K/q),C=-(v*T),_=-(x*U);return{backgroundImage:`url(${u})`,backgroundSize:`${I}px ${O}px`,backgroundPosition:`${C}px ${_}px`,backgroundRepeat:"no-repeat",width:`${T}px`,height:`${U}px`,imageRendering:"auto"}},[s,k,F,K,u,P]);return Y("div",{ref:l,className:`relative w-full h-full overflow-hidden cursor-crosshair group bg-black select-none ${o}`,onMouseEnter:M,onMouseLeave:A,onMouseMove:D,children:[b("img",{src:d,alt:"Thumbnail",className:`absolute inset-0 w-full h-full object-contain transition-opacity duration-200 ${p&&c?"opacity-0":"opacity-100"}`,draggable:!1}),p&&!c&&b("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 z-10",children:b("div",{className:"w-6 h-6 border-2 border-white/30 border-t-white rounded-full animate-spin"})}),c&&b("div",{className:`absolute inset-0 flex items-center justify-center transition-opacity duration-75 ${p?"opacity-100":"opacity-0"}`,children:b("div",{style:G})}),p&&b("div",{className:"absolute top-0 bottom-0 w-0.5 bg-red-500 shadow-[0_0_4px_rgba(255,0,0,0.8)] z-20 pointer-events-none",style:{transform:`translateX(${j}px)`}})]})};
|
|
2
|
+
export{S as fg,r as gg};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
export{B as
|
|
1
|
+
import{Af as A}from"./chunk-t0detvbj.js";import{Gh as w,Th as z,ph as v}from"./chunk-q0dhm16d.js";var B=(b)=>({queryKey:["projects",b],queryFn:async()=>{let h=await z.api.projects[":projectId"].$get({param:{projectId:b}});if(!h.ok)throw Error("Failed to fetch project");return await h.json()}}),H=w("/projects/$projectId/folders/$folderId")({loader:({context:{queryClient:b},params:{projectId:h}})=>b.ensureQueryData(B(h)),pendingComponent:()=>v(A,{})});
|
|
2
|
+
export{B as df,H as ef};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{Lh as O,Mh as R,Rh as $,Th as D,nh as x,uh as v}from"./chunk-q0dhm16d.js";import{Wk as b}from"./chunk-6f1twjf6.js";var E=null,I=R((p)=>({projectState:null,setProjectState:(c)=>{if(E)clearTimeout(E),E=null;p({projectState:c})},clearProjectState:()=>{if(E)clearTimeout(E);E=setTimeout(()=>{p({projectState:null}),E=null},10)}}));var H=R((p)=>({isChatbotOpen:!1,setIsChatbotOpen:(c)=>p({isChatbotOpen:c}),isHistoryMode:!1,setIsHistoryMode:(c)=>p({isHistoryMode:c}),currentSessionId:null,setCurrentSessionId:(c)=>p({currentSessionId:c}),chatAssets:[],addAssets:(c)=>p((j)=>{let f=new Set(j.chatAssets.map((T)=>T.id)),F=c.filter((T)=>!f.has(T.id));return{chatAssets:[...j.chatAssets,...F]}}),removeAsset:(c)=>p((j)=>({chatAssets:j.chatAssets.filter((f)=>f.id!==c)})),clearAssets:()=>p({chatAssets:[]}),messages:[],setMessages:(c)=>p({messages:c}),historySessions:[],setHistorySessions:(c)=>p({historySessions:c}),isStreaming:!1,setIsStreaming:(c)=>p({isStreaming:c}),selectedAgentId:null,setSelectedAgentId:(c)=>p({selectedAgentId:c}),scrollTop:0,isAtBottom:!0,setScrollState:(c,j)=>p({scrollTop:c,isAtBottom:j}),fetchHistorySessions:async(c)=>{try{let j=await D.api.teams[":teamId"].chat.sessions.$get({param:{teamId:c},query:{first:"50"}});if(j.ok){let f=await j.json();p({historySessions:f.data||[]})}}catch(j){console.error("Failed to fetch history sessions:",j)}},loadSession:async(c,j)=>{try{let f=await D.api.teams[":teamId"].chat.sessions[":sessionId"].messages.$get({param:{teamId:c,sessionId:j}});if(f.ok){let F=await f.json(),P=H.getState().historySessions.find((J)=>J.id===j)?.agentId||null;p({currentSessionId:j,messages:F,isHistoryMode:!1,scrollTop:0,isAtBottom:!0,...P?{selectedAgentId:P}:{}})}else throw Error("Failed to load session messages")}catch(f){let F=f instanceof Error?f.message:"Failed to load session";$.error(F)}},deleteSession:async(c,j)=>{try{if((await D.api.teams[":teamId"].chat.sessions[":sessionId"].$delete({param:{teamId:c,sessionId:j}})).ok)$.success("Session deleted successfully"),p((F)=>({historySessions:F.historySessions.filter((T)=>T.id!==j),currentSessionId:F.currentSessionId===j?null:F.currentSessionId,messages:F.currentSessionId===j?[]:F.messages}));else throw Error("Failed to delete session")}catch(f){let F=f instanceof Error?f.message:"Failed to delete session";$.error(F)}},startNewSession:()=>{p({currentSessionId:null,messages:[],chatAssets:[],scrollTop:0,isAtBottom:!0})},sendMessage:async(c,j,f,F,T)=>{let P=H.getState();if(P.isStreaming)return;let J=`temp-${Date.now()}`,C={id:J,role:"user",content:[{type:"text",text:j}],timestamp:Date.now()},V=[...P.messages];if(P.chatAssets.length>0){let G={id:`temp-context-${Date.now()}`,role:"custom",customType:"context_display_info",details:{assets:P.chatAssets.map((k)=>({id:k.id,name:k.name,type:k.type}))},timestamp:Date.now()-1};V.push(G)}V.push(C),p({messages:V,isStreaming:!0,chatAssets:[],isAtBottom:!0});let A=P.chatAssets.map((K)=>K.id),_=P.selectedAgentId;if(!_){$.error("No agent selected");return}try{let K=await D.api.teams[":teamId"].chat.$post({param:{teamId:c},json:{agentId:_,textPrompt:j,assetIds:A,sessionId:P.currentSessionId||void 0,contextAssetId:F,projectId:f}});if(!K.ok)throw Error("Failed to start chat");let G=K.headers.get("x-session-id");if(G&&!P.currentSessionId)p({currentSessionId:G});let k=K.body?.getReader();if(!k)throw Error("No stream body");let W=new TextDecoder,X="";while(!0){let{done:M,value:S}=await k.read();if(M)break;X+=W.decode(S,{stream:!0});let h=X.split(`
|
|
2
|
+
`);X=h.pop()||"";for(let u of h){let Y=u.trim();if(!Y)continue;if(Y.startsWith("data: ")){let y=Y.slice(6);try{let Q=JSON.parse(y);if(Q.type==="session"){if(!H.getState().currentSessionId)p({currentSessionId:Q.sessionId})}else if(Q.type==="entry"){let w=Q.entry,L=w;if(L.role==="toolResult"&&typeof L.toolName==="string"&&["create_file","create_folder","create_version"].includes(L.toolName)&&!L.isError)T?.();p((N)=>{let z=N.messages.some((q)=>q.id===w.id),Z=N.messages.filter((q)=>{if(w.role==="user"&&!z)return!(q.id.startsWith("temp-")&&!q.id.startsWith("temp-context-"));if(w.role==="custom"&&w.customType==="context_display_info"&&!z)return!q.id.startsWith("temp-context-");return!0}),B=Z.findIndex((q)=>q.id===w.id);if(B!==-1){let q=[...Z];return q[B]=w,{messages:q}}else return{messages:[...Z,w]}})}else if(Q.type==="done"){if(Q.status==="failed")$.error(Q.error||"Workflow failed")}}catch(Q){console.error("Error parsing SSE line:",Q)}}}}H.getState().fetchHistorySessions(c)}catch(K){let G=K instanceof Error?K.message:"Failed to send message";$.error(G),p((k)=>({messages:k.messages.filter((W)=>W.id!==J)}))}finally{p({isStreaming:!1})}},abortActiveSession:async(c)=>{let{currentSessionId:j,isStreaming:f}=H.getState();if(!j||!f)return;try{if((await D.api.teams[":teamId"].chat.sessions[":sessionId"].abort.$post({param:{teamId:c,sessionId:j}})).ok)$.success("Agent execution stopped");else throw Error("Failed to abort agent execution")}catch(F){let T=F instanceof Error?F.message:"Failed to abort execution";$.error(T)}}}));var U=b(x(),1);function l(p){let c=p.match(/teams\/([^/]+)/);if(c)return{teamId:c[1]};let j=p.match(/projects\/([^/]+)/);if(j)return{projectId:j[1]};return{}}function s(){let[p,c]=U.useState(),j=O({select:(P)=>P.location.pathname}),{teamId:f,projectId:F}=l(j),{data:T}=v({queryKey:["projects",F,"team"],queryFn:async()=>{let P=await D.api.projects[":projectId"].team.$get({param:{projectId:F}});if(!P.ok)throw Error("failed to fetch project team");return await P.json()},enabled:!!F});return U.useEffect(()=>{if(f)c(f);else if(T?.teamId)c(T.teamId)},[f,T]),p}
|
|
3
|
+
export{s as hg,I as ig,H as jg};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{$d as Mk,Bd as GW,Dd as _,Ed as kk,Fd as h,Gd as dk,Hd as j,Jd as J,Nd as I,Od as zk,Pd as x,Qd as hk,Rd as Kk,Sd as pW,Td as y,Ud as dW,Vd as v,Wd as fk,Xd as Xk,Yd as w,Zd as sW,_d as TW,be as YW,ce as Ch,vd as c,wd as V,xd as _k,yd as ek,zd as kW}from"./chunk-n4meg9wb.js";function z(k){return kk(k)&&_(k.toOperationNode)}var Q=h({is(k){return k.kind==="ValueNode"},create(k){return h({kind:"ValueNode",value:k})},createImmediate(k){return h({kind:"ValueNode",value:k,immediate:!0})}});var S=h({is(k){return k.kind==="ColumnNode"},create(k){return h({kind:"ColumnNode",column:J.create(k)})}});var pk=h({is(k){return k.kind==="SelectAllNode"},create(){return h({kind:"SelectAllNode"})}});var Ak=h({is(k){return k.kind==="ReferenceNode"},create(k,W){return h({kind:"ReferenceNode",table:W,column:k})},createSelectAll(k){return h({kind:"ReferenceNode",table:k,column:pk.create()})}});function ok(k){return kk(k)&&"expressionType"in k&&z(k)}function iW(k){return kk(k)&&"expression"in k&&V(k.alias)&&z(k)}var a=h({is(k){return k.kind==="SelectModifierNode"},create(k,W){return h({kind:"SelectModifierNode",modifier:k,of:W})},createWithExpression(k){return h({kind:"SelectModifierNode",rawModifier:k})}});var Yk=h({is(k){return k.kind==="BinaryOperationNode"},create(k,W,$){return h({kind:"BinaryOperationNode",leftOperand:k,operator:W,rightOperand:$})}});var sk=h({is(k){return k.kind==="PrimitiveValueListNode"},create(k){return h({kind:"PrimitiveValueListNode",values:h([...k])})}});var rk=h({is(k){return k.kind==="ValueListNode"},create(k){return h({kind:"ValueListNode",values:h(k)})}});function lW(k){if(j(k))return ih(k);return X(k)}function X(k){if(Wk(k))return p(k);return Q.create(k)}function WW(k){return _k(k)||ek(k)||kW(k)}function Bk(k){if(!WW(k))throw Error(`unsafe immediate value ${JSON.stringify(k)}`);return Q.createImmediate(k)}function ih(k){if(k.some(Wk))return rk.create(k.map((W)=>X(W)));return sk.create(k)}function L(k){if(k.length===3)return hW(k[0],k[1],k[2]);else if(k.length===1)return X(k[0]);throw Error(`invalid arguments: ${JSON.stringify(k)}`)}function hW(k,W,$){if(lh(W)&&oW($))return Yk.create(f(k),PW(W),Q.createImmediate($));return Yk.create(f(k),PW(W),lW($))}function m(k,W,$){return Yk.create(f(k),PW(W),f($))}function UW(k,W){return mk(Object.entries(k).filter(([,$])=>!c($)).map(([$,M])=>hW($,oW(M)?"is":"=",M)),W)}function mk(k,W,$=!0){let M=W==="and"?x.create:hk.create;if(k.length===0)return Yk.create(Q.createImmediate(1),y.create("="),Q.createImmediate(W==="and"?1:0));let G=aW(k[0]);for(let q=1;q<k.length;++q)G=M(G,aW(k[q]));if(k.length>1&&$)return Xk.create(G);return G}function lh(k){return k==="is"||k==="is not"}function oW(k){return kW(k)||ek(k)}function PW(k){if(V(k)&&pW.includes(k))return y.create(k);if(z(k))return k.toOperationNode();throw Error(`invalid operator ${JSON.stringify(k)}`)}function aW(k){return z(k)?k.toOperationNode():k}var $k=h({is(k){return k.kind==="OrderByNode"},create(k){return h({kind:"OrderByNode",items:h([...k])})},cloneWithItems(k,W){return h({...k,items:h([...k.items,...W])})}});var VW=h({is(k){return k.kind==="PartitionByNode"},create(k){return h({kind:"PartitionByNode",items:h(k)})},cloneWithItems(k,W){return h({...k,items:h([...k.items,...W])})}});var xk=h({is(k){return k.kind==="OverNode"},create(){return h({kind:"OverNode"})},cloneWithOrderByItems(k,W){return h({...k,orderBy:k.orderBy?$k.cloneWithItems(k.orderBy,W):$k.create(W)})},cloneWithPartitionByItems(k,W){return h({...k,partitionBy:k.partitionBy?VW.cloneWithItems(k.partitionBy,W):VW.create(W)})}});var Vk=h({is(k){return k.kind==="FromNode"},create(k){return h({kind:"FromNode",froms:h(k)})},cloneWithFroms(k,W){return h({...k,froms:h([...k.froms,...W])})}});var wW=h({is(k){return k.kind==="GroupByNode"},create(k){return h({kind:"GroupByNode",items:h(k)})},cloneWithItems(k,W){return h({...k,items:h([...k.items,...W])})}});var FW=h({is(k){return k.kind==="HavingNode"},create(k){return h({kind:"HavingNode",having:k})},cloneWithOperation(k,W,$){return h({...k,having:W==="And"?x.create(k.having,$):hk.create(k.having,$)})}});var o=h({is(k){return k.kind==="UpdateQueryNode"},create(k,W){return h({kind:"UpdateQueryNode",table:k.length===1?k[0]:sW.create(k),...W&&{with:W}})},createWithoutTable(){return h({kind:"UpdateQueryNode"})},cloneWithFromItems(k,W){return h({...k,from:k.from?Vk.cloneWithFroms(k.from,W):Vk.create(W)})},cloneWithUpdates(k,W){return h({...k,updates:k.updates?h([...k.updates,...W]):W})},cloneWithLimit(k,W){return h({...k,limit:W})}});var Dk=h({is(k){return k.kind==="DeleteQueryNode"},create(k,W){return h({kind:"DeleteQueryNode",from:Vk.create(k),...W&&{with:W}})},cloneWithOrderByItems:(k,W)=>K.cloneWithOrderByItems(k,W),cloneWithoutOrderBy:(k)=>K.cloneWithoutOrderBy(k),cloneWithLimit(k,W){return h({...k,limit:W})},cloneWithoutLimit(k){return h({...k,limit:void 0})},cloneWithUsing(k,W){return h({...k,using:k.using!==void 0?TW.cloneWithTables(k.using,W):TW.create(W)})}});var C=h({is(k){return k.kind==="WhereNode"},create(k){return h({kind:"WhereNode",where:k})},cloneWithOperation(k,W,$){return h({...k,where:W==="And"?x.create(k.where,$):hk.create(k.where,$)})}});var vW=h({is(k){return k.kind==="ReturningNode"},create(k){return h({kind:"ReturningNode",selections:h(k)})},cloneWithSelections(k,W){return h({...k,selections:k.selections?h([...k.selections,...W]):h(W)})}});var rW=h({is(k){return k.kind==="ExplainNode"},create(k,W){return h({kind:"ExplainNode",format:k,options:W})}});var N=h({is(k){return k.kind==="MergeQueryNode"},create(k,W){return h({kind:"MergeQueryNode",into:k,...W&&{with:W}})},cloneWithUsing(k,W){return h({...k,using:W})},cloneWithWhen(k,W){return h({...k,whens:k.whens?h([...k.whens,W]):h([W])})},cloneWithThen(k,W){return h({...k,whens:k.whens?h([...k.whens.slice(0,-1),Mk.cloneWithResult(k.whens[k.whens.length-1],W)]):void 0})}});var AW=h({is(k){return k.kind==="OutputNode"},create(k){return h({kind:"OutputNode",selections:h(k)})},cloneWithSelections(k,W){return h({...k,selections:k.selections?h([...k.selections,...W]):h(W)})}});var K=h({is(k){return Y.is(k)||w.is(k)||o.is(k)||Dk.is(k)||N.is(k)},cloneWithEndModifier(k,W){return h({...k,endModifiers:k.endModifiers?h([...k.endModifiers,W]):h([W])})},cloneWithWhere(k,W){return h({...k,where:k.where?C.cloneWithOperation(k.where,"And",W):C.create(W)})},cloneWithJoin(k,W){return h({...k,joins:k.joins?h([...k.joins,W]):h([W])})},cloneWithReturning(k,W){return h({...k,returning:k.returning?vW.cloneWithSelections(k.returning,W):vW.create(W)})},cloneWithoutReturning(k){return h({...k,returning:void 0})},cloneWithoutWhere(k){return h({...k,where:void 0})},cloneWithExplain(k,W,$){return h({...k,explain:rW.create(W,$?.toOperationNode())})},cloneWithTop(k,W){return h({...k,top:W})},cloneWithOutput(k,W){return h({...k,output:k.output?AW.cloneWithSelections(k.output,W):AW.create(W)})},cloneWithOrderByItems(k,W){return h({...k,orderBy:k.orderBy?$k.cloneWithItems(k.orderBy,W):$k.create(W)})},cloneWithoutOrderBy(k){return h({...k,orderBy:void 0})}});var Y=h({is(k){return k.kind==="SelectQueryNode"},create(k){return h({kind:"SelectQueryNode",...k&&{with:k}})},createFrom(k,W){return h({kind:"SelectQueryNode",from:Vk.create(k),...W&&{with:W}})},cloneWithSelections(k,W){return h({...k,selections:k.selections?h([...k.selections,...W]):h(W)})},cloneWithDistinctOn(k,W){return h({...k,distinctOn:k.distinctOn?h([...k.distinctOn,...W]):h(W)})},cloneWithFrontModifier(k,W){return h({...k,frontModifiers:k.frontModifiers?h([...k.frontModifiers,W]):h([W])})},cloneWithOrderByItems:(k,W)=>K.cloneWithOrderByItems(k,W),cloneWithGroupByItems(k,W){return h({...k,groupBy:k.groupBy?wW.cloneWithItems(k.groupBy,W):wW.create(W)})},cloneWithLimit(k,W){return h({...k,limit:W})},cloneWithOffset(k,W){return h({...k,offset:W})},cloneWithFetch(k,W){return h({...k,fetch:W})},cloneWithHaving(k,W){return h({...k,having:k.having?FW.cloneWithOperation(k.having,"And",W):FW.create(W)})},cloneWithSetOperations(k,W){return h({...k,setOperations:k.setOperations?h([...k.setOperations,...W]):h([...W])})},cloneWithoutSelections(k){return h({...k,selections:[]})},cloneWithoutLimit(k){return h({...k,limit:void 0})},cloneWithoutOffset(k){return h({...k,offset:void 0})},cloneWithoutOrderBy:(k)=>K.cloneWithoutOrderBy(k),cloneWithoutGroupBy(k){return h({...k,groupBy:void 0})}});class Rk{#k;constructor(k){this.#k=h(k)}on(...k){return new Rk({...this.#k,joinNode:Kk.cloneWithOn(this.#k.joinNode,L(k))})}onRef(k,W,$){return new Rk({...this.#k,joinNode:Kk.cloneWithOn(this.#k.joinNode,m(k,W,$))})}onTrue(){return new Rk({...this.#k,joinNode:Kk.cloneWithOn(this.#k.joinNode,v.createWithSql("true"))})}$call(k){return k(this)}toOperationNode(){return this.#k.joinNode}}class ah{#k;get dynamicReference(){return this.#k}get refType(){return}constructor(k){this.#k=k}toOperationNode(){return _W(this.#k)}}function $W(k){return kk(k)&&z(k)&&V(k.dynamicReference)}var g=h({is(k){return k.kind==="OrderByItemNode"},create(k,W){return h({kind:"OrderByItemNode",orderBy:k,direction:W})},cloneWith(k,W){return h({...k,...W})}});var eW=h({is(k){return k.kind==="CollateNode"},create(k){return h({kind:"CollateNode",collation:J.create(k)})}});class Lk{#k;constructor(k){this.#k=h(k)}desc(){return new Lk({node:g.cloneWith(this.#k.node,{direction:v.createWithSql("desc")})})}asc(){return new Lk({node:g.cloneWith(this.#k.node,{direction:v.createWithSql("asc")})})}nullsLast(){return new Lk({node:g.cloneWith(this.#k.node,{nulls:"last"})})}nullsFirst(){return new Lk({node:g.cloneWith(this.#k.node,{nulls:"first"})})}collate(k){return new Lk({node:g.cloneWith(this.#k.node,{collation:eW.create(k)})})}toOperationNode(){return this.#k.node}}function RW(k){return k==="asc"||k==="desc"}function B(k){if(k.length===2)return[mW(k[0],k[1])];if(k.length===1){let[W]=k;if(Array.isArray(W))return fk("orderBy(array) is deprecated, use multiple orderBy calls instead."),W.map(($)=>mW($));return[mW(W)]}throw Error(`Invalid number of arguments at order by! expected 1-2, received ${k.length}`)}function mW(k,W){let $=ph(k);if(g.is($)){if(W)throw Error("Cannot specify direction twice!");return $}return kh($,W)}function ph(k){if(Wk(k))return p(k);if($W(k))return k.toOperationNode();let[W,$]=k.split(" ");if($)return fk("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),kh(t(W),$);return t(k)}function kh(k,W){if(typeof W==="string"){if(!RW(W))throw Error(`Invalid order by direction: ${W}`);return g.create(k,v.createWithSql(W))}if(ok(W))return fk("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),g.create(k,W.toOperationNode());let $=g.create(k);if(!W)return $;return W(new Lk({node:$})).toOperationNode()}var Wh=h({is(k){return k.kind==="PartitionByItemNode"},create(k){return h({kind:"PartitionByItemNode",partitionBy:k})}});function hh(k){return Gk(k).map(Wh.create)}class Ck{#k;constructor(k){this.#k=h(k)}orderBy(...k){return new Ck({overNode:xk.cloneWithOrderByItems(this.#k.overNode,B(k))})}clearOrderBy(){return new Ck({overNode:K.cloneWithoutOrderBy(this.#k.overNode)})}partitionBy(k){return new Ck({overNode:xk.cloneWithPartitionByItems(this.#k.overNode,hh(k))})}$call(k){return k(this)}toOperationNode(){return this.#k.overNode}}var Sk=h({is(k){return k.kind==="SelectionNode"},create(k){return h({kind:"SelectionNode",selection:k})},createSelectAll(){return h({kind:"SelectionNode",selection:pk.create()})},createSelectAllFromTable(k){return h({kind:"SelectionNode",selection:Ak.createSelectAll(k)})}});class oh{#k;get table(){return this.#k}constructor(k){this.#k=k}as(k){return new $h(this.#k,k)}}class $h{#k;#W;get table(){return this.#k}get alias(){return this.#W}constructor(k,W){this.#k=k,this.#W=W}toOperationNode(){return I.create(F(this.#k),J.create(this.#W))}}function Mh(k){return kk(k)&&z(k)&&V(k.table)&&V(k.alias)}function n(k){if(j(k))return k.map((W)=>wk(W));else return[wk(k)]}function wk(k){if(V(k))return fW(k);else if(Mh(k))return k.toOperationNode();else return MW(k)}function fW(k){if(k.includes(" as ")){let[$,M]=k.split(" as ").map(Kh);return I.create(F($),J.create(M))}else return F(k)}function F(k){if(k.includes(".")){let[$,M]=k.split(".").map(Kh);return zk.createWithSchema($,M)}else return zk.create(k)}function Kh(k){return k.trim()}function A(k){if(_(k))return A(k(d()));else if(j(k))return k.map((W)=>Gh(W));else return[Gh(k)]}function Gh(k){if(V(k))return Sk.create(Zh(k));else if($W(k))return Sk.create(k.toOperationNode());else return Sk.create(MW(k))}function R(k){if(!k)return[Sk.createSelectAll()];else if(Array.isArray(k))return k.map(Hh);else return[Hh(k)]}function Hh(k){if(V(k))return Sk.createSelectAllFromTable(F(k));throw Error(`invalid value selectAll expression: ${JSON.stringify(k)}`)}var Yh=h({is(k){return k.kind==="ValuesNode"},create(k){return h({kind:"ValuesNode",values:h(k)})}});var Xh=h({is(k){return k.kind==="DefaultInsertValueNode"},create(){return h({kind:"DefaultInsertValueNode"})}});function KW(k){let W=_(k)?k(d()):k,$=j(W)?W:h([W]);return sh($)}function sh(k){let W=rh(k);return[h([...W.keys()].map(S.create)),Yh.create(k.map(($)=>eh($,W)))]}function rh(k){let W=new Map;for(let $ of k){let M=Object.keys($);for(let G of M)if(!W.has(G)&&$[G]!==void 0)W.set(G,W.size)}return W}function eh(k,W){let $=Object.keys(k),M=Array.from({length:W.size}),G=!1,q=$.length;for(let ak of $){let Nk=W.get(ak);if(c(Nk)){q--;continue}let qW=k[ak];if(c(qW)||Wk(qW))G=!0;M[Nk]=qW}if(q<W.size||G){let ak=Xh.create();return rk.create(M.map((Nk)=>c(Nk)?ak:X(Nk)))}return sk.create(M)}var CW=h({is(k){return k.kind==="ColumnUpdateNode"},create(k,W){return h({kind:"ColumnUpdateNode",column:k,value:W})}});function Dh(...k){if(k.length===2)return[CW.create(f(k[0]),X(k[1]))];return ck(k[0])}function ck(k){let W=_(k)?k(d()):k;return Object.entries(W).filter(([$,M])=>M!==void 0).map(([$,M])=>{return CW.create(S.create($),X(M))})}var Lh=h({is(k){return k.kind==="OnDuplicateKeyNode"},create(k){return h({kind:"OnDuplicateKeyNode",updates:k})}});class SW{insertId;numInsertedOrUpdatedRows;constructor(k,W){this.insertId=k,this.numInsertedOrUpdatedRows=W}}class u extends Error{node;constructor(k){super("no result");this.node=k}}function s(k){return Object.prototype.hasOwnProperty.call(k,"prototype")}var E=h({is(k){return k.kind==="OnConflictNode"},create(){return h({kind:"OnConflictNode"})},cloneWith(k,W){return h({...k,...W})},cloneWithIndexWhere(k,W){return h({...k,indexWhere:k.indexWhere?C.cloneWithOperation(k.indexWhere,"And",W):C.create(W)})},cloneWithIndexOrWhere(k,W){return h({...k,indexWhere:k.indexWhere?C.cloneWithOperation(k.indexWhere,"Or",W):C.create(W)})},cloneWithUpdateWhere(k,W){return h({...k,updateWhere:k.updateWhere?C.cloneWithOperation(k.updateWhere,"And",W):C.create(W)})},cloneWithUpdateOrWhere(k,W){return h({...k,updateWhere:k.updateWhere?C.cloneWithOperation(k.updateWhere,"Or",W):C.create(W)})},cloneWithoutIndexWhere(k){return h({...k,indexWhere:void 0})},cloneWithoutUpdateWhere(k){return h({...k,updateWhere:void 0})}});class r{#k;constructor(k){this.#k=h(k)}column(k){let W=S.create(k);return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{columns:this.#k.onConflictNode.columns?h([...this.#k.onConflictNode.columns,W]):h([W])})})}columns(k){let W=k.map(S.create);return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{columns:this.#k.onConflictNode.columns?h([...this.#k.onConflictNode.columns,...W]):h(W)})})}constraint(k){return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{constraint:J.create(k)})})}expression(k){return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{indexExpression:k.toOperationNode()})})}where(...k){return new r({...this.#k,onConflictNode:E.cloneWithIndexWhere(this.#k.onConflictNode,L(k))})}whereRef(k,W,$){return new r({...this.#k,onConflictNode:E.cloneWithIndexWhere(this.#k.onConflictNode,m(k,W,$))})}clearWhere(){return new r({...this.#k,onConflictNode:E.cloneWithoutIndexWhere(this.#k.onConflictNode)})}doNothing(){return new zh({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{doNothing:!0})})}doUpdateSet(k){return new yk({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{updates:ck(k)})})}$call(k){return k(this)}}class zh{#k;constructor(k){this.#k=h(k)}toOperationNode(){return this.#k.onConflictNode}}class yk{#k;constructor(k){this.#k=h(k)}where(...k){return new yk({...this.#k,onConflictNode:E.cloneWithUpdateWhere(this.#k.onConflictNode,L(k))})}whereRef(k,W,$){return new yk({...this.#k,onConflictNode:E.cloneWithUpdateWhere(this.#k.onConflictNode,m(k,W,$))})}clearWhere(){return new yk({...this.#k,onConflictNode:E.cloneWithoutUpdateWhere(this.#k.onConflictNode)})}$call(k){return k(this)}toOperationNode(){return this.#k.onConflictNode}}var Jh=h({is(k){return k.kind==="TopNode"},create(k,W){return h({kind:"TopNode",expression:k,modifiers:W})}});function i(k,W){if(!_k(k)&&!GW(k))throw Error(`Invalid top expression: ${k}`);if(!c(W)&&!k$(W))throw Error(`Invalid top modifiers: ${W}`);return Jh.create(k,W)}function k$(k){return k==="percent"||k==="with ties"||k==="percent with ties"}var Fk=h({is(k){return k.kind==="OrActionNode"},create(k){return h({kind:"OrActionNode",action:k})}});class D{#k;constructor(k){this.#k=h(k)}values(k){let[W,$]=KW(k);return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{columns:W,values:$})})}columns(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{columns:h(k.map(S.create))})})}expression(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{values:p(k)})})}defaultValues(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{defaultValues:!0})})}modifyEnd(k){return new D({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}ignore(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("ignore")})})}orIgnore(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("ignore")})})}orAbort(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("abort")})})}orFail(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("fail")})})}orReplace(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("replace")})})}orRollback(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("rollback")})})}top(k,W){return new D({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}onConflict(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{onConflict:k(new r({onConflictNode:E.create()})).toOperationNode()})})}onDuplicateKeyUpdate(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{onDuplicateKey:Lh.create(ck(k))})})}returning(k){return new D({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(){return new D({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R())})}output(k){return new D({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new D({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}clearReturning(){return new D({...this.#k,queryNode:K.cloneWithoutReturning(this.#k.queryNode)})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new D({...this.#k})}$castTo(){return new D(this.#k)}$narrowType(){return new D(this.#k)}$assertType(){return new D(this.#k)}withPlugin(k){return new D({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new SW(W.insertId,W.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new D({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}class IW{numDeletedRows;constructor(k){this.numDeletedRows=k}}var Ik=h({is(k){return k.kind==="LimitNode"},create(k){return h({kind:"LimitNode",limit:k})}});var P;class HW{#k;constructor(k){this.#k=h(k)}where(...k){return new P({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,L(k))})}whereRef(k,W,$){return new P({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,m(k,W,$))})}clearWhere(){return new P({...this.#k,queryNode:K.cloneWithoutWhere(this.#k.queryNode)})}top(k,W){return new P({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}using(k){return new P({...this.#k,queryNode:Dk.cloneWithUsing(this.#k.queryNode,n(k))})}innerJoin(...k){return this.#W("InnerJoin",k)}leftJoin(...k){return this.#W("LeftJoin",k)}rightJoin(...k){return this.#W("RightJoin",k)}fullJoin(...k){return this.#W("FullJoin",k)}#W(k,W){return new P({...this.#k,queryNode:K.cloneWithJoin(this.#k.queryNode,Jk(k,W))})}returning(k){return new P({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new P({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new P({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new P({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}clearReturning(){return new P({...this.#k,queryNode:K.cloneWithoutReturning(this.#k.queryNode)})}clearLimit(){return new P({...this.#k,queryNode:Dk.cloneWithoutLimit(this.#k.queryNode)})}orderBy(...k){return new P({...this.#k,queryNode:K.cloneWithOrderByItems(this.#k.queryNode,B(k))})}clearOrderBy(){return new P({...this.#k,queryNode:K.cloneWithoutOrderBy(this.#k.queryNode)})}limit(k){return new P({...this.#k,queryNode:Dk.cloneWithLimit(this.#k.queryNode,Ik.create(X(k)))})}modifyEnd(k){return new P({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new P({...this.#k})}$castTo(){return new P(this.#k)}$narrowType(){return new P(this.#k)}$assertType(){return new P(this.#k)}withPlugin(k){return new P({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new IW(W.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new P({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}P=HW;class jW{numUpdatedRows;numChangedRows;constructor(k,W){this.numUpdatedRows=k,this.numChangedRows=W}}var U;class jk{#k;constructor(k){this.#k=h(k)}where(...k){return new U({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,L(k))})}whereRef(k,W,$){return new U({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,m(k,W,$))})}clearWhere(){return new U({...this.#k,queryNode:K.cloneWithoutWhere(this.#k.queryNode)})}top(k,W){return new U({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}from(k){return new U({...this.#k,queryNode:o.cloneWithFromItems(this.#k.queryNode,n(k))})}innerJoin(...k){return this.#W("InnerJoin",k)}leftJoin(...k){return this.#W("LeftJoin",k)}rightJoin(...k){return this.#W("RightJoin",k)}fullJoin(...k){return this.#W("FullJoin",k)}#W(k,W){return new U({...this.#k,queryNode:K.cloneWithJoin(this.#k.queryNode,Jk(k,W))})}orderBy(...k){return new U({...this.#k,queryNode:K.cloneWithOrderByItems(this.#k.queryNode,B(k))})}clearOrderBy(){return new U({...this.#k,queryNode:K.cloneWithoutOrderBy(this.#k.queryNode)})}limit(k){return new U({...this.#k,queryNode:o.cloneWithLimit(this.#k.queryNode,Ik.create(X(k)))})}set(...k){return new U({...this.#k,queryNode:o.cloneWithUpdates(this.#k.queryNode,Dh(...k))})}returning(k){return new U({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new U({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new U({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new U({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}modifyEnd(k){return new U({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}clearReturning(){return new U({...this.#k,queryNode:K.cloneWithoutReturning(this.#k.queryNode)})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new U({...this.#k})}$castTo(){return new U(this.#k)}$narrowType(){return new U(this.#k)}$assertType(){return new U(this.#k)}withPlugin(k){return new U({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new jW(W.numAffectedRows??BigInt(0),W.numChangedRows)]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new U({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}U=jk;var EW=h({is(k){return k.kind==="CommonTableExpressionNameNode"},create(k,W){return h({kind:"CommonTableExpressionNameNode",table:zk.create(k),columns:W?h(W.map(S.create)):void 0})}});var Ek=h({is(k){return k.kind==="CommonTableExpressionNode"},create(k,W){return h({kind:"CommonTableExpressionNode",name:k,expression:W})},cloneWith(k,W){return h({...k,...W})}});class gk{#k;constructor(k){this.#k=h(k)}materialized(){return new gk({...this.#k,node:Ek.cloneWith(this.#k.node,{materialized:!0})})}notMaterialized(){return new gk({...this.#k,node:Ek.cloneWith(this.#k.node,{materialized:!1})})}toOperationNode(){return this.#k.node}}function OW(k,W){let $=W(Ph()).toOperationNode();if(_(k))return k(W$($)).toOperationNode();return Ek.create(qh(k),$)}function W$(k){return(W)=>{return new gk({node:Ek.create(qh(W),k)})}}function qh(k){if(k.includes("(")){let W=k.split(/[\(\)]/),$=W[0],M=W[1].split(",").map((G)=>G.trim());return EW.create($,M)}else return EW.create(k)}var tk=h({is(k){return k.kind==="WithNode"},create(k,W){return h({kind:"WithNode",expressions:h([k]),...W})},cloneWithExpression(k,W){return h({...k,expressions:h([...k.expressions,W])})}});var Uh=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];function Vh(k){let W="";for(let $=0;$<k;++$)W+=h$();return W}function h$(){return Uh[~~(Math.random()*Uh.length)]}function T(){return new wh}class wh{#k;get queryId(){if(this.#k===void 0)this.#k=Vh(8);return this.#k}}var Fh=h({is(k){return k.kind==="MatchedNode"},create(k,W=!1){return h({kind:"MatchedNode",not:k,bySource:W})}});function bW(k,W,$){return Mk.create(mk([Fh.create(!k.isMatched,k.bySource),...W&&W.length>0?[W.length===3&&$?m(W[0],W[1],W[2]):L(W)]:[]],"and",!1))}function Ok(k){if(V(k))return v.create([k],[]);if(z(k))return k.toOperationNode();return k}class ZW{#k;#W;#h;constructor(){this.#k=new Promise((k,W)=>{this.#h=W,this.#W=k})}get promise(){return this.#k}resolve=(k)=>{if(this.#W)this.#W(k)};reject=(k)=>{if(this.#h)this.#h(k)}}async function Th(k){let W=new ZW,$=new ZW;return k.provideConnection(async(M)=>{return W.resolve(M),await $.promise}).catch((M)=>W.reject(M)),h({connection:await W.promise,release:$.resolve})}var $$=h([]);class QW{#k;constructor(k=$$){this.#k=k}get plugins(){return this.#k}transformQuery(k,W){for(let $ of this.#k){let M=$.transformQuery({node:k,queryId:W});if(M.kind===k.kind)k=M;else throw Error(["KyselyPlugin.transformQuery must return a node","of the same kind that was given to it.",`The plugin was given a ${k.kind}`,`but it returned a ${M.kind}`].join(" "))}return k}async executeQuery(k){return await this.provideConnection(async(W)=>{let $=await W.executeQuery(k);if("numUpdatedOrDeletedRows"in $)fk("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`.");return await this.#W($,k.queryId)})}async*stream(k,W){let{connection:$,release:M}=await Th(this);try{for await(let G of $.streamQuery(k,W))yield await this.#W(G,k.queryId)}finally{M()}}async#W(k,W){for(let $ of this.#k)k=await $.transformResult({result:k,queryId:W});return k}}class bk extends QW{get adapter(){throw Error("this query cannot be compiled to SQL")}compileQuery(){throw Error("this query cannot be compiled to SQL")}provideConnection(){throw Error("this query cannot be executed")}withConnectionProvider(){throw Error("this query cannot have a connection provider")}withPlugin(k){return new bk([...this.plugins,k])}withPlugins(k){return new bk([...this.plugins,...k])}withPluginAtFront(k){return new bk([k,...this.plugins])}withoutPlugins(){return new bk([])}}var qk=new bk;class NW{numChangedRows;constructor(k){this.numChangedRows=k}}class Hk{#k;constructor(k){this.#k=h(k)}modifyEnd(k){return new Hk({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}top(k,W){return new Hk({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}using(...k){return new O({...this.#k,queryNode:N.cloneWithUsing(this.#k.queryNode,Jk("Using",k))})}returning(k){return new Hk({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new Hk({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new Hk({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new Hk({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}}class O{#k;constructor(k){this.#k=h(k)}modifyEnd(k){return new O({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}top(k,W){return new O({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}whenMatched(){return this.#W([])}whenMatchedAnd(...k){return this.#W(k)}whenMatchedAndRef(k,W,$){return this.#W([k,W,$],!0)}#W(k,W){return new BW({...this.#k,queryNode:N.cloneWithWhen(this.#k.queryNode,bW({isMatched:!0},k,W))})}whenNotMatched(){return this.#h([])}whenNotMatchedAnd(...k){return this.#h(k)}whenNotMatchedAndRef(k,W,$){return this.#h([k,W,$],!0)}whenNotMatchedBySource(){return this.#h([],!1,!0)}whenNotMatchedBySourceAnd(...k){return this.#h(k,!1,!0)}whenNotMatchedBySourceAndRef(k,W,$){return this.#h([k,W,$],!0,!0)}returning(k){return new O({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new O({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new O({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new O({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}#h(k,W=!1,$=!1){let M={...this.#k,queryNode:N.cloneWithWhen(this.#k.queryNode,bW({isMatched:!1,bySource:$},k,W))};return new($?BW:vh)(M)}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new O({...this.#k})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new NW(W.numAffectedRows)]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}}class BW{#k;constructor(k){this.#k=h(k)}thenDelete(){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok("delete"))})}thenDoNothing(){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok("do nothing"))})}thenUpdate(k){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok(k(new jk({queryId:this.#k.queryId,executor:qk,queryNode:o.createWithoutTable()}))))})}thenUpdateSet(...k){return this.thenUpdate((W)=>W.set(...k))}}class vh{#k;constructor(k){this.#k=h(k)}thenDoNothing(){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok("do nothing"))})}thenInsertValues(k){let[W,$]=KW(k);return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok(w.cloneWith(w.createWithoutInto(),{columns:W,values:$})))})}}class Pk{#k;constructor(k){this.#k=h(k)}selectFrom(k){return nk({queryId:T(),executor:this.#k.executor,queryNode:Y.createFrom(n(k),this.#k.withNode)})}selectNoFrom(k){return nk({queryId:T(),executor:this.#k.executor,queryNode:Y.cloneWithSelections(Y.create(this.#k.withNode),A(k))})}insertInto(k){return new D({queryId:T(),executor:this.#k.executor,queryNode:w.create(F(k),this.#k.withNode)})}replaceInto(k){return new D({queryId:T(),executor:this.#k.executor,queryNode:w.create(F(k),this.#k.withNode,!0)})}deleteFrom(k){return new HW({queryId:T(),executor:this.#k.executor,queryNode:Dk.create(n(k),this.#k.withNode)})}updateTable(k){return new jk({queryId:T(),executor:this.#k.executor,queryNode:o.create(n(k),this.#k.withNode)})}mergeInto(k){return new Hk({queryId:T(),executor:this.#k.executor,queryNode:N.create(fW(k),this.#k.withNode)})}with(k,W){let $=OW(k,W);return new Pk({...this.#k,withNode:this.#k.withNode?tk.cloneWithExpression(this.#k.withNode,$):tk.create($)})}withRecursive(k,W){let $=OW(k,W);return new Pk({...this.#k,withNode:this.#k.withNode?tk.cloneWithExpression(this.#k.withNode,$):tk.create($,{recursive:!0})})}withPlugin(k){return new Pk({...this.#k,executor:this.#k.executor.withPlugin(k)})}withoutPlugins(){return new Pk({...this.#k,executor:this.#k.executor.withoutPlugins()})}withSchema(k){return new Pk({...this.#k,executor:this.#k.executor.withPluginAtFront(new YW(k))})}}function Ph(){return new Pk({executor:qk})}function Ah(k,W){return new Rk({joinNode:Kk.create(k,wk(W))})}function _h(){return new Ck({overNode:xk.create()})}function Jk(k,W){if(W.length===3)return K$(k,W[0],W[1],W[2]);else if(W.length===2)return M$(k,W[0],W[1]);else if(W.length===1)return G$(k,W[0]);else throw Error("not implemented")}function M$(k,W,$){return $(Ah(k,W)).toOperationNode()}function K$(k,W,$,M){return Kk.createWithOn(k,wk(W),m($,"=",M))}function G$(k,W){return Kk.create(k,wk(W))}var mh=h({is(k){return k.kind==="OffsetNode"},create(k){return h({kind:"OffsetNode",offset:k})}});var Rh=h({is(k){return k.kind==="GroupByItemNode"},create(k){return h({kind:"GroupByItemNode",groupBy:k})}});function fh(k){return k=_(k)?k(d()):k,Gk(k).map(Rh.create)}function Tk(k,W,$){if(_(W))W=W(XW());if(!j(W))W=[W];return W.map((M)=>Ch.create(k,p(M),$))}class Z{#k;constructor(k){this.#k=k}get expressionType(){return}as(k){return new zW(this,k)}or(...k){return new DW(hk.create(this.#k,L(k)))}and(...k){return new LW(x.create(this.#k,L(k)))}$castTo(){return new Z(this.#k)}$notNull(){return new Z(this.#k)}toOperationNode(){return this.#k}}class zW{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}toOperationNode(){return I.create(this.#k.toOperationNode(),z(this.#W)?this.#W.toOperationNode():J.create(this.#W))}}class DW{#k;constructor(k){this.#k=k}get expressionType(){return}as(k){return new zW(this,k)}or(...k){return new DW(hk.create(this.#k,L(k)))}$castTo(){return new DW(this.#k)}toOperationNode(){return Xk.create(this.#k)}}class LW{#k;constructor(k){this.#k=k}get expressionType(){return}as(k){return new zW(this,k)}and(...k){return new LW(x.create(this.#k,L(k)))}$castTo(){return new LW(this.#k)}toOperationNode(){return Xk.create(this.#k)}}var Sh=h({is(k){return k.kind==="FetchNode"},create(k,W){return{kind:"FetchNode",rowCount:Q.create(k),modifier:W}}});function Ih(k,W){if(!_k(k)&&!GW(k))throw Error(`Invalid fetch row count: ${k}`);if(!H$(W))throw Error(`Invalid fetch modifier: ${W}`);return Sh.create(k,W)}function H$(k){return k==="only"||k==="with ties"}var H;class xW{#k;constructor(k){this.#k=h(k)}get expressionType(){return}get isSelectQueryBuilder(){return!0}where(...k){return new H({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,L(k))})}whereRef(k,W,$){return new H({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,m(k,W,$))})}having(...k){return new H({...this.#k,queryNode:Y.cloneWithHaving(this.#k.queryNode,L(k))})}havingRef(k,W,$){return new H({...this.#k,queryNode:Y.cloneWithHaving(this.#k.queryNode,m(k,W,$))})}select(k){return new H({...this.#k,queryNode:Y.cloneWithSelections(this.#k.queryNode,A(k))})}distinctOn(k){return new H({...this.#k,queryNode:Y.cloneWithDistinctOn(this.#k.queryNode,Gk(k))})}modifyFront(k){return new H({...this.#k,queryNode:Y.cloneWithFrontModifier(this.#k.queryNode,a.createWithExpression(k.toOperationNode()))})}modifyEnd(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.createWithExpression(k.toOperationNode()))})}distinct(){return new H({...this.#k,queryNode:Y.cloneWithFrontModifier(this.#k.queryNode,a.create("Distinct"))})}forUpdate(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForUpdate",k?dk(k).map(F):void 0))})}forShare(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForShare",k?dk(k).map(F):void 0))})}forKeyShare(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForKeyShare",k?dk(k).map(F):void 0))})}forNoKeyUpdate(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForNoKeyUpdate",k?dk(k).map(F):void 0))})}skipLocked(){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("SkipLocked"))})}noWait(){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("NoWait"))})}selectAll(k){return new H({...this.#k,queryNode:Y.cloneWithSelections(this.#k.queryNode,R(k))})}innerJoin(...k){return this.#W("InnerJoin",k)}leftJoin(...k){return this.#W("LeftJoin",k)}rightJoin(...k){return this.#W("RightJoin",k)}fullJoin(...k){return this.#W("FullJoin",k)}crossJoin(...k){return this.#W("CrossJoin",k)}innerJoinLateral(...k){return this.#W("LateralInnerJoin",k)}leftJoinLateral(...k){return this.#W("LateralLeftJoin",k)}crossJoinLateral(...k){return this.#W("LateralCrossJoin",k)}crossApply(...k){return this.#W("CrossApply",k)}outerApply(...k){return this.#W("OuterApply",k)}#W(k,W){return new H({...this.#k,queryNode:K.cloneWithJoin(this.#k.queryNode,Jk(k,W))})}orderBy(...k){return new H({...this.#k,queryNode:K.cloneWithOrderByItems(this.#k.queryNode,B(k))})}groupBy(k){return new H({...this.#k,queryNode:Y.cloneWithGroupByItems(this.#k.queryNode,fh(k))})}limit(k){return new H({...this.#k,queryNode:Y.cloneWithLimit(this.#k.queryNode,Ik.create(X(k)))})}offset(k){return new H({...this.#k,queryNode:Y.cloneWithOffset(this.#k.queryNode,mh.create(X(k)))})}fetch(k,W="only"){return new H({...this.#k,queryNode:Y.cloneWithFetch(this.#k.queryNode,Ih(k,W))})}top(k,W){return new H({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}union(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("union",k,!1))})}unionAll(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("union",k,!0))})}intersect(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("intersect",k,!1))})}intersectAll(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("intersect",k,!0))})}except(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("except",k,!1))})}exceptAll(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("except",k,!0))})}as(k){return new jh(this,k)}clearSelect(){return new H({...this.#k,queryNode:Y.cloneWithoutSelections(this.#k.queryNode)})}clearWhere(){return new H({...this.#k,queryNode:K.cloneWithoutWhere(this.#k.queryNode)})}clearLimit(){return new H({...this.#k,queryNode:Y.cloneWithoutLimit(this.#k.queryNode)})}clearOffset(){return new H({...this.#k,queryNode:Y.cloneWithoutOffset(this.#k.queryNode)})}clearOrderBy(){return new H({...this.#k,queryNode:K.cloneWithoutOrderBy(this.#k.queryNode)})}clearGroupBy(){return new H({...this.#k,queryNode:Y.cloneWithoutGroupBy(this.#k.queryNode)})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new H({...this.#k})}$castTo(){return new H(this.#k)}$narrowType(){return new H(this.#k)}$assertType(){return new H(this.#k)}$asTuple(){return new Z(this.toOperationNode())}$asScalar(){return new Z(this.toOperationNode())}withPlugin(k){return new H({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile();return(await this.#k.executor.executeQuery(k)).rows}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new H({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}H=xW;function nk(k){return new xW(k)}class jh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return I.create(this.#k.toOperationNode(),J.create(this.#W))}}var e=h({is(k){return k.kind==="AggregateFunctionNode"},create(k,W=[]){return h({kind:"AggregateFunctionNode",func:k,aggregated:W})},cloneWithDistinct(k){return h({...k,distinct:!0})},cloneWithOrderBy(k,W,$=!1){let M=$?"withinGroup":"orderBy";return h({...k,[M]:k[M]?$k.cloneWithItems(k[M],W):$k.create(W)})},cloneWithFilter(k,W){return h({...k,filter:k.filter?C.cloneWithOperation(k.filter,"And",W):C.create(W)})},cloneWithOrFilter(k,W){return h({...k,filter:k.filter?C.cloneWithOperation(k.filter,"Or",W):C.create(W)})},cloneWithOver(k,W){return h({...k,over:W})}});var cW=h({is(k){return k.kind==="FunctionNode"},create(k,W){return h({kind:"FunctionNode",func:k,arguments:W})}});class b{#k;constructor(k){this.#k=h(k)}get expressionType(){return}as(k){return new Eh(this,k)}distinct(){return new b({...this.#k,aggregateFunctionNode:e.cloneWithDistinct(this.#k.aggregateFunctionNode)})}orderBy(...k){return new b({...this.#k,aggregateFunctionNode:K.cloneWithOrderByItems(this.#k.aggregateFunctionNode,B(k))})}clearOrderBy(){return new b({...this.#k,aggregateFunctionNode:K.cloneWithoutOrderBy(this.#k.aggregateFunctionNode)})}withinGroupOrderBy(...k){return new b({...this.#k,aggregateFunctionNode:e.cloneWithOrderBy(this.#k.aggregateFunctionNode,B(k),!0)})}filterWhere(...k){return new b({...this.#k,aggregateFunctionNode:e.cloneWithFilter(this.#k.aggregateFunctionNode,L(k))})}filterWhereRef(k,W,$){return new b({...this.#k,aggregateFunctionNode:e.cloneWithFilter(this.#k.aggregateFunctionNode,m(k,W,$))})}over(k){let W=_h();return new b({...this.#k,aggregateFunctionNode:e.cloneWithOver(this.#k.aggregateFunctionNode,(k?k(W):W).toOperationNode())})}$call(k){return k(this)}$castTo(){return new b(this.#k)}$notNull(){return new b(this.#k)}toOperationNode(){return this.#k.aggregateFunctionNode}}class Eh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}toOperationNode(){return I.create(this.#k.toOperationNode(),J.create(this.#W))}}function Oh(){let k=($,M)=>{return new Z(cW.create($,Gk(M??[])))},W=($,M)=>{return new b({aggregateFunctionNode:e.create($,M?Gk(M):void 0)})};return Object.assign(k,{agg:W,avg($){return W("avg",[$])},coalesce(...$){return k("coalesce",$)},count($){return W("count",[$])},countAll($){return new b({aggregateFunctionNode:e.create("count",R($))})},max($){return W("max",[$])},min($){return W("min",[$])},sum($){return W("sum",[$])},any($){return k("any",[$])},jsonAgg($){return new b({aggregateFunctionNode:e.create("json_agg",[V($)?F($):$.toOperationNode()])})},toJson($){return new Z(cW.create("to_json",[V($)?F($):$.toOperationNode()]))}})}var bh=h({is(k){return k.kind==="UnaryOperationNode"},create(k,W){return h({kind:"UnaryOperationNode",operator:k,operand:W})}});function Qh(k,W){return bh.create(y.create(k),f(W))}var l=h({is(k){return k.kind==="CaseNode"},create(k){return h({kind:"CaseNode",value:k})},cloneWithWhen(k,W){return h({...k,when:h(k.when?[...k.when,W]:[W])})},cloneWithThen(k,W){return h({...k,when:k.when?h([...k.when.slice(0,-1),Mk.cloneWithResult(k.when[k.when.length-1],W)]):void 0})},cloneWith(k,W){return h({...k,...W})}});class yW{#k;constructor(k){this.#k=h(k)}when(...k){return new gW({...this.#k,node:l.cloneWithWhen(this.#k.node,Mk.create(L(k)))})}}class gW{#k;constructor(k){this.#k=h(k)}then(k){return new Nh({...this.#k,node:l.cloneWithThen(this.#k.node,WW(k)?Bk(k):X(k))})}}class Nh{#k;constructor(k){this.#k=h(k)}when(...k){return new gW({...this.#k,node:l.cloneWithWhen(this.#k.node,Mk.create(L(k)))})}else(k){return new Bh({...this.#k,node:l.cloneWith(this.#k.node,{else:WW(k)?Bk(k):X(k)})})}end(){return new Z(l.cloneWith(this.#k.node,{isStatement:!1}))}endCase(){return new Z(l.cloneWith(this.#k.node,{isStatement:!0}))}}class Bh{#k;constructor(k){this.#k=h(k)}end(){return new Z(l.cloneWith(this.#k.node,{isStatement:!1}))}endCase(){return new Z(l.cloneWith(this.#k.node,{isStatement:!0}))}}var JW=h({is(k){return k.kind==="JSONOperatorChainNode"},create(k){return h({kind:"JSONOperatorChainNode",operator:k,values:h([])})},cloneWithValue(k,W){return h({...k,values:h([...k.values,W])})}});var tW=h({is(k){return k.kind==="JSONPathLegNode"},create(k,W){return h({kind:"JSONPathLegNode",type:k,value:W})}});var Uk=h({is(k){return k.kind==="JSONPathNode"},create(k){return h({kind:"JSONPathNode",inOperator:k,pathLegs:h([])})},cloneWithLeg(k,W){return h({...k,pathLegs:h([...k.pathLegs,W])})}});var Qk=h({is(k){return k.kind==="JSONReferenceNode"},create(k,W){return h({kind:"JSONReferenceNode",reference:k,traversal:W})},cloneWithTraversal(k,W){return h({...k,traversal:W})}});var Z$=/^#-\d+$/;class ik{#k;constructor(k){this.#k=k}at(k){if(typeof k!=="number"&&typeof k!=="string"||typeof k==="number"&&!Number.isInteger(k)||typeof k==="string"&&k!=="last"&&!Z$.test(k))throw Error(`Unexpected index value in .at(...): ${k}`);return this.#W("ArrayLocation",k)}key(k){return this.#W("Member",k)}#W(k,W){if(Qk.is(this.#k))return new uk(Qk.cloneWithTraversal(this.#k,Uk.is(this.#k.traversal)?Uk.cloneWithLeg(this.#k.traversal,tW.create(k,W)):JW.cloneWithValue(this.#k.traversal,Q.createImmediate(W))));return new uk(Uk.cloneWithLeg(this.#k,tW.create(k,W)))}}class uk extends ik{#k;constructor(k){super(k);this.#k=k}get expressionType(){return}as(k){return new xh(this,k)}$castTo(){return new uk(this.#k)}$notNull(){return new uk(this.#k)}toOperationNode(){return this.#k}}class xh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}toOperationNode(){return I.create(this.#k.toOperationNode(),z(this.#W)?this.#W.toOperationNode():J.create(this.#W))}}var nW=h({is(k){return k.kind==="TupleNode"},create(k){return h({kind:"TupleNode",values:h(k)})}});var Y$=["varchar","char","text","integer","int2","int4","int8","smallint","bigint","boolean","real","double precision","float4","float8","decimal","numeric","binary","bytea","date","datetime","time","timetz","timestamp","timestamptz","serial","bigserial","uuid","json","jsonb","blob","varbinary","int4range","int4multirange","int8range","int8multirange","numrange","nummultirange","tsrange","tsmultirange","tstzrange","tstzmultirange","daterange","datemultirange"],X$=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],ch=h({is(k){return k.kind==="DataTypeNode"},create(k){return h({kind:"DataTypeNode",dataType:k})}});function yh(k){if(Y$.includes(k))return!0;if(X$.some((W)=>W.test(k)))return!0;return!1}function gh(k){if(z(k))return k.toOperationNode();if(yh(k))return ch.create(k);throw Error(`invalid column data type ${JSON.stringify(k)}`)}var th=h({is(k){return k.kind==="CastNode"},create(k,W){return h({kind:"CastNode",expression:k,dataType:W})}});function XW(k=qk){function W(G,q,vk){return new Z(hW(G,q,vk))}function $(G,q){return new Z(Qh(G,q))}let M=Object.assign(W,{fn:void 0,eb:void 0,selectFrom(G){return nk({queryId:T(),executor:k,queryNode:Y.createFrom(n(G))})},case(G){return new yW({node:l.create(c(G)?void 0:f(G))})},ref(G,q){if(c(q))return new Z(t(G));return new ik(nh(G,q))},jsonPath(){return new ik(Uk.create())},table(G){return new Z(F(G))},val(G){return new Z(X(G))},refTuple(...G){return new Z(nW.create(G.map(f)))},tuple(...G){return new Z(nW.create(G.map(X)))},lit(G){return new Z(Bk(G))},unary:$,not(G){return $("not",G)},exists(G){return $("exists",G)},neg(G){return $("-",G)},between(G,q,vk){return new Z(Yk.create(f(G),y.create("between"),x.create(X(q),X(vk))))},betweenSymmetric(G,q,vk){return new Z(Yk.create(f(G),y.create("between symmetric"),x.create(X(q),X(vk))))},and(G){if(j(G))return new Z(mk(G,"and"));return new Z(UW(G,"and"))},or(G){if(j(G))return new Z(mk(G,"or"));return new Z(UW(G,"or"))},parens(...G){let q=L(G);if(Xk.is(q))return new Z(q);else return new Z(Xk.create(q))},cast(G,q){return new Z(th.create(f(G),gh(q)))},withSchema(G){return XW(k.withPluginAtFront(new YW(G)))}});return M.fn=Oh(),M.eb=M,M}function d(k){return XW()}function p(k){if(z(k))return k.toOperationNode();else if(_(k))return k(d()).toOperationNode();throw Error(`invalid expression: ${JSON.stringify(k)}`)}function MW(k){if(z(k))return k.toOperationNode();else if(_(k))return k(d()).toOperationNode();throw Error(`invalid aliased expression: ${JSON.stringify(k)}`)}function Wk(k){return ok(k)||iW(k)||_(k)}function _W(k){if(V(k))return t(k);return k.toOperationNode()}function Gk(k){if(j(k))return k.map((W)=>f(W));else return[f(k)]}function f(k){if(Wk(k))return p(k);return _W(k)}function nh(k,W){let $=t(k);if(dW(W))return Qk.create($,JW.create(y.create(W)));let M=W.slice(0,-1);if(dW(M))return Qk.create($,Uk.create(y.create(M)));throw Error(`Invalid JSON operator: ${W}`)}function t(k){if(!k.includes("."))return Ak.create(S.create(k));let $=k.split(".").map(uW);if($.length===3)return L$($);if($.length===2)return z$($);throw Error(`invalid column reference ${k}`)}function Zh(k){if(k.includes(" as ")){let[$,M]=k.split(" as ").map(uW);return I.create(t($),J.create(M))}else return t(k)}function D$(k){return S.create(k)}function R3(k){if(k.includes(" ")){let[$,M]=k.split(" ").map(uW);if(!RW(M))throw Error(`invalid order direction "${M}" next to "${$}"`);return B([$,M])[0]}else return D$(k)}function L$(k){let[W,$,M]=k;return Ak.create(S.create(M),zk.createWithSchema(W,$))}function z$(k){let[W,$]=k;return Ak.create(S.create($),zk.create(W))}function uW(k){return k.trim()}class lk{#k;constructor(k){this.#k=h(k)}get expressionType(){return}get isRawBuilder(){return!0}as(k){return new dh(this,k)}$castTo(){return new lk({...this.#k})}$notNull(){return new lk(this.#k)}withPlugin(k){return new lk({...this.#k,plugins:this.#k.plugins!==void 0?h([...this.#k.plugins,k]):h([k])})}toOperationNode(){return this.#h(this.#W())}compile(k){return this.#$(this.#W(k))}async execute(k){let W=this.#W(k);return W.executeQuery(this.#$(W))}#W(k){let W=k!==void 0?k.getExecutor():qk;return this.#k.plugins!==void 0?W.withPlugins(this.#k.plugins):W}#h(k){return k.transformQuery(this.#k.rawNode,this.#k.queryId)}#$(k){return k.compileQuery(this.#h(k),this.#k.queryId)}}function Zk(k){return new lk(k)}class dh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}get rawBuilder(){return this.#k}toOperationNode(){return I.create(this.#k.toOperationNode(),z(this.#W)?this.#W.toOperationNode():J.create(this.#W))}}var J$=Object.assign((k,...W)=>{return Zk({queryId:T(),rawNode:v.create(k,W?.map(uh)??[])})},{ref(k){return Zk({queryId:T(),rawNode:v.createWithChild(t(k))})},val(k){return Zk({queryId:T(),rawNode:v.createWithChild(X(k))})},value(k){return this.val(k)},table(k){return Zk({queryId:T(),rawNode:v.createWithChild(F(k))})},id(...k){let W=Array(k.length+1).fill(".");return W[0]="",W[W.length-1]="",Zk({queryId:T(),rawNode:v.create(W,k.map(J.create))})},lit(k){return Zk({queryId:T(),rawNode:v.createWithChild(Q.createImmediate(k))})},literal(k){return this.lit(k)},raw(k){return Zk({queryId:T(),rawNode:v.createWithSql(k)})},join(k,W=J$`, `){let $=Array(Math.max(2*k.length-1,0)),M=W.toOperationNode();for(let G=0;G<k.length;++G)if($[2*G]=uh(k[G]),G!==k.length-1)$[2*G+1]=M;return Zk({queryId:T(),rawNode:v.createWithChildren($)})}});function uh(k){if(z(k))return k.toOperationNode();return X(k)}var l3=h({raw(k,W=[]){return h({sql:k,query:v.createWithSql(k),parameters:h(W),queryId:T()})}});
|
|
3
|
-
export{z as
|
|
2
|
+
import{$d as TW,Ad as kW,Cd as GW,Ed as _,Fd as kk,Gd as h,Hd as dk,Id as j,Kd as J,Od as I,Pd as zk,Qd as x,Rd as hk,Sd as Kk,Td as pW,Ud as y,Vd as dW,Wd as v,Xd as fk,Yd as Xk,Zd as w,_d as sW,ae as Mk,ce as YW,de as Ch,wd as c,xd as V,yd as _k,zd as ek}from"./chunk-pna93n17.js";function z(k){return kk(k)&&_(k.toOperationNode)}var Q=h({is(k){return k.kind==="ValueNode"},create(k){return h({kind:"ValueNode",value:k})},createImmediate(k){return h({kind:"ValueNode",value:k,immediate:!0})}});var S=h({is(k){return k.kind==="ColumnNode"},create(k){return h({kind:"ColumnNode",column:J.create(k)})}});var pk=h({is(k){return k.kind==="SelectAllNode"},create(){return h({kind:"SelectAllNode"})}});var Ak=h({is(k){return k.kind==="ReferenceNode"},create(k,W){return h({kind:"ReferenceNode",table:W,column:k})},createSelectAll(k){return h({kind:"ReferenceNode",table:k,column:pk.create()})}});function ok(k){return kk(k)&&"expressionType"in k&&z(k)}function iW(k){return kk(k)&&"expression"in k&&V(k.alias)&&z(k)}var a=h({is(k){return k.kind==="SelectModifierNode"},create(k,W){return h({kind:"SelectModifierNode",modifier:k,of:W})},createWithExpression(k){return h({kind:"SelectModifierNode",rawModifier:k})}});var Yk=h({is(k){return k.kind==="BinaryOperationNode"},create(k,W,$){return h({kind:"BinaryOperationNode",leftOperand:k,operator:W,rightOperand:$})}});var sk=h({is(k){return k.kind==="PrimitiveValueListNode"},create(k){return h({kind:"PrimitiveValueListNode",values:h([...k])})}});var rk=h({is(k){return k.kind==="ValueListNode"},create(k){return h({kind:"ValueListNode",values:h(k)})}});function lW(k){if(j(k))return ih(k);return X(k)}function X(k){if(Wk(k))return p(k);return Q.create(k)}function WW(k){return _k(k)||ek(k)||kW(k)}function Bk(k){if(!WW(k))throw Error(`unsafe immediate value ${JSON.stringify(k)}`);return Q.createImmediate(k)}function ih(k){if(k.some(Wk))return rk.create(k.map((W)=>X(W)));return sk.create(k)}function L(k){if(k.length===3)return hW(k[0],k[1],k[2]);else if(k.length===1)return X(k[0]);throw Error(`invalid arguments: ${JSON.stringify(k)}`)}function hW(k,W,$){if(lh(W)&&oW($))return Yk.create(f(k),PW(W),Q.createImmediate($));return Yk.create(f(k),PW(W),lW($))}function m(k,W,$){return Yk.create(f(k),PW(W),f($))}function UW(k,W){return mk(Object.entries(k).filter(([,$])=>!c($)).map(([$,M])=>hW($,oW(M)?"is":"=",M)),W)}function mk(k,W,$=!0){let M=W==="and"?x.create:hk.create;if(k.length===0)return Yk.create(Q.createImmediate(1),y.create("="),Q.createImmediate(W==="and"?1:0));let G=aW(k[0]);for(let q=1;q<k.length;++q)G=M(G,aW(k[q]));if(k.length>1&&$)return Xk.create(G);return G}function lh(k){return k==="is"||k==="is not"}function oW(k){return kW(k)||ek(k)}function PW(k){if(V(k)&&pW.includes(k))return y.create(k);if(z(k))return k.toOperationNode();throw Error(`invalid operator ${JSON.stringify(k)}`)}function aW(k){return z(k)?k.toOperationNode():k}var $k=h({is(k){return k.kind==="OrderByNode"},create(k){return h({kind:"OrderByNode",items:h([...k])})},cloneWithItems(k,W){return h({...k,items:h([...k.items,...W])})}});var VW=h({is(k){return k.kind==="PartitionByNode"},create(k){return h({kind:"PartitionByNode",items:h(k)})},cloneWithItems(k,W){return h({...k,items:h([...k.items,...W])})}});var xk=h({is(k){return k.kind==="OverNode"},create(){return h({kind:"OverNode"})},cloneWithOrderByItems(k,W){return h({...k,orderBy:k.orderBy?$k.cloneWithItems(k.orderBy,W):$k.create(W)})},cloneWithPartitionByItems(k,W){return h({...k,partitionBy:k.partitionBy?VW.cloneWithItems(k.partitionBy,W):VW.create(W)})}});var Vk=h({is(k){return k.kind==="FromNode"},create(k){return h({kind:"FromNode",froms:h(k)})},cloneWithFroms(k,W){return h({...k,froms:h([...k.froms,...W])})}});var wW=h({is(k){return k.kind==="GroupByNode"},create(k){return h({kind:"GroupByNode",items:h(k)})},cloneWithItems(k,W){return h({...k,items:h([...k.items,...W])})}});var FW=h({is(k){return k.kind==="HavingNode"},create(k){return h({kind:"HavingNode",having:k})},cloneWithOperation(k,W,$){return h({...k,having:W==="And"?x.create(k.having,$):hk.create(k.having,$)})}});var o=h({is(k){return k.kind==="UpdateQueryNode"},create(k,W){return h({kind:"UpdateQueryNode",table:k.length===1?k[0]:sW.create(k),...W&&{with:W}})},createWithoutTable(){return h({kind:"UpdateQueryNode"})},cloneWithFromItems(k,W){return h({...k,from:k.from?Vk.cloneWithFroms(k.from,W):Vk.create(W)})},cloneWithUpdates(k,W){return h({...k,updates:k.updates?h([...k.updates,...W]):W})},cloneWithLimit(k,W){return h({...k,limit:W})}});var Dk=h({is(k){return k.kind==="DeleteQueryNode"},create(k,W){return h({kind:"DeleteQueryNode",from:Vk.create(k),...W&&{with:W}})},cloneWithOrderByItems:(k,W)=>K.cloneWithOrderByItems(k,W),cloneWithoutOrderBy:(k)=>K.cloneWithoutOrderBy(k),cloneWithLimit(k,W){return h({...k,limit:W})},cloneWithoutLimit(k){return h({...k,limit:void 0})},cloneWithUsing(k,W){return h({...k,using:k.using!==void 0?TW.cloneWithTables(k.using,W):TW.create(W)})}});var C=h({is(k){return k.kind==="WhereNode"},create(k){return h({kind:"WhereNode",where:k})},cloneWithOperation(k,W,$){return h({...k,where:W==="And"?x.create(k.where,$):hk.create(k.where,$)})}});var vW=h({is(k){return k.kind==="ReturningNode"},create(k){return h({kind:"ReturningNode",selections:h(k)})},cloneWithSelections(k,W){return h({...k,selections:k.selections?h([...k.selections,...W]):h(W)})}});var rW=h({is(k){return k.kind==="ExplainNode"},create(k,W){return h({kind:"ExplainNode",format:k,options:W})}});var N=h({is(k){return k.kind==="MergeQueryNode"},create(k,W){return h({kind:"MergeQueryNode",into:k,...W&&{with:W}})},cloneWithUsing(k,W){return h({...k,using:W})},cloneWithWhen(k,W){return h({...k,whens:k.whens?h([...k.whens,W]):h([W])})},cloneWithThen(k,W){return h({...k,whens:k.whens?h([...k.whens.slice(0,-1),Mk.cloneWithResult(k.whens[k.whens.length-1],W)]):void 0})}});var AW=h({is(k){return k.kind==="OutputNode"},create(k){return h({kind:"OutputNode",selections:h(k)})},cloneWithSelections(k,W){return h({...k,selections:k.selections?h([...k.selections,...W]):h(W)})}});var K=h({is(k){return Y.is(k)||w.is(k)||o.is(k)||Dk.is(k)||N.is(k)},cloneWithEndModifier(k,W){return h({...k,endModifiers:k.endModifiers?h([...k.endModifiers,W]):h([W])})},cloneWithWhere(k,W){return h({...k,where:k.where?C.cloneWithOperation(k.where,"And",W):C.create(W)})},cloneWithJoin(k,W){return h({...k,joins:k.joins?h([...k.joins,W]):h([W])})},cloneWithReturning(k,W){return h({...k,returning:k.returning?vW.cloneWithSelections(k.returning,W):vW.create(W)})},cloneWithoutReturning(k){return h({...k,returning:void 0})},cloneWithoutWhere(k){return h({...k,where:void 0})},cloneWithExplain(k,W,$){return h({...k,explain:rW.create(W,$?.toOperationNode())})},cloneWithTop(k,W){return h({...k,top:W})},cloneWithOutput(k,W){return h({...k,output:k.output?AW.cloneWithSelections(k.output,W):AW.create(W)})},cloneWithOrderByItems(k,W){return h({...k,orderBy:k.orderBy?$k.cloneWithItems(k.orderBy,W):$k.create(W)})},cloneWithoutOrderBy(k){return h({...k,orderBy:void 0})}});var Y=h({is(k){return k.kind==="SelectQueryNode"},create(k){return h({kind:"SelectQueryNode",...k&&{with:k}})},createFrom(k,W){return h({kind:"SelectQueryNode",from:Vk.create(k),...W&&{with:W}})},cloneWithSelections(k,W){return h({...k,selections:k.selections?h([...k.selections,...W]):h(W)})},cloneWithDistinctOn(k,W){return h({...k,distinctOn:k.distinctOn?h([...k.distinctOn,...W]):h(W)})},cloneWithFrontModifier(k,W){return h({...k,frontModifiers:k.frontModifiers?h([...k.frontModifiers,W]):h([W])})},cloneWithOrderByItems:(k,W)=>K.cloneWithOrderByItems(k,W),cloneWithGroupByItems(k,W){return h({...k,groupBy:k.groupBy?wW.cloneWithItems(k.groupBy,W):wW.create(W)})},cloneWithLimit(k,W){return h({...k,limit:W})},cloneWithOffset(k,W){return h({...k,offset:W})},cloneWithFetch(k,W){return h({...k,fetch:W})},cloneWithHaving(k,W){return h({...k,having:k.having?FW.cloneWithOperation(k.having,"And",W):FW.create(W)})},cloneWithSetOperations(k,W){return h({...k,setOperations:k.setOperations?h([...k.setOperations,...W]):h([...W])})},cloneWithoutSelections(k){return h({...k,selections:[]})},cloneWithoutLimit(k){return h({...k,limit:void 0})},cloneWithoutOffset(k){return h({...k,offset:void 0})},cloneWithoutOrderBy:(k)=>K.cloneWithoutOrderBy(k),cloneWithoutGroupBy(k){return h({...k,groupBy:void 0})}});class Rk{#k;constructor(k){this.#k=h(k)}on(...k){return new Rk({...this.#k,joinNode:Kk.cloneWithOn(this.#k.joinNode,L(k))})}onRef(k,W,$){return new Rk({...this.#k,joinNode:Kk.cloneWithOn(this.#k.joinNode,m(k,W,$))})}onTrue(){return new Rk({...this.#k,joinNode:Kk.cloneWithOn(this.#k.joinNode,v.createWithSql("true"))})}$call(k){return k(this)}toOperationNode(){return this.#k.joinNode}}class ah{#k;get dynamicReference(){return this.#k}get refType(){return}constructor(k){this.#k=k}toOperationNode(){return _W(this.#k)}}function $W(k){return kk(k)&&z(k)&&V(k.dynamicReference)}var g=h({is(k){return k.kind==="OrderByItemNode"},create(k,W){return h({kind:"OrderByItemNode",orderBy:k,direction:W})},cloneWith(k,W){return h({...k,...W})}});var eW=h({is(k){return k.kind==="CollateNode"},create(k){return h({kind:"CollateNode",collation:J.create(k)})}});class Lk{#k;constructor(k){this.#k=h(k)}desc(){return new Lk({node:g.cloneWith(this.#k.node,{direction:v.createWithSql("desc")})})}asc(){return new Lk({node:g.cloneWith(this.#k.node,{direction:v.createWithSql("asc")})})}nullsLast(){return new Lk({node:g.cloneWith(this.#k.node,{nulls:"last"})})}nullsFirst(){return new Lk({node:g.cloneWith(this.#k.node,{nulls:"first"})})}collate(k){return new Lk({node:g.cloneWith(this.#k.node,{collation:eW.create(k)})})}toOperationNode(){return this.#k.node}}function RW(k){return k==="asc"||k==="desc"}function B(k){if(k.length===2)return[mW(k[0],k[1])];if(k.length===1){let[W]=k;if(Array.isArray(W))return fk("orderBy(array) is deprecated, use multiple orderBy calls instead."),W.map(($)=>mW($));return[mW(W)]}throw Error(`Invalid number of arguments at order by! expected 1-2, received ${k.length}`)}function mW(k,W){let $=ph(k);if(g.is($)){if(W)throw Error("Cannot specify direction twice!");return $}return kh($,W)}function ph(k){if(Wk(k))return p(k);if($W(k))return k.toOperationNode();let[W,$]=k.split(" ");if($)return fk("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),kh(t(W),$);return t(k)}function kh(k,W){if(typeof W==="string"){if(!RW(W))throw Error(`Invalid order by direction: ${W}`);return g.create(k,v.createWithSql(W))}if(ok(W))return fk("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),g.create(k,W.toOperationNode());let $=g.create(k);if(!W)return $;return W(new Lk({node:$})).toOperationNode()}var Wh=h({is(k){return k.kind==="PartitionByItemNode"},create(k){return h({kind:"PartitionByItemNode",partitionBy:k})}});function hh(k){return Gk(k).map(Wh.create)}class Ck{#k;constructor(k){this.#k=h(k)}orderBy(...k){return new Ck({overNode:xk.cloneWithOrderByItems(this.#k.overNode,B(k))})}clearOrderBy(){return new Ck({overNode:K.cloneWithoutOrderBy(this.#k.overNode)})}partitionBy(k){return new Ck({overNode:xk.cloneWithPartitionByItems(this.#k.overNode,hh(k))})}$call(k){return k(this)}toOperationNode(){return this.#k.overNode}}var Sk=h({is(k){return k.kind==="SelectionNode"},create(k){return h({kind:"SelectionNode",selection:k})},createSelectAll(){return h({kind:"SelectionNode",selection:pk.create()})},createSelectAllFromTable(k){return h({kind:"SelectionNode",selection:Ak.createSelectAll(k)})}});class oh{#k;get table(){return this.#k}constructor(k){this.#k=k}as(k){return new $h(this.#k,k)}}class $h{#k;#W;get table(){return this.#k}get alias(){return this.#W}constructor(k,W){this.#k=k,this.#W=W}toOperationNode(){return I.create(F(this.#k),J.create(this.#W))}}function Mh(k){return kk(k)&&z(k)&&V(k.table)&&V(k.alias)}function n(k){if(j(k))return k.map((W)=>wk(W));else return[wk(k)]}function wk(k){if(V(k))return fW(k);else if(Mh(k))return k.toOperationNode();else return MW(k)}function fW(k){if(k.includes(" as ")){let[$,M]=k.split(" as ").map(Kh);return I.create(F($),J.create(M))}else return F(k)}function F(k){if(k.includes(".")){let[$,M]=k.split(".").map(Kh);return zk.createWithSchema($,M)}else return zk.create(k)}function Kh(k){return k.trim()}function A(k){if(_(k))return A(k(d()));else if(j(k))return k.map((W)=>Gh(W));else return[Gh(k)]}function Gh(k){if(V(k))return Sk.create(Zh(k));else if($W(k))return Sk.create(k.toOperationNode());else return Sk.create(MW(k))}function R(k){if(!k)return[Sk.createSelectAll()];else if(Array.isArray(k))return k.map(Hh);else return[Hh(k)]}function Hh(k){if(V(k))return Sk.createSelectAllFromTable(F(k));throw Error(`invalid value selectAll expression: ${JSON.stringify(k)}`)}var Yh=h({is(k){return k.kind==="ValuesNode"},create(k){return h({kind:"ValuesNode",values:h(k)})}});var Xh=h({is(k){return k.kind==="DefaultInsertValueNode"},create(){return h({kind:"DefaultInsertValueNode"})}});function KW(k){let W=_(k)?k(d()):k,$=j(W)?W:h([W]);return sh($)}function sh(k){let W=rh(k);return[h([...W.keys()].map(S.create)),Yh.create(k.map(($)=>eh($,W)))]}function rh(k){let W=new Map;for(let $ of k){let M=Object.keys($);for(let G of M)if(!W.has(G)&&$[G]!==void 0)W.set(G,W.size)}return W}function eh(k,W){let $=Object.keys(k),M=Array.from({length:W.size}),G=!1,q=$.length;for(let ak of $){let Nk=W.get(ak);if(c(Nk)){q--;continue}let qW=k[ak];if(c(qW)||Wk(qW))G=!0;M[Nk]=qW}if(q<W.size||G){let ak=Xh.create();return rk.create(M.map((Nk)=>c(Nk)?ak:X(Nk)))}return sk.create(M)}var CW=h({is(k){return k.kind==="ColumnUpdateNode"},create(k,W){return h({kind:"ColumnUpdateNode",column:k,value:W})}});function Dh(...k){if(k.length===2)return[CW.create(f(k[0]),X(k[1]))];return ck(k[0])}function ck(k){let W=_(k)?k(d()):k;return Object.entries(W).filter(([$,M])=>M!==void 0).map(([$,M])=>{return CW.create(S.create($),X(M))})}var Lh=h({is(k){return k.kind==="OnDuplicateKeyNode"},create(k){return h({kind:"OnDuplicateKeyNode",updates:k})}});class SW{insertId;numInsertedOrUpdatedRows;constructor(k,W){this.insertId=k,this.numInsertedOrUpdatedRows=W}}class u extends Error{node;constructor(k){super("no result");this.node=k}}function s(k){return Object.prototype.hasOwnProperty.call(k,"prototype")}var E=h({is(k){return k.kind==="OnConflictNode"},create(){return h({kind:"OnConflictNode"})},cloneWith(k,W){return h({...k,...W})},cloneWithIndexWhere(k,W){return h({...k,indexWhere:k.indexWhere?C.cloneWithOperation(k.indexWhere,"And",W):C.create(W)})},cloneWithIndexOrWhere(k,W){return h({...k,indexWhere:k.indexWhere?C.cloneWithOperation(k.indexWhere,"Or",W):C.create(W)})},cloneWithUpdateWhere(k,W){return h({...k,updateWhere:k.updateWhere?C.cloneWithOperation(k.updateWhere,"And",W):C.create(W)})},cloneWithUpdateOrWhere(k,W){return h({...k,updateWhere:k.updateWhere?C.cloneWithOperation(k.updateWhere,"Or",W):C.create(W)})},cloneWithoutIndexWhere(k){return h({...k,indexWhere:void 0})},cloneWithoutUpdateWhere(k){return h({...k,updateWhere:void 0})}});class r{#k;constructor(k){this.#k=h(k)}column(k){let W=S.create(k);return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{columns:this.#k.onConflictNode.columns?h([...this.#k.onConflictNode.columns,W]):h([W])})})}columns(k){let W=k.map(S.create);return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{columns:this.#k.onConflictNode.columns?h([...this.#k.onConflictNode.columns,...W]):h(W)})})}constraint(k){return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{constraint:J.create(k)})})}expression(k){return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{indexExpression:k.toOperationNode()})})}where(...k){return new r({...this.#k,onConflictNode:E.cloneWithIndexWhere(this.#k.onConflictNode,L(k))})}whereRef(k,W,$){return new r({...this.#k,onConflictNode:E.cloneWithIndexWhere(this.#k.onConflictNode,m(k,W,$))})}clearWhere(){return new r({...this.#k,onConflictNode:E.cloneWithoutIndexWhere(this.#k.onConflictNode)})}doNothing(){return new zh({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{doNothing:!0})})}doUpdateSet(k){return new yk({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{updates:ck(k)})})}$call(k){return k(this)}}class zh{#k;constructor(k){this.#k=h(k)}toOperationNode(){return this.#k.onConflictNode}}class yk{#k;constructor(k){this.#k=h(k)}where(...k){return new yk({...this.#k,onConflictNode:E.cloneWithUpdateWhere(this.#k.onConflictNode,L(k))})}whereRef(k,W,$){return new yk({...this.#k,onConflictNode:E.cloneWithUpdateWhere(this.#k.onConflictNode,m(k,W,$))})}clearWhere(){return new yk({...this.#k,onConflictNode:E.cloneWithoutUpdateWhere(this.#k.onConflictNode)})}$call(k){return k(this)}toOperationNode(){return this.#k.onConflictNode}}var Jh=h({is(k){return k.kind==="TopNode"},create(k,W){return h({kind:"TopNode",expression:k,modifiers:W})}});function i(k,W){if(!_k(k)&&!GW(k))throw Error(`Invalid top expression: ${k}`);if(!c(W)&&!k$(W))throw Error(`Invalid top modifiers: ${W}`);return Jh.create(k,W)}function k$(k){return k==="percent"||k==="with ties"||k==="percent with ties"}var Fk=h({is(k){return k.kind==="OrActionNode"},create(k){return h({kind:"OrActionNode",action:k})}});class D{#k;constructor(k){this.#k=h(k)}values(k){let[W,$]=KW(k);return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{columns:W,values:$})})}columns(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{columns:h(k.map(S.create))})})}expression(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{values:p(k)})})}defaultValues(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{defaultValues:!0})})}modifyEnd(k){return new D({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}ignore(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("ignore")})})}orIgnore(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("ignore")})})}orAbort(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("abort")})})}orFail(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("fail")})})}orReplace(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("replace")})})}orRollback(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("rollback")})})}top(k,W){return new D({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}onConflict(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{onConflict:k(new r({onConflictNode:E.create()})).toOperationNode()})})}onDuplicateKeyUpdate(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{onDuplicateKey:Lh.create(ck(k))})})}returning(k){return new D({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(){return new D({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R())})}output(k){return new D({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new D({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}clearReturning(){return new D({...this.#k,queryNode:K.cloneWithoutReturning(this.#k.queryNode)})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new D({...this.#k})}$castTo(){return new D(this.#k)}$narrowType(){return new D(this.#k)}$assertType(){return new D(this.#k)}withPlugin(k){return new D({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new SW(W.insertId,W.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new D({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}class IW{numDeletedRows;constructor(k){this.numDeletedRows=k}}var Ik=h({is(k){return k.kind==="LimitNode"},create(k){return h({kind:"LimitNode",limit:k})}});var P;class HW{#k;constructor(k){this.#k=h(k)}where(...k){return new P({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,L(k))})}whereRef(k,W,$){return new P({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,m(k,W,$))})}clearWhere(){return new P({...this.#k,queryNode:K.cloneWithoutWhere(this.#k.queryNode)})}top(k,W){return new P({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}using(k){return new P({...this.#k,queryNode:Dk.cloneWithUsing(this.#k.queryNode,n(k))})}innerJoin(...k){return this.#W("InnerJoin",k)}leftJoin(...k){return this.#W("LeftJoin",k)}rightJoin(...k){return this.#W("RightJoin",k)}fullJoin(...k){return this.#W("FullJoin",k)}#W(k,W){return new P({...this.#k,queryNode:K.cloneWithJoin(this.#k.queryNode,Jk(k,W))})}returning(k){return new P({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new P({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new P({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new P({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}clearReturning(){return new P({...this.#k,queryNode:K.cloneWithoutReturning(this.#k.queryNode)})}clearLimit(){return new P({...this.#k,queryNode:Dk.cloneWithoutLimit(this.#k.queryNode)})}orderBy(...k){return new P({...this.#k,queryNode:K.cloneWithOrderByItems(this.#k.queryNode,B(k))})}clearOrderBy(){return new P({...this.#k,queryNode:K.cloneWithoutOrderBy(this.#k.queryNode)})}limit(k){return new P({...this.#k,queryNode:Dk.cloneWithLimit(this.#k.queryNode,Ik.create(X(k)))})}modifyEnd(k){return new P({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new P({...this.#k})}$castTo(){return new P(this.#k)}$narrowType(){return new P(this.#k)}$assertType(){return new P(this.#k)}withPlugin(k){return new P({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new IW(W.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new P({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}P=HW;class jW{numUpdatedRows;numChangedRows;constructor(k,W){this.numUpdatedRows=k,this.numChangedRows=W}}var U;class jk{#k;constructor(k){this.#k=h(k)}where(...k){return new U({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,L(k))})}whereRef(k,W,$){return new U({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,m(k,W,$))})}clearWhere(){return new U({...this.#k,queryNode:K.cloneWithoutWhere(this.#k.queryNode)})}top(k,W){return new U({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}from(k){return new U({...this.#k,queryNode:o.cloneWithFromItems(this.#k.queryNode,n(k))})}innerJoin(...k){return this.#W("InnerJoin",k)}leftJoin(...k){return this.#W("LeftJoin",k)}rightJoin(...k){return this.#W("RightJoin",k)}fullJoin(...k){return this.#W("FullJoin",k)}#W(k,W){return new U({...this.#k,queryNode:K.cloneWithJoin(this.#k.queryNode,Jk(k,W))})}orderBy(...k){return new U({...this.#k,queryNode:K.cloneWithOrderByItems(this.#k.queryNode,B(k))})}clearOrderBy(){return new U({...this.#k,queryNode:K.cloneWithoutOrderBy(this.#k.queryNode)})}limit(k){return new U({...this.#k,queryNode:o.cloneWithLimit(this.#k.queryNode,Ik.create(X(k)))})}set(...k){return new U({...this.#k,queryNode:o.cloneWithUpdates(this.#k.queryNode,Dh(...k))})}returning(k){return new U({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new U({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new U({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new U({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}modifyEnd(k){return new U({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}clearReturning(){return new U({...this.#k,queryNode:K.cloneWithoutReturning(this.#k.queryNode)})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new U({...this.#k})}$castTo(){return new U(this.#k)}$narrowType(){return new U(this.#k)}$assertType(){return new U(this.#k)}withPlugin(k){return new U({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new jW(W.numAffectedRows??BigInt(0),W.numChangedRows)]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new U({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}U=jk;var EW=h({is(k){return k.kind==="CommonTableExpressionNameNode"},create(k,W){return h({kind:"CommonTableExpressionNameNode",table:zk.create(k),columns:W?h(W.map(S.create)):void 0})}});var Ek=h({is(k){return k.kind==="CommonTableExpressionNode"},create(k,W){return h({kind:"CommonTableExpressionNode",name:k,expression:W})},cloneWith(k,W){return h({...k,...W})}});class gk{#k;constructor(k){this.#k=h(k)}materialized(){return new gk({...this.#k,node:Ek.cloneWith(this.#k.node,{materialized:!0})})}notMaterialized(){return new gk({...this.#k,node:Ek.cloneWith(this.#k.node,{materialized:!1})})}toOperationNode(){return this.#k.node}}function OW(k,W){let $=W(Ph()).toOperationNode();if(_(k))return k(W$($)).toOperationNode();return Ek.create(qh(k),$)}function W$(k){return(W)=>{return new gk({node:Ek.create(qh(W),k)})}}function qh(k){if(k.includes("(")){let W=k.split(/[\(\)]/),$=W[0],M=W[1].split(",").map((G)=>G.trim());return EW.create($,M)}else return EW.create(k)}var tk=h({is(k){return k.kind==="WithNode"},create(k,W){return h({kind:"WithNode",expressions:h([k]),...W})},cloneWithExpression(k,W){return h({...k,expressions:h([...k.expressions,W])})}});var Uh=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];function Vh(k){let W="";for(let $=0;$<k;++$)W+=h$();return W}function h$(){return Uh[~~(Math.random()*Uh.length)]}function T(){return new wh}class wh{#k;get queryId(){if(this.#k===void 0)this.#k=Vh(8);return this.#k}}var Fh=h({is(k){return k.kind==="MatchedNode"},create(k,W=!1){return h({kind:"MatchedNode",not:k,bySource:W})}});function bW(k,W,$){return Mk.create(mk([Fh.create(!k.isMatched,k.bySource),...W&&W.length>0?[W.length===3&&$?m(W[0],W[1],W[2]):L(W)]:[]],"and",!1))}function Ok(k){if(V(k))return v.create([k],[]);if(z(k))return k.toOperationNode();return k}class ZW{#k;#W;#h;constructor(){this.#k=new Promise((k,W)=>{this.#h=W,this.#W=k})}get promise(){return this.#k}resolve=(k)=>{if(this.#W)this.#W(k)};reject=(k)=>{if(this.#h)this.#h(k)}}async function Th(k){let W=new ZW,$=new ZW;return k.provideConnection(async(M)=>{return W.resolve(M),await $.promise}).catch((M)=>W.reject(M)),h({connection:await W.promise,release:$.resolve})}var $$=h([]);class QW{#k;constructor(k=$$){this.#k=k}get plugins(){return this.#k}transformQuery(k,W){for(let $ of this.#k){let M=$.transformQuery({node:k,queryId:W});if(M.kind===k.kind)k=M;else throw Error(["KyselyPlugin.transformQuery must return a node","of the same kind that was given to it.",`The plugin was given a ${k.kind}`,`but it returned a ${M.kind}`].join(" "))}return k}async executeQuery(k){return await this.provideConnection(async(W)=>{let $=await W.executeQuery(k);if("numUpdatedOrDeletedRows"in $)fk("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`.");return await this.#W($,k.queryId)})}async*stream(k,W){let{connection:$,release:M}=await Th(this);try{for await(let G of $.streamQuery(k,W))yield await this.#W(G,k.queryId)}finally{M()}}async#W(k,W){for(let $ of this.#k)k=await $.transformResult({result:k,queryId:W});return k}}class bk extends QW{get adapter(){throw Error("this query cannot be compiled to SQL")}compileQuery(){throw Error("this query cannot be compiled to SQL")}provideConnection(){throw Error("this query cannot be executed")}withConnectionProvider(){throw Error("this query cannot have a connection provider")}withPlugin(k){return new bk([...this.plugins,k])}withPlugins(k){return new bk([...this.plugins,...k])}withPluginAtFront(k){return new bk([k,...this.plugins])}withoutPlugins(){return new bk([])}}var qk=new bk;class NW{numChangedRows;constructor(k){this.numChangedRows=k}}class Hk{#k;constructor(k){this.#k=h(k)}modifyEnd(k){return new Hk({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}top(k,W){return new Hk({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}using(...k){return new O({...this.#k,queryNode:N.cloneWithUsing(this.#k.queryNode,Jk("Using",k))})}returning(k){return new Hk({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new Hk({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new Hk({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new Hk({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}}class O{#k;constructor(k){this.#k=h(k)}modifyEnd(k){return new O({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}top(k,W){return new O({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}whenMatched(){return this.#W([])}whenMatchedAnd(...k){return this.#W(k)}whenMatchedAndRef(k,W,$){return this.#W([k,W,$],!0)}#W(k,W){return new BW({...this.#k,queryNode:N.cloneWithWhen(this.#k.queryNode,bW({isMatched:!0},k,W))})}whenNotMatched(){return this.#h([])}whenNotMatchedAnd(...k){return this.#h(k)}whenNotMatchedAndRef(k,W,$){return this.#h([k,W,$],!0)}whenNotMatchedBySource(){return this.#h([],!1,!0)}whenNotMatchedBySourceAnd(...k){return this.#h(k,!1,!0)}whenNotMatchedBySourceAndRef(k,W,$){return this.#h([k,W,$],!0,!0)}returning(k){return new O({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new O({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new O({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new O({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}#h(k,W=!1,$=!1){let M={...this.#k,queryNode:N.cloneWithWhen(this.#k.queryNode,bW({isMatched:!1,bySource:$},k,W))};return new($?BW:vh)(M)}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new O({...this.#k})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new NW(W.numAffectedRows)]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}}class BW{#k;constructor(k){this.#k=h(k)}thenDelete(){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok("delete"))})}thenDoNothing(){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok("do nothing"))})}thenUpdate(k){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok(k(new jk({queryId:this.#k.queryId,executor:qk,queryNode:o.createWithoutTable()}))))})}thenUpdateSet(...k){return this.thenUpdate((W)=>W.set(...k))}}class vh{#k;constructor(k){this.#k=h(k)}thenDoNothing(){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok("do nothing"))})}thenInsertValues(k){let[W,$]=KW(k);return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok(w.cloneWith(w.createWithoutInto(),{columns:W,values:$})))})}}class Pk{#k;constructor(k){this.#k=h(k)}selectFrom(k){return nk({queryId:T(),executor:this.#k.executor,queryNode:Y.createFrom(n(k),this.#k.withNode)})}selectNoFrom(k){return nk({queryId:T(),executor:this.#k.executor,queryNode:Y.cloneWithSelections(Y.create(this.#k.withNode),A(k))})}insertInto(k){return new D({queryId:T(),executor:this.#k.executor,queryNode:w.create(F(k),this.#k.withNode)})}replaceInto(k){return new D({queryId:T(),executor:this.#k.executor,queryNode:w.create(F(k),this.#k.withNode,!0)})}deleteFrom(k){return new HW({queryId:T(),executor:this.#k.executor,queryNode:Dk.create(n(k),this.#k.withNode)})}updateTable(k){return new jk({queryId:T(),executor:this.#k.executor,queryNode:o.create(n(k),this.#k.withNode)})}mergeInto(k){return new Hk({queryId:T(),executor:this.#k.executor,queryNode:N.create(fW(k),this.#k.withNode)})}with(k,W){let $=OW(k,W);return new Pk({...this.#k,withNode:this.#k.withNode?tk.cloneWithExpression(this.#k.withNode,$):tk.create($)})}withRecursive(k,W){let $=OW(k,W);return new Pk({...this.#k,withNode:this.#k.withNode?tk.cloneWithExpression(this.#k.withNode,$):tk.create($,{recursive:!0})})}withPlugin(k){return new Pk({...this.#k,executor:this.#k.executor.withPlugin(k)})}withoutPlugins(){return new Pk({...this.#k,executor:this.#k.executor.withoutPlugins()})}withSchema(k){return new Pk({...this.#k,executor:this.#k.executor.withPluginAtFront(new YW(k))})}}function Ph(){return new Pk({executor:qk})}function Ah(k,W){return new Rk({joinNode:Kk.create(k,wk(W))})}function _h(){return new Ck({overNode:xk.create()})}function Jk(k,W){if(W.length===3)return K$(k,W[0],W[1],W[2]);else if(W.length===2)return M$(k,W[0],W[1]);else if(W.length===1)return G$(k,W[0]);else throw Error("not implemented")}function M$(k,W,$){return $(Ah(k,W)).toOperationNode()}function K$(k,W,$,M){return Kk.createWithOn(k,wk(W),m($,"=",M))}function G$(k,W){return Kk.create(k,wk(W))}var mh=h({is(k){return k.kind==="OffsetNode"},create(k){return h({kind:"OffsetNode",offset:k})}});var Rh=h({is(k){return k.kind==="GroupByItemNode"},create(k){return h({kind:"GroupByItemNode",groupBy:k})}});function fh(k){return k=_(k)?k(d()):k,Gk(k).map(Rh.create)}function Tk(k,W,$){if(_(W))W=W(XW());if(!j(W))W=[W];return W.map((M)=>Ch.create(k,p(M),$))}class Z{#k;constructor(k){this.#k=k}get expressionType(){return}as(k){return new zW(this,k)}or(...k){return new DW(hk.create(this.#k,L(k)))}and(...k){return new LW(x.create(this.#k,L(k)))}$castTo(){return new Z(this.#k)}$notNull(){return new Z(this.#k)}toOperationNode(){return this.#k}}class zW{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}toOperationNode(){return I.create(this.#k.toOperationNode(),z(this.#W)?this.#W.toOperationNode():J.create(this.#W))}}class DW{#k;constructor(k){this.#k=k}get expressionType(){return}as(k){return new zW(this,k)}or(...k){return new DW(hk.create(this.#k,L(k)))}$castTo(){return new DW(this.#k)}toOperationNode(){return Xk.create(this.#k)}}class LW{#k;constructor(k){this.#k=k}get expressionType(){return}as(k){return new zW(this,k)}and(...k){return new LW(x.create(this.#k,L(k)))}$castTo(){return new LW(this.#k)}toOperationNode(){return Xk.create(this.#k)}}var Sh=h({is(k){return k.kind==="FetchNode"},create(k,W){return{kind:"FetchNode",rowCount:Q.create(k),modifier:W}}});function Ih(k,W){if(!_k(k)&&!GW(k))throw Error(`Invalid fetch row count: ${k}`);if(!H$(W))throw Error(`Invalid fetch modifier: ${W}`);return Sh.create(k,W)}function H$(k){return k==="only"||k==="with ties"}var H;class xW{#k;constructor(k){this.#k=h(k)}get expressionType(){return}get isSelectQueryBuilder(){return!0}where(...k){return new H({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,L(k))})}whereRef(k,W,$){return new H({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,m(k,W,$))})}having(...k){return new H({...this.#k,queryNode:Y.cloneWithHaving(this.#k.queryNode,L(k))})}havingRef(k,W,$){return new H({...this.#k,queryNode:Y.cloneWithHaving(this.#k.queryNode,m(k,W,$))})}select(k){return new H({...this.#k,queryNode:Y.cloneWithSelections(this.#k.queryNode,A(k))})}distinctOn(k){return new H({...this.#k,queryNode:Y.cloneWithDistinctOn(this.#k.queryNode,Gk(k))})}modifyFront(k){return new H({...this.#k,queryNode:Y.cloneWithFrontModifier(this.#k.queryNode,a.createWithExpression(k.toOperationNode()))})}modifyEnd(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.createWithExpression(k.toOperationNode()))})}distinct(){return new H({...this.#k,queryNode:Y.cloneWithFrontModifier(this.#k.queryNode,a.create("Distinct"))})}forUpdate(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForUpdate",k?dk(k).map(F):void 0))})}forShare(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForShare",k?dk(k).map(F):void 0))})}forKeyShare(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForKeyShare",k?dk(k).map(F):void 0))})}forNoKeyUpdate(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForNoKeyUpdate",k?dk(k).map(F):void 0))})}skipLocked(){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("SkipLocked"))})}noWait(){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("NoWait"))})}selectAll(k){return new H({...this.#k,queryNode:Y.cloneWithSelections(this.#k.queryNode,R(k))})}innerJoin(...k){return this.#W("InnerJoin",k)}leftJoin(...k){return this.#W("LeftJoin",k)}rightJoin(...k){return this.#W("RightJoin",k)}fullJoin(...k){return this.#W("FullJoin",k)}crossJoin(...k){return this.#W("CrossJoin",k)}innerJoinLateral(...k){return this.#W("LateralInnerJoin",k)}leftJoinLateral(...k){return this.#W("LateralLeftJoin",k)}crossJoinLateral(...k){return this.#W("LateralCrossJoin",k)}crossApply(...k){return this.#W("CrossApply",k)}outerApply(...k){return this.#W("OuterApply",k)}#W(k,W){return new H({...this.#k,queryNode:K.cloneWithJoin(this.#k.queryNode,Jk(k,W))})}orderBy(...k){return new H({...this.#k,queryNode:K.cloneWithOrderByItems(this.#k.queryNode,B(k))})}groupBy(k){return new H({...this.#k,queryNode:Y.cloneWithGroupByItems(this.#k.queryNode,fh(k))})}limit(k){return new H({...this.#k,queryNode:Y.cloneWithLimit(this.#k.queryNode,Ik.create(X(k)))})}offset(k){return new H({...this.#k,queryNode:Y.cloneWithOffset(this.#k.queryNode,mh.create(X(k)))})}fetch(k,W="only"){return new H({...this.#k,queryNode:Y.cloneWithFetch(this.#k.queryNode,Ih(k,W))})}top(k,W){return new H({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}union(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("union",k,!1))})}unionAll(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("union",k,!0))})}intersect(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("intersect",k,!1))})}intersectAll(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("intersect",k,!0))})}except(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("except",k,!1))})}exceptAll(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("except",k,!0))})}as(k){return new jh(this,k)}clearSelect(){return new H({...this.#k,queryNode:Y.cloneWithoutSelections(this.#k.queryNode)})}clearWhere(){return new H({...this.#k,queryNode:K.cloneWithoutWhere(this.#k.queryNode)})}clearLimit(){return new H({...this.#k,queryNode:Y.cloneWithoutLimit(this.#k.queryNode)})}clearOffset(){return new H({...this.#k,queryNode:Y.cloneWithoutOffset(this.#k.queryNode)})}clearOrderBy(){return new H({...this.#k,queryNode:K.cloneWithoutOrderBy(this.#k.queryNode)})}clearGroupBy(){return new H({...this.#k,queryNode:Y.cloneWithoutGroupBy(this.#k.queryNode)})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new H({...this.#k})}$castTo(){return new H(this.#k)}$narrowType(){return new H(this.#k)}$assertType(){return new H(this.#k)}$asTuple(){return new Z(this.toOperationNode())}$asScalar(){return new Z(this.toOperationNode())}withPlugin(k){return new H({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile();return(await this.#k.executor.executeQuery(k)).rows}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new H({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}H=xW;function nk(k){return new xW(k)}class jh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return I.create(this.#k.toOperationNode(),J.create(this.#W))}}var e=h({is(k){return k.kind==="AggregateFunctionNode"},create(k,W=[]){return h({kind:"AggregateFunctionNode",func:k,aggregated:W})},cloneWithDistinct(k){return h({...k,distinct:!0})},cloneWithOrderBy(k,W,$=!1){let M=$?"withinGroup":"orderBy";return h({...k,[M]:k[M]?$k.cloneWithItems(k[M],W):$k.create(W)})},cloneWithFilter(k,W){return h({...k,filter:k.filter?C.cloneWithOperation(k.filter,"And",W):C.create(W)})},cloneWithOrFilter(k,W){return h({...k,filter:k.filter?C.cloneWithOperation(k.filter,"Or",W):C.create(W)})},cloneWithOver(k,W){return h({...k,over:W})}});var cW=h({is(k){return k.kind==="FunctionNode"},create(k,W){return h({kind:"FunctionNode",func:k,arguments:W})}});class b{#k;constructor(k){this.#k=h(k)}get expressionType(){return}as(k){return new Eh(this,k)}distinct(){return new b({...this.#k,aggregateFunctionNode:e.cloneWithDistinct(this.#k.aggregateFunctionNode)})}orderBy(...k){return new b({...this.#k,aggregateFunctionNode:K.cloneWithOrderByItems(this.#k.aggregateFunctionNode,B(k))})}clearOrderBy(){return new b({...this.#k,aggregateFunctionNode:K.cloneWithoutOrderBy(this.#k.aggregateFunctionNode)})}withinGroupOrderBy(...k){return new b({...this.#k,aggregateFunctionNode:e.cloneWithOrderBy(this.#k.aggregateFunctionNode,B(k),!0)})}filterWhere(...k){return new b({...this.#k,aggregateFunctionNode:e.cloneWithFilter(this.#k.aggregateFunctionNode,L(k))})}filterWhereRef(k,W,$){return new b({...this.#k,aggregateFunctionNode:e.cloneWithFilter(this.#k.aggregateFunctionNode,m(k,W,$))})}over(k){let W=_h();return new b({...this.#k,aggregateFunctionNode:e.cloneWithOver(this.#k.aggregateFunctionNode,(k?k(W):W).toOperationNode())})}$call(k){return k(this)}$castTo(){return new b(this.#k)}$notNull(){return new b(this.#k)}toOperationNode(){return this.#k.aggregateFunctionNode}}class Eh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}toOperationNode(){return I.create(this.#k.toOperationNode(),J.create(this.#W))}}function Oh(){let k=($,M)=>{return new Z(cW.create($,Gk(M??[])))},W=($,M)=>{return new b({aggregateFunctionNode:e.create($,M?Gk(M):void 0)})};return Object.assign(k,{agg:W,avg($){return W("avg",[$])},coalesce(...$){return k("coalesce",$)},count($){return W("count",[$])},countAll($){return new b({aggregateFunctionNode:e.create("count",R($))})},max($){return W("max",[$])},min($){return W("min",[$])},sum($){return W("sum",[$])},any($){return k("any",[$])},jsonAgg($){return new b({aggregateFunctionNode:e.create("json_agg",[V($)?F($):$.toOperationNode()])})},toJson($){return new Z(cW.create("to_json",[V($)?F($):$.toOperationNode()]))}})}var bh=h({is(k){return k.kind==="UnaryOperationNode"},create(k,W){return h({kind:"UnaryOperationNode",operator:k,operand:W})}});function Qh(k,W){return bh.create(y.create(k),f(W))}var l=h({is(k){return k.kind==="CaseNode"},create(k){return h({kind:"CaseNode",value:k})},cloneWithWhen(k,W){return h({...k,when:h(k.when?[...k.when,W]:[W])})},cloneWithThen(k,W){return h({...k,when:k.when?h([...k.when.slice(0,-1),Mk.cloneWithResult(k.when[k.when.length-1],W)]):void 0})},cloneWith(k,W){return h({...k,...W})}});class yW{#k;constructor(k){this.#k=h(k)}when(...k){return new gW({...this.#k,node:l.cloneWithWhen(this.#k.node,Mk.create(L(k)))})}}class gW{#k;constructor(k){this.#k=h(k)}then(k){return new Nh({...this.#k,node:l.cloneWithThen(this.#k.node,WW(k)?Bk(k):X(k))})}}class Nh{#k;constructor(k){this.#k=h(k)}when(...k){return new gW({...this.#k,node:l.cloneWithWhen(this.#k.node,Mk.create(L(k)))})}else(k){return new Bh({...this.#k,node:l.cloneWith(this.#k.node,{else:WW(k)?Bk(k):X(k)})})}end(){return new Z(l.cloneWith(this.#k.node,{isStatement:!1}))}endCase(){return new Z(l.cloneWith(this.#k.node,{isStatement:!0}))}}class Bh{#k;constructor(k){this.#k=h(k)}end(){return new Z(l.cloneWith(this.#k.node,{isStatement:!1}))}endCase(){return new Z(l.cloneWith(this.#k.node,{isStatement:!0}))}}var JW=h({is(k){return k.kind==="JSONOperatorChainNode"},create(k){return h({kind:"JSONOperatorChainNode",operator:k,values:h([])})},cloneWithValue(k,W){return h({...k,values:h([...k.values,W])})}});var tW=h({is(k){return k.kind==="JSONPathLegNode"},create(k,W){return h({kind:"JSONPathLegNode",type:k,value:W})}});var Uk=h({is(k){return k.kind==="JSONPathNode"},create(k){return h({kind:"JSONPathNode",inOperator:k,pathLegs:h([])})},cloneWithLeg(k,W){return h({...k,pathLegs:h([...k.pathLegs,W])})}});var Qk=h({is(k){return k.kind==="JSONReferenceNode"},create(k,W){return h({kind:"JSONReferenceNode",reference:k,traversal:W})},cloneWithTraversal(k,W){return h({...k,traversal:W})}});var Z$=/^#-\d+$/;class ik{#k;constructor(k){this.#k=k}at(k){if(typeof k!=="number"&&typeof k!=="string"||typeof k==="number"&&!Number.isInteger(k)||typeof k==="string"&&k!=="last"&&!Z$.test(k))throw Error(`Unexpected index value in .at(...): ${k}`);return this.#W("ArrayLocation",k)}key(k){return this.#W("Member",k)}#W(k,W){if(Qk.is(this.#k))return new uk(Qk.cloneWithTraversal(this.#k,Uk.is(this.#k.traversal)?Uk.cloneWithLeg(this.#k.traversal,tW.create(k,W)):JW.cloneWithValue(this.#k.traversal,Q.createImmediate(W))));return new uk(Uk.cloneWithLeg(this.#k,tW.create(k,W)))}}class uk extends ik{#k;constructor(k){super(k);this.#k=k}get expressionType(){return}as(k){return new xh(this,k)}$castTo(){return new uk(this.#k)}$notNull(){return new uk(this.#k)}toOperationNode(){return this.#k}}class xh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}toOperationNode(){return I.create(this.#k.toOperationNode(),z(this.#W)?this.#W.toOperationNode():J.create(this.#W))}}var nW=h({is(k){return k.kind==="TupleNode"},create(k){return h({kind:"TupleNode",values:h(k)})}});var Y$=["varchar","char","text","integer","int2","int4","int8","smallint","bigint","boolean","real","double precision","float4","float8","decimal","numeric","binary","bytea","date","datetime","time","timetz","timestamp","timestamptz","serial","bigserial","uuid","json","jsonb","blob","varbinary","int4range","int4multirange","int8range","int8multirange","numrange","nummultirange","tsrange","tsmultirange","tstzrange","tstzmultirange","daterange","datemultirange"],X$=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],ch=h({is(k){return k.kind==="DataTypeNode"},create(k){return h({kind:"DataTypeNode",dataType:k})}});function yh(k){if(Y$.includes(k))return!0;if(X$.some((W)=>W.test(k)))return!0;return!1}function gh(k){if(z(k))return k.toOperationNode();if(yh(k))return ch.create(k);throw Error(`invalid column data type ${JSON.stringify(k)}`)}var th=h({is(k){return k.kind==="CastNode"},create(k,W){return h({kind:"CastNode",expression:k,dataType:W})}});function XW(k=qk){function W(G,q,vk){return new Z(hW(G,q,vk))}function $(G,q){return new Z(Qh(G,q))}let M=Object.assign(W,{fn:void 0,eb:void 0,selectFrom(G){return nk({queryId:T(),executor:k,queryNode:Y.createFrom(n(G))})},case(G){return new yW({node:l.create(c(G)?void 0:f(G))})},ref(G,q){if(c(q))return new Z(t(G));return new ik(nh(G,q))},jsonPath(){return new ik(Uk.create())},table(G){return new Z(F(G))},val(G){return new Z(X(G))},refTuple(...G){return new Z(nW.create(G.map(f)))},tuple(...G){return new Z(nW.create(G.map(X)))},lit(G){return new Z(Bk(G))},unary:$,not(G){return $("not",G)},exists(G){return $("exists",G)},neg(G){return $("-",G)},between(G,q,vk){return new Z(Yk.create(f(G),y.create("between"),x.create(X(q),X(vk))))},betweenSymmetric(G,q,vk){return new Z(Yk.create(f(G),y.create("between symmetric"),x.create(X(q),X(vk))))},and(G){if(j(G))return new Z(mk(G,"and"));return new Z(UW(G,"and"))},or(G){if(j(G))return new Z(mk(G,"or"));return new Z(UW(G,"or"))},parens(...G){let q=L(G);if(Xk.is(q))return new Z(q);else return new Z(Xk.create(q))},cast(G,q){return new Z(th.create(f(G),gh(q)))},withSchema(G){return XW(k.withPluginAtFront(new YW(G)))}});return M.fn=Oh(),M.eb=M,M}function d(k){return XW()}function p(k){if(z(k))return k.toOperationNode();else if(_(k))return k(d()).toOperationNode();throw Error(`invalid expression: ${JSON.stringify(k)}`)}function MW(k){if(z(k))return k.toOperationNode();else if(_(k))return k(d()).toOperationNode();throw Error(`invalid aliased expression: ${JSON.stringify(k)}`)}function Wk(k){return ok(k)||iW(k)||_(k)}function _W(k){if(V(k))return t(k);return k.toOperationNode()}function Gk(k){if(j(k))return k.map((W)=>f(W));else return[f(k)]}function f(k){if(Wk(k))return p(k);return _W(k)}function nh(k,W){let $=t(k);if(dW(W))return Qk.create($,JW.create(y.create(W)));let M=W.slice(0,-1);if(dW(M))return Qk.create($,Uk.create(y.create(M)));throw Error(`Invalid JSON operator: ${W}`)}function t(k){if(!k.includes("."))return Ak.create(S.create(k));let $=k.split(".").map(uW);if($.length===3)return L$($);if($.length===2)return z$($);throw Error(`invalid column reference ${k}`)}function Zh(k){if(k.includes(" as ")){let[$,M]=k.split(" as ").map(uW);return I.create(t($),J.create(M))}else return t(k)}function D$(k){return S.create(k)}function R3(k){if(k.includes(" ")){let[$,M]=k.split(" ").map(uW);if(!RW(M))throw Error(`invalid order direction "${M}" next to "${$}"`);return B([$,M])[0]}else return D$(k)}function L$(k){let[W,$,M]=k;return Ak.create(S.create(M),zk.createWithSchema(W,$))}function z$(k){let[W,$]=k;return Ak.create(S.create($),zk.create(W))}function uW(k){return k.trim()}class lk{#k;constructor(k){this.#k=h(k)}get expressionType(){return}get isRawBuilder(){return!0}as(k){return new dh(this,k)}$castTo(){return new lk({...this.#k})}$notNull(){return new lk(this.#k)}withPlugin(k){return new lk({...this.#k,plugins:this.#k.plugins!==void 0?h([...this.#k.plugins,k]):h([k])})}toOperationNode(){return this.#h(this.#W())}compile(k){return this.#$(this.#W(k))}async execute(k){let W=this.#W(k);return W.executeQuery(this.#$(W))}#W(k){let W=k!==void 0?k.getExecutor():qk;return this.#k.plugins!==void 0?W.withPlugins(this.#k.plugins):W}#h(k){return k.transformQuery(this.#k.rawNode,this.#k.queryId)}#$(k){return k.compileQuery(this.#h(k),this.#k.queryId)}}function Zk(k){return new lk(k)}class dh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}get rawBuilder(){return this.#k}toOperationNode(){return I.create(this.#k.toOperationNode(),z(this.#W)?this.#W.toOperationNode():J.create(this.#W))}}var J$=Object.assign((k,...W)=>{return Zk({queryId:T(),rawNode:v.create(k,W?.map(uh)??[])})},{ref(k){return Zk({queryId:T(),rawNode:v.createWithChild(t(k))})},val(k){return Zk({queryId:T(),rawNode:v.createWithChild(X(k))})},value(k){return this.val(k)},table(k){return Zk({queryId:T(),rawNode:v.createWithChild(F(k))})},id(...k){let W=Array(k.length+1).fill(".");return W[0]="",W[W.length-1]="",Zk({queryId:T(),rawNode:v.create(W,k.map(J.create))})},lit(k){return Zk({queryId:T(),rawNode:v.createWithChild(Q.createImmediate(k))})},literal(k){return this.lit(k)},raw(k){return Zk({queryId:T(),rawNode:v.createWithSql(k)})},join(k,W=J$`, `){let $=Array(Math.max(2*k.length-1,0)),M=W.toOperationNode();for(let G=0;G<k.length;++G)if($[2*G]=uh(k[G]),G!==k.length-1)$[2*G+1]=M;return Zk({queryId:T(),rawNode:v.createWithChildren($)})}});function uh(k){if(z(k))return k.toOperationNode();return X(k)}var l3=h({raw(k,W=[]){return h({sql:k,query:v.createWithSql(k),parameters:h(W),queryId:T()})}});
|
|
3
|
+
export{z as Uc,S as Vc,pk as Wc,ah as Xc,t as Yc,D$ as Zc,R3 as _c,rk as $c,Q as ad,L as bd,K as cd,Y as dd,Vh as ed,T as fd,ZW as gd,Th as hd,QW as id,Pk as jd,Oh as kd,l as ld,yW as md,gh as nd,p as od,oh as pd,F as qd,J$ as rd,l3 as sd};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
export{z as
|
|
1
|
+
import{rg as f}from"./chunk-z5p39kpk.js";import{ph as b,qh as q}from"./chunk-q0dhm16d.js";function z(){return q("div",{className:"flex h-screen flex-col bg-background min-h-0",children:[q("div",{className:"flex h-14 items-center justify-between border-b px-6 shrink-0",children:[q("div",{className:"flex items-center gap-2",children:[b(f,{className:"h-4 w-24"}),b("span",{className:"text-muted-foreground",children:"/"}),b(f,{className:"h-4 w-32"})]}),q("div",{className:"flex items-center gap-2",children:[b(f,{className:"h-8 w-8 rounded-md"}),b(f,{className:"h-8 w-20 rounded-md"})]})]}),q("div",{className:"flex flex-1 overflow-hidden",children:[q("div",{className:"w-[240px] border-r p-4 space-y-4 hidden md:block shrink-0",children:[q("div",{className:"flex items-center gap-2",children:[b(f,{className:"h-4 w-4 rounded"}),b(f,{className:"h-4 w-24"})]}),q("div",{className:"pl-4 space-y-3",children:[q("div",{className:"flex items-center gap-2",children:[b(f,{className:"h-3 w-3 rounded"}),b(f,{className:"h-3 w-28"})]}),q("div",{className:"flex items-center gap-2",children:[b(f,{className:"h-3 w-3 rounded"}),b(f,{className:"h-3 w-20"})]}),q("div",{className:"flex items-center gap-2",children:[b(f,{className:"h-3 w-3 rounded"}),b(f,{className:"h-3 w-24"})]})]})]}),q("div",{className:"flex-1 p-6 space-y-6 overflow-y-auto",children:[q("div",{className:"flex items-center justify-between border-b pb-4",children:[q("div",{className:"flex items-center gap-4",children:[b(f,{className:"h-5 w-40"}),b(f,{className:"h-4 w-20"})]}),q("div",{className:"flex items-center gap-2",children:[b(f,{className:"h-8 w-8 rounded"}),b(f,{className:"h-8 w-8 rounded"}),b(f,{className:"h-8 w-32 rounded"})]})]}),q("div",{className:"space-y-4",children:[b("div",{className:"flex items-center gap-2",children:b(f,{className:"h-4 w-24"})}),b("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5",children:Array.from({length:10}).map((w,v)=>q("div",{className:"flex flex-col rounded-lg border bg-card p-3 space-y-3",children:[b(f,{className:"aspect-square w-full rounded-md"}),q("div",{className:"space-y-2",children:[b(f,{className:"h-4 w-3/4"}),q("div",{className:"flex justify-between items-center",children:[b(f,{className:"h-3 w-1/4"}),b(f,{className:"h-3 w-1/3"})]})]})]},v))})]})]})]})]})}function A(){return q("div",{className:"h-screen flex flex-col bg-background",children:[q("div",{className:"flex h-14 items-center justify-between border-b px-6 shrink-0",children:[q("div",{className:"flex items-center gap-2",children:[b(f,{className:"h-4 w-16"}),b("span",{className:"text-muted-foreground",children:"/"}),b(f,{className:"h-4 w-28"}),b("span",{className:"text-muted-foreground",children:"/"}),b(f,{className:"h-4 w-32"})]}),b("div",{className:"flex items-center gap-2",children:b(f,{className:"h-8 w-20 rounded"})})]}),q("div",{className:"flex flex-1 overflow-hidden",children:[q("div",{className:"w-[280px] border-r p-4 flex flex-col gap-4 shrink-0 hidden md:flex",children:[b(f,{className:"h-5 w-24"}),b("div",{className:"space-y-3 flex-1 overflow-y-auto",children:Array.from({length:4}).map((w,v)=>q("div",{className:"flex gap-3 p-2 rounded border",children:[b(f,{className:"h-12 w-12 rounded bg-muted shrink-0"}),q("div",{className:"space-y-2 flex-1",children:[b(f,{className:"h-3 w-2/3"}),b(f,{className:"h-2 w-1/2"})]})]},v))})]}),q("div",{className:"flex-1 bg-muted/20 p-6 flex flex-col justify-between relative min-w-0",children:[b("div",{className:"flex-1 flex items-center justify-center",children:b(f,{className:"w-full max-w-4xl aspect-video rounded-lg shadow-lg"})}),q("div",{className:"mt-4 flex items-center justify-between shrink-0",children:[q("div",{className:"flex items-center gap-4",children:[b(f,{className:"h-8 w-8 rounded-full"}),b(f,{className:"h-4 w-32"})]}),b(f,{className:"h-4 w-24"})]})]}),q("div",{className:"w-[360px] border-l p-4 flex flex-col gap-6 shrink-0 hidden lg:flex bg-card",children:[q("div",{className:"space-y-4",children:[b(f,{className:"h-5 w-32"}),b("div",{className:"space-y-3",children:Array.from({length:3}).map((w,v)=>q("div",{className:"flex justify-between items-center py-1 border-b",children:[b(f,{className:"h-3 w-20"}),b(f,{className:"h-3 w-32"})]},v))})]}),q("div",{className:"flex-1 flex flex-col gap-4",children:[b(f,{className:"h-5 w-24"}),b("div",{className:"space-y-3 flex-1 overflow-y-auto",children:Array.from({length:3}).map((w,v)=>q("div",{className:"flex gap-3 p-3 rounded-lg border bg-muted/10",children:[b(f,{className:"h-8 w-8 rounded-full shrink-0"}),q("div",{className:"space-y-2 flex-1",children:[q("div",{className:"flex justify-between",children:[b(f,{className:"h-3 w-24"}),b(f,{className:"h-2 w-12"})]}),b(f,{className:"h-3 w-full"}),b(f,{className:"h-3 w-5/6"})]})]},v))})]})]})]})]})}
|
|
2
|
+
export{z as Af,A as Bf};
|