@warlock.js/cascade 4.0.157 → 4.0.161

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 (689) hide show
  1. package/package.json +4 -4
  2. package/cjs/context/database-data-source-context.d.ts +0 -29
  3. package/cjs/context/database-data-source-context.d.ts.map +0 -1
  4. package/cjs/context/database-data-source-context.js +0 -28
  5. package/cjs/context/database-data-source-context.js.map +0 -1
  6. package/cjs/context/database-transaction-context.d.ts +0 -35
  7. package/cjs/context/database-transaction-context.d.ts.map +0 -1
  8. package/cjs/context/database-transaction-context.js +0 -40
  9. package/cjs/context/database-transaction-context.js.map +0 -1
  10. package/cjs/contracts/database-driver.contract.d.ts +0 -450
  11. package/cjs/contracts/database-driver.contract.d.ts.map +0 -1
  12. package/cjs/contracts/database-id-generator.contract.d.ts +0 -109
  13. package/cjs/contracts/database-id-generator.contract.d.ts.map +0 -1
  14. package/cjs/contracts/database-remover.contract.d.ts +0 -104
  15. package/cjs/contracts/database-remover.contract.d.ts.map +0 -1
  16. package/cjs/contracts/database-restorer.contract.d.ts +0 -143
  17. package/cjs/contracts/database-restorer.contract.d.ts.map +0 -1
  18. package/cjs/contracts/database-writer.contract.d.ts +0 -119
  19. package/cjs/contracts/database-writer.contract.d.ts.map +0 -1
  20. package/cjs/contracts/driver-blueprint.contract.d.ts +0 -49
  21. package/cjs/contracts/driver-blueprint.contract.d.ts.map +0 -1
  22. package/cjs/contracts/index.d.ts +0 -10
  23. package/cjs/contracts/index.d.ts.map +0 -1
  24. package/cjs/contracts/migration-driver.contract.d.ts +0 -522
  25. package/cjs/contracts/migration-driver.contract.d.ts.map +0 -1
  26. package/cjs/contracts/query-builder.contract.d.ts +0 -1609
  27. package/cjs/contracts/query-builder.contract.d.ts.map +0 -1
  28. package/cjs/contracts/sync-adapter.contract.d.ts +0 -58
  29. package/cjs/contracts/sync-adapter.contract.d.ts.map +0 -1
  30. package/cjs/data-source/data-source-registry.d.ts +0 -108
  31. package/cjs/data-source/data-source-registry.d.ts.map +0 -1
  32. package/cjs/data-source/data-source-registry.js +0 -145
  33. package/cjs/data-source/data-source-registry.js.map +0 -1
  34. package/cjs/data-source/data-source.d.ts +0 -147
  35. package/cjs/data-source/data-source.d.ts.map +0 -1
  36. package/cjs/data-source/data-source.js +0 -83
  37. package/cjs/data-source/data-source.js.map +0 -1
  38. package/cjs/database-dirty-tracker.d.ts +0 -252
  39. package/cjs/database-dirty-tracker.d.ts.map +0 -1
  40. package/cjs/database-dirty-tracker.js +0 -386
  41. package/cjs/database-dirty-tracker.js.map +0 -1
  42. package/cjs/drivers/mongodb/mongodb-blueprint.d.ts +0 -30
  43. package/cjs/drivers/mongodb/mongodb-blueprint.d.ts.map +0 -1
  44. package/cjs/drivers/mongodb/mongodb-blueprint.js +0 -51
  45. package/cjs/drivers/mongodb/mongodb-blueprint.js.map +0 -1
  46. package/cjs/drivers/mongodb/mongodb-driver.d.ts +0 -324
  47. package/cjs/drivers/mongodb/mongodb-driver.d.ts.map +0 -1
  48. package/cjs/drivers/mongodb/mongodb-driver.js +0 -799
  49. package/cjs/drivers/mongodb/mongodb-driver.js.map +0 -1
  50. package/cjs/drivers/mongodb/mongodb-id-generator.d.ts +0 -116
  51. package/cjs/drivers/mongodb/mongodb-id-generator.d.ts.map +0 -1
  52. package/cjs/drivers/mongodb/mongodb-id-generator.js +0 -149
  53. package/cjs/drivers/mongodb/mongodb-id-generator.js.map +0 -1
  54. package/cjs/drivers/mongodb/mongodb-migration-driver.d.ts +0 -317
  55. package/cjs/drivers/mongodb/mongodb-migration-driver.d.ts.map +0 -1
  56. package/cjs/drivers/mongodb/mongodb-migration-driver.js +0 -666
  57. package/cjs/drivers/mongodb/mongodb-migration-driver.js.map +0 -1
  58. package/cjs/drivers/mongodb/mongodb-query-builder.d.ts +0 -1122
  59. package/cjs/drivers/mongodb/mongodb-query-builder.d.ts.map +0 -1
  60. package/cjs/drivers/mongodb/mongodb-query-builder.js +0 -1988
  61. package/cjs/drivers/mongodb/mongodb-query-builder.js.map +0 -1
  62. package/cjs/drivers/mongodb/mongodb-query-operations.d.ts +0 -226
  63. package/cjs/drivers/mongodb/mongodb-query-operations.d.ts.map +0 -1
  64. package/cjs/drivers/mongodb/mongodb-query-operations.js +0 -270
  65. package/cjs/drivers/mongodb/mongodb-query-operations.js.map +0 -1
  66. package/cjs/drivers/mongodb/mongodb-query-parser.d.ts +0 -262
  67. package/cjs/drivers/mongodb/mongodb-query-parser.d.ts.map +0 -1
  68. package/cjs/drivers/mongodb/mongodb-query-parser.js +0 -1351
  69. package/cjs/drivers/mongodb/mongodb-query-parser.js.map +0 -1
  70. package/cjs/drivers/mongodb/mongodb-sync-adapter.d.ts +0 -79
  71. package/cjs/drivers/mongodb/mongodb-sync-adapter.d.ts.map +0 -1
  72. package/cjs/drivers/mongodb/mongodb-sync-adapter.js +0 -146
  73. package/cjs/drivers/mongodb/mongodb-sync-adapter.js.map +0 -1
  74. package/cjs/drivers/mongodb/types.d.ts +0 -43
  75. package/cjs/drivers/mongodb/types.d.ts.map +0 -1
  76. package/cjs/drivers/postgres/index.d.ts +0 -16
  77. package/cjs/drivers/postgres/index.d.ts.map +0 -1
  78. package/cjs/drivers/postgres/postgres-blueprint.d.ts +0 -64
  79. package/cjs/drivers/postgres/postgres-blueprint.d.ts.map +0 -1
  80. package/cjs/drivers/postgres/postgres-blueprint.js +0 -121
  81. package/cjs/drivers/postgres/postgres-blueprint.js.map +0 -1
  82. package/cjs/drivers/postgres/postgres-dialect.d.ts +0 -136
  83. package/cjs/drivers/postgres/postgres-dialect.d.ts.map +0 -1
  84. package/cjs/drivers/postgres/postgres-dialect.js +0 -268
  85. package/cjs/drivers/postgres/postgres-dialect.js.map +0 -1
  86. package/cjs/drivers/postgres/postgres-driver.d.ts +0 -432
  87. package/cjs/drivers/postgres/postgres-driver.d.ts.map +0 -1
  88. package/cjs/drivers/postgres/postgres-driver.js +0 -965
  89. package/cjs/drivers/postgres/postgres-driver.js.map +0 -1
  90. package/cjs/drivers/postgres/postgres-migration-driver.d.ts +0 -397
  91. package/cjs/drivers/postgres/postgres-migration-driver.d.ts.map +0 -1
  92. package/cjs/drivers/postgres/postgres-migration-driver.js +0 -900
  93. package/cjs/drivers/postgres/postgres-migration-driver.js.map +0 -1
  94. package/cjs/drivers/postgres/postgres-query-builder.d.ts +0 -254
  95. package/cjs/drivers/postgres/postgres-query-builder.d.ts.map +0 -1
  96. package/cjs/drivers/postgres/postgres-query-builder.js +0 -933
  97. package/cjs/drivers/postgres/postgres-query-builder.js.map +0 -1
  98. package/cjs/drivers/postgres/postgres-query-parser.d.ts +0 -328
  99. package/cjs/drivers/postgres/postgres-query-parser.d.ts.map +0 -1
  100. package/cjs/drivers/postgres/postgres-query-parser.js +0 -864
  101. package/cjs/drivers/postgres/postgres-query-parser.js.map +0 -1
  102. package/cjs/drivers/postgres/postgres-sql-serializer.d.ts +0 -37
  103. package/cjs/drivers/postgres/postgres-sql-serializer.d.ts.map +0 -1
  104. package/cjs/drivers/postgres/postgres-sql-serializer.js +0 -400
  105. package/cjs/drivers/postgres/postgres-sql-serializer.js.map +0 -1
  106. package/cjs/drivers/postgres/postgres-sync-adapter.d.ts +0 -83
  107. package/cjs/drivers/postgres/postgres-sync-adapter.d.ts.map +0 -1
  108. package/cjs/drivers/postgres/postgres-sync-adapter.js +0 -197
  109. package/cjs/drivers/postgres/postgres-sync-adapter.js.map +0 -1
  110. package/cjs/drivers/postgres/types.d.ts +0 -142
  111. package/cjs/drivers/postgres/types.d.ts.map +0 -1
  112. package/cjs/drivers/sql/index.d.ts +0 -10
  113. package/cjs/drivers/sql/index.d.ts.map +0 -1
  114. package/cjs/drivers/sql/sql-dialect.contract.d.ts +0 -204
  115. package/cjs/drivers/sql/sql-dialect.contract.d.ts.map +0 -1
  116. package/cjs/drivers/sql/sql-types.d.ts +0 -202
  117. package/cjs/drivers/sql/sql-types.d.ts.map +0 -1
  118. package/cjs/errors/missing-data-source.error.d.ts +0 -22
  119. package/cjs/errors/missing-data-source.error.d.ts.map +0 -1
  120. package/cjs/errors/missing-data-source.error.js +0 -29
  121. package/cjs/errors/missing-data-source.error.js.map +0 -1
  122. package/cjs/errors/transaction-rollback.error.d.ts +0 -20
  123. package/cjs/errors/transaction-rollback.error.d.ts.map +0 -1
  124. package/cjs/errors/transaction-rollback.error.js +0 -27
  125. package/cjs/errors/transaction-rollback.error.js.map +0 -1
  126. package/cjs/events/model-events.d.ts +0 -231
  127. package/cjs/events/model-events.d.ts.map +0 -1
  128. package/cjs/events/model-events.js +0 -259
  129. package/cjs/events/model-events.js.map +0 -1
  130. package/cjs/expressions/aggregate-expressions.d.ts +0 -215
  131. package/cjs/expressions/aggregate-expressions.d.ts.map +0 -1
  132. package/cjs/expressions/aggregate-expressions.js +0 -221
  133. package/cjs/expressions/aggregate-expressions.js.map +0 -1
  134. package/cjs/expressions/index.d.ts +0 -2
  135. package/cjs/expressions/index.d.ts.map +0 -1
  136. package/cjs/index.d.ts +0 -45
  137. package/cjs/index.d.ts.map +0 -1
  138. package/cjs/index.js +0 -1
  139. package/cjs/index.js.map +0 -1
  140. package/cjs/migration/column-builder.d.ts +0 -417
  141. package/cjs/migration/column-builder.d.ts.map +0 -1
  142. package/cjs/migration/column-builder.js +0 -586
  143. package/cjs/migration/column-builder.js.map +0 -1
  144. package/cjs/migration/column-helpers.d.ts +0 -275
  145. package/cjs/migration/column-helpers.d.ts.map +0 -1
  146. package/cjs/migration/column-helpers.js +0 -389
  147. package/cjs/migration/column-helpers.js.map +0 -1
  148. package/cjs/migration/foreign-key-builder.d.ts +0 -103
  149. package/cjs/migration/foreign-key-builder.d.ts.map +0 -1
  150. package/cjs/migration/foreign-key-builder.js +0 -121
  151. package/cjs/migration/foreign-key-builder.js.map +0 -1
  152. package/cjs/migration/index.d.ts +0 -7
  153. package/cjs/migration/index.d.ts.map +0 -1
  154. package/cjs/migration/migration-runner.d.ts +0 -278
  155. package/cjs/migration/migration-runner.d.ts.map +0 -1
  156. package/cjs/migration/migration-runner.js +0 -815
  157. package/cjs/migration/migration-runner.js.map +0 -1
  158. package/cjs/migration/migration.d.ts +0 -1992
  159. package/cjs/migration/migration.d.ts.map +0 -1
  160. package/cjs/migration/migration.js +0 -2162
  161. package/cjs/migration/migration.js.map +0 -1
  162. package/cjs/migration/sql-grammar.d.ts +0 -61
  163. package/cjs/migration/sql-grammar.d.ts.map +0 -1
  164. package/cjs/migration/sql-grammar.js +0 -164
  165. package/cjs/migration/sql-grammar.js.map +0 -1
  166. package/cjs/migration/sql-serializer.d.ts +0 -22
  167. package/cjs/migration/sql-serializer.d.ts.map +0 -1
  168. package/cjs/migration/sql-serializer.js +0 -26
  169. package/cjs/migration/sql-serializer.js.map +0 -1
  170. package/cjs/migration/types.d.ts +0 -155
  171. package/cjs/migration/types.d.ts.map +0 -1
  172. package/cjs/model/methods/accessor-methods.d.ts +0 -13
  173. package/cjs/model/methods/accessor-methods.d.ts.map +0 -1
  174. package/cjs/model/methods/accessor-methods.js +0 -51
  175. package/cjs/model/methods/accessor-methods.js.map +0 -1
  176. package/cjs/model/methods/delete-methods.d.ts +0 -10
  177. package/cjs/model/methods/delete-methods.d.ts.map +0 -1
  178. package/cjs/model/methods/delete-methods.js +0 -10
  179. package/cjs/model/methods/delete-methods.js.map +0 -1
  180. package/cjs/model/methods/dirty-methods.d.ts +0 -10
  181. package/cjs/model/methods/dirty-methods.d.ts.map +0 -1
  182. package/cjs/model/methods/dirty-methods.js +0 -15
  183. package/cjs/model/methods/dirty-methods.js.map +0 -1
  184. package/cjs/model/methods/hydration-methods.d.ts +0 -10
  185. package/cjs/model/methods/hydration-methods.d.ts.map +0 -1
  186. package/cjs/model/methods/hydration-methods.js +0 -57
  187. package/cjs/model/methods/hydration-methods.js.map +0 -1
  188. package/cjs/model/methods/instance-event-methods.d.ts +0 -7
  189. package/cjs/model/methods/instance-event-methods.d.ts.map +0 -1
  190. package/cjs/model/methods/instance-event-methods.js +0 -15
  191. package/cjs/model/methods/instance-event-methods.js.map +0 -1
  192. package/cjs/model/methods/meta-methods.d.ts +0 -7
  193. package/cjs/model/methods/meta-methods.d.ts.map +0 -1
  194. package/cjs/model/methods/meta-methods.js +0 -78
  195. package/cjs/model/methods/meta-methods.js.map +0 -1
  196. package/cjs/model/methods/query-methods.d.ts +0 -24
  197. package/cjs/model/methods/query-methods.d.ts.map +0 -1
  198. package/cjs/model/methods/query-methods.js +0 -161
  199. package/cjs/model/methods/query-methods.js.map +0 -1
  200. package/cjs/model/methods/restore-methods.d.ts +0 -10
  201. package/cjs/model/methods/restore-methods.d.ts.map +0 -1
  202. package/cjs/model/methods/restore-methods.js +0 -13
  203. package/cjs/model/methods/restore-methods.js.map +0 -1
  204. package/cjs/model/methods/scope-methods.d.ts +0 -7
  205. package/cjs/model/methods/scope-methods.d.ts.map +0 -1
  206. package/cjs/model/methods/scope-methods.js +0 -15
  207. package/cjs/model/methods/scope-methods.js.map +0 -1
  208. package/cjs/model/methods/serialization-methods.d.ts +0 -3
  209. package/cjs/model/methods/serialization-methods.d.ts.map +0 -1
  210. package/cjs/model/methods/serialization-methods.js +0 -27
  211. package/cjs/model/methods/serialization-methods.js.map +0 -1
  212. package/cjs/model/methods/static-event-methods.d.ts +0 -9
  213. package/cjs/model/methods/static-event-methods.d.ts.map +0 -1
  214. package/cjs/model/methods/static-event-methods.js +0 -29
  215. package/cjs/model/methods/static-event-methods.js.map +0 -1
  216. package/cjs/model/methods/write-methods.d.ts +0 -10
  217. package/cjs/model/methods/write-methods.d.ts.map +0 -1
  218. package/cjs/model/methods/write-methods.js +0 -52
  219. package/cjs/model/methods/write-methods.js.map +0 -1
  220. package/cjs/model/model.d.ts +0 -1650
  221. package/cjs/model/model.d.ts.map +0 -1
  222. package/cjs/model/model.js +0 -1657
  223. package/cjs/model/model.js.map +0 -1
  224. package/cjs/model/model.types.d.ts +0 -44
  225. package/cjs/model/model.types.d.ts.map +0 -1
  226. package/cjs/model/register-model.d.ts +0 -81
  227. package/cjs/model/register-model.d.ts.map +0 -1
  228. package/cjs/model/register-model.js +0 -94
  229. package/cjs/model/register-model.js.map +0 -1
  230. package/cjs/query-builder/query-builder.d.ts +0 -556
  231. package/cjs/query-builder/query-builder.d.ts.map +0 -1
  232. package/cjs/query-builder/query-builder.js +0 -1070
  233. package/cjs/query-builder/query-builder.js.map +0 -1
  234. package/cjs/relations/helpers.d.ts +0 -156
  235. package/cjs/relations/helpers.d.ts.map +0 -1
  236. package/cjs/relations/helpers.js +0 -201
  237. package/cjs/relations/helpers.js.map +0 -1
  238. package/cjs/relations/index.d.ts +0 -35
  239. package/cjs/relations/index.d.ts.map +0 -1
  240. package/cjs/relations/pivot-operations.d.ts +0 -160
  241. package/cjs/relations/pivot-operations.d.ts.map +0 -1
  242. package/cjs/relations/pivot-operations.js +0 -293
  243. package/cjs/relations/pivot-operations.js.map +0 -1
  244. package/cjs/relations/relation-hydrator.d.ts +0 -68
  245. package/cjs/relations/relation-hydrator.d.ts.map +0 -1
  246. package/cjs/relations/relation-hydrator.js +0 -81
  247. package/cjs/relations/relation-hydrator.js.map +0 -1
  248. package/cjs/relations/relation-loader.d.ts +0 -194
  249. package/cjs/relations/relation-loader.d.ts.map +0 -1
  250. package/cjs/relations/relation-loader.js +0 -466
  251. package/cjs/relations/relation-loader.js.map +0 -1
  252. package/cjs/relations/types.d.ts +0 -306
  253. package/cjs/relations/types.d.ts.map +0 -1
  254. package/cjs/remover/database-remover.d.ts +0 -100
  255. package/cjs/remover/database-remover.d.ts.map +0 -1
  256. package/cjs/remover/database-remover.js +0 -214
  257. package/cjs/remover/database-remover.js.map +0 -1
  258. package/cjs/restorer/database-restorer.d.ts +0 -131
  259. package/cjs/restorer/database-restorer.d.ts.map +0 -1
  260. package/cjs/restorer/database-restorer.js +0 -434
  261. package/cjs/restorer/database-restorer.js.map +0 -1
  262. package/cjs/sql-database-dirty-tracker.d.ts +0 -13
  263. package/cjs/sql-database-dirty-tracker.d.ts.map +0 -1
  264. package/cjs/sql-database-dirty-tracker.js +0 -14
  265. package/cjs/sql-database-dirty-tracker.js.map +0 -1
  266. package/cjs/sync/index.d.ts +0 -12
  267. package/cjs/sync/index.d.ts.map +0 -1
  268. package/cjs/sync/model-events.d.ts +0 -62
  269. package/cjs/sync/model-events.d.ts.map +0 -1
  270. package/cjs/sync/model-events.js +0 -49
  271. package/cjs/sync/model-events.js.map +0 -1
  272. package/cjs/sync/model-sync-operation.d.ts +0 -163
  273. package/cjs/sync/model-sync-operation.d.ts.map +0 -1
  274. package/cjs/sync/model-sync-operation.js +0 -292
  275. package/cjs/sync/model-sync-operation.js.map +0 -1
  276. package/cjs/sync/model-sync.d.ts +0 -130
  277. package/cjs/sync/model-sync.d.ts.map +0 -1
  278. package/cjs/sync/model-sync.js +0 -178
  279. package/cjs/sync/model-sync.js.map +0 -1
  280. package/cjs/sync/sync-context.d.ts +0 -70
  281. package/cjs/sync/sync-context.d.ts.map +0 -1
  282. package/cjs/sync/sync-context.js +0 -101
  283. package/cjs/sync/sync-context.js.map +0 -1
  284. package/cjs/sync/sync-manager.d.ts +0 -213
  285. package/cjs/sync/sync-manager.d.ts.map +0 -1
  286. package/cjs/sync/sync-manager.js +0 -689
  287. package/cjs/sync/sync-manager.js.map +0 -1
  288. package/cjs/sync/types.d.ts +0 -289
  289. package/cjs/sync/types.d.ts.map +0 -1
  290. package/cjs/test-migrations/test-enhanced-features.migration.d.ts +0 -15
  291. package/cjs/test-migrations/test-enhanced-features.migration.d.ts.map +0 -1
  292. package/cjs/types.d.ts +0 -371
  293. package/cjs/types.d.ts.map +0 -1
  294. package/cjs/utils/connect-to-database.d.ts +0 -300
  295. package/cjs/utils/connect-to-database.d.ts.map +0 -1
  296. package/cjs/utils/connect-to-database.js +0 -128
  297. package/cjs/utils/connect-to-database.js.map +0 -1
  298. package/cjs/utils/database-writer.utils.d.ts +0 -15
  299. package/cjs/utils/database-writer.utils.d.ts.map +0 -1
  300. package/cjs/utils/database-writer.utils.js +0 -14
  301. package/cjs/utils/database-writer.utils.js.map +0 -1
  302. package/cjs/utils/define-model.js +0 -100
  303. package/cjs/utils/define-model.js.map +0 -1
  304. package/cjs/utils/is-valid-date-value.d.ts +0 -5
  305. package/cjs/utils/is-valid-date-value.d.ts.map +0 -1
  306. package/cjs/utils/is-valid-date-value.js +0 -25
  307. package/cjs/utils/is-valid-date-value.js.map +0 -1
  308. package/cjs/utils/once-connected.d.ts +0 -146
  309. package/cjs/utils/once-connected.d.ts.map +0 -1
  310. package/cjs/utils/once-connected.js +0 -251
  311. package/cjs/utils/once-connected.js.map +0 -1
  312. package/cjs/validation/database-seal-plugins.d.ts +0 -12
  313. package/cjs/validation/database-seal-plugins.d.ts.map +0 -1
  314. package/cjs/validation/database-seal-plugins.js +0 -1
  315. package/cjs/validation/database-seal-plugins.js.map +0 -1
  316. package/cjs/validation/database-writer-validation-error.d.ts +0 -97
  317. package/cjs/validation/database-writer-validation-error.d.ts.map +0 -1
  318. package/cjs/validation/database-writer-validation-error.js +0 -160
  319. package/cjs/validation/database-writer-validation-error.js.map +0 -1
  320. package/cjs/validation/index.d.ts +0 -3
  321. package/cjs/validation/index.d.ts.map +0 -1
  322. package/cjs/validation/mutators/embed-mutator.d.ts +0 -9
  323. package/cjs/validation/mutators/embed-mutator.d.ts.map +0 -1
  324. package/cjs/validation/mutators/embed-mutator.js +0 -33
  325. package/cjs/validation/mutators/embed-mutator.js.map +0 -1
  326. package/cjs/validation/plugins/embed-validator-plugin.d.ts +0 -24
  327. package/cjs/validation/plugins/embed-validator-plugin.d.ts.map +0 -1
  328. package/cjs/validation/plugins/embed-validator-plugin.js +0 -18
  329. package/cjs/validation/plugins/embed-validator-plugin.js.map +0 -1
  330. package/cjs/validation/rules/database-model-rule.d.ts +0 -7
  331. package/cjs/validation/rules/database-model-rule.d.ts.map +0 -1
  332. package/cjs/validation/rules/database-model-rule.js +0 -27
  333. package/cjs/validation/rules/database-model-rule.js.map +0 -1
  334. package/cjs/validation/transformers/embed-model-transformer.d.ts +0 -3
  335. package/cjs/validation/transformers/embed-model-transformer.d.ts.map +0 -1
  336. package/cjs/validation/transformers/embed-model-transformer.js +0 -18
  337. package/cjs/validation/transformers/embed-model-transformer.js.map +0 -1
  338. package/cjs/validation/validators/embed-validator.d.ts +0 -21
  339. package/cjs/validation/validators/embed-validator.d.ts.map +0 -1
  340. package/cjs/validation/validators/embed-validator.js +0 -43
  341. package/cjs/validation/validators/embed-validator.js.map +0 -1
  342. package/cjs/writer/database-writer.d.ts +0 -181
  343. package/cjs/writer/database-writer.d.ts.map +0 -1
  344. package/cjs/writer/database-writer.js +0 -407
  345. package/cjs/writer/database-writer.js.map +0 -1
  346. package/esm/context/database-data-source-context.d.ts +0 -29
  347. package/esm/context/database-data-source-context.d.ts.map +0 -1
  348. package/esm/context/database-data-source-context.js +0 -28
  349. package/esm/context/database-data-source-context.js.map +0 -1
  350. package/esm/context/database-transaction-context.d.ts +0 -35
  351. package/esm/context/database-transaction-context.d.ts.map +0 -1
  352. package/esm/context/database-transaction-context.js +0 -40
  353. package/esm/context/database-transaction-context.js.map +0 -1
  354. package/esm/contracts/database-driver.contract.d.ts +0 -450
  355. package/esm/contracts/database-driver.contract.d.ts.map +0 -1
  356. package/esm/contracts/database-id-generator.contract.d.ts +0 -109
  357. package/esm/contracts/database-id-generator.contract.d.ts.map +0 -1
  358. package/esm/contracts/database-remover.contract.d.ts +0 -104
  359. package/esm/contracts/database-remover.contract.d.ts.map +0 -1
  360. package/esm/contracts/database-restorer.contract.d.ts +0 -143
  361. package/esm/contracts/database-restorer.contract.d.ts.map +0 -1
  362. package/esm/contracts/database-writer.contract.d.ts +0 -119
  363. package/esm/contracts/database-writer.contract.d.ts.map +0 -1
  364. package/esm/contracts/driver-blueprint.contract.d.ts +0 -49
  365. package/esm/contracts/driver-blueprint.contract.d.ts.map +0 -1
  366. package/esm/contracts/index.d.ts +0 -10
  367. package/esm/contracts/index.d.ts.map +0 -1
  368. package/esm/contracts/migration-driver.contract.d.ts +0 -522
  369. package/esm/contracts/migration-driver.contract.d.ts.map +0 -1
  370. package/esm/contracts/query-builder.contract.d.ts +0 -1609
  371. package/esm/contracts/query-builder.contract.d.ts.map +0 -1
  372. package/esm/contracts/sync-adapter.contract.d.ts +0 -58
  373. package/esm/contracts/sync-adapter.contract.d.ts.map +0 -1
  374. package/esm/data-source/data-source-registry.d.ts +0 -108
  375. package/esm/data-source/data-source-registry.d.ts.map +0 -1
  376. package/esm/data-source/data-source-registry.js +0 -145
  377. package/esm/data-source/data-source-registry.js.map +0 -1
  378. package/esm/data-source/data-source.d.ts +0 -147
  379. package/esm/data-source/data-source.d.ts.map +0 -1
  380. package/esm/data-source/data-source.js +0 -83
  381. package/esm/data-source/data-source.js.map +0 -1
  382. package/esm/database-dirty-tracker.d.ts +0 -252
  383. package/esm/database-dirty-tracker.d.ts.map +0 -1
  384. package/esm/database-dirty-tracker.js +0 -386
  385. package/esm/database-dirty-tracker.js.map +0 -1
  386. package/esm/drivers/mongodb/mongodb-blueprint.d.ts +0 -30
  387. package/esm/drivers/mongodb/mongodb-blueprint.d.ts.map +0 -1
  388. package/esm/drivers/mongodb/mongodb-blueprint.js +0 -51
  389. package/esm/drivers/mongodb/mongodb-blueprint.js.map +0 -1
  390. package/esm/drivers/mongodb/mongodb-driver.d.ts +0 -324
  391. package/esm/drivers/mongodb/mongodb-driver.d.ts.map +0 -1
  392. package/esm/drivers/mongodb/mongodb-driver.js +0 -799
  393. package/esm/drivers/mongodb/mongodb-driver.js.map +0 -1
  394. package/esm/drivers/mongodb/mongodb-id-generator.d.ts +0 -116
  395. package/esm/drivers/mongodb/mongodb-id-generator.d.ts.map +0 -1
  396. package/esm/drivers/mongodb/mongodb-id-generator.js +0 -149
  397. package/esm/drivers/mongodb/mongodb-id-generator.js.map +0 -1
  398. package/esm/drivers/mongodb/mongodb-migration-driver.d.ts +0 -317
  399. package/esm/drivers/mongodb/mongodb-migration-driver.d.ts.map +0 -1
  400. package/esm/drivers/mongodb/mongodb-migration-driver.js +0 -666
  401. package/esm/drivers/mongodb/mongodb-migration-driver.js.map +0 -1
  402. package/esm/drivers/mongodb/mongodb-query-builder.d.ts +0 -1122
  403. package/esm/drivers/mongodb/mongodb-query-builder.d.ts.map +0 -1
  404. package/esm/drivers/mongodb/mongodb-query-builder.js +0 -1988
  405. package/esm/drivers/mongodb/mongodb-query-builder.js.map +0 -1
  406. package/esm/drivers/mongodb/mongodb-query-operations.d.ts +0 -226
  407. package/esm/drivers/mongodb/mongodb-query-operations.d.ts.map +0 -1
  408. package/esm/drivers/mongodb/mongodb-query-operations.js +0 -270
  409. package/esm/drivers/mongodb/mongodb-query-operations.js.map +0 -1
  410. package/esm/drivers/mongodb/mongodb-query-parser.d.ts +0 -262
  411. package/esm/drivers/mongodb/mongodb-query-parser.d.ts.map +0 -1
  412. package/esm/drivers/mongodb/mongodb-query-parser.js +0 -1351
  413. package/esm/drivers/mongodb/mongodb-query-parser.js.map +0 -1
  414. package/esm/drivers/mongodb/mongodb-sync-adapter.d.ts +0 -79
  415. package/esm/drivers/mongodb/mongodb-sync-adapter.d.ts.map +0 -1
  416. package/esm/drivers/mongodb/mongodb-sync-adapter.js +0 -146
  417. package/esm/drivers/mongodb/mongodb-sync-adapter.js.map +0 -1
  418. package/esm/drivers/mongodb/types.d.ts +0 -43
  419. package/esm/drivers/mongodb/types.d.ts.map +0 -1
  420. package/esm/drivers/postgres/index.d.ts +0 -16
  421. package/esm/drivers/postgres/index.d.ts.map +0 -1
  422. package/esm/drivers/postgres/postgres-blueprint.d.ts +0 -64
  423. package/esm/drivers/postgres/postgres-blueprint.d.ts.map +0 -1
  424. package/esm/drivers/postgres/postgres-blueprint.js +0 -121
  425. package/esm/drivers/postgres/postgres-blueprint.js.map +0 -1
  426. package/esm/drivers/postgres/postgres-dialect.d.ts +0 -136
  427. package/esm/drivers/postgres/postgres-dialect.d.ts.map +0 -1
  428. package/esm/drivers/postgres/postgres-dialect.js +0 -268
  429. package/esm/drivers/postgres/postgres-dialect.js.map +0 -1
  430. package/esm/drivers/postgres/postgres-driver.d.ts +0 -432
  431. package/esm/drivers/postgres/postgres-driver.d.ts.map +0 -1
  432. package/esm/drivers/postgres/postgres-driver.js +0 -965
  433. package/esm/drivers/postgres/postgres-driver.js.map +0 -1
  434. package/esm/drivers/postgres/postgres-migration-driver.d.ts +0 -397
  435. package/esm/drivers/postgres/postgres-migration-driver.d.ts.map +0 -1
  436. package/esm/drivers/postgres/postgres-migration-driver.js +0 -900
  437. package/esm/drivers/postgres/postgres-migration-driver.js.map +0 -1
  438. package/esm/drivers/postgres/postgres-query-builder.d.ts +0 -254
  439. package/esm/drivers/postgres/postgres-query-builder.d.ts.map +0 -1
  440. package/esm/drivers/postgres/postgres-query-builder.js +0 -933
  441. package/esm/drivers/postgres/postgres-query-builder.js.map +0 -1
  442. package/esm/drivers/postgres/postgres-query-parser.d.ts +0 -328
  443. package/esm/drivers/postgres/postgres-query-parser.d.ts.map +0 -1
  444. package/esm/drivers/postgres/postgres-query-parser.js +0 -864
  445. package/esm/drivers/postgres/postgres-query-parser.js.map +0 -1
  446. package/esm/drivers/postgres/postgres-sql-serializer.d.ts +0 -37
  447. package/esm/drivers/postgres/postgres-sql-serializer.d.ts.map +0 -1
  448. package/esm/drivers/postgres/postgres-sql-serializer.js +0 -400
  449. package/esm/drivers/postgres/postgres-sql-serializer.js.map +0 -1
  450. package/esm/drivers/postgres/postgres-sync-adapter.d.ts +0 -83
  451. package/esm/drivers/postgres/postgres-sync-adapter.d.ts.map +0 -1
  452. package/esm/drivers/postgres/postgres-sync-adapter.js +0 -197
  453. package/esm/drivers/postgres/postgres-sync-adapter.js.map +0 -1
  454. package/esm/drivers/postgres/types.d.ts +0 -142
  455. package/esm/drivers/postgres/types.d.ts.map +0 -1
  456. package/esm/drivers/sql/index.d.ts +0 -10
  457. package/esm/drivers/sql/index.d.ts.map +0 -1
  458. package/esm/drivers/sql/sql-dialect.contract.d.ts +0 -204
  459. package/esm/drivers/sql/sql-dialect.contract.d.ts.map +0 -1
  460. package/esm/drivers/sql/sql-types.d.ts +0 -202
  461. package/esm/drivers/sql/sql-types.d.ts.map +0 -1
  462. package/esm/errors/missing-data-source.error.d.ts +0 -22
  463. package/esm/errors/missing-data-source.error.d.ts.map +0 -1
  464. package/esm/errors/missing-data-source.error.js +0 -29
  465. package/esm/errors/missing-data-source.error.js.map +0 -1
  466. package/esm/errors/transaction-rollback.error.d.ts +0 -20
  467. package/esm/errors/transaction-rollback.error.d.ts.map +0 -1
  468. package/esm/errors/transaction-rollback.error.js +0 -27
  469. package/esm/errors/transaction-rollback.error.js.map +0 -1
  470. package/esm/events/model-events.d.ts +0 -231
  471. package/esm/events/model-events.d.ts.map +0 -1
  472. package/esm/events/model-events.js +0 -259
  473. package/esm/events/model-events.js.map +0 -1
  474. package/esm/expressions/aggregate-expressions.d.ts +0 -215
  475. package/esm/expressions/aggregate-expressions.d.ts.map +0 -1
  476. package/esm/expressions/aggregate-expressions.js +0 -221
  477. package/esm/expressions/aggregate-expressions.js.map +0 -1
  478. package/esm/expressions/index.d.ts +0 -2
  479. package/esm/expressions/index.d.ts.map +0 -1
  480. package/esm/index.d.ts +0 -45
  481. package/esm/index.d.ts.map +0 -1
  482. package/esm/index.js +0 -1
  483. package/esm/index.js.map +0 -1
  484. package/esm/migration/column-builder.d.ts +0 -417
  485. package/esm/migration/column-builder.d.ts.map +0 -1
  486. package/esm/migration/column-builder.js +0 -586
  487. package/esm/migration/column-builder.js.map +0 -1
  488. package/esm/migration/column-helpers.d.ts +0 -275
  489. package/esm/migration/column-helpers.d.ts.map +0 -1
  490. package/esm/migration/column-helpers.js +0 -389
  491. package/esm/migration/column-helpers.js.map +0 -1
  492. package/esm/migration/foreign-key-builder.d.ts +0 -103
  493. package/esm/migration/foreign-key-builder.d.ts.map +0 -1
  494. package/esm/migration/foreign-key-builder.js +0 -121
  495. package/esm/migration/foreign-key-builder.js.map +0 -1
  496. package/esm/migration/index.d.ts +0 -7
  497. package/esm/migration/index.d.ts.map +0 -1
  498. package/esm/migration/migration-runner.d.ts +0 -278
  499. package/esm/migration/migration-runner.d.ts.map +0 -1
  500. package/esm/migration/migration-runner.js +0 -815
  501. package/esm/migration/migration-runner.js.map +0 -1
  502. package/esm/migration/migration.d.ts +0 -1992
  503. package/esm/migration/migration.d.ts.map +0 -1
  504. package/esm/migration/migration.js +0 -2162
  505. package/esm/migration/migration.js.map +0 -1
  506. package/esm/migration/sql-grammar.d.ts +0 -61
  507. package/esm/migration/sql-grammar.d.ts.map +0 -1
  508. package/esm/migration/sql-grammar.js +0 -164
  509. package/esm/migration/sql-grammar.js.map +0 -1
  510. package/esm/migration/sql-serializer.d.ts +0 -22
  511. package/esm/migration/sql-serializer.d.ts.map +0 -1
  512. package/esm/migration/sql-serializer.js +0 -26
  513. package/esm/migration/sql-serializer.js.map +0 -1
  514. package/esm/migration/types.d.ts +0 -155
  515. package/esm/migration/types.d.ts.map +0 -1
  516. package/esm/model/methods/accessor-methods.d.ts +0 -13
  517. package/esm/model/methods/accessor-methods.d.ts.map +0 -1
  518. package/esm/model/methods/accessor-methods.js +0 -51
  519. package/esm/model/methods/accessor-methods.js.map +0 -1
  520. package/esm/model/methods/delete-methods.d.ts +0 -10
  521. package/esm/model/methods/delete-methods.d.ts.map +0 -1
  522. package/esm/model/methods/delete-methods.js +0 -10
  523. package/esm/model/methods/delete-methods.js.map +0 -1
  524. package/esm/model/methods/dirty-methods.d.ts +0 -10
  525. package/esm/model/methods/dirty-methods.d.ts.map +0 -1
  526. package/esm/model/methods/dirty-methods.js +0 -15
  527. package/esm/model/methods/dirty-methods.js.map +0 -1
  528. package/esm/model/methods/hydration-methods.d.ts +0 -10
  529. package/esm/model/methods/hydration-methods.d.ts.map +0 -1
  530. package/esm/model/methods/hydration-methods.js +0 -57
  531. package/esm/model/methods/hydration-methods.js.map +0 -1
  532. package/esm/model/methods/instance-event-methods.d.ts +0 -7
  533. package/esm/model/methods/instance-event-methods.d.ts.map +0 -1
  534. package/esm/model/methods/instance-event-methods.js +0 -15
  535. package/esm/model/methods/instance-event-methods.js.map +0 -1
  536. package/esm/model/methods/meta-methods.d.ts +0 -7
  537. package/esm/model/methods/meta-methods.d.ts.map +0 -1
  538. package/esm/model/methods/meta-methods.js +0 -78
  539. package/esm/model/methods/meta-methods.js.map +0 -1
  540. package/esm/model/methods/query-methods.d.ts +0 -24
  541. package/esm/model/methods/query-methods.d.ts.map +0 -1
  542. package/esm/model/methods/query-methods.js +0 -161
  543. package/esm/model/methods/query-methods.js.map +0 -1
  544. package/esm/model/methods/restore-methods.d.ts +0 -10
  545. package/esm/model/methods/restore-methods.d.ts.map +0 -1
  546. package/esm/model/methods/restore-methods.js +0 -13
  547. package/esm/model/methods/restore-methods.js.map +0 -1
  548. package/esm/model/methods/scope-methods.d.ts +0 -7
  549. package/esm/model/methods/scope-methods.d.ts.map +0 -1
  550. package/esm/model/methods/scope-methods.js +0 -15
  551. package/esm/model/methods/scope-methods.js.map +0 -1
  552. package/esm/model/methods/serialization-methods.d.ts +0 -3
  553. package/esm/model/methods/serialization-methods.d.ts.map +0 -1
  554. package/esm/model/methods/serialization-methods.js +0 -27
  555. package/esm/model/methods/serialization-methods.js.map +0 -1
  556. package/esm/model/methods/static-event-methods.d.ts +0 -9
  557. package/esm/model/methods/static-event-methods.d.ts.map +0 -1
  558. package/esm/model/methods/static-event-methods.js +0 -29
  559. package/esm/model/methods/static-event-methods.js.map +0 -1
  560. package/esm/model/methods/write-methods.d.ts +0 -10
  561. package/esm/model/methods/write-methods.d.ts.map +0 -1
  562. package/esm/model/methods/write-methods.js +0 -52
  563. package/esm/model/methods/write-methods.js.map +0 -1
  564. package/esm/model/model.d.ts +0 -1650
  565. package/esm/model/model.d.ts.map +0 -1
  566. package/esm/model/model.js +0 -1657
  567. package/esm/model/model.js.map +0 -1
  568. package/esm/model/model.types.d.ts +0 -44
  569. package/esm/model/model.types.d.ts.map +0 -1
  570. package/esm/model/register-model.d.ts +0 -81
  571. package/esm/model/register-model.d.ts.map +0 -1
  572. package/esm/model/register-model.js +0 -94
  573. package/esm/model/register-model.js.map +0 -1
  574. package/esm/query-builder/query-builder.d.ts +0 -556
  575. package/esm/query-builder/query-builder.d.ts.map +0 -1
  576. package/esm/query-builder/query-builder.js +0 -1070
  577. package/esm/query-builder/query-builder.js.map +0 -1
  578. package/esm/relations/helpers.d.ts +0 -156
  579. package/esm/relations/helpers.d.ts.map +0 -1
  580. package/esm/relations/helpers.js +0 -201
  581. package/esm/relations/helpers.js.map +0 -1
  582. package/esm/relations/index.d.ts +0 -35
  583. package/esm/relations/index.d.ts.map +0 -1
  584. package/esm/relations/pivot-operations.d.ts +0 -160
  585. package/esm/relations/pivot-operations.d.ts.map +0 -1
  586. package/esm/relations/pivot-operations.js +0 -293
  587. package/esm/relations/pivot-operations.js.map +0 -1
  588. package/esm/relations/relation-hydrator.d.ts +0 -68
  589. package/esm/relations/relation-hydrator.d.ts.map +0 -1
  590. package/esm/relations/relation-hydrator.js +0 -81
  591. package/esm/relations/relation-hydrator.js.map +0 -1
  592. package/esm/relations/relation-loader.d.ts +0 -194
  593. package/esm/relations/relation-loader.d.ts.map +0 -1
  594. package/esm/relations/relation-loader.js +0 -466
  595. package/esm/relations/relation-loader.js.map +0 -1
  596. package/esm/relations/types.d.ts +0 -306
  597. package/esm/relations/types.d.ts.map +0 -1
  598. package/esm/remover/database-remover.d.ts +0 -100
  599. package/esm/remover/database-remover.d.ts.map +0 -1
  600. package/esm/remover/database-remover.js +0 -214
  601. package/esm/remover/database-remover.js.map +0 -1
  602. package/esm/restorer/database-restorer.d.ts +0 -131
  603. package/esm/restorer/database-restorer.d.ts.map +0 -1
  604. package/esm/restorer/database-restorer.js +0 -434
  605. package/esm/restorer/database-restorer.js.map +0 -1
  606. package/esm/sql-database-dirty-tracker.d.ts +0 -13
  607. package/esm/sql-database-dirty-tracker.d.ts.map +0 -1
  608. package/esm/sql-database-dirty-tracker.js +0 -14
  609. package/esm/sql-database-dirty-tracker.js.map +0 -1
  610. package/esm/sync/index.d.ts +0 -12
  611. package/esm/sync/index.d.ts.map +0 -1
  612. package/esm/sync/model-events.d.ts +0 -62
  613. package/esm/sync/model-events.d.ts.map +0 -1
  614. package/esm/sync/model-events.js +0 -49
  615. package/esm/sync/model-events.js.map +0 -1
  616. package/esm/sync/model-sync-operation.d.ts +0 -163
  617. package/esm/sync/model-sync-operation.d.ts.map +0 -1
  618. package/esm/sync/model-sync-operation.js +0 -292
  619. package/esm/sync/model-sync-operation.js.map +0 -1
  620. package/esm/sync/model-sync.d.ts +0 -130
  621. package/esm/sync/model-sync.d.ts.map +0 -1
  622. package/esm/sync/model-sync.js +0 -178
  623. package/esm/sync/model-sync.js.map +0 -1
  624. package/esm/sync/sync-context.d.ts +0 -70
  625. package/esm/sync/sync-context.d.ts.map +0 -1
  626. package/esm/sync/sync-context.js +0 -101
  627. package/esm/sync/sync-context.js.map +0 -1
  628. package/esm/sync/sync-manager.d.ts +0 -213
  629. package/esm/sync/sync-manager.d.ts.map +0 -1
  630. package/esm/sync/sync-manager.js +0 -689
  631. package/esm/sync/sync-manager.js.map +0 -1
  632. package/esm/sync/types.d.ts +0 -289
  633. package/esm/sync/types.d.ts.map +0 -1
  634. package/esm/test-migrations/test-enhanced-features.migration.d.ts +0 -15
  635. package/esm/test-migrations/test-enhanced-features.migration.d.ts.map +0 -1
  636. package/esm/types.d.ts +0 -371
  637. package/esm/types.d.ts.map +0 -1
  638. package/esm/utils/connect-to-database.d.ts +0 -300
  639. package/esm/utils/connect-to-database.d.ts.map +0 -1
  640. package/esm/utils/connect-to-database.js +0 -128
  641. package/esm/utils/connect-to-database.js.map +0 -1
  642. package/esm/utils/database-writer.utils.d.ts +0 -15
  643. package/esm/utils/database-writer.utils.d.ts.map +0 -1
  644. package/esm/utils/database-writer.utils.js +0 -14
  645. package/esm/utils/database-writer.utils.js.map +0 -1
  646. package/esm/utils/define-model.js +0 -100
  647. package/esm/utils/define-model.js.map +0 -1
  648. package/esm/utils/is-valid-date-value.d.ts +0 -5
  649. package/esm/utils/is-valid-date-value.d.ts.map +0 -1
  650. package/esm/utils/is-valid-date-value.js +0 -25
  651. package/esm/utils/is-valid-date-value.js.map +0 -1
  652. package/esm/utils/once-connected.d.ts +0 -146
  653. package/esm/utils/once-connected.d.ts.map +0 -1
  654. package/esm/utils/once-connected.js +0 -251
  655. package/esm/utils/once-connected.js.map +0 -1
  656. package/esm/validation/database-seal-plugins.d.ts +0 -12
  657. package/esm/validation/database-seal-plugins.d.ts.map +0 -1
  658. package/esm/validation/database-seal-plugins.js +0 -1
  659. package/esm/validation/database-seal-plugins.js.map +0 -1
  660. package/esm/validation/database-writer-validation-error.d.ts +0 -97
  661. package/esm/validation/database-writer-validation-error.d.ts.map +0 -1
  662. package/esm/validation/database-writer-validation-error.js +0 -160
  663. package/esm/validation/database-writer-validation-error.js.map +0 -1
  664. package/esm/validation/index.d.ts +0 -3
  665. package/esm/validation/index.d.ts.map +0 -1
  666. package/esm/validation/mutators/embed-mutator.d.ts +0 -9
  667. package/esm/validation/mutators/embed-mutator.d.ts.map +0 -1
  668. package/esm/validation/mutators/embed-mutator.js +0 -33
  669. package/esm/validation/mutators/embed-mutator.js.map +0 -1
  670. package/esm/validation/plugins/embed-validator-plugin.d.ts +0 -24
  671. package/esm/validation/plugins/embed-validator-plugin.d.ts.map +0 -1
  672. package/esm/validation/plugins/embed-validator-plugin.js +0 -18
  673. package/esm/validation/plugins/embed-validator-plugin.js.map +0 -1
  674. package/esm/validation/rules/database-model-rule.d.ts +0 -7
  675. package/esm/validation/rules/database-model-rule.d.ts.map +0 -1
  676. package/esm/validation/rules/database-model-rule.js +0 -27
  677. package/esm/validation/rules/database-model-rule.js.map +0 -1
  678. package/esm/validation/transformers/embed-model-transformer.d.ts +0 -3
  679. package/esm/validation/transformers/embed-model-transformer.d.ts.map +0 -1
  680. package/esm/validation/transformers/embed-model-transformer.js +0 -18
  681. package/esm/validation/transformers/embed-model-transformer.js.map +0 -1
  682. package/esm/validation/validators/embed-validator.d.ts +0 -21
  683. package/esm/validation/validators/embed-validator.d.ts.map +0 -1
  684. package/esm/validation/validators/embed-validator.js +0 -43
  685. package/esm/validation/validators/embed-validator.js.map +0 -1
  686. package/esm/writer/database-writer.d.ts +0 -181
  687. package/esm/writer/database-writer.d.ts.map +0 -1
  688. package/esm/writer/database-writer.js +0 -407
  689. package/esm/writer/database-writer.js.map +0 -1
@@ -1,1988 +0,0 @@
1
- 'use strict';var reinforcements=require('@mongez/reinforcements'),databaseTransactionContext=require('../../context/database-transaction-context.js'),dataSourceRegistry=require('../../data-source/data-source-registry.js'),queryBuilder=require('../../query-builder/query-builder.js'),mongodbQueryOperations=require('./mongodb-query-operations.js'),mongodbQueryParser=require('./mongodb-query-parser.js');/* eslint-disable no-case-declarations */
2
- /**
3
- * MongoDB-specific query builder implementation using aggregation pipeline.
4
- */
5
- class MongoQueryBuilder extends queryBuilder.QueryBuilder {
6
- table;
7
- /**
8
- * Ordered list of operations to be converted to MongoDB aggregation pipeline.
9
- * Public to allow parser access. Uses MongoDB's own Operation type.
10
- *
11
- * NOTE: This shadows the base `operations: Op[]` field intentionally — the Mongo
12
- * Operation type carries an extra `stage` discriminator used by the pipeline assembler.
13
- */
14
- operations = [];
15
- /**
16
- * Data source instance
17
- */
18
- dataSource;
19
- /**
20
- * Lazy-loaded operations helper for constructing pipeline operations.
21
- */
22
- _operationsHelper;
23
- hydrateCallback;
24
- fetchingCallback;
25
- hydratingCallback;
26
- fetchedCallback;
27
- // scopesApplied, pendingGlobalScopes, availableLocalScopes, disabledGlobalScopes
28
- // are inherited from QueryBuilder base class.
29
- /**
30
- * Create a new query builder for the given collection.
31
- * @param collection - The MongoDB collection to query
32
- */
33
- constructor(table, dataSource) {
34
- super();
35
- this.table = table;
36
- this.dataSource = dataSource || dataSourceRegistry.dataSourceRegistry.get();
37
- // TODO: Trigger the fetching event
38
- }
39
- /**
40
- * Gets the operations helper instance, creating it if needed.
41
- * @returns The operations helper instance
42
- */
43
- get operationsHelper() {
44
- if (!this._operationsHelper) {
45
- this._operationsHelper = new mongodbQueryOperations.MongoQueryOperations(this.operations);
46
- }
47
- return this._operationsHelper;
48
- }
49
- /**
50
- * Get collection instance
51
- */
52
- get collection() {
53
- const driver = this.dataSource.driver;
54
- return driver.database.collection(this.table);
55
- }
56
- /**
57
- * Add hydrate callback function
58
- */
59
- hydrate(callback) {
60
- this.hydrateCallback = callback;
61
- return this;
62
- }
63
- /**
64
- * Register a callback to be invoked before query execution
65
- * @returns Unsubscribe function to remove the callback
66
- */
67
- onFetching(callback) {
68
- this.fetchingCallback = callback;
69
- return () => {
70
- this.fetchingCallback = undefined;
71
- };
72
- }
73
- /**
74
- * Register a callback to be invoked after records are fetched but before hydration
75
- * @returns Unsubscribe function to remove the callback
76
- */
77
- onHydrating(callback) {
78
- this.hydratingCallback = callback;
79
- return () => {
80
- this.hydratingCallback = undefined;
81
- };
82
- }
83
- /**
84
- * Register a callback to be invoked after records are fetched and hydrated
85
- * @returns Unsubscribe function to remove the callback
86
- */
87
- onFetched(callback) {
88
- this.fetchedCallback = callback;
89
- return () => {
90
- this.fetchedCallback = undefined;
91
- };
92
- }
93
- /**
94
- * Disable one or more global scopes for this query
95
- */
96
- withoutGlobalScope(...scopeNames) {
97
- scopeNames.forEach((name) => this.disabledGlobalScopes.add(name));
98
- return this;
99
- }
100
- /**
101
- * Disable all global scopes for this query
102
- */
103
- withoutGlobalScopes() {
104
- if (this.pendingGlobalScopes) {
105
- this.pendingGlobalScopes.forEach((_, name) => {
106
- this.disabledGlobalScopes.add(name);
107
- });
108
- }
109
- return this;
110
- }
111
- /**
112
- * Apply a local scope to this query
113
- */
114
- scope(scopeName, ...args) {
115
- if (!this.availableLocalScopes) {
116
- throw new Error(`No local scopes available`);
117
- }
118
- const scopeCallback = this.availableLocalScopes.get(scopeName);
119
- if (!scopeCallback) {
120
- throw new Error(`Local scope "${scopeName}" not found`);
121
- }
122
- // Apply scope immediately (not deferred)
123
- scopeCallback(this, ...args);
124
- return this;
125
- }
126
- /**
127
- * Apply pending global scopes before query execution
128
- */
129
- applyPendingScopes() {
130
- if (!this.pendingGlobalScopes || this.scopesApplied) {
131
- return;
132
- }
133
- const beforeOps = [];
134
- const afterOps = [];
135
- for (const [name, { callback, timing }] of this.pendingGlobalScopes) {
136
- // Skip disabled scopes
137
- if (this.disabledGlobalScopes.has(name)) {
138
- continue;
139
- }
140
- // Create temporary query builder to capture operations
141
- const tempBuilder = new MongoQueryBuilder(this.table, this.dataSource);
142
- callback(tempBuilder);
143
- // Collect operations based on timing
144
- if (timing === "before") {
145
- beforeOps.push(...tempBuilder.operations);
146
- }
147
- else {
148
- afterOps.push(...tempBuilder.operations);
149
- }
150
- }
151
- // Apply: before scopes + user operations + after scopes
152
- this.operations = [...beforeOps, ...this.operations, ...afterOps];
153
- this.scopesApplied = true;
154
- }
155
- where(...args) {
156
- this.addWhereClause("where", args);
157
- return this;
158
- }
159
- orWhere(...args) {
160
- this.addWhereClause("orWhere", args);
161
- return this;
162
- }
163
- /**
164
- * Adds a raw WHERE clause using MongoDB's native query syntax.
165
- * @param expression - Raw MongoDB expression
166
- * @param bindings - Optional parameter bindings for string expressions
167
- */
168
- whereRaw(expression, bindings) {
169
- return this.addRawWhere("whereRaw", expression, bindings);
170
- }
171
- /**
172
- * Adds a raw OR WHERE clause using MongoDB's native query syntax.
173
- * @param expression - Raw MongoDB expression
174
- * @param bindings - Optional parameter bindings
175
- */
176
- orWhereRaw(expression, bindings) {
177
- return this.addRawWhere("orWhereRaw", expression, bindings);
178
- }
179
- // ============================================================================
180
- // WHERE CLAUSES - COLUMN COMPARISONS
181
- // ============================================================================
182
- /**
183
- * Adds a WHERE clause comparing two columns/fields directly.
184
- * @param first - The first field name
185
- * @param operator - The comparison operator
186
- * @param second - The second field name
187
- */
188
- whereColumn(first, operator, second) {
189
- this.operationsHelper.addMatchOperation("whereColumn", {
190
- first,
191
- operator,
192
- second,
193
- });
194
- return this;
195
- }
196
- /**
197
- * Adds an OR WHERE clause comparing two columns/fields directly.
198
- * @param first - The first field name
199
- * @param operator - The comparison operator
200
- * @param second - The second field name
201
- */
202
- orWhereColumn(first, operator, second) {
203
- this.operationsHelper.addMatchOperation("orWhereColumn", {
204
- first,
205
- operator,
206
- second,
207
- });
208
- return this;
209
- }
210
- /**
211
- * Adds multiple column comparison clauses at once.
212
- * @param comparisons - Array of tuples [leftField, operator, rightField]
213
- */
214
- whereColumns(comparisons) {
215
- for (const [left, operator, right] of comparisons) {
216
- this.whereColumn(left, operator, right);
217
- }
218
- return this;
219
- }
220
- /**
221
- * Filters documents where a field's value falls between two other fields.
222
- * @param field - The field to check
223
- * @param lowerColumn - The field defining the lower bound
224
- * @param upperColumn - The field defining the upper bound
225
- */
226
- whereBetweenColumns(field, lowerColumn, upperColumn) {
227
- this.operationsHelper.addMatchOperation("whereBetweenColumns", {
228
- field,
229
- lowerColumn,
230
- upperColumn,
231
- });
232
- return this;
233
- }
234
- // ============================================================================
235
- // WHERE CLAUSES - DATE OPERATIONS
236
- // ============================================================================
237
- /**
238
- * Filters documents where a date field matches the given date (ignoring time).
239
- * @param field - The date field name
240
- * @param value - The date to match
241
- */
242
- whereDate(field, value) {
243
- this.operationsHelper.addMatchOperation("whereDate", { field, value });
244
- return this;
245
- }
246
- /**
247
- * Alias for `whereDate()`. Filters by exact date match (ignoring time).
248
- * @param field - The date field name
249
- * @param value - The date to match
250
- */
251
- whereDateEquals(field, value) {
252
- this.operationsHelper.addMatchOperation("whereDateEquals", {
253
- field,
254
- value,
255
- });
256
- return this;
257
- }
258
- /**
259
- * Filters documents where a date field is before the given date.
260
- * @param field - The date field name
261
- * @param value - The cutoff date
262
- */
263
- whereDateBefore(field, value) {
264
- this.operationsHelper.addMatchOperation("whereDateBefore", {
265
- field,
266
- value,
267
- });
268
- return this;
269
- }
270
- /**
271
- * Filters documents where a date field is after the given date.
272
- * @param field - The date field name
273
- * @param value - The cutoff date
274
- */
275
- whereDateAfter(field, value) {
276
- this.operationsHelper.addMatchOperation("whereDateAfter", { field, value });
277
- return this;
278
- }
279
- /**
280
- * Filters documents where a time field matches the given time (HH:MM:SS format).
281
- * @param field - The time/datetime field name
282
- * @param value - The time string in HH:MM:SS format
283
- */
284
- whereTime(field, value) {
285
- this.operationsHelper.addMatchOperation("whereTime", { field, value });
286
- return this;
287
- }
288
- /**
289
- * Filters documents where the day of the month matches the given value (1-31).
290
- * @param field - The date field name
291
- * @param value - The day of the month
292
- */
293
- whereDay(field, value) {
294
- this.operationsHelper.addMatchOperation("whereDay", { field, value });
295
- return this;
296
- }
297
- /**
298
- * Filters documents where the month matches the given value (1-12).
299
- * @param field - The date field name
300
- * @param value - The month number
301
- */
302
- whereMonth(field, value) {
303
- this.operationsHelper.addMatchOperation("whereMonth", { field, value });
304
- return this;
305
- }
306
- /**
307
- * Filters documents where the year matches the given value.
308
- * @param field - The date field name
309
- * @param value - The year
310
- */
311
- whereYear(field, value) {
312
- this.operationsHelper.addMatchOperation("whereYear", { field, value });
313
- return this;
314
- }
315
- // ============================================================================
316
- // WHERE CLAUSES - JSON OPERATIONS
317
- // ============================================================================
318
- /**
319
- * Filters documents where a JSON field contains the specified value.
320
- * @param path - The JSON path to check
321
- * @param value - The value to search for
322
- */
323
- whereJsonContains(path, value) {
324
- this.operationsHelper.addMatchOperation("whereJsonContains", {
325
- path,
326
- value,
327
- });
328
- return this;
329
- }
330
- /**
331
- * Filters documents where a JSON field does NOT contain the specified value.
332
- * @param path - The JSON path to check
333
- * @param value - The value to exclude
334
- */
335
- whereJsonDoesntContain(path, value) {
336
- this.operationsHelper.addMatchOperation("whereJsonDoesntContain", {
337
- path,
338
- value,
339
- });
340
- return this;
341
- }
342
- /**
343
- * Filters documents where a JSON field contains a specific key.
344
- * @param path - The JSON path to check for key existence
345
- */
346
- whereJsonContainsKey(path) {
347
- this.operationsHelper.addMatchOperation("whereJsonContainsKey", { path });
348
- return this;
349
- }
350
- /**
351
- * Filters documents where a JSON array or string has a specific length.
352
- * @param path - The JSON path to check
353
- * @param operator - The comparison operator
354
- * @param value - The length value to compare against
355
- */
356
- whereJsonLength(path, operator, value) {
357
- this.operationsHelper.addMatchOperation("whereJsonLength", {
358
- path,
359
- operator,
360
- value,
361
- });
362
- return this;
363
- }
364
- /**
365
- * Filters documents where a JSON field is an array.
366
- * @param path - The JSON path to check
367
- */
368
- whereJsonIsArray(path) {
369
- this.operationsHelper.addMatchOperation("whereJsonIsArray", { path });
370
- return this;
371
- }
372
- /**
373
- * Filters documents where a JSON field is an object.
374
- * @param path - The JSON path to check
375
- */
376
- whereJsonIsObject(path) {
377
- this.operationsHelper.addMatchOperation("whereJsonIsObject", { path });
378
- return this;
379
- }
380
- /**
381
- * Filters documents where an array field has a specific length.
382
- * @param field - The array field name
383
- * @param operator - The comparison operator
384
- * @param value - The length value to compare against
385
- */
386
- whereArrayLength(field, operator, value) {
387
- this.operationsHelper.addMatchOperation("whereArrayLength", {
388
- field,
389
- operator,
390
- value,
391
- });
392
- return this;
393
- }
394
- // ============================================================================
395
- // WHERE CLAUSES - CONVENIENCE METHODS
396
- // ============================================================================
397
- /**
398
- * Filters documents by ID (convenience method for `where("id", value)`).
399
- * @param value - The ID value to match
400
- */
401
- whereId(value) {
402
- return this.where("id", value);
403
- }
404
- /**
405
- * Filters documents by multiple IDs (convenience method for `whereIn("id", values)`).
406
- * @param values - Array of ID values to match
407
- */
408
- whereIds(values) {
409
- return this.whereIn("id", values);
410
- }
411
- /**
412
- * Filters documents by UUID (convenience method for `where("uuid", value)`).
413
- * @param value - The UUID string to match
414
- */
415
- whereUuid(value) {
416
- return this.where("uuid", value);
417
- }
418
- /**
419
- * Filters documents by ULID (convenience method for `where("ulid", value)`).
420
- * @param value - The ULID string to match
421
- */
422
- whereUlid(value) {
423
- return this.where("ulid", value);
424
- }
425
- /**
426
- * Performs full-text search on one or more fields.
427
- * @param fields - Field name or array of field names to search
428
- * @param query - The search query string
429
- */
430
- whereFullText(fields, query) {
431
- const filters = typeof fields === "string" ? { fields: [fields] } : { fields: fields ?? [] };
432
- this.operationsHelper.addMatchOperation("whereFullText", {
433
- fields: filters.fields,
434
- query,
435
- });
436
- return this;
437
- }
438
- /**
439
- * Performs full-text search with OR logic.
440
- * @param fields - Field name or array of field names to search
441
- * @param query - The search query string
442
- */
443
- orWhereFullText(fields, query) {
444
- const filters = typeof fields === "string" ? { fields: [fields] } : { fields: fields ?? [] };
445
- this.operationsHelper.addMatchOperation("orWhereFullText", {
446
- fields: filters.fields,
447
- query,
448
- });
449
- return this;
450
- }
451
- /**
452
- * Alias for `whereFullText()` with a single field.
453
- * @param field - The field name to search
454
- * @param query - The search query string
455
- */
456
- whereSearch(field, query) {
457
- return this.whereFullText(field, query);
458
- }
459
- /**
460
- * Negates a set of conditions using a callback.
461
- * @param callback - Callback function defining conditions to negate
462
- */
463
- whereNot(callback) {
464
- this.operationsHelper.addMatchOperation("where:not", { callback });
465
- return this;
466
- }
467
- /**
468
- * Negates a set of conditions with OR logic.
469
- * @param callback - Callback function defining conditions to negate
470
- */
471
- orWhereNot(callback) {
472
- this.operationsHelper.addMatchOperation("orWhere:not", { callback });
473
- return this;
474
- }
475
- // ============================================================================
476
- // WHERE CLAUSES - COMPARISON OPERATORS
477
- // ============================================================================
478
- /**
479
- * Filters documents where a field's value matches any value in the given array.
480
- * @param field - The field name to check
481
- * @param values - Array of values to match against
482
- */
483
- whereIn(field, values) {
484
- this.operationsHelper.addMatchOperation("whereIn", { field, values });
485
- return this;
486
- }
487
- /**
488
- * Filters documents where a field's value does NOT match any value in the array.
489
- * @param field - The field name to check
490
- * @param values - Array of values to exclude
491
- */
492
- whereNotIn(field, values) {
493
- this.operationsHelper.addMatchOperation("whereNotIn", { field, values });
494
- return this;
495
- }
496
- /**
497
- * Filters documents where a field's value is null or undefined.
498
- * @param field - The field name to check
499
- */
500
- whereNull(field) {
501
- this.operationsHelper.addMatchOperation("whereNull", { field });
502
- return this;
503
- }
504
- /**
505
- * Filters documents where a field's value is NOT null or undefined.
506
- * @param field - The field name to check
507
- */
508
- whereNotNull(field) {
509
- this.operationsHelper.addMatchOperation("whereNotNull", { field });
510
- return this;
511
- }
512
- /**
513
- * Filters documents where a field's value falls within the given range (inclusive).
514
- * @param field - The field name to check
515
- * @param range - Tuple of [min, max] values
516
- */
517
- whereBetween(field, range) {
518
- this.operationsHelper.addMatchOperation("whereBetween", { field, range });
519
- return this;
520
- }
521
- /**
522
- * Filters documents where a field's value is NOT within the given range.
523
- * @param field - The field name to check
524
- * @param range - Tuple of [min, max] values to exclude
525
- */
526
- whereNotBetween(field, range) {
527
- this.operationsHelper.addMatchOperation("whereNotBetween", {
528
- field,
529
- range,
530
- });
531
- return this;
532
- }
533
- // ============================================================================
534
- // WHERE CLAUSES - PATTERN MATCHING
535
- // ============================================================================
536
- /**
537
- * Filters documents where a field matches the given pattern (case-insensitive).
538
- * @param field - The field name to search
539
- * @param pattern - The pattern to match
540
- */
541
- whereLike(field, pattern) {
542
- this.operationsHelper.addMatchOperation("whereLike", { field, pattern });
543
- return this;
544
- }
545
- /**
546
- * Filters documents where a field does NOT match the given pattern.
547
- * @param field - The field name to search
548
- * @param pattern - The pattern to exclude
549
- */
550
- whereNotLike(field, pattern) {
551
- this.operationsHelper.addMatchOperation("whereNotLike", { field, pattern });
552
- return this;
553
- }
554
- /**
555
- * Filters documents where a field's value starts with the given prefix.
556
- * @param field - The field name to check
557
- * @param value - The prefix to match
558
- */
559
- whereStartsWith(field, value) {
560
- this.operationsHelper.addMatchOperation("whereStartsWith", {
561
- field,
562
- value,
563
- });
564
- return this;
565
- }
566
- /**
567
- * Filters documents where a field's value does NOT start with the given prefix.
568
- * @param field - The field name to check
569
- * @param value - The prefix to exclude
570
- */
571
- whereNotStartsWith(field, value) {
572
- this.operationsHelper.addMatchOperation("whereNotStartsWith", {
573
- field,
574
- value,
575
- });
576
- return this;
577
- }
578
- /**
579
- * Filters documents where a field's value ends with the given suffix.
580
- * @param field - The field name to check
581
- * @param value - The suffix to match
582
- */
583
- whereEndsWith(field, value) {
584
- this.operationsHelper.addMatchOperation("whereEndsWith", { field, value });
585
- return this;
586
- }
587
- /**
588
- * Filters documents where a field's value does NOT end with the given suffix.
589
- * @param field - The field name to check
590
- * @param value - The suffix to exclude
591
- */
592
- whereNotEndsWith(field, value) {
593
- this.operationsHelper.addMatchOperation("whereNotEndsWith", {
594
- field,
595
- value,
596
- });
597
- return this;
598
- }
599
- /**
600
- * Filters documents where a date field falls within the given date range.
601
- * @param field - The date field name
602
- * @param range - Tuple of [startDate, endDate]
603
- */
604
- whereDateBetween(field, range) {
605
- this.operationsHelper.addMatchOperation("whereDateBetween", {
606
- field,
607
- range,
608
- });
609
- return this;
610
- }
611
- /**
612
- * Filters documents where a date field is NOT within the given date range.
613
- * @param field - The date field name
614
- * @param range - Tuple of [startDate, endDate] to exclude
615
- */
616
- whereDateNotBetween(field, range) {
617
- this.operationsHelper.addMatchOperation("whereDateNotBetween", {
618
- field,
619
- range,
620
- });
621
- return this;
622
- }
623
- whereExists(param) {
624
- if (typeof param === "function") {
625
- this.operationsHelper.addMatchOperation("where:exists", {
626
- callback: param,
627
- });
628
- return this;
629
- }
630
- this.operationsHelper.addMatchOperation("whereExists", { field: param });
631
- return this;
632
- }
633
- whereNotExists(param) {
634
- if (typeof param === "function") {
635
- this.operationsHelper.addMatchOperation("where:notExists", {
636
- callback: param,
637
- });
638
- return this;
639
- }
640
- this.operationsHelper.addMatchOperation("whereNotExists", {
641
- field: param,
642
- });
643
- return this;
644
- }
645
- whereSize(field, ...args) {
646
- if (args.length === 1) {
647
- this.operationsHelper.addMatchOperation("whereSize", {
648
- field,
649
- operator: "=",
650
- size: args[0],
651
- });
652
- }
653
- else {
654
- this.operationsHelper.addMatchOperation("whereSize", {
655
- field,
656
- operator: args[0],
657
- size: args[1],
658
- });
659
- }
660
- return this;
661
- }
662
- // ============================================================================
663
- // WHERE CLAUSES - FULL-TEXT SEARCH
664
- // ============================================================================
665
- /**
666
- * Performs a full-text search on the specified fields.
667
- * @param query - The search query string
668
- * @param filters - Optional additional filter conditions
669
- */
670
- textSearch(query, filters) {
671
- this.operationsHelper.addMatchOperation("textSearch", { query, filters });
672
- return this;
673
- }
674
- // ============================================================================
675
- // WHERE CLAUSES - ARRAY OPERATIONS
676
- // ============================================================================
677
- /**
678
- * Filters documents where an array field contains the given value.
679
- * @param field - The array field name
680
- * @param value - The value to search for in the array
681
- * @param key - Optional key to check within array objects
682
- */
683
- whereArrayContains(field, value, key) {
684
- this.operationsHelper.addMatchOperation("whereArrayContains", {
685
- field,
686
- value,
687
- key,
688
- });
689
- return this;
690
- }
691
- /**
692
- * Filters documents where an array field does NOT contain the given value.
693
- * @param field - The array field name
694
- * @param value - The value to exclude from the array
695
- * @param key - Optional key to check within array objects
696
- */
697
- whereArrayNotContains(field, value, key) {
698
- this.operationsHelper.addMatchOperation("whereArrayNotContains", {
699
- field,
700
- value,
701
- key,
702
- });
703
- return this;
704
- }
705
- /**
706
- * Filters documents where an array field contains the value OR is empty.
707
- * @param field - The array field name
708
- * @param value - The value to search for
709
- * @param key - Optional key to check within array objects
710
- */
711
- whereArrayHasOrEmpty(field, value, key) {
712
- this.operationsHelper.addMatchOperation("whereArrayHasOrEmpty", {
713
- field,
714
- value,
715
- key,
716
- });
717
- return this;
718
- }
719
- /**
720
- * Filters documents where an array field does NOT contain the value AND is not empty.
721
- * @param field - The array field name
722
- * @param value - The value to exclude
723
- * @param key - Optional key to check within array objects
724
- */
725
- whereArrayNotHaveOrEmpty(field, value, key) {
726
- this.operationsHelper.addMatchOperation("whereArrayNotHaveOrEmpty", {
727
- field,
728
- value,
729
- key,
730
- });
731
- return this;
732
- }
733
- /**
734
- * Internal helper for processing where clause arguments.
735
- * @param prefix - The operation prefix
736
- * @param args - The arguments passed to where/orWhere
737
- */
738
- addWhereClause(prefix, args) {
739
- if (args.length === 1) {
740
- if (typeof args[0] === "function") {
741
- // Callback-based where
742
- this.operationsHelper.addMatchOperation(`${prefix}:callback`, args[0]);
743
- }
744
- else {
745
- // Object-based where
746
- this.operationsHelper.addMatchOperation(`${prefix}:object`, args[0]);
747
- }
748
- }
749
- else if (args.length === 2) {
750
- // Simple equality: where(field, value)
751
- this.operationsHelper.addMatchOperation(prefix, {
752
- field: args[0],
753
- operator: "=",
754
- value: args[1],
755
- });
756
- }
757
- else if (args.length === 3) {
758
- // With operator: where(field, operator, value)
759
- this.operationsHelper.addMatchOperation(prefix, {
760
- field: args[0],
761
- operator: args[1],
762
- value: args[2],
763
- });
764
- }
765
- }
766
- /**
767
- * Internal helper for adding raw where clauses.
768
- * @param type - The operation type
769
- * @param expression - The raw expression in MongoDB query language
770
- * @param bindings - Optional bindings for the expression
771
- */
772
- addRawWhere(type, expression, bindings) {
773
- this.operationsHelper.addMatchOperation(type, { expression, bindings });
774
- return this;
775
- }
776
- /**
777
- * Normalizes select field arguments into a structured format.
778
- * @param args - The arguments to normalize
779
- * @returns Normalized selection object with fields and aliases
780
- */
781
- normalizeSelectFields(args) {
782
- // Single argument cases
783
- if (args.length === 1) {
784
- const arg = args[0];
785
- // Object format: { field: 1, field2: 0, field3: "alias", field4: true }
786
- if (typeof arg === "object" && !Array.isArray(arg)) {
787
- return { projection: arg };
788
- }
789
- // Array format: ["field1", "field2"]
790
- if (Array.isArray(arg)) {
791
- return { fields: arg };
792
- }
793
- // Single string: "field"
794
- if (typeof arg === "string") {
795
- return { fields: [arg] };
796
- }
797
- }
798
- // Multiple string arguments: select("field1", "field2", "field3")
799
- return { fields: args.filter((arg) => typeof arg === "string") };
800
- }
801
- select(...args) {
802
- const normalized = this.normalizeSelectFields(args);
803
- this.operationsHelper.addProjectOperation("select", normalized);
804
- return this;
805
- }
806
- /**
807
- * Selects a field with an alias.
808
- * @param field - The field to select
809
- * @param alias - The alias name for the field
810
- * @returns The query builder instance
811
- */
812
- selectAs(field, alias) {
813
- return this.select({ [field]: alias });
814
- }
815
- /**
816
- * Adds a computed field using a raw MongoDB expression.
817
- * @param expression - The raw MongoDB expression
818
- * @param bindings - Optional parameter bindings for string expressions
819
- */
820
- selectRaw(expression, bindings) {
821
- this.operationsHelper.addProjectOperation("selectRaw", {
822
- expression,
823
- bindings,
824
- });
825
- return this;
826
- }
827
- /**
828
- * Adds multiple computed fields using raw MongoDB expressions.
829
- * @param definitions - Array of field definitions with alias, expression, and optional bindings
830
- */
831
- selectRawMany(definitions) {
832
- for (const definition of definitions) {
833
- this.selectRaw({ [definition.alias]: definition.expression }, definition.bindings);
834
- }
835
- return this;
836
- }
837
- /**
838
- * Adds a subquery as a computed field.
839
- * @param expression - The subquery expression
840
- * @param alias - The alias for the computed field
841
- */
842
- selectSub(expression, alias) {
843
- this.operationsHelper.addProjectOperation("selectSub", {
844
- expression,
845
- alias,
846
- });
847
- return this;
848
- }
849
- /**
850
- * Adds an additional subquery field to existing selections.
851
- * @param expression - The subquery expression
852
- * @param alias - The alias for the computed field
853
- */
854
- addSelectSub(expression, alias) {
855
- this.operationsHelper.addProjectOperation("addSelectSub", {
856
- expression,
857
- alias,
858
- });
859
- return this;
860
- }
861
- /**
862
- * Adds an aggregate value as a computed field.
863
- * @param field - The field to aggregate
864
- * @param aggregate - The aggregate function to apply
865
- * @param alias - The alias for the computed field
866
- */
867
- selectAggregate(field, aggregate, alias) {
868
- this.operationsHelper.addProjectOperation("selectAggregate", {
869
- field,
870
- aggregate,
871
- alias,
872
- });
873
- return this;
874
- }
875
- /**
876
- * Adds a boolean field indicating whether a related document exists.
877
- * @param field - The field to check for existence
878
- * @param alias - The alias for the boolean field
879
- */
880
- selectExists(field, alias) {
881
- this.operationsHelper.addProjectOperation("selectExists", {
882
- field,
883
- alias,
884
- });
885
- return this;
886
- }
887
- /**
888
- * Adds a count field for a related collection.
889
- * @param field - The field to count
890
- * @param alias - The alias for the count field
891
- */
892
- selectCount(field, alias) {
893
- this.operationsHelper.addProjectOperation("selectCount", { field, alias });
894
- return this;
895
- }
896
- /**
897
- * Adds a CASE-like conditional field using multiple conditions.
898
- * @param cases - Array of when/then pairs
899
- * @param otherwise - Default value if no conditions match
900
- * @param alias - The alias for the computed field
901
- */
902
- selectCase(cases, otherwise, alias) {
903
- this.operationsHelper.addProjectOperation("selectCase", {
904
- cases,
905
- otherwise,
906
- alias,
907
- });
908
- return this;
909
- }
910
- /**
911
- * Adds a simple conditional field (if/else).
912
- * @param condition - The condition to evaluate
913
- * @param thenValue - Value if condition is true
914
- * @param elseValue - Value if condition is false
915
- * @param alias - The alias for the computed field
916
- */
917
- selectWhen(condition, thenValue, elseValue, alias) {
918
- this.operationsHelper.addProjectOperation("selectWhen", {
919
- condition,
920
- thenValue,
921
- elseValue,
922
- alias,
923
- });
924
- return this;
925
- }
926
- /**
927
- * Allows direct manipulation of the MongoDB projection object.
928
- * @param callback - Function that receives and modifies the projection object
929
- */
930
- selectDriverProjection(callback) {
931
- this.operationsHelper.addProjectOperation("selectDriverProjection", {
932
- callback,
933
- });
934
- return this;
935
- }
936
- /**
937
- * Extracts a JSON field from a document.
938
- * @param path - The JSON path to extract
939
- * @param alias - Optional alias for the extracted field
940
- */
941
- selectJson(path, alias) {
942
- this.operationsHelper.addProjectOperation("selectJson", { path, alias });
943
- return this;
944
- }
945
- /**
946
- * Extracts a JSON field using a raw MongoDB expression.
947
- * @param path - The JSON path
948
- * @param expression - The raw expression for extraction
949
- * @param alias - The alias for the extracted field
950
- */
951
- selectJsonRaw(path, expression, alias) {
952
- this.operationsHelper.addProjectOperation("selectJsonRaw", {
953
- path,
954
- expression,
955
- alias,
956
- });
957
- return this;
958
- }
959
- /**
960
- * Excludes a JSON path from the results.
961
- * @param path - The JSON path to exclude
962
- */
963
- deselectJson(path) {
964
- this.operationsHelper.addProjectOperation("deselectJson", { path });
965
- return this;
966
- }
967
- /**
968
- * Concatenates multiple fields into a single string field.
969
- * @param fields - Array of fields or expressions to concatenate
970
- * @param alias - The alias for the concatenated field
971
- */
972
- selectConcat(fields, alias) {
973
- this.operationsHelper.addProjectOperation("selectConcat", {
974
- fields,
975
- alias,
976
- });
977
- return this;
978
- }
979
- /**
980
- * Returns the first non-null value from a list of fields.
981
- * @param fields - Array of fields to check
982
- * @param alias - The alias for the coalesced field
983
- */
984
- selectCoalesce(fields, alias) {
985
- this.operationsHelper.addProjectOperation("selectCoalesce", {
986
- fields,
987
- alias,
988
- });
989
- return this;
990
- }
991
- /**
992
- * Adds window function operations to the query.
993
- * @param spec - The window function specification
994
- */
995
- selectWindow(spec) {
996
- this.operationsHelper.addOperation("$setWindowFields", "selectWindow", { spec }, false);
997
- return this;
998
- }
999
- deselect(...args) {
1000
- const fields = this.normalizeSelectFields(args);
1001
- this.operationsHelper.addProjectOperation("deselect", { fields });
1002
- return this;
1003
- }
1004
- /**
1005
- * Returns only distinct values for the specified fields.
1006
- * @param fields - Optional field names to use for distinctness
1007
- */
1008
- distinctValues(fields) {
1009
- this.operationsHelper.addGroupOperation("distinct", { fields }, false);
1010
- return this;
1011
- }
1012
- addSelect(...args) {
1013
- const fields = this.normalizeSelectFields(args);
1014
- this.operationsHelper.addProjectOperation("addSelect", { fields });
1015
- return this;
1016
- }
1017
- /**
1018
- * Removes all field selection restrictions.
1019
- */
1020
- clearSelect() {
1021
- this.operations = this.operations.filter((op) => op.stage !== "$project");
1022
- return this;
1023
- }
1024
- /**
1025
- * Alias for `clearSelect()`. Removes all field restrictions.
1026
- */
1027
- selectAll() {
1028
- return this.clearSelect();
1029
- }
1030
- /**
1031
- * Alias for `clearSelect()`. Resets to default field selection.
1032
- */
1033
- selectDefault() {
1034
- return this.clearSelect();
1035
- }
1036
- orderBy(fieldOrFields, direction = "asc") {
1037
- if (typeof fieldOrFields === "string") {
1038
- // Single field
1039
- this.operationsHelper.addSortOperation("orderBy", {
1040
- field: fieldOrFields,
1041
- direction,
1042
- });
1043
- }
1044
- else {
1045
- // Multiple fields - add each as a separate operation (they'll be merged)
1046
- for (const [field, dir] of Object.entries(fieldOrFields)) {
1047
- this.operationsHelper.addSortOperation("orderBy", {
1048
- field,
1049
- direction: dir,
1050
- });
1051
- }
1052
- }
1053
- return this;
1054
- }
1055
- /**
1056
- * Orders the query results by a field in descending order.
1057
- * @param field - The field name to sort by
1058
- */
1059
- orderByDesc(field) {
1060
- return this.orderBy(field, "desc");
1061
- }
1062
- /**
1063
- * Orders the query results using a raw MongoDB sort expression.
1064
- * @param expression - The raw MongoDB sort expression
1065
- * @param bindings - Optional parameter bindings
1066
- */
1067
- orderByRaw(expression, bindings) {
1068
- this.operationsHelper.addSortOperation("orderByRaw", {
1069
- expression,
1070
- bindings,
1071
- });
1072
- return this;
1073
- }
1074
- /**
1075
- * Orders the query results randomly.
1076
- */
1077
- orderByRandom(limit = 1000) {
1078
- this.operationsHelper.addSortOperation("orderByRandom", { limit }, false);
1079
- return this;
1080
- }
1081
- /**
1082
- * Orders results by a date field in descending order (newest first).
1083
- * @param column - The date column to sort by
1084
- */
1085
- latest(column = "createdAt") {
1086
- return this.orderBy(column, "desc").get();
1087
- }
1088
- /**
1089
- * Orders results by a date field in ascending order (oldest first).
1090
- * @param column - The date column to sort by
1091
- */
1092
- oldest(column = "createdAt") {
1093
- return this.orderBy(column, "asc");
1094
- }
1095
- // ============================================================================
1096
- // LIMITING / PAGINATION
1097
- // ============================================================================
1098
- /**
1099
- * Limits the number of documents returned by the query.
1100
- * @param value - The maximum number of documents to return
1101
- */
1102
- limit(value) {
1103
- this.operationsHelper.addOperation("$limit", "limit", { value }, false);
1104
- return this;
1105
- }
1106
- /**
1107
- * Skips a specified number of documents in the query results.
1108
- * @param value - The number of documents to skip
1109
- */
1110
- skip(value) {
1111
- this.operationsHelper.addOperation("$skip", "skip", { value }, false);
1112
- return this;
1113
- }
1114
- /**
1115
- * Alias for `skip()`. Skips a specified number of documents.
1116
- * @param value - The number of documents to skip
1117
- */
1118
- offset(value) {
1119
- return this.skip(value);
1120
- }
1121
- /**
1122
- * Alias for `limit()`. Limits the number of documents returned.
1123
- * @param value - The maximum number of documents to return
1124
- */
1125
- take(value) {
1126
- return this.limit(value);
1127
- }
1128
- /**
1129
- * Applies cursor-based filtering for pagination.
1130
- * @param after - Cursor value for forward pagination
1131
- * @param before - Cursor value for backward pagination
1132
- */
1133
- cursor(after, before) {
1134
- this.operationsHelper.addMatchOperation("cursor", { after, before });
1135
- return this;
1136
- }
1137
- groupBy(fields, aggregates) {
1138
- if (aggregates) {
1139
- this.operationsHelper.addGroupOperation("groupByWithAggregates", { fields, aggregates }, false);
1140
- }
1141
- else {
1142
- this.operationsHelper.addGroupOperation("groupBy", { fields }, false);
1143
- }
1144
- return this;
1145
- }
1146
- /**
1147
- * Groups documents using a raw MongoDB expression.
1148
- * @param expression - The raw grouping expression
1149
- * @param bindings - Optional parameter bindings
1150
- */
1151
- groupByRaw(expression, bindings) {
1152
- this.operationsHelper.addGroupOperation("groupByRaw", { expression, bindings }, false);
1153
- return this;
1154
- }
1155
- having(...args) {
1156
- if (args.length === 1) {
1157
- this.operationsHelper.addMatchOperation("having:condition", args[0], false);
1158
- }
1159
- else if (args.length === 2) {
1160
- this.operationsHelper.addMatchOperation("having", { field: args[0], operator: "=", value: args[1] }, false);
1161
- }
1162
- else {
1163
- this.operationsHelper.addMatchOperation("having", { field: args[0], operator: args[1], value: args[2] }, false);
1164
- }
1165
- return this;
1166
- }
1167
- /**
1168
- * Filters grouped results using a raw MongoDB expression.
1169
- * @param expression - The raw having expression
1170
- * @param bindings - Optional parameter bindings
1171
- */
1172
- havingRaw(expression, bindings) {
1173
- this.operationsHelper.addMatchOperation("havingRaw", { expression, bindings }, false);
1174
- return this;
1175
- }
1176
- join(tableOrOptions, localField, foreignField) {
1177
- const options = typeof tableOrOptions === "string"
1178
- ? {
1179
- table: tableOrOptions,
1180
- localField: localField,
1181
- foreignField: foreignField,
1182
- type: "left", // MongoDB $lookup is inherently a left outer join
1183
- }
1184
- : tableOrOptions;
1185
- this.operationsHelper.addLookupOperation("join", options);
1186
- return this;
1187
- }
1188
- leftJoin(tableOrOptions, localField, foreignField) {
1189
- const options = typeof tableOrOptions === "string"
1190
- ? {
1191
- table: tableOrOptions,
1192
- localField: localField,
1193
- foreignField: foreignField,
1194
- type: "left",
1195
- }
1196
- : { ...tableOrOptions, type: "left" };
1197
- this.operationsHelper.addLookupOperation("join", options);
1198
- return this;
1199
- }
1200
- rightJoin(tableOrOptions, localField, foreignField) {
1201
- // MongoDB $lookup is always a left join from the perspective of the input collection
1202
- // Right join semantics would require reversing the query direction
1203
- const options = typeof tableOrOptions === "string"
1204
- ? {
1205
- table: tableOrOptions,
1206
- localField: localField,
1207
- foreignField: foreignField,
1208
- type: "right",
1209
- }
1210
- : { ...tableOrOptions, type: "right" };
1211
- this.operationsHelper.addLookupOperation("join", options);
1212
- return this;
1213
- }
1214
- innerJoin(tableOrOptions, localField, foreignField) {
1215
- const options = typeof tableOrOptions === "string"
1216
- ? {
1217
- table: tableOrOptions,
1218
- localField: localField,
1219
- foreignField: foreignField,
1220
- type: "inner",
1221
- }
1222
- : { ...tableOrOptions, type: "inner" };
1223
- this.operationsHelper.addLookupOperation("join", options);
1224
- return this;
1225
- }
1226
- fullJoin(tableOrOptions, localField, foreignField) {
1227
- const options = typeof tableOrOptions === "string"
1228
- ? {
1229
- table: tableOrOptions,
1230
- localField: localField,
1231
- foreignField: foreignField,
1232
- type: "full",
1233
- }
1234
- : { ...tableOrOptions, type: "full" };
1235
- this.operationsHelper.addLookupOperation("join", options);
1236
- return this;
1237
- }
1238
- /**
1239
- * Performs a cross join with another collection.
1240
- *
1241
- * This creates a cartesian product by using $lookup with empty matching criteria.
1242
- *
1243
- * @param table - Target collection name
1244
- */
1245
- crossJoin(table) {
1246
- // Cross join: match every document in the foreign collection
1247
- this.operationsHelper.addLookupOperation("join", {
1248
- table,
1249
- localField: "_crossJoinDummy",
1250
- foreignField: "_crossJoinDummy",
1251
- type: "cross",
1252
- pipeline: [{ $match: {} }], // Match all documents
1253
- });
1254
- return this;
1255
- }
1256
- /**
1257
- * Performs a raw join using a custom aggregation pipeline.
1258
- *
1259
- * This allows full control over the $lookup stage for complex join scenarios.
1260
- *
1261
- * @param expression - Raw expression (typically a $lookup stage or pipeline)
1262
- * @param _bindings - Optional bindings (not used in MongoDB but kept for API consistency)
1263
- */
1264
- joinRaw(expression, _bindings) {
1265
- // For MongoDB, expression should be a $lookup stage object or a simple string
1266
- // describing the join. We add it as a raw operation.
1267
- this.operationsHelper.addMatchOperation("raw", { builder: () => expression }, false);
1268
- return this;
1269
- }
1270
- /**
1271
- * Allows direct manipulation of the native MongoDB query.
1272
- * @param builder - Function that receives and modifies the native query
1273
- */
1274
- raw(builder) {
1275
- this.operationsHelper.addMatchOperation("raw", { builder }, false);
1276
- return this;
1277
- }
1278
- /**
1279
- * Extends the query builder with driver-specific functionality.
1280
- * @param extension - The extension name
1281
- * @param _args - Extension-specific arguments
1282
- * @returns The extension's return value
1283
- */
1284
- extend(extension, ..._args) {
1285
- // Driver-specific extensions can be added here
1286
- throw new Error(`Extension '${extension}' is not supported by MongoQueryBuilder`);
1287
- }
1288
- /**
1289
- * Creates a deep copy of the query builder.
1290
- * @returns A new query builder instance with copied operations
1291
- */
1292
- clone() {
1293
- const cloned = new MongoQueryBuilder(this.table, this.dataSource);
1294
- cloned.operations = [...this.operations];
1295
- cloned.hydrateCallback = this.hydrateCallback?.bind(cloned);
1296
- cloned.fetchingCallback = this.fetchingCallback?.bind(cloned);
1297
- cloned.hydratingCallback = this.hydratingCallback?.bind(cloned);
1298
- cloned.fetchedCallback = this.fetchedCallback?.bind(cloned);
1299
- // Copy scope state
1300
- cloned.pendingGlobalScopes = this.pendingGlobalScopes;
1301
- cloned.availableLocalScopes = this.availableLocalScopes;
1302
- cloned.disabledGlobalScopes = new Set(this.disabledGlobalScopes);
1303
- cloned.scopesApplied = this.scopesApplied;
1304
- cloned.__operationsHelper = this.__operationsHelper;
1305
- return cloned;
1306
- }
1307
- /**
1308
- * Executes a callback with the query builder without breaking the chain.
1309
- * @param callback - Function to execute with the builder
1310
- */
1311
- tap(callback) {
1312
- callback(this);
1313
- return this;
1314
- }
1315
- /**
1316
- * Conditionally applies query modifications based on a condition.
1317
- * @param condition - The condition to evaluate
1318
- * @param callback - Function to execute if condition is true
1319
- * @param otherwise - Optional function to execute if condition is false
1320
- *
1321
- * @example
1322
- * query.when(searchTerm, (q, term) => q.whereLike('name', term))
1323
- */
1324
- when(condition, callback, otherwise) {
1325
- if (condition) {
1326
- callback(this, condition);
1327
- }
1328
- else if (otherwise) {
1329
- otherwise(this);
1330
- }
1331
- return this;
1332
- }
1333
- // ============================================================================
1334
- // EXECUTION METHODS
1335
- // ============================================================================
1336
- /**
1337
- * Executes the query and returns all matching documents.
1338
- * @returns an array of matching documents
1339
- */
1340
- async get() {
1341
- const startTime = Date.now();
1342
- // Emit onFetching event
1343
- if (this.fetchingCallback) {
1344
- await this.fetchingCallback(this);
1345
- }
1346
- // Execute query and get raw records
1347
- const rawRecords = await this.execute();
1348
- // Emit onHydrating event
1349
- if (this.hydratingCallback) {
1350
- await this.hydratingCallback(rawRecords, {
1351
- query: this,
1352
- hydrateCallback: this.hydrateCallback,
1353
- });
1354
- }
1355
- // Hydrate records
1356
- const hydratedRecords = this.hydrateCallback
1357
- ? rawRecords.map(this.hydrateCallback)
1358
- : rawRecords;
1359
- // Emit onFetched event
1360
- if (this.fetchedCallback) {
1361
- await this.fetchedCallback(hydratedRecords, {
1362
- query: this,
1363
- rawRecords,
1364
- duration: Date.now() - startTime,
1365
- });
1366
- }
1367
- return hydratedRecords;
1368
- }
1369
- /**
1370
- * Execute the query and get first result
1371
- * This is different than `first` as first adds a `limit = 1` to the pipeline
1372
- */
1373
- async getFirst() {
1374
- return (await this.get())?.[0] ?? null;
1375
- }
1376
- /**
1377
- * Executes the query and returns the first matching document.
1378
- * @returns the first document or null
1379
- */
1380
- async first() {
1381
- const results = await this.limit(1).get();
1382
- return results.length > 0 ? results[0] : null;
1383
- }
1384
- /**
1385
- * Executes the query and returns the first matching document, throwing if none found.
1386
- * @returns the first document
1387
- */
1388
- async firstOrFail() {
1389
- const result = await this.first();
1390
- if (!result) {
1391
- throw new Error("No records found matching the query");
1392
- }
1393
- return result;
1394
- }
1395
- /**
1396
- * Find a document by its primary key (id field).
1397
- */
1398
- async find(id) {
1399
- return this.where("id", id).first();
1400
- }
1401
- /**
1402
- * Configures the query to retrieve the last matching document.
1403
- */
1404
- last(field = "createdAt") {
1405
- this.orderBy(field, "desc");
1406
- return this.first();
1407
- }
1408
- /**
1409
- * Counts the number of documents matching the query.
1410
- * @returns the count of matching documents
1411
- */
1412
- async count() {
1413
- const pipeline = this.buildPipeline();
1414
- pipeline.push({ $count: "total" });
1415
- const results = await this.execute(pipeline);
1416
- return results.length > 0 ? results[0].total : 0;
1417
- }
1418
- /**
1419
- * Calculates the sum of a numeric field across matching documents.
1420
- * @param field - The numeric field to sum
1421
- * @returns the sum value
1422
- */
1423
- async sum(field) {
1424
- this.groupByRaw({
1425
- _id: null,
1426
- total: { $sum: `$${field}` },
1427
- });
1428
- // make sure to clear the data map callback
1429
- this.hydrateCallback = undefined;
1430
- const result = await this.getFirst();
1431
- return result?.total ?? 0;
1432
- }
1433
- /**
1434
- * Calculates the average value of a numeric field across matching documents.
1435
- * @param field - The numeric field to average
1436
- * @returns the average value
1437
- */
1438
- async avg(field) {
1439
- this.groupByRaw({
1440
- _id: null,
1441
- average: { $avg: `$${field}` },
1442
- });
1443
- // make sure to clear the data map callback
1444
- this.hydrateCallback = undefined;
1445
- return (await this.getFirst())?.average ?? 0;
1446
- }
1447
- /**
1448
- * Finds the minimum value of a field across matching documents.
1449
- * @param field - The field to find the minimum of
1450
- * @returns the minimum value
1451
- */
1452
- async min(field) {
1453
- this.groupByRaw({
1454
- _id: null,
1455
- minimum: { $min: `$${field}` },
1456
- });
1457
- // make sure to clear the data map callback
1458
- this.hydrateCallback = undefined;
1459
- return (await this.getFirst())?.minimum ?? 0;
1460
- }
1461
- /**
1462
- * Finds the maximum value of a field across matching documents.
1463
- * @param field - The field to find the maximum of
1464
- * @returns the maximum value
1465
- */
1466
- async max(field) {
1467
- this.groupByRaw({
1468
- _id: null,
1469
- maximum: { $max: `$${field}` },
1470
- });
1471
- // make sure to clear the data map callback
1472
- this.hydrateCallback = undefined;
1473
- return (await this.getFirst())?.maximum ?? 0;
1474
- }
1475
- /**
1476
- * Returns an array of distinct values for a field, respecting query filters.
1477
- * @param field - The field to get distinct values from
1478
- * @returns an array of distinct values
1479
- */
1480
- async distinct(field, ignoreNull = true) {
1481
- if (ignoreNull) {
1482
- this.whereNotNull(field);
1483
- }
1484
- this.groupBy(field);
1485
- // make sure to clear the data map callback
1486
- this.hydrateCallback = undefined;
1487
- const results = await this.get();
1488
- return results.map((doc) => doc._id);
1489
- }
1490
- /**
1491
- * Count distinct values for a field, respecting query filters.
1492
- * @param field - The field to count distinct values for
1493
- * @returns the count of distinct values
1494
- */
1495
- async countDistinct(field, ignoreNull = true) {
1496
- if (ignoreNull) {
1497
- this.whereNotNull(field);
1498
- }
1499
- return await this.groupBy(field).count();
1500
- }
1501
- /**
1502
- * Extracts a single field value from each matching document.
1503
- * @param field - The field to extract
1504
- * @returns an array of field values
1505
- */
1506
- async pluck(field) {
1507
- // make sure to clear the data map callback
1508
- this.hydrateCallback = undefined;
1509
- // Use object aliasing: { [field]: "value" } to project field as "value"
1510
- const results = await this.selectAs(field, "value").get();
1511
- return results.map((doc) => doc.value).filter((value) => value !== undefined);
1512
- }
1513
- /**
1514
- * Gets the value of a single field from the first matching document.
1515
- * @param field - The field to extract
1516
- * @returns the field value or null
1517
- */
1518
- async value(field) {
1519
- // make sure to clear the data map callback
1520
- this.hydrateCallback = undefined;
1521
- const result = await this.selectAs(field, "value").first();
1522
- return result?.value ?? null;
1523
- }
1524
- /**
1525
- * Checks if any documents match the query.
1526
- * @param filter - Optional filter to apply to the query
1527
- * @returns true if documents exist, false otherwise
1528
- */
1529
- async exists(filter) {
1530
- if (filter) {
1531
- this.where(filter);
1532
- }
1533
- const count = await this.limit(1).count();
1534
- return count > 0;
1535
- }
1536
- /**
1537
- * Checks if no documents match the query.
1538
- * @param filter - Optional filter to apply to the query
1539
- * @returns true if no documents exist, false otherwise
1540
- */
1541
- async notExists(filter) {
1542
- return !(await this.exists(filter));
1543
- }
1544
- /**
1545
- * Increments a numeric field by the specified amount for first matching document.
1546
- * @param field - The field to increment
1547
- * @param amount - The amount to increment by (default: 1)
1548
- * @returns the new value
1549
- */
1550
- async increment(field, amount = 1) {
1551
- const filter = this.buildFilter();
1552
- const result = await this.collection.findOneAndUpdate(filter, {
1553
- $inc: { [field]: amount },
1554
- }, {
1555
- returnDocument: "after",
1556
- });
1557
- return reinforcements.get(result, field, 0);
1558
- }
1559
- /**
1560
- * Decrements a numeric field by the specified amount.
1561
- * @param field - The field to decrement
1562
- * @param amount - The amount to decrement by
1563
- * @returns the new value
1564
- */
1565
- async decrement(field, amount = 1) {
1566
- return this.increment(field, -amount);
1567
- }
1568
- /**
1569
- * Increments a numeric field by the specified amount for all matching documents.
1570
- * @param field - The field to increment
1571
- * @param amount - The amount to increment by (default: 1)
1572
- * @returns the number of documents modified
1573
- */
1574
- async incrementMany(field, amount = 1) {
1575
- const filter = this.buildFilter();
1576
- const result = await this.dataSource.driver.updateMany(this.table, filter, {
1577
- $inc: { [field]: amount },
1578
- });
1579
- return result.modifiedCount;
1580
- }
1581
- /**
1582
- * Decrements a numeric field by the specified amount for all matching documents.
1583
- * @param field - The field to decrement
1584
- * @param amount - The amount to decrement by (default: 1)
1585
- * @returns the number of documents modified
1586
- */
1587
- async decrementMany(field, amount = 1) {
1588
- return this.incrementMany(field, -amount);
1589
- }
1590
- /**
1591
- * Delete all documents matching the query.
1592
- */
1593
- async delete() {
1594
- const filter = this.buildFilter();
1595
- return await this.dataSource.driver.deleteMany(this.table, filter);
1596
- }
1597
- /**
1598
- * Delete a single document matching the query.
1599
- */
1600
- async deleteOne() {
1601
- const filter = this.buildFilter();
1602
- return await this.dataSource.driver.delete(this.table, filter);
1603
- }
1604
- /**
1605
- * Update the given fields for all documents matching the query.
1606
- */
1607
- async update(fields) {
1608
- const filter = this.buildFilter();
1609
- const result = await this.dataSource.driver.updateMany(this.table, filter, {
1610
- $set: fields,
1611
- });
1612
- return result.modifiedCount;
1613
- }
1614
- /**
1615
- * Unset the given fields from all documents matching the query.
1616
- */
1617
- async unset(...fields) {
1618
- const filter = this.buildFilter();
1619
- const result = await this.dataSource.driver.updateMany(this.table, filter, {
1620
- $unset: fields.reduce((acc, field) => {
1621
- acc[field] = 1;
1622
- return acc;
1623
- }, {}),
1624
- });
1625
- return result.modifiedCount;
1626
- }
1627
- // ============================================================================
1628
- // CHUNKING / PAGINATION
1629
- // ============================================================================
1630
- /**
1631
- * Processes query results in chunks, executing a callback for each chunk.
1632
- * @param size - The number of documents per chunk
1633
- * @param callback - Function to execute for each chunk
1634
- * @returns void
1635
- */
1636
- async chunk(size, callback) {
1637
- let chunkIndex = 0;
1638
- let hasMore = true;
1639
- while (hasMore) {
1640
- const chunk = await this.clone()
1641
- .skip(chunkIndex * size)
1642
- .limit(size)
1643
- .get();
1644
- if (chunk.length === 0) {
1645
- break;
1646
- }
1647
- const shouldContinue = await callback(chunk, chunkIndex);
1648
- if (shouldContinue === false) {
1649
- break;
1650
- }
1651
- hasMore = chunk.length === size;
1652
- chunkIndex++;
1653
- }
1654
- }
1655
- /**
1656
- * Executes the query with traditional page-based pagination.
1657
- * @param options - Pagination options
1658
- * @returns pagination result with data and metadata
1659
- */
1660
- async paginate(options) {
1661
- const page = options?.page ?? 1;
1662
- const limit = options?.limit ?? 10;
1663
- const skip = (page - 1) * limit;
1664
- const [data, total] = await Promise.all([
1665
- this.clone().skip(skip).limit(limit).get(),
1666
- this.count(),
1667
- ]);
1668
- return {
1669
- data,
1670
- pagination: {
1671
- total,
1672
- page,
1673
- limit,
1674
- pages: Math.ceil(total / limit),
1675
- },
1676
- };
1677
- }
1678
- /**
1679
- * Executes the query with cursor-based pagination supporting both directions.
1680
- * @param options - Cursor pagination options
1681
- * @returns cursor pagination result with data and cursor info
1682
- */
1683
- async cursorPaginate(options) {
1684
- const limit = options?.limit ?? 10;
1685
- const cursor = options?.cursor;
1686
- const column = options?.column ?? "id";
1687
- const direction = options?.direction ?? "next";
1688
- // Apply cursor filter
1689
- if (cursor) {
1690
- const operator = direction === "next" ? ">" : "<";
1691
- this.where(column, operator, cursor);
1692
- }
1693
- // Apply sorting
1694
- const sortOrder = direction === "next" ? "asc" : "desc";
1695
- this.orderBy(column, sortOrder);
1696
- this.orderBy("_id", sortOrder); // Always sort by _id to ensure consistent order
1697
- // Fetch one extra to detect if there are more results
1698
- const results = await this.limit(limit + 1).get();
1699
- const hasMore = results.length > limit;
1700
- let data = hasMore ? results.slice(0, limit) : results;
1701
- // Reverse results if fetching previous page to keep natural order
1702
- if (direction === "prev") {
1703
- data = data.reverse();
1704
- }
1705
- // Determine cursors based on actual data
1706
- let nextCursor;
1707
- let prevCursor;
1708
- let hasPrev = false;
1709
- if (data.length > 0) {
1710
- const firstItem = data[0][column];
1711
- const lastItem = data[data.length - 1][column];
1712
- if (direction === "next") {
1713
- // Forward pagination
1714
- nextCursor = hasMore ? lastItem : undefined;
1715
- // Check if there's a previous page
1716
- if (cursor) {
1717
- hasPrev = true;
1718
- prevCursor = firstItem;
1719
- }
1720
- }
1721
- else {
1722
- // Backward pagination
1723
- prevCursor = hasMore ? firstItem : undefined;
1724
- hasPrev = hasMore;
1725
- // Check if there's a next page
1726
- if (cursor) {
1727
- nextCursor = lastItem;
1728
- }
1729
- }
1730
- }
1731
- return {
1732
- data,
1733
- pagination: {
1734
- hasMore,
1735
- hasPrev,
1736
- nextCursor,
1737
- prevCursor,
1738
- },
1739
- };
1740
- }
1741
- // ============================================================================
1742
- // INSPECTION / DEBUGGING
1743
- // ============================================================================
1744
- /**
1745
- * Returns the MongoDB aggregation pipeline that will be executed.
1746
- */
1747
- parse() {
1748
- return { pipeline: this.buildPipeline() };
1749
- }
1750
- /**
1751
- * Returns a formatted string representation of the query pipeline.
1752
- * @returns A formatted string representation of the pipeline
1753
- */
1754
- pretty() {
1755
- return this.getParser().toPrettyString();
1756
- }
1757
- /**
1758
- * Returns the MongoDB query execution plan.
1759
- * @returns MongoDB's explain output
1760
- */
1761
- async explain() {
1762
- // TODO: Trigger the explaining event
1763
- const pipeline = this.buildPipeline();
1764
- const session = databaseTransactionContext.databaseTransactionContext.getSession();
1765
- const options = session ? { session, explain: true } : { explain: true };
1766
- return this.collection.aggregate(pipeline, options).toArray();
1767
- }
1768
- // ============================================================================
1769
- // INTERNAL PIPELINE BUILDING
1770
- // ============================================================================
1771
- /**
1772
- * Get query parser instance
1773
- */
1774
- getParser() {
1775
- this.applyPendingScopes();
1776
- return new mongodbQueryParser.MongoQueryParser({
1777
- collection: this.collection,
1778
- operations: this.operations,
1779
- createSubBuilder: () => new MongoQueryBuilder(this.table, this.dataSource),
1780
- });
1781
- }
1782
- /**
1783
- * Build the MongoDB aggregation pipeline from the operations list.
1784
- * @returns The MongoDB aggregation pipeline
1785
- */
1786
- buildPipeline() {
1787
- const parser = this.getParser();
1788
- return parser.parse();
1789
- }
1790
- /**
1791
- * Build a MongoDB filter object from the query's where clauses.
1792
- * Used for update operations like increment/decrement.
1793
- * @returns The MongoDB filter object
1794
- */
1795
- buildFilter() {
1796
- // Get all match operations
1797
- const matchOperations = this.operations.filter((op) => op.stage === "$match");
1798
- if (matchOperations.length === 0) {
1799
- return {}; // No filters, match all documents
1800
- }
1801
- // Build the pipeline and extract the first $match stage
1802
- const pipeline = this.buildPipeline();
1803
- const matchStage = pipeline.find((stage) => stage.$match);
1804
- if (matchStage && matchStage.$match) {
1805
- return matchStage.$match;
1806
- }
1807
- return {};
1808
- }
1809
- /**
1810
- * Execute the aggregate command
1811
- */
1812
- async execute(pipeline) {
1813
- const aggregationPipeline = pipeline || this.buildPipeline();
1814
- const session = databaseTransactionContext.databaseTransactionContext.getSession();
1815
- const options = { session };
1816
- // TODO: Trigger the executing event
1817
- const results = (await this.collection
1818
- .aggregate(aggregationPipeline, options)
1819
- .toArray());
1820
- // TODO: Trigger the fetched event
1821
- // we need to cleanup the operations list
1822
- this.operations = [];
1823
- this.operationsHelper.setOperations(this.operations);
1824
- return results;
1825
- }
1826
- // ============================================================================
1827
- // RELATIONS / EAGER LOADING (Stubs)
1828
- // ============================================================================
1829
- /**
1830
- * Relations to eagerly load.
1831
- */
1832
- eagerLoadRelations = new Map();
1833
- /**
1834
- * Relations to count.
1835
- */
1836
- countRelations = [];
1837
- /**
1838
- * Relations to load via $lookup (single query).
1839
- */
1840
- joinRelations = new Map();
1841
- /**
1842
- * Load relations using MongoDB $lookup in a single aggregation query.
1843
- *
1844
- * Unlike `with()` which uses separate queries, `joinWith()` uses
1845
- * $lookup to fetch related data in a single aggregation pipeline.
1846
- *
1847
- * @param relations - Relation names to load via $lookup
1848
- * @returns This builder for chaining
1849
- */
1850
- joinWith(...relations) {
1851
- for (const relation of relations) {
1852
- const def = this.relationDefinitions?.[relation];
1853
- if (def) {
1854
- this.joinRelations.set(relation, {
1855
- alias: `_rel_${relation}`,
1856
- type: def.type,
1857
- });
1858
- }
1859
- }
1860
- return this;
1861
- }
1862
- /**
1863
- * Eagerly load one or more relations.
1864
- *
1865
- * Supported patterns:
1866
- * - `with("posts")` - Load relation
1867
- * - `with("posts", "comments")` - Load multiple relations
1868
- * - `with("posts", callback)` - Load relation with constraint
1869
- * - `with({ posts: true, comments: callback })` - Object configuration
1870
- *
1871
- * @param args - Relation name(s), callbacks, or configuration object
1872
- */
1873
- with(...args) {
1874
- for (let i = 0; i < args.length; i++) {
1875
- const arg = args[i];
1876
- if (typeof arg === "string") {
1877
- // Check if next argument is a callback for this relation
1878
- const nextArg = args[i + 1];
1879
- if (typeof nextArg === "function") {
1880
- this.eagerLoadRelations.set(arg, nextArg);
1881
- i++; // Skip the callback in next iteration
1882
- }
1883
- else {
1884
- this.eagerLoadRelations.set(arg, true);
1885
- }
1886
- }
1887
- else if (typeof arg === "object" && arg !== null) {
1888
- for (const [key, value] of Object.entries(arg)) {
1889
- this.eagerLoadRelations.set(key, value);
1890
- }
1891
- }
1892
- // Functions not preceded by a string are ignored (invalid usage)
1893
- }
1894
- return this;
1895
- }
1896
- /**
1897
- * Add a count of related models as a virtual field.
1898
- * @param relations - Relation name(s) to count
1899
- */
1900
- withCount(...relations) {
1901
- this.countRelations.push(...relations);
1902
- return this;
1903
- }
1904
- /**
1905
- * Filter results to only those that have related models.
1906
- * @param relation - Relation name
1907
- * @param operator - Optional comparison operator
1908
- * @param count - Optional count to compare against
1909
- */
1910
- has(relation, operator, count) {
1911
- // TODO: Implement has() using $lookup and $match
1912
- this.operationsHelper.addMatchOperation("has", { relation, operator, count });
1913
- return this;
1914
- }
1915
- /**
1916
- * Filter results that have related models matching specific conditions.
1917
- * @param relation - Relation name
1918
- * @param callback - Callback to define conditions
1919
- */
1920
- whereHas(relation, callback) {
1921
- // TODO: Implement whereHas() using $lookup with pipeline
1922
- this.operationsHelper.addMatchOperation("whereHas", { relation, callback });
1923
- return this;
1924
- }
1925
- /**
1926
- * Filter results that don't have any related models.
1927
- * @param relation - Relation name
1928
- */
1929
- doesntHave(relation) {
1930
- // TODO: Implement doesntHave() using $lookup and $match
1931
- this.operationsHelper.addMatchOperation("doesntHave", { relation });
1932
- return this;
1933
- }
1934
- /**
1935
- * Filter results that don't have related models matching specific conditions.
1936
- * @param relation - Relation name
1937
- * @param callback - Callback to define conditions
1938
- */
1939
- whereDoesntHave(relation, callback) {
1940
- // TODO: Implement whereDoesntHave() using $lookup with pipeline
1941
- this.operationsHelper.addMatchOperation("whereDoesntHave", { relation, callback });
1942
- return this;
1943
- }
1944
- /**
1945
- * Nearest-neighbour vector similarity search via MongoDB Atlas $vectorSearch.
1946
- *
1947
- * Adds two pipeline stages:
1948
- * 1. `$vectorSearch` — runs the ANN search using the Atlas vector index.
1949
- * Must be the first stage in the pipeline. Limit is embedded here.
1950
- * 2. `$addFields` — exposes `{ $meta: "vectorSearchScore" }` under `alias`
1951
- * so callers can filter by minimum score after `.get()`.
1952
- *
1953
- * **Prerequisites:**
1954
- * - MongoDB Atlas cluster (local/Community MongoDB does NOT support $vectorSearch)
1955
- * - A vector search index on the collection, e.g.:
1956
- * `{ "fields": [{ "type": "vector", "path": "embedding", "numDimensions": 1536, "similarity": "cosine" }] }`
1957
- * - The index name convention used here is `"${column}_index"` (override via `alias` if needed).
1958
- *
1959
- * @param column - Vector column name (e.g. `"embedding"`)
1960
- * @param embedding - Query embedding as a plain number array
1961
- * @param alias - Score alias added to each result row (default: `"score"`)
1962
- *
1963
- * @example
1964
- * ```typescript
1965
- * const results = await Vector.query()
1966
- * .where({ organization_id: "org-123" })
1967
- * .nearestTo("embedding", queryEmbedding)
1968
- * .limit(5)
1969
- * .get<VectorRow & { score: number }>();
1970
- * ```
1971
- */
1972
- nearestTo(column, embedding, alias = "score") {
1973
- // Grab the limit op recorded so far (default to 10 if not set yet)
1974
- const limitOp = this.operations.find((op) => op.type === "limit");
1975
- const limit = limitOp?.data?.value ?? 10;
1976
- // Stage 1: $vectorSearch — ANN search via Atlas vector index
1977
- this.operationsHelper.addOperation("$vectorSearch", "vectorSearch", {
1978
- index: `${column}_index`,
1979
- path: column,
1980
- queryVector: embedding,
1981
- numCandidates: limit * 10,
1982
- limit,
1983
- }, false);
1984
- // Stage 2: $addFields — expose vectorSearchScore as the score alias
1985
- this.operationsHelper.addOperation("$addFields", "vectorSearchScore", { [alias]: { $meta: "vectorSearchScore" } }, false);
1986
- return this;
1987
- }
1988
- }exports.MongoQueryBuilder=MongoQueryBuilder;//# sourceMappingURL=mongodb-query-builder.js.map