joist-codegen 2.3.0-next.6 → 2.3.0-next.61

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 (420) hide show
  1. package/build/EntityDbMetadata.cjs +608 -0
  2. package/build/EntityDbMetadata.cjs.map +1 -0
  3. package/build/EntityDbMetadata.d.cts +274 -0
  4. package/build/EntityDbMetadata.d.cts.map +1 -0
  5. package/build/EntityDbMetadata.d.mts +274 -0
  6. package/build/EntityDbMetadata.d.mts.map +1 -0
  7. package/build/EntityDbMetadata.js +485 -661
  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 +127 -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 +110 -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 +955 -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 +738 -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 +290 -0
  194. package/build/generateMetadataFile.cjs.map +1 -0
  195. package/build/generateMetadataFile.d.cts +8 -0
  196. package/build/generateMetadataFile.d.cts.map +1 -0
  197. package/build/generateMetadataFile.d.mts +8 -0
  198. package/build/generateMetadataFile.d.mts.map +1 -0
  199. package/build/generateMetadataFile.js +116 -140
  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 +108 -127
  216. package/build/index.js.map +1 -1
  217. package/build/inheritance.cjs +213 -0
  218. package/build/inheritance.cjs.map +1 -0
  219. package/build/inheritance.d.cts +12 -0
  220. package/build/inheritance.d.cts.map +1 -0
  221. package/build/inheritance.d.mts +12 -0
  222. package/build/inheritance.d.mts.map +1 -0
  223. package/build/inheritance.js +193 -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/scanEntityFiles.cjs +46 -0
  258. package/build/scanEntityFiles.cjs.map +1 -0
  259. package/build/scanEntityFiles.d.cts +8 -0
  260. package/build/scanEntityFiles.d.cts.map +1 -0
  261. package/build/scanEntityFiles.d.mts +8 -0
  262. package/build/scanEntityFiles.d.mts.map +1 -0
  263. package/build/scanEntityFiles.js +37 -42
  264. package/build/scanEntityFiles.js.map +1 -1
  265. package/build/sortForeignKeys.cjs +99 -0
  266. package/build/sortForeignKeys.cjs.map +1 -0
  267. package/build/{sortForeignKeys.d.ts → sortForeignKeys.d.cts} +8 -5
  268. package/build/sortForeignKeys.d.cts.map +1 -0
  269. package/build/sortForeignKeys.d.mts +35 -0
  270. package/build/sortForeignKeys.d.mts.map +1 -0
  271. package/build/sortForeignKeys.js +88 -117
  272. package/build/sortForeignKeys.js.map +1 -1
  273. package/build/symbols.cjs +228 -0
  274. package/build/symbols.cjs.map +1 -0
  275. package/build/symbols.d.cts +115 -0
  276. package/build/symbols.d.cts.map +1 -0
  277. package/build/symbols.d.mts +115 -0
  278. package/build/symbols.d.mts.map +1 -0
  279. package/build/symbols.js +116 -113
  280. package/build/symbols.js.map +1 -1
  281. package/build/tsdoc.cjs +22 -0
  282. package/build/tsdoc.cjs.map +1 -0
  283. package/build/tsdoc.d.cts +15 -0
  284. package/build/tsdoc.d.cts.map +1 -0
  285. package/build/tsdoc.d.mts +15 -0
  286. package/build/tsdoc.d.mts.map +1 -0
  287. package/build/tsdoc.js +18 -15
  288. package/build/tsdoc.js.map +1 -1
  289. package/build/utils.cjs +173 -0
  290. package/build/utils.cjs.map +1 -0
  291. package/build/utils.d.cts +34 -0
  292. package/build/utils.d.cts.map +1 -0
  293. package/build/utils.d.mts +34 -0
  294. package/build/utils.d.mts.map +1 -0
  295. package/build/utils.js +112 -166
  296. package/build/utils.js.map +1 -1
  297. package/build/write-json-schema.cjs +23 -0
  298. package/build/write-json-schema.cjs.map +1 -0
  299. package/build/write-json-schema.d.cts +1 -0
  300. package/build/write-json-schema.d.mts +1 -0
  301. package/build/write-json-schema.js +19 -13
  302. package/build/write-json-schema.js.map +1 -1
  303. package/package.json +37 -17
  304. package/skills/joist-docs/SKILL.md +133 -0
  305. package/skills/joist-em-basics/SKILL.md +114 -0
  306. package/skills/joist-partial-updates/SKILL.md +352 -0
  307. package/skills/joist-reactive-hints/SKILL.md +150 -0
  308. package/skills/joist-test-factories/SKILL.md +397 -0
  309. package/skills/joist-upsert/SKILL.md +95 -0
  310. package/build/EntityDbMetadata.d.ts +0 -269
  311. package/build/EntityDbMetadata.d.ts.map +0 -1
  312. package/build/EntityDbMetadata.test.d.ts +0 -2
  313. package/build/EntityDbMetadata.test.d.ts.map +0 -1
  314. package/build/EntityDbMetadata.test.js +0 -211
  315. package/build/EntityDbMetadata.test.js.map +0 -1
  316. package/build/assignTags.d.ts.map +0 -1
  317. package/build/codemods/Codemod.d.ts +0 -14
  318. package/build/codemods/Codemod.d.ts.map +0 -1
  319. package/build/codemods/Codemod.js.map +0 -1
  320. package/build/codemods/JscodeshiftMod.d.ts +0 -11
  321. package/build/codemods/JscodeshiftMod.d.ts.map +0 -1
  322. package/build/codemods/__tests__/codemod_0001-rename_has_async_property.test.d.ts +0 -2
  323. package/build/codemods/__tests__/codemod_0001-rename_has_async_property.test.d.ts.map +0 -1
  324. package/build/codemods/__tests__/codemod_0001-rename_has_async_property.test.js +0 -9
  325. package/build/codemods/__tests__/codemod_0001-rename_has_async_property.test.js.map +0 -1
  326. package/build/codemods/__tests__/codemod_0002-rename_async_query_fields.test.d.ts +0 -2
  327. package/build/codemods/__tests__/codemod_0002-rename_async_query_fields.test.d.ts.map +0 -1
  328. package/build/codemods/__tests__/codemod_0002-rename_async_query_fields.test.js +0 -9
  329. package/build/codemods/__tests__/codemod_0002-rename_async_query_fields.test.js.map +0 -1
  330. package/build/codemods/__tests__/codemod_0003-rename_find_paginated.test.d.ts +0 -2
  331. package/build/codemods/__tests__/codemod_0003-rename_find_paginated.test.d.ts.map +0 -1
  332. package/build/codemods/__tests__/codemod_0003-rename_find_paginated.test.js +0 -9
  333. package/build/codemods/__tests__/codemod_0003-rename_find_paginated.test.js.map +0 -1
  334. package/build/codemods/codemod_0001-rename_has_async_property.d.ts +0 -7
  335. package/build/codemods/codemod_0001-rename_has_async_property.d.ts.map +0 -1
  336. package/build/codemods/codemod_0002-rename_async_query_fields.d.ts +0 -7
  337. package/build/codemods/codemod_0002-rename_async_query_fields.d.ts.map +0 -1
  338. package/build/codemods/codemod_0003-rename_find_paginated.d.ts +0 -7
  339. package/build/codemods/codemod_0003-rename_find_paginated.d.ts.map +0 -1
  340. package/build/codemods/index.d.ts +0 -9
  341. package/build/codemods/index.d.ts.map +0 -1
  342. package/build/codemods/index.test.d.ts +0 -2
  343. package/build/codemods/index.test.d.ts.map +0 -1
  344. package/build/codemods/index.test.js +0 -24
  345. package/build/codemods/index.test.js.map +0 -1
  346. package/build/config.d.ts +0 -167
  347. package/build/config.d.ts.map +0 -1
  348. package/build/config.test.d.ts +0 -2
  349. package/build/config.test.d.ts.map +0 -1
  350. package/build/config.test.js +0 -78
  351. package/build/config.test.js.map +0 -1
  352. package/build/docs/cache.d.ts +0 -14
  353. package/build/docs/cache.d.ts.map +0 -1
  354. package/build/docs/cache.test.d.ts +0 -2
  355. package/build/docs/cache.test.d.ts.map +0 -1
  356. package/build/docs/cache.test.js +0 -47
  357. package/build/docs/cache.test.js.map +0 -1
  358. package/build/docs/generate-metadata-docs.d.ts +0 -6
  359. package/build/docs/generate-metadata-docs.d.ts.map +0 -1
  360. package/build/docs/index.d.ts +0 -9
  361. package/build/docs/index.d.ts.map +0 -1
  362. package/build/docs/index.test.d.ts +0 -2
  363. package/build/docs/index.test.d.ts.map +0 -1
  364. package/build/docs/index.test.js +0 -100
  365. package/build/docs/index.test.js.map +0 -1
  366. package/build/docs/markdown.d.ts.map +0 -1
  367. package/build/docs/markdown.test.d.ts +0 -2
  368. package/build/docs/markdown.test.d.ts.map +0 -1
  369. package/build/docs/markdown.test.js +0 -280
  370. package/build/docs/markdown.test.js.map +0 -1
  371. package/build/docs/parsing.d.ts +0 -42
  372. package/build/docs/parsing.d.ts.map +0 -1
  373. package/build/docs/parsing.test.d.ts +0 -2
  374. package/build/docs/parsing.test.d.ts.map +0 -1
  375. package/build/docs/parsing.test.js +0 -190
  376. package/build/docs/parsing.test.js.map +0 -1
  377. package/build/findEntityScopes.d.ts +0 -11
  378. package/build/findEntityScopes.d.ts.map +0 -1
  379. package/build/foreignKeyOrdering.d.ts +0 -3
  380. package/build/foreignKeyOrdering.d.ts.map +0 -1
  381. package/build/generate.d.ts +0 -12
  382. package/build/generate.d.ts.map +0 -1
  383. package/build/generateEntitiesFile.d.ts +0 -7
  384. package/build/generateEntitiesFile.d.ts.map +0 -1
  385. package/build/generateEntityCodegenFile.d.ts +0 -11
  386. package/build/generateEntityCodegenFile.d.ts.map +0 -1
  387. package/build/generateEntityFile.d.ts +0 -6
  388. package/build/generateEntityFile.d.ts.map +0 -1
  389. package/build/generateEntityTestFile.d.ts +0 -6
  390. package/build/generateEntityTestFile.d.ts.map +0 -1
  391. package/build/generateEnumFile.d.ts +0 -5
  392. package/build/generateEnumFile.d.ts.map +0 -1
  393. package/build/generateFactoriesFiles.d.ts +0 -4
  394. package/build/generateFactoriesFiles.d.ts.map +0 -1
  395. package/build/generateFlushFunction.d.ts.map +0 -1
  396. package/build/generateMetadataFile.d.ts +0 -5
  397. package/build/generateMetadataFile.d.ts.map +0 -1
  398. package/build/generatePgEnumFile.d.ts +0 -5
  399. package/build/generatePgEnumFile.d.ts.map +0 -1
  400. package/build/index.d.ts +0 -11
  401. package/build/index.d.ts.map +0 -1
  402. package/build/inheritance.d.ts +0 -10
  403. package/build/inheritance.d.ts.map +0 -1
  404. package/build/keywords.d.ts +0 -2
  405. package/build/keywords.d.ts.map +0 -1
  406. package/build/loadMetadata.d.ts +0 -26
  407. package/build/loadMetadata.d.ts.map +0 -1
  408. package/build/logger.d.ts +0 -10
  409. package/build/logger.d.ts.map +0 -1
  410. package/build/scanEntityFiles.d.ts +0 -5
  411. package/build/scanEntityFiles.d.ts.map +0 -1
  412. package/build/sortForeignKeys.d.ts.map +0 -1
  413. package/build/symbols.d.ts +0 -108
  414. package/build/symbols.d.ts.map +0 -1
  415. package/build/tsdoc.d.ts +0 -12
  416. package/build/tsdoc.d.ts.map +0 -1
  417. package/build/utils.d.ts +0 -31
  418. package/build/utils.d.ts.map +0 -1
  419. package/build/write-json-schema.d.ts +0 -2
  420. package/build/write-json-schema.d.ts.map +0 -1
@@ -1,265 +1,211 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyInheritanceUpdates = applyInheritanceUpdates;
4
- exports.getStiEntities = getStiEntities;
5
- const EntityDbMetadata_1 = require("./EntityDbMetadata");
6
- const utils_1 = require("./utils");
1
+ import { fail } from "./utils.js";
2
+ import "./config.js";
3
+ import { canonicalizeOtherEntities, makeEntity } from "./EntityDbMetadata.js";
4
+ //#region src/inheritance.ts
7
5
  function applyInheritanceUpdates(config, db) {
8
- const { entities, entitiesByName } = db;
9
- setClassTableInheritance(entities, entitiesByName);
10
- expandSingleTableInheritance(config, entitiesByName, entities);
11
- rewriteSingleTableForeignKeys(config, entities);
12
- setupSubTypeSpecialization(config, entities);
13
- // Now that all relations (incl. specialized ones) exist, collapse the duplicate `otherEntity` objects
14
- (0, EntityDbMetadata_1.canonicalizeOtherEntities)(db);
6
+ const { entities, entitiesByName } = db;
7
+ setClassTableInheritance(entities, entitiesByName);
8
+ expandSingleTableInheritance(config, entitiesByName, entities);
9
+ rewriteSingleTableForeignKeys(config, entities);
10
+ setupSubTypeSpecialization(config, entities);
11
+ canonicalizeOtherEntities(db);
15
12
  }
16
13
  /**
17
- * Looks for subtypes specializing a FK of their base type, and give them a specialized m2o.
18
- *
19
- * I.e. `SmallPublishers.group: SmallPublisherGroup`.
20
- *
21
- * This means the `publishers.group_id` FK will actually be in the `EntityDbMetadata` twice,
22
- * once for the base and once for the child, which is unusual, but gets the types generated
23
- * that we want, and then we fixup/dedupe them at runtime in `configure.ts` when creating
24
- * `meta.allFields`.
25
- */
14
+ * Looks for subtypes specializing a FK of their base type, and give them a specialized m2o.
15
+ *
16
+ * I.e. `SmallPublishers.group: SmallPublisherGroup`.
17
+ *
18
+ * This means the `publishers.group_id` FK will actually be in the `EntityDbMetadata` twice,
19
+ * once for the base and once for the child, which is unusual, but gets the types generated
20
+ * that we want, and then we fixup/dedupe them at runtime in `configure.ts` when creating
21
+ * `meta.allFields`.
22
+ */
26
23
  function setupSubTypeSpecialization(config, entities) {
27
- for (const entity of entities) {
28
- if (entity.baseType) {
29
- const entityConfig = config.entities[entity.name];
30
- const baseConfig = config.entities[entity.baseType.name];
31
- // Look through the base's m2os & o2ms, looking for a config specialization
32
- for (const rel of [...entity.baseType.manyToOnes, ...entity.baseType.oneToManys]) {
33
- const { notNull } = entityConfig?.relations?.[rel.fieldName] ?? {};
34
- const subType = entityConfig?.relations?.[rel.fieldName]?.subType ??
35
- baseConfig?.relations?.[rel.fieldName]?.subType ??
36
- // Probe the otherFieldName for a `subType: "self"` on self-referential relations in STI tables
37
- baseConfig?.relations?.[rel.otherFieldName]?.subType ??
38
- // if we are only marking the relation as required and not specifying a subtype, then use the original type
39
- (notNull ? rel.otherEntity.name : undefined);
40
- if (!subType) {
41
- // continue...
42
- }
43
- else if (subType === "self" && rel.kind === "m2o") {
44
- // Specialize `TaskNew.copiedFrom: TaskNew` & `TaskOld.copiedFrom: TaskOld`
45
- entity.manyToOnes.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: (0, EntityDbMetadata_1.makeEntity)(entity.name) });
46
- }
47
- else if (subType === "self" && rel.kind === "o2m") {
48
- // Specialize `TaskNew.copiedTo: TaskNew[]` & `TaskOld.copiedTo: TaskOld[]`
49
- entity.oneToManys.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: (0, EntityDbMetadata_1.makeEntity)(entity.name) });
50
- }
51
- else if (rel.kind === "m2o") {
52
- // Specialize `SmallPublisher.group: SmallPublisherGroup`
53
- entity.manyToOnes.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: (0, EntityDbMetadata_1.makeEntity)(subType) });
54
- }
55
- else if (rel.kind === "o2m") {
56
- // Specialize `SmallPublisherGroup.publishers: SmallPublisher`
57
- entity.oneToManys.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: (0, EntityDbMetadata_1.makeEntity)(subType) });
58
- }
59
- }
60
- // Look through the base's primitives looking for a config specialization
61
- for (const field of entity.baseType?.primitives ?? []) {
62
- // the only specialization a primitive can have is nullability
63
- const { notNull } = entityConfig?.fields?.[field.fieldName] ?? {};
64
- if (notNull) {
65
- entity.primitives.push({ ...field, notNull });
66
- }
67
- }
68
- }
69
- }
24
+ for (const entity of entities) if (entity.baseType) {
25
+ const entityConfig = config.entities[entity.name];
26
+ const baseConfig = config.entities[entity.baseType.name];
27
+ for (const rel of [...entity.baseType.manyToOnes, ...entity.baseType.oneToManys]) {
28
+ const { notNull } = entityConfig?.relations?.[rel.fieldName] ?? {};
29
+ const subType = entityConfig?.relations?.[rel.fieldName]?.subType ?? baseConfig?.relations?.[rel.fieldName]?.subType ?? baseConfig?.relations?.[rel.otherFieldName]?.subType ?? (notNull ? rel.otherEntity.name : void 0);
30
+ if (!subType) {} else if (subType === "self" && rel.kind === "m2o") entity.manyToOnes.push({
31
+ ...rel,
32
+ ...notNull ? { notNull } : {},
33
+ otherEntity: makeEntity(entity.name)
34
+ });
35
+ else if (subType === "self" && rel.kind === "o2m") entity.oneToManys.push({
36
+ ...rel,
37
+ ...notNull ? { notNull } : {},
38
+ otherEntity: makeEntity(entity.name)
39
+ });
40
+ else if (rel.kind === "m2o") entity.manyToOnes.push({
41
+ ...rel,
42
+ ...notNull ? { notNull } : {},
43
+ otherEntity: makeEntity(subType)
44
+ });
45
+ else if (rel.kind === "o2m") entity.oneToManys.push({
46
+ ...rel,
47
+ ...notNull ? { notNull } : {},
48
+ otherEntity: makeEntity(subType)
49
+ });
50
+ }
51
+ for (const field of entity.baseType?.primitives ?? []) {
52
+ const { notNull } = entityConfig?.fields?.[field.fieldName] ?? {};
53
+ if (notNull) entity.primitives.push({
54
+ ...field,
55
+ notNull
56
+ });
57
+ }
58
+ }
70
59
  }
71
60
  /**
72
- * Ensure CTI base types have their inheritanceType set.
73
- *
74
- * (We automatically set `inheritanceType` for STI tables when we see their config
75
- * setup, see `expandSingleTableInheritance`.)
76
- */
61
+ * Ensure CTI base types have their inheritanceType set.
62
+ *
63
+ * (We automatically set `inheritanceType` for STI tables when we see their config
64
+ * setup, see `expandSingleTableInheritance`.)
65
+ */
77
66
  function setClassTableInheritance(entities, entitiesByName) {
78
- const ctiBaseNames = [];
79
- for (const entity of entities) {
80
- if (entity.baseClassName) {
81
- ctiBaseNames.push(entity.baseClassName);
82
- const base = entitiesByName[entity.baseClassName];
83
- entity.baseType = base;
84
- base.subTypes.push(entity);
85
- }
86
- }
87
- for (const entity of entities) {
88
- if (ctiBaseNames.includes(entity.name))
89
- entity.inheritanceType = "cti";
90
- }
67
+ const ctiBaseNames = [];
68
+ for (const entity of entities) if (entity.baseClassName) {
69
+ ctiBaseNames.push(entity.baseClassName);
70
+ const base = entitiesByName[entity.baseClassName];
71
+ entity.baseType = base;
72
+ base.subTypes.push(entity);
73
+ }
74
+ for (const entity of entities) if (ctiBaseNames.includes(entity.name)) entity.inheritanceType = "cti";
91
75
  }
92
76
  /** Expands STI tables into multiple entities, so they get separate `SubTypeCodegen.ts` & `SubType.ts` files. */
93
77
  function expandSingleTableInheritance(config, entitiesByName, entities) {
94
- for (const entity of entities) {
95
- const [fieldName, stiField] = Object.entries(config.entities[entity.name]?.fields || {}).find(([, f]) => !!f.stiDiscriminator) ?? [];
96
- if (fieldName && stiField && stiField.stiDiscriminator) {
97
- entity.inheritanceType = "sti";
98
- // Ensure we have an enum field so that we can bake the STI discriminators into the metadata.ts file
99
- const enumField = entity.enums.find((e) => e.fieldName === fieldName) ??
100
- (0, utils_1.fail)(`No enum column found for ${entity.name}.${fieldName}, which is required to use singleTableInheritance`);
101
- entity.stiDiscriminatorField = enumField.fieldName;
102
- // Find the available discriminators/subtypes, i.e. NEW => NewTask, OLD => OldTask, etc.
103
- const subTypes = Object.entries(stiField.stiDiscriminator);
104
- const allFields = [
105
- ...Object.entries(config.entities[entity.name]?.fields ?? {}),
106
- ...Object.entries(config.entities[entity.name]?.relations ?? {}),
107
- ];
108
- // Make sure there aren't any typos in `stiType`s
109
- const availableCodes = subTypes.map(([code]) => code);
110
- const availableNames = subTypes.map(([, name]) => name);
111
- const available = [...availableCodes, ...availableNames];
112
- allFields.filter(([name, f]) => {
113
- if (f.stiType && !available.includes(f.stiType)) {
114
- (0, utils_1.fail)(`${name}.stiType '${f.stiType}' is invalid, expected one of ${available.join(", ")}`);
115
- }
116
- });
117
- // Now split each subType out into its out entity
118
- for (const [enumCode, subTypeName] of subTypes) {
119
- // Find all the base entity's fields that belong to us
120
- const subTypeFields = allFields.filter(([, f]) => f.stiType === subTypeName || f.stiType === enumCode);
121
- const subTypeFieldNames = subTypeFields.map(([name]) => name);
122
- // Make fields as required
123
- function maybeRequired(field) {
124
- const config = subTypeFields.find(([name]) => name === field.fieldName)?.[1];
125
- if (config.notNull)
126
- field.notNull = true;
127
- return field;
128
- }
129
- // Synthesize an entity for this STI sub-entity
130
- const subEntity = {
131
- name: subTypeName,
132
- entity: (0, EntityDbMetadata_1.makeEntity)(subTypeName),
133
- tableName: entity.tableName,
134
- primaryKey: entity.primaryKey,
135
- primitives: entity.primitives.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),
136
- enums: entity.enums.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),
137
- pgEnums: entity.pgEnums.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),
138
- manyToOnes: entity.manyToOnes.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),
139
- oneToManys: entity.oneToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),
140
- largeOneToManys: entity.largeOneToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),
141
- oneToOnes: entity.oneToOnes.filter((f) => subTypeFieldNames.includes(f.fieldName)),
142
- manyToManys: entity.manyToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),
143
- largeManyToManys: entity.largeManyToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),
144
- manyToManyEnums: entity.manyToManyEnums.filter((f) => subTypeFieldNames.includes(f.fieldName)),
145
- polymorphics: entity.polymorphics.filter((f) => subTypeFieldNames.includes(f.fieldName)),
146
- tagName: entity.tagName,
147
- createdAt: undefined,
148
- updatedAt: undefined,
149
- deletedAt: undefined,
150
- baseClassName: entity.name,
151
- baseType: entity,
152
- subTypes: [],
153
- inheritanceType: "sti",
154
- stiDiscriminatorValue: (enumField.enumRows.find((r) => r.code === enumCode) ??
155
- (0, utils_1.fail)(`No enum row found for ${entity.name}.${fieldName}.${enumCode}`)).id,
156
- abstract: false,
157
- nonDeferredFkOrder: entity.nonDeferredFkOrder,
158
- get nonDeferredFks() {
159
- return [
160
- ...this.manyToOnes.filter((r) => !r.isDeferredAndDeferrable),
161
- ...this.polymorphics.flatMap((p) => p.components).filter((c) => !c.isDeferredAndDeferrable),
162
- ];
163
- },
164
- get nonDeferredManyToManyFks() {
165
- return this.manyToManys.filter((r) => !r.isDeferredAndDeferrable);
166
- },
167
- };
168
- // Now strip all the subclass fields from the base class
169
- entity.primitives = entity.primitives.filter((f) => !subTypeFieldNames.includes(f.fieldName));
170
- entity.enums = entity.enums.filter((f) => !subTypeFieldNames.includes(f.fieldName));
171
- entity.pgEnums = entity.pgEnums.filter((f) => !subTypeFieldNames.includes(f.fieldName));
172
- entity.manyToOnes = entity.manyToOnes.filter((f) => !subTypeFieldNames.includes(f.fieldName));
173
- entity.oneToManys = entity.oneToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));
174
- entity.largeOneToManys = entity.largeOneToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));
175
- entity.oneToOnes = entity.oneToOnes.filter((f) => !subTypeFieldNames.includes(f.fieldName));
176
- entity.manyToManys = entity.manyToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));
177
- entity.largeManyToManys = entity.largeManyToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));
178
- entity.manyToManyEnums = entity.manyToManyEnums.filter((f) => !subTypeFieldNames.includes(f.fieldName));
179
- entity.polymorphics = entity.polymorphics.filter((f) => !subTypeFieldNames.includes(f.fieldName));
180
- entity.subTypes.push(subEntity);
181
- entities.push(subEntity);
182
- entitiesByName[subEntity.name] = subEntity;
183
- }
184
- }
185
- }
78
+ for (const entity of entities) {
79
+ const [fieldName, stiField] = Object.entries(config.entities[entity.name]?.fields || {}).find(([, f]) => !!f.stiDiscriminator) ?? [];
80
+ if (fieldName && stiField && stiField.stiDiscriminator) {
81
+ entity.inheritanceType = "sti";
82
+ const enumField = entity.enums.find((e) => e.fieldName === fieldName) ?? fail(`No enum column found for ${entity.name}.${fieldName}, which is required to use singleTableInheritance`);
83
+ entity.stiDiscriminatorField = enumField.fieldName;
84
+ const subTypes = Object.entries(stiField.stiDiscriminator);
85
+ const allFields = [...Object.entries(config.entities[entity.name]?.fields ?? {}), ...Object.entries(config.entities[entity.name]?.relations ?? {})];
86
+ const availableCodes = subTypes.map(([code]) => code);
87
+ const availableNames = subTypes.map(([, name]) => name);
88
+ const available = [...availableCodes, ...availableNames];
89
+ allFields.filter(([name, f]) => {
90
+ if (f.stiType && !available.includes(f.stiType)) fail(`${name}.stiType '${f.stiType}' is invalid, expected one of ${available.join(", ")}`);
91
+ });
92
+ for (const [enumCode, subTypeName] of subTypes) {
93
+ const subTypeFields = allFields.filter(([, f]) => f.stiType === subTypeName || f.stiType === enumCode);
94
+ const subTypeFieldNames = subTypeFields.map(([name]) => name);
95
+ function maybeRequired(field) {
96
+ if ((subTypeFields.find(([name]) => name === field.fieldName)?.[1]).notNull) field.notNull = true;
97
+ return field;
98
+ }
99
+ const subEntity = {
100
+ name: subTypeName,
101
+ entity: makeEntity(subTypeName),
102
+ tableName: entity.tableName,
103
+ primaryKey: entity.primaryKey,
104
+ primitives: entity.primitives.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),
105
+ enums: entity.enums.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),
106
+ pgEnums: entity.pgEnums.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),
107
+ manyToOnes: entity.manyToOnes.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),
108
+ oneToManys: entity.oneToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),
109
+ largeOneToManys: entity.largeOneToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),
110
+ oneToOnes: entity.oneToOnes.filter((f) => subTypeFieldNames.includes(f.fieldName)),
111
+ manyToManys: entity.manyToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),
112
+ largeManyToManys: entity.largeManyToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),
113
+ manyToManyEnums: entity.manyToManyEnums.filter((f) => subTypeFieldNames.includes(f.fieldName)),
114
+ polymorphics: entity.polymorphics.filter((f) => subTypeFieldNames.includes(f.fieldName)),
115
+ tagName: entity.tagName,
116
+ createdAt: void 0,
117
+ updatedAt: void 0,
118
+ deletedAt: void 0,
119
+ baseClassName: entity.name,
120
+ baseType: entity,
121
+ subTypes: [],
122
+ inheritanceType: "sti",
123
+ stiDiscriminatorValue: (enumField.enumRows.find((r) => r.code === enumCode) ?? fail(`No enum row found for ${entity.name}.${fieldName}.${enumCode}`)).id,
124
+ abstract: false,
125
+ nonDeferredFkOrder: entity.nonDeferredFkOrder,
126
+ get nonDeferredFks() {
127
+ return [...this.manyToOnes.filter((r) => !r.isDeferredAndDeferrable), ...this.polymorphics.flatMap((p) => p.components).filter((c) => !c.isDeferredAndDeferrable)];
128
+ },
129
+ get nonDeferredManyToManyFks() {
130
+ return this.manyToManys.filter((r) => !r.isDeferredAndDeferrable);
131
+ }
132
+ };
133
+ entity.primitives = entity.primitives.filter((f) => !subTypeFieldNames.includes(f.fieldName));
134
+ entity.enums = entity.enums.filter((f) => !subTypeFieldNames.includes(f.fieldName));
135
+ entity.pgEnums = entity.pgEnums.filter((f) => !subTypeFieldNames.includes(f.fieldName));
136
+ entity.manyToOnes = entity.manyToOnes.filter((f) => !subTypeFieldNames.includes(f.fieldName));
137
+ entity.oneToManys = entity.oneToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));
138
+ entity.largeOneToManys = entity.largeOneToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));
139
+ entity.oneToOnes = entity.oneToOnes.filter((f) => !subTypeFieldNames.includes(f.fieldName));
140
+ entity.manyToManys = entity.manyToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));
141
+ entity.largeManyToManys = entity.largeManyToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));
142
+ entity.manyToManyEnums = entity.manyToManyEnums.filter((f) => !subTypeFieldNames.includes(f.fieldName));
143
+ entity.polymorphics = entity.polymorphics.filter((f) => !subTypeFieldNames.includes(f.fieldName));
144
+ entity.subTypes.push(subEntity);
145
+ entities.push(subEntity);
146
+ entitiesByName[subEntity.name] = subEntity;
147
+ }
148
+ }
149
+ }
186
150
  }
187
151
  let stiEntities;
188
152
  function getStiEntities(entities) {
189
- if (stiEntities)
190
- return stiEntities;
191
- stiEntities = new Map();
192
- for (const entity of entities) {
193
- if (entity.inheritanceType === "sti" && entity.stiDiscriminatorField) {
194
- const base = entity;
195
- const subTypes = entities.filter((s) => s.baseClassName === entity.name && s !== entity);
196
- stiEntities.set(entity.name, { base, subTypes });
197
- // Allow looking up by subType name
198
- for (const subType of subTypes) {
199
- stiEntities.set(subType.name, { base, subTypes: [] });
200
- }
201
- }
202
- }
203
- return stiEntities;
153
+ if (stiEntities) return stiEntities;
154
+ stiEntities = /* @__PURE__ */ new Map();
155
+ for (const entity of entities) if (entity.inheritanceType === "sti" && entity.stiDiscriminatorField) {
156
+ const base = entity;
157
+ const subTypes = entities.filter((s) => s.baseClassName === entity.name && s !== entity);
158
+ stiEntities.set(entity.name, {
159
+ base,
160
+ subTypes
161
+ });
162
+ for (const subType of subTypes) stiEntities.set(subType.name, {
163
+ base,
164
+ subTypes: []
165
+ });
166
+ }
167
+ return stiEntities;
204
168
  }
205
169
  /** Finds FKs pointing to the base table and, if configured, rewrites them to point to the sub-tables. */
206
170
  function rewriteSingleTableForeignKeys(config, entities) {
207
- // See if we even have any STI tables
208
- const stiEntities = getStiEntities(entities);
209
- if (stiEntities.size === 0)
210
- return;
211
- // Scan for other entities/relations that point to the STI table
212
- for (const entity of entities) {
213
- // m2os -- Look for `entity.task_id` FKs pointing at `Task` and, if configured, rewrite them to point at `TaskOld`
214
- for (const m2o of entity.manyToOnes) {
215
- const target = stiEntities.get(m2o.otherEntity.name);
216
- const base = target?.base.entity.name;
217
- // See if the user has pushed `Task.entities` down to a subtype
218
- const stiType = base && config.entities[base]?.relations?.[m2o.otherFieldName]?.stiType;
219
- if (target && stiType) {
220
- const { subTypes } = target;
221
- m2o.otherEntity = (subTypes.find((s) => s.name === stiType) ??
222
- (0, utils_1.fail)(`Could not find STI type '${stiType}' in ${subTypes.map((s) => s.name)}`)).entity;
223
- }
224
- }
225
- // polys -- Look for `entity.parent_task_id` FKs pointing at `Task` and, if configured, rewrite them to point at `TaskOld`
226
- for (const poly of entity.polymorphics) {
227
- for (const comp of poly.components) {
228
- const target = stiEntities.get(comp.otherEntity.name);
229
- const base = target?.base.entity.name;
230
- // See if the user has pushed `Task.entities` down to a subtype
231
- const stiType = base && config.entities[base]?.relations?.[comp.otherFieldName]?.stiType;
232
- if (target && stiType) {
233
- const { subTypes } = target;
234
- comp.otherEntity = (subTypes.find((s) => s.name === stiType) ??
235
- (0, utils_1.fail)(`Could not find STI type '${stiType}' in ${subTypes.map((s) => s.name)}`)).entity;
236
- }
237
- }
238
- }
239
- // o2ms -- Look for `entity.tasks` collections loading `task.entity_id`, but entity has been pushed down to `TaskOld`
240
- for (const o2m of entity.oneToManys) {
241
- const target = stiEntities.get(o2m.otherEntity.name);
242
- if (target && target.base.inheritanceType === "sti") {
243
- // Ensure the incoming FK is not in the base type, and find the 1st subtype (eventually N subtypes?)
244
- const otherField = target.subTypes.find((st) => !target.base.manyToOnes.some((m) => m.fieldName === o2m.otherFieldName) &&
245
- st.manyToOnes.some((m) => m.fieldName === o2m.otherFieldName));
246
- if (otherField) {
247
- o2m.otherEntity = otherField.entity;
248
- }
249
- }
250
- }
251
- // m2ms -- Look for `entity.tasks` collections loading m2m rows, but `entity` has been pushed down to `TaskOld`
252
- for (const m2m of entity.manyToManys) {
253
- const target = stiEntities.get(m2m.otherEntity.name);
254
- if (target && target.base.inheritanceType === "sti") {
255
- // Ensure the incoming FK is not in the base type, and find the 1st subtype (eventually N subtypes?)
256
- const otherField = target.subTypes.find((st) => !target.base.manyToManys.some((m) => m.fieldName === m2m.otherFieldName) &&
257
- st.manyToManys.some((m) => m.fieldName === m2m.otherFieldName));
258
- if (otherField) {
259
- m2m.otherEntity = otherField.entity;
260
- }
261
- }
262
- }
263
- }
171
+ const stiEntities = getStiEntities(entities);
172
+ if (stiEntities.size === 0) return;
173
+ for (const entity of entities) {
174
+ for (const m2o of entity.manyToOnes) {
175
+ const target = stiEntities.get(m2o.otherEntity.name);
176
+ const base = target?.base.entity.name;
177
+ const stiType = base && config.entities[base]?.relations?.[m2o.otherFieldName]?.stiType;
178
+ if (target && stiType) {
179
+ const { subTypes } = target;
180
+ m2o.otherEntity = (subTypes.find((s) => s.name === stiType) ?? fail(`Could not find STI type '${stiType}' in ${subTypes.map((s) => s.name)}`)).entity;
181
+ }
182
+ }
183
+ for (const poly of entity.polymorphics) for (const comp of poly.components) {
184
+ const target = stiEntities.get(comp.otherEntity.name);
185
+ const base = target?.base.entity.name;
186
+ const stiType = base && config.entities[base]?.relations?.[comp.otherFieldName]?.stiType;
187
+ if (target && stiType) {
188
+ const { subTypes } = target;
189
+ comp.otherEntity = (subTypes.find((s) => s.name === stiType) ?? fail(`Could not find STI type '${stiType}' in ${subTypes.map((s) => s.name)}`)).entity;
190
+ }
191
+ }
192
+ for (const o2m of entity.oneToManys) {
193
+ const target = stiEntities.get(o2m.otherEntity.name);
194
+ if (target && target.base.inheritanceType === "sti") {
195
+ const otherField = target.subTypes.find((st) => !target.base.manyToOnes.some((m) => m.fieldName === o2m.otherFieldName) && st.manyToOnes.some((m) => m.fieldName === o2m.otherFieldName));
196
+ if (otherField) o2m.otherEntity = otherField.entity;
197
+ }
198
+ }
199
+ for (const m2m of entity.manyToManys) {
200
+ const target = stiEntities.get(m2m.otherEntity.name);
201
+ if (target && target.base.inheritanceType === "sti") {
202
+ const otherField = target.subTypes.find((st) => !target.base.manyToManys.some((m) => m.fieldName === m2m.otherFieldName) && st.manyToManys.some((m) => m.fieldName === m2m.otherFieldName));
203
+ if (otherField) m2m.otherEntity = otherField.entity;
204
+ }
205
+ }
206
+ }
264
207
  }
208
+ //#endregion
209
+ export { applyInheritanceUpdates, getStiEntities };
210
+
265
211
  //# sourceMappingURL=inheritance.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"inheritance.js","sourceRoot":"","sources":["../src/inheritance.ts"],"names":[],"mappings":";;AAYA,0DAQC;AAoMD,wCAeC;AAvOD,yDAQ4B;AAE5B,mCAA+B;AAE/B,SAAgB,uBAAuB,CAAC,MAAc,EAAE,EAAc;IACpE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,EAAE,CAAC;IACxC,wBAAwB,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IACnD,4BAA4B,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC;IAC/D,6BAA6B,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAChD,0BAA0B,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC7C,sGAAsG;IACtG,IAAA,4CAAyB,EAAC,EAAE,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,0BAA0B,CAAC,MAAc,EAAE,QAA4B;IAC9E,KAAK,MAAM,MAAM,IAAI,QAAQ,EAAE,CAAC;QAC9B,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YACpB,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAClD,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACzD,2EAA2E;YAC3E,KAAK,MAAM,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;gBACjF,MAAM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CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,GAAG,CAAC,cAAc,CAAC;oBACvE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,GAAG,CAAC,cAAc,CAAC,CAChE,CAAC;gBACF,IAAI,UAAU,EAAE,CAAC;oBACf,GAAG,CAAC,WAAW,GAAG,UAAU,CAAC,MAAM,CAAC;gBACtC,CAAC;YACH,CAAC;QACH,CAAC;QACD,+GAA+G;QAC/G,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;YACrC,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YACrD,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,eAAe,KAAK,KAAK,EAAE,CAAC;gBACpD,oGAAoG;gBACpG,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CACrC,CAAC,EAAE,EAAE,EAAE,CACL,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,GAAG,CAAC,cAAc,CAAC;oBACxE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,GAAG,CAAC,cAAc,CAAC,CACjE,CAAC;gBACF,IAAI,UAAU,EAAE,CAAC;oBACf,GAAG,CAAC,WAAW,GAAG,UAAU,CAAC,MAAM,CAAC;gBACtC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"inheritance.js","names":[],"sources":["../src/inheritance.ts"],"sourcesContent":["import { type Config } from \"./config.ts\";\nimport {\n type DbMetadata,\n type EntityDbMetadata,\n type ManyToManyField,\n type ManyToOneField,\n type PolymorphicFieldComponent,\n canonicalizeOtherEntities,\n makeEntity,\n} from \"./EntityDbMetadata.ts\";\nimport { fail } from \"./utils.ts\";\n\nexport function applyInheritanceUpdates(config: Config, db: DbMetadata): void {\n const { entities, entitiesByName } = db;\n setClassTableInheritance(entities, entitiesByName);\n expandSingleTableInheritance(config, entitiesByName, entities);\n rewriteSingleTableForeignKeys(config, entities);\n setupSubTypeSpecialization(config, entities);\n // Now that all relations (incl. specialized ones) exist, collapse the duplicate `otherEntity` objects\n canonicalizeOtherEntities(db);\n}\n\n/**\n * Looks for subtypes specializing a FK of their base type, and give them a specialized m2o.\n *\n * I.e. `SmallPublishers.group: SmallPublisherGroup`.\n *\n * This means the `publishers.group_id` FK will actually be in the `EntityDbMetadata` twice,\n * once for the base and once for the child, which is unusual, but gets the types generated\n * that we want, and then we fixup/dedupe them at runtime in `configure.ts` when creating\n * `meta.allFields`.\n */\nfunction setupSubTypeSpecialization(config: Config, entities: EntityDbMetadata[]): void {\n for (const entity of entities) {\n if (entity.baseType) {\n const entityConfig = config.entities[entity.name];\n const baseConfig = config.entities[entity.baseType.name];\n // Look through the base's m2os & o2ms, looking for a config specialization\n for (const rel of [...entity.baseType.manyToOnes, ...entity.baseType.oneToManys]) {\n const { notNull } = entityConfig?.relations?.[rel.fieldName] ?? {};\n const subType =\n entityConfig?.relations?.[rel.fieldName]?.subType ??\n baseConfig?.relations?.[rel.fieldName]?.subType ??\n // Probe the otherFieldName for a `subType: \"self\"` on self-referential relations in STI tables\n baseConfig?.relations?.[rel.otherFieldName]?.subType ??\n // if we are only marking the relation as required and not specifying a subtype, then use the original type\n (notNull ? rel.otherEntity.name : undefined);\n\n if (!subType) {\n // continue...\n } else if (subType === \"self\" && rel.kind === \"m2o\") {\n // Specialize `TaskNew.copiedFrom: TaskNew` & `TaskOld.copiedFrom: TaskOld`\n entity.manyToOnes.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(entity.name) });\n } else if (subType === \"self\" && rel.kind === \"o2m\") {\n // Specialize `TaskNew.copiedTo: TaskNew[]` & `TaskOld.copiedTo: TaskOld[]`\n entity.oneToManys.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(entity.name) });\n } else if (rel.kind === \"m2o\") {\n // Specialize `SmallPublisher.group: SmallPublisherGroup`\n entity.manyToOnes.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(subType) });\n } else if (rel.kind === \"o2m\") {\n // Specialize `SmallPublisherGroup.publishers: SmallPublisher`\n entity.oneToManys.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(subType) });\n }\n }\n\n // Look through the base's primitives looking for a config specialization\n for (const field of entity.baseType?.primitives ?? []) {\n // the only specialization a primitive can have is nullability\n const { notNull } = entityConfig?.fields?.[field.fieldName] ?? {};\n if (notNull) {\n entity.primitives.push({ ...field, notNull });\n }\n }\n }\n }\n}\n\n/**\n * Ensure CTI base types have their inheritanceType set.\n *\n * (We automatically set `inheritanceType` for STI tables when we see their config\n * setup, see `expandSingleTableInheritance`.)\n */\nfunction setClassTableInheritance(\n entities: EntityDbMetadata[],\n entitiesByName: Record<string, EntityDbMetadata>,\n): void {\n const ctiBaseNames: string[] = [];\n for (const entity of entities) {\n if (entity.baseClassName) {\n ctiBaseNames.push(entity.baseClassName);\n const base = entitiesByName[entity.baseClassName];\n entity.baseType = base;\n base.subTypes.push(entity);\n }\n }\n for (const entity of entities) {\n if (ctiBaseNames.includes(entity.name)) entity.inheritanceType = \"cti\";\n }\n}\n\n/** Expands STI tables into multiple entities, so they get separate `SubTypeCodegen.ts` & `SubType.ts` files. */\nfunction expandSingleTableInheritance(\n config: Config,\n entitiesByName: Record<string, EntityDbMetadata>,\n entities: EntityDbMetadata[],\n): void {\n for (const entity of entities) {\n const [fieldName, stiField] =\n Object.entries(config.entities[entity.name]?.fields || {}).find(([, f]) => !!f.stiDiscriminator) ?? [];\n if (fieldName && stiField && stiField.stiDiscriminator) {\n entity.inheritanceType = \"sti\";\n\n // Ensure we have an enum field so that we can bake the STI discriminators into the metadata.ts file\n const enumField =\n entity.enums.find((e) => e.fieldName === fieldName) ??\n fail(`No enum column found for ${entity.name}.${fieldName}, which is required to use singleTableInheritance`);\n entity.stiDiscriminatorField = enumField.fieldName;\n\n // Find the available discriminators/subtypes, i.e. NEW => NewTask, OLD => OldTask, etc.\n const subTypes = Object.entries(stiField.stiDiscriminator);\n\n const allFields = [\n ...Object.entries(config.entities[entity.name]?.fields ?? {}),\n ...Object.entries(config.entities[entity.name]?.relations ?? {}),\n ];\n\n // Make sure there aren't any typos in `stiType`s\n const availableCodes = subTypes.map(([code]) => code);\n const availableNames = subTypes.map(([, name]) => name);\n const available = [...availableCodes, ...availableNames];\n allFields.filter(([name, f]) => {\n if (f.stiType && !available.includes(f.stiType)) {\n fail(`${name}.stiType '${f.stiType}' is invalid, expected one of ${available.join(\", \")}`);\n }\n });\n\n // Now split each subType out into its out entity\n for (const [enumCode, subTypeName] of subTypes) {\n // Find all the base entity's fields that belong to us\n const subTypeFields = allFields.filter(([, f]) => f.stiType === subTypeName || f.stiType === enumCode);\n const subTypeFieldNames = subTypeFields.map(([name]) => name);\n\n // Make fields as required\n function maybeRequired<T extends { notNull: boolean; fieldName: string }>(field: T): T {\n const config = subTypeFields.find(([name]) => name === field.fieldName)?.[1]!;\n if (config.notNull) field.notNull = true;\n return field;\n }\n\n // Synthesize an entity for this STI sub-entity\n const subEntity: EntityDbMetadata = {\n name: subTypeName,\n entity: makeEntity(subTypeName),\n tableName: entity.tableName,\n primaryKey: entity.primaryKey,\n primitives: entity.primitives.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n enums: entity.enums.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n pgEnums: entity.pgEnums.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n manyToOnes: entity.manyToOnes.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n oneToManys: entity.oneToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n largeOneToManys: entity.largeOneToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n oneToOnes: entity.oneToOnes.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n manyToManys: entity.manyToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n largeManyToManys: entity.largeManyToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n manyToManyEnums: entity.manyToManyEnums.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n polymorphics: entity.polymorphics.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n tagName: entity.tagName,\n createdAt: undefined,\n updatedAt: undefined,\n deletedAt: undefined,\n baseClassName: entity.name,\n baseType: entity,\n subTypes: [],\n inheritanceType: \"sti\",\n stiDiscriminatorValue: (\n enumField.enumRows.find((r) => r.code === enumCode) ??\n fail(`No enum row found for ${entity.name}.${fieldName}.${enumCode}`)\n ).id,\n abstract: false,\n nonDeferredFkOrder: entity.nonDeferredFkOrder,\n get nonDeferredFks(): Array<ManyToOneField | PolymorphicFieldComponent> {\n return [\n ...this.manyToOnes.filter((r) => !r.isDeferredAndDeferrable),\n ...this.polymorphics.flatMap((p) => p.components).filter((c) => !c.isDeferredAndDeferrable),\n ];\n },\n get nonDeferredManyToManyFks(): Array<ManyToManyField> {\n return this.manyToManys.filter((r) => !r.isDeferredAndDeferrable);\n },\n };\n\n // Now strip all the subclass fields from the base class\n entity.primitives = entity.primitives.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.enums = entity.enums.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.pgEnums = entity.pgEnums.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.manyToOnes = entity.manyToOnes.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.oneToManys = entity.oneToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.largeOneToManys = entity.largeOneToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.oneToOnes = entity.oneToOnes.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.manyToManys = entity.manyToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.largeManyToManys = entity.largeManyToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.manyToManyEnums = entity.manyToManyEnums.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.polymorphics = entity.polymorphics.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.subTypes.push(subEntity);\n\n entities.push(subEntity);\n entitiesByName[subEntity.name] = subEntity;\n }\n }\n }\n}\n\ntype StiEntityMap = Map<string, { base: EntityDbMetadata; subTypes: EntityDbMetadata[] }>;\nlet stiEntities: StiEntityMap;\n\nexport function getStiEntities(entities: EntityDbMetadata[]): StiEntityMap {\n if (stiEntities) return stiEntities;\n stiEntities = new Map();\n for (const entity of entities) {\n if (entity.inheritanceType === \"sti\" && entity.stiDiscriminatorField) {\n const base = entity;\n const subTypes = entities.filter((s) => s.baseClassName === entity.name && s !== entity);\n stiEntities.set(entity.name, { base, subTypes });\n // Allow looking up by subType name\n for (const subType of subTypes) {\n stiEntities.set(subType.name, { base, subTypes: [] });\n }\n }\n }\n return stiEntities;\n}\n\n/** Finds FKs pointing to the base table and, if configured, rewrites them to point to the sub-tables. */\nfunction rewriteSingleTableForeignKeys(config: Config, entities: EntityDbMetadata[]): void {\n // See if we even have any STI tables\n const stiEntities = getStiEntities(entities);\n if (stiEntities.size === 0) return;\n // Scan for other entities/relations that point to the STI table\n for (const entity of entities) {\n // m2os -- Look for `entity.task_id` FKs pointing at `Task` and, if configured, rewrite them to point at `TaskOld`\n for (const m2o of entity.manyToOnes) {\n const target = stiEntities.get(m2o.otherEntity.name);\n const base = target?.base.entity.name;\n // See if the user has pushed `Task.entities` down to a subtype\n const stiType = base && config.entities[base]?.relations?.[m2o.otherFieldName]?.stiType;\n if (target && stiType) {\n const { subTypes } = target;\n m2o.otherEntity = (\n subTypes.find((s) => s.name === stiType) ??\n fail(`Could not find STI type '${stiType}' in ${subTypes.map((s) => s.name)}`)\n ).entity;\n }\n }\n // polys -- Look for `entity.parent_task_id` FKs pointing at `Task` and, if configured, rewrite them to point at `TaskOld`\n for (const poly of entity.polymorphics) {\n for (const comp of poly.components) {\n const target = stiEntities.get(comp.otherEntity.name);\n const base = target?.base.entity.name;\n // See if the user has pushed `Task.entities` down to a subtype\n const stiType = base && config.entities[base]?.relations?.[comp.otherFieldName]?.stiType;\n if (target && stiType) {\n const { subTypes } = target;\n comp.otherEntity = (\n subTypes.find((s) => s.name === stiType) ??\n fail(`Could not find STI type '${stiType}' in ${subTypes.map((s) => s.name)}`)\n ).entity;\n }\n }\n }\n // o2ms -- Look for `entity.tasks` collections loading `task.entity_id`, but entity has been pushed down to `TaskOld`\n for (const o2m of entity.oneToManys) {\n const target = stiEntities.get(o2m.otherEntity.name);\n if (target && target.base.inheritanceType === \"sti\") {\n // Ensure the incoming FK is not in the base type, and find the 1st subtype (eventually N subtypes?)\n const otherField = target.subTypes.find(\n (st) =>\n !target.base.manyToOnes.some((m) => m.fieldName === o2m.otherFieldName) &&\n st.manyToOnes.some((m) => m.fieldName === o2m.otherFieldName),\n );\n if (otherField) {\n o2m.otherEntity = otherField.entity;\n }\n }\n }\n // m2ms -- Look for `entity.tasks` collections loading m2m rows, but `entity` has been pushed down to `TaskOld`\n for (const m2m of entity.manyToManys) {\n const target = stiEntities.get(m2m.otherEntity.name);\n if (target && target.base.inheritanceType === \"sti\") {\n // Ensure the incoming FK is not in the base type, and find the 1st subtype (eventually N subtypes?)\n const otherField = target.subTypes.find(\n (st) =>\n !target.base.manyToManys.some((m) => m.fieldName === m2m.otherFieldName) &&\n st.manyToManys.some((m) => m.fieldName === m2m.otherFieldName),\n );\n if (otherField) {\n m2m.otherEntity = otherField.entity;\n }\n }\n }\n }\n}\n"],"mappings":";;;;AAYA,SAAgB,wBAAwB,QAAgB,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