joist-core 2.4.0 → 2.5.0

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 (891) hide show
  1. package/build/BaseEntity.d.cts +3 -4
  2. package/build/BaseEntity.d.cts.map +1 -1
  3. package/build/BaseEntity.d.mts +3 -4
  4. package/build/BaseEntity.d.mts.map +1 -1
  5. package/build/Entity.d.cts +3 -4
  6. package/build/Entity.d.cts.map +1 -1
  7. package/build/Entity.d.mts +3 -4
  8. package/build/Entity.d.mts.map +1 -1
  9. package/build/EntityFields.d.cts +3 -4
  10. package/build/EntityFields.d.cts.map +1 -1
  11. package/build/EntityFields.d.mts +3 -4
  12. package/build/EntityFields.d.mts.map +1 -1
  13. package/build/EntityManager.cjs +102 -22
  14. package/build/EntityManager.cjs.map +1 -1
  15. package/build/EntityManager.d.cts +99 -54
  16. package/build/EntityManager.d.cts.map +1 -1
  17. package/build/EntityManager.d.mts +99 -54
  18. package/build/EntityManager.d.mts.map +1 -1
  19. package/build/EntityManager.js +102 -24
  20. package/build/EntityManager.js.map +1 -1
  21. package/build/EntityMetadata.cjs +0 -1
  22. package/build/EntityMetadata.cjs.map +1 -1
  23. package/build/EntityMetadata.d.cts +47 -36
  24. package/build/EntityMetadata.d.cts.map +1 -1
  25. package/build/EntityMetadata.d.mts +47 -36
  26. package/build/EntityMetadata.d.mts.map +1 -1
  27. package/build/EntityMetadata.js +0 -1
  28. package/build/EntityMetadata.js.map +1 -1
  29. package/build/EnumMetadata.d.cts +1 -2
  30. package/build/EnumMetadata.d.cts.map +1 -1
  31. package/build/EnumMetadata.d.mts +1 -2
  32. package/build/EnumMetadata.d.mts.map +1 -1
  33. package/build/IndexManager.cjs +25 -5
  34. package/build/IndexManager.cjs.map +1 -1
  35. package/build/IndexManager.d.cts +2 -3
  36. package/build/IndexManager.d.cts.map +1 -1
  37. package/build/IndexManager.d.mts +2 -3
  38. package/build/IndexManager.d.mts.map +1 -1
  39. package/build/IndexManager.js +25 -5
  40. package/build/IndexManager.js.map +1 -1
  41. package/build/InstanceData.cjs.map +1 -1
  42. package/build/InstanceData.d.cts +1 -2
  43. package/build/InstanceData.d.cts.map +1 -1
  44. package/build/InstanceData.d.mts +1 -2
  45. package/build/InstanceData.d.mts.map +1 -1
  46. package/build/InstanceData.js.map +1 -1
  47. package/build/PluginManager.cjs.map +1 -1
  48. package/build/PluginManager.d.cts +4 -4
  49. package/build/PluginManager.d.cts.map +1 -1
  50. package/build/PluginManager.d.mts +4 -4
  51. package/build/PluginManager.d.mts.map +1 -1
  52. package/build/PluginManager.js.map +1 -1
  53. package/build/RowData.d.cts +3 -4
  54. package/build/RowData.d.cts.map +1 -1
  55. package/build/RowData.d.mts +3 -4
  56. package/build/RowData.d.mts.map +1 -1
  57. package/build/batchloaders/BatchLoader.cjs.map +1 -1
  58. package/build/batchloaders/BatchLoader.d.cts +1 -2
  59. package/build/batchloaders/BatchLoader.d.cts.map +1 -1
  60. package/build/batchloaders/BatchLoader.d.mts +1 -2
  61. package/build/batchloaders/BatchLoader.d.mts.map +1 -1
  62. package/build/batchloaders/BatchLoader.js.map +1 -1
  63. package/build/batchloaders/enumCollectionBatchLoader.d.cts +2 -3
  64. package/build/batchloaders/enumCollectionBatchLoader.d.cts.map +1 -1
  65. package/build/batchloaders/enumCollectionBatchLoader.d.mts +2 -3
  66. package/build/batchloaders/enumCollectionBatchLoader.d.mts.map +1 -1
  67. package/build/batchloaders/loadBatchLoader.d.cts +2 -3
  68. package/build/batchloaders/loadBatchLoader.d.cts.map +1 -1
  69. package/build/batchloaders/loadBatchLoader.d.mts +2 -3
  70. package/build/batchloaders/loadBatchLoader.d.mts.map +1 -1
  71. package/build/batchloaders/manyToManyBatchLoader.d.cts +2 -3
  72. package/build/batchloaders/manyToManyBatchLoader.d.cts.map +1 -1
  73. package/build/batchloaders/manyToManyBatchLoader.d.mts +2 -3
  74. package/build/batchloaders/manyToManyBatchLoader.d.mts.map +1 -1
  75. package/build/batchloaders/oneToManyBatchLoader.cjs +1 -1
  76. package/build/batchloaders/oneToManyBatchLoader.d.cts +2 -3
  77. package/build/batchloaders/oneToManyBatchLoader.d.cts.map +1 -1
  78. package/build/batchloaders/oneToManyBatchLoader.d.mts +2 -3
  79. package/build/batchloaders/oneToManyBatchLoader.d.mts.map +1 -1
  80. package/build/batchloaders/oneToManyBatchLoader.js +1 -1
  81. package/build/batchloaders/oneToOneBatchLoader.cjs +1 -1
  82. package/build/batchloaders/oneToOneBatchLoader.d.cts +2 -3
  83. package/build/batchloaders/oneToOneBatchLoader.d.cts.map +1 -1
  84. package/build/batchloaders/oneToOneBatchLoader.d.mts +2 -3
  85. package/build/batchloaders/oneToOneBatchLoader.d.mts.map +1 -1
  86. package/build/batchloaders/oneToOneBatchLoader.js +1 -1
  87. package/build/batchloaders/populateBatchLoader.d.cts +2 -3
  88. package/build/batchloaders/populateBatchLoader.d.cts.map +1 -1
  89. package/build/batchloaders/populateBatchLoader.d.mts +2 -3
  90. package/build/batchloaders/populateBatchLoader.d.mts.map +1 -1
  91. package/build/batchloaders/recursiveChildrenBatchLoader.cjs +1 -1
  92. package/build/batchloaders/recursiveChildrenBatchLoader.d.cts +2 -3
  93. package/build/batchloaders/recursiveChildrenBatchLoader.d.cts.map +1 -1
  94. package/build/batchloaders/recursiveChildrenBatchLoader.d.mts +2 -3
  95. package/build/batchloaders/recursiveChildrenBatchLoader.d.mts.map +1 -1
  96. package/build/batchloaders/recursiveChildrenBatchLoader.js +1 -1
  97. package/build/batchloaders/recursiveM2mBatchLoader.d.cts +2 -3
  98. package/build/batchloaders/recursiveM2mBatchLoader.d.cts.map +1 -1
  99. package/build/batchloaders/recursiveM2mBatchLoader.d.mts +2 -3
  100. package/build/batchloaders/recursiveM2mBatchLoader.d.mts.map +1 -1
  101. package/build/batchloaders/recursiveParentsBatchLoader.cjs +1 -1
  102. package/build/batchloaders/recursiveParentsBatchLoader.d.cts +2 -3
  103. package/build/batchloaders/recursiveParentsBatchLoader.d.cts.map +1 -1
  104. package/build/batchloaders/recursiveParentsBatchLoader.d.mts +2 -3
  105. package/build/batchloaders/recursiveParentsBatchLoader.d.mts.map +1 -1
  106. package/build/batchloaders/recursiveParentsBatchLoader.js +1 -1
  107. package/build/changes.cjs +1 -1
  108. package/build/changes.cjs.map +1 -1
  109. package/build/changes.d.cts +9 -10
  110. package/build/changes.d.cts.map +1 -1
  111. package/build/changes.d.mts +9 -10
  112. package/build/changes.d.mts.map +1 -1
  113. package/build/changes.js +1 -1
  114. package/build/changes.js.map +1 -1
  115. package/build/config.cjs +165 -26
  116. package/build/config.cjs.map +1 -1
  117. package/build/config.d.cts +111 -19
  118. package/build/config.d.cts.map +1 -1
  119. package/build/config.d.mts +111 -19
  120. package/build/config.d.mts.map +1 -1
  121. package/build/config.js +165 -26
  122. package/build/config.js.map +1 -1
  123. package/build/configure.cjs +32 -2
  124. package/build/configure.cjs.map +1 -1
  125. package/build/configure.d.cts +8 -9
  126. package/build/configure.d.cts.map +1 -1
  127. package/build/configure.d.mts +8 -9
  128. package/build/configure.d.mts.map +1 -1
  129. package/build/configure.js +32 -2
  130. package/build/configure.js.map +1 -1
  131. package/build/dataloaders/fastWhereFilterHash.d.cts +1 -2
  132. package/build/dataloaders/fastWhereFilterHash.d.cts.map +1 -1
  133. package/build/dataloaders/fastWhereFilterHash.d.mts +1 -2
  134. package/build/dataloaders/fastWhereFilterHash.d.mts.map +1 -1
  135. package/build/dataloaders/findByUniqueDataLoader.d.cts +2 -3
  136. package/build/dataloaders/findByUniqueDataLoader.d.cts.map +1 -1
  137. package/build/dataloaders/findByUniqueDataLoader.d.mts +2 -3
  138. package/build/dataloaders/findByUniqueDataLoader.d.mts.map +1 -1
  139. package/build/dataloaders/findCountDataLoader.d.cts +4 -5
  140. package/build/dataloaders/findCountDataLoader.d.cts.map +1 -1
  141. package/build/dataloaders/findCountDataLoader.d.mts +4 -5
  142. package/build/dataloaders/findCountDataLoader.d.mts.map +1 -1
  143. package/build/dataloaders/findDataLoader.cjs +1 -1
  144. package/build/dataloaders/findDataLoader.d.cts +11 -12
  145. package/build/dataloaders/findDataLoader.d.cts.map +1 -1
  146. package/build/dataloaders/findDataLoader.d.mts +11 -12
  147. package/build/dataloaders/findDataLoader.d.mts.map +1 -1
  148. package/build/dataloaders/findDataLoader.js +1 -1
  149. package/build/dataloaders/findIdsDataLoader.d.cts +2 -3
  150. package/build/dataloaders/findIdsDataLoader.d.cts.map +1 -1
  151. package/build/dataloaders/findIdsDataLoader.d.mts +2 -3
  152. package/build/dataloaders/findIdsDataLoader.d.mts.map +1 -1
  153. package/build/dataloaders/findOrCreateDataLoader.cjs +6 -2
  154. package/build/dataloaders/findOrCreateDataLoader.cjs.map +1 -1
  155. package/build/dataloaders/findOrCreateDataLoader.d.cts +3 -3
  156. package/build/dataloaders/findOrCreateDataLoader.d.cts.map +1 -1
  157. package/build/dataloaders/findOrCreateDataLoader.d.mts +3 -3
  158. package/build/dataloaders/findOrCreateDataLoader.d.mts.map +1 -1
  159. package/build/dataloaders/findOrCreateDataLoader.js +7 -3
  160. package/build/dataloaders/findOrCreateDataLoader.js.map +1 -1
  161. package/build/dataloaders/findPaginatedDataLoader.cjs +10 -12
  162. package/build/dataloaders/findPaginatedDataLoader.cjs.map +1 -1
  163. package/build/dataloaders/findPaginatedDataLoader.d.cts +1 -2
  164. package/build/dataloaders/findPaginatedDataLoader.d.cts.map +1 -1
  165. package/build/dataloaders/findPaginatedDataLoader.d.mts +1 -2
  166. package/build/dataloaders/findPaginatedDataLoader.d.mts.map +1 -1
  167. package/build/dataloaders/findPaginatedDataLoader.js +10 -12
  168. package/build/dataloaders/findPaginatedDataLoader.js.map +1 -1
  169. package/build/dataloaders/lensDataLoader.d.cts +2 -3
  170. package/build/dataloaders/lensDataLoader.d.cts.map +1 -1
  171. package/build/dataloaders/lensDataLoader.d.mts +2 -3
  172. package/build/dataloaders/lensDataLoader.d.mts.map +1 -1
  173. package/build/dataloaders/manyToManyFindDataLoader.d.cts +2 -3
  174. package/build/dataloaders/manyToManyFindDataLoader.d.cts.map +1 -1
  175. package/build/dataloaders/manyToManyFindDataLoader.d.mts +2 -3
  176. package/build/dataloaders/manyToManyFindDataLoader.d.mts.map +1 -1
  177. package/build/dataloaders/oneToManyFindDataLoader.d.cts +2 -3
  178. package/build/dataloaders/oneToManyFindDataLoader.d.cts.map +1 -1
  179. package/build/dataloaders/oneToManyFindDataLoader.d.mts +2 -3
  180. package/build/dataloaders/oneToManyFindDataLoader.d.mts.map +1 -1
  181. package/build/defaults.cjs +1 -1
  182. package/build/defaults.cjs.map +1 -1
  183. package/build/defaults.d.cts +7 -7
  184. package/build/defaults.d.cts.map +1 -1
  185. package/build/defaults.d.mts +7 -7
  186. package/build/defaults.d.mts.map +1 -1
  187. package/build/defaults.js +1 -1
  188. package/build/defaults.js.map +1 -1
  189. package/build/drivers/Driver.d.cts +2 -3
  190. package/build/drivers/Driver.d.cts.map +1 -1
  191. package/build/drivers/Driver.d.mts +2 -3
  192. package/build/drivers/Driver.d.mts.map +1 -1
  193. package/build/drivers/EntityWriter.cjs +4 -3
  194. package/build/drivers/EntityWriter.cjs.map +1 -1
  195. package/build/drivers/EntityWriter.d.cts +19 -7
  196. package/build/drivers/EntityWriter.d.cts.map +1 -1
  197. package/build/drivers/EntityWriter.d.mts +19 -7
  198. package/build/drivers/EntityWriter.d.mts.map +1 -1
  199. package/build/drivers/EntityWriter.js +5 -4
  200. package/build/drivers/EntityWriter.js.map +1 -1
  201. package/build/drivers/IdAssigner.cjs.map +1 -1
  202. package/build/drivers/IdAssigner.d.cts +5 -5
  203. package/build/drivers/IdAssigner.d.cts.map +1 -1
  204. package/build/drivers/IdAssigner.d.mts +5 -5
  205. package/build/drivers/IdAssigner.d.mts.map +1 -1
  206. package/build/drivers/IdAssigner.js.map +1 -1
  207. package/build/drivers/driverApi.d.cts +2 -3
  208. package/build/drivers/driverApi.d.cts.map +1 -1
  209. package/build/drivers/driverApi.d.mts +2 -3
  210. package/build/drivers/driverApi.d.mts.map +1 -1
  211. package/build/fields.cjs +12 -9
  212. package/build/fields.cjs.map +1 -1
  213. package/build/fields.d.cts +10 -11
  214. package/build/fields.d.cts.map +1 -1
  215. package/build/fields.d.mts +10 -11
  216. package/build/fields.d.mts.map +1 -1
  217. package/build/fields.js +12 -9
  218. package/build/fields.js.map +1 -1
  219. package/build/flush/FlushLock.cjs.map +1 -1
  220. package/build/flush/FlushLock.d.cts +1 -2
  221. package/build/flush/FlushLock.d.cts.map +1 -1
  222. package/build/flush/FlushLock.d.mts +1 -2
  223. package/build/flush/FlushLock.d.mts.map +1 -1
  224. package/build/flush/FlushLock.js.map +1 -1
  225. package/build/flush/JoinRows.cjs.map +1 -1
  226. package/build/flush/JoinRows.d.cts +5 -6
  227. package/build/flush/JoinRows.d.cts.map +1 -1
  228. package/build/flush/JoinRows.d.mts +5 -6
  229. package/build/flush/JoinRows.d.mts.map +1 -1
  230. package/build/flush/JoinRows.js.map +1 -1
  231. package/build/flush/PendingChanges.d.cts +5 -6
  232. package/build/flush/PendingChanges.d.cts.map +1 -1
  233. package/build/flush/PendingChanges.d.mts +5 -6
  234. package/build/flush/PendingChanges.d.mts.map +1 -1
  235. package/build/flush/ReadDrift.cjs +90 -0
  236. package/build/flush/ReadDrift.cjs.map +1 -0
  237. package/build/flush/ReadDrift.d.cts +25 -0
  238. package/build/flush/ReadDrift.d.cts.map +1 -0
  239. package/build/flush/ReadDrift.d.mts +25 -0
  240. package/build/flush/ReadDrift.d.mts.map +1 -0
  241. package/build/flush/ReadDrift.js +87 -0
  242. package/build/flush/ReadDrift.js.map +1 -0
  243. package/build/flush/Todo.d.cts +5 -6
  244. package/build/flush/Todo.d.cts.map +1 -1
  245. package/build/flush/Todo.d.mts +5 -6
  246. package/build/flush/Todo.d.mts.map +1 -1
  247. package/build/getProperties.cjs +1 -1
  248. package/build/getProperties.d.cts +3 -4
  249. package/build/getProperties.d.cts.map +1 -1
  250. package/build/getProperties.d.mts +3 -4
  251. package/build/getProperties.d.mts.map +1 -1
  252. package/build/getProperties.js +1 -1
  253. package/build/index.cjs +20 -7
  254. package/build/index.cjs.map +1 -1
  255. package/build/index.d.cts +23 -19
  256. package/build/index.d.cts.map +1 -1
  257. package/build/index.d.mts +23 -19
  258. package/build/index.d.mts.map +1 -1
  259. package/build/index.js +17 -10
  260. package/build/index.js.map +1 -1
  261. package/build/json.d.cts +11 -11
  262. package/build/json.d.cts.map +1 -1
  263. package/build/json.d.mts +11 -11
  264. package/build/json.d.mts.map +1 -1
  265. package/build/keys.d.cts +27 -27
  266. package/build/keys.d.cts.map +1 -1
  267. package/build/keys.d.mts +27 -27
  268. package/build/keys.d.mts.map +1 -1
  269. package/build/loading/HintTree.d.cts +3 -4
  270. package/build/loading/HintTree.d.cts.map +1 -1
  271. package/build/loading/HintTree.d.mts +3 -4
  272. package/build/loading/HintTree.d.mts.map +1 -1
  273. package/build/loading/IsLoadedCache.cjs +2 -2
  274. package/build/loading/IsLoadedCache.cjs.map +1 -1
  275. package/build/loading/IsLoadedCache.d.cts +3 -4
  276. package/build/loading/IsLoadedCache.d.cts.map +1 -1
  277. package/build/loading/IsLoadedCache.d.mts +3 -4
  278. package/build/loading/IsLoadedCache.d.mts.map +1 -1
  279. package/build/loading/IsLoadedCache.js +2 -2
  280. package/build/loading/IsLoadedCache.js.map +1 -1
  281. package/build/loading/loadHints.d.cts +17 -17
  282. package/build/loading/loadHints.d.cts.map +1 -1
  283. package/build/loading/loadHints.d.mts +17 -17
  284. package/build/loading/loadHints.d.mts.map +1 -1
  285. package/build/loading/loadLens.d.cts +13 -13
  286. package/build/loading/loadLens.d.cts.map +1 -1
  287. package/build/loading/loadLens.d.mts +13 -13
  288. package/build/loading/loadLens.d.mts.map +1 -1
  289. package/build/loading/withLoaded.d.cts +5 -6
  290. package/build/loading/withLoaded.d.cts.map +1 -1
  291. package/build/loading/withLoaded.d.mts +5 -6
  292. package/build/loading/withLoaded.d.mts.map +1 -1
  293. package/build/logging/FactoryLogger.cjs +1 -1
  294. package/build/logging/FactoryLogger.cjs.map +1 -1
  295. package/build/logging/FactoryLogger.d.cts +3 -4
  296. package/build/logging/FactoryLogger.d.cts.map +1 -1
  297. package/build/logging/FactoryLogger.d.mts +3 -4
  298. package/build/logging/FactoryLogger.d.mts.map +1 -1
  299. package/build/logging/FactoryLogger.js +2 -2
  300. package/build/logging/FactoryLogger.js.map +1 -1
  301. package/build/logging/FieldLogger.cjs.map +1 -1
  302. package/build/logging/FieldLogger.d.cts +4 -5
  303. package/build/logging/FieldLogger.d.cts.map +1 -1
  304. package/build/logging/FieldLogger.d.mts +4 -5
  305. package/build/logging/FieldLogger.d.mts.map +1 -1
  306. package/build/logging/FieldLogger.js.map +1 -1
  307. package/build/logging/ReactionLogger.d.cts +7 -7
  308. package/build/logging/ReactionLogger.d.cts.map +1 -1
  309. package/build/logging/ReactionLogger.d.mts +7 -7
  310. package/build/logging/ReactionLogger.d.mts.map +1 -1
  311. package/build/metrics/EntityMetrics.cjs +81 -0
  312. package/build/metrics/EntityMetrics.cjs.map +1 -0
  313. package/build/metrics/EntityMetrics.d.cts +55 -0
  314. package/build/metrics/EntityMetrics.d.cts.map +1 -0
  315. package/build/metrics/EntityMetrics.d.mts +55 -0
  316. package/build/metrics/EntityMetrics.d.mts.map +1 -0
  317. package/build/metrics/EntityMetrics.js +79 -0
  318. package/build/metrics/EntityMetrics.js.map +1 -0
  319. package/build/newEntity.cjs +1 -1
  320. package/build/newEntity.cjs.map +1 -1
  321. package/build/newEntity.d.cts +4 -5
  322. package/build/newEntity.d.cts.map +1 -1
  323. package/build/newEntity.d.mts +4 -5
  324. package/build/newEntity.d.mts.map +1 -1
  325. package/build/newEntity.js +1 -1
  326. package/build/newEntity.js.map +1 -1
  327. package/build/newTestInstance.cjs +1 -0
  328. package/build/newTestInstance.cjs.map +1 -1
  329. package/build/newTestInstance.d.cts +21 -21
  330. package/build/newTestInstance.d.cts.map +1 -1
  331. package/build/newTestInstance.d.mts +21 -21
  332. package/build/newTestInstance.d.mts.map +1 -1
  333. package/build/newTestInstance.js +1 -0
  334. package/build/newTestInstance.js.map +1 -1
  335. package/build/normalizeHints.d.cts +7 -8
  336. package/build/normalizeHints.d.cts.map +1 -1
  337. package/build/normalizeHints.d.mts +7 -8
  338. package/build/normalizeHints.d.mts.map +1 -1
  339. package/build/nowUTC.d.cts +4 -5
  340. package/build/nowUTC.d.cts.map +1 -1
  341. package/build/nowUTC.d.mts +4 -5
  342. package/build/nowUTC.d.mts.map +1 -1
  343. package/build/plugins/ImmutableEntitiesPlugin.d.cts +1 -2
  344. package/build/plugins/ImmutableEntitiesPlugin.d.cts.map +1 -1
  345. package/build/plugins/ImmutableEntitiesPlugin.d.mts +1 -2
  346. package/build/plugins/ImmutableEntitiesPlugin.d.mts.map +1 -1
  347. package/build/plugins/PreloadPlugin.d.cts +3 -4
  348. package/build/plugins/PreloadPlugin.d.cts.map +1 -1
  349. package/build/plugins/PreloadPlugin.d.mts +3 -4
  350. package/build/plugins/PreloadPlugin.d.mts.map +1 -1
  351. package/build/preloading/JsonAggregatePreloader.d.cts +1 -2
  352. package/build/preloading/JsonAggregatePreloader.d.cts.map +1 -1
  353. package/build/preloading/JsonAggregatePreloader.d.mts +1 -2
  354. package/build/preloading/JsonAggregatePreloader.d.mts.map +1 -1
  355. package/build/preloading/canPreload.d.cts +1 -2
  356. package/build/preloading/canPreload.d.cts.map +1 -1
  357. package/build/preloading/canPreload.d.mts +1 -2
  358. package/build/preloading/canPreload.d.mts.map +1 -1
  359. package/build/preloading/partitionHint.cjs +1 -1
  360. package/build/preloading/partitionHint.d.cts +1 -2
  361. package/build/preloading/partitionHint.d.cts.map +1 -1
  362. package/build/preloading/partitionHint.d.mts +1 -2
  363. package/build/preloading/partitionHint.d.mts.map +1 -1
  364. package/build/preloading/partitionHint.js +1 -1
  365. package/build/queries/ConditionBuilder.d.cts +2 -2
  366. package/build/queries/ConditionBuilder.d.cts.map +1 -1
  367. package/build/queries/ConditionBuilder.d.mts +2 -2
  368. package/build/queries/ConditionBuilder.d.mts.map +1 -1
  369. package/build/queries/conditions.d.cts +11 -12
  370. package/build/queries/conditions.d.cts.map +1 -1
  371. package/build/queries/conditions.d.mts +11 -12
  372. package/build/queries/conditions.d.mts.map +1 -1
  373. package/build/queries/entityQueryUtils.d.cts +4 -5
  374. package/build/queries/entityQueryUtils.d.cts.map +1 -1
  375. package/build/queries/entityQueryUtils.d.mts +4 -5
  376. package/build/queries/entityQueryUtils.d.mts.map +1 -1
  377. package/build/queries/find/Aliases.d.cts +16 -16
  378. package/build/queries/find/Aliases.d.cts.map +1 -1
  379. package/build/queries/find/Aliases.d.mts +16 -16
  380. package/build/queries/find/Aliases.d.mts.map +1 -1
  381. package/build/queries/find/DeferredAlias.d.cts +5 -6
  382. package/build/queries/find/DeferredAlias.d.cts.map +1 -1
  383. package/build/queries/find/DeferredAlias.d.mts +5 -6
  384. package/build/queries/find/DeferredAlias.d.mts.map +1 -1
  385. package/build/queries/find/EntityFilter.d.cts +12 -13
  386. package/build/queries/find/EntityFilter.d.cts.map +1 -1
  387. package/build/queries/find/EntityFilter.d.mts +12 -13
  388. package/build/queries/find/EntityFilter.d.mts.map +1 -1
  389. package/build/queries/find/EntityGraphQLFilter.d.cts +8 -9
  390. package/build/queries/find/EntityGraphQLFilter.d.cts.map +1 -1
  391. package/build/queries/find/EntityGraphQLFilter.d.mts +8 -9
  392. package/build/queries/find/EntityGraphQLFilter.d.mts.map +1 -1
  393. package/build/queries/find/QueryParser.collectionJoins.d.cts +1 -2
  394. package/build/queries/find/QueryParser.collectionJoins.d.cts.map +1 -1
  395. package/build/queries/find/QueryParser.collectionJoins.d.mts +1 -2
  396. package/build/queries/find/QueryParser.collectionJoins.d.mts.map +1 -1
  397. package/build/queries/find/QueryParser.d.cts +18 -18
  398. package/build/queries/find/QueryParser.d.cts.map +1 -1
  399. package/build/queries/find/QueryParser.d.mts +18 -18
  400. package/build/queries/find/QueryParser.d.mts.map +1 -1
  401. package/build/queries/find/QueryParser.pruning.d.cts +2 -3
  402. package/build/queries/find/QueryParser.pruning.d.cts.map +1 -1
  403. package/build/queries/find/QueryParser.pruning.d.mts +2 -3
  404. package/build/queries/find/QueryParser.pruning.d.mts.map +1 -1
  405. package/build/queries/find/QueryVisitor.d.cts +4 -4
  406. package/build/queries/find/QueryVisitor.d.cts.map +1 -1
  407. package/build/queries/find/QueryVisitor.d.mts +4 -4
  408. package/build/queries/find/QueryVisitor.d.mts.map +1 -1
  409. package/build/queries/find/buildFindQuery.d.cts +3 -3
  410. package/build/queries/find/buildFindQuery.d.cts.map +1 -1
  411. package/build/queries/find/buildFindQuery.d.mts +3 -3
  412. package/build/queries/find/buildFindQuery.d.mts.map +1 -1
  413. package/build/queries/find/scopes.cjs.map +1 -1
  414. package/build/queries/find/scopes.d.cts +12 -13
  415. package/build/queries/find/scopes.d.cts.map +1 -1
  416. package/build/queries/find/scopes.d.mts +12 -13
  417. package/build/queries/find/scopes.d.mts.map +1 -1
  418. package/build/queries/find/scopes.js.map +1 -1
  419. package/build/queries/parsedConditions.d.cts +7 -8
  420. package/build/queries/parsedConditions.d.cts.map +1 -1
  421. package/build/queries/parsedConditions.d.mts +7 -8
  422. package/build/queries/parsedConditions.d.mts.map +1 -1
  423. package/build/queries/renderConditions.d.cts +3 -4
  424. package/build/queries/renderConditions.d.cts.map +1 -1
  425. package/build/queries/renderConditions.d.mts +3 -4
  426. package/build/queries/renderConditions.d.mts.map +1 -1
  427. package/build/queries/skipCondition.d.cts +1 -2
  428. package/build/queries/skipCondition.d.cts.map +1 -1
  429. package/build/queries/skipCondition.d.mts +1 -2
  430. package/build/queries/skipCondition.d.mts.map +1 -1
  431. package/build/queries/sql/AliasAssigner.cjs.map +1 -1
  432. package/build/queries/sql/AliasAssigner.d.cts +1 -2
  433. package/build/queries/sql/AliasAssigner.d.cts.map +1 -1
  434. package/build/queries/sql/AliasAssigner.d.mts +1 -2
  435. package/build/queries/sql/AliasAssigner.d.mts.map +1 -1
  436. package/build/queries/sql/AliasAssigner.js.map +1 -1
  437. package/build/queries/sql/Expr.cjs +38 -0
  438. package/build/queries/sql/Expr.cjs.map +1 -1
  439. package/build/queries/sql/Expr.d.cts +45 -27
  440. package/build/queries/sql/Expr.d.cts.map +1 -1
  441. package/build/queries/sql/Expr.d.mts +45 -27
  442. package/build/queries/sql/Expr.d.mts.map +1 -1
  443. package/build/queries/sql/Expr.js +38 -1
  444. package/build/queries/sql/Expr.js.map +1 -1
  445. package/build/queries/sql/JoinTree.d.cts +5 -5
  446. package/build/queries/sql/JoinTree.d.cts.map +1 -1
  447. package/build/queries/sql/JoinTree.d.mts +5 -5
  448. package/build/queries/sql/JoinTree.d.mts.map +1 -1
  449. package/build/queries/sql/Tables.cjs +9 -0
  450. package/build/queries/sql/Tables.cjs.map +1 -1
  451. package/build/queries/sql/Tables.d.cts +46 -39
  452. package/build/queries/sql/Tables.d.cts.map +1 -1
  453. package/build/queries/sql/Tables.d.mts +46 -39
  454. package/build/queries/sql/Tables.d.mts.map +1 -1
  455. package/build/queries/sql/Tables.js +10 -1
  456. package/build/queries/sql/Tables.js.map +1 -1
  457. package/build/queries/sql/custom.d.cts +14 -14
  458. package/build/queries/sql/custom.d.cts.map +1 -1
  459. package/build/queries/sql/custom.d.mts +14 -14
  460. package/build/queries/sql/custom.d.mts.map +1 -1
  461. package/build/queries/sql/execute.cjs +68 -89
  462. package/build/queries/sql/execute.cjs.map +1 -1
  463. package/build/queries/sql/execute.d.cts +49 -32
  464. package/build/queries/sql/execute.d.cts.map +1 -1
  465. package/build/queries/sql/execute.d.mts +49 -32
  466. package/build/queries/sql/execute.d.mts.map +1 -1
  467. package/build/queries/sql/execute.js +70 -91
  468. package/build/queries/sql/execute.js.map +1 -1
  469. package/build/queries/sql/expressions/arrayAgg.d.cts +5 -6
  470. package/build/queries/sql/expressions/arrayAgg.d.cts.map +1 -1
  471. package/build/queries/sql/expressions/arrayAgg.d.mts +5 -6
  472. package/build/queries/sql/expressions/arrayAgg.d.mts.map +1 -1
  473. package/build/queries/sql/expressions/case.d.cts +10 -10
  474. package/build/queries/sql/expressions/case.d.cts.map +1 -1
  475. package/build/queries/sql/expressions/case.d.mts +10 -10
  476. package/build/queries/sql/expressions/case.d.mts.map +1 -1
  477. package/build/queries/sql/expressions/coalesce.d.cts +5 -6
  478. package/build/queries/sql/expressions/coalesce.d.cts.map +1 -1
  479. package/build/queries/sql/expressions/coalesce.d.mts +5 -6
  480. package/build/queries/sql/expressions/coalesce.d.mts.map +1 -1
  481. package/build/queries/sql/expressions/codecs.d.cts +1 -2
  482. package/build/queries/sql/expressions/codecs.d.cts.map +1 -1
  483. package/build/queries/sql/expressions/codecs.d.mts +1 -2
  484. package/build/queries/sql/expressions/codecs.d.mts.map +1 -1
  485. package/build/queries/sql/expressions/expression.d.cts +6 -6
  486. package/build/queries/sql/expressions/expression.d.cts.map +1 -1
  487. package/build/queries/sql/expressions/expression.d.mts +6 -6
  488. package/build/queries/sql/expressions/expression.d.mts.map +1 -1
  489. package/build/queries/sql/expressions/greatest.d.cts +5 -6
  490. package/build/queries/sql/expressions/greatest.d.cts.map +1 -1
  491. package/build/queries/sql/expressions/greatest.d.mts +5 -6
  492. package/build/queries/sql/expressions/greatest.d.mts.map +1 -1
  493. package/build/queries/sql/expressions/least.d.cts +5 -6
  494. package/build/queries/sql/expressions/least.d.cts.map +1 -1
  495. package/build/queries/sql/expressions/least.d.mts +5 -6
  496. package/build/queries/sql/expressions/least.d.mts.map +1 -1
  497. package/build/queries/sql/expressions/nullIf.d.cts +5 -6
  498. package/build/queries/sql/expressions/nullIf.d.cts.map +1 -1
  499. package/build/queries/sql/expressions/nullIf.d.mts +5 -6
  500. package/build/queries/sql/expressions/nullIf.d.mts.map +1 -1
  501. package/build/queries/sql/expressions/parseExpression.d.cts +5 -6
  502. package/build/queries/sql/expressions/parseExpression.d.cts.map +1 -1
  503. package/build/queries/sql/expressions/parseExpression.d.mts +5 -6
  504. package/build/queries/sql/expressions/parseExpression.d.mts.map +1 -1
  505. package/build/queries/sql/expressions/types.d.cts +11 -11
  506. package/build/queries/sql/expressions/types.d.cts.map +1 -1
  507. package/build/queries/sql/expressions/types.d.mts +11 -11
  508. package/build/queries/sql/expressions/types.d.mts.map +1 -1
  509. package/build/queries/sql/keywords.d.cts +4 -5
  510. package/build/queries/sql/keywords.d.cts.map +1 -1
  511. package/build/queries/sql/keywords.d.mts +4 -5
  512. package/build/queries/sql/keywords.d.mts.map +1 -1
  513. package/build/queries/sql/query.cjs +77 -30
  514. package/build/queries/sql/query.cjs.map +1 -1
  515. package/build/queries/sql/query.d.cts +119 -76
  516. package/build/queries/sql/query.d.cts.map +1 -1
  517. package/build/queries/sql/query.d.mts +119 -76
  518. package/build/queries/sql/query.d.mts.map +1 -1
  519. package/build/queries/sql/query.js +75 -30
  520. package/build/queries/sql/query.js.map +1 -1
  521. package/build/queries/unnest.cjs +4 -5
  522. package/build/queries/unnest.cjs.map +1 -1
  523. package/build/queries/unnest.d.cts +2 -3
  524. package/build/queries/unnest.d.cts.map +1 -1
  525. package/build/queries/unnest.d.mts +2 -3
  526. package/build/queries/unnest.d.mts.map +1 -1
  527. package/build/queries/unnest.js +4 -5
  528. package/build/queries/unnest.js.map +1 -1
  529. package/build/queries/valueFilters.d.cts +5 -6
  530. package/build/queries/valueFilters.d.cts.map +1 -1
  531. package/build/queries/valueFilters.d.mts +5 -6
  532. package/build/queries/valueFilters.d.mts.map +1 -1
  533. package/build/reactivity/ReactionsManager.cjs +171 -2
  534. package/build/reactivity/ReactionsManager.cjs.map +1 -1
  535. package/build/reactivity/ReactionsManager.d.cts +56 -4
  536. package/build/reactivity/ReactionsManager.d.cts.map +1 -1
  537. package/build/reactivity/ReactionsManager.d.mts +56 -4
  538. package/build/reactivity/ReactionsManager.d.mts.map +1 -1
  539. package/build/reactivity/ReactionsManager.js +172 -3
  540. package/build/reactivity/ReactionsManager.js.map +1 -1
  541. package/build/reactivity/reactiveHints.cjs +9 -3
  542. package/build/reactivity/reactiveHints.cjs.map +1 -1
  543. package/build/reactivity/reactiveHints.d.cts +19 -18
  544. package/build/reactivity/reactiveHints.d.cts.map +1 -1
  545. package/build/reactivity/reactiveHints.d.mts +19 -18
  546. package/build/reactivity/reactiveHints.d.mts.map +1 -1
  547. package/build/reactivity/reactiveHints.js +9 -3
  548. package/build/reactivity/reactiveHints.js.map +1 -1
  549. package/build/relations/AbstractPropertyImpl.cjs.map +1 -1
  550. package/build/relations/AbstractPropertyImpl.d.cts +1 -2
  551. package/build/relations/AbstractPropertyImpl.d.cts.map +1 -1
  552. package/build/relations/AbstractPropertyImpl.d.mts +1 -2
  553. package/build/relations/AbstractPropertyImpl.d.mts.map +1 -1
  554. package/build/relations/AbstractPropertyImpl.js.map +1 -1
  555. package/build/relations/AbstractRelationImpl.d.cts +1 -2
  556. package/build/relations/AbstractRelationImpl.d.cts.map +1 -1
  557. package/build/relations/AbstractRelationImpl.d.mts +1 -2
  558. package/build/relations/AbstractRelationImpl.d.mts.map +1 -1
  559. package/build/relations/AsyncProperty.cjs +1 -1
  560. package/build/relations/AsyncProperty.cjs.map +1 -1
  561. package/build/relations/AsyncProperty.d.cts +5 -6
  562. package/build/relations/AsyncProperty.d.cts.map +1 -1
  563. package/build/relations/AsyncProperty.d.mts +5 -6
  564. package/build/relations/AsyncProperty.d.mts.map +1 -1
  565. package/build/relations/AsyncProperty.js +1 -1
  566. package/build/relations/AsyncProperty.js.map +1 -1
  567. package/build/relations/AsyncReactiveField.cjs +23 -5
  568. package/build/relations/AsyncReactiveField.cjs.map +1 -1
  569. package/build/relations/AsyncReactiveField.d.cts +7 -6
  570. package/build/relations/AsyncReactiveField.d.cts.map +1 -1
  571. package/build/relations/AsyncReactiveField.d.mts +7 -6
  572. package/build/relations/AsyncReactiveField.d.mts.map +1 -1
  573. package/build/relations/AsyncReactiveField.js +23 -5
  574. package/build/relations/AsyncReactiveField.js.map +1 -1
  575. package/build/relations/Collection.d.cts +4 -5
  576. package/build/relations/Collection.d.cts.map +1 -1
  577. package/build/relations/Collection.d.mts +4 -5
  578. package/build/relations/Collection.d.mts.map +1 -1
  579. package/build/relations/CustomCollection.cjs +1 -1
  580. package/build/relations/CustomCollection.cjs.map +1 -1
  581. package/build/relations/CustomCollection.d.cts +3 -4
  582. package/build/relations/CustomCollection.d.cts.map +1 -1
  583. package/build/relations/CustomCollection.d.mts +3 -4
  584. package/build/relations/CustomCollection.d.mts.map +1 -1
  585. package/build/relations/CustomCollection.js +1 -1
  586. package/build/relations/CustomCollection.js.map +1 -1
  587. package/build/relations/CustomReference.cjs +2 -2
  588. package/build/relations/CustomReference.cjs.map +1 -1
  589. package/build/relations/CustomReference.d.cts +3 -4
  590. package/build/relations/CustomReference.d.cts.map +1 -1
  591. package/build/relations/CustomReference.d.mts +3 -4
  592. package/build/relations/CustomReference.d.mts.map +1 -1
  593. package/build/relations/CustomReference.js +2 -2
  594. package/build/relations/CustomReference.js.map +1 -1
  595. package/build/relations/EnumCollection.cjs +1 -1
  596. package/build/relations/EnumCollection.cjs.map +1 -1
  597. package/build/relations/EnumCollection.d.cts +5 -5
  598. package/build/relations/EnumCollection.d.cts.map +1 -1
  599. package/build/relations/EnumCollection.d.mts +5 -5
  600. package/build/relations/EnumCollection.d.mts.map +1 -1
  601. package/build/relations/EnumCollection.js +1 -1
  602. package/build/relations/EnumCollection.js.map +1 -1
  603. package/build/relations/LargeCollection.d.cts +1 -2
  604. package/build/relations/LargeCollection.d.cts.map +1 -1
  605. package/build/relations/LargeCollection.d.mts +1 -2
  606. package/build/relations/LargeCollection.d.mts.map +1 -1
  607. package/build/relations/LazyField.cjs +16 -2
  608. package/build/relations/LazyField.cjs.map +1 -1
  609. package/build/relations/LazyField.d.cts +13 -8
  610. package/build/relations/LazyField.d.cts.map +1 -1
  611. package/build/relations/LazyField.d.mts +13 -8
  612. package/build/relations/LazyField.d.mts.map +1 -1
  613. package/build/relations/LazyField.js +16 -2
  614. package/build/relations/LazyField.js.map +1 -1
  615. package/build/relations/ManyToManyCollection.cjs +1 -1
  616. package/build/relations/ManyToManyCollection.cjs.map +1 -1
  617. package/build/relations/ManyToManyCollection.d.cts +2 -3
  618. package/build/relations/ManyToManyCollection.d.cts.map +1 -1
  619. package/build/relations/ManyToManyCollection.d.mts +2 -3
  620. package/build/relations/ManyToManyCollection.d.mts.map +1 -1
  621. package/build/relations/ManyToManyCollection.js +1 -1
  622. package/build/relations/ManyToManyCollection.js.map +1 -1
  623. package/build/relations/ManyToManyLargeCollection.cjs +1 -1
  624. package/build/relations/ManyToManyLargeCollection.d.cts +2 -3
  625. package/build/relations/ManyToManyLargeCollection.d.cts.map +1 -1
  626. package/build/relations/ManyToManyLargeCollection.d.mts +2 -3
  627. package/build/relations/ManyToManyLargeCollection.d.mts.map +1 -1
  628. package/build/relations/ManyToManyLargeCollection.js +1 -1
  629. package/build/relations/ManyToOneReference.cjs +2 -2
  630. package/build/relations/ManyToOneReference.cjs.map +1 -1
  631. package/build/relations/ManyToOneReference.d.cts +6 -7
  632. package/build/relations/ManyToOneReference.d.cts.map +1 -1
  633. package/build/relations/ManyToOneReference.d.mts +6 -7
  634. package/build/relations/ManyToOneReference.d.mts.map +1 -1
  635. package/build/relations/ManyToOneReference.js +2 -2
  636. package/build/relations/ManyToOneReference.js.map +1 -1
  637. package/build/relations/OneToManyCollection.cjs +1 -1
  638. package/build/relations/OneToManyCollection.cjs.map +1 -1
  639. package/build/relations/OneToManyCollection.d.cts +2 -3
  640. package/build/relations/OneToManyCollection.d.cts.map +1 -1
  641. package/build/relations/OneToManyCollection.d.mts +2 -3
  642. package/build/relations/OneToManyCollection.d.mts.map +1 -1
  643. package/build/relations/OneToManyCollection.js +1 -1
  644. package/build/relations/OneToManyCollection.js.map +1 -1
  645. package/build/relations/OneToManyLargeCollection.cjs +1 -1
  646. package/build/relations/OneToManyLargeCollection.cjs.map +1 -1
  647. package/build/relations/OneToManyLargeCollection.d.cts +2 -3
  648. package/build/relations/OneToManyLargeCollection.d.cts.map +1 -1
  649. package/build/relations/OneToManyLargeCollection.d.mts +2 -3
  650. package/build/relations/OneToManyLargeCollection.d.mts.map +1 -1
  651. package/build/relations/OneToManyLargeCollection.js +1 -1
  652. package/build/relations/OneToManyLargeCollection.js.map +1 -1
  653. package/build/relations/OneToOneReference.cjs +2 -2
  654. package/build/relations/OneToOneReference.cjs.map +1 -1
  655. package/build/relations/OneToOneReference.d.cts +7 -7
  656. package/build/relations/OneToOneReference.d.cts.map +1 -1
  657. package/build/relations/OneToOneReference.d.mts +7 -7
  658. package/build/relations/OneToOneReference.d.mts.map +1 -1
  659. package/build/relations/OneToOneReference.js +2 -2
  660. package/build/relations/OneToOneReference.js.map +1 -1
  661. package/build/relations/PolymorphicReference.cjs +2 -2
  662. package/build/relations/PolymorphicReference.cjs.map +1 -1
  663. package/build/relations/PolymorphicReference.d.cts +4 -5
  664. package/build/relations/PolymorphicReference.d.cts.map +1 -1
  665. package/build/relations/PolymorphicReference.d.mts +4 -5
  666. package/build/relations/PolymorphicReference.d.mts.map +1 -1
  667. package/build/relations/PolymorphicReference.js +2 -2
  668. package/build/relations/PolymorphicReference.js.map +1 -1
  669. package/build/relations/PropertySymbols.d.cts +1 -2
  670. package/build/relations/PropertySymbols.d.cts.map +1 -1
  671. package/build/relations/PropertySymbols.d.mts +1 -2
  672. package/build/relations/PropertySymbols.d.mts.map +1 -1
  673. package/build/relations/ReactiveField.cjs +27 -6
  674. package/build/relations/ReactiveField.cjs.map +1 -1
  675. package/build/relations/ReactiveField.d.cts +11 -7
  676. package/build/relations/ReactiveField.d.cts.map +1 -1
  677. package/build/relations/ReactiveField.d.mts +11 -7
  678. package/build/relations/ReactiveField.d.mts.map +1 -1
  679. package/build/relations/ReactiveField.js +27 -6
  680. package/build/relations/ReactiveField.js.map +1 -1
  681. package/build/relations/ReactiveGetter.cjs +1 -1
  682. package/build/relations/ReactiveGetter.cjs.map +1 -1
  683. package/build/relations/ReactiveGetter.d.cts +4 -5
  684. package/build/relations/ReactiveGetter.d.cts.map +1 -1
  685. package/build/relations/ReactiveGetter.d.mts +4 -5
  686. package/build/relations/ReactiveGetter.d.mts.map +1 -1
  687. package/build/relations/ReactiveGetter.js +1 -1
  688. package/build/relations/ReactiveGetter.js.map +1 -1
  689. package/build/relations/ReactiveManyToMany.cjs +1 -1
  690. package/build/relations/ReactiveManyToMany.cjs.map +1 -1
  691. package/build/relations/ReactiveManyToMany.d.cts +4 -5
  692. package/build/relations/ReactiveManyToMany.d.cts.map +1 -1
  693. package/build/relations/ReactiveManyToMany.d.mts +4 -5
  694. package/build/relations/ReactiveManyToMany.d.mts.map +1 -1
  695. package/build/relations/ReactiveManyToMany.js +1 -1
  696. package/build/relations/ReactiveManyToMany.js.map +1 -1
  697. package/build/relations/ReactiveManyToManyOtherSide.cjs +1 -1
  698. package/build/relations/ReactiveManyToManyOtherSide.cjs.map +1 -1
  699. package/build/relations/ReactiveManyToManyOtherSide.d.cts +4 -5
  700. package/build/relations/ReactiveManyToManyOtherSide.d.cts.map +1 -1
  701. package/build/relations/ReactiveManyToManyOtherSide.d.mts +4 -5
  702. package/build/relations/ReactiveManyToManyOtherSide.d.mts.map +1 -1
  703. package/build/relations/ReactiveManyToManyOtherSide.js +1 -1
  704. package/build/relations/ReactiveManyToManyOtherSide.js.map +1 -1
  705. package/build/relations/ReactiveReference.cjs +2 -2
  706. package/build/relations/ReactiveReference.cjs.map +1 -1
  707. package/build/relations/ReactiveReference.d.cts +6 -7
  708. package/build/relations/ReactiveReference.d.cts.map +1 -1
  709. package/build/relations/ReactiveReference.d.mts +6 -7
  710. package/build/relations/ReactiveReference.d.mts.map +1 -1
  711. package/build/relations/ReactiveReference.js +2 -2
  712. package/build/relations/ReactiveReference.js.map +1 -1
  713. package/build/relations/ReadOnlyCollection.d.cts +4 -5
  714. package/build/relations/ReadOnlyCollection.d.cts.map +1 -1
  715. package/build/relations/ReadOnlyCollection.d.mts +4 -5
  716. package/build/relations/ReadOnlyCollection.d.mts.map +1 -1
  717. package/build/relations/RecursiveCollection.cjs +1 -1
  718. package/build/relations/RecursiveCollection.cjs.map +1 -1
  719. package/build/relations/RecursiveCollection.d.cts +10 -10
  720. package/build/relations/RecursiveCollection.d.cts.map +1 -1
  721. package/build/relations/RecursiveCollection.d.mts +10 -10
  722. package/build/relations/RecursiveCollection.d.mts.map +1 -1
  723. package/build/relations/RecursiveCollection.js +1 -1
  724. package/build/relations/RecursiveCollection.js.map +1 -1
  725. package/build/relations/RecursiveCycleError.d.cts +2 -2
  726. package/build/relations/RecursiveCycleError.d.cts.map +1 -1
  727. package/build/relations/RecursiveCycleError.d.mts +2 -2
  728. package/build/relations/RecursiveCycleError.d.mts.map +1 -1
  729. package/build/relations/Reference.d.cts +5 -5
  730. package/build/relations/Reference.d.cts.map +1 -1
  731. package/build/relations/Reference.d.mts +5 -5
  732. package/build/relations/Reference.d.mts.map +1 -1
  733. package/build/relations/ReferenceSymbols.d.cts +1 -2
  734. package/build/relations/ReferenceSymbols.d.cts.map +1 -1
  735. package/build/relations/ReferenceSymbols.d.mts +1 -2
  736. package/build/relations/ReferenceSymbols.d.mts.map +1 -1
  737. package/build/relations/Relation.d.cts +3 -3
  738. package/build/relations/Relation.d.cts.map +1 -1
  739. package/build/relations/Relation.d.mts +3 -3
  740. package/build/relations/Relation.d.mts.map +1 -1
  741. package/build/relations/RelationSymbols.d.cts +2 -3
  742. package/build/relations/RelationSymbols.d.cts.map +1 -1
  743. package/build/relations/RelationSymbols.d.mts +2 -3
  744. package/build/relations/RelationSymbols.d.mts.map +1 -1
  745. package/build/relations/hasAsyncMethod.cjs +24 -5
  746. package/build/relations/hasAsyncMethod.cjs.map +1 -1
  747. package/build/relations/hasAsyncMethod.d.cts +9 -8
  748. package/build/relations/hasAsyncMethod.d.cts.map +1 -1
  749. package/build/relations/hasAsyncMethod.d.mts +9 -8
  750. package/build/relations/hasAsyncMethod.d.mts.map +1 -1
  751. package/build/relations/hasAsyncMethod.js +24 -6
  752. package/build/relations/hasAsyncMethod.js.map +1 -1
  753. package/build/relations/hasManyDerived.cjs +1 -1
  754. package/build/relations/hasManyDerived.d.cts +2 -2
  755. package/build/relations/hasManyDerived.d.cts.map +1 -1
  756. package/build/relations/hasManyDerived.d.mts +2 -2
  757. package/build/relations/hasManyDerived.d.mts.map +1 -1
  758. package/build/relations/hasManyDerived.js +1 -1
  759. package/build/relations/hasManyThrough.cjs +1 -1
  760. package/build/relations/hasManyThrough.d.cts +1 -2
  761. package/build/relations/hasManyThrough.d.cts.map +1 -1
  762. package/build/relations/hasManyThrough.d.mts +1 -2
  763. package/build/relations/hasManyThrough.d.mts.map +1 -1
  764. package/build/relations/hasManyThrough.js +1 -1
  765. package/build/relations/hasOneDerived.cjs +1 -1
  766. package/build/relations/hasOneDerived.d.cts +1 -2
  767. package/build/relations/hasOneDerived.d.cts.map +1 -1
  768. package/build/relations/hasOneDerived.d.mts +1 -2
  769. package/build/relations/hasOneDerived.d.mts.map +1 -1
  770. package/build/relations/hasOneDerived.js +1 -1
  771. package/build/relations/hasOneThrough.cjs +1 -1
  772. package/build/relations/hasOneThrough.d.cts +1 -2
  773. package/build/relations/hasOneThrough.d.cts.map +1 -1
  774. package/build/relations/hasOneThrough.d.mts +1 -2
  775. package/build/relations/hasOneThrough.d.mts.map +1 -1
  776. package/build/relations/hasOneThrough.js +1 -1
  777. package/build/relations/hasProperty.cjs +1 -1
  778. package/build/relations/hasProperty.cjs.map +1 -1
  779. package/build/relations/hasProperty.d.cts +8 -8
  780. package/build/relations/hasProperty.d.cts.map +1 -1
  781. package/build/relations/hasProperty.d.mts +8 -8
  782. package/build/relations/hasProperty.d.mts.map +1 -1
  783. package/build/relations/hasProperty.js +1 -1
  784. package/build/relations/hasProperty.js.map +1 -1
  785. package/build/relations/hasReactiveAsyncMethod.cjs +87 -0
  786. package/build/relations/hasReactiveAsyncMethod.cjs.map +1 -0
  787. package/build/relations/hasReactiveAsyncMethod.d.cts +32 -0
  788. package/build/relations/hasReactiveAsyncMethod.d.cts.map +1 -0
  789. package/build/relations/hasReactiveAsyncMethod.d.mts +32 -0
  790. package/build/relations/hasReactiveAsyncMethod.d.mts.map +1 -0
  791. package/build/relations/hasReactiveAsyncMethod.js +85 -0
  792. package/build/relations/hasReactiveAsyncMethod.js.map +1 -0
  793. package/build/relations/index.cjs +2 -0
  794. package/build/relations/index.d.cts +2 -1
  795. package/build/relations/index.d.mts +2 -1
  796. package/build/relations/index.js +2 -1
  797. package/build/relations/isCascadeDelete.d.cts +1 -2
  798. package/build/relations/isCascadeDelete.d.cts.map +1 -1
  799. package/build/relations/isCascadeDelete.d.mts +1 -2
  800. package/build/relations/isCascadeDelete.d.mts.map +1 -1
  801. package/build/resurrection.cjs +11 -1
  802. package/build/resurrection.cjs.map +1 -1
  803. package/build/resurrection.d.cts +5 -3
  804. package/build/resurrection.d.cts.map +1 -1
  805. package/build/resurrection.d.mts +5 -3
  806. package/build/resurrection.d.mts.map +1 -1
  807. package/build/resurrection.js +11 -2
  808. package/build/resurrection.js.map +1 -1
  809. package/build/rules.cjs +1 -1
  810. package/build/rules.cjs.map +1 -1
  811. package/build/rules.d.cts +25 -20
  812. package/build/rules.d.cts.map +1 -1
  813. package/build/rules.d.mts +25 -20
  814. package/build/rules.d.mts.map +1 -1
  815. package/build/rules.js +1 -1
  816. package/build/rules.js.map +1 -1
  817. package/build/runtimeConfig.d.cts +4 -5
  818. package/build/runtimeConfig.d.cts.map +1 -1
  819. package/build/runtimeConfig.d.mts +4 -5
  820. package/build/runtimeConfig.d.mts.map +1 -1
  821. package/build/serde/TypeInfo.d.cts +3 -4
  822. package/build/serde/TypeInfo.d.cts.map +1 -1
  823. package/build/serde/TypeInfo.d.mts +3 -4
  824. package/build/serde/TypeInfo.d.mts.map +1 -1
  825. package/build/serde/columns.cjs +3 -0
  826. package/build/serde/columns.cjs.map +1 -1
  827. package/build/serde/columns.d.cts +3 -3
  828. package/build/serde/columns.d.cts.map +1 -1
  829. package/build/serde/columns.d.mts +3 -3
  830. package/build/serde/columns.d.mts.map +1 -1
  831. package/build/serde/columns.js +3 -0
  832. package/build/serde/columns.js.map +1 -1
  833. package/build/serde/fieldSerde.cjs +3 -0
  834. package/build/serde/fieldSerde.cjs.map +1 -1
  835. package/build/serde/fieldSerde.d.cts +10 -9
  836. package/build/serde/fieldSerde.d.cts.map +1 -1
  837. package/build/serde/fieldSerde.d.mts +10 -9
  838. package/build/serde/fieldSerde.d.mts.map +1 -1
  839. package/build/serde/fieldSerde.js +3 -0
  840. package/build/serde/fieldSerde.js.map +1 -1
  841. package/build/serde/serde.cjs +60 -0
  842. package/build/serde/serde.cjs.map +1 -1
  843. package/build/serde/serde.d.cts +58 -19
  844. package/build/serde/serde.d.cts.map +1 -1
  845. package/build/serde/serde.d.mts +58 -19
  846. package/build/serde/serde.d.mts.map +1 -1
  847. package/build/serde/serde.js +60 -1
  848. package/build/serde/serde.js.map +1 -1
  849. package/build/serde/temporal.cjs +7 -12
  850. package/build/serde/temporal.cjs.map +1 -1
  851. package/build/serde/temporal.d.cts +6 -6
  852. package/build/serde/temporal.d.cts.map +1 -1
  853. package/build/serde/temporal.d.mts +6 -6
  854. package/build/serde/temporal.d.mts.map +1 -1
  855. package/build/serde/temporal.js +7 -12
  856. package/build/serde/temporal.js.map +1 -1
  857. package/build/serde/temporalMappers.cjs +8 -4
  858. package/build/serde/temporalMappers.cjs.map +1 -1
  859. package/build/serde/temporalMappers.d.cts +4 -5
  860. package/build/serde/temporalMappers.d.cts.map +1 -1
  861. package/build/serde/temporalMappers.d.mts +4 -5
  862. package/build/serde/temporalMappers.d.mts.map +1 -1
  863. package/build/serde/temporalMappers.js +8 -4
  864. package/build/serde/temporalMappers.js.map +1 -1
  865. package/build/transitions.cjs +91 -0
  866. package/build/transitions.cjs.map +1 -0
  867. package/build/transitions.d.cts +115 -0
  868. package/build/transitions.d.cts.map +1 -0
  869. package/build/transitions.d.mts +115 -0
  870. package/build/transitions.d.mts.map +1 -0
  871. package/build/transitions.js +86 -0
  872. package/build/transitions.js.map +1 -0
  873. package/build/trusted.d.cts +2 -3
  874. package/build/trusted.d.cts.map +1 -1
  875. package/build/trusted.d.mts +2 -3
  876. package/build/trusted.d.mts.map +1 -1
  877. package/build/typeMap.d.cts +17 -17
  878. package/build/typeMap.d.cts.map +1 -1
  879. package/build/typeMap.d.mts +17 -17
  880. package/build/typeMap.d.mts.map +1 -1
  881. package/build/upsert.cjs +1 -1
  882. package/build/upsert.d.cts +4 -4
  883. package/build/upsert.d.cts.map +1 -1
  884. package/build/upsert.d.mts +4 -4
  885. package/build/upsert.d.mts.map +1 -1
  886. package/build/upsert.js +1 -1
  887. package/build/utils.d.cts +27 -28
  888. package/build/utils.d.cts.map +1 -1
  889. package/build/utils.d.mts +27 -28
  890. package/build/utils.d.mts.map +1 -1
  891. package/package.json +6 -6
@@ -1,14 +1,14 @@
1
+ import { lazyField } from "../newEntity.js";
1
2
  import { AbstractRelationImpl } from "./AbstractRelationImpl.js";
2
3
  import { RelationT, RelationU } from "./RelationSymbols.js";
3
4
  import { ReferenceN } from "./ReferenceSymbols.js";
4
- import { setField } from "../fields.js";
5
5
  import { deTagId } from "../keys.js";
6
6
  import "./Reference.js";
7
7
  import { isCascadeDelete } from "./isCascadeDelete.js";
8
8
  import { failIfNewEntity, failNoId } from "./ManyToOneReference.js";
9
9
  import { oneToOneBatchLoader } from "../batchloaders/oneToOneBatchLoader.js";
10
10
  import { isReactiveReference } from "./ReactiveReference.js";
11
- import { lazyField } from "../newEntity.js";
11
+ import { setField } from "../fields.js";
12
12
  import { getMetadata } from "../EntityMetadata.js";
13
13
  import { ensureNotDeleted } from "../index.js";
14
14
  import { appendStack, getEmInternalApi } from "../EntityManager.js";
@@ -1 +1 @@
1
- {"version":3,"file":"OneToOneReference.js","names":["#field","#hasBeenSet"],"sources":["../../src/relations/OneToOneReference.ts"],"sourcesContent":["import { oneToOneBatchLoader } from \"src/batchloaders/oneToOneBatchLoader.ts\";\nimport { type Entity } from \"src/Entity.ts\";\nimport { type EntityMetadata } from \"src/EntityMetadata.ts\";\nimport { setField } from \"src/fields.ts\";\nimport {\n type IdOf,\n type LoadedReference,\n type OneToOneField,\n type TaggedId,\n appendStack,\n deTagId,\n ensureNotDeleted,\n getEmInternalApi,\n getInstanceData,\n getMetadata,\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 { type ManyToOneReference, failIfNewEntity, failNoId } from \"src/relations/ManyToOneReference.ts\";\nimport { isReactiveReference } from \"src/relations/ReactiveReference.ts\";\nimport { type Reference } from \"src/relations/Reference.ts\";\nimport { ReferenceN } from \"src/relations/ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"src/relations/RelationSymbols.ts\";\n\nconst OneToOne = Symbol();\n\n/** An alias for creating `OneToOneReference`s. */\nexport function hasOneToOne<T extends Entity, U extends Entity>(): OneToOneReference<T, U> {\n return lazyField((entity: T, fieldName) => {\n const o2o = getMetadata(entity).allFields[fieldName] as OneToOneField;\n return new OneToOneReferenceImpl<T, U>(entity, o2o);\n });\n}\n\n/** The lazy-loaded/lookup side of a one-to-one, i.e. the side w/o the unique foreign key column. */\nexport interface OneToOneReference<T extends Entity, U extends Entity> extends Reference<T, U, undefined> {\n // Need to differentiate OneToOneReference from Reference\n [OneToOne]: T;\n}\n\n/** Adds a known-safe `get` accessor. */\nexport interface LoadedOneToOneReference<T extends Entity, U extends Entity> extends LoadedReference<T, U, undefined> {\n get: U | undefined;\n\n getWithDeleted: U | undefined;\n\n // Once OneToOneReference is loaded, it can get a lot of the ManyToOneReference methods that\n // are available even in an unloaded state; below is mostly a copy/paste of those.\n\n /** Returns the id of the current assigned entity or a runtime error if it's either a) unset or b) set to a new entity that doesn't have an `id` yet. */\n id: IdOf<U>;\n\n idIfSet: IdOf<U> | undefined;\n\n idUntagged: string;\n\n idUntaggedMaybe: 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/** Type guard utility for determining if an entity field is a Reference. */\nexport function isOneToOneReference(maybeReference: any): maybeReference is OneToOneReference<any, any> {\n return maybeReference instanceof OneToOneReferenceImpl;\n}\n\n/** Type guard utility for determining if an entity field is a loaded Reference. */\nexport function isLoadedOneToOneReference(\n maybeReference: any,\n): maybeReference is Reference<any, any, any> & LoadedOneToOneReference<any, any> {\n return isOneToOneReference(maybeReference) && maybeReference.isLoaded;\n}\n\n/**\n * Represents the \"many\" side of a one-to-one relationship.\n *\n * I.e. in a one-to-many from Book -> Reviews, there is a review.book_id that can have many books.\n *\n * This class is for when that `review.book_id` column is itself unique, i.e. like `image.book_id`, and\n * so instead of `Book.images: OneToManyCollection` we have a `Book.image: OneToOneReference`.\n *\n * This class implements `Reference` because it is essentially like \"one entity pointing/refereing to another\",\n * however because we require a `.load` call to lazily know the value of other side (unlike ManyToOneReference\n * which has it's `book_id` column immediately available in the entity `data` hash), there is some wonkiness\n * around methods like `Reference.id` that are usually callable without `load`/`populate`, that for this\n * class can actually only be called post `load`/`populate`.\n *\n * Currently we enforce this with a runtime check, which is not great, but the trade-off of implementing\n * `Reference` seemed worth the downside of a un-type-safe `.id` property.\n */\nexport class OneToOneReferenceImpl<T extends Entity, U extends Entity>\n extends AbstractRelationImpl<T, U>\n implements OneToOneReference<T, U>\n{\n #field: OneToOneField;\n private loaded: U | undefined;\n private _isLoaded: boolean = false;\n #hasBeenSet = false;\n\n constructor(entity: T, field: OneToOneField) {\n super(entity);\n this.#field = field;\n if (getInstanceData(entity).isOrWasNew) {\n this._isLoaded = true;\n }\n }\n\n // These are public to our internal implementation but not exposed in the Collection API\n get fieldName(): keyof T & string {\n return this.#field.fieldName as keyof T & string;\n }\n\n get otherFieldName(): keyof U & string {\n return this.#field.otherFieldName as keyof U & string;\n }\n\n get id(): IdOf<U> {\n return this.idMaybe || failNoId(this.entity, this.fieldName, this.loaded);\n }\n\n get idIfSet(): IdOf<U> | undefined {\n if (this._isLoaded) {\n return this.idMaybe || failIfNewEntity(this.entity, this.fieldName, this.loaded);\n }\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n\n get idUntagged(): string {\n return this.idUntaggedMaybe || failNoId(this.entity, this.fieldName, this.loaded);\n }\n\n get idUntaggedIfSet(): string | undefined {\n return this.idUntaggedMaybe || failIfNewEntity(this.entity, this.fieldName, this.loaded);\n }\n\n private get idMaybe(): IdOf<U> | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n if (this._isLoaded) {\n return this.loaded?.idMaybe as IdOf<U> | undefined;\n }\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n\n get idTaggedMaybe(): TaggedId | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n if (this._isLoaded) {\n return this.loaded?.idTaggedMaybe;\n }\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n\n private get idUntaggedMaybe(): string | undefined {\n return deTagId(this.otherMeta, this.idMaybe);\n }\n\n get isSet(): boolean {\n if (this._isLoaded) {\n return this.loaded !== undefined;\n }\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n\n // opts is an internal parameter\n async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<U | undefined> {\n ensureNotDeleted(this.entity, \"pending\");\n if (!this._isLoaded || opts.forceReload) {\n if (!this.entity.isNewEntity) {\n const joinLoaded = this.getPreloaded();\n if (joinLoaded) {\n this.loaded = joinLoaded[0];\n } else {\n try {\n await oneToOneBatchLoader(this.entity.em, this).load(this.entity.idTagged);\n } catch (err) {\n throw appendStack(err as Error, new Error());\n }\n this.preload();\n }\n }\n this._isLoaded = true;\n }\n return this.filterDeleted(this.loaded, opts);\n }\n\n set(other: U, opts: { percolating?: boolean } = {}): void {\n ensureNotDeleted(this.entity, \"pending\");\n this.#hasBeenSet = true;\n if (other === this.loaded) {\n this._isLoaded = true;\n return;\n }\n if (this._isLoaded) {\n if (this.loaded && !opts.percolating) {\n this.getOtherRelation(this.loaded).set(undefined);\n }\n }\n const { fieldLogger } = getEmInternalApi(this.entity.em);\n fieldLogger.logSet(this.entity, this.fieldName, other);\n this.loaded = other;\n this._isLoaded = true;\n // This will no-op and mark other dirty if necessary\n if (other && !opts.percolating) {\n this.getOtherRelation(other).set(this.entity);\n }\n }\n\n get isLoaded(): boolean {\n return this._isLoaded;\n }\n\n get isPreloaded(): boolean {\n return !!this.getPreloaded();\n }\n\n preload(): void {\n this.loaded = this.getPreloaded()?.[0];\n this._isLoaded = true;\n }\n\n import(other: OneToOneReferenceImpl<T, U>, findEntity: (e: U) => U): void {\n this.loaded = other.loaded ? findEntity(other.loaded) : undefined;\n this._isLoaded = true;\n }\n\n get getWithDeleted(): U | undefined {\n return this.filterDeleted(this.doGet(), { withDeleted: true });\n }\n\n get get(): U | undefined {\n return this.filterDeleted(this.doGet(), { withDeleted: false });\n }\n\n get otherMeta(): EntityMetadata {\n return this.#field.otherMetadata();\n }\n\n private doGet(): U | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n if (!this._isLoaded) {\n // This should only be callable in the type system if we've already resolved this to an instance\n throw new Error(\"get was called when not loaded\");\n }\n return this.loaded;\n }\n\n // internal impl\n\n setFromOpts(other: U): void {\n this.set(other);\n }\n\n maybeCascadeDelete(): void {\n if (this.isCascadeDelete && this.loaded) {\n this.entity.em.delete(this.loaded);\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 otherSide = this.getOtherRelation(current);\n // Don't call `ReactiveReference.set` because it'll blow up\n if (!isReactiveReference(otherSide)) {\n otherSide.set(undefined as any);\n }\n setField(current, this.otherFieldName, undefined);\n }\n this.loaded = undefined as any;\n this._isLoaded = true;\n }\n\n get hasBeenSet() {\n return this.#hasBeenSet;\n }\n\n public toString(): string {\n return `OneToOneReference(entity: ${this.entity}, fieldName: ${this.fieldName}, otherType: ${this.otherMeta.type}, otherFieldName: ${this.otherFieldName})`;\n }\n\n private filterDeleted(entity: U | undefined, opts?: { withDeleted?: boolean }): U | undefined {\n return opts?.withDeleted === true || entity === undefined || !entity.isDeletedEntity ? entity : undefined;\n }\n\n /** Returns the other relation that points back at us, i.e. we're `Author.image` and this is `Image.author_id`. */\n private getOtherRelation(other: U): ManyToOneReference<U, T, any> {\n return (other as U)[this.otherFieldName] as any;\n }\n\n private getPreloaded(): U[] | undefined {\n if (this.entity.isNewEntity) return undefined;\n return getEmInternalApi(this.entity.em).getPreloadedRelation(this.entity.idTagged, this.fieldName);\n }\n\n private get isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.fieldName);\n }\n\n [RelationT] = null!;\n [RelationU] = null!;\n [ReferenceN] = null!;\n [OneToOne] = null!;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyBA,MAAM,WAAW,OAAO;;AAGxB,SAAgB,cAA2E;CACzF,OAAO,WAAW,QAAW,cAAc;EACzC,MAAM,MAAM,YAAY,MAAM,CAAC,CAAC,UAAU;EAC1C,OAAO,IAAI,sBAA4B,QAAQ,GAAG;CACpD,CAAC;AACH;;AA+BA,SAAgB,oBAAoB,gBAAoE;CACtG,OAAO,0BAA0B;AACnC;;AAGA,SAAgB,0BACd,gBACgF;CAChF,OAAO,oBAAoB,cAAc,KAAK,eAAe;AAC/D;;;;;;;;;;;;;;;;;;AAmBA,IAAa,wBAAb,cACU,qBAEV;CACE;CACA;CACA,YAA6B;CAC7B,cAAc;CAEd,YAAY,QAAW,OAAsB;EAC3C,MAAM,MAAM;EACZ,KAAKA,SAAS;EACd,IAAI,gBAAgB,MAAM,CAAC,CAAC,YAC1B,KAAK,YAAY;CAErB;CAGA,IAAI,YAA8B;EAChC,OAAO,KAAKA,OAAO;CACrB;CAEA,IAAI,iBAAmC;EACrC,OAAO,KAAKA,OAAO;CACrB;CAEA,IAAI,KAAc;EAChB,OAAO,KAAK,WAAW,SAAS,KAAK,QAAQ,KAAK,WAAW,KAAK,MAA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AACf"}
1
+ {"version":3,"file":"OneToOneReference.js","names":[],"sources":["../../src/relations/OneToOneReference.ts"],"sourcesContent":["import { oneToOneBatchLoader } from \"src/batchloaders/oneToOneBatchLoader.ts\";\nimport { type Entity } from \"src/Entity.ts\";\nimport { type EntityMetadata } from \"src/EntityMetadata.ts\";\nimport { setField } from \"src/fields.ts\";\nimport {\n type IdOf,\n type LoadedReference,\n type OneToOneField,\n type TaggedId,\n appendStack,\n deTagId,\n ensureNotDeleted,\n getEmInternalApi,\n getInstanceData,\n getMetadata,\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 { type ManyToOneReference, failIfNewEntity, failNoId } from \"src/relations/ManyToOneReference.ts\";\nimport { isReactiveReference } from \"src/relations/ReactiveReference.ts\";\nimport { type Reference } from \"src/relations/Reference.ts\";\nimport { ReferenceN } from \"src/relations/ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"src/relations/RelationSymbols.ts\";\n\nconst OneToOne = Symbol();\n\n/** An alias for creating `OneToOneReference`s. */\nexport function hasOneToOne<T extends Entity, U extends Entity>(): OneToOneReference<T, U> {\n return lazyField((entity: T, fieldName) => {\n const o2o = getMetadata(entity).allFields[fieldName] as OneToOneField;\n return new OneToOneReferenceImpl<T, U>(entity, o2o);\n });\n}\n\n/** The lazy-loaded/lookup side of a one-to-one, i.e. the side w/o the unique foreign key column. */\nexport interface OneToOneReference<T extends Entity, U extends Entity> extends Reference<T, U, undefined> {\n // Need to differentiate OneToOneReference from Reference\n [OneToOne]: T;\n}\n\n/** Adds a known-safe `get` accessor. */\nexport interface LoadedOneToOneReference<T extends Entity, U extends Entity> extends LoadedReference<T, U, undefined> {\n get: U | undefined;\n\n getWithDeleted: U | undefined;\n\n // Once OneToOneReference is loaded, it can get a lot of the ManyToOneReference methods that\n // are available even in an unloaded state; below is mostly a copy/paste of those.\n\n /** Returns the id of the current assigned entity or a runtime error if it's either a) unset or b) set to a new entity that doesn't have an `id` yet. */\n id: IdOf<U>;\n\n idIfSet: IdOf<U> | undefined;\n\n idUntagged: string;\n\n idUntaggedMaybe: 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/** Type guard utility for determining if an entity field is a Reference. */\nexport function isOneToOneReference(maybeReference: any): maybeReference is OneToOneReference<any, any> {\n return maybeReference instanceof OneToOneReferenceImpl;\n}\n\n/** Type guard utility for determining if an entity field is a loaded Reference. */\nexport function isLoadedOneToOneReference(\n maybeReference: any,\n): maybeReference is Reference<any, any, any> & LoadedOneToOneReference<any, any> {\n return isOneToOneReference(maybeReference) && maybeReference.isLoaded;\n}\n\n/**\n * Represents the \"many\" side of a one-to-one relationship.\n *\n * I.e. in a one-to-many from Book -> Reviews, there is a review.book_id that can have many books.\n *\n * This class is for when that `review.book_id` column is itself unique, i.e. like `image.book_id`, and\n * so instead of `Book.images: OneToManyCollection` we have a `Book.image: OneToOneReference`.\n *\n * This class implements `Reference` because it is essentially like \"one entity pointing/refereing to another\",\n * however because we require a `.load` call to lazily know the value of other side (unlike ManyToOneReference\n * which has it's `book_id` column immediately available in the entity `data` hash), there is some wonkiness\n * around methods like `Reference.id` that are usually callable without `load`/`populate`, that for this\n * class can actually only be called post `load`/`populate`.\n *\n * Currently we enforce this with a runtime check, which is not great, but the trade-off of implementing\n * `Reference` seemed worth the downside of a un-type-safe `.id` property.\n */\nexport class OneToOneReferenceImpl<T extends Entity, U extends Entity>\n extends AbstractRelationImpl<T, U>\n implements OneToOneReference<T, U>\n{\n #field: OneToOneField;\n private loaded: U | undefined;\n private _isLoaded: boolean = false;\n #hasBeenSet = false;\n\n constructor(entity: T, field: OneToOneField) {\n super(entity);\n this.#field = field;\n if (getInstanceData(entity).isOrWasNew) {\n this._isLoaded = true;\n }\n }\n\n // These are public to our internal implementation but not exposed in the Collection API\n get fieldName(): keyof T & string {\n return this.#field.fieldName as keyof T & string;\n }\n\n get otherFieldName(): keyof U & string {\n return this.#field.otherFieldName as keyof U & string;\n }\n\n get id(): IdOf<U> {\n return this.idMaybe || failNoId(this.entity, this.fieldName, this.loaded);\n }\n\n get idIfSet(): IdOf<U> | undefined {\n if (this._isLoaded) {\n return this.idMaybe || failIfNewEntity(this.entity, this.fieldName, this.loaded);\n }\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n\n get idUntagged(): string {\n return this.idUntaggedMaybe || failNoId(this.entity, this.fieldName, this.loaded);\n }\n\n get idUntaggedIfSet(): string | undefined {\n return this.idUntaggedMaybe || failIfNewEntity(this.entity, this.fieldName, this.loaded);\n }\n\n private get idMaybe(): IdOf<U> | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n if (this._isLoaded) {\n return this.loaded?.idMaybe as IdOf<U> | undefined;\n }\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n\n get idTaggedMaybe(): TaggedId | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n if (this._isLoaded) {\n return this.loaded?.idTaggedMaybe;\n }\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n\n private get idUntaggedMaybe(): string | undefined {\n return deTagId(this.otherMeta, this.idMaybe);\n }\n\n get isSet(): boolean {\n if (this._isLoaded) {\n return this.loaded !== undefined;\n }\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n\n // opts is an internal parameter\n async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<U | undefined> {\n ensureNotDeleted(this.entity, \"pending\");\n if (!this._isLoaded || opts.forceReload) {\n if (!this.entity.isNewEntity) {\n const joinLoaded = this.getPreloaded();\n if (joinLoaded) {\n this.loaded = joinLoaded[0];\n } else {\n try {\n await oneToOneBatchLoader(this.entity.em, this).load(this.entity.idTagged);\n } catch (err) {\n throw appendStack(err as Error, new Error());\n }\n this.preload();\n }\n }\n this._isLoaded = true;\n }\n return this.filterDeleted(this.loaded, opts);\n }\n\n set(other: U, opts: { percolating?: boolean } = {}): void {\n ensureNotDeleted(this.entity, \"pending\");\n this.#hasBeenSet = true;\n if (other === this.loaded) {\n this._isLoaded = true;\n return;\n }\n if (this._isLoaded) {\n if (this.loaded && !opts.percolating) {\n this.getOtherRelation(this.loaded).set(undefined);\n }\n }\n const { fieldLogger } = getEmInternalApi(this.entity.em);\n fieldLogger.logSet(this.entity, this.fieldName, other);\n this.loaded = other;\n this._isLoaded = true;\n // This will no-op and mark other dirty if necessary\n if (other && !opts.percolating) {\n this.getOtherRelation(other).set(this.entity);\n }\n }\n\n get isLoaded(): boolean {\n return this._isLoaded;\n }\n\n get isPreloaded(): boolean {\n return !!this.getPreloaded();\n }\n\n preload(): void {\n this.loaded = this.getPreloaded()?.[0];\n this._isLoaded = true;\n }\n\n import(other: OneToOneReferenceImpl<T, U>, findEntity: (e: U) => U): void {\n this.loaded = other.loaded ? findEntity(other.loaded) : undefined;\n this._isLoaded = true;\n }\n\n get getWithDeleted(): U | undefined {\n return this.filterDeleted(this.doGet(), { withDeleted: true });\n }\n\n get get(): U | undefined {\n return this.filterDeleted(this.doGet(), { withDeleted: false });\n }\n\n get otherMeta(): EntityMetadata {\n return this.#field.otherMetadata();\n }\n\n private doGet(): U | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n if (!this._isLoaded) {\n // This should only be callable in the type system if we've already resolved this to an instance\n throw new Error(\"get was called when not loaded\");\n }\n return this.loaded;\n }\n\n // internal impl\n\n setFromOpts(other: U): void {\n this.set(other);\n }\n\n maybeCascadeDelete(): void {\n if (this.isCascadeDelete && this.loaded) {\n this.entity.em.delete(this.loaded);\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 otherSide = this.getOtherRelation(current);\n // Don't call `ReactiveReference.set` because it'll blow up\n if (!isReactiveReference(otherSide)) {\n otherSide.set(undefined as any);\n }\n setField(current, this.otherFieldName, undefined);\n }\n this.loaded = undefined as any;\n this._isLoaded = true;\n }\n\n get hasBeenSet() {\n return this.#hasBeenSet;\n }\n\n public toString(): string {\n return `OneToOneReference(entity: ${this.entity}, fieldName: ${this.fieldName}, otherType: ${this.otherMeta.type}, otherFieldName: ${this.otherFieldName})`;\n }\n\n private filterDeleted(entity: U | undefined, opts?: { withDeleted?: boolean }): U | undefined {\n return opts?.withDeleted === true || entity === undefined || !entity.isDeletedEntity ? entity : undefined;\n }\n\n /** Returns the other relation that points back at us, i.e. we're `Author.image` and this is `Image.author_id`. */\n private getOtherRelation(other: U): ManyToOneReference<U, T, any> {\n return (other as U)[this.otherFieldName] as any;\n }\n\n private getPreloaded(): U[] | undefined {\n if (this.entity.isNewEntity) return undefined;\n return getEmInternalApi(this.entity.em).getPreloadedRelation(this.entity.idTagged, this.fieldName);\n }\n\n private get isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.fieldName);\n }\n\n [RelationT] = null!;\n [RelationU] = null!;\n [ReferenceN] = null!;\n [OneToOne] = null!;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyBA,MAAM,WAAW,OAAO;;AAGxB,SAAgB,cAA2E;CACzF,OAAO,WAAW,QAAW,cAAc;EACzC,MAAM,MAAM,YAAY,MAAM,CAAC,CAAC,UAAU;EAC1C,OAAO,IAAI,sBAA4B,QAAQ,GAAG;CACpD,CAAC;AACH;;AA+BA,SAAgB,oBAAoB,gBAAoE;CACtG,OAAO,0BAA0B;AACnC;;AAGA,SAAgB,0BACd,gBACgF;CAChF,OAAO,oBAAoB,cAAc,KAAK,eAAe;AAC/D;;;;;;;;;;;;;;;;;;AAmBA,IAAa,wBAAb,cACU,qBAEV;CACE;CACA;CACA,YAA6B;CAC7B,cAAc;CAEd,YAAY,QAAW,OAAsB;EAC3C,MAAM,MAAM;EACZ,KAAK,SAAS;EACd,IAAI,gBAAgB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OAAO,iBAAiB,KAAK,OAAO,EAAE,CAAC,CAAC,qBAAqB,KAAK,OAAO,UAAU,KAAK,SAAS;CACnG;CAEA,IAAY,kBAA2B;EACrC,OAAO,gBAAgB,MAAM,KAAK,SAAS;CAC7C;CAEA,CAAC,aAAa;CACd,CAAC,aAAa;CACd,CAAC,cAAc;CACf,CAAC,YAAY;AACf"}
@@ -1,14 +1,14 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_newEntity = require("../newEntity.cjs");
2
3
  const require_relations_AbstractRelationImpl = require("./AbstractRelationImpl.cjs");
3
4
  const require_relations_RelationSymbols = require("./RelationSymbols.cjs");
4
5
  const require_relations_ReferenceSymbols = require("./ReferenceSymbols.cjs");
5
- const require_fields = require("../fields.cjs");
6
6
  const require_keys = require("../keys.cjs");
7
7
  const require_relations_isCascadeDelete = require("./isCascadeDelete.cjs");
8
8
  const require_relations_OneToManyCollection = require("./OneToManyCollection.cjs");
9
9
  const require_relations_ManyToOneReference = require("./ManyToOneReference.cjs");
10
10
  const require_utils = require("../utils.cjs");
11
- const require_newEntity = require("../newEntity.cjs");
11
+ const require_fields = require("../fields.cjs");
12
12
  const require_configure = require("../configure.cjs");
13
13
  const require_EntityMetadata = require("../EntityMetadata.cjs");
14
14
  const require_index = require("../index.cjs");
@@ -1 +1 @@
1
- {"version":3,"file":"PolymorphicReference.cjs","names":["lazyField","AbstractRelationImpl","getMetadata","getInstanceData","maybeGetConstructorFromReference","isCascadeDelete","isEntity","getConstructorFromTaggedId","failNoId","maybeResolveReferenceToId","failIfNewEntity","#hasBeenSet","OneToManyCollection","sameEntity","getField","RelationT","RelationU","ReferenceN"],"sources":["../../src/relations/PolymorphicReference.ts"],"sourcesContent":["import { maybeGetConstructorFromReference } from \"src/configure.ts\";\nimport { type Entity, isEntity } from \"src/Entity.ts\";\nimport { type IdOf, type TaggedId, sameEntity } from \"src/EntityManager.ts\";\nimport { type PolymorphicFieldComponent, getMetadata } from \"src/EntityMetadata.ts\";\nimport { getField, setField } from \"src/fields.ts\";\nimport {\n type OneToOneReference,\n type PolymorphicField,\n type Reference,\n ensureNotDeleted,\n fail,\n getConstructorFromTaggedId,\n getInstanceData,\n maybeResolveReferenceToId,\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 { failIfNewEntity, failNoId } from \"src/relations/ManyToOneReference.ts\";\nimport { OneToManyCollection } from \"src/relations/OneToManyCollection.ts\";\nimport { ReferenceN } from \"src/relations/ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"src/relations/RelationSymbols.ts\";\n\nexport function hasOnePolymorphic<\n T extends Entity,\n U extends Entity,\n N extends never | undefined,\n>(): PolymorphicReference<T, U, N> {\n return lazyField((entity: T, fieldName) => {\n return new PolymorphicReferenceImpl<T, U, N>(entity, fieldName as keyof T & string);\n });\n}\n\n/** Type guard utility for determining if an entity field is a PolymorphicReference. */\nexport function isPolymorphicReference(maybeReference: any): maybeReference is PolymorphicReference<any, any, any> {\n return maybeReference instanceof PolymorphicReferenceImpl;\n}\n\n/**\n * A reference that can be assigned to multiple different entity types.\n *\n * I.e. a `Comment.parent` reference that can be an `Author` or `Book`.\n *\n * The `U` generic will be the type union of `Author | Book`.\n */\nexport interface PolymorphicReference<\n T extends Entity,\n U extends Entity,\n N extends never | undefined,\n> extends Reference<T, U, 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 idTagged: string;\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 set of foreign keys from one entity to another, i.e. `Comment.parent --> Book | BookReview`.\n *\n * We keep the current `parent` / `parent.id` value in the `__orm.data` hash, where the\n * current value could be either the `comments.parent_book_id` / `comments.parent_book_review_id` id (as a tagged string)\n * from the database, or an entity `Book` / `BookReview` that the user has set.\n *\n * Note that if any of our columns (eg `comments.parent_book_review_id`) is unique, this `PolymorphicReference` will\n * essentially be half of a one-to-one relationship, but we'll keep using this reference on the \"owning\" side; the other\n * side, i.e. `BookReview.comment` will use a `OneToOneReference` to point back to us.\n */\nexport class PolymorphicReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined>\n extends AbstractRelationImpl<T, U>\n implements PolymorphicReference<T, U, N>\n{\n private loaded: U | N | undefined;\n // We need a separate boolean to b/c loaded == undefined can still mean \"_isLoaded\" for nullable fks.\n private _isLoaded = false;\n private field: PolymorphicField;\n #hasBeenSet = false;\n\n constructor(\n entity: T,\n public fieldName: keyof T & string,\n ) {\n super(entity);\n this.field = getMetadata(entity).allFields[this.fieldName] as PolymorphicField;\n if (getInstanceData(entity).isOrWasNew) {\n this._isLoaded = true;\n }\n }\n\n private get currentComponent(): PolymorphicFieldComponent | N {\n const cstr = maybeGetConstructorFromReference(this.current());\n return this.field.components.find((c) => c.otherMetadata().cstr === cstr) as any;\n }\n\n private get isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.fieldName);\n }\n\n async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<U | N> {\n ensureNotDeleted(this.entity, \"pending\");\n const current = this.current();\n // Resolve the id to an entity\n if (!this._isLoaded || opts.forceReload) {\n this.loaded =\n isEntity(current) || current === undefined\n ? (current as U | undefined)\n : ((await this.entity.em.load(getConstructorFromTaggedId(current), current)) as U);\n }\n this._isLoaded = true;\n return this.filterDeleted(this.loaded!, 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 return this._isLoaded;\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 this.loaded first b/c a new entity won't have an id yet\n const { idTaggedMaybe } = this;\n return this.loaded ?? (idTaggedMaybe !== undefined ? (this.entity.em.getEntity(idTaggedMaybe) as U) : undefined);\n }\n\n get isPreloaded(): boolean {\n return !!this.maybeFindEntity();\n }\n\n preload(): void {\n this.loaded = this.maybeFindEntity();\n this._isLoaded = true;\n }\n\n private unload(): void {\n this.loaded = undefined;\n this._isLoaded = false;\n }\n\n import(other: PolymorphicReferenceImpl<T, U, N>, findEntity: (e: U) => U): void {\n this.loaded = other.loaded ? findEntity(other.loaded) : undefined;\n this._isLoaded = true;\n }\n\n private doGet(opts?: { withDeleted?: boolean }): U | N {\n ensureNotDeleted(this.entity, \"pending\");\n // This should only be callable in the type system if we've already resolved this to an instance,\n // but, just in case we somehow got here in an unloaded state, check to see if we're already in the UoW\n if (!this._isLoaded) {\n const existing = this.maybeFindExisting();\n if (existing === undefined) {\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n this.loaded = existing;\n this._isLoaded = true;\n }\n\n return this.filterDeleted(this.loaded!, 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 get id(): IdOf<U> {\n return this.idMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idMaybe(): IdOf<U> | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current()) as IdOf<U> | undefined;\n }\n\n get idIfSet(): IdOf<U> | N | undefined {\n return this.idMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get idTagged(): string {\n return this.idTaggedMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idTaggedMaybe(): string | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current());\n }\n\n get hasBeenSet() {\n return this.#hasBeenSet;\n }\n\n // private impl\n\n setFromOpts(other: U): 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 && typeof current !== \"string\") {\n this.entity.em.delete(current as U);\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 {\n o2m.set(undefined as any);\n }\n }\n setField(this.entity, this.fieldName, undefined);\n this.loaded = undefined as any;\n this._isLoaded = true;\n }\n\n // Internal method used by PolymorphicReference\n setImpl(other: U | N): void {\n this.#hasBeenSet = true;\n\n if (sameEntity(other, this.current({ withDeleted: true }))) {\n return;\n }\n\n if (\n other !== undefined &&\n !this.field.components.some(\n (c) =>\n other instanceof c.otherMetadata().cstr ||\n (typeof other === \"string\" && getConstructorFromTaggedId(other) === c.otherMetadata().cstr),\n )\n ) {\n fail(`${other} cannot be set as '${this.field.fieldName}' on ${this.entity}`);\n }\n\n // we may not be loaded yet, but our previous entity might already be in the UoW\n const previousLoaded = this.loaded ?? this.maybeFindExisting();\n\n ensureNotDeleted(this.entity, \"pending\");\n\n // Keep the entity when its tagged id cannot distinguish between sibling subtypes.\n if (isEntity(other)) {\n const otherMeta = getMetadata(other);\n const hasComponentsWithSameBaseType =\n otherMeta.baseType &&\n this.field.components.some(\n (component) =>\n component.otherMetadata().baseType === otherMeta.baseType &&\n !(other instanceof component.otherMetadata().cstr),\n );\n setField(\n this.entity,\n this.fieldName,\n other.isNewEntity || hasComponentsWithSameBaseType ? other : other.idTagged,\n );\n } else {\n setField(this.entity, this.fieldName, other);\n }\n\n if (typeof other === \"string\") {\n this.loaded = undefined;\n this._isLoaded = false;\n } else {\n this.loaded = other;\n this._isLoaded = true;\n }\n\n // If had an existing value, remove us from its collection\n if (previousLoaded) {\n const prevRelation = this.getOtherRelation(previousLoaded);\n if (prevRelation instanceof OneToManyCollection) {\n prevRelation.removeIfLoaded(this.entity);\n } else {\n prevRelation.set(undefined as any);\n }\n }\n if (other !== undefined && isEntity(other)) {\n const newRelation = this.getOtherRelation(other);\n if (newRelation instanceof OneToManyCollection) {\n newRelation.add(this.entity);\n } else {\n newRelation.set(this.entity);\n }\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 public toString(): string {\n return `PolymorphicReference(entity: ${this.entity}, fieldName: ${\n this.fieldName\n }, otherType: ${this.currentComponent?.otherMetadata().type}, otherFieldName: ${\n this.currentComponent?.otherFieldName\n }, id: ${this.id})`;\n }\n\n private filterDeleted(entity: U | N, opts?: { withDeleted?: boolean }): U | N {\n return opts?.withDeleted === true || entity === undefined || !entity.isDeletedEntity ? entity : (undefined as N);\n }\n\n /** Returns the other relation that points back at us, i.e. we're `comment.parent_book_id` and this is `Book.comments`. */\n private getOtherRelation(other: U): OneToManyCollection<U, T> | OneToOneReference<U, T> {\n const component = this.field.components.find((c) => other instanceof c.otherMetadata().cstr) as any;\n return (other as U)[component?.otherFieldName as keyof U] as any;\n }\n\n private maybeFindExisting(): U | undefined {\n return this.idTaggedMaybe !== undefined ? (this.entity.em.getEntity(this.idTagged) as U) : undefined;\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n [ReferenceN]: N = null!;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuBA,SAAgB,oBAImB;CACjC,OAAOA,kBAAAA,WAAW,QAAW,cAAc;EACzC,OAAO,IAAI,yBAAkC,QAAQ,SAA6B;CACpF,CAAC;AACH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AAO,MAAM,gBAAgB,QAAQ,WAAW,KAAA,KAAa,CAAC,OAAO,kBAAkB,SAAU,KAAA;CACnG;;CAGA,iBAAyB,OAA+D;EAEtF,OAAQ,MADU,KAAK,MAAM,WAAW,MAAM,MAAM,iBAAiB,EAAE,cAAc,CAAC,CAAC,IAC3D,CAAC,EAAE;CACjC;CAEA,oBAA2C;EACzC,OAAO,KAAK,kBAAkB,KAAA,IAAa,KAAK,OAAO,GAAG,UAAU,KAAK,QAAQ,IAAU,KAAA;CAC7F;CAEA,CAACS,kCAAAA,aAAgB;CACjB,CAACC,kCAAAA,aAAgB;CACjB,CAACC,mCAAAA,cAAiB;AACpB"}
1
+ {"version":3,"file":"PolymorphicReference.cjs","names":["lazyField","AbstractRelationImpl","getMetadata","getInstanceData","maybeGetConstructorFromReference","isCascadeDelete","isEntity","getConstructorFromTaggedId","failNoId","maybeResolveReferenceToId","failIfNewEntity","OneToManyCollection","sameEntity","getField","RelationT","RelationU","ReferenceN"],"sources":["../../src/relations/PolymorphicReference.ts"],"sourcesContent":["import { maybeGetConstructorFromReference } from \"src/configure.ts\";\nimport { type Entity, isEntity } from \"src/Entity.ts\";\nimport { type IdOf, type TaggedId, sameEntity } from \"src/EntityManager.ts\";\nimport { type PolymorphicFieldComponent, getMetadata } from \"src/EntityMetadata.ts\";\nimport { getField, setField } from \"src/fields.ts\";\nimport {\n type OneToOneReference,\n type PolymorphicField,\n type Reference,\n ensureNotDeleted,\n fail,\n getConstructorFromTaggedId,\n getInstanceData,\n maybeResolveReferenceToId,\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 { failIfNewEntity, failNoId } from \"src/relations/ManyToOneReference.ts\";\nimport { OneToManyCollection } from \"src/relations/OneToManyCollection.ts\";\nimport { ReferenceN } from \"src/relations/ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"src/relations/RelationSymbols.ts\";\n\nexport function hasOnePolymorphic<\n T extends Entity,\n U extends Entity,\n N extends never | undefined,\n>(): PolymorphicReference<T, U, N> {\n return lazyField((entity: T, fieldName) => {\n return new PolymorphicReferenceImpl<T, U, N>(entity, fieldName as keyof T & string);\n });\n}\n\n/** Type guard utility for determining if an entity field is a PolymorphicReference. */\nexport function isPolymorphicReference(maybeReference: any): maybeReference is PolymorphicReference<any, any, any> {\n return maybeReference instanceof PolymorphicReferenceImpl;\n}\n\n/**\n * A reference that can be assigned to multiple different entity types.\n *\n * I.e. a `Comment.parent` reference that can be an `Author` or `Book`.\n *\n * The `U` generic will be the type union of `Author | Book`.\n */\nexport interface PolymorphicReference<\n T extends Entity,\n U extends Entity,\n N extends never | undefined,\n> extends Reference<T, U, 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 idTagged: string;\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 set of foreign keys from one entity to another, i.e. `Comment.parent --> Book | BookReview`.\n *\n * We keep the current `parent` / `parent.id` value in the `__orm.data` hash, where the\n * current value could be either the `comments.parent_book_id` / `comments.parent_book_review_id` id (as a tagged string)\n * from the database, or an entity `Book` / `BookReview` that the user has set.\n *\n * Note that if any of our columns (eg `comments.parent_book_review_id`) is unique, this `PolymorphicReference` will\n * essentially be half of a one-to-one relationship, but we'll keep using this reference on the \"owning\" side; the other\n * side, i.e. `BookReview.comment` will use a `OneToOneReference` to point back to us.\n */\nexport class PolymorphicReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined>\n extends AbstractRelationImpl<T, U>\n implements PolymorphicReference<T, U, N>\n{\n private loaded: U | N | undefined;\n // We need a separate boolean to b/c loaded == undefined can still mean \"_isLoaded\" for nullable fks.\n private _isLoaded = false;\n private field: PolymorphicField;\n #hasBeenSet = false;\n\n constructor(\n entity: T,\n public fieldName: keyof T & string,\n ) {\n super(entity);\n this.field = getMetadata(entity).allFields[this.fieldName] as PolymorphicField;\n if (getInstanceData(entity).isOrWasNew) {\n this._isLoaded = true;\n }\n }\n\n private get currentComponent(): PolymorphicFieldComponent | N {\n const cstr = maybeGetConstructorFromReference(this.current());\n return this.field.components.find((c) => c.otherMetadata().cstr === cstr) as any;\n }\n\n private get isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.fieldName);\n }\n\n async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<U | N> {\n ensureNotDeleted(this.entity, \"pending\");\n const current = this.current();\n // Resolve the id to an entity\n if (!this._isLoaded || opts.forceReload) {\n this.loaded =\n isEntity(current) || current === undefined\n ? (current as U | undefined)\n : ((await this.entity.em.load(getConstructorFromTaggedId(current), current)) as U);\n }\n this._isLoaded = true;\n return this.filterDeleted(this.loaded!, 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 return this._isLoaded;\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 this.loaded first b/c a new entity won't have an id yet\n const { idTaggedMaybe } = this;\n return this.loaded ?? (idTaggedMaybe !== undefined ? (this.entity.em.getEntity(idTaggedMaybe) as U) : undefined);\n }\n\n get isPreloaded(): boolean {\n return !!this.maybeFindEntity();\n }\n\n preload(): void {\n this.loaded = this.maybeFindEntity();\n this._isLoaded = true;\n }\n\n private unload(): void {\n this.loaded = undefined;\n this._isLoaded = false;\n }\n\n import(other: PolymorphicReferenceImpl<T, U, N>, findEntity: (e: U) => U): void {\n this.loaded = other.loaded ? findEntity(other.loaded) : undefined;\n this._isLoaded = true;\n }\n\n private doGet(opts?: { withDeleted?: boolean }): U | N {\n ensureNotDeleted(this.entity, \"pending\");\n // This should only be callable in the type system if we've already resolved this to an instance,\n // but, just in case we somehow got here in an unloaded state, check to see if we're already in the UoW\n if (!this._isLoaded) {\n const existing = this.maybeFindExisting();\n if (existing === undefined) {\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n this.loaded = existing;\n this._isLoaded = true;\n }\n\n return this.filterDeleted(this.loaded!, 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 get id(): IdOf<U> {\n return this.idMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idMaybe(): IdOf<U> | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current()) as IdOf<U> | undefined;\n }\n\n get idIfSet(): IdOf<U> | N | undefined {\n return this.idMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get idTagged(): string {\n return this.idTaggedMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idTaggedMaybe(): string | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current());\n }\n\n get hasBeenSet() {\n return this.#hasBeenSet;\n }\n\n // private impl\n\n setFromOpts(other: U): 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 && typeof current !== \"string\") {\n this.entity.em.delete(current as U);\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 {\n o2m.set(undefined as any);\n }\n }\n setField(this.entity, this.fieldName, undefined);\n this.loaded = undefined as any;\n this._isLoaded = true;\n }\n\n // Internal method used by PolymorphicReference\n setImpl(other: U | N): void {\n this.#hasBeenSet = true;\n\n if (sameEntity(other, this.current({ withDeleted: true }))) {\n return;\n }\n\n if (\n other !== undefined &&\n !this.field.components.some(\n (c) =>\n other instanceof c.otherMetadata().cstr ||\n (typeof other === \"string\" && getConstructorFromTaggedId(other) === c.otherMetadata().cstr),\n )\n ) {\n fail(`${other} cannot be set as '${this.field.fieldName}' on ${this.entity}`);\n }\n\n // we may not be loaded yet, but our previous entity might already be in the UoW\n const previousLoaded = this.loaded ?? this.maybeFindExisting();\n\n ensureNotDeleted(this.entity, \"pending\");\n\n // Keep the entity when its tagged id cannot distinguish between sibling subtypes.\n if (isEntity(other)) {\n const otherMeta = getMetadata(other);\n const hasComponentsWithSameBaseType =\n otherMeta.baseType &&\n this.field.components.some(\n (component) =>\n component.otherMetadata().baseType === otherMeta.baseType &&\n !(other instanceof component.otherMetadata().cstr),\n );\n setField(\n this.entity,\n this.fieldName,\n other.isNewEntity || hasComponentsWithSameBaseType ? other : other.idTagged,\n );\n } else {\n setField(this.entity, this.fieldName, other);\n }\n\n if (typeof other === \"string\") {\n this.loaded = undefined;\n this._isLoaded = false;\n } else {\n this.loaded = other;\n this._isLoaded = true;\n }\n\n // If had an existing value, remove us from its collection\n if (previousLoaded) {\n const prevRelation = this.getOtherRelation(previousLoaded);\n if (prevRelation instanceof OneToManyCollection) {\n prevRelation.removeIfLoaded(this.entity);\n } else {\n prevRelation.set(undefined as any);\n }\n }\n if (other !== undefined && isEntity(other)) {\n const newRelation = this.getOtherRelation(other);\n if (newRelation instanceof OneToManyCollection) {\n newRelation.add(this.entity);\n } else {\n newRelation.set(this.entity);\n }\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 public toString(): string {\n return `PolymorphicReference(entity: ${this.entity}, fieldName: ${\n this.fieldName\n }, otherType: ${this.currentComponent?.otherMetadata().type}, otherFieldName: ${\n this.currentComponent?.otherFieldName\n }, id: ${this.id})`;\n }\n\n private filterDeleted(entity: U | N, opts?: { withDeleted?: boolean }): U | N {\n return opts?.withDeleted === true || entity === undefined || !entity.isDeletedEntity ? entity : (undefined as N);\n }\n\n /** Returns the other relation that points back at us, i.e. we're `comment.parent_book_id` and this is `Book.comments`. */\n private getOtherRelation(other: U): OneToManyCollection<U, T> | OneToOneReference<U, T> {\n const component = this.field.components.find((c) => other instanceof c.otherMetadata().cstr) as any;\n return (other as U)[component?.otherFieldName as keyof U] as any;\n }\n\n private maybeFindExisting(): U | undefined {\n return this.idTaggedMaybe !== undefined ? (this.entity.em.getEntity(this.idTagged) as U) : undefined;\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n [ReferenceN]: N = null!;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuBA,SAAgB,oBAImB;CACjC,OAAOA,kBAAAA,WAAW,QAAW,cAAc;EACzC,OAAO,IAAI,yBAAkC,QAAQ,SAA6B;CACpF,CAAC;AACH;;AAGA,SAAgB,uBAAuB,gBAA4E;CACjH,OAAO,0BAA0B;AACnC;;;;;;;;;;;;AAwCA,IAAa,2BAAb,cACUC,uCAAAA,qBAEV;CASW;CART;CAEA,YAAoB;CACpB;CACA,cAAc;CAEd,YACE,QACA,WACA;EACA,MAAM,MAAM;EAFL,KAAA,YAAA;EAGP,KAAK,QAAQC,uBAAAA,YAAY,MAAM,CAAC,CAAC,UAAU,KAAK;EAChD,IAAIC,mBAAAA,gBAAgB,MAAM,CAAC,CAAC,YAC1B,KAAK,YAAY;CAErB;CAEA,IAAY,mBAAkD;EAC5D,MAAM,OAAOC,kBAAAA,iCAAiC,KAAK,QAAQ,CAAC;EAC5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 @@ import "../index.cjs";
6
6
  import { IdOf, TaggedId } from "../EntityManager.cjs";
7
7
  import { Entity } from "../Entity.cjs";
8
8
  //#region src/relations/PolymorphicReference.d.ts
9
- declare function hasOnePolymorphic<T extends Entity, U extends Entity, N extends never | undefined>(): PolymorphicReference<T, U, N>;
9
+ export declare function hasOnePolymorphic<T extends Entity, U extends Entity, N extends never | undefined>(): PolymorphicReference<T, U, N>;
10
10
  /** Type guard utility for determining if an entity field is a PolymorphicReference. */
11
- declare function isPolymorphicReference(maybeReference: any): maybeReference is PolymorphicReference<any, any, any>;
11
+ export declare function isPolymorphicReference(maybeReference: any): maybeReference is PolymorphicReference<any, any, any>;
12
12
  /**
13
13
  * A reference that can be assigned to multiple different entity types.
14
14
  *
@@ -16,7 +16,7 @@ declare function isPolymorphicReference(maybeReference: any): maybeReference is
16
16
  *
17
17
  * The `U` generic will be the type union of `Author | Book`.
18
18
  */
19
- interface PolymorphicReference<T extends Entity, U extends Entity, N extends never | undefined> extends Reference<T, U, N> {
19
+ export interface PolymorphicReference<T extends Entity, U extends Entity, N extends never | undefined> extends Reference<T, U, N> {
20
20
  /** 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. */
21
21
  id: IdOf<U>;
22
22
  /** Returns the id of the current assigned entity, undefined if unset, or a runtime error if set to a new entity. */
@@ -38,7 +38,7 @@ interface PolymorphicReference<T extends Entity, U extends Entity, N extends nev
38
38
  * essentially be half of a one-to-one relationship, but we'll keep using this reference on the "owning" side; the other
39
39
  * side, i.e. `BookReview.comment` will use a `OneToOneReference` to point back to us.
40
40
  */
41
- declare class PolymorphicReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined> extends AbstractRelationImpl<T, U> implements PolymorphicReference<T, U, N> {
41
+ export declare class PolymorphicReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined> extends AbstractRelationImpl<T, U> implements PolymorphicReference<T, U, N> {
42
42
  #private;
43
43
  fieldName: keyof T & string;
44
44
  private loaded;
@@ -89,5 +89,4 @@ declare class PolymorphicReferenceImpl<T extends Entity, U extends Entity, N ext
89
89
  [ReferenceN]: N;
90
90
  }
91
91
  //#endregion
92
- export { PolymorphicReference, PolymorphicReferenceImpl, hasOnePolymorphic, isPolymorphicReference };
93
92
  //# sourceMappingURL=PolymorphicReference.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PolymorphicReference.d.cts","names":[],"sources":["../../src/relations/PolymorphicReference.ts"],"mappings":";;;;;;;;iBAuBgB,kBACd,UAAU,QACV,UAAU,QACV,gCACG,qBAAqB,GAAG,GAAG;;iBAOhB,uBAAuB,sBAAsB,kBAAkB;;;;;;;;UAW9D,qBACf,UAAU,QACV,UAAU,QACV,qCACQ,UAAU,GAAG,GAAG;;EAExB,IAAI,KAAK;;EAGT,SAAS,KAAK;;EAGd,SAAS,KAAK;EAEd;;WAGS;;;;;;;;;;;;;cAcE,yBAAyB,UAAU,QAAQ,UAAU,QAAQ,qCAChE,qBAAqB,GAAG,cACrB,qBAAqB,GAAG,GAAG;;EAU7B,iBAAiB;UARlB;UAEA;UACA;EAGR,YACE,QAAQ,GACD,iBAAiB;cASd;cAKA;EAIN,KAAK;IAAQ;IAAuB;MAA+B,QAAQ,IAAI;EAcrF,IAAI,OAAO,IAAI;MAIX;MAIA;;;;;EAQJ,mBAAmB;MAMf;EAIJ;UAKQ;EAKR,OAAO,OAAO,yBAAyB,GAAG,GAAG,IAAI,aAAa,GAAG,MAAM;UAK/D;MAgBJ,kBAAkB,IAAI;MAItB,OAAO,IAAI;MAIX,MAAM,KAAK;MAIX,WAAW,KAAK;MAKhB,WAAW,KAAK,KAAK;MAIrB;MAIA;MAKA;EAMJ,YAAY,OAAO;EAInB;EASM,0BAA0B;EAkBhC,QAAQ,OAAO,IAAI;EAsEnB,QAAQ;IAAS;MAA0B,IAAI,WAAW;EAQnD;UAQC;;UAKA;UAKA;GAIP,YAAY;GACZ,YAAY;GACZ,aAAa"}
1
+ {"version":3,"file":"PolymorphicReference.d.cts","names":[],"sources":["../../src/relations/PolymorphicReference.ts"],"mappings":";;;;;;;;wBAuBgB,kBACd,UAAU,QACV,UAAU,QACV,gCACG,qBAAqB,GAAG,GAAG;;wBAOhB,uBAAuB,sBAAsB,kBAAkB;;;;;;;;iBAW9D,qBACf,UAAU,QACV,UAAU,QACV,qCACQ,UAAU,GAAG,GAAG;;EAExB,IAAI,KAAK;;EAGT,SAAS,KAAK;;EAGd,SAAS,KAAK;EAEd;;WAGS;;;;;;;;;;;;;qBAcE,yBAAyB,UAAU,QAAQ,UAAU,QAAQ,qCAChE,qBAAqB,GAAG,cACrB,qBAAqB,GAAG,GAAG;;EAU7B,iBAAiB;UARlB;UAEA;UACA;EAGR,YACE,QAAQ,GACD,iBAAiB;cASd;cAKA;EAIN,KAAK;IAAQ;IAAuB;MAA+B,QAAQ,IAAI;EAcrF,IAAI,OAAO,IAAI;MAIX;MAIA;;;;;EAQJ,mBAAmB;MAMf;EAIJ;UAKQ;EAKR,OAAO,OAAO,yBAAyB,GAAG,GAAG,IAAI,aAAa,GAAG,MAAM;UAK/D;MAgBJ,kBAAkB,IAAI;MAItB,OAAO,IAAI;MAIX,MAAM,KAAK;MAIX,WAAW,KAAK;MAKhB,WAAW,KAAK,KAAK;MAIrB;MAIA;MAKA;EAMJ,YAAY,OAAO;EAInB;EASM,0BAA0B;EAkBhC,QAAQ,OAAO,IAAI;EAsEnB,QAAQ;IAAS;MAA0B,IAAI,WAAW;EAQnD;UAQC;;UAKA;UAKA;GAIP,YAAY;GACZ,YAAY;GACZ,aAAa"}
@@ -6,9 +6,9 @@ import "../index.mjs";
6
6
  import { IdOf, TaggedId } from "../EntityManager.mjs";
7
7
  import { Entity } from "../Entity.mjs";
8
8
  //#region src/relations/PolymorphicReference.d.ts
9
- declare function hasOnePolymorphic<T extends Entity, U extends Entity, N extends never | undefined>(): PolymorphicReference<T, U, N>;
9
+ export declare function hasOnePolymorphic<T extends Entity, U extends Entity, N extends never | undefined>(): PolymorphicReference<T, U, N>;
10
10
  /** Type guard utility for determining if an entity field is a PolymorphicReference. */
11
- declare function isPolymorphicReference(maybeReference: any): maybeReference is PolymorphicReference<any, any, any>;
11
+ export declare function isPolymorphicReference(maybeReference: any): maybeReference is PolymorphicReference<any, any, any>;
12
12
  /**
13
13
  * A reference that can be assigned to multiple different entity types.
14
14
  *
@@ -16,7 +16,7 @@ declare function isPolymorphicReference(maybeReference: any): maybeReference is
16
16
  *
17
17
  * The `U` generic will be the type union of `Author | Book`.
18
18
  */
19
- interface PolymorphicReference<T extends Entity, U extends Entity, N extends never | undefined> extends Reference<T, U, N> {
19
+ export interface PolymorphicReference<T extends Entity, U extends Entity, N extends never | undefined> extends Reference<T, U, N> {
20
20
  /** 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. */
21
21
  id: IdOf<U>;
22
22
  /** Returns the id of the current assigned entity, undefined if unset, or a runtime error if set to a new entity. */
@@ -38,7 +38,7 @@ interface PolymorphicReference<T extends Entity, U extends Entity, N extends nev
38
38
  * essentially be half of a one-to-one relationship, but we'll keep using this reference on the "owning" side; the other
39
39
  * side, i.e. `BookReview.comment` will use a `OneToOneReference` to point back to us.
40
40
  */
41
- declare class PolymorphicReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined> extends AbstractRelationImpl<T, U> implements PolymorphicReference<T, U, N> {
41
+ export declare class PolymorphicReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined> extends AbstractRelationImpl<T, U> implements PolymorphicReference<T, U, N> {
42
42
  #private;
43
43
  fieldName: keyof T & string;
44
44
  private loaded;
@@ -89,5 +89,4 @@ declare class PolymorphicReferenceImpl<T extends Entity, U extends Entity, N ext
89
89
  [ReferenceN]: N;
90
90
  }
91
91
  //#endregion
92
- export { PolymorphicReference, PolymorphicReferenceImpl, hasOnePolymorphic, isPolymorphicReference };
93
92
  //# sourceMappingURL=PolymorphicReference.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PolymorphicReference.d.mts","names":[],"sources":["../../src/relations/PolymorphicReference.ts"],"mappings":";;;;;;;;iBAuBgB,kBACd,UAAU,QACV,UAAU,QACV,gCACG,qBAAqB,GAAG,GAAG;;iBAOhB,uBAAuB,sBAAsB,kBAAkB;;;;;;;;UAW9D,qBACf,UAAU,QACV,UAAU,QACV,qCACQ,UAAU,GAAG,GAAG;;EAExB,IAAI,KAAK;;EAGT,SAAS,KAAK;;EAGd,SAAS,KAAK;EAEd;;WAGS;;;;;;;;;;;;;cAcE,yBAAyB,UAAU,QAAQ,UAAU,QAAQ,qCAChE,qBAAqB,GAAG,cACrB,qBAAqB,GAAG,GAAG;;EAU7B,iBAAiB;UARlB;UAEA;UACA;EAGR,YACE,QAAQ,GACD,iBAAiB;cASd;cAKA;EAIN,KAAK;IAAQ;IAAuB;MAA+B,QAAQ,IAAI;EAcrF,IAAI,OAAO,IAAI;MAIX;MAIA;;;;;EAQJ,mBAAmB;MAMf;EAIJ;UAKQ;EAKR,OAAO,OAAO,yBAAyB,GAAG,GAAG,IAAI,aAAa,GAAG,MAAM;UAK/D;MAgBJ,kBAAkB,IAAI;MAItB,OAAO,IAAI;MAIX,MAAM,KAAK;MAIX,WAAW,KAAK;MAKhB,WAAW,KAAK,KAAK;MAIrB;MAIA;MAKA;EAMJ,YAAY,OAAO;EAInB;EASM,0BAA0B;EAkBhC,QAAQ,OAAO,IAAI;EAsEnB,QAAQ;IAAS;MAA0B,IAAI,WAAW;EAQnD;UAQC;;UAKA;UAKA;GAIP,YAAY;GACZ,YAAY;GACZ,aAAa"}
1
+ {"version":3,"file":"PolymorphicReference.d.mts","names":[],"sources":["../../src/relations/PolymorphicReference.ts"],"mappings":";;;;;;;;wBAuBgB,kBACd,UAAU,QACV,UAAU,QACV,gCACG,qBAAqB,GAAG,GAAG;;wBAOhB,uBAAuB,sBAAsB,kBAAkB;;;;;;;;iBAW9D,qBACf,UAAU,QACV,UAAU,QACV,qCACQ,UAAU,GAAG,GAAG;;EAExB,IAAI,KAAK;;EAGT,SAAS,KAAK;;EAGd,SAAS,KAAK;EAEd;;WAGS;;;;;;;;;;;;;qBAcE,yBAAyB,UAAU,QAAQ,UAAU,QAAQ,qCAChE,qBAAqB,GAAG,cACrB,qBAAqB,GAAG,GAAG;;EAU7B,iBAAiB;UARlB;UAEA;UACA;EAGR,YACE,QAAQ,GACD,iBAAiB;cASd;cAKA;EAIN,KAAK;IAAQ;IAAuB;MAA+B,QAAQ,IAAI;EAcrF,IAAI,OAAO,IAAI;MAIX;MAIA;;;;;EAQJ,mBAAmB;MAMf;EAIJ;UAKQ;EAKR,OAAO,OAAO,yBAAyB,GAAG,GAAG,IAAI,aAAa,GAAG,MAAM;UAK/D;MAgBJ,kBAAkB,IAAI;MAItB,OAAO,IAAI;MAIX,MAAM,KAAK;MAIX,WAAW,KAAK;MAKhB,WAAW,KAAK,KAAK;MAIrB;MAIA;MAKA;EAMJ,YAAY,OAAO;EAInB;EASM,0BAA0B;EAkBhC,QAAQ,OAAO,IAAI;EAsEnB,QAAQ;IAAS;MAA0B,IAAI,WAAW;EAQnD;UAQC;;UAKA;UAKA;GAIP,YAAY;GACZ,YAAY;GACZ,aAAa"}
@@ -1,13 +1,13 @@
1
+ import { lazyField } from "../newEntity.js";
1
2
  import { AbstractRelationImpl } from "./AbstractRelationImpl.js";
2
3
  import { RelationT, RelationU } from "./RelationSymbols.js";
3
4
  import { ReferenceN } from "./ReferenceSymbols.js";
4
- import { getField, setField } from "../fields.js";
5
5
  import { maybeResolveReferenceToId } from "../keys.js";
6
6
  import { isCascadeDelete } from "./isCascadeDelete.js";
7
7
  import { OneToManyCollection } from "./OneToManyCollection.js";
8
8
  import { failIfNewEntity, failNoId } from "./ManyToOneReference.js";
9
9
  import { fail } from "../utils.js";
10
- import { lazyField } from "../newEntity.js";
10
+ import { getField, setField } from "../fields.js";
11
11
  import { getConstructorFromTaggedId, maybeGetConstructorFromReference } from "../configure.js";
12
12
  import { getMetadata } from "../EntityMetadata.js";
13
13
  import { ensureNotDeleted } from "../index.js";
@@ -1 +1 @@
1
- {"version":3,"file":"PolymorphicReference.js","names":["#hasBeenSet"],"sources":["../../src/relations/PolymorphicReference.ts"],"sourcesContent":["import { maybeGetConstructorFromReference } from \"src/configure.ts\";\nimport { type Entity, isEntity } from \"src/Entity.ts\";\nimport { type IdOf, type TaggedId, sameEntity } from \"src/EntityManager.ts\";\nimport { type PolymorphicFieldComponent, getMetadata } from \"src/EntityMetadata.ts\";\nimport { getField, setField } from \"src/fields.ts\";\nimport {\n type OneToOneReference,\n type PolymorphicField,\n type Reference,\n ensureNotDeleted,\n fail,\n getConstructorFromTaggedId,\n getInstanceData,\n maybeResolveReferenceToId,\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 { failIfNewEntity, failNoId } from \"src/relations/ManyToOneReference.ts\";\nimport { OneToManyCollection } from \"src/relations/OneToManyCollection.ts\";\nimport { ReferenceN } from \"src/relations/ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"src/relations/RelationSymbols.ts\";\n\nexport function hasOnePolymorphic<\n T extends Entity,\n U extends Entity,\n N extends never | undefined,\n>(): PolymorphicReference<T, U, N> {\n return lazyField((entity: T, fieldName) => {\n return new PolymorphicReferenceImpl<T, U, N>(entity, fieldName as keyof T & string);\n });\n}\n\n/** Type guard utility for determining if an entity field is a PolymorphicReference. */\nexport function isPolymorphicReference(maybeReference: any): maybeReference is PolymorphicReference<any, any, any> {\n return maybeReference instanceof PolymorphicReferenceImpl;\n}\n\n/**\n * A reference that can be assigned to multiple different entity types.\n *\n * I.e. a `Comment.parent` reference that can be an `Author` or `Book`.\n *\n * The `U` generic will be the type union of `Author | Book`.\n */\nexport interface PolymorphicReference<\n T extends Entity,\n U extends Entity,\n N extends never | undefined,\n> extends Reference<T, U, 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 idTagged: string;\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 set of foreign keys from one entity to another, i.e. `Comment.parent --> Book | BookReview`.\n *\n * We keep the current `parent` / `parent.id` value in the `__orm.data` hash, where the\n * current value could be either the `comments.parent_book_id` / `comments.parent_book_review_id` id (as a tagged string)\n * from the database, or an entity `Book` / `BookReview` that the user has set.\n *\n * Note that if any of our columns (eg `comments.parent_book_review_id`) is unique, this `PolymorphicReference` will\n * essentially be half of a one-to-one relationship, but we'll keep using this reference on the \"owning\" side; the other\n * side, i.e. `BookReview.comment` will use a `OneToOneReference` to point back to us.\n */\nexport class PolymorphicReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined>\n extends AbstractRelationImpl<T, U>\n implements PolymorphicReference<T, U, N>\n{\n private loaded: U | N | undefined;\n // We need a separate boolean to b/c loaded == undefined can still mean \"_isLoaded\" for nullable fks.\n private _isLoaded = false;\n private field: PolymorphicField;\n #hasBeenSet = false;\n\n constructor(\n entity: T,\n public fieldName: keyof T & string,\n ) {\n super(entity);\n this.field = getMetadata(entity).allFields[this.fieldName] as PolymorphicField;\n if (getInstanceData(entity).isOrWasNew) {\n this._isLoaded = true;\n }\n }\n\n private get currentComponent(): PolymorphicFieldComponent | N {\n const cstr = maybeGetConstructorFromReference(this.current());\n return this.field.components.find((c) => c.otherMetadata().cstr === cstr) as any;\n }\n\n private get isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.fieldName);\n }\n\n async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<U | N> {\n ensureNotDeleted(this.entity, \"pending\");\n const current = this.current();\n // Resolve the id to an entity\n if (!this._isLoaded || opts.forceReload) {\n this.loaded =\n isEntity(current) || current === undefined\n ? (current as U | undefined)\n : ((await this.entity.em.load(getConstructorFromTaggedId(current), current)) as U);\n }\n this._isLoaded = true;\n return this.filterDeleted(this.loaded!, 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 return this._isLoaded;\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 this.loaded first b/c a new entity won't have an id yet\n const { idTaggedMaybe } = this;\n return this.loaded ?? (idTaggedMaybe !== undefined ? (this.entity.em.getEntity(idTaggedMaybe) as U) : undefined);\n }\n\n get isPreloaded(): boolean {\n return !!this.maybeFindEntity();\n }\n\n preload(): void {\n this.loaded = this.maybeFindEntity();\n this._isLoaded = true;\n }\n\n private unload(): void {\n this.loaded = undefined;\n this._isLoaded = false;\n }\n\n import(other: PolymorphicReferenceImpl<T, U, N>, findEntity: (e: U) => U): void {\n this.loaded = other.loaded ? findEntity(other.loaded) : undefined;\n this._isLoaded = true;\n }\n\n private doGet(opts?: { withDeleted?: boolean }): U | N {\n ensureNotDeleted(this.entity, \"pending\");\n // This should only be callable in the type system if we've already resolved this to an instance,\n // but, just in case we somehow got here in an unloaded state, check to see if we're already in the UoW\n if (!this._isLoaded) {\n const existing = this.maybeFindExisting();\n if (existing === undefined) {\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n this.loaded = existing;\n this._isLoaded = true;\n }\n\n return this.filterDeleted(this.loaded!, 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 get id(): IdOf<U> {\n return this.idMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idMaybe(): IdOf<U> | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current()) as IdOf<U> | undefined;\n }\n\n get idIfSet(): IdOf<U> | N | undefined {\n return this.idMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get idTagged(): string {\n return this.idTaggedMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idTaggedMaybe(): string | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current());\n }\n\n get hasBeenSet() {\n return this.#hasBeenSet;\n }\n\n // private impl\n\n setFromOpts(other: U): 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 && typeof current !== \"string\") {\n this.entity.em.delete(current as U);\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 {\n o2m.set(undefined as any);\n }\n }\n setField(this.entity, this.fieldName, undefined);\n this.loaded = undefined as any;\n this._isLoaded = true;\n }\n\n // Internal method used by PolymorphicReference\n setImpl(other: U | N): void {\n this.#hasBeenSet = true;\n\n if (sameEntity(other, this.current({ withDeleted: true }))) {\n return;\n }\n\n if (\n other !== undefined &&\n !this.field.components.some(\n (c) =>\n other instanceof c.otherMetadata().cstr ||\n (typeof other === \"string\" && getConstructorFromTaggedId(other) === c.otherMetadata().cstr),\n )\n ) {\n fail(`${other} cannot be set as '${this.field.fieldName}' on ${this.entity}`);\n }\n\n // we may not be loaded yet, but our previous entity might already be in the UoW\n const previousLoaded = this.loaded ?? this.maybeFindExisting();\n\n ensureNotDeleted(this.entity, \"pending\");\n\n // Keep the entity when its tagged id cannot distinguish between sibling subtypes.\n if (isEntity(other)) {\n const otherMeta = getMetadata(other);\n const hasComponentsWithSameBaseType =\n otherMeta.baseType &&\n this.field.components.some(\n (component) =>\n component.otherMetadata().baseType === otherMeta.baseType &&\n !(other instanceof component.otherMetadata().cstr),\n );\n setField(\n this.entity,\n this.fieldName,\n other.isNewEntity || hasComponentsWithSameBaseType ? other : other.idTagged,\n );\n } else {\n setField(this.entity, this.fieldName, other);\n }\n\n if (typeof other === \"string\") {\n this.loaded = undefined;\n this._isLoaded = false;\n } else {\n this.loaded = other;\n this._isLoaded = true;\n }\n\n // If had an existing value, remove us from its collection\n if (previousLoaded) {\n const prevRelation = this.getOtherRelation(previousLoaded);\n if (prevRelation instanceof OneToManyCollection) {\n prevRelation.removeIfLoaded(this.entity);\n } else {\n prevRelation.set(undefined as any);\n }\n }\n if (other !== undefined && isEntity(other)) {\n const newRelation = this.getOtherRelation(other);\n if (newRelation instanceof OneToManyCollection) {\n newRelation.add(this.entity);\n } else {\n newRelation.set(this.entity);\n }\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 public toString(): string {\n return `PolymorphicReference(entity: ${this.entity}, fieldName: ${\n this.fieldName\n }, otherType: ${this.currentComponent?.otherMetadata().type}, otherFieldName: ${\n this.currentComponent?.otherFieldName\n }, id: ${this.id})`;\n }\n\n private filterDeleted(entity: U | N, opts?: { withDeleted?: boolean }): U | N {\n return opts?.withDeleted === true || entity === undefined || !entity.isDeletedEntity ? entity : (undefined as N);\n }\n\n /** Returns the other relation that points back at us, i.e. we're `comment.parent_book_id` and this is `Book.comments`. */\n private getOtherRelation(other: U): OneToManyCollection<U, T> | OneToOneReference<U, T> {\n const component = this.field.components.find((c) => other instanceof c.otherMetadata().cstr) as any;\n return (other as U)[component?.otherFieldName as keyof U] as any;\n }\n\n private maybeFindExisting(): U | undefined {\n return this.idTaggedMaybe !== undefined ? (this.entity.em.getEntity(this.idTagged) as U) : undefined;\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n [ReferenceN]: N = null!;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,SAAgB,oBAImB;CACjC,OAAO,WAAW,QAAW,cAAc;EACzC,OAAO,IAAI,yBAAkC,QAAQ,SAA6B;CACpF,CAAC;AACH;;AAGA,SAAgB,uBAAuB,gBAA4E;CACjH,OAAO,0BAA0B;AACnC;;;;;;;;;;;;AAwCA,IAAa,2BAAb,cACU,qBAEV;CASW;CART;CAEA,YAAoB;CACpB;CACA,cAAc;CAEd,YACE,QACA,WACA;EACA,MAAM,MAAM;EAFL,KAAA,YAAA;EAGP,KAAK,QAAQ,YAAY,MAAM,CAAC,CAAC,UAAU,KAAK;EAChD,IAAI,gBAAgB,MAAM,CAAC,CAAC,YAC1B,KAAK,YAAY;CAErB;CAEA,IAAY,mBAAkD;EAC5D,MAAM,OAAO,iCAAiC,KAAK,QAAQ,CAAC;EAC5D,OAAO,KAAK,MAAM,WAAW,MAAM,MAAM,EAAE,cAAc,CAAC,CAAC,SAAS,IAAI;CAC1E;CAEA,IAAY,kBAA2B;EACrC,OAAO,gBAAgB,MAAM,KAAK,SAAS;CAC7C;CAEA,MAAM,KAAK,OAAyD,CAAC,GAAmB;EACtF,iBAAiB,KAAK,QAAQ,SAAS;EACvC,MAAM,UAAU,KAAK,QAAQ;EAE7B,IAAI,CAAC,KAAK,aAAa,KAAK,aAC1B,KAAK,SACH,SAAS,OAAO,KAAK,YAAY,KAAA,IAC5B,UACC,MAAM,KAAK,OAAO,GAAG,KAAK,2BAA2B,OAAO,GAAG,OAAO;EAEhF,KAAK,YAAY;EACjB,OAAO,KAAK,cAAc,KAAK,QAAS,IAAI;CAC9C;CAEA,IAAI,OAAoB;EACtB,KAAK,QAAQ,KAAK;CACpB;CAEA,IAAI,QAAiB;EACnB,OAAO,KAAK,QAAQ,MAAM,KAA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AC5E,OAAO,MAAM,gBAAgB,QAAQ,WAAW,KAAA,KAAa,CAAC,OAAO,kBAAkB,SAAU,KAAA;CACnG;;CAGA,iBAAyB,OAA+D;EAEtF,OAAQ,MADU,KAAK,MAAM,WAAW,MAAM,MAAM,iBAAiB,EAAE,cAAc,CAAC,CAAC,IAC3D,CAAC,EAAE;CACjC;CAEA,oBAA2C;EACzC,OAAO,KAAK,kBAAkB,KAAA,IAAa,KAAK,OAAO,GAAG,UAAU,KAAK,QAAQ,IAAU,KAAA;CAC7F;CAEA,CAAC,aAAgB;CACjB,CAAC,aAAgB;CACjB,CAAC,cAAiB;AACpB"}
1
+ {"version":3,"file":"PolymorphicReference.js","names":[],"sources":["../../src/relations/PolymorphicReference.ts"],"sourcesContent":["import { maybeGetConstructorFromReference } from \"src/configure.ts\";\nimport { type Entity, isEntity } from \"src/Entity.ts\";\nimport { type IdOf, type TaggedId, sameEntity } from \"src/EntityManager.ts\";\nimport { type PolymorphicFieldComponent, getMetadata } from \"src/EntityMetadata.ts\";\nimport { getField, setField } from \"src/fields.ts\";\nimport {\n type OneToOneReference,\n type PolymorphicField,\n type Reference,\n ensureNotDeleted,\n fail,\n getConstructorFromTaggedId,\n getInstanceData,\n maybeResolveReferenceToId,\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 { failIfNewEntity, failNoId } from \"src/relations/ManyToOneReference.ts\";\nimport { OneToManyCollection } from \"src/relations/OneToManyCollection.ts\";\nimport { ReferenceN } from \"src/relations/ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"src/relations/RelationSymbols.ts\";\n\nexport function hasOnePolymorphic<\n T extends Entity,\n U extends Entity,\n N extends never | undefined,\n>(): PolymorphicReference<T, U, N> {\n return lazyField((entity: T, fieldName) => {\n return new PolymorphicReferenceImpl<T, U, N>(entity, fieldName as keyof T & string);\n });\n}\n\n/** Type guard utility for determining if an entity field is a PolymorphicReference. */\nexport function isPolymorphicReference(maybeReference: any): maybeReference is PolymorphicReference<any, any, any> {\n return maybeReference instanceof PolymorphicReferenceImpl;\n}\n\n/**\n * A reference that can be assigned to multiple different entity types.\n *\n * I.e. a `Comment.parent` reference that can be an `Author` or `Book`.\n *\n * The `U` generic will be the type union of `Author | Book`.\n */\nexport interface PolymorphicReference<\n T extends Entity,\n U extends Entity,\n N extends never | undefined,\n> extends Reference<T, U, 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 idTagged: string;\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 set of foreign keys from one entity to another, i.e. `Comment.parent --> Book | BookReview`.\n *\n * We keep the current `parent` / `parent.id` value in the `__orm.data` hash, where the\n * current value could be either the `comments.parent_book_id` / `comments.parent_book_review_id` id (as a tagged string)\n * from the database, or an entity `Book` / `BookReview` that the user has set.\n *\n * Note that if any of our columns (eg `comments.parent_book_review_id`) is unique, this `PolymorphicReference` will\n * essentially be half of a one-to-one relationship, but we'll keep using this reference on the \"owning\" side; the other\n * side, i.e. `BookReview.comment` will use a `OneToOneReference` to point back to us.\n */\nexport class PolymorphicReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined>\n extends AbstractRelationImpl<T, U>\n implements PolymorphicReference<T, U, N>\n{\n private loaded: U | N | undefined;\n // We need a separate boolean to b/c loaded == undefined can still mean \"_isLoaded\" for nullable fks.\n private _isLoaded = false;\n private field: PolymorphicField;\n #hasBeenSet = false;\n\n constructor(\n entity: T,\n public fieldName: keyof T & string,\n ) {\n super(entity);\n this.field = getMetadata(entity).allFields[this.fieldName] as PolymorphicField;\n if (getInstanceData(entity).isOrWasNew) {\n this._isLoaded = true;\n }\n }\n\n private get currentComponent(): PolymorphicFieldComponent | N {\n const cstr = maybeGetConstructorFromReference(this.current());\n return this.field.components.find((c) => c.otherMetadata().cstr === cstr) as any;\n }\n\n private get isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.fieldName);\n }\n\n async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<U | N> {\n ensureNotDeleted(this.entity, \"pending\");\n const current = this.current();\n // Resolve the id to an entity\n if (!this._isLoaded || opts.forceReload) {\n this.loaded =\n isEntity(current) || current === undefined\n ? (current as U | undefined)\n : ((await this.entity.em.load(getConstructorFromTaggedId(current), current)) as U);\n }\n this._isLoaded = true;\n return this.filterDeleted(this.loaded!, 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 return this._isLoaded;\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 this.loaded first b/c a new entity won't have an id yet\n const { idTaggedMaybe } = this;\n return this.loaded ?? (idTaggedMaybe !== undefined ? (this.entity.em.getEntity(idTaggedMaybe) as U) : undefined);\n }\n\n get isPreloaded(): boolean {\n return !!this.maybeFindEntity();\n }\n\n preload(): void {\n this.loaded = this.maybeFindEntity();\n this._isLoaded = true;\n }\n\n private unload(): void {\n this.loaded = undefined;\n this._isLoaded = false;\n }\n\n import(other: PolymorphicReferenceImpl<T, U, N>, findEntity: (e: U) => U): void {\n this.loaded = other.loaded ? findEntity(other.loaded) : undefined;\n this._isLoaded = true;\n }\n\n private doGet(opts?: { withDeleted?: boolean }): U | N {\n ensureNotDeleted(this.entity, \"pending\");\n // This should only be callable in the type system if we've already resolved this to an instance,\n // but, just in case we somehow got here in an unloaded state, check to see if we're already in the UoW\n if (!this._isLoaded) {\n const existing = this.maybeFindExisting();\n if (existing === undefined) {\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n this.loaded = existing;\n this._isLoaded = true;\n }\n\n return this.filterDeleted(this.loaded!, 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 get id(): IdOf<U> {\n return this.idMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idMaybe(): IdOf<U> | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current()) as IdOf<U> | undefined;\n }\n\n get idIfSet(): IdOf<U> | N | undefined {\n return this.idMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get idTagged(): string {\n return this.idTaggedMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idTaggedMaybe(): string | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current());\n }\n\n get hasBeenSet() {\n return this.#hasBeenSet;\n }\n\n // private impl\n\n setFromOpts(other: U): 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 && typeof current !== \"string\") {\n this.entity.em.delete(current as U);\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 {\n o2m.set(undefined as any);\n }\n }\n setField(this.entity, this.fieldName, undefined);\n this.loaded = undefined as any;\n this._isLoaded = true;\n }\n\n // Internal method used by PolymorphicReference\n setImpl(other: U | N): void {\n this.#hasBeenSet = true;\n\n if (sameEntity(other, this.current({ withDeleted: true }))) {\n return;\n }\n\n if (\n other !== undefined &&\n !this.field.components.some(\n (c) =>\n other instanceof c.otherMetadata().cstr ||\n (typeof other === \"string\" && getConstructorFromTaggedId(other) === c.otherMetadata().cstr),\n )\n ) {\n fail(`${other} cannot be set as '${this.field.fieldName}' on ${this.entity}`);\n }\n\n // we may not be loaded yet, but our previous entity might already be in the UoW\n const previousLoaded = this.loaded ?? this.maybeFindExisting();\n\n ensureNotDeleted(this.entity, \"pending\");\n\n // Keep the entity when its tagged id cannot distinguish between sibling subtypes.\n if (isEntity(other)) {\n const otherMeta = getMetadata(other);\n const hasComponentsWithSameBaseType =\n otherMeta.baseType &&\n this.field.components.some(\n (component) =>\n component.otherMetadata().baseType === otherMeta.baseType &&\n !(other instanceof component.otherMetadata().cstr),\n );\n setField(\n this.entity,\n this.fieldName,\n other.isNewEntity || hasComponentsWithSameBaseType ? other : other.idTagged,\n );\n } else {\n setField(this.entity, this.fieldName, other);\n }\n\n if (typeof other === \"string\") {\n this.loaded = undefined;\n this._isLoaded = false;\n } else {\n this.loaded = other;\n this._isLoaded = true;\n }\n\n // If had an existing value, remove us from its collection\n if (previousLoaded) {\n const prevRelation = this.getOtherRelation(previousLoaded);\n if (prevRelation instanceof OneToManyCollection) {\n prevRelation.removeIfLoaded(this.entity);\n } else {\n prevRelation.set(undefined as any);\n }\n }\n if (other !== undefined && isEntity(other)) {\n const newRelation = this.getOtherRelation(other);\n if (newRelation instanceof OneToManyCollection) {\n newRelation.add(this.entity);\n } else {\n newRelation.set(this.entity);\n }\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 public toString(): string {\n return `PolymorphicReference(entity: ${this.entity}, fieldName: ${\n this.fieldName\n }, otherType: ${this.currentComponent?.otherMetadata().type}, otherFieldName: ${\n this.currentComponent?.otherFieldName\n }, id: ${this.id})`;\n }\n\n private filterDeleted(entity: U | N, opts?: { withDeleted?: boolean }): U | N {\n return opts?.withDeleted === true || entity === undefined || !entity.isDeletedEntity ? entity : (undefined as N);\n }\n\n /** Returns the other relation that points back at us, i.e. we're `comment.parent_book_id` and this is `Book.comments`. */\n private getOtherRelation(other: U): OneToManyCollection<U, T> | OneToOneReference<U, T> {\n const component = this.field.components.find((c) => other instanceof c.otherMetadata().cstr) as any;\n return (other as U)[component?.otherFieldName as keyof U] as any;\n }\n\n private maybeFindExisting(): U | undefined {\n return this.idTaggedMaybe !== undefined ? (this.entity.em.getEntity(this.idTagged) as U) : undefined;\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n [ReferenceN]: N = null!;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,SAAgB,oBAImB;CACjC,OAAO,WAAW,QAAW,cAAc;EACzC,OAAO,IAAI,yBAAkC,QAAQ,SAA6B;CACpF,CAAC;AACH;;AAGA,SAAgB,uBAAuB,gBAA4E;CACjH,OAAO,0BAA0B;AACnC;;;;;;;;;;;;AAwCA,IAAa,2BAAb,cACU,qBAEV;CASW;CART;CAEA,YAAoB;CACpB;CACA,cAAc;CAEd,YACE,QACA,WACA;EACA,MAAM,MAAM;EAFL,KAAA,YAAA;EAGP,KAAK,QAAQ,YAAY,MAAM,CAAC,CAAC,UAAU,KAAK;EAChD,IAAI,gBAAgB,MAAM,CAAC,CAAC,YAC1B,KAAK,YAAY;CAErB;CAEA,IAAY,mBAAkD;EAC5D,MAAM,OAAO,iCAAiC,KAAK,QAAQ,CAAC;EAC5D,OAAO,KAAK,MAAM,WAAW,MAAM,MAAM,EAAE,cAAc,CAAC,CAAC,SAAS,IAAI;CAC1E;CAEA,IAAY,kBAA2B;EACrC,OAAO,gBAAgB,MAAM,KAAK,SAAS;CAC7C;CAEA,MAAM,KAAK,OAAyD,CAAC,GAAmB;EACtF,iBAAiB,KAAK,QAAQ,SAAS;EACvC,M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AQ,MAAoD;EAC1D,MAAM,UAAU,SAAS,KAAK,QAAQ,KAAK,SAAS;EACpD,IAAI,YAAY,KAAA,KAAa,SAAS,OAAO,GAC3C,OAAO,KAAK,cAAc,SAAc,IAAI;EAE9C,OAAO;CACT;CAEA,WAA0B;EACxB,OAAO,gCAAgC,KAAK,OAAO,eACjD,KAAK,UACN,eAAe,KAAK,kBAAkB,cAAc,CAAC,CAAC,KAAK,oBAC1D,KAAK,kBAAkB,eACxB,QAAQ,KAAK,GAAG;CACnB;CAEA,cAAsB,QAAe,MAAyC;EAC5E,OAAO,MAAM,gBAAgB,QAAQ,WAAW,KAAA,KAAa,CAAC,OAAO,kBAAkB,SAAU,KAAA;CACnG;;CAGA,iBAAyB,OAA+D;EAEtF,OAAQ,MADU,KAAK,MAAM,WAAW,MAAM,MAAM,iBAAiB,EAAE,cAAc,CAAC,CAAC,IAC3D,CAAC,EAAE;CACjC;CAEA,oBAA2C;EACzC,OAAO,KAAK,kBAAkB,KAAA,IAAa,KAAK,OAAO,GAAG,UAAU,KAAK,QAAQ,IAAU,KAAA;CAC7F;CAEA,CAAC,aAAgB;CACjB,CAAC,aAAgB;CACjB,CAAC,cAAiB;AACpB"}
@@ -1,5 +1,4 @@
1
1
  //#region src/relations/PropertySymbols.d.ts
2
- declare const PropertyT: unique symbol;
2
+ export declare const PropertyT: unique symbol;
3
3
  //#endregion
4
- export { PropertyT };
5
4
  //# sourceMappingURL=PropertySymbols.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PropertySymbols.d.cts","names":[],"sources":["../../src/relations/PropertySymbols.ts"],"mappings":";cAAa"}
1
+ {"version":3,"file":"PropertySymbols.d.cts","names":[],"sources":["../../src/relations/PropertySymbols.ts"],"mappings":";qBAAa"}
@@ -1,5 +1,4 @@
1
1
  //#region src/relations/PropertySymbols.d.ts
2
- declare const PropertyT: unique symbol;
2
+ export declare const PropertyT: unique symbol;
3
3
  //#endregion
4
- export { PropertyT };
5
4
  //# sourceMappingURL=PropertySymbols.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PropertySymbols.d.mts","names":[],"sources":["../../src/relations/PropertySymbols.ts"],"mappings":";cAAa"}
1
+ {"version":3,"file":"PropertySymbols.d.mts","names":[],"sources":["../../src/relations/PropertySymbols.ts"],"mappings":";qBAAa"}
@@ -1,10 +1,11 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_newEntity = require("../newEntity.cjs");
2
3
  const require_relations_AbstractPropertyImpl = require("./AbstractPropertyImpl.cjs");
4
+ const require_metrics_EntityMetrics = require("../metrics/EntityMetrics.cjs");
3
5
  const require_relations_PropertySymbols = require("./PropertySymbols.cjs");
4
6
  const require_reactivity_reactiveHints = require("../reactivity/reactiveHints.cjs");
5
7
  const require_loading_loadHints = require("../loading/loadHints.cjs");
6
8
  const require_fields = require("../fields.cjs");
7
- const require_newEntity = require("../newEntity.cjs");
8
9
  const require_EntityMetadata = require("../EntityMetadata.cjs");
9
10
  require("../index.cjs");
10
11
  const require_EntityManager = require("../EntityManager.cjs");
@@ -18,22 +19,29 @@ require("../Entity.cjs");
18
19
  * But if `someProperty` is used as a populate hint, then it can be accessed synchronously,
19
20
  * with `someProperty.get`.
20
21
  */
21
- function hasReactiveField(hint, fn) {
22
+ function hasReactiveField(hint, fn, opts) {
23
+ let evaluation;
22
24
  return require_newEntity.lazyField((entity, fieldName) => {
23
- const field = require_EntityMetadata.getMetadata(entity).allFields[fieldName];
24
- return new ReactiveFieldImpl(entity, field, hint, fn);
25
+ const meta = require_EntityMetadata.getMetadata(entity);
26
+ const field = meta.allFields[fieldName];
27
+ evaluation ??= new require_metrics_EntityMetrics.EvaluationSlot(`${meta.type}.${fieldName}`);
28
+ return new ReactiveFieldImpl(entity, field, hint, fn, evaluation, opts?.onInvalidate);
25
29
  });
26
30
  }
27
31
  var ReactiveFieldImpl = class extends require_relations_AbstractPropertyImpl.AbstractPropertyImpl {
28
32
  fn;
33
+ evaluation;
34
+ onInvalidate;
29
35
  #field;
30
36
  #reactiveHint;
31
37
  #loadPromise;
32
38
  #isLoaded;
33
39
  #isCached = false;
34
- constructor(entity, field, reactiveHint, fn) {
40
+ constructor(entity, field, reactiveHint, fn, evaluation, onInvalidate) {
35
41
  super(entity);
36
42
  this.fn = fn;
43
+ this.evaluation = evaluation;
44
+ this.onInvalidate = onInvalidate;
37
45
  this.#field = field;
38
46
  this.#reactiveHint = reactiveHint;
39
47
  }
@@ -53,7 +61,19 @@ var ReactiveFieldImpl = class extends require_relations_AbstractPropertyImpl.Abs
53
61
  const { fn } = this;
54
62
  if (this.#isCached) return this.fieldValue;
55
63
  if (this.isLoaded) {
56
- const newValue = fn(this.entity);
64
+ const metrics = require_EntityManager.getEmInternalApi(this.entity.em).metrics;
65
+ let newValue;
66
+ if (metrics) {
67
+ const totals = metrics.start(this.evaluation);
68
+ const started = performance.now();
69
+ try {
70
+ newValue = fn(this.entity);
71
+ } catch (error) {
72
+ metrics.finish(totals, started);
73
+ throw error;
74
+ }
75
+ newValue = metrics.finish(totals, started, newValue);
76
+ } else newValue = fn(this.entity);
57
77
  if (!require_EntityManager.getEmInternalApi(this.entity.em).isValidating) {
58
78
  require_fields.setField(this.entity, this.fieldName, newValue);
59
79
  this.#isCached = true;
@@ -87,6 +107,7 @@ var ReactiveFieldImpl = class extends require_relations_AbstractPropertyImpl.Abs
87
107
  resetIsLoaded() {
88
108
  this.#isLoaded = void 0;
89
109
  this.resetCacheUnlessFactoryPinned();
110
+ this.onInvalidate?.(this.entity);
90
111
  }
91
112
  get loadHint() {
92
113
  const meta = require_EntityMetadata.getMetadata(this.entity);
@@ -1 +1 @@
1
- {"version":3,"file":"ReactiveField.cjs","names":["lazyField","getMetadata","AbstractPropertyImpl","#field","#reactiveHint","#loadPromise","#isLoaded","#isCached","getEmInternalApi","getField","isFieldSet","isLoaded","convertToLoadHint","PropertyT"],"sources":["../../src/relations/ReactiveField.ts"],"sourcesContent":["import { type Entity } from \"src/Entity.ts\";\nimport { getEmInternalApi } from \"src/EntityManager.ts\";\nimport { type PrimitiveField, getMetadata } from \"src/EntityMetadata.ts\";\nimport { getField, isFieldSet, setField } from \"src/fields.ts\";\nimport { isLoaded } from \"src/index.ts\";\nimport type { IsLoadedCachable } from \"src/loading/IsLoadedCache.ts\";\nimport { lazyField } from \"src/newEntity.ts\";\nimport { type Reacted, type ReactiveHint, convertToLoadHint } from \"src/reactivity/reactiveHints.ts\";\nimport { AbstractPropertyImpl } from \"src/relations/AbstractPropertyImpl.ts\";\nimport { PropertyT } from \"src/relations/PropertySymbols.ts\";\n\n/**\n * A `ReactiveField` is a value that is derived from other entities/values,\n * similar to a `Property`, but it is also persisted in the database.\n *\n * This allows callers (or SQL queries) to access the value without first calling\n * `await load()` on the property.\n *\n * So, unlike `Property`, `.get` is always available; if the property is unloaded,\n * then `.get` will return the last-calculated value, but if the property is loaded,\n * then it will go ahead and invoke function to calculate the latest value (i.e. so\n * that you can observe the latest & greatest value w/o waiting for `em.flush` to\n * re-calc the value while persisting to the database.\n */\nexport interface ReactiveField<T extends Entity, V> {\n [PropertyT]: T;\n isLoaded: boolean;\n isSet: boolean;\n\n /**\n * Calculates the latest derived value.\n *\n * Users are not required to call this method explicitly, as Joist will keep the\n * persisted value automatically in-sync, but if for some reason (code changes,\n * bug fixes, etc.) you need to trigger an explicit recalc, you can call `.load()`,\n * any dependent data will be loaded from the database, and the latest value\n * returned, and then later stored to the database on `em.flush`.\n *\n * Note that persisted properties used in load hints, i.e. `em.populate`s that\n * accidentally list reactive fields (instead of just relations) will not have\n * `.load()` invoked, and will instead use the previously-calculated value.\n * The rationale is that one persisted property should be able to declare its\n * dependency on another persisted property (for its reactive field-level hint)\n * without causing that dependent property's populate hint to itself be loaded.\n */\n load(opts?: { forceReload?: boolean }): Promise<V>;\n\n /** If loaded, returns the latest derived value, or if unload returns the previously-calculated value. */\n get: V;\n\n /**\n * Returns the as-of-last-flush previously-calculated value.\n *\n * This is useful if you have to purposefully avoid using the lambda to calc the latest value,\n * i.e. if you're in a test and want to watch a calculated value change from some dummy value\n * to the new derived value.\n * */\n fieldValue: V;\n}\n\n/**\n * Creates a calculated derived value from a load hint + lambda.\n *\n * The property can be accessed by default as a promise, with `someProperty.load()`.\n *\n * But if `someProperty` is used as a populate hint, then it can be accessed synchronously,\n * with `someProperty.get`.\n */\nexport function hasReactiveField<T extends Entity, const H extends ReactiveHint<T>, V>(\n hint: H,\n fn: (entity: Reacted<T, H>) => V,\n): ReactiveField<T, V> {\n return lazyField((entity: T, fieldName) => {\n const field = getMetadata(entity).allFields[fieldName] as PrimitiveField;\n return new ReactiveFieldImpl(entity, field, hint, fn);\n });\n}\n\nexport class ReactiveFieldImpl<T extends Entity, H extends ReactiveHint<T>, V>\n extends AbstractPropertyImpl<T>\n implements ReactiveField<T, V>, IsLoadedCachable\n{\n readonly #field: PrimitiveField;\n readonly #reactiveHint: H;\n #loadPromise: any;\n // Initially undefined, then cached as true/false\n #isLoaded: boolean | undefined;\n #isCached: boolean | \"factory-value\" = false;\n\n constructor(\n entity: T,\n field: PrimitiveField,\n reactiveHint: H,\n private fn: (entity: Reacted<T, H>) => V,\n ) {\n super(entity);\n this.#field = field;\n this.#reactiveHint = reactiveHint;\n }\n\n async load(opts?: { forceReload?: boolean }): Promise<V> {\n // Even without `forceReload=true`, any explicit calls to `.load()` ==> ensure a fresh value,\n // because `.get` may have cached the stale/previously-calculated value.\n //\n // (Currently `em.populate` / `populateDataLoader` has a hack/escape hatch that ignores calling\n // RF.load(), to avoid pulling in the RF subgraph over using the materialized value, which ideally would be\n // replaced with us learning to do the maybeDirty approach.)\n if (!this.isLoaded || opts?.forceReload) {\n return (this.#loadPromise ??= this.entity.em.populate(this.entity, { hint: this.loadHint } as any).then(() => {\n this.#loadPromise = undefined;\n this.#isLoaded = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n // Wait and reset `#isCached` until inside this `then`, so that we don't have a race condition where:\n // - two relations (us and someone else) are both passed to `em.calc`\n // - their load hint is simpler, so their promises resolves first, and their `.get` calls our `.get`\n // - our `.get` sees we're not loaded, but calls `fieldValue` for the existing value, and dutifully sets `#isCached=true`\n // - finally our promise runs, and if we didn't immediately set `#isCached=false` here, our `.get` would again\n // early return and keep using the stale fieldValue.\n this.resetCacheUnlessFactoryPinned();\n // Go through `this.get` so that `setField` is called to set our latest value\n return this.get;\n }));\n }\n this.resetCacheUnlessFactoryPinned();\n return this.get;\n }\n\n /** Returns either the latest calculated value (if loaded) or the previously-calculated value (if not loaded). */\n get get(): V {\n const { fn } = this;\n // Some ReactiveFields can have surprisingly expensive calculations, especially in loops\n // or those that invoke loops, so cache the value.\n if (this.#isCached) return this.fieldValue;\n // isLoaded will watch for our previously-loaded subgraph being mutated (isLoaded is locally cached but hooked into\n // our IsLoadedCache cache that is immediately invalidated on write-path), and if we've drifted to not-loaded, it's\n // better to fail and tell the user.\n if (this.isLoaded) {\n const newValue = fn(this.entity as Reacted<T, H>);\n if (!getEmInternalApi(this.entity.em).isValidating) {\n // setField will immediately invalidate downstream #isLoaded/#isCached values\n setField(this.entity, this.fieldName, newValue);\n this.#isCached = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n }\n return newValue;\n } else if (this.isSet) {\n this.#isCached = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n return this.fieldValue;\n } else {\n throw new Error(`${this.fieldName} has not been derived yet`);\n }\n }\n\n get fieldName(): keyof T & string {\n return this.#field.fieldName as keyof T & string;\n }\n\n get reactiveHint(): H {\n return this.#reactiveHint;\n }\n\n get fieldValue(): V {\n return getField(this.entity, this.fieldName);\n }\n\n get isSet() {\n return isFieldSet(this.entity, this.fieldName);\n }\n\n get isLoaded() {\n // Skip an expensive isLoaded(subgraph) call if no mutations have happened\n if (this.#isLoaded !== undefined) return this.#isLoaded;\n this.#isLoaded = isLoaded(this.entity, this.loadHint);\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n return this.#isLoaded;\n }\n\n resetIsLoaded(): void {\n // Even though we reset this on every mutation, `isLoaded` will still realize when the subgraph\n // is still loaded (as it did before we added caching), so users won't see false positive.\n this.#isLoaded = undefined;\n this.resetCacheUnlessFactoryPinned();\n }\n\n get loadHint(): any {\n const meta = getMetadata(this.entity);\n return (meta.config.__data.cachedReactiveLoadHints[this.fieldName] ??= convertToLoadHint(meta, this.reactiveHint));\n }\n\n setFactoryValue(newValue: any): void {\n setField(this.entity, this.fieldName, newValue);\n this.#isCached = \"factory-value\";\n }\n\n [PropertyT] = undefined as any as T;\n\n private resetCacheUnlessFactoryPinned(): void {\n // If factories asked for a hard-coded value, don't reset the cached flag\n if (this.#isCached === \"factory-value\") return;\n this.#isCached = false;\n }\n}\n\n/** Type guard utility for determining if an entity field is a ReactiveField. */\nexport function isReactiveField(maybeReactiveField: any): maybeReactiveField is ReactiveField<any, any> {\n return maybeReactiveField instanceof ReactiveFieldImpl;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,iBACd,MACA,IACqB;CACrB,OAAOA,kBAAAA,WAAW,QAAW,cAAc;EACzC,MAAM,QAAQC,uBAAAA,YAAY,MAAM,CAAC,CAAC,UAAU;EAC5C,OAAO,IAAI,kBAAkB,QAAQ,OAAO,MAAM,EAAE;CACtD,CAAC;AACH;AAEA,IAAa,oBAAb,cACUC,uCAAAA,qBAEV;CAYY;CAXV;CACA;CACA;CAEA;CACA,YAAuC;CAEvC,YACE,QACA,OACA,cACA,IACA;EACA,MAAM,MAAM;EAFJ,KAAA,KAAA;EAGR,KAAKC,SAAS;EACd,KAAKC,gBAAgB;CACvB;CAEA,MAAM,KAAK,MAA8C;EAOvD,IAAI,CAAC,KAAK,YAAY,MAAM,aAC1B,OAAQ,KAAKC,iBAAiB,KAAK,OAAO,GAAG,SAAS,KAAK,QAAQ,EAAE,MAAM,KAAK,SAAS,CAAQ,CAAC,CAAC,WAAW;GAC5G,KAAKA,eAAe,KAAA;GACpB,KAAKC,YAAY;GACjB,sBAAA,iBAAiB,KAAK,OAA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BAA8B;CACrC;CAEA,IAAI,WAAgB;EAClB,MAAM,OAAOL,uBAAAA,YAAY,KAAK,MAAM;EACpC,OAAQ,KAAK,OAAO,OAAO,wBAAwB,KAAK,eAAeW,iCAAAA,kBAAkB,MAAM,KAAK,YAAY;CAClH;CAEA,gBAAgB,UAAqB;EACnC,eAAA,SAAS,KAAK,QAAQ,KAAK,WAAW,QAAQ;EAC9C,KAAKL,YAAY;CACnB;CAEA,CAACM,kCAAAA,aAAa,KAAA;CAEd,gCAA8C;EAE5C,IAAI,KAAKN,cAAc,iBAAiB;EACxC,KAAKA,YAAY;CACnB;AACF;;AAGA,SAAgB,gBAAgB,oBAAwE;CACtG,OAAO,8BAA8B;AACvC"}
1
+ {"version":3,"file":"ReactiveField.cjs","names":["lazyField","getMetadata","EvaluationSlot","AbstractPropertyImpl","getEmInternalApi","getField","isFieldSet","isLoaded","convertToLoadHint","PropertyT"],"sources":["../../src/relations/ReactiveField.ts"],"sourcesContent":["import { type Entity } from \"src/Entity.ts\";\nimport { getEmInternalApi } from \"src/EntityManager.ts\";\nimport { type PrimitiveField, getMetadata } from \"src/EntityMetadata.ts\";\nimport { getField, isFieldSet, setField } from \"src/fields.ts\";\nimport { isLoaded } from \"src/index.ts\";\nimport type { IsLoadedCachable } from \"src/loading/IsLoadedCache.ts\";\nimport { EvaluationSlot } from \"src/metrics/EntityMetrics.ts\";\nimport { lazyField } from \"src/newEntity.ts\";\nimport { type Reacted, type ReactiveHint, convertToLoadHint } from \"src/reactivity/reactiveHints.ts\";\nimport { AbstractPropertyImpl } from \"src/relations/AbstractPropertyImpl.ts\";\nimport { PropertyT } from \"src/relations/PropertySymbols.ts\";\n\n/**\n * A `ReactiveField` is a value that is derived from other entities/values,\n * similar to a `Property`, but it is also persisted in the database.\n *\n * This allows callers (or SQL queries) to access the value without first calling\n * `await load()` on the property.\n *\n * So, unlike `Property`, `.get` is always available; if the property is unloaded,\n * then `.get` will return the last-calculated value, but if the property is loaded,\n * then it will go ahead and invoke function to calculate the latest value (i.e. so\n * that you can observe the latest & greatest value w/o waiting for `em.flush` to\n * re-calc the value while persisting to the database.\n */\nexport interface ReactiveField<T extends Entity, V> {\n [PropertyT]: T;\n isLoaded: boolean;\n isSet: boolean;\n\n /**\n * Calculates the latest derived value.\n *\n * Users are not required to call this method explicitly, as Joist will keep the\n * persisted value automatically in-sync, but if for some reason (code changes,\n * bug fixes, etc.) you need to trigger an explicit recalc, you can call `.load()`,\n * any dependent data will be loaded from the database, and the latest value\n * returned, and then later stored to the database on `em.flush`.\n *\n * Note that persisted properties used in load hints, i.e. `em.populate`s that\n * accidentally list reactive fields (instead of just relations) will not have\n * `.load()` invoked, and will instead use the previously-calculated value.\n * The rationale is that one persisted property should be able to declare its\n * dependency on another persisted property (for its reactive field-level hint)\n * without causing that dependent property's populate hint to itself be loaded.\n */\n load(opts?: { forceReload?: boolean }): Promise<V>;\n\n /** If loaded, returns the latest derived value, or if unload returns the previously-calculated value. */\n get: V;\n\n /**\n * Returns the as-of-last-flush previously-calculated value.\n *\n * This is useful if you have to purposefully avoid using the lambda to calc the latest value,\n * i.e. if you're in a test and want to watch a calculated value change from some dummy value\n * to the new derived value.\n * */\n fieldValue: V;\n}\n\n/**\n * Creates a calculated derived value from a load hint + lambda.\n *\n * The property can be accessed by default as a promise, with `someProperty.load()`.\n *\n * But if `someProperty` is used as a populate hint, then it can be accessed synchronously,\n * with `someProperty.get`.\n */\nexport function hasReactiveField<T extends Entity, const H extends ReactiveHint<T>, V>(\n hint: H,\n fn: (entity: Reacted<T, H>) => V,\n opts?: { onInvalidate?: (entity: T) => void },\n): ReactiveField<T, V> {\n // Lazy field definitions are built per concrete type; all its instances share this named slot.\n let evaluation: EvaluationSlot | undefined;\n return lazyField((entity: T, fieldName) => {\n const meta = getMetadata(entity);\n const field = meta.allFields[fieldName] as PrimitiveField;\n evaluation ??= new EvaluationSlot(`${meta.type}.${fieldName}`);\n return new ReactiveFieldImpl(entity, field, hint, fn, evaluation, opts?.onInvalidate);\n });\n}\n\nexport class ReactiveFieldImpl<T extends Entity, H extends ReactiveHint<T>, V>\n extends AbstractPropertyImpl<T>\n implements ReactiveField<T, V>, IsLoadedCachable\n{\n readonly #field: PrimitiveField;\n readonly #reactiveHint: H;\n #loadPromise: any;\n // Initially undefined, then cached as true/false\n #isLoaded: boolean | undefined;\n #isCached: boolean | \"factory-value\" = false;\n\n constructor(\n entity: T,\n field: PrimitiveField,\n reactiveHint: H,\n private fn: (entity: Reacted<T, H>) => V,\n private readonly evaluation: EvaluationSlot,\n private onInvalidate?: (entity: T) => void,\n ) {\n super(entity);\n this.#field = field;\n this.#reactiveHint = reactiveHint;\n }\n\n async load(opts?: { forceReload?: boolean }): Promise<V> {\n // Even without `forceReload=true`, any explicit calls to `.load()` ==> ensure a fresh value,\n // because `.get` may have cached the stale/previously-calculated value.\n //\n // (Currently `em.populate` / `populateDataLoader` has a hack/escape hatch that ignores calling\n // RF.load(), to avoid pulling in the RF subgraph over using the materialized value, which ideally would be\n // replaced with us learning to do the maybeDirty approach.)\n if (!this.isLoaded || opts?.forceReload) {\n return (this.#loadPromise ??= this.entity.em.populate(this.entity, { hint: this.loadHint } as any).then(() => {\n this.#loadPromise = undefined;\n this.#isLoaded = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n // Wait and reset `#isCached` until inside this `then`, so that we don't have a race condition where:\n // - two relations (us and someone else) are both passed to `em.calc`\n // - their load hint is simpler, so their promises resolves first, and their `.get` calls our `.get`\n // - our `.get` sees we're not loaded, but calls `fieldValue` for the existing value, and dutifully sets `#isCached=true`\n // - finally our promise runs, and if we didn't immediately set `#isCached=false` here, our `.get` would again\n // early return and keep using the stale fieldValue.\n this.resetCacheUnlessFactoryPinned();\n // Go through `this.get` so that `setField` is called to set our latest value\n return this.get;\n }));\n }\n this.resetCacheUnlessFactoryPinned();\n return this.get;\n }\n\n /** Returns either the latest calculated value (if loaded) or the previously-calculated value (if not loaded). */\n get get(): V {\n const { fn } = this;\n // Some ReactiveFields can have surprisingly expensive calculations, especially in loops\n // or those that invoke loops, so cache the value.\n if (this.#isCached) return this.fieldValue;\n // isLoaded will watch for our previously-loaded subgraph being mutated (isLoaded is locally cached but hooked into\n // our IsLoadedCache cache that is immediately invalidated on write-path), and if we've drifted to not-loaded, it's\n // better to fail and tell the user.\n if (this.isLoaded) {\n const metrics = getEmInternalApi(this.entity.em).metrics;\n let newValue: V;\n if (metrics) {\n const totals = metrics.start(this.evaluation);\n const started = performance.now();\n try {\n newValue = fn(this.entity as Reacted<T, H>);\n } catch (error) {\n metrics.finish(totals, started);\n throw error;\n }\n newValue = metrics.finish(totals, started, newValue);\n } else {\n newValue = fn(this.entity as Reacted<T, H>);\n }\n if (!getEmInternalApi(this.entity.em).isValidating) {\n // setField will immediately invalidate downstream #isLoaded/#isCached values\n setField(this.entity, this.fieldName, newValue);\n this.#isCached = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n }\n return newValue;\n } else if (this.isSet) {\n this.#isCached = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n return this.fieldValue;\n } else {\n throw new Error(`${this.fieldName} has not been derived yet`);\n }\n }\n\n get fieldName(): keyof T & string {\n return this.#field.fieldName as keyof T & string;\n }\n\n get reactiveHint(): H {\n return this.#reactiveHint;\n }\n\n get fieldValue(): V {\n return getField(this.entity, this.fieldName);\n }\n\n get isSet() {\n return isFieldSet(this.entity, this.fieldName);\n }\n\n get isLoaded() {\n // Skip an expensive isLoaded(subgraph) call if no mutations have happened\n if (this.#isLoaded !== undefined) return this.#isLoaded;\n this.#isLoaded = isLoaded(this.entity, this.loadHint);\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n return this.#isLoaded;\n }\n\n resetIsLoaded(): void {\n // Even though we reset this on every mutation, `isLoaded` will still realize when the subgraph\n // is still loaded (as it did before we added caching), so users won't see false positive.\n this.#isLoaded = undefined;\n this.resetCacheUnlessFactoryPinned();\n this.onInvalidate?.(this.entity);\n }\n\n get loadHint(): any {\n const meta = getMetadata(this.entity);\n return (meta.config.__data.cachedReactiveLoadHints[this.fieldName] ??= convertToLoadHint(meta, this.reactiveHint));\n }\n\n setFactoryValue(newValue: any): void {\n setField(this.entity, this.fieldName, newValue);\n this.#isCached = \"factory-value\";\n }\n\n [PropertyT] = undefined as any as T;\n\n private resetCacheUnlessFactoryPinned(): void {\n // If factories asked for a hard-coded value, don't reset the cached flag\n if (this.#isCached === \"factory-value\") return;\n this.#isCached = false;\n }\n}\n\n/** Type guard utility for determining if an entity field is a ReactiveField. */\nexport function isReactiveField(maybeReactiveField: any): maybeReactiveField is ReactiveField<any, any> {\n return maybeReactiveField instanceof ReactiveFieldImpl;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqEA,SAAgB,iBACd,MACA,IACA,MACqB;CAErB,IAAI;CACJ,OAAOA,kBAAAA,WAAW,QAAW,cAAc;EACzC,MAAM,OAAOC,uBAAAA,YAAY,MAAM;EAC/B,MAAM,QAAQ,KAAK,UAAU;EAC7B,eAAe,IAAIC,8BAAAA,eAAe,GAAG,KAAK,KAAK,GAAG,WAAW;EAC7D,OAAO,IAAI,kBAAkB,QAAQ,OAAO,MAAM,IAAI,YAAY,MAAM,YAAY;CACtF,CAAC;AACH;AAEA,IAAa,oBAAb,cACUC,uCAAAA,qBAEV;CAYY;CACS;CACT;CAbV;CACA;CACA;CAEA;CACA,YAAuC;CAEvC,YACE,QACA,OACA,cACA,IACA,YACA,cACA;EACA,MAAM,MAAM;EAJJ,KAAA,KAAA;EACS,KAAA,aAAA;EACT,KAAA,eAAA;EAGR,KAAK,SAAS;EACd,KAAK,gBAAgB;CACvB;CAEA,MAAM,KAAK,MAA8C;EAOvD,IAAI,CAAC,KAAK,YAAY,MAAM,aAC1B,OAAQ,KAAK,iBAAiB,KAAK,OAAO,GAAG,SAAS,KAAK,QAAQ,EAAE,MAAM,KAAK,SAAS,CAAQ,CAAC,CAAC,WAAW;GAC5G,KAAK,eAAe,KAAA;GACpB,KAAK,YAAY;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AI,QAAQ;EACV,OAAOC,eAAAA,WAAW,KAAK,QAAQ,KAAK,SAAS;CAC/C;CAEA,IAAI,WAAW;EAEb,IAAI,KAAK,cAAc,KAAA,GAAW,OAAO,KAAK;EAC9C,KAAK,YAAYC,0BAAAA,SAAS,KAAK,QAAQ,KAAK,QAAQ;EACpD,sBAAA,iBAAiB,KAAK,OAAO,EAAE,CAAC,CAAC,cAAc,IAAI,IAAI;EACvD,OAAO,KAAK;CACd;CAEA,gBAAsB;EAGpB,KAAK,YAAY,KAAA;EACjB,KAAK,8BAA8B;EACnC,KAAK,eAAe,KAAK,MAAM;CACjC;CAEA,IAAI,WAAgB;EAClB,MAAM,OAAON,uBAAAA,YAAY,KAAK,MAAM;EACpC,OAAQ,KAAK,OAAO,OAAO,wBAAwB,KAAK,eAAeO,iCAAAA,kBAAkB,MAAM,KAAK,YAAY;CAClH;CAEA,gBAAgB,UAAqB;EACnC,eAAA,SAAS,KAAK,QAAQ,KAAK,WAAW,QAAQ;EAC9C,KAAK,YAAY;CACnB;CAEA,CAACC,kCAAAA,aAAa,KAAA;CAEd,gCAA8C;EAE5C,IAAI,KAAK,cAAc,iBAAiB;EACxC,KAAK,YAAY;CACnB;AACF;;AAGA,SAAgB,gBAAgB,oBAAwE;CACtG,OAAO,8BAA8B;AACvC"}
@@ -1,6 +1,7 @@
1
+ import { EvaluationSlot } from "../metrics/EntityMetrics.cjs";
1
2
  import { AbstractPropertyImpl } from "./AbstractPropertyImpl.cjs";
2
- import { PropertyT } from "./PropertySymbols.cjs";
3
3
  import { IsLoadedCachable } from "../loading/IsLoadedCache.cjs";
4
+ import { PropertyT } from "./PropertySymbols.cjs";
4
5
  import { Reacted, ReactiveHint } from "../reactivity/reactiveHints.cjs";
5
6
  import { PrimitiveField } from "../EntityMetadata.cjs";
6
7
  import { Entity } from "../Entity.cjs";
@@ -18,7 +19,7 @@ import { Entity } from "../Entity.cjs";
18
19
  * that you can observe the latest & greatest value w/o waiting for `em.flush` to
19
20
  * re-calc the value while persisting to the database.
20
21
  */
21
- interface ReactiveField<T extends Entity, V> {
22
+ export interface ReactiveField<T extends Entity, V> {
22
23
  [PropertyT]: T;
23
24
  isLoaded: boolean;
24
25
  isSet: boolean;
@@ -60,11 +61,15 @@ interface ReactiveField<T extends Entity, V> {
60
61
  * But if `someProperty` is used as a populate hint, then it can be accessed synchronously,
61
62
  * with `someProperty.get`.
62
63
  */
63
- declare function hasReactiveField<T extends Entity, const H extends ReactiveHint<T>, V>(hint: H, fn: (entity: Reacted<T, H>) => V): ReactiveField<T, V>;
64
- declare class ReactiveFieldImpl<T extends Entity, H extends ReactiveHint<T>, V> extends AbstractPropertyImpl<T> implements ReactiveField<T, V>, IsLoadedCachable {
64
+ export declare function hasReactiveField<T extends Entity, const H extends ReactiveHint<T>, V>(hint: H, fn: (entity: Reacted<T, H>) => V, opts?: {
65
+ onInvalidate?: (entity: T) => void;
66
+ }): ReactiveField<T, V>;
67
+ export declare class ReactiveFieldImpl<T extends Entity, H extends ReactiveHint<T>, V> extends AbstractPropertyImpl<T> implements ReactiveField<T, V>, IsLoadedCachable {
65
68
  #private;
66
69
  private fn;
67
- constructor(entity: T, field: PrimitiveField, reactiveHint: H, fn: (entity: Reacted<T, H>) => V);
70
+ private readonly evaluation;
71
+ private onInvalidate?;
72
+ constructor(entity: T, field: PrimitiveField, reactiveHint: H, fn: (entity: Reacted<T, H>) => V, evaluation: EvaluationSlot, onInvalidate?: ((entity: T) => void) | undefined);
68
73
  load(opts?: {
69
74
  forceReload?: boolean;
70
75
  }): Promise<V>;
@@ -82,7 +87,6 @@ declare class ReactiveFieldImpl<T extends Entity, H extends ReactiveHint<T>, V>
82
87
  private resetCacheUnlessFactoryPinned;
83
88
  }
84
89
  /** Type guard utility for determining if an entity field is a ReactiveField. */
85
- declare function isReactiveField(maybeReactiveField: any): maybeReactiveField is ReactiveField<any, any>;
90
+ export declare function isReactiveField(maybeReactiveField: any): maybeReactiveField is ReactiveField<any, any>;
86
91
  //#endregion
87
- export { ReactiveField, ReactiveFieldImpl, hasReactiveField, isReactiveField };
88
92
  //# sourceMappingURL=ReactiveField.d.cts.map