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 +1 @@
1
- {"version":3,"file":"fields.cjs","names":["getEmInternalApi","getInstanceData","getMetadata","fail","cleanStringValue","isEntity","maybeResolveReferenceToId","maybeRequireTemporal"],"sources":["../src/fields.ts"],"sourcesContent":["import { getInstanceData } from \"src/BaseEntity.ts\";\nimport { type Entity, isEntity } from \"src/Entity.ts\";\nimport { getEmInternalApi } from \"src/EntityManager.ts\";\nimport { type Field, getMetadata } from \"src/EntityMetadata.ts\";\nimport { cleanStringValue, ensureNotDeleted, maybeResolveReferenceToId } from \"src/index.ts\";\nimport { maybeRequireTemporal } from \"src/serde/temporal.ts\";\nimport { fail } from \"src/utils.ts\";\n\n/**\n * Returns the current value of `fieldName`, this is an internal method that should\n * only be called by the code-generated getters.\n *\n * We skip any typing like `fieldName: keyof T` because this method should only be\n * called by trusted codegen anyway.\n */\nexport function getField(entity: Entity, fieldName: string): any {\n const { em } = entity;\n const api = getEmInternalApi(em);\n api.pluginManager.beforeGetField(entity, fieldName);\n // We may not have converted the database column value into domain values yet\n const instanceData = getInstanceData(entity);\n const { data } = instanceData;\n if (fieldName in data) {\n return data[fieldName];\n } else {\n if (!entity.isNewEntity) {\n const field = getMetadata(entity).allFields[fieldName];\n const serde = field?.serde ?? fail(`Missing serde for ${fieldName}`);\n data[fieldName] = serde.fromRow(instanceData.rowData, instanceData.rowIndex);\n }\n return data[fieldName];\n }\n}\n\n/** Returns whether `fieldName` is a field/column on `entity` that can be changed. */\nexport function isChangeableField(entity: Entity, fieldName: string): boolean {\n return !!getMetadata(entity).allFields[fieldName]?.serde;\n}\n\n/** Returns whether `fieldName` has been set, even if it's undefined, on `entity`. */\nexport function isFieldSet(entity: Entity, fieldName: string): boolean {\n const { data } = getInstanceData(entity);\n if (fieldName in data) return true;\n // Avoid calling `getField` on new entities because it populates the field as a side effect.\n if (entity.isNewEntity) return false;\n // We may not have converted the database column value into domain values yet.\n getField(entity, fieldName);\n return fieldName in data;\n}\n\n/**\n * Sets the current value of `fieldName`, this is an internal method that should\n * only be called by the code-generated setters.\n *\n * We skip any typing like `fieldName: keyof T` because this method should only be\n * called by trusted codegen anyway.\n *\n * Returns `true` if the value was changed, or `false` if it was a noop.\n */\nexport function setField(entity: Entity, fieldName: string, newValue: any): boolean {\n ensureNotDeleted(entity, \"pending\");\n const { em } = entity;\n const api = getEmInternalApi(em);\n const { rm, pluginManager, indexManager, fieldLogger, isLoadedCache } = api;\n\n // If we're flushing, only allow writes from hooks\n api.checkWritesAllowed();\n\n // Tell any `#isLoaded` or `#value` caches that they might be stale\n isLoadedCache.resetIsLoaded(entity, fieldName);\n\n const instanceData = getInstanceData(entity);\n const { data, originalData, flushedData } = instanceData;\n\n // Do string sanitization\n const field = getMetadata(entity).allFields[fieldName];\n if (field.kind === \"primitive\" && field.type === \"string\" && field.sanitize !== false) {\n newValue = cleanStringValue(newValue);\n }\n\n const currentValue = getField(entity, fieldName);\n const isReference = field.kind === \"m2o\" || field.kind === \"poly\";\n const currentEqualsNew = fieldValueEquals(field, currentValue, newValue);\n // Remember every prior reference value so `followReverseHint` can rewalk both original and transient owners.\n if (isReference && !currentEqualsNew) {\n instanceData.rememberReferenceValue(fieldName, currentValue);\n }\n\n // If a `set` occurs during the AsyncReactiveField-loop, copy the last-flushed value to flushedData.\n // Then our `pendingOperation` logic can tell \"do we need another micro-flush?\" separately\n // from our public-facing changed fields logic.\n if (flushedData) {\n if (fieldName in flushedData) {\n // We've already copied the last-micro-flush value into flushedData,\n // are we changing back to that? If so, we won't need another micro-flush.\n if (equalOrSameEntity(flushedData[fieldName], newValue)) {\n delete flushedData[fieldName];\n } else {\n // Otherwise just let data[fieldName] get the even-newer value, and keep\n // flushedData[fieldName] as the last-micro-flushed value.\n }\n } else if (!currentEqualsNew) {\n // This is the 1st rqf-loop change for this field, so let data[fieldName]\n // get the even newer value, but keep the last-micro-flushed value in flushedData.\n flushedData[fieldName] = currentValue;\n }\n }\n\n // \"Un-dirty\" our originalData if newValue is reverting to originalData\n if (fieldName in originalData) {\n if (fieldValueEquals(field, originalData[fieldName], newValue)) {\n indexManager.maybeUpdateFieldIndex(entity, fieldName, currentValue, newValue);\n\n pluginManager.beforeSetField(entity, fieldName, newValue);\n data[fieldName] = newValue;\n instanceData.markFieldClean(fieldName);\n\n fieldLogger.logSet(entity, fieldName, newValue);\n if (isReference && instanceData.getReferenceHistory(fieldName).length > 0) {\n rm.queueDownstreamReactables(entity, fieldName);\n } else {\n // For normal reverts, the field is clean again, so any pending downstream work can be removed.\n rm.dequeueDownstreamReactables(entity, fieldName);\n }\n\n return true;\n }\n }\n\n // Push this logic into a field serde type abstraction?\n if (currentEqualsNew) {\n // If we're doing `entity.field = undefined`, we'll be equal, but mark ourselves as \"set\"\n // so that defaults know to respect the intent of keeping this field undefined.\n if (!(fieldName in data)) data[fieldName] = undefined;\n return false;\n }\n\n // Only save the currentValue on the 1st change of this field\n if (!(fieldName in originalData)) {\n instanceData.markFieldDirty(fieldName, currentValue);\n }\n fieldLogger.logSet(entity, fieldName, newValue);\n rm.queueDownstreamReactables(entity, fieldName);\n\n indexManager.maybeUpdateFieldIndex(entity, fieldName, currentValue, newValue);\n\n pluginManager.beforeSetField(entity, fieldName, newValue);\n data[fieldName] = newValue;\n return true;\n}\n\nfunction fieldValueEquals(field: Field, a: unknown, b: unknown): boolean {\n // Primitive scalar sets are the common path, so avoid Date/Temporal/entity checks when both values cannot need them.\n if (field.kind !== \"m2o\" && field.kind !== \"poly\" && isNonObjectValue(a) && isNonObjectValue(b)) return a === b;\n return equalOrSameEntity(a, b);\n}\n\nfunction isNonObjectValue(value: unknown): boolean {\n return value === null || typeof value !== \"object\";\n}\n\nfunction equalOrSameEntity(a: any, b: any): boolean {\n return (\n equal(a, b) ||\n (Array.isArray(a) && Array.isArray(b) && equalArrays(a, b)) ||\n // This is kind of gross, but make sure not to compare two both-new entities\n (((isEntity(a) && !a.isNewEntity) || (isEntity(b) && !b.isNewEntity)) &&\n maybeResolveReferenceToId(a) === maybeResolveReferenceToId(b))\n );\n}\n\nexport function equalArrays(a: any[], b: any[]): boolean {\n if (a.length !== b.length) return false;\n return a.every((_: any, i) => equal(a[i], b[i]));\n}\n\nconst Temporal = maybeRequireTemporal()?.Temporal;\nexport function equal(a: any, b: any): boolean {\n if (a === b) return true;\n if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();\n if (Temporal) {\n if (a instanceof Temporal.ZonedDateTime && b instanceof Temporal.ZonedDateTime) return a.equals(b);\n if (a instanceof Temporal.PlainDateTime && b instanceof Temporal.PlainDateTime) return a.equals(b);\n if (a instanceof Temporal.PlainDate && b instanceof Temporal.PlainDate) return a.equals(b);\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAeA,SAAgB,SAAS,QAAgB,WAAwB;CAC/D,MAAM,EAAE,OAAO;CAEf,sBADYA,iBAAiB,EAC3B,CAAC,CAAC,cAAc,eAAe,QAAQ,SAAS;CAElD,MAAM,eAAeC,mBAAAA,gBAAgB,MAAM;CAC3C,MAAM,EAAE,SAAS;CACjB,IAAI,aAAa,MACf,OAAO,KAAK;MACP;EACL,IAAI,CAAC,OAAO,aAGV,KAAK,cAFSC,uBAAAA,YAAY,MAAM,CAAC,CAAC,UAAU,UACzB,EAAE,SAASC,cAAAA,KAAK,qBAAqB,WAAW,EAAA,CAC3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,0BAA0B,CAAC;AAElE;AAEA,SAAgB,YAAY,GAAU,GAAmB;CACvD,IAAI,EAAE,WAAW,EAAE,QAAQ,OAAO;CAClC,OAAO,EAAE,OAAO,GAAQ,MAAM,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC;AACjD;AAEA,MAAM,WAAWC,uBAAAA,qBAAqB,CAAC,EAAE;AACzC,SAAgB,MAAM,GAAQ,GAAiB;CAC7C,IAAI,MAAM,GAAG,OAAO;CACpB,IAAI,aAAa,QAAQ,aAAa,MAAM,OAAO,EAAE,QAAQ,MAAM,EAAE,QAAQ;CAC7E,IAAI,UAAU;EACZ,IAAI,aAAa,SAAS,iBAAiB,aAAa,SAAS,eAAe,OAAO,EAAE,OAAO,CAAC;EACjG,IAAI,aAAa,SAAS,iBAAiB,aAAa,SAAS,eAAe,OAAO,EAAE,OAAO,CAAC;EACjG,IAAI,aAAa,SAAS,aAAa,aAAa,SAAS,WAAW,OAAO,EAAE,OAAO,CAAC;CAC3F;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"fields.cjs","names":["getEmInternalApi","getInstanceData","fail","getMetadata","cleanStringValue","isEntity","maybeResolveReferenceToId","maybeRequireTemporal"],"sources":["../src/fields.ts"],"sourcesContent":["import { getInstanceData } from \"src/BaseEntity.ts\";\nimport { type Entity, isEntity } from \"src/Entity.ts\";\nimport { getEmInternalApi } from \"src/EntityManager.ts\";\nimport { type Field, getMetadata } from \"src/EntityMetadata.ts\";\nimport { cleanStringValue, ensureNotDeleted, maybeResolveReferenceToId } from \"src/index.ts\";\nimport { maybeRequireTemporal } from \"src/serde/temporal.ts\";\nimport { fail } from \"src/utils.ts\";\n\n/**\n * Returns the current value of `fieldName`, marking the entity for read locking if the field is configured.\n *\n * Generated getters and direct application calls are protected by default. Only ORM\n * housekeeping should pass `isInternal`, not domain logic in hooks, rules, or reactions.\n * The field name is a string because generated getters and ORM internals know its type.\n */\nexport function getField(entity: Entity, fieldName: string, isInternal = false): any {\n const { em } = entity;\n const api = getEmInternalApi(em);\n api.pluginManager.beforeGetField(entity, fieldName);\n // We may not have converted the database column value into domain values yet\n const instanceData = getInstanceData(entity);\n const field = instanceData.metadata.allFields[fieldName];\n if (!isInternal && field?.assertUnchanged) em.assertUnchanged(entity);\n\n const { data } = instanceData;\n if (fieldName in data) {\n return data[fieldName];\n } else {\n if (!entity.isNewEntity) {\n const serde = field?.serde ?? fail(`Missing serde for ${fieldName}`);\n data[fieldName] = serde.fromRow(instanceData.rowData, instanceData.rowIndex);\n }\n return data[fieldName];\n }\n}\n\n/** Returns whether `fieldName` is a field/column on `entity` that can be changed. */\nexport function isChangeableField(entity: Entity, fieldName: string): boolean {\n return !!getMetadata(entity).allFields[fieldName]?.serde;\n}\n\n/** Returns whether `fieldName` has been set, even if it's undefined, on `entity`. */\nexport function isFieldSet(entity: Entity, fieldName: string): boolean {\n const { data } = getInstanceData(entity);\n if (fieldName in data) return true;\n // Avoid calling `getField` on new entities because it populates the field as a side effect.\n if (entity.isNewEntity) return false;\n // We may not have converted the database column value into domain values yet.\n getField(entity, fieldName, true);\n return fieldName in data;\n}\n\n/**\n * Sets the current value of `fieldName`, this is an internal method that should\n * only be called by the code-generated setters.\n *\n * We skip any typing like `fieldName: keyof T` because this method should only be\n * called by trusted codegen anyway.\n *\n * Returns `true` if the value was changed, or `false` if it was a noop.\n */\nexport function setField(entity: Entity, fieldName: string, newValue: any): boolean {\n ensureNotDeleted(entity, \"pending\");\n const { em } = entity;\n const api = getEmInternalApi(em);\n const { rm, pluginManager, indexManager, fieldLogger, isLoadedCache } = api;\n\n // If we're flushing, only allow writes from hooks\n api.checkWritesAllowed();\n\n const instanceData = getInstanceData(entity);\n const { data, originalData, flushedData } = instanceData;\n\n // Do string sanitization\n const field = getMetadata(entity).allFields[fieldName];\n if (field.kind === \"primitive\" && field.type === \"string\" && field.sanitize !== false) {\n newValue = cleanStringValue(newValue);\n }\n\n const currentValue = getField(entity, fieldName, true);\n const isReference = field.kind === \"m2o\" || field.kind === \"poly\";\n const currentEqualsNew = fieldValueEquals(field, currentValue, newValue);\n\n // Tell any `#isLoaded` or `#value` caches that they might be stale, but only\n // after we've checked if the current value changed. Also we do it here,\n // before the \"reverting a dirty value to the original\" check below,\n // because caches might have already observed the dirty value, so would\n // still need to refresh.\n if (!currentEqualsNew) isLoadedCache.resetIsLoaded(entity, fieldName);\n\n // Check `config.setTransitions` tables while the change is still synchronous, before we change anything,\n // and record the transition for `em.flush` to run its (async) guards and reactions\n if (field.kind === \"enum\" && !currentEqualsNew) rm.queueTransition(entity, fieldName, currentValue, newValue);\n // Remember every prior reference value so `followReverseHint` can rewalk both original and transient owners.\n if (isReference && !currentEqualsNew) {\n instanceData.rememberReferenceValue(fieldName, currentValue);\n }\n\n // If a `set` occurs during the AsyncReactiveField-loop, copy the last-flushed value to flushedData.\n // Then our `pendingOperation` logic can tell \"do we need another micro-flush?\" separately\n // from our public-facing changed fields logic.\n if (flushedData) {\n if (fieldName in flushedData) {\n // We've already copied the last-micro-flush value into flushedData,\n // are we changing back to that? If so, we won't need another micro-flush.\n if (equalOrSameEntity(flushedData[fieldName], newValue)) {\n delete flushedData[fieldName];\n } else {\n // Otherwise just let data[fieldName] get the even-newer value, and keep\n // flushedData[fieldName] as the last-micro-flushed value.\n }\n } else if (!currentEqualsNew) {\n // This is the 1st rqf-loop change for this field, so let data[fieldName]\n // get the even newer value, but keep the last-micro-flushed value in flushedData.\n flushedData[fieldName] = currentValue;\n }\n }\n\n // \"Un-dirty\" our originalData if newValue is reverting to originalData\n if (fieldName in originalData) {\n if (fieldValueEquals(field, originalData[fieldName], newValue)) {\n indexManager.maybeUpdateFieldIndex(entity, fieldName, currentValue, newValue);\n\n pluginManager.beforeSetField(entity, fieldName, newValue);\n data[fieldName] = newValue;\n instanceData.markFieldClean(fieldName);\n\n fieldLogger.logSet(entity, fieldName, newValue);\n if (isReference && instanceData.getReferenceHistory(fieldName).length > 0) {\n rm.queueDownstreamReactables(entity, fieldName);\n } else {\n // For normal reverts, the field is clean again, so any pending downstream work can be removed.\n rm.dequeueDownstreamReactables(entity, fieldName);\n }\n\n return true;\n }\n }\n\n // Push this logic into a field serde type abstraction?\n if (currentEqualsNew) {\n // If we're doing `entity.field = undefined`, we'll be equal, but mark ourselves as \"set\"\n // so that defaults know to respect the intent of keeping this field undefined.\n if (!(fieldName in data)) data[fieldName] = undefined;\n return false;\n }\n\n // Only save the currentValue on the 1st change of this field\n if (!(fieldName in originalData)) {\n instanceData.markFieldDirty(fieldName, currentValue);\n }\n fieldLogger.logSet(entity, fieldName, newValue);\n rm.queueDownstreamReactables(entity, fieldName);\n\n indexManager.maybeUpdateFieldIndex(entity, fieldName, currentValue, newValue);\n\n pluginManager.beforeSetField(entity, fieldName, newValue);\n data[fieldName] = newValue;\n return true;\n}\n\nfunction fieldValueEquals(field: Field, a: unknown, b: unknown): boolean {\n // Primitive scalar sets are the common path, so avoid Date/Temporal/entity checks when both values cannot need them.\n if (field.kind !== \"m2o\" && field.kind !== \"poly\" && isNonObjectValue(a) && isNonObjectValue(b)) return a === b;\n return equalOrSameEntity(a, b);\n}\n\nfunction isNonObjectValue(value: unknown): boolean {\n return value === null || typeof value !== \"object\";\n}\n\nfunction equalOrSameEntity(a: any, b: any): boolean {\n return (\n equal(a, b) ||\n (Array.isArray(a) && Array.isArray(b) && equalArrays(a, b)) ||\n // This is kind of gross, but make sure not to compare two both-new entities\n (((isEntity(a) && !a.isNewEntity) || (isEntity(b) && !b.isNewEntity)) &&\n maybeResolveReferenceToId(a) === maybeResolveReferenceToId(b))\n );\n}\n\nexport function equalArrays(a: any[], b: any[]): boolean {\n if (a.length !== b.length) return false;\n return a.every((_: any, i) => equal(a[i], b[i]));\n}\n\nconst Temporal = maybeRequireTemporal()?.Temporal;\nexport function equal(a: any, b: any): boolean {\n if (a === b) return true;\n if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();\n if (Temporal) {\n if (a instanceof Temporal.ZonedDateTime && b instanceof Temporal.ZonedDateTime) return a.equals(b);\n if (a instanceof Temporal.PlainDateTime && b instanceof Temporal.PlainDateTime) return a.equals(b);\n if (a instanceof Temporal.PlainDate && b instanceof Temporal.PlainDate) return a.equals(b);\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAeA,SAAgB,SAAS,QAAgB,WAAmB,aAAa,OAAY;CACnF,MAAM,EAAE,OAAO;CAEf,sBADYA,iBAAiB,EAC3B,CAAC,CAAC,cAAc,eAAe,QAAQ,SAAS;CAElD,MAAM,eAAeC,mBAAAA,gBAAgB,MAAM;CAC3C,MAAM,QAAQ,aAAa,SAAS,UAAU;CAC9C,IAAI,CAAC,cAAc,OAAO,iBAAiB,GAAG,gBAAgB,MAAM;CAEpE,MAAM,EAAE,SAAS;CACjB,IAAI,aAAa,MACf,OAAO,KAAK;MACP;EACL,IAAI,CAAC,OAAO,aAEV,KAAK,cADS,OAAO,SAASC,cAAAA,KAAK,qBAAqB,WAAW,EAAA,CAC3C,QAAQ,aAAa,SAAS,aAAa,QAAQ;EAE7E,OAAO,KAAK;CACd;AACF;;AAGA,SAAgB,kBAAkB,QAAgB,WAA4B;CAC5E,OAAO,CAAC,CAACC,uBAAAA,YAAY,MAAM,CAAC,CAAC,UAAU,UAAU,EAAE;AACrD;;AAGA,SAAgB,WAAW,QAAgB,WAA4B;CACrE,MAAM,EAAE,SAASF,mBAAAA,gBAAgB,MAAM;CACvC,IAAI,aAAa,MAAM,OAAO;CAE9B,IAAI,OAAO,aAAa,OAAO;CAE/B,SAAS,QAAQ,WAAW,IAAI;CAChC,OAAO,aAAa;AACtB;;;;;;;;;;AAWA,SAAgB,SAAS,QAAgB,WAAmB,UAAwB;CAClF,cAAA,iBAAiB,QAAQ,SAAS;CAClC,MAAM,EAAE,OAAO;CACf,MAAM,MAAMD,sBAAAA,iBAAiB,EAAE;CAC/B,MAAM,EAAE,IAAI,eAAe,cAAc,aAAa,kBAAkB;CAGxE,IAAI,mBAAmB;CAEvB,MAAM,eAAeC,mBAAAA,gBAAgB,MAA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AC;EACjG,IAAI,aAAa,SAAS,aAAa,aAAa,SAAS,WAAW,OAAO,EAAE,OAAO,CAAC;CAC3F;CACA,OAAO;AACT"}
@@ -1,17 +1,17 @@
1
1
  import { Entity } from "./Entity.cjs";
2
2
  //#region src/fields.d.ts
3
3
  /**
4
- * Returns the current value of `fieldName`, this is an internal method that should
5
- * only be called by the code-generated getters.
4
+ * Returns the current value of `fieldName`, marking the entity for read locking if the field is configured.
6
5
  *
7
- * We skip any typing like `fieldName: keyof T` because this method should only be
8
- * called by trusted codegen anyway.
6
+ * Generated getters and direct application calls are protected by default. Only ORM
7
+ * housekeeping should pass `isInternal`, not domain logic in hooks, rules, or reactions.
8
+ * The field name is a string because generated getters and ORM internals know its type.
9
9
  */
10
- declare function getField(entity: Entity, fieldName: string): any;
10
+ export declare function getField(entity: Entity, fieldName: string, isInternal?: boolean): any;
11
11
  /** Returns whether `fieldName` is a field/column on `entity` that can be changed. */
12
- declare function isChangeableField(entity: Entity, fieldName: string): boolean;
12
+ export declare function isChangeableField(entity: Entity, fieldName: string): boolean;
13
13
  /** Returns whether `fieldName` has been set, even if it's undefined, on `entity`. */
14
- declare function isFieldSet(entity: Entity, fieldName: string): boolean;
14
+ export declare function isFieldSet(entity: Entity, fieldName: string): boolean;
15
15
  /**
16
16
  * Sets the current value of `fieldName`, this is an internal method that should
17
17
  * only be called by the code-generated setters.
@@ -21,9 +21,8 @@ declare function isFieldSet(entity: Entity, fieldName: string): boolean;
21
21
  *
22
22
  * Returns `true` if the value was changed, or `false` if it was a noop.
23
23
  */
24
- declare function setField(entity: Entity, fieldName: string, newValue: any): boolean;
25
- declare function equalArrays(a: any[], b: any[]): boolean;
26
- declare function equal(a: any, b: any): boolean;
24
+ export declare function setField(entity: Entity, fieldName: string, newValue: any): boolean;
25
+ export declare function equalArrays(a: any[], b: any[]): boolean;
26
+ export declare function equal(a: any, b: any): boolean;
27
27
  //#endregion
28
- export { equal, equalArrays, getField, isChangeableField, isFieldSet, setField };
29
28
  //# sourceMappingURL=fields.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fields.d.cts","names":[],"sources":["../src/fields.ts"],"mappings":";;;;;;;;;iBAegB,SAAS,QAAQ,QAAQ;;iBAoBzB,kBAAkB,QAAQ,QAAQ;;iBAKlC,WAAW,QAAQ,QAAQ;;;;;;;;;;iBAmB3B,SAAS,QAAQ,QAAQ,mBAAmB;iBAgH5C,YAAY,UAAU;iBAMtB,MAAM,QAAQ"}
1
+ {"version":3,"file":"fields.d.cts","names":[],"sources":["../src/fields.ts"],"mappings":";;;;;;;;;wBAegB,SAAS,QAAQ,QAAQ,mBAAmB;;wBAsB5C,kBAAkB,QAAQ,QAAQ;;wBAKlC,WAAW,QAAQ,QAAQ;;;;;;;;;;wBAmB3B,SAAS,QAAQ,QAAQ,mBAAmB;wBAwH5C,YAAY,UAAU;wBAMtB,MAAM,QAAQ"}
@@ -1,17 +1,17 @@
1
1
  import { Entity } from "./Entity.mjs";
2
2
  //#region src/fields.d.ts
3
3
  /**
4
- * Returns the current value of `fieldName`, this is an internal method that should
5
- * only be called by the code-generated getters.
4
+ * Returns the current value of `fieldName`, marking the entity for read locking if the field is configured.
6
5
  *
7
- * We skip any typing like `fieldName: keyof T` because this method should only be
8
- * called by trusted codegen anyway.
6
+ * Generated getters and direct application calls are protected by default. Only ORM
7
+ * housekeeping should pass `isInternal`, not domain logic in hooks, rules, or reactions.
8
+ * The field name is a string because generated getters and ORM internals know its type.
9
9
  */
10
- declare function getField(entity: Entity, fieldName: string): any;
10
+ export declare function getField(entity: Entity, fieldName: string, isInternal?: boolean): any;
11
11
  /** Returns whether `fieldName` is a field/column on `entity` that can be changed. */
12
- declare function isChangeableField(entity: Entity, fieldName: string): boolean;
12
+ export declare function isChangeableField(entity: Entity, fieldName: string): boolean;
13
13
  /** Returns whether `fieldName` has been set, even if it's undefined, on `entity`. */
14
- declare function isFieldSet(entity: Entity, fieldName: string): boolean;
14
+ export declare function isFieldSet(entity: Entity, fieldName: string): boolean;
15
15
  /**
16
16
  * Sets the current value of `fieldName`, this is an internal method that should
17
17
  * only be called by the code-generated setters.
@@ -21,9 +21,8 @@ declare function isFieldSet(entity: Entity, fieldName: string): boolean;
21
21
  *
22
22
  * Returns `true` if the value was changed, or `false` if it was a noop.
23
23
  */
24
- declare function setField(entity: Entity, fieldName: string, newValue: any): boolean;
25
- declare function equalArrays(a: any[], b: any[]): boolean;
26
- declare function equal(a: any, b: any): boolean;
24
+ export declare function setField(entity: Entity, fieldName: string, newValue: any): boolean;
25
+ export declare function equalArrays(a: any[], b: any[]): boolean;
26
+ export declare function equal(a: any, b: any): boolean;
27
27
  //#endregion
28
- export { equal, equalArrays, getField, isChangeableField, isFieldSet, setField };
29
28
  //# sourceMappingURL=fields.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fields.d.mts","names":[],"sources":["../src/fields.ts"],"mappings":";;;;;;;;;iBAegB,SAAS,QAAQ,QAAQ;;iBAoBzB,kBAAkB,QAAQ,QAAQ;;iBAKlC,WAAW,QAAQ,QAAQ;;;;;;;;;;iBAmB3B,SAAS,QAAQ,QAAQ,mBAAmB;iBAgH5C,YAAY,UAAU;iBAMtB,MAAM,QAAQ"}
1
+ {"version":3,"file":"fields.d.mts","names":[],"sources":["../src/fields.ts"],"mappings":";;;;;;;;;wBAegB,SAAS,QAAQ,QAAQ,mBAAmB;;wBAsB5C,kBAAkB,QAAQ,QAAQ;;wBAKlC,WAAW,QAAQ,QAAQ;;;;;;;;;;wBAmB3B,SAAS,QAAQ,QAAQ,mBAAmB;wBAwH5C,YAAY,UAAU;wBAMtB,MAAM,QAAQ"}
package/build/fields.js CHANGED
@@ -8,20 +8,22 @@ import { isEntity } from "./Entity.js";
8
8
  import { getInstanceData } from "./BaseEntity.js";
9
9
  //#region src/fields.ts
10
10
  /**
11
- * Returns the current value of `fieldName`, this is an internal method that should
12
- * only be called by the code-generated getters.
11
+ * Returns the current value of `fieldName`, marking the entity for read locking if the field is configured.
13
12
  *
14
- * We skip any typing like `fieldName: keyof T` because this method should only be
15
- * called by trusted codegen anyway.
13
+ * Generated getters and direct application calls are protected by default. Only ORM
14
+ * housekeeping should pass `isInternal`, not domain logic in hooks, rules, or reactions.
15
+ * The field name is a string because generated getters and ORM internals know its type.
16
16
  */
17
- function getField(entity, fieldName) {
17
+ function getField(entity, fieldName, isInternal = false) {
18
18
  const { em } = entity;
19
19
  getEmInternalApi(em).pluginManager.beforeGetField(entity, fieldName);
20
20
  const instanceData = getInstanceData(entity);
21
+ const field = instanceData.metadata.allFields[fieldName];
22
+ if (!isInternal && field?.assertUnchanged) em.assertUnchanged(entity);
21
23
  const { data } = instanceData;
22
24
  if (fieldName in data) return data[fieldName];
23
25
  else {
24
- if (!entity.isNewEntity) data[fieldName] = (getMetadata(entity).allFields[fieldName]?.serde ?? fail(`Missing serde for ${fieldName}`)).fromRow(instanceData.rowData, instanceData.rowIndex);
26
+ if (!entity.isNewEntity) data[fieldName] = (field?.serde ?? fail(`Missing serde for ${fieldName}`)).fromRow(instanceData.rowData, instanceData.rowIndex);
25
27
  return data[fieldName];
26
28
  }
27
29
  }
@@ -34,7 +36,7 @@ function isFieldSet(entity, fieldName) {
34
36
  const { data } = getInstanceData(entity);
35
37
  if (fieldName in data) return true;
36
38
  if (entity.isNewEntity) return false;
37
- getField(entity, fieldName);
39
+ getField(entity, fieldName, true);
38
40
  return fieldName in data;
39
41
  }
40
42
  /**
@@ -52,14 +54,15 @@ function setField(entity, fieldName, newValue) {
52
54
  const api = getEmInternalApi(em);
53
55
  const { rm, pluginManager, indexManager, fieldLogger, isLoadedCache } = api;
54
56
  api.checkWritesAllowed();
55
- isLoadedCache.resetIsLoaded(entity, fieldName);
56
57
  const instanceData = getInstanceData(entity);
57
58
  const { data, originalData, flushedData } = instanceData;
58
59
  const field = getMetadata(entity).allFields[fieldName];
59
60
  if (field.kind === "primitive" && field.type === "string" && field.sanitize !== false) newValue = cleanStringValue(newValue);
60
- const currentValue = getField(entity, fieldName);
61
+ const currentValue = getField(entity, fieldName, true);
61
62
  const isReference = field.kind === "m2o" || field.kind === "poly";
62
63
  const currentEqualsNew = fieldValueEquals(field, currentValue, newValue);
64
+ if (!currentEqualsNew) isLoadedCache.resetIsLoaded(entity, fieldName);
65
+ if (field.kind === "enum" && !currentEqualsNew) rm.queueTransition(entity, fieldName, currentValue, newValue);
63
66
  if (isReference && !currentEqualsNew) instanceData.rememberReferenceValue(fieldName, currentValue);
64
67
  if (flushedData) {
65
68
  if (fieldName in flushedData) {
@@ -1 +1 @@
1
- {"version":3,"file":"fields.js","names":[],"sources":["../src/fields.ts"],"sourcesContent":["import { getInstanceData } from \"src/BaseEntity.ts\";\nimport { type Entity, isEntity } from \"src/Entity.ts\";\nimport { getEmInternalApi } from \"src/EntityManager.ts\";\nimport { type Field, getMetadata } from \"src/EntityMetadata.ts\";\nimport { cleanStringValue, ensureNotDeleted, maybeResolveReferenceToId } from \"src/index.ts\";\nimport { maybeRequireTemporal } from \"src/serde/temporal.ts\";\nimport { fail } from \"src/utils.ts\";\n\n/**\n * Returns the current value of `fieldName`, this is an internal method that should\n * only be called by the code-generated getters.\n *\n * We skip any typing like `fieldName: keyof T` because this method should only be\n * called by trusted codegen anyway.\n */\nexport function getField(entity: Entity, fieldName: string): any {\n const { em } = entity;\n const api = getEmInternalApi(em);\n api.pluginManager.beforeGetField(entity, fieldName);\n // We may not have converted the database column value into domain values yet\n const instanceData = getInstanceData(entity);\n const { data } = instanceData;\n if (fieldName in data) {\n return data[fieldName];\n } else {\n if (!entity.isNewEntity) {\n const field = getMetadata(entity).allFields[fieldName];\n const serde = field?.serde ?? fail(`Missing serde for ${fieldName}`);\n data[fieldName] = serde.fromRow(instanceData.rowData, instanceData.rowIndex);\n }\n return data[fieldName];\n }\n}\n\n/** Returns whether `fieldName` is a field/column on `entity` that can be changed. */\nexport function isChangeableField(entity: Entity, fieldName: string): boolean {\n return !!getMetadata(entity).allFields[fieldName]?.serde;\n}\n\n/** Returns whether `fieldName` has been set, even if it's undefined, on `entity`. */\nexport function isFieldSet(entity: Entity, fieldName: string): boolean {\n const { data } = getInstanceData(entity);\n if (fieldName in data) return true;\n // Avoid calling `getField` on new entities because it populates the field as a side effect.\n if (entity.isNewEntity) return false;\n // We may not have converted the database column value into domain values yet.\n getField(entity, fieldName);\n return fieldName in data;\n}\n\n/**\n * Sets the current value of `fieldName`, this is an internal method that should\n * only be called by the code-generated setters.\n *\n * We skip any typing like `fieldName: keyof T` because this method should only be\n * called by trusted codegen anyway.\n *\n * Returns `true` if the value was changed, or `false` if it was a noop.\n */\nexport function setField(entity: Entity, fieldName: string, newValue: any): boolean {\n ensureNotDeleted(entity, \"pending\");\n const { em } = entity;\n const api = getEmInternalApi(em);\n const { rm, pluginManager, indexManager, fieldLogger, isLoadedCache } = api;\n\n // If we're flushing, only allow writes from hooks\n api.checkWritesAllowed();\n\n // Tell any `#isLoaded` or `#value` caches that they might be stale\n isLoadedCache.resetIsLoaded(entity, fieldName);\n\n const instanceData = getInstanceData(entity);\n const { data, originalData, flushedData } = instanceData;\n\n // Do string sanitization\n const field = getMetadata(entity).allFields[fieldName];\n if (field.kind === \"primitive\" && field.type === \"string\" && field.sanitize !== false) {\n newValue = cleanStringValue(newValue);\n }\n\n const currentValue = getField(entity, fieldName);\n const isReference = field.kind === \"m2o\" || field.kind === \"poly\";\n const currentEqualsNew = fieldValueEquals(field, currentValue, newValue);\n // Remember every prior reference value so `followReverseHint` can rewalk both original and transient owners.\n if (isReference && !currentEqualsNew) {\n instanceData.rememberReferenceValue(fieldName, currentValue);\n }\n\n // If a `set` occurs during the AsyncReactiveField-loop, copy the last-flushed value to flushedData.\n // Then our `pendingOperation` logic can tell \"do we need another micro-flush?\" separately\n // from our public-facing changed fields logic.\n if (flushedData) {\n if (fieldName in flushedData) {\n // We've already copied the last-micro-flush value into flushedData,\n // are we changing back to that? If so, we won't need another micro-flush.\n if (equalOrSameEntity(flushedData[fieldName], newValue)) {\n delete flushedData[fieldName];\n } else {\n // Otherwise just let data[fieldName] get the even-newer value, and keep\n // flushedData[fieldName] as the last-micro-flushed value.\n }\n } else if (!currentEqualsNew) {\n // This is the 1st rqf-loop change for this field, so let data[fieldName]\n // get the even newer value, but keep the last-micro-flushed value in flushedData.\n flushedData[fieldName] = currentValue;\n }\n }\n\n // \"Un-dirty\" our originalData if newValue is reverting to originalData\n if (fieldName in originalData) {\n if (fieldValueEquals(field, originalData[fieldName], newValue)) {\n indexManager.maybeUpdateFieldIndex(entity, fieldName, currentValue, newValue);\n\n pluginManager.beforeSetField(entity, fieldName, newValue);\n data[fieldName] = newValue;\n instanceData.markFieldClean(fieldName);\n\n fieldLogger.logSet(entity, fieldName, newValue);\n if (isReference && instanceData.getReferenceHistory(fieldName).length > 0) {\n rm.queueDownstreamReactables(entity, fieldName);\n } else {\n // For normal reverts, the field is clean again, so any pending downstream work can be removed.\n rm.dequeueDownstreamReactables(entity, fieldName);\n }\n\n return true;\n }\n }\n\n // Push this logic into a field serde type abstraction?\n if (currentEqualsNew) {\n // If we're doing `entity.field = undefined`, we'll be equal, but mark ourselves as \"set\"\n // so that defaults know to respect the intent of keeping this field undefined.\n if (!(fieldName in data)) data[fieldName] = undefined;\n return false;\n }\n\n // Only save the currentValue on the 1st change of this field\n if (!(fieldName in originalData)) {\n instanceData.markFieldDirty(fieldName, currentValue);\n }\n fieldLogger.logSet(entity, fieldName, newValue);\n rm.queueDownstreamReactables(entity, fieldName);\n\n indexManager.maybeUpdateFieldIndex(entity, fieldName, currentValue, newValue);\n\n pluginManager.beforeSetField(entity, fieldName, newValue);\n data[fieldName] = newValue;\n return true;\n}\n\nfunction fieldValueEquals(field: Field, a: unknown, b: unknown): boolean {\n // Primitive scalar sets are the common path, so avoid Date/Temporal/entity checks when both values cannot need them.\n if (field.kind !== \"m2o\" && field.kind !== \"poly\" && isNonObjectValue(a) && isNonObjectValue(b)) return a === b;\n return equalOrSameEntity(a, b);\n}\n\nfunction isNonObjectValue(value: unknown): boolean {\n return value === null || typeof value !== \"object\";\n}\n\nfunction equalOrSameEntity(a: any, b: any): boolean {\n return (\n equal(a, b) ||\n (Array.isArray(a) && Array.isArray(b) && equalArrays(a, b)) ||\n // This is kind of gross, but make sure not to compare two both-new entities\n (((isEntity(a) && !a.isNewEntity) || (isEntity(b) && !b.isNewEntity)) &&\n maybeResolveReferenceToId(a) === maybeResolveReferenceToId(b))\n );\n}\n\nexport function equalArrays(a: any[], b: any[]): boolean {\n if (a.length !== b.length) return false;\n return a.every((_: any, i) => equal(a[i], b[i]));\n}\n\nconst Temporal = maybeRequireTemporal()?.Temporal;\nexport function equal(a: any, b: any): boolean {\n if (a === b) return true;\n if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();\n if (Temporal) {\n if (a instanceof Temporal.ZonedDateTime && b instanceof Temporal.ZonedDateTime) return a.equals(b);\n if (a instanceof Temporal.PlainDateTime && b instanceof Temporal.PlainDateTime) return a.equals(b);\n if (a instanceof Temporal.PlainDate && b instanceof Temporal.PlainDate) return a.equals(b);\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,SAAgB,SAAS,QAAgB,WAAwB;CAC/D,MAAM,EAAE,OAAO;CAEf,iBAD6B,EAC3B,CAAC,CAAC,cAAc,eAAe,QAAQ,SAAS;CAElD,MAAM,eAAe,gBAAgB,MAAM;CAC3C,MAAM,EAAE,SAAS;CACjB,IAAI,aAAa,MACf,OAAO,KAAK;MACP;EACL,IAAI,CAAC,OAAO,aAGV,KAAK,cAFS,YAAY,MAAM,CAAC,CAAC,UAAU,UACzB,EAAE,SAAS,KAAK,qBAAqB,WAAW,EAAA,CAC3C,QAAQ,aAAa,SAAS,aAAa,QAAQ;EAE7E,OAAO,KAAK;CACd;AACF;;AAGA,SAAgB,kBAAkB,QAAgB,WAA4B;CAC5E,OAAO,CAAC,CAAC,YAAY,MAAM,CAAC,CAAC,UAAU,UAAU,EAAE;AACrD;;AAGA,SAAgB,WAAW,QAAgB,WAA4B;CACrE,MAAM,EAAE,SAAS,gBAAg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AQ,MAAM,EAAE,QAAQ;CAC7E,IAAI,UAAU;EACZ,IAAI,aAAa,SAAS,iBAAiB,aAAa,SAAS,eAAe,OAAO,EAAE,OAAO,CAAC;EACjG,IAAI,aAAa,SAAS,iBAAiB,aAAa,SAAS,eAAe,OAAO,EAAE,OAAO,CAAC;EACjG,IAAI,aAAa,SAAS,aAAa,aAAa,SAAS,WAAW,OAAO,EAAE,OAAO,CAAC;CAC3F;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"fields.js","names":[],"sources":["../src/fields.ts"],"sourcesContent":["import { getInstanceData } from \"src/BaseEntity.ts\";\nimport { type Entity, isEntity } from \"src/Entity.ts\";\nimport { getEmInternalApi } from \"src/EntityManager.ts\";\nimport { type Field, getMetadata } from \"src/EntityMetadata.ts\";\nimport { cleanStringValue, ensureNotDeleted, maybeResolveReferenceToId } from \"src/index.ts\";\nimport { maybeRequireTemporal } from \"src/serde/temporal.ts\";\nimport { fail } from \"src/utils.ts\";\n\n/**\n * Returns the current value of `fieldName`, marking the entity for read locking if the field is configured.\n *\n * Generated getters and direct application calls are protected by default. Only ORM\n * housekeeping should pass `isInternal`, not domain logic in hooks, rules, or reactions.\n * The field name is a string because generated getters and ORM internals know its type.\n */\nexport function getField(entity: Entity, fieldName: string, isInternal = false): any {\n const { em } = entity;\n const api = getEmInternalApi(em);\n api.pluginManager.beforeGetField(entity, fieldName);\n // We may not have converted the database column value into domain values yet\n const instanceData = getInstanceData(entity);\n const field = instanceData.metadata.allFields[fieldName];\n if (!isInternal && field?.assertUnchanged) em.assertUnchanged(entity);\n\n const { data } = instanceData;\n if (fieldName in data) {\n return data[fieldName];\n } else {\n if (!entity.isNewEntity) {\n const serde = field?.serde ?? fail(`Missing serde for ${fieldName}`);\n data[fieldName] = serde.fromRow(instanceData.rowData, instanceData.rowIndex);\n }\n return data[fieldName];\n }\n}\n\n/** Returns whether `fieldName` is a field/column on `entity` that can be changed. */\nexport function isChangeableField(entity: Entity, fieldName: string): boolean {\n return !!getMetadata(entity).allFields[fieldName]?.serde;\n}\n\n/** Returns whether `fieldName` has been set, even if it's undefined, on `entity`. */\nexport function isFieldSet(entity: Entity, fieldName: string): boolean {\n const { data } = getInstanceData(entity);\n if (fieldName in data) return true;\n // Avoid calling `getField` on new entities because it populates the field as a side effect.\n if (entity.isNewEntity) return false;\n // We may not have converted the database column value into domain values yet.\n getField(entity, fieldName, true);\n return fieldName in data;\n}\n\n/**\n * Sets the current value of `fieldName`, this is an internal method that should\n * only be called by the code-generated setters.\n *\n * We skip any typing like `fieldName: keyof T` because this method should only be\n * called by trusted codegen anyway.\n *\n * Returns `true` if the value was changed, or `false` if it was a noop.\n */\nexport function setField(entity: Entity, fieldName: string, newValue: any): boolean {\n ensureNotDeleted(entity, \"pending\");\n const { em } = entity;\n const api = getEmInternalApi(em);\n const { rm, pluginManager, indexManager, fieldLogger, isLoadedCache } = api;\n\n // If we're flushing, only allow writes from hooks\n api.checkWritesAllowed();\n\n const instanceData = getInstanceData(entity);\n const { data, originalData, flushedData } = instanceData;\n\n // Do string sanitization\n const field = getMetadata(entity).allFields[fieldName];\n if (field.kind === \"primitive\" && field.type === \"string\" && field.sanitize !== false) {\n newValue = cleanStringValue(newValue);\n }\n\n const currentValue = getField(entity, fieldName, true);\n const isReference = field.kind === \"m2o\" || field.kind === \"poly\";\n const currentEqualsNew = fieldValueEquals(field, currentValue, newValue);\n\n // Tell any `#isLoaded` or `#value` caches that they might be stale, but only\n // after we've checked if the current value changed. Also we do it here,\n // before the \"reverting a dirty value to the original\" check below,\n // because caches might have already observed the dirty value, so would\n // still need to refresh.\n if (!currentEqualsNew) isLoadedCache.resetIsLoaded(entity, fieldName);\n\n // Check `config.setTransitions` tables while the change is still synchronous, before we change anything,\n // and record the transition for `em.flush` to run its (async) guards and reactions\n if (field.kind === \"enum\" && !currentEqualsNew) rm.queueTransition(entity, fieldName, currentValue, newValue);\n // Remember every prior reference value so `followReverseHint` can rewalk both original and transient owners.\n if (isReference && !currentEqualsNew) {\n instanceData.rememberReferenceValue(fieldName, currentValue);\n }\n\n // If a `set` occurs during the AsyncReactiveField-loop, copy the last-flushed value to flushedData.\n // Then our `pendingOperation` logic can tell \"do we need another micro-flush?\" separately\n // from our public-facing changed fields logic.\n if (flushedData) {\n if (fieldName in flushedData) {\n // We've already copied the last-micro-flush value into flushedData,\n // are we changing back to that? If so, we won't need another micro-flush.\n if (equalOrSameEntity(flushedData[fieldName], newValue)) {\n delete flushedData[fieldName];\n } else {\n // Otherwise just let data[fieldName] get the even-newer value, and keep\n // flushedData[fieldName] as the last-micro-flushed value.\n }\n } else if (!currentEqualsNew) {\n // This is the 1st rqf-loop change for this field, so let data[fieldName]\n // get the even newer value, but keep the last-micro-flushed value in flushedData.\n flushedData[fieldName] = currentValue;\n }\n }\n\n // \"Un-dirty\" our originalData if newValue is reverting to originalData\n if (fieldName in originalData) {\n if (fieldValueEquals(field, originalData[fieldName], newValue)) {\n indexManager.maybeUpdateFieldIndex(entity, fieldName, currentValue, newValue);\n\n pluginManager.beforeSetField(entity, fieldName, newValue);\n data[fieldName] = newValue;\n instanceData.markFieldClean(fieldName);\n\n fieldLogger.logSet(entity, fieldName, newValue);\n if (isReference && instanceData.getReferenceHistory(fieldName).length > 0) {\n rm.queueDownstreamReactables(entity, fieldName);\n } else {\n // For normal reverts, the field is clean again, so any pending downstream work can be removed.\n rm.dequeueDownstreamReactables(entity, fieldName);\n }\n\n return true;\n }\n }\n\n // Push this logic into a field serde type abstraction?\n if (currentEqualsNew) {\n // If we're doing `entity.field = undefined`, we'll be equal, but mark ourselves as \"set\"\n // so that defaults know to respect the intent of keeping this field undefined.\n if (!(fieldName in data)) data[fieldName] = undefined;\n return false;\n }\n\n // Only save the currentValue on the 1st change of this field\n if (!(fieldName in originalData)) {\n instanceData.markFieldDirty(fieldName, currentValue);\n }\n fieldLogger.logSet(entity, fieldName, newValue);\n rm.queueDownstreamReactables(entity, fieldName);\n\n indexManager.maybeUpdateFieldIndex(entity, fieldName, currentValue, newValue);\n\n pluginManager.beforeSetField(entity, fieldName, newValue);\n data[fieldName] = newValue;\n return true;\n}\n\nfunction fieldValueEquals(field: Field, a: unknown, b: unknown): boolean {\n // Primitive scalar sets are the common path, so avoid Date/Temporal/entity checks when both values cannot need them.\n if (field.kind !== \"m2o\" && field.kind !== \"poly\" && isNonObjectValue(a) && isNonObjectValue(b)) return a === b;\n return equalOrSameEntity(a, b);\n}\n\nfunction isNonObjectValue(value: unknown): boolean {\n return value === null || typeof value !== \"object\";\n}\n\nfunction equalOrSameEntity(a: any, b: any): boolean {\n return (\n equal(a, b) ||\n (Array.isArray(a) && Array.isArray(b) && equalArrays(a, b)) ||\n // This is kind of gross, but make sure not to compare two both-new entities\n (((isEntity(a) && !a.isNewEntity) || (isEntity(b) && !b.isNewEntity)) &&\n maybeResolveReferenceToId(a) === maybeResolveReferenceToId(b))\n );\n}\n\nexport function equalArrays(a: any[], b: any[]): boolean {\n if (a.length !== b.length) return false;\n return a.every((_: any, i) => equal(a[i], b[i]));\n}\n\nconst Temporal = maybeRequireTemporal()?.Temporal;\nexport function equal(a: any, b: any): boolean {\n if (a === b) return true;\n if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();\n if (Temporal) {\n if (a instanceof Temporal.ZonedDateTime && b instanceof Temporal.ZonedDateTime) return a.equals(b);\n if (a instanceof Temporal.PlainDateTime && b instanceof Temporal.PlainDateTime) return a.equals(b);\n if (a instanceof Temporal.PlainDate && b instanceof Temporal.PlainDate) return a.equals(b);\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,SAAgB,SAAS,QAAgB,WAAmB,aAAa,OAAY;CACnF,MAAM,EAAE,OAAO;CAEf,iBAD6B,EAC3B,CAAC,CAAC,cAAc,eAAe,QAAQ,SAAS;CAElD,MAAM,eAAe,gBAAgB,MAAM;CAC3C,MAAM,QAAQ,aAAa,SAAS,UAAU;CAC9C,IAAI,CAAC,cAAc,OAAO,iBAAiB,GAAG,gBAAgB,MAAM;CAEpE,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,QAAQ,CAAC,KAAK,MAAM,QAAQ,CAAC,KAAK,YAAY,GAAG,CAAC,MAEtD,SAAS,CAAC,KAAK,CAAC,EAAE,eAAiB,SAAS,CAAC,KAAK,CAAC,EAAE,gBACtD,0BAA0B,CAAC,MAAM,0BAA0B,CAAC;AAElE;AAEA,SAAgB,YAAY,GAAU,GAAmB;CACvD,IAAI,EAAE,WAAW,EAAE,QAAQ,OAAO;CAClC,OAAO,EAAE,OAAO,GAAQ,MAAM,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC;AACjD;AAEA,MAAM,WAAW,qBAAqB,CAAC,EAAE;AACzC,SAAgB,MAAM,GAAQ,GAAiB;CAC7C,IAAI,MAAM,GAAG,OAAO;CACpB,IAAI,aAAa,QAAQ,aAAa,MAAM,OAAO,EAAE,QAAQ,MAAM,EAAE,QAAQ;CAC7E,IAAI,UAAU;EACZ,IAAI,aAAa,SAAS,iBAAiB,aAAa,SAAS,eAAe,OAAO,EAAE,OAAO,CAAC;EACjG,IAAI,aAAa,SAAS,iBAAiB,aAAa,SAAS,eAAe,OAAO,EAAE,OAAO,CAAC;EACjG,IAAI,aAAa,SAAS,aAAa,aAAa,SAAS,WAAW,OAAO,EAAE,OAAO,CAAC;CAC3F;CACA,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"FlushLock.cjs","names":["AsyncLocalStorage","#isFlushing","#flushSecret"],"sources":["../../src/flush/FlushLock.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"async_hooks\";\n\n/** A marker to prevent setter calls during `flush` calls. */\nconst currentFlushSecret = new AsyncLocalStorage<{ flushSecret: number }>();\n\n/**\n * Prevents entities being mutated mid-flush.\n *\n * The `flush` process does a dirty check + SQL flush and generally doesn't want\n * entities to re-dirtied after it's done the initial dirty check. So we'd like\n * to prevent all setter calls while `flush` is running.\n *\n * That said, lifecycle code like hooks actually can make setter calls b/c `flush`\n * invokes them at a specific point in its process.\n *\n * We solve this by using node's `AsyncLocalStorage` to mark certain callbacks (promise\n * handlers) as blessed / invoked-from-`flush`-itself, and they are allowed to call setters,\n * but any external callers (i.e. application code) will be rejected.\n */\nexport class FlushLock {\n #flushSecret: number = 0;\n #isFlushing: boolean = false;\n\n /** This will begin any non-hook restrictions on writing to entities. */\n startLock(): void {\n if (this.#isFlushing) {\n throw new Error(\"Cannot flush while another flush is already in progress\");\n }\n this.#isFlushing = true;\n }\n\n releaseLock(): void {\n this.#isFlushing = false;\n }\n\n /** Any writes that happen from `fn`, despite flush being locked, will be allowed. */\n allowWrites(fn: () => Promise<void>): Promise<void> {\n return currentFlushSecret.run({ flushSecret: this.#flushSecret }, () =>\n fn().then(() => {\n this.#flushSecret += 1;\n }),\n );\n }\n\n /** Blows up if writes are locked, i.e. we're flushing and the caller is not within an `allowWrites` block. */\n checkWritesAllowed(): void {\n if (this.#isFlushing) {\n const { flushSecret } = currentFlushSecret.getStore() || {};\n if (flushSecret === undefined) {\n throw new Error(`Cannot mutate an entity during an em.flush outside of a entity hook or from afterCommit`);\n } else if (flushSecret !== this.#flushSecret) {\n throw new Error(`Attempting to reuse a hook context outside its flush loop`);\n }\n }\n }\n\n get isFlushing(): boolean {\n return this.#isFlushing;\n }\n}\n"],"mappings":";;;AAGA,MAAM,qBAAqB,0BAAIA,EAAAA,CAAAA,kBAA2C;;;;;;;;;;;;;;;AAgB1E,IAAa,YAAb,MAAuB;CACrB,eAAuB;CACvB,cAAuB;;CAGvB,YAAkB;EAChB,IAAI,KAAKC,aACP,MAAM,IAAI,MAAM,yDAAyD;EAE3E,KAAKA,cAAc;CACrB;CAEA,cAAoB;EAClB,KAAKA,cAAc;CACrB;;CAGA,YAAY,IAAwC;EAClD,OAAO,mBAAmB,IAAI,EAAE,aAAa,KAAKC,aAAa,SAC7D,GAAG,CAAC,CAAC,WAAW;GACd,KAAKA,gBAAgB;EACvB,CAAC,CACH;CACF;;CAGA,qBAA2B;EACzB,IAAI,KAAKD,aAAa;GACpB,MAAM,EAAE,gBAAgB,mBAAmB,SAAS,KAAK,CAAC;GAC1D,IAAI,gBAAgB,KAAA,GAClB,MAAM,IAAI,MAAM,yFAAyF;QACpG,IAAI,gBAAgB,KAAKC,cAC9B,MAAM,IAAI,MAAM,2DAA2D;EAE/E;CACF;CAEA,IAAI,aAAsB;EACxB,OAAO,KAAKD;CACd;AACF"}
1
+ {"version":3,"file":"FlushLock.cjs","names":["AsyncLocalStorage"],"sources":["../../src/flush/FlushLock.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"async_hooks\";\n\n/** A marker to prevent setter calls during `flush` calls. */\nconst currentFlushSecret = new AsyncLocalStorage<{ flushSecret: number }>();\n\n/**\n * Prevents entities being mutated mid-flush.\n *\n * The `flush` process does a dirty check + SQL flush and generally doesn't want\n * entities to re-dirtied after it's done the initial dirty check. So we'd like\n * to prevent all setter calls while `flush` is running.\n *\n * That said, lifecycle code like hooks actually can make setter calls b/c `flush`\n * invokes them at a specific point in its process.\n *\n * We solve this by using node's `AsyncLocalStorage` to mark certain callbacks (promise\n * handlers) as blessed / invoked-from-`flush`-itself, and they are allowed to call setters,\n * but any external callers (i.e. application code) will be rejected.\n */\nexport class FlushLock {\n #flushSecret: number = 0;\n #isFlushing: boolean = false;\n\n /** This will begin any non-hook restrictions on writing to entities. */\n startLock(): void {\n if (this.#isFlushing) {\n throw new Error(\"Cannot flush while another flush is already in progress\");\n }\n this.#isFlushing = true;\n }\n\n releaseLock(): void {\n this.#isFlushing = false;\n }\n\n /** Any writes that happen from `fn`, despite flush being locked, will be allowed. */\n allowWrites(fn: () => Promise<void>): Promise<void> {\n return currentFlushSecret.run({ flushSecret: this.#flushSecret }, () =>\n fn().then(() => {\n this.#flushSecret += 1;\n }),\n );\n }\n\n /** Blows up if writes are locked, i.e. we're flushing and the caller is not within an `allowWrites` block. */\n checkWritesAllowed(): void {\n if (this.#isFlushing) {\n const { flushSecret } = currentFlushSecret.getStore() || {};\n if (flushSecret === undefined) {\n throw new Error(`Cannot mutate an entity during an em.flush outside of a entity hook or from afterCommit`);\n } else if (flushSecret !== this.#flushSecret) {\n throw new Error(`Attempting to reuse a hook context outside its flush loop`);\n }\n }\n }\n\n get isFlushing(): boolean {\n return this.#isFlushing;\n }\n}\n"],"mappings":";;;AAGA,MAAM,qBAAqB,0BAAIA,EAAAA,CAAAA,kBAA2C;;;;;;;;;;;;;;;AAgB1E,IAAa,YAAb,MAAuB;CACrB,eAAuB;CACvB,cAAuB;;CAGvB,YAAkB;EAChB,IAAI,KAAK,aACP,MAAM,IAAI,MAAM,yDAAyD;EAE3E,KAAK,cAAc;CACrB;CAEA,cAAoB;EAClB,KAAK,cAAc;CACrB;;CAGA,YAAY,IAAwC;EAClD,OAAO,mBAAmB,IAAI,EAAE,aAAa,KAAK,aAAa,SAC7D,GAAG,CAAC,CAAC,WAAW;GACd,KAAK,gBAAgB;EACvB,CAAC,CACH;CACF;;CAGA,qBAA2B;EACzB,IAAI,KAAK,aAAa;GACpB,MAAM,EAAE,gBAAgB,mBAAmB,SAAS,KAAK,CAAC;GAC1D,IAAI,gBAAgB,KAAA,GAClB,MAAM,IAAI,MAAM,yFAAyF;QACpG,IAAI,gBAAgB,KAAK,cAC9B,MAAM,IAAI,MAAM,2DAA2D;EAE/E;CACF;CAEA,IAAI,aAAsB;EACxB,OAAO,KAAK;CACd;AACF"}
@@ -13,7 +13,7 @@
13
13
  * handlers) as blessed / invoked-from-`flush`-itself, and they are allowed to call setters,
14
14
  * but any external callers (i.e. application code) will be rejected.
15
15
  */
16
- declare class FlushLock {
16
+ export declare class FlushLock {
17
17
  #private;
18
18
  /** This will begin any non-hook restrictions on writing to entities. */
19
19
  startLock(): void;
@@ -25,5 +25,4 @@ declare class FlushLock {
25
25
  get isFlushing(): boolean;
26
26
  }
27
27
  //#endregion
28
- export { FlushLock };
29
28
  //# sourceMappingURL=FlushLock.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FlushLock.d.cts","names":[],"sources":["../../src/flush/FlushLock.ts"],"mappings":";;;;;;;;;;;;;;;cAmBa;;;EAKX;EAOA;;EAKA,YAAY,UAAU,gBAAgB;;EAStC;MAWI"}
1
+ {"version":3,"file":"FlushLock.d.cts","names":[],"sources":["../../src/flush/FlushLock.ts"],"mappings":";;;;;;;;;;;;;;;qBAmBa;;;EAKX;EAOA;;EAKA,YAAY,UAAU,gBAAgB;;EAStC;MAWI"}
@@ -13,7 +13,7 @@
13
13
  * handlers) as blessed / invoked-from-`flush`-itself, and they are allowed to call setters,
14
14
  * but any external callers (i.e. application code) will be rejected.
15
15
  */
16
- declare class FlushLock {
16
+ export declare class FlushLock {
17
17
  #private;
18
18
  /** This will begin any non-hook restrictions on writing to entities. */
19
19
  startLock(): void;
@@ -25,5 +25,4 @@ declare class FlushLock {
25
25
  get isFlushing(): boolean;
26
26
  }
27
27
  //#endregion
28
- export { FlushLock };
29
28
  //# sourceMappingURL=FlushLock.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FlushLock.d.mts","names":[],"sources":["../../src/flush/FlushLock.ts"],"mappings":";;;;;;;;;;;;;;;cAmBa;;;EAKX;EAOA;;EAKA,YAAY,UAAU,gBAAgB;;EAStC;MAWI"}
1
+ {"version":3,"file":"FlushLock.d.mts","names":[],"sources":["../../src/flush/FlushLock.ts"],"mappings":";;;;;;;;;;;;;;;qBAmBa;;;EAKX;EAOA;;EAKA,YAAY,UAAU,gBAAgB;;EAStC;MAWI"}
@@ -1 +1 @@
1
- {"version":3,"file":"FlushLock.js","names":["#isFlushing","#flushSecret"],"sources":["../../src/flush/FlushLock.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"async_hooks\";\n\n/** A marker to prevent setter calls during `flush` calls. */\nconst currentFlushSecret = new AsyncLocalStorage<{ flushSecret: number }>();\n\n/**\n * Prevents entities being mutated mid-flush.\n *\n * The `flush` process does a dirty check + SQL flush and generally doesn't want\n * entities to re-dirtied after it's done the initial dirty check. So we'd like\n * to prevent all setter calls while `flush` is running.\n *\n * That said, lifecycle code like hooks actually can make setter calls b/c `flush`\n * invokes them at a specific point in its process.\n *\n * We solve this by using node's `AsyncLocalStorage` to mark certain callbacks (promise\n * handlers) as blessed / invoked-from-`flush`-itself, and they are allowed to call setters,\n * but any external callers (i.e. application code) will be rejected.\n */\nexport class FlushLock {\n #flushSecret: number = 0;\n #isFlushing: boolean = false;\n\n /** This will begin any non-hook restrictions on writing to entities. */\n startLock(): void {\n if (this.#isFlushing) {\n throw new Error(\"Cannot flush while another flush is already in progress\");\n }\n this.#isFlushing = true;\n }\n\n releaseLock(): void {\n this.#isFlushing = false;\n }\n\n /** Any writes that happen from `fn`, despite flush being locked, will be allowed. */\n allowWrites(fn: () => Promise<void>): Promise<void> {\n return currentFlushSecret.run({ flushSecret: this.#flushSecret }, () =>\n fn().then(() => {\n this.#flushSecret += 1;\n }),\n );\n }\n\n /** Blows up if writes are locked, i.e. we're flushing and the caller is not within an `allowWrites` block. */\n checkWritesAllowed(): void {\n if (this.#isFlushing) {\n const { flushSecret } = currentFlushSecret.getStore() || {};\n if (flushSecret === undefined) {\n throw new Error(`Cannot mutate an entity during an em.flush outside of a entity hook or from afterCommit`);\n } else if (flushSecret !== this.#flushSecret) {\n throw new Error(`Attempting to reuse a hook context outside its flush loop`);\n }\n }\n }\n\n get isFlushing(): boolean {\n return this.#isFlushing;\n }\n}\n"],"mappings":";;;AAGA,MAAM,qBAAqB,IAAI,kBAA2C;;;;;;;;;;;;;;;AAgB1E,IAAa,YAAb,MAAuB;CACrB,eAAuB;CACvB,cAAuB;;CAGvB,YAAkB;EAChB,IAAI,KAAKA,aACP,MAAM,IAAI,MAAM,yDAAyD;EAE3E,KAAKA,cAAc;CACrB;CAEA,cAAoB;EAClB,KAAKA,cAAc;CACrB;;CAGA,YAAY,IAAwC;EAClD,OAAO,mBAAmB,IAAI,EAAE,aAAa,KAAKC,aAAa,SAC7D,GAAG,CAAC,CAAC,WAAW;GACd,KAAKA,gBAAgB;EACvB,CAAC,CACH;CACF;;CAGA,qBAA2B;EACzB,IAAI,KAAKD,aAAa;GACpB,MAAM,EAAE,gBAAgB,mBAAmB,SAAS,KAAK,CAAC;GAC1D,IAAI,gBAAgB,KAAA,GAClB,MAAM,IAAI,MAAM,yFAAyF;QACpG,IAAI,gBAAgB,KAAKC,cAC9B,MAAM,IAAI,MAAM,2DAA2D;EAE/E;CACF;CAEA,IAAI,aAAsB;EACxB,OAAO,KAAKD;CACd;AACF"}
1
+ {"version":3,"file":"FlushLock.js","names":[],"sources":["../../src/flush/FlushLock.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"async_hooks\";\n\n/** A marker to prevent setter calls during `flush` calls. */\nconst currentFlushSecret = new AsyncLocalStorage<{ flushSecret: number }>();\n\n/**\n * Prevents entities being mutated mid-flush.\n *\n * The `flush` process does a dirty check + SQL flush and generally doesn't want\n * entities to re-dirtied after it's done the initial dirty check. So we'd like\n * to prevent all setter calls while `flush` is running.\n *\n * That said, lifecycle code like hooks actually can make setter calls b/c `flush`\n * invokes them at a specific point in its process.\n *\n * We solve this by using node's `AsyncLocalStorage` to mark certain callbacks (promise\n * handlers) as blessed / invoked-from-`flush`-itself, and they are allowed to call setters,\n * but any external callers (i.e. application code) will be rejected.\n */\nexport class FlushLock {\n #flushSecret: number = 0;\n #isFlushing: boolean = false;\n\n /** This will begin any non-hook restrictions on writing to entities. */\n startLock(): void {\n if (this.#isFlushing) {\n throw new Error(\"Cannot flush while another flush is already in progress\");\n }\n this.#isFlushing = true;\n }\n\n releaseLock(): void {\n this.#isFlushing = false;\n }\n\n /** Any writes that happen from `fn`, despite flush being locked, will be allowed. */\n allowWrites(fn: () => Promise<void>): Promise<void> {\n return currentFlushSecret.run({ flushSecret: this.#flushSecret }, () =>\n fn().then(() => {\n this.#flushSecret += 1;\n }),\n );\n }\n\n /** Blows up if writes are locked, i.e. we're flushing and the caller is not within an `allowWrites` block. */\n checkWritesAllowed(): void {\n if (this.#isFlushing) {\n const { flushSecret } = currentFlushSecret.getStore() || {};\n if (flushSecret === undefined) {\n throw new Error(`Cannot mutate an entity during an em.flush outside of a entity hook or from afterCommit`);\n } else if (flushSecret !== this.#flushSecret) {\n throw new Error(`Attempting to reuse a hook context outside its flush loop`);\n }\n }\n }\n\n get isFlushing(): boolean {\n return this.#isFlushing;\n }\n}\n"],"mappings":";;;AAGA,MAAM,qBAAqB,IAAI,kBAA2C;;;;;;;;;;;;;;;AAgB1E,IAAa,YAAb,MAAuB;CACrB,eAAuB;CACvB,cAAuB;;CAGvB,YAAkB;EAChB,IAAI,KAAK,aACP,MAAM,IAAI,MAAM,yDAAyD;EAE3E,KAAK,cAAc;CACrB;CAEA,cAAoB;EAClB,KAAK,cAAc;CACrB;;CAGA,YAAY,IAAwC;EAClD,OAAO,mBAAmB,IAAI,EAAE,aAAa,KAAK,aAAa,SAC7D,GAAG,CAAC,CAAC,WAAW;GACd,KAAK,gBAAgB;EACvB,CAAC,CACH;CACF;;CAGA,qBAA2B;EACzB,IAAI,KAAK,aAAa;GACpB,MAAM,EAAE,gBAAgB,mBAAmB,SAAS,KAAK,CAAC;GAC1D,IAAI,gBAAgB,KAAA,GAClB,MAAM,IAAI,MAAM,yFAAyF;QACpG,IAAI,gBAAgB,KAAK,cAC9B,MAAM,IAAI,MAAM,2DAA2D;EAE/E;CACF;CAEA,IAAI,aAAsB;EACxB,OAAO,KAAK;CACd;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"JoinRows.cjs","names":["#reactToChange","keyToTaggedId","#dbValue","keyToNumber","getEmInternalApi","getBaseAndSelfMetas","#doAdd","#doRemove"],"sources":["../../src/flush/JoinRows.ts"],"sourcesContent":["import type { Entity } from \"src/Entity.ts\";\nimport { getEmInternalApi } from \"src/EntityManager.ts\";\nimport { type EntityMetadata, getBaseAndSelfMetas } from \"src/EntityMetadata.ts\";\nimport type { EnumMetadata } from \"src/EnumMetadata.ts\";\nimport type { JoinRowTodo } from \"src/flush/Todo.ts\";\nimport { keyToNumber, keyToTaggedId } from \"src/keys.ts\";\nimport type { ReactionsManager } from \"src/reactivity/ReactionsManager.ts\";\nimport { remove } from \"src/utils.ts\";\n\n/**\n * A simplified interface for ManyToManyCollection-like relations.\n *\n * Specifically lets ReactiveManyToMany & ReactiveManyToManyOtherSide use JoinRows\n * as if they were full-fledged m2m relations.\n *\n * The \"other\" side of the join table is usually a second entity, but for `EnumCollection`s\n * (i.e. `Publisher.logoColors`) it is an enum table; in that case `otherEnum` is set and the\n * other column's value is the enum's numeric id rather than an `Entity` (there is also no\n * `otherMeta`/`otherFieldName`, since enums have no reverse collection to keep in sync).\n */\nexport type ManyToManyLike = {\n entity: Entity;\n joinTableName: string;\n columnName: string;\n otherColumnName: string;\n fieldName: string;\n meta: EntityMetadata;\n /** Undefined when the other side is an enum. */\n otherFieldName?: string;\n /** Undefined when the other side is an enum. */\n otherMeta?: EntityMetadata;\n /** Set when the other side is an enum table, for mapping enum codes <-> their numeric ids. */\n otherEnum?: EnumMetadata<any, any, number>;\n /** Whether the join table has a surrogate `id` PK; if false the FK pair is the composite PK. */\n hasJoinTableId: boolean;\n};\n\n/** The value of a join row's column: an `Entity`, or an enum's numeric id for `EnumCollection`s. */\nexport type JoinColumnValue = Entity | number;\n\n/** Whether a join column points at a not-yet-inserted entity (enum ids are never \"new\"). */\nfunction isNewColumn(value: JoinColumnValue): boolean {\n return typeof value !== \"number\" && value.isNewEntity;\n}\n\n/** A small holder around m2m join rows, which we treat as psuedo-entities. */\nexport class JoinRows {\n // The in-memory rows for our m2m table.\n private readonly rows: JoinRow[] = [];\n private readonly index: ManyToManyIndex;\n\n constructor(\n // This could be either side of the m2m relation, depending on which is accessed first.\n // Regardless of which m2m side, we still have a single `JoinRows` instance in memory per m2m table.\n readonly m2m: ManyToManyLike,\n private rm: ReactionsManager,\n ) {\n this.index = new ManyToManyIndex(m2m);\n }\n\n /** Adds a new join row to this table. */\n addNew(m2m: ManyToManyLike, e1: Entity, e2: JoinColumnValue): void {\n if (!e1) throw new Error(`Cannot add a m2m row with an entity that is ${e1}`);\n if (!e2) throw new Error(`Cannot add a m2m row with an entity that is ${e2}`);\n const existing = this.index.get(m2m, e1, e2);\n if (existing) {\n existing.deleted = false;\n existing.op = JoinRowOperation.Pending;\n } else {\n const row = {\n op: JoinRowOperation.Pending,\n id: undefined,\n persisted: false,\n columns: { [m2m.columnName]: e1, [m2m.otherColumnName]: e2 },\n } satisfies JoinRow;\n this.rows.push(row);\n this.index.add(m2m, e1, e2, row);\n }\n this.#reactToChange(m2m, e1, e2);\n }\n\n /** Adds a new remove to this table. */\n addRemove(m2m: ManyToManyLike, e1: Entity, e2: JoinColumnValue): void {\n const existing = this.index.get(m2m, e1, e2);\n if (existing) {\n if (!existing.persisted) {\n // It was only added in-memory and never persisted, so just drop it\n remove(this.rows, existing);\n this.index.remove(existing);\n } else {\n existing.deleted = true;\n }\n existing.op = JoinRowOperation.Pending;\n } else {\n // We're removing against an unloaded collection, so assume the row exists in the database\n // (persisted: true) and queue a delete; the delete keys off the (col1, col2) composite.\n const row = {\n op: JoinRowOperation.Pending,\n id: undefined,\n persisted: true,\n columns: { [m2m.columnName]: e1, [m2m.otherColumnName]: e2 },\n deleted: true,\n } satisfies JoinRow;\n this.rows.push(row);\n this.index.add(m2m, e1, e2, row);\n }\n this.#reactToChange(m2m, e1, e2);\n }\n\n /** Return any \"old values\" for a m2m collection that might need reactivity checks. */\n removedFor(m2m: ManyToManyLike, e1: Entity): JoinColumnValue[] {\n const { otherColumnName } = m2m;\n // I.e. if we did `t1.books.remove(b1)` find all join rows that have\n // `tag_id=t1`, are marked for deletion, and then `.map` them to the removed book.\n const removedRows = this.index.getOthers(m2m.columnName, e1).filter((r) => r.deleted);\n return removedRows.map((r) => r.columns[otherColumnName]);\n }\n\n addedFor(m2m: ManyToManyLike, e1: Entity): JoinColumnValue[] {\n const { otherColumnName } = m2m;\n const addedRows = this.index\n .getOthers(m2m.columnName, e1)\n .filter(\n (r) =>\n ((!r.persisted && r.op === JoinRowOperation.Pending) || r.op === JoinRowOperation.Flushed) &&\n r.deleted !== true,\n );\n return addedRows.map((r) => r.columns[otherColumnName]);\n }\n\n /** Adds an existing join row to this table. */\n addPreloadedRow(m2m: ManyToManyLike, id: number | undefined, e1: Entity, e2: JoinColumnValue): void {\n const existing = this.index.get(m2m, e1, e2);\n if (existing) {\n // Treat any existing WIP change as source-of-truth, so leave it alone\n } else {\n const row = {\n op: JoinRowOperation.Pending,\n id,\n persisted: true,\n columns: { [m2m.columnName]: e1, [m2m.otherColumnName]: e2 },\n } satisfies JoinRow;\n this.rows.push(row);\n this.index.add(m2m, e1, e2, row);\n }\n }\n\n /** Look up/create our internal JoinRow psuedo-entities for the db rows. */\n async loadRows(tuples: [string, string][], dbRows: any[]): Promise<void> {\n const { em } = this.m2m.entity;\n const { columnName: column1, otherColumnName: column2, meta: meta1, otherMeta: meta2, otherEnum } = this.m2m;\n\n const oneIds: string[] = [];\n // Tagged ids for an entity other-side, or raw enum ids for an enum other-side.\n const twoVals: JoinColumnValue[] = [];\n for (const dbRow of dbRows) {\n oneIds.push(keyToTaggedId(meta1, dbRow[column1])!);\n twoVals.push(\n otherEnum ? (dbRow[column2] as number) : (em.getEntity(keyToTaggedId(meta2!, dbRow[column2])!) as any),\n );\n }\n\n // Make sure we have entities in memory for all the joined-to tables. The enum side has no\n // entities to load; the entity sides do (and `twoVals` is re-resolved to entities below).\n await Promise.all([\n em.loadAll(meta1.cstr, oneIds),\n otherEnum\n ? Promise.resolve([])\n : em.loadAll(\n meta2!.cstr,\n dbRows.map((dbRow) => keyToTaggedId(meta2!, dbRow[column2])!),\n ),\n ]);\n\n // If we're doing a em.refresh/reload, we need to watch for rows that are no longer here. For an\n // enum other-side, only persisted rows are delete-candidates (pending in-memory adds are kept,\n // since `EnumCollection` relies on `JoinRows` to hold them rather than re-asserting on load).\n const existingRows = new Set<JoinRow>();\n for (const [columnName, id] of tuples) {\n const others = this.index.getOthers(columnName, em.getEntity(id)!);\n for (const row of others) if (!otherEnum || row.persisted) existingRows.add(row);\n }\n\n let i = 0;\n for (const dbRow of dbRows) {\n const e1 = em.getEntity(oneIds[i])!;\n const e2 = otherEnum ? (dbRow[column2] as number) : em.getEntity(keyToTaggedId(meta2!, dbRow[column2])!)!;\n i++;\n let row = this.index.get(this.m2m, e1, e2);\n if (!row) {\n row = {\n op: JoinRowOperation.Completed,\n id: dbRow.id,\n persisted: true,\n columns: { [column1]: e1, [column2]: e2 },\n created_at: dbRow.created_at,\n };\n this.rows.push(row);\n this.index.add(this.m2m, e1, e2, row);\n } else {\n // If a placeholder row was created while a ManyToManyCollection was unloaded, and we find it during\n // a subsequent load/query, update its id to be what is in the database and mark it persisted.\n row.id = dbRow.id;\n row.persisted = true;\n // Mark this row as still valid\n existingRows.delete(row);\n }\n }\n\n // Mark all no-longer-there rows as deleted\n for (const row of existingRows) row.deleted = true;\n }\n\n getOthers(columnName: string, entity: Entity): JoinColumnValue[] {\n const others = this.index.getOthers(columnName, entity);\n if (others.length === 0) return [];\n const [c1, c2] = Object.keys(others[0].columns);\n const c = others[0].columns[c1] === entity ? c2 : c1;\n return others.filter((o) => !o.deleted).map((row) => row.columns[c]);\n }\n\n /** Drops all in-memory rows where `entity` is on `columnName`, e.g. when it is being deleted. */\n removeAllFor(columnName: string, entity: Entity): void {\n for (const row of this.index.getOthers(columnName, entity)) {\n remove(this.rows, row);\n this.index.remove(row);\n }\n }\n\n /** Drops a single `(e1, e2)` row without queuing a flush, e.g. when mirroring another em's removal. */\n removePreloadedRow(m2m: ManyToManyLike, e1: Entity, e2: JoinColumnValue): void {\n const row = this.index.get(m2m, e1, e2);\n if (row) {\n remove(this.rows, row);\n this.index.remove(row);\n }\n }\n\n /** Scans our `rows` for newly-added/newly-deleted rows that need `INSERT`s/`UPDATE`s. */\n toTodo(): JoinRowTodo | undefined {\n const newRows = this.rows.filter((r) => !r.persisted && r.deleted !== true && r.op === \"pending\");\n const deletedRows = this.rows.filter((r) => r.persisted && r.deleted === true && r.op === \"pending\");\n if (newRows.length === 0 && deletedRows.length === 0) {\n return undefined;\n }\n return {\n m2m: this.m2m,\n newRows,\n deletedRows,\n resetAfterFlushed: () => {\n for (const row of this.rows) {\n if (row.op === JoinRowOperation.Pending || row.op === JoinRowOperation.Flushed)\n row.op = JoinRowOperation.Completed;\n }\n },\n // The driver flushes pure (int, int) FK pairs; resolve them here so it never has to know\n // whether a column points at an entity (use its id) or an enum (its value is already the id).\n dbValue: (row, columnName) => this.#dbValue(row, columnName),\n isNew: (row, columnName) => isNewColumn(row.columns[columnName]),\n };\n }\n\n get hasChanges() {\n return this.rows.some(({ op }) => op === JoinRowOperation.Pending || op === JoinRowOperation.Flushed);\n }\n\n /** The db int value for `row`'s `columnName`: an entity's id, or (for enums) the enum's id itself. */\n #dbValue(row: JoinRow, columnName: string): number {\n const value = row.columns[columnName];\n if (typeof value === \"number\") return value;\n const meta = columnName === this.m2m.columnName ? this.m2m.meta : this.m2m.otherMeta!;\n return keyToNumber(meta, value.idTagged)!;\n }\n\n /**\n * Invalidates caches & queues reactivity for a join-row change.\n *\n * The owning entity (`e1`) always reacts; the \"other\" side only reacts when it is an entity,\n * since enum other-sides have no `em`/reverse-field to keep in sync.\n */\n #reactToChange(m2m: ManyToManyLike, e1: Entity, e2: JoinColumnValue): void {\n const { em } = this.m2m.entity;\n const api = getEmInternalApi(e1.em);\n api.isLoadedCache.resetIsLoaded(e1, m2m.fieldName);\n this.rm.queueDownstreamReactables(e1, m2m.fieldName);\n if (getBaseAndSelfMetas(e1).some((meta) => meta.config.__data.touchOnChange.has(m2m.fieldName))) {\n em.touch(e1);\n }\n if (!m2m.otherEnum) {\n const other = e2 as Entity;\n const otherFieldName = m2m.otherFieldName!;\n api.isLoadedCache.resetIsLoaded(other, otherFieldName);\n this.rm.queueDownstreamReactables(other, otherFieldName);\n if (getBaseAndSelfMetas(other).some((meta) => meta.config.__data.touchOnChange.has(otherFieldName))) {\n em.touch(other);\n }\n }\n }\n}\n\n/**\n * A \"psuedo-entity\" for a join row.\n *\n * We treat this as a special entity, i.e. it has two \"relations\" to each entity for the current\n * row, an optional surrogate `id` primary key, and an optional `created_at` column.\n *\n * These rows are immutable, i.e. once created we don't change either FK, and instead make\n * collection changes only by inserting new rows and deleting old rows.\n *\n * This makes the column1+column2 combination a composite key. For id-less join tables, that\n * composite is the actual primary key and `id` is always undefined.\n */\nexport interface JoinRow {\n /**\n * Whether our relation has been processed or not.\n *\n * - `pending` means we've not flushed it to the Database\n * - `flushed` means we've flushed but `em.flush` hasn't fully completed yet, likely due to AsyncReactiveField calcs\n * - `completed` means we've been flushed and `em.flush` has completed\n */\n op: JoinRowOperation;\n /** The surrogate key for id-ful join tables; always undefined for id-less tables. */\n id: number | undefined;\n /**\n * Whether this row exists (or is assumed to exist) in the database.\n *\n * This is orthogonal to `op` (the flush lifecycle) and is what distinguishes a pending insert\n * from a pending delete: a `pending` row that is `!persisted` is a pending INSERT (added in\n * memory, not yet in the db), while a `pending` row that is `persisted` is a pending DELETE\n * (in the db, marked `deleted`). `op` alone cannot tell these apart, because both inserts and\n * deletes walk the same `pending -> flushed -> completed` progression.\n *\n * We track this as its own flag rather than inferring it from `id` being set/unset, because\n * id-less join tables (whose PK is just the composite of the two FKs) never have an `id` — so\n * `id === undefined` would be ambiguous. `persisted` is the id-agnostic generalization of the\n * `id`-is-set check that id-ful tables historically relied on.\n *\n * It must survive add/remove/re-add sequences: e.g. loading a row (persisted), removing it\n * (pending delete), then re-adding it (`deleted` flipped back to false, `op` back to `pending`)\n * leaves a `pending && !deleted` row that looks identical to a fresh insert — but it is still in\n * the db, so a subsequent remove must issue a DELETE, which only `persisted` can tell us.\n */\n persisted: boolean;\n /** Maps each FK column to its value: an `Entity`, or (for `EnumCollection`s) an enum's numeric id. */\n columns: Record<string, JoinColumnValue>;\n created_at?: Date;\n deleted?: boolean;\n}\n\n/** An enum to track our insert/delete state progression. */\nexport enum JoinRowOperation {\n Pending = \"pending\",\n Flushed = \"flushed\",\n Completed = \"completed\",\n}\n\n/** Keep an in-memory index to avoid sequentially scanning `rows`. */\nclass ManyToManyIndex {\n private indexes: Record<string, Map<JoinColumnValue, Map<JoinColumnValue, JoinRow>>> = {};\n\n constructor(private readonly m2m: ManyToManyLike) {\n this.indexes[m2m.columnName] = new Map();\n this.indexes[m2m.otherColumnName] = new Map();\n }\n\n add(m2m: ManyToManyLike, e1: JoinColumnValue, e2: JoinColumnValue, value: JoinRow): void {\n // Store both e1+e2 => value and e2+e1 => value so we can do lookups from either side\n this.#doAdd(this.indexes[m2m.columnName], e1, e2, value);\n this.#doAdd(this.indexes[m2m.otherColumnName], e2, e1, value);\n }\n\n remove(value: JoinRow): void {\n const [[column1, e1], [column2, e2]] = Object.entries(value.columns);\n this.#doRemove(this.indexes[column1], e1, e2);\n this.#doRemove(this.indexes[column2], e2, e1);\n }\n\n get(m2m: ManyToManyLike, e1: JoinColumnValue, e2: JoinColumnValue): JoinRow | undefined {\n return this.indexes[m2m.columnName].get(e1)?.get(e2);\n }\n\n /** Cheat and use the index to return \"the other entities\" for `entity`. */\n getOthers(columnName: string, entity: JoinColumnValue): JoinRow[] {\n // It's empty m2m collection won't have any other entities, and so no index entries\n const map = this.indexes[columnName].get(entity);\n if (!map) return [];\n // Sort for a stable order regardless of how many batches contributed rows — the underlying\n // Map preserves insertion order, which depends on DataLoader timing and is non-deterministic\n // across processes. New rows (no key yet) sort last.\n const rows = Array.from(map.values());\n if (this.m2m.hasJoinTableId) {\n // Sort by join-row id.\n return rows.sort((a, b) => (a.id ?? Infinity) - (b.id ?? Infinity));\n }\n // Id-less tables have no surrogate id, so sort by the other side's id.\n const otherColumn = columnName === this.m2m.columnName ? this.m2m.otherColumnName : this.m2m.columnName;\n if (this.m2m.otherEnum && otherColumn === this.m2m.otherColumnName) {\n // The other side is an enum, so its column value is already its numeric id.\n return rows.sort((a, b) => (a.columns[otherColumn] as number) - (b.columns[otherColumn] as number));\n }\n const otherMeta = columnName === this.m2m.columnName ? this.m2m.otherMeta! : this.m2m.meta;\n const key = (r: JoinRow) => {\n const other = r.columns[otherColumn] as Entity;\n return other.isNewEntity ? Infinity : keyToNumber(otherMeta, other.id)!;\n };\n return rows.sort((a, b) => key(a) - key(b));\n }\n\n #doAdd(\n index: Map<JoinColumnValue, Map<JoinColumnValue, JoinRow>>,\n e1: JoinColumnValue,\n e2: JoinColumnValue,\n value: JoinRow,\n ): void {\n const map = index.get(e1) ?? new Map();\n if (map.size === 0) index.set(e1, map);\n map.set(e2, value);\n }\n\n #doRemove(\n index: Map<JoinColumnValue, Map<JoinColumnValue, JoinRow>>,\n e1: JoinColumnValue,\n e2: JoinColumnValue,\n ): void {\n index.get(e1)?.delete(e2);\n }\n}\n"],"mappings":";;;;;;;AAyCA,SAAS,YAAY,OAAiC;CACpD,OAAO,OAAO,UAAU,YAAY,MAAM;AAC5C;;AAGA,IAAa,WAAb,MAAsB;CAQT;CACD;CAPV,OAAmC,CAAC;CACpC;CAEA,YAGE,KACA,IACA;EAFS,KAAA,MAAA;EACD,KAAA,KAAA;EAER,KAAK,QAAQ,IAAI,gBAAgB,GAAG;CACtC;;CAGA,OAAO,KAAqB,IAAY,IAA2B;EACjE,IAAI,CAAC,IAAI,MAAM,IAAI,MAAM,+CAA+C,IAAI;EAC5E,IAAI,CAAC,IAAI,MAAM,IAAI,MAAM,+CAA+C,IAAI;EAC5E,MAAM,WAAW,KAAK,MAAM,IAAI,KAAK,IAAI,EAAE;EAC3C,IAAI,UAAU;GACZ,SAAS,UAAU;GACnB,SAAS,KAAA;EACX,OAAO;GACL,MAAM,MAAM;IACV,IAAA;IACA,IAAI,KAAA;IACJ,WAAW;IACX,SAAS;MAAG,IAAI,aAAa;MAAK,IAAI,kBAAkB;IAAG;GAC7D;GACA,KAAK,KAAK,KAAK,GAAG;GAClB,KAAK,MAAM,IAAI,KAAK,IAAI,IAAI,GAAG;EACjC;EACA,KAAKA,eAAe,KAAK,IAAI,EAAE;CACjC;;CAGA,UAAU,KAAqB,IAAY,IAA2B;EACpE,MAAM,WAAW,KAAK,MAAM,IAAI,KAAK,IAAI,EAAE;EAC3C,IAAI,UAAU;GACZ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Q,EAAE,QAAQ;GACxB,OAAO,MAAM,cAAc,WAAWJ,aAAAA,YAAY,WAAW,MAAM,EAAE;EACvE;EACA,OAAO,KAAK,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC;CAC5C;CAEA,OACE,OACA,IACA,IACA,OACM;EACN,MAAM,MAAM,MAAM,IAAI,EAAE,qBAAK,IAAI,IAAI;EACrC,IAAI,IAAI,SAAS,GAAG,MAAM,IAAI,IAAI,GAAG;EACrC,IAAI,IAAI,IAAI,KAAK;CACnB;CAEA,UACE,OACA,IACA,IACM;EACN,MAAM,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE;CAC1B;AACF"}
1
+ {"version":3,"file":"JoinRows.cjs","names":["keyToTaggedId","keyToNumber","getEmInternalApi","getBaseAndSelfMetas"],"sources":["../../src/flush/JoinRows.ts"],"sourcesContent":["import type { Entity } from \"src/Entity.ts\";\nimport { getEmInternalApi } from \"src/EntityManager.ts\";\nimport { type EntityMetadata, getBaseAndSelfMetas } from \"src/EntityMetadata.ts\";\nimport type { EnumMetadata } from \"src/EnumMetadata.ts\";\nimport type { JoinRowTodo } from \"src/flush/Todo.ts\";\nimport { keyToNumber, keyToTaggedId } from \"src/keys.ts\";\nimport type { ReactionsManager } from \"src/reactivity/ReactionsManager.ts\";\nimport { remove } from \"src/utils.ts\";\n\n/**\n * A simplified interface for ManyToManyCollection-like relations.\n *\n * Specifically lets ReactiveManyToMany & ReactiveManyToManyOtherSide use JoinRows\n * as if they were full-fledged m2m relations.\n *\n * The \"other\" side of the join table is usually a second entity, but for `EnumCollection`s\n * (i.e. `Publisher.logoColors`) it is an enum table; in that case `otherEnum` is set and the\n * other column's value is the enum's numeric id rather than an `Entity` (there is also no\n * `otherMeta`/`otherFieldName`, since enums have no reverse collection to keep in sync).\n */\nexport type ManyToManyLike = {\n entity: Entity;\n joinTableName: string;\n columnName: string;\n otherColumnName: string;\n fieldName: string;\n meta: EntityMetadata;\n /** Undefined when the other side is an enum. */\n otherFieldName?: string;\n /** Undefined when the other side is an enum. */\n otherMeta?: EntityMetadata;\n /** Set when the other side is an enum table, for mapping enum codes <-> their numeric ids. */\n otherEnum?: EnumMetadata<any, any, number>;\n /** Whether the join table has a surrogate `id` PK; if false the FK pair is the composite PK. */\n hasJoinTableId: boolean;\n};\n\n/** The value of a join row's column: an `Entity`, or an enum's numeric id for `EnumCollection`s. */\nexport type JoinColumnValue = Entity | number;\n\n/** Whether a join column points at a not-yet-inserted entity (enum ids are never \"new\"). */\nfunction isNewColumn(value: JoinColumnValue): boolean {\n return typeof value !== \"number\" && value.isNewEntity;\n}\n\n/** A small holder around m2m join rows, which we treat as psuedo-entities. */\nexport class JoinRows {\n // The in-memory rows for our m2m table.\n private readonly rows: JoinRow[] = [];\n private readonly index: ManyToManyIndex;\n\n constructor(\n // This could be either side of the m2m relation, depending on which is accessed first.\n // Regardless of which m2m side, we still have a single `JoinRows` instance in memory per m2m table.\n readonly m2m: ManyToManyLike,\n private rm: ReactionsManager,\n ) {\n this.index = new ManyToManyIndex(m2m);\n }\n\n /** Adds a new join row to this table. */\n addNew(m2m: ManyToManyLike, e1: Entity, e2: JoinColumnValue): void {\n if (!e1) throw new Error(`Cannot add a m2m row with an entity that is ${e1}`);\n if (!e2) throw new Error(`Cannot add a m2m row with an entity that is ${e2}`);\n const existing = this.index.get(m2m, e1, e2);\n if (existing) {\n existing.deleted = false;\n existing.op = JoinRowOperation.Pending;\n } else {\n const row = {\n op: JoinRowOperation.Pending,\n id: undefined,\n persisted: false,\n columns: { [m2m.columnName]: e1, [m2m.otherColumnName]: e2 },\n } satisfies JoinRow;\n this.rows.push(row);\n this.index.add(m2m, e1, e2, row);\n }\n this.#reactToChange(m2m, e1, e2);\n }\n\n /** Adds a new remove to this table. */\n addRemove(m2m: ManyToManyLike, e1: Entity, e2: JoinColumnValue): void {\n const existing = this.index.get(m2m, e1, e2);\n if (existing) {\n if (!existing.persisted) {\n // It was only added in-memory and never persisted, so just drop it\n remove(this.rows, existing);\n this.index.remove(existing);\n } else {\n existing.deleted = true;\n }\n existing.op = JoinRowOperation.Pending;\n } else {\n // We're removing against an unloaded collection, so assume the row exists in the database\n // (persisted: true) and queue a delete; the delete keys off the (col1, col2) composite.\n const row = {\n op: JoinRowOperation.Pending,\n id: undefined,\n persisted: true,\n columns: { [m2m.columnName]: e1, [m2m.otherColumnName]: e2 },\n deleted: true,\n } satisfies JoinRow;\n this.rows.push(row);\n this.index.add(m2m, e1, e2, row);\n }\n this.#reactToChange(m2m, e1, e2);\n }\n\n /** Return any \"old values\" for a m2m collection that might need reactivity checks. */\n removedFor(m2m: ManyToManyLike, e1: Entity): JoinColumnValue[] {\n const { otherColumnName } = m2m;\n // I.e. if we did `t1.books.remove(b1)` find all join rows that have\n // `tag_id=t1`, are marked for deletion, and then `.map` them to the removed book.\n const removedRows = this.index.getOthers(m2m.columnName, e1).filter((r) => r.deleted);\n return removedRows.map((r) => r.columns[otherColumnName]);\n }\n\n addedFor(m2m: ManyToManyLike, e1: Entity): JoinColumnValue[] {\n const { otherColumnName } = m2m;\n const addedRows = this.index\n .getOthers(m2m.columnName, e1)\n .filter(\n (r) =>\n ((!r.persisted && r.op === JoinRowOperation.Pending) || r.op === JoinRowOperation.Flushed) &&\n r.deleted !== true,\n );\n return addedRows.map((r) => r.columns[otherColumnName]);\n }\n\n /** Adds an existing join row to this table. */\n addPreloadedRow(m2m: ManyToManyLike, id: number | undefined, e1: Entity, e2: JoinColumnValue): void {\n const existing = this.index.get(m2m, e1, e2);\n if (existing) {\n // Treat any existing WIP change as source-of-truth, so leave it alone\n } else {\n const row = {\n op: JoinRowOperation.Pending,\n id,\n persisted: true,\n columns: { [m2m.columnName]: e1, [m2m.otherColumnName]: e2 },\n } satisfies JoinRow;\n this.rows.push(row);\n this.index.add(m2m, e1, e2, row);\n }\n }\n\n /** Look up/create our internal JoinRow psuedo-entities for the db rows. */\n async loadRows(tuples: [string, string][], dbRows: any[]): Promise<void> {\n const { em } = this.m2m.entity;\n const { columnName: column1, otherColumnName: column2, meta: meta1, otherMeta: meta2, otherEnum } = this.m2m;\n\n const oneIds: string[] = [];\n // Tagged ids for an entity other-side, or raw enum ids for an enum other-side.\n const twoVals: JoinColumnValue[] = [];\n for (const dbRow of dbRows) {\n oneIds.push(keyToTaggedId(meta1, dbRow[column1])!);\n twoVals.push(\n otherEnum ? (dbRow[column2] as number) : (em.getEntity(keyToTaggedId(meta2!, dbRow[column2])!) as any),\n );\n }\n\n // Make sure we have entities in memory for all the joined-to tables. The enum side has no\n // entities to load; the entity sides do (and `twoVals` is re-resolved to entities below).\n await Promise.all([\n em.loadAll(meta1.cstr, oneIds),\n otherEnum\n ? Promise.resolve([])\n : em.loadAll(\n meta2!.cstr,\n dbRows.map((dbRow) => keyToTaggedId(meta2!, dbRow[column2])!),\n ),\n ]);\n\n // If we're doing a em.refresh/reload, we need to watch for rows that are no longer here. For an\n // enum other-side, only persisted rows are delete-candidates (pending in-memory adds are kept,\n // since `EnumCollection` relies on `JoinRows` to hold them rather than re-asserting on load).\n const existingRows = new Set<JoinRow>();\n for (const [columnName, id] of tuples) {\n const others = this.index.getOthers(columnName, em.getEntity(id)!);\n for (const row of others) if (!otherEnum || row.persisted) existingRows.add(row);\n }\n\n let i = 0;\n for (const dbRow of dbRows) {\n const e1 = em.getEntity(oneIds[i])!;\n const e2 = otherEnum ? (dbRow[column2] as number) : em.getEntity(keyToTaggedId(meta2!, dbRow[column2])!)!;\n i++;\n let row = this.index.get(this.m2m, e1, e2);\n if (!row) {\n row = {\n op: JoinRowOperation.Completed,\n id: dbRow.id,\n persisted: true,\n columns: { [column1]: e1, [column2]: e2 },\n created_at: dbRow.created_at,\n };\n this.rows.push(row);\n this.index.add(this.m2m, e1, e2, row);\n } else {\n // If a placeholder row was created while a ManyToManyCollection was unloaded, and we find it during\n // a subsequent load/query, update its id to be what is in the database and mark it persisted.\n row.id = dbRow.id;\n row.persisted = true;\n // Mark this row as still valid\n existingRows.delete(row);\n }\n }\n\n // Mark all no-longer-there rows as deleted\n for (const row of existingRows) row.deleted = true;\n }\n\n getOthers(columnName: string, entity: Entity): JoinColumnValue[] {\n const others = this.index.getOthers(columnName, entity);\n if (others.length === 0) return [];\n const [c1, c2] = Object.keys(others[0].columns);\n const c = others[0].columns[c1] === entity ? c2 : c1;\n return others.filter((o) => !o.deleted).map((row) => row.columns[c]);\n }\n\n /** Drops all in-memory rows where `entity` is on `columnName`, e.g. when it is being deleted. */\n removeAllFor(columnName: string, entity: Entity): void {\n for (const row of this.index.getOthers(columnName, entity)) {\n remove(this.rows, row);\n this.index.remove(row);\n }\n }\n\n /** Drops a single `(e1, e2)` row without queuing a flush, e.g. when mirroring another em's removal. */\n removePreloadedRow(m2m: ManyToManyLike, e1: Entity, e2: JoinColumnValue): void {\n const row = this.index.get(m2m, e1, e2);\n if (row) {\n remove(this.rows, row);\n this.index.remove(row);\n }\n }\n\n /** Scans our `rows` for newly-added/newly-deleted rows that need `INSERT`s/`UPDATE`s. */\n toTodo(): JoinRowTodo | undefined {\n const newRows = this.rows.filter((r) => !r.persisted && r.deleted !== true && r.op === \"pending\");\n const deletedRows = this.rows.filter((r) => r.persisted && r.deleted === true && r.op === \"pending\");\n if (newRows.length === 0 && deletedRows.length === 0) {\n return undefined;\n }\n return {\n m2m: this.m2m,\n newRows,\n deletedRows,\n resetAfterFlushed: () => {\n for (const row of this.rows) {\n if (row.op === JoinRowOperation.Pending || row.op === JoinRowOperation.Flushed)\n row.op = JoinRowOperation.Completed;\n }\n },\n // The driver flushes pure (int, int) FK pairs; resolve them here so it never has to know\n // whether a column points at an entity (use its id) or an enum (its value is already the id).\n dbValue: (row, columnName) => this.#dbValue(row, columnName),\n isNew: (row, columnName) => isNewColumn(row.columns[columnName]),\n };\n }\n\n get hasChanges() {\n return this.rows.some(({ op }) => op === JoinRowOperation.Pending || op === JoinRowOperation.Flushed);\n }\n\n /** The db int value for `row`'s `columnName`: an entity's id, or (for enums) the enum's id itself. */\n #dbValue(row: JoinRow, columnName: string): number {\n const value = row.columns[columnName];\n if (typeof value === \"number\") return value;\n const meta = columnName === this.m2m.columnName ? this.m2m.meta : this.m2m.otherMeta!;\n return keyToNumber(meta, value.idTagged)!;\n }\n\n /**\n * Invalidates caches & queues reactivity for a join-row change.\n *\n * The owning entity (`e1`) always reacts; the \"other\" side only reacts when it is an entity,\n * since enum other-sides have no `em`/reverse-field to keep in sync.\n */\n #reactToChange(m2m: ManyToManyLike, e1: Entity, e2: JoinColumnValue): void {\n const { em } = this.m2m.entity;\n const api = getEmInternalApi(e1.em);\n api.isLoadedCache.resetIsLoaded(e1, m2m.fieldName);\n this.rm.queueDownstreamReactables(e1, m2m.fieldName);\n if (getBaseAndSelfMetas(e1).some((meta) => meta.config.__data.touchOnChange.has(m2m.fieldName))) {\n em.touch(e1);\n }\n if (!m2m.otherEnum) {\n const other = e2 as Entity;\n const otherFieldName = m2m.otherFieldName!;\n api.isLoadedCache.resetIsLoaded(other, otherFieldName);\n this.rm.queueDownstreamReactables(other, otherFieldName);\n if (getBaseAndSelfMetas(other).some((meta) => meta.config.__data.touchOnChange.has(otherFieldName))) {\n em.touch(other);\n }\n }\n }\n}\n\n/**\n * A \"psuedo-entity\" for a join row.\n *\n * We treat this as a special entity, i.e. it has two \"relations\" to each entity for the current\n * row, an optional surrogate `id` primary key, and an optional `created_at` column.\n *\n * These rows are immutable, i.e. once created we don't change either FK, and instead make\n * collection changes only by inserting new rows and deleting old rows.\n *\n * This makes the column1+column2 combination a composite key. For id-less join tables, that\n * composite is the actual primary key and `id` is always undefined.\n */\nexport interface JoinRow {\n /**\n * Whether our relation has been processed or not.\n *\n * - `pending` means we've not flushed it to the Database\n * - `flushed` means we've flushed but `em.flush` hasn't fully completed yet, likely due to AsyncReactiveField calcs\n * - `completed` means we've been flushed and `em.flush` has completed\n */\n op: JoinRowOperation;\n /** The surrogate key for id-ful join tables; always undefined for id-less tables. */\n id: number | undefined;\n /**\n * Whether this row exists (or is assumed to exist) in the database.\n *\n * This is orthogonal to `op` (the flush lifecycle) and is what distinguishes a pending insert\n * from a pending delete: a `pending` row that is `!persisted` is a pending INSERT (added in\n * memory, not yet in the db), while a `pending` row that is `persisted` is a pending DELETE\n * (in the db, marked `deleted`). `op` alone cannot tell these apart, because both inserts and\n * deletes walk the same `pending -> flushed -> completed` progression.\n *\n * We track this as its own flag rather than inferring it from `id` being set/unset, because\n * id-less join tables (whose PK is just the composite of the two FKs) never have an `id` — so\n * `id === undefined` would be ambiguous. `persisted` is the id-agnostic generalization of the\n * `id`-is-set check that id-ful tables historically relied on.\n *\n * It must survive add/remove/re-add sequences: e.g. loading a row (persisted), removing it\n * (pending delete), then re-adding it (`deleted` flipped back to false, `op` back to `pending`)\n * leaves a `pending && !deleted` row that looks identical to a fresh insert — but it is still in\n * the db, so a subsequent remove must issue a DELETE, which only `persisted` can tell us.\n */\n persisted: boolean;\n /** Maps each FK column to its value: an `Entity`, or (for `EnumCollection`s) an enum's numeric id. */\n columns: Record<string, JoinColumnValue>;\n created_at?: Date;\n deleted?: boolean;\n}\n\n/** An enum to track our insert/delete state progression. */\nexport enum JoinRowOperation {\n Pending = \"pending\",\n Flushed = \"flushed\",\n Completed = \"completed\",\n}\n\n/** Keep an in-memory index to avoid sequentially scanning `rows`. */\nclass ManyToManyIndex {\n private indexes: Record<string, Map<JoinColumnValue, Map<JoinColumnValue, JoinRow>>> = {};\n\n constructor(private readonly m2m: ManyToManyLike) {\n this.indexes[m2m.columnName] = new Map();\n this.indexes[m2m.otherColumnName] = new Map();\n }\n\n add(m2m: ManyToManyLike, e1: JoinColumnValue, e2: JoinColumnValue, value: JoinRow): void {\n // Store both e1+e2 => value and e2+e1 => value so we can do lookups from either side\n this.#doAdd(this.indexes[m2m.columnName], e1, e2, value);\n this.#doAdd(this.indexes[m2m.otherColumnName], e2, e1, value);\n }\n\n remove(value: JoinRow): void {\n const [[column1, e1], [column2, e2]] = Object.entries(value.columns);\n this.#doRemove(this.indexes[column1], e1, e2);\n this.#doRemove(this.indexes[column2], e2, e1);\n }\n\n get(m2m: ManyToManyLike, e1: JoinColumnValue, e2: JoinColumnValue): JoinRow | undefined {\n return this.indexes[m2m.columnName].get(e1)?.get(e2);\n }\n\n /** Cheat and use the index to return \"the other entities\" for `entity`. */\n getOthers(columnName: string, entity: JoinColumnValue): JoinRow[] {\n // It's empty m2m collection won't have any other entities, and so no index entries\n const map = this.indexes[columnName].get(entity);\n if (!map) return [];\n // Sort for a stable order regardless of how many batches contributed rows — the underlying\n // Map preserves insertion order, which depends on DataLoader timing and is non-deterministic\n // across processes. New rows (no key yet) sort last.\n const rows = Array.from(map.values());\n if (this.m2m.hasJoinTableId) {\n // Sort by join-row id.\n return rows.sort((a, b) => (a.id ?? Infinity) - (b.id ?? Infinity));\n }\n // Id-less tables have no surrogate id, so sort by the other side's id.\n const otherColumn = columnName === this.m2m.columnName ? this.m2m.otherColumnName : this.m2m.columnName;\n if (this.m2m.otherEnum && otherColumn === this.m2m.otherColumnName) {\n // The other side is an enum, so its column value is already its numeric id.\n return rows.sort((a, b) => (a.columns[otherColumn] as number) - (b.columns[otherColumn] as number));\n }\n const otherMeta = columnName === this.m2m.columnName ? this.m2m.otherMeta! : this.m2m.meta;\n const key = (r: JoinRow) => {\n const other = r.columns[otherColumn] as Entity;\n return other.isNewEntity ? Infinity : keyToNumber(otherMeta, other.id)!;\n };\n return rows.sort((a, b) => key(a) - key(b));\n }\n\n #doAdd(\n index: Map<JoinColumnValue, Map<JoinColumnValue, JoinRow>>,\n e1: JoinColumnValue,\n e2: JoinColumnValue,\n value: JoinRow,\n ): void {\n const map = index.get(e1) ?? new Map();\n if (map.size === 0) index.set(e1, map);\n map.set(e2, value);\n }\n\n #doRemove(\n index: Map<JoinColumnValue, Map<JoinColumnValue, JoinRow>>,\n e1: JoinColumnValue,\n e2: JoinColumnValue,\n ): void {\n index.get(e1)?.delete(e2);\n }\n}\n"],"mappings":";;;;;;;AAyCA,SAAS,YAAY,OAAiC;CACpD,OAAO,OAAO,UAAU,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7 +15,7 @@ import { Entity } from "../Entity.cjs";
15
15
  * other column's value is the enum's numeric id rather than an `Entity` (there is also no
16
16
  * `otherMeta`/`otherFieldName`, since enums have no reverse collection to keep in sync).
17
17
  */
18
- type ManyToManyLike = {
18
+ export type ManyToManyLike = {
19
19
  entity: Entity;
20
20
  joinTableName: string;
21
21
  columnName: string;
@@ -32,9 +32,9 @@ type ManyToManyLike = {
32
32
  hasJoinTableId: boolean;
33
33
  };
34
34
  /** The value of a join row's column: an `Entity`, or an enum's numeric id for `EnumCollection`s. */
35
- type JoinColumnValue = Entity | number;
35
+ export type JoinColumnValue = Entity | number;
36
36
  /** A small holder around m2m join rows, which we treat as psuedo-entities. */
37
- declare class JoinRows {
37
+ export declare class JoinRows {
38
38
  #private;
39
39
  readonly m2m: ManyToManyLike;
40
40
  private rm;
@@ -73,7 +73,7 @@ declare class JoinRows {
73
73
  * This makes the column1+column2 combination a composite key. For id-less join tables, that
74
74
  * composite is the actual primary key and `id` is always undefined.
75
75
  */
76
- interface JoinRow {
76
+ export interface JoinRow {
77
77
  /**
78
78
  * Whether our relation has been processed or not.
79
79
  *
@@ -110,11 +110,10 @@ interface JoinRow {
110
110
  deleted?: boolean;
111
111
  }
112
112
  /** An enum to track our insert/delete state progression. */
113
- declare enum JoinRowOperation {
113
+ export declare enum JoinRowOperation {
114
114
  Pending = "pending",
115
115
  Flushed = "flushed",
116
116
  Completed = "completed"
117
117
  }
118
118
  //#endregion
119
- export { JoinColumnValue, JoinRow, JoinRowOperation, JoinRows, ManyToManyLike };
120
119
  //# sourceMappingURL=JoinRows.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"JoinRows.d.cts","names":[],"sources":["../../src/flush/JoinRows.ts"],"mappings":";;;;;;;;;;;;;;;;;KAoBY;EACV,QAAQ;EACR;EACA;EACA;EACA;EACA,MAAM;;EAEN;;EAEA,YAAY;;EAEZ,YAAY;;EAEZ;;;KAIU,kBAAkB;;cAQjB;;WAQA,KAAK;UACN;mBAPO;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QAAQ,IAAI;;EASxD,UAAU;MAuBN;;;;;;;;;;;;;;iBAkDW;;;;;;;;EAQf,IAAI;;EAEJ;;;;;;;;;;;;;;;;;;;;EAoBA;;EAEA,SAAS,eAAe;EACxB,aAAa;EACb;;;oBAIU;EACV;EACA;EACA"}
@@ -15,7 +15,7 @@ import { Entity } from "../Entity.mjs";
15
15
  * other column's value is the enum's numeric id rather than an `Entity` (there is also no
16
16
  * `otherMeta`/`otherFieldName`, since enums have no reverse collection to keep in sync).
17
17
  */
18
- type ManyToManyLike = {
18
+ export type ManyToManyLike = {
19
19
  entity: Entity;
20
20
  joinTableName: string;
21
21
  columnName: string;
@@ -32,9 +32,9 @@ type ManyToManyLike = {
32
32
  hasJoinTableId: boolean;
33
33
  };
34
34
  /** The value of a join row's column: an `Entity`, or an enum's numeric id for `EnumCollection`s. */
35
- type JoinColumnValue = Entity | number;
35
+ export type JoinColumnValue = Entity | number;
36
36
  /** A small holder around m2m join rows, which we treat as psuedo-entities. */
37
- declare class JoinRows {
37
+ export declare class JoinRows {
38
38
  #private;
39
39
  readonly m2m: ManyToManyLike;
40
40
  private rm;
@@ -73,7 +73,7 @@ declare class JoinRows {
73
73
  * This makes the column1+column2 combination a composite key. For id-less join tables, that
74
74
  * composite is the actual primary key and `id` is always undefined.
75
75
  */
76
- interface JoinRow {
76
+ export interface JoinRow {
77
77
  /**
78
78
  * Whether our relation has been processed or not.
79
79
  *
@@ -110,11 +110,10 @@ interface JoinRow {
110
110
  deleted?: boolean;
111
111
  }
112
112
  /** An enum to track our insert/delete state progression. */
113
- declare enum JoinRowOperation {
113
+ export declare enum JoinRowOperation {
114
114
  Pending = "pending",
115
115
  Flushed = "flushed",
116
116
  Completed = "completed"
117
117
  }
118
118
  //#endregion
119
- export { JoinColumnValue, JoinRow, JoinRowOperation, JoinRows, ManyToManyLike };
120
119
  //# sourceMappingURL=JoinRows.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"JoinRows.d.mts","names":[],"sources":["../../src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