joist-core 2.3.0-next.97 → 2.3.0-next.99

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 (747) hide show
  1. package/build/BaseEntity.cjs.map +1 -1
  2. package/build/BaseEntity.js.map +1 -1
  3. package/build/Entity.cjs.map +1 -1
  4. package/build/Entity.js.map +1 -1
  5. package/build/EntityManager.cjs +45 -46
  6. package/build/EntityManager.cjs.map +1 -1
  7. package/build/EntityManager.d.cts +7 -7
  8. package/build/EntityManager.d.cts.map +1 -1
  9. package/build/EntityManager.d.mts +7 -7
  10. package/build/EntityManager.d.mts.map +1 -1
  11. package/build/EntityManager.js +27 -28
  12. package/build/EntityManager.js.map +1 -1
  13. package/build/EntityMetadata.cjs +0 -2
  14. package/build/EntityMetadata.cjs.map +1 -1
  15. package/build/EntityMetadata.d.cts +3 -3
  16. package/build/EntityMetadata.d.mts +3 -3
  17. package/build/EntityMetadata.js +0 -2
  18. package/build/EntityMetadata.js.map +1 -1
  19. package/build/IndexManager.cjs +1 -1
  20. package/build/IndexManager.cjs.map +1 -1
  21. package/build/IndexManager.js +1 -1
  22. package/build/IndexManager.js.map +1 -1
  23. package/build/InstanceData.cjs.map +1 -1
  24. package/build/InstanceData.js.map +1 -1
  25. package/build/PluginManager.cjs +0 -1
  26. package/build/PluginManager.cjs.map +1 -1
  27. package/build/PluginManager.d.cts +1 -1
  28. package/build/PluginManager.d.mts +1 -1
  29. package/build/PluginManager.js +0 -1
  30. package/build/PluginManager.js.map +1 -1
  31. package/build/batchloaders/enumCollectionBatchLoader.cjs +1 -1
  32. package/build/batchloaders/enumCollectionBatchLoader.cjs.map +1 -1
  33. package/build/batchloaders/enumCollectionBatchLoader.d.cts +1 -1
  34. package/build/batchloaders/enumCollectionBatchLoader.d.mts +1 -1
  35. package/build/batchloaders/enumCollectionBatchLoader.js +1 -1
  36. package/build/batchloaders/enumCollectionBatchLoader.js.map +1 -1
  37. package/build/batchloaders/loadBatchLoader.cjs +3 -4
  38. package/build/batchloaders/loadBatchLoader.cjs.map +1 -1
  39. package/build/batchloaders/loadBatchLoader.d.cts +1 -1
  40. package/build/batchloaders/loadBatchLoader.d.mts +1 -1
  41. package/build/batchloaders/loadBatchLoader.js +2 -3
  42. package/build/batchloaders/loadBatchLoader.js.map +1 -1
  43. package/build/batchloaders/manyToManyBatchLoader.cjs +1 -1
  44. package/build/batchloaders/manyToManyBatchLoader.cjs.map +1 -1
  45. package/build/batchloaders/manyToManyBatchLoader.d.cts +1 -1
  46. package/build/batchloaders/manyToManyBatchLoader.d.mts +1 -1
  47. package/build/batchloaders/manyToManyBatchLoader.js +1 -1
  48. package/build/batchloaders/manyToManyBatchLoader.js.map +1 -1
  49. package/build/batchloaders/oneToManyBatchLoader.cjs +1 -1
  50. package/build/batchloaders/oneToManyBatchLoader.cjs.map +1 -1
  51. package/build/batchloaders/oneToManyBatchLoader.js +1 -1
  52. package/build/batchloaders/oneToManyBatchLoader.js.map +1 -1
  53. package/build/batchloaders/oneToOneBatchLoader.cjs +1 -1
  54. package/build/batchloaders/oneToOneBatchLoader.cjs.map +1 -1
  55. package/build/batchloaders/oneToOneBatchLoader.js +1 -1
  56. package/build/batchloaders/oneToOneBatchLoader.js.map +1 -1
  57. package/build/batchloaders/populateBatchLoader.cjs +11 -12
  58. package/build/batchloaders/populateBatchLoader.cjs.map +1 -1
  59. package/build/batchloaders/populateBatchLoader.d.cts +1 -1
  60. package/build/batchloaders/populateBatchLoader.d.mts +1 -1
  61. package/build/batchloaders/populateBatchLoader.js +7 -8
  62. package/build/batchloaders/populateBatchLoader.js.map +1 -1
  63. package/build/batchloaders/recursiveChildrenBatchLoader.cjs +2 -2
  64. package/build/batchloaders/recursiveChildrenBatchLoader.cjs.map +1 -1
  65. package/build/batchloaders/recursiveChildrenBatchLoader.js +2 -2
  66. package/build/batchloaders/recursiveChildrenBatchLoader.js.map +1 -1
  67. package/build/batchloaders/recursiveM2mBatchLoader.cjs +2 -2
  68. package/build/batchloaders/recursiveM2mBatchLoader.cjs.map +1 -1
  69. package/build/batchloaders/recursiveM2mBatchLoader.js +2 -2
  70. package/build/batchloaders/recursiveM2mBatchLoader.js.map +1 -1
  71. package/build/batchloaders/recursiveParentsBatchLoader.cjs +2 -2
  72. package/build/batchloaders/recursiveParentsBatchLoader.cjs.map +1 -1
  73. package/build/batchloaders/recursiveParentsBatchLoader.js +2 -2
  74. package/build/batchloaders/recursiveParentsBatchLoader.js.map +1 -1
  75. package/build/changes.cjs +2 -3
  76. package/build/changes.cjs.map +1 -1
  77. package/build/changes.js +2 -3
  78. package/build/changes.js.map +1 -1
  79. package/build/config.cjs +3 -3
  80. package/build/config.cjs.map +1 -1
  81. package/build/config.d.cts +2 -2
  82. package/build/config.d.mts +2 -2
  83. package/build/config.js +1 -1
  84. package/build/config.js.map +1 -1
  85. package/build/configure.cjs +10 -10
  86. package/build/configure.cjs.map +1 -1
  87. package/build/configure.js +5 -5
  88. package/build/configure.js.map +1 -1
  89. package/build/dataloaders/fastWhereFilterHash.cjs +8 -8
  90. package/build/dataloaders/fastWhereFilterHash.cjs.map +1 -1
  91. package/build/dataloaders/fastWhereFilterHash.d.cts.map +1 -1
  92. package/build/dataloaders/fastWhereFilterHash.d.mts.map +1 -1
  93. package/build/dataloaders/fastWhereFilterHash.js +3 -3
  94. package/build/dataloaders/fastWhereFilterHash.js.map +1 -1
  95. package/build/dataloaders/findByUniqueDataLoader.cjs.map +1 -1
  96. package/build/dataloaders/findByUniqueDataLoader.d.cts.map +1 -1
  97. package/build/dataloaders/findByUniqueDataLoader.d.mts.map +1 -1
  98. package/build/dataloaders/findByUniqueDataLoader.js.map +1 -1
  99. package/build/dataloaders/findCountDataLoader.cjs +2 -2
  100. package/build/dataloaders/findCountDataLoader.cjs.map +1 -1
  101. package/build/dataloaders/findCountDataLoader.js +1 -1
  102. package/build/dataloaders/findCountDataLoader.js.map +1 -1
  103. package/build/dataloaders/findDataLoader.cjs +6 -6
  104. package/build/dataloaders/findDataLoader.cjs.map +1 -1
  105. package/build/dataloaders/findDataLoader.d.cts +1 -1
  106. package/build/dataloaders/findDataLoader.d.mts +1 -1
  107. package/build/dataloaders/findDataLoader.js +3 -3
  108. package/build/dataloaders/findDataLoader.js.map +1 -1
  109. package/build/dataloaders/findIdsDataLoader.cjs +3 -3
  110. package/build/dataloaders/findIdsDataLoader.cjs.map +1 -1
  111. package/build/dataloaders/findIdsDataLoader.js +2 -2
  112. package/build/dataloaders/findIdsDataLoader.js.map +1 -1
  113. package/build/dataloaders/findOrCreateDataLoader.cjs +1 -1
  114. package/build/dataloaders/findOrCreateDataLoader.cjs.map +1 -1
  115. package/build/dataloaders/findOrCreateDataLoader.d.cts.map +1 -1
  116. package/build/dataloaders/findOrCreateDataLoader.d.mts.map +1 -1
  117. package/build/dataloaders/findOrCreateDataLoader.js +1 -1
  118. package/build/dataloaders/findOrCreateDataLoader.js.map +1 -1
  119. package/build/dataloaders/findPaginatedDataLoader.cjs +6 -6
  120. package/build/dataloaders/findPaginatedDataLoader.cjs.map +1 -1
  121. package/build/dataloaders/findPaginatedDataLoader.d.cts +1 -1
  122. package/build/dataloaders/findPaginatedDataLoader.d.mts +1 -1
  123. package/build/dataloaders/findPaginatedDataLoader.js +3 -3
  124. package/build/dataloaders/findPaginatedDataLoader.js.map +1 -1
  125. package/build/dataloaders/lensDataLoader.cjs +3 -3
  126. package/build/dataloaders/lensDataLoader.cjs.map +1 -1
  127. package/build/dataloaders/lensDataLoader.d.cts.map +1 -1
  128. package/build/dataloaders/lensDataLoader.d.mts.map +1 -1
  129. package/build/dataloaders/lensDataLoader.js +2 -2
  130. package/build/dataloaders/lensDataLoader.js.map +1 -1
  131. package/build/dataloaders/manyToManyFindDataLoader.cjs +1 -1
  132. package/build/dataloaders/manyToManyFindDataLoader.cjs.map +1 -1
  133. package/build/dataloaders/manyToManyFindDataLoader.d.cts.map +1 -1
  134. package/build/dataloaders/manyToManyFindDataLoader.d.mts.map +1 -1
  135. package/build/dataloaders/manyToManyFindDataLoader.js +1 -1
  136. package/build/dataloaders/manyToManyFindDataLoader.js.map +1 -1
  137. package/build/dataloaders/oneToManyFindDataLoader.cjs +1 -1
  138. package/build/dataloaders/oneToManyFindDataLoader.cjs.map +1 -1
  139. package/build/dataloaders/oneToManyFindDataLoader.d.cts.map +1 -1
  140. package/build/dataloaders/oneToManyFindDataLoader.d.mts.map +1 -1
  141. package/build/dataloaders/oneToManyFindDataLoader.js +1 -1
  142. package/build/dataloaders/oneToManyFindDataLoader.js.map +1 -1
  143. package/build/defaults.cjs +5 -5
  144. package/build/defaults.cjs.map +1 -1
  145. package/build/defaults.d.cts +1 -1
  146. package/build/defaults.d.cts.map +1 -1
  147. package/build/defaults.d.mts +1 -1
  148. package/build/defaults.d.mts.map +1 -1
  149. package/build/defaults.js +4 -4
  150. package/build/defaults.js.map +1 -1
  151. package/build/drivers/Driver.cjs +0 -1
  152. package/build/drivers/Driver.d.cts +1 -1
  153. package/build/drivers/Driver.d.mts +1 -1
  154. package/build/drivers/Driver.js +0 -1
  155. package/build/drivers/EntityWriter.cjs +6 -7
  156. package/build/drivers/EntityWriter.cjs.map +1 -1
  157. package/build/drivers/EntityWriter.d.cts +1 -1
  158. package/build/drivers/EntityWriter.d.mts +1 -1
  159. package/build/drivers/EntityWriter.js +2 -3
  160. package/build/drivers/EntityWriter.js.map +1 -1
  161. package/build/drivers/IdAssigner.cjs +0 -1
  162. package/build/drivers/IdAssigner.cjs.map +1 -1
  163. package/build/drivers/IdAssigner.d.cts +1 -1
  164. package/build/drivers/IdAssigner.d.mts +1 -1
  165. package/build/drivers/IdAssigner.js +0 -1
  166. package/build/drivers/IdAssigner.js.map +1 -1
  167. package/build/drivers/driverApi.cjs +19 -0
  168. package/build/drivers/driverApi.cjs.map +1 -0
  169. package/build/drivers/driverApi.d.cts +22 -0
  170. package/build/drivers/driverApi.d.cts.map +1 -0
  171. package/build/drivers/driverApi.d.mts +22 -0
  172. package/build/drivers/driverApi.d.mts.map +1 -0
  173. package/build/drivers/driverApi.js +18 -0
  174. package/build/drivers/driverApi.js.map +1 -0
  175. package/build/fields.cjs +3 -3
  176. package/build/fields.cjs.map +1 -1
  177. package/build/fields.js +2 -2
  178. package/build/fields.js.map +1 -1
  179. package/build/{FlushLock.cjs → flush/FlushLock.cjs} +1 -1
  180. package/build/flush/FlushLock.cjs.map +1 -0
  181. package/build/{FlushLock.d.cts → flush/FlushLock.d.cts} +1 -1
  182. package/build/flush/FlushLock.d.cts.map +1 -0
  183. package/build/{FlushLock.d.mts → flush/FlushLock.d.mts} +1 -1
  184. package/build/flush/FlushLock.d.mts.map +1 -0
  185. package/build/{FlushLock.js → flush/FlushLock.js} +1 -1
  186. package/build/flush/FlushLock.js.map +1 -0
  187. package/build/{JoinRows.cjs → flush/JoinRows.cjs} +5 -8
  188. package/build/flush/JoinRows.cjs.map +1 -0
  189. package/build/{JoinRows.d.cts → flush/JoinRows.d.cts} +5 -5
  190. package/build/flush/JoinRows.d.cts.map +1 -0
  191. package/build/{JoinRows.d.mts → flush/JoinRows.d.mts} +5 -5
  192. package/build/flush/JoinRows.d.mts.map +1 -0
  193. package/build/{JoinRows.js → flush/JoinRows.js} +5 -8
  194. package/build/flush/JoinRows.js.map +1 -0
  195. package/build/{PendingChanges.cjs → flush/PendingChanges.cjs} +0 -1
  196. package/build/{PendingChanges.d.cts → flush/PendingChanges.d.cts} +2 -2
  197. package/build/flush/PendingChanges.d.cts.map +1 -0
  198. package/build/{PendingChanges.d.mts → flush/PendingChanges.d.mts} +2 -2
  199. package/build/flush/PendingChanges.d.mts.map +1 -0
  200. package/build/flush/PendingChanges.js +1 -0
  201. package/build/{Todo.cjs → flush/Todo.cjs} +4 -6
  202. package/build/flush/Todo.cjs.map +1 -0
  203. package/build/{Todo.d.cts → flush/Todo.d.cts} +3 -3
  204. package/build/flush/Todo.d.cts.map +1 -0
  205. package/build/{Todo.d.mts → flush/Todo.d.mts} +3 -3
  206. package/build/flush/Todo.d.mts.map +1 -0
  207. package/build/{Todo.js → flush/Todo.js} +4 -6
  208. package/build/flush/Todo.js.map +1 -0
  209. package/build/getProperties.cjs.map +1 -1
  210. package/build/getProperties.js.map +1 -1
  211. package/build/index.cjs +100 -100
  212. package/build/index.cjs.map +1 -1
  213. package/build/index.d.cts +15 -15
  214. package/build/index.d.mts +15 -15
  215. package/build/index.js +42 -42
  216. package/build/index.js.map +1 -1
  217. package/build/json.cjs +4 -4
  218. package/build/json.cjs.map +1 -1
  219. package/build/json.js +3 -3
  220. package/build/json.js.map +1 -1
  221. package/build/keys.cjs +1 -1
  222. package/build/keys.cjs.map +1 -1
  223. package/build/keys.js +1 -1
  224. package/build/keys.js.map +1 -1
  225. package/build/{HintTree.cjs → loading/HintTree.cjs} +2 -5
  226. package/build/loading/HintTree.cjs.map +1 -0
  227. package/build/{HintTree.d.cts → loading/HintTree.d.cts} +3 -3
  228. package/build/loading/HintTree.d.cts.map +1 -0
  229. package/build/{HintTree.d.mts → loading/HintTree.d.mts} +3 -3
  230. package/build/loading/HintTree.d.mts.map +1 -0
  231. package/build/{HintTree.js → loading/HintTree.js} +2 -5
  232. package/build/loading/HintTree.js.map +1 -0
  233. package/build/{IsLoadedCache.cjs → loading/IsLoadedCache.cjs} +2 -3
  234. package/build/loading/IsLoadedCache.cjs.map +1 -0
  235. package/build/{IsLoadedCache.d.cts → loading/IsLoadedCache.d.cts} +2 -2
  236. package/build/loading/IsLoadedCache.d.cts.map +1 -0
  237. package/build/{IsLoadedCache.d.mts → loading/IsLoadedCache.d.mts} +2 -2
  238. package/build/loading/IsLoadedCache.d.mts.map +1 -0
  239. package/build/{IsLoadedCache.js → loading/IsLoadedCache.js} +2 -3
  240. package/build/{IsLoadedCache.cjs.map → loading/IsLoadedCache.js.map} +1 -1
  241. package/build/{loadHints.cjs → loading/loadHints.cjs} +6 -11
  242. package/build/loading/loadHints.cjs.map +1 -0
  243. package/build/{loadHints.d.cts → loading/loadHints.d.cts} +14 -14
  244. package/build/loading/loadHints.d.cts.map +1 -0
  245. package/build/{loadHints.d.mts → loading/loadHints.d.mts} +14 -14
  246. package/build/loading/loadHints.d.mts.map +1 -0
  247. package/build/{loadHints.js → loading/loadHints.js} +3 -8
  248. package/build/loading/loadHints.js.map +1 -0
  249. package/build/{loadLens.cjs → loading/loadLens.cjs} +8 -9
  250. package/build/loading/loadLens.cjs.map +1 -0
  251. package/build/{loadLens.d.cts → loading/loadLens.d.cts} +3 -3
  252. package/build/loading/loadLens.d.cts.map +1 -0
  253. package/build/{loadLens.d.mts → loading/loadLens.d.mts} +3 -3
  254. package/build/loading/loadLens.d.mts.map +1 -0
  255. package/build/{loadLens.js → loading/loadLens.js} +8 -9
  256. package/build/loading/loadLens.js.map +1 -0
  257. package/build/{withLoaded.cjs → loading/withLoaded.cjs} +12 -13
  258. package/build/loading/withLoaded.cjs.map +1 -0
  259. package/build/{withLoaded.d.cts → loading/withLoaded.d.cts} +9 -9
  260. package/build/loading/withLoaded.d.cts.map +1 -0
  261. package/build/{withLoaded.d.mts → loading/withLoaded.d.mts} +9 -9
  262. package/build/loading/withLoaded.d.mts.map +1 -0
  263. package/build/{withLoaded.js → loading/withLoaded.js} +10 -11
  264. package/build/loading/withLoaded.js.map +1 -0
  265. package/build/logging/FactoryLogger.cjs.map +1 -1
  266. package/build/logging/FactoryLogger.d.cts.map +1 -1
  267. package/build/logging/FactoryLogger.d.mts.map +1 -1
  268. package/build/logging/FactoryLogger.js.map +1 -1
  269. package/build/logging/FieldLogger.cjs.map +1 -1
  270. package/build/logging/FieldLogger.d.cts.map +1 -1
  271. package/build/logging/FieldLogger.d.mts.map +1 -1
  272. package/build/logging/FieldLogger.js.map +1 -1
  273. package/build/logging/ReactionLogger.cjs +0 -2
  274. package/build/logging/ReactionLogger.cjs.map +1 -1
  275. package/build/logging/ReactionLogger.d.cts +2 -2
  276. package/build/logging/ReactionLogger.d.cts.map +1 -1
  277. package/build/logging/ReactionLogger.d.mts +2 -2
  278. package/build/logging/ReactionLogger.d.mts.map +1 -1
  279. package/build/logging/ReactionLogger.js +0 -2
  280. package/build/logging/ReactionLogger.js.map +1 -1
  281. package/build/newEntity.cjs.map +1 -1
  282. package/build/newEntity.js.map +1 -1
  283. package/build/newTestInstance.cjs +3 -3
  284. package/build/newTestInstance.cjs.map +1 -1
  285. package/build/newTestInstance.d.cts +1 -1
  286. package/build/newTestInstance.d.cts.map +1 -1
  287. package/build/newTestInstance.d.mts +1 -1
  288. package/build/newTestInstance.d.mts.map +1 -1
  289. package/build/newTestInstance.js +2 -2
  290. package/build/newTestInstance.js.map +1 -1
  291. package/build/normalizeHints.cjs +0 -2
  292. package/build/normalizeHints.cjs.map +1 -1
  293. package/build/normalizeHints.d.cts +2 -2
  294. package/build/normalizeHints.d.mts +2 -2
  295. package/build/normalizeHints.js +0 -2
  296. package/build/normalizeHints.js.map +1 -1
  297. package/build/nowUTC.cjs +2 -2
  298. package/build/nowUTC.cjs.map +1 -1
  299. package/build/nowUTC.d.cts +1 -1
  300. package/build/nowUTC.d.mts +1 -1
  301. package/build/nowUTC.js +1 -1
  302. package/build/nowUTC.js.map +1 -1
  303. package/build/plugins/ImmutableEntitiesPlugin.cjs.map +1 -1
  304. package/build/plugins/ImmutableEntitiesPlugin.js.map +1 -1
  305. package/build/plugins/PreloadPlugin.cjs +0 -2
  306. package/build/plugins/PreloadPlugin.d.cts +2 -2
  307. package/build/plugins/PreloadPlugin.d.mts +2 -2
  308. package/build/plugins/PreloadPlugin.js +0 -2
  309. package/build/preloading/JsonAggregatePreloader.cjs +1 -4
  310. package/build/preloading/JsonAggregatePreloader.cjs.map +1 -1
  311. package/build/preloading/JsonAggregatePreloader.d.cts +2 -2
  312. package/build/preloading/JsonAggregatePreloader.d.cts.map +1 -1
  313. package/build/preloading/JsonAggregatePreloader.d.mts +2 -2
  314. package/build/preloading/JsonAggregatePreloader.d.mts.map +1 -1
  315. package/build/preloading/JsonAggregatePreloader.js +1 -4
  316. package/build/preloading/JsonAggregatePreloader.js.map +1 -1
  317. package/build/preloading/canPreload.cjs.map +1 -1
  318. package/build/preloading/canPreload.js.map +1 -1
  319. package/build/preloading/partitionHint.cjs +2 -3
  320. package/build/preloading/partitionHint.cjs.map +1 -1
  321. package/build/preloading/partitionHint.d.cts +1 -1
  322. package/build/preloading/partitionHint.d.mts +1 -1
  323. package/build/preloading/partitionHint.js +2 -3
  324. package/build/preloading/partitionHint.js.map +1 -1
  325. package/build/queries/ConditionBuilder.cjs.map +1 -1
  326. package/build/queries/ConditionBuilder.d.cts +1 -1
  327. package/build/queries/ConditionBuilder.d.mts +1 -1
  328. package/build/queries/ConditionBuilder.js.map +1 -1
  329. package/build/queries/conditions.cjs.map +1 -1
  330. package/build/queries/conditions.js.map +1 -1
  331. package/build/queries/entityQueryUtils.cjs.map +1 -1
  332. package/build/queries/entityQueryUtils.js.map +1 -1
  333. package/build/queries/find/Aliases.cjs +1 -1
  334. package/build/queries/find/Aliases.cjs.map +1 -1
  335. package/build/queries/find/Aliases.d.cts.map +1 -1
  336. package/build/queries/find/Aliases.d.mts.map +1 -1
  337. package/build/queries/find/Aliases.js +1 -1
  338. package/build/queries/find/Aliases.js.map +1 -1
  339. package/build/queries/find/DeferredAlias.cjs.map +1 -1
  340. package/build/queries/find/DeferredAlias.js.map +1 -1
  341. package/build/queries/find/EntityFilter.cjs.map +1 -1
  342. package/build/queries/find/EntityFilter.js.map +1 -1
  343. package/build/queries/find/EntityGraphQLFilter.cjs.map +1 -1
  344. package/build/queries/find/EntityGraphQLFilter.js.map +1 -1
  345. package/build/queries/find/QueryParser.cjs +2 -2
  346. package/build/queries/find/QueryParser.cjs.map +1 -1
  347. package/build/queries/find/QueryParser.collectionJoins.cjs.map +1 -1
  348. package/build/queries/find/QueryParser.collectionJoins.js.map +1 -1
  349. package/build/queries/find/QueryParser.d.cts.map +1 -1
  350. package/build/queries/find/QueryParser.d.mts.map +1 -1
  351. package/build/queries/find/QueryParser.js +2 -2
  352. package/build/queries/find/QueryParser.js.map +1 -1
  353. package/build/queries/find/QueryParser.pruning.cjs.map +1 -1
  354. package/build/queries/find/QueryParser.pruning.js.map +1 -1
  355. package/build/queries/find/QueryVisitor.cjs.map +1 -1
  356. package/build/queries/find/QueryVisitor.js.map +1 -1
  357. package/build/queries/find/buildFindQuery.cjs.map +1 -1
  358. package/build/queries/find/buildFindQuery.js.map +1 -1
  359. package/build/queries/find/scopes.cjs.map +1 -1
  360. package/build/queries/find/scopes.d.cts +1 -1
  361. package/build/queries/find/scopes.d.mts +1 -1
  362. package/build/queries/find/scopes.js.map +1 -1
  363. package/build/queries/parsedConditions.cjs.map +1 -1
  364. package/build/queries/parsedConditions.js.map +1 -1
  365. package/build/queries/renderConditions.cjs.map +1 -1
  366. package/build/queries/renderConditions.js.map +1 -1
  367. package/build/queries/skipCondition.cjs.map +1 -1
  368. package/build/queries/skipCondition.js.map +1 -1
  369. package/build/queries/sql/AliasAssigner.cjs.map +1 -1
  370. package/build/queries/sql/AliasAssigner.js.map +1 -1
  371. package/build/queries/sql/Expr.cjs +2 -2
  372. package/build/queries/sql/Expr.cjs.map +1 -1
  373. package/build/queries/sql/Expr.d.cts +1 -1
  374. package/build/queries/sql/Expr.d.mts +1 -1
  375. package/build/queries/sql/Expr.js +1 -1
  376. package/build/queries/sql/Expr.js.map +1 -1
  377. package/build/queries/sql/Tables.cjs +1 -1
  378. package/build/queries/sql/Tables.cjs.map +1 -1
  379. package/build/queries/sql/Tables.d.cts.map +1 -1
  380. package/build/queries/sql/Tables.d.mts.map +1 -1
  381. package/build/queries/sql/Tables.js +1 -1
  382. package/build/queries/sql/Tables.js.map +1 -1
  383. package/build/queries/sql/execute.cjs +1 -1
  384. package/build/queries/sql/execute.cjs.map +1 -1
  385. package/build/queries/sql/execute.js +1 -1
  386. package/build/queries/sql/execute.js.map +1 -1
  387. package/build/queries/sql/expressions/arrayAgg.cjs.map +1 -1
  388. package/build/queries/sql/expressions/arrayAgg.js.map +1 -1
  389. package/build/queries/sql/expressions/case.cjs.map +1 -1
  390. package/build/queries/sql/expressions/case.js.map +1 -1
  391. package/build/queries/sql/expressions/coalesce.cjs.map +1 -1
  392. package/build/queries/sql/expressions/coalesce.js.map +1 -1
  393. package/build/queries/sql/expressions/codecs.cjs +2 -2
  394. package/build/queries/sql/expressions/codecs.cjs.map +1 -1
  395. package/build/queries/sql/expressions/codecs.js +1 -1
  396. package/build/queries/sql/expressions/codecs.js.map +1 -1
  397. package/build/queries/sql/expressions/expression.cjs.map +1 -1
  398. package/build/queries/sql/expressions/expression.d.cts.map +1 -1
  399. package/build/queries/sql/expressions/expression.d.mts.map +1 -1
  400. package/build/queries/sql/expressions/expression.js.map +1 -1
  401. package/build/queries/sql/expressions/greatest.cjs.map +1 -1
  402. package/build/queries/sql/expressions/greatest.js.map +1 -1
  403. package/build/queries/sql/expressions/least.cjs.map +1 -1
  404. package/build/queries/sql/expressions/least.js.map +1 -1
  405. package/build/queries/sql/expressions/nullIf.cjs.map +1 -1
  406. package/build/queries/sql/expressions/nullIf.js.map +1 -1
  407. package/build/queries/sql/expressions/parseExpression.cjs.map +1 -1
  408. package/build/queries/sql/expressions/parseExpression.js.map +1 -1
  409. package/build/queries/sql/expressions/types.d.cts.map +1 -1
  410. package/build/queries/sql/expressions/types.d.mts.map +1 -1
  411. package/build/queries/sql/query.cjs +1 -1
  412. package/build/queries/sql/query.cjs.map +1 -1
  413. package/build/queries/sql/query.d.cts +1 -1
  414. package/build/queries/sql/query.d.mts +1 -1
  415. package/build/queries/sql/query.js +1 -1
  416. package/build/queries/sql/query.js.map +1 -1
  417. package/build/{unnest.cjs → queries/unnest.cjs} +1 -2
  418. package/build/queries/unnest.cjs.map +1 -0
  419. package/build/{unnest.d.cts → queries/unnest.d.cts} +3 -3
  420. package/build/queries/unnest.d.cts.map +1 -0
  421. package/build/{unnest.d.mts → queries/unnest.d.mts} +3 -3
  422. package/build/queries/unnest.d.mts.map +1 -0
  423. package/build/{unnest.js → queries/unnest.js} +1 -2
  424. package/build/queries/unnest.js.map +1 -0
  425. package/build/queries/valueFilters.cjs.map +1 -1
  426. package/build/queries/valueFilters.d.cts +1 -1
  427. package/build/queries/valueFilters.d.cts.map +1 -1
  428. package/build/queries/valueFilters.d.mts +1 -1
  429. package/build/queries/valueFilters.d.mts.map +1 -1
  430. package/build/queries/valueFilters.js.map +1 -1
  431. package/build/{ReactionsManager.cjs → reactivity/ReactionsManager.cjs} +8 -10
  432. package/build/reactivity/ReactionsManager.cjs.map +1 -0
  433. package/build/{ReactionsManager.d.cts → reactivity/ReactionsManager.d.cts} +5 -6
  434. package/build/reactivity/ReactionsManager.d.cts.map +1 -0
  435. package/build/{ReactionsManager.d.mts → reactivity/ReactionsManager.d.mts} +5 -6
  436. package/build/reactivity/ReactionsManager.d.mts.map +1 -0
  437. package/build/{ReactionsManager.js → reactivity/ReactionsManager.js} +6 -8
  438. package/build/reactivity/ReactionsManager.js.map +1 -0
  439. package/build/{reactiveHints.cjs → reactivity/reactiveHints.cjs} +12 -16
  440. package/build/reactivity/reactiveHints.cjs.map +1 -0
  441. package/build/{reactiveHints.d.cts → reactivity/reactiveHints.d.cts} +17 -17
  442. package/build/reactivity/reactiveHints.d.cts.map +1 -0
  443. package/build/{reactiveHints.d.mts → reactivity/reactiveHints.d.mts} +17 -17
  444. package/build/reactivity/reactiveHints.d.mts.map +1 -0
  445. package/build/{reactiveHints.js → reactivity/reactiveHints.js} +12 -16
  446. package/build/reactivity/reactiveHints.js.map +1 -0
  447. package/build/relations/AbstractRelationImpl.cjs.map +1 -1
  448. package/build/relations/AbstractRelationImpl.js.map +1 -1
  449. package/build/relations/AsyncProperty.cjs.map +1 -1
  450. package/build/relations/AsyncProperty.js.map +1 -1
  451. package/build/relations/AsyncReactiveField.cjs +6 -6
  452. package/build/relations/AsyncReactiveField.cjs.map +1 -1
  453. package/build/relations/AsyncReactiveField.d.cts +1 -1
  454. package/build/relations/AsyncReactiveField.d.mts +1 -1
  455. package/build/relations/AsyncReactiveField.js +4 -4
  456. package/build/relations/AsyncReactiveField.js.map +1 -1
  457. package/build/relations/Collection.cjs +1 -1
  458. package/build/relations/Collection.cjs.map +1 -1
  459. package/build/relations/Collection.js +1 -1
  460. package/build/relations/Collection.js.map +1 -1
  461. package/build/relations/CustomCollection.cjs.map +1 -1
  462. package/build/relations/CustomCollection.d.cts +1 -1
  463. package/build/relations/CustomCollection.d.mts +1 -1
  464. package/build/relations/CustomCollection.js.map +1 -1
  465. package/build/relations/CustomReference.cjs +1 -1
  466. package/build/relations/CustomReference.cjs.map +1 -1
  467. package/build/relations/CustomReference.d.cts +1 -1
  468. package/build/relations/CustomReference.d.mts +1 -1
  469. package/build/relations/CustomReference.js +1 -1
  470. package/build/relations/CustomReference.js.map +1 -1
  471. package/build/relations/EnumCollection.cjs.map +1 -1
  472. package/build/relations/EnumCollection.d.cts +1 -1
  473. package/build/relations/EnumCollection.d.mts +1 -1
  474. package/build/relations/EnumCollection.js.map +1 -1
  475. package/build/relations/LazyField.cjs +4 -4
  476. package/build/relations/LazyField.cjs.map +1 -1
  477. package/build/relations/LazyField.js +4 -4
  478. package/build/relations/LazyField.js.map +1 -1
  479. package/build/relations/ManyToManyCollection.cjs +3 -3
  480. package/build/relations/ManyToManyCollection.cjs.map +1 -1
  481. package/build/relations/ManyToManyCollection.js +3 -3
  482. package/build/relations/ManyToManyCollection.js.map +1 -1
  483. package/build/relations/ManyToManyLargeCollection.cjs +3 -3
  484. package/build/relations/ManyToManyLargeCollection.cjs.map +1 -1
  485. package/build/relations/ManyToManyLargeCollection.js +3 -3
  486. package/build/relations/ManyToManyLargeCollection.js.map +1 -1
  487. package/build/relations/ManyToOneReference.cjs +4 -4
  488. package/build/relations/ManyToOneReference.cjs.map +1 -1
  489. package/build/relations/ManyToOneReference.js +4 -4
  490. package/build/relations/ManyToOneReference.js.map +1 -1
  491. package/build/relations/OneToManyCollection.cjs +1 -2
  492. package/build/relations/OneToManyCollection.cjs.map +1 -1
  493. package/build/relations/OneToManyCollection.d.cts +1 -1
  494. package/build/relations/OneToManyCollection.d.mts +1 -1
  495. package/build/relations/OneToManyCollection.js +1 -2
  496. package/build/relations/OneToManyCollection.js.map +1 -1
  497. package/build/relations/OneToManyLargeCollection.cjs +1 -1
  498. package/build/relations/OneToManyLargeCollection.cjs.map +1 -1
  499. package/build/relations/OneToManyLargeCollection.js +1 -1
  500. package/build/relations/OneToManyLargeCollection.js.map +1 -1
  501. package/build/relations/OneToOneReference.cjs +5 -5
  502. package/build/relations/OneToOneReference.cjs.map +1 -1
  503. package/build/relations/OneToOneReference.js +5 -5
  504. package/build/relations/OneToOneReference.js.map +1 -1
  505. package/build/relations/PolymorphicReference.cjs +3 -3
  506. package/build/relations/PolymorphicReference.cjs.map +1 -1
  507. package/build/relations/PolymorphicReference.js +3 -3
  508. package/build/relations/PolymorphicReference.js.map +1 -1
  509. package/build/relations/ReactiveField.cjs +5 -6
  510. package/build/relations/ReactiveField.cjs.map +1 -1
  511. package/build/relations/ReactiveField.d.cts +2 -2
  512. package/build/relations/ReactiveField.d.mts +2 -2
  513. package/build/relations/ReactiveField.js +3 -4
  514. package/build/relations/ReactiveField.js.map +1 -1
  515. package/build/relations/ReactiveGetter.cjs +0 -1
  516. package/build/relations/ReactiveGetter.cjs.map +1 -1
  517. package/build/relations/ReactiveGetter.d.cts +1 -1
  518. package/build/relations/ReactiveGetter.d.mts +1 -1
  519. package/build/relations/ReactiveGetter.js +0 -1
  520. package/build/relations/ReactiveGetter.js.map +1 -1
  521. package/build/relations/ReactiveManyToMany.cjs +5 -6
  522. package/build/relations/ReactiveManyToMany.cjs.map +1 -1
  523. package/build/relations/ReactiveManyToMany.d.cts +2 -2
  524. package/build/relations/ReactiveManyToMany.d.cts.map +1 -1
  525. package/build/relations/ReactiveManyToMany.d.mts +2 -2
  526. package/build/relations/ReactiveManyToMany.d.mts.map +1 -1
  527. package/build/relations/ReactiveManyToMany.js +3 -4
  528. package/build/relations/ReactiveManyToMany.js.map +1 -1
  529. package/build/relations/ReactiveManyToManyOtherSide.cjs +1 -3
  530. package/build/relations/ReactiveManyToManyOtherSide.cjs.map +1 -1
  531. package/build/relations/ReactiveManyToManyOtherSide.d.cts +2 -2
  532. package/build/relations/ReactiveManyToManyOtherSide.d.mts +2 -2
  533. package/build/relations/ReactiveManyToManyOtherSide.js +1 -3
  534. package/build/relations/ReactiveManyToManyOtherSide.js.map +1 -1
  535. package/build/relations/ReactiveReference.cjs +8 -9
  536. package/build/relations/ReactiveReference.cjs.map +1 -1
  537. package/build/relations/ReactiveReference.d.cts +2 -2
  538. package/build/relations/ReactiveReference.d.cts.map +1 -1
  539. package/build/relations/ReactiveReference.d.mts +2 -2
  540. package/build/relations/ReactiveReference.d.mts.map +1 -1
  541. package/build/relations/ReactiveReference.js +6 -7
  542. package/build/relations/ReactiveReference.js.map +1 -1
  543. package/build/relations/ReadOnlyCollection.cjs.map +1 -1
  544. package/build/relations/ReadOnlyCollection.js.map +1 -1
  545. package/build/relations/RecursiveCollection.cjs +3 -4
  546. package/build/relations/RecursiveCollection.cjs.map +1 -1
  547. package/build/relations/RecursiveCollection.d.cts +1 -1
  548. package/build/relations/RecursiveCollection.d.mts +1 -1
  549. package/build/relations/RecursiveCollection.js +3 -4
  550. package/build/relations/RecursiveCollection.js.map +1 -1
  551. package/build/relations/RecursiveCycleError.cjs.map +1 -1
  552. package/build/relations/RecursiveCycleError.js.map +1 -1
  553. package/build/relations/Reference.cjs +1 -1
  554. package/build/relations/Reference.cjs.map +1 -1
  555. package/build/relations/Reference.js +1 -1
  556. package/build/relations/Reference.js.map +1 -1
  557. package/build/relations/Relation.cjs.map +1 -1
  558. package/build/relations/Relation.js.map +1 -1
  559. package/build/relations/hasAsyncMethod.cjs +2 -2
  560. package/build/relations/hasAsyncMethod.cjs.map +1 -1
  561. package/build/relations/hasAsyncMethod.d.cts +1 -1
  562. package/build/relations/hasAsyncMethod.d.mts +1 -1
  563. package/build/relations/hasAsyncMethod.js +1 -1
  564. package/build/relations/hasAsyncMethod.js.map +1 -1
  565. package/build/relations/hasManyDerived.cjs +3 -3
  566. package/build/relations/hasManyDerived.cjs.map +1 -1
  567. package/build/relations/hasManyDerived.d.cts +1 -1
  568. package/build/relations/hasManyDerived.d.mts +1 -1
  569. package/build/relations/hasManyDerived.js +2 -2
  570. package/build/relations/hasManyDerived.js.map +1 -1
  571. package/build/relations/hasManyThrough.cjs +6 -6
  572. package/build/relations/hasManyThrough.cjs.map +1 -1
  573. package/build/relations/hasManyThrough.d.cts +1 -1
  574. package/build/relations/hasManyThrough.d.mts +1 -1
  575. package/build/relations/hasManyThrough.js +2 -2
  576. package/build/relations/hasManyThrough.js.map +1 -1
  577. package/build/relations/hasOneDerived.cjs +3 -3
  578. package/build/relations/hasOneDerived.cjs.map +1 -1
  579. package/build/relations/hasOneDerived.d.cts +1 -1
  580. package/build/relations/hasOneDerived.d.mts +1 -1
  581. package/build/relations/hasOneDerived.js +2 -2
  582. package/build/relations/hasOneDerived.js.map +1 -1
  583. package/build/relations/hasOneThrough.cjs +7 -7
  584. package/build/relations/hasOneThrough.cjs.map +1 -1
  585. package/build/relations/hasOneThrough.d.cts +1 -1
  586. package/build/relations/hasOneThrough.d.mts +1 -1
  587. package/build/relations/hasOneThrough.js +2 -2
  588. package/build/relations/hasOneThrough.js.map +1 -1
  589. package/build/relations/hasProperty.cjs +4 -4
  590. package/build/relations/hasProperty.cjs.map +1 -1
  591. package/build/relations/hasProperty.d.cts +2 -2
  592. package/build/relations/hasProperty.d.mts +2 -2
  593. package/build/relations/hasProperty.js +2 -2
  594. package/build/relations/hasProperty.js.map +1 -1
  595. package/build/relations/index.cjs +10 -10
  596. package/build/relations/index.js +10 -10
  597. package/build/relations/isCascadeDelete.cjs.map +1 -1
  598. package/build/relations/isCascadeDelete.js.map +1 -1
  599. package/build/resurrection.cjs.map +1 -1
  600. package/build/resurrection.js.map +1 -1
  601. package/build/rules.cjs +3 -4
  602. package/build/rules.cjs.map +1 -1
  603. package/build/rules.d.cts +1 -1
  604. package/build/rules.d.mts +1 -1
  605. package/build/rules.js +3 -4
  606. package/build/rules.js.map +1 -1
  607. package/build/runtimeConfig.cjs.map +1 -1
  608. package/build/runtimeConfig.js.map +1 -1
  609. package/build/{TypeInfo.cjs → serde/TypeInfo.cjs} +1 -1
  610. package/build/serde/TypeInfo.cjs.map +1 -0
  611. package/build/{TypeInfo.d.cts → serde/TypeInfo.d.cts} +2 -2
  612. package/build/serde/TypeInfo.d.cts.map +1 -0
  613. package/build/{TypeInfo.d.mts → serde/TypeInfo.d.mts} +2 -2
  614. package/build/serde/TypeInfo.d.mts.map +1 -0
  615. package/build/{TypeInfo.js → serde/TypeInfo.js} +1 -1
  616. package/build/serde/TypeInfo.js.map +1 -0
  617. package/build/{columns.cjs → serde/columns.cjs} +1 -1
  618. package/build/serde/columns.cjs.map +1 -0
  619. package/build/{columns.d.cts → serde/columns.d.cts} +2 -2
  620. package/build/serde/columns.d.cts.map +1 -0
  621. package/build/{columns.d.mts → serde/columns.d.mts} +2 -2
  622. package/build/serde/columns.d.mts.map +1 -0
  623. package/build/{columns.js → serde/columns.js} +1 -1
  624. package/build/serde/columns.js.map +1 -0
  625. package/build/{fieldSerde.cjs → serde/fieldSerde.cjs} +6 -6
  626. package/build/serde/fieldSerde.cjs.map +1 -0
  627. package/build/{fieldSerde.d.cts → serde/fieldSerde.d.cts} +5 -5
  628. package/build/serde/fieldSerde.d.cts.map +1 -0
  629. package/build/{fieldSerde.d.mts → serde/fieldSerde.d.mts} +5 -5
  630. package/build/serde/fieldSerde.d.mts.map +1 -0
  631. package/build/{fieldSerde.js → serde/fieldSerde.js} +6 -6
  632. package/build/serde/fieldSerde.js.map +1 -0
  633. package/build/{serde.cjs → serde/serde.cjs} +25 -26
  634. package/build/serde/serde.cjs.map +1 -0
  635. package/build/{serde.d.cts → serde/serde.d.cts} +1 -1
  636. package/build/serde/serde.d.cts.map +1 -0
  637. package/build/{serde.d.mts → serde/serde.d.mts} +1 -1
  638. package/build/serde/serde.d.mts.map +1 -0
  639. package/build/{serde.js → serde/serde.js} +4 -5
  640. package/build/serde/serde.js.map +1 -0
  641. package/build/{temporal.cjs → serde/temporal.cjs} +1 -1
  642. package/build/serde/temporal.cjs.map +1 -0
  643. package/build/{temporal.d.cts → serde/temporal.d.cts} +1 -1
  644. package/build/serde/temporal.d.cts.map +1 -0
  645. package/build/{temporal.d.mts → serde/temporal.d.mts} +1 -1
  646. package/build/serde/temporal.d.mts.map +1 -0
  647. package/build/{temporal.js → serde/temporal.js} +1 -1
  648. package/build/serde/temporal.js.map +1 -0
  649. package/build/{temporalMappers.cjs → serde/temporalMappers.cjs} +4 -5
  650. package/build/serde/temporalMappers.cjs.map +1 -0
  651. package/build/{temporalMappers.d.cts → serde/temporalMappers.d.cts} +1 -1
  652. package/build/serde/temporalMappers.d.cts.map +1 -0
  653. package/build/{temporalMappers.d.mts → serde/temporalMappers.d.mts} +1 -1
  654. package/build/serde/temporalMappers.d.mts.map +1 -0
  655. package/build/{temporalMappers.js → serde/temporalMappers.js} +2 -3
  656. package/build/serde/temporalMappers.js.map +1 -0
  657. package/build/upsert.cjs +1 -1
  658. package/build/upsert.cjs.map +1 -1
  659. package/build/upsert.d.cts.map +1 -1
  660. package/build/upsert.d.mts.map +1 -1
  661. package/build/upsert.js +1 -1
  662. package/build/upsert.js.map +1 -1
  663. package/build/utils.cjs +0 -1
  664. package/build/utils.cjs.map +1 -1
  665. package/build/utils.d.cts +1 -1
  666. package/build/utils.d.mts +1 -1
  667. package/build/utils.js +0 -1
  668. package/build/utils.js.map +1 -1
  669. package/package.json +2 -2
  670. package/build/FlushLock.cjs.map +0 -1
  671. package/build/FlushLock.d.cts.map +0 -1
  672. package/build/FlushLock.d.mts.map +0 -1
  673. package/build/FlushLock.js.map +0 -1
  674. package/build/HintTree.cjs.map +0 -1
  675. package/build/HintTree.d.cts.map +0 -1
  676. package/build/HintTree.d.mts.map +0 -1
  677. package/build/HintTree.js.map +0 -1
  678. package/build/IsLoadedCache.d.cts.map +0 -1
  679. package/build/IsLoadedCache.d.mts.map +0 -1
  680. package/build/IsLoadedCache.js.map +0 -1
  681. package/build/JoinRows.cjs.map +0 -1
  682. package/build/JoinRows.d.cts.map +0 -1
  683. package/build/JoinRows.d.mts.map +0 -1
  684. package/build/JoinRows.js.map +0 -1
  685. package/build/PendingChanges.d.cts.map +0 -1
  686. package/build/PendingChanges.d.mts.map +0 -1
  687. package/build/PendingChanges.js +0 -2
  688. package/build/ReactionsManager.cjs.map +0 -1
  689. package/build/ReactionsManager.d.cts.map +0 -1
  690. package/build/ReactionsManager.d.mts.map +0 -1
  691. package/build/ReactionsManager.js.map +0 -1
  692. package/build/Todo.cjs.map +0 -1
  693. package/build/Todo.d.cts.map +0 -1
  694. package/build/Todo.d.mts.map +0 -1
  695. package/build/Todo.js.map +0 -1
  696. package/build/TypeInfo.cjs.map +0 -1
  697. package/build/TypeInfo.d.cts.map +0 -1
  698. package/build/TypeInfo.d.mts.map +0 -1
  699. package/build/TypeInfo.js.map +0 -1
  700. package/build/columns.cjs.map +0 -1
  701. package/build/columns.d.cts.map +0 -1
  702. package/build/columns.d.mts.map +0 -1
  703. package/build/columns.js.map +0 -1
  704. package/build/driverApi.cjs +0 -18
  705. package/build/driverApi.cjs.map +0 -1
  706. package/build/driverApi.d.cts +0 -22
  707. package/build/driverApi.d.cts.map +0 -1
  708. package/build/driverApi.d.mts +0 -22
  709. package/build/driverApi.d.mts.map +0 -1
  710. package/build/driverApi.js +0 -18
  711. package/build/driverApi.js.map +0 -1
  712. package/build/fieldSerde.cjs.map +0 -1
  713. package/build/fieldSerde.d.cts.map +0 -1
  714. package/build/fieldSerde.d.mts.map +0 -1
  715. package/build/fieldSerde.js.map +0 -1
  716. package/build/loadHints.cjs.map +0 -1
  717. package/build/loadHints.d.cts.map +0 -1
  718. package/build/loadHints.d.mts.map +0 -1
  719. package/build/loadHints.js.map +0 -1
  720. package/build/loadLens.cjs.map +0 -1
  721. package/build/loadLens.d.cts.map +0 -1
  722. package/build/loadLens.d.mts.map +0 -1
  723. package/build/loadLens.js.map +0 -1
  724. package/build/reactiveHints.cjs.map +0 -1
  725. package/build/reactiveHints.d.cts.map +0 -1
  726. package/build/reactiveHints.d.mts.map +0 -1
  727. package/build/reactiveHints.js.map +0 -1
  728. package/build/serde.cjs.map +0 -1
  729. package/build/serde.d.cts.map +0 -1
  730. package/build/serde.d.mts.map +0 -1
  731. package/build/serde.js.map +0 -1
  732. package/build/temporal.cjs.map +0 -1
  733. package/build/temporal.d.cts.map +0 -1
  734. package/build/temporal.d.mts.map +0 -1
  735. package/build/temporal.js.map +0 -1
  736. package/build/temporalMappers.cjs.map +0 -1
  737. package/build/temporalMappers.d.cts.map +0 -1
  738. package/build/temporalMappers.d.mts.map +0 -1
  739. package/build/temporalMappers.js.map +0 -1
  740. package/build/unnest.cjs.map +0 -1
  741. package/build/unnest.d.cts.map +0 -1
  742. package/build/unnest.d.mts.map +0 -1
  743. package/build/unnest.js.map +0 -1
  744. package/build/withLoaded.cjs.map +0 -1
  745. package/build/withLoaded.d.cts.map +0 -1
  746. package/build/withLoaded.d.mts.map +0 -1
  747. package/build/withLoaded.js.map +0 -1
package/build/index.d.mts CHANGED
@@ -1,6 +1,3 @@
1
- import { Temporal, maybeRequireTemporal, requireTemporal } from "./temporal.mjs";
2
- import { BigIntSerde, CustomSerde, CustomSerdeAdapter, DateSerde, DecimalToNumberSerde, EnumArrayFieldSerde, EnumFieldSerde, JsonSerde, KeySerde, PlainDateSerde, PlainDateTimeSerde, PlainTimeSerde, PrimitiveSerde, ScalarCodec, SuperstructSerde, TimestampCodec, ZodSerde, ZonedDateTimeSerde } from "./serde.mjs";
3
- import { Column, ColumnDescriptors } from "./columns.mjs";
4
1
  import { ActualFactoryOpts, ColumnsOf, EntityOf, FactoryExtrasOf, FieldsOf, FilterOf, GraphQLFilterOf, InheritanceTypeOf, OptIdsOf, OptsOf, OrderOf, RelationsOf, RootTypeNameOf, TypeMap, TypeMapEntry, TypeNameOf } from "./typeMap.mjs";
5
2
  import { Changes, EntityChanges, EnumCollectionFieldStatus, FieldStatus, ManyToManyFieldStatus, ManyToOneFieldStatus, OneToManyFieldStatus, PrimitiveFieldStatus, newChangesProxy } from "./changes.mjs";
6
3
  import { deepNormalizeHint, normalizeHint } from "./normalizeHints.mjs";
@@ -31,9 +28,9 @@ import { PolymorphicReference, PolymorphicReferenceImpl, hasOnePolymorphic, isPo
31
28
  import { ReactiveField, hasReactiveField, isReactiveField } from "./relations/ReactiveField.mjs";
32
29
  import { ReactiveGetter, hasReactiveGetter, isReactiveGetter } from "./relations/ReactiveGetter.mjs";
33
30
  import { ReactiveManyToMany, ReactiveManyToManyImpl, hasReactiveManyToMany, isReactiveManyToMany } from "./relations/ReactiveManyToMany.mjs";
34
- import { JoinRowTodo, Todo } from "./Todo.mjs";
31
+ import { JoinRowTodo, Todo } from "./flush/Todo.mjs";
35
32
  import { ReactionLogger, setReactionLogging } from "./logging/ReactionLogger.mjs";
36
- import { JoinColumnValue, JoinRow, JoinRowOperation, ManyToManyLike } from "./JoinRows.mjs";
33
+ import { JoinColumnValue, JoinRow, JoinRowOperation, ManyToManyLike } from "./flush/JoinRows.mjs";
37
34
  import { ReactiveManyToManyOtherSide, ReactiveManyToManyOtherSideImpl, hasReactiveManyToManyOtherSide, isReactiveManyToManyOtherSide } from "./relations/ReactiveManyToManyOtherSide.mjs";
38
35
  import { hasAsyncReactiveField, isAsyncReactiveField } from "./relations/AsyncReactiveField.mjs";
39
36
  import { ReactiveReference, ReactiveReferenceImpl, hasReactiveReference, isReactiveReference } from "./relations/ReactiveReference.mjs";
@@ -49,16 +46,19 @@ import { BooleanGraphQLFilter, EntityGraphQLFilter, GraphQLFilterAndSettings, Gr
49
46
  import { AliasFn, ResolvedScope, Scope, ScopeFilterFragment, ScopeFn, ScopeJoinFilter, ScopeQuery, isScope, isScopeJoinFilter, isSelectAllFilter, newScopeFn, resolveScope } from "./queries/find/scopes.mjs";
50
47
  import { BooleanFilter, EntityFilter, EntityFilterObject, ExpressionCondition, ExpressionFilter, FilterAndSettings, FilterWithAlias, FindFilter, OrderBy, UniqueFilter, ValueFilter, mergeFindOptions } from "./queries/find/EntityFilter.mjs";
51
48
  import { abbreviation, asNew, assertNever, cleanSql, cleanStringValue, fail, failIfAnyRejected, indexBy, partition, zeroTo } from "./utils.mjs";
52
- import { DeepNew, LoadHint, Loadable, Loaded, MarkLoaded, NestedLoadHint, New, RelationsIn, assertLoaded, ensureLoaded, isLoaded, isNew, maybePopulateThen, unsafeLoaded } from "./loadHints.mjs";
53
- import { Reactable, Reacted, ReactiveHint, ReactiveTarget, convertToLoadHint, isTypeOrSubType, reverseReactiveHint } from "./reactiveHints.mjs";
49
+ import { DeepNew, LoadHint, Loadable, Loaded, MarkLoaded, NestedLoadHint, New, RelationsIn, assertLoaded, ensureLoaded, isLoaded, isNew, maybePopulateThen, unsafeLoaded } from "./loading/loadHints.mjs";
50
+ import { Reactable, Reacted, ReactiveHint, ReactiveTarget, convertToLoadHint, isTypeOrSubType, reverseReactiveHint } from "./reactivity/reactiveHints.mjs";
54
51
  import { GenericError, ValidationCode, ValidationError, ValidationErrors, ValidationRule, ValidationRuleInternal, ValidationRuleResult, cannotBeChanged, cannotBeUpdated, maxValueRule, minValueRule, mustBeSubType, newRequiredLazyFieldRule, newRequiredRule, rangeValueRule } from "./rules.mjs";
55
52
  import { ConfigApi, EntityHook, resetBootFlag } from "./config.mjs";
53
+ import { Temporal, maybeRequireTemporal, requireTemporal } from "./serde/temporal.mjs";
54
+ import { BigIntSerde, CustomSerde, CustomSerdeAdapter, DateSerde, DecimalToNumberSerde, EnumArrayFieldSerde, EnumFieldSerde, JsonSerde, KeySerde, PlainDateSerde, PlainDateTimeSerde, PlainTimeSerde, PrimitiveSerde, ScalarCodec, SuperstructSerde, TimestampCodec, ZodSerde, ZonedDateTimeSerde } from "./serde/serde.mjs";
55
+ import { Column, ColumnDescriptors } from "./serde/columns.mjs";
56
56
  import { DeleteOp, InsertFixup, InsertOp, OpColumn, UpdateOp, generateOps } from "./drivers/EntityWriter.mjs";
57
57
  import { PojoRowData, RowData, emptyRowData } from "./RowData.mjs";
58
- import { FieldColumn, FieldSerde, PolyComponent, PolymorphicKeySerde, SimpleFieldSerde, TimestampSerde, hasSerde, polymorphicField } from "./fieldSerde.mjs";
58
+ import { FieldColumn, FieldSerde, PolyComponent, PolymorphicKeySerde, SimpleFieldSerde, TimestampSerde, hasSerde, polymorphicField } from "./serde/fieldSerde.mjs";
59
59
  import { EntityMetadata, EnumField, Field, LargeOneToManyField, ManyToManyEnumField, ManyToManyField, ManyToOneField, OneToManyField, OneToOneField, PolymorphicField, PolymorphicFieldComponent, PrimaryKeyField, PrimitiveField, SerdeField, getBaseAndSelfMetas, getBaseMeta, getBaseSelfAndSubMetas, getMetadata, getMetadataForField, getSubMetas, isCollectionField, isManyToManyEnumField, isManyToManyField, isManyToOneField, isOneToManyField, isOneToOneField, isPolymorphicField, isReferenceField } from "./EntityMetadata.mjs";
60
60
  import { getDefaultDependencies } from "./defaults.mjs";
61
- import { Lens, getLens, getLensPath, isAllSqlPaths, isLensLoaded, isLensLoadedPath, lensPathToLoadHint, lensToLoadHint, lensToPath, loadLens, loadLensPath, mapPathsToTarget } from "./loadLens.mjs";
61
+ import { Lens, getLens, getLensPath, isAllSqlPaths, isLensLoaded, isLensLoadedPath, lensPathToLoadHint, lensToLoadHint, lensToPath, loadLens, loadLensPath, mapPathsToTarget } from "./loading/loadLens.mjs";
62
62
  import { partitionHint } from "./preloading/partitionHint.mjs";
63
63
  import { SubqueryRenderer, buildValueCondition, buildWhereClause } from "./queries/renderConditions.mjs";
64
64
  import { AliasAssigner } from "./queries/sql/AliasAssigner.mjs";
@@ -70,13 +70,13 @@ import { ArrayAggOptions, Expr, ExprBrand, ExprLike, InnerJoin, LeftJoin, exprBr
70
70
  import { CollectionJoin, EntityColumn, PolyReference, PrimitiveColumn, ReferenceColumn, ReferenceJoin, Table, TableBrand, TableFilter, TableFor, TableMgmt, getTableMetadata, getTableMgmt, isTable, newTableProxy, table, tableMgmt, tables } from "./queries/sql/Tables.mjs";
71
71
  import { ConditionBuilder } from "./queries/ConditionBuilder.mjs";
72
72
  import { EntityField, EntityFields, SettableFields } from "./EntityFields.mjs";
73
- import { EntityOrId, HintNode } from "./HintTree.mjs";
73
+ import { EntityOrId, HintNode } from "./loading/HintTree.mjs";
74
74
  import { JoinResult, PreloadHydrator, PreloadPlugin } from "./plugins/PreloadPlugin.mjs";
75
75
  import { Driver, DriverQueryResult } from "./drivers/Driver.mjs";
76
76
  import { DeleteStatement, ExecuteResult, InsertStatement, InsertValues, MutationReturning, MutationStatement, UpdateStatement, UpdateValues } from "./queries/sql/execute.mjs";
77
77
  import { skipCondition } from "./queries/skipCondition.mjs";
78
78
  import { InstanceData } from "./InstanceData.mjs";
79
- import { PendingChange, PendingCreate, PendingDelete, PendingM2M, PendingUpdate } from "./PendingChanges.mjs";
79
+ import { PendingChange, PendingCreate, PendingDelete, PendingM2M, PendingUpdate } from "./flush/PendingChanges.mjs";
80
80
  import { Plugin } from "./PluginManager.mjs";
81
81
  import { buildCteSql, buildRawQuery } from "./queries/find/buildFindQuery.mjs";
82
82
  import { ParsedEntityFilter, makeLike, mapToDb, parseEntityFilter, parseValueFilter } from "./queries/valueFilters.mjs";
@@ -85,7 +85,7 @@ import { optimizeCollectionJoins } from "./queries/find/QueryParser.collectionJo
85
85
  import { visitConditions } from "./queries/find/QueryVisitor.mjs";
86
86
  import { configureMetadata, getConstructorFromTaggedId, getMetadataForTable, getMetadataForType, maybeGetConstructorFromReference } from "./configure.mjs";
87
87
  import { RuntimeConfig, getRuntimeConfig, setRuntimeConfig } from "./runtimeConfig.mjs";
88
- import { driverApi } from "./driverApi.mjs";
88
+ import { driverApi } from "./drivers/driverApi.mjs";
89
89
  import { IdAssigner, RandomUuidAssigner, SequenceIdAssigner, TestUuidAssigner } from "./drivers/IdAssigner.mjs";
90
90
  import "./drivers/index.mjs";
91
91
  import { getField, isChangeableField, isFieldSet, setField } from "./fields.mjs";
@@ -100,11 +100,11 @@ import { FieldLogger, FieldLoggerWatch, WriteFn, noopFieldLogger } from "./loggi
100
100
  import { ImmutableEntitiesPlugin } from "./plugins/ImmutableEntitiesPlugin.mjs";
101
101
  import { JsonAggregatePreloader } from "./preloading/JsonAggregatePreloader.mjs";
102
102
  import { nowUTC } from "./nowUTC.mjs";
103
- import { plainDateMapper, plainDateTimeMapper, plainTimeMapper, zonedDateTimeMapper } from "./temporalMappers.mjs";
103
+ import { plainDateMapper, plainDateTimeMapper, plainTimeMapper, zonedDateTimeMapper } from "./serde/temporalMappers.mjs";
104
104
  import { isInTrustedContext, runInTrustedContext } from "./trusted.mjs";
105
- import { buildUnnestCte, ensureRectangularArraySizes } from "./unnest.mjs";
105
+ import { buildUnnestCte, ensureRectangularArraySizes } from "./queries/unnest.mjs";
106
106
  import { DeepPartialOrNull, updatePartial, upsert } from "./upsert.mjs";
107
- import { StubbedRelation, WithLoaded, ensureWithLoaded, withLoaded } from "./withLoaded.mjs";
107
+ import { StubbedRelation, WithLoaded, ensureWithLoaded, withLoaded } from "./loading/withLoaded.mjs";
108
108
  import { EntityConstructor, EntityManager, EntityManagerHook, EntityManagerInternalApi, EntityManagerMode, EntityManagerOpts, FindCountFilterOptions, FindFilterOptions, FindGqlFilterOptions, FindOperation, FlushOptions, IdOf, LoaderCache, MaybeAbstractEntityConstructor, NotFoundError, ReadOnlyError, TaggedId, TimestampFields, TooManyError, appendStack, createRowFromEntityData, driverAfterBegin, driverAfterCommit, driverBeforeBegin, driverBeforeCommit, getDefaultEntityLimit, getEmInternalApi, isDefined, isId, isKey, resetDefaultEntityLimit, sameEntity, sameReference, setDefaultEntityLimit, setLastNow } from "./EntityManager.mjs";
109
109
  import { Entity, IdType, isEntity } from "./Entity.mjs";
110
110
  import { BaseEntity, getInstanceData } from "./BaseEntity.mjs";
package/build/index.js CHANGED
@@ -1,70 +1,66 @@
1
- import { Column } from "./columns.js";
2
1
  import { isCollection, isLoadedCollection } from "./relations/Collection.js";
3
- import { Temporal, maybeRequireTemporal, requireTemporal } from "./temporal.js";
4
- import { getField, isChangeableField, isFieldSet, setField } from "./fields.js";
5
- import { Todo } from "./Todo.js";
6
- import { ReactionLogger, setReactionLogging } from "./logging/ReactionLogger.js";
7
- import { isInTrustedContext, runInTrustedContext } from "./trusted.js";
8
- import { JoinRowOperation } from "./JoinRows.js";
9
2
  import { AbstractRelationImpl } from "./relations/AbstractRelationImpl.js";
3
+ import { CustomCollection, hasCustomCollection } from "./relations/CustomCollection.js";
10
4
  import { EnumCollectionImpl, hasEnumCollection } from "./relations/EnumCollection.js";
11
- import { kq, kqDot, kqStar } from "./queries/sql/keywords.js";
12
- import { PojoRowData, emptyRowData } from "./RowData.js";
5
+ import { CustomReference, hasCustomReference } from "./relations/CustomReference.js";
6
+ import { deepNormalizeHint, normalizeHint } from "./normalizeHints.js";
7
+ import { hasReactiveGetter, isReactiveGetter } from "./relations/ReactiveGetter.js";
8
+ import { isRelation } from "./relations/Relation.js";
9
+ import { isLoadedReadOnlyCollection, isReadOnlyCollection } from "./relations/ReadOnlyCollection.js";
13
10
  import { RecursiveCycleError } from "./relations/RecursiveCycleError.js";
11
+ import { hasRecursiveChildren, hasRecursiveM2m, hasRecursiveParents } from "./relations/RecursiveCollection.js";
12
+ import { convertToLoadHint, isTypeOrSubType, reverseReactiveHint } from "./reactivity/reactiveHints.js";
13
+ import { assertLoaded, ensureLoaded, isLoaded, isNew, maybePopulateThen, unsafeLoaded } from "./loading/loadHints.js";
14
+ import { hasAsyncMethod } from "./relations/hasAsyncMethod.js";
14
15
  import { PropertyImpl, hasProperty, hasReactiveProperty, isLoadedProperty, isProperty } from "./relations/hasProperty.js";
16
+ import { AsyncPropertyImpl, hasAsyncProperty, isAsyncProperty, isLoadedAsyncProperty } from "./relations/AsyncProperty.js";
17
+ import { Temporal, maybeRequireTemporal, requireTemporal } from "./serde/temporal.js";
18
+ import { getField, isChangeableField, isFieldSet, setField } from "./fields.js";
19
+ import { assertIdIsTagged, assertIdsAreTagged, deTagId, deTagIds, ensureTagged, isTaggedId, keyToNumber, keyToTaggedId, maybeResolveReferenceToId, setTaggedIdDelimiter, tagFromId, tagId, tagIds, toIdOf, toTaggedId, unsafeDeTagIds } from "./keys.js";
20
+ import { kq, kqDot, kqStar } from "./queries/sql/keywords.js";
21
+ import { PojoRowData, emptyRowData } from "./RowData.js";
15
22
  import { LazyFieldImpl, hasLazyField, isLazyField, isLoadedLazyField } from "./relations/LazyField.js";
16
- import "./typeMap.js";
17
- import { newChangesProxy } from "./changes.js";
23
+ import { hasManyDerived } from "./relations/hasManyDerived.js";
24
+ import { hasManyThrough } from "./relations/hasManyThrough.js";
25
+ import { isLoadedReference, isReference } from "./relations/Reference.js";
26
+ import { hasOneDerived } from "./relations/hasOneDerived.js";
27
+ import { hasOneThrough } from "./relations/hasOneThrough.js";
28
+ import { ManyToManyCollection, hasManyToMany } from "./relations/ManyToManyCollection.js";
29
+ import { ManyToManyLargeCollection, hasLargeManyToMany } from "./relations/ManyToManyLargeCollection.js";
18
30
  import { skipCondition } from "./queries/skipCondition.js";
19
31
  import { alias, aliases, getAliasMetadata, getAliasMgmt, getMaybeCtiAlias, isAlias, newAliasProxy } from "./queries/find/Aliases.js";
20
32
  import { isScope, isScopeJoinFilter, isSelectAllFilter, newScopeFn, resolveScope } from "./queries/find/scopes.js";
21
33
  import { makeLike, mapToDb, parseEntityFilter, parseValueFilter } from "./queries/valueFilters.js";
22
34
  import { ConditionBuilder } from "./queries/ConditionBuilder.js";
23
35
  import { filterSoftDeletes, lazyExcludedSelects, maybeAddNotSoftDeleted, stiSubtypeFilter } from "./queries/entityQueryUtils.js";
24
- import { exprBrand } from "./queries/sql/Expr.js";
25
36
  import { visitConditions } from "./queries/find/QueryVisitor.js";
37
+ import { exprBrand } from "./queries/sql/Expr.js";
26
38
  import { addTablePerClassJoinsAndClassTag, findFilterField, getTables, maybeAddIdNotNulls, maybeAddOrderBy, parseAlias, parseFindQuery } from "./queries/find/QueryParser.js";
27
39
  import { OneToManyCollection, hasMany } from "./relations/OneToManyCollection.js";
28
40
  import { ManyToOneReferenceImpl, hasOne, isManyToOneReference } from "./relations/ManyToOneReference.js";
29
- import { isLoadedReference, isReference } from "./relations/Reference.js";
41
+ import { OneToManyLargeCollection, hasLargeMany } from "./relations/OneToManyLargeCollection.js";
30
42
  import { ReactiveReferenceImpl, hasReactiveReference, isReactiveReference } from "./relations/ReactiveReference.js";
31
43
  import { OneToOneReferenceImpl, hasOneToOne, isLoadedOneToOneReference, isOneToOneReference } from "./relations/OneToOneReference.js";
32
- import { hasReactiveGetter, isReactiveGetter } from "./relations/ReactiveGetter.js";
33
- import { isRelation } from "./relations/Relation.js";
34
- import { isLoadedReadOnlyCollection, isReadOnlyCollection } from "./relations/ReadOnlyCollection.js";
35
- import { hasRecursiveChildren, hasRecursiveM2m, hasRecursiveParents } from "./relations/RecursiveCollection.js";
36
- import { convertToLoadHint, isTypeOrSubType, reverseReactiveHint } from "./reactiveHints.js";
37
- import { deepNormalizeHint, normalizeHint } from "./normalizeHints.js";
38
- import { assertLoaded, ensureLoaded, isLoaded, isNew, maybePopulateThen, unsafeLoaded } from "./loadHints.js";
39
- import { abbreviation, asNew, assertNever, cleanSql, cleanStringValue, fail, failIfAnyRejected, indexBy, partition, zeroTo } from "./utils.js";
40
- import { UnknownProperty, getLazyFields, getProperties } from "./getProperties.js";
41
- import { lazyField } from "./newEntity.js";
42
- import { CustomCollection, hasCustomCollection } from "./relations/CustomCollection.js";
43
- import { CustomReference, hasCustomReference } from "./relations/CustomReference.js";
44
- import { hasAsyncMethod } from "./relations/hasAsyncMethod.js";
45
- import { AsyncPropertyImpl, hasAsyncProperty, isAsyncProperty, isLoadedAsyncProperty } from "./relations/AsyncProperty.js";
46
- import { hasManyDerived } from "./relations/hasManyDerived.js";
47
- import { hasManyThrough } from "./relations/hasManyThrough.js";
48
- import { hasOneDerived } from "./relations/hasOneDerived.js";
49
- import { hasOneThrough } from "./relations/hasOneThrough.js";
50
- import { ManyToManyCollection, hasManyToMany } from "./relations/ManyToManyCollection.js";
51
- import { ManyToManyLargeCollection, hasLargeManyToMany } from "./relations/ManyToManyLargeCollection.js";
52
- import { OneToManyLargeCollection, hasLargeMany } from "./relations/OneToManyLargeCollection.js";
53
44
  import { PolymorphicReferenceImpl, hasOnePolymorphic, isPolymorphicReference } from "./relations/PolymorphicReference.js";
54
45
  import { ReactiveFieldImpl, hasReactiveField, isReactiveField } from "./relations/ReactiveField.js";
55
46
  import { ReactiveManyToManyImpl, hasReactiveManyToMany, isReactiveManyToMany } from "./relations/ReactiveManyToMany.js";
56
47
  import { ReactiveManyToManyOtherSideImpl, hasReactiveManyToManyOtherSide, isReactiveManyToManyOtherSide } from "./relations/ReactiveManyToManyOtherSide.js";
57
48
  import { AsyncReactiveFieldImpl, hasAsyncReactiveField, isAsyncReactiveField } from "./relations/AsyncReactiveField.js";
58
49
  import "./relations/index.js";
59
- import { assertIdIsTagged, assertIdsAreTagged, deTagId, deTagIds, ensureTagged, isTaggedId, keyToNumber, keyToTaggedId, maybeResolveReferenceToId, setTaggedIdDelimiter, tagFromId, tagId, tagIds, toIdOf, toTaggedId, unsafeDeTagIds } from "./keys.js";
60
- import { FieldColumn, PolyComponent, PolymorphicKeySerde, SimpleFieldSerde, hasSerde, polymorphicField } from "./fieldSerde.js";
50
+ import { abbreviation, asNew, assertNever, cleanSql, cleanStringValue, fail, failIfAnyRejected, indexBy, partition, zeroTo } from "./utils.js";
51
+ import { lazyField } from "./newEntity.js";
52
+ import { UnknownProperty, getLazyFields, getProperties } from "./getProperties.js";
53
+ import "./typeMap.js";
54
+ import { newChangesProxy } from "./changes.js";
61
55
  import { ValidationCode, ValidationErrors, cannotBeChanged, cannotBeUpdated, maxValueRule, minValueRule, mustBeSubType, newRequiredLazyFieldRule, newRequiredRule, rangeValueRule } from "./rules.js";
62
56
  import { getRuntimeConfig, setRuntimeConfig } from "./runtimeConfig.js";
57
+ import { FieldColumn, PolyComponent, PolymorphicKeySerde, SimpleFieldSerde, hasSerde, polymorphicField } from "./serde/fieldSerde.js";
63
58
  import { configureMetadata, getConstructorFromTaggedId, getMetadataForTable, getMetadataForType, maybeGetConstructorFromReference } from "./configure.js";
64
59
  import { ConfigApi, resetBootFlag } from "./config.js";
65
60
  import { getBaseAndSelfMetas, getBaseMeta, getBaseSelfAndSubMetas, getMetadata, getMetadataForField, getSubMetas, isCollectionField, isManyToManyEnumField, isManyToManyField, isManyToOneField, isOneToManyField, isOneToOneField, isPolymorphicField, isReferenceField } from "./EntityMetadata.js";
61
+ import { isInTrustedContext, runInTrustedContext } from "./trusted.js";
66
62
  import { getDefaultDependencies } from "./defaults.js";
67
- import { getLens, getLensPath, isAllSqlPaths, isLensLoaded, isLensLoadedPath, lensPathToLoadHint, lensToLoadHint, lensToPath, loadLens, loadLensPath, mapPathsToTarget } from "./loadLens.js";
63
+ import { getLens, getLensPath, isAllSqlPaths, isLensLoaded, isLensLoadedPath, lensPathToLoadHint, lensToLoadHint, lensToPath, loadLens, loadLensPath, mapPathsToTarget } from "./loading/loadLens.js";
68
64
  import { setFactoryWriter } from "./logging/FactoryLogger.js";
69
65
  import { FactoryInitialValue, defaultValue, factories, getTestIndex, isFactoryCreation, maybeBranchValue, maybeNew, maybeNewPoly, newTestInstance, noValue, setFactoryLogging, testIndex } from "./newTestInstance.js";
70
66
  import { partitionHint } from "./preloading/partitionHint.js";
@@ -75,24 +71,28 @@ import { getTableMetadata, getTableMgmt, isTable, newTableProxy, table, tableMgm
75
71
  import { mergeFindOptions } from "./queries/find/EntityFilter.js";
76
72
  import { expr } from "./queries/sql/expressions/expression.js";
77
73
  import { InstanceData } from "./InstanceData.js";
74
+ import { JoinRowOperation } from "./flush/JoinRows.js";
78
75
  import { Plugin } from "./PluginManager.js";
79
76
  import { buildCteSql, buildRawQuery } from "./queries/find/buildFindQuery.js";
80
77
  import { optimizeCollectionJoins } from "./queries/find/QueryParser.collectionJoins.js";
78
+ import { Todo } from "./flush/Todo.js";
79
+ import { plainDateMapper, plainDateTimeMapper, plainTimeMapper, zonedDateTimeMapper } from "./serde/temporalMappers.js";
80
+ import { buildUnnestCte, ensureRectangularArraySizes } from "./queries/unnest.js";
81
81
  import { generateOps } from "./drivers/EntityWriter.js";
82
- import { buildUnnestCte, ensureRectangularArraySizes } from "./unnest.js";
83
- import { BigIntSerde, CustomSerdeAdapter, DateSerde, DecimalToNumberSerde, EnumArrayFieldSerde, EnumFieldSerde, JsonSerde, KeySerde, PlainDateSerde, PlainDateTimeSerde, PlainTimeSerde, PrimitiveSerde, SuperstructSerde, ZodSerde, ZonedDateTimeSerde } from "./serde.js";
84
- import { plainDateMapper, plainDateTimeMapper, plainTimeMapper, zonedDateTimeMapper } from "./temporalMappers.js";
85
- import { driverApi } from "./driverApi.js";
82
+ import { driverApi } from "./drivers/driverApi.js";
86
83
  import { RandomUuidAssigner, SequenceIdAssigner, TestUuidAssigner } from "./drivers/IdAssigner.js";
87
84
  import "./drivers/index.js";
88
85
  import { toJSON } from "./json.js";
89
86
  import { FieldLogger, noopFieldLogger } from "./logging/FieldLogger.js";
87
+ import { ReactionLogger, setReactionLogging } from "./logging/ReactionLogger.js";
90
88
  import { ImmutableEntitiesPlugin } from "./plugins/ImmutableEntitiesPlugin.js";
91
89
  import { JsonAggregatePreloader } from "./preloading/JsonAggregatePreloader.js";
92
90
  import { entityQueryBrand, query, queryMaybe, recursiveQuery, sql, subqueryBrand } from "./queries/sql/query.js";
93
91
  import { nowUTC } from "./nowUTC.js";
92
+ import { BigIntSerde, CustomSerdeAdapter, DateSerde, DecimalToNumberSerde, EnumArrayFieldSerde, EnumFieldSerde, JsonSerde, KeySerde, PlainDateSerde, PlainDateTimeSerde, PlainTimeSerde, PrimitiveSerde, SuperstructSerde, ZodSerde, ZonedDateTimeSerde } from "./serde/serde.js";
93
+ import { Column } from "./serde/columns.js";
94
94
  import { updatePartial, upsert } from "./upsert.js";
95
- import { StubbedRelation, ensureWithLoaded, withLoaded } from "./withLoaded.js";
95
+ import { StubbedRelation, ensureWithLoaded, withLoaded } from "./loading/withLoaded.js";
96
96
  import { EntityManager, NotFoundError, ReadOnlyError, TooManyError, appendStack, createRowFromEntityData, driverAfterBegin, driverAfterCommit, driverBeforeBegin, driverBeforeCommit, getDefaultEntityLimit, getEmInternalApi, isDefined, isId, isKey, resetDefaultEntityLimit, sameEntity, sameReference, setDefaultEntityLimit, setLastNow } from "./EntityManager.js";
97
97
  import { isEntity } from "./Entity.js";
98
98
  import { BaseEntity, getInstanceData } from "./BaseEntity.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { getInstanceData } from \"./BaseEntity.ts\";\nimport { getDefaultDependencies } from \"./defaults.ts\";\nimport { type Entity } from \"./Entity.ts\";\nimport { type EntityConstructor, type MaybeAbstractEntityConstructor } from \"./EntityManager.ts\";\nimport { type EntityMetadata, getBaseMeta, getMetadata } from \"./EntityMetadata.ts\";\nimport { getField, setField } from \"./fields.ts\";\nimport { getProperties } from \"./getProperties.ts\";\nimport { type New } from \"./loadHints.ts\";\nimport { isAllSqlPaths } from \"./loadLens.ts\";\nimport { FactoryInitialValue } from \"./newTestInstance.ts\";\nimport { partitionHint } from \"./preloading/partitionHint.ts\";\nimport { buildWhereClause } from \"./queries/renderConditions.ts\";\nimport { AbstractRelationImpl } from \"./relations/AbstractRelationImpl.ts\";\nimport { AsyncReactiveFieldImpl } from \"./relations/AsyncReactiveField.ts\";\nimport {\n isAsyncProperty,\n isAsyncReactiveField,\n isLazyField,\n isProperty,\n isReactiveField,\n isReactiveGetter,\n} from \"./relations/index.ts\";\nimport { ReactiveFieldImpl } from \"./relations/ReactiveField.ts\";\nimport { type OptsOf } from \"./typeMap.ts\";\nimport { fail } from \"./utils.ts\";\n\nexport const testing = { isAllSqlPaths, getDefaultDependencies, partitionHint };\nexport const internals = { buildWhereClause };\nexport { newPgConnectionConfig } from \"joist-utils\";\nexport { AliasAssigner } from \"./queries/sql/AliasAssigner.ts\";\nexport {\n type AndCondition,\n type ConditionGroup,\n type DomainPredicate,\n type OrCondition,\n type PredicateBrand,\n type SqlCondition,\n type SqlPredicate,\n} from \"./queries/conditions.ts\";\n// Domain aliases belong to em.find; physical table expressions belong to em.query/em.execute.\nexport {\n alias,\n aliases,\n getAliasMetadata,\n getAliasMgmt,\n getMaybeCtiAlias,\n isAlias,\n newAliasProxy,\n type Alias,\n type AliasBrand,\n type AliasMgmt,\n type AliasColumn,\n type EntityAlias,\n type PolyAlias,\n type PrimitiveAlias,\n} from \"./queries/find/Aliases.ts\";\nexport {\n table,\n tables,\n tableMgmt,\n getTableMetadata,\n getTableMgmt,\n isTable,\n newTableProxy,\n type Table,\n type TableFilter,\n type TableBrand,\n type TableFor,\n type TableMgmt,\n type ReferenceJoin,\n type PrimitiveColumn,\n type EntityColumn,\n type ReferenceColumn,\n type CollectionJoin,\n type PolyReference,\n} from \"./queries/sql/Tables.ts\";\nexport { BaseEntity, getInstanceData } from \"./BaseEntity.ts\";\nexport { ConditionBuilder } from \"./queries/ConditionBuilder.ts\";\nexport { type Entity, type IdType, isEntity } from \"./Entity.ts\";\nexport type * from \"./EntityFields.ts\";\nexport * from \"./queries/find/EntityFilter.ts\";\nexport * from \"./queries/find/EntityGraphQLFilter.ts\";\nexport * from \"./EntityManager.ts\";\nexport * from \"./EntityMetadata.ts\";\nexport type {\n DeleteStatement,\n ExecuteResult,\n InsertStatement,\n InsertValues,\n MutationReturning,\n MutationStatement,\n UpdateStatement,\n UpdateValues,\n} from \"./queries/sql/execute.ts\";\nexport type { EnumMetadata } from \"./EnumMetadata.ts\";\n// `em.query`'s expression surface. Only the user-facing types are re-exported: the runtime half\n// (BaseExpr, asNode, deferredCondition, the FnExpr/TemplateExpr node classes) stays internal to\n// joist-core, so `toSql`/`decode`/`encode` never show up as something a user could call.\nexport {\n type ArrayAggOptions,\n type Expr,\n type ExprBrand,\n exprBrand,\n type ExprLike,\n type InnerJoin,\n type LeftJoin,\n} from \"./queries/sql/Expr.ts\";\nexport {\n expr,\n type CaseElse,\n type CaseWhen,\n type ExprFromInput,\n type ExprInput,\n} from \"./queries/sql/expressions/expression.ts\";\nexport { skipCondition } from \"./queries/skipCondition.ts\";\nexport type { EntityOrId, HintNode } from \"./HintTree.ts\";\nexport { InstanceData } from \"./InstanceData.ts\";\nexport { type JoinColumnValue, type JoinRow, JoinRowOperation, type ManyToManyLike } from \"./JoinRows.ts\";\nexport type * from \"./PendingChanges.ts\";\nexport { Plugin } from \"./PluginManager.ts\";\nexport * from \"./queries/find/QueryParser.ts\";\nexport * from \"./queries/find/buildFindQuery.ts\";\nexport * from \"./queries/renderConditions.ts\";\nexport type {\n ColumnCondition,\n ExistsCondition,\n ParsedExpressionCondition,\n ParsedExpressionFilter,\n ParsedValueFilter,\n RawCondition,\n} from \"./queries/parsedConditions.ts\";\nexport {\n type ParsedEntityFilter,\n makeLike,\n mapToDb,\n parseEntityFilter,\n parseValueFilter,\n} from \"./queries/valueFilters.ts\";\nexport {\n filterSoftDeletes,\n lazyExcludedSelects,\n maybeAddNotSoftDeleted,\n stiSubtypeFilter,\n} from \"./queries/entityQueryUtils.ts\";\nexport * from \"./queries/find/QueryParser.collectionJoins.ts\";\nexport { visitConditions } from \"./queries/find/QueryVisitor.ts\";\nexport * from \"./RowData.ts\";\nexport { type JoinRowTodo, Todo } from \"./Todo.ts\";\nexport * from \"./changes.ts\";\nexport { ConfigApi, type EntityHook, resetBootFlag } from \"./config.ts\";\nexport {\n configureMetadata,\n getConstructorFromTaggedId,\n getMetadataForTable,\n getMetadataForType,\n maybeGetConstructorFromReference,\n} from \"./configure.ts\";\nexport { driverApi } from \"./driverApi.ts\";\nexport * from \"./drivers/index.ts\";\nexport { getField, isChangeableField, isFieldSet, setField } from \"./fields.ts\";\nexport * from \"./getProperties.ts\";\nexport * from \"./json.ts\";\nexport * from \"./keys.ts\";\nexport { kq, kqDot, kqStar } from \"./queries/sql/keywords.ts\";\nexport {\n assertLoaded,\n type DeepNew,\n ensureLoaded,\n isLoaded,\n isNew,\n type Loadable,\n type Loaded,\n type LoadHint,\n type MarkLoaded,\n maybePopulateThen,\n type NestedLoadHint,\n type New,\n type RelationsIn,\n unsafeLoaded,\n} from \"./loadHints.ts\";\nexport * from \"./loadLens.ts\";\nexport { setFactoryWriter } from \"./logging/FactoryLogger.ts\";\nexport * from \"./logging/FieldLogger.ts\";\nexport { ReactionLogger, setReactionLogging } from \"./logging/ReactionLogger.ts\";\nexport { lazyField } from \"./newEntity.ts\";\nexport {\n defaultValue,\n factories,\n type FactoryEntityOpt,\n type FactoryOpts,\n getTestIndex,\n isFactoryCreation,\n maybeBranchValue,\n maybeNew,\n maybeNewPoly,\n newTestInstance,\n noValue,\n setFactoryLogging,\n testIndex,\n} from \"./newTestInstance.ts\";\nexport { deepNormalizeHint, normalizeHint } from \"./normalizeHints.ts\";\nexport { ImmutableEntitiesPlugin } from \"./plugins/ImmutableEntitiesPlugin.ts\";\nexport type { JoinResult, PreloadHydrator, PreloadPlugin } from \"./plugins/PreloadPlugin.ts\";\nexport { JsonAggregatePreloader } from \"./preloading/JsonAggregatePreloader.ts\";\n// `em.query`'s query surface; the parse pipeline (SubqueryHandle, parseUserQuery, Plan) stays internal\nexport {\n type CheckScope,\n type Clauses,\n type EntityQuery,\n type ExpressionOrderBy,\n type ExistsQuery,\n entityQueryBrand,\n type MaybeNull,\n type NameOf,\n type NotWidened,\n type OrderByDirection,\n type OrderByKeys,\n type Query,\n type QueryArg,\n type QueryCondition,\n type QueryJoin,\n type QueryJoins,\n type QueryRow,\n type QuerySelect,\n type QuerySource,\n type QueryValue,\n recursiveQuery,\n type RecursiveOptions,\n type ScalarQuery,\n type SetQuery,\n query,\n queryMaybe,\n sql,\n type Subquery,\n type SubqueryBrand,\n subqueryBrand,\n type WithInput,\n type WithSource,\n} from \"./queries/sql/query.ts\";\nexport {\n convertToLoadHint,\n isTypeOrSubType,\n type Reactable,\n type Reacted,\n type ReactiveHint,\n type ReactiveTarget,\n reverseReactiveHint,\n} from \"./reactiveHints.ts\";\nexport * from \"./relations/index.ts\";\nexport {\n cannotBeChanged,\n cannotBeUpdated,\n type GenericError,\n maxValueRule,\n minValueRule,\n mustBeSubType,\n newRequiredLazyFieldRule,\n newRequiredRule,\n rangeValueRule,\n ValidationCode,\n type ValidationError,\n ValidationErrors,\n type ValidationRule,\n type ValidationRuleInternal,\n type ValidationRuleResult,\n} from \"./rules.ts\";\nexport { getRuntimeConfig, setRuntimeConfig, type RuntimeConfig } from \"./runtimeConfig.ts\";\nexport { nowUTC } from \"./nowUTC.ts\";\nexport * from \"./serde.ts\";\nexport * from \"./columns.ts\";\nexport * from \"./fieldSerde.ts\";\nexport * from \"./queries/find/scopes.ts\";\nexport { maybeRequireTemporal, requireTemporal, Temporal } from \"./temporal.ts\";\nexport * from \"./temporalMappers.ts\";\nexport { isInTrustedContext, runInTrustedContext } from \"./trusted.ts\";\nexport type * from \"./typeMap.ts\";\nexport { buildUnnestCte, ensureRectangularArraySizes } from \"./unnest.ts\";\nexport { type DeepPartialOrNull, updatePartial, upsert } from \"./upsert.ts\";\nexport {\n abbreviation,\n asNew,\n assertNever,\n cleanSql,\n cleanStringValue,\n fail,\n failIfAnyRejected,\n indexBy,\n partition,\n zeroTo,\n} from \"./utils.ts\";\nexport { ensureWithLoaded, StubbedRelation, type WithLoaded, withLoaded } from \"./withLoaded.ts\";\n\n// https://spin.atomicobject.com/2018/01/15/typescript-flexible-nominal-typing/\ninterface Flavoring<FlavorT> {\n _type?: FlavorT;\n}\n\nexport type Flavor<T, FlavorT> = T & Flavoring<FlavorT>;\n\n/**\n * Sets each value in `values` on the current entity.\n *\n * The default behavior is that passing a value as either `null` or `undefined` will set\n * the field as `undefined`, i.e. automatic `null` to `undefined` conversion.\n *\n * However, if you pass `ignoreUndefined: true`, then any opt that is `undefined` will be treated\n * as \"do not set\", and `null` will still mean \"set to `undefined`\". This is useful for implementing\n * APIs were an input of `undefined` means \"do not set / noop\" and `null` means \"unset\".\n *\n * Note that constructors _always_ call this method, but if the call is coming from `em.hydrate`, we\n * use `values` being a primary key to short-circuit and let hydration callers assign the values\n * returned by the serde `fromRow` methods.\n */\nexport function setOpts<T extends Entity>(\n entity: T,\n values: Partial<OptsOf<T>> | undefined,\n opts?: { partial?: boolean; calledFromConstructor?: boolean },\n): void {\n const { calledFromConstructor = false, partial } = opts || {};\n // If `values` is undefined, we're being called by `createPartial` that will do its\n // own opt handling, but we still want the sync defaults applied after this opts handling.\n if (values !== undefined) {\n const meta = getMetadata(entity);\n for (const [key, _value] of Object.entries(values as {})) {\n setOpt(meta, entity, key, _value, partial, calledFromConstructor);\n }\n }\n}\n\n/**\n * Applies some standard behavior & protections to `entity[key] = value`. I.e.\n *\n * - We don't set over AsyncProperties/relations/etc., and instead call current.set(value)\n * - We catch missing/invalid field names\n * - We handle FactoryInitialValues\n */\nexport function setOpt<T extends Entity>(\n meta: EntityMetadata<T>,\n entity: T,\n key: string,\n _value: any,\n partial = false,\n calledFromConstructor = false,\n): void {\n const field = meta.allFields[key];\n if (!field) {\n // Allow setting non-field properties like fullName setters\n const prop = getProperties(meta)[key];\n if (!prop) {\n throw new Error(`Unknown field ${key}`);\n }\n }\n\n // If partial is set, we treat undefined as a noop\n if (partial && _value === undefined) return;\n // Ignore the STI discriminator, em.register will set this accordingly\n if (meta.inheritanceType === \"sti\" && getBaseMeta(meta).stiDiscriminatorField === key) return;\n\n // We let optional opts fields be `| null` for convenience, and convert to undefined.\n const value = _value === null ? undefined : _value;\n\n // Use `getField` to side-step `id` blowing up on new entities that are setting an\n // explicit id; otherwise use `entity[key]` to get back the relation.\n const current = key === \"id\" ? getField(entity, key) : (entity as any)[key];\n\n if (current instanceof AbstractRelationImpl) {\n if (calledFromConstructor) {\n current.setFromOpts(value);\n } else {\n current.set(value);\n }\n } else if (isLazyField(current)) {\n current.set(value);\n } else if (isProperty(current) || isAsyncProperty(current) || isReactiveGetter(current)) {\n throw new Error(`Invalid argument, cannot set over ${key} ${current.constructor.name}`);\n } else if (isReactiveField(current) || isAsyncReactiveField(current)) {\n if (value instanceof FactoryInitialValue) {\n if (current instanceof ReactiveFieldImpl) {\n current.setFactoryValue(value.value);\n } else if (current instanceof AsyncReactiveFieldImpl) {\n current.setFactoryValue(value.value);\n } else {\n throw new Error(`Unhandled case ${current.constructor.name}`);\n }\n } else {\n throw new Error(`Invalid argument, cannot set over ${key} ${current.constructor.name}`);\n }\n } else {\n // If setting an explicit id, go through setField, otherwise use\n // `entity[key]` to set the value directly to that we go through setters.\n if (key === \"id\" && entity.isNewEntity) {\n setField(entity, key, value);\n } else {\n (entity as any)[key] = value;\n }\n }\n}\n\nexport function ensureNotDeleted(entity: Entity, ignore?: \"pending\"): void {\n if (entity.isDeletedEntity && (ignore === undefined || getInstanceData(entity).isDeletedAndFlushed)) {\n fail(`${entity} is marked as deleted`);\n }\n}\n\n/** Adds `null` to every key in `T` to accept partial-update-style input. */\nexport type PartialOrNull<T> = {\n [P in keyof T]?: T[P] | null;\n};\n\nexport function getRequiredKeys<T extends Entity>(entity: T): string[];\nexport function getRequiredKeys<T extends Entity>(type: EntityConstructor<T>): string[];\nexport function getRequiredKeys<T extends Entity>(entityOrType: T | EntityConstructor<T>): string[] {\n return Object.values(getMetadata(entityOrType as any).fields)\n .filter((f) => f.required)\n .map((f) => f.fieldName);\n}\n\nexport function getRelations(entity: Entity): AbstractRelationImpl<any, any>[] {\n return Object.entries(getProperties(getMetadata(entity)))\n .filter(([, v]) => v instanceof AbstractRelationImpl)\n .map(([name]) => (entity as any)[name]);\n}\n\nexport function getRelationEntries(entity: Entity): [string, AbstractRelationImpl<any, any>][] {\n return Object.entries(getProperties(getMetadata(entity)))\n .filter(([, v]) => v instanceof AbstractRelationImpl)\n .map(([name]) => [name, (entity as any)[name]]);\n}\n\n/** Casts a \"maybe abstract\" cstr to a concrete cstr when the calling code knows it's safe. */\nexport function asConcreteCstr<T extends Entity>(cstr: MaybeAbstractEntityConstructor<T>): EntityConstructor<T> {\n return cstr as any;\n}\n\n/**\n * Thrown when `.id` is accessed on an entity that does not have an id yet.\n *\n * For Postgres, entities are actually allowed to have ids pre-INSERT, if you call\n * `em.assignNewIds()`. Other databases typically require INSERTs to trigger the auto\n * id assignment.\n */\nexport class NoIdError extends Error {}\n\n/** Throws a `NoIdError` for `entity`, i.e. because `id` was called before being saved. */\nexport function failNoIdYet(entity: string): never {\n throw new NoIdError(`${entity} has no id yet`);\n}\n\n/**\n * Add a static function since getters can't have type guards.\n *\n * See https://github.com/microsoft/TypeScript/issues/43368\n */\nexport function isNewEntity<T extends Entity>(entity: T): entity is New<T> {\n return entity.isNewEntity;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,UAAU;CAAE;CAAe;CAAwB;AAAc;AAC9E,MAAa,YAAY,EAAE,iBAAiB;;;;;;;;;;;;;;;AA8R5C,SAAgB,QACd,QACA,QACA,MACM;CACN,MAAM,EAAE,wBAAwB,OAAO,YAAY,QAAQ,CAAC;CAG5D,IAAI,WAAW,KAAA,GAAW;EACxB,MAAM,OAAO,YAAY,MAAM;EAC/B,KAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,MAAY,GACrD,OAAO,MAAM,QAAQ,KAAK,QAAQ,SAAS,qBAAqB;CAEpE;AACF;;;;;;;;AASA,SAAgB,OACd,MACA,QACA,KACA,QACA,UAAU,OACV,wBAAwB,OAClB;CAEN,IAAI,CADU,KAAK,UAAU,MAIvB;MAAA,CADS,cAAc,IAAI,CAAC,CAAC,MAE/B,MAAM,IAAI,MAAM,iBAAiB,KAAK;CAAA;CAK1C,IAAI,WAAW,WAAW,KAAA,GAAW;CAErC,IAAI,KAAK,oBAAoB,SAAS,YAAY,IAAI,CAAC,CAAC,0BAA0B,KAAK;CAGvF,MAAM,QAAQ,WAAW,OAAO,KAAA,IAAY;CAI5C,MAAM,UAAU,QAAQ,OAAO,SAAS,QAAQ,GA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D;CAC7F,OAAO,OAAO,QAAQ,cAAc,YAAY,MAAM,CAAC,CAAC,CAAC,CACtD,QAAQ,GAAG,OAAO,aAAa,oBAAoB,CAAC,CACpD,KAAK,CAAC,UAAU,CAAC,MAAO,OAAe,KAAK,CAAC;AAClD;;AAGA,SAAgB,eAAiC,MAA+D;CAC9G,OAAO;AACT;;;;;;;;AASA,IAAa,YAAb,cAA+B,MAAM,CAAC;;AAGtC,SAAgB,YAAY,QAAuB;CACjD,MAAM,IAAI,UAAU,GAAG,OAAO,eAAe;AAC/C;;;;;;AAOA,SAAgB,YAA8B,QAA6B;CACzE,OAAO,OAAO;AAChB"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { getInstanceData } from \"src/BaseEntity.ts\";\nimport { getDefaultDependencies } from \"src/defaults.ts\";\nimport { type Entity } from \"src/Entity.ts\";\nimport { type EntityConstructor, type MaybeAbstractEntityConstructor } from \"src/EntityManager.ts\";\nimport { type EntityMetadata, getBaseMeta, getMetadata } from \"src/EntityMetadata.ts\";\nimport { getField, setField } from \"src/fields.ts\";\nimport { getProperties } from \"src/getProperties.ts\";\nimport type { New } from \"src/loading/loadHints.ts\";\nimport { isAllSqlPaths } from \"src/loading/loadLens.ts\";\nimport { FactoryInitialValue } from \"src/newTestInstance.ts\";\nimport { partitionHint } from \"src/preloading/partitionHint.ts\";\nimport { buildWhereClause } from \"src/queries/renderConditions.ts\";\nimport { AbstractRelationImpl } from \"src/relations/AbstractRelationImpl.ts\";\nimport { AsyncReactiveFieldImpl } from \"src/relations/AsyncReactiveField.ts\";\nimport {\n isAsyncProperty,\n isAsyncReactiveField,\n isLazyField,\n isProperty,\n isReactiveField,\n isReactiveGetter,\n} from \"src/relations/index.ts\";\nimport { ReactiveFieldImpl } from \"src/relations/ReactiveField.ts\";\nimport { type OptsOf } from \"src/typeMap.ts\";\nimport { fail } from \"src/utils.ts\";\n\nexport const testing = { isAllSqlPaths, getDefaultDependencies, partitionHint };\nexport const internals = { buildWhereClause };\nexport { newPgConnectionConfig } from \"joist-utils\";\nexport { AliasAssigner } from \"src/queries/sql/AliasAssigner.ts\";\nexport {\n type AndCondition,\n type ConditionGroup,\n type DomainPredicate,\n type OrCondition,\n type PredicateBrand,\n type SqlCondition,\n type SqlPredicate,\n} from \"src/queries/conditions.ts\";\n// Domain aliases belong to em.find; physical table expressions belong to em.query/em.execute.\nexport {\n alias,\n aliases,\n getAliasMetadata,\n getAliasMgmt,\n getMaybeCtiAlias,\n isAlias,\n newAliasProxy,\n type Alias,\n type AliasBrand,\n type AliasMgmt,\n type AliasColumn,\n type EntityAlias,\n type PolyAlias,\n type PrimitiveAlias,\n} from \"src/queries/find/Aliases.ts\";\nexport {\n table,\n tables,\n tableMgmt,\n getTableMetadata,\n getTableMgmt,\n isTable,\n newTableProxy,\n type Table,\n type TableFilter,\n type TableBrand,\n type TableFor,\n type TableMgmt,\n type ReferenceJoin,\n type PrimitiveColumn,\n type EntityColumn,\n type ReferenceColumn,\n type CollectionJoin,\n type PolyReference,\n} from \"src/queries/sql/Tables.ts\";\nexport { BaseEntity, getInstanceData } from \"src/BaseEntity.ts\";\nexport { ConditionBuilder } from \"src/queries/ConditionBuilder.ts\";\nexport { type Entity, type IdType, isEntity } from \"src/Entity.ts\";\nexport type * from \"src/EntityFields.ts\";\nexport * from \"src/queries/find/EntityFilter.ts\";\nexport * from \"src/queries/find/EntityGraphQLFilter.ts\";\nexport * from \"src/EntityManager.ts\";\nexport * from \"src/EntityMetadata.ts\";\nexport type {\n DeleteStatement,\n ExecuteResult,\n InsertStatement,\n InsertValues,\n MutationReturning,\n MutationStatement,\n UpdateStatement,\n UpdateValues,\n} from \"src/queries/sql/execute.ts\";\nexport type { EnumMetadata } from \"src/EnumMetadata.ts\";\n// `em.query`'s expression surface. Only the user-facing types are re-exported: the runtime half\n// (BaseExpr, asNode, deferredCondition, the FnExpr/TemplateExpr node classes) stays internal to\n// joist-core, so `toSql`/`decode`/`encode` never show up as something a user could call.\nexport {\n type ArrayAggOptions,\n type Expr,\n type ExprBrand,\n exprBrand,\n type ExprLike,\n type InnerJoin,\n type LeftJoin,\n} from \"src/queries/sql/Expr.ts\";\nexport {\n expr,\n type CaseElse,\n type CaseWhen,\n type ExprFromInput,\n type ExprInput,\n} from \"src/queries/sql/expressions/expression.ts\";\nexport { skipCondition } from \"src/queries/skipCondition.ts\";\nexport type { EntityOrId, HintNode } from \"src/loading/HintTree.ts\";\nexport { InstanceData } from \"src/InstanceData.ts\";\nexport { type JoinColumnValue, type JoinRow, JoinRowOperation, type ManyToManyLike } from \"src/flush/JoinRows.ts\";\nexport type * from \"src/flush/PendingChanges.ts\";\nexport { Plugin } from \"src/PluginManager.ts\";\nexport * from \"src/queries/find/QueryParser.ts\";\nexport * from \"src/queries/find/buildFindQuery.ts\";\nexport * from \"src/queries/renderConditions.ts\";\nexport type {\n ColumnCondition,\n ExistsCondition,\n ParsedExpressionCondition,\n ParsedExpressionFilter,\n ParsedValueFilter,\n RawCondition,\n} from \"src/queries/parsedConditions.ts\";\nexport {\n type ParsedEntityFilter,\n makeLike,\n mapToDb,\n parseEntityFilter,\n parseValueFilter,\n} from \"src/queries/valueFilters.ts\";\nexport {\n filterSoftDeletes,\n lazyExcludedSelects,\n maybeAddNotSoftDeleted,\n stiSubtypeFilter,\n} from \"src/queries/entityQueryUtils.ts\";\nexport * from \"src/queries/find/QueryParser.collectionJoins.ts\";\nexport { visitConditions } from \"src/queries/find/QueryVisitor.ts\";\nexport * from \"src/RowData.ts\";\nexport { type JoinRowTodo, Todo } from \"src/flush/Todo.ts\";\nexport * from \"src/changes.ts\";\nexport { ConfigApi, type EntityHook, resetBootFlag } from \"src/config.ts\";\nexport {\n configureMetadata,\n getConstructorFromTaggedId,\n getMetadataForTable,\n getMetadataForType,\n maybeGetConstructorFromReference,\n} from \"src/configure.ts\";\nexport { driverApi } from \"src/drivers/driverApi.ts\";\nexport * from \"src/drivers/index.ts\";\nexport { getField, isChangeableField, isFieldSet, setField } from \"src/fields.ts\";\nexport * from \"src/getProperties.ts\";\nexport * from \"src/json.ts\";\nexport * from \"src/keys.ts\";\nexport { kq, kqDot, kqStar } from \"src/queries/sql/keywords.ts\";\nexport {\n assertLoaded,\n type DeepNew,\n ensureLoaded,\n isLoaded,\n isNew,\n type Loadable,\n type Loaded,\n type LoadHint,\n type MarkLoaded,\n maybePopulateThen,\n type NestedLoadHint,\n type New,\n type RelationsIn,\n unsafeLoaded,\n} from \"src/loading/loadHints.ts\";\nexport * from \"src/loading/loadLens.ts\";\nexport { setFactoryWriter } from \"src/logging/FactoryLogger.ts\";\nexport * from \"src/logging/FieldLogger.ts\";\nexport { ReactionLogger, setReactionLogging } from \"src/logging/ReactionLogger.ts\";\nexport { lazyField } from \"src/newEntity.ts\";\nexport {\n defaultValue,\n factories,\n type FactoryEntityOpt,\n type FactoryOpts,\n getTestIndex,\n isFactoryCreation,\n maybeBranchValue,\n maybeNew,\n maybeNewPoly,\n newTestInstance,\n noValue,\n setFactoryLogging,\n testIndex,\n} from \"src/newTestInstance.ts\";\nexport { deepNormalizeHint, normalizeHint } from \"src/normalizeHints.ts\";\nexport { ImmutableEntitiesPlugin } from \"src/plugins/ImmutableEntitiesPlugin.ts\";\nexport type { JoinResult, PreloadHydrator, PreloadPlugin } from \"src/plugins/PreloadPlugin.ts\";\nexport { JsonAggregatePreloader } from \"src/preloading/JsonAggregatePreloader.ts\";\n// `em.query`'s query surface; the parse pipeline (SubqueryHandle, parseUserQuery, Plan) stays internal\nexport {\n type CheckScope,\n type Clauses,\n type EntityQuery,\n type ExpressionOrderBy,\n type ExistsQuery,\n entityQueryBrand,\n type MaybeNull,\n type NameOf,\n type NotWidened,\n type OrderByDirection,\n type OrderByKeys,\n type Query,\n type QueryArg,\n type QueryCondition,\n type QueryJoin,\n type QueryJoins,\n type QueryRow,\n type QuerySelect,\n type QuerySource,\n type QueryValue,\n recursiveQuery,\n type RecursiveOptions,\n type ScalarQuery,\n type SetQuery,\n query,\n queryMaybe,\n sql,\n type Subquery,\n type SubqueryBrand,\n subqueryBrand,\n type WithInput,\n type WithSource,\n} from \"src/queries/sql/query.ts\";\nexport {\n convertToLoadHint,\n isTypeOrSubType,\n type Reactable,\n type Reacted,\n type ReactiveHint,\n type ReactiveTarget,\n reverseReactiveHint,\n} from \"src/reactivity/reactiveHints.ts\";\nexport * from \"src/relations/index.ts\";\nexport {\n cannotBeChanged,\n cannotBeUpdated,\n type GenericError,\n maxValueRule,\n minValueRule,\n mustBeSubType,\n newRequiredLazyFieldRule,\n newRequiredRule,\n rangeValueRule,\n ValidationCode,\n type ValidationError,\n ValidationErrors,\n type ValidationRule,\n type ValidationRuleInternal,\n type ValidationRuleResult,\n} from \"src/rules.ts\";\nexport { getRuntimeConfig, setRuntimeConfig, type RuntimeConfig } from \"src/runtimeConfig.ts\";\nexport { nowUTC } from \"src/nowUTC.ts\";\nexport * from \"src/serde/serde.ts\";\nexport * from \"src/serde/columns.ts\";\nexport * from \"src/serde/fieldSerde.ts\";\nexport * from \"src/queries/find/scopes.ts\";\nexport { maybeRequireTemporal, requireTemporal, Temporal } from \"src/serde/temporal.ts\";\nexport * from \"src/serde/temporalMappers.ts\";\nexport { isInTrustedContext, runInTrustedContext } from \"src/trusted.ts\";\nexport type * from \"src/typeMap.ts\";\nexport { buildUnnestCte, ensureRectangularArraySizes } from \"src/queries/unnest.ts\";\nexport { type DeepPartialOrNull, updatePartial, upsert } from \"src/upsert.ts\";\nexport {\n abbreviation,\n asNew,\n assertNever,\n cleanSql,\n cleanStringValue,\n fail,\n failIfAnyRejected,\n indexBy,\n partition,\n zeroTo,\n} from \"src/utils.ts\";\nexport { ensureWithLoaded, StubbedRelation, type WithLoaded, withLoaded } from \"src/loading/withLoaded.ts\";\n\n// https://spin.atomicobject.com/2018/01/15/typescript-flexible-nominal-typing/\ninterface Flavoring<FlavorT> {\n _type?: FlavorT;\n}\n\nexport type Flavor<T, FlavorT> = T & Flavoring<FlavorT>;\n\n/**\n * Sets each value in `values` on the current entity.\n *\n * The default behavior is that passing a value as either `null` or `undefined` will set\n * the field as `undefined`, i.e. automatic `null` to `undefined` conversion.\n *\n * However, if you pass `ignoreUndefined: true`, then any opt that is `undefined` will be treated\n * as \"do not set\", and `null` will still mean \"set to `undefined`\". This is useful for implementing\n * APIs were an input of `undefined` means \"do not set / noop\" and `null` means \"unset\".\n *\n * Note that constructors _always_ call this method, but if the call is coming from `em.hydrate`, we\n * use `values` being a primary key to short-circuit and let hydration callers assign the values\n * returned by the serde `fromRow` methods.\n */\nexport function setOpts<T extends Entity>(\n entity: T,\n values: Partial<OptsOf<T>> | undefined,\n opts?: { partial?: boolean; calledFromConstructor?: boolean },\n): void {\n const { calledFromConstructor = false, partial } = opts || {};\n // If `values` is undefined, we're being called by `createPartial` that will do its\n // own opt handling, but we still want the sync defaults applied after this opts handling.\n if (values !== undefined) {\n const meta = getMetadata(entity);\n for (const [key, _value] of Object.entries(values as {})) {\n setOpt(meta, entity, key, _value, partial, calledFromConstructor);\n }\n }\n}\n\n/**\n * Applies some standard behavior & protections to `entity[key] = value`. I.e.\n *\n * - We don't set over AsyncProperties/relations/etc., and instead call current.set(value)\n * - We catch missing/invalid field names\n * - We handle FactoryInitialValues\n */\nexport function setOpt<T extends Entity>(\n meta: EntityMetadata<T>,\n entity: T,\n key: string,\n _value: any,\n partial = false,\n calledFromConstructor = false,\n): void {\n const field = meta.allFields[key];\n if (!field) {\n // Allow setting non-field properties like fullName setters\n const prop = getProperties(meta)[key];\n if (!prop) {\n throw new Error(`Unknown field ${key}`);\n }\n }\n\n // If partial is set, we treat undefined as a noop\n if (partial && _value === undefined) return;\n // Ignore the STI discriminator, em.register will set this accordingly\n if (meta.inheritanceType === \"sti\" && getBaseMeta(meta).stiDiscriminatorField === key) return;\n\n // We let optional opts fields be `| null` for convenience, and convert to undefined.\n const value = _value === null ? undefined : _value;\n\n // Use `getField` to side-step `id` blowing up on new entities that are setting an\n // explicit id; otherwise use `entity[key]` to get back the relation.\n const current = key === \"id\" ? getField(entity, key) : (entity as any)[key];\n\n if (current instanceof AbstractRelationImpl) {\n if (calledFromConstructor) {\n current.setFromOpts(value);\n } else {\n current.set(value);\n }\n } else if (isLazyField(current)) {\n current.set(value);\n } else if (isProperty(current) || isAsyncProperty(current) || isReactiveGetter(current)) {\n throw new Error(`Invalid argument, cannot set over ${key} ${current.constructor.name}`);\n } else if (isReactiveField(current) || isAsyncReactiveField(current)) {\n if (value instanceof FactoryInitialValue) {\n if (current instanceof ReactiveFieldImpl) {\n current.setFactoryValue(value.value);\n } else if (current instanceof AsyncReactiveFieldImpl) {\n current.setFactoryValue(value.value);\n } else {\n throw new Error(`Unhandled case ${current.constructor.name}`);\n }\n } else {\n throw new Error(`Invalid argument, cannot set over ${key} ${current.constructor.name}`);\n }\n } else {\n // If setting an explicit id, go through setField, otherwise use\n // `entity[key]` to set the value directly to that we go through setters.\n if (key === \"id\" && entity.isNewEntity) {\n setField(entity, key, value);\n } else {\n (entity as any)[key] = value;\n }\n }\n}\n\nexport function ensureNotDeleted(entity: Entity, ignore?: \"pending\"): void {\n if (entity.isDeletedEntity && (ignore === undefined || getInstanceData(entity).isDeletedAndFlushed)) {\n fail(`${entity} is marked as deleted`);\n }\n}\n\n/** Adds `null` to every key in `T` to accept partial-update-style input. */\nexport type PartialOrNull<T> = {\n [P in keyof T]?: T[P] | null;\n};\n\nexport function getRequiredKeys<T extends Entity>(entity: T): string[];\nexport function getRequiredKeys<T extends Entity>(type: EntityConstructor<T>): string[];\nexport function getRequiredKeys<T extends Entity>(entityOrType: T | EntityConstructor<T>): string[] {\n return Object.values(getMetadata(entityOrType as any).fields)\n .filter((f) => f.required)\n .map((f) => f.fieldName);\n}\n\nexport function getRelations(entity: Entity): AbstractRelationImpl<any, any>[] {\n return Object.entries(getProperties(getMetadata(entity)))\n .filter(([, v]) => v instanceof AbstractRelationImpl)\n .map(([name]) => (entity as any)[name]);\n}\n\nexport function getRelationEntries(entity: Entity): [string, AbstractRelationImpl<any, any>][] {\n return Object.entries(getProperties(getMetadata(entity)))\n .filter(([, v]) => v instanceof AbstractRelationImpl)\n .map(([name]) => [name, (entity as any)[name]]);\n}\n\n/** Casts a \"maybe abstract\" cstr to a concrete cstr when the calling code knows it's safe. */\nexport function asConcreteCstr<T extends Entity>(cstr: MaybeAbstractEntityConstructor<T>): EntityConstructor<T> {\n return cstr as any;\n}\n\n/**\n * Thrown when `.id` is accessed on an entity that does not have an id yet.\n *\n * For Postgres, entities are actually allowed to have ids pre-INSERT, if you call\n * `em.assignNewIds()`. Other databases typically require INSERTs to trigger the auto\n * id assignment.\n */\nexport class NoIdError extends Error {}\n\n/** Throws a `NoIdError` for `entity`, i.e. because `id` was called before being saved. */\nexport function failNoIdYet(entity: string): never {\n throw new NoIdError(`${entity} has no id yet`);\n}\n\n/**\n * Add a static function since getters can't have type guards.\n *\n * See https://github.com/microsoft/TypeScript/issues/43368\n */\nexport function isNewEntity<T extends Entity>(entity: T): entity is New<T> {\n return entity.isNewEntity;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,UAAU;CAAE;CAAe;CAAwB;AAAc;AAC9E,MAAa,YAAY,EAAE,iBAAiB;;;;;;;;;;;;;;;AA8R5C,SAAgB,QACd,QACA,QACA,MACM;CACN,MAAM,EAAE,wBAAwB,OAAO,YAAY,QAAQ,CAAC;CAG5D,IAAI,WAAW,KAAA,GAAW;EACxB,MAAM,OAAO,YAAY,MAAM;EAC/B,KAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,MAAY,GACrD,OAAO,MAAM,QAAQ,KAAK,QAAQ,SAAS,qBAAqB;CAEpE;AACF;;;;;;;;AASA,SAAgB,OACd,MACA,QACA,KACA,QACA,UAAU,OACV,wBAAwB,OAClB;CAEN,IAAI,CADU,KAAK,UAAU,MAIvB;MAAA,CADS,cAAc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AAM,EAAE,QAAQ,CAAC,CACzB,KAAK,MAAM,EAAE,SAAS;AAC3B;AAEA,SAAgB,aAAa,QAAkD;CAC7E,OAAO,OAAO,QAAQ,cAAc,YAAY,MAAM,CAAC,CAAC,CAAC,CACtD,QAAQ,GAAG,OAAO,aAAa,oBAAoB,CAAC,CACpD,KAAK,CAAC,UAAW,OAAe,KAAK;AAC1C;AAEA,SAAgB,mBAAmB,QAA4D;CAC7F,OAAO,OAAO,QAAQ,cAAc,YAAY,MAAM,CAAC,CAAC,CAAC,CACtD,QAAQ,GAAG,OAAO,aAAa,oBAAoB,CAAC,CACpD,KAAK,CAAC,UAAU,CAAC,MAAO,OAAe,KAAK,CAAC;AAClD;;AAGA,SAAgB,eAAiC,MAA+D;CAC9G,OAAO;AACT;;;;;;;;AASA,IAAa,YAAb,cAA+B,MAAM,CAAC;;AAGtC,SAAgB,YAAY,QAAuB;CACjD,MAAM,IAAI,UAAU,GAAG,OAAO,eAAe;AAC/C;;;;;;AAOA,SAAgB,YAA8B,QAA6B;CACzE,OAAO,OAAO;AAChB"}
package/build/json.cjs CHANGED
@@ -1,9 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_relations_AbstractRelationImpl = require("./relations/AbstractRelationImpl.cjs");
3
- const require_relations_hasProperty = require("./relations/hasProperty.cjs");
4
- const require_relations_ReactiveGetter = require("./relations/ReactiveGetter.cjs");
5
- const require_reactiveHints = require("./reactiveHints.cjs");
6
3
  const require_normalizeHints = require("./normalizeHints.cjs");
4
+ const require_relations_ReactiveGetter = require("./relations/ReactiveGetter.cjs");
5
+ const require_reactivity_reactiveHints = require("./reactivity/reactiveHints.cjs");
6
+ const require_relations_hasProperty = require("./relations/hasProperty.cjs");
7
7
  const require_relations_ReactiveField = require("./relations/ReactiveField.cjs");
8
8
  const require_relations_AsyncReactiveField = require("./relations/AsyncReactiveField.cjs");
9
9
  require("./relations/index.cjs");
@@ -14,7 +14,7 @@ const require_Entity = require("./Entity.cjs");
14
14
  async function toJSON(entityOrList, hint) {
15
15
  if (Array.isArray(entityOrList) && entityOrList.length === 0) return [];
16
16
  const entity = Array.isArray(entityOrList) ? entityOrList[0] : entityOrList;
17
- const loadHint = require_reactiveHints.convertToLoadHint(require_EntityMetadata.getMetadata(entity), hint, true);
17
+ const loadHint = require_reactivity_reactiveHints.convertToLoadHint(require_EntityMetadata.getMetadata(entity), hint, true);
18
18
  await entity.em.populate(entityOrList, loadHint);
19
19
  const normHint = require_normalizeHints.normalizeHint(hint);
20
20
  if (Array.isArray(entityOrList)) {
@@ -1 +1 @@
1
- {"version":3,"file":"json.cjs","names":["convertToLoadHint","getMetadata","normalizeHint","AbstractRelationImpl","ReactiveFieldImpl","ReactiveGetterImpl","AsyncReactiveFieldImpl","PropertyImpl","isEntity"],"sources":["../src/json.ts"],"sourcesContent":["import { type Entity, isEntity } from \"./Entity.ts\";\nimport { type IdOf } from \"./EntityManager.ts\";\nimport { getMetadata } from \"./EntityMetadata.ts\";\nimport { normalizeHint } from \"./normalizeHints.ts\";\nimport { convertToLoadHint } from \"./reactiveHints.ts\";\nimport { AbstractRelationImpl } from \"./relations/AbstractRelationImpl.ts\";\nimport { AsyncReactiveFieldImpl } from \"./relations/AsyncReactiveField.ts\";\nimport { PropertyImpl } from \"./relations/hasProperty.ts\";\nimport {\n type AsyncMethod,\n type Collection,\n type Property,\n type ReactiveGetter,\n type Reference,\n} from \"./relations/index.ts\";\nimport { ReactiveFieldImpl } from \"./relations/ReactiveField.ts\";\nimport { ReactiveGetterImpl } from \"./relations/ReactiveGetter.ts\";\n\n/**\n * A JSON hint of a single key, multiple keys, or nested keys and sub-hints.\n *\n * JSON hints are much like load hints/reactive hints:\n *\n * - Similar to load hints, they specify which relations should be loaded from the database\n * - Similar to reactive hints, they include specific fields to output\n * - Unlike either, they can include completely custom keys that are lambdas to generate custom values\n */\nexport type JsonHint<T extends Entity> =\n | (keyof Jsonable<T> & string)\n | ReadonlyArray<keyof Jsonable<T> & string>\n | NestedJsonHint<T>;\n\n/** For object literal/nested hints, we allow mapping both entity keys 1:1 & custom keys via a lambdas. */\nexport type NestedJsonHint<T extends Entity> = EntityKeyJsonHint<T> | CustomJsonKeyHint<T>;\n\n/** Foreach `Jsonable` key, we can provide a sub-hint, or just a boolean to include/exclude. */\nexport type EntityKeyJsonHint<T extends Entity> = {\n // The `as K` makes `bookIds` as a hint work...\n [K in keyof Jsonable<T> as `${K}`]?: (Jsonable<T>[K] extends infer U extends Entity ? JsonHint<U> : {}) | boolean;\n};\n\nexport type CustomJsonKeyHint<T> = {\n [key: string]: (entity: T) => any;\n};\n\n/**\n * Describes the JSON payload for `Entity.toJSON` to produce.\n *\n * - `[\"firstName\", \"lastName\"]` will produce a JSON payload with just those fields\n * - `{ author: { books: \"title\" } }` will produce a JSON payload with the author's books' titles\n *\n * We only accept object literals & arrays to `toJSON` to avoid a `JSON.stringify` oddity.\n */\nexport type ToJsonHint<T extends Entity> = NestedJsonHint<T> | ReadonlyArray<keyof Jsonable<T> & string>;\n\n/** The keys in `T` that we can put into a JSON payload. */\nexport type Jsonable<T extends Entity> = {\n -readonly [K in keyof T as JsonableValue<T[K]> extends never ? never : K]: JsonableValue<T[K]>;\n};\n\n// this should probably be `keyof T` as long as they aren't methods/AsyncMethods.\n// so primitives, enums, references, collections, async properties, but also random getters.\nexport type JsonableValue<V> =\n V extends Reference<any, infer U, any>\n ? U\n : V extends Collection<any, infer U>\n ? U\n : V extends AsyncMethod<any, any, any>\n ? never\n : V extends Property<any, infer P>\n ? DropUndefined<P>\n : V extends ReactiveGetter<any, infer P>\n ? P\n : V;\n\n/**\n * Provides an API to put an entity, or list of entities, into a JSON payload.\n *\n * The `hint` parameter is a JSON hint that describes what to include in the payload,\n *\n * - fields like `id`, `name`, etc.\n * - relations like m2o, o2m, m2m, and o2o\n * - relations are allowed to provide nested hints, just like nested load hints\n * - custom fields like `fullName: (entity) => entity.firstName + ' ' + entity.lastName`\n */\nexport async function toJSON<T extends Entity, const H extends JsonHint<T>>(\n entity: T,\n hint: H,\n): Promise<JsonPayload<T, H>>;\n\n/**\n * Provides an API to put an entity, or list of entities, into a JSON payload.\n *\n * The `hint` parameter is a JSON hint that describes what to include in the payload,\n *\n * - fields like `id`, `name`, etc.\n * - relations like m2o, o2m, m2m, and o2o\n * - relations are allowed to provide nested hints, just like nested load hints\n * - custom fields like `fullName: (entity) => entity.firstName + ' ' + entity.lastName`\n */\nexport async function toJSON<T extends Entity, const H extends JsonHint<T>>(\n entities: readonly T[],\n hint: H,\n): Promise<JsonPayload<T, H>[]>;\nexport async function toJSON<T extends Entity, const H extends JsonHint<T>>(\n entityOrList: T | readonly T[],\n hint: H,\n): Promise<JsonPayload<T, H> | JsonPayload<T, H>[]> {\n // If called with a list, and nothing there, just early return\n if (Array.isArray(entityOrList) && entityOrList.length === 0) return [];\n\n // Otherwise probe to get our first entity\n const entity = Array.isArray(entityOrList) ? entityOrList[0] : entityOrList;\n const loadHint = convertToLoadHint(getMetadata(entity), hint as any, true);\n await entity.em.populate(entityOrList, loadHint);\n const normHint = normalizeHint(hint as any);\n\n if (Array.isArray(entityOrList)) {\n const list = [] as any;\n await Promise.all(\n entityOrList.map((entity) => {\n const json = {};\n list.push(json);\n return copyToPayload(json, entity, normHint);\n }),\n );\n return list;\n } else {\n const json = {};\n await copyToPayload(json, entity, normHint);\n return json as any;\n }\n}\n\n/**\n * Statically types the return value of `toJSON` based on the given `hint`.\n */\nexport type JsonPayload<T, H> = {\n [HK in keyof NormalizeHint<H> & string]: HK extends keyof T\n ? JsonPayloadKey<T, H, HK, HK>\n : HK extends `${infer TK extends string & keyof T}Id`\n ? JsonPayloadKey<T, H, TK, HK>\n : HK extends `${infer SK extends string}Ids` // bookIds -> books\n ? // Very naive singularization to see if the guessed bookIds -> books actually exists on T to map 1:1\n `${SK}s` extends keyof T\n ? JsonPayloadKey<T, H, `${SK}s`, HK>\n : JsonPayloadCustom<NormalizeHint<H>[HK]>\n : JsonPayloadCustom<NormalizeHint<H>[HK]>;\n};\n\ntype JsonPayloadKey<T, H, TK extends keyof T, HK extends keyof NormalizeHint<H>> =\n T[TK] extends Reference<any, infer U, any>\n ? JsonPayloadReference<U, NormalizeHint<H>[HK]>\n : T[TK] extends Collection<any, infer U>\n ? JsonPayloadCollection<U, NormalizeHint<H>[HK]>\n : T[TK] extends Property<any, infer U>\n ? JsonPayloadProperty<U, NormalizeHint<H>[HK]>\n : T[TK] extends ReactiveGetter<any, infer V>\n ? V\n : T[TK];\n\n// If the hint is empty, we just output the id as a string.\ntype JsonPayloadReference<U, H> = IsEmpty<H> extends true ? string : JsonPayload<U, H>;\n\ntype JsonPayloadCollection<U extends Entity, H> =\n // If this is `books: true`, use the id\n H extends true\n ? IdOf<U>[]\n : // If this is `{}`, use the id\n IsEmpty<H> extends true\n ? IdOf<U>[]\n : // Otherwise it's a nested hint\n JsonPayload<U, H>[];\n\ntype JsonPayloadProperty<P, H> =\n // If an async property returns an entity, treat it like a reference\n P extends Entity | undefined\n ? JsonPayloadReference<P, H>\n : // If an async property returns an entity[], treat it like a collection\n P extends (infer U extends Entity)[] | undefined\n ? JsonPayloadCollection<U, H>\n : // Otherwise leave it as-is\n P;\n\ntype JsonPayloadCustom<H> = H extends (...args: any) => infer V ? UnwrapPromise<V> : H;\n\ntype UnwrapPromise<T> = T extends Promise<infer U> ? U : T;\n\n/** Recursively copies the fields of `hint` from `entity` into the `payload`. */\nasync function copyToPayload(payload: Record<string, {}>, entity: any, hint: object): Promise<void> {\n // Look at each key in the hint and determine\n for (const [payloadKey, nestedHint] of Object.entries(hint)) {\n const nextHint = normalizeHint(nestedHint);\n // Watch for `companyId`\n let entityKey = payloadKey;\n if (!(entityKey in entity)) {\n const field = Object.values(getMetadata(entity).allFields).find((f) => f.fieldIdName === payloadKey);\n if (field) {\n entityKey = field.fieldName;\n }\n }\n // Look for custom props\n if (!(entityKey in entity)) {\n if (typeof nestedHint !== \"function\") {\n throw new Error(`Entity does not have a property ${payloadKey}`);\n }\n payload[payloadKey] = await nestedHint(entity);\n } else {\n const value = entity[entityKey];\n if (isPrimitive(value)) {\n payload[payloadKey] = value;\n } else if (\n value instanceof AbstractRelationImpl ||\n value instanceof ReactiveFieldImpl ||\n value instanceof ReactiveGetterImpl ||\n value instanceof AsyncReactiveFieldImpl ||\n value instanceof PropertyImpl\n ) {\n await copyToPayloadValue(payload, payloadKey, value.get, nextHint);\n } else {\n throw new Error(`Unable to encode value ${value} to JSON`);\n }\n }\n }\n}\n\nfunction copyToPayloadValue(payload: any, key: any, value: any, nextHint: any): Promise<unknown> | undefined {\n if (value === undefined || value === null || isPrimitive(value)) {\n payload[key] = value;\n } else if (isEntity(value)) {\n if (nextHint && Object.keys(nextHint).length > 0) {\n payload[key] = {};\n return copyToPayload(payload[key], value, nextHint);\n } else {\n payload[key] = value.id;\n }\n } else if (Array.isArray(value)) {\n const list = [] as any[];\n payload[key] = list;\n if (nextHint && Object.keys(nextHint).length > 0) {\n return Promise.all(\n value.map(async (item, i) => {\n if (isEntity(item)) {\n list[i] = {};\n return copyToPayload(list[i], item, nextHint);\n } else {\n // This is probably undefined\n list[i] = item;\n }\n }),\n );\n } else {\n // This is assuming an array of entities...\n for (const item of value) list.push(item.id);\n }\n } else {\n payload[key] = value;\n }\n}\n\nfunction isPrimitive(value: any): boolean {\n return value === null || typeof value !== \"object\";\n}\n\ntype DropUndefined<T> = T extends infer U extends Entity | undefined ? U : T;\n\n// A copy/paste of NormalizeHint w/o the `DropSuffix` stuff\ntype NormalizeHint<H> = H extends string\n ? Record<H, {}>\n : H extends ReadonlyArray<any>\n ? Record<H[number], {}>\n : { [K in keyof H]: H[K] };\n\ntype IsEmpty<T> = keyof T extends never ? true : false;\n"],"mappings":";;;;;;;;;;;;;AAwGA,eAAsB,OACpB,cACA,MACkD;CAElD,IAAI,MAAM,QAAQ,YAAY,KAAK,aAAa,WAAW,GAAG,OAAO,CAAC;CAGtE,MAAM,SAAS,MAAM,QAAQ,YAAY,IAAI,aAAa,KA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,IAAI,MAAM,0BAA0B,MAAM,SAAS;EAE7D;CACF;AACF;AAEA,SAAS,mBAAmB,SAAc,KAAU,OAAY,UAA6C;CAC3G,IAAI,UAAU,KAAA,KAAa,UAAU,QAAQ,YAAY,KAAK,GAC5D,QAAQ,OAAO;MACV,IAAIC,eAAAA,SAAS,KAAK,GAAG;EAC1B,IAAI,YAAY,OAAO,KAAK,QAAQ,CAAC,CAAC,SAAS,GAAG;GAChD,QAAQ,OAAO,CAAC;GAChB,OAAO,cAAc,QAAQ,MAAM,OAAO,QAAQ;EACpD,OACE,QAAQ,OAAO,MAAM;CAEzB,OAAO,IAAI,MAAM,QAAQ,KAAK,GAAG;EAC/B,MAAM,OAAO,CAAC;EACd,QAAQ,OAAO;EACf,IAAI,YAAY,OAAO,KAAK,QAAQ,CAAC,CAAC,SAAS,GAC7C,OAAO,QAAQ,IACb,MAAM,IAAI,OAAO,MAAM,MAAM;GAC3B,IAAIA,eAAAA,SAAS,IAAI,GAAG;IAClB,KAAK,KAAK,CAAC;IACX,OAAO,cAAc,KAAK,IAAI,MAAM,QAAQ;GAC9C,OAEE,KAAK,KAAK;EAEd,CAAC,CACH;OAGA,KAAK,MAAM,QAAQ,OAAO,KAAK,KAAK,KAAK,EAAE;CAE/C,OACE,QAAQ,OAAO;AAEnB;AAEA,SAAS,YAAY,OAAqB;CACxC,OAAO,UAAU,QAAQ,OAAO,UAAU;AAC5C"}
1
+ {"version":3,"file":"json.cjs","names":["convertToLoadHint","getMetadata","normalizeHint","AbstractRelationImpl","ReactiveFieldImpl","ReactiveGetterImpl","AsyncReactiveFieldImpl","PropertyImpl","isEntity"],"sources":["../src/json.ts"],"sourcesContent":["import { type Entity, isEntity } from \"src/Entity.ts\";\nimport { type IdOf } from \"src/EntityManager.ts\";\nimport { getMetadata } from \"src/EntityMetadata.ts\";\nimport { normalizeHint } from \"src/normalizeHints.ts\";\nimport { convertToLoadHint } from \"src/reactivity/reactiveHints.ts\";\nimport { AbstractRelationImpl } from \"src/relations/AbstractRelationImpl.ts\";\nimport { AsyncReactiveFieldImpl } from \"src/relations/AsyncReactiveField.ts\";\nimport { PropertyImpl } from \"src/relations/hasProperty.ts\";\nimport {\n type AsyncMethod,\n type Collection,\n type Property,\n type ReactiveGetter,\n type Reference,\n} from \"src/relations/index.ts\";\nimport { ReactiveFieldImpl } from \"src/relations/ReactiveField.ts\";\nimport { ReactiveGetterImpl } from \"src/relations/ReactiveGetter.ts\";\n\n/**\n * A JSON hint of a single key, multiple keys, or nested keys and sub-hints.\n *\n * JSON hints are much like load hints/reactive hints:\n *\n * - Similar to load hints, they specify which relations should be loaded from the database\n * - Similar to reactive hints, they include specific fields to output\n * - Unlike either, they can include completely custom keys that are lambdas to generate custom values\n */\nexport type JsonHint<T extends Entity> =\n | (keyof Jsonable<T> & string)\n | ReadonlyArray<keyof Jsonable<T> & string>\n | NestedJsonHint<T>;\n\n/** For object literal/nested hints, we allow mapping both entity keys 1:1 & custom keys via a lambdas. */\nexport type NestedJsonHint<T extends Entity> = EntityKeyJsonHint<T> | CustomJsonKeyHint<T>;\n\n/** Foreach `Jsonable` key, we can provide a sub-hint, or just a boolean to include/exclude. */\nexport type EntityKeyJsonHint<T extends Entity> = {\n // The `as K` makes `bookIds` as a hint work...\n [K in keyof Jsonable<T> as `${K}`]?: (Jsonable<T>[K] extends infer U extends Entity ? JsonHint<U> : {}) | boolean;\n};\n\nexport type CustomJsonKeyHint<T> = {\n [key: string]: (entity: T) => any;\n};\n\n/**\n * Describes the JSON payload for `Entity.toJSON` to produce.\n *\n * - `[\"firstName\", \"lastName\"]` will produce a JSON payload with just those fields\n * - `{ author: { books: \"title\" } }` will produce a JSON payload with the author's books' titles\n *\n * We only accept object literals & arrays to `toJSON` to avoid a `JSON.stringify` oddity.\n */\nexport type ToJsonHint<T extends Entity> = NestedJsonHint<T> | ReadonlyArray<keyof Jsonable<T> & string>;\n\n/** The keys in `T` that we can put into a JSON payload. */\nexport type Jsonable<T extends Entity> = {\n -readonly [K in keyof T as JsonableValue<T[K]> extends never ? never : K]: JsonableValue<T[K]>;\n};\n\n// this should probably be `keyof T` as long as they aren't methods/AsyncMethods.\n// so primitives, enums, references, collections, async properties, but also random getters.\nexport type JsonableValue<V> =\n V extends Reference<any, infer U, any>\n ? U\n : V extends Collection<any, infer U>\n ? U\n : V extends AsyncMethod<any, any, any>\n ? never\n : V extends Property<any, infer P>\n ? DropUndefined<P>\n : V extends ReactiveGetter<any, infer P>\n ? P\n : V;\n\n/**\n * Provides an API to put an entity, or list of entities, into a JSON payload.\n *\n * The `hint` parameter is a JSON hint that describes what to include in the payload,\n *\n * - fields like `id`, `name`, etc.\n * - relations like m2o, o2m, m2m, and o2o\n * - relations are allowed to provide nested hints, just like nested load hints\n * - custom fields like `fullName: (entity) => entity.firstName + ' ' + entity.lastName`\n */\nexport async function toJSON<T extends Entity, const H extends JsonHint<T>>(\n entity: T,\n hint: H,\n): Promise<JsonPayload<T, H>>;\n\n/**\n * Provides an API to put an entity, or list of entities, into a JSON payload.\n *\n * The `hint` parameter is a JSON hint that describes what to include in the payload,\n *\n * - fields like `id`, `name`, etc.\n * - relations like m2o, o2m, m2m, and o2o\n * - relations are allowed to provide nested hints, just like nested load hints\n * - custom fields like `fullName: (entity) => entity.firstName + ' ' + entity.lastName`\n */\nexport async function toJSON<T extends Entity, const H extends JsonHint<T>>(\n entities: readonly T[],\n hint: H,\n): Promise<JsonPayload<T, H>[]>;\nexport async function toJSON<T extends Entity, const H extends JsonHint<T>>(\n entityOrList: T | readonly T[],\n hint: H,\n): Promise<JsonPayload<T, H> | JsonPayload<T, H>[]> {\n // If called with a list, and nothing there, just early return\n if (Array.isArray(entityOrList) && entityOrList.length === 0) return [];\n\n // Otherwise probe to get our first entity\n const entity = Array.isArray(entityOrList) ? entityOrList[0] : entityOrList;\n const loadHint = convertToLoadHint(getMetadata(entity), hint as any, true);\n await entity.em.populate(entityOrList, loadHint);\n const normHint = normalizeHint(hint as any);\n\n if (Array.isArray(entityOrList)) {\n const list = [] as any;\n await Promise.all(\n entityOrList.map((entity) => {\n const json = {};\n list.push(json);\n return copyToPayload(json, entity, normHint);\n }),\n );\n return list;\n } else {\n const json = {};\n await copyToPayload(json, entity, normHint);\n return json as any;\n }\n}\n\n/**\n * Statically types the return value of `toJSON` based on the given `hint`.\n */\nexport type JsonPayload<T, H> = {\n [HK in keyof NormalizeHint<H> & string]: HK extends keyof T\n ? JsonPayloadKey<T, H, HK, HK>\n : HK extends `${infer TK extends string & keyof T}Id`\n ? JsonPayloadKey<T, H, TK, HK>\n : HK extends `${infer SK extends string}Ids` // bookIds -> books\n ? // Very naive singularization to see if the guessed bookIds -> books actually exists on T to map 1:1\n `${SK}s` extends keyof T\n ? JsonPayloadKey<T, H, `${SK}s`, HK>\n : JsonPayloadCustom<NormalizeHint<H>[HK]>\n : JsonPayloadCustom<NormalizeHint<H>[HK]>;\n};\n\ntype JsonPayloadKey<T, H, TK extends keyof T, HK extends keyof NormalizeHint<H>> =\n T[TK] extends Reference<any, infer U, any>\n ? JsonPayloadReference<U, NormalizeHint<H>[HK]>\n : T[TK] extends Collection<any, infer U>\n ? JsonPayloadCollection<U, NormalizeHint<H>[HK]>\n : T[TK] extends Property<any, infer U>\n ? JsonPayloadProperty<U, NormalizeHint<H>[HK]>\n : T[TK] extends ReactiveGetter<any, infer V>\n ? V\n : T[TK];\n\n// If the hint is empty, we just output the id as a string.\ntype JsonPayloadReference<U, H> = IsEmpty<H> extends true ? string : JsonPayload<U, H>;\n\ntype JsonPayloadCollection<U extends Entity, H> =\n // If this is `books: true`, use the id\n H extends true\n ? IdOf<U>[]\n : // If this is `{}`, use the id\n IsEmpty<H> extends true\n ? IdOf<U>[]\n : // Otherwise it's a nested hint\n JsonPayload<U, H>[];\n\ntype JsonPayloadProperty<P, H> =\n // If an async property returns an entity, treat it like a reference\n P extends Entity | undefined\n ? JsonPayloadReference<P, H>\n : // If an async property returns an entity[], treat it like a collection\n P extends (infer U extends Entity)[] | undefined\n ? JsonPayloadCollection<U, H>\n : // Otherwise leave it as-is\n P;\n\ntype JsonPayloadCustom<H> = H extends (...args: any) => infer V ? UnwrapPromise<V> : H;\n\ntype UnwrapPromise<T> = T extends Promise<infer U> ? U : T;\n\n/** Recursively copies the fields of `hint` from `entity` into the `payload`. */\nasync function copyToPayload(payload: Record<string, {}>, entity: any, hint: object): Promise<void> {\n // Look at each key in the hint and determine\n for (const [payloadKey, nestedHint] of Object.entries(hint)) {\n const nextHint = normalizeHint(nestedHint);\n // Watch for `companyId`\n let entityKey = payloadKey;\n if (!(entityKey in entity)) {\n const field = Object.values(getMetadata(entity).allFields).find((f) => f.fieldIdName === payloadKey);\n if (field) {\n entityKey = field.fieldName;\n }\n }\n // Look for custom props\n if (!(entityKey in entity)) {\n if (typeof nestedHint !== \"function\") {\n throw new Error(`Entity does not have a property ${payloadKey}`);\n }\n payload[payloadKey] = await nestedHint(entity);\n } else {\n const value = entity[entityKey];\n if (isPrimitive(value)) {\n payload[payloadKey] = value;\n } else if (\n value instanceof AbstractRelationImpl ||\n value instanceof ReactiveFieldImpl ||\n value instanceof ReactiveGetterImpl ||\n value instanceof AsyncReactiveFieldImpl ||\n value instanceof PropertyImpl\n ) {\n await copyToPayloadValue(payload, payloadKey, value.get, nextHint);\n } else {\n throw new Error(`Unable to encode value ${value} to JSON`);\n }\n }\n }\n}\n\nfunction copyToPayloadValue(payload: any, key: any, value: any, nextHint: any): Promise<unknown> | undefined {\n if (value === undefined || value === null || isPrimitive(value)) {\n payload[key] = value;\n } else if (isEntity(value)) {\n if (nextHint && Object.keys(nextHint).length > 0) {\n payload[key] = {};\n return copyToPayload(payload[key], value, nextHint);\n } else {\n payload[key] = value.id;\n }\n } else if (Array.isArray(value)) {\n const list = [] as any[];\n payload[key] = list;\n if (nextHint && Object.keys(nextHint).length > 0) {\n return Promise.all(\n value.map(async (item, i) => {\n if (isEntity(item)) {\n list[i] = {};\n return copyToPayload(list[i], item, nextHint);\n } else {\n // This is probably undefined\n list[i] = item;\n }\n }),\n );\n } else {\n // This is assuming an array of entities...\n for (const item of value) list.push(item.id);\n }\n } else {\n payload[key] = value;\n }\n}\n\nfunction isPrimitive(value: any): boolean {\n return value === null || typeof value !== \"object\";\n}\n\ntype DropUndefined<T> = T extends infer U extends Entity | undefined ? U : T;\n\n// A copy/paste of NormalizeHint w/o the `DropSuffix` stuff\ntype NormalizeHint<H> = H extends string\n ? Record<H, {}>\n : H extends ReadonlyArray<any>\n ? Record<H[number], {}>\n : { [K in keyof H]: H[K] };\n\ntype IsEmpty<T> = keyof T extends never ? true : false;\n"],"mappings":";;;;;;;;;;;;;AAwGA,eAAsB,OACpB,cACA,MACkD;CAElD,IAAI,MAAM,QAAQ,YAAY,KAAK,aAAa,WAAW,GAAG,OAAO,CAAC;CAGtE,MAAM,SAAS,MAAM,QAAQ,YAAY,IAAI,aAAa,KAAK;CAC/D,MAAM,WAAWA,iCAAAA,kBAAkBC,uBAAAA,YAAY,MAAM,GAAG,MAAa,IAAI;CACzE,MAAM,OAAO,GAAG,SAAS,cAAc,QAAQ;CAC/C,MAAM,WAAWC,uBAAAA,cAAc,IAAW;CAE1C,IAAI,MAAM,QAAQ,YAAY,GAAG;EAC/B,MAAM,OAAO,CAAC;EACd,MAAM,QAAQ,IACZ,aAAa,KAAK,WAAW;GAC3B,MAAM,OAAO,CAAC;GACd,KAAK,KAAK,IAAI;GACd,OAAO,cAAc,MAAM,QAAQ,QAAQ;EAC7C,CAAC,CACH;EACA,OAAO;CACT,OAAO;EACL,MAAM,OAAO,CAAC;EACd,MAAM,cAAc,MAAM,QAAQ,QAAQ;EAC1C,OAAO;CACT;AACF;;AAyDA,eAAe,cAAc,SAA6B,QAAa,MAA6B;CAElG,KAAK,MAAM,CAAC,YAAY,eAAe,OAAO,QAAQ,IAAI,GAAG;EAC3D,MAAM,WAAWA,uBAAAA,cAAc,UAAU;EAEzC,IAAI,YAAY;EAChB,IAAI,EAAE,aAAa,SAAS;GAC1B,MAAM,QAAQ,OAAO,OAAOD,uBA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AAC,CACH;OAGA,KAAK,MAAM,QAAQ,OAAO,KAAK,KAAK,KAAK,EAAE;CAE/C,OACE,QAAQ,OAAO;AAEnB;AAEA,SAAS,YAAY,OAAqB;CACxC,OAAO,UAAU,QAAQ,OAAO,UAAU;AAC5C"}
package/build/json.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { AbstractRelationImpl } from "./relations/AbstractRelationImpl.js";
2
- import { PropertyImpl } from "./relations/hasProperty.js";
3
- import { ReactiveGetterImpl } from "./relations/ReactiveGetter.js";
4
- import { convertToLoadHint } from "./reactiveHints.js";
5
2
  import { normalizeHint } from "./normalizeHints.js";
3
+ import { ReactiveGetterImpl } from "./relations/ReactiveGetter.js";
4
+ import { convertToLoadHint } from "./reactivity/reactiveHints.js";
5
+ import { PropertyImpl } from "./relations/hasProperty.js";
6
6
  import { ReactiveFieldImpl } from "./relations/ReactiveField.js";
7
7
  import { AsyncReactiveFieldImpl } from "./relations/AsyncReactiveField.js";
8
8
  import "./relations/index.js";
package/build/json.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"json.js","names":[],"sources":["../src/json.ts"],"sourcesContent":["import { type Entity, isEntity } from \"./Entity.ts\";\nimport { type IdOf } from \"./EntityManager.ts\";\nimport { getMetadata } from \"./EntityMetadata.ts\";\nimport { normalizeHint } from \"./normalizeHints.ts\";\nimport { convertToLoadHint } from \"./reactiveHints.ts\";\nimport { AbstractRelationImpl } from \"./relations/AbstractRelationImpl.ts\";\nimport { AsyncReactiveFieldImpl } from \"./relations/AsyncReactiveField.ts\";\nimport { PropertyImpl } from \"./relations/hasProperty.ts\";\nimport {\n type AsyncMethod,\n type Collection,\n type Property,\n type ReactiveGetter,\n type Reference,\n} from \"./relations/index.ts\";\nimport { ReactiveFieldImpl } from \"./relations/ReactiveField.ts\";\nimport { ReactiveGetterImpl } from \"./relations/ReactiveGetter.ts\";\n\n/**\n * A JSON hint of a single key, multiple keys, or nested keys and sub-hints.\n *\n * JSON hints are much like load hints/reactive hints:\n *\n * - Similar to load hints, they specify which relations should be loaded from the database\n * - Similar to reactive hints, they include specific fields to output\n * - Unlike either, they can include completely custom keys that are lambdas to generate custom values\n */\nexport type JsonHint<T extends Entity> =\n | (keyof Jsonable<T> & string)\n | ReadonlyArray<keyof Jsonable<T> & string>\n | NestedJsonHint<T>;\n\n/** For object literal/nested hints, we allow mapping both entity keys 1:1 & custom keys via a lambdas. */\nexport type NestedJsonHint<T extends Entity> = EntityKeyJsonHint<T> | CustomJsonKeyHint<T>;\n\n/** Foreach `Jsonable` key, we can provide a sub-hint, or just a boolean to include/exclude. */\nexport type EntityKeyJsonHint<T extends Entity> = {\n // The `as K` makes `bookIds` as a hint work...\n [K in keyof Jsonable<T> as `${K}`]?: (Jsonable<T>[K] extends infer U extends Entity ? JsonHint<U> : {}) | boolean;\n};\n\nexport type CustomJsonKeyHint<T> = {\n [key: string]: (entity: T) => any;\n};\n\n/**\n * Describes the JSON payload for `Entity.toJSON` to produce.\n *\n * - `[\"firstName\", \"lastName\"]` will produce a JSON payload with just those fields\n * - `{ author: { books: \"title\" } }` will produce a JSON payload with the author's books' titles\n *\n * We only accept object literals & arrays to `toJSON` to avoid a `JSON.stringify` oddity.\n */\nexport type ToJsonHint<T extends Entity> = NestedJsonHint<T> | ReadonlyArray<keyof Jsonable<T> & string>;\n\n/** The keys in `T` that we can put into a JSON payload. */\nexport type Jsonable<T extends Entity> = {\n -readonly [K in keyof T as JsonableValue<T[K]> extends never ? never : K]: JsonableValue<T[K]>;\n};\n\n// this should probably be `keyof T` as long as they aren't methods/AsyncMethods.\n// so primitives, enums, references, collections, async properties, but also random getters.\nexport type JsonableValue<V> =\n V extends Reference<any, infer U, any>\n ? U\n : V extends Collection<any, infer U>\n ? U\n : V extends AsyncMethod<any, any, any>\n ? never\n : V extends Property<any, infer P>\n ? DropUndefined<P>\n : V extends ReactiveGetter<any, infer P>\n ? P\n : V;\n\n/**\n * Provides an API to put an entity, or list of entities, into a JSON payload.\n *\n * The `hint` parameter is a JSON hint that describes what to include in the payload,\n *\n * - fields like `id`, `name`, etc.\n * - relations like m2o, o2m, m2m, and o2o\n * - relations are allowed to provide nested hints, just like nested load hints\n * - custom fields like `fullName: (entity) => entity.firstName + ' ' + entity.lastName`\n */\nexport async function toJSON<T extends Entity, const H extends JsonHint<T>>(\n entity: T,\n hint: H,\n): Promise<JsonPayload<T, H>>;\n\n/**\n * Provides an API to put an entity, or list of entities, into a JSON payload.\n *\n * The `hint` parameter is a JSON hint that describes what to include in the payload,\n *\n * - fields like `id`, `name`, etc.\n * - relations like m2o, o2m, m2m, and o2o\n * - relations are allowed to provide nested hints, just like nested load hints\n * - custom fields like `fullName: (entity) => entity.firstName + ' ' + entity.lastName`\n */\nexport async function toJSON<T extends Entity, const H extends JsonHint<T>>(\n entities: readonly T[],\n hint: H,\n): Promise<JsonPayload<T, H>[]>;\nexport async function toJSON<T extends Entity, const H extends JsonHint<T>>(\n entityOrList: T | readonly T[],\n hint: H,\n): Promise<JsonPayload<T, H> | JsonPayload<T, H>[]> {\n // If called with a list, and nothing there, just early return\n if (Array.isArray(entityOrList) && entityOrList.length === 0) return [];\n\n // Otherwise probe to get our first entity\n const entity = Array.isArray(entityOrList) ? entityOrList[0] : entityOrList;\n const loadHint = convertToLoadHint(getMetadata(entity), hint as any, true);\n await entity.em.populate(entityOrList, loadHint);\n const normHint = normalizeHint(hint as any);\n\n if (Array.isArray(entityOrList)) {\n const list = [] as any;\n await Promise.all(\n entityOrList.map((entity) => {\n const json = {};\n list.push(json);\n return copyToPayload(json, entity, normHint);\n }),\n );\n return list;\n } else {\n const json = {};\n await copyToPayload(json, entity, normHint);\n return json as any;\n }\n}\n\n/**\n * Statically types the return value of `toJSON` based on the given `hint`.\n */\nexport type JsonPayload<T, H> = {\n [HK in keyof NormalizeHint<H> & string]: HK extends keyof T\n ? JsonPayloadKey<T, H, HK, HK>\n : HK extends `${infer TK extends string & keyof T}Id`\n ? JsonPayloadKey<T, H, TK, HK>\n : HK extends `${infer SK extends string}Ids` // bookIds -> books\n ? // Very naive singularization to see if the guessed bookIds -> books actually exists on T to map 1:1\n `${SK}s` extends keyof T\n ? JsonPayloadKey<T, H, `${SK}s`, HK>\n : JsonPayloadCustom<NormalizeHint<H>[HK]>\n : JsonPayloadCustom<NormalizeHint<H>[HK]>;\n};\n\ntype JsonPayloadKey<T, H, TK extends keyof T, HK extends keyof NormalizeHint<H>> =\n T[TK] extends Reference<any, infer U, any>\n ? JsonPayloadReference<U, NormalizeHint<H>[HK]>\n : T[TK] extends Collection<any, infer U>\n ? JsonPayloadCollection<U, NormalizeHint<H>[HK]>\n : T[TK] extends Property<any, infer U>\n ? JsonPayloadProperty<U, NormalizeHint<H>[HK]>\n : T[TK] extends ReactiveGetter<any, infer V>\n ? V\n : T[TK];\n\n// If the hint is empty, we just output the id as a string.\ntype JsonPayloadReference<U, H> = IsEmpty<H> extends true ? string : JsonPayload<U, H>;\n\ntype JsonPayloadCollection<U extends Entity, H> =\n // If this is `books: true`, use the id\n H extends true\n ? IdOf<U>[]\n : // If this is `{}`, use the id\n IsEmpty<H> extends true\n ? IdOf<U>[]\n : // Otherwise it's a nested hint\n JsonPayload<U, H>[];\n\ntype JsonPayloadProperty<P, H> =\n // If an async property returns an entity, treat it like a reference\n P extends Entity | undefined\n ? JsonPayloadReference<P, H>\n : // If an async property returns an entity[], treat it like a collection\n P extends (infer U extends Entity)[] | undefined\n ? JsonPayloadCollection<U, H>\n : // Otherwise leave it as-is\n P;\n\ntype JsonPayloadCustom<H> = H extends (...args: any) => infer V ? UnwrapPromise<V> : H;\n\ntype UnwrapPromise<T> = T extends Promise<infer U> ? U : T;\n\n/** Recursively copies the fields of `hint` from `entity` into the `payload`. */\nasync function copyToPayload(payload: Record<string, {}>, entity: any, hint: object): Promise<void> {\n // Look at each key in the hint and determine\n for (const [payloadKey, nestedHint] of Object.entries(hint)) {\n const nextHint = normalizeHint(nestedHint);\n // Watch for `companyId`\n let entityKey = payloadKey;\n if (!(entityKey in entity)) {\n const field = Object.values(getMetadata(entity).allFields).find((f) => f.fieldIdName === payloadKey);\n if (field) {\n entityKey = field.fieldName;\n }\n }\n // Look for custom props\n if (!(entityKey in entity)) {\n if (typeof nestedHint !== \"function\") {\n throw new Error(`Entity does not have a property ${payloadKey}`);\n }\n payload[payloadKey] = await nestedHint(entity);\n } else {\n const value = entity[entityKey];\n if (isPrimitive(value)) {\n payload[payloadKey] = value;\n } else if (\n value instanceof AbstractRelationImpl ||\n value instanceof ReactiveFieldImpl ||\n value instanceof ReactiveGetterImpl ||\n value instanceof AsyncReactiveFieldImpl ||\n value instanceof PropertyImpl\n ) {\n await copyToPayloadValue(payload, payloadKey, value.get, nextHint);\n } else {\n throw new Error(`Unable to encode value ${value} to JSON`);\n }\n }\n }\n}\n\nfunction copyToPayloadValue(payload: any, key: any, value: any, nextHint: any): Promise<unknown> | undefined {\n if (value === undefined || value === null || isPrimitive(value)) {\n payload[key] = value;\n } else if (isEntity(value)) {\n if (nextHint && Object.keys(nextHint).length > 0) {\n payload[key] = {};\n return copyToPayload(payload[key], value, nextHint);\n } else {\n payload[key] = value.id;\n }\n } else if (Array.isArray(value)) {\n const list = [] as any[];\n payload[key] = list;\n if (nextHint && Object.keys(nextHint).length > 0) {\n return Promise.all(\n value.map(async (item, i) => {\n if (isEntity(item)) {\n list[i] = {};\n return copyToPayload(list[i], item, nextHint);\n } else {\n // This is probably undefined\n list[i] = item;\n }\n }),\n );\n } else {\n // This is assuming an array of entities...\n for (const item of value) list.push(item.id);\n }\n } else {\n payload[key] = value;\n }\n}\n\nfunction isPrimitive(value: any): boolean {\n return value === null || typeof value !== \"object\";\n}\n\ntype DropUndefined<T> = T extends infer U extends Entity | undefined ? U : T;\n\n// A copy/paste of NormalizeHint w/o the `DropSuffix` stuff\ntype NormalizeHint<H> = H extends string\n ? Record<H, {}>\n : H extends ReadonlyArray<any>\n ? Record<H[number], {}>\n : { [K in keyof H]: H[K] };\n\ntype IsEmpty<T> = keyof T extends never ? true : false;\n"],"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,iBAAiB,cAEjB,MAAM,mBAAmB,SAAS,YAAY,MAAM,KAAK,QAAQ;QAEjE,MAAM,IAAI,MAAM,0BAA0B,MAAM,SAAS;EAE7D;CACF;AACF;AAEA,SAAS,mBAAmB,SAAc,KAAU,OAAY,UAA6C;CAC3G,IAAI,UAAU,KAAA,KAAa,UAAU,QAAQ,YAAY,KAAK,GAC5D,QAAQ,OAAO;MACV,IAAI,SAAS,KAAK,GAAG;EAC1B,IAAI,YAAY,OAAO,KAAK,QAAQ,CAAC,CAAC,SAAS,GAAG;GAChD,QAAQ,OAAO,CAAC;GAChB,OAAO,cAAc,QAAQ,MAAM,OAAO,QAAQ;EACpD,OACE,QAAQ,OAAO,MAAM;CAEzB,OAAO,IAAI,MAAM,QAAQ,KAAK,GAAG;EAC/B,MAAM,OAAO,CAAC;EACd,QAAQ,OAAO;EACf,IAAI,YAAY,OAAO,KAAK,QAAQ,CAAC,CAAC,SAAS,GAC7C,OAAO,QAAQ,IACb,MAAM,IAAI,OAAO,MAAM,MAAM;GAC3B,IAAI,SAAS,IAAI,GAAG;IAClB,KAAK,KAAK,CAAC;IACX,OAAO,cAAc,KAAK,IAAI,MAAM,QAAQ;GAC9C,OAEE,KAAK,KAAK;EAEd,CAAC,CACH;OAGA,KAAK,MAAM,QAAQ,OAAO,KAAK,KAAK,KAAK,EAAE;CAE/C,OACE,QAAQ,OAAO;AAEnB;AAEA,SAAS,YAAY,OAAqB;CACxC,OAAO,UAAU,QAAQ,OAAO,UAAU;AAC5C"}
1
+ {"version":3,"file":"json.js","names":[],"sources":["../src/json.ts"],"sourcesContent":["import { type Entity, isEntity } from \"src/Entity.ts\";\nimport { type IdOf } from \"src/EntityManager.ts\";\nimport { getMetadata } from \"src/EntityMetadata.ts\";\nimport { normalizeHint } from \"src/normalizeHints.ts\";\nimport { convertToLoadHint } from \"src/reactivity/reactiveHints.ts\";\nimport { AbstractRelationImpl } from \"src/relations/AbstractRelationImpl.ts\";\nimport { AsyncReactiveFieldImpl } from \"src/relations/AsyncReactiveField.ts\";\nimport { PropertyImpl } from \"src/relations/hasProperty.ts\";\nimport {\n type AsyncMethod,\n type Collection,\n type Property,\n type ReactiveGetter,\n type Reference,\n} from \"src/relations/index.ts\";\nimport { ReactiveFieldImpl } from \"src/relations/ReactiveField.ts\";\nimport { ReactiveGetterImpl } from \"src/relations/ReactiveGetter.ts\";\n\n/**\n * A JSON hint of a single key, multiple keys, or nested keys and sub-hints.\n *\n * JSON hints are much like load hints/reactive hints:\n *\n * - Similar to load hints, they specify which relations should be loaded from the database\n * - Similar to reactive hints, they include specific fields to output\n * - Unlike either, they can include completely custom keys that are lambdas to generate custom values\n */\nexport type JsonHint<T extends Entity> =\n | (keyof Jsonable<T> & string)\n | ReadonlyArray<keyof Jsonable<T> & string>\n | NestedJsonHint<T>;\n\n/** For object literal/nested hints, we allow mapping both entity keys 1:1 & custom keys via a lambdas. */\nexport type NestedJsonHint<T extends Entity> = EntityKeyJsonHint<T> | CustomJsonKeyHint<T>;\n\n/** Foreach `Jsonable` key, we can provide a sub-hint, or just a boolean to include/exclude. */\nexport type EntityKeyJsonHint<T extends Entity> = {\n // The `as K` makes `bookIds` as a hint work...\n [K in keyof Jsonable<T> as `${K}`]?: (Jsonable<T>[K] extends infer U extends Entity ? JsonHint<U> : {}) | boolean;\n};\n\nexport type CustomJsonKeyHint<T> = {\n [key: string]: (entity: T) => any;\n};\n\n/**\n * Describes the JSON payload for `Entity.toJSON` to produce.\n *\n * - `[\"firstName\", \"lastName\"]` will produce a JSON payload with just those fields\n * - `{ author: { books: \"title\" } }` will produce a JSON payload with the author's books' titles\n *\n * We only accept object literals & arrays to `toJSON` to avoid a `JSON.stringify` oddity.\n */\nexport type ToJsonHint<T extends Entity> = NestedJsonHint<T> | ReadonlyArray<keyof Jsonable<T> & string>;\n\n/** The keys in `T` that we can put into a JSON payload. */\nexport type Jsonable<T extends Entity> = {\n -readonly [K in keyof T as JsonableValue<T[K]> extends never ? never : K]: JsonableValue<T[K]>;\n};\n\n// this should probably be `keyof T` as long as they aren't methods/AsyncMethods.\n// so primitives, enums, references, collections, async properties, but also random getters.\nexport type JsonableValue<V> =\n V extends Reference<any, infer U, any>\n ? U\n : V extends Collection<any, infer U>\n ? U\n : V extends AsyncMethod<any, any, any>\n ? never\n : V extends Property<any, infer P>\n ? DropUndefined<P>\n : V extends ReactiveGetter<any, infer P>\n ? P\n : V;\n\n/**\n * Provides an API to put an entity, or list of entities, into a JSON payload.\n *\n * The `hint` parameter is a JSON hint that describes what to include in the payload,\n *\n * - fields like `id`, `name`, etc.\n * - relations like m2o, o2m, m2m, and o2o\n * - relations are allowed to provide nested hints, just like nested load hints\n * - custom fields like `fullName: (entity) => entity.firstName + ' ' + entity.lastName`\n */\nexport async function toJSON<T extends Entity, const H extends JsonHint<T>>(\n entity: T,\n hint: H,\n): Promise<JsonPayload<T, H>>;\n\n/**\n * Provides an API to put an entity, or list of entities, into a JSON payload.\n *\n * The `hint` parameter is a JSON hint that describes what to include in the payload,\n *\n * - fields like `id`, `name`, etc.\n * - relations like m2o, o2m, m2m, and o2o\n * - relations are allowed to provide nested hints, just like nested load hints\n * - custom fields like `fullName: (entity) => entity.firstName + ' ' + entity.lastName`\n */\nexport async function toJSON<T extends Entity, const H extends JsonHint<T>>(\n entities: readonly T[],\n hint: H,\n): Promise<JsonPayload<T, H>[]>;\nexport async function toJSON<T extends Entity, const H extends JsonHint<T>>(\n entityOrList: T | readonly T[],\n hint: H,\n): Promise<JsonPayload<T, H> | JsonPayload<T, H>[]> {\n // If called with a list, and nothing there, just early return\n if (Array.isArray(entityOrList) && entityOrList.length === 0) return [];\n\n // Otherwise probe to get our first entity\n const entity = Array.isArray(entityOrList) ? entityOrList[0] : entityOrList;\n const loadHint = convertToLoadHint(getMetadata(entity), hint as any, true);\n await entity.em.populate(entityOrList, loadHint);\n const normHint = normalizeHint(hint as any);\n\n if (Array.isArray(entityOrList)) {\n const list = [] as any;\n await Promise.all(\n entityOrList.map((entity) => {\n const json = {};\n list.push(json);\n return copyToPayload(json, entity, normHint);\n }),\n );\n return list;\n } else {\n const json = {};\n await copyToPayload(json, entity, normHint);\n return json as any;\n }\n}\n\n/**\n * Statically types the return value of `toJSON` based on the given `hint`.\n */\nexport type JsonPayload<T, H> = {\n [HK in keyof NormalizeHint<H> & string]: HK extends keyof T\n ? JsonPayloadKey<T, H, HK, HK>\n : HK extends `${infer TK extends string & keyof T}Id`\n ? JsonPayloadKey<T, H, TK, HK>\n : HK extends `${infer SK extends string}Ids` // bookIds -> books\n ? // Very naive singularization to see if the guessed bookIds -> books actually exists on T to map 1:1\n `${SK}s` extends keyof T\n ? JsonPayloadKey<T, H, `${SK}s`, HK>\n : JsonPayloadCustom<NormalizeHint<H>[HK]>\n : JsonPayloadCustom<NormalizeHint<H>[HK]>;\n};\n\ntype JsonPayloadKey<T, H, TK extends keyof T, HK extends keyof NormalizeHint<H>> =\n T[TK] extends Reference<any, infer U, any>\n ? JsonPayloadReference<U, NormalizeHint<H>[HK]>\n : T[TK] extends Collection<any, infer U>\n ? JsonPayloadCollection<U, NormalizeHint<H>[HK]>\n : T[TK] extends Property<any, infer U>\n ? JsonPayloadProperty<U, NormalizeHint<H>[HK]>\n : T[TK] extends ReactiveGetter<any, infer V>\n ? V\n : T[TK];\n\n// If the hint is empty, we just output the id as a string.\ntype JsonPayloadReference<U, H> = IsEmpty<H> extends true ? string : JsonPayload<U, H>;\n\ntype JsonPayloadCollection<U extends Entity, H> =\n // If this is `books: true`, use the id\n H extends true\n ? IdOf<U>[]\n : // If this is `{}`, use the id\n IsEmpty<H> extends true\n ? IdOf<U>[]\n : // Otherwise it's a nested hint\n JsonPayload<U, H>[];\n\ntype JsonPayloadProperty<P, H> =\n // If an async property returns an entity, treat it like a reference\n P extends Entity | undefined\n ? JsonPayloadReference<P, H>\n : // If an async property returns an entity[], treat it like a collection\n P extends (infer U extends Entity)[] | undefined\n ? JsonPayloadCollection<U, H>\n : // Otherwise leave it as-is\n P;\n\ntype JsonPayloadCustom<H> = H extends (...args: any) => infer V ? UnwrapPromise<V> : H;\n\ntype UnwrapPromise<T> = T extends Promise<infer U> ? U : T;\n\n/** Recursively copies the fields of `hint` from `entity` into the `payload`. */\nasync function copyToPayload(payload: Record<string, {}>, entity: any, hint: object): Promise<void> {\n // Look at each key in the hint and determine\n for (const [payloadKey, nestedHint] of Object.entries(hint)) {\n const nextHint = normalizeHint(nestedHint);\n // Watch for `companyId`\n let entityKey = payloadKey;\n if (!(entityKey in entity)) {\n const field = Object.values(getMetadata(entity).allFields).find((f) => f.fieldIdName === payloadKey);\n if (field) {\n entityKey = field.fieldName;\n }\n }\n // Look for custom props\n if (!(entityKey in entity)) {\n if (typeof nestedHint !== \"function\") {\n throw new Error(`Entity does not have a property ${payloadKey}`);\n }\n payload[payloadKey] = await nestedHint(entity);\n } else {\n const value = entity[entityKey];\n if (isPrimitive(value)) {\n payload[payloadKey] = value;\n } else if (\n value instanceof AbstractRelationImpl ||\n value instanceof ReactiveFieldImpl ||\n value instanceof ReactiveGetterImpl ||\n value instanceof AsyncReactiveFieldImpl ||\n value instanceof PropertyImpl\n ) {\n await copyToPayloadValue(payload, payloadKey, value.get, nextHint);\n } else {\n throw new Error(`Unable to encode value ${value} to JSON`);\n }\n }\n }\n}\n\nfunction copyToPayloadValue(payload: any, key: any, value: any, nextHint: any): Promise<unknown> | undefined {\n if (value === undefined || value === null || isPrimitive(value)) {\n payload[key] = value;\n } else if (isEntity(value)) {\n if (nextHint && Object.keys(nextHint).length > 0) {\n payload[key] = {};\n return copyToPayload(payload[key], value, nextHint);\n } else {\n payload[key] = value.id;\n }\n } else if (Array.isArray(value)) {\n const list = [] as any[];\n payload[key] = list;\n if (nextHint && Object.keys(nextHint).length > 0) {\n return Promise.all(\n value.map(async (item, i) => {\n if (isEntity(item)) {\n list[i] = {};\n return copyToPayload(list[i], item, nextHint);\n } else {\n // This is probably undefined\n list[i] = item;\n }\n }),\n );\n } else {\n // This is assuming an array of entities...\n for (const item of value) list.push(item.id);\n }\n } else {\n payload[key] = value;\n }\n}\n\nfunction isPrimitive(value: any): boolean {\n return value === null || typeof value !== \"object\";\n}\n\ntype DropUndefined<T> = T extends infer U extends Entity | undefined ? U : T;\n\n// A copy/paste of NormalizeHint w/o the `DropSuffix` stuff\ntype NormalizeHint<H> = H extends string\n ? Record<H, {}>\n : H extends ReadonlyArray<any>\n ? Record<H[number], {}>\n : { [K in keyof H]: H[K] };\n\ntype IsEmpty<T> = keyof T extends never ? true : false;\n"],"mappings":";;;;;;;;;;;;AAwGA,eAAsB,OACpB,cACA,MACkD;CAElD,IAAI,MAAM,QAAQ,YAAY,KAAK,aAAa,WAAW,GAAG,OAAO,CAAC;CAGtE,MAAM,SAAS,MAAM,QAAQ,YAAY,IAAI,aAAa,KAAK;CAC/D,MAAM,WAAW,kBAAkB,YAAY,MAAM,GAAG,MAAa,IAAI;CACzE,MAAM,OAAO,GAAG,SAAS,cAAc,QAAQ;CAC/C,MAAM,WAAW,cAAc,IAAW;CAE1C,IAAI,MAAM,QAAQ,YAAY,GAAG;EAC/B,MAAM,OAAO,CAAC;EACd,MAAM,QAAQ,IACZ,aAAa,KAAK,WAAW;GAC3B,MAAM,OAAO,CAAC;GACd,KAAK,KAAK,IAAI;GACd,OAAO,cAAc,MAAM,QAAQ,QAAQ;EAC7C,CAAC,CACH;EACA,OAAO;CACT,OAAO;EACL,MAAM,OAAO,CAAC;EACd,MAAM,cAAc,MAAM,QAAQ,QAAQ;EAC1C,OAAO;CACT;AACF;;AAyDA,eAAe,cAAc,SAA6B,QAAa,MAA6B;CAElG,KAAK,MAAM,CAAC,YAAY,eAAe,OAAO,QAAQ,IAAI,GAAG;EAC3D,MAAM,WAAW,cAAc,UAAU;EAEzC,IAAI,YAAY;EAChB,IAAI,EAAE,aAAa,SAAS;GAC1B,MAAM,QAAQ,OAAO,OAAO,YAAY,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,MAAM,EAAE,gBAAgB,UAAU;GACnG,IAAI,OACF,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AC5C"}
package/build/keys.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_utils = require("./utils.cjs");
3
2
  require("./relations/index.cjs");
3
+ const require_utils = require("./utils.cjs");
4
4
  const require_EntityMetadata = require("./EntityMetadata.cjs");
5
5
  require("./EntityManager.cjs");
6
6
  const require_Entity = require("./Entity.cjs");
@@ -1 +1 @@
1
- {"version":3,"file":"keys.cjs","names":["assertNever","isEntity","BaseEntity","getMetadata","fail"],"sources":["../src/keys.ts"],"sourcesContent":["import { BaseEntity } from \"./BaseEntity.ts\";\nimport { type Entity, type IdType, isEntity } from \"./Entity.ts\";\nimport { type EntityConstructor, type IdOf, type TaggedId } from \"./EntityManager.ts\";\nimport { type EntityMetadata, getMetadata } from \"./EntityMetadata.ts\";\nimport { type Reference } from \"./relations/index.ts\";\nimport { assertNever, fail } from \"./utils.ts\";\n\nlet tagDelimiter: string | undefined = \":\";\n\n/** Sets the process-wide tagged-id format during metadata boot. */\nexport function setTaggedIdDelimiter(delimiter: string | undefined): void {\n tagDelimiter = delimiter;\n}\n\n// I'm not entirely sure this is still necessary, but use a small subset of EntityMetadata so\n// that this file doesn't have to import the type and potentially create import cycles.\ntype HasTagName = {\n tagName: string;\n /** The database column type, i.e. used to do `::type` casts in Postgres. */\n idDbType: \"bigint\" | \"int\" | \"uuid\" | \"text\";\n};\n\n/** Converts our internal/always-tagged `id` to the domain entity's `id` type (could be a number or uuid). */\nexport function toIdOf<T extends Entity>(meta: EntityMetadata<T>, id: TaggedId | undefined): IdOf<T> | undefined {\n if (!id) return undefined;\n switch (meta.idType) {\n case \"number\":\n return Number(deTagId(meta, id)) as IdOf<T>;\n case \"tagged-string\":\n return id as IdOf<T>;\n case \"untagged-string\":\n return deTagId(meta, id) as IdOf<T>;\n default:\n return assertNever(meta.idType);\n }\n}\n\n// Before a referred-to object is saved, we keep its instance in our data\n// map, and then assume it will be persisted before we're asked to persist\nexport function maybeResolveReferenceToId(\n value: Entity | Reference<any, any, any> | string | undefined,\n): TaggedId | undefined {\n return typeof value === \"string\" ? value : value?.idTaggedMaybe;\n}\n\n/** Converts `value` to a number, i.e. for string ids, unless its undefined. */\nexport function keyToNumber(meta: HasTagName, value: string | number): number;\nexport function keyToNumber(meta: HasTagName, value: string | number | undefined): number | undefined;\nexport function keyToNumber(meta: HasTagName, value: any): number | undefined {\n if (value === undefined || value === null) {\n return undefined;\n } else if (typeof value === \"number\") {\n return value;\n } else if (typeof value === \"string\") {\n if (tagDelimiter === undefined) {\n const id = value.startsWith(meta.tagName) ? value.slice(meta.tagName.length) : value;\n return maybeNumberUnlessUuid(meta, id);\n }\n const delimiterIndex = value.indexOf(tagDelimiter);\n if (delimiterIndex === -1) {\n return maybeNumberUnlessUuid(meta, value);\n }\n const tag = value.slice(0, delimiterIndex);\n if (tag !== meta.tagName) {\n throw new Error(`Invalid tagged id, expected tag ${meta.tagName}, got ${value}`);\n }\n return maybeNumberUnlessUuid(meta, value.slice(delimiterIndex + tagDelimiter.length));\n } else {\n throw new Error(`Invalid key ${value}`);\n }\n}\n\n// UUIDs, text, and bigints are strings at the database boundary, so lie to the type system and pretend they're numbers.\nfunction maybeNumberUnlessUuid(meta: HasTagName, key: string): number {\n switch (meta.idDbType) {\n case \"bigint\":\n case \"uuid\":\n case \"text\":\n return key as any;\n case \"int\":\n return Number(key);\n default:\n assertNever(meta.idDbType);\n }\n}\n\n/** Converts `dbValue` (big int, int, uuid) to a tagged string, unless its undefined. */\nexport function keyToTaggedId(meta: HasTagName, dbValue: string | number): TaggedId | undefined {\n if (dbValue === undefined || dbValue === null) return undefined;\n return `${meta.tagName}${tagDelimiter ?? \"\"}${dbValue}`;\n}\n\n/** Fails if any keys are untagged; internal batch-loader keys must always be tagged. */\nexport function assertIdsAreTagged(keys: readonly string[]): void {\n for (const key of keys) {\n const isTagged = tagDelimiter === undefined ? validSlugId.test(key) : key.indexOf(tagDelimiter) !== -1;\n if (!isTagged) throw new Error(`Key ${key} is missing a tag`);\n }\n}\n\nconst validSlugId = /^([a-z]+)(\\d+)$/i;\nconst uuidIshId = /[0-9a-z-]+/i;\n\n/** Returns whether `id` is tagged and a probably-correct value. */\nexport function isTaggedId(id: string | number): boolean;\n/** Returns whether `id` is tagged and the tag matches `meta`'s tag. */\nexport function isTaggedId(meta: EntityMetadata, id: string): boolean;\nexport function isTaggedId(metaOrId: string | number | HasTagName, id?: string): boolean {\n if (typeof metaOrId === \"number\") {\n // number overload\n return false;\n } else if (typeof metaOrId === \"string\") {\n // string overload\n return tagDelimiter === undefined ? validSlugId.test(metaOrId) : hasTagDelimiter(metaOrId);\n } else {\n // meta + string overload\n return isTaggedIdForMeta(metaOrId, id!);\n }\n}\n\nexport function assertIdIsTagged(id: string): void {\n if (!isTaggedId(id)) {\n throw new Error(`Key is not tagged ${id}`);\n }\n}\n\n/** We accept an entity in case this is m2o storing a not-yet-saved entity. */\nexport function toTaggedId(meta: HasTagName, id: IdType): TaggedId;\nexport function toTaggedId(meta: HasTagName, id: IdType | undefined): TaggedId | undefined;\nexport function toTaggedId(meta: HasTagName, id: IdType | undefined): TaggedId | undefined {\n if (typeof id === \"number\") {\n return `${meta.tagName}${tagDelimiter ?? \"\"}${id}`;\n } else if (typeof id === \"string\") {\n // This seems odd, but is covered by a unit test, so I guess we need it?\n if (id === \"\") return undefined;\n if (tagDelimiter === undefined) {\n const tag = validSlugId.exec(id)?.[1];\n if (tag && tag !== meta.tagName) {\n throw new Error(`Invalid tagged id, expected tag ${meta.tagName}, got ${id}`);\n }\n return tag ? id : `${meta.tagName}${id}`;\n } else {\n const i = id.indexOf(tagDelimiter);\n if (i === -1) return `${meta.tagName}${tagDelimiter}${id}`;\n const tag = id.slice(0, i);\n if (tag !== meta.tagName) {\n throw new Error(`Invalid tagged id, expected tag ${meta.tagName}, got ${id}`);\n }\n }\n }\n return id;\n}\n\n/** Similar to `toTaggedId`, but we accept an entity for handling relations to not-yet-saved entities. */\nexport function ensureTagged<T extends Entity>(\n meta: HasTagName,\n value: T | string | number | undefined,\n): T | TaggedId | undefined {\n return isEntity(value) ? value : toTaggedId(meta, value);\n}\n\n/** Tags a potentially untagged id, while our API inputs still accept either tagged or untagged ids. */\nexport function tagId(meta: HasTagName, id: string | number): string;\nexport function tagId(cstr: EntityConstructor<any>, id: string | number): string;\nexport function tagId(meta: HasTagName, id: string | number | null | undefined): string | undefined;\nexport function tagId(cstr: EntityConstructor<any>, id: string | number | null | undefined): string | undefined;\nexport function tagId(\n metaOrCstr: HasTagName | EntityConstructor<any>,\n id: string | number | null | undefined,\n): string | undefined {\n const meta = metadata(metaOrCstr);\n const tag = meta.tagName;\n if (typeof id === \"number\") {\n return `${tag}${tagDelimiter ?? \"\"}${id}`;\n }\n if (id === null || id === undefined) {\n return undefined;\n }\n if (tagDelimiter === undefined) {\n const existingTag = validSlugId.exec(id)?.[1];\n if (existingTag && existingTag !== tag) {\n throw new Error(`Invalid tagged id, expected tag ${tag}, got ${id}`);\n }\n return existingTag ? id : `${tag}${id}`;\n }\n // Avoid using includes/split, for a faster indexOf + length + startsWith\n const delimiterIndex = id.indexOf(tagDelimiter);\n if (delimiterIndex !== -1) {\n if (delimiterIndex !== tag.length || !id.startsWith(tag)) {\n throw new Error(`Invalid tagged id, expected tag ${tag}, got ${id}`);\n }\n return id;\n }\n return `${tag}${tagDelimiter}${id}`;\n}\n\n/** Adds the tag prefixes. */\nexport function tagIds(meta: HasTagName, keys: readonly (string | number)[]): readonly string[];\nexport function tagIds(cstr: EntityConstructor<any>, keys: readonly (string | number)[]): readonly string[];\nexport function tagIds(\n metaOrCstr: HasTagName | EntityConstructor<any>,\n keys: readonly (string | number)[],\n): readonly string[] {\n return keys.map((k) => tagId(metaOrCstr as any, k));\n}\n\nexport function deTagId(meta: HasTagName, id: string | number): string;\nexport function deTagId(meta: HasTagName, id: string | number | undefined): string | undefined;\nexport function deTagId(entity: Entity): string;\nexport function deTagId(entityOrMeta: Entity | HasTagName, id?: string | number): string | undefined {\n const meta = entityOrMeta instanceof BaseEntity ? getMetadata(entityOrMeta) : (entityOrMeta as HasTagName);\n id = id ?? (entityOrMeta as Entity).id;\n return id === undefined ? undefined : keyToNumber(meta, id).toString();\n}\n\n/** Removes the tag prefixes so we can use the keys for SQL operations. */\nexport function deTagIds(meta: HasTagName, keys: readonly string[]): readonly string[] {\n const deTagged = Array(keys.length);\n for (let i = 0; i < keys.length; i++) deTagged[i] = deTagId(meta, keys[i]);\n return deTagged;\n}\n\n/** Removes the tag prefixes so we can use the keys for SQL operations. */\nexport function unsafeDeTagIds(keys: readonly string[]): readonly string[] {\n const deTagged = Array(keys.length);\n for (let i = 0; i < keys.length; i++) {\n if (tagDelimiter === undefined) {\n deTagged[i] = validSlugId.exec(keys[i])?.[2];\n } else {\n const delimiterIndex = keys[i].indexOf(tagDelimiter);\n deTagged[i] = delimiterIndex === -1 ? undefined : keys[i].slice(delimiterIndex + tagDelimiter.length);\n }\n }\n return deTagged;\n}\n\n/** Given a tagged id, returns its tag. */\nexport function tagFromId(id: string): string {\n if (tagDelimiter === undefined) {\n return validSlugId.exec(id)?.[1] ?? fail(`Unknown tagged id format: \"${id}\"`);\n }\n const delimiterIndex = id.indexOf(tagDelimiter);\n return delimiterIndex > 0 && delimiterIndex + tagDelimiter.length < id.length\n ? id.slice(0, delimiterIndex)\n : fail(`Unknown tagged id format: \"${id}\"`);\n}\n\n/** Returns the metadata needed to format an id. */\nfunction metadata(metaOrCstr: HasTagName | EntityConstructor<any>): HasTagName {\n return typeof metaOrCstr === \"function\" ? getMetadata(metaOrCstr) : metaOrCstr;\n}\n\n/** Returns whether `id` has the tag and database id shape required by `meta`. */\nfunction isTaggedIdForMeta(meta: HasTagName, id: string): boolean {\n if (tagDelimiter === undefined) {\n return validSlugId.exec(id)?.[1] === meta.tagName;\n }\n const delimiterIndex = id.indexOf(tagDelimiter);\n if (delimiterIndex === -1) return false;\n const tag = id.slice(0, delimiterIndex);\n const untaggedId = id.slice(delimiterIndex + tagDelimiter.length);\n if (meta.tagName !== tag) return false;\n switch (meta.idDbType) {\n case \"int\":\n case \"bigint\":\n return !Number.isNaN(Number(untaggedId));\n case \"uuid\":\n return uuidIshId.test(untaggedId);\n case \"text\":\n return true;\n default:\n return assertNever(meta.idDbType);\n }\n}\n\n/** Returns whether `id` has a non-empty tag and value separated by the configured delimiter. */\nfunction hasTagDelimiter(id: string): boolean {\n if (tagDelimiter === undefined) return false;\n const delimiterIndex = id.indexOf(tagDelimiter);\n return delimiterIndex > 0 && delimiterIndex + tagDelimiter.length < id.length;\n}\n"],"mappings":";;;;;;;;AAOA,IAAI,eAAmC;;AAGvC,SAAgB,qBAAqB,WAAqC;CACxE,eAAe;AACjB;;AAWA,SAAgB,OAAyB,MAAyB,IAA+C;CAC/G,IAAI,CAAC,IAAI,OAAO,KAAA;CAChB,QAAQ,KAAK,QAAb;EACE,KAAK,UACH,OAAO,OAAO,QAAQ,MAAM,EAAE,CAAC;EACjC,KAAK,iBACH,OAAO;EACT,KAAK,mBACH,OAAO,QAAQ,MAAM,EAAE;EACzB,SACE,OAAOA,cAAAA,YAAY,KAAK,MAAM;CAClC;AACF;AAIA,SAAgB,0BACd,OACsB;CACtB,OAAO,OAAO,UAAU,WAAW,QAAQ,OAAO;AACpD;AAKA,SAAgB,YAAY,MAAkB,OAAgC;CAC5E,IAAI,UAAU,KAAA,KAAa,UAAU,MACnC;MACK,IAAI,OAAO,UAAU,UAC1B,OAAO;MACF,IAAI,OAAO,UAAU,UAAU;EACpC,IAAI,iBAAiB,KAAA,GAEnB,OAAO,sBAAsB,MADlB,MAAM,WAAW,KAAK,OAAO,IAAI,MAAM,MAAM,KAAK,QAAQ,MAAM,IAAI,KAC1C;EAEvC,MAAM,iBAAiB,MAAM,QAAQ,YAAY;EACjD,IAAI,mBAAmB,IACrB,OAAO,sBAAsB,MAAM,KAAK;EAG1C,IADY,MAAM,MAAM,GAAG,cACrB,MAAM,KAAK,SACf,MAAM,IAAI,MAAM,mCAAmC,KAAK,QA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O,KAAK;CAE5C,MAAM,iBAAiB,GAAG,QAAQ,YAAY;CAC9C,IAAI,mBAAmB,IAAI,OAAO;CAClC,MAAM,MAAM,GAAG,MAAM,GAAG,cAAc;CACtC,MAAM,aAAa,GAAG,MAAM,iBAAiB,aAAa,MAAM;CAChE,IAAI,KAAK,YAAY,KAAK,OAAO;CACjC,QAAQ,KAAK,UAAb;EACE,KAAK;EACL,KAAK,UACH,OAAO,CAAC,OAAO,MAAM,OAAO,UAAU,CAAC;EACzC,KAAK,QACH,OAAO,UAAU,KAAK,UAAU;EAClC,KAAK,QACH,OAAO;EACT,SACE,OAAOH,cAAAA,YAAY,KAAK,QAAQ;CACpC;AACF;;AAGA,SAAS,gBAAgB,IAAqB;CAC5C,IAAI,iBAAiB,KAAA,GAAW,OAAO;CACvC,MAAM,iBAAiB,GAAG,QAAQ,YAAY;CAC9C,OAAO,iBAAiB,KAAK,iBAAiB,aAAa,SAAS,GAAG;AACzE"}
1
+ {"version":3,"file":"keys.cjs","names":["assertNever","isEntity","BaseEntity","getMetadata","fail"],"sources":["../src/keys.ts"],"sourcesContent":["import { BaseEntity } from \"src/BaseEntity.ts\";\nimport { type Entity, type IdType, isEntity } from \"src/Entity.ts\";\nimport { type EntityConstructor, type IdOf, type TaggedId } from \"src/EntityManager.ts\";\nimport { type EntityMetadata, getMetadata } from \"src/EntityMetadata.ts\";\nimport { type Reference } from \"src/relations/index.ts\";\nimport { assertNever, fail } from \"src/utils.ts\";\n\nlet tagDelimiter: string | undefined = \":\";\n\n/** Sets the process-wide tagged-id format during metadata boot. */\nexport function setTaggedIdDelimiter(delimiter: string | undefined): void {\n tagDelimiter = delimiter;\n}\n\n// I'm not entirely sure this is still necessary, but use a small subset of EntityMetadata so\n// that this file doesn't have to import the type and potentially create import cycles.\ntype HasTagName = {\n tagName: string;\n /** The database column type, i.e. used to do `::type` casts in Postgres. */\n idDbType: \"bigint\" | \"int\" | \"uuid\" | \"text\";\n};\n\n/** Converts our internal/always-tagged `id` to the domain entity's `id` type (could be a number or uuid). */\nexport function toIdOf<T extends Entity>(meta: EntityMetadata<T>, id: TaggedId | undefined): IdOf<T> | undefined {\n if (!id) return undefined;\n switch (meta.idType) {\n case \"number\":\n return Number(deTagId(meta, id)) as IdOf<T>;\n case \"tagged-string\":\n return id as IdOf<T>;\n case \"untagged-string\":\n return deTagId(meta, id) as IdOf<T>;\n default:\n return assertNever(meta.idType);\n }\n}\n\n// Before a referred-to object is saved, we keep its instance in our data\n// map, and then assume it will be persisted before we're asked to persist\nexport function maybeResolveReferenceToId(\n value: Entity | Reference<any, any, any> | string | undefined,\n): TaggedId | undefined {\n return typeof value === \"string\" ? value : value?.idTaggedMaybe;\n}\n\n/** Converts `value` to a number, i.e. for string ids, unless its undefined. */\nexport function keyToNumber(meta: HasTagName, value: string | number): number;\nexport function keyToNumber(meta: HasTagName, value: string | number | undefined): number | undefined;\nexport function keyToNumber(meta: HasTagName, value: any): number | undefined {\n if (value === undefined || value === null) {\n return undefined;\n } else if (typeof value === \"number\") {\n return value;\n } else if (typeof value === \"string\") {\n if (tagDelimiter === undefined) {\n const id = value.startsWith(meta.tagName) ? value.slice(meta.tagName.length) : value;\n return maybeNumberUnlessUuid(meta, id);\n }\n const delimiterIndex = value.indexOf(tagDelimiter);\n if (delimiterIndex === -1) {\n return maybeNumberUnlessUuid(meta, value);\n }\n const tag = value.slice(0, delimiterIndex);\n if (tag !== meta.tagName) {\n throw new Error(`Invalid tagged id, expected tag ${meta.tagName}, got ${value}`);\n }\n return maybeNumberUnlessUuid(meta, value.slice(delimiterIndex + tagDelimiter.length));\n } else {\n throw new Error(`Invalid key ${value}`);\n }\n}\n\n// UUIDs, text, and bigints are strings at the database boundary, so lie to the type system and pretend they're numbers.\nfunction maybeNumberUnlessUuid(meta: HasTagName, key: string): number {\n switch (meta.idDbType) {\n case \"bigint\":\n case \"uuid\":\n case \"text\":\n return key as any;\n case \"int\":\n return Number(key);\n default:\n assertNever(meta.idDbType);\n }\n}\n\n/** Converts `dbValue` (big int, int, uuid) to a tagged string, unless its undefined. */\nexport function keyToTaggedId(meta: HasTagName, dbValue: string | number): TaggedId | undefined {\n if (dbValue === undefined || dbValue === null) return undefined;\n return `${meta.tagName}${tagDelimiter ?? \"\"}${dbValue}`;\n}\n\n/** Fails if any keys are untagged; internal batch-loader keys must always be tagged. */\nexport function assertIdsAreTagged(keys: readonly string[]): void {\n for (const key of keys) {\n const isTagged = tagDelimiter === undefined ? validSlugId.test(key) : key.indexOf(tagDelimiter) !== -1;\n if (!isTagged) throw new Error(`Key ${key} is missing a tag`);\n }\n}\n\nconst validSlugId = /^([a-z]+)(\\d+)$/i;\nconst uuidIshId = /[0-9a-z-]+/i;\n\n/** Returns whether `id` is tagged and a probably-correct value. */\nexport function isTaggedId(id: string | number): boolean;\n/** Returns whether `id` is tagged and the tag matches `meta`'s tag. */\nexport function isTaggedId(meta: EntityMetadata, id: string): boolean;\nexport function isTaggedId(metaOrId: string | number | HasTagName, id?: string): boolean {\n if (typeof metaOrId === \"number\") {\n // number overload\n return false;\n } else if (typeof metaOrId === \"string\") {\n // string overload\n return tagDelimiter === undefined ? validSlugId.test(metaOrId) : hasTagDelimiter(metaOrId);\n } else {\n // meta + string overload\n return isTaggedIdForMeta(metaOrId, id!);\n }\n}\n\nexport function assertIdIsTagged(id: string): void {\n if (!isTaggedId(id)) {\n throw new Error(`Key is not tagged ${id}`);\n }\n}\n\n/** We accept an entity in case this is m2o storing a not-yet-saved entity. */\nexport function toTaggedId(meta: HasTagName, id: IdType): TaggedId;\nexport function toTaggedId(meta: HasTagName, id: IdType | undefined): TaggedId | undefined;\nexport function toTaggedId(meta: HasTagName, id: IdType | undefined): TaggedId | undefined {\n if (typeof id === \"number\") {\n return `${meta.tagName}${tagDelimiter ?? \"\"}${id}`;\n } else if (typeof id === \"string\") {\n // This seems odd, but is covered by a unit test, so I guess we need it?\n if (id === \"\") return undefined;\n if (tagDelimiter === undefined) {\n const tag = validSlugId.exec(id)?.[1];\n if (tag && tag !== meta.tagName) {\n throw new Error(`Invalid tagged id, expected tag ${meta.tagName}, got ${id}`);\n }\n return tag ? id : `${meta.tagName}${id}`;\n } else {\n const i = id.indexOf(tagDelimiter);\n if (i === -1) return `${meta.tagName}${tagDelimiter}${id}`;\n const tag = id.slice(0, i);\n if (tag !== meta.tagName) {\n throw new Error(`Invalid tagged id, expected tag ${meta.tagName}, got ${id}`);\n }\n }\n }\n return id;\n}\n\n/** Similar to `toTaggedId`, but we accept an entity for handling relations to not-yet-saved entities. */\nexport function ensureTagged<T extends Entity>(\n meta: HasTagName,\n value: T | string | number | undefined,\n): T | TaggedId | undefined {\n return isEntity(value) ? value : toTaggedId(meta, value);\n}\n\n/** Tags a potentially untagged id, while our API inputs still accept either tagged or untagged ids. */\nexport function tagId(meta: HasTagName, id: string | number): string;\nexport function tagId(cstr: EntityConstructor<any>, id: string | number): string;\nexport function tagId(meta: HasTagName, id: string | number | null | undefined): string | undefined;\nexport function tagId(cstr: EntityConstructor<any>, id: string | number | null | undefined): string | undefined;\nexport function tagId(\n metaOrCstr: HasTagName | EntityConstructor<any>,\n id: string | number | null | undefined,\n): string | undefined {\n const meta = metadata(metaOrCstr);\n const tag = meta.tagName;\n if (typeof id === \"number\") {\n return `${tag}${tagDelimiter ?? \"\"}${id}`;\n }\n if (id === null || id === undefined) {\n return undefined;\n }\n if (tagDelimiter === undefined) {\n const existingTag = validSlugId.exec(id)?.[1];\n if (existingTag && existingTag !== tag) {\n throw new Error(`Invalid tagged id, expected tag ${tag}, got ${id}`);\n }\n return existingTag ? id : `${tag}${id}`;\n }\n // Avoid using includes/split, for a faster indexOf + length + startsWith\n const delimiterIndex = id.indexOf(tagDelimiter);\n if (delimiterIndex !== -1) {\n if (delimiterIndex !== tag.length || !id.startsWith(tag)) {\n throw new Error(`Invalid tagged id, expected tag ${tag}, got ${id}`);\n }\n return id;\n }\n return `${tag}${tagDelimiter}${id}`;\n}\n\n/** Adds the tag prefixes. */\nexport function tagIds(meta: HasTagName, keys: readonly (string | number)[]): readonly string[];\nexport function tagIds(cstr: EntityConstructor<any>, keys: readonly (string | number)[]): readonly string[];\nexport function tagIds(\n metaOrCstr: HasTagName | EntityConstructor<any>,\n keys: readonly (string | number)[],\n): readonly string[] {\n return keys.map((k) => tagId(metaOrCstr as any, k));\n}\n\nexport function deTagId(meta: HasTagName, id: string | number): string;\nexport function deTagId(meta: HasTagName, id: string | number | undefined): string | undefined;\nexport function deTagId(entity: Entity): string;\nexport function deTagId(entityOrMeta: Entity | HasTagName, id?: string | number): string | undefined {\n const meta = entityOrMeta instanceof BaseEntity ? getMetadata(entityOrMeta) : (entityOrMeta as HasTagName);\n id = id ?? (entityOrMeta as Entity).id;\n return id === undefined ? undefined : keyToNumber(meta, id).toString();\n}\n\n/** Removes the tag prefixes so we can use the keys for SQL operations. */\nexport function deTagIds(meta: HasTagName, keys: readonly string[]): readonly string[] {\n const deTagged = Array(keys.length);\n for (let i = 0; i < keys.length; i++) deTagged[i] = deTagId(meta, keys[i]);\n return deTagged;\n}\n\n/** Removes the tag prefixes so we can use the keys for SQL operations. */\nexport function unsafeDeTagIds(keys: readonly string[]): readonly string[] {\n const deTagged = Array(keys.length);\n for (let i = 0; i < keys.length; i++) {\n if (tagDelimiter === undefined) {\n deTagged[i] = validSlugId.exec(keys[i])?.[2];\n } else {\n const delimiterIndex = keys[i].indexOf(tagDelimiter);\n deTagged[i] = delimiterIndex === -1 ? undefined : keys[i].slice(delimiterIndex + tagDelimiter.length);\n }\n }\n return deTagged;\n}\n\n/** Given a tagged id, returns its tag. */\nexport function tagFromId(id: string): string {\n if (tagDelimiter === undefined) {\n return validSlugId.exec(id)?.[1] ?? fail(`Unknown tagged id format: \"${id}\"`);\n }\n const delimiterIndex = id.indexOf(tagDelimiter);\n return delimiterIndex > 0 && delimiterIndex + tagDelimiter.length < id.length\n ? id.slice(0, delimiterIndex)\n : fail(`Unknown tagged id format: \"${id}\"`);\n}\n\n/** Returns the metadata needed to format an id. */\nfunction metadata(metaOrCstr: HasTagName | EntityConstructor<any>): HasTagName {\n return typeof metaOrCstr === \"function\" ? getMetadata(metaOrCstr) : metaOrCstr;\n}\n\n/** Returns whether `id` has the tag and database id shape required by `meta`. */\nfunction isTaggedIdForMeta(meta: HasTagName, id: string): boolean {\n if (tagDelimiter === undefined) {\n return validSlugId.exec(id)?.[1] === meta.tagName;\n }\n const delimiterIndex = id.indexOf(tagDelimiter);\n if (delimiterIndex === -1) return false;\n const tag = id.slice(0, delimiterIndex);\n const untaggedId = id.slice(delimiterIndex + tagDelimiter.length);\n if (meta.tagName !== tag) return false;\n switch (meta.idDbType) {\n case \"int\":\n case \"bigint\":\n return !Number.isNaN(Number(untaggedId));\n case \"uuid\":\n return uuidIshId.test(untaggedId);\n case \"text\":\n return true;\n default:\n return assertNever(meta.idDbType);\n }\n}\n\n/** Returns whether `id` has a non-empty tag and value separated by the configured delimiter. */\nfunction hasTagDelimiter(id: string): boolean {\n if (tagDelimiter === undefined) return false;\n const delimiterIndex = id.indexOf(tagDelimiter);\n return delimiterIndex > 0 && delimiterIndex + tagDelimiter.length < id.length;\n}\n"],"mappings":";;;;;;;;AAOA,IAAI,eAAmC;;AAGvC,SAAgB,qBAAqB,WAAqC;CACxE,eAAe;AACjB;;AAWA,SAAgB,OAAyB,MAAyB,IAA+C;CAC/G,IAAI,CAAC,IAAI,OAAO,KAAA;CAChB,QAAQ,KAAK,QAAb;EACE,KAAK,UACH,OAAO,OAAO,QAAQ,MAAM,EAAE,CAAC;EACjC,KAAK,iBACH,OAAO;EACT,KAAK,mBACH,OAAO,QAAQ,MAAM,EAAE;EACzB,SACE,OAAOA,cAAAA,YAAY,KAAK,MAAM;CAClC;AACF;AAIA,SAAgB,0BACd,OACsB;CACtB,OAAO,OAAO,UAAU,WAAW,QAAQ,OAAO;AACpD;AAKA,SAAgB,YAAY,MAAkB,OAAgC;CAC5E,IAAI,UAAU,KAAA,KAAa,UAAU,MACnC;MACK,IAAI,OAAO,UAAU,UAC1B,OAAO;MACF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