"use strict";var __decorate=this&&this.__decorate||function(i,t,r,a){var o=arguments.length,e=o<3?t:a===null?a=Object.getOwnPropertyDescriptor(t,r):a,u;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")e=Reflect.decorate(i,t,r,a);else for(var c=i.length-1;c>=0;c--)if(u=i[c])e=(o<3?u(e):o>3?u(t,r,e):u(t,r))||e;return o>3&&e&&Object.defineProperty(t,r,e),e};var __metadata=this&&this.__metadata||function(i,t){if(typeof Reflect==="object"&&typeof Reflect.metadata==="function")return Reflect.metadata(i,t)};var __awaiter=this&&this.__awaiter||function(i,t,r,a){function o(e){return e instanceof r?e:new r(function(u){u(e)})}return new(r||(r=Promise))(function(e,u){function c(s){try{n(a.next(s))}catch(f){u(f)}}function l(s){try{n(a["throw"](s))}catch(f){u(f)}}function n(s){s.done?e(s.value):o(s.value).then(c,l)}n((a=a.apply(i,t||[])).next())})};var __generator=this&&this.__generator||function(i,t){var r={label:0,sent:function(){if(e[0]&1)throw e[1];return e[1]},trys:[],ops:[]},a,o,e,u=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return u.next=c(0),u["throw"]=c(1),u["return"]=c(2),typeof Symbol==="function"&&(u[Symbol.iterator]=function(){return this}),u;function c(n){return function(s){return l([n,s])}}function l(n){if(a)throw new TypeError("Generator is already executing.");while(u&&(u=0,n[0]&&(r=0)),r)try{if(a=1,o&&(e=n[0]&2?o["return"]:n[0]?o["throw"]||((e=o["return"])&&e.call(o),0):o.next)&&!(e=e.call(o,n[1])).done)return e;if(o=0,e)n=[n[0]&2,e.value];switch(n[0]){case 0:case 1:e=n;break;case 4:r.label++;return{value:n[1],done:false};case 5:r.label++;o=n[1];n=[0];continue;case 7:n=r.ops.pop();r.trys.pop();continue;default:if(!(e=r.trys,e=e.length>0&&e[e.length-1])&&(n[0]===6||n[0]===2)){r=0;continue}if(n[0]===3&&(!e||n[1]>e[0]&&n[1]<e[3])){r.label=n[1];break}if(n[0]===6&&r.label<e[1]){r.label=e[1];e=n;break}if(e&&r.label<e[2]){r.label=e[2];r.ops.push(n);break}if(e[2])r.ops.pop();r.trys.pop();continue}n=t.call(i,r)}catch(s){n=[6,s];o=0}finally{a=e=0}if(n[0]&5)throw n[1];return{value:n[0]?n[1]:void 0,done:true}}};Object.defineProperty(exports,"__esModule",{value:true});exports.Aggregate=void 0;var faas_db_builder_1=require("@alipay/faas-db-builder");var decorator_1=require("../decorator");var utils_1=require("../utils");var Aggregate=function(){function i(t,r){this.collectionName=t;this.options=r;this.builder=new faas_db_builder_1.AggregateBuilder(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 __awaiter(this,void 0,void 0,function(){var t,r,a,o;return __generator(this,function(e){switch(e.label){case 0:t=this.builder.end().options;r="POST";a="".concat(this.getCollectionPath(),"?aggregate");return[4,this.options.httpclient.request({method:r,path:a,data:t})];case 1:o=e.sent();return[2,utils_1.ResponseUtil.handleResponse(o)]}})})};i.prototype.getCollectionPath=function(){return"/".concat(this.options.databaseName||"faas","/").concat(this.collectionName)};__decorate([(0,decorator_1.WrapCallback)(),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",Promise)],i.prototype,"end",null);return i}();exports.Aggregate=Aggregate;