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
@@ -1,773 +1,661 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EntityDbMetadata = void 0;
4
- exports.oneToOneName = oneToOneName;
5
- exports.referenceName = referenceName;
6
- exports.manyToManyName = manyToManyName;
7
- exports.collectionName = collectionName;
8
- exports.failIfOverlappingFieldNames = failIfOverlappingFieldNames;
9
- exports.makeEntity = makeEntity;
10
- exports.canonicalizeOtherEntities = canonicalizeOtherEntities;
11
- exports.resolveNameConflicts = resolveNameConflicts;
12
- const change_case_1 = require("change-case");
13
- const joist_utils_1 = require("joist-utils");
14
- const pg_structure_1 = require("pg-structure");
15
- const pluralize_1 = require("pluralize");
16
- const ts_poet_1 = require("ts-poet");
17
- const config_1 = require("./config");
18
- const symbols_1 = require("./symbols");
19
- const utils_1 = require("./utils");
20
- /** Adapts the generally-great pg-structure metadata into our specific ORM types. */
21
- class EntityDbMetadata {
22
- entity;
23
- primaryKey;
24
- primitives;
25
- enums;
26
- pgEnums;
27
- manyToOnes;
28
- oneToManys;
29
- largeOneToManys;
30
- oneToOnes;
31
- manyToManys;
32
- largeManyToManys;
33
- manyToManyEnums;
34
- polymorphics;
35
- tableName;
36
- tagName;
37
- createdAt;
38
- updatedAt;
39
- deletedAt;
40
- baseClassName;
41
- baseType;
42
- subTypes = [];
43
- inheritanceType;
44
- /** This will only be set on the base meta. */
45
- stiDiscriminatorField;
46
- /** This will only be set on the sub metas. */
47
- stiDiscriminatorValue;
48
- abstract;
49
- nonDeferredFkOrder = -1;
50
- uniqueConstraints;
51
- constructor(config, table, enums = {}) {
52
- this.entity = makeEntity((0, utils_1.tableToEntityName)(config, table));
53
- if ((0, utils_1.isSubClassTable)(table)) {
54
- this.baseClassName = (0, utils_1.tableToEntityName)(config, table.columns.get("id").foreignKeys[0].referencedTable);
55
- this.inheritanceType = "cti";
56
- }
57
- this.primaryKey =
58
- table.columns
59
- .filter((c) => c.isPrimaryKey)
60
- .map((column) => newPrimitive(config, this.entity, column, table))[0] ||
61
- (0, utils_1.fail)(`No primary key found for ${table.name}`);
62
- this.primitives = table.columns
63
- .filter((c) => !c.isPrimaryKey && !c.isForeignKey)
64
- .filter((c) => !isEnumArray(c) && !isPgEnum(c))
65
- .map((column) => newPrimitive(config, this.entity, column, table))
66
- .filter((f) => !f.ignore);
67
- this.enums = [
68
- ...table.m2oRelations
69
- .filter((r) => (0, utils_1.isEnumTable)(config, r.targetTable))
70
- .map((r) => newEnumField(config, this.entity, r, enums))
71
- .filter((f) => !f.ignore),
72
- ...table.columns
73
- .filter((c) => isEnumArray(c))
74
- .map((column) => newEnumArrayField(config, this.entity, column, enums))
75
- .filter((f) => !f.ignore),
76
- ];
77
- this.pgEnums = [
78
- ...table.columns
79
- .filter((c) => isPgEnum(c))
80
- .map((column) => newPgEnumField(config, this.entity, column))
81
- .filter((f) => !f.ignore),
82
- ];
83
- this.manyToOnes = table.m2oRelations
84
- .filter((r) => !(0, utils_1.isEnumTable)(config, r.targetTable))
85
- .filter((r) => !isMultiColumnForeignKey(r))
86
- .filter((r) => !isComponentOfPolymorphicRelation(config, r))
87
- .filter((r) => !isBaseClassForeignKey(r))
88
- .map((r) => newManyToOneField(config, this.entity, r))
89
- .filter((f) => !f.ignore);
90
- // We split these into regular/large...
91
- const allOneToManys = table.o2mRelations
92
- // ManyToMany join tables also show up as OneToMany tables in pg-structure
93
- .filter((r) => !(0, utils_1.isJoinTable)(config, r.targetTable))
94
- .filter((r) => !isMultiColumnForeignKey(r))
95
- .filter((r) => !isOneToOneRelation(r))
96
- .map((r) => newOneToMany(config, this.entity, r))
97
- // Do not generate o2m for ReactiveReferences
98
- .filter((f) => !(0, config_1.isReactiveReference)(config, f.otherEntity, f.otherFieldName))
99
- .filter((f) => !f.ignore);
100
- this.oneToManys = allOneToManys.filter((f) => !f.isLargeCollection);
101
- this.largeOneToManys = allOneToManys.filter((f) => f.isLargeCollection);
102
- this.oneToOnes = table.o2mRelations
103
- // ManyToMany join tables also show up as OneToMany tables in pg-structure
104
- .filter((r) => !(0, utils_1.isJoinTable)(config, r.targetTable))
105
- .filter((r) => !isMultiColumnForeignKey(r))
106
- .filter((r) => !isBaseClassForeignKey(r))
107
- .filter((r) => isOneToOneRelation(r))
108
- .map((r) => newOneToOne(config, this.entity, r))
109
- .filter((f) => !f.ignore);
110
- // We split these into regular/large
111
- const allManyToManys = table.m2mRelations
112
- // pg-structure is really loose on what it considers a m2m relationship, i.e. any entity
113
- // that has a foreign key to us, and a foreign key to something else, is automatically
114
- // considered as a join table/m2m between "us" and "something else". Filter these out
115
- // by looking for only true join tables, i.e. tables with only id, fk1, and fk2.
116
- .filter((r) => (0, utils_1.isJoinTable)(config, r.joinTable))
117
- .filter((r) => !isMultiColumnForeignKey(r))
118
- // Join tables whose "other" side is an enum table become EnumCollections instead.
119
- .filter((r) => !(0, utils_1.isEnumTable)(config, r.targetTable))
120
- .map((r) => newManyToManyField(config, this.entity, r))
121
- .filter((f) => !f.ignore);
122
- this.manyToManys = allManyToManys.filter((f) => !f.isLargeCollection);
123
- this.largeManyToManys = allManyToManys.filter((f) => f.isLargeCollection);
124
- // A join table between us and an enum table, i.e. `Publisher.logoColors`.
125
- this.manyToManyEnums = table.m2mRelations
126
- .filter((r) => (0, utils_1.isJoinTable)(config, r.joinTable))
127
- .filter((r) => !isMultiColumnForeignKey(r))
128
- .filter((r) => (0, utils_1.isEnumTable)(config, r.targetTable))
129
- .map((r) => newManyToManyEnumField(config, this.entity, r, enums))
130
- .filter((f) => !f.ignore);
131
- this.polymorphics = polymorphicRelations(config, table).map((rc) => newPolymorphicField(config, table, this.entity, rc));
132
- this.tableName = table.name;
133
- this.tagName = config.entities[this.entity.name]?.tag;
134
- this.abstract = config.entities[this.entity.name]?.abstract || false;
135
- const { createdAtConf, updatedAtConf, deletedAtConf } = (0, config_1.getTimestampConfig)(config);
136
- this.createdAt = this.primitives.find((f) => createdAtConf.names.includes(f.columnName));
137
- this.updatedAt = this.primitives.find((f) => updatedAtConf.names.includes(f.columnName));
138
- this.deletedAt = this.primitives.find((f) => deletedAtConf.names.includes(f.columnName));
139
- this.uniqueConstraints = inferUniqueConstraints(this, table);
140
- }
141
- get name() {
142
- return this.entity.name;
143
- }
144
- get nonDeferredFks() {
145
- return [
146
- ...this.manyToOnes.filter((r) => !r.isDeferredAndDeferrable),
147
- ...this.polymorphics.flatMap((p) => p.components).filter((c) => !c.isDeferredAndDeferrable),
148
- ];
149
- }
150
- get nonDeferredManyToManyFks() {
151
- return this.manyToManys.filter((r) => !r.isDeferredAndDeferrable);
152
- }
153
- }
154
- exports.EntityDbMetadata = EntityDbMetadata;
1
+ import { EnumType, M2ORelation } from "./pgMetadata.js";
2
+ import { fail, isEnumTable, isJoinTable, isSubClassTable, joinTableHasId, mapSimpleDbTypeToTypescriptType, parseOrder, tableToEntityName } from "./utils.js";
3
+ import { fieldTypeConfig, getTimestampConfig, isFieldHasDefault, isFieldIgnored, isGetterField, isLargeCollection, isLazyField, isProtected, isReactiveField, isReactiveManyToMany, isReactiveReference, ormMaintainedFields, serdeConfig, softDeletesConfig, superstructConfig, zodSchemaConfig } from "./config.js";
4
+ import { Zod } from "./symbols.js";
5
+ import "./loadMetadata.js";
6
+ import { camelCase, pascalCase, snakeCase } from "change-case";
7
+ import { groupBy } from "joist-utils";
8
+ import pluralize from "pluralize";
9
+ import { Import, code, imp } from "ts-poet";
10
+ //#region src/EntityDbMetadata.ts
11
+ const { plural, singular } = pluralize;
12
+ /** Adapts PostgreSQL catalog metadata into our specific ORM types. */
13
+ var EntityDbMetadata = class {
14
+ entity;
15
+ primaryKey;
16
+ primitives;
17
+ enums;
18
+ pgEnums;
19
+ manyToOnes;
20
+ oneToManys;
21
+ largeOneToManys;
22
+ oneToOnes;
23
+ manyToManys;
24
+ largeManyToManys;
25
+ manyToManyEnums;
26
+ polymorphics;
27
+ tableName;
28
+ tagName;
29
+ createdAt;
30
+ updatedAt;
31
+ deletedAt;
32
+ baseClassName;
33
+ baseType;
34
+ subTypes = [];
35
+ inheritanceType;
36
+ /** This will only be set on the base meta. */
37
+ stiDiscriminatorField;
38
+ /** This will only be set on the sub metas. */
39
+ stiDiscriminatorValue;
40
+ abstract;
41
+ nonDeferredFkOrder = -1;
42
+ uniqueConstraints;
43
+ /** Gates mutation targets, not reads; false when required columns or array storage have no supported mutation mapping. */
44
+ supportsEmExecute;
45
+ /** Original table fields, captured before inheritance partitions or specializes them. */
46
+ physicalMetadata;
47
+ /** Physical columns ignored by entity fields, retained for direct SQL reads and writes. */
48
+ ignoredColumns;
49
+ constructor(config, table, enums = {}) {
50
+ this.entity = makeEntity(tableToEntityName(config, table));
51
+ if (isSubClassTable(table)) {
52
+ this.baseClassName = tableToEntityName(config, table.columns.get("id").foreignKeys[0].referencedTable);
53
+ this.inheritanceType = "cti";
54
+ }
55
+ this.primaryKey = table.columns.filter((c) => c.isPrimaryKey).map((column) => newPrimitive(config, this.entity, column, table))[0] || fail(`No primary key found for ${table.name}`);
56
+ 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);
57
+ this.enums = [...table.m2oRelations.filter((r) => 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)];
58
+ this.pgEnums = table.columns.filter((c) => isPgEnum(c)).map((column) => newPgEnumField(config, this.entity, column)).filter((f) => !f.ignore);
59
+ this.manyToOnes = table.m2oRelations.filter((r) => !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);
60
+ const allOneToManys = table.o2mRelations.filter((r) => !isJoinTable(config, r.targetTable)).filter((r) => !isMultiColumnForeignKey(r)).filter((r) => !isOneToOneRelation(r)).map((r) => newOneToMany(config, this.entity, r)).filter((f) => !isReactiveReference(config, f.otherEntity, f.otherFieldName)).filter((f) => !f.ignore);
61
+ this.oneToManys = allOneToManys.filter((f) => !f.isLargeCollection);
62
+ this.largeOneToManys = allOneToManys.filter((f) => f.isLargeCollection);
63
+ this.oneToOnes = table.o2mRelations.filter((r) => !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);
64
+ const allManyToManys = table.m2mRelations.filter((r) => isJoinTable(config, r.joinTable)).filter((r) => !isMultiColumnForeignKey(r)).filter((r) => !isEnumTable(config, r.targetTable)).map((r) => newManyToManyField(config, this.entity, r)).filter((f) => !f.ignore);
65
+ this.manyToManys = allManyToManys.filter((f) => !f.isLargeCollection);
66
+ this.largeManyToManys = allManyToManys.filter((f) => f.isLargeCollection);
67
+ this.manyToManyEnums = table.m2mRelations.filter((r) => isJoinTable(config, r.joinTable)).filter((r) => !isMultiColumnForeignKey(r)).filter((r) => isEnumTable(config, r.targetTable)).map((r) => newManyToManyEnumField(config, this.entity, r, enums)).filter((f) => !f.ignore);
68
+ this.polymorphics = polymorphicRelations(config, table).map((rc) => newPolymorphicField(config, table, this.entity, rc));
69
+ const modeledColumns = /* @__PURE__ */ new Set([
70
+ this.primaryKey.columnName,
71
+ ...this.primitives.map((field) => field.columnName),
72
+ ...this.enums.map((field) => field.columnName),
73
+ ...this.pgEnums.map((field) => field.columnName),
74
+ ...this.manyToOnes.map((field) => field.columnName),
75
+ ...this.polymorphics.flatMap((field) => field.components.map((component) => component.columnName))
76
+ ]);
77
+ this.ignoredColumns = table.columns.filter((column) => !modeledColumns.has(column.name)).map((column) => newPhysicalColumn(config, this.entity, column));
78
+ this.tableName = table.name;
79
+ this.tagName = config.entities[this.entity.name]?.tag;
80
+ this.abstract = config.entities[this.entity.name]?.abstract || false;
81
+ const { createdAtConf, updatedAtConf, deletedAtConf } = getTimestampConfig(config);
82
+ this.createdAt = this.primitives.find((f) => createdAtConf.names.includes(f.columnName));
83
+ this.updatedAt = this.primitives.find((f) => updatedAtConf.names.includes(f.columnName));
84
+ this.deletedAt = this.primitives.find((f) => deletedAtConf.names.includes(f.columnName));
85
+ this.uniqueConstraints = inferUniqueConstraints(this, table);
86
+ 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")));
87
+ }
88
+ get name() {
89
+ return this.entity.name;
90
+ }
91
+ get nonDeferredFks() {
92
+ return [...this.manyToOnes.filter((r) => !r.isDeferredAndDeferrable), ...this.polymorphics.flatMap((p) => p.components).filter((c) => !c.isDeferredAndDeferrable)];
93
+ }
94
+ get nonDeferredManyToManyFks() {
95
+ return this.manyToManys.filter((r) => !r.isDeferredAndDeferrable);
96
+ }
97
+ };
155
98
  function isMultiColumnForeignKey(r) {
156
- return r.foreignKey.columns.length > 1;
99
+ return r.foreignKey.columns.length > 1;
157
100
  }
158
101
  function isBaseClassForeignKey(r) {
159
- return r.foreignKey.columns.length === 1 && r.foreignKey.columns[0].name === "id";
102
+ return r.foreignKey.columns.length === 1 && r.foreignKey.columns[0].name === "id";
160
103
  }
161
104
  function isOneToOneRelation(r) {
162
- // otherColumn will be the images.book_id in the other table
163
- const otherColumn = r.foreignKey.columns[0];
164
- // r.foreignKey.index is the index on _us_ (i.e. our Book primary key), so look up indexes in the target table
165
- const indexes = r.targetTable.columns.find((c) => c.name == otherColumn.name)?.uniqueIndexes || [];
166
- return indexes.find(isOneToOneIndex) !== undefined;
105
+ const otherColumn = r.foreignKey.columns[0];
106
+ return (r.targetTable.columns.find((c) => c.name == otherColumn.name)?.uniqueIndexes || []).find(isOneToOneIndex) !== void 0;
167
107
  }
168
- // If the unique index has only one column and is NOT a partial index, it's a one-to-one
169
108
  function isOneToOneIndex(i) {
170
- return i.columns.length === 1 && !i.isPartial;
109
+ return i.columns.length === 1 && !i.isPartial;
171
110
  }
172
111
  /** Infers field names from unique constraints, i.e. `(author_id, title)` becomes `author, title`. */
173
112
  function inferUniqueConstraints(meta, table) {
174
- return table.uniqueConstraints.flatMap((constraint) => {
175
- if (constraint.index.isPartial)
176
- return [];
177
- const fields = Array.from(constraint.columns).map((column) => fieldNameForColumn(meta, column.name));
178
- if (fields.some((field) => field === undefined))
179
- return [];
180
- return [fields];
181
- });
113
+ return table.uniqueConstraints.flatMap((constraint) => {
114
+ if (constraint.index.isPartial) return [];
115
+ const fields = Array.from(constraint.columns).map((column) => fieldNameForColumn(meta, column.name));
116
+ if (fields.some((field) => field === void 0)) return [];
117
+ return [fields];
118
+ });
182
119
  }
183
120
  /** Returns the queryable field name for a unique constraint column. */
184
121
  function fieldNameForColumn(meta, columnName) {
185
- const primitive = meta.primitives.find((field) => field.columnName === columnName);
186
- if (primitive && !primitive.derived && !primitive.isArray && !primitive.customSerde)
187
- return primitive.fieldName;
188
- const enumField = meta.enums.find((field) => field.columnName === columnName);
189
- if (enumField && !enumField.derived && !enumField.isArray)
190
- return enumField.fieldName;
191
- const pgEnum = meta.pgEnums.find((field) => field.columnName === columnName);
192
- if (pgEnum)
193
- return pgEnum.fieldName;
194
- const manyToOne = meta.manyToOnes.find((field) => field.columnName === columnName);
195
- if (manyToOne && !manyToOne.derived)
196
- return manyToOne.fieldName;
197
- return undefined;
122
+ const primitive = meta.primitives.find((field) => field.columnName === columnName);
123
+ if (primitive && !primitive.derived && !primitive.isArray && !primitive.customSerde) return primitive.fieldName;
124
+ const enumField = meta.enums.find((field) => field.columnName === columnName);
125
+ if (enumField && !enumField.derived && !enumField.isArray) return enumField.fieldName;
126
+ const pgEnum = meta.pgEnums.find((field) => field.columnName === columnName);
127
+ if (pgEnum) return pgEnum.fieldName;
128
+ const manyToOne = meta.manyToOnes.find((field) => field.columnName === columnName);
129
+ if (manyToOne && !manyToOne.derived) return manyToOne.fieldName;
198
130
  }
199
131
  function polymorphicRelations(config, table) {
200
- const entity = config.entities[(0, utils_1.tableToEntityName)(config, table)];
201
- return Object.entries(entity?.relations ?? {})
202
- .filter(([, r]) => r.polymorphic)
203
- .map(([fieldName, { polymorphic }]) => ({ fieldName, notNull: polymorphic === "notNull" }));
132
+ const entity = config.entities[tableToEntityName(config, table)];
133
+ return Object.entries(entity?.relations ?? {}).filter(([, r]) => r.polymorphic).map(([fieldName, { polymorphic }]) => ({
134
+ fieldName,
135
+ notNull: polymorphic === "notNull"
136
+ }));
204
137
  }
205
138
  function polymorphicFieldName(config, r) {
206
- const { name } = r.foreignKey.columns[0];
207
- const table = r.type === "m2o" ? r.sourceTable : r.targetTable;
208
- return polymorphicRelations(config, table).find((pr) => name.startsWith(`${(0, change_case_1.snakeCase)(pr.fieldName)}_`))?.fieldName;
139
+ const { name } = r.foreignKey.columns[0];
140
+ return polymorphicRelations(config, r.type === "m2o" ? r.sourceTable : r.targetTable).find((pr) => name.startsWith(`${snakeCase(pr.fieldName)}_`))?.fieldName;
209
141
  }
210
142
  function isComponentOfPolymorphicRelation(config, r) {
211
- return polymorphicFieldName(config, r) !== undefined;
143
+ return polymorphicFieldName(config, r) !== void 0;
212
144
  }
213
145
  function determineUserType(fieldType, superstruct, zodSchema, userFieldType) {
214
- if (fieldType === "Object" && superstruct) {
215
- return superstructType(superstruct);
216
- }
217
- if (fieldType === "Object" && zodSchema) {
218
- return zodSchemaType(zodSchema);
219
- }
220
- if (userFieldType) {
221
- return userFieldTypeType(userFieldType);
222
- }
223
- return fieldType;
146
+ if (fieldType === "Object" && superstruct) return superstructType(superstruct);
147
+ if (fieldType === "Object" && zodSchema) return zodSchemaType(zodSchema);
148
+ if (userFieldType) return userFieldTypeType(userFieldType);
149
+ return fieldType;
224
150
  }
225
151
  function newPrimitive(config, entity, column, table) {
226
- const fieldName = primitiveFieldName(column.name);
227
- const columnName = column.name;
228
- const columnType = (column.type.shortName || column.type.name);
229
- const array = isArray(column);
230
- const fieldType = mapType(config, table.name, columnName, columnType);
231
- const customSerde = (0, config_1.serdeConfig)(config, entity, fieldName);
232
- const superstruct = (0, config_1.superstructConfig)(config, entity, fieldName);
233
- const zodSchema = (0, config_1.zodSchemaConfig)(config, entity, fieldName);
234
- const userFieldType = (0, config_1.fieldTypeConfig)(config, entity, fieldName);
235
- const maybeUserType = determineUserType(fieldType, superstruct, zodSchema, userFieldType);
236
- const unique = column.uniqueIndexes.find(isOneToOneIndex) !== undefined;
237
- const hasConfigDefault = (0, config_1.isFieldHasDefault)(config, entity, fieldName);
238
- return {
239
- kind: "primitive",
240
- fieldName,
241
- columnName,
242
- columnType,
243
- fieldType: array ? (0, ts_poet_1.code) `${fieldType}[]` : maybeUserType,
244
- rawFieldType: fieldType,
245
- notNull: column.notNull,
246
- columnDefault: column.default,
247
- derived: fieldDerived(config, entity, fieldName),
248
- protected: (0, config_1.isProtected)(config, entity, fieldName),
249
- unique,
250
- ignore: (0, config_1.isFieldIgnored)(config, entity, fieldName, column.notNull, column.default !== null),
251
- superstruct: fieldType === "Object" && superstruct ? ts_poet_1.Import.from(superstruct) : undefined,
252
- zodSchema: fieldType === "Object" && zodSchema ? ts_poet_1.Import.from(zodSchema) : undefined,
253
- customSerde: customSerde ? serdeType(customSerde) : undefined,
254
- isArray: array,
255
- hasConfigDefault, // can be set to true by scanEntityFiles
256
- };
152
+ const fieldName = primitiveFieldName(column.name);
153
+ const columnName = column.name;
154
+ const columnType = column.type.shortName || column.type.name;
155
+ const array = isArray(column);
156
+ const fieldType = mapType(config, table.name, columnName, columnType);
157
+ const customSerde = serdeConfig(config, entity, fieldName);
158
+ const superstruct = superstructConfig(config, entity, fieldName);
159
+ const zodSchema = zodSchemaConfig(config, entity, fieldName);
160
+ const maybeUserType = determineUserType(fieldType, superstruct, zodSchema, fieldTypeConfig(config, entity, fieldName));
161
+ const unique = column.uniqueIndexes.find(isOneToOneIndex) !== void 0;
162
+ const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);
163
+ return {
164
+ kind: "primitive",
165
+ columnOwner: entity,
166
+ columnNotNull: column.notNull,
167
+ fieldName,
168
+ columnName,
169
+ columnType,
170
+ fieldType: array ? code`${maybeUserType}[]` : maybeUserType,
171
+ rawFieldType: fieldType,
172
+ notNull: column.notNull,
173
+ columnDefault: column.default,
174
+ columnGenerated: column.isGenerated,
175
+ derived: fieldDerived(config, entity, fieldName),
176
+ protected: isProtected(config, entity, fieldName),
177
+ unique,
178
+ ignore: isFieldIgnored(config, entity, fieldName, column.notNull, column.default !== null),
179
+ superstruct: fieldType === "Object" && superstruct ? Import.from(superstruct) : void 0,
180
+ zodSchema: fieldType === "Object" && zodSchema ? Import.from(zodSchema) : void 0,
181
+ customSerde: customSerde ? serdeType(customSerde) : void 0,
182
+ isArray: array,
183
+ hasConfigDefault,
184
+ lazy: isLazyField(config, entity, fieldName)
185
+ };
186
+ }
187
+ /** Keeps an ignored column's database type without applying entity-only field configuration. */
188
+ function newPhysicalColumn(config, entity, column) {
189
+ const columnType = column.type.shortName || column.type.name;
190
+ const rawFieldType = column.type instanceof EnumType ? "string" : mapSimpleDbTypeToTypescriptType(config, columnType);
191
+ const isArray = column.arrayDimension === 1;
192
+ return {
193
+ kind: "primitive",
194
+ columnOwner: entity,
195
+ columnNotNull: column.notNull,
196
+ fieldName: primitiveFieldName(column.name),
197
+ columnName: column.name,
198
+ columnType,
199
+ fieldType: isArray ? code`${rawFieldType}[]` : rawFieldType,
200
+ rawFieldType,
201
+ notNull: column.notNull,
202
+ columnDefault: column.default,
203
+ columnGenerated: column.isGenerated,
204
+ derived: false,
205
+ protected: false,
206
+ unique: false,
207
+ superstruct: void 0,
208
+ zodSchema: void 0,
209
+ customSerde: void 0,
210
+ isArray,
211
+ hasConfigDefault: false
212
+ };
257
213
  }
258
214
  function fieldDerived(config, entity, fieldName) {
259
- if (config_1.ormMaintainedFields.includes(fieldName)) {
260
- return "orm";
261
- }
262
- else if ((0, config_1.isGetterField)(config, entity, fieldName)) {
263
- return "sync";
264
- }
265
- else if ((0, config_1.isReactiveField)(config, entity, fieldName)) {
266
- return "async";
267
- }
268
- else {
269
- return false;
270
- }
215
+ if (ormMaintainedFields.includes(fieldName)) return "orm";
216
+ else if (isGetterField(config, entity, fieldName)) return "sync";
217
+ else if (isReactiveField(config, entity, fieldName)) return "async";
218
+ else return false;
271
219
  }
272
220
  function fkFieldDerived(config, entity, fieldName) {
273
- if ((0, config_1.isReactiveReference)(config, entity, fieldName)) {
274
- return "async";
275
- }
276
- else {
277
- return false;
278
- }
221
+ if (isReactiveReference(config, entity, fieldName)) return "async";
222
+ else return false;
279
223
  }
280
224
  function newEnumField(config, entity, r, enums) {
281
- const column = r.foreignKey.columns[0];
282
- const columnName = column.name;
283
- const columnType = (column.type.shortName || column.type.name);
284
- const fieldName = enumFieldName(column.name);
285
- const enumName = (0, utils_1.tableToEntityName)(config, r.targetTable);
286
- const enumType = (0, ts_poet_1.imp)(`${enumName}@./entities.ts`);
287
- const enumDetailType = (0, ts_poet_1.imp)(`${(0, pluralize_1.plural)(enumName)}@./entities.ts`);
288
- const enumDetailsType = (0, ts_poet_1.imp)(`${enumName}Details@./entities.ts`);
289
- const notNull = column.notNull;
290
- const ignore = (0, config_1.isFieldIgnored)(config, entity, fieldName, notNull, column.default !== null);
291
- const hasConfigDefault = (0, config_1.isFieldHasDefault)(config, entity, fieldName);
292
- return {
293
- kind: "enum",
294
- fieldName,
295
- columnName,
296
- columnType,
297
- columnDefault: column.default,
298
- derived: fieldDerived(config, entity, fieldName),
299
- enumName,
300
- enumType,
301
- enumDetailType,
302
- enumDetailsType,
303
- notNull,
304
- ignore,
305
- enumRows: enums[r.targetTable.name].rows,
306
- isArray: false,
307
- hasConfigDefault, // can be set to true by scanEntityFiles
308
- };
225
+ const column = r.foreignKey.columns[0];
226
+ const columnName = column.name;
227
+ const columnType = column.type.shortName || column.type.name;
228
+ const fieldName = enumFieldName(column.name);
229
+ const enumName = tableToEntityName(config, r.targetTable);
230
+ const enumType = imp(`${enumName}@./entities.ts`);
231
+ const enumDetailType = imp(`${plural(enumName)}@./entities.ts`);
232
+ const enumDetailsType = imp(`${enumName}Details@./entities.ts`);
233
+ const notNull = column.notNull;
234
+ const ignore = isFieldIgnored(config, entity, fieldName, notNull, column.default !== null);
235
+ const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);
236
+ return {
237
+ kind: "enum",
238
+ columnOwner: entity,
239
+ columnNotNull: column.notNull,
240
+ fieldName,
241
+ columnName,
242
+ columnType,
243
+ columnDefault: column.default,
244
+ columnGenerated: column.isGenerated,
245
+ derived: fieldDerived(config, entity, fieldName),
246
+ enumName,
247
+ enumType,
248
+ enumDetailType,
249
+ enumDetailsType,
250
+ notNull,
251
+ ignore,
252
+ enumRows: enums[r.targetTable.name].rows,
253
+ isArray: false,
254
+ hasConfigDefault
255
+ };
309
256
  }
310
257
  function newEnumArrayField(config, entity, column, enums) {
311
- const columnName = column.name;
312
- const columnType = (column.type.shortName || column.type.name);
313
- const fieldName = enumFieldName(column.name);
314
- // Find the enum table name via the comment hint (instead of a FK constraint), and strip the enum= prefix
315
- const enumTable = column.comment.replace("enum=", "");
316
- const enumName = (enums[enumTable] || (0, utils_1.fail)(`Could not find enum ${enumTable}`)).name;
317
- const enumType = (0, ts_poet_1.imp)(`${enumName}@./entities.ts`);
318
- const enumDetailType = (0, ts_poet_1.imp)(`${(0, pluralize_1.plural)(enumName)}@./entities.ts`);
319
- const enumDetailsType = (0, ts_poet_1.imp)(`${enumName}Details@./entities.ts`);
320
- const notNull = column.notNull;
321
- const ignore = (0, config_1.isFieldIgnored)(config, entity, fieldName, notNull, column.default !== null);
322
- const hasConfigDefault = (0, config_1.isFieldHasDefault)(config, entity, fieldName);
323
- return {
324
- kind: "enum",
325
- fieldName,
326
- columnName,
327
- columnType,
328
- columnDefault: column.default,
329
- derived: fieldDerived(config, entity, fieldName),
330
- enumName,
331
- enumType,
332
- enumDetailType,
333
- enumDetailsType,
334
- notNull,
335
- ignore,
336
- enumRows: enums[enumTable].rows,
337
- isArray: true,
338
- hasConfigDefault, // can be set to true by scanEntityFiles
339
- };
258
+ const columnName = column.name;
259
+ const columnType = column.type.shortName || column.type.name;
260
+ const fieldName = enumFieldName(column.name);
261
+ const enumTable = column.comment.replace("enum=", "");
262
+ const enumName = (enums[enumTable] || fail(`Could not find enum ${enumTable}`)).name;
263
+ const enumType = imp(`${enumName}@./entities.ts`);
264
+ const enumDetailType = imp(`${plural(enumName)}@./entities.ts`);
265
+ const enumDetailsType = imp(`${enumName}Details@./entities.ts`);
266
+ const notNull = column.notNull;
267
+ const ignore = isFieldIgnored(config, entity, fieldName, notNull, column.default !== null);
268
+ const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);
269
+ return {
270
+ kind: "enum",
271
+ columnOwner: entity,
272
+ columnNotNull: column.notNull,
273
+ fieldName,
274
+ columnName,
275
+ columnType,
276
+ columnDefault: column.default,
277
+ columnGenerated: column.isGenerated,
278
+ derived: fieldDerived(config, entity, fieldName),
279
+ enumName,
280
+ enumType,
281
+ enumDetailType,
282
+ enumDetailsType,
283
+ notNull,
284
+ ignore,
285
+ enumRows: enums[enumTable].rows,
286
+ isArray: true,
287
+ hasConfigDefault
288
+ };
340
289
  }
341
290
  function newPgEnumField(config, entity, column) {
342
- const fieldName = primitiveFieldName(column.name);
343
- const columnName = column.name;
344
- const enumName = (0, change_case_1.pascalCase)(column.type.name);
345
- const enumType = (0, ts_poet_1.imp)(`${enumName}@./entities.ts`);
346
- const hasConfigDefault = (0, config_1.isFieldHasDefault)(config, entity, fieldName);
347
- return {
348
- kind: "pg-enum",
349
- fieldName,
350
- columnName,
351
- dbType: column.type.name,
352
- enumType,
353
- enumName,
354
- enumValues: column.type.values,
355
- notNull: column.notNull,
356
- columnDefault: column.default,
357
- ignore: (0, config_1.isFieldIgnored)(config, entity, fieldName, column.notNull, column.default !== null),
358
- hasConfigDefault, // can be set to true by scanEntityFiles
359
- };
291
+ const fieldName = primitiveFieldName(column.name);
292
+ const columnName = column.name;
293
+ const enumName = pascalCase(column.type.name);
294
+ const enumType = imp(`${enumName}@./entities.ts`);
295
+ const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);
296
+ return {
297
+ kind: "pg-enum",
298
+ columnOwner: entity,
299
+ columnNotNull: column.notNull,
300
+ fieldName,
301
+ columnName,
302
+ dbType: column.type.name,
303
+ enumType,
304
+ enumName,
305
+ enumValues: column.type.values,
306
+ notNull: column.notNull,
307
+ columnDefault: column.default,
308
+ columnGenerated: column.isGenerated,
309
+ ignore: isFieldIgnored(config, entity, fieldName, column.notNull, column.default !== null),
310
+ hasConfigDefault
311
+ };
360
312
  }
361
313
  function newManyToOneField(config, entity, r) {
362
- const column = r.foreignKey.columns[0];
363
- const columnName = column.name;
364
- const dbType = r.foreignKey.columns[0].type.shortName;
365
- const fieldName = referenceName(config, entity, r);
366
- const otherEntity = makeEntity((0, utils_1.tableToEntityName)(config, r.targetTable));
367
- const isOneToOne = column.uniqueIndexes.find(isOneToOneIndex) !== undefined;
368
- const otherFieldName = isOneToOne
369
- ? oneToOneName(config, otherEntity, entity, r)
370
- : collectionName(config, otherEntity, entity, r).fieldName;
371
- const notNull = column.notNull;
372
- const ignore = (0, config_1.isFieldIgnored)(config, entity, fieldName, notNull, column.default !== null);
373
- const isDeferredAndDeferrable = r.foreignKey.isDeferred && r.foreignKey.isDeferrable;
374
- const derived = fkFieldDerived(config, entity, fieldName);
375
- const hasConfigDefault = (0, config_1.isFieldHasDefault)(config, entity, fieldName);
376
- return {
377
- kind: "m2o",
378
- fieldName,
379
- columnName,
380
- otherEntity,
381
- otherFieldName,
382
- notNull,
383
- ignore,
384
- derived,
385
- dbType,
386
- isDeferredAndDeferrable,
387
- constraintName: r.foreignKey.name,
388
- hasConfigDefault, // can be set to true by scanEntityFiles
389
- onDelete: r.foreignKey.onDelete,
390
- };
314
+ const column = r.foreignKey.columns[0];
315
+ const columnName = column.name;
316
+ const dbType = r.foreignKey.columns[0].type.shortName;
317
+ const fieldName = referenceName(config, entity, r);
318
+ const otherEntity = makeEntity(tableToEntityName(config, r.targetTable));
319
+ const otherFieldName = column.uniqueIndexes.find(isOneToOneIndex) !== void 0 ? oneToOneName(config, otherEntity, entity, r) : collectionName(config, otherEntity, entity, r).fieldName;
320
+ const notNull = column.notNull;
321
+ const ignore = isFieldIgnored(config, entity, fieldName, notNull, column.default !== null);
322
+ const isDeferredAndDeferrable = r.foreignKey.isDeferred && r.foreignKey.isDeferrable;
323
+ const derived = fkFieldDerived(config, entity, fieldName);
324
+ const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);
325
+ return {
326
+ kind: "m2o",
327
+ columnOwner: entity,
328
+ columnNotNull: column.notNull,
329
+ fieldName,
330
+ columnName,
331
+ columnDefault: column.default,
332
+ columnGenerated: column.isGenerated,
333
+ otherEntity,
334
+ otherFieldName,
335
+ notNull,
336
+ ignore,
337
+ derived,
338
+ dbType,
339
+ isDeferredAndDeferrable,
340
+ constraintName: r.foreignKey.name,
341
+ hasConfigDefault,
342
+ onDelete: r.foreignKey.onDelete
343
+ };
391
344
  }
392
345
  function newOneToMany(config, entity, r) {
393
- const column = r.foreignKey.columns[0];
394
- // source == parent i.e. the reference of the foreign key column
395
- // target == child i.e. the table with the foreign key column in it
396
- const otherEntity = makeEntity((0, utils_1.tableToEntityName)(config, r.targetTable));
397
- const { singularName, fieldName } = collectionName(config, entity, otherEntity, r);
398
- const otherFieldName = referenceName(config, otherEntity, r);
399
- const orderBy = config.entities[entity.name]?.relations?.[fieldName]?.orderBy ?? config.entities[otherEntity.name]?.orderBy;
400
- return {
401
- kind: "o2m",
402
- fieldName,
403
- singularName,
404
- otherEntity,
405
- otherFieldName,
406
- otherColumnName: column.name,
407
- otherColumnNotNull: column.notNull,
408
- ignore: (0, config_1.isFieldIgnored)(config, entity, fieldName) || (0, config_1.isFieldIgnored)(config, otherEntity, otherFieldName),
409
- isLargeCollection: (0, config_1.isLargeCollection)(config, entity, fieldName),
410
- orderBy: (0, utils_1.parseOrder)(orderBy),
411
- };
346
+ const column = r.foreignKey.columns[0];
347
+ const otherEntity = makeEntity(tableToEntityName(config, r.targetTable));
348
+ const { singularName, fieldName } = collectionName(config, entity, otherEntity, r);
349
+ const otherFieldName = referenceName(config, otherEntity, r);
350
+ const orderBy = config.entities[entity.name]?.relations?.[fieldName]?.orderBy ?? config.entities[otherEntity.name]?.orderBy;
351
+ return {
352
+ kind: "o2m",
353
+ fieldName,
354
+ singularName,
355
+ otherEntity,
356
+ otherFieldName,
357
+ otherColumnName: column.name,
358
+ otherColumnNotNull: column.notNull,
359
+ ignore: isFieldIgnored(config, entity, fieldName) || isFieldIgnored(config, otherEntity, otherFieldName),
360
+ isLargeCollection: isLargeCollection(config, entity, fieldName),
361
+ orderBy: parseOrder(orderBy),
362
+ softDeletes: softDeletesConfig(config, entity, fieldName)
363
+ };
412
364
  }
413
365
  function newOneToOne(config, entity, r) {
414
- const column = r.foreignKey.columns[0];
415
- // source == parent i.e. the reference of the foreign key column
416
- // target == child i.e. the table with the foreign key column in it
417
- const otherEntity = makeEntity((0, utils_1.tableToEntityName)(config, r.targetTable));
418
- const fieldName = oneToOneName(config, entity, otherEntity, r);
419
- const otherFieldName = referenceName(config, otherEntity, r);
420
- const otherColumnName = column.name;
421
- const otherColumnNotNull = column.notNull;
422
- const ignore = (0, config_1.isFieldIgnored)(config, entity, fieldName) || (0, config_1.isFieldIgnored)(config, otherEntity, otherFieldName);
423
- return { kind: "o2o", fieldName, otherEntity, otherFieldName, otherColumnName, otherColumnNotNull, ignore };
366
+ const column = r.foreignKey.columns[0];
367
+ const otherEntity = makeEntity(tableToEntityName(config, r.targetTable));
368
+ const fieldName = oneToOneName(config, entity, otherEntity, r);
369
+ const otherFieldName = referenceName(config, otherEntity, r);
370
+ return {
371
+ kind: "o2o",
372
+ fieldName,
373
+ otherEntity,
374
+ otherFieldName,
375
+ otherColumnName: column.name,
376
+ otherColumnNotNull: column.notNull,
377
+ ignore: isFieldIgnored(config, entity, fieldName) || isFieldIgnored(config, otherEntity, otherFieldName)
378
+ };
424
379
  }
425
380
  function newManyToManyField(config, entity, r) {
426
- const { foreignKey, targetForeignKey, targetTable } = r;
427
- const otherEntity = makeEntity((0, utils_1.tableToEntityName)(config, targetTable));
428
- // For foo_to_bar.some_foo_id use the `some_foo_id` column i.e. `someFoos`
429
- const fieldName = manyToManyName(targetForeignKey.columns[0]);
430
- const otherFieldName = manyToManyName(foreignKey.columns[0]);
431
- const isDeferredAndDeferrable = targetForeignKey.isDeferred && targetForeignKey.isDeferrable;
432
- // Determine if this m2m is derived:
433
- // - "async" if this side is explicitly marked as a ReactiveManyToMany
434
- // - "otherSide" if the OTHER side is marked as a ReactiveManyToMany (making this the read-only other side)
435
- // - false otherwise (regular m2m)
436
- const isThisSideDerived = (0, config_1.isReactiveManyToMany)(config, entity, fieldName);
437
- const isOtherSideDerived = (0, config_1.isReactiveManyToMany)(config, otherEntity, otherFieldName);
438
- const derived = isThisSideDerived ? "async" : isOtherSideDerived ? "otherSide" : false;
439
- return {
440
- kind: "m2m",
441
- joinTableName: r.joinTable.name,
442
- fieldName,
443
- singularName: (0, pluralize_1.singular)(fieldName),
444
- columnName: foreignKey.columns[0].name,
445
- otherEntity,
446
- otherFieldName,
447
- otherColumnName: targetForeignKey.columns[0].name,
448
- ignore: (0, config_1.isFieldIgnored)(config, entity, fieldName) || (0, config_1.isFieldIgnored)(config, otherEntity, otherFieldName),
449
- isLargeCollection: (0, config_1.isLargeCollection)(config, entity, fieldName),
450
- isDeferredAndDeferrable,
451
- derived,
452
- hasJoinTableId: (0, utils_1.joinTableHasId)(r.joinTable),
453
- };
381
+ const { foreignKey, targetForeignKey, targetTable } = r;
382
+ const otherEntity = makeEntity(tableToEntityName(config, targetTable));
383
+ const fieldName = manyToManyName(targetForeignKey.columns[0]);
384
+ const otherFieldName = manyToManyName(foreignKey.columns[0]);
385
+ const isDeferredAndDeferrable = targetForeignKey.isDeferred && targetForeignKey.isDeferrable;
386
+ const isThisSideDerived = isReactiveManyToMany(config, entity, fieldName);
387
+ const isOtherSideDerived = isReactiveManyToMany(config, otherEntity, otherFieldName);
388
+ const derived = isThisSideDerived ? "async" : isOtherSideDerived ? "otherSide" : false;
389
+ return {
390
+ kind: "m2m",
391
+ joinTableName: r.joinTable.name,
392
+ fieldName,
393
+ singularName: singular(fieldName),
394
+ columnName: foreignKey.columns[0].name,
395
+ otherEntity,
396
+ otherFieldName,
397
+ otherColumnName: targetForeignKey.columns[0].name,
398
+ ignore: isFieldIgnored(config, entity, fieldName) || isFieldIgnored(config, otherEntity, otherFieldName),
399
+ isLargeCollection: isLargeCollection(config, entity, fieldName),
400
+ isDeferredAndDeferrable,
401
+ derived,
402
+ softDeletes: softDeletesConfig(config, entity, fieldName),
403
+ hasJoinTableId: joinTableHasId(r.joinTable)
404
+ };
454
405
  }
455
406
  function newManyToManyEnumField(config, entity, r, enums) {
456
- const { foreignKey, targetForeignKey, targetTable } = r;
457
- // For publisher_logo_colors.logo_color_id use the `logo_color_id` column i.e. `logoColors`
458
- const fieldName = manyToManyName(targetForeignKey.columns[0]);
459
- const enumName = (0, utils_1.tableToEntityName)(config, targetTable);
460
- return {
461
- kind: "m2mEnum",
462
- joinTableName: r.joinTable.name,
463
- fieldName,
464
- columnName: foreignKey.columns[0].name,
465
- otherColumnName: targetForeignKey.columns[0].name,
466
- enumName,
467
- enumType: (0, ts_poet_1.imp)(`${enumName}@./entities.ts`),
468
- enumDetailType: (0, ts_poet_1.imp)(`${(0, pluralize_1.plural)(enumName)}@./entities.ts`),
469
- enumDetailsType: (0, ts_poet_1.imp)(`${enumName}Details@./entities.ts`),
470
- enumRows: enums[targetTable.name].rows,
471
- ignore: (0, config_1.isFieldIgnored)(config, entity, fieldName),
472
- hasJoinTableId: (0, utils_1.joinTableHasId)(r.joinTable),
473
- };
407
+ const { foreignKey, targetForeignKey, targetTable } = r;
408
+ const fieldName = manyToManyName(targetForeignKey.columns[0]);
409
+ const enumName = tableToEntityName(config, targetTable);
410
+ return {
411
+ kind: "m2mEnum",
412
+ joinTableName: r.joinTable.name,
413
+ fieldName,
414
+ columnName: foreignKey.columns[0].name,
415
+ otherColumnName: targetForeignKey.columns[0].name,
416
+ enumName,
417
+ enumType: imp(`${enumName}@./entities.ts`),
418
+ enumDetailType: imp(`${plural(enumName)}@./entities.ts`),
419
+ enumDetailsType: imp(`${enumName}Details@./entities.ts`),
420
+ enumRows: enums[targetTable.name].rows,
421
+ ignore: isFieldIgnored(config, entity, fieldName),
422
+ hasJoinTableId: joinTableHasId(r.joinTable)
423
+ };
474
424
  }
475
425
  function newPolymorphicField(config, table, entity, pr) {
476
- const { fieldName, notNull } = pr;
477
- const components = table.m2oRelations
478
- .filter((r) => !(0, utils_1.isEnumTable)(config, r.targetTable))
479
- .filter((r) => !isMultiColumnForeignKey(r))
480
- .filter((r) => polymorphicFieldName(config, r) === fieldName)
481
- .map((r) => newPolymorphicFieldComponent(config, entity, r));
482
- const fieldType = `${entity.name}${(0, change_case_1.pascalCase)(fieldName)}`;
483
- const hasConfigDefault = (0, config_1.isFieldHasDefault)(config, entity, fieldName);
484
- return {
485
- kind: "poly",
486
- fieldName,
487
- fieldType,
488
- notNull,
489
- components,
490
- hasConfigDefault, // can be set to true by scanEntityFiles
491
- };
426
+ const { fieldName, notNull } = pr;
427
+ const components = table.m2oRelations.filter((r) => !isEnumTable(config, r.targetTable)).filter((r) => !isMultiColumnForeignKey(r)).filter((r) => polymorphicFieldName(config, r) === fieldName).map((r) => newPolymorphicFieldComponent(config, entity, r));
428
+ return {
429
+ kind: "poly",
430
+ fieldName,
431
+ fieldType: `${entity.name}${pascalCase(fieldName)}`,
432
+ notNull,
433
+ components,
434
+ hasConfigDefault: isFieldHasDefault(config, entity, fieldName)
435
+ };
492
436
  }
493
437
  function newPolymorphicFieldComponent(config, entity, r) {
494
- const column = r.foreignKey.columns[0];
495
- const columnName = column.name;
496
- const otherEntity = makeEntity((0, utils_1.tableToEntityName)(config, r.targetTable));
497
- const isOneToOne = column.uniqueIndexes.find(isOneToOneIndex) !== undefined;
498
- const otherFieldName = isOneToOne
499
- ? oneToOneName(config, otherEntity, entity, r)
500
- : collectionName(config, otherEntity, entity, r).fieldName;
501
- const isDeferredAndDeferrable = r.foreignKey.isDeferred && r.foreignKey.isDeferrable;
502
- return {
503
- columnName,
504
- otherEntity,
505
- otherFieldName,
506
- isDeferredAndDeferrable,
507
- constraintName: r.foreignKey.name,
508
- notNull: false,
509
- };
438
+ const column = r.foreignKey.columns[0];
439
+ const columnName = column.name;
440
+ const otherEntity = makeEntity(tableToEntityName(config, r.targetTable));
441
+ return {
442
+ columnName,
443
+ columnOwner: entity,
444
+ otherEntity,
445
+ otherFieldName: column.uniqueIndexes.find(isOneToOneIndex) !== void 0 ? oneToOneName(config, otherEntity, entity, r) : collectionName(config, otherEntity, entity, r).fieldName,
446
+ isDeferredAndDeferrable: r.foreignKey.isDeferred && r.foreignKey.isDeferrable,
447
+ constraintName: r.foreignKey.name,
448
+ notNull: false
449
+ };
510
450
  }
511
451
  function isFieldNameOverrides(maybeOverride) {
512
- return (maybeOverride !== null &&
513
- !Array.isArray(maybeOverride) &&
514
- typeof maybeOverride === "object" &&
515
- Object.keys(maybeOverride).some((k) => k === "fieldName" || k === "otherFieldName"));
452
+ return maybeOverride !== null && !Array.isArray(maybeOverride) && typeof maybeOverride === "object" && Object.keys(maybeOverride).some((k) => k === "fieldName" || k === "otherFieldName");
516
453
  }
517
454
  /** Finds the field name for o2o side of a o2o/m2o. */
518
- function oneToOneName(config,
519
- // I.e. the Book for o2o Book.image <-- `images.book_id`
520
- refEntity,
521
- // I.e. the Image for o2o Book.image <-- `images.book_id`
522
- keyEntity, r) {
523
- // If the name is overridden then use that
524
- const overrides = r.foreignKey.columns[0].commentData;
525
- if (isFieldNameOverrides(overrides) && overrides.otherFieldName) {
526
- return overrides.otherFieldName;
527
- }
528
- // For `comments.parent_book_review_id`, we would just use `BookReview.comment` as the name
529
- // For `authors.draft_current_book_id`, we would just use `Book.author` as the name
530
- // For `project_items.current_selection_id`, we would use `HomeownerSelection.currentProjectItem`
531
- const refTable = r instanceof pg_structure_1.M2ORelation ? r.targetTable : r.sourceTable;
532
- // Does the ref table have any m2o pointing table at the key table?
533
- const found = refTable.m2oRelations.find((s) => (0, utils_1.tableToEntityName)(config, s.targetTable) === keyEntity.name);
534
- // console.log({refTable: refTable.name, keyTable: keyTable.name, found: found?.name, fieldName});
535
- if (!found) {
536
- // If there aren't any m2os, just use the raw type name like `.image` or `.comment`
537
- return (0, change_case_1.camelCase)(keyEntity.name);
538
- }
539
- else {
540
- // If there is a m2o, assume we might conflict, and use the column name to at least be unique
541
- // Start with `book` from `images.book_id` or `current_draft_book` from `authors.current_draft_book_id`
542
- let fieldName = r.foreignKey.columns[0].name.replace(idSuffix, "");
543
- // Suffix the new type that we're pointing to, to `current_draft_book_author`
544
- fieldName = `${fieldName}_${keyEntity.name}`;
545
- // And drop the `book`, to `current_draft__author`
546
- fieldName = fieldName.replace(refEntity.name.toLowerCase(), "");
547
- // Then camel case, to `currentDraftAuthor`
548
- return (0, change_case_1.camelCase)(fieldName);
549
- }
455
+ function oneToOneName(config, refEntity, keyEntity, r) {
456
+ const overrides = r.foreignKey.columns[0].commentData;
457
+ if (isFieldNameOverrides(overrides) && overrides.otherFieldName) return overrides.otherFieldName;
458
+ if (!(r instanceof M2ORelation ? r.targetTable : r.sourceTable).m2oRelations.find((s) => tableToEntityName(config, s.targetTable) === keyEntity.name)) return camelCase(keyEntity.name);
459
+ else {
460
+ let fieldName = r.foreignKey.columns[0].name.replace(idSuffix, "");
461
+ fieldName = `${fieldName}_${keyEntity.name}`;
462
+ fieldName = fieldName.replace(refEntity.name.toLowerCase(), "");
463
+ return camelCase(fieldName);
464
+ }
550
465
  }
551
466
  const idSuffix = /_id$|Id$/;
552
467
  function referenceName(config, entity, r) {
553
- const [column] = r.foreignKey.columns;
554
- const overrides = column.commentData;
555
- return (polymorphicFieldName(config, r) ??
556
- // If the name is overridden then use that
557
- (isFieldNameOverrides(overrides) ? overrides.fieldName : undefined) ??
558
- (0, change_case_1.camelCase)(column.name.replace(idSuffix, "")));
468
+ const [column] = r.foreignKey.columns;
469
+ const overrides = column.commentData;
470
+ return polymorphicFieldName(config, r) ?? (isFieldNameOverrides(overrides) ? overrides.fieldName : void 0) ?? camelCase(column.name.replace(idSuffix, ""));
559
471
  }
560
472
  function enumFieldName(columnName) {
561
- return (0, change_case_1.camelCase)(columnName.replace(idSuffix, ""));
473
+ return camelCase(columnName.replace(idSuffix, ""));
562
474
  }
563
475
  function primitiveFieldName(columnName) {
564
- return (0, change_case_1.camelCase)(columnName);
476
+ return camelCase(columnName);
565
477
  }
566
478
  function manyToManyName(column) {
567
- const overrides = column.commentData;
568
- // If the name is overridden then use that
569
- if (isFieldNameOverrides(overrides) && overrides.otherFieldName) {
570
- return overrides.otherFieldName;
571
- }
572
- return (0, change_case_1.camelCase)((0, pluralize_1.plural)(column.name.replace(idSuffix, "")));
479
+ const overrides = column.commentData;
480
+ if (isFieldNameOverrides(overrides) && overrides.otherFieldName) return overrides.otherFieldName;
481
+ return camelCase(plural(column.name.replace(idSuffix, "")));
573
482
  }
574
483
  /** Returns the collection name to use on `entity` when referring to `otherEntity`s. */
575
- function collectionName(config,
576
- // I.e. the Author for o2m Author.books --> books.author_id
577
- singleEntity,
578
- // I.e. the Book for o2m Author.books --> books.author_id
579
- collectionEntity, r) {
580
- const [column] = r.foreignKey.columns;
581
- const overrides = column.commentData;
582
- // If the name is overridden then use that, but also singularize it
583
- if (isFieldNameOverrides(overrides) && overrides.otherFieldName) {
584
- const fieldName = overrides.otherFieldName;
585
- return { fieldName, singularName: (0, pluralize_1.singular)(fieldName) };
586
- }
587
- // I.e. if the m2o is `books.author_id`, use `Author.books` as the collection name (we pluralize at the end).
588
- let singularName = collectionEntity.name;
589
- // Check if we have multiple FKs from collectionEntity --> singleEntity and prefix with FK name if so
590
- const sourceTable = r.type === "m2o" ? r.sourceTable : r.targetTable;
591
- const targetTable = r.type === "m2o" ? r.targetTable : r.sourceTable;
592
- // If `books.foo_author_id` and `books.bar_author_id` both exist
593
- if (r.type !== "m2m" && sourceTable.m2oRelations.filter((r) => r.targetTable === targetTable).length > 1) {
594
- // Use `fooAuthorBooks`, `barAuthorBooks`
595
- singularName = `${column.name.replace(idSuffix, "")}_${singularName}`;
596
- }
597
- // If we've guessed `Book.bookReviews` based on `book_reviews.book_id` --> `bookReviews`, strip the `Book` prefix
598
- if (singularName.length > singleEntity.name.length && singularName.startsWith(singleEntity.name)) {
599
- singularName = singularName.substring(singleEntity.name.length);
600
- }
601
- // camelize the name
602
- singularName = (0, change_case_1.camelCase)(singularName);
603
- // and pluralize for fieldName
604
- return { fieldName: (0, pluralize_1.plural)(singularName), singularName };
484
+ function collectionName(config, singleEntity, collectionEntity, r) {
485
+ const [column] = r.foreignKey.columns;
486
+ const overrides = column.commentData;
487
+ if (isFieldNameOverrides(overrides) && overrides.otherFieldName) {
488
+ const fieldName = overrides.otherFieldName;
489
+ return {
490
+ fieldName,
491
+ singularName: singular(fieldName)
492
+ };
493
+ }
494
+ let singularName = collectionEntity.name;
495
+ const sourceTable = r.type === "m2o" ? r.sourceTable : r.targetTable;
496
+ const targetTable = r.type === "m2o" ? r.targetTable : r.sourceTable;
497
+ if (r.type !== "m2m" && sourceTable.m2oRelations.filter((r) => r.targetTable === targetTable).length > 1) singularName = `${column.name.replace(idSuffix, "")}_${singularName}`;
498
+ if (singularName.length > singleEntity.name.length && singularName.startsWith(singleEntity.name)) singularName = singularName.substring(singleEntity.name.length);
499
+ singularName = camelCase(singularName);
500
+ return {
501
+ fieldName: plural(singularName),
502
+ singularName
503
+ };
605
504
  }
606
505
  function failIfOverlappingFieldNames(entity) {
607
- const allFields = [
608
- entity.primaryKey,
609
- ...entity.primitives,
610
- ...entity.enums,
611
- ...entity.pgEnums,
612
- ...entity.manyToOnes,
613
- ...entity.oneToManys,
614
- ...entity.largeOneToManys,
615
- ...entity.oneToOnes,
616
- ...entity.manyToManys,
617
- ...entity.largeManyToManys,
618
- ...entity.manyToManyEnums,
619
- ...entity.polymorphics,
620
- ];
621
- Object.entries((0, joist_utils_1.groupBy)(allFields, (f) => f.fieldName)).forEach(([fieldName, fields]) => {
622
- if (fields.length > 1) {
623
- throw new Error(`In ${entity.name}, found multiple fields named '${fieldName}': ${fields.map((f) => f.kind).join(" ")}`);
624
- }
625
- });
506
+ const allFields = [
507
+ entity.primaryKey,
508
+ ...entity.primitives,
509
+ ...entity.enums,
510
+ ...entity.pgEnums,
511
+ ...entity.manyToOnes,
512
+ ...entity.oneToManys,
513
+ ...entity.largeOneToManys,
514
+ ...entity.oneToOnes,
515
+ ...entity.manyToManys,
516
+ ...entity.largeManyToManys,
517
+ ...entity.manyToManyEnums,
518
+ ...entity.polymorphics
519
+ ];
520
+ Object.entries(groupBy(allFields, (f) => f.fieldName)).forEach(([fieldName, fields]) => {
521
+ if (fields.length > 1) throw new Error(`In ${entity.name}, found multiple fields named '${fieldName}': ${fields.map((f) => f.kind).join(" ")}`);
522
+ });
626
523
  }
627
524
  function makeEntity(entityName) {
628
- // Default to the conventional names; `resolveNameConflicts` rewrites them if they collide.
629
- const names = entitySymbolNames(entityName);
630
- return {
631
- name: entityName,
632
- type: entityType(entityName),
633
- typeSymbol: entityTypeSymbol(entityName),
634
- typeForMetadataFile: entityTypeForMetadataFile(entityName),
635
- metaName: metaName(entityName),
636
- metaType: metaType(entityName),
637
- idType: entityTypeImport(entityName, names.idName),
638
- orderType: entityTypeImport(entityName, names.orderName),
639
- optsType: entityTypeImport(entityName, names.optsName),
640
- configConst: (0, ts_poet_1.imp)(`${(0, change_case_1.camelCase)(entityName)}Config@./entities.ts`, {
641
- definedIn: `./codegen/${entityName}Codegen.ts`,
642
- }),
643
- ...names,
644
- };
525
+ const names = entitySymbolNames(entityName);
526
+ return {
527
+ name: entityName,
528
+ type: entityType(entityName),
529
+ typeSymbol: entityTypeSymbol(entityName),
530
+ typeForMetadataFile: entityTypeForMetadataFile(entityName),
531
+ metaName: metaName(entityName),
532
+ metaType: metaType(entityName),
533
+ idType: entityTypeImport(entityName, names.idName),
534
+ orderType: entityTypeImport(entityName, names.orderName),
535
+ optsType: entityTypeImport(entityName, names.optsName),
536
+ configConst: imp(`${camelCase(entityName)}Config@./entities.ts`, { definedIn: `./codegen/${entityName}Codegen.ts` }),
537
+ ...names
538
+ };
645
539
  }
646
540
  /**
647
- * Collapses the per-relation `otherEntity` copies down to the one primary `Entity` per name.
648
- *
649
- * `makeEntity` mints a fresh `Entity` for every relation's `otherEntity`, so each entity ends up with
650
- * many duplicate objects floating around. Pointing them all at the single `entitiesByName[name].entity`
651
- * instance means later passes (i.e. `resolveNameConflicts`) only have to update one object per name.
652
- *
653
- * Must run after inheritance, since STI/CTI specialization both adds and re-points `otherEntity`s.
654
- */
541
+ * Collapses the per-relation `otherEntity` copies down to the one primary `Entity` per name.
542
+ *
543
+ * `makeEntity` mints a fresh `Entity` for every relation's `otherEntity`, so each entity ends up with
544
+ * many duplicate objects floating around. Pointing them all at the single `entitiesByName[name].entity`
545
+ * instance means later passes (i.e. `resolveNameConflicts`) only have to update one object per name.
546
+ *
547
+ * Must run after inheritance, since STI/CTI specialization both adds and re-points `otherEntity`s.
548
+ */
655
549
  function canonicalizeOtherEntities(db) {
656
- const canonical = (other) => db.entitiesByName[other.name]?.entity ?? other;
657
- for (const meta of db.entities) {
658
- for (const field of [
659
- ...meta.manyToOnes,
660
- ...meta.oneToManys,
661
- ...meta.largeOneToManys,
662
- ...meta.oneToOnes,
663
- ...meta.manyToManys,
664
- ...meta.largeManyToManys,
665
- ]) {
666
- field.otherEntity = canonical(field.otherEntity);
667
- }
668
- for (const poly of meta.polymorphics) {
669
- for (const comp of poly.components)
670
- comp.otherEntity = canonical(comp.otherEntity);
671
- }
672
- }
550
+ const canonical = (other) => db.entitiesByName[other.name]?.entity ?? other;
551
+ for (const meta of db.entities) {
552
+ for (const field of [
553
+ ...meta.manyToOnes,
554
+ ...meta.oneToManys,
555
+ ...meta.largeOneToManys,
556
+ ...meta.oneToOnes,
557
+ ...meta.manyToManys,
558
+ ...meta.largeManyToManys
559
+ ]) field.otherEntity = canonical(field.otherEntity);
560
+ for (const poly of meta.polymorphics) for (const comp of poly.components) comp.otherEntity = canonical(comp.otherEntity);
561
+ if (meta.physicalMetadata) canonicalizeOtherEntities({
562
+ ...db,
563
+ entities: [meta.physicalMetadata]
564
+ });
565
+ }
673
566
  }
674
567
  /**
675
- * Rewrites codegen'd type names that collide with another exported type name.
676
- *
677
- * `makeEntity` defaults each name to the conventional `${name}<Suffix>`, but if a separate entity or
678
- * enum is literally named e.g. `AuthorScope` or `AuthorOrder`, our generated type of the same name
679
- * would collide with it, so we fall back to `Author_Scope` / `Author_Order`.
680
- *
681
- * Relies on `canonicalizeOtherEntities` having run, so mutating each primary `meta.entity` also updates
682
- * the `otherEntity` references that point at it (e.g. `Book.author: AuthorId` follows `Author`'s rename).
683
- */
568
+ * Rewrites codegen'd type names that collide with another exported type name.
569
+ *
570
+ * `makeEntity` defaults each name to the conventional `${name}<Suffix>`, but if a separate entity or
571
+ * enum is literally named e.g. `AuthorScope` or `AuthorOrder`, our generated type of the same name
572
+ * would collide with it, so we fall back to `Author_Scope` / `Author_Order`.
573
+ *
574
+ * Relies on `canonicalizeOtherEntities` having run, so mutating each primary `meta.entity` also updates
575
+ * the `otherEntity` references that point at it (e.g. `Book.author: AuthorId` follows `Author`'s rename).
576
+ */
684
577
  function resolveNameConflicts(config, db) {
685
- // The names exported into `entities.ts` that a codegen'd type could shadow.
686
- const reserved = new Set(db.entities.map((meta) => meta.name));
687
- for (const enumData of Object.values(db.enums)) {
688
- // An enum table exports its (singularized) type, its `Details` type/const, and its pluralized const,
689
- // i.e. `ChangeRequestAssetScope`, `ChangeRequestAssetScopeDetails`, and `ChangeRequestAssetScopes`.
690
- const enumName = (0, utils_1.tableToEntityName)(config, enumData.table);
691
- reserved.add(enumName).add(`${enumName}Details`).add((0, pluralize_1.plural)(enumName));
692
- }
693
- for (const pgEnum of Object.values(db.pgEnums))
694
- reserved.add(pgEnum.name);
695
- for (const meta of db.entities) {
696
- if (hasNameConflict(meta.name, reserved))
697
- applyEntityNames(meta.entity, reserved);
698
- }
578
+ const reserved = new Set(db.entities.map((meta) => meta.name));
579
+ for (const enumData of Object.values(db.enums)) {
580
+ const enumName = tableToEntityName(config, enumData.table);
581
+ reserved.add(enumName).add(`${enumName}Details`).add(plural(enumName));
582
+ }
583
+ for (const pgEnum of Object.values(db.pgEnums)) reserved.add(pgEnum.name);
584
+ for (const meta of db.entities) if (hasNameConflict(meta.name, reserved)) applyEntityNames(meta.entity, reserved);
699
585
  }
700
586
  /** Computes the codegen'd type names for an entity, underscoring any that `reserved` already contains. */
701
587
  function entitySymbolNames(name, reserved) {
702
- const pick = (suffix) => (reserved?.has(`${name}${suffix}`) ? `${name}_${suffix}` : `${name}${suffix}`);
703
- return {
704
- idName: pick("Id"),
705
- fieldsName: pick("Fields"),
706
- optsName: pick("Opts"),
707
- idsOptsName: pick("IdsOpts"),
708
- filterName: pick("Filter"),
709
- graphqlFilterName: pick("GraphQLFilter"),
710
- orderName: pick("Order"),
711
- factoryExtrasName: pick("FactoryExtras"),
712
- scopeName: pick("Scope"),
713
- scopesName: pick("Scopes"),
714
- };
588
+ const pick = (suffix) => reserved?.has(`${name}${suffix}`) ? `${name}_${suffix}` : `${name}${suffix}`;
589
+ return {
590
+ idName: pick("Id"),
591
+ fieldsName: pick("Fields"),
592
+ optsName: pick("Opts"),
593
+ idsOptsName: pick("IdsOpts"),
594
+ filterName: pick("Filter"),
595
+ graphqlFilterName: pick("GraphQLFilter"),
596
+ orderName: pick("Order"),
597
+ factoryExtrasName: pick("FactoryExtras"),
598
+ scopeName: pick("Scope"),
599
+ scopesName: pick("Scopes")
600
+ };
715
601
  }
716
602
  /** Returns true if any of the entity's conventional type names is already taken. */
717
603
  function hasNameConflict(name, reserved) {
718
- return Object.values(entitySymbolNames(name)).some((conventional) => reserved.has(conventional));
604
+ return Object.values(entitySymbolNames(name)).some((conventional) => reserved.has(conventional));
719
605
  }
720
606
  /** Rewrites an entity's type names (and the `Import`s built from them) to their de-conflicted form. */
721
607
  function applyEntityNames(entity, reserved) {
722
- const names = entitySymbolNames(entity.name, reserved);
723
- Object.assign(entity, names);
724
- entity.idType = entityTypeImport(entity.name, names.idName);
725
- entity.orderType = entityTypeImport(entity.name, names.orderName);
726
- entity.optsType = entityTypeImport(entity.name, names.optsName);
608
+ const names = entitySymbolNames(entity.name, reserved);
609
+ Object.assign(entity, names);
610
+ entity.idType = entityTypeImport(entity.name, names.idName);
611
+ entity.orderType = entityTypeImport(entity.name, names.orderName);
612
+ entity.optsType = entityTypeImport(entity.name, names.optsName);
727
613
  }
728
614
  function entityTypeImport(entityName, symbolName) {
729
- return (0, ts_poet_1.imp)(`t:${symbolName}@./entities.ts`, { definedIn: `./codegen/${entityName}Codegen.ts` });
615
+ return imp(`t:${symbolName}@./entities.ts`, { definedIn: `./codegen/${entityName}Codegen.ts` });
730
616
  }
731
617
  function metaName(entityName) {
732
- return `${(0, change_case_1.camelCase)(entityName)}Meta`;
618
+ return `${camelCase(entityName)}Meta`;
733
619
  }
734
620
  function metaType(entityName) {
735
- return (0, ts_poet_1.imp)(`${metaName(entityName)}@./entities.ts`);
621
+ return imp(`${metaName(entityName)}@./entities.ts`);
736
622
  }
737
623
  function entityType(entityName) {
738
- return (0, ts_poet_1.imp)(`t:${entityName}@./entities.ts`);
624
+ return imp(`t:${entityName}@./entities.ts`);
739
625
  }
740
626
  function entityTypeSymbol(entityName) {
741
- return (0, ts_poet_1.imp)(`${entityName}@./entities.ts`);
627
+ return imp(`${entityName}@./entities.ts`);
742
628
  }
743
629
  function entityTypeForMetadataFile(entityName) {
744
- return (0, ts_poet_1.imp)(`${entityName}@./${entityName}.ts`);
630
+ return imp(`${entityName}@./${entityName}.ts`);
745
631
  }
746
632
  function mapType(config, tableName, columnName, dbColumnType) {
747
- return (0, utils_1.mapSimpleDbTypeToTypescriptType)(config, dbColumnType);
633
+ return mapSimpleDbTypeToTypescriptType(config, dbColumnType);
748
634
  }
749
635
  function isEnumArray(c) {
750
- return c.arrayDimension === 1 && !!c.comment && c.comment.startsWith("enum=");
636
+ return c.arrayDimension === 1 && !!c.comment && c.comment.startsWith("enum=");
751
637
  }
752
638
  function isArray(c) {
753
- return c.arrayDimension === 1;
639
+ return c.arrayDimension === 1;
754
640
  }
755
641
  function isPgEnum(c) {
756
- return c.type instanceof pg_structure_1.EnumType;
642
+ return c.type instanceof EnumType;
757
643
  }
758
644
  function superstructType(s) {
759
- // Assume it's `foo@...`, turn it into `Foo@...`
760
- const [symbol, ...path] = s.split("@");
761
- return ts_poet_1.Import.from(`${(0, change_case_1.pascalCase)(symbol)}@${path.join("@")}`);
645
+ const [symbol, ...path] = s.split("@");
646
+ return Import.from(`${pascalCase(symbol)}@${path.join("@")}`);
762
647
  }
763
648
  function zodSchemaType(s) {
764
- const schema = ts_poet_1.Import.from(s);
765
- return (0, ts_poet_1.code) `${symbols_1.Zod}.input<typeof ${schema}>`;
649
+ const schema = Import.from(s);
650
+ return code`${Zod}.input<typeof ${schema}>`;
766
651
  }
767
652
  function userFieldTypeType(s) {
768
- return ts_poet_1.Import.from(`t:${s}`);
653
+ return Import.from(`t:${s}`);
769
654
  }
770
655
  function serdeType(s) {
771
- return ts_poet_1.Import.from(s);
656
+ return Import.from(s);
772
657
  }
658
+ //#endregion
659
+ export { EntityDbMetadata, canonicalizeOtherEntities, collectionName, failIfOverlappingFieldNames, makeEntity, manyToManyName, oneToOneName, referenceName, resolveNameConflicts };
660
+
773
661
  //# sourceMappingURL=EntityDbMetadata.js.map