@warlock.js/cascade 4.0.31 → 4.0.39

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 (533) hide show
  1. package/cjs/index.js +15 -1
  2. package/cjs/index.js.map +1 -1
  3. package/esm/index.js +15 -1
  4. package/esm/index.js.map +1 -1
  5. package/package.json +52 -61
  6. package/cjs/aggregate/DeselectPipeline.d.ts +0 -10
  7. package/cjs/aggregate/DeselectPipeline.d.ts.map +0 -1
  8. package/cjs/aggregate/DeselectPipeline.js +0 -17
  9. package/cjs/aggregate/DeselectPipeline.js.map +0 -1
  10. package/cjs/aggregate/GeoNearPipeline.d.ts +0 -34
  11. package/cjs/aggregate/GeoNearPipeline.d.ts.map +0 -1
  12. package/cjs/aggregate/GeoNearPipeline.js +0 -44
  13. package/cjs/aggregate/GeoNearPipeline.js.map +0 -1
  14. package/cjs/aggregate/GroupByPipeline.d.ts +0 -12
  15. package/cjs/aggregate/GroupByPipeline.d.ts.map +0 -1
  16. package/cjs/aggregate/GroupByPipeline.js +0 -28
  17. package/cjs/aggregate/GroupByPipeline.js.map +0 -1
  18. package/cjs/aggregate/LimitPipeline.d.ts +0 -10
  19. package/cjs/aggregate/LimitPipeline.d.ts.map +0 -1
  20. package/cjs/aggregate/LimitPipeline.js +0 -14
  21. package/cjs/aggregate/LimitPipeline.js.map +0 -1
  22. package/cjs/aggregate/LookupPipeline.d.ts +0 -19
  23. package/cjs/aggregate/LookupPipeline.d.ts.map +0 -1
  24. package/cjs/aggregate/LookupPipeline.js +0 -23
  25. package/cjs/aggregate/LookupPipeline.js.map +0 -1
  26. package/cjs/aggregate/OrWherePipeline.d.ts +0 -21
  27. package/cjs/aggregate/OrWherePipeline.d.ts.map +0 -1
  28. package/cjs/aggregate/OrWherePipeline.js +0 -63
  29. package/cjs/aggregate/OrWherePipeline.js.map +0 -1
  30. package/cjs/aggregate/SelectPipeline.d.ts +0 -10
  31. package/cjs/aggregate/SelectPipeline.d.ts.map +0 -1
  32. package/cjs/aggregate/SelectPipeline.js +0 -26
  33. package/cjs/aggregate/SelectPipeline.js.map +0 -1
  34. package/cjs/aggregate/SkipPipeline.d.ts +0 -10
  35. package/cjs/aggregate/SkipPipeline.d.ts.map +0 -1
  36. package/cjs/aggregate/SkipPipeline.js +0 -14
  37. package/cjs/aggregate/SkipPipeline.js.map +0 -1
  38. package/cjs/aggregate/SortByPipeline.d.ts +0 -10
  39. package/cjs/aggregate/SortByPipeline.d.ts.map +0 -1
  40. package/cjs/aggregate/SortByPipeline.js +0 -18
  41. package/cjs/aggregate/SortByPipeline.js.map +0 -1
  42. package/cjs/aggregate/SortPipeline.d.ts +0 -11
  43. package/cjs/aggregate/SortPipeline.d.ts.map +0 -1
  44. package/cjs/aggregate/SortPipeline.js +0 -18
  45. package/cjs/aggregate/SortPipeline.js.map +0 -1
  46. package/cjs/aggregate/SortRandomPipeline.d.ts +0 -10
  47. package/cjs/aggregate/SortRandomPipeline.d.ts.map +0 -1
  48. package/cjs/aggregate/SortRandomPipeline.js +0 -16
  49. package/cjs/aggregate/SortRandomPipeline.js.map +0 -1
  50. package/cjs/aggregate/UnwindPipeline.d.ts +0 -14
  51. package/cjs/aggregate/UnwindPipeline.d.ts.map +0 -1
  52. package/cjs/aggregate/UnwindPipeline.js +0 -19
  53. package/cjs/aggregate/UnwindPipeline.js.map +0 -1
  54. package/cjs/aggregate/WhereExpression.d.ts +0 -17
  55. package/cjs/aggregate/WhereExpression.d.ts.map +0 -1
  56. package/cjs/aggregate/WhereExpression.js +0 -149
  57. package/cjs/aggregate/WhereExpression.js.map +0 -1
  58. package/cjs/aggregate/WhereExpressionPipeline.d.ts +0 -10
  59. package/cjs/aggregate/WhereExpressionPipeline.d.ts.map +0 -1
  60. package/cjs/aggregate/WhereExpressionPipeline.js +0 -15
  61. package/cjs/aggregate/WhereExpressionPipeline.js.map +0 -1
  62. package/cjs/aggregate/WherePipeline.d.ts +0 -13
  63. package/cjs/aggregate/WherePipeline.d.ts.map +0 -1
  64. package/cjs/aggregate/WherePipeline.js +0 -12
  65. package/cjs/aggregate/WherePipeline.js.map +0 -1
  66. package/cjs/aggregate/aggregate.d.ts +0 -409
  67. package/cjs/aggregate/aggregate.d.ts.map +0 -1
  68. package/cjs/aggregate/aggregate.js +0 -911
  69. package/cjs/aggregate/aggregate.js.map +0 -1
  70. package/cjs/aggregate/expressions.d.ts +0 -361
  71. package/cjs/aggregate/expressions.d.ts.map +0 -1
  72. package/cjs/aggregate/expressions.js +0 -536
  73. package/cjs/aggregate/expressions.js.map +0 -1
  74. package/cjs/aggregate/filters/apply-filters.d.ts +0 -3
  75. package/cjs/aggregate/filters/apply-filters.d.ts.map +0 -1
  76. package/cjs/aggregate/filters/apply-filters.js +0 -75
  77. package/cjs/aggregate/filters/apply-filters.js.map +0 -1
  78. package/cjs/aggregate/filters/boolean-filters.d.ts +0 -3
  79. package/cjs/aggregate/filters/boolean-filters.d.ts.map +0 -1
  80. package/cjs/aggregate/filters/boolean-filters.js +0 -33
  81. package/cjs/aggregate/filters/boolean-filters.js.map +0 -1
  82. package/cjs/aggregate/filters/date-filters.d.ts +0 -3
  83. package/cjs/aggregate/filters/date-filters.d.ts.map +0 -1
  84. package/cjs/aggregate/filters/date-filters.js +0 -128
  85. package/cjs/aggregate/filters/date-filters.js.map +0 -1
  86. package/cjs/aggregate/filters/index.d.ts +0 -3
  87. package/cjs/aggregate/filters/index.d.ts.map +0 -1
  88. package/cjs/aggregate/filters/numeric-filters.d.ts +0 -3
  89. package/cjs/aggregate/filters/numeric-filters.d.ts.map +0 -1
  90. package/cjs/aggregate/filters/numeric-filters.js +0 -99
  91. package/cjs/aggregate/filters/numeric-filters.js.map +0 -1
  92. package/cjs/aggregate/filters/types.d.ts +0 -46
  93. package/cjs/aggregate/filters/types.d.ts.map +0 -1
  94. package/cjs/aggregate/filters/utils.d.ts +0 -13
  95. package/cjs/aggregate/filters/utils.d.ts.map +0 -1
  96. package/cjs/aggregate/filters/utils.js +0 -38
  97. package/cjs/aggregate/filters/utils.js.map +0 -1
  98. package/cjs/aggregate/index.d.ts +0 -21
  99. package/cjs/aggregate/index.d.ts.map +0 -1
  100. package/cjs/aggregate/parsePipelines.d.ts +0 -5
  101. package/cjs/aggregate/parsePipelines.d.ts.map +0 -1
  102. package/cjs/aggregate/parsePipelines.js +0 -6
  103. package/cjs/aggregate/parsePipelines.js.map +0 -1
  104. package/cjs/aggregate/pipeline.d.ts +0 -31
  105. package/cjs/aggregate/pipeline.d.ts.map +0 -1
  106. package/cjs/aggregate/pipeline.js +0 -42
  107. package/cjs/aggregate/pipeline.js.map +0 -1
  108. package/cjs/aggregate/types.d.ts +0 -8
  109. package/cjs/aggregate/types.d.ts.map +0 -1
  110. package/cjs/aggregate/types.js +0 -31
  111. package/cjs/aggregate/types.js.map +0 -1
  112. package/cjs/blueprint/blueprint-column.d.ts +0 -82
  113. package/cjs/blueprint/blueprint-column.d.ts.map +0 -1
  114. package/cjs/blueprint/blueprint.d.ts +0 -162
  115. package/cjs/blueprint/blueprint.d.ts.map +0 -1
  116. package/cjs/blueprint/blueprint.js +0 -340
  117. package/cjs/blueprint/blueprint.js.map +0 -1
  118. package/cjs/blueprint/index.d.ts +0 -3
  119. package/cjs/blueprint/index.d.ts.map +0 -1
  120. package/cjs/blueprint/model-blueprint.d.ts +0 -15
  121. package/cjs/blueprint/model-blueprint.d.ts.map +0 -1
  122. package/cjs/blueprint/model-blueprint.js +0 -16
  123. package/cjs/blueprint/model-blueprint.js.map +0 -1
  124. package/cjs/casts/arrayOf.d.ts +0 -5
  125. package/cjs/casts/arrayOf.d.ts.map +0 -1
  126. package/cjs/casts/arrayOf.js +0 -18
  127. package/cjs/casts/arrayOf.js.map +0 -1
  128. package/cjs/casts/cast-email.d.ts +0 -2
  129. package/cjs/casts/cast-email.d.ts.map +0 -1
  130. package/cjs/casts/cast-email.js +0 -5
  131. package/cjs/casts/cast-email.js.map +0 -1
  132. package/cjs/casts/castModel.d.ts +0 -3
  133. package/cjs/casts/castModel.d.ts.map +0 -1
  134. package/cjs/casts/castModel.js +0 -49
  135. package/cjs/casts/castModel.js.map +0 -1
  136. package/cjs/casts/expiresAfter.d.ts +0 -3
  137. package/cjs/casts/expiresAfter.d.ts.map +0 -1
  138. package/cjs/casts/expiresAfter.js +0 -5
  139. package/cjs/casts/expiresAfter.js.map +0 -1
  140. package/cjs/casts/index.d.ts +0 -9
  141. package/cjs/casts/index.d.ts.map +0 -1
  142. package/cjs/casts/oneOf.d.ts +0 -3
  143. package/cjs/casts/oneOf.d.ts.map +0 -1
  144. package/cjs/casts/oneOf.js +0 -22
  145. package/cjs/casts/oneOf.js.map +0 -1
  146. package/cjs/casts/random-string.d.ts +0 -2
  147. package/cjs/casts/random-string.d.ts.map +0 -1
  148. package/cjs/casts/random-string.js +0 -5
  149. package/cjs/casts/random-string.js.map +0 -1
  150. package/cjs/casts/randomInteger.d.ts +0 -2
  151. package/cjs/casts/randomInteger.d.ts.map +0 -1
  152. package/cjs/casts/randomInteger.js +0 -7
  153. package/cjs/casts/randomInteger.js.map +0 -1
  154. package/cjs/casts/shapedArray.d.ts +0 -26
  155. package/cjs/casts/shapedArray.d.ts.map +0 -1
  156. package/cjs/casts/shapedArray.js +0 -100
  157. package/cjs/casts/shapedArray.js.map +0 -1
  158. package/cjs/config.d.ts +0 -6
  159. package/cjs/config.d.ts.map +0 -1
  160. package/cjs/config.js +0 -16
  161. package/cjs/config.js.map +0 -1
  162. package/cjs/connection.d.ts +0 -49
  163. package/cjs/connection.d.ts.map +0 -1
  164. package/cjs/connection.js +0 -108
  165. package/cjs/connection.js.map +0 -1
  166. package/cjs/database.d.ts +0 -97
  167. package/cjs/database.d.ts.map +0 -1
  168. package/cjs/database.js +0 -164
  169. package/cjs/database.js.map +0 -1
  170. package/cjs/index.d.ts +0 -13
  171. package/cjs/index.d.ts.map +0 -1
  172. package/cjs/migration/index.d.ts +0 -4
  173. package/cjs/migration/index.d.ts.map +0 -1
  174. package/cjs/migration/migrate.d.ts +0 -13
  175. package/cjs/migration/migrate.d.ts.map +0 -1
  176. package/cjs/migration/migrate.js +0 -72
  177. package/cjs/migration/migrate.js.map +0 -1
  178. package/cjs/migration/migration-office.d.ts +0 -21
  179. package/cjs/migration/migration-office.d.ts.map +0 -1
  180. package/cjs/migration/migration-office.js +0 -39
  181. package/cjs/migration/migration-office.js.map +0 -1
  182. package/cjs/migration/migration-officer.d.ts +0 -33
  183. package/cjs/migration/migration-officer.d.ts.map +0 -1
  184. package/cjs/migration/migration-officer.js +0 -55
  185. package/cjs/migration/migration-officer.js.map +0 -1
  186. package/cjs/migration/types.d.ts +0 -34
  187. package/cjs/migration/types.d.ts.map +0 -1
  188. package/cjs/model/ModelAggregate.d.ts +0 -114
  189. package/cjs/model/ModelAggregate.d.ts.map +0 -1
  190. package/cjs/model/ModelAggregate.js +0 -182
  191. package/cjs/model/ModelAggregate.js.map +0 -1
  192. package/cjs/model/ModelSync.d.ts +0 -73
  193. package/cjs/model/ModelSync.d.ts.map +0 -1
  194. package/cjs/model/ModelSync.js +0 -215
  195. package/cjs/model/ModelSync.js.map +0 -1
  196. package/cjs/model/RelationshipWithMany.d.ts +0 -24
  197. package/cjs/model/RelationshipWithMany.d.ts.map +0 -1
  198. package/cjs/model/RelationshipWithMany.js +0 -42
  199. package/cjs/model/RelationshipWithMany.js.map +0 -1
  200. package/cjs/model/base-model.d.ts +0 -161
  201. package/cjs/model/base-model.d.ts.map +0 -1
  202. package/cjs/model/base-model.js +0 -265
  203. package/cjs/model/base-model.js.map +0 -1
  204. package/cjs/model/crud-model.d.ts +0 -122
  205. package/cjs/model/crud-model.d.ts.map +0 -1
  206. package/cjs/model/crud-model.js +0 -366
  207. package/cjs/model/crud-model.js.map +0 -1
  208. package/cjs/model/index.d.ts +0 -10
  209. package/cjs/model/index.d.ts.map +0 -1
  210. package/cjs/model/joinable.d.ts +0 -87
  211. package/cjs/model/joinable.d.ts.map +0 -1
  212. package/cjs/model/joinable.js +0 -158
  213. package/cjs/model/joinable.js.map +0 -1
  214. package/cjs/model/master-mind.d.ts +0 -44
  215. package/cjs/model/master-mind.d.ts.map +0 -1
  216. package/cjs/model/master-mind.js +0 -118
  217. package/cjs/model/master-mind.js.map +0 -1
  218. package/cjs/model/model-events.d.ts +0 -57
  219. package/cjs/model/model-events.d.ts.map +0 -1
  220. package/cjs/model/model-events.js +0 -102
  221. package/cjs/model/model-events.js.map +0 -1
  222. package/cjs/model/model.d.ts +0 -464
  223. package/cjs/model/model.d.ts.map +0 -1
  224. package/cjs/model/model.js +0 -1134
  225. package/cjs/model/model.js.map +0 -1
  226. package/cjs/model/types.d.ts +0 -149
  227. package/cjs/model/types.d.ts.map +0 -1
  228. package/cjs/model/types.js +0 -11
  229. package/cjs/model/types.js.map +0 -1
  230. package/cjs/query/index.d.ts +0 -2
  231. package/cjs/query/index.d.ts.map +0 -1
  232. package/cjs/query/query.d.ts +0 -218
  233. package/cjs/query/query.d.ts.map +0 -1
  234. package/cjs/query/query.js +0 -672
  235. package/cjs/query/query.js.map +0 -1
  236. package/cjs/query/types.d.ts +0 -60
  237. package/cjs/query/types.d.ts.map +0 -1
  238. package/cjs/types.d.ts +0 -75
  239. package/cjs/types.d.ts.map +0 -1
  240. package/cjs/utils/connectToDatabase.d.ts +0 -3
  241. package/cjs/utils/connectToDatabase.d.ts.map +0 -1
  242. package/cjs/utils/connectToDatabase.js +0 -3
  243. package/cjs/utils/connectToDatabase.js.map +0 -1
  244. package/cjs/utils/deep-diff.d.ts +0 -9
  245. package/cjs/utils/deep-diff.d.ts.map +0 -1
  246. package/cjs/utils/deep-diff.js +0 -44
  247. package/cjs/utils/deep-diff.js.map +0 -1
  248. package/cjs/utils/dropAllDatabaseIndexes.d.ts +0 -2
  249. package/cjs/utils/dropAllDatabaseIndexes.d.ts.map +0 -1
  250. package/cjs/utils/dropAllDatabaseIndexes.js +0 -10
  251. package/cjs/utils/dropAllDatabaseIndexes.js.map +0 -1
  252. package/cjs/utils/index.d.ts +0 -6
  253. package/cjs/utils/index.d.ts.map +0 -1
  254. package/cjs/utils/joinable-proxy.d.ts +0 -3
  255. package/cjs/utils/joinable-proxy.d.ts.map +0 -1
  256. package/cjs/utils/joinable-proxy.js +0 -14
  257. package/cjs/utils/joinable-proxy.js.map +0 -1
  258. package/cjs/utils/listDatabaseIndexes.d.ts +0 -4
  259. package/cjs/utils/listDatabaseIndexes.d.ts.map +0 -1
  260. package/cjs/utils/listDatabaseIndexes.js +0 -101
  261. package/cjs/utils/listDatabaseIndexes.js.map +0 -1
  262. package/cjs/utils/onceConnected.d.ts +0 -2
  263. package/cjs/utils/onceConnected.d.ts.map +0 -1
  264. package/cjs/utils/onceConnected.js +0 -8
  265. package/cjs/utils/onceConnected.js.map +0 -1
  266. package/cjs/utils/sync-with.d.ts +0 -27
  267. package/cjs/utils/sync-with.d.ts.map +0 -1
  268. package/cjs/utils/sync-with.js +0 -60
  269. package/cjs/utils/sync-with.js.map +0 -1
  270. package/esm/aggregate/DeselectPipeline.d.ts +0 -10
  271. package/esm/aggregate/DeselectPipeline.d.ts.map +0 -1
  272. package/esm/aggregate/DeselectPipeline.js +0 -17
  273. package/esm/aggregate/DeselectPipeline.js.map +0 -1
  274. package/esm/aggregate/GeoNearPipeline.d.ts +0 -34
  275. package/esm/aggregate/GeoNearPipeline.d.ts.map +0 -1
  276. package/esm/aggregate/GeoNearPipeline.js +0 -44
  277. package/esm/aggregate/GeoNearPipeline.js.map +0 -1
  278. package/esm/aggregate/GroupByPipeline.d.ts +0 -12
  279. package/esm/aggregate/GroupByPipeline.d.ts.map +0 -1
  280. package/esm/aggregate/GroupByPipeline.js +0 -28
  281. package/esm/aggregate/GroupByPipeline.js.map +0 -1
  282. package/esm/aggregate/LimitPipeline.d.ts +0 -10
  283. package/esm/aggregate/LimitPipeline.d.ts.map +0 -1
  284. package/esm/aggregate/LimitPipeline.js +0 -14
  285. package/esm/aggregate/LimitPipeline.js.map +0 -1
  286. package/esm/aggregate/LookupPipeline.d.ts +0 -19
  287. package/esm/aggregate/LookupPipeline.d.ts.map +0 -1
  288. package/esm/aggregate/LookupPipeline.js +0 -23
  289. package/esm/aggregate/LookupPipeline.js.map +0 -1
  290. package/esm/aggregate/OrWherePipeline.d.ts +0 -21
  291. package/esm/aggregate/OrWherePipeline.d.ts.map +0 -1
  292. package/esm/aggregate/OrWherePipeline.js +0 -63
  293. package/esm/aggregate/OrWherePipeline.js.map +0 -1
  294. package/esm/aggregate/SelectPipeline.d.ts +0 -10
  295. package/esm/aggregate/SelectPipeline.d.ts.map +0 -1
  296. package/esm/aggregate/SelectPipeline.js +0 -26
  297. package/esm/aggregate/SelectPipeline.js.map +0 -1
  298. package/esm/aggregate/SkipPipeline.d.ts +0 -10
  299. package/esm/aggregate/SkipPipeline.d.ts.map +0 -1
  300. package/esm/aggregate/SkipPipeline.js +0 -14
  301. package/esm/aggregate/SkipPipeline.js.map +0 -1
  302. package/esm/aggregate/SortByPipeline.d.ts +0 -10
  303. package/esm/aggregate/SortByPipeline.d.ts.map +0 -1
  304. package/esm/aggregate/SortByPipeline.js +0 -18
  305. package/esm/aggregate/SortByPipeline.js.map +0 -1
  306. package/esm/aggregate/SortPipeline.d.ts +0 -11
  307. package/esm/aggregate/SortPipeline.d.ts.map +0 -1
  308. package/esm/aggregate/SortPipeline.js +0 -18
  309. package/esm/aggregate/SortPipeline.js.map +0 -1
  310. package/esm/aggregate/SortRandomPipeline.d.ts +0 -10
  311. package/esm/aggregate/SortRandomPipeline.d.ts.map +0 -1
  312. package/esm/aggregate/SortRandomPipeline.js +0 -16
  313. package/esm/aggregate/SortRandomPipeline.js.map +0 -1
  314. package/esm/aggregate/UnwindPipeline.d.ts +0 -14
  315. package/esm/aggregate/UnwindPipeline.d.ts.map +0 -1
  316. package/esm/aggregate/UnwindPipeline.js +0 -19
  317. package/esm/aggregate/UnwindPipeline.js.map +0 -1
  318. package/esm/aggregate/WhereExpression.d.ts +0 -17
  319. package/esm/aggregate/WhereExpression.d.ts.map +0 -1
  320. package/esm/aggregate/WhereExpression.js +0 -149
  321. package/esm/aggregate/WhereExpression.js.map +0 -1
  322. package/esm/aggregate/WhereExpressionPipeline.d.ts +0 -10
  323. package/esm/aggregate/WhereExpressionPipeline.d.ts.map +0 -1
  324. package/esm/aggregate/WhereExpressionPipeline.js +0 -15
  325. package/esm/aggregate/WhereExpressionPipeline.js.map +0 -1
  326. package/esm/aggregate/WherePipeline.d.ts +0 -13
  327. package/esm/aggregate/WherePipeline.d.ts.map +0 -1
  328. package/esm/aggregate/WherePipeline.js +0 -12
  329. package/esm/aggregate/WherePipeline.js.map +0 -1
  330. package/esm/aggregate/aggregate.d.ts +0 -409
  331. package/esm/aggregate/aggregate.d.ts.map +0 -1
  332. package/esm/aggregate/aggregate.js +0 -911
  333. package/esm/aggregate/aggregate.js.map +0 -1
  334. package/esm/aggregate/expressions.d.ts +0 -361
  335. package/esm/aggregate/expressions.d.ts.map +0 -1
  336. package/esm/aggregate/expressions.js +0 -536
  337. package/esm/aggregate/expressions.js.map +0 -1
  338. package/esm/aggregate/filters/apply-filters.d.ts +0 -3
  339. package/esm/aggregate/filters/apply-filters.d.ts.map +0 -1
  340. package/esm/aggregate/filters/apply-filters.js +0 -75
  341. package/esm/aggregate/filters/apply-filters.js.map +0 -1
  342. package/esm/aggregate/filters/boolean-filters.d.ts +0 -3
  343. package/esm/aggregate/filters/boolean-filters.d.ts.map +0 -1
  344. package/esm/aggregate/filters/boolean-filters.js +0 -33
  345. package/esm/aggregate/filters/boolean-filters.js.map +0 -1
  346. package/esm/aggregate/filters/date-filters.d.ts +0 -3
  347. package/esm/aggregate/filters/date-filters.d.ts.map +0 -1
  348. package/esm/aggregate/filters/date-filters.js +0 -128
  349. package/esm/aggregate/filters/date-filters.js.map +0 -1
  350. package/esm/aggregate/filters/index.d.ts +0 -3
  351. package/esm/aggregate/filters/index.d.ts.map +0 -1
  352. package/esm/aggregate/filters/numeric-filters.d.ts +0 -3
  353. package/esm/aggregate/filters/numeric-filters.d.ts.map +0 -1
  354. package/esm/aggregate/filters/numeric-filters.js +0 -99
  355. package/esm/aggregate/filters/numeric-filters.js.map +0 -1
  356. package/esm/aggregate/filters/types.d.ts +0 -46
  357. package/esm/aggregate/filters/types.d.ts.map +0 -1
  358. package/esm/aggregate/filters/utils.d.ts +0 -13
  359. package/esm/aggregate/filters/utils.d.ts.map +0 -1
  360. package/esm/aggregate/filters/utils.js +0 -38
  361. package/esm/aggregate/filters/utils.js.map +0 -1
  362. package/esm/aggregate/index.d.ts +0 -21
  363. package/esm/aggregate/index.d.ts.map +0 -1
  364. package/esm/aggregate/parsePipelines.d.ts +0 -5
  365. package/esm/aggregate/parsePipelines.d.ts.map +0 -1
  366. package/esm/aggregate/parsePipelines.js +0 -6
  367. package/esm/aggregate/parsePipelines.js.map +0 -1
  368. package/esm/aggregate/pipeline.d.ts +0 -31
  369. package/esm/aggregate/pipeline.d.ts.map +0 -1
  370. package/esm/aggregate/pipeline.js +0 -42
  371. package/esm/aggregate/pipeline.js.map +0 -1
  372. package/esm/aggregate/types.d.ts +0 -8
  373. package/esm/aggregate/types.d.ts.map +0 -1
  374. package/esm/aggregate/types.js +0 -31
  375. package/esm/aggregate/types.js.map +0 -1
  376. package/esm/blueprint/blueprint-column.d.ts +0 -82
  377. package/esm/blueprint/blueprint-column.d.ts.map +0 -1
  378. package/esm/blueprint/blueprint.d.ts +0 -162
  379. package/esm/blueprint/blueprint.d.ts.map +0 -1
  380. package/esm/blueprint/blueprint.js +0 -340
  381. package/esm/blueprint/blueprint.js.map +0 -1
  382. package/esm/blueprint/index.d.ts +0 -3
  383. package/esm/blueprint/index.d.ts.map +0 -1
  384. package/esm/blueprint/model-blueprint.d.ts +0 -15
  385. package/esm/blueprint/model-blueprint.d.ts.map +0 -1
  386. package/esm/blueprint/model-blueprint.js +0 -16
  387. package/esm/blueprint/model-blueprint.js.map +0 -1
  388. package/esm/casts/arrayOf.d.ts +0 -5
  389. package/esm/casts/arrayOf.d.ts.map +0 -1
  390. package/esm/casts/arrayOf.js +0 -18
  391. package/esm/casts/arrayOf.js.map +0 -1
  392. package/esm/casts/cast-email.d.ts +0 -2
  393. package/esm/casts/cast-email.d.ts.map +0 -1
  394. package/esm/casts/cast-email.js +0 -5
  395. package/esm/casts/cast-email.js.map +0 -1
  396. package/esm/casts/castModel.d.ts +0 -3
  397. package/esm/casts/castModel.d.ts.map +0 -1
  398. package/esm/casts/castModel.js +0 -49
  399. package/esm/casts/castModel.js.map +0 -1
  400. package/esm/casts/expiresAfter.d.ts +0 -3
  401. package/esm/casts/expiresAfter.d.ts.map +0 -1
  402. package/esm/casts/expiresAfter.js +0 -5
  403. package/esm/casts/expiresAfter.js.map +0 -1
  404. package/esm/casts/index.d.ts +0 -9
  405. package/esm/casts/index.d.ts.map +0 -1
  406. package/esm/casts/oneOf.d.ts +0 -3
  407. package/esm/casts/oneOf.d.ts.map +0 -1
  408. package/esm/casts/oneOf.js +0 -22
  409. package/esm/casts/oneOf.js.map +0 -1
  410. package/esm/casts/random-string.d.ts +0 -2
  411. package/esm/casts/random-string.d.ts.map +0 -1
  412. package/esm/casts/random-string.js +0 -5
  413. package/esm/casts/random-string.js.map +0 -1
  414. package/esm/casts/randomInteger.d.ts +0 -2
  415. package/esm/casts/randomInteger.d.ts.map +0 -1
  416. package/esm/casts/randomInteger.js +0 -7
  417. package/esm/casts/randomInteger.js.map +0 -1
  418. package/esm/casts/shapedArray.d.ts +0 -26
  419. package/esm/casts/shapedArray.d.ts.map +0 -1
  420. package/esm/casts/shapedArray.js +0 -100
  421. package/esm/casts/shapedArray.js.map +0 -1
  422. package/esm/config.d.ts +0 -6
  423. package/esm/config.d.ts.map +0 -1
  424. package/esm/config.js +0 -16
  425. package/esm/config.js.map +0 -1
  426. package/esm/connection.d.ts +0 -49
  427. package/esm/connection.d.ts.map +0 -1
  428. package/esm/connection.js +0 -108
  429. package/esm/connection.js.map +0 -1
  430. package/esm/database.d.ts +0 -97
  431. package/esm/database.d.ts.map +0 -1
  432. package/esm/database.js +0 -164
  433. package/esm/database.js.map +0 -1
  434. package/esm/index.d.ts +0 -13
  435. package/esm/index.d.ts.map +0 -1
  436. package/esm/migration/index.d.ts +0 -4
  437. package/esm/migration/index.d.ts.map +0 -1
  438. package/esm/migration/migrate.d.ts +0 -13
  439. package/esm/migration/migrate.d.ts.map +0 -1
  440. package/esm/migration/migrate.js +0 -72
  441. package/esm/migration/migrate.js.map +0 -1
  442. package/esm/migration/migration-office.d.ts +0 -21
  443. package/esm/migration/migration-office.d.ts.map +0 -1
  444. package/esm/migration/migration-office.js +0 -39
  445. package/esm/migration/migration-office.js.map +0 -1
  446. package/esm/migration/migration-officer.d.ts +0 -33
  447. package/esm/migration/migration-officer.d.ts.map +0 -1
  448. package/esm/migration/migration-officer.js +0 -55
  449. package/esm/migration/migration-officer.js.map +0 -1
  450. package/esm/migration/types.d.ts +0 -34
  451. package/esm/migration/types.d.ts.map +0 -1
  452. package/esm/model/ModelAggregate.d.ts +0 -114
  453. package/esm/model/ModelAggregate.d.ts.map +0 -1
  454. package/esm/model/ModelAggregate.js +0 -182
  455. package/esm/model/ModelAggregate.js.map +0 -1
  456. package/esm/model/ModelSync.d.ts +0 -73
  457. package/esm/model/ModelSync.d.ts.map +0 -1
  458. package/esm/model/ModelSync.js +0 -215
  459. package/esm/model/ModelSync.js.map +0 -1
  460. package/esm/model/RelationshipWithMany.d.ts +0 -24
  461. package/esm/model/RelationshipWithMany.d.ts.map +0 -1
  462. package/esm/model/RelationshipWithMany.js +0 -42
  463. package/esm/model/RelationshipWithMany.js.map +0 -1
  464. package/esm/model/base-model.d.ts +0 -161
  465. package/esm/model/base-model.d.ts.map +0 -1
  466. package/esm/model/base-model.js +0 -265
  467. package/esm/model/base-model.js.map +0 -1
  468. package/esm/model/crud-model.d.ts +0 -122
  469. package/esm/model/crud-model.d.ts.map +0 -1
  470. package/esm/model/crud-model.js +0 -366
  471. package/esm/model/crud-model.js.map +0 -1
  472. package/esm/model/index.d.ts +0 -10
  473. package/esm/model/index.d.ts.map +0 -1
  474. package/esm/model/joinable.d.ts +0 -87
  475. package/esm/model/joinable.d.ts.map +0 -1
  476. package/esm/model/joinable.js +0 -158
  477. package/esm/model/joinable.js.map +0 -1
  478. package/esm/model/master-mind.d.ts +0 -44
  479. package/esm/model/master-mind.d.ts.map +0 -1
  480. package/esm/model/master-mind.js +0 -118
  481. package/esm/model/master-mind.js.map +0 -1
  482. package/esm/model/model-events.d.ts +0 -57
  483. package/esm/model/model-events.d.ts.map +0 -1
  484. package/esm/model/model-events.js +0 -102
  485. package/esm/model/model-events.js.map +0 -1
  486. package/esm/model/model.d.ts +0 -464
  487. package/esm/model/model.d.ts.map +0 -1
  488. package/esm/model/model.js +0 -1134
  489. package/esm/model/model.js.map +0 -1
  490. package/esm/model/types.d.ts +0 -149
  491. package/esm/model/types.d.ts.map +0 -1
  492. package/esm/model/types.js +0 -11
  493. package/esm/model/types.js.map +0 -1
  494. package/esm/query/index.d.ts +0 -2
  495. package/esm/query/index.d.ts.map +0 -1
  496. package/esm/query/query.d.ts +0 -218
  497. package/esm/query/query.d.ts.map +0 -1
  498. package/esm/query/query.js +0 -672
  499. package/esm/query/query.js.map +0 -1
  500. package/esm/query/types.d.ts +0 -60
  501. package/esm/query/types.d.ts.map +0 -1
  502. package/esm/types.d.ts +0 -75
  503. package/esm/types.d.ts.map +0 -1
  504. package/esm/utils/connectToDatabase.d.ts +0 -3
  505. package/esm/utils/connectToDatabase.d.ts.map +0 -1
  506. package/esm/utils/connectToDatabase.js +0 -3
  507. package/esm/utils/connectToDatabase.js.map +0 -1
  508. package/esm/utils/deep-diff.d.ts +0 -9
  509. package/esm/utils/deep-diff.d.ts.map +0 -1
  510. package/esm/utils/deep-diff.js +0 -44
  511. package/esm/utils/deep-diff.js.map +0 -1
  512. package/esm/utils/dropAllDatabaseIndexes.d.ts +0 -2
  513. package/esm/utils/dropAllDatabaseIndexes.d.ts.map +0 -1
  514. package/esm/utils/dropAllDatabaseIndexes.js +0 -10
  515. package/esm/utils/dropAllDatabaseIndexes.js.map +0 -1
  516. package/esm/utils/index.d.ts +0 -6
  517. package/esm/utils/index.d.ts.map +0 -1
  518. package/esm/utils/joinable-proxy.d.ts +0 -3
  519. package/esm/utils/joinable-proxy.d.ts.map +0 -1
  520. package/esm/utils/joinable-proxy.js +0 -14
  521. package/esm/utils/joinable-proxy.js.map +0 -1
  522. package/esm/utils/listDatabaseIndexes.d.ts +0 -4
  523. package/esm/utils/listDatabaseIndexes.d.ts.map +0 -1
  524. package/esm/utils/listDatabaseIndexes.js +0 -101
  525. package/esm/utils/listDatabaseIndexes.js.map +0 -1
  526. package/esm/utils/onceConnected.d.ts +0 -2
  527. package/esm/utils/onceConnected.d.ts.map +0 -1
  528. package/esm/utils/onceConnected.js +0 -8
  529. package/esm/utils/onceConnected.js.map +0 -1
  530. package/esm/utils/sync-with.d.ts +0 -27
  531. package/esm/utils/sync-with.d.ts.map +0 -1
  532. package/esm/utils/sync-with.js +0 -60
  533. package/esm/utils/sync-with.js.map +0 -1
@@ -1,911 +0,0 @@
1
- 'use strict';var reinforcements=require('@mongez/reinforcements'),logger=require('@warlock.js/logger'),mongodb=require('mongodb'),modelEvents=require('../model/model-events.js'),query=require('../query/query.js'),DeselectPipeline=require('./DeselectPipeline.js'),GroupByPipeline=require('./GroupByPipeline.js'),LimitPipeline=require('./LimitPipeline.js'),LookupPipeline=require('./LookupPipeline.js'),OrWherePipeline=require('./OrWherePipeline.js'),SelectPipeline=require('./SelectPipeline.js'),SkipPipeline=require('./SkipPipeline.js'),SortByPipeline=require('./SortByPipeline.js'),SortPipeline=require('./SortPipeline.js'),SortRandomPipeline=require('./SortRandomPipeline.js'),UnwindPipeline=require('./UnwindPipeline.js'),WhereExpression=require('./WhereExpression.js'),WherePipeline=require('./WherePipeline.js'),expressions=require('./expressions.js'),applyFilters=require('./filters/apply-filters.js'),parsePipelines=require('./parsePipelines.js');class Aggregate {
2
- collection;
3
- /**
4
- * Collection pipelines
5
- */
6
- pipelines = [];
7
- /**
8
- * Aggregate events
9
- */
10
- static _events = new modelEvents.ModelEvents();
11
- /**
12
- * Query manager
13
- */
14
- query = query.query;
15
- /**
16
- * Constructor
17
- */
18
- constructor(collection) {
19
- this.collection = collection;
20
- // get the events instance
21
- const events = Aggregate._events;
22
- Aggregate._events.trigger("fetching", this);
23
- events.collection = collection;
24
- }
25
- /**
26
- * Get the events instance
27
- */
28
- static events() {
29
- return Aggregate._events;
30
- }
31
- /**
32
- * Sort by the given column
33
- */
34
- sort(column, direction = "asc") {
35
- return this.pipeline(new SortPipeline.SortPipeline(column, direction));
36
- }
37
- /**
38
- * @alias sort
39
- */
40
- orderBy(column, direction = "asc") {
41
- return this.sort(column, direction);
42
- }
43
- /**
44
- * Order by descending
45
- */
46
- sortByDesc(column) {
47
- return this.sort(column, "desc");
48
- }
49
- /**
50
- * Order by descending
51
- */
52
- orderByDesc(column) {
53
- return this.sort(column, "desc");
54
- }
55
- /**
56
- * Sort by multiple columns
57
- */
58
- sortBy(columns) {
59
- return this.pipeline(new SortByPipeline.SortByPipeline(columns));
60
- }
61
- /**
62
- * Sort randomly
63
- */
64
- random(limit) {
65
- if (!limit) {
66
- // get limit pipeline
67
- const limitPipeline = this.pipelines.find(pipeline => pipeline.name === "limit");
68
- if (limitPipeline) {
69
- limit = limitPipeline.getData();
70
- }
71
- if (!limit) {
72
- throw new Error("You must provide a limit when using random() or use limit() pipeline");
73
- }
74
- }
75
- // order by random in mongodb using $sample
76
- return this.pipeline(new SortRandomPipeline.SortRandomPipeline(limit));
77
- }
78
- /**
79
- * Order by latest created records
80
- */
81
- latest(column = "createdAt") {
82
- return this.sort(column, "desc");
83
- }
84
- /**
85
- * Order by oldest created records
86
- */
87
- oldest(column = "createdAt") {
88
- return this.sort(column, "asc");
89
- }
90
- groupBy(...args) {
91
- const [groupBy_id, groupByData] = args;
92
- if (groupBy_id instanceof GroupByPipeline.GroupByPipeline) {
93
- return this.pipeline(groupBy_id);
94
- }
95
- return this.pipeline(new GroupByPipeline.GroupByPipeline(groupBy_id, groupByData));
96
- }
97
- /**
98
- * Group by year
99
- */
100
- groupByYear(column, groupByData) {
101
- return this.groupBy({
102
- year: expressions.year(expressions.$agg.columnName(column)),
103
- }, groupByData);
104
- }
105
- /**
106
- * Group by month and year
107
- */
108
- groupByMonthAndYear(column, groupByData) {
109
- column = expressions.$agg.columnName(column);
110
- return this.groupBy({
111
- year: expressions.year(column),
112
- month: expressions.month(column),
113
- }, groupByData);
114
- }
115
- /**
116
- * Group by month only
117
- */
118
- groupByMonth(column, groupByData) {
119
- column = expressions.$agg.columnName(column);
120
- return this.groupBy({
121
- month: expressions.month(column),
122
- }, groupByData);
123
- }
124
- /**
125
- * Group by day, month and year
126
- */
127
- groupByDate(column, groupByData) {
128
- column = expressions.$agg.columnName(column);
129
- return this.groupBy({
130
- year: expressions.year(column),
131
- month: expressions.month(column),
132
- day: expressions.dayOfMonth(column),
133
- }, groupByData);
134
- }
135
- /**
136
- * Group by week and year
137
- */
138
- groupByWeek(column, groupByData) {
139
- column = expressions.$agg.columnName(column);
140
- return this.groupBy({
141
- year: expressions.year(column),
142
- week: expressions.week(column),
143
- }, groupByData);
144
- }
145
- /**
146
- * Group by day only
147
- */
148
- groupByDayOfMonth(column, groupByData) {
149
- column = expressions.$agg.columnName(column);
150
- return this.groupBy({
151
- day: expressions.dayOfMonth(column),
152
- }, groupByData);
153
- }
154
- /**
155
- * Pluck only the given column
156
- */
157
- async pluck(column) {
158
- return await this.select([column]).get(record => reinforcements.get(record, column));
159
- }
160
- /**
161
- * Get average of the given column
162
- */
163
- async avg(column) {
164
- const document = await this.groupBy(null, {
165
- avg: expressions.$agg.avg(column),
166
- }).first(document => document);
167
- return document?.avg || 0;
168
- }
169
- /**
170
- * {@alias} avg
171
- */
172
- average(column) {
173
- return this.avg(column);
174
- }
175
- /**
176
- * Sum values of the given column
177
- */
178
- async sum(column) {
179
- const document = await this.groupBy(null, {
180
- sum: expressions.$agg.sum(column),
181
- }).first(document => document);
182
- return document?.sum || 0;
183
- }
184
- /**
185
- * Get minimum value of the given column
186
- */
187
- async min(column) {
188
- const document = await this.groupBy(null, {
189
- min: expressions.$agg.min(column),
190
- }).first(document => document);
191
- return document?.min || 0;
192
- }
193
- /**
194
- * Get maximum value of the given column
195
- */
196
- async max(column) {
197
- const document = await this.groupBy(null, {
198
- max: expressions.$agg.max(column),
199
- }).first(document => document);
200
- return document?.max || 0;
201
- }
202
- /**
203
- * Get distinct value for the given column using aggregation
204
- */
205
- async distinct(column) {
206
- return (await this.groupBy(null, {
207
- // use addToSet to get unique values
208
- [column]: expressions.$agg.addToSet(column),
209
- })
210
- .select([column])
211
- .get(data => data[column]));
212
- }
213
- /**
214
- * {@alias} distinct
215
- */
216
- unique(column) {
217
- return this.distinct(column);
218
- }
219
- /**
220
- * Get distinct values that are not empty
221
- */
222
- async distinctHeavy(column) {
223
- return await this.whereNotNull(column).distinct(column);
224
- }
225
- /**
226
- * {@alias} distinctHeavy
227
- */
228
- async uniqueHeavy(column) {
229
- return await this.distinctHeavy(column);
230
- }
231
- /**
232
- * Get values list of the given column
233
- */
234
- async values(column) {
235
- return (await this.groupBy(null, {
236
- values: expressions.$agg.push(column),
237
- })
238
- .select(["values"])
239
- .get(data => data.values));
240
- }
241
- /**
242
- * Limit the number of results
243
- */
244
- limit(limit) {
245
- return this.pipeline(new LimitPipeline.LimitPipeline(limit));
246
- }
247
- /**
248
- * Skip the given number of results
249
- */
250
- skip(skip) {
251
- return this.pipeline(new SkipPipeline.SkipPipeline(skip));
252
- }
253
- select(...columns) {
254
- if (columns.length === 1 && Array.isArray(columns[0])) {
255
- columns = columns[0];
256
- }
257
- return this.pipeline(new SelectPipeline.SelectPipeline(columns));
258
- }
259
- /**
260
- * Deselect the given columns
261
- */
262
- deselect(columns) {
263
- return this.pipeline(new DeselectPipeline.DeselectPipeline(columns));
264
- }
265
- /**
266
- * Unwind/Extract the given column
267
- */
268
- unwind(column, options) {
269
- return this.pipeline(new UnwindPipeline.UnwindPipeline(column, options));
270
- }
271
- where(...args) {
272
- return this.pipeline(new WherePipeline.WherePipeline(WhereExpression.WhereExpression.parse.apply(null, args)));
273
- }
274
- /**
275
- * Add comparison between two or more columns
276
- */
277
- whereColumns(column1, operator, ...otherColumns) {
278
- const mongoOperator = WhereExpression.toOperator(operator) || operator;
279
- return this.where(expressions.$agg.expr({
280
- [mongoOperator]: [
281
- expressions.$agg.columnName(column1),
282
- ...otherColumns.map(column => expressions.$agg.columnName(column)),
283
- ],
284
- }));
285
- }
286
- orWhere(column) {
287
- return this.pipeline(new OrWherePipeline.OrWherePipeline(column));
288
- }
289
- /**
290
- * Perform a text search
291
- * Please note that this method will add the `match` stage to the beginning of the pipeline
292
- * Also it will add `score` field to the result automatically
293
- *
294
- * @warning This method will not work if the collection is not indexed for text search
295
- */
296
- textSearch(query, moreFilters) {
297
- this.pipelines.unshift({
298
- $match: {
299
- $text: { $search: query },
300
- ...moreFilters,
301
- },
302
- });
303
- this.addField("score", { $meta: "textScore" });
304
- return this;
305
- }
306
- /**
307
- * Where null
308
- */
309
- whereNull(column) {
310
- return this.where(column, null);
311
- }
312
- /**
313
- * Check if the given column array has the given value or it is empty
314
- * Empty means either the array column does not exists or exists but empty
315
- *
316
- * @usecase for when to use this method is when you have lessons collection and you want to get all lessons that either does not have column `allowedStudents`
317
- * or has an empty array of `allowedStudents` or the `allowedStudents` column has the given student id
318
- *
319
- * Passing third argument empty means we will check directly in the given array (not array of objects in this case)
320
- */
321
- whereArrayHasOrEmpty(column, value, key = "id") {
322
- const keyName = key ? `.${key}` : "";
323
- return this.orWhere([
324
- {
325
- [`${column}${keyName}`]: value,
326
- },
327
- {
328
- [column]: { $size: 0 },
329
- },
330
- {
331
- [column]: { $exists: false },
332
- },
333
- ]);
334
- }
335
- /**
336
- * Check if the given column array does not have the given value or it is empty.
337
- * Empty means either the array column does not exist or exists but is empty.
338
- *
339
- * @usecase This method is useful when you have a collection, such as `lessons`, and you want to retrieve all lessons that either column `excludedStudents` does not contain the specified student id,
340
- * have an empty array for `excludedStudents`, or the `excludedStudents` does not exist.
341
- */
342
- whereArrayNotHaveOrEmpty(column, value, key = "id") {
343
- const keyName = key ? `.${key}` : "";
344
- return this.orWhere([
345
- {
346
- [`${column}${keyName}`]: { $ne: value },
347
- },
348
- {
349
- [column]: { $size: 0 },
350
- },
351
- {
352
- [column]: { $exists: false },
353
- },
354
- ]);
355
- }
356
- /**
357
- * Where not null
358
- */
359
- whereNotNull(column) {
360
- return this.where(column, "!=", null);
361
- }
362
- /**
363
- * Where like operator
364
- */
365
- whereLike(column, value) {
366
- return this.where(column, "like", value);
367
- }
368
- /**
369
- * Where not like operator
370
- */
371
- whereNotLike(column, value) {
372
- return this.where(column, "notLike", value);
373
- }
374
- /**
375
- * Where column starts with the given value
376
- */
377
- whereStartsWith(column, value) {
378
- return this.where(column, "startsWith", value);
379
- }
380
- /**
381
- * Where column not starts with the given value
382
- */
383
- whereNotStartsWith(column, value) {
384
- return this.where(column, "notStartsWith", value);
385
- }
386
- /**
387
- * Where column ends with the given value
388
- */
389
- whereEndsWith(column, value) {
390
- return this.where(column, "endsWith", value);
391
- }
392
- /**
393
- * Where column not ends with the given value
394
- */
395
- whereNotEndsWith(column, value) {
396
- return this.where(column, "notEndsWith", value);
397
- }
398
- /**
399
- * Where between operator
400
- */
401
- whereBetween(column, value) {
402
- return this.where(column, "between", value);
403
- }
404
- /**
405
- * Where date between operator
406
- */
407
- whereDateBetween(column, value) {
408
- return this.where(column, "between", value);
409
- }
410
- /**
411
- * Where date not between operator
412
- */
413
- whereDateNotBetween(column, value) {
414
- return this.where(column, "notBetween", value);
415
- }
416
- /**
417
- * Where not between operator
418
- */
419
- whereNotBetween(column, value) {
420
- return this.where(column, "notBetween", value);
421
- }
422
- /**
423
- * Where exists operator
424
- */
425
- whereExists(column) {
426
- return this.where(column, "exists", true);
427
- }
428
- /**
429
- * Where not exists operator
430
- */
431
- whereNotExists(column) {
432
- return this.where(column, "exists", false);
433
- }
434
- whereSize(...args) {
435
- // first we need to project the column to get the size
436
- const [column, operator, columnSize] = args;
437
- this.project({
438
- [column + "_size"]: {
439
- $size: expressions.$agg.columnName(column),
440
- },
441
- });
442
- // then we can use the size operator
443
- this.where(column + "_size", operator, columnSize);
444
- // now we need to deselect the column size
445
- // this.project({
446
- // [column + "_size"]: 0,
447
- // });
448
- return this;
449
- }
450
- /**
451
- * Add project pipeline
452
- *
453
- */
454
- project(data) {
455
- return this.addPipeline({
456
- $project: data,
457
- });
458
- }
459
- /**
460
- * Where in operator
461
- * If value is a string, it will be treated as a column name
462
- */
463
- whereIn(column, values) {
464
- return this.where(column, "in", values);
465
- }
466
- /**
467
- * Where not in operator
468
- * If value is a string, it will be treated as a column name
469
- */
470
- whereNotIn(column, values) {
471
- return this.where(column, "notIn", values);
472
- }
473
- /**
474
- * // TODO: Make a proper implementation
475
- * Where location near
476
- */
477
- whereNear(column, value, _distance) {
478
- return this.where(column, "near", value);
479
- }
480
- /**
481
- * // TODO: Make a proper implementation
482
- * Get nearby location between the given min and max distance
483
- */
484
- async whereNearByIn(column, value, _minDistance, _maxDistance) {
485
- return this.where(column, value);
486
- }
487
- /**
488
- * Lookup the given collection
489
- */
490
- lookup(options) {
491
- this.pipeline(new LookupPipeline.LookupPipeline(options));
492
- if (options.single && options.as) {
493
- const as = options.as;
494
- this.addField(as, expressions.last(as));
495
- }
496
- return this;
497
- }
498
- /**
499
- * Add field to the pipeline
500
- */
501
- addField(field, value) {
502
- return this.addPipeline({
503
- $addFields: {
504
- [field]: value,
505
- },
506
- });
507
- }
508
- /**
509
- * Add fields to the pipeline
510
- */
511
- addFields(fields) {
512
- return this.addPipeline({
513
- $addFields: fields,
514
- });
515
- }
516
- /**
517
- * Get new pipeline instance
518
- */
519
- pipeline(...pipelines) {
520
- this.pipelines.push(...pipelines);
521
- return this;
522
- }
523
- /**
524
- * Unshift pipeline to the beginning of the pipelines
525
- */
526
- unshiftPipelines(pipelines) {
527
- this.pipelines.unshift(...pipelines);
528
- return this;
529
- }
530
- /**
531
- * Add mongodb plain stage
532
- */
533
- addPipeline(pipeline) {
534
- this.pipelines.push(pipeline);
535
- return this;
536
- }
537
- /**
538
- * Add mongodb plain stages
539
- */
540
- addPipelines(pipelines) {
541
- this.pipelines.push(...pipelines);
542
- return this;
543
- }
544
- /**
545
- * Get pipelines
546
- */
547
- getPipelines() {
548
- return this.pipelines;
549
- }
550
- /**
551
- * Determine if record exists
552
- */
553
- async exists() {
554
- return (await this.limit(1).count()) > 0;
555
- }
556
- /**
557
- * {@inheritdoc}
558
- */
559
- toJSON() {
560
- return this.parse();
561
- }
562
- /**
563
- * Get only first result
564
- */
565
- async first(mapData) {
566
- const results = await this.limit(1).get(mapData);
567
- return results[0];
568
- }
569
- /**
570
- * Get last result
571
- */
572
- async last(filters) {
573
- if (filters) {
574
- this.where(filters);
575
- }
576
- const results = await this.orderByDesc("id").limit(1).get();
577
- return results[0];
578
- }
579
- /**
580
- * Delete records
581
- */
582
- async delete() {
583
- const ids = await (await this.select(["_id"]).pluck("_id")).map(_id => new mongodb.ObjectId(_id));
584
- Aggregate._events.trigger("deleting", this);
585
- return await query.query.delete(this.collection, {
586
- _id: ids,
587
- });
588
- }
589
- /**
590
- * Get the data
591
- */
592
- async get(mapData) {
593
- const records = await this.execute();
594
- return mapData ? records.map(mapData) : records;
595
- }
596
- /**
597
- * Chunk documents based on the given limit
598
- */
599
- async chunk(limit, callback, mapData) {
600
- const totalDocuments = await this.clone().count();
601
- const totalPages = Math.ceil(totalDocuments / limit);
602
- for (let page = 1; page <= totalPages; page++) {
603
- const results = await this.clone().paginate(page, limit, mapData);
604
- const { documents, paginationInfo } = results;
605
- const output = await callback(documents, paginationInfo);
606
- if (output === false)
607
- break;
608
- }
609
- }
610
- /**
611
- * Paginate records based on the given filter
612
- */
613
- async paginate(page = 1, limit = 15, mapData) {
614
- const totalDocumentsQuery = this.parse();
615
- this.skip((page - 1) * limit).limit(limit);
616
- const records = await this.get(mapData);
617
- this.pipelines = totalDocumentsQuery;
618
- const totalDocuments = await this.count();
619
- const result = {
620
- documents: records,
621
- paginationInfo: {
622
- limit,
623
- page,
624
- result: records.length,
625
- total: totalDocuments,
626
- pages: Math.ceil(totalDocuments / limit),
627
- },
628
- };
629
- return result;
630
- }
631
- /**
632
- * Use cursor pagination-based for better performance
633
- */
634
- async cursorPaginate(options, mapData) {
635
- if (options.cursorId) {
636
- this.where(options.column ?? "id", options.direction === "next" ? ">" : "<", options.cursorId);
637
- }
638
- // now set the limit
639
- // we need to increase the limit by 1 to check if we have more records
640
- this.limit(options.limit + 1);
641
- const records = await this.execute();
642
- // now let's check if we have more records
643
- const hasMore = records.length > options.limit;
644
- let nextCursorId = null;
645
- if (hasMore) {
646
- // Remove the extra fetched record depending on the pagination direction
647
- const record = options.direction === "next"
648
- ? records.pop() // Forward: pop the last record
649
- : records.shift(); // Backward: shift the first record
650
- // Get the next cursor id from the popped or shifted record
651
- nextCursorId = reinforcements.get(record, options.column ?? "id");
652
- }
653
- return {
654
- documents: mapData ? records.map(mapData) : records,
655
- hasMore,
656
- nextCursorId,
657
- };
658
- }
659
- /**
660
- * Explain the query
661
- */
662
- async explain() {
663
- return (await this.query.aggregate(this.collection, this.parse(), {
664
- explain: true,
665
- })).explain();
666
- }
667
- /**
668
- * Update the given data
669
- */
670
- async update(data) {
671
- try {
672
- const query = [];
673
- const filters = {};
674
- this.parse().forEach(pipeline => {
675
- if (pipeline.$match) {
676
- Object.assign(filters, pipeline.$match);
677
- }
678
- else {
679
- query.push(pipeline);
680
- }
681
- });
682
- Aggregate._events.trigger("updating", this);
683
- const results = await this.query.updateMany(this.collection, filters, [
684
- ...query,
685
- {
686
- $set: WhereExpression.parseValuesInObject(data),
687
- },
688
- ]);
689
- return results.modifiedCount;
690
- }
691
- catch (error) {
692
- logger.log.error("database", "aggregate.update", error);
693
- throw error;
694
- }
695
- }
696
- /**
697
- * Increment the given column
698
- */
699
- async increment(column, value = 1) {
700
- try {
701
- const query = [];
702
- const filters = {};
703
- this.parse().forEach(pipeline => {
704
- if (pipeline.$match) {
705
- Object.assign(filters, pipeline.$match);
706
- }
707
- else {
708
- query.push(pipeline);
709
- }
710
- });
711
- Aggregate._events.trigger("updating", this);
712
- let incrementData;
713
- if (typeof column === "string") {
714
- incrementData = { [column]: value };
715
- }
716
- else if (Array.isArray(column)) {
717
- incrementData = column.reduce((acc, col) => {
718
- acc[col] = value;
719
- return acc;
720
- }, {});
721
- }
722
- else {
723
- incrementData = column;
724
- }
725
- const results = await this.query.updateMany(this.collection, filters, [
726
- ...query,
727
- {
728
- $inc: incrementData,
729
- },
730
- ]);
731
- return results.modifiedCount;
732
- }
733
- catch (error) {
734
- logger.log.error("database", "aggregate.increment", error);
735
- throw error;
736
- }
737
- }
738
- /**
739
- * Decrement the given column(s)
740
- */
741
- async decrement(column, value = 1) {
742
- return this.increment(column, -value);
743
- }
744
- /**
745
- * Multiply the given column(s)
746
- */
747
- async multiply(column, value) {
748
- try {
749
- const query = [];
750
- const filters = {};
751
- this.parse().forEach(pipeline => {
752
- if (pipeline.$match) {
753
- Object.assign(filters, pipeline.$match);
754
- }
755
- else {
756
- query.push(pipeline);
757
- }
758
- });
759
- Aggregate._events.trigger("updating", this);
760
- let multiplyData;
761
- if (typeof column === "string") {
762
- multiplyData = { [column]: value };
763
- }
764
- else if (Array.isArray(column)) {
765
- multiplyData = column.reduce((acc, col) => {
766
- acc[col] = value;
767
- return acc;
768
- }, {});
769
- }
770
- else {
771
- multiplyData = column;
772
- }
773
- const results = await this.query.updateMany(this.collection, filters, [
774
- ...query,
775
- {
776
- $mul: multiplyData,
777
- },
778
- ]);
779
- return results.modifiedCount;
780
- }
781
- catch (error) {
782
- logger.log.error("database", "aggregate.multiply", error);
783
- throw error;
784
- }
785
- }
786
- /**
787
- * Divide the given column(s)
788
- */
789
- async divide(column, value) {
790
- if (value === 0) {
791
- throw new Error("Division by zero is not allowed.");
792
- }
793
- try {
794
- const query = [];
795
- const filters = {};
796
- this.parse().forEach(pipeline => {
797
- if (pipeline.$match) {
798
- Object.assign(filters, pipeline.$match);
799
- }
800
- else {
801
- query.push(pipeline);
802
- }
803
- });
804
- Aggregate._events.trigger("updating", this);
805
- let divideData;
806
- if (typeof column === "string") {
807
- divideData = { [column]: 1 / value };
808
- }
809
- else if (Array.isArray(column)) {
810
- divideData = column.reduce((acc, col) => {
811
- acc[col] = 1 / value;
812
- return acc;
813
- }, {});
814
- }
815
- else {
816
- divideData = Object.fromEntries(Object.entries(column).map(([key, val]) => [key, 1 / val]));
817
- }
818
- const results = await this.query.updateMany(this.collection, filters, [
819
- ...query,
820
- {
821
- $mul: divideData,
822
- },
823
- ]);
824
- return results.modifiedCount;
825
- }
826
- catch (error) {
827
- logger.log.error("database", "aggregate.divide", error);
828
- throw error;
829
- }
830
- }
831
- /**
832
- * Unset the given columns
833
- */
834
- async unset(...columns) {
835
- try {
836
- const query = [];
837
- const filters = {};
838
- this.parse().forEach(pipeline => {
839
- if (pipeline.$match) {
840
- Object.assign(filters, pipeline.$match);
841
- }
842
- else {
843
- query.push(pipeline);
844
- }
845
- });
846
- Aggregate._events.trigger("updating", this);
847
- const results = await this.query.updateMany(this.collection, filters, [
848
- ...query,
849
- {
850
- $unset: columns,
851
- },
852
- ]);
853
- return results.modifiedCount;
854
- }
855
- catch (error) {
856
- logger.log.error("database", "aggregate.unset", error);
857
- console.log(error);
858
- throw error;
859
- }
860
- }
861
- /**
862
- * Execute the query
863
- */
864
- async execute() {
865
- const results = (await this.query.aggregate(this.collection, this.parse())).toArray();
866
- return results;
867
- }
868
- /**
869
- * Count the results
870
- */
871
- async count() {
872
- this.groupBy(null, {
873
- total: expressions.count(),
874
- });
875
- const results = await this.execute();
876
- return reinforcements.get(results, "0.total", 0);
877
- }
878
- /**
879
- * Parse pipelines
880
- */
881
- parse() {
882
- return parsePipelines.parsePipelines(this.pipelines);
883
- }
884
- /**
885
- * Reset the pipeline
886
- */
887
- reset() {
888
- this.pipelines = [];
889
- return this;
890
- }
891
- /**
892
- * Clone the aggregate class
893
- */
894
- clone() {
895
- const aggregate = new this.constructor(this.collection);
896
- aggregate.pipelines = this.pipelines.slice();
897
- return aggregate;
898
- }
899
- /**
900
- * Apply filters to the query
901
- */
902
- applyFilters(filters, data = {}, options = {}) {
903
- applyFilters.applyFilters({
904
- query: this,
905
- filters,
906
- data,
907
- options,
908
- });
909
- return this;
910
- }
911
- }exports.Aggregate=Aggregate;//# sourceMappingURL=aggregate.js.map