import e from"@arcgis/core/core/Collection";import{QueryOptions as s}from"../tasks/query/QueryOptions.js";import{checkArg as i}from"../utilities/checkArg.js";import{count as t,query as o}from"../utilities/query.js";import{cancelify as r}from"./Cancellable.js";export function executeQuery(t,l,a,c){i("where",t).isNotMissing(),i("source",l).isNotMissing(),i("queryable",a).isNotMissing();const n={...s.DEFAULTS,...s.fromFeatureSource(l),...c};return i("options.maxResults",n.maxResults).satisfies((e=>null==e||e>0)),async function*(){let s;if(e.isCollection(a)||Array.isArray(a))s=e.isCollection(a)?a.toArray():a.slice();else{s=(await a).features,s.forEach((e=>e.popupTemplate=e.getEffectivePopupTemplate())),s=s.slice()}const i=r(o(t,l,s,n),n.cancelToken);let c=await i;c=c.slice(0,n.maxResults||c.length),yield*c}()}export async function executeCount(o,l,a,c){i("where",o).isNotMissing(),i("source",l).isNotMissing(),i("queryable",a).isNotMissing();const n={...s.DEFAULTS,...s.fromFeatureSource(l),...c},{maxResults:u,cancelToken:f}=n;let m;if(i("options.maxResults",u).satisfies((e=>null==e||e>0)),e.isCollection(a)||Array.isArray(a))m=e.isCollection(a)?a.toArray():a.slice();else{m=(await a).features.slice()}let p=await r(t(o,m,n),f);return u>0&&p>u&&(p=u),{source:l,count:p}}