@ductape/sdk 0.0.4-v5 → 0.0.4-v51

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 (338) hide show
  1. package/README.md +1 -1
  2. package/dist/api/services/appApi.service.d.ts +48 -2
  3. package/dist/api/services/appApi.service.js +101 -2
  4. package/dist/api/services/appApi.service.js.map +1 -1
  5. package/dist/api/services/pricingApi.service.d.ts +10 -0
  6. package/dist/api/services/pricingApi.service.js +34 -0
  7. package/dist/api/services/pricingApi.service.js.map +1 -0
  8. package/dist/api/services/processorApi.service.d.ts +12 -2
  9. package/dist/api/services/processorApi.service.js +12 -2
  10. package/dist/api/services/processorApi.service.js.map +1 -1
  11. package/dist/api/services/productsApi.service.d.ts +40 -1
  12. package/dist/api/services/productsApi.service.js +105 -1
  13. package/dist/api/services/productsApi.service.js.map +1 -1
  14. package/dist/api/services/userApi.service.js +1 -0
  15. package/dist/api/services/userApi.service.js.map +1 -1
  16. package/dist/api/services/workspaceApi.service.js +1 -0
  17. package/dist/api/services/workspaceApi.service.js.map +1 -1
  18. package/dist/api/services/workspaceSecretsApi.service.d.ts +75 -0
  19. package/dist/api/services/workspaceSecretsApi.service.js +62 -0
  20. package/dist/api/services/workspaceSecretsApi.service.js.map +1 -0
  21. package/dist/api/urls.d.ts +6 -1
  22. package/dist/api/urls.js +12 -2
  23. package/dist/api/urls.js.map +1 -1
  24. package/dist/api/utils/cache.utils.d.ts +1 -1
  25. package/dist/api/utils/cache.utils.js +10 -4
  26. package/dist/api/utils/cache.utils.js.map +1 -1
  27. package/dist/api/utils/strings.utils.d.ts +2 -0
  28. package/dist/api/utils/strings.utils.js +14 -0
  29. package/dist/api/utils/strings.utils.js.map +1 -1
  30. package/dist/apps/services/app.service.d.ts +51 -33
  31. package/dist/apps/services/app.service.js +488 -244
  32. package/dist/apps/services/app.service.js.map +1 -1
  33. package/dist/apps/validators/joi-validators/create.appAction.validator.d.ts +1 -2
  34. package/dist/apps/validators/joi-validators/create.appAction.validator.js +21 -2
  35. package/dist/apps/validators/joi-validators/create.appAction.validator.js.map +1 -1
  36. package/dist/apps/validators/joi-validators/create.appWebhook.validator.d.ts +1 -2
  37. package/dist/apps/validators/joi-validators/create.appWebhook.validator.js +2 -15
  38. package/dist/apps/validators/joi-validators/create.appWebhook.validator.js.map +1 -1
  39. package/dist/apps/validators/joi-validators/update.appAction.validator.js +11 -1
  40. package/dist/apps/validators/joi-validators/update.appAction.validator.js.map +1 -1
  41. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.d.ts +1 -1
  42. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js +34 -1
  43. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js.map +1 -1
  44. package/dist/apps/validators/joi-validators/update.appWebhook.validator.d.ts +1 -2
  45. package/dist/apps/validators/joi-validators/update.appWebhook.validator.js +2 -14
  46. package/dist/apps/validators/joi-validators/update.appWebhook.validator.js.map +1 -1
  47. package/dist/clients/pricing.client.d.ts +3 -0
  48. package/dist/clients/pricing.client.js +33 -0
  49. package/dist/clients/pricing.client.js.map +1 -0
  50. package/dist/database/adapters/base.adapter.d.ts +176 -0
  51. package/dist/database/adapters/base.adapter.js +31 -0
  52. package/dist/database/adapters/base.adapter.js.map +1 -0
  53. package/dist/database/adapters/dynamodb.adapter.d.ts +91 -0
  54. package/dist/database/adapters/dynamodb.adapter.js +1608 -0
  55. package/dist/database/adapters/dynamodb.adapter.js.map +1 -0
  56. package/dist/database/adapters/mongodb.adapter.d.ts +71 -0
  57. package/dist/database/adapters/mongodb.adapter.js +1072 -0
  58. package/dist/database/adapters/mongodb.adapter.js.map +1 -0
  59. package/dist/database/adapters/mysql.adapter.d.ts +146 -0
  60. package/dist/database/adapters/mysql.adapter.js +1492 -0
  61. package/dist/database/adapters/mysql.adapter.js.map +1 -0
  62. package/dist/database/adapters/postgresql.adapter.d.ts +147 -0
  63. package/dist/database/adapters/postgresql.adapter.js +1603 -0
  64. package/dist/database/adapters/postgresql.adapter.js.map +1 -0
  65. package/dist/database/database.service.d.ts +232 -0
  66. package/dist/database/database.service.js +802 -0
  67. package/dist/database/database.service.js.map +1 -0
  68. package/dist/database/index.d.ts +18 -0
  69. package/dist/database/index.js +98 -0
  70. package/dist/database/index.js.map +1 -0
  71. package/dist/database/types/aggregation.types.d.ts +261 -0
  72. package/dist/database/types/aggregation.types.js +21 -0
  73. package/dist/database/types/aggregation.types.js.map +1 -0
  74. package/dist/database/types/connection.types.d.ts +132 -0
  75. package/dist/database/types/connection.types.js +6 -0
  76. package/dist/database/types/connection.types.js.map +1 -0
  77. package/dist/database/types/database.types.d.ts +175 -0
  78. package/dist/database/types/database.types.js +75 -0
  79. package/dist/database/types/database.types.js.map +1 -0
  80. package/dist/database/types/index.d.ts +12 -0
  81. package/dist/database/types/index.js +37 -0
  82. package/dist/database/types/index.js.map +1 -0
  83. package/dist/database/types/index.types.d.ts +220 -0
  84. package/dist/database/types/index.types.js +27 -0
  85. package/dist/database/types/index.types.js.map +1 -0
  86. package/dist/database/types/migration.types.d.ts +205 -0
  87. package/dist/database/types/migration.types.js +44 -0
  88. package/dist/database/types/migration.types.js.map +1 -0
  89. package/dist/database/types/query.types.d.ts +305 -0
  90. package/dist/database/types/query.types.js +57 -0
  91. package/dist/database/types/query.types.js.map +1 -0
  92. package/dist/database/types/result.types.d.ts +220 -0
  93. package/dist/database/types/result.types.js +6 -0
  94. package/dist/database/types/result.types.js.map +1 -0
  95. package/dist/database/types/schema.types.d.ts +190 -0
  96. package/dist/database/types/schema.types.js +69 -0
  97. package/dist/database/types/schema.types.js.map +1 -0
  98. package/dist/database/utils/helpers.d.ts +66 -0
  99. package/dist/database/utils/helpers.js +501 -0
  100. package/dist/database/utils/helpers.js.map +1 -0
  101. package/dist/database/utils/migration.utils.d.ts +151 -0
  102. package/dist/database/utils/migration.utils.js +476 -0
  103. package/dist/database/utils/migration.utils.js.map +1 -0
  104. package/dist/database/utils/transaction.d.ts +64 -0
  105. package/dist/database/utils/transaction.js +130 -0
  106. package/dist/database/utils/transaction.js.map +1 -0
  107. package/dist/database/validators/connection.validator.d.ts +20 -0
  108. package/dist/database/validators/connection.validator.js +267 -0
  109. package/dist/database/validators/connection.validator.js.map +1 -0
  110. package/dist/database/validators/query.validator.d.ts +31 -0
  111. package/dist/database/validators/query.validator.js +305 -0
  112. package/dist/database/validators/query.validator.js.map +1 -0
  113. package/dist/database/validators/schema.validator.d.ts +31 -0
  114. package/dist/database/validators/schema.validator.js +334 -0
  115. package/dist/database/validators/schema.validator.js.map +1 -0
  116. package/dist/graph/adapters/arangodb.adapter.d.ts +80 -0
  117. package/dist/graph/adapters/arangodb.adapter.js +1393 -0
  118. package/dist/graph/adapters/arangodb.adapter.js.map +1 -0
  119. package/dist/graph/adapters/base.adapter.d.ts +228 -0
  120. package/dist/graph/adapters/base.adapter.js +38 -0
  121. package/dist/graph/adapters/base.adapter.js.map +1 -0
  122. package/dist/graph/adapters/index.d.ts +10 -0
  123. package/dist/graph/adapters/index.js +23 -0
  124. package/dist/graph/adapters/index.js.map +1 -0
  125. package/dist/graph/adapters/memgraph.adapter.d.ts +85 -0
  126. package/dist/graph/adapters/memgraph.adapter.js +1491 -0
  127. package/dist/graph/adapters/memgraph.adapter.js.map +1 -0
  128. package/dist/graph/adapters/neo4j.adapter.d.ts +88 -0
  129. package/dist/graph/adapters/neo4j.adapter.js +1861 -0
  130. package/dist/graph/adapters/neo4j.adapter.js.map +1 -0
  131. package/dist/graph/adapters/neptune.adapter.d.ts +87 -0
  132. package/dist/graph/adapters/neptune.adapter.js +1430 -0
  133. package/dist/graph/adapters/neptune.adapter.js.map +1 -0
  134. package/dist/graph/graph.service.d.ts +278 -0
  135. package/dist/graph/graph.service.js +687 -0
  136. package/dist/graph/graph.service.js.map +1 -0
  137. package/dist/graph/index.d.ts +11 -0
  138. package/dist/graph/index.js +42 -0
  139. package/dist/graph/index.js.map +1 -0
  140. package/dist/graph/types/connection.types.d.ts +158 -0
  141. package/dist/graph/types/connection.types.js +43 -0
  142. package/dist/graph/types/connection.types.js.map +1 -0
  143. package/dist/graph/types/graph.types.d.ts +144 -0
  144. package/dist/graph/types/graph.types.js +84 -0
  145. package/dist/graph/types/graph.types.js.map +1 -0
  146. package/dist/graph/types/index.d.ts +11 -0
  147. package/dist/graph/types/index.js +35 -0
  148. package/dist/graph/types/index.js.map +1 -0
  149. package/dist/graph/types/node.types.d.ts +193 -0
  150. package/dist/graph/types/node.types.js +49 -0
  151. package/dist/graph/types/node.types.js.map +1 -0
  152. package/dist/graph/types/path.types.d.ts +224 -0
  153. package/dist/graph/types/path.types.js +38 -0
  154. package/dist/graph/types/path.types.js.map +1 -0
  155. package/dist/graph/types/query.types.d.ts +247 -0
  156. package/dist/graph/types/query.types.js +23 -0
  157. package/dist/graph/types/query.types.js.map +1 -0
  158. package/dist/graph/types/relationship.types.d.ts +224 -0
  159. package/dist/graph/types/relationship.types.js +35 -0
  160. package/dist/graph/types/relationship.types.js.map +1 -0
  161. package/dist/graph/types/result.types.d.ts +237 -0
  162. package/dist/graph/types/result.types.js +7 -0
  163. package/dist/graph/types/result.types.js.map +1 -0
  164. package/dist/graph/validators/index.d.ts +81 -0
  165. package/dist/graph/validators/index.js +243 -0
  166. package/dist/graph/validators/index.js.map +1 -0
  167. package/dist/imports/imports.service.d.ts +3 -3
  168. package/dist/imports/imports.service.js +7 -7
  169. package/dist/imports/imports.service.js.map +1 -1
  170. package/dist/imports/imports.types.d.ts +8 -0
  171. package/dist/imports/repos/postmanV21.repo.d.ts +1 -1
  172. package/dist/imports/repos/postmanV21.repo.js +29 -2
  173. package/dist/imports/repos/postmanV21.repo.js.map +1 -1
  174. package/dist/index.d.ts +1244 -150
  175. package/dist/index.js +1309 -209
  176. package/dist/index.js.map +1 -1
  177. package/dist/inputs/inputs.service.js +2 -2
  178. package/dist/inputs/inputs.service.js.map +1 -1
  179. package/dist/inputs/utils/inputs.utils.create.js +1 -1
  180. package/dist/inputs/utils/inputs.utils.create.js.map +1 -1
  181. package/dist/logs/logs.types.d.ts +5 -0
  182. package/dist/logs/logs.types.js +1 -0
  183. package/dist/logs/logs.types.js.map +1 -1
  184. package/dist/parsers/index.d.ts +3 -0
  185. package/dist/parsers/index.js +27 -0
  186. package/dist/parsers/index.js.map +1 -0
  187. package/dist/parsers/pipelines/postman.pipelines.d.ts +15 -0
  188. package/dist/parsers/pipelines/postman.pipelines.js +103 -0
  189. package/dist/parsers/pipelines/postman.pipelines.js.map +1 -0
  190. package/dist/parsers/types/postman.types.d.ts +200 -0
  191. package/dist/parsers/types/postman.types.js +3 -0
  192. package/dist/parsers/types/postman.types.js.map +1 -0
  193. package/dist/parsers/utils/postman.utils.d.ts +12 -0
  194. package/dist/parsers/utils/postman.utils.js +116 -0
  195. package/dist/parsers/utils/postman.utils.js.map +1 -0
  196. package/dist/parsers/validators/postman-auth.validators.d.ts +10 -0
  197. package/dist/parsers/validators/postman-auth.validators.js +127 -0
  198. package/dist/parsers/validators/postman-auth.validators.js.map +1 -0
  199. package/dist/parsers/validators/postman-request.validators.d.ts +13 -0
  200. package/dist/parsers/validators/postman-request.validators.js +139 -0
  201. package/dist/parsers/validators/postman-request.validators.js.map +1 -0
  202. package/dist/parsers/validators/postman-response.validators.d.ts +13 -0
  203. package/dist/parsers/validators/postman-response.validators.js +150 -0
  204. package/dist/parsers/validators/postman-response.validators.js.map +1 -0
  205. package/dist/parsers/validators/postman-variable.validators.d.ts +14 -0
  206. package/dist/parsers/validators/postman-variable.validators.js +163 -0
  207. package/dist/parsers/validators/postman-variable.validators.js.map +1 -0
  208. package/dist/pricing/pricing.repo.d.ts +0 -0
  209. package/dist/pricing/pricing.repo.js +1 -0
  210. package/dist/pricing/pricing.repo.js.map +1 -0
  211. package/dist/pricing/pricing.service.d.ts +24 -0
  212. package/dist/pricing/pricing.service.js +51 -0
  213. package/dist/pricing/pricing.service.js.map +1 -0
  214. package/dist/pricing/pricing.types.d.ts +76 -0
  215. package/dist/pricing/pricing.types.js +21 -0
  216. package/dist/pricing/pricing.types.js.map +1 -0
  217. package/dist/pricing/utils/string.utils.d.ts +1 -0
  218. package/dist/pricing/utils/string.utils.js +9 -0
  219. package/dist/pricing/utils/string.utils.js.map +1 -0
  220. package/dist/processor/repos/sms.repo.d.ts +4 -4
  221. package/dist/processor/repos/sms.repo.js +23 -10
  222. package/dist/processor/repos/sms.repo.js.map +1 -1
  223. package/dist/processor/services/messagebrokers/kafka.service.js +0 -2
  224. package/dist/processor/services/messagebrokers/kafka.service.js.map +1 -1
  225. package/dist/processor/services/messagebrokers/rabbitmq.service.d.ts +9 -1
  226. package/dist/processor/services/messagebrokers/rabbitmq.service.js +40 -11
  227. package/dist/processor/services/messagebrokers/rabbitmq.service.js.map +1 -1
  228. package/dist/processor/services/processor.service.d.ts +38 -10
  229. package/dist/processor/services/processor.service.js +533 -248
  230. package/dist/processor/services/processor.service.js.map +1 -1
  231. package/dist/processor/services/request.service.d.ts +36 -0
  232. package/dist/processor/services/request.service.js +304 -0
  233. package/dist/processor/services/request.service.js.map +1 -0
  234. package/dist/processor/types/request.types.d.ts +14 -0
  235. package/dist/processor/types/request.types.js +3 -0
  236. package/dist/processor/types/request.types.js.map +1 -0
  237. package/dist/processor/utils/processor.utils.d.ts +3 -0
  238. package/dist/processor/utils/processor.utils.js +84 -22
  239. package/dist/processor/utils/processor.utils.js.map +1 -1
  240. package/dist/processor/utils/request.utils.d.ts +20 -0
  241. package/dist/processor/utils/request.utils.js +113 -0
  242. package/dist/processor/utils/request.utils.js.map +1 -0
  243. package/dist/products/services/products.service.d.ts +114 -77
  244. package/dist/products/services/products.service.js +805 -362
  245. package/dist/products/services/products.service.js.map +1 -1
  246. package/dist/products/services/utils/crypt.utils.d.ts +1 -0
  247. package/dist/products/services/utils/crypt.utils.js +17 -0
  248. package/dist/products/services/utils/crypt.utils.js.map +1 -0
  249. package/dist/products/services/utils/functions.utils.d.ts +13 -0
  250. package/dist/products/services/utils/functions.utils.js +289 -0
  251. package/dist/products/services/utils/functions.utils.js.map +1 -0
  252. package/dist/products/services/utils/objects.utils.d.ts +13 -0
  253. package/dist/products/services/utils/objects.utils.js +89 -0
  254. package/dist/products/services/utils/objects.utils.js.map +1 -0
  255. package/dist/products/services/utils/string.utils.d.ts +12 -0
  256. package/dist/products/services/utils/string.utils.js +168 -0
  257. package/dist/products/services/utils/string.utils.js.map +1 -0
  258. package/dist/products/utils/string.utils.d.ts +1 -1
  259. package/dist/products/utils/string.utils.js +14 -2
  260. package/dist/products/utils/string.utils.js.map +1 -1
  261. package/dist/products/validators/index.d.ts +4 -1
  262. package/dist/products/validators/index.js +7 -1
  263. package/dist/products/validators/index.js.map +1 -1
  264. package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.d.ts +15 -4
  265. package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.js +501 -109
  266. package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.js.map +1 -1
  267. package/dist/products/validators/joi-validators/create.productEnv.validator.js +1 -0
  268. package/dist/products/validators/joi-validators/create.productEnv.validator.js.map +1 -1
  269. package/dist/products/validators/joi-validators/create.productGraph.validator.d.ts +3 -0
  270. package/dist/products/validators/joi-validators/create.productGraph.validator.js +82 -0
  271. package/dist/products/validators/joi-validators/create.productGraph.validator.js.map +1 -0
  272. package/dist/products/validators/joi-validators/create.productGraphAction.validator.d.ts +14 -0
  273. package/dist/products/validators/joi-validators/create.productGraphAction.validator.js +696 -0
  274. package/dist/products/validators/joi-validators/create.productGraphAction.validator.js.map +1 -0
  275. package/dist/products/validators/joi-validators/create.productHealthcheck.validator.d.ts +4 -0
  276. package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js +58 -0
  277. package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js.map +1 -0
  278. package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js +1 -0
  279. package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js.map +1 -1
  280. package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js +9 -4
  281. package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js.map +1 -1
  282. package/dist/products/validators/joi-validators/create.productNotification.validator.js +5 -2
  283. package/dist/products/validators/joi-validators/create.productNotification.validator.js.map +1 -1
  284. package/dist/products/validators/joi-validators/create.userAuth.validator.js +1 -0
  285. package/dist/products/validators/joi-validators/create.userAuth.validator.js.map +1 -1
  286. package/dist/products/validators/joi-validators/update.dataValue.validator.js +1 -0
  287. package/dist/products/validators/joi-validators/update.dataValue.validator.js.map +1 -1
  288. package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.d.ts +6 -0
  289. package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.js +28 -26
  290. package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.js.map +1 -1
  291. package/dist/products/validators/joi-validators/update.productEnv.validator.js +3 -0
  292. package/dist/products/validators/joi-validators/update.productEnv.validator.js.map +1 -1
  293. package/dist/products/validators/joi-validators/update.productGraph.validator.d.ts +3 -0
  294. package/dist/products/validators/joi-validators/update.productGraph.validator.js +87 -0
  295. package/dist/products/validators/joi-validators/update.productGraph.validator.js.map +1 -0
  296. package/dist/products/validators/joi-validators/update.productGraphAction.validator.d.ts +7 -0
  297. package/dist/products/validators/joi-validators/update.productGraphAction.validator.js +72 -0
  298. package/dist/products/validators/joi-validators/update.productGraphAction.validator.js.map +1 -0
  299. package/dist/products/validators/joi-validators/update.productMessageBrokerTopic.validator.js +1 -0
  300. package/dist/products/validators/joi-validators/update.productMessageBrokerTopic.validator.js.map +1 -1
  301. package/dist/products/validators/joi-validators/update.userAuth.validator.js +1 -0
  302. package/dist/products/validators/joi-validators/update.userAuth.validator.js.map +1 -1
  303. package/dist/test/test.health.d.ts +1 -0
  304. package/dist/test/test.health.js +49 -0
  305. package/dist/test/test.health.js.map +1 -0
  306. package/dist/test/test.import.js +51 -4
  307. package/dist/test/test.import.js.map +1 -1
  308. package/dist/test/test.imports.js +22 -7
  309. package/dist/test/test.imports.js.map +1 -1
  310. package/dist/test/test.notifiers.d.ts +1 -0
  311. package/dist/test/test.notifiers.js +85 -0
  312. package/dist/test/test.notifiers.js.map +1 -0
  313. package/dist/test/test.processor.js +30 -115
  314. package/dist/test/test.processor.js.map +1 -1
  315. package/dist/test/test.products.d.ts +1 -0
  316. package/dist/test/test.products.js +49 -0
  317. package/dist/test/test.products.js.map +1 -0
  318. package/dist/tsconfig.tsbuildinfo +1 -0
  319. package/dist/types/appBuilder.types.d.ts +5 -12
  320. package/dist/types/enums.d.ts +4 -1
  321. package/dist/types/enums.js +3 -0
  322. package/dist/types/enums.js.map +1 -1
  323. package/dist/types/index.types.d.ts +4 -0
  324. package/dist/types/pricing.types.d.ts +4 -0
  325. package/dist/types/pricing.types.js +3 -0
  326. package/dist/types/pricing.types.js.map +1 -0
  327. package/dist/types/processor.types.d.ts +67 -11
  328. package/dist/types/processor.types.js.map +1 -1
  329. package/dist/types/productsBuilder.types.d.ts +132 -14
  330. package/dist/types/productsBuilder.types.js +69 -4
  331. package/dist/types/productsBuilder.types.js.map +1 -1
  332. package/dist/types/request-tracker.interface.d.ts +0 -0
  333. package/dist/types/request-tracker.interface.js +1 -0
  334. package/dist/types/request-tracker.interface.js.map +1 -0
  335. package/dist/utils/constants.d.ts +1 -0
  336. package/dist/utils/constants.js +5 -0
  337. package/dist/utils/constants.js.map +1 -0
  338. package/package.json +17 -3
@@ -0,0 +1,1072 @@
1
+ "use strict";
2
+ /**
3
+ * MongoDB Database Adapter
4
+ * Implements database operations for MongoDB
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ var __rest = (this && this.__rest) || function (s, e) {
40
+ var t = {};
41
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
42
+ t[p] = s[p];
43
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
44
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
45
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
46
+ t[p[i]] = s[p[i]];
47
+ }
48
+ return t;
49
+ };
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ exports.MongoDBAdapter = void 0;
52
+ const base_adapter_1 = require("./base.adapter");
53
+ const database_types_1 = require("../types/database.types");
54
+ const uuid_1 = require("uuid");
55
+ const query_types_1 = require("../types/query.types");
56
+ /**
57
+ * MongoDB Connection wrapper
58
+ */
59
+ class MongoDBConnection {
60
+ constructor(id, client, db) {
61
+ this.id = id;
62
+ this.type = database_types_1.DatabaseType.MONGODB;
63
+ this.status = database_types_1.ConnectionStatus.CONNECTED;
64
+ this.client = client;
65
+ this.db = db;
66
+ }
67
+ async connect() {
68
+ var _a;
69
+ if (this.client && !((_a = this.client.topology) === null || _a === void 0 ? void 0 : _a.isConnected())) {
70
+ await this.client.connect();
71
+ this.status = database_types_1.ConnectionStatus.CONNECTED;
72
+ }
73
+ }
74
+ async disconnect() {
75
+ if (this.client) {
76
+ await this.client.close();
77
+ this.status = database_types_1.ConnectionStatus.DISCONNECTED;
78
+ }
79
+ }
80
+ isConnected() {
81
+ var _a, _b;
82
+ return this.status === database_types_1.ConnectionStatus.CONNECTED && ((_b = (_a = this.client) === null || _a === void 0 ? void 0 : _a.topology) === null || _b === void 0 ? void 0 : _b.isConnected());
83
+ }
84
+ getClient() {
85
+ return this.db;
86
+ }
87
+ getMongoClient() {
88
+ return this.client;
89
+ }
90
+ }
91
+ /**
92
+ * MongoDB Transaction implementation
93
+ * Note: MongoDB uses sessions for transactions and does NOT support savepoints
94
+ */
95
+ class MongoDBTransaction {
96
+ constructor(connection, session, options) {
97
+ this.id = (0, uuid_1.v4)();
98
+ this.connection = connection;
99
+ this.status = database_types_1.TransactionStatus.ACTIVE;
100
+ this.isolationLevel = options === null || options === void 0 ? void 0 : options.isolationLevel;
101
+ this.createdAt = new Date();
102
+ this.session = session;
103
+ this.native = session;
104
+ }
105
+ async commit() {
106
+ if (this.status !== database_types_1.TransactionStatus.ACTIVE) {
107
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.TRANSACTION_ERROR, `Cannot commit transaction: status is ${this.status}`);
108
+ }
109
+ await this.session.commitTransaction();
110
+ await this.session.endSession();
111
+ this.status = database_types_1.TransactionStatus.COMMITTED;
112
+ }
113
+ async rollback() {
114
+ if (this.status !== database_types_1.TransactionStatus.ACTIVE) {
115
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.TRANSACTION_ERROR, `Cannot rollback transaction: status is ${this.status}`);
116
+ }
117
+ await this.session.abortTransaction();
118
+ await this.session.endSession();
119
+ this.status = database_types_1.TransactionStatus.ROLLED_BACK;
120
+ }
121
+ async savepoint(_name) {
122
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.NOT_SUPPORTED, 'MongoDB does not support savepoints. Transactions are atomic - either all changes commit or all rollback.');
123
+ }
124
+ isActive() {
125
+ return this.status === database_types_1.TransactionStatus.ACTIVE;
126
+ }
127
+ getSession() {
128
+ return this.session;
129
+ }
130
+ }
131
+ /**
132
+ * MongoDB Adapter
133
+ */
134
+ class MongoDBAdapter extends base_adapter_1.BaseDatabaseAdapter {
135
+ constructor() {
136
+ super(...arguments);
137
+ this.type = database_types_1.DatabaseType.MONGODB;
138
+ this.connectionPool = new Map();
139
+ }
140
+ // ==================== Connection Methods ====================
141
+ async connect(config) {
142
+ try {
143
+ // Dynamic import of mongodb library
144
+ // @ts-ignore - mongodb is an optional peer dependency
145
+ const { MongoClient } = await Promise.resolve().then(() => __importStar(require('mongodb')));
146
+ const options = config.options || {};
147
+ // Build connection URI
148
+ let uri;
149
+ if (options.connectionString || options.uri) {
150
+ uri = options.connectionString || options.uri;
151
+ }
152
+ else {
153
+ const host = options.host || 'localhost';
154
+ const port = options.port || 27017;
155
+ const username = options.username || options.user;
156
+ const password = options.password;
157
+ const authSource = options.authSource || 'admin';
158
+ if (username && password) {
159
+ uri = `mongodb://${encodeURIComponent(username)}:${encodeURIComponent(password)}@${host}:${port}/${config.database}?authSource=${authSource}`;
160
+ }
161
+ else {
162
+ uri = `mongodb://${host}:${port}/${config.database}`;
163
+ }
164
+ }
165
+ // Create MongoDB client with options
166
+ const clientOptions = {
167
+ maxPoolSize: options.poolSize || 10,
168
+ minPoolSize: options.minPoolSize || 2,
169
+ connectTimeoutMS: options.connectionTimeout || 10000,
170
+ socketTimeoutMS: options.idleTimeout || 30000,
171
+ retryWrites: options.retryWrites !== false,
172
+ retryReads: options.retryReads !== false,
173
+ };
174
+ // Add SSL/TLS options if specified
175
+ if (options.ssl || options.tls) {
176
+ clientOptions.tls = true;
177
+ if (options.tlsCAFile)
178
+ clientOptions.tlsCAFile = options.tlsCAFile;
179
+ if (options.tlsCertificateKeyFile)
180
+ clientOptions.tlsCertificateKeyFile = options.tlsCertificateKeyFile;
181
+ clientOptions.tlsAllowInvalidCertificates = options.tlsAllowInvalidCertificates || false;
182
+ }
183
+ // Add replica set options if specified
184
+ if (options.replicaSet) {
185
+ clientOptions.replicaSet = options.replicaSet;
186
+ }
187
+ const client = new MongoClient(uri, clientOptions);
188
+ // Connect to MongoDB
189
+ await client.connect();
190
+ // Test connection
191
+ await client.db(config.database).command({ ping: 1 });
192
+ // Get database
193
+ const db = client.db(config.database);
194
+ // Create connection wrapper
195
+ const connectionId = `mongodb-${config.database}-${Date.now()}`;
196
+ const connection = new MongoDBConnection(connectionId, client, db);
197
+ // Store in pool map
198
+ this.connectionPool.set(connectionId, connection);
199
+ return connection;
200
+ }
201
+ catch (error) {
202
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.CONNECTION_ERROR, `Failed to connect to MongoDB: ${error.message}`, error);
203
+ }
204
+ }
205
+ async disconnect(connection) {
206
+ await connection.disconnect();
207
+ this.connectionPool.delete(connection.id);
208
+ }
209
+ async testConnection(connection) {
210
+ const startTime = Date.now();
211
+ try {
212
+ const db = connection.getClient();
213
+ // Test with a simple ping command
214
+ await db.admin().ping();
215
+ const responseTime = Date.now() - startTime;
216
+ return {
217
+ connected: true,
218
+ message: 'Successfully connected to MongoDB',
219
+ databaseType: 'mongodb',
220
+ responseTime,
221
+ };
222
+ }
223
+ catch (error) {
224
+ return {
225
+ connected: false,
226
+ message: 'Failed to connect to MongoDB',
227
+ databaseType: 'mongodb',
228
+ responseTime: Date.now() - startTime,
229
+ error: error.message,
230
+ };
231
+ }
232
+ }
233
+ // ==================== Transaction Methods ====================
234
+ async beginTransaction(connection, options) {
235
+ try {
236
+ // MongoDB needs to access the MongoClient for sessions, not just the db
237
+ const mongoConnection = connection;
238
+ const client = mongoConnection.getMongoClient();
239
+ const session = client.startSession();
240
+ // Build transaction options
241
+ const txnOptions = {
242
+ writeConcern: { w: 'majority' },
243
+ };
244
+ // Map isolation level to MongoDB read concern
245
+ if (options === null || options === void 0 ? void 0 : options.isolationLevel) {
246
+ switch (options.isolationLevel) {
247
+ case database_types_1.TransactionIsolationLevel.READ_UNCOMMITTED:
248
+ case database_types_1.TransactionIsolationLevel.READ_COMMITTED:
249
+ txnOptions.readConcern = { level: 'local' };
250
+ break;
251
+ case database_types_1.TransactionIsolationLevel.REPEATABLE_READ:
252
+ txnOptions.readConcern = { level: 'snapshot' };
253
+ break;
254
+ case database_types_1.TransactionIsolationLevel.SERIALIZABLE:
255
+ txnOptions.readConcern = { level: 'linearizable' };
256
+ break;
257
+ default:
258
+ txnOptions.readConcern = { level: 'snapshot' };
259
+ }
260
+ }
261
+ else {
262
+ txnOptions.readConcern = { level: 'snapshot' };
263
+ }
264
+ session.startTransaction(txnOptions);
265
+ return new MongoDBTransaction(connection, session, options);
266
+ }
267
+ catch (error) {
268
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.TRANSACTION_ERROR, `Failed to begin MongoDB transaction: ${error.message}. Note: MongoDB transactions require a replica set or sharded cluster.`, error);
269
+ }
270
+ }
271
+ async commitTransaction(connection, transaction) {
272
+ await transaction.commit();
273
+ }
274
+ async rollbackTransaction(connection, transaction) {
275
+ await transaction.rollback();
276
+ }
277
+ async createSavepoint(_connection, _transaction, _savepointName) {
278
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.NOT_SUPPORTED, 'MongoDB does not support savepoints. Transactions are atomic - either all changes commit or all rollback.');
279
+ }
280
+ async rollbackToSavepoint(_connection, _transaction, _savepoint) {
281
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.NOT_SUPPORTED, 'MongoDB does not support savepoints.');
282
+ }
283
+ async releaseSavepoint(_connection, _transaction, _savepoint) {
284
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.NOT_SUPPORTED, 'MongoDB does not support savepoints.');
285
+ }
286
+ // ==================== Query Methods ====================
287
+ async query(connection, options) {
288
+ const startTime = Date.now();
289
+ try {
290
+ const db = connection.getClient();
291
+ const collection = db.collection(options.table);
292
+ // Build MongoDB filter from where clause
293
+ const filter = this.buildMongoFilter(options.where);
294
+ // Build MongoDB query
295
+ let query = collection.find(filter);
296
+ // Apply projection (select)
297
+ if (options.select && options.select.length > 0) {
298
+ const projection = {};
299
+ options.select.forEach((field) => {
300
+ projection[field] = 1;
301
+ });
302
+ query = query.project(projection);
303
+ }
304
+ // Apply sorting
305
+ if (options.orderBy) {
306
+ const sort = {};
307
+ const orderByArray = Array.isArray(options.orderBy) ? options.orderBy : [options.orderBy];
308
+ orderByArray.forEach((order) => {
309
+ sort[order.column] = order.order === query_types_1.SortOrder.DESC ? -1 : 1;
310
+ });
311
+ query = query.sort(sort);
312
+ }
313
+ // Apply limit and offset
314
+ if (options.limit) {
315
+ query = query.limit(options.limit);
316
+ }
317
+ if (options.offset) {
318
+ query = query.skip(options.offset);
319
+ }
320
+ const data = await query.toArray();
321
+ const executionTime = Date.now() - startTime;
322
+ return {
323
+ data,
324
+ count: data.length,
325
+ executionTime,
326
+ databaseType: 'mongodb',
327
+ };
328
+ }
329
+ catch (error) {
330
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.QUERY_ERROR, `MongoDB query failed: ${error.message}`, error);
331
+ }
332
+ }
333
+ async insert(connection, options) {
334
+ const startTime = Date.now();
335
+ try {
336
+ const db = connection.getClient();
337
+ const collection = db.collection(options.table);
338
+ const dataArray = Array.isArray(options.data) ? options.data : [options.data];
339
+ const result = await collection.insertMany(dataArray);
340
+ const executionTime = Date.now() - startTime;
341
+ return {
342
+ insertedCount: result.insertedCount,
343
+ insertedIds: Object.values(result.insertedIds).map((id) => id.toString()),
344
+ data: options.returning ? dataArray : undefined,
345
+ executionTime,
346
+ success: true,
347
+ };
348
+ }
349
+ catch (error) {
350
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.QUERY_ERROR, `MongoDB insert failed: ${error.message}`, error);
351
+ }
352
+ }
353
+ async update(connection, options) {
354
+ const startTime = Date.now();
355
+ try {
356
+ const db = connection.getClient();
357
+ const collection = db.collection(options.table);
358
+ const filter = this.buildMongoFilter(options.where);
359
+ const update = { $set: options.data };
360
+ const result = await collection.updateMany(filter, update);
361
+ const executionTime = Date.now() - startTime;
362
+ return {
363
+ updatedCount: result.modifiedCount,
364
+ matchedCount: result.matchedCount,
365
+ executionTime,
366
+ success: true,
367
+ };
368
+ }
369
+ catch (error) {
370
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.QUERY_ERROR, `MongoDB update failed: ${error.message}`, error);
371
+ }
372
+ }
373
+ async delete(connection, options) {
374
+ const startTime = Date.now();
375
+ try {
376
+ const db = connection.getClient();
377
+ const collection = db.collection(options.table);
378
+ const filter = this.buildMongoFilter(options.where);
379
+ const result = await collection.deleteMany(filter);
380
+ const executionTime = Date.now() - startTime;
381
+ return {
382
+ deletedCount: result.deletedCount,
383
+ executionTime,
384
+ success: true,
385
+ };
386
+ }
387
+ catch (error) {
388
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.QUERY_ERROR, `MongoDB delete failed: ${error.message}`, error);
389
+ }
390
+ }
391
+ async upsert(connection, options) {
392
+ const startTime = Date.now();
393
+ try {
394
+ const db = connection.getClient();
395
+ const collection = db.collection(options.table);
396
+ // Upsert only works with single records
397
+ const data = Array.isArray(options.data) ? options.data[0] : options.data;
398
+ // Build conflict filter
399
+ const filter = {};
400
+ options.uniqueColumns.forEach((col) => {
401
+ if (data[col] !== undefined) {
402
+ filter[col] = data[col];
403
+ }
404
+ });
405
+ const update = { $set: data };
406
+ const result = await collection.updateOne(filter, update, { upsert: true });
407
+ const executionTime = Date.now() - startTime;
408
+ return {
409
+ insertedCount: result.upsertedCount || 0,
410
+ updatedCount: result.modifiedCount,
411
+ affectedCount: result.upsertedCount + result.modifiedCount,
412
+ executionTime,
413
+ success: true,
414
+ };
415
+ }
416
+ catch (error) {
417
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.QUERY_ERROR, `MongoDB upsert failed: ${error.message}`, error);
418
+ }
419
+ }
420
+ async executeRaw(connection, options) {
421
+ const startTime = Date.now();
422
+ try {
423
+ const db = connection.getClient();
424
+ // For MongoDB, raw queries might be aggregation pipelines or commands
425
+ // This is a simplified implementation
426
+ const result = await db.command(options.query);
427
+ const executionTime = Date.now() - startTime;
428
+ return {
429
+ rows: Array.isArray(result) ? result : [result],
430
+ rowCount: Array.isArray(result) ? result.length : 1,
431
+ executionTime,
432
+ };
433
+ }
434
+ catch (error) {
435
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.QUERY_ERROR, `MongoDB raw query failed: ${error.message}`, error);
436
+ }
437
+ }
438
+ // ==================== Aggregation Methods ====================
439
+ async count(connection, options) {
440
+ try {
441
+ const db = connection.getClient();
442
+ const collection = db.collection(options.table);
443
+ const filter = this.buildMongoFilter(options.where);
444
+ return await collection.countDocuments(filter);
445
+ }
446
+ catch (error) {
447
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.QUERY_ERROR, `MongoDB count failed: ${error.message}`, error);
448
+ }
449
+ }
450
+ async sum(connection, options) {
451
+ var _a;
452
+ try {
453
+ const db = connection.getClient();
454
+ const collection = db.collection(options.table);
455
+ const matchStage = this.buildMongoFilter(options.where);
456
+ const pipeline = [
457
+ { $match: matchStage },
458
+ {
459
+ $group: {
460
+ _id: null,
461
+ total: { $sum: `$${options.column}` },
462
+ },
463
+ },
464
+ ];
465
+ const result = await collection.aggregate(pipeline).toArray();
466
+ return ((_a = result[0]) === null || _a === void 0 ? void 0 : _a.total) || 0;
467
+ }
468
+ catch (error) {
469
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.QUERY_ERROR, `MongoDB sum failed: ${error.message}`, error);
470
+ }
471
+ }
472
+ async avg(connection, options) {
473
+ var _a;
474
+ try {
475
+ const db = connection.getClient();
476
+ const collection = db.collection(options.table);
477
+ const matchStage = this.buildMongoFilter(options.where);
478
+ const pipeline = [
479
+ { $match: matchStage },
480
+ {
481
+ $group: {
482
+ _id: null,
483
+ average: { $avg: `$${options.column}` },
484
+ },
485
+ },
486
+ ];
487
+ const result = await collection.aggregate(pipeline).toArray();
488
+ return ((_a = result[0]) === null || _a === void 0 ? void 0 : _a.average) || 0;
489
+ }
490
+ catch (error) {
491
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.QUERY_ERROR, `MongoDB avg failed: ${error.message}`, error);
492
+ }
493
+ }
494
+ async min(connection, options) {
495
+ var _a;
496
+ try {
497
+ const db = connection.getClient();
498
+ const collection = db.collection(options.table);
499
+ const matchStage = this.buildMongoFilter(options.where);
500
+ const pipeline = [
501
+ { $match: matchStage },
502
+ {
503
+ $group: {
504
+ _id: null,
505
+ minimum: { $min: `$${options.column}` },
506
+ },
507
+ },
508
+ ];
509
+ const result = await collection.aggregate(pipeline).toArray();
510
+ return ((_a = result[0]) === null || _a === void 0 ? void 0 : _a.minimum) || 0;
511
+ }
512
+ catch (error) {
513
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.QUERY_ERROR, `MongoDB min failed: ${error.message}`, error);
514
+ }
515
+ }
516
+ async max(connection, options) {
517
+ var _a;
518
+ try {
519
+ const db = connection.getClient();
520
+ const collection = db.collection(options.table);
521
+ const matchStage = this.buildMongoFilter(options.where);
522
+ const pipeline = [
523
+ { $match: matchStage },
524
+ {
525
+ $group: {
526
+ _id: null,
527
+ maximum: { $max: `$${options.column}` },
528
+ },
529
+ },
530
+ ];
531
+ const result = await collection.aggregate(pipeline).toArray();
532
+ return ((_a = result[0]) === null || _a === void 0 ? void 0 : _a.maximum) || 0;
533
+ }
534
+ catch (error) {
535
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.QUERY_ERROR, `MongoDB max failed: ${error.message}`, error);
536
+ }
537
+ }
538
+ async groupBy(connection, options) {
539
+ try {
540
+ const db = connection.getClient();
541
+ const collection = db.collection(options.table);
542
+ const matchStage = this.buildMongoFilter(options.where);
543
+ // Build group ID from columns
544
+ const groupId = {};
545
+ options.groupBy.forEach((col) => {
546
+ groupId[col] = `$${col}`;
547
+ });
548
+ // Build aggregations
549
+ const aggregations = {};
550
+ if (options.aggregate) {
551
+ Object.entries(options.aggregate).forEach(([alias, agg]) => {
552
+ const aggObj = agg;
553
+ if (aggObj.$COUNT !== undefined) {
554
+ aggregations[alias] = { $sum: 1 };
555
+ }
556
+ else if (aggObj.$SUM !== undefined) {
557
+ aggregations[alias] = { $sum: `$${aggObj.$SUM}` };
558
+ }
559
+ else if (aggObj.$AVG !== undefined) {
560
+ aggregations[alias] = { $avg: `$${aggObj.$AVG}` };
561
+ }
562
+ else if (aggObj.$MIN !== undefined) {
563
+ aggregations[alias] = { $min: `$${aggObj.$MIN}` };
564
+ }
565
+ else if (aggObj.$MAX !== undefined) {
566
+ aggregations[alias] = { $max: `$${aggObj.$MAX}` };
567
+ }
568
+ else if (aggObj.$ARRAY_AGG !== undefined) {
569
+ aggregations[alias] = { $push: `$${aggObj.$ARRAY_AGG}` };
570
+ }
571
+ });
572
+ }
573
+ const pipeline = [
574
+ { $match: matchStage },
575
+ {
576
+ $group: Object.assign({ _id: groupId }, aggregations),
577
+ },
578
+ ];
579
+ // Add having clause (filter after grouping)
580
+ if (options.having) {
581
+ pipeline.push({ $match: this.buildMongoFilter(options.having) });
582
+ }
583
+ // Add sorting
584
+ if (options.orderBy) {
585
+ const sortSpec = {};
586
+ const orderByArray = Array.isArray(options.orderBy) ? options.orderBy : [options.orderBy];
587
+ orderByArray.forEach((order) => {
588
+ sortSpec[order.column] = order.order.toLowerCase() === query_types_1.SortOrder.DESC ? -1 : 1;
589
+ });
590
+ pipeline.push({ $sort: sortSpec });
591
+ }
592
+ // Add limit and offset
593
+ if (options.offset) {
594
+ pipeline.push({ $skip: options.offset });
595
+ }
596
+ if (options.limit) {
597
+ pipeline.push({ $limit: options.limit });
598
+ }
599
+ const result = await collection.aggregate(pipeline).toArray();
600
+ // Transform result to expected format
601
+ return result.map((doc) => {
602
+ const { _id } = doc, rest = __rest(doc, ["_id"]);
603
+ return Object.assign(Object.assign({}, _id), rest);
604
+ });
605
+ }
606
+ catch (error) {
607
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.QUERY_ERROR, `MongoDB groupBy failed: ${error.message}`, error);
608
+ }
609
+ }
610
+ async aggregate(connection, options) {
611
+ try {
612
+ const db = connection.getClient();
613
+ const collection = db.collection(options.table);
614
+ const matchStage = this.buildMongoFilter(options.where);
615
+ // Build aggregations
616
+ const aggregations = {};
617
+ Object.entries(options.operations).forEach(([alias, agg]) => {
618
+ const aggObj = agg;
619
+ if (aggObj.$COUNT !== undefined) {
620
+ aggregations[alias] = { $sum: 1 };
621
+ }
622
+ else if (aggObj.$SUM !== undefined) {
623
+ aggregations[alias] = { $sum: `$${aggObj.$SUM}` };
624
+ }
625
+ else if (aggObj.$AVG !== undefined) {
626
+ aggregations[alias] = { $avg: `$${aggObj.$AVG}` };
627
+ }
628
+ else if (aggObj.$MIN !== undefined) {
629
+ aggregations[alias] = { $min: `$${aggObj.$MIN}` };
630
+ }
631
+ else if (aggObj.$MAX !== undefined) {
632
+ aggregations[alias] = { $max: `$${aggObj.$MAX}` };
633
+ }
634
+ else if (aggObj.$ARRAY_AGG !== undefined) {
635
+ aggregations[alias] = { $push: `$${aggObj.$ARRAY_AGG}` };
636
+ }
637
+ });
638
+ // Build group stage
639
+ let groupId = null;
640
+ if (options.groupBy && options.groupBy.length > 0) {
641
+ groupId = {};
642
+ options.groupBy.forEach((col) => {
643
+ groupId[col] = `$${col}`;
644
+ });
645
+ }
646
+ const pipeline = [
647
+ { $match: matchStage },
648
+ {
649
+ $group: Object.assign({ _id: groupId }, aggregations),
650
+ },
651
+ ];
652
+ // Add having clause (filter after grouping)
653
+ if (options.having) {
654
+ pipeline.push({ $match: this.buildMongoFilter(options.having) });
655
+ }
656
+ const result = await collection.aggregate(pipeline).toArray();
657
+ if (groupId) {
658
+ // Return all grouped results
659
+ return result.map((doc) => {
660
+ const { _id } = doc, rest = __rest(doc, ["_id"]);
661
+ return Object.assign(Object.assign({}, _id), rest);
662
+ });
663
+ }
664
+ else {
665
+ // Return single aggregate result
666
+ const _a = result[0] || {}, { _id } = _a, aggregateResult = __rest(_a, ["_id"]);
667
+ return aggregateResult;
668
+ }
669
+ }
670
+ catch (error) {
671
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.QUERY_ERROR, `MongoDB aggregate failed: ${error.message}`, error);
672
+ }
673
+ }
674
+ // ==================== Schema Methods ====================
675
+ async createTable(connection, schema, options) {
676
+ const startTime = Date.now();
677
+ try {
678
+ const db = connection.getClient();
679
+ // MongoDB creates collections automatically, but we can create it explicitly
680
+ await db.createCollection(schema.name);
681
+ // Create indexes if specified
682
+ if (schema.indexes && schema.indexes.length > 0) {
683
+ const collection = db.collection(schema.name);
684
+ for (const index of schema.indexes) {
685
+ const indexSpec = {};
686
+ index.columns.forEach((col) => {
687
+ indexSpec[col.name] = col.order === 'DESC' ? -1 : 1;
688
+ });
689
+ await collection.createIndex(indexSpec, { unique: index.unique });
690
+ }
691
+ }
692
+ const executionTime = Date.now() - startTime;
693
+ return {
694
+ success: true,
695
+ operation: 'create',
696
+ table: schema.name,
697
+ executionTime,
698
+ };
699
+ }
700
+ catch (error) {
701
+ return {
702
+ success: false,
703
+ operation: 'create',
704
+ table: schema.name,
705
+ error: error.message,
706
+ executionTime: Date.now() - startTime,
707
+ };
708
+ }
709
+ }
710
+ async dropTable(connection, tableName) {
711
+ const startTime = Date.now();
712
+ try {
713
+ const db = connection.getClient();
714
+ await db.dropCollection(tableName);
715
+ return {
716
+ success: true,
717
+ operation: 'drop',
718
+ table: tableName,
719
+ executionTime: Date.now() - startTime,
720
+ };
721
+ }
722
+ catch (error) {
723
+ return {
724
+ success: false,
725
+ operation: 'drop',
726
+ table: tableName,
727
+ error: error.message,
728
+ executionTime: Date.now() - startTime,
729
+ };
730
+ }
731
+ }
732
+ async alterTable(connection, tableName, alterations, options) {
733
+ // MongoDB doesn't have a schema alteration concept like SQL databases
734
+ // Schema changes happen implicitly when documents are inserted
735
+ return {
736
+ success: true,
737
+ operation: 'alter',
738
+ table: tableName,
739
+ executionTime: 0,
740
+ };
741
+ }
742
+ async getTableSchema(connection, tableName) {
743
+ try {
744
+ const db = connection.getClient();
745
+ const collection = db.collection(tableName);
746
+ // Get a sample document to infer schema
747
+ const sampleDoc = await collection.findOne({});
748
+ // TODO: Infer column definitions from sample document
749
+ // This is a simplified implementation
750
+ const columns = sampleDoc
751
+ ? Object.keys(sampleDoc).map((key) => ({
752
+ name: key,
753
+ type: typeof sampleDoc[key],
754
+ }))
755
+ : [];
756
+ return {
757
+ name: tableName,
758
+ columns,
759
+ };
760
+ }
761
+ catch (error) {
762
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.SCHEMA_ERROR, `Failed to get MongoDB collection schema: ${error.message}`, error);
763
+ }
764
+ }
765
+ async listTables(connection) {
766
+ try {
767
+ const db = connection.getClient();
768
+ const collections = await db.listCollections().toArray();
769
+ return collections.map((col) => col.name);
770
+ }
771
+ catch (error) {
772
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.QUERY_ERROR, `Failed to list MongoDB collections: ${error.message}`, error);
773
+ }
774
+ }
775
+ async tableExists(connection, tableName) {
776
+ try {
777
+ const tables = await this.listTables(connection);
778
+ return tables.includes(tableName);
779
+ }
780
+ catch (error) {
781
+ return false;
782
+ }
783
+ }
784
+ // ==================== Index Methods ====================
785
+ async createIndex(connection, options) {
786
+ const startTime = Date.now();
787
+ try {
788
+ const db = connection.getClient();
789
+ const collection = db.collection(options.table);
790
+ const indexSpec = {};
791
+ options.index.columns.forEach((col) => {
792
+ indexSpec[col.name] = col.order === 'DESC' ? -1 : 1;
793
+ });
794
+ await collection.createIndex(indexSpec, {
795
+ name: options.index.name,
796
+ unique: options.index.unique,
797
+ });
798
+ return {
799
+ success: true,
800
+ operation: 'create',
801
+ indexName: options.index.name,
802
+ table: options.table,
803
+ executionTime: Date.now() - startTime,
804
+ };
805
+ }
806
+ catch (error) {
807
+ return {
808
+ success: false,
809
+ operation: 'create',
810
+ indexName: options.index.name,
811
+ table: options.table,
812
+ error: error.message,
813
+ executionTime: Date.now() - startTime,
814
+ };
815
+ }
816
+ }
817
+ async dropIndex(connection, options) {
818
+ const startTime = Date.now();
819
+ try {
820
+ const db = connection.getClient();
821
+ const collection = db.collection(options.table);
822
+ await collection.dropIndex(options.indexName);
823
+ return {
824
+ success: true,
825
+ operation: 'drop',
826
+ indexName: options.indexName,
827
+ table: options.table,
828
+ executionTime: Date.now() - startTime,
829
+ };
830
+ }
831
+ catch (error) {
832
+ return {
833
+ success: false,
834
+ operation: 'drop',
835
+ indexName: options.indexName,
836
+ table: options.table,
837
+ error: error.message,
838
+ executionTime: Date.now() - startTime,
839
+ };
840
+ }
841
+ }
842
+ async listIndexes(connection, options) {
843
+ try {
844
+ const db = connection.getClient();
845
+ const collection = db.collection(options.table);
846
+ const indexes = await collection.listIndexes().toArray();
847
+ return indexes.map((index) => ({
848
+ name: index.name,
849
+ table: options.table,
850
+ columns: Object.keys(index.key),
851
+ unique: index.unique || false,
852
+ type: index.type || 'BTREE',
853
+ }));
854
+ }
855
+ catch (error) {
856
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.INDEX_ERROR, `Failed to list MongoDB indexes: ${error.message}`, error);
857
+ }
858
+ }
859
+ async getIndexStatistics(connection, tableName, indexName) {
860
+ try {
861
+ const db = connection.getClient();
862
+ const collection = db.collection(tableName);
863
+ const stats = await collection.stats();
864
+ // TODO: Parse and return index statistics
865
+ // This is a simplified implementation
866
+ return [];
867
+ }
868
+ catch (error) {
869
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.INDEX_ERROR, `Failed to get MongoDB index statistics: ${error.message}`, error);
870
+ }
871
+ }
872
+ // ==================== Migration Methods ====================
873
+ async runMigration(connection, migration, options) {
874
+ // TODO: Implement migration logic
875
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.MIGRATION_ERROR, 'MongoDB migration not implemented yet');
876
+ }
877
+ async rollbackMigration(connection, migration, options) {
878
+ // TODO: Implement rollback logic
879
+ throw new database_types_1.DatabaseError(database_types_1.DatabaseErrorType.MIGRATION_ERROR, 'MongoDB migration rollback not implemented yet');
880
+ }
881
+ async getMigrationHistory(connection, options) {
882
+ // TODO: Implement migration history
883
+ return [];
884
+ }
885
+ // ==================== Helper Methods ====================
886
+ /**
887
+ * Build MongoDB filter from where clause
888
+ * Supports both simplified syntax (GT, LT, AND, OR, etc.) and legacy $ prefix operators
889
+ */
890
+ buildMongoFilter(where) {
891
+ if (!where) {
892
+ return {};
893
+ }
894
+ if (typeof where !== 'object' || where === null) {
895
+ return where;
896
+ }
897
+ const buildCondition = (condition) => {
898
+ if (typeof condition !== 'object' || condition === null) {
899
+ return condition;
900
+ }
901
+ // Handle logical operators (supports $AND, AND, and legacy $and)
902
+ if (condition.$AND || condition.AND || condition.$and) {
903
+ const andConditions = condition.$AND || condition.AND || condition.$and;
904
+ if (typeof andConditions === 'object' && !Array.isArray(andConditions)) {
905
+ // New syntax: { $AND: { col1: val1, col2: val2 } }
906
+ return buildCondition(andConditions);
907
+ }
908
+ else {
909
+ // Array syntax: { $AND: [cond1, cond2] }
910
+ return { $and: andConditions.map(buildCondition) };
911
+ }
912
+ }
913
+ if (condition.$OR || condition.OR || condition.$or) {
914
+ const orConditions = condition.$OR || condition.OR || condition.$or;
915
+ if (typeof orConditions === 'object' && !Array.isArray(orConditions)) {
916
+ // New syntax: { $OR: { col1: val1, col2: val2 } }
917
+ const subConditions = [];
918
+ for (const [key, value] of Object.entries(orConditions)) {
919
+ if (key === '$AND' || key === 'AND' || key === '$and' || key === '$OR' || key === 'OR' || key === '$or') {
920
+ subConditions.push(buildCondition({ [key]: value }));
921
+ }
922
+ else {
923
+ subConditions.push(buildCondition({ [key]: value }));
924
+ }
925
+ }
926
+ return { $or: subConditions };
927
+ }
928
+ else {
929
+ // Array syntax: { $OR: [cond1, cond2] }
930
+ return { $or: orConditions.map(buildCondition) };
931
+ }
932
+ }
933
+ // Handle column conditions
934
+ const filter = {};
935
+ for (const [key, value] of Object.entries(condition)) {
936
+ // Skip logical operators at this level
937
+ if (key === '$AND' || key === 'AND' || key === '$and' || key === '$OR' || key === 'OR' || key === '$or') {
938
+ continue;
939
+ }
940
+ if (typeof value === 'object' && value !== null && !Array.isArray(value) && !(value instanceof Date)) {
941
+ // Handle comparison operators
942
+ const operators = {};
943
+ for (const [op, opValue] of Object.entries(value)) {
944
+ switch (op) {
945
+ // Preferred $-prefixed syntax - map to MongoDB operators
946
+ case '$GT':
947
+ case 'GT':
948
+ operators.$gt = opValue;
949
+ break;
950
+ case '$GTE':
951
+ case 'GTE':
952
+ operators.$gte = opValue;
953
+ break;
954
+ case '$LT':
955
+ case 'LT':
956
+ operators.$lt = opValue;
957
+ break;
958
+ case '$LTE':
959
+ case 'LTE':
960
+ operators.$lte = opValue;
961
+ break;
962
+ case '$NE':
963
+ case '$NOT':
964
+ case 'NE':
965
+ case 'NOT':
966
+ operators.$ne = opValue;
967
+ break;
968
+ case '$IN':
969
+ case 'IN':
970
+ operators.$in = opValue;
971
+ break;
972
+ case '$NOT_IN':
973
+ case 'NOT_IN':
974
+ operators.$nin = opValue;
975
+ break;
976
+ case '$LIKE':
977
+ case 'LIKE':
978
+ // MongoDB uses regex for pattern matching
979
+ operators.$regex = opValue.replace(/%/g, '.*').replace(/_/g, '.');
980
+ operators.$options = 'i';
981
+ break;
982
+ case '$IS_NULL':
983
+ case 'IS_NULL':
984
+ operators.$eq = null;
985
+ break;
986
+ case '$IS_NOT_NULL':
987
+ case 'IS_NOT_NULL':
988
+ operators.$ne = null;
989
+ break;
990
+ case '$BETWEEN':
991
+ case 'BETWEEN':
992
+ if (Array.isArray(opValue) && opValue.length === 2) {
993
+ operators.$gte = opValue[0];
994
+ operators.$lte = opValue[1];
995
+ }
996
+ break;
997
+ // Legacy lowercase $ operators - pass through
998
+ case '$gt':
999
+ case '$gte':
1000
+ case '$lt':
1001
+ case '$lte':
1002
+ case '$ne':
1003
+ case '$in':
1004
+ case '$nin':
1005
+ case '$regex':
1006
+ case '$options':
1007
+ case '$exists':
1008
+ case '$type':
1009
+ case '$eq':
1010
+ case '$elemMatch':
1011
+ case '$size':
1012
+ case '$all':
1013
+ operators[op] = opValue;
1014
+ break;
1015
+ }
1016
+ }
1017
+ filter[key] = operators;
1018
+ }
1019
+ else {
1020
+ // Simple equality
1021
+ filter[key] = value;
1022
+ }
1023
+ }
1024
+ return filter;
1025
+ };
1026
+ return buildCondition(where);
1027
+ }
1028
+ // ==================== Utility Methods ====================
1029
+ /**
1030
+ * Escape identifier (collection/field name)
1031
+ */
1032
+ escapeIdentifier(identifier) {
1033
+ // MongoDB doesn't require escaping in the same way as SQL
1034
+ // But we can sanitize the identifier
1035
+ return identifier.replace(/[.$]/g, '_');
1036
+ }
1037
+ /**
1038
+ * Escape value
1039
+ */
1040
+ escapeValue(value) {
1041
+ // MongoDB uses BSON, not SQL, so escaping is different
1042
+ // This is mainly for display/logging purposes
1043
+ if (value === null || value === undefined) {
1044
+ return 'null';
1045
+ }
1046
+ if (typeof value === 'string') {
1047
+ return `"${value.replace(/"/g, '\\"')}"`;
1048
+ }
1049
+ if (value instanceof Date) {
1050
+ return value.toISOString();
1051
+ }
1052
+ if (typeof value === 'object') {
1053
+ return JSON.stringify(value);
1054
+ }
1055
+ return String(value);
1056
+ }
1057
+ /**
1058
+ * Get database version
1059
+ */
1060
+ async getDatabaseVersion(connection) {
1061
+ try {
1062
+ const db = connection.getClient();
1063
+ const info = await db.admin().serverInfo();
1064
+ return info.version || 'Unknown';
1065
+ }
1066
+ catch (error) {
1067
+ return 'Unknown';
1068
+ }
1069
+ }
1070
+ }
1071
+ exports.MongoDBAdapter = MongoDBAdapter;
1072
+ //# sourceMappingURL=mongodb.adapter.js.map