"use strict";var __decorate=this&&this.__decorate||function(i,n,t,u){var o=arguments.length,e=o<3?n:u===null?u=Object.getOwnPropertyDescriptor(n,t):u,c;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")e=Reflect.decorate(i,n,t,u);else for(var a=i.length-1;a>=0;a--)if(c=i[a])e=(o<3?c(e):o>3?c(n,t,e):c(n,t))||e;return o>3&&e&&Object.defineProperty(n,t,e),e};var __metadata=this&&this.__metadata||function(i,n){if(typeof Reflect==="object"&&typeof Reflect.metadata==="function")return Reflect.metadata(i,n)};var __awaiter=this&&this.__awaiter||function(i,n,t,u){function o(e){return e instanceof t?e:new t(function(c){c(e)})}return new(t||(t=Promise))(function(e,c){function a(s){try{r(u.next(s))}catch(f){c(f)}}function l(s){try{r(u["throw"](s))}catch(f){c(f)}}function r(s){s.done?e(s.value):o(s.value).then(a,l)}r((u=u.apply(i,n||[])).next())})};var __generator=this&&this.__generator||function(i,n){var t={label:0,sent:function(){if(e[0]&1)throw e[1];return e[1]},trys:[],ops:[]},u,o,e,c=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return c.next=a(0),c["throw"]=a(1),c["return"]=a(2),typeof Symbol==="function"&&(c[Symbol.iterator]=function(){return this}),c;function a(r){return function(s){return l([r,s])}}function l(r){if(u)throw new TypeError("Generator is already executing.");while(c&&(c=0,r[0]&&(t=0)),t)try{if(u=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:t.label++;return{value:r[1],done:false};case 5:t.label++;o=r[1];r=[0];continue;case 7:r=t.ops.pop();t.trys.pop();continue;default:if(!(e=t.trys,e=e.length>0&&e[e.length-1])&&(r[0]===6||r[0]===2)){t=0;continue}if(r[0]===3&&(!e||r[1]>e[0]&&r[1]<e[3])){t.label=r[1];break}if(r[0]===6&&t.label<e[1]){t.label=e[1];e=r;break}if(e&&t.label<e[2]){t.label=e[2];t.ops.push(r);break}if(e[2])t.ops.pop();t.trys.pop();continue}r=n.call(i,t)}catch(s){r=[6,s];o=0}finally{u=e=0}if(r[0]&5)throw r[1];return{value:r[0]?r[1]:void 0,done:true}}};Object.defineProperty(exports,"__esModule",{value:true});exports.Document=void 0;var decorator_1=require("../decorator");var error_1=require("../error");var Query_1=require("./Query");var Document=function(){function i(n,t,u){this.collectionName=n;this.id=t;this.options=u}i.prototype.projection=function(n){this.query.projection(n);return this};i.prototype.field=function(n){this.query.field(n);return this};i.prototype.update=function(n){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(t){switch(t.label){case 0:return[4,this.query.update(n)];case 1:return[2,t.sent()]}})})};i.prototype.updateAndReturn=function(n){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(t){switch(t.label){case 0:return[4,this.query.updateAndReturn(n)];case 1:return[2,t.sent()]}})})};i.prototype.set=function(n){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(t){switch(t.label){case 0:return[4,this.query.set(n)];case 1:return[2,t.sent()]}})})};i.prototype.remove=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(n){switch(n.label){case 0:return[4,this.query.remove()];case 1:return[2,n.sent()]}})})};i.prototype.get=function(){return __awaiter(this,void 0,void 0,function(){var n,t;return __generator(this,function(u){switch(u.label){case 0:return[4,this.query.get()];case 1:n=u.sent();t=n[0];if(!t){if(this.options.throwOnNotFound){throw error_1.FaasError.NOT_FOUND_ERR("\u4E0D\u5B58\u5728_id \u4E3A ".concat(this.id," \u7684\u6587\u6863"))}return[2,null]}return[2,t]}})})};Object.defineProperty(i.prototype,"query",{get:function(){if(!this._query){this._query=new Query_1.Query(this.collectionName,this.options).where({_id:String(this.id)}).limit(1)}return this._query},enumerable:false,configurable:true});__decorate([(0,decorator_1.WrapCallback)(),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],i.prototype,"update",null);__decorate([(0,decorator_1.WrapCallback)(),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],i.prototype,"updateAndReturn",null);__decorate([(0,decorator_1.WrapCallback)(),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],i.prototype,"set",null);__decorate([(0,decorator_1.WrapCallback)(),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",Promise)],i.prototype,"remove",null);__decorate([(0,decorator_1.WrapCallback)(),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",Promise)],i.prototype,"get",null);return i}();exports.Document=Document;