joist-core 2.4.0-next.4 → 2.4.0-next.41

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 (791) 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 +64 -20
  14. package/build/EntityManager.cjs.map +1 -1
  15. package/build/EntityManager.d.cts +86 -53
  16. package/build/EntityManager.d.cts.map +1 -1
  17. package/build/EntityManager.d.mts +86 -53
  18. package/build/EntityManager.d.mts.map +1 -1
  19. package/build/EntityManager.js +64 -22
  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 +39 -36
  24. package/build/EntityMetadata.d.cts.map +1 -1
  25. package/build/EntityMetadata.d.mts +39 -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 +23 -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 +23 -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.d.cts +2 -3
  76. package/build/batchloaders/oneToManyBatchLoader.d.cts.map +1 -1
  77. package/build/batchloaders/oneToManyBatchLoader.d.mts +2 -3
  78. package/build/batchloaders/oneToManyBatchLoader.d.mts.map +1 -1
  79. package/build/batchloaders/oneToOneBatchLoader.d.cts +2 -3
  80. package/build/batchloaders/oneToOneBatchLoader.d.cts.map +1 -1
  81. package/build/batchloaders/oneToOneBatchLoader.d.mts +2 -3
  82. package/build/batchloaders/oneToOneBatchLoader.d.mts.map +1 -1
  83. package/build/batchloaders/populateBatchLoader.cjs +2 -2
  84. package/build/batchloaders/populateBatchLoader.d.cts +2 -3
  85. package/build/batchloaders/populateBatchLoader.d.cts.map +1 -1
  86. package/build/batchloaders/populateBatchLoader.d.mts +2 -3
  87. package/build/batchloaders/populateBatchLoader.d.mts.map +1 -1
  88. package/build/batchloaders/populateBatchLoader.js +2 -2
  89. package/build/batchloaders/recursiveChildrenBatchLoader.cjs +1 -1
  90. package/build/batchloaders/recursiveChildrenBatchLoader.d.cts +2 -3
  91. package/build/batchloaders/recursiveChildrenBatchLoader.d.cts.map +1 -1
  92. package/build/batchloaders/recursiveChildrenBatchLoader.d.mts +2 -3
  93. package/build/batchloaders/recursiveChildrenBatchLoader.d.mts.map +1 -1
  94. package/build/batchloaders/recursiveChildrenBatchLoader.js +1 -1
  95. package/build/batchloaders/recursiveM2mBatchLoader.cjs +1 -1
  96. package/build/batchloaders/recursiveM2mBatchLoader.d.cts +2 -3
  97. package/build/batchloaders/recursiveM2mBatchLoader.d.cts.map +1 -1
  98. package/build/batchloaders/recursiveM2mBatchLoader.d.mts +2 -3
  99. package/build/batchloaders/recursiveM2mBatchLoader.d.mts.map +1 -1
  100. package/build/batchloaders/recursiveM2mBatchLoader.js +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.map +1 -1
  108. package/build/changes.d.cts +9 -10
  109. package/build/changes.d.cts.map +1 -1
  110. package/build/changes.d.mts +9 -10
  111. package/build/changes.d.mts.map +1 -1
  112. package/build/changes.js.map +1 -1
  113. package/build/config.cjs +75 -1
  114. package/build/config.cjs.map +1 -1
  115. package/build/config.d.cts +99 -17
  116. package/build/config.d.cts.map +1 -1
  117. package/build/config.d.mts +99 -17
  118. package/build/config.d.mts.map +1 -1
  119. package/build/config.js +75 -1
  120. package/build/config.js.map +1 -1
  121. package/build/configure.cjs +6 -2
  122. package/build/configure.cjs.map +1 -1
  123. package/build/configure.d.cts +8 -9
  124. package/build/configure.d.cts.map +1 -1
  125. package/build/configure.d.mts +8 -9
  126. package/build/configure.d.mts.map +1 -1
  127. package/build/configure.js +6 -2
  128. package/build/configure.js.map +1 -1
  129. package/build/dataloaders/fastWhereFilterHash.d.cts +1 -2
  130. package/build/dataloaders/fastWhereFilterHash.d.cts.map +1 -1
  131. package/build/dataloaders/fastWhereFilterHash.d.mts +1 -2
  132. package/build/dataloaders/fastWhereFilterHash.d.mts.map +1 -1
  133. package/build/dataloaders/findByUniqueDataLoader.d.cts +2 -3
  134. package/build/dataloaders/findByUniqueDataLoader.d.cts.map +1 -1
  135. package/build/dataloaders/findByUniqueDataLoader.d.mts +2 -3
  136. package/build/dataloaders/findByUniqueDataLoader.d.mts.map +1 -1
  137. package/build/dataloaders/findCountDataLoader.d.cts +4 -5
  138. package/build/dataloaders/findCountDataLoader.d.cts.map +1 -1
  139. package/build/dataloaders/findCountDataLoader.d.mts +4 -5
  140. package/build/dataloaders/findCountDataLoader.d.mts.map +1 -1
  141. package/build/dataloaders/findDataLoader.cjs +1 -1
  142. package/build/dataloaders/findDataLoader.d.cts +11 -12
  143. package/build/dataloaders/findDataLoader.d.cts.map +1 -1
  144. package/build/dataloaders/findDataLoader.d.mts +11 -12
  145. package/build/dataloaders/findDataLoader.d.mts.map +1 -1
  146. package/build/dataloaders/findDataLoader.js +1 -1
  147. package/build/dataloaders/findIdsDataLoader.d.cts +2 -3
  148. package/build/dataloaders/findIdsDataLoader.d.cts.map +1 -1
  149. package/build/dataloaders/findIdsDataLoader.d.mts +2 -3
  150. package/build/dataloaders/findIdsDataLoader.d.mts.map +1 -1
  151. package/build/dataloaders/findOrCreateDataLoader.cjs +6 -2
  152. package/build/dataloaders/findOrCreateDataLoader.cjs.map +1 -1
  153. package/build/dataloaders/findOrCreateDataLoader.d.cts +3 -3
  154. package/build/dataloaders/findOrCreateDataLoader.d.cts.map +1 -1
  155. package/build/dataloaders/findOrCreateDataLoader.d.mts +3 -3
  156. package/build/dataloaders/findOrCreateDataLoader.d.mts.map +1 -1
  157. package/build/dataloaders/findOrCreateDataLoader.js +7 -3
  158. package/build/dataloaders/findOrCreateDataLoader.js.map +1 -1
  159. package/build/dataloaders/findPaginatedDataLoader.cjs +1 -1
  160. package/build/dataloaders/findPaginatedDataLoader.d.cts +1 -2
  161. package/build/dataloaders/findPaginatedDataLoader.d.cts.map +1 -1
  162. package/build/dataloaders/findPaginatedDataLoader.d.mts +1 -2
  163. package/build/dataloaders/findPaginatedDataLoader.d.mts.map +1 -1
  164. package/build/dataloaders/findPaginatedDataLoader.js +1 -1
  165. package/build/dataloaders/lensDataLoader.d.cts +2 -3
  166. package/build/dataloaders/lensDataLoader.d.cts.map +1 -1
  167. package/build/dataloaders/lensDataLoader.d.mts +2 -3
  168. package/build/dataloaders/lensDataLoader.d.mts.map +1 -1
  169. package/build/dataloaders/manyToManyFindDataLoader.d.cts +2 -3
  170. package/build/dataloaders/manyToManyFindDataLoader.d.cts.map +1 -1
  171. package/build/dataloaders/manyToManyFindDataLoader.d.mts +2 -3
  172. package/build/dataloaders/manyToManyFindDataLoader.d.mts.map +1 -1
  173. package/build/dataloaders/oneToManyFindDataLoader.d.cts +2 -3
  174. package/build/dataloaders/oneToManyFindDataLoader.d.cts.map +1 -1
  175. package/build/dataloaders/oneToManyFindDataLoader.d.mts +2 -3
  176. package/build/dataloaders/oneToManyFindDataLoader.d.mts.map +1 -1
  177. package/build/defaults.cjs +2 -2
  178. package/build/defaults.cjs.map +1 -1
  179. package/build/defaults.d.cts +7 -7
  180. package/build/defaults.d.cts.map +1 -1
  181. package/build/defaults.d.mts +7 -7
  182. package/build/defaults.d.mts.map +1 -1
  183. package/build/defaults.js +2 -2
  184. package/build/defaults.js.map +1 -1
  185. package/build/drivers/Driver.d.cts +2 -3
  186. package/build/drivers/Driver.d.cts.map +1 -1
  187. package/build/drivers/Driver.d.mts +2 -3
  188. package/build/drivers/Driver.d.mts.map +1 -1
  189. package/build/drivers/EntityWriter.d.cts +7 -7
  190. package/build/drivers/EntityWriter.d.cts.map +1 -1
  191. package/build/drivers/EntityWriter.d.mts +7 -7
  192. package/build/drivers/EntityWriter.d.mts.map +1 -1
  193. package/build/drivers/IdAssigner.cjs.map +1 -1
  194. package/build/drivers/IdAssigner.d.cts +5 -5
  195. package/build/drivers/IdAssigner.d.cts.map +1 -1
  196. package/build/drivers/IdAssigner.d.mts +5 -5
  197. package/build/drivers/IdAssigner.d.mts.map +1 -1
  198. package/build/drivers/IdAssigner.js.map +1 -1
  199. package/build/drivers/driverApi.d.cts +2 -3
  200. package/build/drivers/driverApi.d.cts.map +1 -1
  201. package/build/drivers/driverApi.d.mts +2 -3
  202. package/build/drivers/driverApi.d.mts.map +1 -1
  203. package/build/fields.cjs +1 -0
  204. package/build/fields.cjs.map +1 -1
  205. package/build/fields.d.cts +6 -7
  206. package/build/fields.d.cts.map +1 -1
  207. package/build/fields.d.mts +6 -7
  208. package/build/fields.d.mts.map +1 -1
  209. package/build/fields.js +1 -0
  210. package/build/fields.js.map +1 -1
  211. package/build/flush/FlushLock.cjs.map +1 -1
  212. package/build/flush/FlushLock.d.cts +1 -2
  213. package/build/flush/FlushLock.d.cts.map +1 -1
  214. package/build/flush/FlushLock.d.mts +1 -2
  215. package/build/flush/FlushLock.d.mts.map +1 -1
  216. package/build/flush/FlushLock.js.map +1 -1
  217. package/build/flush/JoinRows.cjs.map +1 -1
  218. package/build/flush/JoinRows.d.cts +5 -6
  219. package/build/flush/JoinRows.d.cts.map +1 -1
  220. package/build/flush/JoinRows.d.mts +5 -6
  221. package/build/flush/JoinRows.d.mts.map +1 -1
  222. package/build/flush/JoinRows.js.map +1 -1
  223. package/build/flush/PendingChanges.d.cts +5 -6
  224. package/build/flush/PendingChanges.d.cts.map +1 -1
  225. package/build/flush/PendingChanges.d.mts +5 -6
  226. package/build/flush/PendingChanges.d.mts.map +1 -1
  227. package/build/flush/Todo.d.cts +5 -6
  228. package/build/flush/Todo.d.cts.map +1 -1
  229. package/build/flush/Todo.d.mts +5 -6
  230. package/build/flush/Todo.d.mts.map +1 -1
  231. package/build/getProperties.d.cts +3 -4
  232. package/build/getProperties.d.cts.map +1 -1
  233. package/build/getProperties.d.mts +3 -4
  234. package/build/getProperties.d.mts.map +1 -1
  235. package/build/index.cjs +14 -8
  236. package/build/index.cjs.map +1 -1
  237. package/build/index.d.cts +20 -19
  238. package/build/index.d.cts.map +1 -1
  239. package/build/index.d.mts +20 -19
  240. package/build/index.d.mts.map +1 -1
  241. package/build/index.js +14 -11
  242. package/build/index.js.map +1 -1
  243. package/build/json.cjs +3 -3
  244. package/build/json.d.cts +11 -11
  245. package/build/json.d.cts.map +1 -1
  246. package/build/json.d.mts +11 -11
  247. package/build/json.d.mts.map +1 -1
  248. package/build/json.js +3 -3
  249. package/build/keys.d.cts +27 -27
  250. package/build/keys.d.cts.map +1 -1
  251. package/build/keys.d.mts +27 -27
  252. package/build/keys.d.mts.map +1 -1
  253. package/build/loading/HintTree.d.cts +3 -4
  254. package/build/loading/HintTree.d.cts.map +1 -1
  255. package/build/loading/HintTree.d.mts +3 -4
  256. package/build/loading/HintTree.d.mts.map +1 -1
  257. package/build/loading/IsLoadedCache.cjs.map +1 -1
  258. package/build/loading/IsLoadedCache.d.cts +2 -3
  259. package/build/loading/IsLoadedCache.d.cts.map +1 -1
  260. package/build/loading/IsLoadedCache.d.mts +2 -3
  261. package/build/loading/IsLoadedCache.d.mts.map +1 -1
  262. package/build/loading/IsLoadedCache.js.map +1 -1
  263. package/build/loading/loadHints.cjs +1 -1
  264. package/build/loading/loadHints.d.cts +17 -17
  265. package/build/loading/loadHints.d.cts.map +1 -1
  266. package/build/loading/loadHints.d.mts +17 -17
  267. package/build/loading/loadHints.d.mts.map +1 -1
  268. package/build/loading/loadHints.js +1 -1
  269. package/build/loading/loadLens.d.cts +13 -13
  270. package/build/loading/loadLens.d.cts.map +1 -1
  271. package/build/loading/loadLens.d.mts +13 -13
  272. package/build/loading/loadLens.d.mts.map +1 -1
  273. package/build/loading/withLoaded.cjs +2 -2
  274. package/build/loading/withLoaded.d.cts +5 -6
  275. package/build/loading/withLoaded.d.cts.map +1 -1
  276. package/build/loading/withLoaded.d.mts +5 -6
  277. package/build/loading/withLoaded.d.mts.map +1 -1
  278. package/build/loading/withLoaded.js +2 -2
  279. package/build/logging/FactoryLogger.d.cts +3 -4
  280. package/build/logging/FactoryLogger.d.cts.map +1 -1
  281. package/build/logging/FactoryLogger.d.mts +3 -4
  282. package/build/logging/FactoryLogger.d.mts.map +1 -1
  283. package/build/logging/FieldLogger.cjs.map +1 -1
  284. package/build/logging/FieldLogger.d.cts +4 -5
  285. package/build/logging/FieldLogger.d.cts.map +1 -1
  286. package/build/logging/FieldLogger.d.mts +4 -5
  287. package/build/logging/FieldLogger.d.mts.map +1 -1
  288. package/build/logging/FieldLogger.js.map +1 -1
  289. package/build/logging/ReactionLogger.d.cts +7 -7
  290. package/build/logging/ReactionLogger.d.cts.map +1 -1
  291. package/build/logging/ReactionLogger.d.mts +7 -7
  292. package/build/logging/ReactionLogger.d.mts.map +1 -1
  293. package/build/newEntity.cjs.map +1 -1
  294. package/build/newEntity.d.cts +4 -5
  295. package/build/newEntity.d.cts.map +1 -1
  296. package/build/newEntity.d.mts +4 -5
  297. package/build/newEntity.d.mts.map +1 -1
  298. package/build/newEntity.js.map +1 -1
  299. package/build/newTestInstance.cjs +1 -0
  300. package/build/newTestInstance.cjs.map +1 -1
  301. package/build/newTestInstance.d.cts +21 -21
  302. package/build/newTestInstance.d.cts.map +1 -1
  303. package/build/newTestInstance.d.mts +21 -21
  304. package/build/newTestInstance.d.mts.map +1 -1
  305. package/build/newTestInstance.js +1 -0
  306. package/build/newTestInstance.js.map +1 -1
  307. package/build/normalizeHints.d.cts +7 -8
  308. package/build/normalizeHints.d.cts.map +1 -1
  309. package/build/normalizeHints.d.mts +7 -8
  310. package/build/normalizeHints.d.mts.map +1 -1
  311. package/build/nowUTC.d.cts +4 -5
  312. package/build/nowUTC.d.cts.map +1 -1
  313. package/build/nowUTC.d.mts +4 -5
  314. package/build/nowUTC.d.mts.map +1 -1
  315. package/build/plugins/ImmutableEntitiesPlugin.d.cts +1 -2
  316. package/build/plugins/ImmutableEntitiesPlugin.d.cts.map +1 -1
  317. package/build/plugins/ImmutableEntitiesPlugin.d.mts +1 -2
  318. package/build/plugins/ImmutableEntitiesPlugin.d.mts.map +1 -1
  319. package/build/plugins/PreloadPlugin.d.cts +3 -4
  320. package/build/plugins/PreloadPlugin.d.cts.map +1 -1
  321. package/build/plugins/PreloadPlugin.d.mts +3 -4
  322. package/build/plugins/PreloadPlugin.d.mts.map +1 -1
  323. package/build/preloading/JsonAggregatePreloader.d.cts +1 -2
  324. package/build/preloading/JsonAggregatePreloader.d.cts.map +1 -1
  325. package/build/preloading/JsonAggregatePreloader.d.mts +1 -2
  326. package/build/preloading/JsonAggregatePreloader.d.mts.map +1 -1
  327. package/build/preloading/canPreload.d.cts +1 -2
  328. package/build/preloading/canPreload.d.cts.map +1 -1
  329. package/build/preloading/canPreload.d.mts +1 -2
  330. package/build/preloading/canPreload.d.mts.map +1 -1
  331. package/build/preloading/partitionHint.cjs +1 -1
  332. package/build/preloading/partitionHint.d.cts +1 -2
  333. package/build/preloading/partitionHint.d.cts.map +1 -1
  334. package/build/preloading/partitionHint.d.mts +1 -2
  335. package/build/preloading/partitionHint.d.mts.map +1 -1
  336. package/build/preloading/partitionHint.js +1 -1
  337. package/build/queries/ConditionBuilder.d.cts +2 -2
  338. package/build/queries/ConditionBuilder.d.cts.map +1 -1
  339. package/build/queries/ConditionBuilder.d.mts +2 -2
  340. package/build/queries/ConditionBuilder.d.mts.map +1 -1
  341. package/build/queries/conditions.d.cts +11 -12
  342. package/build/queries/conditions.d.cts.map +1 -1
  343. package/build/queries/conditions.d.mts +11 -12
  344. package/build/queries/conditions.d.mts.map +1 -1
  345. package/build/queries/entityQueryUtils.d.cts +4 -5
  346. package/build/queries/entityQueryUtils.d.cts.map +1 -1
  347. package/build/queries/entityQueryUtils.d.mts +4 -5
  348. package/build/queries/entityQueryUtils.d.mts.map +1 -1
  349. package/build/queries/find/Aliases.d.cts +16 -16
  350. package/build/queries/find/Aliases.d.cts.map +1 -1
  351. package/build/queries/find/Aliases.d.mts +16 -16
  352. package/build/queries/find/Aliases.d.mts.map +1 -1
  353. package/build/queries/find/DeferredAlias.d.cts +5 -6
  354. package/build/queries/find/DeferredAlias.d.cts.map +1 -1
  355. package/build/queries/find/DeferredAlias.d.mts +5 -6
  356. package/build/queries/find/DeferredAlias.d.mts.map +1 -1
  357. package/build/queries/find/EntityFilter.d.cts +12 -13
  358. package/build/queries/find/EntityFilter.d.cts.map +1 -1
  359. package/build/queries/find/EntityFilter.d.mts +12 -13
  360. package/build/queries/find/EntityFilter.d.mts.map +1 -1
  361. package/build/queries/find/EntityGraphQLFilter.d.cts +8 -9
  362. package/build/queries/find/EntityGraphQLFilter.d.cts.map +1 -1
  363. package/build/queries/find/EntityGraphQLFilter.d.mts +8 -9
  364. package/build/queries/find/EntityGraphQLFilter.d.mts.map +1 -1
  365. package/build/queries/find/QueryParser.collectionJoins.d.cts +1 -2
  366. package/build/queries/find/QueryParser.collectionJoins.d.cts.map +1 -1
  367. package/build/queries/find/QueryParser.collectionJoins.d.mts +1 -2
  368. package/build/queries/find/QueryParser.collectionJoins.d.mts.map +1 -1
  369. package/build/queries/find/QueryParser.d.cts +18 -18
  370. package/build/queries/find/QueryParser.d.cts.map +1 -1
  371. package/build/queries/find/QueryParser.d.mts +18 -18
  372. package/build/queries/find/QueryParser.d.mts.map +1 -1
  373. package/build/queries/find/QueryParser.pruning.d.cts +2 -3
  374. package/build/queries/find/QueryParser.pruning.d.cts.map +1 -1
  375. package/build/queries/find/QueryParser.pruning.d.mts +2 -3
  376. package/build/queries/find/QueryParser.pruning.d.mts.map +1 -1
  377. package/build/queries/find/QueryVisitor.d.cts +4 -4
  378. package/build/queries/find/QueryVisitor.d.cts.map +1 -1
  379. package/build/queries/find/QueryVisitor.d.mts +4 -4
  380. package/build/queries/find/QueryVisitor.d.mts.map +1 -1
  381. package/build/queries/find/buildFindQuery.d.cts +3 -3
  382. package/build/queries/find/buildFindQuery.d.cts.map +1 -1
  383. package/build/queries/find/buildFindQuery.d.mts +3 -3
  384. package/build/queries/find/buildFindQuery.d.mts.map +1 -1
  385. package/build/queries/find/scopes.cjs.map +1 -1
  386. package/build/queries/find/scopes.d.cts +12 -13
  387. package/build/queries/find/scopes.d.cts.map +1 -1
  388. package/build/queries/find/scopes.d.mts +12 -13
  389. package/build/queries/find/scopes.d.mts.map +1 -1
  390. package/build/queries/find/scopes.js.map +1 -1
  391. package/build/queries/parsedConditions.d.cts +7 -8
  392. package/build/queries/parsedConditions.d.cts.map +1 -1
  393. package/build/queries/parsedConditions.d.mts +7 -8
  394. package/build/queries/parsedConditions.d.mts.map +1 -1
  395. package/build/queries/renderConditions.d.cts +3 -4
  396. package/build/queries/renderConditions.d.cts.map +1 -1
  397. package/build/queries/renderConditions.d.mts +3 -4
  398. package/build/queries/renderConditions.d.mts.map +1 -1
  399. package/build/queries/skipCondition.d.cts +1 -2
  400. package/build/queries/skipCondition.d.cts.map +1 -1
  401. package/build/queries/skipCondition.d.mts +1 -2
  402. package/build/queries/skipCondition.d.mts.map +1 -1
  403. package/build/queries/sql/AliasAssigner.cjs.map +1 -1
  404. package/build/queries/sql/AliasAssigner.d.cts +1 -2
  405. package/build/queries/sql/AliasAssigner.d.cts.map +1 -1
  406. package/build/queries/sql/AliasAssigner.d.mts +1 -2
  407. package/build/queries/sql/AliasAssigner.d.mts.map +1 -1
  408. package/build/queries/sql/AliasAssigner.js.map +1 -1
  409. package/build/queries/sql/Expr.cjs +38 -0
  410. package/build/queries/sql/Expr.cjs.map +1 -1
  411. package/build/queries/sql/Expr.d.cts +45 -27
  412. package/build/queries/sql/Expr.d.cts.map +1 -1
  413. package/build/queries/sql/Expr.d.mts +45 -27
  414. package/build/queries/sql/Expr.d.mts.map +1 -1
  415. package/build/queries/sql/Expr.js +38 -1
  416. package/build/queries/sql/Expr.js.map +1 -1
  417. package/build/queries/sql/JoinTree.d.cts +5 -5
  418. package/build/queries/sql/JoinTree.d.cts.map +1 -1
  419. package/build/queries/sql/JoinTree.d.mts +5 -5
  420. package/build/queries/sql/JoinTree.d.mts.map +1 -1
  421. package/build/queries/sql/Tables.cjs +9 -0
  422. package/build/queries/sql/Tables.cjs.map +1 -1
  423. package/build/queries/sql/Tables.d.cts +46 -39
  424. package/build/queries/sql/Tables.d.cts.map +1 -1
  425. package/build/queries/sql/Tables.d.mts +46 -39
  426. package/build/queries/sql/Tables.d.mts.map +1 -1
  427. package/build/queries/sql/Tables.js +10 -1
  428. package/build/queries/sql/Tables.js.map +1 -1
  429. package/build/queries/sql/custom.d.cts +14 -14
  430. package/build/queries/sql/custom.d.cts.map +1 -1
  431. package/build/queries/sql/custom.d.mts +14 -14
  432. package/build/queries/sql/custom.d.mts.map +1 -1
  433. package/build/queries/sql/execute.cjs +4 -9
  434. package/build/queries/sql/execute.cjs.map +1 -1
  435. package/build/queries/sql/execute.d.cts +45 -28
  436. package/build/queries/sql/execute.d.cts.map +1 -1
  437. package/build/queries/sql/execute.d.mts +45 -28
  438. package/build/queries/sql/execute.d.mts.map +1 -1
  439. package/build/queries/sql/execute.js +5 -10
  440. package/build/queries/sql/execute.js.map +1 -1
  441. package/build/queries/sql/expressions/arrayAgg.d.cts +5 -6
  442. package/build/queries/sql/expressions/arrayAgg.d.cts.map +1 -1
  443. package/build/queries/sql/expressions/arrayAgg.d.mts +5 -6
  444. package/build/queries/sql/expressions/arrayAgg.d.mts.map +1 -1
  445. package/build/queries/sql/expressions/case.d.cts +10 -10
  446. package/build/queries/sql/expressions/case.d.cts.map +1 -1
  447. package/build/queries/sql/expressions/case.d.mts +10 -10
  448. package/build/queries/sql/expressions/case.d.mts.map +1 -1
  449. package/build/queries/sql/expressions/coalesce.d.cts +5 -6
  450. package/build/queries/sql/expressions/coalesce.d.cts.map +1 -1
  451. package/build/queries/sql/expressions/coalesce.d.mts +5 -6
  452. package/build/queries/sql/expressions/coalesce.d.mts.map +1 -1
  453. package/build/queries/sql/expressions/codecs.d.cts +1 -2
  454. package/build/queries/sql/expressions/codecs.d.cts.map +1 -1
  455. package/build/queries/sql/expressions/codecs.d.mts +1 -2
  456. package/build/queries/sql/expressions/codecs.d.mts.map +1 -1
  457. package/build/queries/sql/expressions/expression.d.cts +6 -6
  458. package/build/queries/sql/expressions/expression.d.cts.map +1 -1
  459. package/build/queries/sql/expressions/expression.d.mts +6 -6
  460. package/build/queries/sql/expressions/expression.d.mts.map +1 -1
  461. package/build/queries/sql/expressions/greatest.d.cts +5 -6
  462. package/build/queries/sql/expressions/greatest.d.cts.map +1 -1
  463. package/build/queries/sql/expressions/greatest.d.mts +5 -6
  464. package/build/queries/sql/expressions/greatest.d.mts.map +1 -1
  465. package/build/queries/sql/expressions/least.d.cts +5 -6
  466. package/build/queries/sql/expressions/least.d.cts.map +1 -1
  467. package/build/queries/sql/expressions/least.d.mts +5 -6
  468. package/build/queries/sql/expressions/least.d.mts.map +1 -1
  469. package/build/queries/sql/expressions/nullIf.d.cts +5 -6
  470. package/build/queries/sql/expressions/nullIf.d.cts.map +1 -1
  471. package/build/queries/sql/expressions/nullIf.d.mts +5 -6
  472. package/build/queries/sql/expressions/nullIf.d.mts.map +1 -1
  473. package/build/queries/sql/expressions/parseExpression.d.cts +5 -6
  474. package/build/queries/sql/expressions/parseExpression.d.cts.map +1 -1
  475. package/build/queries/sql/expressions/parseExpression.d.mts +5 -6
  476. package/build/queries/sql/expressions/parseExpression.d.mts.map +1 -1
  477. package/build/queries/sql/expressions/types.d.cts +11 -11
  478. package/build/queries/sql/expressions/types.d.cts.map +1 -1
  479. package/build/queries/sql/expressions/types.d.mts +11 -11
  480. package/build/queries/sql/expressions/types.d.mts.map +1 -1
  481. package/build/queries/sql/keywords.d.cts +4 -5
  482. package/build/queries/sql/keywords.d.cts.map +1 -1
  483. package/build/queries/sql/keywords.d.mts +4 -5
  484. package/build/queries/sql/keywords.d.mts.map +1 -1
  485. package/build/queries/sql/query.cjs +59 -23
  486. package/build/queries/sql/query.cjs.map +1 -1
  487. package/build/queries/sql/query.d.cts +108 -77
  488. package/build/queries/sql/query.d.cts.map +1 -1
  489. package/build/queries/sql/query.d.mts +108 -77
  490. package/build/queries/sql/query.d.mts.map +1 -1
  491. package/build/queries/sql/query.js +58 -23
  492. package/build/queries/sql/query.js.map +1 -1
  493. package/build/queries/unnest.d.cts +2 -3
  494. package/build/queries/unnest.d.cts.map +1 -1
  495. package/build/queries/unnest.d.mts +2 -3
  496. package/build/queries/unnest.d.mts.map +1 -1
  497. package/build/queries/valueFilters.d.cts +5 -6
  498. package/build/queries/valueFilters.d.cts.map +1 -1
  499. package/build/queries/valueFilters.d.mts +5 -6
  500. package/build/queries/valueFilters.d.mts.map +1 -1
  501. package/build/reactivity/ReactionsManager.cjs +168 -2
  502. package/build/reactivity/ReactionsManager.cjs.map +1 -1
  503. package/build/reactivity/ReactionsManager.d.cts +56 -4
  504. package/build/reactivity/ReactionsManager.d.cts.map +1 -1
  505. package/build/reactivity/ReactionsManager.d.mts +56 -4
  506. package/build/reactivity/ReactionsManager.d.mts.map +1 -1
  507. package/build/reactivity/ReactionsManager.js +169 -3
  508. package/build/reactivity/ReactionsManager.js.map +1 -1
  509. package/build/reactivity/reactiveHints.cjs +3 -3
  510. package/build/reactivity/reactiveHints.cjs.map +1 -1
  511. package/build/reactivity/reactiveHints.d.cts +18 -18
  512. package/build/reactivity/reactiveHints.d.cts.map +1 -1
  513. package/build/reactivity/reactiveHints.d.mts +18 -18
  514. package/build/reactivity/reactiveHints.d.mts.map +1 -1
  515. package/build/reactivity/reactiveHints.js +3 -3
  516. package/build/reactivity/reactiveHints.js.map +1 -1
  517. package/build/relations/AbstractPropertyImpl.cjs.map +1 -1
  518. package/build/relations/AbstractPropertyImpl.d.cts +1 -2
  519. package/build/relations/AbstractPropertyImpl.d.cts.map +1 -1
  520. package/build/relations/AbstractPropertyImpl.d.mts +1 -2
  521. package/build/relations/AbstractPropertyImpl.d.mts.map +1 -1
  522. package/build/relations/AbstractPropertyImpl.js.map +1 -1
  523. package/build/relations/AbstractRelationImpl.d.cts +1 -2
  524. package/build/relations/AbstractRelationImpl.d.cts.map +1 -1
  525. package/build/relations/AbstractRelationImpl.d.mts +1 -2
  526. package/build/relations/AbstractRelationImpl.d.mts.map +1 -1
  527. package/build/relations/AsyncProperty.cjs.map +1 -1
  528. package/build/relations/AsyncProperty.d.cts +5 -6
  529. package/build/relations/AsyncProperty.d.cts.map +1 -1
  530. package/build/relations/AsyncProperty.d.mts +5 -6
  531. package/build/relations/AsyncProperty.d.mts.map +1 -1
  532. package/build/relations/AsyncProperty.js.map +1 -1
  533. package/build/relations/AsyncReactiveField.cjs +3 -3
  534. package/build/relations/AsyncReactiveField.cjs.map +1 -1
  535. package/build/relations/AsyncReactiveField.d.cts +4 -5
  536. package/build/relations/AsyncReactiveField.d.cts.map +1 -1
  537. package/build/relations/AsyncReactiveField.d.mts +4 -5
  538. package/build/relations/AsyncReactiveField.d.mts.map +1 -1
  539. package/build/relations/AsyncReactiveField.js +3 -3
  540. package/build/relations/AsyncReactiveField.js.map +1 -1
  541. package/build/relations/Collection.d.cts +4 -5
  542. package/build/relations/Collection.d.cts.map +1 -1
  543. package/build/relations/Collection.d.mts +4 -5
  544. package/build/relations/Collection.d.mts.map +1 -1
  545. package/build/relations/CustomCollection.cjs.map +1 -1
  546. package/build/relations/CustomCollection.d.cts +3 -4
  547. package/build/relations/CustomCollection.d.cts.map +1 -1
  548. package/build/relations/CustomCollection.d.mts +3 -4
  549. package/build/relations/CustomCollection.d.mts.map +1 -1
  550. package/build/relations/CustomCollection.js.map +1 -1
  551. package/build/relations/CustomReference.cjs.map +1 -1
  552. package/build/relations/CustomReference.d.cts +3 -4
  553. package/build/relations/CustomReference.d.cts.map +1 -1
  554. package/build/relations/CustomReference.d.mts +3 -4
  555. package/build/relations/CustomReference.d.mts.map +1 -1
  556. package/build/relations/CustomReference.js.map +1 -1
  557. package/build/relations/EnumCollection.cjs.map +1 -1
  558. package/build/relations/EnumCollection.d.cts +5 -5
  559. package/build/relations/EnumCollection.d.cts.map +1 -1
  560. package/build/relations/EnumCollection.d.mts +5 -5
  561. package/build/relations/EnumCollection.d.mts.map +1 -1
  562. package/build/relations/EnumCollection.js.map +1 -1
  563. package/build/relations/LargeCollection.d.cts +1 -2
  564. package/build/relations/LargeCollection.d.cts.map +1 -1
  565. package/build/relations/LargeCollection.d.mts +1 -2
  566. package/build/relations/LargeCollection.d.mts.map +1 -1
  567. package/build/relations/LazyField.cjs +14 -0
  568. package/build/relations/LazyField.cjs.map +1 -1
  569. package/build/relations/LazyField.d.cts +13 -8
  570. package/build/relations/LazyField.d.cts.map +1 -1
  571. package/build/relations/LazyField.d.mts +13 -8
  572. package/build/relations/LazyField.d.mts.map +1 -1
  573. package/build/relations/LazyField.js +14 -0
  574. package/build/relations/LazyField.js.map +1 -1
  575. package/build/relations/ManyToManyCollection.cjs.map +1 -1
  576. package/build/relations/ManyToManyCollection.d.cts +2 -3
  577. package/build/relations/ManyToManyCollection.d.cts.map +1 -1
  578. package/build/relations/ManyToManyCollection.d.mts +2 -3
  579. package/build/relations/ManyToManyCollection.d.mts.map +1 -1
  580. package/build/relations/ManyToManyCollection.js.map +1 -1
  581. package/build/relations/ManyToManyLargeCollection.d.cts +2 -3
  582. package/build/relations/ManyToManyLargeCollection.d.cts.map +1 -1
  583. package/build/relations/ManyToManyLargeCollection.d.mts +2 -3
  584. package/build/relations/ManyToManyLargeCollection.d.mts.map +1 -1
  585. package/build/relations/ManyToOneReference.cjs.map +1 -1
  586. package/build/relations/ManyToOneReference.d.cts +6 -7
  587. package/build/relations/ManyToOneReference.d.cts.map +1 -1
  588. package/build/relations/ManyToOneReference.d.mts +6 -7
  589. package/build/relations/ManyToOneReference.d.mts.map +1 -1
  590. package/build/relations/ManyToOneReference.js.map +1 -1
  591. package/build/relations/OneToManyCollection.cjs.map +1 -1
  592. package/build/relations/OneToManyCollection.d.cts +2 -3
  593. package/build/relations/OneToManyCollection.d.cts.map +1 -1
  594. package/build/relations/OneToManyCollection.d.mts +2 -3
  595. package/build/relations/OneToManyCollection.d.mts.map +1 -1
  596. package/build/relations/OneToManyCollection.js.map +1 -1
  597. package/build/relations/OneToManyLargeCollection.cjs.map +1 -1
  598. package/build/relations/OneToManyLargeCollection.d.cts +2 -3
  599. package/build/relations/OneToManyLargeCollection.d.cts.map +1 -1
  600. package/build/relations/OneToManyLargeCollection.d.mts +2 -3
  601. package/build/relations/OneToManyLargeCollection.d.mts.map +1 -1
  602. package/build/relations/OneToManyLargeCollection.js.map +1 -1
  603. package/build/relations/OneToOneReference.cjs.map +1 -1
  604. package/build/relations/OneToOneReference.d.cts +7 -7
  605. package/build/relations/OneToOneReference.d.cts.map +1 -1
  606. package/build/relations/OneToOneReference.d.mts +7 -7
  607. package/build/relations/OneToOneReference.d.mts.map +1 -1
  608. package/build/relations/OneToOneReference.js.map +1 -1
  609. package/build/relations/PolymorphicReference.cjs.map +1 -1
  610. package/build/relations/PolymorphicReference.d.cts +4 -5
  611. package/build/relations/PolymorphicReference.d.cts.map +1 -1
  612. package/build/relations/PolymorphicReference.d.mts +4 -5
  613. package/build/relations/PolymorphicReference.d.mts.map +1 -1
  614. package/build/relations/PolymorphicReference.js.map +1 -1
  615. package/build/relations/PropertySymbols.d.cts +1 -2
  616. package/build/relations/PropertySymbols.d.cts.map +1 -1
  617. package/build/relations/PropertySymbols.d.mts +1 -2
  618. package/build/relations/PropertySymbols.d.mts.map +1 -1
  619. package/build/relations/ReactiveField.cjs +2 -2
  620. package/build/relations/ReactiveField.cjs.map +1 -1
  621. package/build/relations/ReactiveField.d.cts +4 -5
  622. package/build/relations/ReactiveField.d.cts.map +1 -1
  623. package/build/relations/ReactiveField.d.mts +4 -5
  624. package/build/relations/ReactiveField.d.mts.map +1 -1
  625. package/build/relations/ReactiveField.js +2 -2
  626. package/build/relations/ReactiveField.js.map +1 -1
  627. package/build/relations/ReactiveGetter.cjs.map +1 -1
  628. package/build/relations/ReactiveGetter.d.cts +4 -5
  629. package/build/relations/ReactiveGetter.d.cts.map +1 -1
  630. package/build/relations/ReactiveGetter.d.mts +4 -5
  631. package/build/relations/ReactiveGetter.d.mts.map +1 -1
  632. package/build/relations/ReactiveGetter.js.map +1 -1
  633. package/build/relations/ReactiveManyToMany.cjs +1 -1
  634. package/build/relations/ReactiveManyToMany.cjs.map +1 -1
  635. package/build/relations/ReactiveManyToMany.d.cts +4 -5
  636. package/build/relations/ReactiveManyToMany.d.cts.map +1 -1
  637. package/build/relations/ReactiveManyToMany.d.mts +4 -5
  638. package/build/relations/ReactiveManyToMany.d.mts.map +1 -1
  639. package/build/relations/ReactiveManyToMany.js +1 -1
  640. package/build/relations/ReactiveManyToMany.js.map +1 -1
  641. package/build/relations/ReactiveManyToManyOtherSide.cjs.map +1 -1
  642. package/build/relations/ReactiveManyToManyOtherSide.d.cts +4 -5
  643. package/build/relations/ReactiveManyToManyOtherSide.d.cts.map +1 -1
  644. package/build/relations/ReactiveManyToManyOtherSide.d.mts +4 -5
  645. package/build/relations/ReactiveManyToManyOtherSide.d.mts.map +1 -1
  646. package/build/relations/ReactiveManyToManyOtherSide.js.map +1 -1
  647. package/build/relations/ReactiveReference.cjs +1 -1
  648. package/build/relations/ReactiveReference.cjs.map +1 -1
  649. package/build/relations/ReactiveReference.d.cts +5 -6
  650. package/build/relations/ReactiveReference.d.cts.map +1 -1
  651. package/build/relations/ReactiveReference.d.mts +5 -6
  652. package/build/relations/ReactiveReference.d.mts.map +1 -1
  653. package/build/relations/ReactiveReference.js +1 -1
  654. package/build/relations/ReactiveReference.js.map +1 -1
  655. package/build/relations/ReadOnlyCollection.d.cts +4 -5
  656. package/build/relations/ReadOnlyCollection.d.cts.map +1 -1
  657. package/build/relations/ReadOnlyCollection.d.mts +4 -5
  658. package/build/relations/ReadOnlyCollection.d.mts.map +1 -1
  659. package/build/relations/RecursiveCollection.cjs +3 -3
  660. package/build/relations/RecursiveCollection.cjs.map +1 -1
  661. package/build/relations/RecursiveCollection.d.cts +10 -10
  662. package/build/relations/RecursiveCollection.d.cts.map +1 -1
  663. package/build/relations/RecursiveCollection.d.mts +10 -10
  664. package/build/relations/RecursiveCollection.d.mts.map +1 -1
  665. package/build/relations/RecursiveCollection.js +3 -3
  666. package/build/relations/RecursiveCollection.js.map +1 -1
  667. package/build/relations/RecursiveCycleError.d.cts +2 -2
  668. package/build/relations/RecursiveCycleError.d.cts.map +1 -1
  669. package/build/relations/RecursiveCycleError.d.mts +2 -2
  670. package/build/relations/RecursiveCycleError.d.mts.map +1 -1
  671. package/build/relations/Reference.d.cts +5 -5
  672. package/build/relations/Reference.d.cts.map +1 -1
  673. package/build/relations/Reference.d.mts +5 -5
  674. package/build/relations/Reference.d.mts.map +1 -1
  675. package/build/relations/ReferenceSymbols.d.cts +1 -2
  676. package/build/relations/ReferenceSymbols.d.cts.map +1 -1
  677. package/build/relations/ReferenceSymbols.d.mts +1 -2
  678. package/build/relations/ReferenceSymbols.d.mts.map +1 -1
  679. package/build/relations/Relation.d.cts +3 -3
  680. package/build/relations/Relation.d.cts.map +1 -1
  681. package/build/relations/Relation.d.mts +3 -3
  682. package/build/relations/Relation.d.mts.map +1 -1
  683. package/build/relations/RelationSymbols.d.cts +2 -3
  684. package/build/relations/RelationSymbols.d.cts.map +1 -1
  685. package/build/relations/RelationSymbols.d.mts +2 -3
  686. package/build/relations/RelationSymbols.d.mts.map +1 -1
  687. package/build/relations/hasAsyncMethod.cjs.map +1 -1
  688. package/build/relations/hasAsyncMethod.d.cts +6 -6
  689. package/build/relations/hasAsyncMethod.d.cts.map +1 -1
  690. package/build/relations/hasAsyncMethod.d.mts +6 -6
  691. package/build/relations/hasAsyncMethod.d.mts.map +1 -1
  692. package/build/relations/hasAsyncMethod.js.map +1 -1
  693. package/build/relations/hasManyDerived.d.cts +2 -2
  694. package/build/relations/hasManyDerived.d.cts.map +1 -1
  695. package/build/relations/hasManyDerived.d.mts +2 -2
  696. package/build/relations/hasManyDerived.d.mts.map +1 -1
  697. package/build/relations/hasManyThrough.d.cts +1 -2
  698. package/build/relations/hasManyThrough.d.cts.map +1 -1
  699. package/build/relations/hasManyThrough.d.mts +1 -2
  700. package/build/relations/hasManyThrough.d.mts.map +1 -1
  701. package/build/relations/hasOneDerived.d.cts +1 -2
  702. package/build/relations/hasOneDerived.d.cts.map +1 -1
  703. package/build/relations/hasOneDerived.d.mts +1 -2
  704. package/build/relations/hasOneDerived.d.mts.map +1 -1
  705. package/build/relations/hasOneThrough.d.cts +1 -2
  706. package/build/relations/hasOneThrough.d.cts.map +1 -1
  707. package/build/relations/hasOneThrough.d.mts +1 -2
  708. package/build/relations/hasOneThrough.d.mts.map +1 -1
  709. package/build/relations/hasProperty.cjs +2 -2
  710. package/build/relations/hasProperty.cjs.map +1 -1
  711. package/build/relations/hasProperty.d.cts +8 -8
  712. package/build/relations/hasProperty.d.cts.map +1 -1
  713. package/build/relations/hasProperty.d.mts +8 -8
  714. package/build/relations/hasProperty.d.mts.map +1 -1
  715. package/build/relations/hasProperty.js +2 -2
  716. package/build/relations/hasProperty.js.map +1 -1
  717. package/build/relations/index.cjs +5 -5
  718. package/build/relations/index.js +5 -5
  719. package/build/relations/isCascadeDelete.d.cts +1 -2
  720. package/build/relations/isCascadeDelete.d.cts.map +1 -1
  721. package/build/relations/isCascadeDelete.d.mts +1 -2
  722. package/build/relations/isCascadeDelete.d.mts.map +1 -1
  723. package/build/resurrection.cjs +11 -1
  724. package/build/resurrection.cjs.map +1 -1
  725. package/build/resurrection.d.cts +5 -3
  726. package/build/resurrection.d.cts.map +1 -1
  727. package/build/resurrection.d.mts +5 -3
  728. package/build/resurrection.d.mts.map +1 -1
  729. package/build/resurrection.js +11 -2
  730. package/build/resurrection.js.map +1 -1
  731. package/build/rules.d.cts +20 -20
  732. package/build/rules.d.cts.map +1 -1
  733. package/build/rules.d.mts +20 -20
  734. package/build/rules.d.mts.map +1 -1
  735. package/build/runtimeConfig.d.cts +4 -5
  736. package/build/runtimeConfig.d.cts.map +1 -1
  737. package/build/runtimeConfig.d.mts +4 -5
  738. package/build/runtimeConfig.d.mts.map +1 -1
  739. package/build/serde/TypeInfo.d.cts +3 -4
  740. package/build/serde/TypeInfo.d.cts.map +1 -1
  741. package/build/serde/TypeInfo.d.mts +3 -4
  742. package/build/serde/TypeInfo.d.mts.map +1 -1
  743. package/build/serde/columns.d.cts +2 -3
  744. package/build/serde/columns.d.cts.map +1 -1
  745. package/build/serde/columns.d.mts +2 -3
  746. package/build/serde/columns.d.mts.map +1 -1
  747. package/build/serde/fieldSerde.d.cts +9 -9
  748. package/build/serde/fieldSerde.d.cts.map +1 -1
  749. package/build/serde/fieldSerde.d.mts +9 -9
  750. package/build/serde/fieldSerde.d.mts.map +1 -1
  751. package/build/serde/serde.cjs +35 -0
  752. package/build/serde/serde.cjs.map +1 -1
  753. package/build/serde/serde.d.cts +37 -19
  754. package/build/serde/serde.d.cts.map +1 -1
  755. package/build/serde/serde.d.mts +37 -19
  756. package/build/serde/serde.d.mts.map +1 -1
  757. package/build/serde/serde.js +35 -1
  758. package/build/serde/serde.js.map +1 -1
  759. package/build/serde/temporal.d.cts +5 -5
  760. package/build/serde/temporal.d.cts.map +1 -1
  761. package/build/serde/temporal.d.mts +5 -5
  762. package/build/serde/temporal.d.mts.map +1 -1
  763. package/build/serde/temporalMappers.d.cts +4 -5
  764. package/build/serde/temporalMappers.d.cts.map +1 -1
  765. package/build/serde/temporalMappers.d.mts +4 -5
  766. package/build/serde/temporalMappers.d.mts.map +1 -1
  767. package/build/transitions.cjs +89 -0
  768. package/build/transitions.cjs.map +1 -0
  769. package/build/transitions.d.cts +109 -0
  770. package/build/transitions.d.cts.map +1 -0
  771. package/build/transitions.d.mts +109 -0
  772. package/build/transitions.d.mts.map +1 -0
  773. package/build/transitions.js +84 -0
  774. package/build/transitions.js.map +1 -0
  775. package/build/trusted.d.cts +2 -3
  776. package/build/trusted.d.cts.map +1 -1
  777. package/build/trusted.d.mts +2 -3
  778. package/build/trusted.d.mts.map +1 -1
  779. package/build/typeMap.d.cts +17 -17
  780. package/build/typeMap.d.cts.map +1 -1
  781. package/build/typeMap.d.mts +17 -17
  782. package/build/typeMap.d.mts.map +1 -1
  783. package/build/upsert.d.cts +4 -4
  784. package/build/upsert.d.cts.map +1 -1
  785. package/build/upsert.d.mts +4 -4
  786. package/build/upsert.d.mts.map +1 -1
  787. package/build/utils.d.cts +27 -28
  788. package/build/utils.d.cts.map +1 -1
  789. package/build/utils.d.mts +27 -28
  790. package/build/utils.d.mts.map +1 -1
  791. package/package.json +6 -6
@@ -7,8 +7,8 @@ import { IdOf } from "../EntityManager.mjs";
7
7
  import { Entity } from "../Entity.mjs";
8
8
  //#region src/relations/ManyToManyCollection.d.ts
9
9
  /** An alias for creating `ManyToManyCollections`s. */
10
- declare function hasManyToMany<T extends Entity, U extends Entity>(): Collection<T, U>;
11
- declare class ManyToManyCollection<T extends Entity, U extends Entity> extends AbstractRelationImpl<T, U[]> implements Collection<T, U> {
10
+ export declare function hasManyToMany<T extends Entity, U extends Entity>(): Collection<T, U>;
11
+ export declare class ManyToManyCollection<T extends Entity, U extends Entity> extends AbstractRelationImpl<T, U[]> implements Collection<T, U> {
12
12
  #private;
13
13
  constructor(entity: T, field: ManyToManyField);
14
14
  /** @internal */
@@ -55,5 +55,4 @@ declare class ManyToManyCollection<T extends Entity, U extends Entity> extends A
55
55
  [RelationU]: U;
56
56
  }
57
57
  //#endregion
58
- export { ManyToManyCollection, hasManyToMany };
59
58
  //# sourceMappingURL=ManyToManyCollection.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ManyToManyCollection.d.mts","names":[],"sources":["../../src/relations/ManyToManyCollection.ts"],"mappings":";;;;;;;;;iBAuBgB,cAAc,UAAU,QAAQ,UAAU,WAAW,WAAW,GAAG;cAOtE,qBAAqB,UAAU,QAAQ,UAAU,gBACpD,qBAAqB,GAAG,gBACrB,WAAW,GAAG;;EAWzB,YAAY,QAAQ,GAAG,OAAO;;EAW9B,aAAa,OAAO;;EAKpB,gBAAgB,OAAO;;EAKvB,mBAAmB,OAAO;;EAK1B,sBAAsB,OAAO;;UAKrB;EAOF,KAAK;IAAQ;IAAuB;MAA+B,QAAQ,cAAc;EAqBzF,KAAK,IAAI,KAAK,KAAK,QAAQ;EAe3B,SAAS,OAAO,IAAI;EAa1B,IAAI,OAAO,GAAG;EAKd,OAAO,OAAO,GAAG;MAKb;MAIA;EAIJ;EAOA,OAAO,OAAO,qBAAqB,GAAG,IAAI,YAAY,cAAc,GAAG,oBAAoB;UAInF;MAKJ,kBAAkB;MAIlB,OAAO;EAIX,IAAI,iBAAiB;EAKrB;EAYA,YAAY,QAAQ;EAKpB;EAQM,0BAA0B;MAY5B,QAAQ;MAIR,aAAa;MAIb;MAIA;MAIA,iCAAiC;MAIjC;MAIA;MAIA;MAQA;EAIJ;GASC,YAAY;GACZ,YAAY"}
1
+ {"version":3,"file":"ManyToManyCollection.d.mts","names":[],"sources":["../../src/relations/ManyToManyCollection.ts"],"mappings":";;;;;;;;;wBAuBgB,cAAc,UAAU,QAAQ,UAAU,WAAW,WAAW,GAAG;qBAOtE,qBAAqB,UAAU,QAAQ,UAAU,gBACpD,qBAAqB,GAAG,gBACrB,WAAW,GAAG;;EAWzB,YAAY,QAAQ,GAAG,OAAO;;EAW9B,aAAa,OAAO;;EAKpB,gBAAgB,OAAO;;EAKvB,mBAAmB,OAAO;;EAK1B,sBAAsB,OAAO;;UAKrB;EAOF,KAAK;IAAQ;IAAuB;MAA+B,QAAQ,cAAc;EAqBzF,KAAK,IAAI,KAAK,KAAK,QAAQ;EAe3B,SAAS,OAAO,IAAI;EAa1B,IAAI,OAAO,GAAG;EAKd,OAAO,OAAO,GAAG;MAKb;MAIA;EAIJ;EAOA,OAAO,OAAO,qBAAqB,GAAG,IAAI,YAAY,cAAc,GAAG,oBAAoB;UAInF;MAKJ,kBAAkB;MAIlB,OAAO;EAIX,IAAI,iBAAiB;EAKrB;EAYA,YAAY,QAAQ;EAKpB;EAQM,0BAA0B;MAY5B,QAAQ;MAIR,aAAa;MAIb;MAIA;MAIA,iCAAiC;MAIjC;MAIA;MAIA;MAQA;EAIJ;GASC,YAAY;GACZ,YAAY"}
@@ -1 +1 @@
1
- {"version":3,"file":"ManyToManyCollection.js","names":["#field","#state","#getPreloaded","#loadPromise","#isCascadeDelete","#m2m","#added","#removed","#pendingSet","#loaded","#hasBeenSet"],"sources":["../../src/relations/ManyToManyCollection.ts"],"sourcesContent":["import { manyToManyBatchLoader } from \"src/batchloaders/manyToManyBatchLoader.ts\";\nimport { manyToManyFindDataLoader } from \"src/dataloaders/manyToManyFindDataLoader.ts\";\nimport {\n type Collection,\n type Entity,\n type EntityMetadata,\n type IdOf,\n type ManyToManyField,\n appendStack,\n ensureNotDeleted,\n getEmInternalApi,\n getInstanceData,\n getMetadata,\n getMetadataForField,\n toTaggedId,\n} from \"src/index.ts\";\nimport { lazyField } from \"src/newEntity.ts\";\nimport { AbstractRelationImpl } from \"src/relations/AbstractRelationImpl.ts\";\nimport { isCascadeDelete } from \"src/relations/isCascadeDelete.ts\";\nimport { RelationT, RelationU } from \"src/relations/RelationSymbols.ts\";\nimport { maybeAdd, maybeRemove, remove } from \"src/utils.ts\";\n\n/** An alias for creating `ManyToManyCollections`s. */\nexport function hasManyToMany<T extends Entity, U extends Entity>(): Collection<T, U> {\n return lazyField((entity: T, fieldName) => {\n const m2m = getMetadata(entity).allFields[fieldName] as ManyToManyField;\n return new ManyToManyCollection<T, U>(entity, m2m);\n });\n}\n\nexport class ManyToManyCollection<T extends Entity, U extends Entity>\n extends AbstractRelationImpl<T, U[]>\n implements Collection<T, U>\n{\n readonly #field: ManyToManyField;\n #loadPromise: any;\n #state: M2MState<T, U>;\n\n // I.e. when entity = Book:\n // fieldName == tags, because it's our collection to tags\n // columnName = book_id, what we use as the `where book_id = us` to find our join table rows\n // otherFieldName = books, how tags points to us\n // otherColumnName = tag_id, how the other side finds its join table rows\n constructor(entity: T, field: ManyToManyField) {\n super(entity);\n this.#field = field;\n if (getInstanceData(entity).isOrWasNew) {\n this.#state = new LoadedState<T, U>(this, [], false);\n } else {\n this.#state = new UnloadedPristineState<T, U>(this);\n }\n }\n\n /** @internal */\n percolateAdd(other: U): void {\n (other[this.otherFieldName] as any as ManyToManyCollection<U, T>).add(this.entity, true);\n }\n\n /** @internal */\n percolateRemove(other: U): void {\n (other[this.otherFieldName] as any as ManyToManyCollection<U, T>).remove(this.entity, true);\n }\n\n /** @internal */\n registerJoinRowAdd(other: U): void {\n getEmInternalApi(this.entity.em).joinRows(this).addNew(this, this.entity, other);\n }\n\n /** @internal */\n registerJoinRowRemove(other: U): void {\n getEmInternalApi(this.entity.em).joinRows(this).addRemove(this, this.entity, other);\n }\n\n /** Removes pending-hard-delete or soft-deleted entities, unless explicitly asked for. */\n private filterDeleted(entities: U[], opts?: { withDeleted?: boolean }): U[] {\n if (opts?.withDeleted === true) return [...entities];\n // Relations configured with `softDeletes: \"include\"` keep soft-deleted entities in `.get`/`.load`.\n const includeSoftDeleted = this.#field.softDeletes === \"include\";\n return entities.filter((e) => !e.isDeletedEntity && (includeSoftDeleted || !(e as any).isSoftDeletedEntity));\n }\n\n async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<ReadonlyArray<U>> {\n ensureNotDeleted(this.entity, \"pending\");\n if (!this.#state.isLoaded || (opts.forceReload && !this.entity.isNewEntity)) {\n const key = `${this.columnName}=${this.entity.id}`;\n const maybePreloaded = this.#getPreloaded();\n if (maybePreloaded) {\n this.#state = this.#state.applyLoad(maybePreloaded);\n } else {\n await (this.#loadPromise ??= manyToManyBatchLoader(this.entity.em, this).load(key))\n .then(() => this.preload())\n .catch(function load(err: any) {\n throw appendStack(err, new Error());\n })\n .finally(() => {\n this.#loadPromise = undefined;\n });\n }\n }\n return this.filterDeleted(this.#state.doGet(), opts) as ReadonlyArray<U>;\n }\n\n async find(id: IdOf<U>): Promise<U | undefined> {\n ensureNotDeleted(this.entity, \"pending\");\n const inMemory = this.#state.find(id);\n if (inMemory) return inMemory;\n if (this.#state.isLoaded) return undefined;\n const key = `${this.columnName}=${this.entity.id},${this.otherColumnName}=${id}`;\n const includes = await manyToManyFindDataLoader(this.entity.em, this)\n .load(key)\n .catch(function load(err) {\n throw appendStack(err, new Error());\n });\n const taggedId = toTaggedId(this.otherMeta, id);\n return includes ? (this.entity.em.load(taggedId) as Promise<U>) : undefined;\n }\n\n async includes(other: U): Promise<boolean> {\n ensureNotDeleted(this.entity, \"pending\");\n const inMemory = this.#state.includesInMemory(other);\n if (inMemory !== undefined) return inMemory;\n if (other.isNewEntity) return false;\n const key = `${this.columnName}=${this.entity.id},${this.otherColumnName}=${other.id}`;\n return manyToManyFindDataLoader(this.entity.em, this)\n .load(key)\n .catch(function includes(err) {\n throw appendStack(err, new Error());\n });\n }\n\n add(other: U, percolated = false): void {\n ensureNotDeleted(this.entity);\n this.#state = this.#state.add(other, percolated);\n }\n\n remove(other: U, percolated = false): void {\n ensureNotDeleted(this.entity, \"pending\");\n this.#state = this.#state.remove(other, percolated);\n }\n\n get isLoaded(): boolean {\n return this.#state.isLoaded;\n }\n\n get isPreloaded(): boolean {\n return !!this.#getPreloaded();\n }\n\n preload(): void {\n const preloaded = this.#getPreloaded();\n if (preloaded) {\n this.#state = this.#state.applyLoad(preloaded);\n }\n }\n\n import(other: ManyToManyCollection<T, U>, _: unknown, mapEntities: (e: U[] | undefined) => U[] | undefined): void {\n this.#state = other.#state.import(this, mapEntities);\n }\n\n private doGet(): U[] {\n ensureNotDeleted(this.entity, \"pending\");\n return this.#state.doGet();\n }\n\n get getWithDeleted(): U[] {\n return this.filterDeleted(this.doGet(), { withDeleted: true });\n }\n\n get get(): U[] {\n return this.filterDeleted(this.doGet(), { withDeleted: false });\n }\n\n set(values: readonly U[]): void {\n ensureNotDeleted(this.entity);\n this.#state = this.#state.set(values);\n }\n\n removeAll(): void {\n ensureNotDeleted(this.entity);\n if (!this.#state.isLoaded) {\n throw new Error(\"removeAll was called when not loaded\");\n }\n for (const other of [...this.#state.doGet()]) {\n this.remove(other);\n }\n }\n\n // impl details\n\n setFromOpts(others: U[]): void {\n this.#state = new LoadedState<T, U>(this, [], false);\n others.forEach((o) => this.add(o));\n }\n\n maybeCascadeDelete() {\n if (this.#isCascadeDelete) {\n this.filterDeleted(this.#state.current({ withDeleted: true }), { withDeleted: true }).forEach((e) =>\n this.entity.em.delete(e),\n );\n }\n }\n\n async cleanupOnEntityDeleted(): Promise<void> {\n if (this.#isCascadeDelete) return;\n const entities = await this.load({ withDeleted: true });\n entities.forEach((other) => {\n const m2m = other[this.otherFieldName] as any as ManyToManyCollection<U, T>;\n m2m.remove(this.entity);\n });\n if (this.#state instanceof LoadedState) {\n this.#state.setLoaded([]);\n }\n }\n\n get meta(): EntityMetadata {\n return getMetadataForField(getMetadata(this.entity), this.fieldName);\n }\n\n get otherMeta(): EntityMetadata {\n return this.#field.otherMetadata();\n }\n\n get joinTableName(): string {\n return this.#field.joinTableName;\n }\n\n get fieldName(): string {\n return this.#field.fieldName;\n }\n\n get otherFieldName(): string & keyof U {\n return this.#field.otherFieldName as string & keyof U;\n }\n\n get columnName(): string {\n return this.#field.columnNames[0];\n }\n\n get otherColumnName(): string {\n return this.#field.columnNames[1];\n }\n\n get hasJoinTableId(): boolean {\n return this.#field.hasJoinTableId;\n }\n\n get #isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.fieldName);\n }\n\n get hasBeenSet(): boolean {\n return this.#state.hasBeenSet;\n }\n\n toString(): string {\n return `OneToManyCollection(entity: ${this.entity}, fieldName: ${this.fieldName}, otherType: ${this.otherMeta.type}, otherFieldName: ${this.otherFieldName})`;\n }\n\n #getPreloaded(): U[] | undefined {\n if (this.entity.isNewEntity) return undefined;\n return getEmInternalApi(this.entity.em).getPreloadedRelation<U>(this.entity.idTagged, this.fieldName);\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n}\n\n/**\n * State interface for ManyToManyCollection state machine.\n *\n * State transitions:\n * ```\n * Constructor (existing entity) → UnloadedPristine\n * Constructor (new entity) → Loaded\n *\n * UnloadedPristine + add/remove → UnloadedAddedRemoved\n * UnloadedPristine + set → PendingSet\n * UnloadedPristine + applyLoad → Loaded\n *\n * UnloadedAddedRemoved + set → PendingSet\n * UnloadedAddedRemoved + applyLoad → Loaded (merges tracked adds/removes)\n *\n * PendingSet + applyLoad → Loaded (diffs pending values against DB)\n *\n * Loaded + applyLoad (forceReload) → Loaded (refreshed)\n * ```\n */\ninterface M2MState<T extends Entity, U extends Entity> {\n /** Adds an entity; may transition UnloadedPristine → UnloadedAddedRemoved. */\n add(other: U, percolated: boolean): M2MState<T, U>;\n /** Removes an entity; may transition UnloadedPristine → UnloadedAddedRemoved. */\n remove(other: U, percolated: boolean): M2MState<T, U>;\n /** Sets the collection; transitions UnloadedPristine/UnloadedAddedRemoved → PendingSet. */\n set(values: readonly U[]): M2MState<T, U>;\n /** Returns the current entities; throws if not loaded (except PendingSet returns pending values). */\n doGet(): U[];\n /** Finds an entity by id in memory; returns undefined if not found or not tracked. */\n find(id: IdOf<U>): U | undefined;\n /** Checks if entity is in memory; returns undefined if async lookup needed. */\n includesInMemory(other: U): boolean | undefined;\n /** Applies loaded DB entities; always transitions to Loaded. */\n applyLoad(dbEntities: U[]): LoadedState<T, U>;\n /** Returns current entities for cascade delete (works in any state). */\n current(opts?: { withDeleted?: boolean }): U[];\n /** Creates a copy of this state for a different collection (used by em.clone). */\n import(m2m: ManyToManyCollection<T, U>, mapEntities: (e: U[] | undefined) => U[] | undefined): M2MState<T, U>;\n readonly isLoaded: boolean;\n readonly hasBeenSet: boolean;\n}\n\n/** Initial state for existing entities - no data loaded yet. */\nclass UnloadedPristineState<T extends Entity, U extends Entity> implements M2MState<T, U> {\n readonly isLoaded = false;\n readonly hasBeenSet = false;\n #m2m: ManyToManyCollection<T, U>;\n\n constructor(m2m: ManyToManyCollection<T, U>) {\n this.#m2m = m2m;\n }\n\n add(other: U, percolated: boolean): M2MState<T, U> {\n const newState = new UnloadedAddedRemovedState<T, U>(this.#m2m, [other], []);\n if (!percolated) {\n this.#m2m.registerJoinRowAdd(other);\n this.#m2m.percolateAdd(other);\n }\n return newState;\n }\n\n remove(other: U, percolated: boolean): M2MState<T, U> {\n if (!percolated) {\n this.#m2m.registerJoinRowRemove(other);\n this.#m2m.percolateRemove(other);\n }\n return new UnloadedAddedRemovedState<T, U>(this.#m2m, [], [other]);\n }\n\n set(values: readonly U[]): M2MState<T, U> {\n return new PendingSetState<T, U>(this.#m2m, [...values]);\n }\n\n doGet(): U[] {\n throw new Error(`${this.#m2m.entity}.${this.#m2m.fieldName}.get was called when not loaded`);\n }\n\n find(_id: IdOf<U>): U | undefined {\n return undefined;\n }\n\n includesInMemory(_other: U): boolean | undefined {\n return undefined;\n }\n\n applyLoad(dbEntities: U[]): LoadedState<T, U> {\n return new LoadedState<T, U>(this.#m2m, dbEntities, false);\n }\n\n current(_opts?: { withDeleted?: boolean }): U[] {\n return [];\n }\n\n import(m2m: ManyToManyCollection<T, U>, _mapEntities: (e: U[] | undefined) => U[] | undefined): M2MState<T, U> {\n return new UnloadedPristineState<T, U>(m2m);\n }\n}\n\n/** State when add/remove called before load - tracks changes to merge later. */\nclass UnloadedAddedRemovedState<T extends Entity, U extends Entity> implements M2MState<T, U> {\n readonly isLoaded = false;\n readonly hasBeenSet = false;\n #m2m: ManyToManyCollection<T, U>;\n #added: U[];\n #removed: U[];\n\n constructor(m2m: ManyToManyCollection<T, U>, added: U[], removed: U[]) {\n this.#m2m = m2m;\n this.#added = added;\n this.#removed = removed;\n }\n\n add(other: U, percolated: boolean): M2MState<T, U> {\n maybeRemove(this.#removed, other);\n if (!this.#added.includes(other)) {\n this.#added.push(other);\n }\n if (!percolated) {\n this.#m2m.registerJoinRowAdd(other);\n this.#m2m.percolateAdd(other);\n }\n return this;\n }\n\n remove(other: U, percolated: boolean): M2MState<T, U> {\n if (!percolated) {\n this.#m2m.registerJoinRowRemove(other);\n this.#m2m.percolateRemove(other);\n }\n maybeRemove(this.#added, other);\n maybeAdd(this.#removed, other);\n return this;\n }\n\n set(values: readonly U[]): M2MState<T, U> {\n return new PendingSetState<T, U>(this.#m2m, [...values]);\n }\n\n doGet(): U[] {\n throw new Error(`${this.#m2m.entity}.${this.#m2m.fieldName}.get was called when not loaded`);\n }\n\n find(id: IdOf<U>): U | undefined {\n return this.#added.find((u) => u.id === id);\n }\n\n includesInMemory(other: U): boolean | undefined {\n if (this.#added.includes(other)) return true;\n return undefined;\n }\n\n applyLoad(dbEntities: U[]): LoadedState<T, U> {\n const loaded = [...dbEntities];\n for (const e of this.#added) {\n if (!loaded.includes(e)) {\n loaded.unshift(e);\n this.#m2m.registerJoinRowAdd(e);\n }\n }\n for (const e of this.#removed) {\n remove(loaded, e);\n this.#m2m.registerJoinRowRemove(e);\n }\n return new LoadedState<T, U>(this.#m2m, loaded, false);\n }\n\n current(_opts?: { withDeleted?: boolean }): U[] {\n return this.#added;\n }\n\n import(m2m: ManyToManyCollection<T, U>, mapEntities: (e: U[] | undefined) => U[] | undefined): M2MState<T, U> {\n const added = mapEntities(this.#added);\n const removed = mapEntities(this.#removed);\n return new UnloadedAddedRemovedState<T, U>(m2m, added ?? [], removed ?? []);\n }\n}\n\n/** State when set() called before load - holds pending values to diff on load. */\nclass PendingSetState<T extends Entity, U extends Entity> implements M2MState<T, U> {\n readonly isLoaded = false;\n readonly hasBeenSet = true;\n #m2m: ManyToManyCollection<T, U>;\n #pendingSet: U[];\n\n constructor(m2m: ManyToManyCollection<T, U>, pendingSet: U[]) {\n this.#m2m = m2m;\n this.#pendingSet = pendingSet;\n getEmInternalApi(m2m.entity.em).pendingLoads.add(m2m);\n }\n\n add(other: U, percolated: boolean): M2MState<T, U> {\n if (!this.#pendingSet.includes(other)) {\n this.#pendingSet.push(other);\n }\n if (!percolated) {\n this.#m2m.registerJoinRowAdd(other);\n this.#m2m.percolateAdd(other);\n }\n return this;\n }\n\n remove(other: U, percolated: boolean): M2MState<T, U> {\n if (!percolated) {\n this.#m2m.registerJoinRowRemove(other);\n this.#m2m.percolateRemove(other);\n }\n remove(this.#pendingSet, other);\n return this;\n }\n\n set(values: readonly U[]): M2MState<T, U> {\n this.#pendingSet = [...values];\n return this;\n }\n\n doGet(): U[] {\n return this.#pendingSet;\n }\n\n find(id: IdOf<U>): U | undefined {\n return this.#pendingSet.find((u) => u.id === id);\n }\n\n includesInMemory(other: U): boolean | undefined {\n return this.#pendingSet.includes(other);\n }\n\n applyLoad(dbEntities: U[]): LoadedState<T, U> {\n const loaded = [...dbEntities];\n const pending = this.#pendingSet;\n for (const other of [...loaded]) {\n if (!pending.includes(other)) {\n remove(loaded, other);\n this.#m2m.registerJoinRowRemove(other);\n this.#m2m.percolateRemove(other);\n }\n }\n for (const other of pending) {\n if (!loaded.includes(other)) {\n loaded.push(other);\n this.#m2m.registerJoinRowAdd(other);\n this.#m2m.percolateAdd(other);\n }\n }\n return new LoadedState<T, U>(this.#m2m, loaded, true);\n }\n\n current(_opts?: { withDeleted?: boolean }): U[] {\n return this.#pendingSet;\n }\n\n import(m2m: ManyToManyCollection<T, U>, mapEntities: (e: U[] | undefined) => U[] | undefined): M2MState<T, U> {\n const pendingSet = mapEntities(this.#pendingSet);\n return new PendingSetState<T, U>(m2m, pendingSet ?? []);\n }\n}\n\n/** State when collection is loaded - all operations work directly on loaded array. */\nclass LoadedState<T extends Entity, U extends Entity> implements M2MState<T, U> {\n readonly isLoaded = true;\n #m2m: ManyToManyCollection<T, U>;\n #loaded: U[];\n #hasBeenSet: boolean;\n\n constructor(m2m: ManyToManyCollection<T, U>, loaded: U[], hasBeenSet: boolean) {\n this.#m2m = m2m;\n this.#loaded = loaded;\n this.#hasBeenSet = hasBeenSet;\n }\n\n get hasBeenSet(): boolean {\n return this.#hasBeenSet;\n }\n\n add(other: U, percolated: boolean): M2MState<T, U> {\n if (this.#loaded.includes(other)) return this;\n this.#loaded.push(other);\n if (!percolated) {\n this.#m2m.registerJoinRowAdd(other);\n this.#m2m.percolateAdd(other);\n }\n return this;\n }\n\n remove(other: U, percolated: boolean): M2MState<T, U> {\n if (!percolated) {\n this.#m2m.registerJoinRowRemove(other);\n this.#m2m.percolateRemove(other);\n }\n remove(this.#loaded, other);\n return this;\n }\n\n set(values: readonly U[]): M2MState<T, U> {\n this.#hasBeenSet = true;\n const loaded = new Set(this.#loaded);\n const valuesSet = new Set(values);\n for (const other of loaded) {\n if (!valuesSet.has(other)) {\n this.remove(other, false);\n }\n }\n for (const other of values) {\n if (!loaded.has(other)) {\n this.add(other, false);\n }\n }\n return this;\n }\n\n doGet(): U[] {\n return this.#loaded;\n }\n\n find(id: IdOf<U>): U | undefined {\n return this.#loaded.find((u) => u.id === id);\n }\n\n includesInMemory(other: U): boolean | undefined {\n return this.#loaded.includes(other);\n }\n\n applyLoad(dbEntities: U[]): LoadedState<T, U> {\n this.#loaded = dbEntities;\n return this;\n }\n\n current(_opts?: { withDeleted?: boolean }): U[] {\n return this.#loaded;\n }\n\n import(m2m: ManyToManyCollection<T, U>, mapEntities: (e: U[] | undefined) => U[] | undefined): M2MState<T, U> {\n const loaded = mapEntities(this.#loaded);\n return new LoadedState<T, U>(m2m, loaded ?? [], this.#hasBeenSet);\n }\n\n getLoaded(): U[] {\n return this.#loaded;\n }\n\n setLoaded(entities: U[]): void {\n this.#loaded = entities;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAuBA,SAAgB,gBAAsE;CACpF,OAAO,WAAW,QAAW,cAAc;EACzC,MAAM,MAAM,YAAY,MAAM,CAAC,CAAC,UAAU;EAC1C,OAAO,IAAI,qBAA2B,QAAQ,GAAG;CACnD,CAAC;AACH;AAEA,IAAa,uBAAb,cACU,qBAEV;CACE;CACA;CACA;CAOA,YAAY,QAAW,OAAwB;EAC7C,MAAM,MAAM;EACZ,KAAKA,SAAS;EACd,IAAI,gBAAgB,MAAM,CAAC,CAAC,YAC1B,KAAKC,SAAS,IAAI,YAAkB,MAAM,CAAC,GAAG,KAAK;OAEnD,KAAKA,SAAS,IAAI,sBAA4B,IAAI;CAEtD;;CAGA,aAAa,OAAgB;EAC3B,MAAO,KAAK,eAAe,CAAuC,IAAI,KAAK,QAAQ,IAAI;CACzF;;CAGA,gBAAgB,OAAgB;EAC9B,MAAO,KAAK,eAAe,CAAuC,OAAO,KAAK,QAAQ,IAAI;CAC5F;;CAGA,mBAAmB,OAAgB;EACjC,iBAAiB,KAAK,OAAO,EAAE,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,OAAO,MAAM,KAAK,QAAQ,KAAK;CACjF;;CAGA,sBAAsB,OAAgB;EACpC,iBAAiB,KAAK,OAAO,EAAE,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,UAAU,MAAM,KAAK,QAAQ,KAAK;CACpF;;CAGA,cAAsB,UAAe,MAAuC;EAC1E,IAAI,MAAM,gBAAgB,MAAM,OAAO,CAAC,GAAG,QAAQ;EAEnD,MAAM,qBAAqB,KAAKD,OAAO,gBAAgB;EACvD,OAAO,SAAS,QAAQ,MAAM,CAAC,EAAE,oBAAoB,sBAAsB,CAAE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K,aAAa,KAAK;EAC9B;EACA,OAAO;CACT;CAEA,OAAO,OAAU,YAAqC;EACpD,IAAI,CAAC,YAAY;GACf,KAAKA,KAAK,sBAAsB,KAAK;GACrC,KAAKA,KAAK,gBAAgB,KAAK;EACjC;EACA,OAAO,KAAKI,SAAS,KAAK;EAC1B,OAAO;CACT;CAEA,IAAI,QAAsC;EACxC,KAAKC,cAAc;EACnB,MAAM,SAAS,IAAI,IAAI,KAAKD,OAAO;EACnC,MAAM,YAAY,IAAI,IAAI,MAAM;EAChC,KAAK,MAAM,SAAS,QAClB,IAAI,CAAC,UAAU,IAAI,KAAK,GACtB,KAAK,OAAO,OAAO,KAAK;EAG5B,KAAK,MAAM,SAAS,QAClB,IAAI,CAAC,OAAO,IAAI,KAAK,GACnB,KAAK,IAAI,OAAO,KAAK;EAGzB,OAAO;CACT;CAEA,QAAa;EACX,OAAO,KAAKA;CACd;CAEA,KAAK,IAA4B;EAC/B,OAAO,KAAKA,QAAQ,MAAM,MAAM,EAAE,OAAO,EAAE;CAC7C;CAEA,iBAAiB,OAA+B;EAC9C,OAAO,KAAKA,QAAQ,SAAS,KAAK;CACpC;CAEA,UAAU,YAAoC;EAC5C,KAAKA,UAAU;EACf,OAAO;CACT;CAEA,QAAQ,OAAwC;EAC9C,OAAO,KAAKA;CACd;CAEA,OAAO,KAAiC,aAAsE;EAC5G,MAAM,SAAS,YAAY,KAAKA,OAAO;EACvC,OAAO,IAAI,YAAkB,KAAK,UAAU,CAAC,GAAG,KAAKC,WAAW;CAClE;CAEA,YAAiB;EACf,OAAO,KAAKD;CACd;CAEA,UAAU,UAAqB;EAC7B,KAAKA,UAAU;CACjB;AACF"}
1
+ {"version":3,"file":"ManyToManyCollection.js","names":[],"sources":["../../src/relations/ManyToManyCollection.ts"],"sourcesContent":["import { manyToManyBatchLoader } from \"src/batchloaders/manyToManyBatchLoader.ts\";\nimport { manyToManyFindDataLoader } from \"src/dataloaders/manyToManyFindDataLoader.ts\";\nimport {\n type Collection,\n type Entity,\n type EntityMetadata,\n type IdOf,\n type ManyToManyField,\n appendStack,\n ensureNotDeleted,\n getEmInternalApi,\n getInstanceData,\n getMetadata,\n getMetadataForField,\n toTaggedId,\n} from \"src/index.ts\";\nimport { lazyField } from \"src/newEntity.ts\";\nimport { AbstractRelationImpl } from \"src/relations/AbstractRelationImpl.ts\";\nimport { isCascadeDelete } from \"src/relations/isCascadeDelete.ts\";\nimport { RelationT, RelationU } from \"src/relations/RelationSymbols.ts\";\nimport { maybeAdd, maybeRemove, remove } from \"src/utils.ts\";\n\n/** An alias for creating `ManyToManyCollections`s. */\nexport function hasManyToMany<T extends Entity, U extends Entity>(): Collection<T, U> {\n return lazyField((entity: T, fieldName) => {\n const m2m = getMetadata(entity).allFields[fieldName] as ManyToManyField;\n return new ManyToManyCollection<T, U>(entity, m2m);\n });\n}\n\nexport class ManyToManyCollection<T extends Entity, U extends Entity>\n extends AbstractRelationImpl<T, U[]>\n implements Collection<T, U>\n{\n readonly #field: ManyToManyField;\n #loadPromise: any;\n #state: M2MState<T, U>;\n\n // I.e. when entity = Book:\n // fieldName == tags, because it's our collection to tags\n // columnName = book_id, what we use as the `where book_id = us` to find our join table rows\n // otherFieldName = books, how tags points to us\n // otherColumnName = tag_id, how the other side finds its join table rows\n constructor(entity: T, field: ManyToManyField) {\n super(entity);\n this.#field = field;\n if (getInstanceData(entity).isOrWasNew) {\n this.#state = new LoadedState<T, U>(this, [], false);\n } else {\n this.#state = new UnloadedPristineState<T, U>(this);\n }\n }\n\n /** @internal */\n percolateAdd(other: U): void {\n (other[this.otherFieldName] as any as ManyToManyCollection<U, T>).add(this.entity, true);\n }\n\n /** @internal */\n percolateRemove(other: U): void {\n (other[this.otherFieldName] as any as ManyToManyCollection<U, T>).remove(this.entity, true);\n }\n\n /** @internal */\n registerJoinRowAdd(other: U): void {\n getEmInternalApi(this.entity.em).joinRows(this).addNew(this, this.entity, other);\n }\n\n /** @internal */\n registerJoinRowRemove(other: U): void {\n getEmInternalApi(this.entity.em).joinRows(this).addRemove(this, this.entity, other);\n }\n\n /** Removes pending-hard-delete or soft-deleted entities, unless explicitly asked for. */\n private filterDeleted(entities: U[], opts?: { withDeleted?: boolean }): U[] {\n if (opts?.withDeleted === true) return [...entities];\n // Relations configured with `softDeletes: \"include\"` keep soft-deleted entities in `.get`/`.load`.\n const includeSoftDeleted = this.#field.softDeletes === \"include\";\n return entities.filter((e) => !e.isDeletedEntity && (includeSoftDeleted || !(e as any).isSoftDeletedEntity));\n }\n\n async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<ReadonlyArray<U>> {\n ensureNotDeleted(this.entity, \"pending\");\n if (!this.#state.isLoaded || (opts.forceReload && !this.entity.isNewEntity)) {\n const key = `${this.columnName}=${this.entity.id}`;\n const maybePreloaded = this.#getPreloaded();\n if (maybePreloaded) {\n this.#state = this.#state.applyLoad(maybePreloaded);\n } else {\n await (this.#loadPromise ??= manyToManyBatchLoader(this.entity.em, this).load(key))\n .then(() => this.preload())\n .catch(function load(err: any) {\n throw appendStack(err, new Error());\n })\n .finally(() => {\n this.#loadPromise = undefined;\n });\n }\n }\n return this.filterDeleted(this.#state.doGet(), opts) as ReadonlyArray<U>;\n }\n\n async find(id: IdOf<U>): Promise<U | undefined> {\n ensureNotDeleted(this.entity, \"pending\");\n const inMemory = this.#state.find(id);\n if (inMemory) return inMemory;\n if (this.#state.isLoaded) return undefined;\n const key = `${this.columnName}=${this.entity.id},${this.otherColumnName}=${id}`;\n const includes = await manyToManyFindDataLoader(this.entity.em, this)\n .load(key)\n .catch(function load(err) {\n throw appendStack(err, new Error());\n });\n const taggedId = toTaggedId(this.otherMeta, id);\n return includes ? (this.entity.em.load(taggedId) as Promise<U>) : undefined;\n }\n\n async includes(other: U): Promise<boolean> {\n ensureNotDeleted(this.entity, \"pending\");\n const inMemory = this.#state.includesInMemory(other);\n if (inMemory !== undefined) return inMemory;\n if (other.isNewEntity) return false;\n const key = `${this.columnName}=${this.entity.id},${this.otherColumnName}=${other.id}`;\n return manyToManyFindDataLoader(this.entity.em, this)\n .load(key)\n .catch(function includes(err) {\n throw appendStack(err, new Error());\n });\n }\n\n add(other: U, percolated = false): void {\n ensureNotDeleted(this.entity);\n this.#state = this.#state.add(other, percolated);\n }\n\n remove(other: U, percolated = false): void {\n ensureNotDeleted(this.entity, \"pending\");\n this.#state = this.#state.remove(other, percolated);\n }\n\n get isLoaded(): boolean {\n return this.#state.isLoaded;\n }\n\n get isPreloaded(): boolean {\n return !!this.#getPreloaded();\n }\n\n preload(): void {\n const preloaded = this.#getPreloaded();\n if (preloaded) {\n this.#state = this.#state.applyLoad(preloaded);\n }\n }\n\n import(other: ManyToManyCollection<T, U>, _: unknown, mapEntities: (e: U[] | undefined) => U[] | undefined): void {\n this.#state = other.#state.import(this, mapEntities);\n }\n\n private doGet(): U[] {\n ensureNotDeleted(this.entity, \"pending\");\n return this.#state.doGet();\n }\n\n get getWithDeleted(): U[] {\n return this.filterDeleted(this.doGet(), { withDeleted: true });\n }\n\n get get(): U[] {\n return this.filterDeleted(this.doGet(), { withDeleted: false });\n }\n\n set(values: readonly U[]): void {\n ensureNotDeleted(this.entity);\n this.#state = this.#state.set(values);\n }\n\n removeAll(): void {\n ensureNotDeleted(this.entity);\n if (!this.#state.isLoaded) {\n throw new Error(\"removeAll was called when not loaded\");\n }\n for (const other of [...this.#state.doGet()]) {\n this.remove(other);\n }\n }\n\n // impl details\n\n setFromOpts(others: U[]): void {\n this.#state = new LoadedState<T, U>(this, [], false);\n others.forEach((o) => this.add(o));\n }\n\n maybeCascadeDelete() {\n if (this.#isCascadeDelete) {\n this.filterDeleted(this.#state.current({ withDeleted: true }), { withDeleted: true }).forEach((e) =>\n this.entity.em.delete(e),\n );\n }\n }\n\n async cleanupOnEntityDeleted(): Promise<void> {\n if (this.#isCascadeDelete) return;\n const entities = await this.load({ withDeleted: true });\n entities.forEach((other) => {\n const m2m = other[this.otherFieldName] as any as ManyToManyCollection<U, T>;\n m2m.remove(this.entity);\n });\n if (this.#state instanceof LoadedState) {\n this.#state.setLoaded([]);\n }\n }\n\n get meta(): EntityMetadata {\n return getMetadataForField(getMetadata(this.entity), this.fieldName);\n }\n\n get otherMeta(): EntityMetadata {\n return this.#field.otherMetadata();\n }\n\n get joinTableName(): string {\n return this.#field.joinTableName;\n }\n\n get fieldName(): string {\n return this.#field.fieldName;\n }\n\n get otherFieldName(): string & keyof U {\n return this.#field.otherFieldName as string & keyof U;\n }\n\n get columnName(): string {\n return this.#field.columnNames[0];\n }\n\n get otherColumnName(): string {\n return this.#field.columnNames[1];\n }\n\n get hasJoinTableId(): boolean {\n return this.#field.hasJoinTableId;\n }\n\n get #isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.fieldName);\n }\n\n get hasBeenSet(): boolean {\n return this.#state.hasBeenSet;\n }\n\n toString(): string {\n return `OneToManyCollection(entity: ${this.entity}, fieldName: ${this.fieldName}, otherType: ${this.otherMeta.type}, otherFieldName: ${this.otherFieldName})`;\n }\n\n #getPreloaded(): U[] | undefined {\n if (this.entity.isNewEntity) return undefined;\n return getEmInternalApi(this.entity.em).getPreloadedRelation<U>(this.entity.idTagged, this.fieldName);\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n}\n\n/**\n * State interface for ManyToManyCollection state machine.\n *\n * State transitions:\n * ```\n * Constructor (existing entity) → UnloadedPristine\n * Constructor (new entity) → Loaded\n *\n * UnloadedPristine + add/remove → UnloadedAddedRemoved\n * UnloadedPristine + set → PendingSet\n * UnloadedPristine + applyLoad → Loaded\n *\n * UnloadedAddedRemoved + set → PendingSet\n * UnloadedAddedRemoved + applyLoad → Loaded (merges tracked adds/removes)\n *\n * PendingSet + applyLoad → Loaded (diffs pending values against DB)\n *\n * Loaded + applyLoad (forceReload) → Loaded (refreshed)\n * ```\n */\ninterface M2MState<T extends Entity, U extends Entity> {\n /** Adds an entity; may transition UnloadedPristine → UnloadedAddedRemoved. */\n add(other: U, percolated: boolean): M2MState<T, U>;\n /** Removes an entity; may transition UnloadedPristine → UnloadedAddedRemoved. */\n remove(other: U, percolated: boolean): M2MState<T, U>;\n /** Sets the collection; transitions UnloadedPristine/UnloadedAddedRemoved → PendingSet. */\n set(values: readonly U[]): M2MState<T, U>;\n /** Returns the current entities; throws if not loaded (except PendingSet returns pending values). */\n doGet(): U[];\n /** Finds an entity by id in memory; returns undefined if not found or not tracked. */\n find(id: IdOf<U>): U | undefined;\n /** Checks if entity is in memory; returns undefined if async lookup needed. */\n includesInMemory(other: U): boolean | undefined;\n /** Applies loaded DB entities; always transitions to Loaded. */\n applyLoad(dbEntities: U[]): LoadedState<T, U>;\n /** Returns current entities for cascade delete (works in any state). */\n current(opts?: { withDeleted?: boolean }): U[];\n /** Creates a copy of this state for a different collection (used by em.clone). */\n import(m2m: ManyToManyCollection<T, U>, mapEntities: (e: U[] | undefined) => U[] | undefined): M2MState<T, U>;\n readonly isLoaded: boolean;\n readonly hasBeenSet: boolean;\n}\n\n/** Initial state for existing entities - no data loaded yet. */\nclass UnloadedPristineState<T extends Entity, U extends Entity> implements M2MState<T, U> {\n readonly isLoaded = false;\n readonly hasBeenSet = false;\n #m2m: ManyToManyCollection<T, U>;\n\n constructor(m2m: ManyToManyCollection<T, U>) {\n this.#m2m = m2m;\n }\n\n add(other: U, percolated: boolean): M2MState<T, U> {\n const newState = new UnloadedAddedRemovedState<T, U>(this.#m2m, [other], []);\n if (!percolated) {\n this.#m2m.registerJoinRowAdd(other);\n this.#m2m.percolateAdd(other);\n }\n return newState;\n }\n\n remove(other: U, percolated: boolean): M2MState<T, U> {\n if (!percolated) {\n this.#m2m.registerJoinRowRemove(other);\n this.#m2m.percolateRemove(other);\n }\n return new UnloadedAddedRemovedState<T, U>(this.#m2m, [], [other]);\n }\n\n set(values: readonly U[]): M2MState<T, U> {\n return new PendingSetState<T, U>(this.#m2m, [...values]);\n }\n\n doGet(): U[] {\n throw new Error(`${this.#m2m.entity}.${this.#m2m.fieldName}.get was called when not loaded`);\n }\n\n find(_id: IdOf<U>): U | undefined {\n return undefined;\n }\n\n includesInMemory(_other: U): boolean | undefined {\n return undefined;\n }\n\n applyLoad(dbEntities: U[]): LoadedState<T, U> {\n return new LoadedState<T, U>(this.#m2m, dbEntities, false);\n }\n\n current(_opts?: { withDeleted?: boolean }): U[] {\n return [];\n }\n\n import(m2m: ManyToManyCollection<T, U>, _mapEntities: (e: U[] | undefined) => U[] | undefined): M2MState<T, U> {\n return new UnloadedPristineState<T, U>(m2m);\n }\n}\n\n/** State when add/remove called before load - tracks changes to merge later. */\nclass UnloadedAddedRemovedState<T extends Entity, U extends Entity> implements M2MState<T, U> {\n readonly isLoaded = false;\n readonly hasBeenSet = false;\n #m2m: ManyToManyCollection<T, U>;\n #added: U[];\n #removed: U[];\n\n constructor(m2m: ManyToManyCollection<T, U>, added: U[], removed: U[]) {\n this.#m2m = m2m;\n this.#added = added;\n this.#removed = removed;\n }\n\n add(other: U, percolated: boolean): M2MState<T, U> {\n maybeRemove(this.#removed, other);\n if (!this.#added.includes(other)) {\n this.#added.push(other);\n }\n if (!percolated) {\n this.#m2m.registerJoinRowAdd(other);\n this.#m2m.percolateAdd(other);\n }\n return this;\n }\n\n remove(other: U, percolated: boolean): M2MState<T, U> {\n if (!percolated) {\n this.#m2m.registerJoinRowRemove(other);\n this.#m2m.percolateRemove(other);\n }\n maybeRemove(this.#added, other);\n maybeAdd(this.#removed, other);\n return this;\n }\n\n set(values: readonly U[]): M2MState<T, U> {\n return new PendingSetState<T, U>(this.#m2m, [...values]);\n }\n\n doGet(): U[] {\n throw new Error(`${this.#m2m.entity}.${this.#m2m.fieldName}.get was called when not loaded`);\n }\n\n find(id: IdOf<U>): U | undefined {\n return this.#added.find((u) => u.id === id);\n }\n\n includesInMemory(other: U): boolean | undefined {\n if (this.#added.includes(other)) return true;\n return undefined;\n }\n\n applyLoad(dbEntities: U[]): LoadedState<T, U> {\n const loaded = [...dbEntities];\n for (const e of this.#added) {\n if (!loaded.includes(e)) {\n loaded.unshift(e);\n this.#m2m.registerJoinRowAdd(e);\n }\n }\n for (const e of this.#removed) {\n remove(loaded, e);\n this.#m2m.registerJoinRowRemove(e);\n }\n return new LoadedState<T, U>(this.#m2m, loaded, false);\n }\n\n current(_opts?: { withDeleted?: boolean }): U[] {\n return this.#added;\n }\n\n import(m2m: ManyToManyCollection<T, U>, mapEntities: (e: U[] | undefined) => U[] | undefined): M2MState<T, U> {\n const added = mapEntities(this.#added);\n const removed = mapEntities(this.#removed);\n return new UnloadedAddedRemovedState<T, U>(m2m, added ?? [], removed ?? []);\n }\n}\n\n/** State when set() called before load - holds pending values to diff on load. */\nclass PendingSetState<T extends Entity, U extends Entity> implements M2MState<T, U> {\n readonly isLoaded = false;\n readonly hasBeenSet = true;\n #m2m: ManyToManyCollection<T, U>;\n #pendingSet: U[];\n\n constructor(m2m: ManyToManyCollection<T, U>, pendingSet: U[]) {\n this.#m2m = m2m;\n this.#pendingSet = pendingSet;\n getEmInternalApi(m2m.entity.em).pendingLoads.add(m2m);\n }\n\n add(other: U, percolated: boolean): M2MState<T, U> {\n if (!this.#pendingSet.includes(other)) {\n this.#pendingSet.push(other);\n }\n if (!percolated) {\n this.#m2m.registerJoinRowAdd(other);\n this.#m2m.percolateAdd(other);\n }\n return this;\n }\n\n remove(other: U, percolated: boolean): M2MState<T, U> {\n if (!percolated) {\n this.#m2m.registerJoinRowRemove(other);\n this.#m2m.percolateRemove(other);\n }\n remove(this.#pendingSet, other);\n return this;\n }\n\n set(values: readonly U[]): M2MState<T, U> {\n this.#pendingSet = [...values];\n return this;\n }\n\n doGet(): U[] {\n return this.#pendingSet;\n }\n\n find(id: IdOf<U>): U | undefined {\n return this.#pendingSet.find((u) => u.id === id);\n }\n\n includesInMemory(other: U): boolean | undefined {\n return this.#pendingSet.includes(other);\n }\n\n applyLoad(dbEntities: U[]): LoadedState<T, U> {\n const loaded = [...dbEntities];\n const pending = this.#pendingSet;\n for (const other of [...loaded]) {\n if (!pending.includes(other)) {\n remove(loaded, other);\n this.#m2m.registerJoinRowRemove(other);\n this.#m2m.percolateRemove(other);\n }\n }\n for (const other of pending) {\n if (!loaded.includes(other)) {\n loaded.push(other);\n this.#m2m.registerJoinRowAdd(other);\n this.#m2m.percolateAdd(other);\n }\n }\n return new LoadedState<T, U>(this.#m2m, loaded, true);\n }\n\n current(_opts?: { withDeleted?: boolean }): U[] {\n return this.#pendingSet;\n }\n\n import(m2m: ManyToManyCollection<T, U>, mapEntities: (e: U[] | undefined) => U[] | undefined): M2MState<T, U> {\n const pendingSet = mapEntities(this.#pendingSet);\n return new PendingSetState<T, U>(m2m, pendingSet ?? []);\n }\n}\n\n/** State when collection is loaded - all operations work directly on loaded array. */\nclass LoadedState<T extends Entity, U extends Entity> implements M2MState<T, U> {\n readonly isLoaded = true;\n #m2m: ManyToManyCollection<T, U>;\n #loaded: U[];\n #hasBeenSet: boolean;\n\n constructor(m2m: ManyToManyCollection<T, U>, loaded: U[], hasBeenSet: boolean) {\n this.#m2m = m2m;\n this.#loaded = loaded;\n this.#hasBeenSet = hasBeenSet;\n }\n\n get hasBeenSet(): boolean {\n return this.#hasBeenSet;\n }\n\n add(other: U, percolated: boolean): M2MState<T, U> {\n if (this.#loaded.includes(other)) return this;\n this.#loaded.push(other);\n if (!percolated) {\n this.#m2m.registerJoinRowAdd(other);\n this.#m2m.percolateAdd(other);\n }\n return this;\n }\n\n remove(other: U, percolated: boolean): M2MState<T, U> {\n if (!percolated) {\n this.#m2m.registerJoinRowRemove(other);\n this.#m2m.percolateRemove(other);\n }\n remove(this.#loaded, other);\n return this;\n }\n\n set(values: readonly U[]): M2MState<T, U> {\n this.#hasBeenSet = true;\n const loaded = new Set(this.#loaded);\n const valuesSet = new Set(values);\n for (const other of loaded) {\n if (!valuesSet.has(other)) {\n this.remove(other, false);\n }\n }\n for (const other of values) {\n if (!loaded.has(other)) {\n this.add(other, false);\n }\n }\n return this;\n }\n\n doGet(): U[] {\n return this.#loaded;\n }\n\n find(id: IdOf<U>): U | undefined {\n return this.#loaded.find((u) => u.id === id);\n }\n\n includesInMemory(other: U): boolean | undefined {\n return this.#loaded.includes(other);\n }\n\n applyLoad(dbEntities: U[]): LoadedState<T, U> {\n this.#loaded = dbEntities;\n return this;\n }\n\n current(_opts?: { withDeleted?: boolean }): U[] {\n return this.#loaded;\n }\n\n import(m2m: ManyToManyCollection<T, U>, mapEntities: (e: U[] | undefined) => U[] | undefined): M2MState<T, U> {\n const loaded = mapEntities(this.#loaded);\n return new LoadedState<T, U>(m2m, loaded ?? [], this.#hasBeenSet);\n }\n\n getLoaded(): U[] {\n return this.#loaded;\n }\n\n setLoaded(entities: U[]): void {\n this.#loaded = entities;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAuBA,SAAgB,gBAAsE;CACpF,OAAO,WAAW,QAAW,cAAc;EACzC,MAAM,MAAM,YAAY,MAAM,CAAC,CAAC,UAAU;EAC1C,OAAO,IAAI,qBAA2B,QAAQ,GAAG;CACnD,CAAC;AACH;AAEA,IAAa,uBAAb,cACU,qBAEV;CACE;CACA;CACA;CAOA,YAAY,QAAW,OAAwB;EAC7C,MAAM,MAAM;EACZ,KAAK,SAAS;EACd,IAAI,gBAAgB,MAAM,CAAC,CAAC,YAC1B,KAAK,SAAS,IAAI,YAAkB,MAAM,CAAC,GAAG,KAAK;OAEnD,KAAK,SAAS,IAAI,sBAA4B,IAAI;CAEtD;;CAGA,aAAa,OAAgB;EAC3B,MAAO,KAAK,eAAe,CAAuC,IAAI,KAAK,QAAQ,IAAI;CACzF;;CAGA,gBAAgB,OAAgB;EAC9B,MAAO,KAAK,eAAe,CAAuC,OAAO,KAAK,QAAQ,IAAI;CAC5F;;CAGA,mBAAmB,OAAgB;EACjC,iBAAiB,KAAK,OAAO,EAAE,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,OAAO,MAAM,KAAK,QAAQ,KAAK;CACjF;;CAGA,sBAAsB,OAAgB;EACpC,iBAAiB,KAAK,OAAO,EAAE,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,U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EACzC,KAAK,QAAQ,KAAK,KAAK;EACvB,IAAI,CAAC,YAAY;GACf,KAAK,KAAK,mBAAmB,KAAK;GAClC,KAAK,KAAK,aAAa,KAAK;EAC9B;EACA,OAAO;CACT;CAEA,OAAO,OAAU,YAAqC;EACpD,IAAI,CAAC,YAAY;GACf,KAAK,KAAK,sBAAsB,KAAK;GACrC,KAAK,KAAK,gBAAgB,KAAK;EACjC;EACA,OAAO,KAAK,SAAS,KAAK;EAC1B,OAAO;CACT;CAEA,IAAI,QAAsC;EACxC,KAAK,cAAc;EACnB,MAAM,SAAS,IAAI,IAAI,KAAK,OAAO;EACnC,MAAM,YAAY,IAAI,IAAI,MAAM;EAChC,KAAK,MAAM,SAAS,QAClB,IAAI,CAAC,UAAU,IAAI,KAAK,GACtB,KAAK,OAAO,OAAO,KAAK;EAG5B,KAAK,MAAM,SAAS,QAClB,IAAI,CAAC,OAAO,IAAI,KAAK,GACnB,KAAK,IAAI,OAAO,KAAK;EAGzB,OAAO;CACT;CAEA,QAAa;EACX,OAAO,KAAK;CACd;CAEA,KAAK,IAA4B;EAC/B,OAAO,KAAK,QAAQ,MAAM,MAAM,EAAE,OAAO,EAAE;CAC7C;CAEA,iBAAiB,OAA+B;EAC9C,OAAO,KAAK,QAAQ,SAAS,KAAK;CACpC;CAEA,UAAU,YAAoC;EAC5C,KAAK,UAAU;EACf,OAAO;CACT;CAEA,QAAQ,OAAwC;EAC9C,OAAO,KAAK;CACd;CAEA,OAAO,KAAiC,aAAsE;EAC5G,MAAM,SAAS,YAAY,KAAK,OAAO;EACvC,OAAO,IAAI,YAAkB,KAAK,UAAU,CAAC,GAAG,KAAK,WAAW;CAClE;CAEA,YAAiB;EACf,OAAO,KAAK;CACd;CAEA,UAAU,UAAqB;EAC7B,KAAK,UAAU;CACjB;AACF"}
@@ -5,8 +5,8 @@ import { IdOf } from "../EntityManager.cjs";
5
5
  import { Entity } from "../Entity.cjs";
6
6
  //#region src/relations/ManyToManyLargeCollection.d.ts
7
7
  /** An alias for creating `ManyToManyLargeCollection`s. */
8
- declare function hasLargeManyToMany<T extends Entity, U extends Entity>(joinTableName: string, columnName: string, otherFieldName: keyof U & string, otherColumnName: string, hasJoinTableId: boolean): LargeCollection<T, U>;
9
- declare class ManyToManyLargeCollection<T extends Entity, U extends Entity> implements LargeCollection<T, U> {
8
+ export declare function hasLargeManyToMany<T extends Entity, U extends Entity>(joinTableName: string, columnName: string, otherFieldName: keyof U & string, otherColumnName: string, hasJoinTableId: boolean): LargeCollection<T, U>;
9
+ export declare class ManyToManyLargeCollection<T extends Entity, U extends Entity> implements LargeCollection<T, U> {
10
10
  joinTableName: string;
11
11
  entity: T;
12
12
  fieldName: keyof T & string;
@@ -30,5 +30,4 @@ declare class ManyToManyLargeCollection<T extends Entity, U extends Entity> impl
30
30
  [RelationU]: U;
31
31
  }
32
32
  //#endregion
33
- export { ManyToManyLargeCollection, hasLargeManyToMany };
34
33
  //# sourceMappingURL=ManyToManyLargeCollection.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ManyToManyLargeCollection.d.cts","names":[],"sources":["../../src/relations/ManyToManyLargeCollection.ts"],"mappings":";;;;;;;iBAWgB,mBAAmB,UAAU,QAAQ,UAAU,QAC7D,uBACA,oBACA,sBAAsB,YACtB,yBACA,0BACC,gBAAgB,GAAG;cAiBT,0BAA0B,UAAU,QAAQ,UAAU,mBAAmB,gBAAgB,GAAG;EAO9F;EAMA,QAAQ;EACR,iBAAiB;EACjB;EACA,WAAW;EACX,sBAAsB;EACtB;EACA;UAhBD;UACA;EAER,YACS,uBAMA,QAAQ,GACR,iBAAiB,YACjB,oBACA,WAAW,gBACX,sBAAsB,YACtB,yBACA;EAGH,KAAK,IAAI,KAAK,KAAK,QAAQ;EA8B3B,SAAS,OAAO,IAAI;EAwB1B,IAAI,OAAO;EAQX,OAAO,OAAO;MAQV;MAIO,QAAQ;EAIZ;EAIP;GAEC,YAAY;GACZ,YAAY"}
1
+ {"version":3,"file":"ManyToManyLargeCollection.d.cts","names":[],"sources":["../../src/relations/ManyToManyLargeCollection.ts"],"mappings":";;;;;;;wBAWgB,mBAAmB,UAAU,QAAQ,UAAU,QAC7D,uBACA,oBACA,sBAAsB,YACtB,yBACA,0BACC,gBAAgB,GAAG;qBAiBT,0BAA0B,UAAU,QAAQ,UAAU,mBAAmB,gBAAgB,GAAG;EAO9F;EAMA,QAAQ;EACR,iBAAiB;EACjB;EACA,WAAW;EACX,sBAAsB;EACtB;EACA;UAhBD;UACA;EAER,YACS,uBAMA,QAAQ,GACR,iBAAiB,YACjB,oBACA,WAAW,gBACX,sBAAsB,YACtB,yBACA;EAGH,KAAK,IAAI,KAAK,KAAK,QAAQ;EA8B3B,SAAS,OAAO,IAAI;EAwB1B,IAAI,OAAO;EAQX,OAAO,OAAO;MAQV;MAIO,QAAQ;EAIZ;EAIP;GAEC,YAAY;GACZ,YAAY"}
@@ -5,8 +5,8 @@ import { IdOf } from "../EntityManager.mjs";
5
5
  import { Entity } from "../Entity.mjs";
6
6
  //#region src/relations/ManyToManyLargeCollection.d.ts
7
7
  /** An alias for creating `ManyToManyLargeCollection`s. */
8
- declare function hasLargeManyToMany<T extends Entity, U extends Entity>(joinTableName: string, columnName: string, otherFieldName: keyof U & string, otherColumnName: string, hasJoinTableId: boolean): LargeCollection<T, U>;
9
- declare class ManyToManyLargeCollection<T extends Entity, U extends Entity> implements LargeCollection<T, U> {
8
+ export declare function hasLargeManyToMany<T extends Entity, U extends Entity>(joinTableName: string, columnName: string, otherFieldName: keyof U & string, otherColumnName: string, hasJoinTableId: boolean): LargeCollection<T, U>;
9
+ export declare class ManyToManyLargeCollection<T extends Entity, U extends Entity> implements LargeCollection<T, U> {
10
10
  joinTableName: string;
11
11
  entity: T;
12
12
  fieldName: keyof T & string;
@@ -30,5 +30,4 @@ declare class ManyToManyLargeCollection<T extends Entity, U extends Entity> impl
30
30
  [RelationU]: U;
31
31
  }
32
32
  //#endregion
33
- export { ManyToManyLargeCollection, hasLargeManyToMany };
34
33
  //# sourceMappingURL=ManyToManyLargeCollection.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ManyToManyLargeCollection.d.mts","names":[],"sources":["../../src/relations/ManyToManyLargeCollection.ts"],"mappings":";;;;;;;iBAWgB,mBAAmB,UAAU,QAAQ,UAAU,QAC7D,uBACA,oBACA,sBAAsB,YACtB,yBACA,0BACC,gBAAgB,GAAG;cAiBT,0BAA0B,UAAU,QAAQ,UAAU,mBAAmB,gBAAgB,GAAG;EAO9F;EAMA,QAAQ;EACR,iBAAiB;EACjB;EACA,WAAW;EACX,sBAAsB;EACtB;EACA;UAhBD;UACA;EAER,YACS,uBAMA,QAAQ,GACR,iBAAiB,YACjB,oBACA,WAAW,gBACX,sBAAsB,YACtB,yBACA;EAGH,KAAK,IAAI,KAAK,KAAK,QAAQ;EA8B3B,SAAS,OAAO,IAAI;EAwB1B,IAAI,OAAO;EAQX,OAAO,OAAO;MAQV;MAIO,QAAQ;EAIZ;EAIP;GAEC,YAAY;GACZ,YAAY"}
1
+ {"version":3,"file":"ManyToManyLargeCollection.d.mts","names":[],"sources":["../../src/relations/ManyToManyLargeCollection.ts"],"mappings":";;;;;;;wBAWgB,mBAAmB,UAAU,QAAQ,UAAU,QAC7D,uBACA,oBACA,sBAAsB,YACtB,yBACA,0BACC,gBAAgB,GAAG;qBAiBT,0BAA0B,UAAU,QAAQ,UAAU,mBAAmB,gBAAgB,GAAG;EAO9F;EAMA,QAAQ;EACR,iBAAiB;EACjB;EACA,WAAW;EACX,sBAAsB;EACtB;EACA;UAhBD;UACA;EAER,YACS,uBAMA,QAAQ,GACR,iBAAiB,YACjB,oBACA,WAAW,gBACX,sBAAsB,YACtB,yBACA;EAGH,KAAK,IAAI,KAAK,KAAK,QAAQ;EA8B3B,SAAS,OAAO,IAAI;EAwB1B,IAAI,OAAO;EAQX,OAAO,OAAO;MAQV;MAIO,QAAQ;EAIZ;EAIP;GAEC,YAAY;GACZ,YAAY"}
@@ -1 +1 @@
1
- {"version":3,"file":"ManyToOneReference.cjs","names":["lazyField","getMetadata","AbstractRelationImpl","#field","#state","getInstanceData","isEntity","#loadPromise","sameEntity","#setImpl","toTaggedId","setField","#percolateRemove","#percolateAdd","toIdOf","maybeResolveReferenceToId","deTagId","#hasBeenSet","ensureTagged","OneToManyCollection","OneToManyLargeCollection","OneToOneReferenceImpl","getEmInternalApi","getField","isCascadeDelete","RelationT","RelationU","ReferenceN","BaseEntity","NoIdError","#m2o","#loaded"],"sources":["../../src/relations/ManyToOneReference.ts"],"sourcesContent":["import { type Entity, isEntity } from \"src/Entity.ts\";\nimport { type IdOf, type TaggedId, getEmInternalApi, sameEntity } from \"src/EntityManager.ts\";\nimport { type EntityMetadata, type ManyToOneField, getMetadata } from \"src/EntityMetadata.ts\";\nimport { getField, setField } from \"src/fields.ts\";\nimport {\n BaseEntity,\n NoIdError,\n OneToManyLargeCollection,\n OneToOneReferenceImpl,\n type Reference,\n deTagId,\n ensureNotDeleted,\n ensureTagged,\n fail,\n getInstanceData,\n maybeResolveReferenceToId,\n toIdOf,\n toTaggedId,\n} from \"src/index.ts\";\nimport { lazyField } from \"src/newEntity.ts\";\nimport { AbstractRelationImpl } from \"src/relations/AbstractRelationImpl.ts\";\nimport { isCascadeDelete } from \"src/relations/isCascadeDelete.ts\";\nimport { OneToManyCollection } from \"src/relations/OneToManyCollection.ts\";\nimport { ReferenceN } from \"src/relations/ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"src/relations/RelationSymbols.ts\";\nimport { maybeAdd, maybeRemove } from \"src/utils.ts\";\n\n/** An alias for creating `ManyToOneReference`s. */\nexport function hasOne<T extends Entity, U extends Entity, N extends never | undefined>(): ManyToOneReference<T, U, N> {\n return lazyField((entity: T, fieldName) => {\n const m2o = getMetadata(entity).allFields[fieldName] as ManyToOneField;\n return new ManyToOneReferenceImpl<T, U, N>(entity, m2o);\n });\n}\n\n/** Type guard utility for determining if an entity field is a ManyToOneReference. */\nexport function isManyToOneReference(maybeReference: any): maybeReference is ManyToOneReference<any, any, any> {\n return maybeReference instanceof ManyToOneReferenceImpl;\n}\n\nexport interface ManyToOneReference<T extends Entity, U extends Entity, N extends never | undefined> extends Reference<\n T,\n U,\n N\n> {\n /** Returns the id of the current assigned entity, or a runtime error if either 1) unset or 2) set to a new entity that doesn't have an `id` yet. */\n id: IdOf<U>;\n\n /** Returns the id of the current assigned entity, undefined if unset, or a runtime error if set to a new entity. */\n idIfSet: IdOf<U> | undefined;\n\n /** Returns the id of the current assigned entity, undefined if unset, or undefined if set to a new entity. */\n idMaybe: IdOf<U> | undefined;\n\n idUntagged: string;\n\n idUntaggedIfSet: string | undefined;\n\n /** Returns `true` if this relation is currently set (i.e. regardless of whether it's loaded, or if it is set but the assigned entity doesn't have an id saved. */\n readonly isSet: boolean;\n}\n\n/**\n * Manages a foreign key from one entity to another, i.e. `Book.author --> Author`.\n *\n * We keep the current `author` / `author_id` value in the `__orm.data` hash, where the\n * current value could be either the (string) author id from the database, or an entity\n * `Author` that the user has set.\n *\n * Note that if our `images.author_id` column is unique, this `ManyToOneReference` will essentially\n * be half of a one-to-one relationship, but we'll keep using this `ManyToOneReference` on the \"many\"\n * side, and the other side, i.e. `Author.image` will use a `OneToOneReference` to point back to us.\n */\nexport class ManyToOneReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined>\n extends AbstractRelationImpl<T, U>\n implements ManyToOneReference<T, U, N>\n{\n readonly #field: ManyToOneField;\n #state: M2OState<U, N>;\n #loadPromise: Promise<void> | undefined;\n #hasBeenSet = false;\n\n constructor(entity: T, field: ManyToOneField) {\n super(entity);\n this.#field = field;\n this.#state = getInstanceData(entity).isOrWasNew\n ? new M2OLoadedState<U, N>(this, undefined)\n : new M2OUnloadedState<U, N>(this);\n }\n\n async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<U | N> {\n ensureNotDeleted(this.entity, \"pending\");\n this.#state = this.#state.maybeInstantLoad();\n if (!this.#state.isLoaded || opts.forceReload) {\n const current = this.current();\n if (isEntity(current) || current === undefined) {\n this.#state = new M2OLoadedState<U, N>(this, current as U | N | undefined);\n } else {\n await (this.#loadPromise ??= this.entity.em.load(this.otherMeta.cstr, current).then((entity) => {\n this.#loadPromise = undefined;\n // In extremely rare cases, someone might have called `set` while this promise was in-flight,\n // so make sure our current value is still the same as the fetched entity.\n if (sameEntity(entity, this.current())) {\n this.#state = this.#state.applyLoad(entity);\n }\n }));\n }\n }\n return this.filterDeleted(this.#state.doGet() as U | N, opts);\n }\n\n set(other: U | N): void {\n this.#setImpl(other);\n }\n\n get isSet(): boolean {\n return this.current() !== undefined;\n }\n\n get isLoaded(): boolean {\n // Even if `.load()` has not been called, `.get` will detect\n this.#state = this.#state.maybeInstantLoad();\n return this.#state.isLoaded;\n }\n\n get isPreloaded(): boolean {\n return !!this.maybeFindEntity();\n }\n\n preload(): void {\n this.#state = new M2OLoadedState<U, N>(this, this.maybeFindEntity());\n }\n\n private unload(): void {\n this.#state = new M2OUnloadedState<U, N>(this);\n this.#loadPromise = undefined;\n }\n\n /** Copy another em's `source` relation into our state. */\n import(source: ManyToOneReferenceImpl<T, U, N>, findEntity: (e: U) => U): void {\n this.#state = source.#state.import(this, findEntity);\n }\n\n private doGet(opts?: { withDeleted?: boolean }): U | N {\n ensureNotDeleted(this.entity, \"pending\");\n this.#state = this.#state.maybeInstantLoad();\n return this.filterDeleted(this.#state.doGet() as U | N, opts);\n }\n\n get getWithDeleted(): U | N {\n return this.doGet({ withDeleted: true });\n }\n\n get get(): U | N {\n return this.doGet({ withDeleted: false });\n }\n\n /** Returns the id of the current value. */\n get id(): IdOf<U> {\n return this.idMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n /** Sets the m2o to `id`, and allows accepting `undefined` (`N`) if this is a nullable relation. */\n set id(id: IdOf<U> | N) {\n ensureNotDeleted(this.entity, \"pending\");\n const newId = toTaggedId(this.otherMeta, id);\n\n const previousId = this.idTaggedMaybe;\n const previous = this.maybeFindEntity();\n const changed = setField(this.entity, this.fieldName, id);\n if (!changed) {\n return;\n }\n\n const loaded = newId ? (this.entity.em.getEntity(newId) as U) : undefined;\n this.#state = loaded ? new M2OLoadedState<U, N>(this, loaded) : new M2OUnloadedState<U, N>(this);\n this.#loadPromise = undefined;\n this.#percolateRemove(previousId, previous);\n this.#percolateAdd();\n }\n\n get idIfSet(): IdOf<U> | N | undefined {\n return this.idMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get idUntagged(): string {\n return this.idUntaggedMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idUntaggedIfSet(): string | undefined {\n return this.idUntaggedMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get idMaybe(): IdOf<U> | N | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return toIdOf(this.otherMeta, this.idTaggedMaybe);\n }\n\n /** Returns the tagged id of the current value, or undefined if unset or a new entity. */\n get idTaggedMaybe(): TaggedId | undefined {\n // Skip the deleted check so that `isPreloaded` doesn't blow up during em.refreshes/populates\n // ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current());\n }\n\n get fieldName(): string {\n return this.#field.fieldName;\n }\n\n get otherFieldName(): keyof U & string {\n return this.#field.otherFieldName as keyof U & string;\n }\n\n private get idUntaggedMaybe(): string | undefined {\n return deTagId(this.otherMeta, this.idMaybe);\n }\n\n #setImpl(_other: U | IdOf<U> | N): void {\n ensureNotDeleted(this.entity, \"pending\");\n this.#hasBeenSet = true;\n\n // If the project is not using tagged ids, we still want it tagged internally\n const other = ensureTagged(this.otherMeta, _other);\n if (sameEntity(other, this.current({ withDeleted: true }))) {\n return;\n }\n\n const previousId = this.idTaggedMaybe;\n const previous = this.maybeFindEntity();\n // Prefer to keep the id in our data hash, but if this is a new entity w/o an id, use the entity itself\n setField(this.entity, this.fieldName, isEntity(other) ? (other?.idTaggedMaybe ?? other) : other);\n\n // Setting to an entity | undefined => loaded, setting to an id might reverse to unloaded\n const maybeEntity = isEntity(other) ? (other as U) : other ? this.entity.em.getEntity(other) : undefined;\n if (maybeEntity || other === undefined) {\n this.#state = new M2OLoadedState<U, N>(this, (maybeEntity ?? other) as U | N);\n } else {\n this.#state = new M2OUnloadedState<U, N>(this);\n }\n this.#loadPromise = undefined;\n this.#percolateRemove(previousId, previous);\n this.#percolateAdd();\n }\n\n // private impl\n\n setFromOpts(other: U | IdOf<U> | N): void {\n this.#setImpl(other);\n }\n\n maybeCascadeDelete(): void {\n if (this.isCascadeDelete) {\n const current = this.current({ withDeleted: true });\n if (current !== undefined) {\n if (typeof current === \"string\") {\n // We're invoked twice, once sync on em.delete, and again in em.flush when we're loaded;\n // but even when loaded, current might still be the tagged id, but we can find the entity in the EM\n const other = this.entity.em.getEntity(current);\n if (other) this.entity.em.delete(other as U);\n } else {\n this.entity.em.delete(current as U);\n }\n }\n }\n }\n\n async cleanupOnEntityDeleted(): Promise<void> {\n // if we are going to delete this relation as well, then we don't need to clean it up\n if (this.isCascadeDelete) return;\n const current = await this.load({ withDeleted: true });\n if (current !== undefined) {\n const o2m = this.getOtherRelation(current);\n if (o2m instanceof OneToManyCollection) {\n o2m.remove(this.entity, { requireLoaded: false });\n } else if (o2m instanceof OneToManyLargeCollection) {\n o2m.remove(this.entity);\n } else if (o2m instanceof OneToOneReferenceImpl) {\n o2m.set(undefined as any);\n } else {\n throw new Error(`Unhandled ${o2m}`);\n }\n }\n setField(this.entity, this.fieldName, undefined);\n this.#state = new M2OLoadedState<U, N>(this, undefined as any);\n }\n\n // Called on `book.author.set(...)` with our previous value, to percolate a `author.books.remove`. */\n #percolateRemove(prevId: string | undefined, prevEntity: U | undefined) {\n if (prevEntity) {\n const prevRelation = this.getOtherRelation(prevEntity);\n if (prevRelation instanceof OneToManyCollection) {\n prevRelation.removeIfLoaded(this.entity);\n } else if (prevRelation instanceof OneToManyLargeCollection) {\n prevRelation.remove(this.entity);\n } else {\n prevRelation.set(undefined as any, { percolating: true });\n }\n } else if (prevId) {\n // prevEntity is not loaded in memory, but cache it in case our other side is later loaded\n const { em } = this.entity;\n let map = getEmInternalApi(em).pendingPercolate.get(prevId);\n if (!map) {\n map = new Map();\n getEmInternalApi(em).pendingPercolate.set(prevId, map);\n }\n let pending = map.get(this.otherFieldName);\n if (!pending) {\n pending = { adds: [], removes: [] };\n map.set(this.otherFieldName, pending);\n }\n maybeAdd(pending.removes, this.entity);\n maybeRemove(pending.adds, this.entity);\n }\n }\n\n #percolateAdd() {\n const id = this.current();\n const other = this.maybeFindEntity();\n if (other) {\n // Other is already loaded in memory, immediately hook it up\n const newRelation = this.getOtherRelation(other);\n if (newRelation instanceof OneToManyCollection) {\n newRelation.add(this.entity);\n } else if (newRelation instanceof OneToManyLargeCollection) {\n newRelation.add(this.entity);\n } else if (newRelation) {\n newRelation.set(this.entity, { percolating: true });\n } else {\n // Something is wrong, we should always have a relation, but instead\n // of blowing up here, let this finish b/c it will probably turn into\n // a validation error.\n }\n } else if (typeof id === \"string\") {\n // Other is not loaded in memory, but cache it in case our other side is later loaded\n const { em } = this.entity;\n let map = getEmInternalApi(em).pendingPercolate.get(id);\n if (!map) {\n map = new Map();\n getEmInternalApi(em).pendingPercolate.set(id, map);\n }\n let pending = map.get(this.otherFieldName);\n if (!pending) {\n pending = { adds: [], removes: [] };\n map.set(this.otherFieldName, pending);\n }\n maybeAdd(pending.adds, this.entity);\n maybeRemove(pending.removes, this.entity);\n }\n }\n\n // We need to keep U in data[fieldName] to handle entities without an id assigned yet.\n current(opts?: { withDeleted?: boolean }): U | TaggedId | N {\n const current = getField(this.entity, this.fieldName);\n if (current !== undefined && isEntity(current)) {\n return this.filterDeleted(current as U, opts);\n }\n return current;\n }\n\n get otherMeta(): EntityMetadata<U> {\n return this.#field.otherMetadata();\n }\n\n get hasBeenSet(): boolean {\n return this.#hasBeenSet;\n }\n\n public toString(): string {\n return `ManyToOneReference(entity: ${this.entity}, fieldName: ${this.fieldName}, otherType: ${this.otherMeta.type}, otherFieldName: ${this.otherFieldName}, id: ${this.idMaybe})`;\n }\n\n /**\n * Removes pending-hard-delete (but not soft-deleted), unless explicitly asked for.\n *\n * Note that we leave soft-deleted entities b/c the call signature of a `book.author.get`\n * very likely does not expect a soft-deleted entity to result in `undefined`.\n *\n * (Contrasted with `author.books.get` which is more intuitive to have soft-deleted\n * entities filtered out, i.e. it doesn't fundamentally change the return type.)\n */\n private filterDeleted(entity: U | N, opts?: { withDeleted?: boolean }): U | N {\n if (entity && (!opts || !opts.withDeleted) && entity.isDeletedEntity) {\n return undefined!;\n }\n return entity;\n }\n\n /** Returns the other relation that points back at us, i.e. we're `book.author_id` and this is `Author.books`. */\n private getOtherRelation(\n other: U,\n ): OneToManyCollection<U, T> | OneToOneReferenceImpl<U, T> | OneToManyLargeCollection<U, T> {\n return (other as U)[this.otherFieldName] as any;\n }\n\n private get isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.fieldName);\n }\n\n /**\n * Looks for an entity in `EntityManager`, b/c we may have it in memory even if\n * our reference is not specifically loaded.\n */\n maybeFindEntity(): U | undefined {\n // Check current() first b/c a new entity won't have an id yet\n const current = this.current();\n if (isEntity(current)) return current as U;\n const { idTaggedMaybe } = this;\n return idTaggedMaybe !== undefined ? (this.entity.em.getEntity(idTaggedMaybe) as U) : undefined;\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n [ReferenceN]: N = null!;\n}\n\n/**\n * Fails when we can't return an `.id` for a reference, i.e. it's unset or a new entity.\n *\n * We strictly type `book.author.id` as `AuthorId`, even if `book.author` is nullable, to\n * avoid users calling `.id` and getting back `undefined`, but not because \"there is no\n * author\", but only because \"the assigned author doesn't have an id assigned yet\".\n *\n * To handle nullable references, set `.idIfSet`.\n *\n * Assumes being called like `return idMaybe ?? failNoId()`, i.e. if we're called we\n * know the id is not available.\n */\nexport function failNoId(entity: Entity, fieldName: string, current: string | Entity | undefined): never {\n if (!current) fail(`Reference ${entity}.${fieldName} is unset`);\n // Throw NoIdError, which lets ReactionsManager will handle reactive fields gracefully\n if (current instanceof BaseEntity)\n throw new NoIdError(`Reference ${entity}.${fieldName} is assigned to a new entity`);\n fail(`Unreachable`);\n}\n\n/**\n * Fails when we can't return an `.idIfSet` for a reference, i.e. it's a new entity.\n *\n * Assumes being called like `return idMaybe ?? failIfNewEntity()`, i.e. if we're called we\n * know the id is not available.\n */\nexport function failIfNewEntity(entity: Entity, fieldName: string, current: string | Entity | undefined): undefined {\n if (current instanceof BaseEntity) {\n throw new NoIdError(`Reference ${entity}.${fieldName} is assigned to a new entity`);\n }\n // Since this is a `.idIfSet`, having no `current` is fine, return undefined.\n return undefined;\n}\n\ninterface M2OState<U extends Entity, N extends never | undefined> {\n readonly isLoaded: boolean;\n maybeInstantLoad(): M2OState<U, N>;\n applyLoad(loaded: U | N | undefined): M2OLoadedState<U, N>;\n import(target: ManyToOneReferenceImpl<any, any, any>, findEntity: (e: U) => U): M2OState<U, N>;\n doGet(): U | N | undefined;\n}\n\nclass M2OUnloadedState<U extends Entity, N extends never | undefined> implements M2OState<U, N> {\n readonly isLoaded = false;\n #m2o: ManyToOneReferenceImpl<any, any, any>;\n constructor(m2o: ManyToOneReferenceImpl<any, any, any>) {\n this.#m2o = m2o;\n }\n applyLoad(loaded: U | N | undefined): M2OLoadedState<U, N> {\n return new M2OLoadedState<U, N>(this.#m2o, loaded);\n }\n import(target: ManyToOneReferenceImpl<any, any, any>): M2OState<U, N> {\n return new M2OUnloadedState<U, N>(target);\n }\n maybeInstantLoad(): M2OState<U, N> {\n const current = this.#m2o.current();\n if (current === undefined || isEntity(current)) {\n return new M2OLoadedState<U, N>(this.#m2o, current as U | undefined);\n } else {\n const maybeFound = this.#m2o.entity.em.getEntity(current);\n if (maybeFound) {\n return new M2OLoadedState<U, N>(this.#m2o, maybeFound as U);\n }\n }\n return this;\n }\n doGet(): U | N | undefined {\n throw new Error(`${this.#m2o.entity}.${this.#m2o.fieldName} was not loaded`);\n }\n}\n\n/** The when loaded, with either the loaded entity or undefined. */\nclass M2OLoadedState<U extends Entity, N extends never | undefined> implements M2OState<U, N> {\n readonly isLoaded = true;\n #m2o: ManyToOneReferenceImpl<any, any, any>;\n #loaded: U | N | undefined;\n constructor(m2o: ManyToOneReferenceImpl<any, any, any>, loaded: U | N | undefined) {\n this.#loaded = loaded;\n this.#m2o = m2o;\n }\n applyLoad(loaded: U | N | undefined): M2OLoadedState<U, N> {\n return new M2OLoadedState<U, N>(this.#m2o, loaded);\n }\n import(target: ManyToOneReferenceImpl<any, any, any>, findEntity: (e: U) => U): M2OState<U, N> {\n return new M2OLoadedState<U, N>(target, isEntity(this.#loaded) ? findEntity(this.#loaded) : undefined);\n }\n maybeInstantLoad(): M2OState<U, N> {\n return this;\n }\n doGet(): U | N | undefined {\n return this.#loaded;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,SAAuG;CACrH,OAAOA,kBAAAA,WAAW,QAAW,cAAc;EACzC,MAAM,MAAMC,uBAAAA,YAAY,MAAM,CAAC,CAAC,UAAU;EAC1C,OAAO,IAAI,uBAAgC,QAAQ,GAAG;CACxD,CAAC;AACH;;AAGA,SAAgB,qBAAqB,gBAA0E;CAC7G,OAAO,0BAA0B;AACnC;;;;;;;;;;;;AAmCA,IAAa,yBAAb,cACUC,uCAAAA,qBAEV;CACE;CACA;CACA;CACA,cAAc;CAEd,YAAY,QAAW,OAAuB;EAC5C,MAAM,MAAM;EACZ,KAAKC,SAAS;EACd,KAAKC,SAASC,mBAAAA,gBAAgB,MAAM,CAAC,CAAC,aAClC,IAAI,eAAqB,MAAM,KAAA,CAAS,IACxC,IAAI,iBAAuB,IAAI;CACrC;CAEA,MAAM,KAAK,OAAyD,CAAC,GAAmB;EACtF,cAAA,iBAAiB,KAAK,QAAQ,SAAS;EACvC,KAAKD,SAAS,KAAKA,OAAO,iBAAiB;EAC3C,IAAI,CAAC,KAAKA,OAAO,YAAY,KAAK,aAAa;GAC7C,MAAM,UAAU,KAAK,QAAQ;GAC7B,IAAIE,eAAAA,SAAS,OAAO,KAAK,YAAY,KAA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MAAM,OAAwB;OAC9D;GACL,MAAM,aAAa,KAAKA,KAAK,OAAO,GAAG,UAAU,OAAO;GACxD,IAAI,YACF,OAAO,IAAI,eAAqB,KAAKA,MAAM,UAAe;EAE9D;EACA,OAAO;CACT;CACA,QAA2B;EACzB,MAAM,IAAI,MAAM,GAAG,KAAKA,KAAK,OAAO,GAAG,KAAKA,KAAK,UAAU,gBAAgB;CAC7E;AACF;;AAGA,IAAM,iBAAN,MAAM,eAAwF;CAC5F,WAAoB;CACpB;CACA;CACA,YAAY,KAA4C,QAA2B;EACjF,KAAKC,UAAU;EACf,KAAKD,OAAO;CACd;CACA,UAAU,QAAiD;EACzD,OAAO,IAAI,eAAqB,KAAKA,MAAM,MAAM;CACnD;CACA,OAAO,QAA+C,YAAyC;EAC7F,OAAO,IAAI,eAAqB,QAAQxB,eAAAA,SAAS,KAAKyB,OAAO,IAAI,WAAW,KAAKA,OAAO,IAAI,KAAA,CAAS;CACvG;CACA,mBAAmC;EACjC,OAAO;CACT;CACA,QAA2B;EACzB,OAAO,KAAKA;CACd;AACF"}
1
+ {"version":3,"file":"ManyToOneReference.cjs","names":["lazyField","getMetadata","AbstractRelationImpl","getInstanceData","isEntity","sameEntity","toTaggedId","setField","toIdOf","maybeResolveReferenceToId","deTagId","ensureTagged","OneToManyCollection","OneToManyLargeCollection","OneToOneReferenceImpl","getEmInternalApi","getField","isCascadeDelete","RelationT","RelationU","ReferenceN","BaseEntity","NoIdError"],"sources":["../../src/relations/ManyToOneReference.ts"],"sourcesContent":["import { type Entity, isEntity } from \"src/Entity.ts\";\nimport { type IdOf, type TaggedId, getEmInternalApi, sameEntity } from \"src/EntityManager.ts\";\nimport { type EntityMetadata, type ManyToOneField, getMetadata } from \"src/EntityMetadata.ts\";\nimport { getField, setField } from \"src/fields.ts\";\nimport {\n BaseEntity,\n NoIdError,\n OneToManyLargeCollection,\n OneToOneReferenceImpl,\n type Reference,\n deTagId,\n ensureNotDeleted,\n ensureTagged,\n fail,\n getInstanceData,\n maybeResolveReferenceToId,\n toIdOf,\n toTaggedId,\n} from \"src/index.ts\";\nimport { lazyField } from \"src/newEntity.ts\";\nimport { AbstractRelationImpl } from \"src/relations/AbstractRelationImpl.ts\";\nimport { isCascadeDelete } from \"src/relations/isCascadeDelete.ts\";\nimport { OneToManyCollection } from \"src/relations/OneToManyCollection.ts\";\nimport { ReferenceN } from \"src/relations/ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"src/relations/RelationSymbols.ts\";\nimport { maybeAdd, maybeRemove } from \"src/utils.ts\";\n\n/** An alias for creating `ManyToOneReference`s. */\nexport function hasOne<T extends Entity, U extends Entity, N extends never | undefined>(): ManyToOneReference<T, U, N> {\n return lazyField((entity: T, fieldName) => {\n const m2o = getMetadata(entity).allFields[fieldName] as ManyToOneField;\n return new ManyToOneReferenceImpl<T, U, N>(entity, m2o);\n });\n}\n\n/** Type guard utility for determining if an entity field is a ManyToOneReference. */\nexport function isManyToOneReference(maybeReference: any): maybeReference is ManyToOneReference<any, any, any> {\n return maybeReference instanceof ManyToOneReferenceImpl;\n}\n\nexport interface ManyToOneReference<T extends Entity, U extends Entity, N extends never | undefined> extends Reference<\n T,\n U,\n N\n> {\n /** Returns the id of the current assigned entity, or a runtime error if either 1) unset or 2) set to a new entity that doesn't have an `id` yet. */\n id: IdOf<U>;\n\n /** Returns the id of the current assigned entity, undefined if unset, or a runtime error if set to a new entity. */\n idIfSet: IdOf<U> | undefined;\n\n /** Returns the id of the current assigned entity, undefined if unset, or undefined if set to a new entity. */\n idMaybe: IdOf<U> | undefined;\n\n idUntagged: string;\n\n idUntaggedIfSet: string | undefined;\n\n /** Returns `true` if this relation is currently set (i.e. regardless of whether it's loaded, or if it is set but the assigned entity doesn't have an id saved. */\n readonly isSet: boolean;\n}\n\n/**\n * Manages a foreign key from one entity to another, i.e. `Book.author --> Author`.\n *\n * We keep the current `author` / `author_id` value in the `__orm.data` hash, where the\n * current value could be either the (string) author id from the database, or an entity\n * `Author` that the user has set.\n *\n * Note that if our `images.author_id` column is unique, this `ManyToOneReference` will essentially\n * be half of a one-to-one relationship, but we'll keep using this `ManyToOneReference` on the \"many\"\n * side, and the other side, i.e. `Author.image` will use a `OneToOneReference` to point back to us.\n */\nexport class ManyToOneReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined>\n extends AbstractRelationImpl<T, U>\n implements ManyToOneReference<T, U, N>\n{\n readonly #field: ManyToOneField;\n #state: M2OState<U, N>;\n #loadPromise: Promise<void> | undefined;\n #hasBeenSet = false;\n\n constructor(entity: T, field: ManyToOneField) {\n super(entity);\n this.#field = field;\n this.#state = getInstanceData(entity).isOrWasNew\n ? new M2OLoadedState<U, N>(this, undefined)\n : new M2OUnloadedState<U, N>(this);\n }\n\n async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<U | N> {\n ensureNotDeleted(this.entity, \"pending\");\n this.#state = this.#state.maybeInstantLoad();\n if (!this.#state.isLoaded || opts.forceReload) {\n const current = this.current();\n if (isEntity(current) || current === undefined) {\n this.#state = new M2OLoadedState<U, N>(this, current as U | N | undefined);\n } else {\n await (this.#loadPromise ??= this.entity.em.load(this.otherMeta.cstr, current).then((entity) => {\n this.#loadPromise = undefined;\n // In extremely rare cases, someone might have called `set` while this promise was in-flight,\n // so make sure our current value is still the same as the fetched entity.\n if (sameEntity(entity, this.current())) {\n this.#state = this.#state.applyLoad(entity);\n }\n }));\n }\n }\n return this.filterDeleted(this.#state.doGet() as U | N, opts);\n }\n\n set(other: U | N): void {\n this.#setImpl(other);\n }\n\n get isSet(): boolean {\n return this.current() !== undefined;\n }\n\n get isLoaded(): boolean {\n // Even if `.load()` has not been called, `.get` will detect\n this.#state = this.#state.maybeInstantLoad();\n return this.#state.isLoaded;\n }\n\n get isPreloaded(): boolean {\n return !!this.maybeFindEntity();\n }\n\n preload(): void {\n this.#state = new M2OLoadedState<U, N>(this, this.maybeFindEntity());\n }\n\n private unload(): void {\n this.#state = new M2OUnloadedState<U, N>(this);\n this.#loadPromise = undefined;\n }\n\n /** Copy another em's `source` relation into our state. */\n import(source: ManyToOneReferenceImpl<T, U, N>, findEntity: (e: U) => U): void {\n this.#state = source.#state.import(this, findEntity);\n }\n\n private doGet(opts?: { withDeleted?: boolean }): U | N {\n ensureNotDeleted(this.entity, \"pending\");\n this.#state = this.#state.maybeInstantLoad();\n return this.filterDeleted(this.#state.doGet() as U | N, opts);\n }\n\n get getWithDeleted(): U | N {\n return this.doGet({ withDeleted: true });\n }\n\n get get(): U | N {\n return this.doGet({ withDeleted: false });\n }\n\n /** Returns the id of the current value. */\n get id(): IdOf<U> {\n return this.idMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n /** Sets the m2o to `id`, and allows accepting `undefined` (`N`) if this is a nullable relation. */\n set id(id: IdOf<U> | N) {\n ensureNotDeleted(this.entity, \"pending\");\n const newId = toTaggedId(this.otherMeta, id);\n\n const previousId = this.idTaggedMaybe;\n const previous = this.maybeFindEntity();\n const changed = setField(this.entity, this.fieldName, id);\n if (!changed) {\n return;\n }\n\n const loaded = newId ? (this.entity.em.getEntity(newId) as U) : undefined;\n this.#state = loaded ? new M2OLoadedState<U, N>(this, loaded) : new M2OUnloadedState<U, N>(this);\n this.#loadPromise = undefined;\n this.#percolateRemove(previousId, previous);\n this.#percolateAdd();\n }\n\n get idIfSet(): IdOf<U> | N | undefined {\n return this.idMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get idUntagged(): string {\n return this.idUntaggedMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idUntaggedIfSet(): string | undefined {\n return this.idUntaggedMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get idMaybe(): IdOf<U> | N | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return toIdOf(this.otherMeta, this.idTaggedMaybe);\n }\n\n /** Returns the tagged id of the current value, or undefined if unset or a new entity. */\n get idTaggedMaybe(): TaggedId | undefined {\n // Skip the deleted check so that `isPreloaded` doesn't blow up during em.refreshes/populates\n // ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current());\n }\n\n get fieldName(): string {\n return this.#field.fieldName;\n }\n\n get otherFieldName(): keyof U & string {\n return this.#field.otherFieldName as keyof U & string;\n }\n\n private get idUntaggedMaybe(): string | undefined {\n return deTagId(this.otherMeta, this.idMaybe);\n }\n\n #setImpl(_other: U | IdOf<U> | N): void {\n ensureNotDeleted(this.entity, \"pending\");\n this.#hasBeenSet = true;\n\n // If the project is not using tagged ids, we still want it tagged internally\n const other = ensureTagged(this.otherMeta, _other);\n if (sameEntity(other, this.current({ withDeleted: true }))) {\n return;\n }\n\n const previousId = this.idTaggedMaybe;\n const previous = this.maybeFindEntity();\n // Prefer to keep the id in our data hash, but if this is a new entity w/o an id, use the entity itself\n setField(this.entity, this.fieldName, isEntity(other) ? (other?.idTaggedMaybe ?? other) : other);\n\n // Setting to an entity | undefined => loaded, setting to an id might reverse to unloaded\n const maybeEntity = isEntity(other) ? (other as U) : other ? this.entity.em.getEntity(other) : undefined;\n if (maybeEntity || other === undefined) {\n this.#state = new M2OLoadedState<U, N>(this, (maybeEntity ?? other) as U | N);\n } else {\n this.#state = new M2OUnloadedState<U, N>(this);\n }\n this.#loadPromise = undefined;\n this.#percolateRemove(previousId, previous);\n this.#percolateAdd();\n }\n\n // private impl\n\n setFromOpts(other: U | IdOf<U> | N): void {\n this.#setImpl(other);\n }\n\n maybeCascadeDelete(): void {\n if (this.isCascadeDelete) {\n const current = this.current({ withDeleted: true });\n if (current !== undefined) {\n if (typeof current === \"string\") {\n // We're invoked twice, once sync on em.delete, and again in em.flush when we're loaded;\n // but even when loaded, current might still be the tagged id, but we can find the entity in the EM\n const other = this.entity.em.getEntity(current);\n if (other) this.entity.em.delete(other as U);\n } else {\n this.entity.em.delete(current as U);\n }\n }\n }\n }\n\n async cleanupOnEntityDeleted(): Promise<void> {\n // if we are going to delete this relation as well, then we don't need to clean it up\n if (this.isCascadeDelete) return;\n const current = await this.load({ withDeleted: true });\n if (current !== undefined) {\n const o2m = this.getOtherRelation(current);\n if (o2m instanceof OneToManyCollection) {\n o2m.remove(this.entity, { requireLoaded: false });\n } else if (o2m instanceof OneToManyLargeCollection) {\n o2m.remove(this.entity);\n } else if (o2m instanceof OneToOneReferenceImpl) {\n o2m.set(undefined as any);\n } else {\n throw new Error(`Unhandled ${o2m}`);\n }\n }\n setField(this.entity, this.fieldName, undefined);\n this.#state = new M2OLoadedState<U, N>(this, undefined as any);\n }\n\n // Called on `book.author.set(...)` with our previous value, to percolate a `author.books.remove`. */\n #percolateRemove(prevId: string | undefined, prevEntity: U | undefined) {\n if (prevEntity) {\n const prevRelation = this.getOtherRelation(prevEntity);\n if (prevRelation instanceof OneToManyCollection) {\n prevRelation.removeIfLoaded(this.entity);\n } else if (prevRelation instanceof OneToManyLargeCollection) {\n prevRelation.remove(this.entity);\n } else {\n prevRelation.set(undefined as any, { percolating: true });\n }\n } else if (prevId) {\n // prevEntity is not loaded in memory, but cache it in case our other side is later loaded\n const { em } = this.entity;\n let map = getEmInternalApi(em).pendingPercolate.get(prevId);\n if (!map) {\n map = new Map();\n getEmInternalApi(em).pendingPercolate.set(prevId, map);\n }\n let pending = map.get(this.otherFieldName);\n if (!pending) {\n pending = { adds: [], removes: [] };\n map.set(this.otherFieldName, pending);\n }\n maybeAdd(pending.removes, this.entity);\n maybeRemove(pending.adds, this.entity);\n }\n }\n\n #percolateAdd() {\n const id = this.current();\n const other = this.maybeFindEntity();\n if (other) {\n // Other is already loaded in memory, immediately hook it up\n const newRelation = this.getOtherRelation(other);\n if (newRelation instanceof OneToManyCollection) {\n newRelation.add(this.entity);\n } else if (newRelation instanceof OneToManyLargeCollection) {\n newRelation.add(this.entity);\n } else if (newRelation) {\n newRelation.set(this.entity, { percolating: true });\n } else {\n // Something is wrong, we should always have a relation, but instead\n // of blowing up here, let this finish b/c it will probably turn into\n // a validation error.\n }\n } else if (typeof id === \"string\") {\n // Other is not loaded in memory, but cache it in case our other side is later loaded\n const { em } = this.entity;\n let map = getEmInternalApi(em).pendingPercolate.get(id);\n if (!map) {\n map = new Map();\n getEmInternalApi(em).pendingPercolate.set(id, map);\n }\n let pending = map.get(this.otherFieldName);\n if (!pending) {\n pending = { adds: [], removes: [] };\n map.set(this.otherFieldName, pending);\n }\n maybeAdd(pending.adds, this.entity);\n maybeRemove(pending.removes, this.entity);\n }\n }\n\n // We need to keep U in data[fieldName] to handle entities without an id assigned yet.\n current(opts?: { withDeleted?: boolean }): U | TaggedId | N {\n const current = getField(this.entity, this.fieldName);\n if (current !== undefined && isEntity(current)) {\n return this.filterDeleted(current as U, opts);\n }\n return current;\n }\n\n get otherMeta(): EntityMetadata<U> {\n return this.#field.otherMetadata();\n }\n\n get hasBeenSet(): boolean {\n return this.#hasBeenSet;\n }\n\n public toString(): string {\n return `ManyToOneReference(entity: ${this.entity}, fieldName: ${this.fieldName}, otherType: ${this.otherMeta.type}, otherFieldName: ${this.otherFieldName}, id: ${this.idMaybe})`;\n }\n\n /**\n * Removes pending-hard-delete (but not soft-deleted), unless explicitly asked for.\n *\n * Note that we leave soft-deleted entities b/c the call signature of a `book.author.get`\n * very likely does not expect a soft-deleted entity to result in `undefined`.\n *\n * (Contrasted with `author.books.get` which is more intuitive to have soft-deleted\n * entities filtered out, i.e. it doesn't fundamentally change the return type.)\n */\n private filterDeleted(entity: U | N, opts?: { withDeleted?: boolean }): U | N {\n if (entity && (!opts || !opts.withDeleted) && entity.isDeletedEntity) {\n return undefined!;\n }\n return entity;\n }\n\n /** Returns the other relation that points back at us, i.e. we're `book.author_id` and this is `Author.books`. */\n private getOtherRelation(\n other: U,\n ): OneToManyCollection<U, T> | OneToOneReferenceImpl<U, T> | OneToManyLargeCollection<U, T> {\n return (other as U)[this.otherFieldName] as any;\n }\n\n private get isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.fieldName);\n }\n\n /**\n * Looks for an entity in `EntityManager`, b/c we may have it in memory even if\n * our reference is not specifically loaded.\n */\n maybeFindEntity(): U | undefined {\n // Check current() first b/c a new entity won't have an id yet\n const current = this.current();\n if (isEntity(current)) return current as U;\n const { idTaggedMaybe } = this;\n return idTaggedMaybe !== undefined ? (this.entity.em.getEntity(idTaggedMaybe) as U) : undefined;\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n [ReferenceN]: N = null!;\n}\n\n/**\n * Fails when we can't return an `.id` for a reference, i.e. it's unset or a new entity.\n *\n * We strictly type `book.author.id` as `AuthorId`, even if `book.author` is nullable, to\n * avoid users calling `.id` and getting back `undefined`, but not because \"there is no\n * author\", but only because \"the assigned author doesn't have an id assigned yet\".\n *\n * To handle nullable references, set `.idIfSet`.\n *\n * Assumes being called like `return idMaybe ?? failNoId()`, i.e. if we're called we\n * know the id is not available.\n */\nexport function failNoId(entity: Entity, fieldName: string, current: string | Entity | undefined): never {\n if (!current) fail(`Reference ${entity}.${fieldName} is unset`);\n // Throw NoIdError, which lets ReactionsManager will handle reactive fields gracefully\n if (current instanceof BaseEntity)\n throw new NoIdError(`Reference ${entity}.${fieldName} is assigned to a new entity`);\n fail(`Unreachable`);\n}\n\n/**\n * Fails when we can't return an `.idIfSet` for a reference, i.e. it's a new entity.\n *\n * Assumes being called like `return idMaybe ?? failIfNewEntity()`, i.e. if we're called we\n * know the id is not available.\n */\nexport function failIfNewEntity(entity: Entity, fieldName: string, current: string | Entity | undefined): undefined {\n if (current instanceof BaseEntity) {\n throw new NoIdError(`Reference ${entity}.${fieldName} is assigned to a new entity`);\n }\n // Since this is a `.idIfSet`, having no `current` is fine, return undefined.\n return undefined;\n}\n\ninterface M2OState<U extends Entity, N extends never | undefined> {\n readonly isLoaded: boolean;\n maybeInstantLoad(): M2OState<U, N>;\n applyLoad(loaded: U | N | undefined): M2OLoadedState<U, N>;\n import(target: ManyToOneReferenceImpl<any, any, any>, findEntity: (e: U) => U): M2OState<U, N>;\n doGet(): U | N | undefined;\n}\n\nclass M2OUnloadedState<U extends Entity, N extends never | undefined> implements M2OState<U, N> {\n readonly isLoaded = false;\n #m2o: ManyToOneReferenceImpl<any, any, any>;\n constructor(m2o: ManyToOneReferenceImpl<any, any, any>) {\n this.#m2o = m2o;\n }\n applyLoad(loaded: U | N | undefined): M2OLoadedState<U, N> {\n return new M2OLoadedState<U, N>(this.#m2o, loaded);\n }\n import(target: ManyToOneReferenceImpl<any, any, any>): M2OState<U, N> {\n return new M2OUnloadedState<U, N>(target);\n }\n maybeInstantLoad(): M2OState<U, N> {\n const current = this.#m2o.current();\n if (current === undefined || isEntity(current)) {\n return new M2OLoadedState<U, N>(this.#m2o, current as U | undefined);\n } else {\n const maybeFound = this.#m2o.entity.em.getEntity(current);\n if (maybeFound) {\n return new M2OLoadedState<U, N>(this.#m2o, maybeFound as U);\n }\n }\n return this;\n }\n doGet(): U | N | undefined {\n throw new Error(`${this.#m2o.entity}.${this.#m2o.fieldName} was not loaded`);\n }\n}\n\n/** The when loaded, with either the loaded entity or undefined. */\nclass M2OLoadedState<U extends Entity, N extends never | undefined> implements M2OState<U, N> {\n readonly isLoaded = true;\n #m2o: ManyToOneReferenceImpl<any, any, any>;\n #loaded: U | N | undefined;\n constructor(m2o: ManyToOneReferenceImpl<any, any, any>, loaded: U | N | undefined) {\n this.#loaded = loaded;\n this.#m2o = m2o;\n }\n applyLoad(loaded: U | N | undefined): M2OLoadedState<U, N> {\n return new M2OLoadedState<U, N>(this.#m2o, loaded);\n }\n import(target: ManyToOneReferenceImpl<any, any, any>, findEntity: (e: U) => U): M2OState<U, N> {\n return new M2OLoadedState<U, N>(target, isEntity(this.#loaded) ? findEntity(this.#loaded) : undefined);\n }\n maybeInstantLoad(): M2OState<U, N> {\n return this;\n }\n doGet(): U | N | undefined {\n return this.#loaded;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,SAAuG;CACrH,OAAOA,kBAAAA,WAAW,QAAW,cAAc;EACzC,MAAM,MAAMC,uBAAAA,YAAY,MAAM,CAAC,CAAC,UAAU;EAC1C,OAAO,IAAI,uBAAg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ggedId } from "../EntityManager.cjs";
8
8
  import { Entity } from "../Entity.cjs";
9
9
  //#region src/relations/ManyToOneReference.d.ts
10
10
  /** An alias for creating `ManyToOneReference`s. */
11
- declare function hasOne<T extends Entity, U extends Entity, N extends never | undefined>(): ManyToOneReference<T, U, N>;
11
+ export declare function hasOne<T extends Entity, U extends Entity, N extends never | undefined>(): ManyToOneReference<T, U, N>;
12
12
  /** Type guard utility for determining if an entity field is a ManyToOneReference. */
13
- declare function isManyToOneReference(maybeReference: any): maybeReference is ManyToOneReference<any, any, any>;
14
- interface ManyToOneReference<T extends Entity, U extends Entity, N extends never | undefined> extends Reference<T, U, N> {
13
+ export declare function isManyToOneReference(maybeReference: any): maybeReference is ManyToOneReference<any, any, any>;
14
+ export interface ManyToOneReference<T extends Entity, U extends Entity, N extends never | undefined> extends Reference<T, U, N> {
15
15
  /** Returns the id of the current assigned entity, or a runtime error if either 1) unset or 2) set to a new entity that doesn't have an `id` yet. */
16
16
  id: IdOf<U>;
17
17
  /** Returns the id of the current assigned entity, undefined if unset, or a runtime error if set to a new entity. */
@@ -34,7 +34,7 @@ interface ManyToOneReference<T extends Entity, U extends Entity, N extends never
34
34
  * be half of a one-to-one relationship, but we'll keep using this `ManyToOneReference` on the "many"
35
35
  * side, and the other side, i.e. `Author.image` will use a `OneToOneReference` to point back to us.
36
36
  */
37
- declare class ManyToOneReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined> extends AbstractRelationImpl<T, U> implements ManyToOneReference<T, U, N> {
37
+ export declare class ManyToOneReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined> extends AbstractRelationImpl<T, U> implements ManyToOneReference<T, U, N> {
38
38
  #private;
39
39
  constructor(entity: T, field: ManyToOneField);
40
40
  load(opts?: {
@@ -108,14 +108,13 @@ declare class ManyToOneReferenceImpl<T extends Entity, U extends Entity, N exten
108
108
  * Assumes being called like `return idMaybe ?? failNoId()`, i.e. if we're called we
109
109
  * know the id is not available.
110
110
  */
111
- declare function failNoId(entity: Entity, fieldName: string, current: string | Entity | undefined): never;
111
+ export declare function failNoId(entity: Entity, fieldName: string, current: string | Entity | undefined): never;
112
112
  /**
113
113
  * Fails when we can't return an `.idIfSet` for a reference, i.e. it's a new entity.
114
114
  *
115
115
  * Assumes being called like `return idMaybe ?? failIfNewEntity()`, i.e. if we're called we
116
116
  * know the id is not available.
117
117
  */
118
- declare function failIfNewEntity(entity: Entity, fieldName: string, current: string | Entity | undefined): undefined;
118
+ export declare function failIfNewEntity(entity: Entity, fieldName: string, current: string | Entity | undefined): undefined;
119
119
  //#endregion
120
- export { ManyToOneReference, ManyToOneReferenceImpl, failIfNewEntity, failNoId, hasOne, isManyToOneReference };
121
120
  //# sourceMappingURL=ManyToOneReference.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ManyToOneReference.d.cts","names":[],"sources":["../../src/relations/ManyToOneReference.ts"],"mappings":";;;;;;;;;;iBA4BgB,OAAO,UAAU,QAAQ,UAAU,QAAQ,gCAAgC,mBAAmB,GAAG,GAAG;;iBAQpG,qBAAqB,sBAAsB,kBAAkB;UAI5D,mBAAmB,UAAU,QAAQ,UAAU,QAAQ,qCAAqC,UAC3G,GACA,GACA;;EAGA,IAAI,KAAK;;EAGT,SAAS,KAAK;;EAGd,SAAS,KAAK;EAEd;EAEA;;WAGS;;;;;;;;;;;;;cAcE,uBAAuB,UAAU,QAAQ,UAAU,QAAQ,qCAC9D,qBAAqB,GAAG,cACrB,mBAAmB,GAAG,GAAG;;EAOpC,YAAY,QAAQ,GAAG,OAAO;EAQxB,KAAK;IAAQ;IAAuB;MAA+B,QAAQ,IAAI;EAqBrF,IAAI,OAAO,IAAI;MAIX;MAIA;MAMA;EAIJ;UAIQ;;EAMR,OAAO,QAAQ,uBAAuB,GAAG,GAAG,IAAI,aAAa,GAAG,MAAM;UAI9D;MAMJ,kBAAkB,IAAI;MAItB,OAAO,IAAI;;MAKX,MAAM,KAAK;;MAKX,GAAG,IAAI,KAAK,KAAK;MAkBjB,WAAW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AW,KAAK,KAAK;;MAMrB,iBAAiB;MAMjB;MAIA,wBAAwB;cAIhB;EAiCZ,YAAY,OAAO,IAAI,KAAK,KAAK;EAIjC;EAgBM,0BAA0B;EAqFhC,QAAQ;IAAS;MAA0B,IAAI,WAAW;MAQtD,aAAa,eAAe;MAI5B;EAIG;;;;;;;;;;UAaC;;UAQA;cAMI;;;;;EAQZ,mBAAmB;GAQlB,YAAY;GACZ,YAAY;GACZ,aAAa;;;;;;;;;;;;;;wBAeA,SAAS,QAAQ,QAAQ,mBAAmB,kBAAkB;;;;;;;wBAc9D,gBAAgB,QAAQ,QAAQ,mBAAmB,kBAAkB"}
@@ -8,10 +8,10 @@ import { IdOf, TaggedId } from "../EntityManager.mjs";
8
8
  import { Entity } from "../Entity.mjs";
9
9
  //#region src/relations/ManyToOneReference.d.ts
10
10
  /** An alias for creating `ManyToOneReference`s. */
11
- declare function hasOne<T extends Entity, U extends Entity, N extends never | undefined>(): ManyToOneReference<T, U, N>;
11
+ export declare function hasOne<T extends Entity, U extends Entity, N extends never | undefined>(): ManyToOneReference<T, U, N>;
12
12
  /** Type guard utility for determining if an entity field is a ManyToOneReference. */
13
- declare function isManyToOneReference(maybeReference: any): maybeReference is ManyToOneReference<any, any, any>;
14
- interface ManyToOneReference<T extends Entity, U extends Entity, N extends never | undefined> extends Reference<T, U, N> {
13
+ export declare function isManyToOneReference(maybeReference: any): maybeReference is ManyToOneReference<any, any, any>;
14
+ export interface ManyToOneReference<T extends Entity, U extends Entity, N extends never | undefined> extends Reference<T, U, N> {
15
15
  /** Returns the id of the current assigned entity, or a runtime error if either 1) unset or 2) set to a new entity that doesn't have an `id` yet. */
16
16
  id: IdOf<U>;
17
17
  /** Returns the id of the current assigned entity, undefined if unset, or a runtime error if set to a new entity. */
@@ -34,7 +34,7 @@ interface ManyToOneReference<T extends Entity, U extends Entity, N extends never
34
34
  * be half of a one-to-one relationship, but we'll keep using this `ManyToOneReference` on the "many"
35
35
  * side, and the other side, i.e. `Author.image` will use a `OneToOneReference` to point back to us.
36
36
  */
37
- declare class ManyToOneReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined> extends AbstractRelationImpl<T, U> implements ManyToOneReference<T, U, N> {
37
+ export declare class ManyToOneReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined> extends AbstractRelationImpl<T, U> implements ManyToOneReference<T, U, N> {
38
38
  #private;
39
39
  constructor(entity: T, field: ManyToOneField);
40
40
  load(opts?: {
@@ -108,14 +108,13 @@ declare class ManyToOneReferenceImpl<T extends Entity, U extends Entity, N exten
108
108
  * Assumes being called like `return idMaybe ?? failNoId()`, i.e. if we're called we
109
109
  * know the id is not available.
110
110
  */
111
- declare function failNoId(entity: Entity, fieldName: string, current: string | Entity | undefined): never;
111
+ export declare function failNoId(entity: Entity, fieldName: string, current: string | Entity | undefined): never;
112
112
  /**
113
113
  * Fails when we can't return an `.idIfSet` for a reference, i.e. it's a new entity.
114
114
  *
115
115
  * Assumes being called like `return idMaybe ?? failIfNewEntity()`, i.e. if we're called we
116
116
  * know the id is not available.
117
117
  */
118
- declare function failIfNewEntity(entity: Entity, fieldName: string, current: string | Entity | undefined): undefined;
118
+ export declare function failIfNewEntity(entity: Entity, fieldName: string, current: string | Entity | undefined): undefined;
119
119
  //#endregion
120
- export { ManyToOneReference, ManyToOneReferenceImpl, failIfNewEntity, failNoId, hasOne, isManyToOneReference };
121
120
  //# sourceMappingURL=ManyToOneReference.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ManyToOneReference.d.mts","names":[],"sources":["../../src/relations/ManyToOneReference.ts"],"mappings":";;;;;;;;;;iBA4BgB,OAAO,UAAU,QAAQ,UAAU,QAAQ,gCAAgC,mBAAmB,GAAG,GAAG;;iBAQpG,qBAAqB,sBAAsB,kBAAkB;UAI5D,mBAAmB,UAAU,QAAQ,UAAU,QAAQ,qCAAqC,UAC3G,GACA,GACA;;EAGA,IAAI,KAAK;;EAGT,SAAS,KAAK;;EAGd,SAAS,KAAK;EAEd;EA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AuB,UAAU,QAAQ,UAAU,QAAQ,qCAC9D,qBAAqB,GAAG,cACrB,mBAAmB,GAAG,GAAG;;EAOpC,YAAY,QAAQ,GAAG,OAAO;EAQxB,KAAK;IAAQ;IAAuB;MAA+B,QAAQ,IAAI;EAqBrF,IAAI,OAAO,IAAI;MAIX;MAIA;MAMA;EAIJ;UAIQ;;EAMR,OAAO,QAAQ,uBAAuB,GAAG,GAAG,IAAI,aAAa,GAAG,MAAM;UAI9D;MAMJ,kBAAkB,IAAI;MAItB,OAAO,IAAI;;MAKX,MAAM,KAAK;;MAKX,GAAG,IAAI,KAAK,KAAK;MAkBjB,WAAW,KAAK,KAAK;MAIrB;MAIA;MAIA,WAAW,KAAK,KAAK;;MAMrB,iBAAiB;MAMjB;MAIA,wBAAwB;cAIhB;EAiCZ,YAAY,OAAO,IAAI,KAAK,KAAK;EAIjC;EAgBM,0BAA0B;EAqFhC,QAAQ;IAAS;MAA0B,IAAI,WAAW;MAQtD,aAAa,eAAe;MAI5B;EAIG;;;;;;;;;;UAaC;;UAQA;cAMI;;;;;EAQZ,mBAAmB;GAQlB,YAAY;GACZ,YAAY;GACZ,aAAa;;;;;;;;;;;;;;wBAeA,SAAS,QAAQ,QAAQ,mBAAmB,kBAAkB;;;;;;;wBAc9D,gBAAgB,QAAQ,QAAQ,mBAAmB,kBAAkB"}
@@ -1 +1 @@
1
- {"version":3,"file":"ManyToOneReference.js","names":["#field","#state","#loadPromise","#setImpl","#percolateRemove","#percolateAdd","#hasBeenSet","#m2o","#loaded"],"sources":["../../src/relations/ManyToOneReference.ts"],"sourcesContent":["import { type Entity, isEntity } from \"src/Entity.ts\";\nimport { type IdOf, type TaggedId, getEmInternalApi, sameEntity } from \"src/EntityManager.ts\";\nimport { type EntityMetadata, type ManyToOneField, getMetadata } from \"src/EntityMetadata.ts\";\nimport { getField, setField } from \"src/fields.ts\";\nimport {\n BaseEntity,\n NoIdError,\n OneToManyLargeCollection,\n OneToOneReferenceImpl,\n type Reference,\n deTagId,\n ensureNotDeleted,\n ensureTagged,\n fail,\n getInstanceData,\n maybeResolveReferenceToId,\n toIdOf,\n toTaggedId,\n} from \"src/index.ts\";\nimport { lazyField } from \"src/newEntity.ts\";\nimport { AbstractRelationImpl } from \"src/relations/AbstractRelationImpl.ts\";\nimport { isCascadeDelete } from \"src/relations/isCascadeDelete.ts\";\nimport { OneToManyCollection } from \"src/relations/OneToManyCollection.ts\";\nimport { ReferenceN } from \"src/relations/ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"src/relations/RelationSymbols.ts\";\nimport { maybeAdd, maybeRemove } from \"src/utils.ts\";\n\n/** An alias for creating `ManyToOneReference`s. */\nexport function hasOne<T extends Entity, U extends Entity, N extends never | undefined>(): ManyToOneReference<T, U, N> {\n return lazyField((entity: T, fieldName) => {\n const m2o = getMetadata(entity).allFields[fieldName] as ManyToOneField;\n return new ManyToOneReferenceImpl<T, U, N>(entity, m2o);\n });\n}\n\n/** Type guard utility for determining if an entity field is a ManyToOneReference. */\nexport function isManyToOneReference(maybeReference: any): maybeReference is ManyToOneReference<any, any, any> {\n return maybeReference instanceof ManyToOneReferenceImpl;\n}\n\nexport interface ManyToOneReference<T extends Entity, U extends Entity, N extends never | undefined> extends Reference<\n T,\n U,\n N\n> {\n /** Returns the id of the current assigned entity, or a runtime error if either 1) unset or 2) set to a new entity that doesn't have an `id` yet. */\n id: IdOf<U>;\n\n /** Returns the id of the current assigned entity, undefined if unset, or a runtime error if set to a new entity. */\n idIfSet: IdOf<U> | undefined;\n\n /** Returns the id of the current assigned entity, undefined if unset, or undefined if set to a new entity. */\n idMaybe: IdOf<U> | undefined;\n\n idUntagged: string;\n\n idUntaggedIfSet: string | undefined;\n\n /** Returns `true` if this relation is currently set (i.e. regardless of whether it's loaded, or if it is set but the assigned entity doesn't have an id saved. */\n readonly isSet: boolean;\n}\n\n/**\n * Manages a foreign key from one entity to another, i.e. `Book.author --> Author`.\n *\n * We keep the current `author` / `author_id` value in the `__orm.data` hash, where the\n * current value could be either the (string) author id from the database, or an entity\n * `Author` that the user has set.\n *\n * Note that if our `images.author_id` column is unique, this `ManyToOneReference` will essentially\n * be half of a one-to-one relationship, but we'll keep using this `ManyToOneReference` on the \"many\"\n * side, and the other side, i.e. `Author.image` will use a `OneToOneReference` to point back to us.\n */\nexport class ManyToOneReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined>\n extends AbstractRelationImpl<T, U>\n implements ManyToOneReference<T, U, N>\n{\n readonly #field: ManyToOneField;\n #state: M2OState<U, N>;\n #loadPromise: Promise<void> | undefined;\n #hasBeenSet = false;\n\n constructor(entity: T, field: ManyToOneField) {\n super(entity);\n this.#field = field;\n this.#state = getInstanceData(entity).isOrWasNew\n ? new M2OLoadedState<U, N>(this, undefined)\n : new M2OUnloadedState<U, N>(this);\n }\n\n async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<U | N> {\n ensureNotDeleted(this.entity, \"pending\");\n this.#state = this.#state.maybeInstantLoad();\n if (!this.#state.isLoaded || opts.forceReload) {\n const current = this.current();\n if (isEntity(current) || current === undefined) {\n this.#state = new M2OLoadedState<U, N>(this, current as U | N | undefined);\n } else {\n await (this.#loadPromise ??= this.entity.em.load(this.otherMeta.cstr, current).then((entity) => {\n this.#loadPromise = undefined;\n // In extremely rare cases, someone might have called `set` while this promise was in-flight,\n // so make sure our current value is still the same as the fetched entity.\n if (sameEntity(entity, this.current())) {\n this.#state = this.#state.applyLoad(entity);\n }\n }));\n }\n }\n return this.filterDeleted(this.#state.doGet() as U | N, opts);\n }\n\n set(other: U | N): void {\n this.#setImpl(other);\n }\n\n get isSet(): boolean {\n return this.current() !== undefined;\n }\n\n get isLoaded(): boolean {\n // Even if `.load()` has not been called, `.get` will detect\n this.#state = this.#state.maybeInstantLoad();\n return this.#state.isLoaded;\n }\n\n get isPreloaded(): boolean {\n return !!this.maybeFindEntity();\n }\n\n preload(): void {\n this.#state = new M2OLoadedState<U, N>(this, this.maybeFindEntity());\n }\n\n private unload(): void {\n this.#state = new M2OUnloadedState<U, N>(this);\n this.#loadPromise = undefined;\n }\n\n /** Copy another em's `source` relation into our state. */\n import(source: ManyToOneReferenceImpl<T, U, N>, findEntity: (e: U) => U): void {\n this.#state = source.#state.import(this, findEntity);\n }\n\n private doGet(opts?: { withDeleted?: boolean }): U | N {\n ensureNotDeleted(this.entity, \"pending\");\n this.#state = this.#state.maybeInstantLoad();\n return this.filterDeleted(this.#state.doGet() as U | N, opts);\n }\n\n get getWithDeleted(): U | N {\n return this.doGet({ withDeleted: true });\n }\n\n get get(): U | N {\n return this.doGet({ withDeleted: false });\n }\n\n /** Returns the id of the current value. */\n get id(): IdOf<U> {\n return this.idMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n /** Sets the m2o to `id`, and allows accepting `undefined` (`N`) if this is a nullable relation. */\n set id(id: IdOf<U> | N) {\n ensureNotDeleted(this.entity, \"pending\");\n const newId = toTaggedId(this.otherMeta, id);\n\n const previousId = this.idTaggedMaybe;\n const previous = this.maybeFindEntity();\n const changed = setField(this.entity, this.fieldName, id);\n if (!changed) {\n return;\n }\n\n const loaded = newId ? (this.entity.em.getEntity(newId) as U) : undefined;\n this.#state = loaded ? new M2OLoadedState<U, N>(this, loaded) : new M2OUnloadedState<U, N>(this);\n this.#loadPromise = undefined;\n this.#percolateRemove(previousId, previous);\n this.#percolateAdd();\n }\n\n get idIfSet(): IdOf<U> | N | undefined {\n return this.idMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get idUntagged(): string {\n return this.idUntaggedMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idUntaggedIfSet(): string | undefined {\n return this.idUntaggedMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get idMaybe(): IdOf<U> | N | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return toIdOf(this.otherMeta, this.idTaggedMaybe);\n }\n\n /** Returns the tagged id of the current value, or undefined if unset or a new entity. */\n get idTaggedMaybe(): TaggedId | undefined {\n // Skip the deleted check so that `isPreloaded` doesn't blow up during em.refreshes/populates\n // ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current());\n }\n\n get fieldName(): string {\n return this.#field.fieldName;\n }\n\n get otherFieldName(): keyof U & string {\n return this.#field.otherFieldName as keyof U & string;\n }\n\n private get idUntaggedMaybe(): string | undefined {\n return deTagId(this.otherMeta, this.idMaybe);\n }\n\n #setImpl(_other: U | IdOf<U> | N): void {\n ensureNotDeleted(this.entity, \"pending\");\n this.#hasBeenSet = true;\n\n // If the project is not using tagged ids, we still want it tagged internally\n const other = ensureTagged(this.otherMeta, _other);\n if (sameEntity(other, this.current({ withDeleted: true }))) {\n return;\n }\n\n const previousId = this.idTaggedMaybe;\n const previous = this.maybeFindEntity();\n // Prefer to keep the id in our data hash, but if this is a new entity w/o an id, use the entity itself\n setField(this.entity, this.fieldName, isEntity(other) ? (other?.idTaggedMaybe ?? other) : other);\n\n // Setting to an entity | undefined => loaded, setting to an id might reverse to unloaded\n const maybeEntity = isEntity(other) ? (other as U) : other ? this.entity.em.getEntity(other) : undefined;\n if (maybeEntity || other === undefined) {\n this.#state = new M2OLoadedState<U, N>(this, (maybeEntity ?? other) as U | N);\n } else {\n this.#state = new M2OUnloadedState<U, N>(this);\n }\n this.#loadPromise = undefined;\n this.#percolateRemove(previousId, previous);\n this.#percolateAdd();\n }\n\n // private impl\n\n setFromOpts(other: U | IdOf<U> | N): void {\n this.#setImpl(other);\n }\n\n maybeCascadeDelete(): void {\n if (this.isCascadeDelete) {\n const current = this.current({ withDeleted: true });\n if (current !== undefined) {\n if (typeof current === \"string\") {\n // We're invoked twice, once sync on em.delete, and again in em.flush when we're loaded;\n // but even when loaded, current might still be the tagged id, but we can find the entity in the EM\n const other = this.entity.em.getEntity(current);\n if (other) this.entity.em.delete(other as U);\n } else {\n this.entity.em.delete(current as U);\n }\n }\n }\n }\n\n async cleanupOnEntityDeleted(): Promise<void> {\n // if we are going to delete this relation as well, then we don't need to clean it up\n if (this.isCascadeDelete) return;\n const current = await this.load({ withDeleted: true });\n if (current !== undefined) {\n const o2m = this.getOtherRelation(current);\n if (o2m instanceof OneToManyCollection) {\n o2m.remove(this.entity, { requireLoaded: false });\n } else if (o2m instanceof OneToManyLargeCollection) {\n o2m.remove(this.entity);\n } else if (o2m instanceof OneToOneReferenceImpl) {\n o2m.set(undefined as any);\n } else {\n throw new Error(`Unhandled ${o2m}`);\n }\n }\n setField(this.entity, this.fieldName, undefined);\n this.#state = new M2OLoadedState<U, N>(this, undefined as any);\n }\n\n // Called on `book.author.set(...)` with our previous value, to percolate a `author.books.remove`. */\n #percolateRemove(prevId: string | undefined, prevEntity: U | undefined) {\n if (prevEntity) {\n const prevRelation = this.getOtherRelation(prevEntity);\n if (prevRelation instanceof OneToManyCollection) {\n prevRelation.removeIfLoaded(this.entity);\n } else if (prevRelation instanceof OneToManyLargeCollection) {\n prevRelation.remove(this.entity);\n } else {\n prevRelation.set(undefined as any, { percolating: true });\n }\n } else if (prevId) {\n // prevEntity is not loaded in memory, but cache it in case our other side is later loaded\n const { em } = this.entity;\n let map = getEmInternalApi(em).pendingPercolate.get(prevId);\n if (!map) {\n map = new Map();\n getEmInternalApi(em).pendingPercolate.set(prevId, map);\n }\n let pending = map.get(this.otherFieldName);\n if (!pending) {\n pending = { adds: [], removes: [] };\n map.set(this.otherFieldName, pending);\n }\n maybeAdd(pending.removes, this.entity);\n maybeRemove(pending.adds, this.entity);\n }\n }\n\n #percolateAdd() {\n const id = this.current();\n const other = this.maybeFindEntity();\n if (other) {\n // Other is already loaded in memory, immediately hook it up\n const newRelation = this.getOtherRelation(other);\n if (newRelation instanceof OneToManyCollection) {\n newRelation.add(this.entity);\n } else if (newRelation instanceof OneToManyLargeCollection) {\n newRelation.add(this.entity);\n } else if (newRelation) {\n newRelation.set(this.entity, { percolating: true });\n } else {\n // Something is wrong, we should always have a relation, but instead\n // of blowing up here, let this finish b/c it will probably turn into\n // a validation error.\n }\n } else if (typeof id === \"string\") {\n // Other is not loaded in memory, but cache it in case our other side is later loaded\n const { em } = this.entity;\n let map = getEmInternalApi(em).pendingPercolate.get(id);\n if (!map) {\n map = new Map();\n getEmInternalApi(em).pendingPercolate.set(id, map);\n }\n let pending = map.get(this.otherFieldName);\n if (!pending) {\n pending = { adds: [], removes: [] };\n map.set(this.otherFieldName, pending);\n }\n maybeAdd(pending.adds, this.entity);\n maybeRemove(pending.removes, this.entity);\n }\n }\n\n // We need to keep U in data[fieldName] to handle entities without an id assigned yet.\n current(opts?: { withDeleted?: boolean }): U | TaggedId | N {\n const current = getField(this.entity, this.fieldName);\n if (current !== undefined && isEntity(current)) {\n return this.filterDeleted(current as U, opts);\n }\n return current;\n }\n\n get otherMeta(): EntityMetadata<U> {\n return this.#field.otherMetadata();\n }\n\n get hasBeenSet(): boolean {\n return this.#hasBeenSet;\n }\n\n public toString(): string {\n return `ManyToOneReference(entity: ${this.entity}, fieldName: ${this.fieldName}, otherType: ${this.otherMeta.type}, otherFieldName: ${this.otherFieldName}, id: ${this.idMaybe})`;\n }\n\n /**\n * Removes pending-hard-delete (but not soft-deleted), unless explicitly asked for.\n *\n * Note that we leave soft-deleted entities b/c the call signature of a `book.author.get`\n * very likely does not expect a soft-deleted entity to result in `undefined`.\n *\n * (Contrasted with `author.books.get` which is more intuitive to have soft-deleted\n * entities filtered out, i.e. it doesn't fundamentally change the return type.)\n */\n private filterDeleted(entity: U | N, opts?: { withDeleted?: boolean }): U | N {\n if (entity && (!opts || !opts.withDeleted) && entity.isDeletedEntity) {\n return undefined!;\n }\n return entity;\n }\n\n /** Returns the other relation that points back at us, i.e. we're `book.author_id` and this is `Author.books`. */\n private getOtherRelation(\n other: U,\n ): OneToManyCollection<U, T> | OneToOneReferenceImpl<U, T> | OneToManyLargeCollection<U, T> {\n return (other as U)[this.otherFieldName] as any;\n }\n\n private get isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.fieldName);\n }\n\n /**\n * Looks for an entity in `EntityManager`, b/c we may have it in memory even if\n * our reference is not specifically loaded.\n */\n maybeFindEntity(): U | undefined {\n // Check current() first b/c a new entity won't have an id yet\n const current = this.current();\n if (isEntity(current)) return current as U;\n const { idTaggedMaybe } = this;\n return idTaggedMaybe !== undefined ? (this.entity.em.getEntity(idTaggedMaybe) as U) : undefined;\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n [ReferenceN]: N = null!;\n}\n\n/**\n * Fails when we can't return an `.id` for a reference, i.e. it's unset or a new entity.\n *\n * We strictly type `book.author.id` as `AuthorId`, even if `book.author` is nullable, to\n * avoid users calling `.id` and getting back `undefined`, but not because \"there is no\n * author\", but only because \"the assigned author doesn't have an id assigned yet\".\n *\n * To handle nullable references, set `.idIfSet`.\n *\n * Assumes being called like `return idMaybe ?? failNoId()`, i.e. if we're called we\n * know the id is not available.\n */\nexport function failNoId(entity: Entity, fieldName: string, current: string | Entity | undefined): never {\n if (!current) fail(`Reference ${entity}.${fieldName} is unset`);\n // Throw NoIdError, which lets ReactionsManager will handle reactive fields gracefully\n if (current instanceof BaseEntity)\n throw new NoIdError(`Reference ${entity}.${fieldName} is assigned to a new entity`);\n fail(`Unreachable`);\n}\n\n/**\n * Fails when we can't return an `.idIfSet` for a reference, i.e. it's a new entity.\n *\n * Assumes being called like `return idMaybe ?? failIfNewEntity()`, i.e. if we're called we\n * know the id is not available.\n */\nexport function failIfNewEntity(entity: Entity, fieldName: string, current: string | Entity | undefined): undefined {\n if (current instanceof BaseEntity) {\n throw new NoIdError(`Reference ${entity}.${fieldName} is assigned to a new entity`);\n }\n // Since this is a `.idIfSet`, having no `current` is fine, return undefined.\n return undefined;\n}\n\ninterface M2OState<U extends Entity, N extends never | undefined> {\n readonly isLoaded: boolean;\n maybeInstantLoad(): M2OState<U, N>;\n applyLoad(loaded: U | N | undefined): M2OLoadedState<U, N>;\n import(target: ManyToOneReferenceImpl<any, any, any>, findEntity: (e: U) => U): M2OState<U, N>;\n doGet(): U | N | undefined;\n}\n\nclass M2OUnloadedState<U extends Entity, N extends never | undefined> implements M2OState<U, N> {\n readonly isLoaded = false;\n #m2o: ManyToOneReferenceImpl<any, any, any>;\n constructor(m2o: ManyToOneReferenceImpl<any, any, any>) {\n this.#m2o = m2o;\n }\n applyLoad(loaded: U | N | undefined): M2OLoadedState<U, N> {\n return new M2OLoadedState<U, N>(this.#m2o, loaded);\n }\n import(target: ManyToOneReferenceImpl<any, any, any>): M2OState<U, N> {\n return new M2OUnloadedState<U, N>(target);\n }\n maybeInstantLoad(): M2OState<U, N> {\n const current = this.#m2o.current();\n if (current === undefined || isEntity(current)) {\n return new M2OLoadedState<U, N>(this.#m2o, current as U | undefined);\n } else {\n const maybeFound = this.#m2o.entity.em.getEntity(current);\n if (maybeFound) {\n return new M2OLoadedState<U, N>(this.#m2o, maybeFound as U);\n }\n }\n return this;\n }\n doGet(): U | N | undefined {\n throw new Error(`${this.#m2o.entity}.${this.#m2o.fieldName} was not loaded`);\n }\n}\n\n/** The when loaded, with either the loaded entity or undefined. */\nclass M2OLoadedState<U extends Entity, N extends never | undefined> implements M2OState<U, N> {\n readonly isLoaded = true;\n #m2o: ManyToOneReferenceImpl<any, any, any>;\n #loaded: U | N | undefined;\n constructor(m2o: ManyToOneReferenceImpl<any, any, any>, loaded: U | N | undefined) {\n this.#loaded = loaded;\n this.#m2o = m2o;\n }\n applyLoad(loaded: U | N | undefined): M2OLoadedState<U, N> {\n return new M2OLoadedState<U, N>(this.#m2o, loaded);\n }\n import(target: ManyToOneReferenceImpl<any, any, any>, findEntity: (e: U) => U): M2OState<U, N> {\n return new M2OLoadedState<U, N>(target, isEntity(this.#loaded) ? findEntity(this.#loaded) : undefined);\n }\n maybeInstantLoad(): M2OState<U, N> {\n return this;\n }\n doGet(): U | N | undefined {\n return this.#loaded;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4BA,SAAgB,SAAuG;CACrH,OAAO,WAAW,QAAW,cAAc;EACzC,MAAM,MAAM,YAAY,MAAM,CAAC,CAAC,UAAU;E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D,OAAO,IAAI,eAAqB,KAAKA,MAAM,MAAM;CACnD;CACA,OAAO,QAA+D;EACpE,OAAO,IAAI,iBAAuB,MAAM;CAC1C;CACA,mBAAmC;EACjC,MAAM,UAAU,KAAKA,KAAK,QAAQ;EAClC,IAAI,YAAY,KAAA,KAAa,SAAS,OAAO,GAC3C,OAAO,IAAI,eAAqB,KAAKA,MAAM,OAAwB;OAC9D;GACL,MAAM,aAAa,KAAKA,KAAK,OAAO,GAAG,UAAU,OAAO;GACxD,IAAI,YACF,OAAO,IAAI,eAAqB,KAAKA,MAAM,UAAe;EAE9D;EACA,OAAO;CACT;CACA,QAA2B;EACzB,MAAM,IAAI,MAAM,GAAG,KAAKA,KAAK,OAAO,GAAG,KAAKA,KAAK,UAAU,gBAAgB;CAC7E;AACF;;AAGA,IAAM,iBAAN,MAAM,eAAwF;CAC5F,WAAoB;CACpB;CACA;CACA,YAAY,KAA4C,QAA2B;EACjF,KAAKC,UAAU;EACf,KAAKD,OAAO;CACd;CACA,UAAU,QAAiD;EACzD,OAAO,IAAI,eAAqB,KAAKA,MAAM,MAAM;CACnD;CACA,OAAO,QAA+C,YAAyC;EAC7F,OAAO,IAAI,eAAqB,QAAQ,SAAS,KAAKC,OAAO,IAAI,WAAW,KAAKA,OAAO,IAAI,KAAA,CAAS;CACvG;CACA,mBAAmC;EACjC,OAAO;CACT;CACA,QAA2B;EACzB,OAAO,KAAKA;CACd;AACF"}
1
+ {"version":3,"file":"ManyToOneReference.js","names":[],"sources":["../../src/relations/ManyToOneReference.ts"],"sourcesContent":["import { type Entity, isEntity } from \"src/Entity.ts\";\nimport { type IdOf, type TaggedId, getEmInternalApi, sameEntity } from \"src/EntityManager.ts\";\nimport { type EntityMetadata, type ManyToOneField, getMetadata } from \"src/EntityMetadata.ts\";\nimport { getField, setField } from \"src/fields.ts\";\nimport {\n BaseEntity,\n NoIdError,\n OneToManyLargeCollection,\n OneToOneReferenceImpl,\n type Reference,\n deTagId,\n ensureNotDeleted,\n ensureTagged,\n fail,\n getInstanceData,\n maybeResolveReferenceToId,\n toIdOf,\n toTaggedId,\n} from \"src/index.ts\";\nimport { lazyField } from \"src/newEntity.ts\";\nimport { AbstractRelationImpl } from \"src/relations/AbstractRelationImpl.ts\";\nimport { isCascadeDelete } from \"src/relations/isCascadeDelete.ts\";\nimport { OneToManyCollection } from \"src/relations/OneToManyCollection.ts\";\nimport { ReferenceN } from \"src/relations/ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"src/relations/RelationSymbols.ts\";\nimport { maybeAdd, maybeRemove } from \"src/utils.ts\";\n\n/** An alias for creating `ManyToOneReference`s. */\nexport function hasOne<T extends Entity, U extends Entity, N extends never | undefined>(): ManyToOneReference<T, U, N> {\n return lazyField((entity: T, fieldName) => {\n const m2o = getMetadata(entity).allFields[fieldName] as ManyToOneField;\n return new ManyToOneReferenceImpl<T, U, N>(entity, m2o);\n });\n}\n\n/** Type guard utility for determining if an entity field is a ManyToOneReference. */\nexport function isManyToOneReference(maybeReference: any): maybeReference is ManyToOneReference<any, any, any> {\n return maybeReference instanceof ManyToOneReferenceImpl;\n}\n\nexport interface ManyToOneReference<T extends Entity, U extends Entity, N extends never | undefined> extends Reference<\n T,\n U,\n N\n> {\n /** Returns the id of the current assigned entity, or a runtime error if either 1) unset or 2) set to a new entity that doesn't have an `id` yet. */\n id: IdOf<U>;\n\n /** Returns the id of the current assigned entity, undefined if unset, or a runtime error if set to a new entity. */\n idIfSet: IdOf<U> | undefined;\n\n /** Returns the id of the current assigned entity, undefined if unset, or undefined if set to a new entity. */\n idMaybe: IdOf<U> | undefined;\n\n idUntagged: string;\n\n idUntaggedIfSet: string | undefined;\n\n /** Returns `true` if this relation is currently set (i.e. regardless of whether it's loaded, or if it is set but the assigned entity doesn't have an id saved. */\n readonly isSet: boolean;\n}\n\n/**\n * Manages a foreign key from one entity to another, i.e. `Book.author --> Author`.\n *\n * We keep the current `author` / `author_id` value in the `__orm.data` hash, where the\n * current value could be either the (string) author id from the database, or an entity\n * `Author` that the user has set.\n *\n * Note that if our `images.author_id` column is unique, this `ManyToOneReference` will essentially\n * be half of a one-to-one relationship, but we'll keep using this `ManyToOneReference` on the \"many\"\n * side, and the other side, i.e. `Author.image` will use a `OneToOneReference` to point back to us.\n */\nexport class ManyToOneReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined>\n extends AbstractRelationImpl<T, U>\n implements ManyToOneReference<T, U, N>\n{\n readonly #field: ManyToOneField;\n #state: M2OState<U, N>;\n #loadPromise: Promise<void> | undefined;\n #hasBeenSet = false;\n\n constructor(entity: T, field: ManyToOneField) {\n super(entity);\n this.#field = field;\n this.#state = getInstanceData(entity).isOrWasNew\n ? new M2OLoadedState<U, N>(this, undefined)\n : new M2OUnloadedState<U, N>(this);\n }\n\n async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<U | N> {\n ensureNotDeleted(this.entity, \"pending\");\n this.#state = this.#state.maybeInstantLoad();\n if (!this.#state.isLoaded || opts.forceReload) {\n const current = this.current();\n if (isEntity(current) || current === undefined) {\n this.#state = new M2OLoadedState<U, N>(this, current as U | N | undefined);\n } else {\n await (this.#loadPromise ??= this.entity.em.load(this.otherMeta.cstr, current).then((entity) => {\n this.#loadPromise = undefined;\n // In extremely rare cases, someone might have called `set` while this promise was in-flight,\n // so make sure our current value is still the same as the fetched entity.\n if (sameEntity(entity, this.current())) {\n this.#state = this.#state.applyLoad(entity);\n }\n }));\n }\n }\n return this.filterDeleted(this.#state.doGet() as U | N, opts);\n }\n\n set(other: U | N): void {\n this.#setImpl(other);\n }\n\n get isSet(): boolean {\n return this.current() !== undefined;\n }\n\n get isLoaded(): boolean {\n // Even if `.load()` has not been called, `.get` will detect\n this.#state = this.#state.maybeInstantLoad();\n return this.#state.isLoaded;\n }\n\n get isPreloaded(): boolean {\n return !!this.maybeFindEntity();\n }\n\n preload(): void {\n this.#state = new M2OLoadedState<U, N>(this, this.maybeFindEntity());\n }\n\n private unload(): void {\n this.#state = new M2OUnloadedState<U, N>(this);\n this.#loadPromise = undefined;\n }\n\n /** Copy another em's `source` relation into our state. */\n import(source: ManyToOneReferenceImpl<T, U, N>, findEntity: (e: U) => U): void {\n this.#state = source.#state.import(this, findEntity);\n }\n\n private doGet(opts?: { withDeleted?: boolean }): U | N {\n ensureNotDeleted(this.entity, \"pending\");\n this.#state = this.#state.maybeInstantLoad();\n return this.filterDeleted(this.#state.doGet() as U | N, opts);\n }\n\n get getWithDeleted(): U | N {\n return this.doGet({ withDeleted: true });\n }\n\n get get(): U | N {\n return this.doGet({ withDeleted: false });\n }\n\n /** Returns the id of the current value. */\n get id(): IdOf<U> {\n return this.idMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n /** Sets the m2o to `id`, and allows accepting `undefined` (`N`) if this is a nullable relation. */\n set id(id: IdOf<U> | N) {\n ensureNotDeleted(this.entity, \"pending\");\n const newId = toTaggedId(this.otherMeta, id);\n\n const previousId = this.idTaggedMaybe;\n const previous = this.maybeFindEntity();\n const changed = setField(this.entity, this.fieldName, id);\n if (!changed) {\n return;\n }\n\n const loaded = newId ? (this.entity.em.getEntity(newId) as U) : undefined;\n this.#state = loaded ? new M2OLoadedState<U, N>(this, loaded) : new M2OUnloadedState<U, N>(this);\n this.#loadPromise = undefined;\n this.#percolateRemove(previousId, previous);\n this.#percolateAdd();\n }\n\n get idIfSet(): IdOf<U> | N | undefined {\n return this.idMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get idUntagged(): string {\n return this.idUntaggedMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idUntaggedIfSet(): string | undefined {\n return this.idUntaggedMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get idMaybe(): IdOf<U> | N | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return toIdOf(this.otherMeta, this.idTaggedMaybe);\n }\n\n /** Returns the tagged id of the current value, or undefined if unset or a new entity. */\n get idTaggedMaybe(): TaggedId | undefined {\n // Skip the deleted check so that `isPreloaded` doesn't blow up during em.refreshes/populates\n // ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current());\n }\n\n get fieldName(): string {\n return this.#field.fieldName;\n }\n\n get otherFieldName(): keyof U & string {\n return this.#field.otherFieldName as keyof U & string;\n }\n\n private get idUntaggedMaybe(): string | undefined {\n return deTagId(this.otherMeta, this.idMaybe);\n }\n\n #setImpl(_other: U | IdOf<U> | N): void {\n ensureNotDeleted(this.entity, \"pending\");\n this.#hasBeenSet = true;\n\n // If the project is not using tagged ids, we still want it tagged internally\n const other = ensureTagged(this.otherMeta, _other);\n if (sameEntity(other, this.current({ withDeleted: true }))) {\n return;\n }\n\n const previousId = this.idTaggedMaybe;\n const previous = this.maybeFindEntity();\n // Prefer to keep the id in our data hash, but if this is a new entity w/o an id, use the entity itself\n setField(this.entity, this.fieldName, isEntity(other) ? (other?.idTaggedMaybe ?? other) : other);\n\n // Setting to an entity | undefined => loaded, setting to an id might reverse to unloaded\n const maybeEntity = isEntity(other) ? (other as U) : other ? this.entity.em.getEntity(other) : undefined;\n if (maybeEntity || other === undefined) {\n this.#state = new M2OLoadedState<U, N>(this, (maybeEntity ?? other) as U | N);\n } else {\n this.#state = new M2OUnloadedState<U, N>(this);\n }\n this.#loadPromise = undefined;\n this.#percolateRemove(previousId, previous);\n this.#percolateAdd();\n }\n\n // private impl\n\n setFromOpts(other: U | IdOf<U> | N): void {\n this.#setImpl(other);\n }\n\n maybeCascadeDelete(): void {\n if (this.isCascadeDelete) {\n const current = this.current({ withDeleted: true });\n if (current !== undefined) {\n if (typeof current === \"string\") {\n // We're invoked twice, once sync on em.delete, and again in em.flush when we're loaded;\n // but even when loaded, current might still be the tagged id, but we can find the entity in the EM\n const other = this.entity.em.getEntity(current);\n if (other) this.entity.em.delete(other as U);\n } else {\n this.entity.em.delete(current as U);\n }\n }\n }\n }\n\n async cleanupOnEntityDeleted(): Promise<void> {\n // if we are going to delete this relation as well, then we don't need to clean it up\n if (this.isCascadeDelete) return;\n const current = await this.load({ withDeleted: true });\n if (current !== undefined) {\n const o2m = this.getOtherRelation(current);\n if (o2m instanceof OneToManyCollection) {\n o2m.remove(this.entity, { requireLoaded: false });\n } else if (o2m instanceof OneToManyLargeCollection) {\n o2m.remove(this.entity);\n } else if (o2m instanceof OneToOneReferenceImpl) {\n o2m.set(undefined as any);\n } else {\n throw new Error(`Unhandled ${o2m}`);\n }\n }\n setField(this.entity, this.fieldName, undefined);\n this.#state = new M2OLoadedState<U, N>(this, undefined as any);\n }\n\n // Called on `book.author.set(...)` with our previous value, to percolate a `author.books.remove`. */\n #percolateRemove(prevId: string | undefined, prevEntity: U | undefined) {\n if (prevEntity) {\n const prevRelation = this.getOtherRelation(prevEntity);\n if (prevRelation instanceof OneToManyCollection) {\n prevRelation.removeIfLoaded(this.entity);\n } else if (prevRelation instanceof OneToManyLargeCollection) {\n prevRelation.remove(this.entity);\n } else {\n prevRelation.set(undefined as any, { percolating: true });\n }\n } else if (prevId) {\n // prevEntity is not loaded in memory, but cache it in case our other side is later loaded\n const { em } = this.entity;\n let map = getEmInternalApi(em).pendingPercolate.get(prevId);\n if (!map) {\n map = new Map();\n getEmInternalApi(em).pendingPercolate.set(prevId, map);\n }\n let pending = map.get(this.otherFieldName);\n if (!pending) {\n pending = { adds: [], removes: [] };\n map.set(this.otherFieldName, pending);\n }\n maybeAdd(pending.removes, this.entity);\n maybeRemove(pending.adds, this.entity);\n }\n }\n\n #percolateAdd() {\n const id = this.current();\n const other = this.maybeFindEntity();\n if (other) {\n // Other is already loaded in memory, immediately hook it up\n const newRelation = this.getOtherRelation(other);\n if (newRelation instanceof OneToManyCollection) {\n newRelation.add(this.entity);\n } else if (newRelation instanceof OneToManyLargeCollection) {\n newRelation.add(this.entity);\n } else if (newRelation) {\n newRelation.set(this.entity, { percolating: true });\n } else {\n // Something is wrong, we should always have a relation, but instead\n // of blowing up here, let this finish b/c it will probably turn into\n // a validation error.\n }\n } else if (typeof id === \"string\") {\n // Other is not loaded in memory, but cache it in case our other side is later loaded\n const { em } = this.entity;\n let map = getEmInternalApi(em).pendingPercolate.get(id);\n if (!map) {\n map = new Map();\n getEmInternalApi(em).pendingPercolate.set(id, map);\n }\n let pending = map.get(this.otherFieldName);\n if (!pending) {\n pending = { adds: [], removes: [] };\n map.set(this.otherFieldName, pending);\n }\n maybeAdd(pending.adds, this.entity);\n maybeRemove(pending.removes, this.entity);\n }\n }\n\n // We need to keep U in data[fieldName] to handle entities without an id assigned yet.\n current(opts?: { withDeleted?: boolean }): U | TaggedId | N {\n const current = getField(this.entity, this.fieldName);\n if (current !== undefined && isEntity(current)) {\n return this.filterDeleted(current as U, opts);\n }\n return current;\n }\n\n get otherMeta(): EntityMetadata<U> {\n return this.#field.otherMetadata();\n }\n\n get hasBeenSet(): boolean {\n return this.#hasBeenSet;\n }\n\n public toString(): string {\n return `ManyToOneReference(entity: ${this.entity}, fieldName: ${this.fieldName}, otherType: ${this.otherMeta.type}, otherFieldName: ${this.otherFieldName}, id: ${this.idMaybe})`;\n }\n\n /**\n * Removes pending-hard-delete (but not soft-deleted), unless explicitly asked for.\n *\n * Note that we leave soft-deleted entities b/c the call signature of a `book.author.get`\n * very likely does not expect a soft-deleted entity to result in `undefined`.\n *\n * (Contrasted with `author.books.get` which is more intuitive to have soft-deleted\n * entities filtered out, i.e. it doesn't fundamentally change the return type.)\n */\n private filterDeleted(entity: U | N, opts?: { withDeleted?: boolean }): U | N {\n if (entity && (!opts || !opts.withDeleted) && entity.isDeletedEntity) {\n return undefined!;\n }\n return entity;\n }\n\n /** Returns the other relation that points back at us, i.e. we're `book.author_id` and this is `Author.books`. */\n private getOtherRelation(\n other: U,\n ): OneToManyCollection<U, T> | OneToOneReferenceImpl<U, T> | OneToManyLargeCollection<U, T> {\n return (other as U)[this.otherFieldName] as any;\n }\n\n private get isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.fieldName);\n }\n\n /**\n * Looks for an entity in `EntityManager`, b/c we may have it in memory even if\n * our reference is not specifically loaded.\n */\n maybeFindEntity(): U | undefined {\n // Check current() first b/c a new entity won't have an id yet\n const current = this.current();\n if (isEntity(current)) return current as U;\n const { idTaggedMaybe } = this;\n return idTaggedMaybe !== undefined ? (this.entity.em.getEntity(idTaggedMaybe) as U) : undefined;\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n [ReferenceN]: N = null!;\n}\n\n/**\n * Fails when we can't return an `.id` for a reference, i.e. it's unset or a new entity.\n *\n * We strictly type `book.author.id` as `AuthorId`, even if `book.author` is nullable, to\n * avoid users calling `.id` and getting back `undefined`, but not because \"there is no\n * author\", but only because \"the assigned author doesn't have an id assigned yet\".\n *\n * To handle nullable references, set `.idIfSet`.\n *\n * Assumes being called like `return idMaybe ?? failNoId()`, i.e. if we're called we\n * know the id is not available.\n */\nexport function failNoId(entity: Entity, fieldName: string, current: string | Entity | undefined): never {\n if (!current) fail(`Reference ${entity}.${fieldName} is unset`);\n // Throw NoIdError, which lets ReactionsManager will handle reactive fields gracefully\n if (current instanceof BaseEntity)\n throw new NoIdError(`Reference ${entity}.${fieldName} is assigned to a new entity`);\n fail(`Unreachable`);\n}\n\n/**\n * Fails when we can't return an `.idIfSet` for a reference, i.e. it's a new entity.\n *\n * Assumes being called like `return idMaybe ?? failIfNewEntity()`, i.e. if we're called we\n * know the id is not available.\n */\nexport function failIfNewEntity(entity: Entity, fieldName: string, current: string | Entity | undefined): undefined {\n if (current instanceof BaseEntity) {\n throw new NoIdError(`Reference ${entity}.${fieldName} is assigned to a new entity`);\n }\n // Since this is a `.idIfSet`, having no `current` is fine, return undefined.\n return undefined;\n}\n\ninterface M2OState<U extends Entity, N extends never | undefined> {\n readonly isLoaded: boolean;\n maybeInstantLoad(): M2OState<U, N>;\n applyLoad(loaded: U | N | undefined): M2OLoadedState<U, N>;\n import(target: ManyToOneReferenceImpl<any, any, any>, findEntity: (e: U) => U): M2OState<U, N>;\n doGet(): U | N | undefined;\n}\n\nclass M2OUnloadedState<U extends Entity, N extends never | undefined> implements M2OState<U, N> {\n readonly isLoaded = false;\n #m2o: ManyToOneReferenceImpl<any, any, any>;\n constructor(m2o: ManyToOneReferenceImpl<any, any, any>) {\n this.#m2o = m2o;\n }\n applyLoad(loaded: U | N | undefined): M2OLoadedState<U, N> {\n return new M2OLoadedState<U, N>(this.#m2o, loaded);\n }\n import(target: ManyToOneReferenceImpl<any, any, any>): M2OState<U, N> {\n return new M2OUnloadedState<U, N>(target);\n }\n maybeInstantLoad(): M2OState<U, N> {\n const current = this.#m2o.current();\n if (current === undefined || isEntity(current)) {\n return new M2OLoadedState<U, N>(this.#m2o, current as U | undefined);\n } else {\n const maybeFound = this.#m2o.entity.em.getEntity(current);\n if (maybeFound) {\n return new M2OLoadedState<U, N>(this.#m2o, maybeFound as U);\n }\n }\n return this;\n }\n doGet(): U | N | undefined {\n throw new Error(`${this.#m2o.entity}.${this.#m2o.fieldName} was not loaded`);\n }\n}\n\n/** The when loaded, with either the loaded entity or undefined. */\nclass M2OLoadedState<U extends Entity, N extends never | undefined> implements M2OState<U, N> {\n readonly isLoaded = true;\n #m2o: ManyToOneReferenceImpl<any, any, any>;\n #loaded: U | N | undefined;\n constructor(m2o: ManyToOneReferenceImpl<any, any, any>, loaded: U | N | undefined) {\n this.#loaded = loaded;\n this.#m2o = m2o;\n }\n applyLoad(loaded: U | N | undefined): M2OLoadedState<U, N> {\n return new M2OLoadedState<U, N>(this.#m2o, loaded);\n }\n import(target: ManyToOneReferenceImpl<any, any, any>, findEntity: (e: U) => U): M2OState<U, N> {\n return new M2OLoadedState<U, N>(target, isEntity(this.#loaded) ? findEntity(this.#loaded) : undefined);\n }\n maybeInstantLoad(): M2OState<U, N> {\n return this;\n }\n doGet(): U | N | undefined {\n return this.#loaded;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4BA,SAAgB,SAAuG;CACrH,OAAO,WAAW,QAAW,cAAc;EACzC,MAAM,MAAM,YAAY,MAAM,CAAC,CAAC,UAAU;EAC1C,OAAO,IAAI,uBAAg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