@talkpilot/core-db 1.1.8 → 1.1.9

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 (331) hide show
  1. package/README.md +7 -0
  2. package/dist/connection.d.ts +1 -1
  3. package/dist/connection.d.ts.map +1 -1
  4. package/dist/connection.js +21 -24
  5. package/dist/connection.js.map +1 -1
  6. package/dist/index.d.ts +9 -9
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/municipal/cities/cities.getters.d.ts +2 -2
  10. package/dist/municipal/cities/cities.getters.d.ts.map +1 -1
  11. package/dist/municipal/cities/cities.getters.js +8 -4
  12. package/dist/municipal/cities/cities.getters.js.map +1 -1
  13. package/dist/municipal/cities/cities.types.d.ts +1 -1
  14. package/dist/municipal/cities/index.d.ts +2 -2
  15. package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.d.ts +3 -3
  16. package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.d.ts.map +1 -1
  17. package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.js +30 -22
  18. package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.js.map +1 -1
  19. package/dist/municipal/departmentsSubjects/departmentsSubjects.types.d.ts +4 -4
  20. package/dist/municipal/departmentsSubjects/departmentsSubjects.types.d.ts.map +1 -1
  21. package/dist/municipal/departmentsSubjects/index.d.ts +2 -2
  22. package/dist/municipal/index.d.ts +8 -8
  23. package/dist/municipal/index.d.ts.map +1 -1
  24. package/dist/municipal/index.js +1 -1
  25. package/dist/municipal/mongodb-client.d.ts +1 -1
  26. package/dist/municipal/mongodb-client.d.ts.map +1 -1
  27. package/dist/municipal/mongodb-client.js +7 -7
  28. package/dist/municipal/mongodb-client.js.map +1 -1
  29. package/dist/municipal/streets/index.d.ts +2 -2
  30. package/dist/municipal/streets/streets.getters.d.ts +3 -3
  31. package/dist/municipal/streets/streets.getters.d.ts.map +1 -1
  32. package/dist/municipal/streets/streets.getters.js +19 -9
  33. package/dist/municipal/streets/streets.getters.js.map +1 -1
  34. package/dist/municipal/streets/streets.types.d.ts +1 -1
  35. package/dist/municipal/systemInstructions/index.d.ts +3 -3
  36. package/dist/municipal/systemInstructions/index.d.ts.map +1 -1
  37. package/dist/municipal/systemInstructions/instructions.getters.d.ts +3 -3
  38. package/dist/municipal/systemInstructions/instructions.getters.d.ts.map +1 -1
  39. package/dist/municipal/systemInstructions/instructions.getters.js +10 -4
  40. package/dist/municipal/systemInstructions/instructions.getters.js.map +1 -1
  41. package/dist/municipal/systemInstructions/instructions.setters.d.ts +2 -2
  42. package/dist/municipal/systemInstructions/instructions.setters.d.ts.map +1 -1
  43. package/dist/municipal/systemInstructions/instructions.setters.js +13 -8
  44. package/dist/municipal/systemInstructions/instructions.setters.js.map +1 -1
  45. package/dist/municipal/systemInstructions/instructions.types.d.ts +3 -3
  46. package/dist/municipal/systemInstructions/instructions.types.d.ts.map +1 -1
  47. package/dist/municipal/systemInstructions/instructions.types.js +6 -6
  48. package/dist/municipal/tickets/index.d.ts +2 -2
  49. package/dist/municipal/tickets/tickets.getters.d.ts +3 -3
  50. package/dist/municipal/tickets/tickets.getters.d.ts.map +1 -1
  51. package/dist/municipal/tickets/tickets.getters.js +50 -29
  52. package/dist/municipal/tickets/tickets.getters.js.map +1 -1
  53. package/dist/municipal/tickets/tickets.types.d.ts +1 -1
  54. package/dist/municipal/tickets/tickets.types.d.ts.map +1 -1
  55. package/dist/municipal/utils/types.d.ts +1 -1
  56. package/dist/municipal/utils/types.d.ts.map +1 -1
  57. package/dist/talkpilot/agents/agents.getters.d.ts +1 -1
  58. package/dist/talkpilot/agents/agents.getters.js +2 -2
  59. package/dist/talkpilot/agents/agents.types.d.ts +2 -2
  60. package/dist/talkpilot/agents/index.d.ts +2 -2
  61. package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.d.ts +2 -2
  62. package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.d.ts.map +1 -1
  63. package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.js +1 -1
  64. package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.js.map +1 -1
  65. package/dist/talkpilot/backgroundToolResults/backgroundToolResults.types.d.ts +2 -2
  66. package/dist/talkpilot/backgroundToolResults/index.d.ts +2 -2
  67. package/dist/talkpilot/calls/calls.getters.d.ts +3 -3
  68. package/dist/talkpilot/calls/calls.getters.d.ts.map +1 -1
  69. package/dist/talkpilot/calls/calls.getters.js +19 -15
  70. package/dist/talkpilot/calls/calls.getters.js.map +1 -1
  71. package/dist/talkpilot/calls/calls.types.d.ts +3 -3
  72. package/dist/talkpilot/calls/calls.types.d.ts.map +1 -1
  73. package/dist/talkpilot/calls/calls.types.js +2 -2
  74. package/dist/talkpilot/calls/index.d.ts +2 -2
  75. package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.d.ts +2 -2
  76. package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.d.ts.map +1 -1
  77. package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.js +2 -2
  78. package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.js.map +1 -1
  79. package/dist/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.d.ts +2 -2
  80. package/dist/talkpilot/clientAudioBuffers/index.d.ts +2 -2
  81. package/dist/talkpilot/clients/clients.getters.d.ts +2 -2
  82. package/dist/talkpilot/clients/clients.getters.d.ts.map +1 -1
  83. package/dist/talkpilot/clients/clients.getters.js +5 -2
  84. package/dist/talkpilot/clients/clients.getters.js.map +1 -1
  85. package/dist/talkpilot/clients/clients.types.d.ts +1 -1
  86. package/dist/talkpilot/clients/index.d.ts +2 -2
  87. package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts +2 -2
  88. package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts.map +1 -1
  89. package/dist/talkpilot/clientsConfig/clientsConfig.getters.js +1 -1
  90. package/dist/talkpilot/clientsConfig/clientsConfig.getters.js.map +1 -1
  91. package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts +3 -3
  92. package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts.map +1 -1
  93. package/dist/talkpilot/clientsConfig/index.d.ts +2 -2
  94. package/dist/talkpilot/flows/flows.getter.d.ts +2 -2
  95. package/dist/talkpilot/flows/flows.getter.d.ts.map +1 -1
  96. package/dist/talkpilot/flows/flows.getter.js +1 -1
  97. package/dist/talkpilot/flows/flows.getter.js.map +1 -1
  98. package/dist/talkpilot/flows/flows.schema.d.ts +0 -3
  99. package/dist/talkpilot/flows/flows.schema.d.ts.map +1 -1
  100. package/dist/talkpilot/flows/flows.schema.js +87 -80
  101. package/dist/talkpilot/flows/flows.schema.js.map +1 -1
  102. package/dist/talkpilot/flows/flows.types.d.ts +16 -17
  103. package/dist/talkpilot/flows/flows.types.d.ts.map +1 -1
  104. package/dist/talkpilot/flows/index.d.ts +2 -2
  105. package/dist/talkpilot/groups/groups.getters.d.ts +2 -2
  106. package/dist/talkpilot/groups/groups.getters.d.ts.map +1 -1
  107. package/dist/talkpilot/groups/groups.getters.js +2 -2
  108. package/dist/talkpilot/groups/groups.getters.js.map +1 -1
  109. package/dist/talkpilot/groups/groups.types.d.ts +1 -1
  110. package/dist/talkpilot/groups/index.d.ts +3 -3
  111. package/dist/talkpilot/groups/phone.utils.d.ts +1 -1
  112. package/dist/talkpilot/groups/phone.utils.d.ts.map +1 -1
  113. package/dist/talkpilot/groups/phone.utils.js +2 -2
  114. package/dist/talkpilot/groups/phone.utils.js.map +1 -1
  115. package/dist/talkpilot/index.d.ts +16 -16
  116. package/dist/talkpilot/index.js +1 -1
  117. package/dist/talkpilot/leads/index.d.ts +2 -2
  118. package/dist/talkpilot/leads/leads.getter.d.ts +2 -2
  119. package/dist/talkpilot/leads/leads.getter.d.ts.map +1 -1
  120. package/dist/talkpilot/leads/leads.getter.js +1 -1
  121. package/dist/talkpilot/leads/leads.getter.js.map +1 -1
  122. package/dist/talkpilot/leads/leads.schema.js +16 -16
  123. package/dist/talkpilot/leads/leads.types.d.ts +1 -1
  124. package/dist/talkpilot/mongodb-client.d.ts +1 -1
  125. package/dist/talkpilot/mongodb-client.js +8 -9
  126. package/dist/talkpilot/mongodb-client.js.map +1 -1
  127. package/dist/talkpilot/phone_numbers/index.d.ts +1 -1
  128. package/dist/talkpilot/phone_numbers/index.d.ts.map +1 -1
  129. package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts +5 -2
  130. package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts.map +1 -1
  131. package/dist/talkpilot/phone_numbers/phone_numbers.getter.js +66 -12
  132. package/dist/talkpilot/phone_numbers/phone_numbers.getter.js.map +1 -1
  133. package/dist/talkpilot/phone_numbers/phone_numbers.schema.d.ts +11 -2
  134. package/dist/talkpilot/phone_numbers/phone_numbers.schema.d.ts.map +1 -1
  135. package/dist/talkpilot/phone_numbers/phone_numbers.schema.js +5 -2
  136. package/dist/talkpilot/phone_numbers/phone_numbers.schema.js.map +1 -1
  137. package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts +16 -3
  138. package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts.map +1 -1
  139. package/dist/talkpilot/plans/index.d.ts +2 -2
  140. package/dist/talkpilot/plans/plans.getters.d.ts +2 -2
  141. package/dist/talkpilot/plans/plans.getters.d.ts.map +1 -1
  142. package/dist/talkpilot/plans/plans.getters.js +3 -3
  143. package/dist/talkpilot/plans/plans.getters.js.map +1 -1
  144. package/dist/talkpilot/plans/plans.types.d.ts +4 -4
  145. package/dist/talkpilot/plans/plans.types.d.ts.map +1 -1
  146. package/dist/talkpilot/plans/plans.types.js +19 -19
  147. package/dist/talkpilot/results/index.d.ts +2 -2
  148. package/dist/talkpilot/results/index.d.ts.map +1 -1
  149. package/dist/talkpilot/results/index.js.map +1 -1
  150. package/dist/talkpilot/results/results.getter.d.ts +3 -3
  151. package/dist/talkpilot/results/results.getter.d.ts.map +1 -1
  152. package/dist/talkpilot/results/results.getter.js +4 -4
  153. package/dist/talkpilot/results/results.getter.js.map +1 -1
  154. package/dist/talkpilot/results/results.schema.js +18 -18
  155. package/dist/talkpilot/results/results.types.d.ts +1 -1
  156. package/dist/talkpilot/sessions/index.d.ts +2 -2
  157. package/dist/talkpilot/sessions/sessions.getter.d.ts +3 -3
  158. package/dist/talkpilot/sessions/sessions.getter.d.ts.map +1 -1
  159. package/dist/talkpilot/sessions/sessions.getter.js +13 -10
  160. package/dist/talkpilot/sessions/sessions.getter.js.map +1 -1
  161. package/dist/talkpilot/sessions/sessions.schema.js +17 -17
  162. package/dist/talkpilot/sessions/sessions.types.d.ts +2 -2
  163. package/dist/talkpilot/subscriptions/index.d.ts +3 -3
  164. package/dist/talkpilot/subscriptions/subscriptions.getters.d.ts +2 -2
  165. package/dist/talkpilot/subscriptions/subscriptions.getters.d.ts.map +1 -1
  166. package/dist/talkpilot/subscriptions/subscriptions.getters.js +11 -11
  167. package/dist/talkpilot/subscriptions/subscriptions.getters.js.map +1 -1
  168. package/dist/talkpilot/subscriptions/subscriptions.getters.utils.d.ts +2 -2
  169. package/dist/talkpilot/subscriptions/subscriptions.getters.utils.d.ts.map +1 -1
  170. package/dist/talkpilot/subscriptions/subscriptions.getters.utils.js.map +1 -1
  171. package/dist/talkpilot/subscriptions/subscriptions.types.d.ts +2 -2
  172. package/dist/talkpilot/subscriptions/subscriptions.types.d.ts.map +1 -1
  173. package/dist/talkpilot/subscriptions/subscriptions.types.js +7 -7
  174. package/dist/talkpilot/utils/query.utils.d.ts +1 -1
  175. package/dist/test-utils/db-utils.d.ts +1 -1
  176. package/dist/test-utils/db-utils.js +2 -2
  177. package/dist/test-utils/factories/index.d.ts +12 -12
  178. package/dist/test-utils/factories/municipal/cities.d.ts +2 -2
  179. package/dist/test-utils/factories/municipal/cities.d.ts.map +1 -1
  180. package/dist/test-utils/factories/municipal/cities.js +1 -1
  181. package/dist/test-utils/factories/municipal/departmentsSubjects.d.ts +2 -2
  182. package/dist/test-utils/factories/municipal/departmentsSubjects.d.ts.map +1 -1
  183. package/dist/test-utils/factories/municipal/departmentsSubjects.js +7 -1
  184. package/dist/test-utils/factories/municipal/departmentsSubjects.js.map +1 -1
  185. package/dist/test-utils/factories/municipal/streets.d.ts +2 -2
  186. package/dist/test-utils/factories/municipal/streets.d.ts.map +1 -1
  187. package/dist/test-utils/factories/municipal/streets.js +6 -1
  188. package/dist/test-utils/factories/municipal/streets.js.map +1 -1
  189. package/dist/test-utils/factories/municipal/tickets.d.ts +2 -2
  190. package/dist/test-utils/factories/municipal/tickets.d.ts.map +1 -1
  191. package/dist/test-utils/factories/municipal/tickets.js +7 -1
  192. package/dist/test-utils/factories/municipal/tickets.js.map +1 -1
  193. package/dist/test-utils/factories/talkpilot/agents.d.ts +2 -2
  194. package/dist/test-utils/factories/talkpilot/agents.d.ts.map +1 -1
  195. package/dist/test-utils/factories/talkpilot/agents.js +4 -4
  196. package/dist/test-utils/factories/talkpilot/calls.d.ts +2 -2
  197. package/dist/test-utils/factories/talkpilot/calls.d.ts.map +1 -1
  198. package/dist/test-utils/factories/talkpilot/calls.js +1 -1
  199. package/dist/test-utils/factories/talkpilot/clientAudioBuffers.d.ts +2 -2
  200. package/dist/test-utils/factories/talkpilot/clientAudioBuffers.d.ts.map +1 -1
  201. package/dist/test-utils/factories/talkpilot/clientAudioBuffers.js +1 -1
  202. package/dist/test-utils/factories/talkpilot/clientAudioBuffers.js.map +1 -1
  203. package/dist/test-utils/factories/talkpilot/clientsConfig.d.ts +2 -2
  204. package/dist/test-utils/factories/talkpilot/clientsConfig.d.ts.map +1 -1
  205. package/dist/test-utils/factories/talkpilot/clientsConfig.js.map +1 -1
  206. package/dist/test-utils/factories/talkpilot/flows.d.ts +3 -3
  207. package/dist/test-utils/factories/talkpilot/flows.d.ts.map +1 -1
  208. package/dist/test-utils/factories/talkpilot/flows.js.map +1 -1
  209. package/dist/test-utils/factories/talkpilot/groups.d.ts +2 -2
  210. package/dist/test-utils/factories/talkpilot/groups.d.ts.map +1 -1
  211. package/dist/test-utils/factories/talkpilot/groups.js +9 -9
  212. package/dist/test-utils/factories/talkpilot/groups.js.map +1 -1
  213. package/dist/test-utils/factories/talkpilot/phone_numbers.d.ts +3 -3
  214. package/dist/test-utils/factories/talkpilot/phone_numbers.d.ts.map +1 -1
  215. package/dist/test-utils/factories/talkpilot/phone_numbers.js.map +1 -1
  216. package/dist/test-utils/factories/talkpilot/sessions.d.ts +2 -2
  217. package/dist/test-utils/factories/talkpilot/sessions.d.ts.map +1 -1
  218. package/dist/test-utils/factories/talkpilot/sessions.js +1 -1
  219. package/dist/utils/validation.js +2 -2
  220. package/dist/utils/validation.js.map +1 -1
  221. package/package.json +3 -1
  222. package/src/__tests__/setup.ts +3 -3
  223. package/src/connection.ts +27 -25
  224. package/src/index.ts +9 -9
  225. package/src/municipal/__tests__/validation.spec.ts +35 -23
  226. package/src/municipal/cities/cities.getters.ts +16 -10
  227. package/src/municipal/cities/cities.types.ts +1 -1
  228. package/src/municipal/cities/index.ts +2 -2
  229. package/src/municipal/departmentsSubjects/departmentsSubjects.getters.ts +53 -44
  230. package/src/municipal/departmentsSubjects/departmentsSubjects.types.ts +5 -5
  231. package/src/municipal/departmentsSubjects/index.ts +2 -3
  232. package/src/municipal/index.ts +10 -10
  233. package/src/municipal/mongodb-client.ts +13 -10
  234. package/src/municipal/streets/index.ts +2 -2
  235. package/src/municipal/streets/streets.getters.ts +43 -23
  236. package/src/municipal/streets/streets.types.ts +1 -1
  237. package/src/municipal/systemInstructions/__tests__/getters.spec.ts +67 -52
  238. package/src/municipal/systemInstructions/__tests__/setters.spec.ts +271 -238
  239. package/src/municipal/systemInstructions/index.ts +7 -3
  240. package/src/municipal/systemInstructions/instructions.getters.ts +30 -18
  241. package/src/municipal/systemInstructions/instructions.setters.ts +43 -19
  242. package/src/municipal/systemInstructions/instructions.types.ts +10 -10
  243. package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +12 -12
  244. package/src/municipal/tickets/index.ts +2 -2
  245. package/src/municipal/tickets/tickets.getters.ts +69 -42
  246. package/src/municipal/tickets/tickets.types.ts +2 -2
  247. package/src/municipal/utils/types.ts +8 -3
  248. package/src/talkpilot/__tests__/db.spec.ts +12 -12
  249. package/src/talkpilot/__tests__/mongodb-client.spec.ts +7 -8
  250. package/src/talkpilot/__tests__/validation.spec.ts +30 -24
  251. package/src/talkpilot/agents/__tests__/agents.getters.spec.ts +10 -10
  252. package/src/talkpilot/agents/agents.getters.ts +3 -3
  253. package/src/talkpilot/agents/agents.types.ts +2 -2
  254. package/src/talkpilot/agents/index.ts +2 -2
  255. package/src/talkpilot/backgroundToolResults/__tests__/backgroundToolResults.getters.spec.ts +42 -31
  256. package/src/talkpilot/backgroundToolResults/backgroundToolResults.getters.ts +11 -11
  257. package/src/talkpilot/backgroundToolResults/backgroundToolResults.types.ts +2 -3
  258. package/src/talkpilot/backgroundToolResults/index.ts +2 -2
  259. package/src/talkpilot/calls/__tests__/callStats.utils.spec.ts +27 -27
  260. package/src/talkpilot/calls/__tests__/calls.spec.ts +79 -39
  261. package/src/talkpilot/calls/calls.getters.ts +48 -28
  262. package/src/talkpilot/calls/calls.types.ts +16 -16
  263. package/src/talkpilot/calls/index.ts +2 -2
  264. package/src/talkpilot/clientAudioBuffers/__tests__/clientAudioBuffer.getters.spec.ts +73 -39
  265. package/src/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.ts +18 -11
  266. package/src/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.ts +2 -2
  267. package/src/talkpilot/clientAudioBuffers/index.ts +2 -2
  268. package/src/talkpilot/clients/clients.getters.ts +10 -5
  269. package/src/talkpilot/clients/clients.types.ts +1 -1
  270. package/src/talkpilot/clients/index.ts +2 -2
  271. package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +21 -18
  272. package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +6 -4
  273. package/src/talkpilot/clientsConfig/clientsConfig.types.ts +10 -8
  274. package/src/talkpilot/clientsConfig/index.ts +2 -2
  275. package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +38 -37
  276. package/src/talkpilot/flows/flows.getter.ts +8 -5
  277. package/src/talkpilot/flows/flows.schema.ts +87 -80
  278. package/src/talkpilot/flows/flows.types.ts +23 -24
  279. package/src/talkpilot/flows/index.ts +2 -2
  280. package/src/talkpilot/groups/__tests__/groups.spec.ts +34 -27
  281. package/src/talkpilot/groups/__tests__/phone.utils.spec.ts +20 -20
  282. package/src/talkpilot/groups/groups.getters.ts +8 -5
  283. package/src/talkpilot/groups/groups.types.ts +1 -1
  284. package/src/talkpilot/groups/index.ts +3 -3
  285. package/src/talkpilot/groups/phone.utils.ts +12 -6
  286. package/src/talkpilot/index.ts +17 -17
  287. package/src/talkpilot/leads/index.ts +2 -2
  288. package/src/talkpilot/leads/leads.getter.ts +5 -4
  289. package/src/talkpilot/leads/leads.schema.ts +16 -16
  290. package/src/talkpilot/leads/leads.types.ts +1 -1
  291. package/src/talkpilot/mongodb-client.ts +12 -12
  292. package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +162 -33
  293. package/src/talkpilot/phone_numbers/index.ts +1 -1
  294. package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +94 -18
  295. package/src/talkpilot/phone_numbers/phone_numbers.schema.ts +5 -2
  296. package/src/talkpilot/phone_numbers/phone_numbers.types.ts +18 -3
  297. package/src/talkpilot/plans/__tests__/plans.spec.ts +30 -26
  298. package/src/talkpilot/plans/index.ts +2 -2
  299. package/src/talkpilot/plans/plans.getters.ts +25 -18
  300. package/src/talkpilot/plans/plans.types.ts +27 -23
  301. package/src/talkpilot/results/index.ts +5 -2
  302. package/src/talkpilot/results/results.getter.ts +9 -8
  303. package/src/talkpilot/results/results.schema.ts +18 -18
  304. package/src/talkpilot/results/results.types.ts +1 -1
  305. package/src/talkpilot/sessions/__tests__/sessions.spec.ts +65 -41
  306. package/src/talkpilot/sessions/index.ts +2 -2
  307. package/src/talkpilot/sessions/sessions.getter.ts +21 -16
  308. package/src/talkpilot/sessions/sessions.schema.ts +17 -17
  309. package/src/talkpilot/sessions/sessions.types.ts +2 -2
  310. package/src/talkpilot/subscriptions/__tests__/subscriptions.getters.utils.spec.ts +18 -15
  311. package/src/talkpilot/subscriptions/index.ts +3 -3
  312. package/src/talkpilot/subscriptions/subscriptions.getters.ts +36 -33
  313. package/src/talkpilot/subscriptions/subscriptions.getters.utils.ts +10 -3
  314. package/src/talkpilot/subscriptions/subscriptions.types.ts +9 -9
  315. package/src/talkpilot/utils/__tests__/query.utils.spec.ts +8 -8
  316. package/src/talkpilot/utils/query.utils.ts +2 -2
  317. package/src/test-utils/db-utils.ts +5 -5
  318. package/src/test-utils/factories/index.ts +12 -12
  319. package/src/test-utils/factories/municipal/cities.ts +5 -5
  320. package/src/test-utils/factories/municipal/departmentsSubjects.ts +32 -25
  321. package/src/test-utils/factories/municipal/streets.ts +10 -5
  322. package/src/test-utils/factories/municipal/tickets.ts +12 -6
  323. package/src/test-utils/factories/talkpilot/agents.ts +8 -8
  324. package/src/test-utils/factories/talkpilot/calls.ts +5 -5
  325. package/src/test-utils/factories/talkpilot/clientAudioBuffers.ts +14 -12
  326. package/src/test-utils/factories/talkpilot/clientsConfig.ts +7 -8
  327. package/src/test-utils/factories/talkpilot/flows.ts +7 -5
  328. package/src/test-utils/factories/talkpilot/groups.ts +13 -13
  329. package/src/test-utils/factories/talkpilot/phone_numbers.ts +8 -6
  330. package/src/test-utils/factories/talkpilot/sessions.ts +5 -5
  331. package/src/utils/validation.ts +4 -4
@@ -1,7 +1,11 @@
1
- import { ObjectId } from '../index';
2
- import { ObjectId as MongoObjectId } from 'mongodb';
3
- import { MIS_SystemInstruction, MIS_TOOLS, QUERY_TYPES } from './instructions.types';
4
- import { getSystemInstructionsCollection } from './instructions.getters';
1
+ import { ObjectId } from "../index";
2
+ import { ObjectId as MongoObjectId } from "mongodb";
3
+ import {
4
+ MIS_SystemInstruction,
5
+ MIS_TOOLS,
6
+ QUERY_TYPES,
7
+ } from "./instructions.types";
8
+ import { getSystemInstructionsCollection } from "./instructions.getters";
5
9
 
6
10
  /**
7
11
  * Validate system instruction data
@@ -9,11 +13,21 @@ import { getSystemInstructionsCollection } from './instructions.getters';
9
13
  * @throws Error if tool or queryType is invalid
10
14
  */
11
15
  const validateInstructionData = (data: Partial<MIS_SystemInstruction>) => {
12
- if (data.tool && !(Object.values(MIS_TOOLS) as string[]).includes(data.tool)) {
13
- throw new Error(`Invalid tool value: ${data.tool}. Allowed values are: ${Object.values(MIS_TOOLS).join(', ')}`);
16
+ if (
17
+ data.tool &&
18
+ !(Object.values(MIS_TOOLS) as string[]).includes(data.tool)
19
+ ) {
20
+ throw new Error(
21
+ `Invalid tool value: ${data.tool}. Allowed values are: ${Object.values(MIS_TOOLS).join(", ")}`,
22
+ );
14
23
  }
15
- if (data.queryType && !(Object.values(QUERY_TYPES) as string[]).includes(data.queryType)) {
16
- throw new Error(`Invalid queryType value: ${data.queryType}. Allowed values are: ${Object.values(QUERY_TYPES).join(', ')}`);
24
+ if (
25
+ data.queryType &&
26
+ !(Object.values(QUERY_TYPES) as string[]).includes(data.queryType)
27
+ ) {
28
+ throw new Error(
29
+ `Invalid queryType value: ${data.queryType}. Allowed values are: ${Object.values(QUERY_TYPES).join(", ")}`,
30
+ );
17
31
  }
18
32
  };
19
33
 
@@ -23,16 +37,20 @@ const validateInstructionData = (data: Partial<MIS_SystemInstruction>) => {
23
37
  * @returns inserted system instruction id
24
38
  */
25
39
  export const createSystemInstruction = async (
26
- instructionData: Omit<MIS_SystemInstruction, '_id' | 'createdAt' | 'updatedAt'>
40
+ instructionData: Omit<
41
+ MIS_SystemInstruction,
42
+ "_id" | "createdAt" | "updatedAt"
43
+ >,
27
44
  ): Promise<MongoObjectId> => {
28
45
  validateInstructionData(instructionData as Partial<MIS_SystemInstruction>);
29
- const instruction: Omit<MIS_SystemInstruction, '_id'> = { //append doc metadata to user provided data
46
+ const instruction: Omit<MIS_SystemInstruction, "_id"> = {
47
+ //append doc metadata to user provided data
30
48
  ...instructionData,
31
49
  createdAt: new Date(),
32
50
  updatedAt: new Date(),
33
51
  };
34
52
  const { insertedId } = await getSystemInstructionsCollection().insertOne(
35
- instruction as MIS_SystemInstruction
53
+ instruction as MIS_SystemInstruction,
36
54
  );
37
55
  return insertedId;
38
56
  };
@@ -45,13 +63,13 @@ export const createSystemInstruction = async (
45
63
  */
46
64
  export const updateSystemInstruction = async (
47
65
  id: string,
48
- data: Partial<Omit<MIS_SystemInstruction, '_id' | 'createdAt' | 'updatedAt'>>
66
+ data: Partial<Omit<MIS_SystemInstruction, "_id" | "createdAt" | "updatedAt">>,
49
67
  ): Promise<MIS_SystemInstruction | null> => {
50
68
  validateInstructionData(data as Partial<MIS_SystemInstruction>);
51
69
  const result = await getSystemInstructionsCollection().findOneAndUpdate(
52
70
  { _id: new ObjectId(id) },
53
71
  { $set: { ...data, updatedAt: new Date() } },
54
- { returnDocument: 'after' }
72
+ { returnDocument: "after" },
55
73
  );
56
74
  return result || null;
57
75
  };
@@ -62,7 +80,9 @@ export const updateSystemInstruction = async (
62
80
  * @returns true if deleted, false otherwise
63
81
  */
64
82
  export const deleteSystemInstruction = async (id: string): Promise<boolean> => {
65
- const result = await getSystemInstructionsCollection().deleteOne({ _id: new ObjectId(id) });
83
+ const result = await getSystemInstructionsCollection().deleteOne({
84
+ _id: new ObjectId(id),
85
+ });
66
86
  return result.deletedCount > 0;
67
87
  };
68
88
  /**
@@ -71,11 +91,13 @@ export const deleteSystemInstruction = async (id: string): Promise<boolean> => {
71
91
  * @param id system instruction id
72
92
  * @returns true on success, false otherwise
73
93
  */
74
- export const activateSystemInstruction = async (id: string): Promise<boolean> => {
94
+ export const activateSystemInstruction = async (
95
+ id: string,
96
+ ): Promise<boolean> => {
75
97
  const result = await getSystemInstructionsCollection().findOneAndUpdate(
76
98
  { _id: new ObjectId(id) },
77
99
  { $set: { isActive: true } },
78
- { returnDocument: 'after' }
100
+ { returnDocument: "after" },
79
101
  );
80
102
  return Boolean(result);
81
103
  };
@@ -85,11 +107,13 @@ export const activateSystemInstruction = async (id: string): Promise<boolean> =>
85
107
  * @param id system instruction id
86
108
  * @returns true on success, false otherwise
87
109
  */
88
- export const deactivateSystemInstruction = async (id: string): Promise<boolean> => {
110
+ export const deactivateSystemInstruction = async (
111
+ id: string,
112
+ ): Promise<boolean> => {
89
113
  const result = await getSystemInstructionsCollection().findOneAndUpdate(
90
114
  { _id: new ObjectId(id) },
91
115
  { $set: { isActive: false } },
92
- {returnDocument: 'after'}
116
+ { returnDocument: "after" },
93
117
  );
94
118
  return Boolean(result);
95
- }
119
+ };
@@ -1,21 +1,21 @@
1
- import { ObjectId } from 'mongodb';
1
+ import { ObjectId } from "mongodb";
2
2
 
3
- import {CityName} from "../utils/types";
3
+ import { CityName } from "../utils/types";
4
4
 
5
5
  export const MIS_TOOLS = {
6
- findStreet: 'findStreet',
7
- findSubject: 'findSubject'
6
+ findStreet: "findStreet",
7
+ findSubject: "findSubject",
8
8
  } as const;
9
9
 
10
10
  export const QUERY_TYPES = {
11
- exactlyOne: 'exactlyOne',
12
- any: 'any',
13
- all: 'all',
14
- none: 'none'
11
+ exactlyOne: "exactlyOne",
12
+ any: "any",
13
+ all: "all",
14
+ none: "none",
15
15
  } as const;
16
16
 
17
- export type MIS_Tool = typeof MIS_TOOLS[keyof typeof MIS_TOOLS];
18
- export type QueryType = typeof QUERY_TYPES[keyof typeof QUERY_TYPES];
17
+ export type MIS_Tool = (typeof MIS_TOOLS)[keyof typeof MIS_TOOLS];
18
+ export type QueryType = (typeof QUERY_TYPES)[keyof typeof QUERY_TYPES];
19
19
 
20
20
  export type MIS_SystemInstruction = {
21
21
  _id: ObjectId;
@@ -1,14 +1,14 @@
1
- import { findTicketsByCallSid } from '../tickets.getters';
2
- import { setDb } from '../../index';
3
- import { Db, Collection } from 'mongodb';
4
- import { createTicket } from '../../../test-utils/factories';
1
+ import { findTicketsByCallSid } from "../tickets.getters";
2
+ import { setDb } from "../../index";
3
+ import { Db, Collection } from "mongodb";
4
+ import { createTicket } from "../../../test-utils/factories";
5
5
 
6
- describe('tickets getters', () => {
6
+ describe("tickets getters", () => {
7
7
  let mockDb: Partial<Db>;
8
8
  let mockCollection: Partial<Collection>;
9
9
 
10
10
  beforeEach(() => {
11
- const mockTicket = createTicket({ callSid: '123' });
11
+ const mockTicket = createTicket({ callSid: "123" });
12
12
  mockCollection = {
13
13
  find: jest.fn().mockReturnValue({
14
14
  toArray: jest.fn().mockResolvedValue([mockTicket]),
@@ -20,11 +20,11 @@ describe('tickets getters', () => {
20
20
  setDb(mockDb as Db);
21
21
  });
22
22
 
23
- it('findTicketsByCallSid should return tickets for the given callSid', async () => {
24
- const result = await findTicketsByCallSid('123');
25
-
26
- expect(mockDb.collection).toHaveBeenCalledWith('tickets');
27
- expect(mockCollection.find).toHaveBeenCalledWith({ callSid: '123' });
28
- expect(result[0].callSid).toBe('123');
23
+ it("findTicketsByCallSid should return tickets for the given callSid", async () => {
24
+ const result = await findTicketsByCallSid("123");
25
+
26
+ expect(mockDb.collection).toHaveBeenCalledWith("tickets");
27
+ expect(mockCollection.find).toHaveBeenCalledWith({ callSid: "123" });
28
+ expect(result[0].callSid).toBe("123");
29
29
  });
30
30
  });
@@ -1,2 +1,2 @@
1
- export * from './tickets.getters';
2
- export type { Ticket, TicketDoc, SubjectStatsItem } from './tickets.types';
1
+ export * from "./tickets.getters";
2
+ export type { Ticket, TicketDoc, SubjectStatsItem } from "./tickets.types";
@@ -1,6 +1,6 @@
1
- import {CityName, getDb, ObjectId, Ticket} from '../index';
2
- import type { SubjectStatsItem } from './tickets.types';
3
- import { Collection, Filter, ObjectId as MongoObjectId } from 'mongodb';
1
+ import { CityName, getDb, ObjectId, Ticket } from "../index";
2
+ import type { SubjectStatsItem } from "./tickets.types";
3
+ import { Collection, Filter, ObjectId as MongoObjectId } from "mongodb";
4
4
 
5
5
  /**
6
6
  * Generate a new ticket ID as a string
@@ -11,25 +11,33 @@ export const generateTicketId = (): string => {
11
11
  };
12
12
 
13
13
  export const getTicketsCollection = (): Collection<Ticket> => {
14
- return getDb().collection<Ticket>('tickets');
14
+ return getDb().collection<Ticket>("tickets");
15
15
  };
16
16
 
17
- export const findTickets = async (filter: Filter<Ticket> = {}): Promise<Ticket[]> => {
17
+ export const findTickets = async (
18
+ filter: Filter<Ticket> = {},
19
+ ): Promise<Ticket[]> => {
18
20
  return await getTicketsCollection().find(filter).toArray();
19
21
  };
20
22
 
21
- export const findTicketsByCallSid = async (callSid: string): Promise<Ticket[]> => {
23
+ export const findTicketsByCallSid = async (
24
+ callSid: string,
25
+ ): Promise<Ticket[]> => {
22
26
  return await getTicketsCollection().find({ callSid }).toArray();
23
27
  };
24
28
 
25
- export const getTicketById = async (ticketId: string): Promise<Ticket | null> => {
26
- const ticket = await getTicketsCollection().findOne({ _id: new ObjectId(ticketId) });
29
+ export const getTicketById = async (
30
+ ticketId: string,
31
+ ): Promise<Ticket | null> => {
32
+ const ticket = await getTicketsCollection().findOne({
33
+ _id: new ObjectId(ticketId),
34
+ });
27
35
  return ticket ? ticket : null;
28
36
  };
29
37
 
30
38
  export const createTicket = async (
31
- ticketData: Omit<Ticket, '_id' | 'createdAt' | 'updatedAt'>,
32
- ticketId?: string
39
+ ticketData: Omit<Ticket, "_id" | "createdAt" | "updatedAt">,
40
+ ticketId?: string,
33
41
  ): Promise<MongoObjectId> => {
34
42
  const ticket: Ticket = {
35
43
  _id: ticketId ? new ObjectId(ticketId) : new ObjectId(),
@@ -43,18 +51,20 @@ export const createTicket = async (
43
51
 
44
52
  export const updateTicket = async (
45
53
  ticketId: string,
46
- data: Partial<Omit<Ticket, '_id' | 'createdAt' | 'updatedAt'>>
54
+ data: Partial<Omit<Ticket, "_id" | "createdAt" | "updatedAt">>,
47
55
  ): Promise<Ticket | null> => {
48
56
  const result = await getTicketsCollection().findOneAndUpdate(
49
57
  { _id: new ObjectId(ticketId) },
50
58
  { $set: { ...data, updatedAt: new Date() } },
51
- { returnDocument: 'after' }
59
+ { returnDocument: "after" },
52
60
  );
53
61
  return result || null;
54
62
  };
55
63
 
56
64
  export const deleteTicket = async (ticketId: string): Promise<boolean> => {
57
- const result = await getTicketsCollection().deleteOne({ _id: new ObjectId(ticketId) });
65
+ const result = await getTicketsCollection().deleteOne({
66
+ _id: new ObjectId(ticketId),
67
+ });
58
68
  return result.deletedCount > 0;
59
69
  };
60
70
 
@@ -66,7 +76,7 @@ export async function getTicketsCountByCityAndDateRange(
66
76
  cityName: string,
67
77
  startStr: string,
68
78
  endStr: string,
69
- timezone: string
79
+ timezone: string,
70
80
  ): Promise<number> {
71
81
  const doc = await getTicketsCollection()
72
82
  .aggregate<{ n: number }>([
@@ -74,12 +84,12 @@ export async function getTicketsCountByCityAndDateRange(
74
84
  {
75
85
  $addFields: {
76
86
  dateLocal: {
77
- $dateToString: { format: '%Y-%m-%d', date: '$createdAt', timezone },
87
+ $dateToString: { format: "%Y-%m-%d", date: "$createdAt", timezone },
78
88
  },
79
89
  },
80
90
  },
81
91
  { $match: { dateLocal: { $gte: startStr, $lte: endStr } } },
82
- { $count: 'n' },
92
+ { $count: "n" },
83
93
  ])
84
94
  .next();
85
95
  return doc?.n ?? 0;
@@ -93,7 +103,7 @@ export async function getTicketsSubjectStats(
93
103
  cityName: string,
94
104
  startStr: string,
95
105
  endStr: string,
96
- timezone: string
106
+ timezone: string,
97
107
  ): Promise<SubjectStatsItem[]> {
98
108
  const coll = getTicketsCollection();
99
109
  const rows = await coll
@@ -102,7 +112,7 @@ export async function getTicketsSubjectStats(
102
112
  {
103
113
  $addFields: {
104
114
  dateLocal: {
105
- $dateToString: { format: '%Y-%m-%d', date: '$createdAt', timezone },
115
+ $dateToString: { format: "%Y-%m-%d", date: "$createdAt", timezone },
106
116
  },
107
117
  },
108
118
  },
@@ -111,11 +121,11 @@ export async function getTicketsSubjectStats(
111
121
  $addFields: {
112
122
  effectiveSubjectId: {
113
123
  $ifNull: [
114
- '$externalCallFields.event_subject_id',
124
+ "$externalCallFields.event_subject_id",
115
125
  {
116
126
  $ifNull: [
117
- '$externalCallFields.event_sub_subject_id',
118
- '$externalCallFields.event_sub_subject_id2',
127
+ "$externalCallFields.event_sub_subject_id",
128
+ "$externalCallFields.event_sub_subject_id2",
119
129
  ],
120
130
  },
121
131
  ],
@@ -124,19 +134,23 @@ export async function getTicketsSubjectStats(
124
134
  },
125
135
  {
126
136
  $lookup: {
127
- from: 'departmentsSubjects',
128
- let: { sid: '$effectiveSubjectId', c: cityName },
137
+ from: "departmentsSubjects",
138
+ let: { sid: "$effectiveSubjectId", c: cityName },
129
139
  pipeline: [
130
140
  {
131
141
  $match: {
132
142
  $expr: {
133
143
  $and: [
134
- { $eq: ['$cityName', '$$c'] },
144
+ { $eq: ["$cityName", "$$c"] },
135
145
  {
136
146
  $or: [
137
- { $eq: ['$subject_id', { $ifNull: ['$$sid', ''] }] },
138
- { $eq: ['$sub_subject_id', { $ifNull: ['$$sid', ''] }] },
139
- { $eq: ['$sub_subject_id2', { $ifNull: ['$$sid', ''] }] },
147
+ { $eq: ["$subject_id", { $ifNull: ["$$sid", ""] }] },
148
+ {
149
+ $eq: ["$sub_subject_id", { $ifNull: ["$$sid", ""] }],
150
+ },
151
+ {
152
+ $eq: ["$sub_subject_id2", { $ifNull: ["$$sid", ""] }],
153
+ },
140
154
  ],
141
155
  },
142
156
  ],
@@ -145,28 +159,41 @@ export async function getTicketsSubjectStats(
145
159
  },
146
160
  { $limit: 1 },
147
161
  ],
148
- as: 'subj',
162
+ as: "subj",
149
163
  },
150
164
  },
151
165
  {
152
166
  $addFields: {
153
167
  subject_id: {
154
168
  $cond: {
155
- if: { $gt: [{ $size: '$subj' }, 0] },
156
- then: { $ifNull: [{ $arrayElemAt: ['$subj.subject_id', 0] }, ''] },
157
- else: '',
169
+ if: { $gt: [{ $size: "$subj" }, 0] },
170
+ then: {
171
+ $ifNull: [{ $arrayElemAt: ["$subj.subject_id", 0] }, ""],
172
+ },
173
+ else: "",
158
174
  },
159
175
  },
160
176
  subject: {
161
177
  $cond: {
162
- if: { $gt: [{ $size: '$subj' }, 0] },
163
- then: { $ifNull: [{ $arrayElemAt: ['$subj.subjectName', 0] }, 'Unclassified'] },
164
- else: 'Unclassified',
178
+ if: { $gt: [{ $size: "$subj" }, 0] },
179
+ then: {
180
+ $ifNull: [
181
+ { $arrayElemAt: ["$subj.subjectName", 0] },
182
+ "Unclassified",
183
+ ],
184
+ },
185
+ else: "Unclassified",
165
186
  },
166
187
  },
167
188
  },
168
189
  },
169
- { $group: { _id: '$subject_id', subject: { $first: '$subject' }, count: { $sum: 1 } } },
190
+ {
191
+ $group: {
192
+ _id: "$subject_id",
193
+ subject: { $first: "$subject" },
194
+ count: { $sum: 1 },
195
+ },
196
+ },
170
197
  { $sort: { count: -1 } },
171
198
  ])
172
199
  .toArray();
@@ -196,21 +223,21 @@ export const updateTicketFilesByCallNumber = async (params: {
196
223
  const { cityName, callNumber, image1, image2, image3 } = params;
197
224
 
198
225
  const update: any = {};
199
- if (image1) update['externalCallFields.image1'] = image1;
200
- if (image2) update['externalCallFields.image2'] = image2;
201
- if (image3) update['externalCallFields.image3'] = image3;
226
+ if (image1) update["externalCallFields.image1"] = image1;
227
+ if (image2) update["externalCallFields.image2"] = image2;
228
+ if (image3) update["externalCallFields.image3"] = image3;
202
229
 
203
230
  const result = await getTicketsCollection().updateOne(
204
231
  {
205
232
  cityName: cityName,
206
- 'externalCallFields.call_number': callNumber,
233
+ "externalCallFields.call_number": callNumber,
207
234
  },
208
235
  {
209
236
  $set: {
210
237
  ...update,
211
238
  updatedAt: new Date(),
212
239
  },
213
- }
240
+ },
214
241
  );
215
242
 
216
243
  return result.matchedCount > 0;
@@ -226,8 +253,8 @@ export const clearGuestJwtByCallNumber = async (params: {
226
253
  const { cityName, callNumber } = params;
227
254
 
228
255
  const result = await getTicketsCollection().updateOne(
229
- { cityName, 'externalCallFields.call_number': callNumber },
230
- { $unset: { guestJwt: '' }, $set: { updatedAt: new Date() } }
256
+ { cityName, "externalCallFields.call_number": callNumber },
257
+ { $unset: { guestJwt: "" }, $set: { updatedAt: new Date() } },
231
258
  );
232
259
 
233
260
  return result.matchedCount > 0;
@@ -1,6 +1,6 @@
1
- import { ObjectId, WithId } from 'mongodb';
1
+ import { ObjectId, WithId } from "mongodb";
2
2
 
3
- import {CityName} from "../utils/types";
3
+ import { CityName } from "../utils/types";
4
4
 
5
5
  export type Ticket = {
6
6
  _id: ObjectId;
@@ -1,6 +1,11 @@
1
-
2
-
3
1
  /**
4
2
  * City name type for municipal data
5
3
  */
6
- export type CityName = 'ashdod' | 'maltar' | 'billit' | 'hashkelon' | 'eilat' | 'tests' | string;
4
+ export type CityName =
5
+ | "ashdod"
6
+ | "maltar"
7
+ | "billit"
8
+ | "hashkelon"
9
+ | "eilat"
10
+ | "tests"
11
+ | string;
@@ -8,25 +8,25 @@ import {
8
8
  ObjectId,
9
9
  getPlansCollection,
10
10
  getSubscriptionsCollection,
11
- } from '../index';
11
+ } from "../index";
12
12
 
13
- import { ObjectId as MongoObjectId } from 'mongodb';
13
+ import { ObjectId as MongoObjectId } from "mongodb";
14
14
 
15
- describe('talkpilot core/db', () => {
15
+ describe("talkpilot core/db", () => {
16
16
  it.each([
17
- ['flows', getFlowsCollection],
18
- ['sessions', getSessionsCollection],
19
- ['results', getResultsCollection],
20
- ['leads', getLeadsCollection],
21
- ['phone_numbers', getPhoneNumbersCollection],
22
- ['clients', getClientsCollection],
23
- ['plans', getPlansCollection],
24
- ['subscriptions', getSubscriptionsCollection],
17
+ ["flows", getFlowsCollection],
18
+ ["sessions", getSessionsCollection],
19
+ ["results", getResultsCollection],
20
+ ["leads", getLeadsCollection],
21
+ ["phone_numbers", getPhoneNumbersCollection],
22
+ ["clients", getClientsCollection],
23
+ ["plans", getPlansCollection],
24
+ ["subscriptions", getSubscriptionsCollection],
25
25
  ])('%s collection helper returns a "%s" collection', (name, getter) => {
26
26
  expect(getter().collectionName).toBe(name);
27
27
  });
28
28
 
29
- it('ObjectId re-export behaves like mongodb.ObjectId', () => {
29
+ it("ObjectId re-export behaves like mongodb.ObjectId", () => {
30
30
  expect(ObjectId).toBe(MongoObjectId);
31
31
 
32
32
  const id = new ObjectId();
@@ -1,19 +1,18 @@
1
- import { mongodbClient } from '../mongodb-client';
2
- import { getDb } from '../index';
1
+ import { getDb } from "../index";
3
2
 
4
- describe('MongoDBClient', () => {
5
- it('should have a connected database instance from global setup', () => {
3
+ describe("MongoDBClient", () => {
4
+ it("should have a connected database instance from global setup", () => {
6
5
  const db = getDb();
7
6
  expect(db).toBeDefined();
8
- expect(db.databaseName).toBe('test'); // Based on our setup.ts
7
+ expect(db.databaseName).toBe("test"); // Based on our setup.ts
9
8
  });
10
9
 
11
- it('should report as connected', async () => {
10
+ it("should report as connected", async () => {
12
11
  // Note: mongodbClient.connect() was called in global setup
13
12
  // but through setDb, not necessarily through the client singleton instance
14
13
  // since initTestDb calls setDb directly.
15
-
14
+
16
15
  // In a real scenario, you'd use the client.
17
- expect(true).toBe(true);
16
+ expect(true).toBe(true);
18
17
  });
19
18
  });
@@ -1,7 +1,7 @@
1
- import { mongodbClient } from '../mongodb-client';
2
- import { MongoClient } from 'mongodb';
1
+ import { mongodbClient } from "../mongodb-client";
2
+ import { MongoClient } from "mongodb";
3
3
 
4
- describe('MongoDBClient Validation', () => {
4
+ describe("MongoDBClient Validation", () => {
5
5
  const originalEnv = process.env;
6
6
 
7
7
  beforeEach(() => {
@@ -9,7 +9,7 @@ describe('MongoDBClient Validation', () => {
9
9
  delete process.env.MONGO_URI;
10
10
  delete process.env.MONGODB_URI;
11
11
  delete process.env.MONGODB_DB_NAME;
12
-
12
+
13
13
  // Force reset singleton state
14
14
  (mongodbClient as any).client = null;
15
15
  (mongodbClient as any).db = null;
@@ -21,41 +21,47 @@ describe('MongoDBClient Validation', () => {
21
21
  await mongodbClient.disconnect();
22
22
  });
23
23
 
24
- it('should throw error if no URI is provided', async () => {
24
+ it("should throw error if no URI is provided", async () => {
25
25
  await expect(mongodbClient.connect()).rejects.toThrow(
26
- "[core-db] Configuration Error: 'MONGO_URI' is missing"
26
+ "[core-db] Configuration Error: 'MONGO_URI' is missing",
27
27
  );
28
28
  });
29
29
 
30
- it('should throw error if an invalid URI format is provided', async () => {
31
- await expect(mongodbClient.connect('not-a-mongo-uri')).rejects.toThrow(
32
- "[core-db] Connection Error: The provided MongoDB URI is invalid"
30
+ it("should throw error if an invalid URI format is provided", async () => {
31
+ await expect(mongodbClient.connect("not-a-mongo-uri")).rejects.toThrow(
32
+ "[core-db] Connection Error: The provided MongoDB URI is invalid",
33
33
  );
34
34
  });
35
35
 
36
- it('should throw error if URI is valid but database name is missing', async () => {
36
+ it("should throw error if URI is valid but database name is missing", async () => {
37
37
  // We mock the actual MongoClient connection so it doesn't try to hit a real network
38
- const connectSpy = jest.spyOn(MongoClient.prototype, 'connect').mockResolvedValue({} as any);
39
-
40
- const uriWithoutDb = 'mongodb://127.0.0.1:27017';
38
+ const connectSpy = jest
39
+ .spyOn(MongoClient.prototype, "connect")
40
+ .mockResolvedValue({} as any);
41
+
42
+ const uriWithoutDb = "mongodb://127.0.0.1:27017";
41
43
  await expect(mongodbClient.connect(uriWithoutDb)).rejects.toThrow(
42
- "[core-db] Database name not specified"
44
+ "[core-db] Database name not specified",
43
45
  );
44
-
46
+
45
47
  connectSpy.mockRestore();
46
48
  });
47
49
 
48
- it('should succeed when valid URI and DB name are provided', async () => {
49
- const mockDb = { databaseName: 'my-db' };
50
- const connectSpy = jest.spyOn(MongoClient.prototype, 'connect').mockResolvedValue({} as any);
51
- const dbSpy = jest.spyOn(MongoClient.prototype, 'db').mockReturnValue(mockDb as any);
52
-
53
- const validUri = 'mongodb://127.0.0.1:27017/my-db';
50
+ it("should succeed when valid URI and DB name are provided", async () => {
51
+ const mockDb = { databaseName: "my-db" };
52
+ const connectSpy = jest
53
+ .spyOn(MongoClient.prototype, "connect")
54
+ .mockResolvedValue({} as any);
55
+ const dbSpy = jest
56
+ .spyOn(MongoClient.prototype, "db")
57
+ .mockReturnValue(mockDb as any);
58
+
59
+ const validUri = "mongodb://127.0.0.1:27017/my-db";
54
60
  await mongodbClient.connect(validUri);
55
-
61
+
56
62
  expect(mongodbClient.getDb()).toBeDefined();
57
- expect(mongodbClient.getDb().databaseName).toBe('my-db');
58
-
63
+ expect(mongodbClient.getDb().databaseName).toBe("my-db");
64
+
59
65
  connectSpy.mockRestore();
60
66
  dbSpy.mockRestore();
61
67
  });