// @bun
var{defineProperty:x,getOwnPropertyNames:C,getOwnPropertyDescriptor:D}=Object,E=Object.prototype.hasOwnProperty;function F(b){return this[b]}var J=(b)=>{var h=(B??=new WeakMap).get(b),j;if(h)return h;if(h=x({},"__esModule",{value:!0}),b&&typeof b==="object"||typeof b==="function"){for(var q of C(b))if(!E.call(h,q))x(h,q,{get:F.bind(b,q),enumerable:!(j=D(b,q))||j.enumerable})}return B.set(b,h),h},B;var G=(b)=>b;function H(b,h){this[b]=G.bind(null,h)}var K=(b,h)=>{for(var j in h)x(b,j,{get:h[j],enumerable:!0,configurable:!0,set:H.bind(h,j)})};var L=(b,h)=>()=>(b&&(h=b(b=0)),h);class I{spec;constructor(b){this.spec=b}generate(b){let{primary:h}=this.spec.source,j=b.pagination?.page??1,q=b.pagination?.pageSize??20,v=(j-1)*q,A=q,w={skip:v,take:A,...b.filters};if(b.search)w.search=b.search;if(b.sort)w.orderBy={[b.sort.field]:b.sort.direction};return{operationName:h.key,input:w,meta:{pagination:{page:j,pageSize:q,skip:v,take:A},sorting:b.sort}}}validateParams(b){let h=[];if(b.filters&&this.spec.view.filters){for(let j of Object.keys(b.filters))if(!this.spec.view.filters.find((v)=>v.key===j))h.push(`Unknown filter key: ${j}`)}if(b.sort){let j=this.spec.view.fields.find((q)=>q.key===b.sort?.field);if(!j)h.push(`Unknown sort field: ${b.sort.field}`);else if(j.sortable===!1)h.push(`Field is not sortable: ${b.sort.field}`)}return h}}export{I as DataViewQueryGenerator};
