@resolveio/server-lib 20.7.120 → 20.7.122
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.
- package/client-server-app.js +51 -1
- package/client-server-app.js.map +1 -1
- package/collections/app-status.collection.js +51 -1
- package/collections/app-status.collection.js.map +1 -1
- package/collections/counter.collection.js +55 -1
- package/collections/counter.collection.js.map +1 -1
- package/collections/cron-job-history.collection.js +136 -1
- package/collections/cron-job-history.collection.js.map +1 -1
- package/collections/cron-job.collection.js +87 -1
- package/collections/cron-job.collection.js.map +1 -1
- package/collections/email-history.collection.js +98 -1
- package/collections/email-history.collection.js.map +1 -1
- package/collections/email-verified.collection.js +60 -1
- package/collections/email-verified.collection.js.map +1 -1
- package/collections/file.collection.js +73 -1
- package/collections/file.collection.js.map +1 -1
- package/collections/flag-update.collection.js +56 -1
- package/collections/flag-update.collection.js.map +1 -1
- package/collections/flag.collection.js +56 -1
- package/collections/flag.collection.js.map +1 -1
- package/collections/log-method-latency.collection.js +72 -1
- package/collections/log-method-latency.collection.js.map +1 -1
- package/collections/log-subscription.collection.js +75 -1
- package/collections/log-subscription.collection.js.map +1 -1
- package/collections/log.collection.js +87 -1
- package/collections/log.collection.js.map +1 -1
- package/collections/logged-in-users.collection.js +66 -1
- package/collections/logged-in-users.collection.js.map +1 -1
- package/collections/monitor-cpu.collection.js +64 -1
- package/collections/monitor-cpu.collection.js.map +1 -1
- package/collections/monitor-function.collection.js +73 -1
- package/collections/monitor-function.collection.js.map +1 -1
- package/collections/monitor-memory.collection.js +76 -1
- package/collections/monitor-memory.collection.js.map +1 -1
- package/collections/monitor-mongo.collection.js +70 -1
- package/collections/monitor-mongo.collection.js.map +1 -1
- package/collections/notification.collection.js +56 -1
- package/collections/notification.collection.js.map +1 -1
- package/collections/report-builder-dashboard-builder.collection.js +108 -1
- package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
- package/collections/report-builder-library.collection.js +86 -1
- package/collections/report-builder-library.collection.js.map +1 -1
- package/collections/report-builder-report.collection.js +148 -1
- package/collections/report-builder-report.collection.js.map +1 -1
- package/collections/user-group.collection.js +88 -1
- package/collections/user-group.collection.js.map +1 -1
- package/collections/user-guide.collection.js +56 -1
- package/collections/user-guide.collection.js.map +1 -1
- package/collections/user.collection.js +265 -1
- package/collections/user.collection.js.map +1 -1
- package/cron/cron.js +97 -1
- package/cron/cron.js.map +1 -1
- package/fixtures/cron-jobs.js +95 -1
- package/fixtures/cron-jobs.js.map +1 -1
- package/fixtures/init.js +78 -1
- package/fixtures/init.js.map +1 -1
- package/http/auth.js +869 -1
- package/http/auth.js.map +1 -1
- package/http/health.js +11 -1
- package/http/health.js.map +1 -1
- package/http/home.js +114 -1
- package/http/home.js.map +1 -1
- package/index.js +18 -1
- package/index.js.map +1 -1
- package/managers/cron.manager.js +461 -1
- package/managers/cron.manager.js.map +1 -1
- package/managers/local-log.manager.js +79 -1
- package/managers/local-log.manager.js.map +1 -1
- package/managers/method.manager.js +1025 -1
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.js +4231 -1
- package/managers/mongo.manager.js.map +1 -1
- package/managers/monitor.manager.js +534 -1
- package/managers/monitor.manager.js.map +1 -1
- package/managers/subscription.manager.js +1292 -1
- package/managers/subscription.manager.js.map +1 -1
- package/managers/websocket.manager.js +165 -1
- package/managers/websocket.manager.js.map +1 -1
- package/managers/worker-dispatcher.manager.js +335 -1
- package/managers/worker-dispatcher.manager.js.map +1 -1
- package/managers/worker-server.manager.js +292 -1
- package/managers/worker-server.manager.js.map +1 -1
- package/methods/accounts.js +302 -1
- package/methods/accounts.js.map +1 -1
- package/methods/aws.js +748 -1
- package/methods/aws.js.map +1 -1
- package/methods/collections.js +542 -1
- package/methods/collections.js.map +1 -1
- package/methods/counters.js +111 -1
- package/methods/counters.js.map +1 -1
- package/methods/cron-jobs.js +1476 -1
- package/methods/cron-jobs.js.map +1 -1
- package/methods/flag-updates.js +8 -1
- package/methods/flag-updates.js.map +1 -1
- package/methods/flags.js +8 -1
- package/methods/flags.js.map +1 -1
- package/methods/logs.js +417 -1
- package/methods/logs.js.map +1 -1
- package/methods/monitor.js +543 -1
- package/methods/monitor.js.map +1 -1
- package/methods/pdf.js +742 -1
- package/methods/pdf.js.map +1 -1
- package/methods/report-builder.js +840 -1
- package/methods/report-builder.js.map +1 -1
- package/methods/support.js +232 -1
- package/methods/support.js.map +1 -1
- package/models/app-status.model.js +3 -1
- package/models/app-status.model.js.map +1 -1
- package/models/billing-logged-in-users.model.js +3 -1
- package/models/billing-logged-in-users.model.js.map +1 -1
- package/models/collection-document.model.js +3 -1
- package/models/collection-document.model.js.map +1 -1
- package/models/counter.model.js +3 -1
- package/models/counter.model.js.map +1 -1
- package/models/cron-job-history.model.js +3 -1
- package/models/cron-job-history.model.js.map +1 -1
- package/models/cron-job.model.js +3 -1
- package/models/cron-job.model.js.map +1 -1
- package/models/dialog.model.js +3 -1
- package/models/dialog.model.js.map +1 -1
- package/models/email-history.model.js +15 -1
- package/models/email-history.model.js.map +1 -1
- package/models/email-verified.model.js +3 -1
- package/models/email-verified.model.js.map +1 -1
- package/models/file.model.js +3 -1
- package/models/file.model.js.map +1 -1
- package/models/flag-update.model.js +3 -1
- package/models/flag-update.model.js.map +1 -1
- package/models/flag.model.js +3 -1
- package/models/flag.model.js.map +1 -1
- package/models/log-method-latency.model.js +3 -1
- package/models/log-method-latency.model.js.map +1 -1
- package/models/log-subscription.model.js +3 -1
- package/models/log-subscription.model.js.map +1 -1
- package/models/log.model.js +3 -1
- package/models/log.model.js.map +1 -1
- package/models/logged-in-users.model.js +3 -1
- package/models/logged-in-users.model.js.map +1 -1
- package/models/method-response.model.js +3 -1
- package/models/method-response.model.js.map +1 -1
- package/models/method.model.d.ts +0 -1
- package/models/method.model.js +3 -1
- package/models/method.model.js.map +1 -1
- package/models/monitor-cpu.model.js +3 -1
- package/models/monitor-cpu.model.js.map +1 -1
- package/models/monitor-function.model.js +3 -1
- package/models/monitor-function.model.js.map +1 -1
- package/models/monitor-memory.model.js +3 -1
- package/models/monitor-memory.model.js.map +1 -1
- package/models/monitor-mongo.model.js +3 -1
- package/models/monitor-mongo.model.js.map +1 -1
- package/models/notification.model.js +3 -1
- package/models/notification.model.js.map +1 -1
- package/models/pagination.model.js +23 -1
- package/models/pagination.model.js.map +1 -1
- package/models/permission.model.js +3 -1
- package/models/permission.model.js.map +1 -1
- package/models/report-builder-dashboard-builder.model.js +3 -1
- package/models/report-builder-dashboard-builder.model.js.map +1 -1
- package/models/report-builder-library.model.js +3 -1
- package/models/report-builder-library.model.js.map +1 -1
- package/models/report-builder-report.model.js +3 -1
- package/models/report-builder-report.model.js.map +1 -1
- package/models/report-builder.model.js +3 -1
- package/models/report-builder.model.js.map +1 -1
- package/models/select-data-label.model.js +3 -1
- package/models/select-data-label.model.js.map +1 -1
- package/models/server-message.model.js +3 -1
- package/models/server-message.model.js.map +1 -1
- package/models/subscription.model.js +3 -1
- package/models/subscription.model.js.map +1 -1
- package/models/support-ticket.model.js +3 -1
- package/models/support-ticket.model.js.map +1 -1
- package/models/user-group.model.js +3 -1
- package/models/user-group.model.js.map +1 -1
- package/models/user-guide.model.js +3 -1
- package/models/user-guide.model.js.map +1 -1
- package/models/user.model.js +3 -1
- package/models/user.model.js.map +1 -1
- package/package.json +1 -1
- package/public_api.js +77 -1
- package/public_api.js.map +1 -1
- package/publications/app-status.js +16 -1
- package/publications/app-status.js.map +1 -1
- package/publications/cron-jobs.js +32 -1
- package/publications/cron-jobs.js.map +1 -1
- package/publications/files.js +36 -1
- package/publications/files.js.map +1 -1
- package/publications/flags-update.js +22 -1
- package/publications/flags-update.js.map +1 -1
- package/publications/flags.js +22 -1
- package/publications/flags.js.map +1 -1
- package/publications/logs.js +164 -1
- package/publications/logs.js.map +1 -1
- package/publications/notifications.js +16 -1
- package/publications/notifications.js.map +1 -1
- package/publications/report-builder-dashboard-builders.js +42 -1
- package/publications/report-builder-dashboard-builders.js.map +1 -1
- package/publications/report-builder-libraries.js +90 -1
- package/publications/report-builder-libraries.js.map +1 -1
- package/publications/report-builder-reports.js +50 -1
- package/publications/report-builder-reports.js.map +1 -1
- package/publications/super-admin.js +16 -1
- package/publications/super-admin.js.map +1 -1
- package/publications/user-groups.js +16 -1
- package/publications/user-groups.js.map +1 -1
- package/publications/user-guides.js +16 -1
- package/publications/user-guides.js.map +1 -1
- package/resolveio-server-app.js +176 -1
- package/resolveio-server-app.js.map +1 -1
- package/server-app.js +1159 -1
- package/server-app.js.map +1 -1
- package/util/common.js +632 -1
- package/util/common.js.map +1 -1
- package/util/schema-report-builder.js +454 -1
- package/util/schema-report-builder.js.map +1 -1
package/methods/collections.js
CHANGED
|
@@ -1,2 +1,543 @@
|
|
|
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;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.loadCollectionMethods = void 0;
|
|
40
|
+
var simpl_schema_1 = require("simpl-schema");
|
|
41
|
+
var pagination_model_1 = require("../models/pagination.model");
|
|
42
|
+
var resolveio_server_app_1 = require("../resolveio-server-app");
|
|
43
|
+
var common_1 = require("../util/common");
|
|
44
|
+
function loadCollectionMethods(methodManager) {
|
|
45
|
+
methodManager.methods({
|
|
46
|
+
collectionListAll: {
|
|
47
|
+
function: function () {
|
|
48
|
+
return Promise.resolve(resolveio_server_app_1.ResolveIOServer.getMongoManager().collections().map(function (a) { return a.collectionName; }).sort(function (a, b) { return a.localeCompare(b); }));
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
collectionListRB: {
|
|
52
|
+
function: function () {
|
|
53
|
+
return Promise.resolve(resolveio_server_app_1.ResolveIOServer.getMongoManager().collections().filter(function (a) { return a.useRB; }).map(function (a) { return a.collectionName; }).sort(function (a, b) { return a.localeCompare(b); }));
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
// Query database for any collection and query
|
|
57
|
+
findOne: {
|
|
58
|
+
check: new simpl_schema_1.default({
|
|
59
|
+
collection: {
|
|
60
|
+
type: String
|
|
61
|
+
},
|
|
62
|
+
query: {
|
|
63
|
+
type: Object,
|
|
64
|
+
blackbox: true
|
|
65
|
+
}
|
|
66
|
+
}),
|
|
67
|
+
function: function (collection, query) {
|
|
68
|
+
if (query === void 0) { query = {}; }
|
|
69
|
+
if (!resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
70
|
+
throw new Error('Error in Find One Collection: Invalid collection');
|
|
71
|
+
}
|
|
72
|
+
return resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection).findOne(query);
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
find: {
|
|
76
|
+
check: new simpl_schema_1.default({
|
|
77
|
+
collection: {
|
|
78
|
+
type: String
|
|
79
|
+
},
|
|
80
|
+
query: {
|
|
81
|
+
type: Object,
|
|
82
|
+
blackbox: true
|
|
83
|
+
},
|
|
84
|
+
sort: {
|
|
85
|
+
type: Object,
|
|
86
|
+
blackbox: true,
|
|
87
|
+
optional: true
|
|
88
|
+
}
|
|
89
|
+
}),
|
|
90
|
+
function: function (collection, query, sortQuery) {
|
|
91
|
+
if (query === void 0) { query = {}; }
|
|
92
|
+
if (sortQuery === void 0) { sortQuery = {}; }
|
|
93
|
+
if (!resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
94
|
+
throw new Error('Error in Find Collection: Invalid collection');
|
|
95
|
+
}
|
|
96
|
+
return resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection).find(query, { sort: sortQuery });
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
findWithOptions: {
|
|
100
|
+
check: new simpl_schema_1.default({
|
|
101
|
+
collection: {
|
|
102
|
+
type: String
|
|
103
|
+
},
|
|
104
|
+
query: {
|
|
105
|
+
type: Object,
|
|
106
|
+
blackbox: true
|
|
107
|
+
},
|
|
108
|
+
options: {
|
|
109
|
+
type: pagination_model_1.PaginationOptionsSchema
|
|
110
|
+
}
|
|
111
|
+
}),
|
|
112
|
+
function: function (collection, query, options) {
|
|
113
|
+
if (!resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
114
|
+
throw new Error('Error in Find With Options Collection: Invalid collection');
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
var optionsQuery = {};
|
|
118
|
+
if (options.fields && Object.keys(options.fields).length) {
|
|
119
|
+
optionsQuery['projection'] = options.fields;
|
|
120
|
+
}
|
|
121
|
+
if (options.sort && Object.keys(options.sort).length) {
|
|
122
|
+
optionsQuery['sort'] = options.sort;
|
|
123
|
+
}
|
|
124
|
+
if (options.limit) {
|
|
125
|
+
optionsQuery['limit'] = options.limit;
|
|
126
|
+
}
|
|
127
|
+
if (options.skip) {
|
|
128
|
+
optionsQuery['skip'] = options.skip;
|
|
129
|
+
}
|
|
130
|
+
return resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection).find(query, optionsQuery);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
// Insert 1 document
|
|
135
|
+
// @Inputs: collection, document
|
|
136
|
+
// @Outputs: res = _id of new document, err = not inserted
|
|
137
|
+
insertDocument: {
|
|
138
|
+
check: new simpl_schema_1.default({
|
|
139
|
+
collection: {
|
|
140
|
+
type: String
|
|
141
|
+
},
|
|
142
|
+
document: {
|
|
143
|
+
type: Object,
|
|
144
|
+
blackbox: true
|
|
145
|
+
}
|
|
146
|
+
}),
|
|
147
|
+
function: function (collection, document) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
+
var id;
|
|
150
|
+
return __generator(this, function (_a) {
|
|
151
|
+
switch (_a.label) {
|
|
152
|
+
case 0:
|
|
153
|
+
if (!!resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection)) return [3 /*break*/, 1];
|
|
154
|
+
throw new Error('Error in Insert Document Collection: Invalid collection');
|
|
155
|
+
case 1:
|
|
156
|
+
id = (0, common_1.objectIdHexString)();
|
|
157
|
+
document['_id'] = id;
|
|
158
|
+
document['__v'] = 0;
|
|
159
|
+
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection).insertOne(document)];
|
|
160
|
+
case 2:
|
|
161
|
+
_a.sent();
|
|
162
|
+
return [2 /*return*/, id];
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
// Insert 1 document
|
|
169
|
+
// @Inputs: collection, document
|
|
170
|
+
// @Outputs: res = _id of new document, err = not inserted
|
|
171
|
+
insertManyDocuments: {
|
|
172
|
+
check: new simpl_schema_1.default({
|
|
173
|
+
collection: {
|
|
174
|
+
type: String
|
|
175
|
+
},
|
|
176
|
+
documents: {
|
|
177
|
+
type: Array
|
|
178
|
+
},
|
|
179
|
+
'documents.$': {
|
|
180
|
+
type: Object,
|
|
181
|
+
blackbox: true
|
|
182
|
+
}
|
|
183
|
+
}),
|
|
184
|
+
function: function (collection, documents) {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
186
|
+
return __generator(this, function (_a) {
|
|
187
|
+
switch (_a.label) {
|
|
188
|
+
case 0:
|
|
189
|
+
if (!!resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection)) return [3 /*break*/, 1];
|
|
190
|
+
throw new Error('Error in Insert Many Documents Collection: Invalid collection');
|
|
191
|
+
case 1:
|
|
192
|
+
documents.forEach(function (document) {
|
|
193
|
+
document['_id'] = (0, common_1.objectIdHexString)();
|
|
194
|
+
document['__v'] = 0;
|
|
195
|
+
});
|
|
196
|
+
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection).insertMany(documents)];
|
|
197
|
+
case 2:
|
|
198
|
+
_a.sent();
|
|
199
|
+
return [2 /*return*/, documents.map(function (a) { return a['_id']; })];
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
// Replaces 1 document with new document (from _id)
|
|
206
|
+
// @Inputs: collection, document id
|
|
207
|
+
// @Outputs: res = 1 (updated 1), err = not updated/wrong version
|
|
208
|
+
// Search for doc, check version, if found then try and update
|
|
209
|
+
updateDocument: {
|
|
210
|
+
check: new simpl_schema_1.default({
|
|
211
|
+
collection: {
|
|
212
|
+
type: String
|
|
213
|
+
},
|
|
214
|
+
f_document: {
|
|
215
|
+
type: Object,
|
|
216
|
+
blackbox: true
|
|
217
|
+
}
|
|
218
|
+
}),
|
|
219
|
+
function: function (collection, f_document) {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
221
|
+
return __generator(this, function (_a) {
|
|
222
|
+
switch (_a.label) {
|
|
223
|
+
case 0:
|
|
224
|
+
if (!resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
225
|
+
throw new Error('Error in Update Document Collection: Invalid collection');
|
|
226
|
+
}
|
|
227
|
+
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: f_document['_id'] }, f_document)];
|
|
228
|
+
case 1:
|
|
229
|
+
_a.sent();
|
|
230
|
+
return [2 /*return*/, true];
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
// Updates 1 document's props (from _id)
|
|
237
|
+
// @Inputs: collection, document id, document version, update paramters ({prop: 'xxx', data: 'yyy})
|
|
238
|
+
// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version
|
|
239
|
+
// Search for doc, check version, if found then try and update props
|
|
240
|
+
updateDocumentProps: {
|
|
241
|
+
check: new simpl_schema_1.default({
|
|
242
|
+
collection: {
|
|
243
|
+
type: String
|
|
244
|
+
},
|
|
245
|
+
doc_id: {
|
|
246
|
+
type: String
|
|
247
|
+
},
|
|
248
|
+
updateParams: {
|
|
249
|
+
type: Array
|
|
250
|
+
},
|
|
251
|
+
'updateParams.$': {
|
|
252
|
+
type: Object,
|
|
253
|
+
blackbox: true
|
|
254
|
+
},
|
|
255
|
+
doc__v: {
|
|
256
|
+
type: Number,
|
|
257
|
+
optional: true
|
|
258
|
+
}
|
|
259
|
+
}),
|
|
260
|
+
function: function (collection, doc_id, updateParams, doc__v) {
|
|
261
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
262
|
+
var currDoc, modifiedDoc_1, oldDoc, newCurrDocId, newCurrDocV, updatedDoc;
|
|
263
|
+
return __generator(this, function (_a) {
|
|
264
|
+
switch (_a.label) {
|
|
265
|
+
case 0:
|
|
266
|
+
if (!!resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection)) return [3 /*break*/, 1];
|
|
267
|
+
throw new Error('Error in Update Document Props Collection: Invalid collection');
|
|
268
|
+
case 1: return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection).findOne({ _id: doc_id })];
|
|
269
|
+
case 2:
|
|
270
|
+
currDoc = _a.sent();
|
|
271
|
+
if (!currDoc) return [3 /*break*/, 11];
|
|
272
|
+
modifiedDoc_1 = (0, common_1.deepCopy)(currDoc);
|
|
273
|
+
updateParams.forEach(function (data) {
|
|
274
|
+
modifiedDoc_1[data.prop] = data.data;
|
|
275
|
+
});
|
|
276
|
+
if (!(!doc__v || modifiedDoc_1.__v === doc__v)) return [3 /*break*/, 4];
|
|
277
|
+
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: modifiedDoc_1._id }, modifiedDoc_1, {}, false, false, currDoc)];
|
|
278
|
+
case 3:
|
|
279
|
+
_a.sent();
|
|
280
|
+
return [3 /*break*/, 10];
|
|
281
|
+
case 4:
|
|
282
|
+
console.log(new Date(), 'invalid version - ' + collection, currDoc.__v, doc__v);
|
|
283
|
+
if (!resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection + '.versions')) return [3 /*break*/, 9];
|
|
284
|
+
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({
|
|
285
|
+
_id: {
|
|
286
|
+
_id: currDoc._id,
|
|
287
|
+
__v: doc__v
|
|
288
|
+
}
|
|
289
|
+
})];
|
|
290
|
+
case 5:
|
|
291
|
+
oldDoc = _a.sent();
|
|
292
|
+
newCurrDocId = currDoc._id;
|
|
293
|
+
newCurrDocV = currDoc.__v;
|
|
294
|
+
if (!oldDoc) return [3 /*break*/, 7];
|
|
295
|
+
updatedDoc = (0, common_1.getMongoMergeUpdatedDoc)(modifiedDoc_1, currDoc, oldDoc);
|
|
296
|
+
updatedDoc._id = newCurrDocId;
|
|
297
|
+
updatedDoc.__v = newCurrDocV;
|
|
298
|
+
currDoc._id = newCurrDocId;
|
|
299
|
+
currDoc.__v = newCurrDocV;
|
|
300
|
+
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: newCurrDocId }, updatedDoc, {}, false, false, currDoc)];
|
|
301
|
+
case 6:
|
|
302
|
+
_a.sent();
|
|
303
|
+
return [3 /*break*/, 8];
|
|
304
|
+
case 7: throw new Error('Error In Update Document Props Collections: Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV + ', Trying to update with :' + doc__v);
|
|
305
|
+
case 8: return [3 /*break*/, 10];
|
|
306
|
+
case 9: throw new Error('Error In Update Document Props Collections: Invalid Version And We Are NOT Using Versions On This Collection!');
|
|
307
|
+
case 10: return [3 /*break*/, 12];
|
|
308
|
+
case 11: throw new Error('Error in Update Document Props Collections: No Document');
|
|
309
|
+
case 12: return [2 /*return*/, true];
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
updateDocumentOffline: {
|
|
316
|
+
check: new simpl_schema_1.default({
|
|
317
|
+
collection: {
|
|
318
|
+
type: String
|
|
319
|
+
},
|
|
320
|
+
f_document: {
|
|
321
|
+
type: Object,
|
|
322
|
+
blackbox: true
|
|
323
|
+
}
|
|
324
|
+
}),
|
|
325
|
+
function: function (collection, f_document) {
|
|
326
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
327
|
+
var currDoc, newCurrDocId, newCurrDocV, oldDocV, oldDoc, updatedDoc;
|
|
328
|
+
return __generator(this, function (_a) {
|
|
329
|
+
switch (_a.label) {
|
|
330
|
+
case 0:
|
|
331
|
+
if (!!resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection)) return [3 /*break*/, 1];
|
|
332
|
+
throw new Error('Error in Update Document Offline Collection: Invalid collection');
|
|
333
|
+
case 1: return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection).findOne({ _id: f_document['_id'] })];
|
|
334
|
+
case 2:
|
|
335
|
+
currDoc = _a.sent();
|
|
336
|
+
if (!currDoc) return [3 /*break*/, 11];
|
|
337
|
+
if (!(currDoc.__v === f_document['__v'])) return [3 /*break*/, 4];
|
|
338
|
+
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: f_document['_id'] }, f_document, {}, false, false, currDoc)];
|
|
339
|
+
case 3:
|
|
340
|
+
_a.sent();
|
|
341
|
+
return [3 /*break*/, 10];
|
|
342
|
+
case 4:
|
|
343
|
+
console.log('OFFLINE - invalid version - ' + collection, currDoc.__v, f_document['__v']);
|
|
344
|
+
newCurrDocId = currDoc._id;
|
|
345
|
+
newCurrDocV = currDoc.__v;
|
|
346
|
+
oldDocV = f_document['__v'];
|
|
347
|
+
if (!resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection + '.versions')) return [3 /*break*/, 9];
|
|
348
|
+
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({
|
|
349
|
+
_id: {
|
|
350
|
+
_id: newCurrDocId,
|
|
351
|
+
__v: oldDocV
|
|
352
|
+
}
|
|
353
|
+
})];
|
|
354
|
+
case 5:
|
|
355
|
+
oldDoc = _a.sent();
|
|
356
|
+
if (!oldDoc) return [3 /*break*/, 7];
|
|
357
|
+
updatedDoc = (0, common_1.getMongoMergeUpdatedDoc)(f_document, currDoc, oldDoc);
|
|
358
|
+
updatedDoc._id = newCurrDocId;
|
|
359
|
+
updatedDoc.__v = newCurrDocV;
|
|
360
|
+
currDoc._id = newCurrDocId;
|
|
361
|
+
currDoc.__v = newCurrDocV;
|
|
362
|
+
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: newCurrDocId }, updatedDoc, {}, false, false, currDoc)];
|
|
363
|
+
case 6:
|
|
364
|
+
_a.sent();
|
|
365
|
+
return [3 /*break*/, 8];
|
|
366
|
+
case 7: throw new Error('Error in Update Document Offline Collections: OFFLINE - Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV + ', Trying to update with :' + oldDocV);
|
|
367
|
+
case 8: return [3 /*break*/, 10];
|
|
368
|
+
case 9: throw new Error('Error in Update Document Offline Collections: Invalid Version And We Are NOT Using Versions On This Collection!');
|
|
369
|
+
case 10: return [3 /*break*/, 12];
|
|
370
|
+
case 11: throw new Error('Error in Update Document Offline Collections: No Document');
|
|
371
|
+
case 12: return [2 /*return*/, true];
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
// Updates 1 document's props (from _id)
|
|
378
|
+
// @Inputs: collection, document id, document version, update paramters ({prop: 'xxx', data: 'yyy})
|
|
379
|
+
// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version
|
|
380
|
+
// Search for doc, check version, if found then try and update props
|
|
381
|
+
updateDocumentPropsOffline: {
|
|
382
|
+
check: new simpl_schema_1.default({
|
|
383
|
+
collection: {
|
|
384
|
+
type: String
|
|
385
|
+
},
|
|
386
|
+
doc_id: {
|
|
387
|
+
type: String
|
|
388
|
+
},
|
|
389
|
+
updateParams: {
|
|
390
|
+
type: Array
|
|
391
|
+
},
|
|
392
|
+
'updateParams.$': {
|
|
393
|
+
type: Object,
|
|
394
|
+
blackbox: true
|
|
395
|
+
},
|
|
396
|
+
doc__v: {
|
|
397
|
+
type: Number
|
|
398
|
+
}
|
|
399
|
+
}),
|
|
400
|
+
function: function (collection, doc_id, updateParams, doc__v) {
|
|
401
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
402
|
+
var currDoc, modifiedDoc_2, newCurrDocId, newCurrDocV, oldDoc, updatedDoc;
|
|
403
|
+
return __generator(this, function (_a) {
|
|
404
|
+
switch (_a.label) {
|
|
405
|
+
case 0:
|
|
406
|
+
if (!!resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection)) return [3 /*break*/, 1];
|
|
407
|
+
throw new Error('Error in Update Document Props Offline Collection: Invalid collection');
|
|
408
|
+
case 1: return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection).findOne({ _id: doc_id }, null, true)];
|
|
409
|
+
case 2:
|
|
410
|
+
currDoc = _a.sent();
|
|
411
|
+
if (!currDoc) return [3 /*break*/, 11];
|
|
412
|
+
modifiedDoc_2 = (0, common_1.deepCopy)(currDoc);
|
|
413
|
+
updateParams.forEach(function (data) {
|
|
414
|
+
modifiedDoc_2[data.prop] = data.data;
|
|
415
|
+
});
|
|
416
|
+
if (!(modifiedDoc_2.__v === doc__v)) return [3 /*break*/, 4];
|
|
417
|
+
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: modifiedDoc_2._id }, modifiedDoc_2, {}, false, false, currDoc)];
|
|
418
|
+
case 3:
|
|
419
|
+
_a.sent();
|
|
420
|
+
return [3 /*break*/, 10];
|
|
421
|
+
case 4:
|
|
422
|
+
console.log('OFFLINE - invalid version - ' + collection, currDoc.__v, doc__v);
|
|
423
|
+
newCurrDocId = currDoc._id;
|
|
424
|
+
newCurrDocV = currDoc.__v;
|
|
425
|
+
if (!resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection + '.versions')) return [3 /*break*/, 9];
|
|
426
|
+
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({
|
|
427
|
+
_id: {
|
|
428
|
+
_id: currDoc._id,
|
|
429
|
+
__v: doc__v
|
|
430
|
+
}
|
|
431
|
+
})];
|
|
432
|
+
case 5:
|
|
433
|
+
oldDoc = _a.sent();
|
|
434
|
+
if (!oldDoc) return [3 /*break*/, 7];
|
|
435
|
+
updatedDoc = (0, common_1.getMongoMergeUpdatedDoc)(modifiedDoc_2, currDoc, oldDoc);
|
|
436
|
+
updatedDoc._id = newCurrDocId;
|
|
437
|
+
updatedDoc.__v = newCurrDocV;
|
|
438
|
+
currDoc._id = newCurrDocId;
|
|
439
|
+
currDoc.__v = newCurrDocV;
|
|
440
|
+
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: newCurrDocId }, updatedDoc, {}, false, false, currDoc)];
|
|
441
|
+
case 6:
|
|
442
|
+
_a.sent();
|
|
443
|
+
return [3 /*break*/, 8];
|
|
444
|
+
case 7: throw 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);
|
|
445
|
+
case 8: return [3 /*break*/, 10];
|
|
446
|
+
case 9: throw new Error('Error in Update Document Props Offline Collections: Invalid Version And We Are NOT Using Versions On This Collection!');
|
|
447
|
+
case 10: return [3 /*break*/, 12];
|
|
448
|
+
case 11: throw new Error('Error in Update Document Props Offline Collections: No Document');
|
|
449
|
+
case 12: return [2 /*return*/, true];
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
},
|
|
455
|
+
// Removes 1 document (from _id)
|
|
456
|
+
// @Inputs: collection, document id
|
|
457
|
+
// @Outputs: res = 1 (deleted), res = 0 (not deleted), err = not deleted
|
|
458
|
+
// Search for doc, if found then try and remove
|
|
459
|
+
removeDocument: {
|
|
460
|
+
check: new simpl_schema_1.default({
|
|
461
|
+
collection: {
|
|
462
|
+
type: String
|
|
463
|
+
},
|
|
464
|
+
doc_id: {
|
|
465
|
+
type: String
|
|
466
|
+
}
|
|
467
|
+
}),
|
|
468
|
+
function: function (collection, doc_id) {
|
|
469
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
470
|
+
return __generator(this, function (_a) {
|
|
471
|
+
switch (_a.label) {
|
|
472
|
+
case 0:
|
|
473
|
+
if (!resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
474
|
+
throw new Error('Error in Remove Document Collection: Invalid collection');
|
|
475
|
+
}
|
|
476
|
+
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection).deleteOne({ _id: doc_id })];
|
|
477
|
+
case 1:
|
|
478
|
+
_a.sent();
|
|
479
|
+
return [2 /*return*/, true];
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
},
|
|
485
|
+
removeDocumentWithQuery: {
|
|
486
|
+
check: new simpl_schema_1.default({
|
|
487
|
+
collection: {
|
|
488
|
+
type: String
|
|
489
|
+
},
|
|
490
|
+
query: {
|
|
491
|
+
type: Object,
|
|
492
|
+
blackbox: true
|
|
493
|
+
}
|
|
494
|
+
}),
|
|
495
|
+
function: function (collection, query) {
|
|
496
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
497
|
+
return __generator(this, function (_a) {
|
|
498
|
+
switch (_a.label) {
|
|
499
|
+
case 0:
|
|
500
|
+
if (!resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
501
|
+
throw new Error('Error in Remove Document With Query Collection: Invalid collection');
|
|
502
|
+
}
|
|
503
|
+
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection).deleteOne(query)];
|
|
504
|
+
case 1:
|
|
505
|
+
_a.sent();
|
|
506
|
+
return [2 /*return*/, true];
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
},
|
|
512
|
+
removeDocumentsWithQuery: {
|
|
513
|
+
check: new simpl_schema_1.default({
|
|
514
|
+
collection: {
|
|
515
|
+
type: String
|
|
516
|
+
},
|
|
517
|
+
query: {
|
|
518
|
+
type: Object,
|
|
519
|
+
blackbox: true
|
|
520
|
+
}
|
|
521
|
+
}),
|
|
522
|
+
function: function (collection, query) {
|
|
523
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
524
|
+
return __generator(this, function (_a) {
|
|
525
|
+
switch (_a.label) {
|
|
526
|
+
case 0:
|
|
527
|
+
if (!resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
528
|
+
throw new Error('Error in Remove Documents With Query Collections: Invalid Collection');
|
|
529
|
+
}
|
|
530
|
+
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collection).deleteMany(query)];
|
|
531
|
+
case 1:
|
|
532
|
+
_a.sent();
|
|
533
|
+
return [2 /*return*/, true];
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
exports.loadCollectionMethods = loadCollectionMethods;
|
|
542
|
+
|
|
2
543
|
//# sourceMappingURL=collections.js.map
|