"use strict";var __assign=this&&this.__assign||function(){__assign=Object.assign||function(o){for(var a,n=1,u=arguments.length;n<u;n++){a=arguments[n];for(var r in a)if(Object.prototype.hasOwnProperty.call(a,r))o[r]=a[r]}return o};return __assign.apply(this,arguments)};var __awaiter=this&&this.__awaiter||function(o,a,n,u){function r(t){return t instanceof n?t:new n(function(i){i(t)})}return new(n||(n=Promise))(function(t,i){function s(c){try{e(u.next(c))}catch(f){i(f)}}function l(c){try{e(u["throw"](c))}catch(f){i(f)}}function e(c){c.done?t(c.value):r(c.value).then(s,l)}e((u=u.apply(o,a||[])).next())})};var __generator=this&&this.__generator||function(o,a){var n={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},u,r,t,i=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return i.next=s(0),i["throw"]=s(1),i["return"]=s(2),typeof Symbol==="function"&&(i[Symbol.iterator]=function(){return this}),i;function s(e){return function(c){return l([e,c])}}function l(e){if(u)throw new TypeError("Generator is already executing.");while(i&&(i=0,e[0]&&(n=0)),n)try{if(u=1,r&&(t=e[0]&2?r["return"]:e[0]?r["throw"]||((t=r["return"])&&t.call(r),0):r.next)&&!(t=t.call(r,e[1])).done)return t;if(r=0,t)e=[e[0]&2,t.value];switch(e[0]){case 0:case 1:t=e;break;case 4:n.label++;return{value:e[1],done:false};case 5:n.label++;r=e[1];e=[0];continue;case 7:e=n.ops.pop();n.trys.pop();continue;default:if(!(t=n.trys,t=t.length>0&&t[t.length-1])&&(e[0]===6||e[0]===2)){n=0;continue}if(e[0]===3&&(!t||e[1]>t[0]&&e[1]<t[3])){n.label=e[1];break}if(e[0]===6&&n.label<t[1]){n.label=t[1];t=e;break}if(t&&n.label<t[2]){n.label=t[2];n.ops.push(e);break}if(t[2])n.ops.pop();n.trys.pop();continue}e=a.call(o,n)}catch(c){e=[6,c];r=0}finally{u=t=0}if(e[0]&5)throw e[1];return{value:e[0]?e[1]:void 0,done:true}}};Object.defineProperty(exports,"__esModule",{value:true});exports.Database=void 0;var faas_db_builder_1=require("@alipay/faas-db-builder");var error_1=require("../error");var Collection_1=require("./Collection");var DatabaseHttpclient=function(){function o(a){this.httpclient=a}o.prototype.request=function(a){return __awaiter(this,arguments,void 0,function(n){var u=n.method,r=n.path,t=n.data,i=n.headers;return __generator(this,function(s){switch(s.label){case 0:return[4,this.httpclient.request({method:u,path:r,data:t,headers:__assign({"x-alipay-cloud-mode":"mongo","x-data-api-type":"mongo","x-expire-timestamp":"".concat(Date.now()+6e4)},i)})];case 1:return[2,s.sent()]}})})};return o}();var Database=function(){function o(a){this.command=new faas_db_builder_1.Command;this.options=__assign(__assign({},a),{httpclient:new DatabaseHttpclient(a.httpclient)})}o.prototype.collection=function(a){if(!a){throw error_1.FaasError.INVALID_PARAM_ERR("collectionName","\u4E0D\u80FD\u4E3A\u7A7A")}return new Collection_1.Collection(a,this.options)};return o}();exports.Database=Database;