var p=function(i,t,n,c){var o=arguments.length,e=o<3?t:c===null?c=Object.getOwnPropertyDescriptor(t,n):c,u;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")e=Reflect.decorate(i,t,n,c);else for(var a=i.length-1;a>=0;a--)if(u=i[a])e=(o<3?u(e):o>3?u(t,n,e):u(t,n))||e;return o>3&&e&&Object.defineProperty(t,n,e),e};var h=function(i,t){if(typeof Reflect==="object"&&typeof Reflect.metadata==="function")return Reflect.metadata(i,t)};var d=function(i,t,n,c){function o(e){return e instanceof n?e:new n(function(u){u(e)})}return new(n||(n=Promise))(function(e,u){function a(s){try{r(c.next(s))}catch(f){u(f)}}function l(s){try{r(c["throw"](s))}catch(f){u(f)}}function r(s){s.done?e(s.value):o(s.value).then(a,l)}r((c=c.apply(i,t||[])).next())})};var b=function(i,t){var n={label:0,sent:function(){if(e[0]&1)throw e[1];return e[1]},trys:[],ops:[]},c,o,e,u=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return u.next=a(0),u["throw"]=a(1),u["return"]=a(2),typeof Symbol==="function"&&(u[Symbol.iterator]=function(){return this}),u;function a(r){return function(s){return l([r,s])}}function l(r){if(c)throw new TypeError("Generator is already executing.");while(u&&(u=0,r[0]&&(n=0)),n)try{if(c=1,o&&(e=r[0]&2?o["return"]:r[0]?o["throw"]||((e=o["return"])&&e.call(o),0):o.next)&&!(e=e.call(o,r[1])).done)return e;if(o=0,e)r=[r[0]&2,e.value];switch(r[0]){case 0:case 1:e=r;break;case 4:n.label++;return{value:r[1],done:false};case 5:n.label++;o=r[1];r=[0];continue;case 7:r=n.ops.pop();n.trys.pop();continue;default:if(!(e=n.trys,e=e.length>0&&e[e.length-1])&&(r[0]===6||r[0]===2)){n=0;continue}if(r[0]===3&&(!e||r[1]>e[0]&&r[1]<e[3])){n.label=r[1];break}if(r[0]===6&&n.label<e[1]){n.label=e[1];e=r;break}if(e&&n.label<e[2]){n.label=e[2];n.ops.push(r);break}if(e[2])n.ops.pop();n.trys.pop();continue}r=t.call(i,n)}catch(s){r=[6,s];o=0}finally{c=e=0}if(r[0]&5)throw r[1];return{value:r[0]?r[1]:void 0,done:true}}};import{AggregateBuilder as y}from"@alipay/faas-db-builder";import{WrapCallback as m}from"../decorator";import{ResponseUtil as g}from"../utils";var w=function(){function i(t,n){this.collectionName=t;this.options=n;this.builder=new y(t)}i.prototype.addFields=function(t){this.builder.addFields(t);return this};i.prototype.count=function(t){this.builder.count(t);return this};i.prototype.match=function(t){this.builder.match(t);return this};i.prototype.group=function(t){this.builder.group(t);return this};i.prototype.sample=function(t){this.builder.sample(t);return this};i.prototype.lookup=function(t){this.builder.lookup(t);return this};i.prototype.project=function(t){this.builder.project(t);return this};i.prototype.replaceRoot=function(t){this.builder.replaceRoot(t);return this};i.prototype.sort=function(t){this.builder.sort(t);return this};i.prototype.limit=function(t){this.builder.limit(t);return this};i.prototype.skip=function(t){this.builder.skip(t);return this};i.prototype.unwind=function(t){this.builder.unwind(t);return this};i.prototype.geoNear=function(t){this.builder.geoNear(t);return this};i.prototype.bucket=function(t){this.builder.bucket(t);return this};i.prototype.bucketAuto=function(t){this.builder.bucketAuto(t);return this};i.prototype.sortByCount=function(t){this.builder.sortByCount(t);return this};i.prototype.end=function(){return d(this,void 0,void 0,function(){var t,n,c,o;return b(this,function(e){switch(e.label){case 0:t=this.builder.end().options;n="POST";c="".concat(this.getCollectionPath(),"?aggregate");return[4,this.options.httpclient.request({method:n,path:c,data:t})];case 1:o=e.sent();return[2,g.handleResponse(o)]}})})};i.prototype.getCollectionPath=function(){return"/".concat(this.options.databaseName||"faas","/").concat(this.collectionName)};p([m(),h("design:type",Function),h("design:paramtypes",[]),h("design:returntype",Promise)],i.prototype,"end",null);return i}();export{w as Aggregate};