@resolveio/server-lib 20.7.91 → 20.7.93

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(e,n,t,i){return new(t=t||Promise)(function(r,o){function fulfilled(e){try{step(i.next(e))}catch(e){o(e)}}function rejected(e){try{step(i.throw(e))}catch(e){o(e)}}function step(e){var o;e.done?r(e.value):((o=e.value)instanceof t?o:new t(function(e){e(o)})).then(fulfilled,rejected)}step((i=i.apply(e,n||[])).next())})},__generator=this&&this.__generator||function(n,t){var i,l,c,a={label:0,sent:function(){if(1&c[0])throw c[1];return c[1]},trys:[],ops:[]},s={next:verb(0),throw:verb(1),return:verb(2)};return"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function verb(r){return function(e){var o=[r,e];if(i)throw new TypeError("Generator is already executing.");for(;a=s&&o[s=0]?0:a;)try{if(i=1,l&&(c=2&o[0]?l.return:o[0]?l.throw||((c=l.return)&&c.call(l),0):l.next)&&!(c=c.call(l,o[1])).done)return c;switch(l=0,(o=c?[2&o[0],c.value]:o)[0]){case 0:case 1:c=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,l=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(c=0<(c=a.trys).length&&c[c.length-1])&&(6===o[0]||2===o[0])){a=0;continue}if(3===o[0]&&(!c||o[1]>c[0]&&o[1]<c[3]))a.label=o[1];else if(6===o[0]&&a.label<c[1])a.label=c[1],c=o;else{if(!(c&&a.label<c[2])){c[2]&&a.ops.pop(),a.trys.pop();continue}a.label=c[2],a.ops.push(o)}}o=t.call(n,a)}catch(e){o=[6,e],l=0}finally{i=c=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}}},simpl_schema_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.loadCollectionMethods=void 0,require("simpl-schema")),pagination_model_1=require("../models/pagination.model"),resolveio_server_app_1=require("../resolveio-server-app"),common_1=require("../util/common");function loadCollectionMethods(e){e.methods({collectionListAll:{function:function(){return Promise.resolve(resolveio_server_app_1.ResolveIOServer.getMongoManager().collections().map(function(e){return e.collectionName}).sort(function(e,o){return e.localeCompare(o)}))}},collectionListRB:{function:function(){return Promise.resolve(resolveio_server_app_1.ResolveIOServer.getMongoManager().collections().filter(function(e){return e.useRB}).map(function(e){return e.collectionName}).sort(function(e,o){return e.localeCompare(o)}))}},findOne:{check:new simpl_schema_1.default({collection:{type:String},query:{type:Object,blackbox:!0}}),function:function(e,o){if(void 0===o&&(o={}),resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e))return resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e).findOne(o);throw new Error("Error in Find One Collection: Invalid collection")}},find:{check:new simpl_schema_1.default({collection:{type:String},query:{type:Object,blackbox:!0},sort:{type:Object,blackbox:!0,optional:!0}}),function:function(e,o,r){if(void 0===o&&(o={}),void 0===r&&(r={}),resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e))return resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e).find(o,{sort:r});throw new Error("Error in Find Collection: Invalid collection")}},findWithOptions:{check:new simpl_schema_1.default({collection:{type:String},query:{type:Object,blackbox:!0},options:{type:pagination_model_1.PaginationOptionsSchema}}),function:function(e,o,r){var n;if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e))return n={},r.fields&&Object.keys(r.fields).length&&(n.projection=r.fields),r.sort&&Object.keys(r.sort).length&&(n.sort=r.sort),r.limit&&(n.limit=r.limit),r.skip&&(n.skip=r.skip),resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e).find(o,n);throw new Error("Error in Find With Options Collection: Invalid collection")}},insertDocument:{check:new simpl_schema_1.default({collection:{type:String},document:{type:Object,blackbox:!0}}),function:function(r,n){return __awaiter(this,void 0,void 0,function(){var o;return __generator(this,function(e){switch(e.label){case 0:if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(r))return[3,1];throw new Error("Error in Insert Document Collection: Invalid collection");case 1:return o=(0,common_1.objectIdHexString)(),n._id=o,n.__v=0,[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(r).insertOne(n)];case 2:return e.sent(),[2,o]}})})}},insertManyDocuments:{check:new simpl_schema_1.default({collection:{type:String},documents:{type:Array},"documents.$":{type:Object,blackbox:!0}}),function:function(o,r){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(o))return[3,1];throw new Error("Error in Insert Many Documents Collection: Invalid collection");case 1:return r.forEach(function(e){e._id=(0,common_1.objectIdHexString)(),e.__v=0}),[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(o).insertMany(r)];case 2:return e.sent(),[2,r.map(function(e){return e._id})]}})})}},updateDocument:{check:new simpl_schema_1.default({collection:{type:String},f_document:{type:Object,blackbox:!0}}),function:function(e,o){if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e))return resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e).replaceOne({_id:o._id},o);throw new Error("Error in Update Document Collection: Invalid collection")}},updateDocumentProps:{check:new simpl_schema_1.default({collection:{type:String},doc_id:{type:String},updateParams:{type:Array},"updateParams.$":{type:Object,blackbox:!0},doc__v:{type:Number,optional:!0}}),function:function(l,c,a,s){return __awaiter(this,void 0,void 0,function(){var o,r,n,t,i;return __generator(this,function(e){switch(e.label){case 0:if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(l))return[3,1];throw new Error("Error in Update Document Props Collection: Invalid collection");case 1:return[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(l).findOne({_id:c})];case 2:return(o=e.sent())?(r=(0,common_1.deepCopy)(o),a.forEach(function(e){r[e.prop]=e.data}),s&&r.__v!==s?[3,3]:[2,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(l).replaceOne({_id:r._id},r,{},!1,!1,o)]):[3,7];case 3:return(console.log(new Date,"invalid version - "+l,o.__v,s),resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(l+".versions"))?[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(l+".versions").findOne({_id:{_id:o._id,__v:s}})]:[3,5];case 4:if(i=e.sent(),n=o._id,t=o.__v,i)return(i=(0,common_1.getMongoMergeUpdatedDoc)(r,o,i))._id=n,i.__v=t,o._id=n,o.__v=t,[2,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(l).replaceOne({_id:n},i,{},!1,!1,o)];throw new Error("Error In Update Document Props Collections: Invalid Version And Could Not Find History Props - DB: "+t+", Trying to update with :"+s);case 5:throw new Error("Error In Update Document Props Collections: Invalid Version And We Are NOT Using Versions On This Collection!");case 6:return[3,8];case 7:throw new Error("Error in Update Document Props Collections: No Document");case 8:return[2]}})})}},updateDocumentOffline:{check:new simpl_schema_1.default({collection:{type:String},f_document:{type:Object,blackbox:!0}}),function:function(l,c){return __awaiter(this,void 0,void 0,function(){var o,r,n,t,i;return __generator(this,function(e){switch(e.label){case 0:if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(l))return[3,1];throw new Error("Error in Update Document Offline Collection: Invalid collection");case 1:return[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(l).findOne({_id:c._id})];case 2:return(o=e.sent())?o.__v!==c.__v?[3,3]:[2,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(l).replaceOne({_id:c._id},c,{},!1,!1,o)]:[3,7];case 3:return(console.log("OFFLINE - invalid version - "+l,o.__v,c.__v),r=o._id,n=o.__v,t=c.__v,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(l+".versions"))?[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(l+".versions").findOne({_id:{_id:r,__v:t}})]:[3,5];case 4:if(i=e.sent())return(i=(0,common_1.getMongoMergeUpdatedDoc)(c,o,i))._id=r,i.__v=n,o._id=r,o.__v=n,[2,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(l).replaceOne({_id:r},i,{},!1,!1,o)];throw new Error("Error in Update Document Offline Collections: OFFLINE - Invalid Version And Could Not Find History Props - DB: "+n+", Trying to update with :"+t);case 5:throw new Error("Error in Update Document Offline Collections: Invalid Version And We Are NOT Using Versions On This Collection!");case 6:return[3,8];case 7:throw new Error("Error in Update Document Offline Collections: No Document");case 8:return[2]}})})}},updateDocumentPropsOffline:{check:new simpl_schema_1.default({collection:{type:String},doc_id:{type:String},updateParams:{type:Array},"updateParams.$":{type:Object,blackbox:!0},doc__v:{type:Number}}),function:function(l,c,a,s){return __awaiter(this,void 0,void 0,function(){var o,r,n,t,i;return __generator(this,function(e){switch(e.label){case 0:if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(l))return[3,1];throw new Error("Error in Update Document Props Offline Collection: Invalid collection");case 1:return[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(l).findOne({_id:c},null,!0)];case 2:return(o=e.sent())?(r=(0,common_1.deepCopy)(o),a.forEach(function(e){r[e.prop]=e.data}),r.__v!==s?[3,3]:[2,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(l).replaceOne({_id:r._id},r,{},!1,!1,o)]):[3,7];case 3:return(console.log("OFFLINE - invalid version - "+l,o.__v,s),n=o._id,t=o.__v,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(l+".versions"))?[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(l+".versions").findOne({_id:{_id:o._id,__v:s}})]:[3,5];case 4:if(i=e.sent())return(i=(0,common_1.getMongoMergeUpdatedDoc)(r,o,i))._id=n,i.__v=t,o._id=n,o.__v=t,[2,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(l).replaceOne({_id:n},i,{},!1,!1,o)];throw new Error("Error in Update Document Props Offline Collections: OFFLINE - Invalid Version And Could Not Find History Props - DB: "+t+", Trying to update with :"+s);case 5:throw new Error("Error in Update Document Props Offline Collections: Invalid Version And We Are NOT Using Versions On This Collection!");case 6:return[3,8];case 7:throw new Error("Error in Update Document Props Offline Collections: No Document");case 8:return[2]}})})}},removeDocument:{check:new simpl_schema_1.default({collection:{type:String},doc_id:{type:String}}),function:function(e,o){if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e))return resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e).deleteOne({_id:o});throw new Error("Error in Remove Document Collection: Invalid collection")}},removeDocumentWithQuery:{check:new simpl_schema_1.default({collection:{type:String},query:{type:Object,blackbox:!0}}),function:function(e,o){if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e))return resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e).deleteOne(o);throw new Error("Error in Remove Document With Query Collection: Invalid collection")}},removeDocumentsWithQuery:{check:new simpl_schema_1.default({collection:{type:String},query:{type:Object,blackbox:!0}}),function:function(e,o){if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e))return resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e).deleteMany(o);throw new Error("Error in Remove Documents With Query Collections: Invalid Collection")}}})}exports.loadCollectionMethods=loadCollectionMethods;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,n,t,i){return new(t=t||Promise)(function(r,o){function fulfilled(e){try{step(i.next(e))}catch(e){o(e)}}function rejected(e){try{step(i.throw(e))}catch(e){o(e)}}function step(e){var o;e.done?r(e.value):((o=e.value)instanceof t?o:new t(function(e){e(o)})).then(fulfilled,rejected)}step((i=i.apply(e,n||[])).next())})},__generator=this&&this.__generator||function(n,t){var i,c,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},s={next:verb(0),throw:verb(1),return:verb(2)};return"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function verb(r){return function(e){var o=[r,e];if(i)throw new TypeError("Generator is already executing.");for(;a=s&&o[s=0]?0:a;)try{if(i=1,c&&(l=2&o[0]?c.return:o[0]?c.throw||((l=c.return)&&l.call(c),0):c.next)&&!(l=l.call(c,o[1])).done)return l;switch(c=0,(o=l?[2&o[0],l.value]:o)[0]){case 0:case 1:l=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,c=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(l=0<(l=a.trys).length&&l[l.length-1])&&(6===o[0]||2===o[0])){a=0;continue}if(3===o[0]&&(!l||o[1]>l[0]&&o[1]<l[3]))a.label=o[1];else if(6===o[0]&&a.label<l[1])a.label=l[1],l=o;else{if(!(l&&a.label<l[2])){l[2]&&a.ops.pop(),a.trys.pop();continue}a.label=l[2],a.ops.push(o)}}o=t.call(n,a)}catch(e){o=[6,e],c=0}finally{i=l=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}}},simpl_schema_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.loadCollectionMethods=void 0,require("simpl-schema")),pagination_model_1=require("../models/pagination.model"),resolveio_server_app_1=require("../resolveio-server-app"),common_1=require("../util/common");function loadCollectionMethods(e){e.methods({collectionListAll:{function:function(){return Promise.resolve(resolveio_server_app_1.ResolveIOServer.getMongoManager().collections().map(function(e){return e.collectionName}).sort(function(e,o){return e.localeCompare(o)}))}},collectionListRB:{function:function(){return Promise.resolve(resolveio_server_app_1.ResolveIOServer.getMongoManager().collections().filter(function(e){return e.useRB}).map(function(e){return e.collectionName}).sort(function(e,o){return e.localeCompare(o)}))}},findOne:{check:new simpl_schema_1.default({collection:{type:String},query:{type:Object,blackbox:!0}}),function:function(e,o){if(void 0===o&&(o={}),resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e))return resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e).findOne(o);throw new Error("Error in Find One Collection: Invalid collection")}},find:{check:new simpl_schema_1.default({collection:{type:String},query:{type:Object,blackbox:!0},sort:{type:Object,blackbox:!0,optional:!0}}),function:function(e,o,r){if(void 0===o&&(o={}),void 0===r&&(r={}),resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e))return resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e).find(o,{sort:r});throw new Error("Error in Find Collection: Invalid collection")}},findWithOptions:{check:new simpl_schema_1.default({collection:{type:String},query:{type:Object,blackbox:!0},options:{type:pagination_model_1.PaginationOptionsSchema}}),function:function(e,o,r){var n;if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e))return n={},r.fields&&Object.keys(r.fields).length&&(n.projection=r.fields),r.sort&&Object.keys(r.sort).length&&(n.sort=r.sort),r.limit&&(n.limit=r.limit),r.skip&&(n.skip=r.skip),resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(e).find(o,n);throw new Error("Error in Find With Options Collection: Invalid collection")}},insertDocument:{check:new simpl_schema_1.default({collection:{type:String},document:{type:Object,blackbox:!0}}),function:function(r,n){return __awaiter(this,void 0,void 0,function(){var o;return __generator(this,function(e){switch(e.label){case 0:if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(r))return[3,1];throw new Error("Error in Insert Document Collection: Invalid collection");case 1:return o=(0,common_1.objectIdHexString)(),n._id=o,n.__v=0,[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(r).insertOne(n)];case 2:return e.sent(),[2,o]}})})}},insertManyDocuments:{check:new simpl_schema_1.default({collection:{type:String},documents:{type:Array},"documents.$":{type:Object,blackbox:!0}}),function:function(o,r){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(o))return[3,1];throw new Error("Error in Insert Many Documents Collection: Invalid collection");case 1:return r.forEach(function(e){e._id=(0,common_1.objectIdHexString)(),e.__v=0}),[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(o).insertMany(r)];case 2:return e.sent(),[2,r.map(function(e){return e._id})]}})})}},updateDocument:{check:new simpl_schema_1.default({collection:{type:String},f_document:{type:Object,blackbox:!0}}),function:function(o,r){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(o))return[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(o).replaceOne({_id:r._id},r)];throw new Error("Error in Update Document Collection: Invalid collection");case 1:return e.sent(),[2,!0]}})})}},updateDocumentProps:{check:new simpl_schema_1.default({collection:{type:String},doc_id:{type:String},updateParams:{type:Array},"updateParams.$":{type:Object,blackbox:!0},doc__v:{type:Number,optional:!0}}),function:function(c,l,a,s){return __awaiter(this,void 0,void 0,function(){var o,r,n,t,i;return __generator(this,function(e){switch(e.label){case 0:if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(c))return[3,1];throw new Error("Error in Update Document Props Collection: Invalid collection");case 1:return[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(c).findOne({_id:l})];case 2:return(o=e.sent())?(r=(0,common_1.deepCopy)(o),a.forEach(function(e){r[e.prop]=e.data}),s&&r.__v!==s?[3,4]:[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(c).replaceOne({_id:r._id},r,{},!1,!1,o)]):[3,11];case 3:return e.sent(),[3,10];case 4:return(console.log(new Date,"invalid version - "+c,o.__v,s),resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(c+".versions"))?[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(c+".versions").findOne({_id:{_id:o._id,__v:s}})]:[3,9];case 5:return(i=e.sent(),n=o._id,t=o.__v,i)?((i=(0,common_1.getMongoMergeUpdatedDoc)(r,o,i))._id=n,i.__v=t,o._id=n,o.__v=t,[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(c).replaceOne({_id:n},i,{},!1,!1,o)]):[3,7];case 6:return e.sent(),[3,8];case 7:throw new Error("Error In Update Document Props Collections: Invalid Version And Could Not Find History Props - DB: "+t+", Trying to update with :"+s);case 8:return[3,10];case 9:throw new Error("Error In Update Document Props Collections: Invalid Version And We Are NOT Using Versions On This Collection!");case 10:return[3,12];case 11:throw new Error("Error in Update Document Props Collections: No Document");case 12:return[2,!0]}})})}},updateDocumentOffline:{check:new simpl_schema_1.default({collection:{type:String},f_document:{type:Object,blackbox:!0}}),function:function(c,l){return __awaiter(this,void 0,void 0,function(){var o,r,n,t,i;return __generator(this,function(e){switch(e.label){case 0:if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(c))return[3,1];throw new Error("Error in Update Document Offline Collection: Invalid collection");case 1:return[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(c).findOne({_id:l._id})];case 2:return(o=e.sent())?o.__v!==l.__v?[3,4]:[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(c).replaceOne({_id:l._id},l,{},!1,!1,o)]:[3,11];case 3:return e.sent(),[3,10];case 4:return(console.log("OFFLINE - invalid version - "+c,o.__v,l.__v),r=o._id,n=o.__v,t=l.__v,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(c+".versions"))?[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(c+".versions").findOne({_id:{_id:r,__v:t}})]:[3,9];case 5:return(i=e.sent())?((i=(0,common_1.getMongoMergeUpdatedDoc)(l,o,i))._id=r,i.__v=n,o._id=r,o.__v=n,[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(c).replaceOne({_id:r},i,{},!1,!1,o)]):[3,7];case 6:return e.sent(),[3,8];case 7:throw new Error("Error in Update Document Offline Collections: OFFLINE - Invalid Version And Could Not Find History Props - DB: "+n+", Trying to update with :"+t);case 8:return[3,10];case 9:throw new Error("Error in Update Document Offline Collections: Invalid Version And We Are NOT Using Versions On This Collection!");case 10:return[3,12];case 11:throw new Error("Error in Update Document Offline Collections: No Document");case 12:return[2,!0]}})})}},updateDocumentPropsOffline:{check:new simpl_schema_1.default({collection:{type:String},doc_id:{type:String},updateParams:{type:Array},"updateParams.$":{type:Object,blackbox:!0},doc__v:{type:Number}}),function:function(c,l,a,s){return __awaiter(this,void 0,void 0,function(){var o,r,n,t,i;return __generator(this,function(e){switch(e.label){case 0:if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(c))return[3,1];throw new Error("Error in Update Document Props Offline Collection: Invalid collection");case 1:return[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(c).findOne({_id:l},null,!0)];case 2:return(o=e.sent())?(r=(0,common_1.deepCopy)(o),a.forEach(function(e){r[e.prop]=e.data}),r.__v!==s?[3,4]:[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(c).replaceOne({_id:r._id},r,{},!1,!1,o)]):[3,11];case 3:return e.sent(),[3,10];case 4:return(console.log("OFFLINE - invalid version - "+c,o.__v,s),n=o._id,t=o.__v,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(c+".versions"))?[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(c+".versions").findOne({_id:{_id:o._id,__v:s}})]:[3,9];case 5:return(i=e.sent())?((i=(0,common_1.getMongoMergeUpdatedDoc)(r,o,i))._id=n,i.__v=t,o._id=n,o.__v=t,[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(c).replaceOne({_id:n},i,{},!1,!1,o)]):[3,7];case 6:return e.sent(),[3,8];case 7:throw new Error("Error in Update Document Props Offline Collections: OFFLINE - Invalid Version And Could Not Find History Props - DB: "+t+", Trying to update with :"+s);case 8:return[3,10];case 9:throw new Error("Error in Update Document Props Offline Collections: Invalid Version And We Are NOT Using Versions On This Collection!");case 10:return[3,12];case 11:throw new Error("Error in Update Document Props Offline Collections: No Document");case 12:return[2,!0]}})})}},removeDocument:{check:new simpl_schema_1.default({collection:{type:String},doc_id:{type:String}}),function:function(o,r){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(o))return[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(o).deleteOne({_id:r})];throw new Error("Error in Remove Document Collection: Invalid collection");case 1:return e.sent(),[2,!0]}})})}},removeDocumentWithQuery:{check:new simpl_schema_1.default({collection:{type:String},query:{type:Object,blackbox:!0}}),function:function(o,r){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(o))return[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(o).deleteOne(r)];throw new Error("Error in Remove Document With Query Collection: Invalid collection");case 1:return e.sent(),[2,!0]}})})}},removeDocumentsWithQuery:{check:new simpl_schema_1.default({collection:{type:String},query:{type:Object,blackbox:!0}}),function:function(o,r){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:if(resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(o))return[4,resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(o).deleteMany(r)];throw new Error("Error in Remove Documents With Query Collections: Invalid Collection");case 1:return e.sent(),[2,!0]}})})}}})}exports.loadCollectionMethods=loadCollectionMethods;
2
2
  //# sourceMappingURL=collections.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/methods/collections.ts"],"names":["simpl_schema_1","require","pagination_model_1","resolveio_server_app_1","common_1","loadCollectionMethods","methodManager","methods","collectionListAll","function","Promise","resolve","ResolveIOServer","getMongoManager","collections","map","a","collectionName","sort","b","localeCompare","collectionListRB","filter","useRB","findOne","check","default","collection","type","String","query","Object","blackbox","Error","find","optional","sortQuery","findWithOptions","options","PaginationOptionsSchema","optionsQuery","fields","keys","length","limit","skip","insertDocument","document","id","objectIdHexString","insertOne","_a","sent","insertManyDocuments","documents","Array","documents.$","forEach","insertMany","updateDocument","f_document","replaceOne","_id","updateDocumentProps","doc_id","updateParams","updateParams.$","doc__v","Number","currDoc","modifiedDoc_1","deepCopy","data","prop","__v","console","log","Date","oldDoc","newCurrDocId","newCurrDocV","updatedDoc","getMongoMergeUpdatedDoc","updateDocumentOffline","oldDocV","updateDocumentPropsOffline","modifiedDoc_2","removeDocument","deleteOne","removeDocumentWithQuery","removeDocumentsWithQuery","deleteMany","exports"],"mappings":"k8CAAAA,gB,4FAAAC,QAAA,cAAA,GAEAC,mBAAAD,QAA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Schema from 'simpl-schema';\nimport { MethodManager } from '../managers/method.manager';\nimport { PaginationOptions, PaginationOptionsSchema } from '../models/pagination.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { deepCopy, getMongoMergeUpdatedDoc, objectIdHexString } from '../util/common';\n\nexport function loadCollectionMethods(methodManager: MethodManager) {\n\tmethodManager.methods({\n\t\tcollectionListAll: {\n\t\t\tfunction: function() {\n\t\t\t\treturn Promise.resolve(ResolveIOServer.getMongoManager().collections().map(a => a.collectionName).sort((a, b) => a.localeCompare(b)));\n\t\t\t}\n\t\t},\n\t\tcollectionListRB: {\n\t\t\tfunction: function() {\n\t\t\t\treturn Promise.resolve(ResolveIOServer.getMongoManager().collections().filter(a => a.useRB).map(a => a.collectionName).sort((a, b) => a.localeCompare(b)));\n\t\t\t}\n\t\t},\n\t\t// Query database for any collection and query\n\t\tfindOne: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, query = {}) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Find One Collection: Invalid collection');\n\t\t\t\t}\n\n\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).findOne(query);\n\t\t\t}\n\t\t},\n\t\tfind: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tsort: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, query = {}, sortQuery = {}) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Find Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).find(query, {sort: sortQuery});\n\t\t\t}\n\t\t},\n\t\tfindWithOptions: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\toptions: {\n\t\t\t\t\ttype: PaginationOptionsSchema\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, query: Object, options: PaginationOptions) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Find With Options Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet optionsQuery = {};\n\n\t\t\t\t\tif (options.fields && Object.keys(options.fields).length) {\n\t\t\t\t\t\toptionsQuery['projection'] = options.fields;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (options.sort && Object.keys(options.sort).length) {\n\t\t\t\t\t\toptionsQuery['sort'] = options.sort;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (options.limit) {\n\t\t\t\t\t\toptionsQuery['limit'] = options.limit;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (options.skip) {\n\t\t\t\t\t\toptionsQuery['skip'] = options.skip;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).find(query, optionsQuery);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t// Insert 1 document\n\t\t// @Inputs: collection, document\n\t\t// @Outputs: res = _id of new document, err = not inserted\n\t\tinsertDocument: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdocument: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, document: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Insert Document Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet id = objectIdHexString();\n\t\t\t\t\tdocument['_id'] = id;\n\t\t\t\t\tdocument['__v'] = 0;\n\n\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).insertOne(document);\n\t\t\t\t\treturn id;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t// Insert 1 document\n\t\t// @Inputs: collection, document\n\t\t// @Outputs: res = _id of new document, err = not inserted\n\t\tinsertManyDocuments: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdocuments: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'documents.$': {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, documents: Object[]) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Insert Many Documents Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdocuments.forEach(document => {\n\t\t\t\t\t\tdocument['_id'] = objectIdHexString();\n\t\t\t\t\t\tdocument['__v'] = 0;\n\t\t\t\t\t});\n\n\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).insertMany(documents);\n\t\t\t\t\treturn documents.map(a => a['_id']);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t// Replaces 1 document with new document (from _id)\n\t\t// @Inputs: collection, document id\n\t\t// @Outputs: res = 1 (updated 1), err = not updated/wrong version\n\t\t// Search for doc, check version, if found then try and update\n\t\tupdateDocument: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tf_document: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, f_document: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Update Document Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: f_document['_id']}, f_document);\n\t\t\t}\n\t\t},\n\t\t// Updates 1 document's props (from _id)\n\t\t// @Inputs: collection, document id, document version, update paramters ({prop: 'xxx', data: 'yyy})\n\t\t// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version\n\t\t// Search for doc, check version, if found then try and update props\n\t\tupdateDocumentProps: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdoc_id: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tupdateParams: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'updateParams.$': {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tdoc__v: {\n\t\t\t\t\ttype: Number,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, doc_id: string, updateParams: any[], doc__v?: number) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Update Document Props Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet currDoc = await ResolveIOServer.getMongoManager().collection(collection).findOne({_id: doc_id});\n\t\t\t\t\tif (currDoc) {\n\t\t\t\t\t\tlet modifiedDoc = deepCopy(currDoc);\n\n\t\t\t\t\t\tupdateParams.forEach(data => {\n\t\t\t\t\t\t\tmodifiedDoc[data.prop] = data.data;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (!doc__v || modifiedDoc.__v === doc__v) {\n\t\t\t\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: modifiedDoc._id}, modifiedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log(new Date(), 'invalid version - ' + collection, currDoc.__v, doc__v);\n\n\t\t\t\t\t\t\tif (ResolveIOServer.getMongoManager().collection(collection + '.versions')) {\n\t\t\t\t\t\t\t\tlet oldDoc = await ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({\n\t\t\t\t\t\t\t\t\t_id: {\n\t\t\t\t\t\t\t\t\t\t_id: currDoc._id,\n\t\t\t\t\t\t\t\t\t\t__v: doc__v\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tlet newCurrDocId = currDoc._id;\n\t\t\t\t\t\t\t\tlet newCurrDocV = currDoc.__v;\n\n\t\t\t\t\t\t\t\tif (oldDoc) {\n\t\t\t\t\t\t\t\t\tlet updatedDoc = getMongoMergeUpdatedDoc(modifiedDoc, currDoc, oldDoc);\n\t\t\t\t\t\t\t\t\tupdatedDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tupdatedDoc.__v = newCurrDocV;\n\t\t\t\t\t\t\t\t\tcurrDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tcurrDoc.__v = newCurrDocV;\n\n\t\t\t\t\t\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: newCurrDocId}, updatedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tthrow new Error('Error In Update Document Props Collections: Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV + ', Trying to update with :' + doc__v);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tthrow new Error('Error In Update Document Props Collections: Invalid Version And We Are NOT Using Versions On This Collection!');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthrow new Error('Error in Update Document Props Collections: No Document');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tupdateDocumentOffline: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tf_document: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, f_document: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Update Document Offline Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet currDoc = await ResolveIOServer.getMongoManager().collection(collection).findOne({_id: f_document['_id']});\n\t\t\t\t\tif (currDoc) {\n\t\t\t\t\t\tif (currDoc.__v === f_document['__v']) {\n\t\t\t\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: f_document['_id']}, f_document, {}, false, false, currDoc);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log('OFFLINE - invalid version - ' + collection, currDoc.__v, f_document['__v']);\n\n\t\t\t\t\t\t\tlet newCurrDocId = currDoc._id;\n\t\t\t\t\t\t\tlet newCurrDocV = currDoc.__v;\n\t\t\t\t\t\t\tlet oldDocV = f_document['__v'];\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (ResolveIOServer.getMongoManager().collection(collection + '.versions')) {\n\t\t\t\t\t\t\t\tlet oldDoc = await ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({\n\t\t\t\t\t\t\t\t\t_id: {\n\t\t\t\t\t\t\t\t\t\t_id: newCurrDocId,\n\t\t\t\t\t\t\t\t\t\t__v: oldDocV\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tif (oldDoc) {\n\t\t\t\t\t\t\t\t\tlet updatedDoc = getMongoMergeUpdatedDoc(f_document, currDoc, oldDoc);\n\t\t\t\t\t\t\t\t\tupdatedDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tupdatedDoc.__v = newCurrDocV;\n\t\t\t\t\t\t\t\t\tcurrDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tcurrDoc.__v = newCurrDocV;\n\n\t\t\t\t\t\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: newCurrDocId}, updatedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tthrow new Error('Error in Update Document Offline Collections: OFFLINE - Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV + ', Trying to update with :' + oldDocV);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tthrow new Error('Error in Update Document Offline Collections: Invalid Version And We Are NOT Using Versions On This Collection!');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthrow new Error('Error in Update Document Offline Collections: No Document');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t// Updates 1 document's props (from _id)\n\t\t// @Inputs: collection, document id, document version, update paramters ({prop: 'xxx', data: 'yyy})\n\t\t// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version\n\t\t// Search for doc, check version, if found then try and update props\n\t\tupdateDocumentPropsOffline: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdoc_id: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tupdateParams: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'updateParams.$': {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tdoc__v: {\n\t\t\t\t\ttype: Number\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, doc_id: string, updateParams: any[], doc__v: number) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Update Document Props Offline Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet currDoc = await ResolveIOServer.getMongoManager().collection(collection).findOne({_id: doc_id}, null, true);\n\t\t\t\t\tif (currDoc) {\n\t\t\t\t\t\tlet modifiedDoc = deepCopy(currDoc);\n\n\t\t\t\t\t\tupdateParams.forEach(data => {\n\t\t\t\t\t\t\tmodifiedDoc[data.prop] = data.data;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (modifiedDoc.__v === doc__v) {\n\t\t\t\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: modifiedDoc._id}, modifiedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log('OFFLINE - invalid version - ' + collection, currDoc.__v, doc__v);\n\n\t\t\t\t\t\t\tlet newCurrDocId = currDoc._id;\n\t\t\t\t\t\t\tlet newCurrDocV = currDoc.__v;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (ResolveIOServer.getMongoManager().collection(collection + '.versions')) {\n\t\t\t\t\t\t\t\tlet oldDoc = await ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({\n\t\t\t\t\t\t\t\t\t_id: {\n\t\t\t\t\t\t\t\t\t\t_id: currDoc._id,\n\t\t\t\t\t\t\t\t\t\t__v: doc__v\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tif (oldDoc) {\n\t\t\t\t\t\t\t\t\tlet updatedDoc = getMongoMergeUpdatedDoc(modifiedDoc, currDoc, oldDoc);\n\t\t\t\t\t\t\t\t\tupdatedDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tupdatedDoc.__v = newCurrDocV;\n\t\t\t\t\t\t\t\t\tcurrDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tcurrDoc.__v = newCurrDocV;\n\n\t\t\t\t\t\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: newCurrDocId}, updatedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tthrow new Error('Error in Update Document Props Offline Collections: OFFLINE - Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV + ', Trying to update with :' + doc__v);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tthrow new Error('Error in Update Document Props Offline Collections: Invalid Version And We Are NOT Using Versions On This Collection!');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthrow new Error('Error in Update Document Props Offline Collections: No Document');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t// Removes 1 document (from _id)\n\t\t// @Inputs: collection, document id\n\t\t// @Outputs: res = 1 (deleted), res = 0 (not deleted), err = not deleted\n\t\t// Search for doc, if found then try and remove\n\t\tremoveDocument: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdoc_id: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, doc_id: string) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Remove Document Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).deleteOne({_id: doc_id});\n\t\t\t}\n\t\t},\n\t\tremoveDocumentWithQuery: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, query: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Remove Document With Query Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).deleteOne(query);\n\t\t\t}\n\t\t},\n\t\tremoveDocumentsWithQuery: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, query: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Remove Documents With Query Collections: Invalid Collection');\n\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).deleteMany(query);\n\t\t\t}\n\t\t}\n\t});\n}"]}
1
+ {"version":3,"sources":["../../src/methods/collections.ts"],"names":["simpl_schema_1","require","pagination_model_1","resolveio_server_app_1","common_1","loadCollectionMethods","methodManager","methods","collectionListAll","function","Promise","resolve","ResolveIOServer","getMongoManager","collections","map","a","collectionName","sort","b","localeCompare","collectionListRB","filter","useRB","findOne","check","default","collection","type","String","query","Object","blackbox","Error","find","optional","sortQuery","findWithOptions","options","PaginationOptionsSchema","optionsQuery","fields","keys","length","limit","skip","insertDocument","document","id","objectIdHexString","insertOne","_a","sent","insertManyDocuments","documents","Array","documents.$","forEach","insertMany","updateDocument","f_document","replaceOne","_id","updateDocumentProps","doc_id","updateParams","updateParams.$","doc__v","Number","currDoc","modifiedDoc_1","deepCopy","data","prop","__v","console","log","Date","oldDoc","newCurrDocId","newCurrDocV","updatedDoc","getMongoMergeUpdatedDoc","updateDocumentOffline","oldDocV","updateDocumentPropsOffline","modifiedDoc_2","removeDocument","deleteOne","removeDocumentWithQuery","removeDocumentsWithQuery","deleteMany","exports"],"mappings":"k8CAAAA,gB,4FAAAC,QAAA,cAAA,GAEAC,mBAAAD,QAAA,4BAAA,EACAE,uBAAAF,QAAA,yBAAA,EACAG,SAAAH,QAAA,gBAAA,EAEA,SAAgBI,sBAAsBC,GACrCA,EAAcC,QAAQ,CACrBC,kBAAmB,CAClBC,SAAU,WACT,OAAOC,QAAQC,QAAQR,uBAAAS,gBAAgBC,gBAAe,EAAGC,YAAW,EAAGC,IAAI,SAAAC,GAAK,OAAAA,EAAEC,cAAF,CAAgB,EAAEC,KAAK,SAACF,EAAGG,GAAM,OAAAH,EAAEI,cAAcD,CAAC,CAAjB,CAAkB,CAAC,CACrI,C,EAEDE,iBAAkB,CACjBZ,SAAU,WACT,OAAOC,QAAQC,QAAQR,uBAAAS,gBAAgBC,gBAAe,EAAGC,YAAW,EAAGQ,OAAO,SAAAN,GAAK,OAAAA,EAAEO,KAAF,CAAO,EAAER,IAAI,SAAAC,GAAK,OAAAA,EAAEC,cAAF,CAAgB,EAAEC,KAAK,SAACF,EAAGG,GAAM,OAAAH,EAAEI,cAAcD,CAAC,CAAjB,CAAkB,CAAC,CAC1J,C,EAGDK,QAAS,CACRC,MAAO,IAAIzB,eAAA0B,QAAa,CACvBC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gBAAe,EAAGc,WAAWA,CAAU,EAAE6D,UAAU,CAAC1B,IAAKE,CAAM,CAAC,GAHrF,MAAM,IAAI/B,MAAM,yDAAyD,E,OAK1E,OAFAkB,EAAAC,KAAA,EAEA,CAAA,EAAO,CAAA,E,QAGTqC,wBAAyB,CACxBhE,MAAO,IAAIzB,eAAA0B,QAAa,CACvBC,WAAY,CACXC,KAAMC,M,EAEPC,MAAO,CACNF,KAAMG,OACNC,SAAU,CAAA,C,EAEX,EACDvB,SAAU,SAAekB,EAAoBG,G,0GAC5C,GAAK3B,uBAAAS,gBAAgBC,gBAAe,EAAGc,WAAWA,CAAU,EAI5D,MAAA,CAAA,EAAMxB,uBAAAS,gBAAgBC,gBAAe,EAAGc,WAAWA,CAAU,EAAE6D,UAAU1D,CAAK,GAH7E,MAAM,IAAIG,MAAM,oEAAoE,E,OAKrF,OAFAkB,EAAAC,KAAA,EAEA,CAAA,EAAO,CAAA,E,QAGTsC,yBAA0B,CACzBjE,MAAO,IAAIzB,eAAA0B,QAAa,CACvBC,WAAY,CACXC,KAAMC,M,EAEPC,MAAO,CACNF,KAAMG,OACNC,SAAU,CAAA,C,EAEX,EACDvB,SAAU,SAAekB,EAAoBG,G,0GAC5C,GAAK3B,uBAAAS,gBAAgBC,gBAAe,EAAGc,WAAWA,CAAU,EAI5D,MAAA,CAAA,EAAMxB,uBAAAS,gBAAgBC,gBAAe,EAAGc,WAAWA,CAAU,EAAEgE,WAAW7D,CAAK,GAH9E,MAAM,IAAIG,MAAM,sEAAsE,E,OAKvF,OAFAkB,EAAAC,KAAA,EAEA,CAAA,EAAO,CAAA,E,QAGT,CACF,CA3cAwC,QAAAvF,sBAAAA","file":"collections.js","sourcesContent":["import SimpleSchema from 'simpl-schema';\nimport { MethodManager } from '../managers/method.manager';\nimport { PaginationOptions, PaginationOptionsSchema } from '../models/pagination.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { deepCopy, getMongoMergeUpdatedDoc, objectIdHexString } from '../util/common';\n\nexport function loadCollectionMethods(methodManager: MethodManager) {\n\tmethodManager.methods({\n\t\tcollectionListAll: {\n\t\t\tfunction: function() {\n\t\t\t\treturn Promise.resolve(ResolveIOServer.getMongoManager().collections().map(a => a.collectionName).sort((a, b) => a.localeCompare(b)));\n\t\t\t}\n\t\t},\n\t\tcollectionListRB: {\n\t\t\tfunction: function() {\n\t\t\t\treturn Promise.resolve(ResolveIOServer.getMongoManager().collections().filter(a => a.useRB).map(a => a.collectionName).sort((a, b) => a.localeCompare(b)));\n\t\t\t}\n\t\t},\n\t\t// Query database for any collection and query\n\t\tfindOne: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, query = {}) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Find One Collection: Invalid collection');\n\t\t\t\t}\n\n\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).findOne(query);\n\t\t\t}\n\t\t},\n\t\tfind: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tsort: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, query = {}, sortQuery = {}) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Find Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).find(query, {sort: sortQuery});\n\t\t\t}\n\t\t},\n\t\tfindWithOptions: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\toptions: {\n\t\t\t\t\ttype: PaginationOptionsSchema\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, query: Object, options: PaginationOptions) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Find With Options Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet optionsQuery = {};\n\n\t\t\t\t\tif (options.fields && Object.keys(options.fields).length) {\n\t\t\t\t\t\toptionsQuery['projection'] = options.fields;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (options.sort && Object.keys(options.sort).length) {\n\t\t\t\t\t\toptionsQuery['sort'] = options.sort;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (options.limit) {\n\t\t\t\t\t\toptionsQuery['limit'] = options.limit;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (options.skip) {\n\t\t\t\t\t\toptionsQuery['skip'] = options.skip;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).find(query, optionsQuery);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t// Insert 1 document\n\t\t// @Inputs: collection, document\n\t\t// @Outputs: res = _id of new document, err = not inserted\n\t\tinsertDocument: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdocument: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, document: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Insert Document Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet id = objectIdHexString();\n\t\t\t\t\tdocument['_id'] = id;\n\t\t\t\t\tdocument['__v'] = 0;\n\n\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).insertOne(document);\n\t\t\t\t\treturn id;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t// Insert 1 document\n\t\t// @Inputs: collection, document\n\t\t// @Outputs: res = _id of new document, err = not inserted\n\t\tinsertManyDocuments: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdocuments: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'documents.$': {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, documents: Object[]) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Insert Many Documents Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdocuments.forEach(document => {\n\t\t\t\t\t\tdocument['_id'] = objectIdHexString();\n\t\t\t\t\t\tdocument['__v'] = 0;\n\t\t\t\t\t});\n\n\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).insertMany(documents);\n\t\t\t\t\treturn documents.map(a => a['_id']);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t// Replaces 1 document with new document (from _id)\n\t\t// @Inputs: collection, document id\n\t\t// @Outputs: res = 1 (updated 1), err = not updated/wrong version\n\t\t// Search for doc, check version, if found then try and update\n\t\tupdateDocument: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tf_document: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, f_document: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Update Document Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: f_document['_id']}, f_document);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\t// Updates 1 document's props (from _id)\n\t\t// @Inputs: collection, document id, document version, update paramters ({prop: 'xxx', data: 'yyy})\n\t\t// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version\n\t\t// Search for doc, check version, if found then try and update props\n\t\tupdateDocumentProps: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdoc_id: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tupdateParams: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'updateParams.$': {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tdoc__v: {\n\t\t\t\t\ttype: Number,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, doc_id: string, updateParams: any[], doc__v?: number) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Update Document Props Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet currDoc = await ResolveIOServer.getMongoManager().collection(collection).findOne({_id: doc_id});\n\t\t\t\t\tif (currDoc) {\n\t\t\t\t\t\tlet modifiedDoc = deepCopy(currDoc);\n\n\t\t\t\t\t\tupdateParams.forEach(data => {\n\t\t\t\t\t\t\tmodifiedDoc[data.prop] = data.data;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (!doc__v || modifiedDoc.__v === doc__v) {\n\t\t\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: modifiedDoc._id}, modifiedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log(new Date(), 'invalid version - ' + collection, currDoc.__v, doc__v);\n\n\t\t\t\t\t\t\tif (ResolveIOServer.getMongoManager().collection(collection + '.versions')) {\n\t\t\t\t\t\t\t\tlet oldDoc = await ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({\n\t\t\t\t\t\t\t\t\t_id: {\n\t\t\t\t\t\t\t\t\t\t_id: currDoc._id,\n\t\t\t\t\t\t\t\t\t\t__v: doc__v\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tlet newCurrDocId = currDoc._id;\n\t\t\t\t\t\t\t\tlet newCurrDocV = currDoc.__v;\n\n\t\t\t\t\t\t\t\tif (oldDoc) {\n\t\t\t\t\t\t\t\t\tlet updatedDoc = getMongoMergeUpdatedDoc(modifiedDoc, currDoc, oldDoc);\n\t\t\t\t\t\t\t\t\tupdatedDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tupdatedDoc.__v = newCurrDocV;\n\t\t\t\t\t\t\t\t\tcurrDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tcurrDoc.__v = newCurrDocV;\n\n\t\t\t\t\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: newCurrDocId}, updatedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tthrow new Error('Error In Update Document Props Collections: Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV + ', Trying to update with :' + doc__v);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tthrow new Error('Error In Update Document Props Collections: Invalid Version And We Are NOT Using Versions On This Collection!');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthrow new Error('Error in Update Document Props Collections: No Document');\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\tupdateDocumentOffline: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tf_document: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, f_document: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Update Document Offline Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet currDoc = await ResolveIOServer.getMongoManager().collection(collection).findOne({_id: f_document['_id']});\n\t\t\t\t\tif (currDoc) {\n\t\t\t\t\t\tif (currDoc.__v === f_document['__v']) {\n\t\t\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: f_document['_id']}, f_document, {}, false, false, currDoc);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log('OFFLINE - invalid version - ' + collection, currDoc.__v, f_document['__v']);\n\n\t\t\t\t\t\t\tlet newCurrDocId = currDoc._id;\n\t\t\t\t\t\t\tlet newCurrDocV = currDoc.__v;\n\t\t\t\t\t\t\tlet oldDocV = f_document['__v'];\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (ResolveIOServer.getMongoManager().collection(collection + '.versions')) {\n\t\t\t\t\t\t\t\tlet oldDoc = await ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({\n\t\t\t\t\t\t\t\t\t_id: {\n\t\t\t\t\t\t\t\t\t\t_id: newCurrDocId,\n\t\t\t\t\t\t\t\t\t\t__v: oldDocV\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tif (oldDoc) {\n\t\t\t\t\t\t\t\t\tlet updatedDoc = getMongoMergeUpdatedDoc(f_document, currDoc, oldDoc);\n\t\t\t\t\t\t\t\t\tupdatedDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tupdatedDoc.__v = newCurrDocV;\n\t\t\t\t\t\t\t\t\tcurrDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tcurrDoc.__v = newCurrDocV;\n\n\t\t\t\t\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: newCurrDocId}, updatedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tthrow new Error('Error in Update Document Offline Collections: OFFLINE - Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV + ', Trying to update with :' + oldDocV);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tthrow new Error('Error in Update Document Offline Collections: Invalid Version And We Are NOT Using Versions On This Collection!');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthrow new Error('Error in Update Document Offline Collections: No Document');\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\t// Updates 1 document's props (from _id)\n\t\t// @Inputs: collection, document id, document version, update paramters ({prop: 'xxx', data: 'yyy})\n\t\t// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version\n\t\t// Search for doc, check version, if found then try and update props\n\t\tupdateDocumentPropsOffline: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdoc_id: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tupdateParams: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'updateParams.$': {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tdoc__v: {\n\t\t\t\t\ttype: Number\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, doc_id: string, updateParams: any[], doc__v: number) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Update Document Props Offline Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet currDoc = await ResolveIOServer.getMongoManager().collection(collection).findOne({_id: doc_id}, null, true);\n\t\t\t\t\tif (currDoc) {\n\t\t\t\t\t\tlet modifiedDoc = deepCopy(currDoc);\n\n\t\t\t\t\t\tupdateParams.forEach(data => {\n\t\t\t\t\t\t\tmodifiedDoc[data.prop] = data.data;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (modifiedDoc.__v === doc__v) {\n\t\t\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: modifiedDoc._id}, modifiedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log('OFFLINE - invalid version - ' + collection, currDoc.__v, doc__v);\n\n\t\t\t\t\t\t\tlet newCurrDocId = currDoc._id;\n\t\t\t\t\t\t\tlet newCurrDocV = currDoc.__v;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (ResolveIOServer.getMongoManager().collection(collection + '.versions')) {\n\t\t\t\t\t\t\t\tlet oldDoc = await ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({\n\t\t\t\t\t\t\t\t\t_id: {\n\t\t\t\t\t\t\t\t\t\t_id: currDoc._id,\n\t\t\t\t\t\t\t\t\t\t__v: doc__v\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tif (oldDoc) {\n\t\t\t\t\t\t\t\t\tlet updatedDoc = getMongoMergeUpdatedDoc(modifiedDoc, currDoc, oldDoc);\n\t\t\t\t\t\t\t\t\tupdatedDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tupdatedDoc.__v = newCurrDocV;\n\t\t\t\t\t\t\t\t\tcurrDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tcurrDoc.__v = newCurrDocV;\n\n\t\t\t\t\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: newCurrDocId}, updatedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tthrow new Error('Error in Update Document Props Offline Collections: OFFLINE - Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV + ', Trying to update with :' + doc__v);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tthrow new Error('Error in Update Document Props Offline Collections: Invalid Version And We Are NOT Using Versions On This Collection!');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthrow new Error('Error in Update Document Props Offline Collections: No Document');\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\t// Removes 1 document (from _id)\n\t\t// @Inputs: collection, document id\n\t\t// @Outputs: res = 1 (deleted), res = 0 (not deleted), err = not deleted\n\t\t// Search for doc, if found then try and remove\n\t\tremoveDocument: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdoc_id: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, doc_id: string) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Remove Document Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).deleteOne({_id: doc_id});\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\tremoveDocumentWithQuery: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, query: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Remove Document With Query Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).deleteOne(query);\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\tremoveDocumentsWithQuery: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, query: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Remove Documents With Query Collections: Invalid Collection');\n\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).deleteMany(query);\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t});\n}"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "20.7.91",
3
+ "version": "20.7.93",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "package": "./build_package.sh",