@resolveio/server-lib 12.5.54 → 12.5.55

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.
Files changed (400) hide show
  1. package/client-server-app.d.ts +1 -0
  2. package/client-server-app.js +48 -0
  3. package/client-server-app.js.map +1 -0
  4. package/collections/app-status.collection.d.ts +3 -0
  5. package/collections/app-status.collection.js +51 -0
  6. package/collections/app-status.collection.js.map +1 -0
  7. package/collections/counter.collection.d.ts +3 -0
  8. package/collections/counter.collection.js +54 -0
  9. package/collections/counter.collection.js.map +1 -0
  10. package/collections/cron-job-history.collection.d.ts +3 -0
  11. package/collections/cron-job-history.collection.js +82 -0
  12. package/collections/cron-job-history.collection.js.map +1 -0
  13. package/collections/cron-job.collection.d.ts +3 -0
  14. package/collections/cron-job.collection.js +85 -0
  15. package/collections/cron-job.collection.js.map +1 -0
  16. package/collections/email-history.collection.d.ts +3 -0
  17. package/collections/email-history.collection.js +66 -0
  18. package/collections/email-history.collection.js.map +1 -0
  19. package/collections/email-verified.collection.d.ts +3 -0
  20. package/collections/email-verified.collection.js +61 -0
  21. package/collections/email-verified.collection.js.map +1 -0
  22. package/collections/file.collection.d.ts +3 -0
  23. package/collections/file.collection.js +73 -0
  24. package/collections/file.collection.js.map +1 -0
  25. package/collections/flag.collection.d.ts +3 -0
  26. package/collections/flag.collection.js +56 -0
  27. package/collections/flag.collection.js.map +1 -0
  28. package/collections/log-method-latency.collection.d.ts +3 -0
  29. package/collections/log-method-latency.collection.js +64 -0
  30. package/collections/log-method-latency.collection.js.map +1 -0
  31. package/collections/log-subscription.collection.d.ts +3 -0
  32. package/collections/log-subscription.collection.js +68 -0
  33. package/collections/log-subscription.collection.js.map +1 -0
  34. package/collections/log-ts.collection.d.ts +3 -0
  35. package/collections/log-ts.collection.js +78 -0
  36. package/collections/log-ts.collection.js.map +1 -0
  37. package/collections/log.collection.d.ts +3 -0
  38. package/collections/log.collection.js +77 -0
  39. package/collections/log.collection.js.map +1 -0
  40. package/collections/logged-in-users.collection.d.ts +3 -0
  41. package/collections/logged-in-users.collection.js +65 -0
  42. package/collections/logged-in-users.collection.js.map +1 -0
  43. package/collections/method-response.collection.d.ts +3 -0
  44. package/collections/method-response.collection.js +66 -0
  45. package/collections/method-response.collection.js.map +1 -0
  46. package/collections/monitor-cpu.collection.d.ts +3 -0
  47. package/collections/monitor-cpu.collection.js +63 -0
  48. package/collections/monitor-cpu.collection.js.map +1 -0
  49. package/collections/monitor-memory.collection.d.ts +3 -0
  50. package/collections/monitor-memory.collection.js +75 -0
  51. package/collections/monitor-memory.collection.js.map +1 -0
  52. package/collections/monitor-mongo.collection.d.ts +3 -0
  53. package/collections/monitor-mongo.collection.js +69 -0
  54. package/collections/monitor-mongo.collection.js.map +1 -0
  55. package/collections/notification.collection.d.ts +3 -0
  56. package/collections/notification.collection.js +51 -0
  57. package/collections/notification.collection.js.map +1 -0
  58. package/collections/report-builder-dashboard-builder.collection.d.ts +3 -0
  59. package/collections/report-builder-dashboard-builder.collection.js +109 -0
  60. package/collections/report-builder-dashboard-builder.collection.js.map +1 -0
  61. package/collections/report-builder-library.collection.d.ts +3 -0
  62. package/collections/report-builder-library.collection.js +87 -0
  63. package/collections/report-builder-library.collection.js.map +1 -0
  64. package/collections/report-builder-report.collection.d.ts +4 -0
  65. package/collections/report-builder-report.collection.js +149 -0
  66. package/collections/report-builder-report.collection.js.map +1 -0
  67. package/collections/user-group.collection.d.ts +4 -0
  68. package/collections/user-group.collection.js +90 -0
  69. package/collections/user-group.collection.js.map +1 -0
  70. package/collections/user-guide.collection.d.ts +3 -0
  71. package/collections/user-guide.collection.js +57 -0
  72. package/collections/user-guide.collection.js.map +1 -0
  73. package/collections/user.collection.d.ts +4 -0
  74. package/collections/user.collection.js +259 -0
  75. package/collections/user.collection.js.map +1 -0
  76. package/cron/cron.d.ts +5 -0
  77. package/cron/cron.js +162 -0
  78. package/cron/cron.js.map +1 -0
  79. package/fixtures/cron-jobs.d.ts +1 -0
  80. package/fixtures/cron-jobs.js +73 -0
  81. package/fixtures/cron-jobs.js.map +1 -0
  82. package/fixtures/init.d.ts +1 -0
  83. package/fixtures/init.js +59 -0
  84. package/fixtures/init.js.map +1 -0
  85. package/http/auth.d.ts +2 -0
  86. package/http/auth.js +763 -0
  87. package/http/auth.js.map +1 -0
  88. package/http/health.d.ts +1 -0
  89. package/http/health.js +12 -0
  90. package/http/health.js.map +1 -0
  91. package/http/home.d.ts +2 -0
  92. package/http/home.js +66 -0
  93. package/http/home.js.map +1 -0
  94. package/index.d.ts +23 -0
  95. package/index.js +127 -0
  96. package/index.js.map +1 -0
  97. package/managers/cron.manager.d.ts +17 -0
  98. package/managers/cron.manager.js +242 -0
  99. package/managers/cron.manager.js.map +1 -0
  100. package/managers/method.manager.d.ts +38 -0
  101. package/managers/method.manager.js +595 -0
  102. package/managers/method.manager.js.map +1 -0
  103. package/managers/mongo.manager.d.ts +178 -0
  104. package/managers/mongo.manager.js +2221 -0
  105. package/managers/mongo.manager.js.map +1 -0
  106. package/managers/monitor.manager.d.ts +59 -0
  107. package/managers/monitor.manager.js +351 -0
  108. package/managers/monitor.manager.js.map +1 -0
  109. package/managers/subscription.manager.d.ts +50 -0
  110. package/managers/subscription.manager.js +1091 -0
  111. package/managers/subscription.manager.js.map +1 -0
  112. package/managers/subscription.performance.d.ts +1 -0
  113. package/{src/managers/subscription.performance.ts → managers/subscription.performance.js} +33 -68
  114. package/managers/subscription.performance.js.map +1 -0
  115. package/methods/accounts.d.ts +2 -0
  116. package/methods/accounts.js +274 -0
  117. package/methods/accounts.js.map +1 -0
  118. package/methods/aws.d.ts +2 -0
  119. package/methods/aws.js +617 -0
  120. package/methods/aws.js.map +1 -0
  121. package/methods/collections.d.ts +2 -0
  122. package/methods/collections.js +499 -0
  123. package/methods/collections.js.map +1 -0
  124. package/methods/counters.d.ts +2 -0
  125. package/methods/counters.js +122 -0
  126. package/methods/counters.js.map +1 -0
  127. package/methods/cron-jobs.d.ts +2 -0
  128. package/methods/cron-jobs.js +1315 -0
  129. package/methods/cron-jobs.js.map +1 -0
  130. package/methods/flags.d.ts +2 -0
  131. package/methods/flags.js +9 -0
  132. package/methods/flags.js.map +1 -0
  133. package/methods/logs.d.ts +2 -0
  134. package/methods/logs.js +371 -0
  135. package/methods/logs.js.map +1 -0
  136. package/methods/monitor.d.ts +2 -0
  137. package/methods/monitor.js +565 -0
  138. package/methods/monitor.js.map +1 -0
  139. package/methods/pdf.d.ts +2 -0
  140. package/methods/pdf.js +468 -0
  141. package/methods/pdf.js.map +1 -0
  142. package/methods/report-builder.d.ts +2 -0
  143. package/methods/report-builder.js +858 -0
  144. package/methods/report-builder.js.map +1 -0
  145. package/methods/support.d.ts +2 -0
  146. package/methods/support.js +246 -0
  147. package/methods/support.js.map +1 -0
  148. package/{src/models/app-status.model.ts → models/app-status.model.d.ts} +2 -3
  149. package/models/app-status.model.js +4 -0
  150. package/models/app-status.model.js.map +1 -0
  151. package/{src/models/billing-logged-in-users.model.ts → models/billing-logged-in-users.model.d.ts} +4 -5
  152. package/models/billing-logged-in-users.model.js +4 -0
  153. package/models/billing-logged-in-users.model.js.map +1 -0
  154. package/models/collection-document.model.d.ts +19 -0
  155. package/models/collection-document.model.js +4 -0
  156. package/models/collection-document.model.js.map +1 -0
  157. package/{src/models/counter.model.ts → models/counter.model.d.ts} +3 -4
  158. package/models/counter.model.js +4 -0
  159. package/models/counter.model.js.map +1 -0
  160. package/models/cron-job-history.model.d.ts +12 -0
  161. package/models/cron-job-history.model.js +4 -0
  162. package/models/cron-job-history.model.js.map +1 -0
  163. package/models/cron-job.model.d.ts +13 -0
  164. package/models/cron-job.model.js +4 -0
  165. package/models/cron-job.model.js.map +1 -0
  166. package/models/dialog.model.d.ts +23 -0
  167. package/models/dialog.model.js +4 -0
  168. package/models/dialog.model.js.map +1 -0
  169. package/{src/models/email-history.model.ts → models/email-history.model.d.ts} +7 -8
  170. package/models/email-history.model.js +4 -0
  171. package/models/email-history.model.js.map +1 -0
  172. package/{src/models/email-verified.model.ts → models/email-verified.model.d.ts} +5 -6
  173. package/models/email-verified.model.js +4 -0
  174. package/models/email-verified.model.js.map +1 -0
  175. package/{src/models/file.model.ts → models/file.model.d.ts} +7 -8
  176. package/models/file.model.js +4 -0
  177. package/models/file.model.js.map +1 -0
  178. package/{src/models/flag.model.ts → models/flag.model.d.ts} +3 -4
  179. package/models/flag.model.js +4 -0
  180. package/models/flag.model.js.map +1 -0
  181. package/{src/models/log-method-latency.model.ts → models/log-method-latency.model.d.ts} +4 -5
  182. package/models/log-method-latency.model.js +4 -0
  183. package/models/log-method-latency.model.js.map +1 -0
  184. package/{src/models/log-subscription.model.ts → models/log-subscription.model.d.ts} +6 -8
  185. package/models/log-subscription.model.js +4 -0
  186. package/models/log-subscription.model.js.map +1 -0
  187. package/{src/models/log.model.ts → models/log.model.d.ts} +10 -12
  188. package/models/log.model.js +4 -0
  189. package/models/log.model.js.map +1 -0
  190. package/{src/models/logged-in-users.model.ts → models/logged-in-users.model.d.ts} +5 -6
  191. package/models/logged-in-users.model.js +4 -0
  192. package/models/logged-in-users.model.js.map +1 -0
  193. package/{src/models/method-response.model.ts → models/method-response.model.d.ts} +6 -7
  194. package/models/method-response.model.js +4 -0
  195. package/models/method-response.model.js.map +1 -0
  196. package/models/method.model.d.ts +9 -0
  197. package/models/method.model.js +4 -0
  198. package/models/method.model.js.map +1 -0
  199. package/{src/models/monitor-cpu.model.ts → models/monitor-cpu.model.d.ts} +7 -9
  200. package/models/monitor-cpu.model.js +4 -0
  201. package/models/monitor-cpu.model.js.map +1 -0
  202. package/models/monitor-memory.model.d.ts +15 -0
  203. package/models/monitor-memory.model.js +4 -0
  204. package/models/monitor-memory.model.js.map +1 -0
  205. package/models/monitor-mongo.model.d.ts +13 -0
  206. package/models/monitor-mongo.model.js +4 -0
  207. package/models/monitor-mongo.model.js.map +1 -0
  208. package/{src/models/notification.model.ts → models/notification.model.d.ts} +2 -3
  209. package/models/notification.model.js +4 -0
  210. package/models/notification.model.js.map +1 -0
  211. package/models/pagination.model.d.ts +10 -0
  212. package/models/pagination.model.js +24 -0
  213. package/models/pagination.model.js.map +1 -0
  214. package/models/permission.model.d.ts +12 -0
  215. package/models/permission.model.js +4 -0
  216. package/models/permission.model.js.map +1 -0
  217. package/models/report-builder-dashboard-builder.model.d.ts +25 -0
  218. package/models/report-builder-dashboard-builder.model.js +4 -0
  219. package/models/report-builder-dashboard-builder.model.js.map +1 -0
  220. package/models/report-builder-library.model.d.ts +17 -0
  221. package/models/report-builder-library.model.js +4 -0
  222. package/models/report-builder-library.model.js.map +1 -0
  223. package/models/report-builder-report.model.d.ts +98 -0
  224. package/models/report-builder-report.model.js +4 -0
  225. package/models/report-builder-report.model.js.map +1 -0
  226. package/models/report-builder.model.d.ts +61 -0
  227. package/models/report-builder.model.js +4 -0
  228. package/models/report-builder.model.js.map +1 -0
  229. package/models/select-data-label.model.d.ts +9 -0
  230. package/models/select-data-label.model.js +4 -0
  231. package/models/select-data-label.model.js.map +1 -0
  232. package/models/server-response.model.d.ts +5 -0
  233. package/models/server-response.model.js +4 -0
  234. package/models/server-response.model.js.map +1 -0
  235. package/models/subscription.model.d.ts +23 -0
  236. package/models/subscription.model.js +4 -0
  237. package/models/subscription.model.js.map +1 -0
  238. package/models/support-ticket.model.d.ts +72 -0
  239. package/models/support-ticket.model.js +4 -0
  240. package/models/support-ticket.model.js.map +1 -0
  241. package/models/user-group.model.d.ts +19 -0
  242. package/models/user-group.model.js +4 -0
  243. package/models/user-group.model.js.map +1 -0
  244. package/{src/models/user-guide.model.ts → models/user-guide.model.d.ts} +4 -5
  245. package/models/user-guide.model.js +4 -0
  246. package/models/user-guide.model.js.map +1 -0
  247. package/models/user.model.d.ts +70 -0
  248. package/models/user.model.js +4 -0
  249. package/models/user.model.js.map +1 -0
  250. package/package.json +1 -1
  251. package/{src/public_api.ts → public_api.d.ts} +1 -1
  252. package/public_api.js +75 -0
  253. package/public_api.js.map +1 -0
  254. package/publications/app-status.d.ts +2 -0
  255. package/publications/app-status.js +17 -0
  256. package/publications/app-status.js.map +1 -0
  257. package/publications/cron-jobs.d.ts +2 -0
  258. package/publications/cron-jobs.js +33 -0
  259. package/publications/cron-jobs.js.map +1 -0
  260. package/publications/files.d.ts +2 -0
  261. package/publications/files.js +37 -0
  262. package/publications/files.js.map +1 -0
  263. package/publications/flags.d.ts +2 -0
  264. package/publications/flags.js +23 -0
  265. package/publications/flags.js.map +1 -0
  266. package/publications/logs.d.ts +2 -0
  267. package/publications/logs.js +165 -0
  268. package/publications/logs.js.map +1 -0
  269. package/publications/method-responses.d.ts +2 -0
  270. package/publications/method-responses.js +17 -0
  271. package/publications/method-responses.js.map +1 -0
  272. package/publications/notifications.d.ts +2 -0
  273. package/publications/notifications.js +17 -0
  274. package/publications/notifications.js.map +1 -0
  275. package/publications/report-builder-dashboard-builders.d.ts +2 -0
  276. package/publications/report-builder-dashboard-builders.js +43 -0
  277. package/publications/report-builder-dashboard-builders.js.map +1 -0
  278. package/publications/report-builder-libraries.d.ts +2 -0
  279. package/publications/report-builder-libraries.js +90 -0
  280. package/publications/report-builder-libraries.js.map +1 -0
  281. package/publications/report-builder-reports.d.ts +2 -0
  282. package/publications/report-builder-reports.js +51 -0
  283. package/publications/report-builder-reports.js.map +1 -0
  284. package/publications/super-admin.d.ts +2 -0
  285. package/publications/super-admin.js +17 -0
  286. package/publications/super-admin.js.map +1 -0
  287. package/publications/user-groups.d.ts +1 -0
  288. package/publications/user-groups.js +17 -0
  289. package/publications/user-groups.js.map +1 -0
  290. package/publications/user-guides.d.ts +1 -0
  291. package/publications/user-guides.js +17 -0
  292. package/publications/user-guides.js.map +1 -0
  293. package/server-app.d.ts +52 -0
  294. package/server-app.js +739 -0
  295. package/server-app.js.map +1 -0
  296. package/util/common.d.ts +24 -0
  297. package/util/common.js +511 -0
  298. package/util/common.js.map +1 -0
  299. package/util/schema-report-builder.d.ts +6 -0
  300. package/util/schema-report-builder.js +453 -0
  301. package/util/schema-report-builder.js.map +1 -0
  302. package/.nodemon.json +0 -5
  303. package/.vscode/settings.json +0 -3
  304. package/README.md +0 -22
  305. package/compileDTS.pl +0 -64
  306. package/gulpfile.js +0 -127
  307. package/mongodbensurers.js +0 -2
  308. package/mongostop.js +0 -3
  309. package/settings.development.json +0 -13
  310. package/src/client-server-app.ts +0 -7
  311. package/src/collections/app-status.collection.ts +0 -51
  312. package/src/collections/counter.collection.ts +0 -54
  313. package/src/collections/cron-job-history.collection.ts +0 -82
  314. package/src/collections/cron-job.collection.ts +0 -85
  315. package/src/collections/email-history.collection.ts +0 -66
  316. package/src/collections/email-verified.collection.ts +0 -61
  317. package/src/collections/file.collection.ts +0 -73
  318. package/src/collections/flag.collection.ts +0 -56
  319. package/src/collections/log-method-latency.collection.ts +0 -64
  320. package/src/collections/log-subscription.collection.ts +0 -68
  321. package/src/collections/log-ts.collection.ts +0 -78
  322. package/src/collections/log.collection.ts +0 -77
  323. package/src/collections/logged-in-users.collection.ts +0 -65
  324. package/src/collections/method-response.collection.ts +0 -66
  325. package/src/collections/monitor-cpu.collection.ts +0 -63
  326. package/src/collections/monitor-memory.collection.ts +0 -75
  327. package/src/collections/monitor-mongo.collection.ts +0 -69
  328. package/src/collections/notification.collection.ts +0 -51
  329. package/src/collections/report-builder-dashboard-builder.collection.ts +0 -109
  330. package/src/collections/report-builder-library.collection.ts +0 -89
  331. package/src/collections/report-builder-report.collection.ts +0 -149
  332. package/src/collections/user-group.collection.ts +0 -90
  333. package/src/collections/user-guide.collection.ts +0 -57
  334. package/src/collections/user.collection.ts +0 -259
  335. package/src/cron/cron.ts +0 -188
  336. package/src/fixtures/cron-jobs.ts +0 -25
  337. package/src/fixtures/init.ts +0 -10
  338. package/src/http/auth.ts +0 -732
  339. package/src/http/health.ts +0 -7
  340. package/src/http/home.ts +0 -71
  341. package/src/index.ts +0 -71
  342. package/src/managers/cron.manager.ts +0 -208
  343. package/src/managers/method.manager.ts +0 -607
  344. package/src/managers/mongo.manager.ts +0 -2282
  345. package/src/managers/monitor.manager.ts +0 -323
  346. package/src/managers/subscription.manager.ts +0 -1196
  347. package/src/methods/accounts.ts +0 -202
  348. package/src/methods/aws.ts +0 -507
  349. package/src/methods/collections.ts +0 -512
  350. package/src/methods/counters.ts +0 -75
  351. package/src/methods/cron-jobs.ts +0 -1454
  352. package/src/methods/flags.ts +0 -7
  353. package/src/methods/logs.ts +0 -327
  354. package/src/methods/monitor.ts +0 -548
  355. package/src/methods/pdf.ts +0 -615
  356. package/src/methods/report-builder.ts +0 -876
  357. package/src/methods/support.ts +0 -146
  358. package/src/models/collection-document.model.ts +0 -22
  359. package/src/models/cron-job-history.model.ts +0 -13
  360. package/src/models/cron-job.model.ts +0 -14
  361. package/src/models/dialog.model.ts +0 -25
  362. package/src/models/method.model.ts +0 -11
  363. package/src/models/monitor-memory.model.ts +0 -17
  364. package/src/models/monitor-mongo.model.ts +0 -15
  365. package/src/models/pagination.model.ts +0 -30
  366. package/src/models/permission.model.ts +0 -14
  367. package/src/models/report-builder-dashboard-builder.model.ts +0 -29
  368. package/src/models/report-builder-library.model.ts +0 -20
  369. package/src/models/report-builder-report.model.ts +0 -110
  370. package/src/models/report-builder.model.ts +0 -68
  371. package/src/models/select-data-label.model.ts +0 -9
  372. package/src/models/server-response.model.ts +0 -5
  373. package/src/models/subscription.model.ts +0 -64
  374. package/src/models/support-ticket.model.ts +0 -81
  375. package/src/models/user-group.model.ts +0 -23
  376. package/src/models/user.model.ts +0 -79
  377. package/src/publications/app-status.ts +0 -13
  378. package/src/publications/cron-jobs.ts +0 -30
  379. package/src/publications/files.ts +0 -34
  380. package/src/publications/flags.ts +0 -20
  381. package/src/publications/logs.ts +0 -164
  382. package/src/publications/method-responses.ts +0 -13
  383. package/src/publications/notifications.ts +0 -13
  384. package/src/publications/report-builder-dashboard-builders.ts +0 -39
  385. package/src/publications/report-builder-libraries.ts +0 -41
  386. package/src/publications/report-builder-reports.ts +0 -48
  387. package/src/publications/super-admin.ts +0 -13
  388. package/src/publications/user-groups.ts +0 -12
  389. package/src/publications/user-guides.ts +0 -12
  390. package/src/server-app.ts +0 -769
  391. package/src/util/common.ts +0 -519
  392. package/src/util/schema-report-builder.ts +0 -413
  393. package/tsconfig.json +0 -30
  394. package/tslint.json +0 -143
  395. /package/{src/private → private}/email-templates/enrollment.html +0 -0
  396. /package/{src/private → private}/email-templates/forgot-password.html +0 -0
  397. /package/{src/private → private}/email-templates/support-ticket-deleted.html +0 -0
  398. /package/{src/private → private}/email-templates/support-ticket-modified.html +0 -0
  399. /package/{src/private → private}/email-templates/support-ticket.html +0 -0
  400. /package/{src/private → private}/images/ResolveIO.png +0 -0
@@ -0,0 +1,1091 @@
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
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
+ if (ar || !(i in from)) {
41
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
+ ar[i] = from[i];
43
+ }
44
+ }
45
+ return to.concat(ar || Array.prototype.slice.call(from));
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.SubscriptionManager = void 0;
49
+ var logs_1 = require("../publications/logs");
50
+ var app_status_1 = require("../publications/app-status");
51
+ var files_1 = require("../publications/files");
52
+ var super_admin_1 = require("../publications/super-admin");
53
+ var logged_in_users_collection_1 = require("../collections/logged-in-users.collection");
54
+ var cron_jobs_1 = require("../publications/cron-jobs");
55
+ var flags_1 = require("../publications/flags");
56
+ var method_responses_1 = require("../publications/method-responses");
57
+ var index_1 = require("../index");
58
+ var notifications_1 = require("../publications/notifications");
59
+ var report_builder_reports_1 = require("../publications/report-builder-reports");
60
+ var report_builder_libraries_1 = require("../publications/report-builder-libraries");
61
+ var user_groups_1 = require("../publications/user-groups");
62
+ var user_guides_1 = require("../publications/user-guides");
63
+ var report_builder_dashboard_builders_1 = require("../publications/report-builder-dashboard-builders");
64
+ var mongo_manager_1 = require("./mongo.manager");
65
+ var common_1 = require("../util/common");
66
+ var NodeCache = require("node-cache");
67
+ var flag_collection_1 = require("../collections/flag.collection");
68
+ var os_1 = require("os");
69
+ var numCPUs = (0, os_1.cpus)().length;
70
+ var v8 = require('v8');
71
+ // interface CurrentPerformanceMonitor {
72
+ // _id: number;
73
+ // function: string;
74
+ // publication: string;
75
+ // subscriptionData: any[];
76
+ // date_start: Date;
77
+ // date_end: Date;
78
+ // duration: number;
79
+ // result: string;
80
+ // }
81
+ var SubscriptionManager = /** @class */ (function () {
82
+ // private currentPerfomanceMonitor: CurrentPerformanceMonitor[] = [];
83
+ // private idPerformance: number = 0;
84
+ // private performanceThread;
85
+ function SubscriptionManager(mainServer, wss, serverConfig, monitorManagerFunction) {
86
+ var _this = this;
87
+ this._publications = {};
88
+ this._subscriptions = [];
89
+ this._loggedInUsers = [];
90
+ this._mongoQueue = [];
91
+ this._mongoQueueId = 0;
92
+ this._sendQueue = [];
93
+ this._runningQueue = false;
94
+ this._cacheId = 1;
95
+ this._heapStats = v8.getHeapStatistics();
96
+ this._heapLimit = this._heapStats.heap_size_limit / numCPUs / 8;
97
+ this._enableDebug = false;
98
+ this._debugOplogCollections = [];
99
+ this._debugOplogHits = 0;
100
+ this._debugSubCollections = [];
101
+ this._debugSubHits = 0;
102
+ this._debugUnSubHits = 0;
103
+ this._debugUnSubAllHits = 0;
104
+ this._debugMongoQueueHits = 0;
105
+ this._debugMongoQueueCollections = [];
106
+ this._debugSendQueueHits = 0;
107
+ this._debugRemoveCacheHits = 0;
108
+ this._oplogRetryCount = 0;
109
+ this._mainServer = mainServer;
110
+ this._monitorManagerFunction = monitorManagerFunction;
111
+ this._nodeCache = new NodeCache({ stdTTL: 0, checkperiod: 0 });
112
+ // setTimeout(() => {
113
+ // console.log('Setting up performance thread');
114
+ // this.performanceThread = new Worker(path.join(__dirname, './subscription.performance.js'));
115
+ // this.performanceThread.on('exit', code => {
116
+ // console.error(new Date(), 'THREAD EXITED!!!!!!!!!!!!!!!!!!', code);
117
+ // });
118
+ // this.performanceThread.on('error', code => {
119
+ // console.error(new Date(), 'THREAD RECV ERROR !!!!!!!!!!!!!!!!!!', code);
120
+ // });
121
+ // }, 5000);
122
+ // setInterval(() => {
123
+ // console.log('Post thread msg');
124
+ // this.performanceThread.postMessage(this.currentPerfomanceMonitor);
125
+ // this.currentPerfomanceMonitor = [];
126
+ // }, 10000);
127
+ this.serverConfig = serverConfig;
128
+ this._wss = wss;
129
+ // Publications
130
+ (0, super_admin_1.loadSuperAdminPublications)(this);
131
+ (0, app_status_1.loadAppStatusPublications)(this);
132
+ (0, logs_1.loadLogPublications)(this);
133
+ (0, files_1.loadFilePublications)(this);
134
+ (0, cron_jobs_1.loadCronJobPublications)(this);
135
+ (0, flags_1.loadFlagsPublications)(this);
136
+ (0, method_responses_1.loadMethodResponsePublications)(this);
137
+ (0, notifications_1.loadNotificationPublications)(this);
138
+ (0, report_builder_reports_1.loadReportBuilderReportPublications)(this);
139
+ (0, report_builder_libraries_1.loadReportBuilderLibraryPublications)(this);
140
+ (0, user_groups_1.loadUserGroupPublications)(this);
141
+ (0, user_guides_1.loadUserGuidePublications)(this);
142
+ (0, report_builder_dashboard_builders_1.loadReportBuilderDashboardBuilderPublications)(this);
143
+ this.tailOpLog();
144
+ setInterval(function () {
145
+ _this._oplogRetryCount = 0;
146
+ }, 15000);
147
+ setInterval(function () {
148
+ if (_this.getEnableDebug()) {
149
+ console.log(new Date(), 'Sub Manager', 'Subs', _this._subscriptions.length);
150
+ console.log(new Date(), 'Sub Manager', 'Logged In Users', _this._loggedInUsers.length);
151
+ console.log(new Date(), 'Sub Manager', 'Mongo Queue', _this._mongoQueue.length);
152
+ console.log(new Date(), 'Sub Manager', 'Mongo Queue Hits', _this._debugMongoQueueHits);
153
+ console.log(new Date(), 'Sub Manager', 'Mongo Queue Collections', JSON.stringify(_this._debugMongoQueueCollections.sort(function (a, b) { return a.collection.localeCompare(b.collection) || a.publication.localeCompare(b.publication); }), null, 2));
154
+ console.log(new Date(), 'Sub Manager', 'Oplog Hits', _this._debugOplogHits);
155
+ console.log(new Date(), 'Sub Manager', 'Oplog Collections', JSON.stringify(_this._debugOplogCollections.sort(function (a, b) { return a.collection.localeCompare(b.collection) || a.type.localeCompare(b.type); }), null, 2));
156
+ console.log(new Date(), 'Sub Manager', 'Send Queue Hits', _this._debugSendQueueHits);
157
+ console.log(new Date(), 'Sub Manager', 'Sub Hits', _this._debugSubHits);
158
+ console.log(new Date(), 'Sub Manager', 'Sub Collections', JSON.stringify(_this._debugSubCollections.sort(function (a, b) { return a.publication.localeCompare(b.publication); }), null, 2));
159
+ console.log(new Date(), 'Sub Manager', 'Unsub Hits', _this._debugUnSubHits);
160
+ console.log(new Date(), 'Sub Manager', 'Unsub All Hits', _this._debugUnSubAllHits);
161
+ console.log(new Date(), 'Sub Manager', 'Cache Cleanup Hits', _this._debugRemoveCacheHits);
162
+ }
163
+ _this._debugOplogHits = 0;
164
+ _this._debugOplogCollections = [];
165
+ _this._debugSubCollections = [];
166
+ _this._debugMongoQueueHits = 0;
167
+ _this._debugMongoQueueCollections = [];
168
+ _this._debugSendQueueHits = 0;
169
+ _this._debugSubHits = 0;
170
+ _this._debugUnSubHits = 0;
171
+ _this._debugUnSubAllHits = 0;
172
+ _this._debugRemoveCacheHits = 0;
173
+ }, 60000);
174
+ setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
175
+ var _loop_1, this_1, i, queueArr, _loop_2, this_2, i;
176
+ var _this = this;
177
+ return __generator(this, function (_a) {
178
+ if (!this._runningQueue) {
179
+ this._runningQueue = true;
180
+ if (this._sendQueue.length) {
181
+ _loop_1 = function (i) {
182
+ this_1._debugSendQueueHits += 1;
183
+ var ws = this_1._mainServer.getWS(this_1._sendQueue[i].id_ws);
184
+ if (ws && ws.readyState === ws.OPEN) {
185
+ if (ws.bufferedAmount < 20480) {
186
+ var sendItem = this_1._sendQueue.pop();
187
+ ws.send(JSON.stringify(sendItem.data), function (error) {
188
+ if (error) {
189
+ console.log('Error on WS: ', error);
190
+ if (_this.getEnableDebug()) {
191
+ console.log(new Date(), 'Sub Manager', 'Unsub WS', ws['user'], ws['id_socket'], 1);
192
+ }
193
+ _this.unsubscribeAll(ws);
194
+ }
195
+ });
196
+ }
197
+ }
198
+ else {
199
+ this_1._sendQueue.splice(i, 1);
200
+ }
201
+ };
202
+ this_1 = this;
203
+ // let startDate = new Date();
204
+ for (i = this._sendQueue.length - 1; i >= 0; i--) {
205
+ _loop_1(i);
206
+ }
207
+ // let endDate = new Date();
208
+ // this.currentPerfomanceMonitor.push({
209
+ // _id: this.idPerformance++,
210
+ // function: 'sendInterval',
211
+ // publication: '',
212
+ // subscriptionData: [],
213
+ // date_start: startDate,
214
+ // date_end: endDate,
215
+ // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
216
+ // result: 'Done'
217
+ // });
218
+ }
219
+ queueArr = this._mongoQueue.filter(function (a) { return !a.running; });
220
+ if (queueArr.length) {
221
+ queueArr.forEach(function (entry) {
222
+ entry.running = true;
223
+ });
224
+ _loop_2 = function (i) {
225
+ this_2._debugMongoQueueHits += 1;
226
+ var mongoQueue = queueArr[i];
227
+ if (!this_2._debugMongoQueueCollections.some(function (a) { return a.collection === mongoQueue.collection && a.publication === mongoQueue.subscription.publication; })) {
228
+ this_2._debugMongoQueueCollections.push({
229
+ collection: mongoQueue.collection,
230
+ publication: mongoQueue.subscription.publication,
231
+ hits: 1
232
+ });
233
+ }
234
+ else {
235
+ this_2._debugMongoQueueCollections.filter(function (a) { return a.collection === mongoQueue.collection && a.publication === mongoQueue.subscription.publication; })[0].hits += 1;
236
+ }
237
+ if (this_2._publications[mongoQueue.subscription.publication].user_specific) {
238
+ var promises = [];
239
+ var _loop_3 = function (j) {
240
+ var client = mongoQueue.subscription.clients[j];
241
+ var ws = this_2._mainServer.getWS(client.id_socket);
242
+ if (ws && ws['id_socket'] === client.id_socket) {
243
+ promises.push(this_2.sendDataToOne(ws, client.messageId, mongoQueue.subscription, mongoQueue.type, mongoQueue.collection).catch(function (err) {
244
+ _this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + _this.serverConfig['CLIENT_NAME'], 'Error Detected During sendDataToOne - User Specific - Socket: ' + client.id_socket + ', User: ' + client.id_user + ', MessageId: ' + client.messageId + ', Pub: ' + mongoQueue.subscription.publication + ', Err: ' + JSON.stringify(err, null, 2));
245
+ return null;
246
+ }));
247
+ }
248
+ };
249
+ for (var j = 0; j < mongoQueue.subscription.clients.length; j++) {
250
+ _loop_3(j);
251
+ }
252
+ Promise.all(promises).then(function () {
253
+ if (mongoQueue.run_again) {
254
+ mongoQueue.running = false;
255
+ mongoQueue.run_again = false;
256
+ }
257
+ else {
258
+ if (_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id) >= 0) {
259
+ _this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id), 1);
260
+ }
261
+ }
262
+ });
263
+ }
264
+ else {
265
+ this_2.sendDataToAll(mongoQueue).then(function () {
266
+ if (mongoQueue.run_again) {
267
+ mongoQueue.running = false;
268
+ mongoQueue.run_again = false;
269
+ }
270
+ else {
271
+ if (_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id) >= 0) {
272
+ _this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id), 1);
273
+ }
274
+ }
275
+ }, function () {
276
+ if (_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id) >= 0) {
277
+ _this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id), 1);
278
+ }
279
+ });
280
+ }
281
+ };
282
+ this_2 = this;
283
+ for (i = queueArr.length - 1; i >= 0; i--) {
284
+ _loop_2(i);
285
+ }
286
+ // let endDate = new Date();
287
+ // this.currentPerfomanceMonitor.push({
288
+ // _id: this.idPerformance++,
289
+ // function: 'mongoQueue',
290
+ // publication: '',
291
+ // subscriptionData: [],
292
+ // date_start: startDate,
293
+ // date_end: endDate,
294
+ // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
295
+ // result: 'Done'
296
+ // });
297
+ }
298
+ this._runningQueue = false;
299
+ }
300
+ return [2 /*return*/];
301
+ });
302
+ }); }, 25);
303
+ setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
304
+ var _a, userCopy, _loop_4, this_3, i, i, sub, _loop_5, this_4, j;
305
+ return __generator(this, function (_b) {
306
+ switch (_b.label) {
307
+ case 0:
308
+ _a = this;
309
+ return [4 /*yield*/, logged_in_users_collection_1.LoggedInUsers.find()];
310
+ case 1:
311
+ _a._loggedInUsers = _b.sent();
312
+ userCopy = (0, common_1.deepCopy)(this._loggedInUsers);
313
+ _loop_4 = function (i) {
314
+ var loggedInUser = userCopy[i];
315
+ if (!loggedInUser.date || Date.now() - loggedInUser.date.getTime() > 120000) {
316
+ if (this_3._mainServer.getWS(loggedInUser.id_ws)) {
317
+ if (this_3.getEnableDebug()) {
318
+ console.log(new Date(), 'Sub Manager', 'Unsub WS', this_3._mainServer.getWS(loggedInUser.id_ws)['user'], this_3._mainServer.getWS(loggedInUser.id_ws)['id_socket'], 2);
319
+ }
320
+ this_3.unsubscribeAll(this_3._mainServer.getWS(loggedInUser.id_ws));
321
+ }
322
+ else {
323
+ this_3._subscriptions.forEach(function (sub) {
324
+ for (var j = sub.clients.length - 1; j >= 0; j--) {
325
+ var client = sub.clients[j];
326
+ if (client.id_socket === loggedInUser.id_ws) {
327
+ sub.clients.splice(j, 1);
328
+ }
329
+ }
330
+ });
331
+ logged_in_users_collection_1.LoggedInUsers.deleteOne({ _id: loggedInUser._id });
332
+ if (this_3._loggedInUsers.findIndex(function (a) { return a._id === loggedInUser._id; }) >= 0) {
333
+ this_3._loggedInUsers.splice(this_3._loggedInUsers.findIndex(function (a) { return a._id === loggedInUser._id; }), 1);
334
+ }
335
+ }
336
+ }
337
+ };
338
+ this_3 = this;
339
+ for (i = this._loggedInUsers.length - 1; i >= 0; i--) {
340
+ _loop_4(i);
341
+ }
342
+ for (i = 0; i < this._subscriptions.length; i++) {
343
+ sub = this._subscriptions[i];
344
+ _loop_5 = function (j) {
345
+ var client = sub.clients[j];
346
+ if (!this_4._loggedInUsers.some(function (a) { return a.id_ws === client.id_socket; })) {
347
+ sub.clients.splice(j, 1);
348
+ }
349
+ };
350
+ this_4 = this;
351
+ for (j = sub.clients.length - 1; j >= 0; j--) {
352
+ _loop_5(j);
353
+ }
354
+ }
355
+ return [2 /*return*/];
356
+ }
357
+ });
358
+ }); }, 30000);
359
+ flag_collection_1.Flags.findOne({ type: 'Enable Debug' }).then(function (flag) {
360
+ if (flag && flag.value) {
361
+ _this._enableDebug = true;
362
+ }
363
+ else {
364
+ _this._enableDebug = false;
365
+ }
366
+ });
367
+ }
368
+ SubscriptionManager.prototype.addToQueue = function (mongoQueue) {
369
+ // let startDate = new Date();
370
+ var _mongoQueue = this._mongoQueue.filter(function (a) { return a.subscription.publication === mongoQueue.subscription.publication && JSON.stringify(a.subscription.subscriptionData) === JSON.stringify(mongoQueue.subscription.subscriptionData); })[0];
371
+ if (_mongoQueue) {
372
+ if (_mongoQueue.running) {
373
+ _mongoQueue.run_again = true;
374
+ // let endDate = new Date();
375
+ // this.currentPerfomanceMonitor.push({
376
+ // _id: this.idPerformance++,
377
+ // function: 'addToQueue',
378
+ // publication: mongoQueue.subscription.publication,
379
+ // // subscriptionData: mongoQueue.subscription.subscriptionData,
380
+ // subscriptionData: [],
381
+ // date_start: startDate,
382
+ // date_end: endDate,
383
+ // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
384
+ // result: 'Run Again'
385
+ // });
386
+ }
387
+ // else {
388
+ // let endDate = new Date();
389
+ // this.currentPerfomanceMonitor.push({
390
+ // _id: this.idPerformance++,
391
+ // function: 'addToQueue',
392
+ // publication: mongoQueue.subscription.publication,
393
+ // // subscriptionData: mongoQueue.subscription.subscriptionData,
394
+ // subscriptionData: [],
395
+ // date_start: startDate,
396
+ // date_end: endDate,
397
+ // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
398
+ // result: 'Not Running Yet'
399
+ // });
400
+ // }
401
+ }
402
+ else {
403
+ mongoQueue._id = this._mongoQueueId;
404
+ this._mongoQueueId += 1;
405
+ this._mongoQueue.splice(0, 0, mongoQueue);
406
+ // let endDate = new Date();
407
+ // this.currentPerfomanceMonitor.push({
408
+ // _id: this.idPerformance++,
409
+ // function: 'addToQueue',
410
+ // publication: mongoQueue.subscription.publication,
411
+ // // subscriptionData: mongoQueue.subscription.subscriptionData,
412
+ // subscriptionData: [],
413
+ // date_start: startDate,
414
+ // date_end: endDate,
415
+ // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
416
+ // result: 'Add to Queue'
417
+ // });
418
+ }
419
+ };
420
+ SubscriptionManager.prototype.invalidatePubsCache = function (collection, type) {
421
+ // let startDate = new Date();
422
+ index_1.ResolveIOServer.getMongoManager().invalidateQueryCache(collection);
423
+ var collSubs = this._subscriptions.filter(function (a) { return a.collections.includes(collection); });
424
+ for (var i = collSubs.length - 1; i >= 0; i--) {
425
+ var sub = collSubs[i];
426
+ this.addToQueue({
427
+ _id: 0,
428
+ type: type,
429
+ collection: collection,
430
+ subscription: sub,
431
+ running: false,
432
+ run_again: false
433
+ });
434
+ }
435
+ // let endDate = new Date();
436
+ // this.currentPerfomanceMonitor.push({
437
+ // _id: this.idPerformance++,
438
+ // function: 'invalidatePubsCache',
439
+ // publication: collection,
440
+ // subscriptionData: [],
441
+ // date_start: startDate,
442
+ // date_end: endDate,
443
+ // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
444
+ // result: 'Done'
445
+ // });
446
+ };
447
+ // Add all files to publications private object
448
+ SubscriptionManager.prototype.publications = function (method) {
449
+ this._publications = Object.assign(this._publications, method);
450
+ };
451
+ SubscriptionManager.prototype.loggedInLatency = function (ws) {
452
+ var _this = this;
453
+ var loggedInUser = this._loggedInUsers.filter(function (a) { return a.id_ws === ws['id_socket']; })[0];
454
+ if (loggedInUser) {
455
+ loggedInUser.date = new Date();
456
+ logged_in_users_collection_1.LoggedInUsers.updateOne({ id_ws: ws['id_socket'] }, { $set: { latency: ws['latency'], date: loggedInUser.date } }).then(function (res) {
457
+ if (!res) {
458
+ _this.unsubscribeAll(ws);
459
+ if (_this.getEnableDebug()) {
460
+ console.log(new Date(), 'Sub Manager', 'Unsub WS', ws['user'], ws['id_socket'], 3);
461
+ }
462
+ }
463
+ }, function () {
464
+ _this.unsubscribeAll(ws);
465
+ if (_this.getEnableDebug()) {
466
+ console.log(new Date(), 'Sub Manager', 'Unsub WS', ws['user'], ws['id_socket'], 4);
467
+ }
468
+ });
469
+ }
470
+ };
471
+ // Subscribe to publication
472
+ SubscriptionManager.prototype.subscribe = function (messageRoute, messageDate, ws, messageId, publication, subscriptionData) {
473
+ var _this = this;
474
+ // let startDate = new Date();
475
+ this._debugSubHits += 1;
476
+ if (!this._debugSubCollections.some(function (a) { return a.publication === publication; })) {
477
+ this._debugSubCollections.push({
478
+ publication: publication,
479
+ hits: 1
480
+ });
481
+ }
482
+ else {
483
+ this._debugSubCollections.filter(function (a) { return a.publication === publication; })[0].hits += 1;
484
+ }
485
+ var pub = this._publications[publication];
486
+ if (!pub) {
487
+ console.error(new Date(), 'No Publication: ' + publication);
488
+ return;
489
+ }
490
+ else {
491
+ if (subscriptionData.length > 1 || subscriptionData[0]) {
492
+ if (!pub.check) {
493
+ console.error(new Date(), 'No Check Function For Pub ' + publication);
494
+ return;
495
+ }
496
+ else if (!pub.check._schema) {
497
+ console.error(new Date(), 'No Check Schema For Pub ' + publication);
498
+ return;
499
+ }
500
+ else {
501
+ var valObj = {};
502
+ var valKeys = Object.keys(pub.check._schema);
503
+ var rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
504
+ for (var i = 0; i < subscriptionData.length; i++) {
505
+ valObj[rootKeys[i]] = subscriptionData[i];
506
+ }
507
+ try {
508
+ pub.check.validate(valObj);
509
+ }
510
+ catch (errors) {
511
+ if (errors) {
512
+ console.error(new Date(), 'Error in Pub Check (' + publication + ')', errors);
513
+ return;
514
+ }
515
+ }
516
+ }
517
+ }
518
+ if (messageRoute !== 'Bypass') {
519
+ var urlData = messageRoute.split('/');
520
+ var urlModule_1 = '';
521
+ var urlNext = urlData[0];
522
+ if (urlData[0] === '') {
523
+ urlModule_1 = '/';
524
+ urlNext = urlData[1];
525
+ }
526
+ urlModule_1 += urlNext;
527
+ if (urlData.length > 1) {
528
+ urlModule_1 += '/';
529
+ }
530
+ var otherRouteSubs = this._subscriptions.filter(function (a) { return a.clients.some(function (b) { return b.id_socket === ws['id_socket'] && b.messageRoute !== 'Bypass' && b.messageRoute !== '/' && b.messageRoute !== messageRoute && !b.messageRoute.startsWith(urlModule_1); }); });
531
+ if (otherRouteSubs.length) {
532
+ this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Detected Undestroyed Subscription - ' + this.serverConfig['CLIENT_NAME'], 'USER: ' + ws['user'] + ' (Socket: ' + ws['id_socket'] + ') ' + ' is on route: ' + messageRoute + ' but has the following subscriptions on other routes:' + JSON.stringify(otherRouteSubs, null, 2));
533
+ otherRouteSubs.forEach(function (otherSub) {
534
+ otherSub.clients.filter(function (a) { return a.id_socket === ws['id_socket']; }).forEach(function (client) {
535
+ _this.unsubscribe(client.messageRoute, new Date(), ws, client.messageId, otherSub.publication, otherSub.subscriptionData);
536
+ });
537
+ });
538
+ }
539
+ }
540
+ var sub_1 = this._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
541
+ // If sub found (another user watching same data), add client to same sub
542
+ if (sub_1) {
543
+ if (!sub_1.clients.some(function (a) { return a.id_socket === ws['id_socket'] && a.messageId === messageId; })) {
544
+ sub_1.clients.push({
545
+ id_user: ws['id_user'],
546
+ messageId: messageId,
547
+ id_socket: ws['id_socket'],
548
+ messageRoute: messageRoute
549
+ });
550
+ }
551
+ }
552
+ // If sub not found, create new sub
553
+ else {
554
+ this._subscriptions.push({
555
+ publication: publication,
556
+ subscriptionData: subscriptionData,
557
+ collections: this.getPublicationCollections(publication),
558
+ clients: [{
559
+ id_user: ws['id_user'],
560
+ messageId: messageId,
561
+ id_socket: ws['id_socket'],
562
+ messageRoute: messageRoute
563
+ }],
564
+ cacheId: 0
565
+ });
566
+ }
567
+ if (!sub_1) {
568
+ sub_1 = this._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
569
+ }
570
+ if (!sub_1.cacheId && !this._mongoQueue.some(function (a) { return a.subscription.publication === sub_1.publication && JSON.stringify(a.subscription.subscriptionData) === JSON.stringify(sub_1.subscriptionData); })) {
571
+ this.addToQueue({
572
+ _id: 0,
573
+ type: 'newSub',
574
+ collection: '',
575
+ subscription: sub_1,
576
+ running: false,
577
+ run_again: false
578
+ });
579
+ // let endDate = new Date();
580
+ // this.currentPerfomanceMonitor.push({
581
+ // _id: this.idPerformance++,
582
+ // function: 'subscribe',
583
+ // publication: publication,
584
+ // // subscriptionData: subscriptionData,
585
+ // subscriptionData: [],
586
+ // date_start: startDate,
587
+ // date_end: endDate,
588
+ // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
589
+ // result: 'Add to Queue'
590
+ // });
591
+ }
592
+ else if (sub_1.cacheId) {
593
+ this.sendDataToOne(ws, messageId, sub_1, 'newSub', publication);
594
+ // let endDate = new Date();
595
+ // this.currentPerfomanceMonitor.push({
596
+ // _id: this.idPerformance++,
597
+ // function: 'subscribe',
598
+ // publication: publication,
599
+ // // subscriptionData: subscriptionData,
600
+ // subscriptionData: [],
601
+ // date_start: startDate,
602
+ // date_end: endDate,
603
+ // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
604
+ // result: 'Send Pub Data Once'
605
+ // });
606
+ }
607
+ }
608
+ };
609
+ SubscriptionManager.prototype.createLoggedInUser = function (id_ws) {
610
+ return __awaiter(this, void 0, void 0, function () {
611
+ var _this = this;
612
+ return __generator(this, function (_a) {
613
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
614
+ var ws, user;
615
+ return __generator(this, function (_a) {
616
+ ws = this._mainServer.getWS(id_ws);
617
+ if (ws) {
618
+ user = {
619
+ _id: (0, mongo_manager_1.objectIdHexString)(),
620
+ __v: 0,
621
+ date: new Date(),
622
+ id_user: ws['id_user'],
623
+ user: ws['user'],
624
+ id_ws: ws['id_socket']
625
+ };
626
+ this._loggedInUsers.push(user);
627
+ logged_in_users_collection_1.LoggedInUsers.insertOne(user);
628
+ resolve(user);
629
+ }
630
+ else {
631
+ resolve(null);
632
+ }
633
+ return [2 /*return*/];
634
+ });
635
+ }); })];
636
+ });
637
+ });
638
+ };
639
+ // Unsubscribe from publication
640
+ SubscriptionManager.prototype.unsubscribe = function (messageRoute, messageDate, ws, messageId, publication, subscriptionData) {
641
+ this._debugUnSubHits += 1;
642
+ // let startDate = new Date();
643
+ // console.log('Before');
644
+ // console.dir(this._subscriptions.map(a => a.publication));
645
+ if (!this._publications[publication]) {
646
+ console.log('No Publication: ' + publication);
647
+ return;
648
+ }
649
+ else {
650
+ var sub = this._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
651
+ if (sub) {
652
+ for (var i = sub.clients.length - 1; i >= 0; i--) {
653
+ if (sub.clients[i].id_user === ws['id_user'] && sub.clients[i].messageId === messageId && sub.clients[i].id_socket === ws['id_socket']) {
654
+ sub.clients.splice(i, 1);
655
+ }
656
+ }
657
+ }
658
+ }
659
+ // let endDate = new Date();
660
+ // this.currentPerfomanceMonitor.push({
661
+ // _id: this.idPerformance++,
662
+ // function: 'unsubscribe',
663
+ // publication: publication,
664
+ // // subscriptionData: subscriptionData,
665
+ // subscriptionData: [],
666
+ // date_start: startDate,
667
+ // date_end: endDate,
668
+ // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
669
+ // result: 'Done'
670
+ // });
671
+ };
672
+ // Unsubscribe from publication
673
+ SubscriptionManager.prototype.unsubscribeAll = function (ws) {
674
+ return __awaiter(this, void 0, void 0, function () {
675
+ var loggedInUser, userSubs, i, sub, j;
676
+ return __generator(this, function (_a) {
677
+ switch (_a.label) {
678
+ case 0:
679
+ this._debugUnSubAllHits += 1;
680
+ if (!ws) return [3 /*break*/, 2];
681
+ return [4 /*yield*/, logged_in_users_collection_1.LoggedInUsers.findOne({ id_ws: ws['id_socket'] })];
682
+ case 1:
683
+ loggedInUser = _a.sent();
684
+ if (loggedInUser) {
685
+ if (this._loggedInUsers.map(function (a) { return a._id; }).indexOf(loggedInUser._id) >= 0) {
686
+ this._loggedInUsers.splice(this._loggedInUsers.map(function (a) { return a._id; }).indexOf(loggedInUser._id), 1);
687
+ }
688
+ logged_in_users_collection_1.LoggedInUsers.deleteOne({ _id: loggedInUser._id });
689
+ }
690
+ userSubs = this._subscriptions.filter(function (a) { return a.clients.some(function (b) { return b.id_user === ws['id_user'] && b.id_socket === ws['id_socket']; }); });
691
+ for (i = userSubs.length - 1; i >= 0; i--) {
692
+ sub = userSubs[i];
693
+ for (j = sub.clients.length - 1; j >= 0; j--) {
694
+ if (sub.clients[j].id_socket === ws['id_socket']) {
695
+ sub.clients.splice(j, 1);
696
+ }
697
+ }
698
+ }
699
+ ws.close();
700
+ process.nextTick(function () {
701
+ if ([ws.OPEN, ws.CLOSING].includes(ws.readyState)) {
702
+ // Socket still hangs, hard close
703
+ ws.terminate();
704
+ }
705
+ });
706
+ _a.label = 2;
707
+ case 2: return [2 /*return*/];
708
+ }
709
+ });
710
+ });
711
+ };
712
+ SubscriptionManager.prototype.getActiveSubscriptions = function () {
713
+ return this._subscriptions;
714
+ };
715
+ // Get publication collection
716
+ SubscriptionManager.prototype.getPublicationCollections = function (publication) {
717
+ return this._publications[publication].collections;
718
+ };
719
+ // Watch (tail) Mongo's operation log on the entire database (all insert/modify/delete will trigger this function)
720
+ SubscriptionManager.prototype.tailOpLog = function (resumeToken) {
721
+ var _this = this;
722
+ if (!this._oplog || this._oplog.closed) {
723
+ this._oplogRetryCount += 1;
724
+ if (this._oplogRetryCount > 10) {
725
+ console.error('****************** TAIL OPLOG ERROR, RETRYING A BUNCH OF TIMES, KILLING PROCESS **************************');
726
+ process.exit(1);
727
+ }
728
+ var lastResumeToken_1;
729
+ if (resumeToken) {
730
+ lastResumeToken_1 = resumeToken;
731
+ try {
732
+ this._oplog = index_1.ResolveIOServer.getMainDB().watch([], { resumeAfter: resumeToken });
733
+ }
734
+ catch (errOp) {
735
+ if (this._oplog && !this._oplog.closed) {
736
+ this._oplog.close();
737
+ }
738
+ else {
739
+ this._oplog = index_1.ResolveIOServer.getMainDB().watch();
740
+ }
741
+ }
742
+ }
743
+ else {
744
+ this._oplog = index_1.ResolveIOServer.getMainDB().watch();
745
+ }
746
+ console.log(new Date(), 'oplog started');
747
+ this._oplog.on('change', function (doc) {
748
+ // let startDate = new Date();
749
+ if (doc.ns) {
750
+ var collection = doc.ns.coll;
751
+ if (!_this._debugOplogCollections.some(function (a) { return a.collection === doc.ns.coll && a.type === doc.operationType; })) {
752
+ _this._debugOplogCollections.push({
753
+ collection: doc.ns.coll,
754
+ type: doc.operationType,
755
+ hits: 1
756
+ });
757
+ }
758
+ else {
759
+ _this._debugOplogCollections.filter(function (a) { return a.collection === doc.ns.coll && a.type === doc.operationType; })[0].hits += 1;
760
+ }
761
+ // console.log(new Date(), 'Op log doc', doc.operationType, collection);
762
+ if (collection && !collection.endsWith('.versions') && !collection.startsWith('monitor-') && collection !== 'logs' && collection !== 'log-method-latencies' && collection !== 'log-subscriptions') {
763
+ _this._debugOplogHits += 1;
764
+ if (doc.operationType === 'insert') {
765
+ if (collection === 'support-tickets') {
766
+ if (_this.serverConfig['ROOT_URL'] === 'https://resolveio.com') {
767
+ _this._mainServer.getMethodManager().callMethodInternal.call(_this._mainServer.getMethodManager(), 'sendSupportTicketEmail', doc.documentKey['_id']);
768
+ _this.invalidatePubsCache(collection, 'insert');
769
+ }
770
+ }
771
+ if (collection !== 'method-responses') {
772
+ _this.invalidatePubsCache(collection, 'insert');
773
+ }
774
+ // let endDate = new Date();
775
+ // this.currentPerfomanceMonitor.push({
776
+ // _id: this.idPerformance++,
777
+ // function: 'oplog',
778
+ // publication: collection,
779
+ // subscriptionData: [],
780
+ // date_start: startDate,
781
+ // date_end: endDate,
782
+ // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
783
+ // result: 'Insert'
784
+ // });
785
+ }
786
+ else if (doc.operationType === 'update' || doc.operationType === 'replace') {
787
+ if (collection !== 'method-responses') {
788
+ _this.invalidatePubsCache(collection, 'update');
789
+ }
790
+ // let endDate = new Date();
791
+ // this.currentPerfomanceMonitor.push({
792
+ // _id: this.idPerformance++,
793
+ // function: 'oplog',
794
+ // publication: collection,
795
+ // subscriptionData: [],
796
+ // date_start: startDate,
797
+ // date_end: endDate,
798
+ // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
799
+ // result: 'Update'
800
+ // });
801
+ }
802
+ else if (doc.operationType === 'delete') {
803
+ if (collection !== 'method-responses') {
804
+ _this.invalidatePubsCache(collection, 'delete');
805
+ }
806
+ // let endDate = new Date();
807
+ // this.currentPerfomanceMonitor.push({
808
+ // _id: this.idPerformance++,
809
+ // function: 'oplog',
810
+ // publication: collection,
811
+ // subscriptionData: [],
812
+ // date_start: startDate,
813
+ // date_end: endDate,
814
+ // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
815
+ // result: 'Delete'
816
+ // });
817
+ }
818
+ }
819
+ if (collection === 'flags') {
820
+ flag_collection_1.Flags.findOne({ type: 'Enable Debug' }).then(function (flag) {
821
+ if (flag && flag.value) {
822
+ _this._enableDebug = true;
823
+ }
824
+ else {
825
+ _this._enableDebug = false;
826
+ }
827
+ });
828
+ }
829
+ lastResumeToken_1 = doc._id;
830
+ }
831
+ });
832
+ this._oplog.on('error', function (error) {
833
+ console.log(new Date(), 'oplog error', error);
834
+ _this._oplog.close();
835
+ });
836
+ this._oplog.on('end', function () {
837
+ console.log(new Date(), 'oplog end');
838
+ _this._oplog.close();
839
+ });
840
+ this._oplog.on('close', function () {
841
+ _this._oplog = null;
842
+ console.log(new Date(), 'oplog close');
843
+ _this.tailOpLog(lastResumeToken_1);
844
+ });
845
+ }
846
+ else {
847
+ this._oplog.close();
848
+ }
849
+ };
850
+ // Fetch pub once, send to all clients linked to this pub
851
+ SubscriptionManager.prototype.sendDataToOne = function (ws, messageId, subscription, type, collection) {
852
+ var _this = this;
853
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
854
+ var cacheData, serverRes, monitor_1;
855
+ var _a;
856
+ var _this = this;
857
+ return __generator(this, function (_b) {
858
+ // let startDate = new Date();
859
+ if (!this._publications[subscription.publication].user_specific) { // Same pub for all users
860
+ if (subscription.cacheId) {
861
+ try {
862
+ cacheData = JSON.parse(this._nodeCache.get(subscription.cacheId), common_1.dateReviver);
863
+ serverRes = {
864
+ messageId: messageId,
865
+ hasError: false,
866
+ data: cacheData
867
+ };
868
+ this.sendWS(ws, serverRes);
869
+ }
870
+ catch (err) {
871
+ this._nodeCache.del(subscription.cacheId);
872
+ subscription.cacheId = 0;
873
+ this.addToQueue({
874
+ _id: 0,
875
+ type: 'newSub',
876
+ collection: '',
877
+ subscription: subscription,
878
+ running: false,
879
+ run_again: false
880
+ });
881
+ }
882
+ // let endDate = new Date();
883
+ // this.currentPerfomanceMonitor.push({
884
+ // _id: this.idPerformance++,
885
+ // function: 'sendDataToOne',
886
+ // publication: subscription.publication,
887
+ // // subscriptionData: subscription.subscriptionData,
888
+ // subscriptionData: [],
889
+ // date_start: startDate,
890
+ // date_end: endDate,
891
+ // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
892
+ // result: 'Send cache'
893
+ // });
894
+ resolve(true);
895
+ }
896
+ else {
897
+ this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During sendDataToOne - No Cache! - ' + subscription.publication + '\n\nData \n' + JSON.stringify(subscription.subscriptionData, null, 2));
898
+ resolve(false);
899
+ }
900
+ }
901
+ else { // Pub is different for each user (Look at users publication) [MUCH SLOWER, RE-RUNS FOR EACH USER]
902
+ monitor_1 = this._monitorManagerFunction.startMonitorFunction('User Specific Publication', subscription.publication, '', '', subscription.subscriptionData);
903
+ (_a = this._publications[subscription.publication].function).call.apply(_a, __spreadArray([Object.assign({}, this, SubscriptionManager.prototype), ws['id_user']], subscription.subscriptionData, false)).then(function (res) {
904
+ _this._monitorManagerFunction.finishMonitorFunction(monitor_1);
905
+ var serverRes = {
906
+ messageId: messageId,
907
+ hasError: false,
908
+ data: res
909
+ };
910
+ // console.log('Send Pub Data Once 2', new Date(), 'Success', subscription);
911
+ _this.sendWS(ws, serverRes);
912
+ // let endDate = new Date();
913
+ // this.currentPerfomanceMonitor.push({
914
+ // _id: this.idPerformance++,
915
+ // function: 'sendDataToOne',
916
+ // publication: subscription.publication,
917
+ // // subscriptionData: subscription.subscriptionData,
918
+ // subscriptionData: [],
919
+ // date_start: startDate,
920
+ // date_end: endDate,
921
+ // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
922
+ // result: 'Send ws spec data'
923
+ // });
924
+ resolve(true);
925
+ }, function (err) {
926
+ _this._monitorManagerFunction.finishMonitorFunction(monitor_1);
927
+ var serverRes = {
928
+ messageId: messageId,
929
+ hasError: true,
930
+ data: err
931
+ };
932
+ // console.log('Send Pub Data Once 2', new Date(), 'Error', subscription);
933
+ _this.sendWS(ws, serverRes);
934
+ _this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + _this.serverConfig['CLIENT_NAME'], 'Error Detected During Subscription ' + subscription.publication + ' - (sendDataToOne - WS)\n\nData \n' + JSON.stringify(subscription.subscriptionData, null, 2) + '\n\nErrors\n' + JSON.stringify(err, null, 2));
935
+ reject(err);
936
+ });
937
+ }
938
+ return [2 /*return*/];
939
+ });
940
+ }); });
941
+ };
942
+ // Fetch pub once, send to all clients linked to this pub
943
+ SubscriptionManager.prototype.sendDataToAll = function (mongoQueue) {
944
+ var _this = this;
945
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
946
+ var monitor_2;
947
+ var _a;
948
+ var _this = this;
949
+ return __generator(this, function (_b) {
950
+ // let startDate = new Date();
951
+ if (!mongoQueue.subscription.clients.length) {
952
+ if (mongoQueue.subscription.cacheId) {
953
+ this._nodeCache.del(mongoQueue.subscription.cacheId);
954
+ }
955
+ if (this._subscriptions.findIndex(function (a) { return a.publication === mongoQueue.subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(mongoQueue.subscription.subscriptionData); }) >= 0) {
956
+ this._subscriptions.splice(this._subscriptions.findIndex(function (a) { return a.publication === mongoQueue.subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(mongoQueue.subscription.subscriptionData); }), 1);
957
+ }
958
+ resolve(false);
959
+ }
960
+ else {
961
+ if (mongoQueue.subscription.publication !== 'superadminAPM' && mongoQueue.subscription.publication !== 'loggedInUsers') {
962
+ this._mainServer.getMethodManager().callMethodInternal.call(this._mainServer.getMethodManager(), 'insertSubscriptionLog', mongoQueue.type, mongoQueue.subscription.publication, mongoQueue.collection, JSON.stringify(mongoQueue.subscription.subscriptionData));
963
+ }
964
+ monitor_2 = this._monitorManagerFunction.startMonitorFunction('Publication', mongoQueue.subscription.publication, '', '', mongoQueue.subscription.subscriptionData);
965
+ (_a = this._publications[mongoQueue.subscription.publication].function).call.apply(_a, __spreadArray([Object.assign({}, this, SubscriptionManager.prototype)], mongoQueue.subscription.subscriptionData, false)).then(function (res) {
966
+ _this._monitorManagerFunction.finishMonitorFunction(monitor_2);
967
+ if (!mongoQueue.subscription.clients.length) {
968
+ var nodeCacheSize = _this._nodeCache.getStats().vsize;
969
+ if (nodeCacheSize > _this._heapLimit) {
970
+ var deleteCount = 0;
971
+ var subArr = _this._subscriptions.filter(function (a) { return a.cacheId && !a.clients.length; });
972
+ for (var zz = 0; zz < subArr.length; zz++) {
973
+ _this._debugRemoveCacheHits += 1;
974
+ _this._nodeCache.del(subArr[zz].cacheId);
975
+ subArr[zz].cacheId = 0;
976
+ deleteCount += 1;
977
+ nodeCacheSize = _this._nodeCache.getStats().vsize;
978
+ if (nodeCacheSize < _this._heapLimit * 0.75) {
979
+ break;
980
+ }
981
+ }
982
+ console.log('Sub Cache: ' + 'Too Big - ' + mongoQueue.subscription.publication + ' - Deleted: ' + deleteCount + ' - ' + nodeCacheSize);
983
+ }
984
+ if (mongoQueue.subscription.cacheId) {
985
+ _this._nodeCache.del(mongoQueue.subscription.cacheId);
986
+ }
987
+ var cacheId = _this._cacheId;
988
+ _this._cacheId += 1;
989
+ _this._nodeCache.set(cacheId, JSON.stringify(res));
990
+ mongoQueue.subscription.cacheId = cacheId;
991
+ // let endDate = new Date();
992
+ // this.currentPerfomanceMonitor.push({
993
+ // _id: this.idPerformance++,
994
+ // function: 'sendPubData',
995
+ // publication: subscription.publication,
996
+ // // subscriptionData: subscription.subscriptionData,
997
+ // subscriptionData: [],
998
+ // date_start: startDate,
999
+ // date_end: endDate,
1000
+ // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
1001
+ // result: 'No clients'
1002
+ // });
1003
+ resolve(false);
1004
+ }
1005
+ else {
1006
+ if (!mongoQueue.subscription.cacheId || _this._nodeCache.get(mongoQueue.subscription.cacheId) !== JSON.stringify(res)) {
1007
+ mongoQueue.subscription.clients.forEach(function (client) {
1008
+ var ws = _this._mainServer.getWS(client.id_socket);
1009
+ if (ws) {
1010
+ var serverRes = {
1011
+ messageId: client.messageId,
1012
+ hasError: false,
1013
+ data: res
1014
+ };
1015
+ _this.sendWS(ws, serverRes);
1016
+ }
1017
+ });
1018
+ var nodeCacheSize = _this._nodeCache.getStats().vsize;
1019
+ if (nodeCacheSize > _this._heapLimit) {
1020
+ var deleteCount = 0;
1021
+ var subArr = _this._subscriptions.filter(function (a) { return a.cacheId && !a.clients.length; });
1022
+ for (var zz = 0; zz < subArr.length; zz++) {
1023
+ _this._nodeCache.del(subArr[zz].cacheId);
1024
+ subArr[zz].cacheId = 0;
1025
+ deleteCount += 1;
1026
+ nodeCacheSize = _this._nodeCache.getStats().vsize;
1027
+ if (nodeCacheSize < _this._heapLimit * 0.75) {
1028
+ break;
1029
+ }
1030
+ }
1031
+ console.log('Sub Cache: ' + 'Too Big - ' + mongoQueue.subscription.publication + ' - Deleted: ' + deleteCount + ' - ' + nodeCacheSize);
1032
+ }
1033
+ if (mongoQueue.subscription.cacheId) {
1034
+ _this._nodeCache.del(mongoQueue.subscription.cacheId);
1035
+ }
1036
+ var cacheId = _this._cacheId;
1037
+ _this._cacheId += 1;
1038
+ _this._nodeCache.set(cacheId, JSON.stringify(res));
1039
+ mongoQueue.subscription.cacheId = cacheId;
1040
+ // let endDate = new Date();
1041
+ // this.currentPerfomanceMonitor.push({
1042
+ // _id: this.idPerformance++,
1043
+ // function: 'sendPubData',
1044
+ // publication: subscription.publication,
1045
+ // // subscriptionData: subscription.subscriptionData,
1046
+ // subscriptionData: [],
1047
+ // date_start: startDate,
1048
+ // date_end: endDate,
1049
+ // duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
1050
+ // result: 'Same data'
1051
+ // });
1052
+ }
1053
+ resolve(true);
1054
+ }
1055
+ }, function (err) {
1056
+ _this._monitorManagerFunction.finishMonitorFunction(monitor_2);
1057
+ _this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + _this.serverConfig['CLIENT_NAME'], 'Error Detected During Subscription ' + mongoQueue.subscription.publication + ' - (sendPubData)\n\nData \n' + JSON.stringify(mongoQueue.subscription.subscriptionData, null, 2) + '\n\nErrors\n' + JSON.stringify(err, null, 2));
1058
+ mongoQueue.subscription.clients.forEach(function (client) {
1059
+ var ws = _this._mainServer.getWS(client.id_socket);
1060
+ if (ws) {
1061
+ if (ws['id_socket'] === client.id_socket) {
1062
+ var serverRes = {
1063
+ messageId: client.messageId,
1064
+ hasError: true,
1065
+ data: err
1066
+ };
1067
+ _this.sendWS(ws, serverRes);
1068
+ }
1069
+ }
1070
+ });
1071
+ reject(err);
1072
+ });
1073
+ }
1074
+ return [2 /*return*/];
1075
+ });
1076
+ }); });
1077
+ };
1078
+ SubscriptionManager.prototype.sendWS = function (ws, data) {
1079
+ this._sendQueue.splice(0, 0, {
1080
+ id_ws: ws['id_socket'],
1081
+ data: data
1082
+ });
1083
+ };
1084
+ SubscriptionManager.prototype.getEnableDebug = function () {
1085
+ return this._enableDebug;
1086
+ };
1087
+ return SubscriptionManager;
1088
+ }());
1089
+ exports.SubscriptionManager = SubscriptionManager;
1090
+
1091
+ //# sourceMappingURL=subscription.manager.js.map