@resolveio/server-lib 12.0.0 → 12.0.1

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.
@@ -69,6 +69,7 @@ setInterval(function () { return __awaiter(void 0, void 0, void 0, function () {
69
69
  });
70
70
  }); }, 1);
71
71
  function generatePDF(data) {
72
+ console.log('Running generate PDF');
72
73
  var html = data[0];
73
74
  var fileName = data[1];
74
75
  var orientation = data[2] || 'portrait';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/multi_threaded/helper_thread.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAM,IAAA,KAAqC,OAAO,CAAC,gBAAgB,CAAC,EAA5D,UAAU,gBAAA,EAAE,UAAU,gBAAA,EAAE,MAAM,YAA8B,CAAC;AACrE,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAGvB,IAAI,QAAQ,GAA0B,EAAE,CAAC;AACzC,IAAI,YAAY,GAAG,KAAK,CAAC;AAEzB,IAAI,MAAM,GAAG,CAAC,CAAC;AAEf,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAErC,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,UAAC,GAAwB;IAC9C,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;AAC/B,CAAC,CAAC,CAAC;AAEH,WAAW,CAAC;;;QACR,IAAI,CAAC,YAAY,IAAI,QAAQ,CAAC,MAAM,EAAE;YAClC,YAAY,GAAG,IAAI,CAAC;YAEhB,QAAM,QAAQ,CAAC,GAAG,EAAE,CAAC;YACzB,IAAI,KAAG,CAAC,MAAM,KAAK,aAAa,EAAE;gBAC9B,WAAW,CAAC,KAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,UAAA,GAAG;oBAC5B,KAAG,CAAC,MAAM,GAAG,GAAG,CAAC;oBACjB,KAAG,CAAC,KAAK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,MAAM,EAAE,KAAK;wBACb,OAAO,EAAE,KAAK;qBACjB,CAAC,CAAC,IAAI,CAAC;wBACJ,IAAI,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE;4BAC5B,EAAE,CAAC,QAAQ,CAAC,WAAW,EAAE,UAAC,OAAO,EAAE,IAAI;gCACnC,IAAI,CAAC,OAAO,EAAE;oCACV,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;oCAC3B,OAAO,CAAC,8BAA8B,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;iCAClF;qCACI;oCACF,MAAM,CAAC,SAAS,CAAC,CAAC;iCACpB;gCAED,UAAU,CAAC,cAAa,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;4BACrD,CAAC,CAAC,CAAC;yBACN;6BACI;4BACD,MAAM,CAAC,aAAa,CAAC,CAAC;4BACtB,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;yBAC5C;oBACL,CAAC,EAAE,UAAA,GAAG;wBACF,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;wBACjB,UAAU,CAAC,cAAa,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;oBACrD,CAAC,CAAC,CAAC;iBACN;YACL,CAAC,EAAE,IAAI,CAAC,CAAC;QACb,CAAC,EAAE,UAAA,KAAK;YACJ,MAAM,CAAC,KAAK,CAAC,CAAC;YACd,UAAU,CAAC,cAAa,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC","file":"helper_thread.js","sourcesContent":["const { workerData, parentPort, Worker } = require('worker_threads');\nlet fs = require('fs');\nimport { HelperThreadMessage } from 'src/managers/method.manager';\n\nlet jobQueue: HelperThreadMessage[] = [];\nlet runningQueue = false;\n\nlet pdfCnt = 0;\n\nconsole.log('Helper thread started');\n\nparentPort.on('message', (msg: HelperThreadMessage) => {\n jobQueue.splice(0, 0, msg);\n});\n\nsetInterval(async () => {\n if (!runningQueue && jobQueue.length) {\n runningQueue = true;\n\n let job = jobQueue.pop();\n if (job.method === 'generatePDF') {\n generatePDF(job.params).then(res => {\n job.result = res;\n job.error = false;\n parentPort.postMessage(job);\n runningQueue = false;\n }, err => {\n job.result = err;\n job.error = true;\n parentPort.postMessage(job);\n runningQueue = false;\n });\n }\n }\n}, 1);\n\nfunction generatePDF(data: any[]) {\n let html = data[0];\n let fileName = data[1];\n let orientation = data[2] || 'portrait';\n let fontSize = data[3] || '8px';\n \n return new Promise((resolve, reject) => {\n let phantom = require('phantom');\n let phInstance = null;\n \n phantom.create().then(instance => {\n phInstance = instance;\n return instance.createPage();\n }).then(page => {\n let requestsArray = [];\n\n page.on('onResourceRequested', (requestData, networkRequest) => {\n requestsArray.push(requestData.id);\n });\n\n page.on('onResourceReceived', (response) => {\n if (response.stage === 'end') {\n let index = requestsArray.indexOf(response.id);\n requestsArray.splice(index, 1);\n }\n });\n\n page.property('paperSize', {\n format: 'letter',\n margin: '1cm',\n orientation: orientation,\n footer: {\n height: '1cm',\n contents: phInstance.callback((pageNum, numPages) => {\n return '<span style=\\'float:right; font-size: 12px;\\'>Page ' + pageNum + ' of ' + numPages + '</span>';\n })\n }\n });\n page.property('content', `\n <head>\n <style>\n @font-face {\n font-family: 'Dejavu Serif', serif;\n font-style: normal;\n font-weight: normal;\n src: url(\"/usr/share/fonts/dejavu/DejaVuSerif.ttf\");\n }\n\n @font-face {\n font-family: 'Dejavu Serif', serif;\n font-style: normal;\n font-weight: bold;\n src: url(\"/usr/share/fonts/dejavu/DejaVuSerif-Bold.ttf\");\n }\n\n @font-face {\n font-family: 'Dejavu Serif', serif;\n font-style: italic;\n font-weight: normal;\n src: url(\"/usr/share/fonts/dejavu/DejaVuSerif-Italic.ttf\");\n }\n\n @font-face {\n font-family: 'Dejavu Serif', serif;\n font-style: italic;\n font-weight: bold;\n src: url(\"/usr/share/fonts/dejavu/DejaVuSerif-BoldItalic.ttf\");\n }\n\n body {\n font-family: 'Dejavu Serif', serif;\n font-size: ` + (fontSize ? fontSize : '8px') + `;\n }\n\n .row {\n display: -webkit-flex;\n display: flex;\n flex-wrap: wrap;\n -webkit-flex-wrap: wrap;\n }\n \n .page-break {\n page-break-before: always !important;\n margin-bottom: 1px;\n }\n\n .cell {\n box-sizing: border-box;\n padding : 2px;\n -webkit-flex: 1;\n word-wrap: break-word;\n }\n\n .cell-no-padding {\n box-sizing: border-box;\n -webkit-flex: 1;\n word-wrap: break-word;\n }\n\n .centered {\n -webkit-justify-content: center;\n -webkit-align-items: center;\n display: -webkit-flex;\n text-align: center;\n }\n\n .centered-left {\n -webkit-align-items: center;\n display: -webkit-flex;\n -webkit-justify-content: flex-start;\n }\n\n .centered-right {\n -webkit-justify-content: flex-end;\n -webkit-align-items: center;\n display: -webkit-flex;\n }\n \n .box {\n border: 1px solid black;\n margin: -1px 0px 0px -1px;\n }\n\n .boxNoBorder {\n margin: -1px 0px 0px -1px;\n }\n\n pre {\n white-space: pre-wrap; /* css-3 */\n white-space: -moz-pre-wrap; /* Mozilla, since 1999 */\n white-space: -pre-wrap; /* Opera 4-6 */\n white-space: -o-pre-wrap; /* Opera 7 */\n word-wrap: break-word; /* Internet Explorer 5.5+ */\n font-size: 12px;\n font-family: Open Sans; \n }\n </style>\n </head>\n <body>\n ` + html.replace(new RegExp('flex-basis:', 'g'), '-webkit-flex-basis:').replace(new RegExp('flex:', 'g'), '-webkit-flex:') + '</body>');\n let tmpFileName = (pdfCnt++) + '-' + fileName.replace(new RegExp(/\\W/g), '');\n \n let interval = setInterval(() => {\n if (requestsArray.length === 0) {\n clearInterval(interval);\n \n page.render(tmpFileName, {\n format: 'pdf',\n quality: '100'\n }).then(() => {\n if (fs.existsSync(tmpFileName)) {\n fs.readFile(tmpFileName, (errRead, data) => {\n if (!errRead) {\n fs.unlinkSync(tmpFileName);\n resolve('data:application/pdf;base64,' + Buffer.from(data).toString('base64'));\n }\n else {\n reject('No file');\n }\n \n setTimeout(function() { phInstance.exit(); }, 0);\n });\n }\n else {\n reject('No tmp file');\n console.log('No tmp file ', tmpFileName);\n }\n }, err => {\n console.log(err);\n setTimeout(function() { phInstance.exit(); }, 0);\n });\n }\n }, 1000);\n }, error => {\n reject(error);\n setTimeout(function() { phInstance.exit(); }, 0);\n });\n });\n}"]}
1
+ {"version":3,"sources":["../../src/multi_threaded/helper_thread.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAM,IAAA,KAAqC,OAAO,CAAC,gBAAgB,CAAC,EAA5D,UAAU,gBAAA,EAAE,UAAU,gBAAA,EAAE,MAAM,YAA8B,CAAC;AACrE,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAGvB,IAAI,QAAQ,GAA0B,EAAE,CAAC;AACzC,IAAI,YAAY,GAAG,KAAK,CAAC;AAEzB,IAAI,MAAM,GAAG,CAAC,CAAC;AAEf,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAErC,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,UAAC,GAAwB;IAC9C,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;AAC/B,CAAC,CAAC,CAAC;AAEH,WAAW,CAAC;;;QACR,IAAI,CAAC,YAAY,IAAI,QAAQ,CAAC,MAAM,EAAE;YAClC,YAAY,GAAG,IAAI,CAAC;YAEhB,QAAM,QAAQ,CAAC,GAAG,EAAE,CAAC;YACzB,IAAI,KAAG,CAAC,MAAM,KAAK,aAAa,EAAE;gBAC9B,WAAW,CAAC,KAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,UAAA,GAAG;oBAC5B,KAAG,CAAC,MAAM,G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thread.js","sourcesContent":["const { workerData, parentPort, Worker } = require('worker_threads');\nlet fs = require('fs');\nimport { HelperThreadMessage } from 'src/managers/method.manager';\n\nlet jobQueue: HelperThreadMessage[] = [];\nlet runningQueue = false;\n\nlet pdfCnt = 0;\n\nconsole.log('Helper thread started');\n\nparentPort.on('message', (msg: HelperThreadMessage) => {\n jobQueue.splice(0, 0, msg);\n});\n\nsetInterval(async () => {\n if (!runningQueue && jobQueue.length) {\n runningQueue = true;\n\n let job = jobQueue.pop();\n if (job.method === 'generatePDF') {\n generatePDF(job.params).then(res => {\n job.result = res;\n job.error = false;\n parentPort.postMessage(job);\n runningQueue = false;\n }, err => {\n job.result = err;\n job.error = true;\n parentPort.postMessage(job);\n runningQueue = false;\n });\n }\n }\n}, 1);\n\nfunction generatePDF(data: any[]) {\n console.log('Running generate PDF');\n \n let html = data[0];\n let fileName = data[1];\n let orientation = data[2] || 'portrait';\n let fontSize = data[3] || '8px';\n\n return new Promise((resolve, reject) => {\n let phantom = require('phantom');\n let phInstance = null;\n \n phantom.create().then(instance => {\n phInstance = instance;\n return instance.createPage();\n }).then(page => {\n let requestsArray = [];\n\n page.on('onResourceRequested', (requestData, networkRequest) => {\n requestsArray.push(requestData.id);\n });\n\n page.on('onResourceReceived', (response) => {\n if (response.stage === 'end') {\n let index = requestsArray.indexOf(response.id);\n requestsArray.splice(index, 1);\n }\n });\n\n page.property('paperSize', {\n format: 'letter',\n margin: '1cm',\n orientation: orientation,\n footer: {\n height: '1cm',\n contents: phInstance.callback((pageNum, numPages) => {\n return '<span style=\\'float:right; font-size: 12px;\\'>Page ' + pageNum + ' of ' + numPages + '</span>';\n })\n }\n });\n page.property('content', `\n <head>\n <style>\n @font-face {\n font-family: 'Dejavu Serif', serif;\n font-style: normal;\n font-weight: normal;\n src: url(\"/usr/share/fonts/dejavu/DejaVuSerif.ttf\");\n }\n\n @font-face {\n font-family: 'Dejavu Serif', serif;\n font-style: normal;\n font-weight: bold;\n src: url(\"/usr/share/fonts/dejavu/DejaVuSerif-Bold.ttf\");\n }\n\n @font-face {\n font-family: 'Dejavu Serif', serif;\n font-style: italic;\n font-weight: normal;\n src: url(\"/usr/share/fonts/dejavu/DejaVuSerif-Italic.ttf\");\n }\n\n @font-face {\n font-family: 'Dejavu Serif', serif;\n font-style: italic;\n font-weight: bold;\n src: url(\"/usr/share/fonts/dejavu/DejaVuSerif-BoldItalic.ttf\");\n }\n\n body {\n font-family: 'Dejavu Serif', serif;\n font-size: ` + (fontSize ? fontSize : '8px') + `;\n }\n\n .row {\n display: -webkit-flex;\n display: flex;\n flex-wrap: wrap;\n -webkit-flex-wrap: wrap;\n }\n \n .page-break {\n page-break-before: always !important;\n margin-bottom: 1px;\n }\n\n .cell {\n box-sizing: border-box;\n padding : 2px;\n -webkit-flex: 1;\n word-wrap: break-word;\n }\n\n .cell-no-padding {\n box-sizing: border-box;\n -webkit-flex: 1;\n word-wrap: break-word;\n }\n\n .centered {\n -webkit-justify-content: center;\n -webkit-align-items: center;\n display: -webkit-flex;\n text-align: center;\n }\n\n .centered-left {\n -webkit-align-items: center;\n display: -webkit-flex;\n -webkit-justify-content: flex-start;\n }\n\n .centered-right {\n -webkit-justify-content: flex-end;\n -webkit-align-items: center;\n display: -webkit-flex;\n }\n \n .box {\n border: 1px solid black;\n margin: -1px 0px 0px -1px;\n }\n\n .boxNoBorder {\n margin: -1px 0px 0px -1px;\n }\n\n pre {\n white-space: pre-wrap; /* css-3 */\n white-space: -moz-pre-wrap; /* Mozilla, since 1999 */\n white-space: -pre-wrap; /* Opera 4-6 */\n white-space: -o-pre-wrap; /* Opera 7 */\n word-wrap: break-word; /* Internet Explorer 5.5+ */\n font-size: 12px;\n font-family: Open Sans; \n }\n </style>\n </head>\n <body>\n ` + html.replace(new RegExp('flex-basis:', 'g'), '-webkit-flex-basis:').replace(new RegExp('flex:', 'g'), '-webkit-flex:') + '</body>');\n let tmpFileName = (pdfCnt++) + '-' + fileName.replace(new RegExp(/\\W/g), '');\n \n let interval = setInterval(() => {\n if (requestsArray.length === 0) {\n clearInterval(interval);\n \n page.render(tmpFileName, {\n format: 'pdf',\n quality: '100'\n }).then(() => {\n if (fs.existsSync(tmpFileName)) {\n fs.readFile(tmpFileName, (errRead, data) => {\n if (!errRead) {\n fs.unlinkSync(tmpFileName);\n resolve('data:application/pdf;base64,' + Buffer.from(data).toString('base64'));\n }\n else {\n reject('No file');\n }\n \n setTimeout(function() { phInstance.exit(); }, 0);\n });\n }\n else {\n reject('No tmp file');\n console.log('No tmp file ', tmpFileName);\n }\n }, err => {\n console.log(err);\n setTimeout(function() { phInstance.exit(); }, 0);\n });\n }\n }, 1000);\n }, error => {\n reject(error);\n setTimeout(function() { phInstance.exit(); }, 0);\n });\n });\n}"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "12.0.0",
3
+ "version": "12.0.1",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "package": "npm run build-prod && npm pack ./dist",
package/public_api.d.ts CHANGED
@@ -57,3 +57,4 @@ export * from './models/user-guide.model';
57
57
  export * from './models/user.model';
58
58
  export * from './util/common';
59
59
  export * from './managers/mongo.manager';
60
+ export * from './multi_threaded/helper_thread';
package/public_api.js CHANGED
@@ -69,5 +69,6 @@ __exportStar(require("./models/user-guide.model"), exports);
69
69
  __exportStar(require("./models/user.model"), exports);
70
70
  __exportStar(require("./util/common"), exports);
71
71
  __exportStar(require("./managers/mongo.manager"), exports);
72
+ __exportStar(require("./multi_threaded/helper_thread"), exports);
72
73
 
73
74
  //# sourceMappingURL=public_api.js.map
package/public_api.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/public_api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sEAAoD;AACpD,uEAAqD;AACrD,mEAAiD;AACjD,4EAA0D;AAC1D,oEAAkD;AAClD,yEAAuD;AACvD,0EAAwD;AACxD,gEAA8C;AAC9C,gEAA8C;AAC9C,8EAA4D;AAC5D,4EAA0D;AAC1D,+DAA6C;AAC7C,2EAAyD;AACzD,2EAAyD;AACzD,uEAAqD;AACrD,0EAAwD;AACxD,yEAAuD;AACvD,wEAAsD;AACtD,kFAAgE;AAChE,iFAA+D;AAC/D,sEAAoD;AACpD,sEAAoD;AACpD,gEAA8C;AAC9C,4DAA0C;AAC1C,6DAA2C;AAC3C,yEAAuD;AACvD,qEAAmD;AACnD,yDAAuC;AACvC,kEAAgD;AAChD,0DAAwC;AACxC,wDAAsC;AACtC,+DAA6C;AAC7C,gEAA8C;AAC9C,sDAAoC;AACpC,sDAAoC;AACpC,oEAAkD;AAClD,kEAAgD;AAChD,qDAAmC;AACnC,iEAA+C;AAC/C,iEAA+C;AAC/C,wDAAsC;AACtC,6DAA2C;AAC3C,gEAA8C;AAC9C,+DAA6C;AAC7C,8DAA4C;AAC5C,4DAA0C;AAC1C,4DAA0C;AAC1C,wEAAsD;AACtD,uEAAqD;AACrD,gEAA8C;AAC9C,mEAAiD;AACjD,iEAA+C;AAC/C,8DAA4C;AAC5C,gEAA8C;AAC9C,4DAA0C;AAC1C,4DAA0C;AAC1C,sDAAoC;AACpC,gDAA8B;AAC9B,2DAAyC","file":"public_api.js","sourcesContent":["export * from './collections/app-status.collection';\nexport * from './collections/app-version.collection';\nexport * from './collections/counter.collection';\nexport * from './collections/cron-job-history.collection';\nexport * from './collections/cron-job.collection';\nexport * from './collections/email-history.collection';\nexport * from './collections/email-verified.collection';\nexport * from './collections/file.collection';\nexport * from './collections/flag.collection';\nexport * from './collections/log-method-latency.collection';\nexport * from './collections/log-subscription.collection';\nexport * from './collections/log.collection';\nexport * from './collections/logged-in-users.collection';\nexport * from './collections/method-response.collection';\nexport * from './collections/monitor-cpu.collection';\nexport * from './collections/monitor-memory.collection';\nexport * from './collections/monitor-mongo.collection';\nexport * from './collections/notification.collection';\nexport * from './collections/report-builder-library.collection';\nexport * from './collections/report-builder-report.collection';\nexport * from './collections/user-group.collection';\nexport * from './collections/user-guide.collection';\nexport * from './collections/user.collection';\nexport * from './models/app-status.model';\nexport * from './models/app-version.model';\nexport * from './models/billing-logged-in-users.model';\nexport * from './models/collection-document.model';\nexport * from './models/counter.model';\nexport * from './models/cron-job-history.model';\nexport * from './models/cron-job.model';\nexport * from './models/dialog.model';\nexport * from './models/email-history.model';\nexport * from './models/email-verified.model';\nexport * from './models/file.model';\nexport * from './models/flag.model';\nexport * from './models/log-method-latency.model';\nexport * from './models/log-subscription.model';\nexport * from './models/log.model';\nexport * from './models/logged-in-users.model';\nexport * from './models/method-response.model';\nexport * from './models/method.model';\nexport * from './models/monitor-cpu.model';\nexport * from './models/monitor-memory.model';\nexport * from './models/monitor-mongo.model';\nexport * from './models/notification.model';\nexport * from './models/pagination.model';\nexport * from './models/permission.model';\nexport * from './models/report-builder-library.model';\nexport * from './models/report-builder-report.model';\nexport * from './models/report-builder.model';\nexport * from './models/select-data-label.model';\nexport * from './models/server-response.model';\nexport * from './models/subscription.model';\nexport * from './models/support-ticket.model';\nexport * from './models/user-group.model';\nexport * from './models/user-guide.model';\nexport * from './models/user.model';\nexport * from './util/common';\nexport * from './managers/mongo.manager';"]}
1
+ {"version":3,"sources":["../../src/public_api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sEAAoD;AACpD,uEAAqD;AACrD,mEAAiD;AACjD,4EAA0D;AAC1D,oEAAkD;AAClD,yEAAuD;AACvD,0EAAwD;AACxD,gEAA8C;AAC9C,gEAA8C;AAC9C,8EAA4D;AAC5D,4EAA0D;AAC1D,+DAA6C;AAC7C,2EAAyD;AACzD,2EAAyD;AACzD,uEAAqD;AACrD,0EAAwD;AACxD,yEAAuD;AACvD,wEAAsD;AACtD,kFAAgE;AAChE,iFAA+D;AAC/D,sEAAoD;AACpD,sEAAoD;AACpD,gEAA8C;AAC9C,4DAA0C;AAC1C,6DAA2C;AAC3C,yEAAuD;AACvD,qEAAmD;AACnD,yDAAuC;AACvC,kEAAgD;AAChD,0DAAwC;AACxC,wDAAsC;AACtC,+DAA6C;AAC7C,gEAA8C;AAC9C,sDAAoC;AACpC,sDAAoC;AACpC,oEAAkD;AAClD,kEAAgD;AAChD,qDAAmC;AACnC,iEAA+C;AAC/C,iEAA+C;AAC/C,wDAAsC;AACtC,6DAA2C;AAC3C,gEAA8C;AAC9C,+DAA6C;AAC7C,8DAA4C;AAC5C,4DAA0C;AAC1C,4DAA0C;AAC1C,wEAAsD;AACtD,uEAAqD;AACrD,gEAA8C;AAC9C,mEAAiD;AACjD,iEAA+C;AAC/C,8DAA4C;AAC5C,gEAA8C;AAC9C,4DAA0C;AAC1C,4DAA0C;AAC1C,sDAAoC;AACpC,gDAA8B;AAC9B,2DAAyC;AACzC,iEAA+C","file":"public_api.js","sourcesContent":["export * from './collections/app-status.collection';\nexport * from './collections/app-version.collection';\nexport * from './collections/counter.collection';\nexport * from './collections/cron-job-history.collection';\nexport * from './collections/cron-job.collection';\nexport * from './collections/email-history.collection';\nexport * from './collections/email-verified.collection';\nexport * from './collections/file.collection';\nexport * from './collections/flag.collection';\nexport * from './collections/log-method-latency.collection';\nexport * from './collections/log-subscription.collection';\nexport * from './collections/log.collection';\nexport * from './collections/logged-in-users.collection';\nexport * from './collections/method-response.collection';\nexport * from './collections/monitor-cpu.collection';\nexport * from './collections/monitor-memory.collection';\nexport * from './collections/monitor-mongo.collection';\nexport * from './collections/notification.collection';\nexport * from './collections/report-builder-library.collection';\nexport * from './collections/report-builder-report.collection';\nexport * from './collections/user-group.collection';\nexport * from './collections/user-guide.collection';\nexport * from './collections/user.collection';\nexport * from './models/app-status.model';\nexport * from './models/app-version.model';\nexport * from './models/billing-logged-in-users.model';\nexport * from './models/collection-document.model';\nexport * from './models/counter.model';\nexport * from './models/cron-job-history.model';\nexport * from './models/cron-job.model';\nexport * from './models/dialog.model';\nexport * from './models/email-history.model';\nexport * from './models/email-verified.model';\nexport * from './models/file.model';\nexport * from './models/flag.model';\nexport * from './models/log-method-latency.model';\nexport * from './models/log-subscription.model';\nexport * from './models/log.model';\nexport * from './models/logged-in-users.model';\nexport * from './models/method-response.model';\nexport * from './models/method.model';\nexport * from './models/monitor-cpu.model';\nexport * from './models/monitor-memory.model';\nexport * from './models/monitor-mongo.model';\nexport * from './models/notification.model';\nexport * from './models/pagination.model';\nexport * from './models/permission.model';\nexport * from './models/report-builder-library.model';\nexport * from './models/report-builder-report.model';\nexport * from './models/report-builder.model';\nexport * from './models/select-data-label.model';\nexport * from './models/server-response.model';\nexport * from './models/subscription.model';\nexport * from './models/support-ticket.model';\nexport * from './models/user-group.model';\nexport * from './models/user-guide.model';\nexport * from './models/user.model';\nexport * from './util/common';\nexport * from './managers/mongo.manager';\nexport * from './multi_threaded/helper_thread';"]}