joist-codegen 2.3.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (431) hide show
  1. package/build/EntityDbMetadata.cjs +672 -0
  2. package/build/EntityDbMetadata.cjs.map +1 -0
  3. package/build/EntityDbMetadata.d.cts +301 -0
  4. package/build/EntityDbMetadata.d.cts.map +1 -0
  5. package/build/EntityDbMetadata.d.mts +301 -0
  6. package/build/EntityDbMetadata.d.mts.map +1 -0
  7. package/build/EntityDbMetadata.js +550 -662
  8. package/build/EntityDbMetadata.js.map +1 -1
  9. package/build/_virtual/_rolldown/runtime.cjs +23 -0
  10. package/build/_virtual/_rolldown/runtime.js +5 -0
  11. package/build/assignTags.cjs +45 -0
  12. package/build/assignTags.cjs.map +1 -0
  13. package/build/{assignTags.d.ts → assignTags.d.cts} +8 -4
  14. package/build/assignTags.d.cts.map +1 -0
  15. package/build/assignTags.d.mts +16 -0
  16. package/build/assignTags.d.mts.map +1 -0
  17. package/build/assignTags.js +37 -59
  18. package/build/assignTags.js.map +1 -1
  19. package/build/codemods/Codemod.cjs +2 -0
  20. package/build/codemods/Codemod.d.cts +17 -0
  21. package/build/codemods/Codemod.d.cts.map +1 -0
  22. package/build/codemods/Codemod.d.mts +17 -0
  23. package/build/codemods/Codemod.d.mts.map +1 -0
  24. package/build/codemods/Codemod.js +2 -3
  25. package/build/codemods/JscodeshiftMod.cjs +42 -0
  26. package/build/codemods/JscodeshiftMod.cjs.map +1 -0
  27. package/build/codemods/JscodeshiftMod.d.cts +14 -0
  28. package/build/codemods/JscodeshiftMod.d.cts.map +1 -0
  29. package/build/codemods/JscodeshiftMod.d.mts +14 -0
  30. package/build/codemods/JscodeshiftMod.d.mts.map +1 -0
  31. package/build/codemods/JscodeshiftMod.js +33 -33
  32. package/build/codemods/JscodeshiftMod.js.map +1 -1
  33. package/build/codemods/codemod_0001-rename_has_async_property.cjs +30 -0
  34. package/build/codemods/codemod_0001-rename_has_async_property.cjs.map +1 -0
  35. package/build/codemods/codemod_0001-rename_has_async_property.d.cts +9 -0
  36. package/build/codemods/codemod_0001-rename_has_async_property.d.cts.map +1 -0
  37. package/build/codemods/codemod_0001-rename_has_async_property.d.mts +9 -0
  38. package/build/codemods/codemod_0001-rename_has_async_property.d.mts.map +1 -0
  39. package/build/codemods/codemod_0001-rename_has_async_property.js +21 -25
  40. package/build/codemods/codemod_0001-rename_has_async_property.js.map +1 -1
  41. package/build/codemods/codemod_0002-rename_async_query_fields.cjs +50 -0
  42. package/build/codemods/codemod_0002-rename_async_query_fields.cjs.map +1 -0
  43. package/build/codemods/codemod_0002-rename_async_query_fields.d.cts +9 -0
  44. package/build/codemods/codemod_0002-rename_async_query_fields.d.cts.map +1 -0
  45. package/build/codemods/codemod_0002-rename_async_query_fields.d.mts +9 -0
  46. package/build/codemods/codemod_0002-rename_async_query_fields.d.mts.map +1 -0
  47. package/build/codemods/codemod_0002-rename_async_query_fields.js +38 -52
  48. package/build/codemods/codemod_0002-rename_async_query_fields.js.map +1 -1
  49. package/build/codemods/codemod_0003-rename_find_paginated.cjs +25 -0
  50. package/build/codemods/codemod_0003-rename_find_paginated.cjs.map +1 -0
  51. package/build/codemods/codemod_0003-rename_find_paginated.d.cts +9 -0
  52. package/build/codemods/codemod_0003-rename_find_paginated.d.cts.map +1 -0
  53. package/build/codemods/codemod_0003-rename_find_paginated.d.mts +9 -0
  54. package/build/codemods/codemod_0003-rename_find_paginated.d.mts.map +1 -0
  55. package/build/codemods/codemod_0003-rename_find_paginated.js +17 -26
  56. package/build/codemods/codemod_0003-rename_find_paginated.js.map +1 -1
  57. package/build/codemods/index.cjs +49 -0
  58. package/build/codemods/index.cjs.map +1 -0
  59. package/build/codemods/index.d.cts +12 -0
  60. package/build/codemods/index.d.cts.map +1 -0
  61. package/build/codemods/index.d.mts +12 -0
  62. package/build/codemods/index.d.mts.map +1 -0
  63. package/build/codemods/index.js +34 -42
  64. package/build/codemods/index.js.map +1 -1
  65. package/build/config.cjs +377 -0
  66. package/build/config.cjs.map +1 -0
  67. package/build/config.d.cts +181 -0
  68. package/build/config.d.cts.map +1 -0
  69. package/build/config.d.mts +181 -0
  70. package/build/config.d.mts.map +1 -0
  71. package/build/config.js +309 -347
  72. package/build/config.js.map +1 -1
  73. package/build/docs/cache.cjs +62 -0
  74. package/build/docs/cache.cjs.map +1 -0
  75. package/build/docs/cache.d.cts +17 -0
  76. package/build/docs/cache.d.cts.map +1 -0
  77. package/build/docs/cache.d.mts +17 -0
  78. package/build/docs/cache.d.mts.map +1 -0
  79. package/build/docs/cache.js +52 -53
  80. package/build/docs/cache.js.map +1 -1
  81. package/build/docs/generate-metadata-docs.cjs +32 -0
  82. package/build/docs/generate-metadata-docs.cjs.map +1 -0
  83. package/build/docs/generate-metadata-docs.d.cts +9 -0
  84. package/build/docs/generate-metadata-docs.d.cts.map +1 -0
  85. package/build/docs/generate-metadata-docs.d.mts +9 -0
  86. package/build/docs/generate-metadata-docs.d.mts.map +1 -0
  87. package/build/docs/generate-metadata-docs.js +19 -24
  88. package/build/docs/generate-metadata-docs.js.map +1 -1
  89. package/build/docs/index.cjs +90 -0
  90. package/build/docs/index.cjs.map +1 -0
  91. package/build/docs/index.d.cts +16 -0
  92. package/build/docs/index.d.cts.map +1 -0
  93. package/build/docs/index.d.mts +16 -0
  94. package/build/docs/index.d.mts.map +1 -0
  95. package/build/docs/index.js +75 -80
  96. package/build/docs/index.js.map +1 -1
  97. package/build/docs/markdown.cjs +181 -0
  98. package/build/docs/markdown.cjs.map +1 -0
  99. package/build/docs/{markdown.d.ts → markdown.d.cts} +14 -12
  100. package/build/docs/markdown.d.cts.map +1 -0
  101. package/build/docs/markdown.d.mts +32 -0
  102. package/build/docs/markdown.d.mts.map +1 -0
  103. package/build/docs/markdown.js +152 -220
  104. package/build/docs/markdown.js.map +1 -1
  105. package/build/docs/parsing.cjs +117 -0
  106. package/build/docs/parsing.cjs.map +1 -0
  107. package/build/docs/parsing.d.cts +48 -0
  108. package/build/docs/parsing.d.cts.map +1 -0
  109. package/build/docs/parsing.d.mts +48 -0
  110. package/build/docs/parsing.d.mts.map +1 -0
  111. package/build/docs/parsing.js +89 -88
  112. package/build/docs/parsing.js.map +1 -1
  113. package/build/findEntityScopes.cjs +119 -0
  114. package/build/findEntityScopes.cjs.map +1 -0
  115. package/build/findEntityScopes.d.cts +14 -0
  116. package/build/findEntityScopes.d.cts.map +1 -0
  117. package/build/findEntityScopes.d.mts +14 -0
  118. package/build/findEntityScopes.d.mts.map +1 -0
  119. package/build/findEntityScopes.js +83 -111
  120. package/build/findEntityScopes.js.map +1 -1
  121. package/build/foreignKeyOrdering.cjs +52 -0
  122. package/build/foreignKeyOrdering.cjs.map +1 -0
  123. package/build/foreignKeyOrdering.d.cts +8 -0
  124. package/build/foreignKeyOrdering.d.cts.map +1 -0
  125. package/build/foreignKeyOrdering.d.mts +8 -0
  126. package/build/foreignKeyOrdering.d.mts.map +1 -0
  127. package/build/foreignKeyOrdering.js +46 -55
  128. package/build/foreignKeyOrdering.js.map +1 -1
  129. package/build/generate.cjs +128 -0
  130. package/build/generate.cjs.map +1 -0
  131. package/build/generate.d.cts +17 -0
  132. package/build/generate.d.cts.map +1 -0
  133. package/build/generate.d.mts +17 -0
  134. package/build/generate.d.mts.map +1 -0
  135. package/build/generate.js +111 -124
  136. package/build/generate.js.map +1 -1
  137. package/build/generateEntitiesFile.cjs +46 -0
  138. package/build/generateEntitiesFile.cjs.map +1 -0
  139. package/build/generateEntitiesFile.d.cts +11 -0
  140. package/build/generateEntitiesFile.d.cts.map +1 -0
  141. package/build/generateEntitiesFile.d.mts +11 -0
  142. package/build/generateEntitiesFile.d.mts.map +1 -0
  143. package/build/generateEntitiesFile.js +28 -25
  144. package/build/generateEntitiesFile.js.map +1 -1
  145. package/build/generateEntityCodegenFile.cjs +1011 -0
  146. package/build/generateEntityCodegenFile.cjs.map +1 -0
  147. package/build/generateEntityCodegenFile.d.cts +16 -0
  148. package/build/generateEntityCodegenFile.d.cts.map +1 -0
  149. package/build/generateEntityCodegenFile.d.mts +16 -0
  150. package/build/generateEntityCodegenFile.d.mts.map +1 -0
  151. package/build/generateEntityCodegenFile.js +794 -827
  152. package/build/generateEntityCodegenFile.js.map +1 -1
  153. package/build/generateEntityFile.cjs +23 -0
  154. package/build/generateEntityFile.cjs.map +1 -0
  155. package/build/generateEntityFile.d.cts +9 -0
  156. package/build/generateEntityFile.d.cts.map +1 -0
  157. package/build/generateEntityFile.d.mts +9 -0
  158. package/build/generateEntityFile.d.mts.map +1 -0
  159. package/build/generateEntityFile.js +11 -8
  160. package/build/generateEntityFile.js.map +1 -1
  161. package/build/generateEntityTestFile.cjs +25 -0
  162. package/build/generateEntityTestFile.cjs.map +1 -0
  163. package/build/generateEntityTestFile.d.cts +9 -0
  164. package/build/generateEntityTestFile.d.cts.map +1 -0
  165. package/build/generateEntityTestFile.d.mts +9 -0
  166. package/build/generateEntityTestFile.d.mts.map +1 -0
  167. package/build/generateEntityTestFile.js +10 -7
  168. package/build/generateEntityTestFile.js.map +1 -1
  169. package/build/generateEnumFile.cjs +73 -0
  170. package/build/generateEnumFile.cjs.map +1 -0
  171. package/build/generateEnumFile.d.cts +9 -0
  172. package/build/generateEnumFile.d.cts.map +1 -0
  173. package/build/generateEnumFile.d.mts +9 -0
  174. package/build/generateEnumFile.d.mts.map +1 -0
  175. package/build/generateEnumFile.js +33 -43
  176. package/build/generateEnumFile.js.map +1 -1
  177. package/build/generateFactoriesFiles.cjs +28 -0
  178. package/build/generateFactoriesFiles.cjs.map +1 -0
  179. package/build/generateFactoriesFiles.d.cts +7 -0
  180. package/build/generateFactoriesFiles.d.cts.map +1 -0
  181. package/build/generateFactoriesFiles.d.mts +7 -0
  182. package/build/generateFactoriesFiles.d.mts.map +1 -0
  183. package/build/generateFactoriesFiles.js +21 -16
  184. package/build/generateFactoriesFiles.js.map +1 -1
  185. package/build/generateFlushFunction.cjs +61 -0
  186. package/build/generateFlushFunction.cjs.map +1 -0
  187. package/build/{generateFlushFunction.d.ts → generateFlushFunction.d.cts} +8 -5
  188. package/build/generateFlushFunction.d.cts.map +1 -0
  189. package/build/generateFlushFunction.d.mts +23 -0
  190. package/build/generateFlushFunction.d.mts.map +1 -0
  191. package/build/generateFlushFunction.js +32 -78
  192. package/build/generateFlushFunction.js.map +1 -1
  193. package/build/generateMetadataFile.cjs +315 -0
  194. package/build/generateMetadataFile.cjs.map +1 -0
  195. package/build/generateMetadataFile.d.cts +10 -0
  196. package/build/generateMetadataFile.d.cts.map +1 -0
  197. package/build/generateMetadataFile.d.mts +10 -0
  198. package/build/generateMetadataFile.d.mts.map +1 -0
  199. package/build/generateMetadataFile.js +156 -156
  200. package/build/generateMetadataFile.js.map +1 -1
  201. package/build/generatePgEnumFile.cjs +21 -0
  202. package/build/generatePgEnumFile.cjs.map +1 -0
  203. package/build/generatePgEnumFile.d.cts +9 -0
  204. package/build/generatePgEnumFile.d.cts.map +1 -0
  205. package/build/generatePgEnumFile.d.mts +9 -0
  206. package/build/generatePgEnumFile.d.mts.map +1 -0
  207. package/build/generatePgEnumFile.js +12 -9
  208. package/build/generatePgEnumFile.js.map +1 -1
  209. package/build/index.cjs +135 -0
  210. package/build/index.cjs.map +1 -0
  211. package/build/index.d.cts +12 -0
  212. package/build/index.d.cts.map +1 -0
  213. package/build/index.d.mts +12 -0
  214. package/build/index.d.mts.map +1 -0
  215. package/build/index.js +109 -127
  216. package/build/index.js.map +1 -1
  217. package/build/inheritance.cjs +258 -0
  218. package/build/inheritance.cjs.map +1 -0
  219. package/build/inheritance.d.cts +13 -0
  220. package/build/inheritance.d.cts.map +1 -0
  221. package/build/inheritance.d.mts +13 -0
  222. package/build/inheritance.d.mts.map +1 -0
  223. package/build/inheritance.js +238 -247
  224. package/build/inheritance.js.map +1 -1
  225. package/build/installSkills.cjs +68 -0
  226. package/build/installSkills.cjs.map +1 -0
  227. package/build/installSkills.d.cts +16 -0
  228. package/build/installSkills.d.cts.map +1 -0
  229. package/build/installSkills.d.mts +16 -0
  230. package/build/installSkills.d.mts.map +1 -0
  231. package/build/installSkills.js +67 -0
  232. package/build/installSkills.js.map +1 -0
  233. package/build/keywords.cjs +7 -0
  234. package/build/keywords.cjs.map +1 -0
  235. package/build/keywords.d.cts +5 -0
  236. package/build/keywords.d.cts.map +1 -0
  237. package/build/keywords.d.mts +5 -0
  238. package/build/keywords.d.mts.map +1 -0
  239. package/build/keywords.js +5 -4
  240. package/build/keywords.js.map +1 -1
  241. package/build/loadMetadata.cjs +39 -0
  242. package/build/loadMetadata.cjs.map +1 -0
  243. package/build/loadMetadata.d.cts +31 -0
  244. package/build/loadMetadata.d.cts.map +1 -0
  245. package/build/loadMetadata.d.mts +31 -0
  246. package/build/loadMetadata.d.mts.map +1 -0
  247. package/build/loadMetadata.js +32 -39
  248. package/build/loadMetadata.js.map +1 -1
  249. package/build/logger.cjs +28 -0
  250. package/build/logger.cjs.map +1 -0
  251. package/build/logger.d.cts +13 -0
  252. package/build/logger.d.cts.map +1 -0
  253. package/build/logger.d.mts +13 -0
  254. package/build/logger.d.mts.map +1 -0
  255. package/build/logger.js +17 -16
  256. package/build/logger.js.map +1 -1
  257. package/build/pgMetadata.cjs +332 -0
  258. package/build/pgMetadata.cjs.map +1 -0
  259. package/build/pgMetadata.d.cts +128 -0
  260. package/build/pgMetadata.d.cts.map +1 -0
  261. package/build/pgMetadata.d.mts +128 -0
  262. package/build/pgMetadata.d.mts.map +1 -0
  263. package/build/pgMetadata.js +320 -0
  264. package/build/pgMetadata.js.map +1 -0
  265. package/build/scanEntityFiles.cjs +46 -0
  266. package/build/scanEntityFiles.cjs.map +1 -0
  267. package/build/scanEntityFiles.d.cts +8 -0
  268. package/build/scanEntityFiles.d.cts.map +1 -0
  269. package/build/scanEntityFiles.d.mts +8 -0
  270. package/build/scanEntityFiles.d.mts.map +1 -0
  271. package/build/scanEntityFiles.js +37 -42
  272. package/build/scanEntityFiles.js.map +1 -1
  273. package/build/sortForeignKeys.cjs +99 -0
  274. package/build/sortForeignKeys.cjs.map +1 -0
  275. package/build/{sortForeignKeys.d.ts → sortForeignKeys.d.cts} +8 -5
  276. package/build/sortForeignKeys.d.cts.map +1 -0
  277. package/build/sortForeignKeys.d.mts +35 -0
  278. package/build/sortForeignKeys.d.mts.map +1 -0
  279. package/build/sortForeignKeys.js +88 -117
  280. package/build/sortForeignKeys.js.map +1 -1
  281. package/build/symbols.cjs +238 -0
  282. package/build/symbols.cjs.map +1 -0
  283. package/build/symbols.d.cts +120 -0
  284. package/build/symbols.d.cts.map +1 -0
  285. package/build/symbols.d.mts +120 -0
  286. package/build/symbols.d.mts.map +1 -0
  287. package/build/symbols.js +121 -113
  288. package/build/symbols.js.map +1 -1
  289. package/build/tsdoc.cjs +22 -0
  290. package/build/tsdoc.cjs.map +1 -0
  291. package/build/tsdoc.d.cts +15 -0
  292. package/build/tsdoc.d.cts.map +1 -0
  293. package/build/tsdoc.d.mts +15 -0
  294. package/build/tsdoc.d.mts.map +1 -0
  295. package/build/tsdoc.js +18 -15
  296. package/build/tsdoc.js.map +1 -1
  297. package/build/utils.cjs +175 -0
  298. package/build/utils.cjs.map +1 -0
  299. package/build/utils.d.cts +36 -0
  300. package/build/utils.d.cts.map +1 -0
  301. package/build/utils.d.mts +36 -0
  302. package/build/utils.d.mts.map +1 -0
  303. package/build/utils.js +113 -166
  304. package/build/utils.js.map +1 -1
  305. package/build/write-json-schema.cjs +23 -0
  306. package/build/write-json-schema.cjs.map +1 -0
  307. package/build/write-json-schema.d.cts +1 -0
  308. package/build/write-json-schema.d.mts +1 -0
  309. package/build/write-json-schema.js +19 -13
  310. package/build/write-json-schema.js.map +1 -1
  311. package/package.json +47 -18
  312. package/skills/joist-docs/SKILL.md +142 -0
  313. package/skills/joist-em-basics/SKILL.md +114 -0
  314. package/skills/joist-em-execute/SKILL.md +35 -0
  315. package/skills/joist-em-find/SKILL.md +27 -0
  316. package/skills/joist-em-query/SKILL.md +32 -0
  317. package/skills/joist-partial-updates/SKILL.md +352 -0
  318. package/skills/joist-reactive-hints/SKILL.md +150 -0
  319. package/skills/joist-test-factories/SKILL.md +397 -0
  320. package/skills/joist-upsert/SKILL.md +95 -0
  321. package/build/EntityDbMetadata.d.ts +0 -269
  322. package/build/EntityDbMetadata.d.ts.map +0 -1
  323. package/build/EntityDbMetadata.test.d.ts +0 -2
  324. package/build/EntityDbMetadata.test.d.ts.map +0 -1
  325. package/build/EntityDbMetadata.test.js +0 -211
  326. package/build/EntityDbMetadata.test.js.map +0 -1
  327. package/build/assignTags.d.ts.map +0 -1
  328. package/build/codemods/Codemod.d.ts +0 -14
  329. package/build/codemods/Codemod.d.ts.map +0 -1
  330. package/build/codemods/Codemod.js.map +0 -1
  331. package/build/codemods/JscodeshiftMod.d.ts +0 -11
  332. package/build/codemods/JscodeshiftMod.d.ts.map +0 -1
  333. package/build/codemods/__tests__/codemod_0001-rename_has_async_property.test.d.ts +0 -2
  334. package/build/codemods/__tests__/codemod_0001-rename_has_async_property.test.d.ts.map +0 -1
  335. package/build/codemods/__tests__/codemod_0001-rename_has_async_property.test.js +0 -9
  336. package/build/codemods/__tests__/codemod_0001-rename_has_async_property.test.js.map +0 -1
  337. package/build/codemods/__tests__/codemod_0002-rename_async_query_fields.test.d.ts +0 -2
  338. package/build/codemods/__tests__/codemod_0002-rename_async_query_fields.test.d.ts.map +0 -1
  339. package/build/codemods/__tests__/codemod_0002-rename_async_query_fields.test.js +0 -9
  340. package/build/codemods/__tests__/codemod_0002-rename_async_query_fields.test.js.map +0 -1
  341. package/build/codemods/__tests__/codemod_0003-rename_find_paginated.test.d.ts +0 -2
  342. package/build/codemods/__tests__/codemod_0003-rename_find_paginated.test.d.ts.map +0 -1
  343. package/build/codemods/__tests__/codemod_0003-rename_find_paginated.test.js +0 -9
  344. package/build/codemods/__tests__/codemod_0003-rename_find_paginated.test.js.map +0 -1
  345. package/build/codemods/codemod_0001-rename_has_async_property.d.ts +0 -7
  346. package/build/codemods/codemod_0001-rename_has_async_property.d.ts.map +0 -1
  347. package/build/codemods/codemod_0002-rename_async_query_fields.d.ts +0 -7
  348. package/build/codemods/codemod_0002-rename_async_query_fields.d.ts.map +0 -1
  349. package/build/codemods/codemod_0003-rename_find_paginated.d.ts +0 -7
  350. package/build/codemods/codemod_0003-rename_find_paginated.d.ts.map +0 -1
  351. package/build/codemods/index.d.ts +0 -9
  352. package/build/codemods/index.d.ts.map +0 -1
  353. package/build/codemods/index.test.d.ts +0 -2
  354. package/build/codemods/index.test.d.ts.map +0 -1
  355. package/build/codemods/index.test.js +0 -24
  356. package/build/codemods/index.test.js.map +0 -1
  357. package/build/config.d.ts +0 -167
  358. package/build/config.d.ts.map +0 -1
  359. package/build/config.test.d.ts +0 -2
  360. package/build/config.test.d.ts.map +0 -1
  361. package/build/config.test.js +0 -78
  362. package/build/config.test.js.map +0 -1
  363. package/build/docs/cache.d.ts +0 -14
  364. package/build/docs/cache.d.ts.map +0 -1
  365. package/build/docs/cache.test.d.ts +0 -2
  366. package/build/docs/cache.test.d.ts.map +0 -1
  367. package/build/docs/cache.test.js +0 -47
  368. package/build/docs/cache.test.js.map +0 -1
  369. package/build/docs/generate-metadata-docs.d.ts +0 -6
  370. package/build/docs/generate-metadata-docs.d.ts.map +0 -1
  371. package/build/docs/index.d.ts +0 -9
  372. package/build/docs/index.d.ts.map +0 -1
  373. package/build/docs/index.test.d.ts +0 -2
  374. package/build/docs/index.test.d.ts.map +0 -1
  375. package/build/docs/index.test.js +0 -100
  376. package/build/docs/index.test.js.map +0 -1
  377. package/build/docs/markdown.d.ts.map +0 -1
  378. package/build/docs/markdown.test.d.ts +0 -2
  379. package/build/docs/markdown.test.d.ts.map +0 -1
  380. package/build/docs/markdown.test.js +0 -280
  381. package/build/docs/markdown.test.js.map +0 -1
  382. package/build/docs/parsing.d.ts +0 -42
  383. package/build/docs/parsing.d.ts.map +0 -1
  384. package/build/docs/parsing.test.d.ts +0 -2
  385. package/build/docs/parsing.test.d.ts.map +0 -1
  386. package/build/docs/parsing.test.js +0 -190
  387. package/build/docs/parsing.test.js.map +0 -1
  388. package/build/findEntityScopes.d.ts +0 -11
  389. package/build/findEntityScopes.d.ts.map +0 -1
  390. package/build/foreignKeyOrdering.d.ts +0 -3
  391. package/build/foreignKeyOrdering.d.ts.map +0 -1
  392. package/build/generate.d.ts +0 -12
  393. package/build/generate.d.ts.map +0 -1
  394. package/build/generateEntitiesFile.d.ts +0 -7
  395. package/build/generateEntitiesFile.d.ts.map +0 -1
  396. package/build/generateEntityCodegenFile.d.ts +0 -11
  397. package/build/generateEntityCodegenFile.d.ts.map +0 -1
  398. package/build/generateEntityFile.d.ts +0 -6
  399. package/build/generateEntityFile.d.ts.map +0 -1
  400. package/build/generateEntityTestFile.d.ts +0 -6
  401. package/build/generateEntityTestFile.d.ts.map +0 -1
  402. package/build/generateEnumFile.d.ts +0 -5
  403. package/build/generateEnumFile.d.ts.map +0 -1
  404. package/build/generateFactoriesFiles.d.ts +0 -4
  405. package/build/generateFactoriesFiles.d.ts.map +0 -1
  406. package/build/generateFlushFunction.d.ts.map +0 -1
  407. package/build/generateMetadataFile.d.ts +0 -5
  408. package/build/generateMetadataFile.d.ts.map +0 -1
  409. package/build/generatePgEnumFile.d.ts +0 -5
  410. package/build/generatePgEnumFile.d.ts.map +0 -1
  411. package/build/index.d.ts +0 -11
  412. package/build/index.d.ts.map +0 -1
  413. package/build/inheritance.d.ts +0 -10
  414. package/build/inheritance.d.ts.map +0 -1
  415. package/build/keywords.d.ts +0 -2
  416. package/build/keywords.d.ts.map +0 -1
  417. package/build/loadMetadata.d.ts +0 -26
  418. package/build/loadMetadata.d.ts.map +0 -1
  419. package/build/logger.d.ts +0 -10
  420. package/build/logger.d.ts.map +0 -1
  421. package/build/scanEntityFiles.d.ts +0 -5
  422. package/build/scanEntityFiles.d.ts.map +0 -1
  423. package/build/sortForeignKeys.d.ts.map +0 -1
  424. package/build/symbols.d.ts +0 -108
  425. package/build/symbols.d.ts.map +0 -1
  426. package/build/tsdoc.d.ts +0 -12
  427. package/build/tsdoc.d.ts.map +0 -1
  428. package/build/utils.d.ts +0 -31
  429. package/build/utils.d.ts.map +0 -1
  430. package/build/write-json-schema.d.ts +0 -2
  431. package/build/write-json-schema.d.ts.map +0 -1
@@ -0,0 +1,672 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
3
+ const require_pgMetadata = require("./pgMetadata.cjs");
4
+ const require_utils = require("./utils.cjs");
5
+ const require_config = require("./config.cjs");
6
+ const require_symbols = require("./symbols.cjs");
7
+ require("./loadMetadata.cjs");
8
+ let change_case = require("change-case");
9
+ let joist_utils = require("joist-utils");
10
+ let pluralize = require("pluralize");
11
+ pluralize = require_runtime.__toESM(pluralize, 1);
12
+ let ts_poet = require("ts-poet");
13
+ //#region src/EntityDbMetadata.ts
14
+ const { plural, singular } = pluralize.default;
15
+ /** Adapts PostgreSQL catalog metadata into our specific ORM types. */
16
+ var EntityDbMetadata = class {
17
+ entity;
18
+ primaryKey;
19
+ primitives;
20
+ enums;
21
+ pgEnums;
22
+ manyToOnes;
23
+ oneToManys;
24
+ largeOneToManys;
25
+ oneToOnes;
26
+ manyToManys;
27
+ largeManyToManys;
28
+ manyToManyEnums;
29
+ polymorphics;
30
+ tableName;
31
+ tagName;
32
+ createdAt;
33
+ updatedAt;
34
+ deletedAt;
35
+ baseClassName;
36
+ baseType;
37
+ subTypes = [];
38
+ inheritanceType;
39
+ /** This will only be set on the base meta. */
40
+ stiDiscriminatorField;
41
+ /** This will only be set on the sub metas. */
42
+ stiDiscriminatorValue;
43
+ abstract;
44
+ nonDeferredFkOrder = -1;
45
+ uniqueConstraints;
46
+ /** Gates mutation targets, not reads; false when required columns or array storage have no supported mutation mapping. */
47
+ supportsEmExecute;
48
+ /** Original table fields, captured before inheritance partitions or specializes them. */
49
+ physicalMetadata;
50
+ /** Physical columns ignored by entity fields, retained for direct SQL reads and writes. */
51
+ ignoredColumns;
52
+ constructor(config, table, enums = {}) {
53
+ this.entity = makeEntity(require_utils.tableToEntityName(config, table));
54
+ if (require_utils.isSubClassTable(table)) {
55
+ this.baseClassName = require_utils.tableToEntityName(config, table.columns.get("id").foreignKeys[0].referencedTable);
56
+ this.inheritanceType = "cti";
57
+ }
58
+ this.primaryKey = table.columns.filter((c) => c.isPrimaryKey).map((column) => newPrimitive(config, this.entity, column, table))[0] || require_utils.fail(`No primary key found for ${table.name}`);
59
+ this.primitives = table.columns.filter((c) => !c.isPrimaryKey && !c.isForeignKey).filter((c) => !isEnumArray(c) && !isPgEnum(c)).map((column) => newPrimitive(config, this.entity, column, table)).filter((f) => !f.ignore);
60
+ this.enums = [...table.m2oRelations.filter((r) => require_utils.isEnumTable(config, r.targetTable)).map((r) => newEnumField(config, this.entity, r, enums)).filter((f) => !f.ignore), ...table.columns.filter((c) => isEnumArray(c)).map((column) => newEnumArrayField(config, this.entity, column, enums)).filter((f) => !f.ignore)];
61
+ this.pgEnums = table.columns.filter((c) => isPgEnum(c)).map((column) => newPgEnumField(config, this.entity, column)).filter((f) => !f.ignore);
62
+ this.manyToOnes = table.m2oRelations.filter((r) => !require_utils.isEnumTable(config, r.targetTable)).filter((r) => !isMultiColumnForeignKey(r)).filter((r) => !isComponentOfPolymorphicRelation(config, r)).filter((r) => !isBaseClassForeignKey(r)).map((r) => newManyToOneField(config, this.entity, r)).filter((f) => !f.ignore);
63
+ const allOneToManys = table.o2mRelations.filter((r) => !require_utils.isJoinTable(config, r.targetTable)).filter((r) => !isMultiColumnForeignKey(r)).filter((r) => !isOneToOneRelation(r)).map((r) => newOneToMany(config, this.entity, r)).filter((f) => !require_config.isReactiveReference(config, f.otherEntity, f.otherFieldName)).filter((f) => !f.ignore);
64
+ this.oneToManys = allOneToManys.filter((f) => !f.isLargeCollection);
65
+ this.largeOneToManys = allOneToManys.filter((f) => f.isLargeCollection);
66
+ this.oneToOnes = table.o2mRelations.filter((r) => !require_utils.isJoinTable(config, r.targetTable)).filter((r) => !isMultiColumnForeignKey(r)).filter((r) => !isBaseClassForeignKey(r)).filter((r) => isOneToOneRelation(r)).map((r) => newOneToOne(config, this.entity, r)).filter((f) => !f.ignore);
67
+ const allManyToManys = table.m2mRelations.filter((r) => require_utils.isJoinTable(config, r.joinTable)).filter((r) => !isMultiColumnForeignKey(r)).filter((r) => !require_utils.isEnumTable(config, r.targetTable)).map((r) => newManyToManyField(config, this.entity, r)).filter((f) => !f.ignore);
68
+ this.manyToManys = allManyToManys.filter((f) => !f.isLargeCollection);
69
+ this.largeManyToManys = allManyToManys.filter((f) => f.isLargeCollection);
70
+ this.manyToManyEnums = table.m2mRelations.filter((r) => require_utils.isJoinTable(config, r.joinTable)).filter((r) => !isMultiColumnForeignKey(r)).filter((r) => require_utils.isEnumTable(config, r.targetTable)).map((r) => newManyToManyEnumField(config, this.entity, r, enums)).filter((f) => !f.ignore);
71
+ this.polymorphics = polymorphicRelations(config, table).map((rc) => newPolymorphicField(config, table, this.entity, rc));
72
+ const modeledColumns = /* @__PURE__ */ new Set([
73
+ this.primaryKey.columnName,
74
+ ...this.primitives.map((field) => field.columnName),
75
+ ...this.enums.map((field) => field.columnName),
76
+ ...this.pgEnums.map((field) => field.columnName),
77
+ ...this.manyToOnes.map((field) => field.columnName),
78
+ ...this.polymorphics.flatMap((field) => field.components.map((component) => component.columnName))
79
+ ]);
80
+ this.ignoredColumns = table.columns.filter((column) => !modeledColumns.has(column.name)).map((column) => newPhysicalColumn(config, this.entity, column));
81
+ this.tableName = table.name;
82
+ this.tagName = config.entities[this.entity.name]?.tag;
83
+ this.abstract = config.entities[this.entity.name]?.abstract || false;
84
+ const { createdAtConf, updatedAtConf, deletedAtConf } = require_config.getTimestampConfig(config);
85
+ this.createdAt = this.primitives.find((f) => createdAtConf.names.includes(f.columnName));
86
+ this.updatedAt = this.primitives.find((f) => updatedAtConf.names.includes(f.columnName));
87
+ this.deletedAt = this.primitives.find((f) => deletedAtConf.names.includes(f.columnName));
88
+ this.uniqueConstraints = inferUniqueConstraints(this, table);
89
+ this.supportsEmExecute = table.primaryKey?.columns.length === 1 && this.primaryKey.columnName === "id" && table.columns.every((column) => column.arrayDimension <= 1 && !(isArray(column) && isPgEnum(column))) && ![...this.primitives, ...this.ignoredColumns].some((field) => field.isArray && !field.customSerde && (field.columnType === "jsonb" || !config.temporal && (field.columnType === "date" || field.columnType === "timestamp with time zone" || field.columnType === "timestamp without time zone")));
90
+ }
91
+ get name() {
92
+ return this.entity.name;
93
+ }
94
+ get nonDeferredFks() {
95
+ return [...this.manyToOnes.filter((r) => !r.isDeferredAndDeferrable), ...this.polymorphics.flatMap((p) => p.components).filter((c) => !c.isDeferredAndDeferrable)];
96
+ }
97
+ get nonDeferredManyToManyFks() {
98
+ return this.manyToManys.filter((r) => !r.isDeferredAndDeferrable);
99
+ }
100
+ };
101
+ function isMultiColumnForeignKey(r) {
102
+ return r.foreignKey.columns.length > 1;
103
+ }
104
+ function isBaseClassForeignKey(r) {
105
+ return r.foreignKey.columns.length === 1 && r.foreignKey.columns[0].name === "id";
106
+ }
107
+ function isOneToOneRelation(r) {
108
+ const otherColumn = r.foreignKey.columns[0];
109
+ return (r.targetTable.columns.find((c) => c.name == otherColumn.name)?.uniqueIndexes || []).find(isOneToOneIndex) !== void 0;
110
+ }
111
+ function isOneToOneIndex(i) {
112
+ return i.columns.length === 1 && !i.isPartial;
113
+ }
114
+ /** Infers field names from unique constraints, i.e. `(author_id, title)` becomes `author, title`. */
115
+ function inferUniqueConstraints(meta, table) {
116
+ return table.uniqueConstraints.flatMap((constraint) => {
117
+ if (constraint.index.isPartial) return [];
118
+ const fields = Array.from(constraint.columns).map((column) => fieldNameForColumn(meta, column.name));
119
+ if (fields.some((field) => field === void 0)) return [];
120
+ return [fields];
121
+ });
122
+ }
123
+ /** Returns the queryable field name for a unique constraint column. */
124
+ function fieldNameForColumn(meta, columnName) {
125
+ const primitive = meta.primitives.find((field) => field.columnName === columnName);
126
+ if (primitive && !primitive.derived && !primitive.isArray && !primitive.customSerde) return primitive.fieldName;
127
+ const enumField = meta.enums.find((field) => field.columnName === columnName);
128
+ if (enumField && !enumField.derived && !enumField.isArray) return enumField.fieldName;
129
+ const pgEnum = meta.pgEnums.find((field) => field.columnName === columnName);
130
+ if (pgEnum) return pgEnum.fieldName;
131
+ const manyToOne = meta.manyToOnes.find((field) => field.columnName === columnName);
132
+ if (manyToOne && !manyToOne.derived) return manyToOne.fieldName;
133
+ }
134
+ function polymorphicRelations(config, table) {
135
+ const entity = config.entities[require_utils.tableToEntityName(config, table)];
136
+ return Object.entries(entity?.relations ?? {}).filter(([, r]) => r.polymorphic).map(([fieldName, { polymorphic }]) => ({
137
+ fieldName,
138
+ notNull: polymorphic === "notNull"
139
+ }));
140
+ }
141
+ function polymorphicFieldName(config, r) {
142
+ const { name } = r.foreignKey.columns[0];
143
+ return polymorphicRelations(config, r.type === "m2o" ? r.sourceTable : r.targetTable).find((pr) => name.startsWith(`${(0, change_case.snakeCase)(pr.fieldName)}_`))?.fieldName;
144
+ }
145
+ function isComponentOfPolymorphicRelation(config, r) {
146
+ return polymorphicFieldName(config, r) !== void 0;
147
+ }
148
+ function determineUserType(fieldType, superstruct, zodSchema, userFieldType) {
149
+ if (fieldType === "Object" && superstruct) return superstructType(superstruct);
150
+ if (fieldType === "Object" && zodSchema) return zodSchemaType(zodSchema);
151
+ if (userFieldType) return userFieldTypeType(userFieldType);
152
+ return fieldType;
153
+ }
154
+ function newPrimitive(config, entity, column, table) {
155
+ const fieldName = primitiveFieldName(column.name);
156
+ const columnName = column.name;
157
+ const columnType = column.type.shortName || column.type.name;
158
+ const array = isArray(column);
159
+ const fieldType = mapType(config, table.name, columnName, columnType);
160
+ const customSerde = require_config.serdeConfig(config, entity, fieldName);
161
+ const superstruct = require_config.superstructConfig(config, entity, fieldName);
162
+ const zodSchema = require_config.zodSchemaConfig(config, entity, fieldName);
163
+ const maybeUserType = determineUserType(fieldType, superstruct, zodSchema, require_config.fieldTypeConfig(config, entity, fieldName));
164
+ const unique = column.uniqueIndexes.find(isOneToOneIndex) !== void 0;
165
+ const hasConfigDefault = require_config.isFieldHasDefault(config, entity, fieldName);
166
+ return {
167
+ kind: "primitive",
168
+ columnOwner: entity,
169
+ columnNotNull: column.notNull,
170
+ fieldName,
171
+ columnName,
172
+ columnType,
173
+ fieldType: array ? ts_poet.code`${maybeUserType}[]` : maybeUserType,
174
+ rawFieldType: fieldType,
175
+ notNull: column.notNull,
176
+ columnDefault: column.default,
177
+ columnGenerated: column.isGenerated,
178
+ derived: fieldDerived(config, entity, fieldName),
179
+ protected: require_config.isProtected(config, entity, fieldName),
180
+ unique,
181
+ ignore: require_config.isFieldIgnored(config, entity, fieldName, column.notNull, column.default !== null),
182
+ superstruct: fieldType === "Object" && superstruct ? ts_poet.Import.from(superstruct) : void 0,
183
+ zodSchema: fieldType === "Object" && zodSchema ? ts_poet.Import.from(zodSchema) : void 0,
184
+ customSerde: customSerde ? serdeType(customSerde) : void 0,
185
+ isArray: array,
186
+ hasConfigDefault,
187
+ lazy: require_config.isLazyField(config, entity, fieldName)
188
+ };
189
+ }
190
+ /** Keeps an ignored column's database type without applying entity-only field configuration. */
191
+ function newPhysicalColumn(config, entity, column) {
192
+ const columnType = column.type.shortName || column.type.name;
193
+ const rawFieldType = column.type instanceof require_pgMetadata.EnumType ? "string" : require_utils.mapSimpleDbTypeToTypescriptType(config, columnType);
194
+ const isArray = column.arrayDimension === 1;
195
+ return {
196
+ kind: "primitive",
197
+ columnOwner: entity,
198
+ columnNotNull: column.notNull,
199
+ fieldName: primitiveFieldName(column.name),
200
+ columnName: column.name,
201
+ columnType,
202
+ fieldType: isArray ? ts_poet.code`${rawFieldType}[]` : rawFieldType,
203
+ rawFieldType,
204
+ notNull: column.notNull,
205
+ columnDefault: column.default,
206
+ columnGenerated: column.isGenerated,
207
+ derived: false,
208
+ protected: false,
209
+ unique: false,
210
+ superstruct: void 0,
211
+ zodSchema: void 0,
212
+ customSerde: void 0,
213
+ isArray,
214
+ hasConfigDefault: false
215
+ };
216
+ }
217
+ function fieldDerived(config, entity, fieldName) {
218
+ if (require_config.ormMaintainedFields.includes(fieldName)) return "orm";
219
+ else if (require_config.isGetterField(config, entity, fieldName)) return "sync";
220
+ else if (require_config.isReactiveField(config, entity, fieldName)) return "async";
221
+ else return false;
222
+ }
223
+ function fkFieldDerived(config, entity, fieldName) {
224
+ if (require_config.isReactiveReference(config, entity, fieldName)) return "async";
225
+ else return false;
226
+ }
227
+ function newEnumField(config, entity, r, enums) {
228
+ const column = r.foreignKey.columns[0];
229
+ const columnName = column.name;
230
+ const columnType = column.type.shortName || column.type.name;
231
+ const fieldName = enumFieldName(column.name);
232
+ const enumName = require_utils.tableToEntityName(config, r.targetTable);
233
+ const enumType = (0, ts_poet.imp)(`${enumName}@./entities.ts`);
234
+ const enumDetailType = (0, ts_poet.imp)(`${plural(enumName)}@./entities.ts`);
235
+ const enumDetailsType = (0, ts_poet.imp)(`${enumName}Details@./entities.ts`);
236
+ const notNull = column.notNull;
237
+ const ignore = require_config.isFieldIgnored(config, entity, fieldName, notNull, column.default !== null);
238
+ const hasConfigDefault = require_config.isFieldHasDefault(config, entity, fieldName);
239
+ return {
240
+ kind: "enum",
241
+ columnOwner: entity,
242
+ columnNotNull: column.notNull,
243
+ fieldName,
244
+ columnName,
245
+ columnType,
246
+ columnDefault: column.default,
247
+ columnGenerated: column.isGenerated,
248
+ derived: fieldDerived(config, entity, fieldName),
249
+ enumName,
250
+ enumType,
251
+ enumDetailType,
252
+ enumDetailsType,
253
+ notNull,
254
+ ignore,
255
+ enumRows: enums[r.targetTable.name].rows,
256
+ isArray: false,
257
+ hasConfigDefault
258
+ };
259
+ }
260
+ function newEnumArrayField(config, entity, column, enums) {
261
+ const columnName = column.name;
262
+ const columnType = column.type.shortName || column.type.name;
263
+ const fieldName = enumFieldName(column.name);
264
+ const enumTable = column.comment.replace("enum=", "");
265
+ const enumName = (enums[enumTable] || require_utils.fail(`Could not find enum ${enumTable}`)).name;
266
+ const enumType = (0, ts_poet.imp)(`${enumName}@./entities.ts`);
267
+ const enumDetailType = (0, ts_poet.imp)(`${plural(enumName)}@./entities.ts`);
268
+ const enumDetailsType = (0, ts_poet.imp)(`${enumName}Details@./entities.ts`);
269
+ const notNull = column.notNull;
270
+ const ignore = require_config.isFieldIgnored(config, entity, fieldName, notNull, column.default !== null);
271
+ const hasConfigDefault = require_config.isFieldHasDefault(config, entity, fieldName);
272
+ return {
273
+ kind: "enum",
274
+ columnOwner: entity,
275
+ columnNotNull: column.notNull,
276
+ fieldName,
277
+ columnName,
278
+ columnType,
279
+ columnDefault: column.default,
280
+ columnGenerated: column.isGenerated,
281
+ derived: fieldDerived(config, entity, fieldName),
282
+ enumName,
283
+ enumType,
284
+ enumDetailType,
285
+ enumDetailsType,
286
+ notNull,
287
+ ignore,
288
+ enumRows: enums[enumTable].rows,
289
+ isArray: true,
290
+ hasConfigDefault
291
+ };
292
+ }
293
+ function newPgEnumField(config, entity, column) {
294
+ const fieldName = primitiveFieldName(column.name);
295
+ const columnName = column.name;
296
+ const enumName = (0, change_case.pascalCase)(column.type.name);
297
+ const enumType = (0, ts_poet.imp)(`${enumName}@./entities.ts`);
298
+ const hasConfigDefault = require_config.isFieldHasDefault(config, entity, fieldName);
299
+ return {
300
+ kind: "pg-enum",
301
+ columnOwner: entity,
302
+ columnNotNull: column.notNull,
303
+ fieldName,
304
+ columnName,
305
+ dbType: column.type.name,
306
+ enumType,
307
+ enumName,
308
+ enumValues: column.type.values,
309
+ notNull: column.notNull,
310
+ columnDefault: column.default,
311
+ columnGenerated: column.isGenerated,
312
+ ignore: require_config.isFieldIgnored(config, entity, fieldName, column.notNull, column.default !== null),
313
+ hasConfigDefault
314
+ };
315
+ }
316
+ function newManyToOneField(config, entity, r) {
317
+ const column = r.foreignKey.columns[0];
318
+ const columnName = column.name;
319
+ const dbType = r.foreignKey.columns[0].type.shortName;
320
+ const fieldName = referenceName(config, entity, r);
321
+ const otherEntity = makeEntity(require_utils.tableToEntityName(config, r.targetTable));
322
+ const otherFieldName = column.uniqueIndexes.find(isOneToOneIndex) !== void 0 ? oneToOneName(config, otherEntity, entity, r) : collectionName(config, otherEntity, entity, r).fieldName;
323
+ const notNull = column.notNull;
324
+ const ignore = require_config.isFieldIgnored(config, entity, fieldName, notNull, column.default !== null);
325
+ const isDeferredAndDeferrable = r.foreignKey.isDeferred && r.foreignKey.isDeferrable;
326
+ const derived = fkFieldDerived(config, entity, fieldName);
327
+ const hasConfigDefault = require_config.isFieldHasDefault(config, entity, fieldName);
328
+ return {
329
+ kind: "m2o",
330
+ columnOwner: entity,
331
+ columnNotNull: column.notNull,
332
+ fieldName,
333
+ columnName,
334
+ columnDefault: column.default,
335
+ columnGenerated: column.isGenerated,
336
+ otherEntity,
337
+ otherFieldName,
338
+ notNull,
339
+ ignore,
340
+ derived,
341
+ dbType,
342
+ isDeferredAndDeferrable,
343
+ constraintName: r.foreignKey.name,
344
+ hasConfigDefault,
345
+ onDelete: r.foreignKey.onDelete
346
+ };
347
+ }
348
+ function newOneToMany(config, entity, r) {
349
+ const column = r.foreignKey.columns[0];
350
+ const otherEntity = makeEntity(require_utils.tableToEntityName(config, r.targetTable));
351
+ const { singularName, fieldName } = collectionName(config, entity, otherEntity, r);
352
+ const otherFieldName = referenceName(config, otherEntity, r);
353
+ const orderBy = config.entities[entity.name]?.relations?.[fieldName]?.orderBy ?? config.entities[otherEntity.name]?.orderBy;
354
+ return {
355
+ kind: "o2m",
356
+ fieldName,
357
+ singularName,
358
+ otherEntity,
359
+ otherFieldName,
360
+ otherColumnName: column.name,
361
+ otherColumnNotNull: column.notNull,
362
+ ignore: require_config.isFieldIgnored(config, entity, fieldName) || require_config.isFieldIgnored(config, otherEntity, otherFieldName),
363
+ isLargeCollection: require_config.isLargeCollection(config, entity, fieldName),
364
+ orderBy: require_utils.parseOrder(orderBy),
365
+ softDeletes: require_config.softDeletesConfig(config, entity, fieldName)
366
+ };
367
+ }
368
+ function newOneToOne(config, entity, r) {
369
+ const column = r.foreignKey.columns[0];
370
+ const otherEntity = makeEntity(require_utils.tableToEntityName(config, r.targetTable));
371
+ const fieldName = oneToOneName(config, entity, otherEntity, r);
372
+ const otherFieldName = referenceName(config, otherEntity, r);
373
+ return {
374
+ kind: "o2o",
375
+ fieldName,
376
+ otherEntity,
377
+ otherFieldName,
378
+ otherColumnName: column.name,
379
+ otherColumnNotNull: column.notNull,
380
+ ignore: require_config.isFieldIgnored(config, entity, fieldName) || require_config.isFieldIgnored(config, otherEntity, otherFieldName)
381
+ };
382
+ }
383
+ function newManyToManyField(config, entity, r) {
384
+ const { foreignKey, targetForeignKey, targetTable } = r;
385
+ const otherEntity = makeEntity(require_utils.tableToEntityName(config, targetTable));
386
+ const fieldName = manyToManyName(targetForeignKey.columns[0]);
387
+ const otherFieldName = manyToManyName(foreignKey.columns[0]);
388
+ const isDeferredAndDeferrable = targetForeignKey.isDeferred && targetForeignKey.isDeferrable;
389
+ const isThisSideDerived = require_config.isReactiveManyToMany(config, entity, fieldName);
390
+ const isOtherSideDerived = require_config.isReactiveManyToMany(config, otherEntity, otherFieldName);
391
+ const derived = isThisSideDerived ? "async" : isOtherSideDerived ? "otherSide" : false;
392
+ return {
393
+ kind: "m2m",
394
+ joinTableName: r.joinTable.name,
395
+ fieldName,
396
+ singularName: singular(fieldName),
397
+ columnName: foreignKey.columns[0].name,
398
+ otherEntity,
399
+ otherFieldName,
400
+ otherColumnName: targetForeignKey.columns[0].name,
401
+ ignore: require_config.isFieldIgnored(config, entity, fieldName) || require_config.isFieldIgnored(config, otherEntity, otherFieldName),
402
+ isLargeCollection: require_config.isLargeCollection(config, entity, fieldName),
403
+ isDeferredAndDeferrable,
404
+ derived,
405
+ softDeletes: require_config.softDeletesConfig(config, entity, fieldName),
406
+ hasJoinTableId: require_utils.joinTableHasId(r.joinTable)
407
+ };
408
+ }
409
+ function newManyToManyEnumField(config, entity, r, enums) {
410
+ const { foreignKey, targetForeignKey, targetTable } = r;
411
+ const fieldName = manyToManyName(targetForeignKey.columns[0]);
412
+ const enumName = require_utils.tableToEntityName(config, targetTable);
413
+ return {
414
+ kind: "m2mEnum",
415
+ joinTableName: r.joinTable.name,
416
+ fieldName,
417
+ columnName: foreignKey.columns[0].name,
418
+ otherColumnName: targetForeignKey.columns[0].name,
419
+ enumName,
420
+ enumType: (0, ts_poet.imp)(`${enumName}@./entities.ts`),
421
+ enumDetailType: (0, ts_poet.imp)(`${plural(enumName)}@./entities.ts`),
422
+ enumDetailsType: (0, ts_poet.imp)(`${enumName}Details@./entities.ts`),
423
+ enumRows: enums[targetTable.name].rows,
424
+ ignore: require_config.isFieldIgnored(config, entity, fieldName),
425
+ hasJoinTableId: require_utils.joinTableHasId(r.joinTable)
426
+ };
427
+ }
428
+ function newPolymorphicField(config, table, entity, pr) {
429
+ const { fieldName, notNull } = pr;
430
+ const components = table.m2oRelations.filter((r) => !require_utils.isEnumTable(config, r.targetTable)).filter((r) => !isMultiColumnForeignKey(r)).filter((r) => polymorphicFieldName(config, r) === fieldName).map((r) => newPolymorphicFieldComponent(config, entity, r));
431
+ return {
432
+ kind: "poly",
433
+ fieldName,
434
+ fieldType: `${entity.name}${(0, change_case.pascalCase)(fieldName)}`,
435
+ notNull,
436
+ components,
437
+ hasConfigDefault: require_config.isFieldHasDefault(config, entity, fieldName)
438
+ };
439
+ }
440
+ function newPolymorphicFieldComponent(config, entity, r) {
441
+ const column = r.foreignKey.columns[0];
442
+ const columnName = column.name;
443
+ const otherEntity = makeEntity(require_utils.tableToEntityName(config, r.targetTable));
444
+ return {
445
+ columnName,
446
+ columnOwner: entity,
447
+ otherEntity,
448
+ otherFieldName: column.uniqueIndexes.find(isOneToOneIndex) !== void 0 ? oneToOneName(config, otherEntity, entity, r) : collectionName(config, otherEntity, entity, r).fieldName,
449
+ isDeferredAndDeferrable: r.foreignKey.isDeferred && r.foreignKey.isDeferrable,
450
+ constraintName: r.foreignKey.name,
451
+ notNull: false
452
+ };
453
+ }
454
+ function isFieldNameOverrides(maybeOverride) {
455
+ return maybeOverride !== null && !Array.isArray(maybeOverride) && typeof maybeOverride === "object" && Object.keys(maybeOverride).some((k) => k === "fieldName" || k === "otherFieldName");
456
+ }
457
+ /** Finds the field name for o2o side of a o2o/m2o. */
458
+ function oneToOneName(config, refEntity, keyEntity, r) {
459
+ const overrides = r.foreignKey.columns[0].commentData;
460
+ if (isFieldNameOverrides(overrides) && overrides.otherFieldName) return overrides.otherFieldName;
461
+ if (!(r instanceof require_pgMetadata.M2ORelation ? r.targetTable : r.sourceTable).m2oRelations.find((s) => require_utils.tableToEntityName(config, s.targetTable) === keyEntity.name)) return (0, change_case.camelCase)(keyEntity.name);
462
+ else {
463
+ let fieldName = r.foreignKey.columns[0].name.replace(idSuffix, "");
464
+ fieldName = `${fieldName}_${keyEntity.name}`;
465
+ fieldName = fieldName.replace(refEntity.name.toLowerCase(), "");
466
+ return (0, change_case.camelCase)(fieldName);
467
+ }
468
+ }
469
+ const idSuffix = /_id$|Id$/;
470
+ function referenceName(config, entity, r) {
471
+ const [column] = r.foreignKey.columns;
472
+ const overrides = column.commentData;
473
+ return polymorphicFieldName(config, r) ?? (isFieldNameOverrides(overrides) ? overrides.fieldName : void 0) ?? (0, change_case.camelCase)(column.name.replace(idSuffix, ""));
474
+ }
475
+ function enumFieldName(columnName) {
476
+ return (0, change_case.camelCase)(columnName.replace(idSuffix, ""));
477
+ }
478
+ function primitiveFieldName(columnName) {
479
+ return (0, change_case.camelCase)(columnName);
480
+ }
481
+ function manyToManyName(column) {
482
+ const overrides = column.commentData;
483
+ if (isFieldNameOverrides(overrides) && overrides.otherFieldName) return overrides.otherFieldName;
484
+ return (0, change_case.camelCase)(plural(column.name.replace(idSuffix, "")));
485
+ }
486
+ /** Returns the collection name to use on `entity` when referring to `otherEntity`s. */
487
+ function collectionName(config, singleEntity, collectionEntity, r) {
488
+ const [column] = r.foreignKey.columns;
489
+ const overrides = column.commentData;
490
+ if (isFieldNameOverrides(overrides) && overrides.otherFieldName) {
491
+ const fieldName = overrides.otherFieldName;
492
+ return {
493
+ fieldName,
494
+ singularName: singular(fieldName)
495
+ };
496
+ }
497
+ let singularName = collectionEntity.name;
498
+ const sourceTable = r.type === "m2o" ? r.sourceTable : r.targetTable;
499
+ const targetTable = r.type === "m2o" ? r.targetTable : r.sourceTable;
500
+ if (r.type !== "m2m" && sourceTable.m2oRelations.filter((r) => r.targetTable === targetTable).length > 1) singularName = `${column.name.replace(idSuffix, "")}_${singularName}`;
501
+ if (singularName.length > singleEntity.name.length && singularName.startsWith(singleEntity.name)) singularName = singularName.substring(singleEntity.name.length);
502
+ singularName = (0, change_case.camelCase)(singularName);
503
+ return {
504
+ fieldName: plural(singularName),
505
+ singularName
506
+ };
507
+ }
508
+ function failIfOverlappingFieldNames(entity) {
509
+ const allFields = [
510
+ entity.primaryKey,
511
+ ...entity.primitives,
512
+ ...entity.enums,
513
+ ...entity.pgEnums,
514
+ ...entity.manyToOnes,
515
+ ...entity.oneToManys,
516
+ ...entity.largeOneToManys,
517
+ ...entity.oneToOnes,
518
+ ...entity.manyToManys,
519
+ ...entity.largeManyToManys,
520
+ ...entity.manyToManyEnums,
521
+ ...entity.polymorphics
522
+ ];
523
+ Object.entries((0, joist_utils.groupBy)(allFields, (f) => f.fieldName)).forEach(([fieldName, fields]) => {
524
+ if (fields.length > 1) throw new Error(`In ${entity.name}, found multiple fields named '${fieldName}': ${fields.map((f) => f.kind).join(" ")}`);
525
+ });
526
+ }
527
+ function makeEntity(entityName) {
528
+ const names = entitySymbolNames(entityName);
529
+ return {
530
+ name: entityName,
531
+ type: entityType(entityName),
532
+ typeSymbol: entityTypeSymbol(entityName),
533
+ typeForMetadataFile: entityTypeForMetadataFile(entityName),
534
+ metaName: metaName(entityName),
535
+ metaType: metaType(entityName),
536
+ idType: entityTypeImport(entityName, names.idName),
537
+ orderType: entityTypeImport(entityName, names.orderName),
538
+ optsType: entityTypeImport(entityName, names.optsName),
539
+ configConst: (0, ts_poet.imp)(`${(0, change_case.camelCase)(entityName)}Config@./entities.ts`, { definedIn: `./codegen/${entityName}Codegen.ts` }),
540
+ ...names
541
+ };
542
+ }
543
+ /**
544
+ * Collapses the per-relation `otherEntity` copies down to the one primary `Entity` per name.
545
+ *
546
+ * `makeEntity` mints a fresh `Entity` for every relation's `otherEntity`, so each entity ends up with
547
+ * many duplicate objects floating around. Pointing them all at the single `entitiesByName[name].entity`
548
+ * instance means later passes (i.e. `resolveNameConflicts`) only have to update one object per name.
549
+ *
550
+ * Must run after inheritance, since STI/CTI specialization both adds and re-points `otherEntity`s.
551
+ */
552
+ function canonicalizeOtherEntities(db) {
553
+ const canonical = (other) => db.entitiesByName[other.name]?.entity ?? other;
554
+ for (const meta of db.entities) {
555
+ for (const field of [
556
+ ...meta.manyToOnes,
557
+ ...meta.oneToManys,
558
+ ...meta.largeOneToManys,
559
+ ...meta.oneToOnes,
560
+ ...meta.manyToManys,
561
+ ...meta.largeManyToManys
562
+ ]) field.otherEntity = canonical(field.otherEntity);
563
+ for (const poly of meta.polymorphics) for (const comp of poly.components) comp.otherEntity = canonical(comp.otherEntity);
564
+ if (meta.physicalMetadata) canonicalizeOtherEntities({
565
+ ...db,
566
+ entities: [meta.physicalMetadata]
567
+ });
568
+ }
569
+ }
570
+ /**
571
+ * Rewrites codegen'd type names that collide with another exported type name.
572
+ *
573
+ * `makeEntity` defaults each name to the conventional `${name}<Suffix>`, but if a separate entity or
574
+ * enum is literally named e.g. `AuthorScope` or `AuthorOrder`, our generated type of the same name
575
+ * would collide with it, so we fall back to `Author_Scope` / `Author_Order`.
576
+ *
577
+ * Relies on `canonicalizeOtherEntities` having run, so mutating each primary `meta.entity` also updates
578
+ * the `otherEntity` references that point at it (e.g. `Book.author: AuthorId` follows `Author`'s rename).
579
+ */
580
+ function resolveNameConflicts(config, db) {
581
+ const reserved = new Set(db.entities.map((meta) => meta.name));
582
+ for (const enumData of Object.values(db.enums)) {
583
+ const enumName = require_utils.tableToEntityName(config, enumData.table);
584
+ reserved.add(enumName).add(`${enumName}Details`).add(plural(enumName));
585
+ }
586
+ for (const pgEnum of Object.values(db.pgEnums)) reserved.add(pgEnum.name);
587
+ for (const meta of db.entities) if (hasNameConflict(meta.name, reserved)) applyEntityNames(meta.entity, reserved);
588
+ }
589
+ /** Computes the codegen'd type names for an entity, underscoring any that `reserved` already contains. */
590
+ function entitySymbolNames(name, reserved) {
591
+ const pick = (suffix) => reserved?.has(`${name}${suffix}`) ? `${name}_${suffix}` : `${name}${suffix}`;
592
+ return {
593
+ idName: pick("Id"),
594
+ fieldsName: pick("Fields"),
595
+ optsName: pick("Opts"),
596
+ idsOptsName: pick("IdsOpts"),
597
+ filterName: pick("Filter"),
598
+ graphqlFilterName: pick("GraphQLFilter"),
599
+ orderName: pick("Order"),
600
+ factoryExtrasName: pick("FactoryExtras"),
601
+ scopeName: pick("Scope"),
602
+ scopesName: pick("Scopes")
603
+ };
604
+ }
605
+ /** Returns true if any of the entity's conventional type names is already taken. */
606
+ function hasNameConflict(name, reserved) {
607
+ return Object.values(entitySymbolNames(name)).some((conventional) => reserved.has(conventional));
608
+ }
609
+ /** Rewrites an entity's type names (and the `Import`s built from them) to their de-conflicted form. */
610
+ function applyEntityNames(entity, reserved) {
611
+ const names = entitySymbolNames(entity.name, reserved);
612
+ Object.assign(entity, names);
613
+ entity.idType = entityTypeImport(entity.name, names.idName);
614
+ entity.orderType = entityTypeImport(entity.name, names.orderName);
615
+ entity.optsType = entityTypeImport(entity.name, names.optsName);
616
+ }
617
+ function entityTypeImport(entityName, symbolName) {
618
+ return (0, ts_poet.imp)(`t:${symbolName}@./entities.ts`, { definedIn: `./codegen/${entityName}Codegen.ts` });
619
+ }
620
+ function metaName(entityName) {
621
+ return `${(0, change_case.camelCase)(entityName)}Meta`;
622
+ }
623
+ function metaType(entityName) {
624
+ return (0, ts_poet.imp)(`${metaName(entityName)}@./entities.ts`);
625
+ }
626
+ function entityType(entityName) {
627
+ return (0, ts_poet.imp)(`t:${entityName}@./entities.ts`);
628
+ }
629
+ function entityTypeSymbol(entityName) {
630
+ return (0, ts_poet.imp)(`${entityName}@./entities.ts`);
631
+ }
632
+ function entityTypeForMetadataFile(entityName) {
633
+ return (0, ts_poet.imp)(`${entityName}@./${entityName}.ts`);
634
+ }
635
+ function mapType(config, tableName, columnName, dbColumnType) {
636
+ return require_utils.mapSimpleDbTypeToTypescriptType(config, dbColumnType);
637
+ }
638
+ function isEnumArray(c) {
639
+ return c.arrayDimension === 1 && !!c.comment && c.comment.startsWith("enum=");
640
+ }
641
+ function isArray(c) {
642
+ return c.arrayDimension === 1;
643
+ }
644
+ function isPgEnum(c) {
645
+ return c.type instanceof require_pgMetadata.EnumType;
646
+ }
647
+ function superstructType(s) {
648
+ const [symbol, ...path] = s.split("@");
649
+ return ts_poet.Import.from(`${(0, change_case.pascalCase)(symbol)}@${path.join("@")}`);
650
+ }
651
+ function zodSchemaType(s) {
652
+ const schema = ts_poet.Import.from(s);
653
+ return ts_poet.code`${require_symbols.Zod}.input<typeof ${schema}>`;
654
+ }
655
+ function userFieldTypeType(s) {
656
+ return ts_poet.Import.from(`t:${s}`);
657
+ }
658
+ function serdeType(s) {
659
+ return ts_poet.Import.from(s);
660
+ }
661
+ //#endregion
662
+ exports.EntityDbMetadata = EntityDbMetadata;
663
+ exports.canonicalizeOtherEntities = canonicalizeOtherEntities;
664
+ exports.collectionName = collectionName;
665
+ exports.failIfOverlappingFieldNames = failIfOverlappingFieldNames;
666
+ exports.makeEntity = makeEntity;
667
+ exports.manyToManyName = manyToManyName;
668
+ exports.oneToOneName = oneToOneName;
669
+ exports.referenceName = referenceName;
670
+ exports.resolveNameConflicts = resolveNameConflicts;
671
+
672
+ //# sourceMappingURL=EntityDbMetadata.cjs.map