joist-core 2.4.0 → 2.5.0-next.1

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 (903) hide show
  1. package/build/BaseEntity.d.cts +3 -4
  2. package/build/BaseEntity.d.cts.map +1 -1
  3. package/build/BaseEntity.d.mts +3 -4
  4. package/build/BaseEntity.d.mts.map +1 -1
  5. package/build/Entity.d.cts +3 -4
  6. package/build/Entity.d.cts.map +1 -1
  7. package/build/Entity.d.mts +3 -4
  8. package/build/Entity.d.mts.map +1 -1
  9. package/build/EntityFields.d.cts +3 -4
  10. package/build/EntityFields.d.cts.map +1 -1
  11. package/build/EntityFields.d.mts +3 -4
  12. package/build/EntityFields.d.mts.map +1 -1
  13. package/build/EntityManager.cjs +102 -22
  14. package/build/EntityManager.cjs.map +1 -1
  15. package/build/EntityManager.d.cts +99 -54
  16. package/build/EntityManager.d.cts.map +1 -1
  17. package/build/EntityManager.d.mts +99 -54
  18. package/build/EntityManager.d.mts.map +1 -1
  19. package/build/EntityManager.js +102 -24
  20. package/build/EntityManager.js.map +1 -1
  21. package/build/EntityMetadata.cjs +0 -1
  22. package/build/EntityMetadata.cjs.map +1 -1
  23. package/build/EntityMetadata.d.cts +47 -36
  24. package/build/EntityMetadata.d.cts.map +1 -1
  25. package/build/EntityMetadata.d.mts +47 -36
  26. package/build/EntityMetadata.d.mts.map +1 -1
  27. package/build/EntityMetadata.js +0 -1
  28. package/build/EntityMetadata.js.map +1 -1
  29. package/build/EnumMetadata.d.cts +1 -2
  30. package/build/EnumMetadata.d.cts.map +1 -1
  31. package/build/EnumMetadata.d.mts +1 -2
  32. package/build/EnumMetadata.d.mts.map +1 -1
  33. package/build/IndexManager.cjs +25 -5
  34. package/build/IndexManager.cjs.map +1 -1
  35. package/build/IndexManager.d.cts +2 -3
  36. package/build/IndexManager.d.cts.map +1 -1
  37. package/build/IndexManager.d.mts +2 -3
  38. package/build/IndexManager.d.mts.map +1 -1
  39. package/build/IndexManager.js +25 -5
  40. package/build/IndexManager.js.map +1 -1
  41. package/build/InstanceData.cjs.map +1 -1
  42. package/build/InstanceData.d.cts +1 -2
  43. package/build/InstanceData.d.cts.map +1 -1
  44. package/build/InstanceData.d.mts +1 -2
  45. package/build/InstanceData.d.mts.map +1 -1
  46. package/build/InstanceData.js.map +1 -1
  47. package/build/PluginManager.cjs.map +1 -1
  48. package/build/PluginManager.d.cts +4 -4
  49. package/build/PluginManager.d.cts.map +1 -1
  50. package/build/PluginManager.d.mts +4 -4
  51. package/build/PluginManager.d.mts.map +1 -1
  52. package/build/PluginManager.js.map +1 -1
  53. package/build/RowData.d.cts +3 -4
  54. package/build/RowData.d.cts.map +1 -1
  55. package/build/RowData.d.mts +3 -4
  56. package/build/RowData.d.mts.map +1 -1
  57. package/build/batchloaders/BatchLoader.cjs.map +1 -1
  58. package/build/batchloaders/BatchLoader.d.cts +1 -2
  59. package/build/batchloaders/BatchLoader.d.cts.map +1 -1
  60. package/build/batchloaders/BatchLoader.d.mts +1 -2
  61. package/build/batchloaders/BatchLoader.d.mts.map +1 -1
  62. package/build/batchloaders/BatchLoader.js.map +1 -1
  63. package/build/batchloaders/enumCollectionBatchLoader.d.cts +2 -3
  64. package/build/batchloaders/enumCollectionBatchLoader.d.cts.map +1 -1
  65. package/build/batchloaders/enumCollectionBatchLoader.d.mts +2 -3
  66. package/build/batchloaders/enumCollectionBatchLoader.d.mts.map +1 -1
  67. package/build/batchloaders/loadBatchLoader.d.cts +2 -3
  68. package/build/batchloaders/loadBatchLoader.d.cts.map +1 -1
  69. package/build/batchloaders/loadBatchLoader.d.mts +2 -3
  70. package/build/batchloaders/loadBatchLoader.d.mts.map +1 -1
  71. package/build/batchloaders/manyToManyBatchLoader.d.cts +2 -3
  72. package/build/batchloaders/manyToManyBatchLoader.d.cts.map +1 -1
  73. package/build/batchloaders/manyToManyBatchLoader.d.mts +2 -3
  74. package/build/batchloaders/manyToManyBatchLoader.d.mts.map +1 -1
  75. package/build/batchloaders/oneToManyBatchLoader.cjs +1 -1
  76. package/build/batchloaders/oneToManyBatchLoader.d.cts +2 -3
  77. package/build/batchloaders/oneToManyBatchLoader.d.cts.map +1 -1
  78. package/build/batchloaders/oneToManyBatchLoader.d.mts +2 -3
  79. package/build/batchloaders/oneToManyBatchLoader.d.mts.map +1 -1
  80. package/build/batchloaders/oneToManyBatchLoader.js +1 -1
  81. package/build/batchloaders/oneToOneBatchLoader.cjs +1 -1
  82. package/build/batchloaders/oneToOneBatchLoader.d.cts +2 -3
  83. package/build/batchloaders/oneToOneBatchLoader.d.cts.map +1 -1
  84. package/build/batchloaders/oneToOneBatchLoader.d.mts +2 -3
  85. package/build/batchloaders/oneToOneBatchLoader.d.mts.map +1 -1
  86. package/build/batchloaders/oneToOneBatchLoader.js +1 -1
  87. package/build/batchloaders/populateBatchLoader.d.cts +2 -3
  88. package/build/batchloaders/populateBatchLoader.d.cts.map +1 -1
  89. package/build/batchloaders/populateBatchLoader.d.mts +2 -3
  90. package/build/batchloaders/populateBatchLoader.d.mts.map +1 -1
  91. package/build/batchloaders/recursiveChildrenBatchLoader.cjs +1 -1
  92. package/build/batchloaders/recursiveChildrenBatchLoader.d.cts +2 -3
  93. package/build/batchloaders/recursiveChildrenBatchLoader.d.cts.map +1 -1
  94. package/build/batchloaders/recursiveChildrenBatchLoader.d.mts +2 -3
  95. package/build/batchloaders/recursiveChildrenBatchLoader.d.mts.map +1 -1
  96. package/build/batchloaders/recursiveChildrenBatchLoader.js +1 -1
  97. package/build/batchloaders/recursiveM2mBatchLoader.d.cts +2 -3
  98. package/build/batchloaders/recursiveM2mBatchLoader.d.cts.map +1 -1
  99. package/build/batchloaders/recursiveM2mBatchLoader.d.mts +2 -3
  100. package/build/batchloaders/recursiveM2mBatchLoader.d.mts.map +1 -1
  101. package/build/batchloaders/recursiveParentsBatchLoader.cjs +1 -1
  102. package/build/batchloaders/recursiveParentsBatchLoader.d.cts +2 -3
  103. package/build/batchloaders/recursiveParentsBatchLoader.d.cts.map +1 -1
  104. package/build/batchloaders/recursiveParentsBatchLoader.d.mts +2 -3
  105. package/build/batchloaders/recursiveParentsBatchLoader.d.mts.map +1 -1
  106. package/build/batchloaders/recursiveParentsBatchLoader.js +1 -1
  107. package/build/changes.cjs +1 -1
  108. package/build/changes.cjs.map +1 -1
  109. package/build/changes.d.cts +9 -10
  110. package/build/changes.d.cts.map +1 -1
  111. package/build/changes.d.mts +9 -10
  112. package/build/changes.d.mts.map +1 -1
  113. package/build/changes.js +1 -1
  114. package/build/changes.js.map +1 -1
  115. package/build/config.cjs +165 -26
  116. package/build/config.cjs.map +1 -1
  117. package/build/config.d.cts +111 -19
  118. package/build/config.d.cts.map +1 -1
  119. package/build/config.d.mts +111 -19
  120. package/build/config.d.mts.map +1 -1
  121. package/build/config.js +165 -26
  122. package/build/config.js.map +1 -1
  123. package/build/configure.cjs +32 -2
  124. package/build/configure.cjs.map +1 -1
  125. package/build/configure.d.cts +8 -9
  126. package/build/configure.d.cts.map +1 -1
  127. package/build/configure.d.mts +8 -9
  128. package/build/configure.d.mts.map +1 -1
  129. package/build/configure.js +32 -2
  130. package/build/configure.js.map +1 -1
  131. package/build/dataloaders/fastWhereFilterHash.d.cts +1 -2
  132. package/build/dataloaders/fastWhereFilterHash.d.cts.map +1 -1
  133. package/build/dataloaders/fastWhereFilterHash.d.mts +1 -2
  134. package/build/dataloaders/fastWhereFilterHash.d.mts.map +1 -1
  135. package/build/dataloaders/findByUniqueDataLoader.d.cts +2 -3
  136. package/build/dataloaders/findByUniqueDataLoader.d.cts.map +1 -1
  137. package/build/dataloaders/findByUniqueDataLoader.d.mts +2 -3
  138. package/build/dataloaders/findByUniqueDataLoader.d.mts.map +1 -1
  139. package/build/dataloaders/findCountDataLoader.d.cts +4 -5
  140. package/build/dataloaders/findCountDataLoader.d.cts.map +1 -1
  141. package/build/dataloaders/findCountDataLoader.d.mts +4 -5
  142. package/build/dataloaders/findCountDataLoader.d.mts.map +1 -1
  143. package/build/dataloaders/findDataLoader.cjs +1 -1
  144. package/build/dataloaders/findDataLoader.d.cts +11 -12
  145. package/build/dataloaders/findDataLoader.d.cts.map +1 -1
  146. package/build/dataloaders/findDataLoader.d.mts +11 -12
  147. package/build/dataloaders/findDataLoader.d.mts.map +1 -1
  148. package/build/dataloaders/findDataLoader.js +1 -1
  149. package/build/dataloaders/findIdsDataLoader.d.cts +2 -3
  150. package/build/dataloaders/findIdsDataLoader.d.cts.map +1 -1
  151. package/build/dataloaders/findIdsDataLoader.d.mts +2 -3
  152. package/build/dataloaders/findIdsDataLoader.d.mts.map +1 -1
  153. package/build/dataloaders/findOrCreateDataLoader.cjs +6 -2
  154. package/build/dataloaders/findOrCreateDataLoader.cjs.map +1 -1
  155. package/build/dataloaders/findOrCreateDataLoader.d.cts +3 -3
  156. package/build/dataloaders/findOrCreateDataLoader.d.cts.map +1 -1
  157. package/build/dataloaders/findOrCreateDataLoader.d.mts +3 -3
  158. package/build/dataloaders/findOrCreateDataLoader.d.mts.map +1 -1
  159. package/build/dataloaders/findOrCreateDataLoader.js +7 -3
  160. package/build/dataloaders/findOrCreateDataLoader.js.map +1 -1
  161. package/build/dataloaders/findPaginatedDataLoader.cjs +10 -12
  162. package/build/dataloaders/findPaginatedDataLoader.cjs.map +1 -1
  163. package/build/dataloaders/findPaginatedDataLoader.d.cts +1 -2
  164. package/build/dataloaders/findPaginatedDataLoader.d.cts.map +1 -1
  165. package/build/dataloaders/findPaginatedDataLoader.d.mts +1 -2
  166. package/build/dataloaders/findPaginatedDataLoader.d.mts.map +1 -1
  167. package/build/dataloaders/findPaginatedDataLoader.js +10 -12
  168. package/build/dataloaders/findPaginatedDataLoader.js.map +1 -1
  169. package/build/dataloaders/lensDataLoader.d.cts +2 -3
  170. package/build/dataloaders/lensDataLoader.d.cts.map +1 -1
  171. package/build/dataloaders/lensDataLoader.d.mts +2 -3
  172. package/build/dataloaders/lensDataLoader.d.mts.map +1 -1
  173. package/build/dataloaders/manyToManyFindDataLoader.d.cts +2 -3
  174. package/build/dataloaders/manyToManyFindDataLoader.d.cts.map +1 -1
  175. package/build/dataloaders/manyToManyFindDataLoader.d.mts +2 -3
  176. package/build/dataloaders/manyToManyFindDataLoader.d.mts.map +1 -1
  177. package/build/dataloaders/oneToManyFindDataLoader.d.cts +2 -3
  178. package/build/dataloaders/oneToManyFindDataLoader.d.cts.map +1 -1
  179. package/build/dataloaders/oneToManyFindDataLoader.d.mts +2 -3
  180. package/build/dataloaders/oneToManyFindDataLoader.d.mts.map +1 -1
  181. package/build/defaults.cjs +1 -1
  182. package/build/defaults.cjs.map +1 -1
  183. package/build/defaults.d.cts +7 -7
  184. package/build/defaults.d.cts.map +1 -1
  185. package/build/defaults.d.mts +7 -7
  186. package/build/defaults.d.mts.map +1 -1
  187. package/build/defaults.js +1 -1
  188. package/build/defaults.js.map +1 -1
  189. package/build/drivers/Driver.d.cts +2 -3
  190. package/build/drivers/Driver.d.cts.map +1 -1
  191. package/build/drivers/Driver.d.mts +2 -3
  192. package/build/drivers/Driver.d.mts.map +1 -1
  193. package/build/drivers/EntityWriter.cjs +4 -3
  194. package/build/drivers/EntityWriter.cjs.map +1 -1
  195. package/build/drivers/EntityWriter.d.cts +19 -7
  196. package/build/drivers/EntityWriter.d.cts.map +1 -1
  197. package/build/drivers/EntityWriter.d.mts +19 -7
  198. package/build/drivers/EntityWriter.d.mts.map +1 -1
  199. package/build/drivers/EntityWriter.js +5 -4
  200. package/build/drivers/EntityWriter.js.map +1 -1
  201. package/build/drivers/IdAssigner.cjs.map +1 -1
  202. package/build/drivers/IdAssigner.d.cts +5 -5
  203. package/build/drivers/IdAssigner.d.cts.map +1 -1
  204. package/build/drivers/IdAssigner.d.mts +5 -5
  205. package/build/drivers/IdAssigner.d.mts.map +1 -1
  206. package/build/drivers/IdAssigner.js.map +1 -1
  207. package/build/drivers/driverApi.d.cts +2 -3
  208. package/build/drivers/driverApi.d.cts.map +1 -1
  209. package/build/drivers/driverApi.d.mts +2 -3
  210. package/build/drivers/driverApi.d.mts.map +1 -1
  211. package/build/fields.cjs +12 -9
  212. package/build/fields.cjs.map +1 -1
  213. package/build/fields.d.cts +10 -11
  214. package/build/fields.d.cts.map +1 -1
  215. package/build/fields.d.mts +10 -11
  216. package/build/fields.d.mts.map +1 -1
  217. package/build/fields.js +12 -9
  218. package/build/fields.js.map +1 -1
  219. package/build/flush/FlushLock.cjs.map +1 -1
  220. package/build/flush/FlushLock.d.cts +1 -2
  221. package/build/flush/FlushLock.d.cts.map +1 -1
  222. package/build/flush/FlushLock.d.mts +1 -2
  223. package/build/flush/FlushLock.d.mts.map +1 -1
  224. package/build/flush/FlushLock.js.map +1 -1
  225. package/build/flush/JoinRows.cjs.map +1 -1
  226. package/build/flush/JoinRows.d.cts +5 -6
  227. package/build/flush/JoinRows.d.cts.map +1 -1
  228. package/build/flush/JoinRows.d.mts +5 -6
  229. package/build/flush/JoinRows.d.mts.map +1 -1
  230. package/build/flush/JoinRows.js.map +1 -1
  231. package/build/flush/PendingChanges.d.cts +5 -6
  232. package/build/flush/PendingChanges.d.cts.map +1 -1
  233. package/build/flush/PendingChanges.d.mts +5 -6
  234. package/build/flush/PendingChanges.d.mts.map +1 -1
  235. package/build/flush/ReadDrift.cjs +90 -0
  236. package/build/flush/ReadDrift.cjs.map +1 -0
  237. package/build/flush/ReadDrift.d.cts +25 -0
  238. package/build/flush/ReadDrift.d.cts.map +1 -0
  239. package/build/flush/ReadDrift.d.mts +25 -0
  240. package/build/flush/ReadDrift.d.mts.map +1 -0
  241. package/build/flush/ReadDrift.js +87 -0
  242. package/build/flush/ReadDrift.js.map +1 -0
  243. package/build/flush/Todo.d.cts +5 -6
  244. package/build/flush/Todo.d.cts.map +1 -1
  245. package/build/flush/Todo.d.mts +5 -6
  246. package/build/flush/Todo.d.mts.map +1 -1
  247. package/build/getProperties.cjs +1 -1
  248. package/build/getProperties.d.cts +3 -4
  249. package/build/getProperties.d.cts.map +1 -1
  250. package/build/getProperties.d.mts +3 -4
  251. package/build/getProperties.d.mts.map +1 -1
  252. package/build/getProperties.js +1 -1
  253. package/build/index.cjs +20 -7
  254. package/build/index.cjs.map +1 -1
  255. package/build/index.d.cts +23 -19
  256. package/build/index.d.cts.map +1 -1
  257. package/build/index.d.mts +23 -19
  258. package/build/index.d.mts.map +1 -1
  259. package/build/index.js +17 -10
  260. package/build/index.js.map +1 -1
  261. package/build/json.d.cts +11 -11
  262. package/build/json.d.cts.map +1 -1
  263. package/build/json.d.mts +11 -11
  264. package/build/json.d.mts.map +1 -1
  265. package/build/keys.d.cts +27 -27
  266. package/build/keys.d.cts.map +1 -1
  267. package/build/keys.d.mts +27 -27
  268. package/build/keys.d.mts.map +1 -1
  269. package/build/loading/HintTree.d.cts +3 -4
  270. package/build/loading/HintTree.d.cts.map +1 -1
  271. package/build/loading/HintTree.d.mts +3 -4
  272. package/build/loading/HintTree.d.mts.map +1 -1
  273. package/build/loading/IsLoadedCache.cjs +2 -2
  274. package/build/loading/IsLoadedCache.cjs.map +1 -1
  275. package/build/loading/IsLoadedCache.d.cts +3 -4
  276. package/build/loading/IsLoadedCache.d.cts.map +1 -1
  277. package/build/loading/IsLoadedCache.d.mts +3 -4
  278. package/build/loading/IsLoadedCache.d.mts.map +1 -1
  279. package/build/loading/IsLoadedCache.js +2 -2
  280. package/build/loading/IsLoadedCache.js.map +1 -1
  281. package/build/loading/loadHints.d.cts +17 -17
  282. package/build/loading/loadHints.d.cts.map +1 -1
  283. package/build/loading/loadHints.d.mts +17 -17
  284. package/build/loading/loadHints.d.mts.map +1 -1
  285. package/build/loading/loadLens.d.cts +13 -13
  286. package/build/loading/loadLens.d.cts.map +1 -1
  287. package/build/loading/loadLens.d.mts +13 -13
  288. package/build/loading/loadLens.d.mts.map +1 -1
  289. package/build/loading/withLoaded.d.cts +5 -6
  290. package/build/loading/withLoaded.d.cts.map +1 -1
  291. package/build/loading/withLoaded.d.mts +5 -6
  292. package/build/loading/withLoaded.d.mts.map +1 -1
  293. package/build/logging/FactoryLogger.cjs +1 -1
  294. package/build/logging/FactoryLogger.cjs.map +1 -1
  295. package/build/logging/FactoryLogger.d.cts +3 -4
  296. package/build/logging/FactoryLogger.d.cts.map +1 -1
  297. package/build/logging/FactoryLogger.d.mts +3 -4
  298. package/build/logging/FactoryLogger.d.mts.map +1 -1
  299. package/build/logging/FactoryLogger.js +2 -2
  300. package/build/logging/FactoryLogger.js.map +1 -1
  301. package/build/logging/FieldLogger.cjs.map +1 -1
  302. package/build/logging/FieldLogger.d.cts +4 -5
  303. package/build/logging/FieldLogger.d.cts.map +1 -1
  304. package/build/logging/FieldLogger.d.mts +4 -5
  305. package/build/logging/FieldLogger.d.mts.map +1 -1
  306. package/build/logging/FieldLogger.js.map +1 -1
  307. package/build/logging/ReactionLogger.d.cts +7 -7
  308. package/build/logging/ReactionLogger.d.cts.map +1 -1
  309. package/build/logging/ReactionLogger.d.mts +7 -7
  310. package/build/logging/ReactionLogger.d.mts.map +1 -1
  311. package/build/metrics/EntityMetrics.cjs +81 -0
  312. package/build/metrics/EntityMetrics.cjs.map +1 -0
  313. package/build/metrics/EntityMetrics.d.cts +55 -0
  314. package/build/metrics/EntityMetrics.d.cts.map +1 -0
  315. package/build/metrics/EntityMetrics.d.mts +55 -0
  316. package/build/metrics/EntityMetrics.d.mts.map +1 -0
  317. package/build/metrics/EntityMetrics.js +79 -0
  318. package/build/metrics/EntityMetrics.js.map +1 -0
  319. package/build/newEntity.cjs +1 -1
  320. package/build/newEntity.cjs.map +1 -1
  321. package/build/newEntity.d.cts +4 -5
  322. package/build/newEntity.d.cts.map +1 -1
  323. package/build/newEntity.d.mts +4 -5
  324. package/build/newEntity.d.mts.map +1 -1
  325. package/build/newEntity.js +1 -1
  326. package/build/newEntity.js.map +1 -1
  327. package/build/newTestInstance.cjs +1 -0
  328. package/build/newTestInstance.cjs.map +1 -1
  329. package/build/newTestInstance.d.cts +21 -21
  330. package/build/newTestInstance.d.cts.map +1 -1
  331. package/build/newTestInstance.d.mts +21 -21
  332. package/build/newTestInstance.d.mts.map +1 -1
  333. package/build/newTestInstance.js +1 -0
  334. package/build/newTestInstance.js.map +1 -1
  335. package/build/normalizeHints.d.cts +7 -8
  336. package/build/normalizeHints.d.cts.map +1 -1
  337. package/build/normalizeHints.d.mts +7 -8
  338. package/build/normalizeHints.d.mts.map +1 -1
  339. package/build/nowUTC.d.cts +4 -5
  340. package/build/nowUTC.d.cts.map +1 -1
  341. package/build/nowUTC.d.mts +4 -5
  342. package/build/nowUTC.d.mts.map +1 -1
  343. package/build/plugins/ImmutableEntitiesPlugin.d.cts +1 -2
  344. package/build/plugins/ImmutableEntitiesPlugin.d.cts.map +1 -1
  345. package/build/plugins/ImmutableEntitiesPlugin.d.mts +1 -2
  346. package/build/plugins/ImmutableEntitiesPlugin.d.mts.map +1 -1
  347. package/build/plugins/PreloadPlugin.d.cts +3 -4
  348. package/build/plugins/PreloadPlugin.d.cts.map +1 -1
  349. package/build/plugins/PreloadPlugin.d.mts +3 -4
  350. package/build/plugins/PreloadPlugin.d.mts.map +1 -1
  351. package/build/preloading/JsonAggregatePreloader.d.cts +1 -2
  352. package/build/preloading/JsonAggregatePreloader.d.cts.map +1 -1
  353. package/build/preloading/JsonAggregatePreloader.d.mts +1 -2
  354. package/build/preloading/JsonAggregatePreloader.d.mts.map +1 -1
  355. package/build/preloading/canPreload.d.cts +1 -2
  356. package/build/preloading/canPreload.d.cts.map +1 -1
  357. package/build/preloading/canPreload.d.mts +1 -2
  358. package/build/preloading/canPreload.d.mts.map +1 -1
  359. package/build/preloading/partitionHint.cjs +1 -1
  360. package/build/preloading/partitionHint.d.cts +1 -2
  361. package/build/preloading/partitionHint.d.cts.map +1 -1
  362. package/build/preloading/partitionHint.d.mts +1 -2
  363. package/build/preloading/partitionHint.d.mts.map +1 -1
  364. package/build/preloading/partitionHint.js +1 -1
  365. package/build/queries/ConditionBuilder.d.cts +2 -2
  366. package/build/queries/ConditionBuilder.d.cts.map +1 -1
  367. package/build/queries/ConditionBuilder.d.mts +2 -2
  368. package/build/queries/ConditionBuilder.d.mts.map +1 -1
  369. package/build/queries/conditions.d.cts +11 -12
  370. package/build/queries/conditions.d.cts.map +1 -1
  371. package/build/queries/conditions.d.mts +11 -12
  372. package/build/queries/conditions.d.mts.map +1 -1
  373. package/build/queries/entityQueryUtils.d.cts +4 -5
  374. package/build/queries/entityQueryUtils.d.cts.map +1 -1
  375. package/build/queries/entityQueryUtils.d.mts +4 -5
  376. package/build/queries/entityQueryUtils.d.mts.map +1 -1
  377. package/build/queries/find/Aliases.d.cts +16 -16
  378. package/build/queries/find/Aliases.d.cts.map +1 -1
  379. package/build/queries/find/Aliases.d.mts +16 -16
  380. package/build/queries/find/Aliases.d.mts.map +1 -1
  381. package/build/queries/find/DeferredAlias.d.cts +5 -6
  382. package/build/queries/find/DeferredAlias.d.cts.map +1 -1
  383. package/build/queries/find/DeferredAlias.d.mts +5 -6
  384. package/build/queries/find/DeferredAlias.d.mts.map +1 -1
  385. package/build/queries/find/EntityFilter.d.cts +12 -13
  386. package/build/queries/find/EntityFilter.d.cts.map +1 -1
  387. package/build/queries/find/EntityFilter.d.mts +12 -13
  388. package/build/queries/find/EntityFilter.d.mts.map +1 -1
  389. package/build/queries/find/EntityGraphQLFilter.d.cts +8 -9
  390. package/build/queries/find/EntityGraphQLFilter.d.cts.map +1 -1
  391. package/build/queries/find/EntityGraphQLFilter.d.mts +8 -9
  392. package/build/queries/find/EntityGraphQLFilter.d.mts.map +1 -1
  393. package/build/queries/find/QueryParser.cjs +18 -7
  394. package/build/queries/find/QueryParser.cjs.map +1 -1
  395. package/build/queries/find/QueryParser.collectionJoins.cjs +2 -1
  396. package/build/queries/find/QueryParser.collectionJoins.cjs.map +1 -1
  397. package/build/queries/find/QueryParser.collectionJoins.d.cts +1 -2
  398. package/build/queries/find/QueryParser.collectionJoins.d.cts.map +1 -1
  399. package/build/queries/find/QueryParser.collectionJoins.d.mts +1 -2
  400. package/build/queries/find/QueryParser.collectionJoins.d.mts.map +1 -1
  401. package/build/queries/find/QueryParser.collectionJoins.js +2 -1
  402. package/build/queries/find/QueryParser.collectionJoins.js.map +1 -1
  403. package/build/queries/find/QueryParser.d.cts +39 -18
  404. package/build/queries/find/QueryParser.d.cts.map +1 -1
  405. package/build/queries/find/QueryParser.d.mts +39 -18
  406. package/build/queries/find/QueryParser.d.mts.map +1 -1
  407. package/build/queries/find/QueryParser.js +18 -7
  408. package/build/queries/find/QueryParser.js.map +1 -1
  409. package/build/queries/find/QueryParser.pruning.cjs +50 -1
  410. package/build/queries/find/QueryParser.pruning.cjs.map +1 -1
  411. package/build/queries/find/QueryParser.pruning.d.cts +15 -3
  412. package/build/queries/find/QueryParser.pruning.d.cts.map +1 -1
  413. package/build/queries/find/QueryParser.pruning.d.mts +15 -3
  414. package/build/queries/find/QueryParser.pruning.d.mts.map +1 -1
  415. package/build/queries/find/QueryParser.pruning.js +50 -1
  416. package/build/queries/find/QueryParser.pruning.js.map +1 -1
  417. package/build/queries/find/QueryVisitor.d.cts +4 -4
  418. package/build/queries/find/QueryVisitor.d.cts.map +1 -1
  419. package/build/queries/find/QueryVisitor.d.mts +4 -4
  420. package/build/queries/find/QueryVisitor.d.mts.map +1 -1
  421. package/build/queries/find/buildFindQuery.d.cts +3 -3
  422. package/build/queries/find/buildFindQuery.d.cts.map +1 -1
  423. package/build/queries/find/buildFindQuery.d.mts +3 -3
  424. package/build/queries/find/buildFindQuery.d.mts.map +1 -1
  425. package/build/queries/find/scopes.cjs.map +1 -1
  426. package/build/queries/find/scopes.d.cts +12 -13
  427. package/build/queries/find/scopes.d.cts.map +1 -1
  428. package/build/queries/find/scopes.d.mts +12 -13
  429. package/build/queries/find/scopes.d.mts.map +1 -1
  430. package/build/queries/find/scopes.js.map +1 -1
  431. package/build/queries/parsedConditions.d.cts +7 -8
  432. package/build/queries/parsedConditions.d.cts.map +1 -1
  433. package/build/queries/parsedConditions.d.mts +7 -8
  434. package/build/queries/parsedConditions.d.mts.map +1 -1
  435. package/build/queries/renderConditions.d.cts +3 -4
  436. package/build/queries/renderConditions.d.cts.map +1 -1
  437. package/build/queries/renderConditions.d.mts +3 -4
  438. package/build/queries/renderConditions.d.mts.map +1 -1
  439. package/build/queries/skipCondition.d.cts +1 -2
  440. package/build/queries/skipCondition.d.cts.map +1 -1
  441. package/build/queries/skipCondition.d.mts +1 -2
  442. package/build/queries/skipCondition.d.mts.map +1 -1
  443. package/build/queries/sql/AliasAssigner.cjs.map +1 -1
  444. package/build/queries/sql/AliasAssigner.d.cts +1 -2
  445. package/build/queries/sql/AliasAssigner.d.cts.map +1 -1
  446. package/build/queries/sql/AliasAssigner.d.mts +1 -2
  447. package/build/queries/sql/AliasAssigner.d.mts.map +1 -1
  448. package/build/queries/sql/AliasAssigner.js.map +1 -1
  449. package/build/queries/sql/Expr.cjs +38 -0
  450. package/build/queries/sql/Expr.cjs.map +1 -1
  451. package/build/queries/sql/Expr.d.cts +45 -27
  452. package/build/queries/sql/Expr.d.cts.map +1 -1
  453. package/build/queries/sql/Expr.d.mts +45 -27
  454. package/build/queries/sql/Expr.d.mts.map +1 -1
  455. package/build/queries/sql/Expr.js +38 -1
  456. package/build/queries/sql/Expr.js.map +1 -1
  457. package/build/queries/sql/JoinTree.d.cts +5 -5
  458. package/build/queries/sql/JoinTree.d.cts.map +1 -1
  459. package/build/queries/sql/JoinTree.d.mts +5 -5
  460. package/build/queries/sql/JoinTree.d.mts.map +1 -1
  461. package/build/queries/sql/Tables.cjs +9 -0
  462. package/build/queries/sql/Tables.cjs.map +1 -1
  463. package/build/queries/sql/Tables.d.cts +46 -39
  464. package/build/queries/sql/Tables.d.cts.map +1 -1
  465. package/build/queries/sql/Tables.d.mts +46 -39
  466. package/build/queries/sql/Tables.d.mts.map +1 -1
  467. package/build/queries/sql/Tables.js +10 -1
  468. package/build/queries/sql/Tables.js.map +1 -1
  469. package/build/queries/sql/custom.d.cts +14 -14
  470. package/build/queries/sql/custom.d.cts.map +1 -1
  471. package/build/queries/sql/custom.d.mts +14 -14
  472. package/build/queries/sql/custom.d.mts.map +1 -1
  473. package/build/queries/sql/execute.cjs +68 -89
  474. package/build/queries/sql/execute.cjs.map +1 -1
  475. package/build/queries/sql/execute.d.cts +49 -32
  476. package/build/queries/sql/execute.d.cts.map +1 -1
  477. package/build/queries/sql/execute.d.mts +49 -32
  478. package/build/queries/sql/execute.d.mts.map +1 -1
  479. package/build/queries/sql/execute.js +70 -91
  480. package/build/queries/sql/execute.js.map +1 -1
  481. package/build/queries/sql/expressions/arrayAgg.d.cts +5 -6
  482. package/build/queries/sql/expressions/arrayAgg.d.cts.map +1 -1
  483. package/build/queries/sql/expressions/arrayAgg.d.mts +5 -6
  484. package/build/queries/sql/expressions/arrayAgg.d.mts.map +1 -1
  485. package/build/queries/sql/expressions/case.d.cts +10 -10
  486. package/build/queries/sql/expressions/case.d.cts.map +1 -1
  487. package/build/queries/sql/expressions/case.d.mts +10 -10
  488. package/build/queries/sql/expressions/case.d.mts.map +1 -1
  489. package/build/queries/sql/expressions/coalesce.d.cts +5 -6
  490. package/build/queries/sql/expressions/coalesce.d.cts.map +1 -1
  491. package/build/queries/sql/expressions/coalesce.d.mts +5 -6
  492. package/build/queries/sql/expressions/coalesce.d.mts.map +1 -1
  493. package/build/queries/sql/expressions/codecs.d.cts +1 -2
  494. package/build/queries/sql/expressions/codecs.d.cts.map +1 -1
  495. package/build/queries/sql/expressions/codecs.d.mts +1 -2
  496. package/build/queries/sql/expressions/codecs.d.mts.map +1 -1
  497. package/build/queries/sql/expressions/expression.d.cts +6 -6
  498. package/build/queries/sql/expressions/expression.d.cts.map +1 -1
  499. package/build/queries/sql/expressions/expression.d.mts +6 -6
  500. package/build/queries/sql/expressions/expression.d.mts.map +1 -1
  501. package/build/queries/sql/expressions/greatest.d.cts +5 -6
  502. package/build/queries/sql/expressions/greatest.d.cts.map +1 -1
  503. package/build/queries/sql/expressions/greatest.d.mts +5 -6
  504. package/build/queries/sql/expressions/greatest.d.mts.map +1 -1
  505. package/build/queries/sql/expressions/least.d.cts +5 -6
  506. package/build/queries/sql/expressions/least.d.cts.map +1 -1
  507. package/build/queries/sql/expressions/least.d.mts +5 -6
  508. package/build/queries/sql/expressions/least.d.mts.map +1 -1
  509. package/build/queries/sql/expressions/nullIf.d.cts +5 -6
  510. package/build/queries/sql/expressions/nullIf.d.cts.map +1 -1
  511. package/build/queries/sql/expressions/nullIf.d.mts +5 -6
  512. package/build/queries/sql/expressions/nullIf.d.mts.map +1 -1
  513. package/build/queries/sql/expressions/parseExpression.d.cts +5 -6
  514. package/build/queries/sql/expressions/parseExpression.d.cts.map +1 -1
  515. package/build/queries/sql/expressions/parseExpression.d.mts +5 -6
  516. package/build/queries/sql/expressions/parseExpression.d.mts.map +1 -1
  517. package/build/queries/sql/expressions/types.d.cts +11 -11
  518. package/build/queries/sql/expressions/types.d.cts.map +1 -1
  519. package/build/queries/sql/expressions/types.d.mts +11 -11
  520. package/build/queries/sql/expressions/types.d.mts.map +1 -1
  521. package/build/queries/sql/keywords.d.cts +4 -5
  522. package/build/queries/sql/keywords.d.cts.map +1 -1
  523. package/build/queries/sql/keywords.d.mts +4 -5
  524. package/build/queries/sql/keywords.d.mts.map +1 -1
  525. package/build/queries/sql/query.cjs +77 -30
  526. package/build/queries/sql/query.cjs.map +1 -1
  527. package/build/queries/sql/query.d.cts +119 -76
  528. package/build/queries/sql/query.d.cts.map +1 -1
  529. package/build/queries/sql/query.d.mts +119 -76
  530. package/build/queries/sql/query.d.mts.map +1 -1
  531. package/build/queries/sql/query.js +75 -30
  532. package/build/queries/sql/query.js.map +1 -1
  533. package/build/queries/unnest.cjs +4 -5
  534. package/build/queries/unnest.cjs.map +1 -1
  535. package/build/queries/unnest.d.cts +2 -3
  536. package/build/queries/unnest.d.cts.map +1 -1
  537. package/build/queries/unnest.d.mts +2 -3
  538. package/build/queries/unnest.d.mts.map +1 -1
  539. package/build/queries/unnest.js +4 -5
  540. package/build/queries/unnest.js.map +1 -1
  541. package/build/queries/valueFilters.d.cts +5 -6
  542. package/build/queries/valueFilters.d.cts.map +1 -1
  543. package/build/queries/valueFilters.d.mts +5 -6
  544. package/build/queries/valueFilters.d.mts.map +1 -1
  545. package/build/reactivity/ReactionsManager.cjs +171 -2
  546. package/build/reactivity/ReactionsManager.cjs.map +1 -1
  547. package/build/reactivity/ReactionsManager.d.cts +56 -4
  548. package/build/reactivity/ReactionsManager.d.cts.map +1 -1
  549. package/build/reactivity/ReactionsManager.d.mts +56 -4
  550. package/build/reactivity/ReactionsManager.d.mts.map +1 -1
  551. package/build/reactivity/ReactionsManager.js +172 -3
  552. package/build/reactivity/ReactionsManager.js.map +1 -1
  553. package/build/reactivity/reactiveHints.cjs +9 -3
  554. package/build/reactivity/reactiveHints.cjs.map +1 -1
  555. package/build/reactivity/reactiveHints.d.cts +19 -18
  556. package/build/reactivity/reactiveHints.d.cts.map +1 -1
  557. package/build/reactivity/reactiveHints.d.mts +19 -18
  558. package/build/reactivity/reactiveHints.d.mts.map +1 -1
  559. package/build/reactivity/reactiveHints.js +9 -3
  560. package/build/reactivity/reactiveHints.js.map +1 -1
  561. package/build/relations/AbstractPropertyImpl.cjs.map +1 -1
  562. package/build/relations/AbstractPropertyImpl.d.cts +1 -2
  563. package/build/relations/AbstractPropertyImpl.d.cts.map +1 -1
  564. package/build/relations/AbstractPropertyImpl.d.mts +1 -2
  565. package/build/relations/AbstractPropertyImpl.d.mts.map +1 -1
  566. package/build/relations/AbstractPropertyImpl.js.map +1 -1
  567. package/build/relations/AbstractRelationImpl.d.cts +1 -2
  568. package/build/relations/AbstractRelationImpl.d.cts.map +1 -1
  569. package/build/relations/AbstractRelationImpl.d.mts +1 -2
  570. package/build/relations/AbstractRelationImpl.d.mts.map +1 -1
  571. package/build/relations/AsyncProperty.cjs +1 -1
  572. package/build/relations/AsyncProperty.cjs.map +1 -1
  573. package/build/relations/AsyncProperty.d.cts +5 -6
  574. package/build/relations/AsyncProperty.d.cts.map +1 -1
  575. package/build/relations/AsyncProperty.d.mts +5 -6
  576. package/build/relations/AsyncProperty.d.mts.map +1 -1
  577. package/build/relations/AsyncProperty.js +1 -1
  578. package/build/relations/AsyncProperty.js.map +1 -1
  579. package/build/relations/AsyncReactiveField.cjs +23 -5
  580. package/build/relations/AsyncReactiveField.cjs.map +1 -1
  581. package/build/relations/AsyncReactiveField.d.cts +7 -6
  582. package/build/relations/AsyncReactiveField.d.cts.map +1 -1
  583. package/build/relations/AsyncReactiveField.d.mts +7 -6
  584. package/build/relations/AsyncReactiveField.d.mts.map +1 -1
  585. package/build/relations/AsyncReactiveField.js +23 -5
  586. package/build/relations/AsyncReactiveField.js.map +1 -1
  587. package/build/relations/Collection.d.cts +4 -5
  588. package/build/relations/Collection.d.cts.map +1 -1
  589. package/build/relations/Collection.d.mts +4 -5
  590. package/build/relations/Collection.d.mts.map +1 -1
  591. package/build/relations/CustomCollection.cjs +1 -1
  592. package/build/relations/CustomCollection.cjs.map +1 -1
  593. package/build/relations/CustomCollection.d.cts +3 -4
  594. package/build/relations/CustomCollection.d.cts.map +1 -1
  595. package/build/relations/CustomCollection.d.mts +3 -4
  596. package/build/relations/CustomCollection.d.mts.map +1 -1
  597. package/build/relations/CustomCollection.js +1 -1
  598. package/build/relations/CustomCollection.js.map +1 -1
  599. package/build/relations/CustomReference.cjs +2 -2
  600. package/build/relations/CustomReference.cjs.map +1 -1
  601. package/build/relations/CustomReference.d.cts +3 -4
  602. package/build/relations/CustomReference.d.cts.map +1 -1
  603. package/build/relations/CustomReference.d.mts +3 -4
  604. package/build/relations/CustomReference.d.mts.map +1 -1
  605. package/build/relations/CustomReference.js +2 -2
  606. package/build/relations/CustomReference.js.map +1 -1
  607. package/build/relations/EnumCollection.cjs +1 -1
  608. package/build/relations/EnumCollection.cjs.map +1 -1
  609. package/build/relations/EnumCollection.d.cts +5 -5
  610. package/build/relations/EnumCollection.d.cts.map +1 -1
  611. package/build/relations/EnumCollection.d.mts +5 -5
  612. package/build/relations/EnumCollection.d.mts.map +1 -1
  613. package/build/relations/EnumCollection.js +1 -1
  614. package/build/relations/EnumCollection.js.map +1 -1
  615. package/build/relations/LargeCollection.d.cts +1 -2
  616. package/build/relations/LargeCollection.d.cts.map +1 -1
  617. package/build/relations/LargeCollection.d.mts +1 -2
  618. package/build/relations/LargeCollection.d.mts.map +1 -1
  619. package/build/relations/LazyField.cjs +16 -2
  620. package/build/relations/LazyField.cjs.map +1 -1
  621. package/build/relations/LazyField.d.cts +13 -8
  622. package/build/relations/LazyField.d.cts.map +1 -1
  623. package/build/relations/LazyField.d.mts +13 -8
  624. package/build/relations/LazyField.d.mts.map +1 -1
  625. package/build/relations/LazyField.js +16 -2
  626. package/build/relations/LazyField.js.map +1 -1
  627. package/build/relations/ManyToManyCollection.cjs +1 -1
  628. package/build/relations/ManyToManyCollection.cjs.map +1 -1
  629. package/build/relations/ManyToManyCollection.d.cts +2 -3
  630. package/build/relations/ManyToManyCollection.d.cts.map +1 -1
  631. package/build/relations/ManyToManyCollection.d.mts +2 -3
  632. package/build/relations/ManyToManyCollection.d.mts.map +1 -1
  633. package/build/relations/ManyToManyCollection.js +1 -1
  634. package/build/relations/ManyToManyCollection.js.map +1 -1
  635. package/build/relations/ManyToManyLargeCollection.cjs +1 -1
  636. package/build/relations/ManyToManyLargeCollection.d.cts +2 -3
  637. package/build/relations/ManyToManyLargeCollection.d.cts.map +1 -1
  638. package/build/relations/ManyToManyLargeCollection.d.mts +2 -3
  639. package/build/relations/ManyToManyLargeCollection.d.mts.map +1 -1
  640. package/build/relations/ManyToManyLargeCollection.js +1 -1
  641. package/build/relations/ManyToOneReference.cjs +2 -2
  642. package/build/relations/ManyToOneReference.cjs.map +1 -1
  643. package/build/relations/ManyToOneReference.d.cts +6 -7
  644. package/build/relations/ManyToOneReference.d.cts.map +1 -1
  645. package/build/relations/ManyToOneReference.d.mts +6 -7
  646. package/build/relations/ManyToOneReference.d.mts.map +1 -1
  647. package/build/relations/ManyToOneReference.js +2 -2
  648. package/build/relations/ManyToOneReference.js.map +1 -1
  649. package/build/relations/OneToManyCollection.cjs +1 -1
  650. package/build/relations/OneToManyCollection.cjs.map +1 -1
  651. package/build/relations/OneToManyCollection.d.cts +2 -3
  652. package/build/relations/OneToManyCollection.d.cts.map +1 -1
  653. package/build/relations/OneToManyCollection.d.mts +2 -3
  654. package/build/relations/OneToManyCollection.d.mts.map +1 -1
  655. package/build/relations/OneToManyCollection.js +1 -1
  656. package/build/relations/OneToManyCollection.js.map +1 -1
  657. package/build/relations/OneToManyLargeCollection.cjs +1 -1
  658. package/build/relations/OneToManyLargeCollection.cjs.map +1 -1
  659. package/build/relations/OneToManyLargeCollection.d.cts +2 -3
  660. package/build/relations/OneToManyLargeCollection.d.cts.map +1 -1
  661. package/build/relations/OneToManyLargeCollection.d.mts +2 -3
  662. package/build/relations/OneToManyLargeCollection.d.mts.map +1 -1
  663. package/build/relations/OneToManyLargeCollection.js +1 -1
  664. package/build/relations/OneToManyLargeCollection.js.map +1 -1
  665. package/build/relations/OneToOneReference.cjs +2 -2
  666. package/build/relations/OneToOneReference.cjs.map +1 -1
  667. package/build/relations/OneToOneReference.d.cts +7 -7
  668. package/build/relations/OneToOneReference.d.cts.map +1 -1
  669. package/build/relations/OneToOneReference.d.mts +7 -7
  670. package/build/relations/OneToOneReference.d.mts.map +1 -1
  671. package/build/relations/OneToOneReference.js +2 -2
  672. package/build/relations/OneToOneReference.js.map +1 -1
  673. package/build/relations/PolymorphicReference.cjs +2 -2
  674. package/build/relations/PolymorphicReference.cjs.map +1 -1
  675. package/build/relations/PolymorphicReference.d.cts +4 -5
  676. package/build/relations/PolymorphicReference.d.cts.map +1 -1
  677. package/build/relations/PolymorphicReference.d.mts +4 -5
  678. package/build/relations/PolymorphicReference.d.mts.map +1 -1
  679. package/build/relations/PolymorphicReference.js +2 -2
  680. package/build/relations/PolymorphicReference.js.map +1 -1
  681. package/build/relations/PropertySymbols.d.cts +1 -2
  682. package/build/relations/PropertySymbols.d.cts.map +1 -1
  683. package/build/relations/PropertySymbols.d.mts +1 -2
  684. package/build/relations/PropertySymbols.d.mts.map +1 -1
  685. package/build/relations/ReactiveField.cjs +27 -6
  686. package/build/relations/ReactiveField.cjs.map +1 -1
  687. package/build/relations/ReactiveField.d.cts +11 -7
  688. package/build/relations/ReactiveField.d.cts.map +1 -1
  689. package/build/relations/ReactiveField.d.mts +11 -7
  690. package/build/relations/ReactiveField.d.mts.map +1 -1
  691. package/build/relations/ReactiveField.js +27 -6
  692. package/build/relations/ReactiveField.js.map +1 -1
  693. package/build/relations/ReactiveGetter.cjs +1 -1
  694. package/build/relations/ReactiveGetter.cjs.map +1 -1
  695. package/build/relations/ReactiveGetter.d.cts +4 -5
  696. package/build/relations/ReactiveGetter.d.cts.map +1 -1
  697. package/build/relations/ReactiveGetter.d.mts +4 -5
  698. package/build/relations/ReactiveGetter.d.mts.map +1 -1
  699. package/build/relations/ReactiveGetter.js +1 -1
  700. package/build/relations/ReactiveGetter.js.map +1 -1
  701. package/build/relations/ReactiveManyToMany.cjs +1 -1
  702. package/build/relations/ReactiveManyToMany.cjs.map +1 -1
  703. package/build/relations/ReactiveManyToMany.d.cts +4 -5
  704. package/build/relations/ReactiveManyToMany.d.cts.map +1 -1
  705. package/build/relations/ReactiveManyToMany.d.mts +4 -5
  706. package/build/relations/ReactiveManyToMany.d.mts.map +1 -1
  707. package/build/relations/ReactiveManyToMany.js +1 -1
  708. package/build/relations/ReactiveManyToMany.js.map +1 -1
  709. package/build/relations/ReactiveManyToManyOtherSide.cjs +1 -1
  710. package/build/relations/ReactiveManyToManyOtherSide.cjs.map +1 -1
  711. package/build/relations/ReactiveManyToManyOtherSide.d.cts +4 -5
  712. package/build/relations/ReactiveManyToManyOtherSide.d.cts.map +1 -1
  713. package/build/relations/ReactiveManyToManyOtherSide.d.mts +4 -5
  714. package/build/relations/ReactiveManyToManyOtherSide.d.mts.map +1 -1
  715. package/build/relations/ReactiveManyToManyOtherSide.js +1 -1
  716. package/build/relations/ReactiveManyToManyOtherSide.js.map +1 -1
  717. package/build/relations/ReactiveReference.cjs +2 -2
  718. package/build/relations/ReactiveReference.cjs.map +1 -1
  719. package/build/relations/ReactiveReference.d.cts +6 -7
  720. package/build/relations/ReactiveReference.d.cts.map +1 -1
  721. package/build/relations/ReactiveReference.d.mts +6 -7
  722. package/build/relations/ReactiveReference.d.mts.map +1 -1
  723. package/build/relations/ReactiveReference.js +2 -2
  724. package/build/relations/ReactiveReference.js.map +1 -1
  725. package/build/relations/ReadOnlyCollection.d.cts +4 -5
  726. package/build/relations/ReadOnlyCollection.d.cts.map +1 -1
  727. package/build/relations/ReadOnlyCollection.d.mts +4 -5
  728. package/build/relations/ReadOnlyCollection.d.mts.map +1 -1
  729. package/build/relations/RecursiveCollection.cjs +1 -1
  730. package/build/relations/RecursiveCollection.cjs.map +1 -1
  731. package/build/relations/RecursiveCollection.d.cts +10 -10
  732. package/build/relations/RecursiveCollection.d.cts.map +1 -1
  733. package/build/relations/RecursiveCollection.d.mts +10 -10
  734. package/build/relations/RecursiveCollection.d.mts.map +1 -1
  735. package/build/relations/RecursiveCollection.js +1 -1
  736. package/build/relations/RecursiveCollection.js.map +1 -1
  737. package/build/relations/RecursiveCycleError.d.cts +2 -2
  738. package/build/relations/RecursiveCycleError.d.cts.map +1 -1
  739. package/build/relations/RecursiveCycleError.d.mts +2 -2
  740. package/build/relations/RecursiveCycleError.d.mts.map +1 -1
  741. package/build/relations/Reference.d.cts +5 -5
  742. package/build/relations/Reference.d.cts.map +1 -1
  743. package/build/relations/Reference.d.mts +5 -5
  744. package/build/relations/Reference.d.mts.map +1 -1
  745. package/build/relations/ReferenceSymbols.d.cts +1 -2
  746. package/build/relations/ReferenceSymbols.d.cts.map +1 -1
  747. package/build/relations/ReferenceSymbols.d.mts +1 -2
  748. package/build/relations/ReferenceSymbols.d.mts.map +1 -1
  749. package/build/relations/Relation.d.cts +3 -3
  750. package/build/relations/Relation.d.cts.map +1 -1
  751. package/build/relations/Relation.d.mts +3 -3
  752. package/build/relations/Relation.d.mts.map +1 -1
  753. package/build/relations/RelationSymbols.d.cts +2 -3
  754. package/build/relations/RelationSymbols.d.cts.map +1 -1
  755. package/build/relations/RelationSymbols.d.mts +2 -3
  756. package/build/relations/RelationSymbols.d.mts.map +1 -1
  757. package/build/relations/hasAsyncMethod.cjs +24 -5
  758. package/build/relations/hasAsyncMethod.cjs.map +1 -1
  759. package/build/relations/hasAsyncMethod.d.cts +9 -8
  760. package/build/relations/hasAsyncMethod.d.cts.map +1 -1
  761. package/build/relations/hasAsyncMethod.d.mts +9 -8
  762. package/build/relations/hasAsyncMethod.d.mts.map +1 -1
  763. package/build/relations/hasAsyncMethod.js +24 -6
  764. package/build/relations/hasAsyncMethod.js.map +1 -1
  765. package/build/relations/hasManyDerived.cjs +1 -1
  766. package/build/relations/hasManyDerived.d.cts +2 -2
  767. package/build/relations/hasManyDerived.d.cts.map +1 -1
  768. package/build/relations/hasManyDerived.d.mts +2 -2
  769. package/build/relations/hasManyDerived.d.mts.map +1 -1
  770. package/build/relations/hasManyDerived.js +1 -1
  771. package/build/relations/hasManyThrough.cjs +1 -1
  772. package/build/relations/hasManyThrough.d.cts +1 -2
  773. package/build/relations/hasManyThrough.d.cts.map +1 -1
  774. package/build/relations/hasManyThrough.d.mts +1 -2
  775. package/build/relations/hasManyThrough.d.mts.map +1 -1
  776. package/build/relations/hasManyThrough.js +1 -1
  777. package/build/relations/hasOneDerived.cjs +1 -1
  778. package/build/relations/hasOneDerived.d.cts +1 -2
  779. package/build/relations/hasOneDerived.d.cts.map +1 -1
  780. package/build/relations/hasOneDerived.d.mts +1 -2
  781. package/build/relations/hasOneDerived.d.mts.map +1 -1
  782. package/build/relations/hasOneDerived.js +1 -1
  783. package/build/relations/hasOneThrough.cjs +1 -1
  784. package/build/relations/hasOneThrough.d.cts +1 -2
  785. package/build/relations/hasOneThrough.d.cts.map +1 -1
  786. package/build/relations/hasOneThrough.d.mts +1 -2
  787. package/build/relations/hasOneThrough.d.mts.map +1 -1
  788. package/build/relations/hasOneThrough.js +1 -1
  789. package/build/relations/hasProperty.cjs +1 -1
  790. package/build/relations/hasProperty.cjs.map +1 -1
  791. package/build/relations/hasProperty.d.cts +8 -8
  792. package/build/relations/hasProperty.d.cts.map +1 -1
  793. package/build/relations/hasProperty.d.mts +8 -8
  794. package/build/relations/hasProperty.d.mts.map +1 -1
  795. package/build/relations/hasProperty.js +1 -1
  796. package/build/relations/hasProperty.js.map +1 -1
  797. package/build/relations/hasReactiveAsyncMethod.cjs +87 -0
  798. package/build/relations/hasReactiveAsyncMethod.cjs.map +1 -0
  799. package/build/relations/hasReactiveAsyncMethod.d.cts +32 -0
  800. package/build/relations/hasReactiveAsyncMethod.d.cts.map +1 -0
  801. package/build/relations/hasReactiveAsyncMethod.d.mts +32 -0
  802. package/build/relations/hasReactiveAsyncMethod.d.mts.map +1 -0
  803. package/build/relations/hasReactiveAsyncMethod.js +85 -0
  804. package/build/relations/hasReactiveAsyncMethod.js.map +1 -0
  805. package/build/relations/index.cjs +2 -0
  806. package/build/relations/index.d.cts +2 -1
  807. package/build/relations/index.d.mts +2 -1
  808. package/build/relations/index.js +2 -1
  809. package/build/relations/isCascadeDelete.d.cts +1 -2
  810. package/build/relations/isCascadeDelete.d.cts.map +1 -1
  811. package/build/relations/isCascadeDelete.d.mts +1 -2
  812. package/build/relations/isCascadeDelete.d.mts.map +1 -1
  813. package/build/resurrection.cjs +11 -1
  814. package/build/resurrection.cjs.map +1 -1
  815. package/build/resurrection.d.cts +5 -3
  816. package/build/resurrection.d.cts.map +1 -1
  817. package/build/resurrection.d.mts +5 -3
  818. package/build/resurrection.d.mts.map +1 -1
  819. package/build/resurrection.js +11 -2
  820. package/build/resurrection.js.map +1 -1
  821. package/build/rules.cjs +1 -1
  822. package/build/rules.cjs.map +1 -1
  823. package/build/rules.d.cts +25 -20
  824. package/build/rules.d.cts.map +1 -1
  825. package/build/rules.d.mts +25 -20
  826. package/build/rules.d.mts.map +1 -1
  827. package/build/rules.js +1 -1
  828. package/build/rules.js.map +1 -1
  829. package/build/runtimeConfig.d.cts +4 -5
  830. package/build/runtimeConfig.d.cts.map +1 -1
  831. package/build/runtimeConfig.d.mts +4 -5
  832. package/build/runtimeConfig.d.mts.map +1 -1
  833. package/build/serde/TypeInfo.d.cts +3 -4
  834. package/build/serde/TypeInfo.d.cts.map +1 -1
  835. package/build/serde/TypeInfo.d.mts +3 -4
  836. package/build/serde/TypeInfo.d.mts.map +1 -1
  837. package/build/serde/columns.cjs +3 -0
  838. package/build/serde/columns.cjs.map +1 -1
  839. package/build/serde/columns.d.cts +3 -3
  840. package/build/serde/columns.d.cts.map +1 -1
  841. package/build/serde/columns.d.mts +3 -3
  842. package/build/serde/columns.d.mts.map +1 -1
  843. package/build/serde/columns.js +3 -0
  844. package/build/serde/columns.js.map +1 -1
  845. package/build/serde/fieldSerde.cjs +3 -0
  846. package/build/serde/fieldSerde.cjs.map +1 -1
  847. package/build/serde/fieldSerde.d.cts +10 -9
  848. package/build/serde/fieldSerde.d.cts.map +1 -1
  849. package/build/serde/fieldSerde.d.mts +10 -9
  850. package/build/serde/fieldSerde.d.mts.map +1 -1
  851. package/build/serde/fieldSerde.js +3 -0
  852. package/build/serde/fieldSerde.js.map +1 -1
  853. package/build/serde/serde.cjs +60 -0
  854. package/build/serde/serde.cjs.map +1 -1
  855. package/build/serde/serde.d.cts +58 -19
  856. package/build/serde/serde.d.cts.map +1 -1
  857. package/build/serde/serde.d.mts +58 -19
  858. package/build/serde/serde.d.mts.map +1 -1
  859. package/build/serde/serde.js +60 -1
  860. package/build/serde/serde.js.map +1 -1
  861. package/build/serde/temporal.cjs +7 -12
  862. package/build/serde/temporal.cjs.map +1 -1
  863. package/build/serde/temporal.d.cts +6 -6
  864. package/build/serde/temporal.d.cts.map +1 -1
  865. package/build/serde/temporal.d.mts +6 -6
  866. package/build/serde/temporal.d.mts.map +1 -1
  867. package/build/serde/temporal.js +7 -12
  868. package/build/serde/temporal.js.map +1 -1
  869. package/build/serde/temporalMappers.cjs +8 -4
  870. package/build/serde/temporalMappers.cjs.map +1 -1
  871. package/build/serde/temporalMappers.d.cts +4 -5
  872. package/build/serde/temporalMappers.d.cts.map +1 -1
  873. package/build/serde/temporalMappers.d.mts +4 -5
  874. package/build/serde/temporalMappers.d.mts.map +1 -1
  875. package/build/serde/temporalMappers.js +8 -4
  876. package/build/serde/temporalMappers.js.map +1 -1
  877. package/build/transitions.cjs +91 -0
  878. package/build/transitions.cjs.map +1 -0
  879. package/build/transitions.d.cts +115 -0
  880. package/build/transitions.d.cts.map +1 -0
  881. package/build/transitions.d.mts +115 -0
  882. package/build/transitions.d.mts.map +1 -0
  883. package/build/transitions.js +86 -0
  884. package/build/transitions.js.map +1 -0
  885. package/build/trusted.d.cts +2 -3
  886. package/build/trusted.d.cts.map +1 -1
  887. package/build/trusted.d.mts +2 -3
  888. package/build/trusted.d.mts.map +1 -1
  889. package/build/typeMap.d.cts +17 -17
  890. package/build/typeMap.d.cts.map +1 -1
  891. package/build/typeMap.d.mts +17 -17
  892. package/build/typeMap.d.mts.map +1 -1
  893. package/build/upsert.cjs +1 -1
  894. package/build/upsert.d.cts +4 -4
  895. package/build/upsert.d.cts.map +1 -1
  896. package/build/upsert.d.mts +4 -4
  897. package/build/upsert.d.mts.map +1 -1
  898. package/build/upsert.js +1 -1
  899. package/build/utils.d.cts +27 -28
  900. package/build/utils.d.cts.map +1 -1
  901. package/build/utils.d.mts +27 -28
  902. package/build/utils.d.mts.map +1 -1
  903. package/package.json +6 -6
@@ -1 +1 @@
1
- {"version":3,"file":"QueryParser.collectionJoins.js","names":[],"sources":["../../../src/queries/find/QueryParser.collectionJoins.ts"],"sourcesContent":["import { pruneUnusedJoins, selectReferencesAlias } from \"src/queries/find/QueryParser.pruning.ts\";\nimport {\n type JoinTable,\n type ParsedFindQuery,\n type PrimaryTable,\n maybeAddIdNotNulls,\n parseAlias,\n} from \"src/queries/find/QueryParser.ts\";\nimport type {\n ExistsCondition,\n ParsedExpressionCondition,\n ParsedExpressionFilter,\n RawCondition,\n} from \"src/queries/parsedConditions.ts\";\nimport { assertNever } from \"src/utils.ts\";\n\n/** A collection root plus every join nested under it, i.e. `books b` with `book_reviews br`. */\ninterface CollectionRoot {\n /** The top-level collection join that becomes the EXISTS FROM table, i.e. `books b`. */\n table: JoinTable;\n /** Every alias in this collection subtree, i.e. `b` and `br` for `authors -> books -> reviews`. */\n aliases: Set<string>;\n /** Every join table in this collection subtree, i.e. `att` and `t` for an m2m tag filter. */\n joinTables: JoinTable[];\n}\n\n/**\n * Rewrites eligible logical collection LEFT JOINs into EXISTS after plugins have mutated the AST.\n *\n * QueryParser intentionally leaves collection filters as ordinary joins so `beforeFind` plugins see\n * stabler/simpler input than \"sometimes JOINs / sometimes EXISTS\".\n *\n * This pass runs after plugins and before SQL rendering:\n *\n * 1. `rewriteCollectionJoins` finds top-level collection joins and moves conditions that reference only\n * that subtree into a correlated EXISTS subquery. I.e. `{ books: { title: \"b1\" } }` becomes\n * `EXISTS (SELECT 1 FROM books b WHERE a.id = b.author_id AND b.title = 'b1')`.\n * 2. The same helper recurses into the generated subquery, so nested collections become nested EXISTS clauses.\n * I.e. `{ books: { reviews: { rating: 5 } } }` becomes EXISTS(books WHERE EXISTS(reviews)).\n * 3. Conditions that cannot be safely moved stay as LEFT JOINs. I.e. `OR(b.title = 'x', a.first_name = 'x')`\n * needs both aliases in one SQL scope, so `b` remains a join instead of becoming an EXISTS.\n * 4. Remaining fanout LEFT JOIN roots are rejected unless `allowMultipleLeftJoins` is set,\n * because they can produce cross-product row explosions.\n * 5. Finally, `maybeAddIdNotNulls` and `pruneUnusedJoins` clean up the joins that remain.\n */\nexport function optimizeCollectionJoins(\n query: ParsedFindQuery,\n opts: {\n allowMultipleLeftJoins?: boolean;\n optimizeJoinsToExists?: boolean;\n pruneJoins?: boolean;\n keepAliases?: string[];\n } = {},\n): void {\n const { allowMultipleLeftJoins = false, optimizeJoinsToExists = true, pruneJoins = true, keepAliases = [] } = opts;\n for (const table of query.tables) {\n // I.e. batched find/count queries wrap the real query in a LATERAL subquery; optimize that inner query too,\n // but let the outer query decide final pruning so it can keep the lateral alias itself.\n if (table.join === \"lateral\") optimizeCollectionJoins(table.query, { ...opts, pruneJoins: false });\n }\n if (optimizeJoinsToExists) rewriteCollectionJoins(query, keepAliases);\n\n // I.e. collection LEFT JOINs now fall into three buckets:\n // 1. local real filters, like `{ books: { title: \"b1\" } }`, were rewritten to EXISTS above;\n // 2. no local real filters, like `{ books: {}, comments: {} }`, are safe because pruning will remove them;\n // 3. blocked real filters, like cross-scope ORs, must stay as LEFT JOINs and can multiply rows.\n // Only the third bucket should trip the fanout guard.\n const fanoutLeftJoinAliases = getCollectionRoots(query)\n .filter((root) => conditionBlocksExistsRewrite(query.condition, root.aliases))\n .map((root) => root.table.alias);\n if (optimizeJoinsToExists && !allowMultipleLeftJoins && fanoutLeftJoinAliases.length > 1) {\n throw new Error(\n `em.find would issue multiple LEFT JOINs across collection relations (${fanoutLeftJoinAliases.join(\n \", \",\n )}); pass allowMultipleLeftJoins: true if this fanout is intentional`,\n );\n }\n\n if (query.tables.some((t) => t.join === \"outer\")) {\n // I.e. preserve legacy LEFT JOIN null semantics for any joins that could not become EXISTS.\n maybeAddIdNotNulls(query);\n }\n if (pruneJoins) {\n // I.e. remove logical collection joins that were replaced by EXISTS and any joins only needed before plugin edits.\n pruneUnusedJoins(query, keepAliases);\n }\n}\n\n/**\n * Rewrites root-level collection join subtrees into EXISTS when their conditions are locally scoped.\n *\n * I.e. for `authors a -> books b -> book_reviews br`, `b` is the collection root and `br` is part of its subtree.\n */\nfunction rewriteCollectionJoins(query: ParsedFindQuery, keepAliases: string[] = []): void {\n const roots = getCollectionRoots(query);\n if (query.condition) rewriteSiblingOrExpression(query, query.condition, roots, keepAliases);\n for (const root of roots) {\n if (queryReferencesAliasesOutsideConditions(query, root.aliases, keepAliases)) continue;\n if (conditionHasCrossScopeReference(query.condition, root.aliases)) continue;\n // I.e. move `b.title = 'x'` and `(br.rating = 5 OR br.rating = 4)`, but not `b.title = 'x' OR a.first_name = 'x'`.\n const moved = query.condition ? removeLocallyScopedConditions(query.condition, root.aliases) : [];\n if (moved.length === 0) continue;\n const exists = createExistsCondition(query, root, moved);\n if (!exists) {\n addConditions(query, moved);\n continue;\n }\n addConditions(query, [exists]);\n // I.e. after adding EXISTS, remove `books b` and its children from the outer FROM list.\n query.tables = query.tables.filter((t) => !root.aliases.has(t.alias));\n }\n removeEmptyExpressions(query.condition);\n}\n\n/** Rewrites eligible sibling collection ORs while preserving outer/mixed-scope ORs as joins. */\nfunction rewriteSiblingOrExpression(\n query: ParsedFindQuery,\n condition: ParsedExpressionCondition,\n roots: CollectionRoot[],\n keepAliases: string[],\n): void {\n if (condition.kind !== \"exp\") return;\n if (condition.op === \"or\" && rewriteSiblingOrExpressionChildren(query, condition, roots, keepAliases)) return;\n if (condition.op === \"and\") {\n for (const child of condition.conditions) rewriteSiblingOrExpression(query, child, roots, keepAliases);\n }\n}\n\n/** Returns true when OR branches that are scoped to collection subtrees became EXISTS conditions. */\nfunction rewriteSiblingOrExpressionChildren(\n query: ParsedFindQuery,\n exp: ParsedExpressionFilter,\n roots: CollectionRoot[],\n keepAliases: string[],\n): boolean {\n const matches: { collectionRoot: CollectionRoot; condition: ParsedExpressionCondition }[] = [];\n const usedAliases = new Set<string>();\n const usedRoots = new Set<string>();\n let hasAntiJoinBranch = false;\n for (const condition of exp.conditions) {\n if (!isRealCondition(condition)) return false;\n const match = roots.find((root) => conditionReferencesOnlyAliases(condition, root.aliases));\n if (!match) {\n const found = conditionAliases(condition);\n // I.e. `a.first_name = 'x'` can stay in the OR while `b.title = 'x'` becomes EXISTS, but\n // `a.first_name = 'x' AND b.title = 'x'` must stay joined because one branch spans both scopes.\n if (roots.some((root) => hasAnyAlias(found, root.aliases))) return false;\n continue;\n }\n matches.push({ collectionRoot: match, condition });\n usedRoots.add(match.table.alias);\n hasAntiJoinBranch ||= isCollectionAntiJoin(condition, match);\n for (const alias of match.aliases) usedAliases.add(alias);\n }\n if (matches.length === 0) return false;\n // I.e. rewrite true sibling collection ORs like `b.id IS NOT NULL OR c.id IS NOT NULL`, and same-root\n // anti-join ORs like `b.id IS NULL OR br.rating = 5` that need `b.id IS NULL` to become `NOT EXISTS`.\n // skip positive-only single-root ORs, i.e. ORs with no `b.id IS NULL` anti-join branch like\n // `b.title = 'x' OR br.rating = 5`; mixed ordinary/collection ORs like `a.first_name = 'x' OR b.title = 'x'`\n // are safe because only the collection branch is replaced. Aliases are also filtered elsewhere like\n // `b.order = 1 AND (b.title = 'x' OR c.text = 'x')`, and aliases that must stay projected/sorted like\n // `SELECT b.title` or `ORDER BY b.title`.\n if (\n (matches.length === exp.conditions.length && usedRoots.size < 2 && !hasAntiJoinBranch) ||\n conditionReferencesAliasesOutside(query.condition, exp, usedAliases) ||\n queryReferencesAliasesOutsideConditions(query, usedAliases, keepAliases)\n ) {\n return false;\n }\n\n const existsConditions = new Map<ParsedExpressionCondition, ExistsCondition>();\n for (const match of matches) {\n const exists = createExistsCondition(query, match.collectionRoot, [match.condition]);\n if (!exists) return false;\n existsConditions.set(match.condition, exists);\n }\n exp.conditions = exp.conditions.map((condition) => existsConditions.get(condition) ?? condition);\n // I.e. leave the collection joins in place for now; pruning removes them after all rewrites.\n return true;\n}\n\n/** Creates an EXISTS/NOT EXISTS condition for moved collection filters, or undefined when a LEFT JOIN must stay. */\nfunction createExistsCondition(\n query: ParsedFindQuery,\n collectionRoot: CollectionRoot,\n moved: ParsedExpressionCondition[],\n): ExistsCondition | undefined {\n const root = collectionRoot.table;\n const hasOnlyAntiJoin = moved.length === 1 && isCollectionAntiJoin(moved[0], collectionRoot);\n if (!hasOnlyAntiJoin && !moved.some(isRealCondition)) {\n // I.e. only soft-delete/STI conditions moved; don't create an EXISTS that changes nothing.\n return undefined;\n }\n if (!hasOnlyAntiJoin && moved.some((c) => conditionContainsCollectionAntiJoin(c, collectionRoot))) {\n // I.e. `b.id IS NULL OR br.rating = 5` is not a pure anti-join; leave it as a LEFT JOIN for SQL semantics.\n return undefined;\n }\n\n // I.e. `rpm` may correlate through `_pp_version.id = rpm.ready_plan_version_id`, so pruning must keep\n // `_pp_version` even when the collection metadata's parent alias is only `pp`.\n const correlationAliases = joinDependencies(root);\n const correlation: RawCondition = {\n kind: \"raw\",\n aliases: [root.alias, ...correlationAliases],\n condition: `${root.col1} = ${root.col2}`,\n bindings: [],\n pruneable: false,\n };\n // I.e. a pure `b.id IS NULL` anti-join becomes `NOT EXISTS (SELECT 1 FROM books b WHERE a.id = b.author_id)`.\n const conditions = hasOnlyAntiJoin ? [correlation] : [correlation, ...moved];\n const subquery: ParsedFindQuery = {\n selects: [\"1\"],\n tables: query.tables\n .filter((t) => (hasOnlyAntiJoin ? t.alias === root.alias : collectionRoot.aliases.has(t.alias)))\n .map((t) => {\n // I.e. the collection root becomes the subquery's FROM table; children remain joins off that root.\n if (t.alias === root.alias) return { join: \"primary\", alias: t.alias, table: t.table } satisfies PrimaryTable;\n // I.e. preserve nullable paths like `LEFT JOIN p ... LEFT JOIN sp ... WHERE p.id = 1 OR sp.id = 1`; forcing\n // children to INNER JOIN would require every optional branch to exist before the OR can match any branch.\n if (t.join === \"outer\") return { ...t, distinct: false };\n return t;\n }),\n condition: { kind: \"exp\", op: \"and\", conditions },\n orderBys: [],\n };\n // I.e. nested `books.reviews` first creates an EXISTS for books, then this recursive call creates EXISTS for reviews.\n rewriteCollectionJoins(subquery);\n return {\n kind: \"exists\",\n negate: hasOnlyAntiJoin,\n subquery,\n outerAliases: correlationAliases,\n };\n}\n\n/** Appends conditions to the top-level expression, creating an AND wrapper when needed. */\nfunction addConditions(query: ParsedFindQuery, conditions: ParsedExpressionCondition[]): void {\n query.condition ??= { kind: \"exp\", op: \"and\", conditions: [] };\n query.condition.conditions.push(...conditions);\n}\n\n/** Returns top-level collection roots with their full join subtrees. */\nfunction getCollectionRoots(query: ParsedFindQuery): CollectionRoot[] {\n return getTopLevelCollectionRoots(query).map((table) => {\n const aliases = collectJoinSubtreeAliases(query, table.alias);\n return {\n table,\n aliases,\n joinTables: query.tables.filter((t): t is JoinTable => isJoinTable(t) && aliases.has(t.alias)),\n };\n });\n}\n\n/** Returns top-level collection roots, i.e. `books b` but not nested `book_reviews br`. */\nfunction getTopLevelCollectionRoots(query: ParsedFindQuery): JoinTable[] {\n // I.e. if `books b` is nested under another collection root, the parent pass should absorb it; don't rewrite it here.\n const joinTables = query.tables.filter(isJoinTable);\n const collectionAliases = new Set(joinTables.flatMap((t) => (t.collection ? [t.alias] : [])));\n return joinTables.filter(\n (t) => t.collection?.rootAlias === t.alias && !collectionAliases.has(t.collection.parentAlias),\n );\n}\n\n/** Returns true if a remaining real condition prevents this subtree from becoming EXISTS, i.e. a cross-scope OR. */\nfunction conditionBlocksExistsRewrite(condition: ParsedExpressionCondition | undefined, aliases: Set<string>): boolean {\n if (!condition || !isRealCondition(condition)) return false;\n if (condition.kind === \"exp\" && condition.op === \"and\") {\n return condition.conditions.some((c) => conditionBlocksExistsRewrite(c, aliases));\n }\n return conditionReferencesAnyAlias(condition, aliases);\n}\n\n/** Collects a collection root and all joins that depend on it, i.e. `b -> br -> c`. */\nfunction collectJoinSubtreeAliases(query: ParsedFindQuery, rootAlias: string): Set<string> {\n const aliases = new Set([rootAlias]);\n let changed = true;\n while (changed) {\n changed = false;\n for (const table of query.tables) {\n if (!isJoinTable(table)) continue;\n // I.e. `book_reviews br ON b.id = br.book_id` depends on `b`, so `br` belongs in the `b` subtree.\n if (!aliases.has(table.alias) && joinReferencesAnyAlias(table, aliases)) {\n aliases.add(table.alias);\n changed = true;\n }\n }\n }\n return aliases;\n}\n\n/**\n * Removes AND-safe conditions whose aliases all live inside one collection subtree.\n *\n * I.e. in `a.age = 1 AND b.title = 'x'`, only `b.title = 'x'` moves. In `b.title = 'x' OR br.rating = 5`,\n * the whole OR moves only if every alias is inside the same subtree.\n */\nfunction removeLocallyScopedConditions(exp: ParsedExpressionFilter, aliases: Set<string>): ParsedExpressionCondition[] {\n if (exp.op === \"or\") {\n // I.e. OR cannot be split across scopes; either move the whole OR into the EXISTS, or leave it outside.\n if (!conditionReferencesOnlyAliases(exp, aliases)) return [];\n const moved = { ...exp, conditions: [...exp.conditions] } satisfies ParsedExpressionFilter;\n exp.conditions = [];\n return [moved];\n }\n const moved: ParsedExpressionCondition[] = [];\n for (let i = exp.conditions.length - 1; i >= 0; i--) {\n const condition = exp.conditions[i];\n if (condition.kind === \"exp\" && condition.op === \"and\") {\n // I.e. flatten nested AND movement so `a AND (b AND br)` can still move `b` and `br` into the EXISTS.\n moved.push(...removeLocallyScopedConditions(condition, aliases));\n if (condition.conditions.length === 0) exp.conditions.splice(i, 1);\n } else if (conditionReferencesOnlyAliases(condition, aliases)) {\n // I.e. move `b.title = 'x'` out of the parent AND and into the collection EXISTS.\n moved.unshift(condition);\n exp.conditions.splice(i, 1);\n }\n }\n return moved;\n}\n\n/** Returns true when a condition references at least one alias and all aliases are in `aliases`, i.e. only `b`/`br`. */\nfunction conditionReferencesOnlyAliases(condition: ParsedExpressionCondition, aliases: Set<string>): boolean {\n const found = conditionAliases(condition);\n return found.size > 0 && [...found].every((alias) => aliases.has(alias));\n}\n\n/** Returns true when `aliases` are referenced by a real condition other than the targeted OR expression. */\nfunction conditionReferencesAliasesOutside(\n condition: ParsedExpressionCondition | undefined,\n target: ParsedExpressionCondition,\n aliases: Set<string>,\n): boolean {\n if (!condition || condition === target || !isRealCondition(condition)) return false;\n if (condition.kind === \"exp\") {\n return condition.conditions.some((child) => conditionReferencesAliasesOutside(child, target, aliases));\n }\n return conditionReferencesAnyAlias(condition, aliases);\n}\n\n/** Returns true when selected/ordered aliases would force these joins to remain in the outer query. */\nfunction queryReferencesAliasesOutsideConditions(\n query: ParsedFindQuery,\n aliases: Set<string>,\n keepAliases: string[],\n): boolean {\n const requiredAliases = queryRequiredAliasesOutsideConditions(query, keepAliases);\n // I.e. if `array_agg(br.rating)` requires `br`, then `b` is required too because `br` joins through `b`; don't\n // move `b` under EXISTS just because the select references only its child alias directly.\n return hasAnyAlias(requiredAliases, aliases);\n}\n\n/**\n * Returns aliases needed by SELECT/GROUP/ORDER plus their join dependencies.\n *\n * I.e. `array_agg(br.rating)` requires `br`, and then `br` requires `b` because it joins through `b`.\n */\nfunction queryRequiredAliasesOutsideConditions(query: ParsedFindQuery, keepAliases: string[]): Set<string> {\n const required = new Set<string>();\n for (const alias of keepAliases) required.add(alias);\n for (const orderBy of query.orderBys) required.add(orderBy.alias);\n for (const groupBy of query.groupBys ?? []) {\n if (\"expression\" in groupBy) {\n addSelectAliases(query, required, groupBy.expression);\n } else {\n required.add(groupBy.alias);\n }\n }\n for (const select of query.selects) {\n if (typeof select === \"string\") {\n addSelectAliases(query, required, select);\n } else if (\"aliases\" in select) {\n for (const alias of select.aliases) required.add(alias);\n addSelectAliases(query, required, select.sql);\n }\n }\n\n const todo = [...required];\n while (todo.length > 0) {\n const alias = todo.pop()!;\n const table = query.tables.find((t) => t.alias === alias);\n if (!table || !isJoinTable(table)) continue;\n for (const dependency of joinDependencies(table)) {\n if (!required.has(dependency)) {\n required.add(dependency);\n todo.push(dependency);\n }\n }\n }\n return required;\n}\n\n/** Adds aliases referenced by raw select SQL, i.e. `array_agg(br.rating)` requires `br`. */\nfunction addSelectAliases(query: ParsedFindQuery, required: Set<string>, select: string): void {\n for (const table of query.tables) {\n if (selectReferencesAlias(select, table.alias)) required.add(table.alias);\n }\n}\n\n/** Returns the aliases needed to evaluate a join's ON clause, excluding the joined alias itself. */\nfunction joinDependencies(table: JoinTable): string[] {\n return [parseAlias(table.col1), parseAlias(table.col2)].filter((alias) => alias !== table.alias);\n}\n\n/** Returns true when a condition references this subtree and another scope, i.e. `b.title = 'x' OR c.text = 'x'`. */\nfunction conditionHasCrossScopeReference(\n condition: ParsedExpressionCondition | undefined,\n aliases: Set<string>,\n): boolean {\n if (!condition || !isRealCondition(condition)) return false;\n if (condition.kind === \"exp\" && condition.op === \"and\") {\n return condition.conditions.some((child) => conditionHasCrossScopeReference(child, aliases));\n }\n const found = conditionAliases(condition);\n return hasAnyAlias(found, aliases) && ![...found].every((alias) => aliases.has(alias));\n}\n\n/** Returns true when a condition references any alias in `aliases`, i.e. `b` in `b.title = c.text`. */\nfunction conditionReferencesAnyAlias(condition: ParsedExpressionCondition, aliases: Set<string>): boolean {\n return hasAnyAlias(conditionAliases(condition), aliases);\n}\n\n/** Returns true when `table` is an ordinary SQL join. */\nfunction isJoinTable(table: ParsedFindQuery[\"tables\"][number]): table is JoinTable {\n return table.join === \"inner\" || table.join === \"outer\";\n}\n\n/** Returns true when a join's ON clause references any alias in `aliases`. */\nfunction joinReferencesAnyAlias(table: JoinTable, aliases: Set<string>): boolean {\n return joinDependencies(table).some((alias) => aliases.has(alias));\n}\n\n/** Returns true when two alias sets overlap. */\nfunction hasAnyAlias(found: Set<string>, aliases: Set<string>): boolean {\n return [...found].some((alias) => aliases.has(alias));\n}\n\n/** Returns true for collection anti-joins, i.e. `b.id IS NULL` or m2m target `t.id IS NULL` for root `att`. */\nfunction isCollectionAntiJoin(condition: ParsedExpressionCondition, root: CollectionRoot): boolean {\n return collectionAntiJoinAliases(root).some((alias) => isAliasIdNull(condition, alias));\n}\n\n/** Returns aliases whose `id IS NULL` means the collection root has no matching row. */\nfunction collectionAntiJoinAliases(root: CollectionRoot): string[] {\n return [...root.aliases].filter((alias) => {\n if (alias === root.table.alias) return true;\n const table = rootTable(root, alias);\n // I.e. for m2m `authors -> authors_to_tags att -> tags t`, `t.id IS NULL` means no tag membership.\n return table?.collection?.rootAlias === root.table.alias;\n });\n}\n\n/** Returns a join table from a collection subtree by alias. */\nfunction rootTable(root: CollectionRoot, alias: string): JoinTable | undefined {\n return root.joinTables.find((table) => table.alias === alias);\n}\n\n/** Returns true for `alias.id IS NULL`, i.e. the parse shape for `{ books: { id: null } }`. */\nfunction isAliasIdNull(condition: ParsedExpressionCondition, alias: string): boolean {\n return (\n condition.kind === \"column\" &&\n condition.alias === alias &&\n condition.column === \"id\" &&\n condition.cond.kind === \"is-null\"\n );\n}\n\n/** Returns true when a condition tree contains a collection anti-join branch inside an OR. */\nfunction conditionContainsCollectionAntiJoin(condition: ParsedExpressionCondition, root: CollectionRoot): boolean {\n if (isCollectionAntiJoin(condition, root)) return true;\n if (condition.kind === \"exp\") return condition.conditions.some((c) => conditionContainsCollectionAntiJoin(c, root));\n return false;\n}\n\n/** Removes empty expression wrappers left behind by condition movement, i.e. `AND []` after all children moved. */\nfunction removeEmptyExpressions(exp: ParsedExpressionFilter | undefined): void {\n if (!exp) return;\n for (let i = exp.conditions.length - 1; i >= 0; i--) {\n const condition = exp.conditions[i];\n if (condition.kind === \"exp\") {\n removeEmptyExpressions(condition);\n if (condition.conditions.length === 0) exp.conditions.splice(i, 1);\n }\n }\n}\n\n/** Returns true if a condition must be preserved to maintain query semantics, i.e. user filters vs soft-delete filters. */\nfunction isRealCondition(condition: ParsedExpressionCondition): boolean {\n if (condition.kind === \"column\" || condition.kind === \"raw\") {\n return !condition.pruneable;\n } else if (condition.kind === \"exists\") {\n return true;\n } else if (condition.kind === \"exp\") {\n return condition.conditions.some(isRealCondition);\n } else {\n assertNever(condition);\n }\n}\n\n/** Returns all aliases referenced by a condition, i.e. `b` and `a` in an OR. */\nfunction conditionAliases(condition: ParsedExpressionCondition): Set<string> {\n const aliases = new Set<string>();\n collectAllAliases(condition, aliases);\n return aliases;\n}\n\n/** Collects all aliases referenced by a condition, including inside nested expressions, i.e. `b` and `a` in an OR. */\nfunction collectAllAliases(cond: ParsedExpressionCondition, out: Set<string>): void {\n if (cond.kind === \"column\") {\n out.add(cond.alias);\n } else if (cond.kind === \"raw\") {\n for (const a of cond.aliases) out.add(a);\n } else if (cond.kind === \"exp\") {\n for (const c of cond.conditions) collectAllAliases(c, out);\n } else if (cond.kind === \"exists\") {\n // I.e. an EXISTS subquery is already a scoped unit; outer movement decisions should not inspect its internals.\n } else {\n assertNever(cond);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,wBACd,OACA,OAKI,CAAC,GACC;CACN,MA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AAGA,SAAS,oCAAoC,WAAsC,MAA+B;CAChH,IAAI,qBAAqB,WAAW,IAAI,GAAG,OAAO;CAClD,IAAI,UAAU,SAAS,OAAO,OAAO,UAAU,WAAW,MAAM,MAAM,oCAAoC,GAAG,IAAI,CAAC;CAClH,OAAO;AACT;;AAGA,SAAS,uBAAuB,KAA+C;CAC7E,IAAI,CAAC,KAAK;CACV,KAAK,IAAI,IAAI,IAAI,WAAW,SAAS,GAAG,KAAK,GAAG,KAAK;EACnD,MAAM,YAAY,IAAI,WAAW;EACjC,IAAI,UAAU,SAAS,OAAO;GAC5B,uBAAuB,SAAS;GAChC,IAAI,UAAU,WAAW,WAAW,GAAG,IAAI,WAAW,OAAO,GAAG,CAAC;EACnE;CACF;AACF;;AAGA,SAAS,gBAAgB,WAA+C;CACtE,IAAI,UAAU,SAAS,YAAY,UAAU,SAAS,OACpD,OAAO,CAAC,UAAU;MACb,IAAI,UAAU,SAAS,UAC5B,OAAO;MACF,IAAI,UAAU,SAAS,OAC5B,OAAO,UAAU,WAAW,KAAK,eAAe;MAEhD,YAAY,SAAS;AAEzB;;AAGA,SAAS,iBAAiB,WAAmD;CAC3E,MAAM,0BAAU,IAAI,IAAY;CAChC,kBAAkB,WAAW,OAAO;CACpC,OAAO;AACT;;AAGA,SAAS,kBAAkB,MAAiC,KAAwB;CAClF,IAAI,KAAK,SAAS,UAChB,IAAI,IAAI,KAAK,KAAK;MACb,IAAI,KAAK,SAAS,OACvB,KAAK,MAAM,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC;MAClC,IAAI,KAAK,SAAS,OACvB,KAAK,MAAM,KAAK,KAAK,YAAY,kBAAkB,GAAG,GAAG;MACpD,IAAI,KAAK,SAAS,UAAU,CAEnC,OACE,YAAY,IAAI;AAEpB"}
1
+ {"version":3,"file":"QueryParser.collectionJoins.js","names":[],"sources":["../../../src/queries/find/QueryParser.collectionJoins.ts"],"sourcesContent":["import { pruneUnusedJoins, selectReferencesAlias } from \"src/queries/find/QueryParser.pruning.ts\";\nimport {\n type JoinTable,\n type ParsedFindQuery,\n type PrimaryTable,\n maybeAddIdNotNulls,\n parseAlias,\n} from \"src/queries/find/QueryParser.ts\";\nimport type {\n ExistsCondition,\n ParsedExpressionCondition,\n ParsedExpressionFilter,\n RawCondition,\n} from \"src/queries/parsedConditions.ts\";\nimport { assertNever } from \"src/utils.ts\";\n\n/** A collection root plus every join nested under it, i.e. `books b` with `book_reviews br`. */\ninterface CollectionRoot {\n /** The top-level collection join that becomes the EXISTS FROM table, i.e. `books b`. */\n table: JoinTable;\n /** Every alias in this collection subtree, i.e. `b` and `br` for `authors -> books -> reviews`. */\n aliases: Set<string>;\n /** Every join table in this collection subtree, i.e. `att` and `t` for an m2m tag filter. */\n joinTables: JoinTable[];\n}\n\n/**\n * Rewrites eligible logical collection LEFT JOINs into EXISTS after plugins have mutated the AST.\n *\n * QueryParser intentionally leaves collection filters as ordinary joins so `beforeFind` plugins see\n * stabler/simpler input than \"sometimes JOINs / sometimes EXISTS\".\n *\n * This pass runs after plugins and before SQL rendering:\n *\n * 1. `rewriteCollectionJoins` finds top-level collection joins and moves conditions that reference only\n * that subtree into a correlated EXISTS subquery. I.e. `{ books: { title: \"b1\" } }` becomes\n * `EXISTS (SELECT 1 FROM books b WHERE a.id = b.author_id AND b.title = 'b1')`.\n * 2. The same helper recurses into the generated subquery, so nested collections become nested EXISTS clauses.\n * I.e. `{ books: { reviews: { rating: 5 } } }` becomes EXISTS(books WHERE EXISTS(reviews)).\n * 3. Conditions that cannot be safely moved stay as LEFT JOINs. I.e. `OR(b.title = 'x', a.first_name = 'x')`\n * needs both aliases in one SQL scope, so `b` remains a join instead of becoming an EXISTS.\n * 4. Remaining fanout LEFT JOIN roots are rejected unless `allowMultipleLeftJoins` is set,\n * because they can produce cross-product row explosions.\n * 5. Finally, `maybeAddIdNotNulls` and `pruneUnusedJoins` clean up the joins that remain.\n */\nexport function optimizeCollectionJoins(\n query: ParsedFindQuery,\n opts: {\n allowMultipleLeftJoins?: boolean;\n optimizeJoinsToExists?: boolean;\n pruneJoins?: boolean;\n keepAliases?: string[];\n } = {},\n): void {\n const { allowMultipleLeftJoins = false, optimizeJoinsToExists = true, pruneJoins = true, keepAliases = [] } = opts;\n for (const table of query.tables) {\n // I.e. batched find/count queries wrap the real query in a LATERAL subquery; optimize that inner query too,\n // but let the outer query decide final pruning so it can keep the lateral alias itself.\n if (table.join === \"lateral\") optimizeCollectionJoins(table.query, { ...opts, pruneJoins: false });\n }\n if (optimizeJoinsToExists) rewriteCollectionJoins(query, keepAliases);\n\n // I.e. collection LEFT JOINs now fall into three buckets:\n // 1. local real filters, like `{ books: { title: \"b1\" } }`, were rewritten to EXISTS above;\n // 2. no local real filters, like `{ books: {}, comments: {} }`, are safe because pruning will remove them;\n // 3. blocked real filters, like cross-scope ORs, must stay as LEFT JOINs and can multiply rows.\n // Only the third bucket should trip the fanout guard.\n const fanoutLeftJoinAliases = getCollectionRoots(query)\n .filter((root) => conditionBlocksExistsRewrite(query.condition, root.aliases))\n .map((root) => root.table.alias);\n if (optimizeJoinsToExists && !allowMultipleLeftJoins && fanoutLeftJoinAliases.length > 1) {\n throw new Error(\n `em.find would issue multiple LEFT JOINs across collection relations (${fanoutLeftJoinAliases.join(\n \", \",\n )}); pass allowMultipleLeftJoins: true if this fanout is intentional`,\n );\n }\n\n if (query.tables.some((t) => t.join === \"outer\")) {\n // I.e. preserve legacy LEFT JOIN null semantics for any joins that could not become EXISTS.\n maybeAddIdNotNulls(query);\n }\n if (pruneJoins) {\n // I.e. remove logical collection joins that were replaced by EXISTS and any joins only needed before plugin edits.\n pruneUnusedJoins(query, keepAliases);\n }\n}\n\n/**\n * Rewrites root-level collection join subtrees into EXISTS when their conditions are locally scoped.\n *\n * I.e. for `authors a -> books b -> book_reviews br`, `b` is the collection root and `br` is part of its subtree.\n */\nfunction rewriteCollectionJoins(query: ParsedFindQuery, keepAliases: string[] = []): void {\n const roots = getCollectionRoots(query);\n if (query.condition) rewriteSiblingOrExpression(query, query.condition, roots, keepAliases);\n for (const root of roots) {\n if (queryReferencesAliasesOutsideConditions(query, root.aliases, keepAliases)) continue;\n if (conditionHasCrossScopeReference(query.condition, root.aliases)) continue;\n // I.e. move `b.title = 'x'` and `(br.rating = 5 OR br.rating = 4)`, but not `b.title = 'x' OR a.first_name = 'x'`.\n const moved = query.condition ? removeLocallyScopedConditions(query.condition, root.aliases) : [];\n if (moved.length === 0) continue;\n const exists = createExistsCondition(query, root, moved);\n if (!exists) {\n addConditions(query, moved);\n continue;\n }\n addConditions(query, [exists]);\n // I.e. after adding EXISTS, remove `books b` and its children from the outer FROM list.\n query.tables = query.tables.filter((t) => !root.aliases.has(t.alias));\n }\n removeEmptyExpressions(query.condition);\n}\n\n/** Rewrites eligible sibling collection ORs while preserving outer/mixed-scope ORs as joins. */\nfunction rewriteSiblingOrExpression(\n query: ParsedFindQuery,\n condition: ParsedExpressionCondition,\n roots: CollectionRoot[],\n keepAliases: string[],\n): void {\n if (condition.kind !== \"exp\") return;\n if (condition.op === \"or\" && rewriteSiblingOrExpressionChildren(query, condition, roots, keepAliases)) return;\n if (condition.op === \"and\") {\n for (const child of condition.conditions) rewriteSiblingOrExpression(query, child, roots, keepAliases);\n }\n}\n\n/** Returns true when OR branches that are scoped to collection subtrees became EXISTS conditions. */\nfunction rewriteSiblingOrExpressionChildren(\n query: ParsedFindQuery,\n exp: ParsedExpressionFilter,\n roots: CollectionRoot[],\n keepAliases: string[],\n): boolean {\n const matches: { collectionRoot: CollectionRoot; condition: ParsedExpressionCondition }[] = [];\n const usedAliases = new Set<string>();\n const usedRoots = new Set<string>();\n let hasAntiJoinBranch = false;\n for (const condition of exp.conditions) {\n if (!isRealCondition(condition)) return false;\n const match = roots.find((root) => conditionReferencesOnlyAliases(condition, root.aliases));\n if (!match) {\n const found = conditionAliases(condition);\n // I.e. `a.first_name = 'x'` can stay in the OR while `b.title = 'x'` becomes EXISTS, but\n // `a.first_name = 'x' AND b.title = 'x'` must stay joined because one branch spans both scopes.\n if (roots.some((root) => hasAnyAlias(found, root.aliases))) return false;\n continue;\n }\n matches.push({ collectionRoot: match, condition });\n usedRoots.add(match.table.alias);\n hasAntiJoinBranch ||= isCollectionAntiJoin(condition, match);\n for (const alias of match.aliases) usedAliases.add(alias);\n }\n if (matches.length === 0) return false;\n // I.e. rewrite true sibling collection ORs like `b.id IS NOT NULL OR c.id IS NOT NULL`, and same-root\n // anti-join ORs like `b.id IS NULL OR br.rating = 5` that need `b.id IS NULL` to become `NOT EXISTS`.\n // skip positive-only single-root ORs, i.e. ORs with no `b.id IS NULL` anti-join branch like\n // `b.title = 'x' OR br.rating = 5`; mixed ordinary/collection ORs like `a.first_name = 'x' OR b.title = 'x'`\n // are safe because only the collection branch is replaced. Aliases are also filtered elsewhere like\n // `b.order = 1 AND (b.title = 'x' OR c.text = 'x')`, and aliases that must stay projected/sorted like\n // `SELECT b.title` or `ORDER BY b.title`.\n if (\n (matches.length === exp.conditions.length && usedRoots.size < 2 && !hasAntiJoinBranch) ||\n conditionReferencesAliasesOutside(query.condition, exp, usedAliases) ||\n queryReferencesAliasesOutsideConditions(query, usedAliases, keepAliases)\n ) {\n return false;\n }\n\n const existsConditions = new Map<ParsedExpressionCondition, ExistsCondition>();\n for (const match of matches) {\n const exists = createExistsCondition(query, match.collectionRoot, [match.condition]);\n if (!exists) return false;\n existsConditions.set(match.condition, exists);\n }\n exp.conditions = exp.conditions.map((condition) => existsConditions.get(condition) ?? condition);\n // I.e. leave the collection joins in place for now; pruning removes them after all rewrites.\n return true;\n}\n\n/** Creates an EXISTS/NOT EXISTS condition for moved collection filters, or undefined when a LEFT JOIN must stay. */\nfunction createExistsCondition(\n query: ParsedFindQuery,\n collectionRoot: CollectionRoot,\n moved: ParsedExpressionCondition[],\n): ExistsCondition | undefined {\n const root = collectionRoot.table;\n const hasOnlyAntiJoin = moved.length === 1 && isCollectionAntiJoin(moved[0], collectionRoot);\n if (!hasOnlyAntiJoin && !moved.some(isRealCondition)) {\n // I.e. only soft-delete/STI conditions moved; don't create an EXISTS that changes nothing.\n return undefined;\n }\n if (!hasOnlyAntiJoin && moved.some((c) => conditionContainsCollectionAntiJoin(c, collectionRoot))) {\n // I.e. `b.id IS NULL OR br.rating = 5` is not a pure anti-join; leave it as a LEFT JOIN for SQL semantics.\n return undefined;\n }\n\n // I.e. `rpm` may correlate through `_pp_version.id = rpm.ready_plan_version_id`, so pruning must keep\n // `_pp_version` even when the collection metadata's parent alias is only `pp`.\n const correlationAliases = joinDependencies(root);\n const correlation: RawCondition = {\n kind: \"raw\",\n aliases: [root.alias, ...correlationAliases],\n condition: `${root.col1} = ${root.col2}`,\n bindings: [],\n pruneable: false,\n };\n // I.e. a pure `b.id IS NULL` anti-join becomes `NOT EXISTS (SELECT 1 FROM books b WHERE a.id = b.author_id)`.\n const conditions = hasOnlyAntiJoin ? [correlation] : [correlation, ...moved];\n const subquery: ParsedFindQuery = {\n selects: [\"1\"],\n tables: query.tables\n .filter((t) => (hasOnlyAntiJoin ? t.alias === root.alias : collectionRoot.aliases.has(t.alias)))\n .map((t) => {\n // I.e. the collection root becomes the subquery's FROM table; children remain joins off that root.\n if (t.alias === root.alias) {\n // The m2m table still owns its otherTable FK metadata after becoming the EXISTS root.\n return {\n join: \"primary\",\n alias: t.alias,\n table: t.table,\n ...(root.idJoin && { idJoin: root.idJoin }),\n } satisfies PrimaryTable;\n }\n // I.e. preserve nullable paths like `LEFT JOIN p ... LEFT JOIN sp ... WHERE p.id = 1 OR sp.id = 1`; forcing\n // children to INNER JOIN would require every optional branch to exist before the OR can match any branch.\n if (t.join === \"outer\") return { ...t, distinct: false };\n return t;\n }),\n condition: { kind: \"exp\", op: \"and\", conditions },\n orderBys: [],\n };\n // I.e. nested `books.reviews` first creates an EXISTS for books, then this recursive call creates EXISTS for reviews.\n rewriteCollectionJoins(subquery);\n return {\n kind: \"exists\",\n negate: hasOnlyAntiJoin,\n subquery,\n outerAliases: correlationAliases,\n };\n}\n\n/** Appends conditions to the top-level expression, creating an AND wrapper when needed. */\nfunction addConditions(query: ParsedFindQuery, conditions: ParsedExpressionCondition[]): void {\n query.condition ??= { kind: \"exp\", op: \"and\", conditions: [] };\n query.condition.conditions.push(...conditions);\n}\n\n/** Returns top-level collection roots with their full join subtrees. */\nfunction getCollectionRoots(query: ParsedFindQuery): CollectionRoot[] {\n return getTopLevelCollectionRoots(query).map((table) => {\n const aliases = collectJoinSubtreeAliases(query, table.alias);\n return {\n table,\n aliases,\n joinTables: query.tables.filter((t): t is JoinTable => isJoinTable(t) && aliases.has(t.alias)),\n };\n });\n}\n\n/** Returns top-level collection roots, i.e. `books b` but not nested `book_reviews br`. */\nfunction getTopLevelCollectionRoots(query: ParsedFindQuery): JoinTable[] {\n // I.e. if `books b` is nested under another collection root, the parent pass should absorb it; don't rewrite it here.\n const joinTables = query.tables.filter(isJoinTable);\n const collectionAliases = new Set(joinTables.flatMap((t) => (t.collection ? [t.alias] : [])));\n return joinTables.filter(\n (t) => t.collection?.rootAlias === t.alias && !collectionAliases.has(t.collection.parentAlias),\n );\n}\n\n/** Returns true if a remaining real condition prevents this subtree from becoming EXISTS, i.e. a cross-scope OR. */\nfunction conditionBlocksExistsRewrite(condition: ParsedExpressionCondition | undefined, aliases: Set<string>): boolean {\n if (!condition || !isRealCondition(condition)) return false;\n if (condition.kind === \"exp\" && condition.op === \"and\") {\n return condition.conditions.some((c) => conditionBlocksExistsRewrite(c, aliases));\n }\n return conditionReferencesAnyAlias(condition, aliases);\n}\n\n/** Collects a collection root and all joins that depend on it, i.e. `b -> br -> c`. */\nfunction collectJoinSubtreeAliases(query: ParsedFindQuery, rootAlias: string): Set<string> {\n const aliases = new Set([rootAlias]);\n let changed = true;\n while (changed) {\n changed = false;\n for (const table of query.tables) {\n if (!isJoinTable(table)) continue;\n // I.e. `book_reviews br ON b.id = br.book_id` depends on `b`, so `br` belongs in the `b` subtree.\n if (!aliases.has(table.alias) && joinReferencesAnyAlias(table, aliases)) {\n aliases.add(table.alias);\n changed = true;\n }\n }\n }\n return aliases;\n}\n\n/**\n * Removes AND-safe conditions whose aliases all live inside one collection subtree.\n *\n * I.e. in `a.age = 1 AND b.title = 'x'`, only `b.title = 'x'` moves. In `b.title = 'x' OR br.rating = 5`,\n * the whole OR moves only if every alias is inside the same subtree.\n */\nfunction removeLocallyScopedConditions(exp: ParsedExpressionFilter, aliases: Set<string>): ParsedExpressionCondition[] {\n if (exp.op === \"or\") {\n // I.e. OR cannot be split across scopes; either move the whole OR into the EXISTS, or leave it outside.\n if (!conditionReferencesOnlyAliases(exp, aliases)) return [];\n const moved = { ...exp, conditions: [...exp.conditions] } satisfies ParsedExpressionFilter;\n exp.conditions = [];\n return [moved];\n }\n const moved: ParsedExpressionCondition[] = [];\n for (let i = exp.conditions.length - 1; i >= 0; i--) {\n const condition = exp.conditions[i];\n if (condition.kind === \"exp\" && condition.op === \"and\") {\n // I.e. flatten nested AND movement so `a AND (b AND br)` can still move `b` and `br` into the EXISTS.\n moved.push(...removeLocallyScopedConditions(condition, aliases));\n if (condition.conditions.length === 0) exp.conditions.splice(i, 1);\n } else if (conditionReferencesOnlyAliases(condition, aliases)) {\n // I.e. move `b.title = 'x'` out of the parent AND and into the collection EXISTS.\n moved.unshift(condition);\n exp.conditions.splice(i, 1);\n }\n }\n return moved;\n}\n\n/** Returns true when a condition references at least one alias and all aliases are in `aliases`, i.e. only `b`/`br`. */\nfunction conditionReferencesOnlyAliases(condition: ParsedExpressionCondition, aliases: Set<string>): boolean {\n const found = conditionAliases(condition);\n return found.size > 0 && [...found].every((alias) => aliases.has(alias));\n}\n\n/** Returns true when `aliases` are referenced by a real condition other than the targeted OR expression. */\nfunction conditionReferencesAliasesOutside(\n condition: ParsedExpressionCondition | undefined,\n target: ParsedExpressionCondition,\n aliases: Set<string>,\n): boolean {\n if (!condition || condition === target || !isRealCondition(condition)) return false;\n if (condition.kind === \"exp\") {\n return condition.conditions.some((child) => conditionReferencesAliasesOutside(child, target, aliases));\n }\n return conditionReferencesAnyAlias(condition, aliases);\n}\n\n/** Returns true when selected/ordered aliases would force these joins to remain in the outer query. */\nfunction queryReferencesAliasesOutsideConditions(\n query: ParsedFindQuery,\n aliases: Set<string>,\n keepAliases: string[],\n): boolean {\n const requiredAliases = queryRequiredAliasesOutsideConditions(query, keepAliases);\n // I.e. if `array_agg(br.rating)` requires `br`, then `b` is required too because `br` joins through `b`; don't\n // move `b` under EXISTS just because the select references only its child alias directly.\n return hasAnyAlias(requiredAliases, aliases);\n}\n\n/**\n * Returns aliases needed by SELECT/GROUP/ORDER plus their join dependencies.\n *\n * I.e. `array_agg(br.rating)` requires `br`, and then `br` requires `b` because it joins through `b`.\n */\nfunction queryRequiredAliasesOutsideConditions(query: ParsedFindQuery, keepAliases: string[]): Set<string> {\n const required = new Set<string>();\n for (const alias of keepAliases) required.add(alias);\n for (const orderBy of query.orderBys) required.add(orderBy.alias);\n for (const groupBy of query.groupBys ?? []) {\n if (\"expression\" in groupBy) {\n addSelectAliases(query, required, groupBy.expression);\n } else {\n required.add(groupBy.alias);\n }\n }\n for (const select of query.selects) {\n if (typeof select === \"string\") {\n addSelectAliases(query, required, select);\n } else if (\"aliases\" in select) {\n for (const alias of select.aliases) required.add(alias);\n addSelectAliases(query, required, select.sql);\n }\n }\n\n const todo = [...required];\n while (todo.length > 0) {\n const alias = todo.pop()!;\n const table = query.tables.find((t) => t.alias === alias);\n if (!table || !isJoinTable(table)) continue;\n for (const dependency of joinDependencies(table)) {\n if (!required.has(dependency)) {\n required.add(dependency);\n todo.push(dependency);\n }\n }\n }\n return required;\n}\n\n/** Adds aliases referenced by raw select SQL, i.e. `array_agg(br.rating)` requires `br`. */\nfunction addSelectAliases(query: ParsedFindQuery, required: Set<string>, select: string): void {\n for (const table of query.tables) {\n if (selectReferencesAlias(select, table.alias)) required.add(table.alias);\n }\n}\n\n/** Returns the aliases needed to evaluate a join's ON clause, excluding the joined alias itself. */\nfunction joinDependencies(table: JoinTable): string[] {\n return [parseAlias(table.col1), parseAlias(table.col2)].filter((alias) => alias !== table.alias);\n}\n\n/** Returns true when a condition references this subtree and another scope, i.e. `b.title = 'x' OR c.text = 'x'`. */\nfunction conditionHasCrossScopeReference(\n condition: ParsedExpressionCondition | undefined,\n aliases: Set<string>,\n): boolean {\n if (!condition || !isRealCondition(condition)) return false;\n if (condition.kind === \"exp\" && condition.op === \"and\") {\n return condition.conditions.some((child) => conditionHasCrossScopeReference(child, aliases));\n }\n const found = conditionAliases(condition);\n return hasAnyAlias(found, aliases) && ![...found].every((alias) => aliases.has(alias));\n}\n\n/** Returns true when a condition references any alias in `aliases`, i.e. `b` in `b.title = c.text`. */\nfunction conditionReferencesAnyAlias(condition: ParsedExpressionCondition, aliases: Set<string>): boolean {\n return hasAnyAlias(conditionAliases(condition), aliases);\n}\n\n/** Returns true when `table` is an ordinary SQL join. */\nfunction isJoinTable(table: ParsedFindQuery[\"tables\"][number]): table is JoinTable {\n return table.join === \"inner\" || table.join === \"outer\";\n}\n\n/** Returns true when a join's ON clause references any alias in `aliases`. */\nfunction joinReferencesAnyAlias(table: JoinTable, aliases: Set<string>): boolean {\n return joinDependencies(table).some((alias) => aliases.has(alias));\n}\n\n/** Returns true when two alias sets overlap. */\nfunction hasAnyAlias(found: Set<string>, aliases: Set<string>): boolean {\n return [...found].some((alias) => aliases.has(alias));\n}\n\n/** Returns true for collection anti-joins, i.e. `b.id IS NULL` or m2m target `t.id IS NULL` for root `att`. */\nfunction isCollectionAntiJoin(condition: ParsedExpressionCondition, root: CollectionRoot): boolean {\n return collectionAntiJoinAliases(root).some((alias) => isAliasIdNull(condition, alias));\n}\n\n/** Returns aliases whose `id IS NULL` means the collection root has no matching row. */\nfunction collectionAntiJoinAliases(root: CollectionRoot): string[] {\n return [...root.aliases].filter((alias) => {\n if (alias === root.table.alias) return true;\n const table = rootTable(root, alias);\n // I.e. for m2m `authors -> authors_to_tags att -> tags t`, `t.id IS NULL` means no tag membership.\n return table?.collection?.rootAlias === root.table.alias;\n });\n}\n\n/** Returns a join table from a collection subtree by alias. */\nfunction rootTable(root: CollectionRoot, alias: string): JoinTable | undefined {\n return root.joinTables.find((table) => table.alias === alias);\n}\n\n/** Returns true for `alias.id IS NULL`, i.e. the parse shape for `{ books: { id: null } }`. */\nfunction isAliasIdNull(condition: ParsedExpressionCondition, alias: string): boolean {\n return (\n condition.kind === \"column\" &&\n condition.alias === alias &&\n condition.column === \"id\" &&\n condition.cond.kind === \"is-null\"\n );\n}\n\n/** Returns true when a condition tree contains a collection anti-join branch inside an OR. */\nfunction conditionContainsCollectionAntiJoin(condition: ParsedExpressionCondition, root: CollectionRoot): boolean {\n if (isCollectionAntiJoin(condition, root)) return true;\n if (condition.kind === \"exp\") return condition.conditions.some((c) => conditionContainsCollectionAntiJoin(c, root));\n return false;\n}\n\n/** Removes empty expression wrappers left behind by condition movement, i.e. `AND []` after all children moved. */\nfunction removeEmptyExpressions(exp: ParsedExpressionFilter | undefined): void {\n if (!exp) return;\n for (let i = exp.conditions.length - 1; i >= 0; i--) {\n const condition = exp.conditions[i];\n if (condition.kind === \"exp\") {\n removeEmptyExpressions(condition);\n if (condition.conditions.length === 0) exp.conditions.splice(i, 1);\n }\n }\n}\n\n/** Returns true if a condition must be preserved to maintain query semantics, i.e. user filters vs soft-delete filters. */\nfunction isRealCondition(condition: ParsedExpressionCondition): boolean {\n if (condition.kind === \"column\" || condition.kind === \"raw\") {\n return !condition.pruneable;\n } else if (condition.kind === \"exists\") {\n return true;\n } else if (condition.kind === \"exp\") {\n return condition.conditions.some(isRealCondition);\n } else {\n assertNever(condition);\n }\n}\n\n/** Returns all aliases referenced by a condition, i.e. `b` and `a` in an OR. */\nfunction conditionAliases(condition: ParsedExpressionCondition): Set<string> {\n const aliases = new Set<string>();\n collectAllAliases(condition, aliases);\n return aliases;\n}\n\n/** Collects all aliases referenced by a condition, including inside nested expressions, i.e. `b` and `a` in an OR. */\nfunction collectAllAliases(cond: ParsedExpressionCondition, out: Set<string>): void {\n if (cond.kind === \"column\") {\n out.add(cond.alias);\n } else if (cond.kind === \"raw\") {\n for (const a of cond.aliases) out.add(a);\n } else if (cond.kind === \"exp\") {\n for (const c of cond.conditions) collectAllAliases(c, out);\n } else if (cond.kind === \"exists\") {\n // I.e. an EXISTS subquery is already a scoped unit; outer movement decisions should not inspect its internals.\n } else {\n assertNever(cond);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,wBACd,OACA,OAKI,CAAC,GACC;CACN,MAAM,EAAE,yBAAyB,OAAO,wBAAwB,MAAM,aAAa,MAAM,cAAc,CAAC,MAAM;CAC9G,KAAK,MAAM,SAAS,MAAM,QAGxB,IAAI,MAAM,SAAS,WAAW,wBAAwB,MAAM,OAAO;EAAE,GAAG;EAAM,YAAY;CAAM,CAAC;CAEnG,IAAI,uBAAuB,uBAAuB,OAAO,WAAW;CAOpE,MAAM,wBAAwB,mBAAmB,KAAK,CAAC,CACpD,QAAQ,SAAS,6BAA6B,MAAM,WAAW,KAAK,OAAO,CAAC,CAAC,CAC7E,KAAK,SAAS,KAAK,MAAM,KAAK;CACjC,IAAI,yBAAyB,CAAC,0BAA0B,sBAAsB,SAAS,GACrF,MAAM,IAAI,MACR,wEAAwE,sBAAsB,KAC5F,IACF,EAAE,mEACJ;CAGF,IAAI,MAAM,OAAO,MAAM,MAAM,EAAE,SAAS,OAAO,GAE7C,mBAAmB,KAAK;CAE1B,IAAI,YAEF,iBAAiB,OAAO,WAAW;AAEvC;;;;;;AAOA,SAAS,uBAAuB,OAAwB,cAAwB,CAAC,GAAS;CACxF,MAAM,QAAQ,mBAAmB,KAAK;CACtC,IAAI,MAAM,WAAW,2BAA2B,OAAO,MAAM,WAAW,OAAO,WAAW;CAC1F,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,wCAAwC,OAAO,KAAK,SAAS,WAAW,GAAG;EAC/E,IAAI,gCAAgC,MAAM,WAAW,KAAK,OAAO,GAAG;EAEpE,MAAM,QAAQ,MAAM,YAAY,8BAA8B,MAAM,WA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AS,OACvB,KAAK,MAAM,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC;MAClC,IAAI,KAAK,SAAS,OACvB,KAAK,MAAM,KAAK,KAAK,YAAY,kBAAkB,GAAG,GAAG;MACpD,IAAI,KAAK,SAAS,UAAU,CAEnC,OACE,YAAY,IAAI;AAEpB"}
@@ -2,18 +2,39 @@ import { ParsedExpressionFilter } from "../parsedConditions.cjs";
2
2
  import { ExpressionFilter, OrderBy } from "./EntityFilter.cjs";
3
3
  import { EntityMetadata, Field } from "../../EntityMetadata.cjs";
4
4
  //#region src/queries/find/QueryParser.d.ts
5
- interface PrimaryTable {
5
+ export interface PrimaryTable {
6
6
  join: "primary";
7
7
  alias: string;
8
8
  table: string;
9
+ /** Set when a many-to-many join table becomes the FROM table inside EXISTS. */
10
+ idJoin?: JoinTable["idJoin"];
9
11
  }
10
- interface JoinTable {
12
+ export interface JoinTable {
11
13
  join: "inner" | "outer";
12
14
  alias: string;
13
15
  table: string;
14
16
  col1: string;
15
17
  col2: string;
16
18
  distinct?: boolean;
19
+ /**
20
+ * On a many-to-many join table, identifies its otherTable join.
21
+ *
22
+ * I.e. `authors_to_tags att` stores the `tags t ON att.tag_id = t.id` join here,
23
+ * letting pruning replace `t.id` conditions with `att.tag_id` and remove `tags t`.
24
+ * `fkColumn` is the join-table column name (`tag_id`), taken from the m2m field metadata.
25
+ *
26
+ * Only set when soft-delete exclusion and inheritance do not require reading otherTable.
27
+ *
28
+ * Pruning compares these saved values with the final join; if a plugin changed the table
29
+ * or either ON column, it keeps the join instead of substituting the join-table FK.
30
+ */
31
+ idJoin?: {
32
+ alias: string;
33
+ table: string;
34
+ col1: string;
35
+ col2: string;
36
+ fkColumn: string;
37
+ };
17
38
  /**
18
39
  * Metadata used by `optimizeCollectionJoins` to rewrite collection joins into EXISTS.
19
40
  *
@@ -62,7 +83,7 @@ interface JoinTable {
62
83
  * GROUP BY a.id
63
84
  * ```
64
85
  */
65
- interface CrossJoinTable {
86
+ export interface CrossJoinTable {
66
87
  join: "cross";
67
88
  /** The new alias for the joined table. */
68
89
  alias: string;
@@ -80,7 +101,7 @@ interface CrossJoinTable {
80
101
  * )
81
102
  * ```
82
103
  */
83
- interface ParsedCteClause {
104
+ export interface ParsedCteClause {
84
105
  /** The new alias for the CTE, i.e. `_find` in the above query. */
85
106
  alias: string;
86
107
  /** The columns, i.e. `tag, arg0, arg1` in the above query. */
@@ -103,7 +124,7 @@ interface ParsedCteClause {
103
124
  /**
104
125
  * Creates `LATERAL JOIN`s, currently used by `findCount` and JSON preloading.
105
126
  */
106
- interface LateralJoinTable {
127
+ export interface LateralJoinTable {
107
128
  join: "lateral";
108
129
  alias: string;
109
130
  /** Used for join dependency tracking. */
@@ -118,26 +139,26 @@ interface LateralJoinTable {
118
139
  offset?: number;
119
140
  };
120
141
  }
121
- type ParsedTable = PrimaryTable | JoinTable | CrossJoinTable | LateralJoinTable;
122
- interface ParsedOrderBy {
142
+ export type ParsedTable = PrimaryTable | JoinTable | CrossJoinTable | LateralJoinTable;
143
+ export interface ParsedOrderBy {
123
144
  alias: string;
124
145
  column: string;
125
146
  order: OrderBy;
126
147
  }
127
- type ParsedGroupBy = {
148
+ export type ParsedGroupBy = {
128
149
  alias: string;
129
150
  column: string;
130
151
  } | {
131
152
  expression: string;
132
153
  };
133
- type ParsedSelect = string | ParsedSelectWithBindings;
154
+ export type ParsedSelect = string | ParsedSelectWithBindings;
134
155
  type ParsedSelectWithBindings = {
135
156
  sql: string;
136
157
  bindings: any[];
137
158
  aliases: string[];
138
159
  };
139
160
  /** The result of parsing an `em.find` filter. */
140
- interface ParsedFindQuery {
161
+ export interface ParsedFindQuery {
141
162
  selects: ParsedSelect[];
142
163
  /** The primary table plus any joins. */
143
164
  tables: ParsedTable[];
@@ -156,7 +177,7 @@ interface ParsedFindQuery {
156
177
  * The main execution flow is:
157
178
  * parseFindQuery -> beforeFind plugins -> optimizeCollectionJoins -> pruneUnusedJoins -> execute SQL.
158
179
  */
159
- declare function parseFindQuery(meta: EntityMetadata, filter: any, opts?: {
180
+ export declare function parseFindQuery(meta: EntityMetadata, filter: any, opts?: {
160
181
  conditions?: ExpressionFilter;
161
182
  orderBy?: any;
162
183
  pruneJoins?: boolean;
@@ -176,17 +197,17 @@ declare function parseFindQuery(meta: EntityMetadata, filter: any, opts?: {
176
197
  * to do an `OR` across two different children (which queries both children being
177
198
  * OUTER JOINs, and detecting that case seemed complicated).
178
199
  */
179
- declare function maybeAddIdNotNulls(query: ParsedFindQuery): void;
200
+ export declare function maybeAddIdNotNulls(query: ParsedFindQuery): void;
180
201
  /** Returns the `a` from `"a".*`. */
181
- declare function parseAlias(alias: string): string;
202
+ export declare function parseAlias(alias: string): string;
182
203
  /** Finds a filter field by fieldName or generated fieldIdName. */
183
- declare function findFilterField(meta: EntityMetadata, key: string): (Field & {
204
+ export declare function findFilterField(meta: EntityMetadata, key: string): (Field & {
184
205
  aliasSuffix: string;
185
206
  }) | undefined;
186
207
  /** Adds any user-configured default order, plus an "always order by id" for determinism. */
187
- declare function maybeAddOrderBy(query: ParsedFindQuery, meta: EntityMetadata, alias: string): void;
188
- declare function addTablePerClassJoinsAndClassTag(query: ParsedFindQuery, meta: EntityMetadata, alias: string, isPrimary: boolean): void;
189
- declare function getTables(query: ParsedFindQuery): [PrimaryTable, JoinTable[], LateralJoinTable[], CrossJoinTable[]];
208
+ export declare function maybeAddOrderBy(query: ParsedFindQuery, meta: EntityMetadata, alias: string): void;
209
+ export declare function addTablePerClassJoinsAndClassTag(query: ParsedFindQuery, meta: EntityMetadata, alias: string, isPrimary: boolean): void;
210
+ export declare function getTables(query: ParsedFindQuery): [PrimaryTable, JoinTable[], LateralJoinTable[], CrossJoinTable[]];
190
211
  //#endregion
191
- export { CrossJoinTable, JoinTable, LateralJoinTable, ParsedCteClause, ParsedFindQuery, ParsedGroupBy, ParsedOrderBy, ParsedSelect, ParsedTable, PrimaryTable, addTablePerClassJoinsAndClassTag, findFilterField, getTables, maybeAddIdNotNulls, maybeAddOrderBy, parseAlias, parseFindQuery };
212
+ export {};
192
213
  //# sourceMappingURL=QueryParser.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"QueryParser.d.cts","names":[],"sources":["../../../src/queries/find/QueryParser.ts"],"mappings":";;;;UA6BiB;EACf;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;;;;;;;;;;;;;;;;;;;;;EAsBA;;IAEE;;IAEA;;IAEA;;;;;;;;;;;;;;;;;;;;;UAsBa;EACf;;EAEA;;EAEA;;;;;;;;;;;;;UAce;;EAEf;;EAEA;IAAY;IAAoB;;;EAEhC;IAAS;IAAa;IAAa;;IAA+B;IAAa,OAAO;;;EAEtF;;;;;UAMe;EACf;EACA;;EAEA;;EAEA;;EAEA,OAAO;;EAEP;IAAa;IAAgB;;;KAGnB,cAAc,eAAe,YAAY,iBAAiB;UAErD;EACf;EACA;EACA,OAAO;;KAGG;EAAkB;EAAe;;EAAqB;;KAEtD,wBAAwB;KAC/B;EAA6B;EAAa;EAAiB;;;UAG/C;EACf,SAAS;;EAET,QAAQ;;EAER,YAAY;;EAEZ,WAAW;;EAEX,UAAU;;EAEV,OAAO;;;;;;;;iBASO,eACd,MAAM,gBACN,aACA;EACE,aAAa;EACb;EACA;EACA;EACA;EACA;EACA;IAED;;;;;;;;;;;;iBAqhBa,mBAAmB,OAAO;;iBAgC1B,WAAW;;iBAKX,gBAAgB,MAAM,gBAAgB,eAAe;EAAU;;;iBAU/D,gBAAgB,OAAO,iBAAiB,MAAM,gBAAgB;iBAiB9D,iCACd,OAAO,iBACP,MAAM,gBACN,eACA;iBA8Fc,UAAU,OAAO,mBAAmB,cAAc,aAAa,oBAAoB"}
1
+ {"version":3,"file":"QueryParser.d.cts","names":[],"sources":["../../../src/queries/find/QueryParser.ts"],"mappings":";;;;iBA6BiB;EACf;EACA;EACA;;EAEA,SAAS;;iBAGM;EACf;EACA;EACA;EACA;EACA;EACA;;;;;;;;;;;;;EAaA;IAAW;IAAe;IAAe;IAAc;IAAc;;;;;;;;;;;;;;;;;;;;;;;EAsBrE;;IAEE;;IAEA;;IAEA;;;;;;;;;;;;;;;;;;;;;iBAsBa;EACf;;EAEA;;EAEA;;;;;;;;;;;;;iBAce;;EAEf;;EAEA;IAAY;IAAoB;;;EAEhC;IAAS;IAAa;IAAa;;IAA+B;IAAa,OAAO;;;EAEtF;;;;;iBAMe;EACf;EACA;;EAEA;;EAEA;;EAEA,OAAO;;EAEP;IAAa;IAAgB;;;YAGnB,cAAc,eAAe,YAAY,iBAAiB;iBAErD;EACf;EACA;EACA,OAAO;;YAGG;EAAkB;EAAe;;EAAqB;;YAEtD,wBAAwB;KAC/B;EAA6B;EAAa;EAAiB;;;iBAG/C;EACf,SAAS;;EAET,QAAQ;;EAER,YAAY;;EAEZ,WAAW;;EAEX,UAAU;;EAEV,OAAO;;;;;;;;wBASO,eACd,MAAM,gBACN,aACA;EACE,aAAa;EACb;EACA;EACA;EACA;EACA;EACA;IAED;;;;;;;;;;;;wBAoiBa,mBAAmB,OAAO;;wBAgC1B,WAAW;;wBAKX,gBAAgB,MAAM,gBAAgB,eAAe;EAAU;;;wBAU/D,gBAAgB,OAAO,iBAAiB,MAAM,gBAAgB;wBAiB9D,iCACd,OAAO,iBACP,MAAM,gBACN,eACA;wBA8Fc,UAAU,OAAO,mBAAmB,cAAc,aAAa,oBAAoB"}
@@ -2,18 +2,39 @@ import { ParsedExpressionFilter } from "../parsedConditions.mjs";
2
2
  import { ExpressionFilter, OrderBy } from "./EntityFilter.mjs";
3
3
  import { EntityMetadata, Field } from "../../EntityMetadata.mjs";
4
4
  //#region src/queries/find/QueryParser.d.ts
5
- interface PrimaryTable {
5
+ export interface PrimaryTable {
6
6
  join: "primary";
7
7
  alias: string;
8
8
  table: string;
9
+ /** Set when a many-to-many join table becomes the FROM table inside EXISTS. */
10
+ idJoin?: JoinTable["idJoin"];
9
11
  }
10
- interface JoinTable {
12
+ export interface JoinTable {
11
13
  join: "inner" | "outer";
12
14
  alias: string;
13
15
  table: string;
14
16
  col1: string;
15
17
  col2: string;
16
18
  distinct?: boolean;
19
+ /**
20
+ * On a many-to-many join table, identifies its otherTable join.
21
+ *
22
+ * I.e. `authors_to_tags att` stores the `tags t ON att.tag_id = t.id` join here,
23
+ * letting pruning replace `t.id` conditions with `att.tag_id` and remove `tags t`.
24
+ * `fkColumn` is the join-table column name (`tag_id`), taken from the m2m field metadata.
25
+ *
26
+ * Only set when soft-delete exclusion and inheritance do not require reading otherTable.
27
+ *
28
+ * Pruning compares these saved values with the final join; if a plugin changed the table
29
+ * or either ON column, it keeps the join instead of substituting the join-table FK.
30
+ */
31
+ idJoin?: {
32
+ alias: string;
33
+ table: string;
34
+ col1: string;
35
+ col2: string;
36
+ fkColumn: string;
37
+ };
17
38
  /**
18
39
  * Metadata used by `optimizeCollectionJoins` to rewrite collection joins into EXISTS.
19
40
  *
@@ -62,7 +83,7 @@ interface JoinTable {
62
83
  * GROUP BY a.id
63
84
  * ```
64
85
  */
65
- interface CrossJoinTable {
86
+ export interface CrossJoinTable {
66
87
  join: "cross";
67
88
  /** The new alias for the joined table. */
68
89
  alias: string;
@@ -80,7 +101,7 @@ interface CrossJoinTable {
80
101
  * )
81
102
  * ```
82
103
  */
83
- interface ParsedCteClause {
104
+ export interface ParsedCteClause {
84
105
  /** The new alias for the CTE, i.e. `_find` in the above query. */
85
106
  alias: string;
86
107
  /** The columns, i.e. `tag, arg0, arg1` in the above query. */
@@ -103,7 +124,7 @@ interface ParsedCteClause {
103
124
  /**
104
125
  * Creates `LATERAL JOIN`s, currently used by `findCount` and JSON preloading.
105
126
  */
106
- interface LateralJoinTable {
127
+ export interface LateralJoinTable {
107
128
  join: "lateral";
108
129
  alias: string;
109
130
  /** Used for join dependency tracking. */
@@ -118,26 +139,26 @@ interface LateralJoinTable {
118
139
  offset?: number;
119
140
  };
120
141
  }
121
- type ParsedTable = PrimaryTable | JoinTable | CrossJoinTable | LateralJoinTable;
122
- interface ParsedOrderBy {
142
+ export type ParsedTable = PrimaryTable | JoinTable | CrossJoinTable | LateralJoinTable;
143
+ export interface ParsedOrderBy {
123
144
  alias: string;
124
145
  column: string;
125
146
  order: OrderBy;
126
147
  }
127
- type ParsedGroupBy = {
148
+ export type ParsedGroupBy = {
128
149
  alias: string;
129
150
  column: string;
130
151
  } | {
131
152
  expression: string;
132
153
  };
133
- type ParsedSelect = string | ParsedSelectWithBindings;
154
+ export type ParsedSelect = string | ParsedSelectWithBindings;
134
155
  type ParsedSelectWithBindings = {
135
156
  sql: string;
136
157
  bindings: any[];
137
158
  aliases: string[];
138
159
  };
139
160
  /** The result of parsing an `em.find` filter. */
140
- interface ParsedFindQuery {
161
+ export interface ParsedFindQuery {
141
162
  selects: ParsedSelect[];
142
163
  /** The primary table plus any joins. */
143
164
  tables: ParsedTable[];
@@ -156,7 +177,7 @@ interface ParsedFindQuery {
156
177
  * The main execution flow is:
157
178
  * parseFindQuery -> beforeFind plugins -> optimizeCollectionJoins -> pruneUnusedJoins -> execute SQL.
158
179
  */
159
- declare function parseFindQuery(meta: EntityMetadata, filter: any, opts?: {
180
+ export declare function parseFindQuery(meta: EntityMetadata, filter: any, opts?: {
160
181
  conditions?: ExpressionFilter;
161
182
  orderBy?: any;
162
183
  pruneJoins?: boolean;
@@ -176,17 +197,17 @@ declare function parseFindQuery(meta: EntityMetadata, filter: any, opts?: {
176
197
  * to do an `OR` across two different children (which queries both children being
177
198
  * OUTER JOINs, and detecting that case seemed complicated).
178
199
  */
179
- declare function maybeAddIdNotNulls(query: ParsedFindQuery): void;
200
+ export declare function maybeAddIdNotNulls(query: ParsedFindQuery): void;
180
201
  /** Returns the `a` from `"a".*`. */
181
- declare function parseAlias(alias: string): string;
202
+ export declare function parseAlias(alias: string): string;
182
203
  /** Finds a filter field by fieldName or generated fieldIdName. */
183
- declare function findFilterField(meta: EntityMetadata, key: string): (Field & {
204
+ export declare function findFilterField(meta: EntityMetadata, key: string): (Field & {
184
205
  aliasSuffix: string;
185
206
  }) | undefined;
186
207
  /** Adds any user-configured default order, plus an "always order by id" for determinism. */
187
- declare function maybeAddOrderBy(query: ParsedFindQuery, meta: EntityMetadata, alias: string): void;
188
- declare function addTablePerClassJoinsAndClassTag(query: ParsedFindQuery, meta: EntityMetadata, alias: string, isPrimary: boolean): void;
189
- declare function getTables(query: ParsedFindQuery): [PrimaryTable, JoinTable[], LateralJoinTable[], CrossJoinTable[]];
208
+ export declare function maybeAddOrderBy(query: ParsedFindQuery, meta: EntityMetadata, alias: string): void;
209
+ export declare function addTablePerClassJoinsAndClassTag(query: ParsedFindQuery, meta: EntityMetadata, alias: string, isPrimary: boolean): void;
210
+ export declare function getTables(query: ParsedFindQuery): [PrimaryTable, JoinTable[], LateralJoinTable[], CrossJoinTable[]];
190
211
  //#endregion
191
- export { CrossJoinTable, JoinTable, LateralJoinTable, ParsedCteClause, ParsedFindQuery, ParsedGroupBy, ParsedOrderBy, ParsedSelect, ParsedTable, PrimaryTable, addTablePerClassJoinsAndClassTag, findFilterField, getTables, maybeAddIdNotNulls, maybeAddOrderBy, parseAlias, parseFindQuery };
212
+ export {};
192
213
  //# sourceMappingURL=QueryParser.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"QueryParser.d.mts","names":[],"sources":["../../../src/queries/find/QueryParser.ts"],"mappings":";;;;UA6BiB;EACf;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;;;;;;;;;;;;;;;;;;;;;EAsBA;;IAEE;;IAEA;;IAEA;;;;;;;;;;;;;;;;;;;;;UAsBa;EACf;;EAEA;;EAEA;;;;;;;;;;;;;UAce;;EAEf;;EAEA;IAAY;IAAoB;;;EAEhC;IAAS;IAAa;IAAa;;IAA+B;IAAa,OAAO;;;EAEtF;;;;;UAMe;EACf;EACA;;EAEA;;EAEA;;EAEA,OAAO;;EAEP;IAAa;IAAgB;;;KAGnB,cAAc,eAAe,YAAY,iBAAiB;UAErD;EACf;EACA;EACA,OAAO;;KAGG;EAAkB;EAAe;;EAAqB;;KAEtD,wBAAwB;KAC/B;EAA6B;EAAa;EAAiB;;;UAG/C;EACf,SAAS;;EAET,QAAQ;;EAER,YAAY;;EAEZ,WAAW;;EAEX,UAAU;;EAEV,OAAO;;;;;;;;iBASO,eACd,MAAM,gBACN,aACA;EACE,aAAa;EACb;EACA;EACA;EACA;EACA;EACA;IAED;;;;;;;;;;;;iBAqhBa,mBAAmB,OAAO;;iBAgC1B,WAAW;;iBAKX,gBAAgB,MAAM,gBAAgB,eAAe;EAAU;;;iBAU/D,gBAAgB,OAAO,iBAAiB,MAAM,gBAAgB;iBAiB9D,iCACd,OAAO,iBACP,MAAM,gBACN,eACA;iBA8Fc,UAAU,OAAO,mBAAmB,cAAc,aAAa,oBAAoB"}
1
+ {"version":3,"file":"QueryParser.d.mts","names":[],"sources":["../../../src/queries/find/QueryParser.ts"],"mappings":";;;;iBA6BiB;EACf;EACA;EACA;;EAEA,SAAS;;iBAGM;EACf;EACA;EACA;EACA;EACA;EACA;;;;;;;;;;;;;EAaA;IAAW;IAAe;IAAe;IAAc;IAAc;;;;;;;;;;;;;;;;;;;;;;;EAsBrE;;IAEE;;IAEA;;IAEA;;;;;;;;;;;;;;;;;;;;;iBAsBa;EACf;;EAEA;;EAEA;;;;;;;;;;;;;iBAce;;EAEf;;EAEA;IAAY;IAAoB;;;EAEhC;IAAS;IAAa;IAAa;;IAA+B;IAAa,OAAO;;;EAEtF;;;;;iBAMe;EACf;EACA;;EAEA;;EAEA;;EAEA,OAAO;;EAEP;IAAa;IAAgB;;;YAGnB,cAAc,eAAe,YAAY,iBAAiB;iBAErD;EACf;EACA;EACA,OAAO;;YAGG;EAAkB;EAAe;;EAAqB;;YAEtD,wBAAwB;KAC/B;EAA6B;EAAa;EAAiB;;;iBAG/C;EACf,SAAS;;EAET,QAAQ;;EAER,YAAY;;EAEZ,WAAW;;EAEX,UAAU;;EAEV,OAAO;;;;;;;;wBASO,eACd,MAAM,gBACN,aACA;EACE,aAAa;EACb;EACA;EACA;EACA;EACA;EACA;IAED;;;;;;;;;;;;wBAoiBa,mBAAmB,OAAO;;wBAgC1B,WAAW;;wBAKX,gBAAgB,MAAM,gBAAgB,eAAe;EAAU;;;wBAU/D,gBAAgB,OAAO,iBAAiB,MAAM,gBAAgB;wBAiB9D,iCACd,OAAO,iBACP,MAAM,gBACN,eACA;wBA8Fc,UAAU,OAAO,mBAAmB,cAAc,aAAa,oBAAoB"}
@@ -262,7 +262,7 @@ function parseFindQuery(meta, filter, opts = {}) {
262
262
  const f = parseEntityFilter(field.otherMetadata(), sub);
263
263
  if (!f && !isAlias(sub)) return;
264
264
  const ja = getAlias(field.joinTableName);
265
- tables.push({
265
+ const joinTable = {
266
266
  join: "outer",
267
267
  alias: ja,
268
268
  table: field.joinTableName,
@@ -273,16 +273,27 @@ function parseFindQuery(meta, filter, opts = {}) {
273
273
  rootAlias: ja,
274
274
  kind: "m2m"
275
275
  }
276
- });
276
+ };
277
+ tables.push(joinTable);
277
278
  if (isAlias(sub) || f?.kind === "join" || filterSoftDeletes(field.otherMetadata(), softDeletes)) {
278
279
  const a = getAlias(field.otherMetadata().tableName);
279
280
  addTable(field.otherMetadata(), a, "outer", kqDot(ja, field.columnNames[1]), kqDot(a, "id"), sub, void 0, targetCb, true);
280
281
  const table = tables.find((t) => t.alias === a);
281
- if (table && (table.join === "inner" || table.join === "outer")) table.collection = {
282
- parentAlias: ja,
283
- rootAlias: ja,
284
- kind: "m2m"
285
- };
282
+ if (table && (table.join === "inner" || table.join === "outer")) {
283
+ table.collection = {
284
+ parentAlias: ja,
285
+ rootAlias: ja,
286
+ kind: "m2m"
287
+ };
288
+ const otherMeta = field.otherMetadata();
289
+ if (!otherMeta.inheritanceType && !filterSoftDeletes(otherMeta, softDeletes)) joinTable.idJoin = {
290
+ alias: table.alias,
291
+ table: table.table,
292
+ col1: table.col1,
293
+ col2: table.col2,
294
+ fkColumn: field.columnNames[1]
295
+ };
296
+ }
286
297
  } else if (f) {
287
298
  const otherMeta = field.otherMetadata();
288
299
  const column = {