"use strict";var P=Object.defineProperty;var i=(n,a)=>P(n,"name",{value:a,configurable:!0});const m=class m{constructor(a){this.options=a,this.createQueryExecutor=r=>t=>async s=>{const e=typeof s=="function"?s(this.createSqlHelper()):s;if(typeof t.params=="function"){const f=await r(e),y=i(async p=>{const u=this.parseAndStringifyParams({...t,params:p}),h=await f(u);return t.resultSchema?.parse(h)??h},"executeAndParseResult");return async function*(){for await(const p of t.params())yield await y(p)}()}if(Array.isArray(t.params)){const f=await r(e),y=this.parseAndStringifyParams(t),p=i(async u=>{const h=await f(u);return t.resultSchema?.parse(h)??h},"executeAndParseResult");return async function*(){for await(const u of y)yield await p(u)}()}const o=this.parseAndStringifyParams(t),c=await r(e)(o);return t.resultSchema?.parse(c)??c},this.createIterativeExecutor=r=>t=>s=>{const e=typeof s=="function"?s(this.createSqlHelper()):s,o=this.parseAndStringifyParams(t);return async function*(){for await(const c of r(e)(o)())yield t.resultSchema?.parse(c)??c}()},this.parseAndStringifyParams=r=>{if(typeof r.params>"u")return;const t=r.paramsSchema?.parse(r.params)??r.params;return this.options.shouldStringifyObjectParams?Array.isArray(t)?t.map(s=>l(s)):l(t):t},this.createSqlHelper=()=>({sql:i((r,...t)=>this.processLiteralExpressions(r,t),"sql"),sqlCond:i((r,t,s="")=>`\xA7${r?t:s}`,"sqlCond"),sqlRaw:i(r=>`\xA7${r}`,"sqlRaw")}),this.processLiteralExpressions=(r,t)=>r.reduce((s,e,o)=>{const c=t[o];return`${s}${e}${c!==void 0?this.processLiteralExpression(c):""}`},""),this.processLiteralExpression=r=>{if(typeof r=="object"){const t=Object.entries(r);if(t.length===1){const[s,e]=t[0];return`${s} (${Array.isArray(e)?e.join(", "):e})`}}if(typeof r=="string")switch(!0){case r.startsWith("@"):{const t=r.indexOf(" $.");if(t!==-1)return`'${r.slice(t+1)}'`;let s=r;const e=s.indexOf(" ->");if(e!==-1){const o=x(s.slice(e+1));s=`${s.slice(0,e)}${o}`}return s.endsWith("-")?s.split(".")[1]?.slice(0,-1)??"":s.slice(1)}case r.startsWith("$"):case r.startsWith("\xA7"):return r.slice(1);default:return r}return String(r)},this.first=this.createQueryExecutor(this.options.adapter.queryFirst),this.firstOrThrow=this.createQueryExecutor(this.options.adapter.queryFirstOrThrow),this.all=this.createQueryExecutor(this.options.adapter.queryAll),this.iterate=this.createIterativeExecutor(this.options.adapter.queryIterate)}};i(m,"SchemQl");let d=m;const l=i(n=>Object.entries(n).reduce((a,[r,t])=>(a[r]=t!==null&&typeof t=="object"?JSON.stringify(t):t,a),{}),"stringifyObjectParams"),x=i(n=>n.split(/(?=->)/).reduce((a,r)=>{const t=r.startsWith("->>")?"->>":"->",s=r.replace(t,"");return`${a}${t}'${s}'`},""),"quotifyJsonPath"),A=i((n,a)=>{if(typeof n=="string")try{return JSON.parse(n)}catch(r){a.addIssue({code:"custom",message:r.message})}return n},"parseJsonPreprocessor");exports.SchemQl=d,exports.parseJsonPreprocessor=A;